ff.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*---------------------------------------------------------------------------/
  2. / FatFs - FAT file system module include file R0.07c (C)ChaN, 2009
  3. /----------------------------------------------------------------------------/
  4. / FatFs module is an open source software to implement FAT file system to
  5. / small embedded systems. This is a free software and is opened for education,
  6. / research and commercial developments under license policy of following trems.
  7. /
  8. / Copyright (C) 2009, 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. #include "integer.h"
  16. /*---------------------------------------------------------------------------/
  17. / FatFs Configuration Options
  18. /
  19. / CAUTION! Do not forget to make clean the project after any changes to
  20. / the configuration options.
  21. /
  22. /----------------------------------------------------------------------------*/
  23. #ifndef _FATFS
  24. #define _FATFS 0x007C
  25. #ifdef RT_DFS_ELM_WORD_ACCESS
  26. #define _WORD_ACCESS 1
  27. #else
  28. #define _WORD_ACCESS 0
  29. #endif
  30. /* The _WORD_ACCESS option defines which access method is used to the word
  31. / data in the FAT structure.
  32. /
  33. / 0: Byte-by-byte access. Always compatible with all platforms.
  34. / 1: Word access. Do not choose this unless following condition is met.
  35. /
  36. / When the byte order on the memory is big-endian or address miss-aligned
  37. / word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
  38. / If it is not the case, the value can also be set to 1 to improve the
  39. / performance and code efficiency. */
  40. #define _FS_READONLY 0
  41. /* Setting _FS_READONLY to 1 defines read only configuration. This removes
  42. / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
  43. / f_truncate and useless f_getfree. */
  44. #define _FS_MINIMIZE 0
  45. /* The _FS_MINIMIZE option defines minimization level to remove some functions.
  46. /
  47. / 0: Full function.
  48. / 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename
  49. / are removed.
  50. / 2: f_opendir and f_readdir are removed in addition to level 1.
  51. / 3: f_lseek is removed in addition to level 2. */
  52. #define _FS_TINY 0
  53. /* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
  54. / object instead of the sector buffer in the individual file object for file
  55. / data transfer. This reduces memory consumption 512 bytes each file object. */
  56. #define _USE_STRFUNC 0
  57. /* To enable string functions, set _USE_STRFUNC to 1 or 2. */
  58. #define _USE_MKFS 0
  59. /* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
  60. #define _USE_FORWARD 0
  61. /* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
  62. #define _CODE_PAGE 936
  63. /* The _CODE_PAGE specifies the OEM code page to be used on the target system.
  64. /
  65. / 932 - Japanese Shift-JIS (DBCS, OEM, Windows)
  66. / 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
  67. / 949 - Korean (DBCS, OEM, Windows)
  68. / 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
  69. / 1250 - Central Europe (Windows)
  70. / 1251 - Cyrillic (Windows)
  71. / 1252 - Latin 1 (Windows)
  72. / 1253 - Greek (Windows)
  73. / 1254 - Turkish (Windows)
  74. / 1255 - Hebrew (Windows)
  75. / 1256 - Arabic (Windows)
  76. / 1257 - Baltic (Windows)
  77. / 1258 - Vietnam (OEM, Windows)
  78. / 437 - U.S. (OEM)
  79. / 720 - Arabic (OEM)
  80. / 737 - Greek (OEM)
  81. / 775 - Baltic (OEM)
  82. / 850 - Multilingual Latin 1 (OEM)
  83. / 858 - Multilingual Latin 1 + Euro (OEM)
  84. / 852 - Latin 2 (OEM)
  85. / 855 - Cyrillic (OEM)
  86. / 866 - Russian (OEM)
  87. / 857 - Turkish (OEM)
  88. / 862 - Hebrew (OEM)
  89. / 874 - Thai (OEM, Windows)
  90. / 1 - ASCII (Valid for only non LFN cfg.)
  91. */
  92. #define _USE_LFN 0
  93. #define _MAX_LFN 255 /* Maximum LFN length to handle (max:255) */
  94. /* The _USE_LFN option switches the LFN support.
  95. /
  96. / 0: Disable LFN.
  97. / 1: Enable LFN with static working buffer on the bss. NOT REENTRANT.
  98. / 2: Enable LFN with dynamic working buffer on the caller's STACK.
  99. /
  100. / The working buffer occupies (_MAX_LFN + 1) * 2 bytes. When enable LFN,
  101. / a Unicode handling functions ff_convert() and ff_wtoupper() must be added
  102. / to the project. */
  103. #define _FS_RPATH 0
  104. /* When _FS_RPATH is set to 1, relative path feature is enabled and f_chdir,
  105. / f_chdrive function are available.
  106. / Note that output of the f_readdir fnction is affected by this option. */
  107. #define _FS_REENTRANT 0
  108. #define _TIMEOUT 1000 /* Timeout period in unit of time ticks of the OS */
  109. #define _SYNC_t HANDLE /* Type of sync object used on the OS. e.g. HANDLE, OS_EVENT*, ID and etc.. */
  110. /* To make the FatFs module re-entrant, set _FS_REENTRANT to 1 and add user
  111. / provided synchronization handlers, ff_req_grant, ff_rel_grant, ff_del_syncobj
  112. / and ff_cre_syncobj function to the project. */
  113. #define _DRIVES 1
  114. /* Number of volumes (logical drives) to be used. */
  115. #define _MAX_SS 512
  116. /* Maximum sector size to be handled. (512/1024/2048/4096) */
  117. /* Usually set 512 for memory card and hard disk but 1024 for floppy disk, 2048 for MO disk */
  118. /* When _MAX_SS > 512, GET_SECTOR_SIZE must be implememted to disk_ioctl() */
  119. #define _MULTI_PARTITION 0
  120. /* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical
  121. / drive number and can mount only first primaly partition. When it is set to 1,
  122. / each volume is tied to the partitions listed in Drives[]. */
  123. /* End of configuration options. Do not change followings without care. */
  124. /*--------------------------------------------------------------------------*/
  125. /* DBCS code ranges and SBCS extend char conversion table */
  126. #if _CODE_PAGE == 932 /* Japanese Shift-JIS */
  127. #define _DF1S 0x81 /* DBC 1st byte range 1 start */
  128. #define _DF1E 0x9F /* DBC 1st byte range 1 end */
  129. #define _DF2S 0xE0 /* DBC 1st byte range 2 start */
  130. #define _DF2E 0xFC /* DBC 1st byte range 2 end */
  131. #define _DS1S 0x40 /* DBC 2nd byte range 1 start */
  132. #define _DS1E 0x7E /* DBC 2nd byte range 1 end */
  133. #define _DS2S 0x80 /* DBC 2nd byte range 2 start */
  134. #define _DS2E 0xFC /* DBC 2nd byte range 2 end */
  135. #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */
  136. #define _DF1S 0x81
  137. #define _DF1E 0xFE
  138. #define _DS1S 0x40
  139. #define _DS1E 0x7E
  140. #define _DS2S 0x80
  141. #define _DS2E 0xFE
  142. #elif _CODE_PAGE == 949 /* Korean */
  143. #define _DF1S 0x81
  144. #define _DF1E 0xFE
  145. #define _DS1S 0x41
  146. #define _DS1E 0x5A
  147. #define _DS2S 0x61
  148. #define _DS2E 0x7A
  149. #define _DS3S 0x81
  150. #define _DS3E 0xFE
  151. #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */
  152. #define _DF1S 0x81
  153. #define _DF1E 0xFE
  154. #define _DS1S 0x40
  155. #define _DS1E 0x7E
  156. #define _DS2S 0xA1
  157. #define _DS2E 0xFE
  158. #elif _CODE_PAGE == 437 /* U.S. (OEM) */
  159. #define _DF1S 0
  160. #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F,0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
  161. 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
  162. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  163. 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
  164. #elif _CODE_PAGE == 720 /* Arabic (OEM) */
  165. #define _DF1S 0
  166. #define _EXCVT {0x80,0x81,0x45,0x41,0x84,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x49,0x49,0x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DB,0xDC,0xDD,0xDE,0xDF, \
  175. 0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xE7,0xE8,0xF1,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
  176. #elif _CODE_PAGE == 775 /* Baltic (OEM) */
  177. #define _DF1S 0
  178. #define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
  179. 0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
  180. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xA5,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  181. 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE3,0xE8,0xE8,0xEA,0xEA,0xEE,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
  182. #elif _CODE_PAGE == 850 /* Multilingual Latin 1 (OEM) */
  183. #define _DF1S 0
  184. #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0xDE,0x8E,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0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD2,0xD5,0xD6,0xD7,0xB7,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  193. 0xE0,0xE1,0xE2,0xE3,0xE3,0xD5,0xE6,0xE6,0xE8,0xE9,0xE8,0xEB,0xED,0xED,0xDD,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}
  194. #elif _CODE_PAGE == 855 /* Cyrillic (OEM) */
  195. #define _DF1S 0
  196. #define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F,0x91,0x91,0x93,0x93,0x95,0x95,0x97,0x97,0x99,0x99,0x9B,0x9B,0x9D,0x9D,0x9F,0x9F, \
  197. 0xA1,0xA1,0xA3,0xA3,0xA5,0xA5,0xA7,0xA7,0xA9,0xA9,0xAB,0xAB,0xAD,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB6,0xB6,0xB8,0xB8,0xB9,0xBA,0xBB,0xBC,0xBE,0xBE,0xBF, \
  198. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD3,0xD3,0xD5,0xD5,0xD7,0xD7,0xDD,0xD9,0xDA,0xDB,0xDC,0xDD,0xE0,0xDF, \
  199. 0xE0,0xE2,0xE2,0xE4,0xE4,0xE6,0xE6,0xE8,0xE8,0xEA,0xEA,0xEC,0xEC,0xEE,0xEE,0xEF,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}
  200. #elif _CODE_PAGE == 857 /* Turkish (OEM) */
  201. #define _DF1S 0
  202. #define _EXCVT {0x80,0x9A,0x90,0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ODE_PAGE == 866 /* Russian (OEM) */
  219. #define _DF1S 0
  220. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
  221. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
  222. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  223. 0x90,0x91,0x92,0x93,0x9d,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
  224. #elif _CODE_PAGE == 874 /* Thai (OEM, Windows) */
  225. #define _DF1S 0
  226. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
  227. 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,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0xDD,0xDE,0xFF}
  236. #elif _CODE_PAGE == 1251 /* Cyrillic (Windows) */
  237. #define _DF1S 0
  238. #define _EXCVT {0x80,0x81,0x82,0x82,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x80,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \
  239. 0xA0,0xA2,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB2,0xA5,0xB5,0xB6,0xB7,0xA8,0xB9,0xAA,0xBB,0xA3,0xBD,0xBD,0xAF, \
  240. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  241. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF}
  242. #elif _CODE_PAGE == 1252 /* Latin 1 (Windows) */
  243. #define _DF1S 0
  244. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0xAd,0x9B,0x8C,0x9D,0xAE,0x9F, \
  245. 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4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0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xFB,0xBC,0xFD,0xBF,0xFF}
  254. #elif _CODE_PAGE == 1254 /* Turkish (Windows) */
  255. #define _DF1S 0
  256. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x9D,0x9E,0x9F, \
  257. 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
  258. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  259. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F}
  260. #elif _CODE_PAGE == 1255 /* Hebrew (Windows) */
  261. #define _DF1S 0
  262. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
  263. 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xA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xED,0x49,0x49,0xF0,0xF1,0xF2,0xF3,0x4F,0xF5,0xF6,0xF7,0xF8,0x55,0xFA,0x55,0x55,0xFD,0xFE,0xFF}
  272. #elif _CODE_PAGE == 1257 /* Baltic (Windows) */
  273. #define _DF1S 0
  274. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
  275. 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xA8,0xB9,0xAA,0xBB,0xBC,0xBD,0xBE,0xAF, \
  276. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  277. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF}
  278. #elif _CODE_PAGE == 1258 /* Vietnam (OEM, Windows) */
  279. #define _DF1S 0
  280. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0xAC,0x9D,0x9E,0x9F, \
  281. 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
  282. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  283. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xEC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xFE,0x9F}
  284. #elif _CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */
  285. #define _DF1S 0
  286. #else
  287. #error Unknown code page
  288. #endif
  289. /* Character code support macros */
  290. #define IsUpper(c) (((c)>='A')&&((c)<='Z'))
  291. #define IsLower(c) (((c)>='a')&&((c)<='z'))
  292. #define IsDigit(c) (((c)>='0')&&((c)<='9'))
  293. #if _DF1S /* DBCS configuration */
  294. #if _DF2S /* Two 1st byte areas */
  295. #define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))
  296. #else /* One 1st byte area */
  297. #define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)
  298. #endif
  299. #if _DS3S /* Three 2nd byte areas */
  300. #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))
  301. #else /* Two 2nd byte areas */
  302. #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))
  303. #endif
  304. #else /* SBCS configuration */
  305. #define IsDBCS1(c) 0
  306. #define IsDBCS2(c) 0
  307. #endif /* _DF1S */
  308. /* Definitions corresponds to multi partition */
  309. #if _MULTI_PARTITION /* Multiple partition configuration */
  310. typedef struct _PARTITION {
  311. BYTE pd; /* Physical drive# */
  312. BYTE pt; /* Partition # (0-3) */
  313. } PARTITION;
  314. extern
  315. const PARTITION Drives[]; /* Logical drive# to physical location conversion table */
  316. #define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */
  317. #define LD2PT(drv) (Drives[drv].pt) /* Get partition# */
  318. #else /* Single partition configuration */
  319. #define LD2PD(drv) (drv) /* Physical drive# is equal to the logical drive# */
  320. #define LD2PT(drv) 0 /* Always mounts the 1st partition */
  321. #endif
  322. /* Definitions corresponds to multiple sector size */
  323. #if _MAX_SS == 512
  324. #define SS(fs) 512U
  325. #elif _MAX_SS == 1024 || _MAX_SS == 2048 || _MAX_SS == 4096
  326. #define SS(fs) ((fs)->s_size)
  327. #else
  328. #error Sector size must be 512, 1024, 2048 or 4096.
  329. #endif
  330. /* Type of file name on FatFs API */
  331. #if _LFN_UNICODE && _USE_LFN
  332. typedef WCHAR XCHAR; /* Unicode */
  333. #else
  334. typedef char XCHAR; /* SBCS, DBCS */
  335. #endif
  336. /* File system object structure */
  337. typedef struct _FATFS_ {
  338. BYTE fs_type; /* FAT sub type */
  339. BYTE drive; /* Physical drive number */
  340. BYTE csize; /* Number of sectors per cluster */
  341. BYTE n_fats; /* Number of FAT copies */
  342. BYTE wflag; /* win[] dirty flag (1:must be written back) */
  343. WORD id; /* File system mount ID */
  344. WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
  345. #if _FS_REENTRANT
  346. _SYNC_t sobj; /* Identifier of sync object */
  347. #endif
  348. #if _MAX_SS != 512
  349. WORD s_size; /* Sector size */
  350. #endif
  351. #if !_FS_READONLY
  352. BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
  353. DWORD last_clust; /* Last allocated cluster */
  354. DWORD free_clust; /* Number of free clusters */
  355. DWORD fsi_sector; /* fsinfo sector */
  356. #endif
  357. #if _FS_RPATH
  358. DWORD cdir; /* Current directory (0:root)*/
  359. #endif
  360. DWORD sects_fat; /* Sectors per fat */
  361. DWORD max_clust; /* Maximum cluster# + 1. Number of clusters is max_clust - 2 */
  362. DWORD fatbase; /* FAT start sector */
  363. DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
  364. DWORD database; /* Data start sector */
  365. DWORD winsect; /* Current sector appearing in the win[] */
  366. BYTE win[_MAX_SS];/* Disk access window for Directory/FAT */
  367. } FATFS;
  368. /* Directory object structure */
  369. typedef struct _DIR_ {
  370. FATFS* fs; /* Pointer to the owner file system object */
  371. WORD id; /* Owner file system mount ID */
  372. WORD index; /* Current read/write index number */
  373. DWORD sclust; /* Table start cluster (0:Static table) */
  374. DWORD clust; /* Current cluster */
  375. DWORD sect; /* Current sector */
  376. BYTE* dir; /* Pointer to the current SFN entry in the win[] */
  377. BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
  378. #if _USE_LFN
  379. WCHAR* lfn; /* Pointer to the LFN working buffer */
  380. WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
  381. #endif
  382. } DIR;
  383. /* File object structure */
  384. typedef struct _FIL_ {
  385. FATFS* fs; /* Pointer to the owner file system object */
  386. WORD id; /* Owner file system mount ID */
  387. BYTE flag; /* File status flags */
  388. BYTE csect; /* Sector address in the cluster */
  389. DWORD fptr; /* File R/W pointer */
  390. DWORD fsize; /* File size */
  391. DWORD org_clust; /* File start cluster */
  392. DWORD curr_clust; /* Current cluster */
  393. DWORD dsect; /* Current data sector */
  394. #if !_FS_READONLY
  395. DWORD dir_sect; /* Sector containing the directory entry */
  396. BYTE* dir_ptr; /* Ponter to the directory entry in the window */
  397. #endif
  398. #if !_FS_TINY
  399. BYTE buf[_MAX_SS];/* File R/W buffer */
  400. #endif
  401. } FIL;
  402. /* File status structure */
  403. typedef struct _FILINFO_ {
  404. DWORD fsize; /* File size */
  405. WORD fdate; /* Last modified date */
  406. WORD ftime; /* Last modified time */
  407. BYTE fattrib; /* Attribute */
  408. char fname[13]; /* Short file name (8.3 format) */
  409. #if _USE_LFN
  410. XCHAR* lfname; /* Pointer to the LFN buffer */
  411. int lfsize; /* Size of LFN buffer [chrs] */
  412. #endif
  413. } FILINFO;
  414. /* File function return code (FRESULT) */
  415. typedef enum {
  416. FR_OK = 0, /* 0 */
  417. FR_DISK_ERR, /* 1 */
  418. FR_INT_ERR, /* 2 */
  419. FR_NOT_READY, /* 3 */
  420. FR_NO_FILE, /* 4 */
  421. FR_NO_PATH, /* 5 */
  422. FR_INVALID_NAME, /* 6 */
  423. FR_DENIED, /* 7 */
  424. FR_EXIST, /* 8 */
  425. FR_INVALID_OBJECT, /* 9 */
  426. FR_WRITE_PROTECTED, /* 10 */
  427. FR_INVALID_DRIVE, /* 11 */
  428. FR_NOT_ENABLED, /* 12 */
  429. FR_NO_FILESYSTEM, /* 13 */
  430. FR_MKFS_ABORTED, /* 14 */
  431. FR_TIMEOUT /* 15 */
  432. } FRESULT;
  433. /*--------------------------------------------------------------*/
  434. /* FatFs module application interface */
  435. FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
  436. FRESULT f_open (FIL*, const XCHAR*, BYTE); /* Open or create a file */
  437. FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
  438. FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
  439. FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
  440. FRESULT f_close (FIL*); /* Close an open file object */
  441. FRESULT f_opendir (DIR*, const XCHAR*); /* Open an existing directory */
  442. FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
  443. FRESULT f_stat (const XCHAR*, FILINFO*); /* Get file status */
  444. FRESULT f_getfree (const XCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
  445. FRESULT f_truncate (FIL*); /* Truncate file */
  446. FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
  447. FRESULT f_unlink (const XCHAR*); /* Delete an existing file or directory */
  448. FRESULT f_mkdir (const XCHAR*); /* Create a new directory */
  449. FRESULT f_chmod (const XCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */
  450. FRESULT f_utime (const XCHAR*, const FILINFO*); /* Change timestamp of the file/dir */
  451. FRESULT f_rename (const XCHAR*, const XCHAR*); /* Rename/Move a file or directory */
  452. FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
  453. FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */
  454. FRESULT f_chdir (const XCHAR*); /* Change current directory */
  455. FRESULT f_chdrive (BYTE); /* Change current drive */
  456. #if _USE_STRFUNC
  457. int f_putc (int, FIL*); /* Put a character to the file */
  458. int f_puts (const char*, FIL*); /* Put a string to the file */
  459. int f_printf (FIL*, const char*, ...); /* Put a formatted string to the file */
  460. char* f_gets (char*, int, FIL*); /* Get a string from the file */
  461. #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
  462. #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
  463. #ifndef EOF
  464. #define EOF -1
  465. #endif
  466. #endif
  467. /*--------------------------------------------------------------*/
  468. /* User defined functions */
  469. /* Real time clock */
  470. #if !_FS_READONLY
  471. DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
  472. /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
  473. #endif
  474. /* Unicode - OEM code conversion */
  475. #if _USE_LFN
  476. WCHAR ff_convert (WCHAR, UINT);
  477. WCHAR ff_wtoupper (WCHAR);
  478. #endif
  479. /* Sync functions */
  480. #if _FS_REENTRANT
  481. BOOL ff_cre_syncobj(BYTE, _SYNC_t*);
  482. BOOL ff_del_syncobj(_SYNC_t);
  483. BOOL ff_req_grant(_SYNC_t);
  484. void ff_rel_grant(_SYNC_t);
  485. #endif
  486. /*--------------------------------------------------------------*/
  487. /* Flags and offset address */
  488. /* File access control and file status flags (FIL.flag) */
  489. #define FA_READ 0x01
  490. #define FA_OPEN_EXISTING 0x00
  491. #if _FS_READONLY == 0
  492. #define FA_WRITE 0x02
  493. #define FA_CREATE_NEW 0x04
  494. #define FA_CREATE_ALWAYS 0x08
  495. #define FA_OPEN_ALWAYS 0x10
  496. #define FA__WRITTEN 0x20
  497. #define FA__DIRTY 0x40
  498. #endif
  499. #define FA__ERROR 0x80
  500. /* FAT sub type (FATFS.fs_type) */
  501. #define FS_FAT12 1
  502. #define FS_FAT16 2
  503. #define FS_FAT32 3
  504. /* File attribute bits for directory entry */
  505. #define AM_RDO 0x01 /* Read only */
  506. #define AM_HID 0x02 /* Hidden */
  507. #define AM_SYS 0x04 /* System */
  508. #define AM_VOL 0x08 /* Volume label */
  509. #define AM_LFN 0x0F /* LFN entry */
  510. #define AM_DIR 0x10 /* Directory */
  511. #define AM_ARC 0x20 /* Archive */
  512. #define AM_MASK 0x3F /* Mask of defined bits */
  513. /* FatFs refers the members in the FAT structures with byte offset instead
  514. / of structure member because there are incompatibility of the packing option
  515. / between various compilers. */
  516. #define BS_jmpBoot 0
  517. #define BS_OEMName 3
  518. #define BPB_BytsPerSec 11
  519. #define BPB_SecPerClus 13
  520. #define BPB_RsvdSecCnt 14
  521. #define BPB_NumFATs 16
  522. #define BPB_RootEntCnt 17
  523. #define BPB_TotSec16 19
  524. #define BPB_Media 21
  525. #define BPB_FATSz16 22
  526. #define BPB_SecPerTrk 24
  527. #define BPB_NumHeads 26
  528. #define BPB_HiddSec 28
  529. #define BPB_TotSec32 32
  530. #define BS_55AA 510
  531. #define BS_DrvNum 36
  532. #define BS_BootSig 38
  533. #define BS_VolID 39
  534. #define BS_VolLab 43
  535. #define BS_FilSysType 54
  536. #define BPB_FATSz32 36
  537. #define BPB_ExtFlags 40
  538. #define BPB_FSVer 42
  539. #define BPB_RootClus 44
  540. #define BPB_FSInfo 48
  541. #define BPB_BkBootSec 50
  542. #define BS_DrvNum32 64
  543. #define BS_BootSig32 66
  544. #define BS_VolID32 67
  545. #define BS_VolLab32 71
  546. #define BS_FilSysType32 82
  547. #define FSI_LeadSig 0
  548. #define FSI_StrucSig 484
  549. #define FSI_Free_Count 488
  550. #define FSI_Nxt_Free 492
  551. #define MBR_Table 446
  552. #define DIR_Name 0
  553. #define DIR_Attr 11
  554. #define DIR_NTres 12
  555. #define DIR_CrtTime 14
  556. #define DIR_CrtDate 16
  557. #define DIR_FstClusHI 20
  558. #define DIR_WrtTime 22
  559. #define DIR_WrtDate 24
  560. #define DIR_FstClusLO 26
  561. #define DIR_FileSize 28
  562. #define LDIR_Ord 0
  563. #define LDIR_Attr 11
  564. #define LDIR_Type 12
  565. #define LDIR_Chksum 13
  566. #define LDIR_FstClusLO 26
  567. /*--------------------------------*/
  568. /* Multi-byte word access macros */
  569. #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
  570. #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
  571. #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
  572. #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
  573. #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
  574. #else /* Use byte-by-byte access to the FAT structure */
  575. #define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
  576. #define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
  577. #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
  578. #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24)
  579. #endif
  580. #endif /* _FATFS */