Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1278317
  • 博文数量: 129
  • 博客积分: 1449
  • 博客等级: 上尉
  • 技术积分: 3048
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-24 18:36
文章分类

全部博文(129)

文章存档

2015年(3)

2014年(20)

2013年(65)

2012年(41)

分类: C/C++

2013-05-13 09:10:51

1. 参考了 Q-sys的V2.35版本, 2个文件为 fswrap.h, fswarp.c
fswrap.h

点击(此处)折叠或打开

  1. #ifndef __FS_WRAP_H__
  2. #define __FS_WRAP_H__

  3. #define FS_size_t unsigned long /* 32 bit unsigned */
  4. #define FS_u32 unsigned long /* 32 bit unsigned */
  5. #define FS_i32 signed long /* 32 bit signed */
  6. #define FS_u16 unsigned short /* 16 bit unsigned */
  7. #define FS_i16 signed short /* 16 bit signed */
  8. #define FS_i8 signed char /* 8 bit signed */
  9. #define FS_u8 unsigned char /* 8 bit unsigned */
  10. //#define NULL             0

  11. typedef void FS_FILE;
  12. typedef void FS_DIR;

  13. typedef struct {
  14.   FS_u32 total_size;
  15.   FS_u32 free_size;
  16. } _DISK_INFO;

  17. /* Global constants*/
  18. #define FS_SEEK_CUR 1
  19. #define FS_SEEK_END 2
  20. #define FS_SEEK_SET 0 /*文件开头*/

  21. #ifndef _OPENDIR_TYPE_
  22. #define _OPENDIR_TYPE_

  23. typedef unsigned int size_t;
  24. typedef short dev_t;
  25. typedef unsigned int ino_t;
  26. typedef unsigned int mode_t;
  27. typedef unsigned short nlink_t;
  28. typedef unsigned long off_t;
  29. typedef unsigned short gid_t;
  30. typedef unsigned short uid_t;
  31. typedef int pid_t;
  32. typedef int time_t;

  33. struct stat {
  34.     mode_t st_mode; /* File mode */
  35.     ino_t st_ino; /* File serial number */
  36.     dev_t st_dev; /* ID of device containing file */
  37.     nlink_t st_nlink; /* Number of hard links */
  38.     uid_t st_uid; /* User ID of the file owner */
  39.     gid_t st_gid; /* Group ID of the file's group */
  40.     off_t st_size; /* File size (regular files only) */
  41.     time_t st_atime; /* Last access time */
  42.     time_t st_mtime; /* Last data modification time */
  43.     time_t st_ctime; /* Last file status change time */
  44. };

  45. #define NAME_MAX 63 /* domain */
  46. struct dirent
  47. {
  48.     char d_name[NAME_MAX+1];
  49.     unsigned int id;    /* use for id file, and only valid when the */
  50.     mode_t st_mode; /* file mode */
  51.     int st_ctime; /* file create time */


  52.                         /* size of d_name is zero */
  53.     /* now we needn't u_name, we save file name as utf8 */
  54.     //char u_name[NAME_MAX+1];

  55. };

  56. #define    _IFMT        0170000    /* type of file */
  57. #define        _IFDIR    0040000    /* directory */
  58. #define        _IFCHR    0020000    /* character special */
  59. #define        _IFBLK    0060000    /* block special */
  60. #define        _IFREG    0100000    /* regular */
  61. #define        _IFLNK    0120000    /* symbolic link */
  62. #define        _IFSOCK    0140000    /* socket */
  63. #define        _IFIFO    0010000    /* fifo */
  64. #define     S_BLKSIZE 1024 /* size of a block */
  65. #define    S_ISUID        0004000    /* set user id on execution */
  66. #define    S_ISGID        0002000    /* set group id on execution */

  67. #define    S_ISBLK(m)    (((m)&_IFMT) == _IFBLK)
  68. #define    S_ISCHR(m)    (((m)&_IFMT) == _IFCHR)
  69. #define    S_ISDIR(m)    (((m)&_IFMT) == _IFDIR)
  70. #define    S_ISFIFO(m)    (((m)&_IFMT) == _IFIFO)
  71. #define    S_ISREG(m)    (((m)&_IFMT) == _IFREG)
  72. #define    S_ISLNK(m)    (((m)&_IFMT) == _IFLNK)
  73. #define    S_ISSOCK(m)    (((m)&_IFMT) == _IFSOCK)

  74. #endif

  75. #ifndef _INC_TCHAR
  76. #define _INC_TCHAR
  77. typedef char TCHAR;
  78. #define _T(x) x
  79. #define _TEXT(x) x
  80. #endif

  81. #if 0
  82. #ifndef FA_READ
  83. #define    FA_READ                0x01
  84. #endif

  85. #ifndef FA_OPEN_EXISTING
  86. #define    FA_OPEN_EXISTING    0x00
  87. #endif

  88. #ifndef FA_WRITE
  89. #define    FA_WRITE            0x02
  90. #endif

  91. #ifndef FA_CREATE_NEW
  92. #define    FA_CREATE_NEW        0x04
  93. #endif

  94. #ifndef FA_CREATE_ALWAYS
  95. #define    FA_CREATE_ALWAYS    0x08
  96. #endif

  97. #ifndef FA_OPEN_ALWAYS
  98. #define    FA_OPEN_ALWAYS        0x10
  99. #endif
  100. #endif

  101. FS_FILE* FS_FOpen(const TCHAR *pFileName, const FS_i32 Mode);
  102. FS_i32 FS_FClose(FS_FILE*pFile);
  103. FS_size_t FS_FWrite(const void *pData, FS_size_t Size, FS_size_t N, FS_FILE *pFile);
  104. FS_size_t FS_FRead(void *pData, FS_size_t Size, FS_size_t N, FS_FILE *pFile);
  105. FS_i32 FS_FSeek(FS_FILE *pFile, FS_i32 Offset, FS_i32 Whence);
  106. FS_i32 FS_FTell(FS_FILE *pFile);

  107. FS_DIR *FS_OpenDir( const TCHAR *dirname );
  108. struct dirent * FS_ReadDir( FS_DIR *dirp);
  109. struct dirent * FS_ReadDir_IDX( FS_DIR *dirp,unsigned short idx);
  110. void FS_RewindDir(FS_DIR *pDir);
  111. FS_i32 FS_CloseDir( FS_DIR *dirp );
  112. FS_i32 FS_Unlink(const TCHAR *Path);
  113. FS_i32 FS_Stat(const TCHAR *path,struct stat *buf);
  114. FS_i32 FS_Rename(const TCHAR *OldName,const TCHAR *NewName);
  115. FS_i32 FS_Init(void);
  116. FS_i32 FS_Exit(void);

  117. FS_i32 GetDiskInfo(const TCHAR* Path,_DISK_INFO* info);
  118. FS_i32 FS_FileCpy(const TCHAR*path1, const TCHAR*path2);        //path1: souce file path2: destination file
  119. FS_i32 FS_GetFileSize(FS_FILE *pFile);


  120. //--- qiushui007, 自己习惯的写法
  121. #define fs_init     FS_Init
  122. #define fs_exit     FS_Exit

  123. #define fs_fopen     FS_FOpen
  124. #define fs_fclose FS_FClose
  125. #define fs_fwrite FS_FWrite
  126. #define fs_fread     FS_FRead
  127. #define fs_fseek     FS_FSeek
  128. #define fs_ftell     FS_FTell

  129. #endif
fswrap.c 

点击(此处)折叠或打开

  1. /************************************************************************
  2.     Project :
  3.     Module : file system api
  4.     File Name : fs_api.c
  5.     Author : dragon_zhang
  6.     Start Date : 2011.4.25
  7.     Language : C
  8.     Target :
  9.     Summary :
  10.     Change Notes : 2011.4.25 V1.0 creat file
  11. **************************************************************************/
  12. #include <string.h>
  13. #include "ff.h"
  14. #include "FsWrap.h"
  15. #include "OS_Wrap.h"

  16. #define DEBUGP //printf

  17. static FATFS FileSystemArea[_VOLUMES];         /* Work area (file system object) for logical drives */
  18. #if _USE_LFN
  19. static WCHAR LenFileName[_MAX_LFN+1];
  20. #endif

  21. typedef struct {
  22.     FRESULT error;
  23.     union {
  24.         FIL file;
  25.         DIR dir;
  26.     }fs;
  27. } _FS_PTR;

  28. //--------------------------------------------------------------------
  29. FS_i32 FS_Init(void)
  30. {
  31. #if 2
  32.     FS_i32 i = _VOLUMES;

  33.     for(i=0;i<_VOLUMES;i++) f_mount(i, &FileSystemArea[i]);

  34. #else
  35.     f_mount(0, &FileSystemArea[0]);
  36. #endif

  37.     return 0;
  38. }

  39. FS_i32 FS_Exit(void) {

  40.   FS_i32 i = _VOLUMES;

  41.   while(i--) f_mount(0, NULL);

  42.   return 0;
  43. }

  44. //---- 其余函数
  45. FS_FILE* FS_FOpen(const TCHAR *pFileName, const FS_i32 Mode)
  46. {
  47.     _FS_PTR * fp;

  48.     fp = (_FS_PTR*)Q_Mallco(sizeof(_FS_PTR));
  49.     memset((void*)fp,0,sizeof(_FS_PTR));

  50.     fp->error = f_open(&fp->fs.file,pFileName,Mode);

  51.     if(fp->error!=FR_OK)
  52.     {
  53.         Q_Free((void *)fp );
  54.         fp = 0;
  55.     }

  56.     return (FS_FILE*)fp;
  57. }

  58. FS_i32 FS_FClose(FS_FILE* pFile)
  59. {
  60.     _FS_PTR * fp = (_FS_PTR *)pFile;

  61.     if (!pFile)    return -1; /* No pointer to a FS_FILE structure */

  62.     fp->error = f_close(&fp->fs.file);

  63.     if(fp->error!=FR_OK) return -1;

  64.     Q_Free((void *)pFile);

  65.     return 0;
  66. }

  67. FS_size_t FS_FWrite(const void *pData, FS_size_t Size, FS_size_t N, FS_FILE *pFile)
  68. {
  69.     UINT i;
  70.     _FS_PTR * fp = (_FS_PTR *)pFile;

  71.      if (!pFile) return 0; /* No pointer to a FS_FILE structure */

  72.     fp->error = f_write(&fp->fs.file,pData,Size*N,&i);

  73.     if(fp->error!=FR_OK) return 0;

  74.     return i;
  75. }

  76. FS_size_t FS_FRead(void *pData, FS_size_t Size, FS_size_t N, FS_FILE *pFile)
  77. {
  78.     UINT i=0;
  79.     _FS_PTR * fp = (_FS_PTR *)pFile;

  80.     if (!pFile) return 0; /* No pointer to a FS_FILE structure */

  81.     fp->error = f_read(&fp->fs.file,pData,Size*N,&i);

  82.     if(fp->error!=FR_OK) return 0;

  83.     return i;
  84. }

  85. FS_i32 FS_FSeek(FS_FILE *pFile, FS_i32 Offset, FS_i32 Whence)
  86. {
  87.     FS_i32 value;
  88.     _FS_PTR * fp = (_FS_PTR *)pFile;

  89.     if (!pFile) return -1;

  90.     if(FS_SEEK_SET==Whence) value = 0;
  91.     else if(FS_SEEK_CUR==Whence)    value = fp->fs.file.fptr;
  92.     else if(FS_SEEK_END==Whence)    value = fp->fs.file.fsize;
  93.     else    return -1;

  94.     fp->error = f_lseek(&fp->fs.file,value+Offset);

  95.     if(fp->error!=FR_OK) return -1;

  96.     return 0;
  97. }


  98. FS_i32 FS_FTell(FS_FILE *pFile)
  99. {
  100.     _FS_PTR * fp = (_FS_PTR *)pFile;

  101.     if (!pFile) return -1;

  102.     return fp->fs.file.fptr;
  103. }

  104. FS_DIR *FS_OpenDir( const TCHAR *dirname )
  105. {
  106.     _FS_PTR * dir;

  107.     dir = (_FS_PTR *)Q_Mallco(sizeof(_FS_PTR));
  108.     memset((void*)dir,0,sizeof(_FS_PTR));

  109.     dir->error= f_opendir(&dir->fs.dir,dirname);

  110.     if(dir->error!=FR_OK)
  111.     {
  112.         Q_Free((void *)dir );
  113.         dir= 0;
  114.     }

  115.     return (FS_DIR *)dir;
  116. }


  117. #if _MAX_LFN > (NAME_MAX/2)
  118. #error " _MAX_LFN must less than NAME_MAX/2"
  119. #endif

  120. struct dirent * FS_ReadDir( FS_DIR *dirp)
  121. {
  122.     _FS_PTR * dir = (_FS_PTR *) dirp;

  123.     FILINFO FileInfo;
  124.     static struct dirent ent;
  125.     char *fn;
  126. #if _USE_LFN
  127.     FileInfo.lfname = (TCHAR*)LenFileName;
  128.     FileInfo.lfsize = sizeof(LenFileName);
  129. #endif

  130.     ent.d_name[0]=0;

  131.     if (dirp == 0) {
  132.           return 0; /* Device not found */
  133.     }

  134.      dir->error = f_readdir (
  135.      &dir->fs.dir,     /* Pointer to the open directory object */
  136.      &FileInfo /* Pointer to the file information structure */
  137.     );

  138.    if(dir->error!=FR_OK)
  139.    {
  140.      ent.d_name[0]=0;
  141.      ent.st_mode=0;
  142.      ent.id = 0;
  143.      ent.st_ctime = 0;

  144.      return 0;
  145.    }

  146. #if _USE_LFN
  147.    fn = (char *)FileInfo.lfname;
  148. #else
  149.    fn = (char *)FileInfo.fname;
  150. #endif

  151.    if(FileInfo.fname[0] == 0) //end
  152.      ent.d_name[0]=0;
  153.    else
  154.         strcpy(ent.d_name,fn);

  155.    ent.st_mode = (FileInfo.fattrib & AM_DIR)?_IFDIR:0;
  156.    ent.id = FileInfo.fsize;
  157.    ent.st_ctime = FileInfo.ftime|(FileInfo.fdate<<16);

  158.    return &ent;
  159. }

  160. struct dirent * FS_ReadDir_IDX( FS_DIR *dirp,unsigned short idx)
  161. {
  162.     _FS_PTR * dir = (_FS_PTR *) dirp;

  163.     FILINFO FileInfo;
  164.     static struct dirent ent;
  165.     char *fn;
  166. #if _USE_LFN
  167.     FileInfo.lfname = (TCHAR*)LenFileName;
  168.     FileInfo.lfsize = sizeof(LenFileName);
  169. #endif

  170.     ent.d_name[0]=0;

  171.     if (dirp == 0) {
  172.           return 0; /* Device not found */
  173.     }

  174.     dir->error = f_readdir (
  175.      &dir->fs.dir, /* Pointer to the open directory object */
  176.      0 /* Pointer to the file information structure */
  177.      );

  178.     for(;idx;idx--)
  179.         f_readdir_noinfo(&dir->fs.dir,&FileInfo);

  180.      dir->error = f_readdir (
  181.          &dir->fs.dir,     /* Pointer to the open directory object */
  182.          &FileInfo /* Pointer to the file information structure */
  183.         );

  184.    if(dir->error!=FR_OK)
  185.    {
  186.      ent.d_name[0]=0;
  187.      ent.st_mode=0;
  188.      ent.id = 0;
  189.      ent.st_ctime = 0;

  190.      return 0;
  191.    }

  192. #if _USE_LFN
  193.    fn = (char *)FileInfo.lfname;
  194. #else
  195.    fn = (char *)FileInfo.fname;
  196. #endif

  197.    if(FileInfo.fname[0] == 0) //end
  198.      ent.d_name[0]=0;
  199.    else
  200.        strcpy(ent.d_name,fn);

  201.    ent.st_mode = (FileInfo.fattrib & AM_DIR)?_IFDIR:0;
  202.    ent.id = FileInfo.fsize;
  203.    ent.st_ctime = FileInfo.ftime|(FileInfo.fdate<<16);

  204.    return &ent;
  205. }

  206. void FS_RewindDir(FS_DIR *dirp)
  207. {
  208.     _FS_PTR * dir = (_FS_PTR *) dirp;

  209.     if (!dirp) return;

  210.     dir->fs.dir.index = 0;
  211. }

  212. FS_i32 FS_CloseDir( FS_DIR *dirp )
  213. {
  214.   if(dirp == 0) return -1;

  215.   Q_Free((void *)dirp);

  216.     return 0;
  217. }

  218. FS_i32 FS_Unlink(const TCHAR *Path)
  219. {
  220.      if(f_unlink(Path)!=FR_OK) return -1;

  221.      return 0;
  222. }

  223. FS_i32 FS_GetFileSize(FS_FILE *pFile)
  224. {
  225.     _FS_PTR * fp = (_FS_PTR *)pFile;

  226.     return fp->fs.file.fsize;
  227. }

  228. FS_i32 FS_Stat(const TCHAR *path,struct stat *buf)
  229. {
  230.     FRESULT res;
  231.     FILINFO stat;
  232. #if _USE_LFN
  233.     stat.lfname = (TCHAR*)LenFileName;
  234.     stat.lfsize = sizeof(LenFileName);
  235. #endif

  236.     res=f_stat(path,&stat);

  237.      if(res!=FR_OK)
  238.     {
  239.         buf->st_size = 0;
  240.         buf->st_mode = 0;
  241.         buf->st_mtime = 0;
  242.       return -1;
  243.     }

  244.      buf->st_size = stat.fsize;
  245.     buf->st_mode = (stat.fattrib & AM_DIR)?_IFDIR:0;
  246.     buf->st_mtime = stat.ftime|(stat.fdate<<16);

  247.     return 0;
  248. }

  249. FS_i32 FS_Rename(const TCHAR *OldName,const TCHAR *NewName)
  250. {
  251.     FRESULT res ;

  252.     res =f_rename (OldName,NewName);

  253.     if(res!=FR_OK) return -1;

  254.     return 0;
  255. }

  256. #define COPY_FILE_BUFFER    512
  257. FS_i32 FS_FileCpy(const TCHAR*path1, const TCHAR*path2)        //path1: souce file path2: destination file
  258. {
  259.     FS_FILE *src;
  260.     FS_FILE * dst;
  261.     FS_i32 read_size,write_size;
  262.     FS_i32 src_size, dst_size;
  263.     struct stat buf;
  264.     _DISK_INFO info;
  265.     FS_i8 *buffer;

  266.     if( !strcmp((const char *)path1, (const char *)path2) )
  267.     {
  268.         DEBUGP("ERROR:can not copy a file to itselfrn");
  269.         return 0;
  270.     }

  271.     if( -1 == FS_Stat( path1, &buf ) ) return 0;

  272.     src_size = buf.st_size;

  273.     if(GetDiskInfo(path2,&info)==-1)
  274.     {
  275.         DEBUGP("ERROR:getdiskinfo errrn");
  276.         return 0;
  277.     }

  278.     if(src_size > info.free_size)
  279.     {
  280.         DEBUGP("there is no enough space on the flash!nr");
  281.         return 0;
  282.     }

  283.     src = FS_FOpen(path1, FA_READ|FA_OPEN_EXISTING);
  284.     if(0 == src)
  285.     {
  286.         DEBUGP("ERROR:cannot open the source filern");
  287.         return 0;
  288.     }

  289.     dst = FS_FOpen(path2, FA_CREATE_ALWAYS|FA_WRITE);
  290.     if(0 == dst)
  291.     {
  292.         DEBUGP("ERROR:cannot create the distance filern");
  293.         FS_FClose(src);
  294.         return 0;
  295.     }

  296.     buffer=Q_Mallco(COPY_FILE_BUFFER);

  297.     do{
  298.         read_size = FS_FRead(buffer, COPY_FILE_BUFFER,1,src);
  299.         write_size = FS_FWrite(buffer, read_size,1,dst);

  300.         if(write_size < read_size)
  301.         {
  302.             DEBUGP("ERROR:file write errorrn");
  303.             Q_Free(buffer);
  304.             goto CP_FILE_ERROR;
  305.         }
  306.     }while(read_size == COPY_FILE_BUFFER);

  307.     Q_Free(buffer);
  308.     FS_FClose(src);
  309.     FS_FClose(dst);

  310.     if( -1 == FS_Stat( path2, &buf ) ) return 0;

  311.     dst_size = buf.st_size;

  312.     if(dst_size < src_size)
  313.     {
  314.         DEBUGP("there is an unkown flash operation during the copyfile!nr");
  315.         FS_Unlink(path2);
  316.         return 0;
  317.     }

  318.     return 1;

  319. CP_FILE_ERROR:
  320.     FS_FClose(src);
  321.     FS_FClose(dst);
  322.     return 0;
  323. }

  324. FS_i32 GetDiskInfo(const TCHAR* Path,_DISK_INFO* info)
  325. {
  326.   FATFS *fs;
  327.   DWORD fre_clust, tot_sect,fre_sect;
  328.     FRESULT res;

  329.   /* Get volume information and free clusters of drive 1 */
  330.   res = f_getfree(Path, &fre_clust, &fs);
  331.   if (res)
  332.   {
  333.       info->total_size = 0;
  334.     info->free_size = 0;
  335.     return -1;
  336.   }
  337.   /* Get total sectors and free sectors */
  338.   tot_sect = (fs->n_fatent - 2) * fs->csize;
  339.   fre_sect = fre_clust * fs->csize;

  340.     info->total_size = tot_sect *512;
  341.     info->free_size = fre_sect *512;

  342.     return 0;
  343. }

2. 应用例程如下

点击(此处)折叠或打开

  1. u8 readfile(char *filename)
  2. {
  3. #if HAVE_FSWRAP
  4.     FS_FILE *fp;

  5. #else
  6.     FATFS fs;         // Work area (file system object) for logical drive
  7.     FIL fsrc, fdst; // file objects
  8.     FRESULT res;     // FatFs function common result code
  9.     UINT br, bw;     // File R/W count
  10. #endif

  11.     u8 bytelen = 38, readlen, ty;
  12.     u8 buffer[50];
  13.     static u16 ustimes = 1;

  14.     memset(buffer, 0x00, sizeof(buffer));

  15. #if HAVE_FSWRAP
  16.     fs_init();

  17.     fp = fs_fopen(filename, FA_OPEN_EXISTING | FA_READ);
  18.     if (fp == 0) {
  19.         display_status((char *)buffer);
  20.         fs_exit();
  21.         return(-1);
  22.     }
  23.     else {
  24.         DEBUGP("fopen OKrn!");
  25.         readlen = fs_fread(buffer, sizeof(char), bytelen, fp);
  26.         if (readlen != bytelen) {
  27.             display_status((char *)buffer);
  28.             fs_exit();
  29.             return(-2);
  30.         }
  31.         fs_fclose(fp);
  32.     }
  33.     fs_exit();

  34. #else
  35.     f_mount(0, &fs);

  36.   res = f_open(&fsrc, filename, FA_OPEN_EXISTING | FA_READ);
  37.   if (res != FR_OK) {
  38.       sprintf((char *)buffer, "f_open Error: %d", res);
  39.       display_status((char *)buffer);

  40.       f_mount(0, NULL);
  41.       return(res);
  42.   }

  43.     f_lseek(&fsrc, 0);
  44.     res = f_read(&fsrc, buffer, bytelen, &br);
  45.     //if (res != FR_OK) {
  46.     if (br != bytelen) {
  47.         sprintf((char *)buffer, "f_read Error: %d", res);
  48.       display_status((char *)buffer);

  49.       f_mount(0, NULL);
  50.         return(res);
  51.     }
  52.     //ty = fsrc.fsize;
  53.     //f_lseek(&fsrc, ty);
  54.     //res = f_write(&fsrc, buffer, ByteLen, &bw);

  55.     f_close(&fsrc);
  56.     f_mount(0, NULL);
  57. #endif    

  58.     return SD_OK;
  59. }
3. 移植参考
ff.c: 主要为底层协议, 配置文件为 ffconf.h,
diskio.c: 数据读取的驱动代码, 中间层, 为ff.c 服务. 至少完成disk_read和disk_write
sdcard.c: 底层的硬件驱动
每次读写时都调用 f_mount 可以支持热插拔. 带目录如: theme/f/common/btn/backp.bmp

//--- FatFs module application interface,
FRESULT f_mount (BYTE, FATFS*); //加载文件系统,BYTE参数是ID,后一个是文件系统定义。
FRESULT f_open (FIL*, const XCHAR*, BYTE); //打开文件,第一个参数是文件信息结构,第二个参数是文件名,第三是文件打开模式
FRESULT f_read (FIL*, void*, UINT, UINT*); //文件读取函数,参数1为文件对象(文件打开函数中得到),参数2为文件读取缓冲区,参数3为读取的字节数,参数4意义不清晰,等读到源代码就清楚了。
FRESULT f_write (FIL*, const void*, UINT, UINT*);//写文件,参数跟读差不多
FRESULT f_lseek (FIL*, DWORD); //移动文件的读写指针,参数2应该是移动的数目。
FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const XCHAR*); //打开目录,返回目录对象
FRESULT f_readdir (DIR*, FILINFO*); //读取目录,获得文件信息
FRESULT f_stat (const XCHAR*, FILINFO*); /* Get file status */
FRESULT f_getfree (const XCHAR*, 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 XCHAR*); //删除目录中的一个文件
FRESULT f_mkdir (const XCHAR*); /* Create a new directory */
FRESULT f_chmod (const XCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */
FRESULT f_utime (const XCHAR*, const FILINFO*); /* Change timestamp of the file/dir */
FRESULT f_rename (const XCHAR*, const XCHAR*); /* Rename/Move a file or directory */
FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ 这个函数还要提供一个回调函数。
FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */
FRESULT f_chdir (const XCHAR*); /* Change current directory */改变当前目录
FRESULT f_chdrive (BYTE); /* Change current drive */



 

阅读(2470) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~