mirror of https://github.com/ARMmbed/mbed-os.git
Added implementation for "rename" on FAT file system
parent
1409f2a090
commit
cde156cadc
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue