Add rmdir support (#17)

This commit is contained in:
mtheall 2020-04-19 17:41:01 -05:00 committed by GitHub
parent fef8efe371
commit 1087f6ed6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 4 deletions

View File

@ -86,7 +86,7 @@ int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink) {
return -1; return -1;
} }
int _FAT_unlink_r (struct _reent *r, const char *path) { static int _FAT_unlinkCommon (struct _reent *r, const char *path, bool isRmDir) {
PARTITION* partition = NULL; PARTITION* partition = NULL;
DIR_ENTRY dirEntry; DIR_ENTRY dirEntry;
DIR_ENTRY dirContents; DIR_ENTRY dirContents;
@ -130,6 +130,12 @@ int _FAT_unlink_r (struct _reent *r, const char *path) {
// If this is a directory, make sure it is empty // If this is a directory, make sure it is empty
if (_FAT_directory_isDirectory (&dirEntry)) { if (_FAT_directory_isDirectory (&dirEntry)) {
if (!isRmDir) {
_FAT_unlock(&partition->lock);
r->_errno = EISDIR;
return -1;
}
nextEntry = _FAT_directory_getFirstEntry (partition, &dirContents, cluster); nextEntry = _FAT_directory_getFirstEntry (partition, &dirContents, cluster);
while (nextEntry) { while (nextEntry) {
@ -141,6 +147,10 @@ int _FAT_unlink_r (struct _reent *r, const char *path) {
} }
nextEntry = _FAT_directory_getNextEntry (partition, &dirContents); nextEntry = _FAT_directory_getNextEntry (partition, &dirContents);
} }
} else if (isRmDir) {
_FAT_unlock(&partition->lock);
r->_errno = ENOTDIR;
return -1;
} }
if (_FAT_fat_isValidCluster(partition, cluster)) { if (_FAT_fat_isValidCluster(partition, cluster)) {
@ -171,6 +181,10 @@ int _FAT_unlink_r (struct _reent *r, const char *path) {
} }
} }
int _FAT_unlink_r (struct _reent *r, const char *path) {
return _FAT_unlinkCommon (r, path, false);
}
int _FAT_chdir_r (struct _reent *r, const char *path) { int _FAT_chdir_r (struct _reent *r, const char *path) {
PARTITION* partition = NULL; PARTITION* partition = NULL;
@ -451,6 +465,10 @@ int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) {
return 0; return 0;
} }
int _FAT_rmdir_r (struct _reent *r, const char *path) {
return _FAT_unlinkCommon (r, path, true);
}
int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
{ {
PARTITION* partition = NULL; PARTITION* partition = NULL;

View File

@ -59,6 +59,8 @@ extern int _FAT_rename_r (struct _reent *r, const char *oldName, const char *new
extern int _FAT_mkdir_r (struct _reent *r, const char *path, int mode); extern int _FAT_mkdir_r (struct _reent *r, const char *path, int mode);
extern int _FAT_rmdir_r (struct _reent *r, const char *path);
extern int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf); extern int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf);
/* /*

View File

@ -85,8 +85,6 @@ int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st);
int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink); int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink);
int _FAT_unlink_r (struct _reent *r, const char *name);
int _FAT_chdir_r (struct _reent *r, const char *name); int _FAT_chdir_r (struct _reent *r, const char *name);
int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName); int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName);

View File

@ -66,7 +66,7 @@ static const devoptab_t dotab_fat = {
NULL, /* Device data */ NULL, /* Device data */
NULL, // chmod_r NULL, // chmod_r
NULL, // fchmod_r NULL, // fchmod_r
NULL // rmdir_r _FAT_rmdir_r,
}; };
bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage) { bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage) {