Added implementation for "rename" on FAT file system

pull/445/head
Alexander Valitov 2014-08-13 10:19:03 +01:00 committed by Bogdan Marinescu
parent 1409f2a090
commit cde156cadc
3 changed files with 19 additions and 1 deletions

View File

@ -108,6 +108,15 @@ int FATFileSystem::remove(const char *filename) {
return 0;
}
int FATFileSystem::rename(const char *oldname, const char *newname) {
FRESULT res = f_rename(oldname, newname);
if (res) {
debug_if(FFS_DBG, "f_rename() failed: %d\n", res);
return -1;
}
return 0;
}
int FATFileSystem::format() {
FRESULT res = f_mkfs(_fsid, 0, 512); // Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
if (res) {

View File

@ -41,6 +41,7 @@ public:
virtual FileHandle *open(const char* name, int flags);
virtual int remove(const char *filename);
virtual int rename(const char *oldname, const char *newname);
virtual int format();
virtual DirHandle *opendir(const char *name);
virtual int mkdir(const char *name, mode_t mode);

View File

@ -323,7 +323,15 @@ extern "C" int remove(const char *path) {
}
extern "C" int rename(const char *oldname, const char *newname) {
return -1;
FilePath fpOld(oldname);
FilePath fpNew(newname);
FileSystemLike *fsOld = fpOld.fileSystem();
FileSystemLike *fsNew = fpNew.fileSystem();
/* rename only if both files are on the same FS */
if (fsOld != fsNew || fsOld == NULL) return -1;
return fsOld->rename(fpOld.fileName(), fpNew.fileName());
}
extern "C" char *tmpnam(char *s) {