Adaptation of the official mbed FATFileSystem repository to allow more than one file system volume

Dependents:   DMSupport DMSupport DMSupport

Fork of DM_FATFileSystem by EmbeddedArtists AB

Files at this revision

API Documentation at this revision

Comitter:
embeddedartists
Date:
Thu Dec 11 11:07:47 2014 +0000
Parent:
6:4b97221ac12e
Commit message:
Fixed the implementation of opendir() and mkdir() functions so that they work in multi-volume environments (e.g. when using MCI and USB file systems at the same time)

Changed in this revision

FATFileSystem.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4b97221ac12e -r edfd01fea6d7 FATFileSystem.cpp
--- a/FATFileSystem.cpp	Tue Dec 02 15:09:28 2014 +0000
+++ b/FATFileSystem.cpp	Thu Dec 11 11:07:47 2014 +0000
@@ -68,7 +68,7 @@
 FileHandle *FATFileSystem::open(const char* name, int flags) {
     debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
     char n[64];
-    sprintf(n, "%d:/%s", _fsid, name);
+    snprintf(n, 64, "%d:/%s", _fsid, name);
 
     /* POSIX flags -> FatFS open mode */
     BYTE openmode;
@@ -127,8 +127,13 @@
 }
 
 DirHandle *FATFileSystem::opendir(const char *name) {
+    // Added by Embedded Artists to fix implementation when using more than one volume
+    debug_if(FFS_DBG, "opendir(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
+    char n[64];
+    snprintf(n, 64, "%d:/%s", _fsid, name);
+    
     FATFS_DIR dir;
-    FRESULT res = f_opendir(&dir, name);
+    FRESULT res = f_opendir(&dir, n);
     if (res != 0) {
         return NULL;
     }
@@ -136,7 +141,12 @@
 }
 
 int FATFileSystem::mkdir(const char *name, mode_t mode) {
-    FRESULT res = f_mkdir(name);
+    // Added by Embedded Artists to fix implementation when using more than one volume
+    debug_if(FFS_DBG, "mkdir(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
+    char n[64];
+    snprintf(n, 64, "%d:/%s", _fsid, name);
+    
+    FRESULT res = f_mkdir(n);
     return res == 0 ? 0 : -1;
 }