mirror of
https://github.com/wiiu-env/libfat.git
synced 2024-11-22 01:49:17 +01:00
Add rmdir support (#17)
This commit is contained in:
parent
fef8efe371
commit
1087f6ed6d
@ -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;
|
||||
@ -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) {
|
||||
@ -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)) {
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
/*
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user