ff.h 34 KB

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