This is SDFileSystem which corrected the bug for MiMicSDK.
Dependents: MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more
Fork of SDFileSystem by
Revision 6:972a52e4d92c, committed 2013-04-26
- Comitter:
- nyatla
- Date:
- Fri Apr 26 09:07:37 2013 +0000
- Parent:
- 5:2c7b6bd5b079
- Child:
- 7:5429e81addde
- Commit message:
- remove sprintf and n[64] from FATFileSystem; change ChaN library.
Changed in this revision
--- a/FATFileSystem/ChaN/ff.cpp Thu Apr 25 02:14:56 2013 +0000 +++ b/FATFileSystem/ChaN/ff.cpp Fri Apr 26 09:07:37 2013 +0000 @@ -2041,6 +2041,7 @@ static FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */ + int drive_number, const TCHAR **path, /* Pointer to pointer to the path name (drive number) */ FATFS **rfs, /* Pointer to pointer to the found file system object */ BYTE wmode /* !=0: Check write protection for write access */ @@ -2051,10 +2052,17 @@ DSTATUS stat; DWORD bsect, fasize, tsect, sysect, nclst, szbfat; WORD nrsv; - const TCHAR *p = *path; +// const TCHAR *p = *path; FATFS *fs; - - + +#if _FS_RPATH + vol=drive_number<0?CurrVol:(UINT)drive_number; +#else + vol=drive_number<0?0:(UINT)drive_number; +#endif + + +#ifdef nyatla_comment /* Get logical drive number from the path name */ vol = p[0] - '0'; /* Is there a drive number? */ if (vol <= 9 && p[1] == ':') { /* Found a drive number, get and strip it */ @@ -2066,6 +2074,7 @@ vol = 0; /* Use drive 0 */ #endif } +#endif /* Check if the file system object is valid or not */ *rfs = 0; @@ -2285,6 +2294,7 @@ FRESULT f_open ( FIL *fp, /* Pointer to the blank file object */ + int drive_number, const TCHAR *path, /* Pointer to the file name */ BYTE mode /* Access mode and file open mode flags */ ) @@ -2298,10 +2308,10 @@ fp->fs = 0; /* Clear file object */ #if !_FS_READONLY mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW; - res = chk_mounted(&path, &dj.fs, (BYTE)(mode & ~FA_READ)); + res = chk_mounted(drive_number,&path, &dj.fs, (BYTE)(mode & ~FA_READ)); #else mode &= FA_READ; - res = chk_mounted(&path, &dj.fs, 0); + res = chk_mounted(drive_number,&path, &dj.fs, 0); #endif @@ -2743,6 +2753,7 @@ FRESULT f_chdir ( + int drive_number, const TCHAR *path /* Pointer to the directory path */ ) { @@ -2751,7 +2762,7 @@ DEF_NAMEBUF; - res = chk_mounted(&path, &dj.fs, 0); + res = chk_mounted(drive_number,&path, &dj.fs, 0); if (res == FR_OK) { INIT_BUF(dj); res = follow_path(&dj, path); /* Follow the path */ @@ -2775,6 +2786,7 @@ #if _FS_RPATH >= 2 FRESULT f_getcwd ( + int drive_number, TCHAR *path, /* Pointer to the directory path */ UINT sz_path /* Size of path */ ) @@ -2789,7 +2801,7 @@ *path = 0; - res = chk_mounted((const TCHAR**)&path, &dj.fs, 0); /* Get current volume */ + res = chk_mounted(drive_number,(const TCHAR**)&path, &dj.fs, 0); /* Get current volume */ if (res == FR_OK) { INIT_BUF(dj); i = sz_path; /* Bottom of buffer (dir stack base) */ @@ -3012,6 +3024,7 @@ FRESULT f_opendir ( FATFS_DIR *dj, /* Pointer to directory object to create */ + int drive_number, const TCHAR *path /* Pointer to the directory path */ ) { @@ -3021,7 +3034,7 @@ if (!dj) return FR_INVALID_OBJECT; - res = chk_mounted(&path, &dj->fs, 0); + res = chk_mounted(drive_number,&path, &dj->fs, 0); fs = dj->fs; if (res == FR_OK) { INIT_BUF(*dj); @@ -3098,6 +3111,7 @@ /*-----------------------------------------------------------------------*/ FRESULT f_stat ( + int drive_number, const TCHAR *path, /* Pointer to the file path */ FILINFO *fno /* Pointer to file information to return */ ) @@ -3107,7 +3121,7 @@ DEF_NAMEBUF; - res = chk_mounted(&path, &dj.fs, 0); + res = chk_mounted(drive_number,&path, &dj.fs, 0); if (res == FR_OK) { INIT_BUF(dj); res = follow_path(&dj, path); /* Follow the file path */ @@ -3131,6 +3145,7 @@ /*-----------------------------------------------------------------------*/ FRESULT f_getfree ( + int drive_number, const TCHAR *path, /* Pointer to the logical drive number (root dir) */ DWORD *nclst, /* Pointer to the variable to return number of free clusters */ FATFS **fatfs /* Pointer to pointer to corresponding file system object to return */ @@ -3144,7 +3159,7 @@ /* Get drive number */ - res = chk_mounted(&path, fatfs, 0); + res = chk_mounted(drive_number,&path, fatfs, 0); fs = *fatfs; if (res == FR_OK) { /* If free_clust is valid, return it without full cluster scan */ @@ -3248,6 +3263,7 @@ /*-----------------------------------------------------------------------*/ FRESULT f_unlink ( + int drive_number, const TCHAR *path /* Pointer to the file or directory path */ ) { @@ -3258,7 +3274,7 @@ DEF_NAMEBUF; - res = chk_mounted(&path, &dj.fs, 1); + res = chk_mounted(drive_number,&path, &dj.fs, 1); if (res == FR_OK) { INIT_BUF(dj); res = follow_path(&dj, path); /* Follow the file path */ @@ -3316,6 +3332,7 @@ /*-----------------------------------------------------------------------*/ FRESULT f_mkdir ( + int drive_number, const TCHAR *path /* Pointer to the directory path */ ) { @@ -3326,7 +3343,7 @@ DEF_NAMEBUF; - res = chk_mounted(&path, &dj.fs, 1); + res = chk_mounted(drive_number,&path, &dj.fs, 1); if (res == FR_OK) { INIT_BUF(dj); res = follow_path(&dj, path); /* Follow the file path */ @@ -3389,6 +3406,7 @@ /*-----------------------------------------------------------------------*/ FRESULT f_chmod ( + int drive_number, const TCHAR *path, /* Pointer to the file path */ BYTE value, /* Attribute bits */ BYTE mask /* Attribute mask to change */ @@ -3400,7 +3418,7 @@ DEF_NAMEBUF; - res = chk_mounted(&path, &dj.fs, 1); + res = chk_mounted(drive_number,&path, &dj.fs, 1); if (res == FR_OK) { INIT_BUF(dj); res = follow_path(&dj, path); /* Follow the file path */ @@ -3431,6 +3449,7 @@ /*-----------------------------------------------------------------------*/ FRESULT f_utime ( + int drive_number, const TCHAR *path, /* Pointer to the file/directory name */ const FILINFO *fno /* Pointer to the time stamp to be set */ ) @@ -3441,7 +3460,7 @@ DEF_NAMEBUF; - res = chk_mounted(&path, &dj.fs, 1); + res = chk_mounted(drive_number,&path, &dj.fs, 1); if (res == FR_OK) { INIT_BUF(dj); res = follow_path(&dj, path); /* Follow the file path */ @@ -3472,6 +3491,7 @@ /*-----------------------------------------------------------------------*/ FRESULT f_rename ( + int drive_number, const TCHAR *path_old, /* Pointer to the old name */ const TCHAR *path_new /* Pointer to the new name */ ) @@ -3483,7 +3503,7 @@ DEF_NAMEBUF; - res = chk_mounted(&path_old, &djo.fs, 1); + res = chk_mounted(drive_number,&path_old, &djo.fs, 1); if (res == FR_OK) { djn.fs = djo.fs; INIT_BUF(djo);
--- a/FATFileSystem/ChaN/ff.h Thu Apr 25 02:14:56 2013 +0000 +++ b/FATFileSystem/ChaN/ff.h Fri Apr 26 09:07:37 2013 +0000 @@ -203,25 +203,25 @@ /* FatFs module application interface */ FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ -FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */ +FRESULT f_open (FIL*,int,const TCHAR*, BYTE); /* Open or create a file */ FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ FRESULT f_close (FIL*); /* Close an open file object */ -FRESULT f_opendir (FATFS_DIR*, const TCHAR*); /* Open an existing directory */ +FRESULT f_opendir (FATFS_DIR*,int, const TCHAR*); /* Open an existing directory */ FRESULT f_readdir (FATFS_DIR*, FILINFO*); /* Read a directory item */ -FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */ +FRESULT f_stat (int,const TCHAR*, FILINFO*); /* Get file status */ FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ -FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ +FRESULT f_getfree (int,const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ FRESULT f_truncate (FIL*); /* Truncate file */ FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ -FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */ -FRESULT f_mkdir (const TCHAR*); /* Create a new directory */ -FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attribute of the file/dir */ -FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change times-tamp of the file/dir */ -FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */ +FRESULT f_unlink (int,const TCHAR*); /* Delete an existing file or directory */ +FRESULT f_mkdir (int,const TCHAR*); /* Create a new directory */ +FRESULT f_chmod (int,const TCHAR*, BYTE, BYTE); /* Change attribute of the file/dir */ +FRESULT f_utime (int,const TCHAR*, const FILINFO*); /* Change times-tamp of the file/dir */ +FRESULT f_rename (int,const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */ FRESULT f_chdrive (BYTE); /* Change current drive */ -FRESULT f_chdir (const TCHAR*); /* Change current directory */ -FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */ +FRESULT f_chdir (int,const TCHAR*); /* Change current directory */ +FRESULT f_getcwd (int,TCHAR*, UINT); /* Get current directory */ FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */ FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */
--- a/FATFileSystem/FATDirHandle.cpp Thu Apr 25 02:14:56 2013 +0000 +++ b/FATFileSystem/FATDirHandle.cpp Fri Apr 26 09:07:37 2013 +0000 @@ -48,6 +48,8 @@ if(res != 0 || finfo.fname[0]==0) { return NULL; } else { + cur_entry.fattrib=finfo.fattrib; + cur_entry.fsize=finfo.fsize; if(cur_entry.d_name[0]==0) { // No long filename so use short filename. memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); @@ -58,6 +60,7 @@ if(res != 0 || finfo.fname[0]==0) { return NULL; } else { + cur_entry.fatatlib=finfo.fattrib; memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); return &cur_entry; }
--- a/FATFileSystem/FATDirHandle.h Thu Apr 25 02:14:56 2013 +0000 +++ b/FATFileSystem/FATDirHandle.h Fri Apr 26 09:07:37 2013 +0000 @@ -21,11 +21,17 @@ */ #ifndef MBED_FATDIRHANDLE_H #define MBED_FATDIRHANDLE_H - +#include "ff.h" #include "DirHandle.h" using namespace mbed; +struct direntFAT:public dirent +{ + unsigned char fattrib; + unsigned int fsize; +}; + class FATDirHandle : public DirHandle { public: @@ -38,7 +44,7 @@ private: FATFS_DIR dir; - struct dirent cur_entry; + struct direntFAT cur_entry; };
--- a/FATFileSystem/FATFileSystem.cpp Thu Apr 25 02:14:56 2013 +0000 +++ b/FATFileSystem/FATFileSystem.cpp Fri Apr 26 09:07:37 2013 +0000 @@ -67,8 +67,8 @@ 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); +// char n[64]; +// sprintf(n, "%d:/%s", _fsid, name); /* POSIX flags -> FatFS open mode */ BYTE openmode; @@ -87,7 +87,7 @@ } } FIL fh; - FRESULT res = f_open(&fh, n, openmode); + FRESULT res = f_open(&fh,this->_fsid,name, openmode); if (res) { debug_if(FFS_DBG, "f_open('w') failed: %d\n", res); return NULL; @@ -99,7 +99,7 @@ } int FATFileSystem::remove(const char *filename) { - FRESULT res = f_unlink(filename); + FRESULT res = f_unlink(this->_fsid,filename); if (res) { debug_if(FFS_DBG, "f_unlink() failed: %d\n", res); return -1; @@ -115,10 +115,9 @@ } return 0; } - DirHandle *FATFileSystem::opendir(const char *name) { - FATFS_DIR dir; - FRESULT res = f_opendir(&dir, name); + FATFS_DIR dir; + FRESULT res = f_opendir(&dir,this->_fsid,name); if (res != 0) { return NULL; } @@ -126,6 +125,6 @@ } int FATFileSystem::mkdir(const char *name, mode_t mode) { - FRESULT res = f_mkdir(name); + FRESULT res = f_mkdir(this->_fsid,name); return res == 0 ? 0 : -1; }