?login_element?

Subversion Repositories NedoOS

Rev

Rev 641 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*---------------------------------------------------------------------------/
  2. /  FatFs - FAT file system module include file  R0.08b    (C)ChaN, 2011
  3. /----------------------------------------------------------------------------/
  4. / FatFs module is a generic FAT file system module for small embedded systems.
  5. / This is a free software that opened for education, research and commercial
  6. / developments under license policy of following trems.
  7. /
  8. /  Copyright (C) 2011, ChaN, all right reserved.
  9. /
  10. / * The FatFs module is a free software and there is NO WARRANTY.
  11. / * No restriction on use. You can use, modify and redistribute it for
  12. /   personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
  13. / * Redistributions of source code must retain the above copyright notice.
  14. /
  15. /----------------------------------------------------------------------------*/
  16.  
  17. #ifndef _FATFS
  18. #define _FATFS  8237    /* Revision ID */
  19.  
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23.  
  24. #include "integer.h"    /* Basic integer types */
  25. #include "ffconf.h"             /* FatFs configuration options */
  26.  
  27. #if _FATFS != _FFCONF
  28. #error Wrong configuration file (ffconf.h).
  29. #endif
  30.  
  31.  
  32.  
  33. /* Definitions of volume management */
  34.  
  35. //#if _MULTI_PARTITION          /* Multiple partition configuration */
  36. //#define LD2PD(vol) (VolToPart[vol].pd)        /* Get physical drive# */
  37. //#define LD2PT(vol) (VolToPart[vol].pt)        /* Get partition# */
  38. //typedef struct {
  39. //      BYTE pd;        /* Physical drive# */
  40. //      BYTE pt;        /* Partition # (0-3) */
  41. //} PARTITION;
  42. //extern PARTITION VolToPart[2];        /* Volume - Physical location resolution table */
  43.  
  44. //#else                                         /* Single partition configuration */
  45. //#define LD2PD(vol) (vol)      /* Logical drive# is bound to the same physical drive# */
  46. //#define LD2PT(vol) 0          /* Always mounts the 1st partition */
  47.  
  48. //#endif
  49.  
  50.  
  51.  
  52. /* Type of path name strings on FatFs API */
  53.  
  54. #if _LFN_UNICODE                        /* Unicode string */
  55. #if !_USE_LFN
  56. #error _LFN_UNICODE must be 0 in non-LFN cfg.
  57. #endif
  58. #ifndef _INC_TCHAR
  59. typedef WCHAR TCHAR;
  60. #define _T(x) L ## x
  61. #define _TEXT(x) L ## x
  62. #endif
  63.  
  64. #else                                           /* ANSI/OEM string */
  65. #ifndef _INC_TCHAR
  66. typedef char TCHAR;
  67. #define _T(x) x
  68. #define _TEXT(x) x
  69. #endif
  70.  
  71. #endif
  72.  
  73.  
  74.  
  75. /* File system object structure (FATFS) */
  76.  
  77. typedef struct {
  78.         BYTE    fs_type;                /* FAT sub-type (0:Not mounted) */
  79.         BYTE    drv;                    /* Physical drive number */
  80.         BYTE    part;           /* Partition # (0-3) */
  81.         BYTE    csize;                  /* Sectors per cluster (1,2,4...128) */
  82.         BYTE    n_fats;                 /* Number of FAT copies (1,2) */
  83.         BYTE    wflag;                  /* win[] dirty flag (1:must be written back) */
  84.         BYTE    fsi_flag;               /* fsinfo dirty flag (1:must be written back) */
  85.         WORD    id;                             /* File system mount ID */
  86.         WORD    n_rootdir;              /* Number of root directory entries (FAT12/16) */
  87. #if _MAX_SS != 512
  88.         WORD    ssize;                  /* Bytes per sector (512,1024,2048,4096) */
  89. #endif
  90. #if _FS_REENTRANT
  91.         _SYNC_t sobj;                   /* Identifier of sync object */
  92. #endif
  93. #if !_FS_READONLY
  94.         DWORD   last_clust;             /* Last allocated cluster */
  95.         DWORD   free_clust;             /* Number of free clusters */
  96.         DWORD   fsi_sector;             /* fsinfo sector (FAT32) */
  97. #endif
  98. #if _FS_RPATH
  99.         DWORD   cdir;                   /* Current directory start cluster (0:root) */
  100. #endif
  101.         DWORD   n_fatent;               /* Number of FAT entries (= number of clusters + 2) */
  102.         DWORD   fsize;                  /* Sectors per FAT */
  103.         DWORD   fatbase;                /* FAT start sector */
  104.         DWORD   dirbase;                /* Root directory start sector (FAT32:Cluster#) */
  105.         DWORD   database;               /* Data start sector */
  106.         DWORD   winsect;                /* Current sector appearing in the win[] */
  107.         BYTE    win[_MAX_SS];   /* Disk access window for Directory, FAT (and Data on tiny cfg) */
  108. } FATFS;
  109.  
  110.  
  111.  
  112. /* File object structure (FIL) */
  113.  
  114. typedef struct {
  115.         FATFS*  fs;                             /* Pointer to the owner file system object */
  116.         WORD    id;                             /* Owner file system mount ID */
  117.         BYTE    flag;                   /* File status flags */
  118.         BYTE    pad1;
  119.         DWORD   fptr;                   /* File read/write pointer (0 on file open) */
  120.         DWORD   fsize;                  /* File size */
  121.         DWORD   sclust;                 /* File start cluster (0 when fsize==0) */
  122.         DWORD   clust;                  /* Current cluster */
  123.         DWORD   dsect;                  /* Current data sector */
  124. #if !_FS_READONLY
  125.         DWORD   dir_sect;               /* Sector containing the directory entry */
  126.         BYTE*   dir_ptr;                /* Ponter to the directory entry in the window */
  127. #endif
  128. #if _USE_FASTSEEK
  129.         DWORD*  cltbl;                  /* Pointer to the cluster link map table (null on file open) */
  130. #endif
  131. #if _FS_SHARE
  132.         UINT    lockid;                 /* File lock ID (index of file semaphore table) */
  133. #endif
  134. #if !_FS_TINY
  135.         BYTE    buf[_MAX_SS];   /* File data read/write buffer */
  136. #endif
  137. } FIL;
  138.  
  139.  
  140.  
  141. /* Directory object structure (DIR) */
  142.  
  143. typedef struct {
  144.         FATFS*  fs;                             /* Pointer to the owner file system object */
  145.         WORD    id;                             /* Owner file system mount ID */
  146.         WORD    index;                  /* Current read/write index number */
  147.         DWORD   sclust;                 /* Table start cluster (0:Root dir) */
  148.         DWORD   clust;                  /* Current cluster */
  149.         DWORD   sect;                   /* Current sector */
  150.         BYTE*   dir;                    /* Pointer to the current SFN entry in the win[] */
  151.         BYTE*   fn;                             /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
  152. #if _USE_LFN
  153.         WCHAR*  lfn;                    /* Pointer to the LFN working buffer */
  154.         WORD    lfn_idx;                /* Last matched LFN index number (0xFFFF:No LFN) */
  155. #endif
  156. } DIR;
  157.  
  158.  
  159.  
  160. /* File status structure (FILINFO) */
  161.  
  162. typedef struct {
  163.         DWORD   fsize;                  /* File size */
  164.         WORD    fdate;                  /* Last modified date */
  165.         WORD    ftime;                  /* Last modified time */
  166.         BYTE    fattrib;                /* Attribute */
  167.         TCHAR   fname[13];              /* Short file name (8.3 format) */
  168. #if _USE_LFN
  169.         TCHAR   lfname[64];                     /* Pointer to the LFN buffer */
  170. //      TCHAR*  lfname;                 /* Pointer to the LFN buffer */
  171. //      UINT    lfsize;                 /* Size of LFN buffer in TCHAR */
  172. #endif
  173. } FILINFO;
  174.  
  175.  
  176.  
  177. /* File function return code (FRESULT) */
  178.  
  179. typedef enum {
  180.         FR_OK = 0,                              /* (0) Succeeded */
  181.         FR_DISK_ERR,                    /* (1) A hard error occured in the low level disk I/O layer */
  182.         FR_INT_ERR,                             /* (2) Assertion failed */
  183.         FR_NOT_READY,                   /* (3) The physical drive cannot work */
  184.         FR_NO_FILE,                             /* (4) Could not find the file */
  185.         FR_NO_PATH,                             /* (5) Could not find the path */
  186.         FR_INVALID_NAME,                /* (6) The path name format is invalid */
  187.         FR_DENIED,                              /* (7) Acces denied due to prohibited access or directory full */
  188.         FR_EXIST,                               /* (8) Acces denied due to prohibited access */
  189.         FR_INVALID_OBJECT,              /* (9) The file/directory object is invalid */
  190.         FR_WRITE_PROTECTED,             /* (10) The physical drive is write protected */
  191.         FR_INVALID_DRIVE,               /* (11) The logical drive number is invalid */
  192.         FR_NOT_ENABLED,                 /* (12) The volume has no work area */
  193.         FR_NO_FILESYSTEM,               /* (13) There is no valid FAT volume on the physical drive */
  194.         FR_MKFS_ABORTED,                /* (14) The f_mkfs() aborted due to any parameter error */
  195.         FR_TIMEOUT,                             /* (15) Could not get a grant to access the volume within defined period */
  196.         FR_LOCKED,                              /* (16) The operation is rejected according to the file shareing policy */
  197.         FR_NOT_ENOUGH_CORE,             /* (17) LFN working buffer could not be allocated */
  198.         FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
  199.         FR_NO_MBR                               /* (19) Without MBR */
  200. } FRESULT;
  201.  
  202.  
  203.  
  204. /*--------------------------------------------------------------*/
  205. /* FatFs module application interface                           */
  206.  
  207. FRESULT f_mount (void); //BYTE, FATFS*);                        /* Mount/Unmount a logical drive */
  208. FRESULT f_open (FIL*, const TCHAR*, BYTE);                      /* Open or create a file */
  209. FRESULT f_read (FIL*, void*, UINT, UINT*);                      /* Read data from a file */
  210. FRESULT f_lseek (FIL*, DWORD);                                          /* Move file pointer of a file object */
  211. FRESULT f_close (FIL*);                                                         /* Close an open file object */
  212. FRESULT f_opendir (DIR*, const TCHAR*);                         /* Open an existing directory */
  213. FRESULT f_readdir (DIR*, FILINFO*);                                     /* Read a directory item */
  214. FRESULT f_stat (const TCHAR*, FILINFO*);                        /* Get file status */
  215. FRESULT f_write (FIL*, const void*, UINT, UINT*);       /* Write data to a file */
  216. FRESULT f_getfree (/*const TCHAR*,*/ DWORD*, FATFS**);  /* Get number of free clusters on the drive */
  217. FRESULT f_truncate (FIL*);                                                      /* Truncate file */
  218. FRESULT f_sync (FIL*);                                                          /* Flush cached data of a writing file */
  219. FRESULT f_unlink (const TCHAR*);                                        /* Delete an existing file or directory */
  220. FRESULT f_mkdir (const TCHAR*);                                         /* Create a new directory */
  221. FRESULT f_chmod (const TCHAR*, BYTE, BYTE);                     /* Change attriburte of the file/dir */
  222. //FRESULT f_utime (const TCHAR*, const FILINFO*);       /* Change timestamp of the file/dir */
  223. FRESULT f_utime (const TCHAR*, WORD fdate, WORD ftime);         /* Change timestamp of the file/dir */
  224.  FRESULT f_getutime (const TCHAR*, WORD* ftimedate);            /* Get timestamp of the file/dir */
  225. FRESULT f_rename (const TCHAR*, const TCHAR*);          /* Rename/Move a file or directory */
  226. FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*);       /* Forward data to the stream */
  227. FRESULT f_mkfs (BYTE, BYTE, UINT);                                      /* Create a file system on the drive */
  228. FRESULT f_chdrive (BYTE);                                                       /* Change current drive */
  229. FRESULT f_chdir (const TCHAR*);                                         /* Change current directory */
  230. FRESULT f_getcwd (TCHAR*, UINT);                                        /* Get current directory */
  231. int f_putc (TCHAR, FIL*);                                                       /* Put a character to the file */
  232. int f_puts (const TCHAR*, FIL*);                                        /* Put a string to the file */
  233. int f_printf (FIL*, const TCHAR*, ...);                         /* Put a formatted string to the file */
  234. TCHAR* f_gets (TCHAR*, int, FIL*);                                      /* Get a string from the file */
  235.  
  236. #ifndef EOF
  237. #define EOF (-1)
  238. #endif
  239.  
  240. #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
  241. #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
  242. #define f_tell(fp) ((fp)->fptr)
  243. #define f_size(fp) ((fp)->fsize)
  244.  
  245.  
  246.  
  247.  
  248. /*--------------------------------------------------------------*/
  249. /* Additional user defined functions                            */
  250.  
  251. /* RTC function */
  252. #if !_FS_READONLY
  253. //extern void get_fattime (DWORD*);
  254. #define get_fattime drv_calls.RTC
  255. #endif
  256.  
  257. /* Unicode support functions */
  258. #if _USE_LFN                                            /* Unicode - OEM code conversion */
  259. WCHAR ff_convert (WCHAR, UINT);         /* OEM-Unicode bidirectional conversion */
  260. WCHAR ff_wtoupper (WCHAR);                      /* Unicode upper-case conversion */
  261. #if _USE_LFN == 3                                       /* Memory functions */
  262. void* ff_memalloc (UINT);                       /* Allocate memory block */
  263. void ff_memfree (void*);                        /* Free memory block */
  264. #endif
  265. #endif
  266.  
  267. /* Sync functions */
  268. #if _FS_REENTRANT
  269. int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */
  270. int ff_req_grant (_SYNC_t);                     /* Lock sync object */
  271. void ff_rel_grant (_SYNC_t);            /* Unlock sync object */
  272. int ff_del_syncobj (_SYNC_t);           /* Delete a sync object */
  273. #endif
  274.  
  275.  
  276.  
  277.  
  278. /*--------------------------------------------------------------*/
  279. /* Flags and offset address                                     */
  280.  
  281.  
  282. /* File access control and file status flags (FIL.flag) */
  283.  
  284. #define FA_READ                         0x01
  285. #define FA_OPEN_EXISTING        0x00
  286. #define FA__ERROR                       0x80
  287.  
  288. #if !_FS_READONLY
  289. #define FA_WRITE                        0x02
  290. #define FA_CREATE_NEW           0x04
  291. #define FA_CREATE_ALWAYS        0x08
  292. #define FA_OPEN_ALWAYS          0x10
  293. #define FA__WRITTEN                     0x20
  294. #define FA__DIRTY                       0x40
  295. #endif
  296.  
  297.  
  298. /* FAT sub type (FATFS.fs_type) */
  299.  
  300. #define FS_FAT12        1
  301. #define FS_FAT16        2
  302. #define FS_FAT32        3
  303.  
  304.  
  305. /* File attribute bits for directory entry */
  306.  
  307. #define AM_RDO  0x01    /* Read only */
  308. #define AM_HID  0x02    /* Hidden */
  309. #define AM_SYS  0x04    /* System */
  310. #define AM_VOL  0x08    /* Volume label */
  311. #define AM_LFN  0x0F    /* LFN entry */
  312. #define AM_DIR  0x10    /* Directory */
  313. #define AM_ARC  0x20    /* Archive */
  314. #define AM_MASK 0x3F    /* Mask of defined bits */
  315.  
  316.  
  317. /* Fast seek function */
  318. #define CREATE_LINKMAP  0xFFFFFFFF
  319.  
  320.  
  321.  
  322. /*--------------------------------*/
  323. /* Multi-byte word access macros  */
  324. #define LD_WORD(ptr)            (WORD)(*(WORD*)(BYTE*)(ptr))
  325. #define LD_DWORD(ptr)           (DWORD)(*(DWORD*)(BYTE*)(ptr))
  326. #define ST_WORD(ptr,val)        *(WORD*)(BYTE*)(ptr)=(WORD)(val)
  327. #define ST_DWORD(ptr,val)       *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
  328.  
  329. #ifdef __cplusplus
  330. }
  331. #endif
  332.  
  333. #endif /* _FATFS */
  334.