Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion source/fatdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink) {
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;
DIR_ENTRY dirEntry;
DIR_ENTRY dirContents;
Expand Down Expand Up @@ -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 (_FAT_directory_isDirectory (&dirEntry)) {
if (!isRmDir) {
_FAT_unlock(&partition->lock);
r->_errno = EISDIR;
return -1;
}

nextEntry = _FAT_directory_getFirstEntry (partition, &dirContents, cluster);

while (nextEntry) {
Expand All @@ -141,6 +147,10 @@ int _FAT_unlink_r (struct _reent *r, const char *path) {
}
nextEntry = _FAT_directory_getNextEntry (partition, &dirContents);
}
} else if (isRmDir) {
_FAT_unlock(&partition->lock);
r->_errno = ENOTDIR;
return -1;
}

if (_FAT_fat_isValidCluster(partition, cluster)) {
Expand Down Expand Up @@ -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) {
PARTITION* partition = NULL;

Expand Down Expand Up @@ -451,6 +465,10 @@ int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) {
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)
{
PARTITION* partition = NULL;
Expand Down
2 changes: 2 additions & 0 deletions source/fatdir.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_rmdir_r (struct _reent *r, const char *path);

extern int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf);

/*
Expand Down
2 changes: 0 additions & 2 deletions source/fatfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_unlink_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);
Expand Down
2 changes: 1 addition & 1 deletion source/libfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static const devoptab_t dotab_fat = {
NULL, /* Device data */
NULL, // chmod_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) {
Expand Down