FS_i32 FS_Stat(const TCHAR *path,struct stat *buf) { FRESULT res; FILINFO stat; #if _USE_LFN static WCHAR lfn[_MAX_LFN+1]; stat.lfname = (TCHAR*)lfn; stat.lfsize = sizeof(lfn); #endif FS_X_OS_LockDirHandle(); res=f_stat ( path, /* Pointer to the file or directory name */ &stat /* Pointer to the FILINFO structure */ ); if(res!=FR_OK) { buf->st_size = 0; buf->st_mode = 0; buf->st_mtime = 0; FS_X_OS_UnlockDirHandle(); return -1; } buf->st_size = stat.fsize; buf->st_mode = (stat.fattrib & AM_DIR)?_IFDIR:0; buf->st_mtime = stat.ftime|(stat.fdate<<16); FS_X_OS_UnlockDirHandle(); return 0; }
FS_DIR *FS_OpenDir(const char *pDirName) { FS_DIR *handle; unsigned int i; int idx; char *s; /* Find correct FSL (device:unit:name) */ idx = FS__find_fsl(pDirName, &s); if (idx < 0) { return 0; /* Device not found */ } if (FS__pDevInfo[idx].fs_ptr->fsl_opendir) { /* Find next free entry in _FS_dirhandle */ FS_X_OS_LockDirHandle(); i = 0; while (1) { if (i >= _FS_dir_maxopen) { break; /* No free entry in _FS_dirhandle */ } if (!_FS_dirhandle[i].inuse) { break; /* Free entry found */ } i++; } if (i < _FS_dir_maxopen) { /* Execute open function of the found FSL */ _FS_dirhandle[i].dev_index = idx; handle = (FS__pDevInfo[idx].fs_ptr->fsl_opendir)(s, &_FS_dirhandle[i]); FS_X_OS_UnlockDirHandle(); return handle; } FS_X_OS_UnlockDirHandle(); } return 0; }
FS_DIR *FS_OpenDir( const TCHAR *dirname ) { _FS_PTR * dir; FS_X_OS_LockDirHandle(); dir = (_FS_PTR *)FS_malloc(); if (dir == 0) { FS_X_OS_UnlockDirHandle(); DEBUG_PRINT("FSW_ERROR:OpenDir %s ,but fs malloc fail \r\n",dirname); return 0; /* Device not found */ } dir->error= f_opendir ( &dir->fs.dir, /* Pointer to the blank directory object structure */ dirname /* Pointer to the directory name */ ); if(dir->error!=FR_OK) { FS_free((void *)dir ); dir= 0; } FS_X_OS_UnlockDirHandle(); return (FS_DIR *)dir; }
FS_i32 FS_CloseDir( FS_DIR *dirp ) { if( dirp == 0 ) return -1; FS_X_OS_LockDirHandle(); FS_free((void *)dirp); FS_X_OS_UnlockDirHandle(); return 0; }
FS_i32 FS_Unlink(const TCHAR *Path) { FRESULT res ; FS_X_OS_LockDirHandle(); res=f_unlink(Path); FS_X_OS_UnlockDirHandle(); if(res!=FR_OK) return -1; return 0; }
int FS_RmDir(const char *pDirName) { FS_DIR *dirp; struct FS_DIRENT *direntp; int idx; int i; char *s; /* Check if directory is empty */ dirp = FS_OpenDir(pDirName); if (!dirp) { /* Directory not found */ return -1; } i=0; while (1) { direntp = FS_ReadDir(dirp); i++; if (i >= 4) { break; /* There is more than '..' and '.' */ } if (!direntp) { break; /* There is no more entry in this directory. */ } } FS_CloseDir(dirp); if (i >= 4) { /* There is more than '..' and '.' in the directory, so you must not delete it. */ return -1; } /* Find correct FSL (device:unit:name) */ idx = FS__find_fsl(pDirName, &s); if (idx < 0) { return -1; /* Device not found */ } if (FS__pDevInfo[idx].fs_ptr->fsl_rmdir) { /* Execute the FSL function */ FS_X_OS_LockDirHandle(); i = (FS__pDevInfo[idx].fs_ptr->fsl_rmdir)(s, idx, 0); FS_X_OS_UnlockDirHandle(); return i; } return -1; }
FS_i32 FS_Rename(const TCHAR *OldName,const TCHAR *NewName) { FRESULT res ; FS_X_OS_LockDirHandle(); res =f_rename ( OldName, /* Pointer to old object name */ NewName /* Pointer to new object name */ ); FS_X_OS_UnlockDirHandle(); if(res!=FR_OK) return -1; return 0; }
int FS_MkDir(const char *pDirName) { int idx; int i; char *s; /* Find correct FSL (device:unit:name) */ idx = FS__find_fsl(pDirName, &s); if (idx < 0) { return -1; /* Device not found */ } if (FS__pDevInfo[idx].fs_ptr->fsl_mkdir) { /* Execute the FSL function */ FS_X_OS_LockDirHandle(); i = (FS__pDevInfo[idx].fs_ptr->fsl_mkdir)(s, idx, 1); FS_X_OS_UnlockDirHandle(); return i; } return -1; }
int FS_CloseDir(FS_DIR *pDir) { int i; if (!pDir) { return -1; /* No pointer to a FS_DIR data structure */ } FS_X_OS_LockDirHandle(); if (!pDir->inuse) { /* FS_DIR structure is not in use and cannot be closed */ FS_X_OS_UnlockDirHandle(); return -1; } i = -1; if (pDir->dev_index >= 0) { if (FS__pDevInfo[pDir->dev_index].fs_ptr->fsl_closedir) { /* Execute close function of the corresponding FSL */ i = (FS__pDevInfo[pDir->dev_index].fs_ptr->fsl_closedir)(pDir); } } FS_X_OS_UnlockDirHandle(); return i; }