ff.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*---------------------------------------------------------------------------/
  2. / FatFs - FAT file system module include file R0.07e (C)ChaN, 2009
  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) 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. #ifndef _FATFS
  16. #define _FATFS 0x007E
  17. #include <rtthread.h>
  18. #include "integer.h" /* Basic integer types */
  19. #include "ffconf.h" /* FatFs configuration options */
  20. #if _FATFS != _FFCONFIG
  21. #error Wrong configuration file (ffconf.h).
  22. #endif
  23. /* DBCS code ranges and SBCS extend char conversion table */
  24. #if _CODE_PAGE == 932 /* Japanese Shift-JIS */
  25. #define _DF1S 0x81 /* DBC 1st byte range 1 start */
  26. #define _DF1E 0x9F /* DBC 1st byte range 1 end */
  27. #define _DF2S 0xE0 /* DBC 1st byte range 2 start */
  28. #define _DF2E 0xFC /* DBC 1st byte range 2 end */
  29. #define _DS1S 0x40 /* DBC 2nd byte range 1 start */
  30. #define _DS1E 0x7E /* DBC 2nd byte range 1 end */
  31. #define _DS2S 0x80 /* DBC 2nd byte range 2 start */
  32. #define _DS2E 0xFC /* DBC 2nd byte range 2 end */
  33. #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */
  34. #define _DF1S 0x81
  35. #define _DF1E 0xFE
  36. #define _DS1S 0x40
  37. #define _DS1E 0x7E
  38. #define _DS2S 0x80
  39. #define _DS2E 0xFE
  40. #elif _CODE_PAGE == 949 /* Korean */
  41. #define _DF1S 0x81
  42. #define _DF1E 0xFE
  43. #define _DS1S 0x41
  44. #define _DS1E 0x5A
  45. #define _DS2S 0x61
  46. #define _DS2E 0x7A
  47. #define _DS3S 0x81
  48. #define _DS3E 0xFE
  49. #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */
  50. #define _DF1S 0x81
  51. #define _DF1E 0xFE
  52. #define _DS1S 0x40
  53. #define _DS1E 0x7E
  54. #define _DS2S 0xA1
  55. #define _DS2E 0xFE
  56. #elif _CODE_PAGE == 437 /* U.S. (OEM) */
  57. #define _DF1S 0
  58. #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, \
  59. 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,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xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
  68. #elif _CODE_PAGE == 737 /* Greek (OEM) */
  69. #define _DF1S 0
  70. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \
  71. 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
  72. 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, \
  73. 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}
  74. #elif _CODE_PAGE == 775 /* Baltic (OEM) */
  75. #define _DF1S 0
  76. #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, \
  77. 0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xA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B,0xED,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
  86. #elif _CODE_PAGE == 852 /* Latin 2 (OEM) */
  87. #define _DF1S 0
  88. #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F,0x90,0x91,0x91,0xE2,0x99,0x95,0x95,0x97,0x97,0x99,0x9A,0x9B,0x9B,0x9D,0x9E,0x9F, \
  89. 0xB5,0xD6,0xE0,0xE9,0xA4,0xA4,0xA6,0xA6,0xA8,0xA8,0xAA,0x8D,0xAC,0xB8,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBD,0xBF, \
  90. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC6,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD2,0xD5,0xD6,0xD7,0xB7,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  91. 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}
  92. #elif _CODE_PAGE == 855 /* Cyrillic (OEM) */
  93. #define _DF1S 0
  94. #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, \
  95. 0xA1,0xA1,0xA3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xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xDE,0x59,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
  104. #elif _CODE_PAGE == 858 /* Multilingual Latin 1 + Euro (OEM) */
  105. #define _DF1S 0
  106. #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,0x9D,0x9E,0x9F, \
  107. 0xB5,0xD6,0xE0,0xE9,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, \
  108. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  109. 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}
  110. #elif _CODE_PAGE == 862 /* Hebrew (OEM) */
  111. #define _DF1S 0
  112. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x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,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  121. 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}
  122. #elif _CODE_PAGE == 874 /* Thai (OEM, Windows) */
  123. #define _DF1S 0
  124. #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, \
  125. 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, \
  126. 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, \
  127. 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}
  128. #elif _CODE_PAGE == 1250 /* Central Europe (Windows) */
  129. #define _DF1S 0
  130. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90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xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  139. 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}
  140. #elif _CODE_PAGE == 1252 /* Latin 1 (Windows) */
  141. #define _DF1S 0
  142. #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, \
  143. 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, \
  144. 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, \
  145. 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}
  146. #elif _CODE_PAGE == 1253 /* Greek (Windows) */
  147. #define _DF1S 0
  148. #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,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,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
  157. 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}
  158. #elif _CODE_PAGE == 1255 /* Hebrew (Windows) */
  159. #define _DF1S 0
  160. #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, \
  161. 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, \
  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 == 1256 /* Arabic (Windows) */
  165. #define _DF1S 0
  166. #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,0x8C,0x9D,0x9E,0x9F, \
  167. 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, \
  168. 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, \
  169. 0x41,0xE1,0x41,0xE3,0xE4,0xE5,0xE6,0x43,0x45,0x45,0x45,0x45,0xEC,0xED,0x49,0x49,0xF0,0xF1,0xF2,0xF3,0x4F,0xF5,0xF6,0xF7,0xF8,0x55,0xFA,0x55,0x55,0xFD,0xFE,0xFF}
  170. #elif _CODE_PAGE == 1257 /* Baltic (Windows) */
  171. #define _DF1S 0
  172. #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, \
  173. 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, \
  174. 0xC0,0xC1,0xC2,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PAGE == 1 /* ASCII (for only non-LFN cfg) */
  183. #define _DF1S 0
  184. #else
  185. #error Unknown code page
  186. #endif
  187. /* Character code support macros */
  188. #define IsUpper(c) (((c)>='A')&&((c)<='Z'))
  189. #define IsLower(c) (((c)>='a')&&((c)<='z'))
  190. #if _DF1S /* DBCS configuration */
  191. #ifdef _DF2S /* Two 1st byte areas */
  192. #define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))
  193. #else /* One 1st byte area */
  194. #define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)
  195. #endif
  196. #ifdef _DS3S /* Three 2nd byte areas */
  197. #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))
  198. #else /* Two 2nd byte areas */
  199. #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))
  200. #endif
  201. #else /* SBCS configuration */
  202. #define IsDBCS1(c) 0
  203. #define IsDBCS2(c) 0
  204. #endif /* _DF1S */
  205. /* Definitions corresponds to multi partition */
  206. #if _MULTI_PARTITION /* Multiple partition configuration */
  207. typedef struct _PARTITION {
  208. BYTE pd; /* Physical drive# */
  209. BYTE pt; /* Partition # (0-3) */
  210. } PARTITION;
  211. extern
  212. const PARTITION Drives[]; /* Logical drive# to physical location conversion table */
  213. #define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */
  214. #define LD2PT(drv) (Drives[drv].pt) /* Get partition# */
  215. #else /* Single partition configuration */
  216. #define LD2PD(drv) (drv) /* Physical drive# is equal to the logical drive# */
  217. #define LD2PT(drv) 0 /* Always mounts the 1st partition */
  218. #endif
  219. /* Definitions corresponds to multiple sector size */
  220. #if _MAX_SS == 512 /* Single sector size */
  221. #define SS(fs) 512U
  222. #elif _MAX_SS == 1024 || _MAX_SS == 2048 || _MAX_SS == 4096 /* Multiple sector size */
  223. #define SS(fs) ((fs)->s_size)
  224. #else
  225. #error Sector size must be 512, 1024, 2048 or 4096.
  226. #endif
  227. /* Type of file name on FatFs API */
  228. #if _LFN_UNICODE && _USE_LFN
  229. typedef WCHAR XCHAR; /* Unicode */
  230. #else
  231. typedef char XCHAR; /* SBCS, DBCS */
  232. #endif
  233. /* File system object structure */
  234. typedef struct _FATFS_ {
  235. BYTE fs_type; /* FAT sub type */
  236. BYTE drive; /* Physical drive number */
  237. BYTE csize; /* Number of sectors per cluster */
  238. BYTE n_fats; /* Number of FAT copies */
  239. BYTE wflag; /* win[] dirty flag (1:must be written back) */
  240. BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
  241. WORD id; /* File system mount ID */
  242. WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
  243. #if _FS_REENTRANT
  244. _SYNC_t sobj; /* Identifier of sync object */
  245. #endif
  246. #if _MAX_SS != 512
  247. WORD s_size; /* Sector size */
  248. #endif
  249. #if !_FS_READONLY
  250. DWORD last_clust; /* Last allocated cluster */
  251. DWORD free_clust; /* Number of free clusters */
  252. DWORD fsi_sector; /* fsinfo sector */
  253. #endif
  254. #if _FS_RPATH
  255. DWORD cdir; /* Current directory (0:root)*/
  256. #endif
  257. DWORD sects_fat; /* Sectors per fat */
  258. DWORD max_clust; /* Maximum cluster# + 1. Number of clusters is max_clust - 2 */
  259. DWORD fatbase; /* FAT start sector */
  260. DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
  261. DWORD database; /* Data start sector */
  262. DWORD winsect; /* Current sector appearing in the win[] */
  263. BYTE win[_MAX_SS];/* Disk access window for Directory/FAT */
  264. } FATFS;
  265. /* Directory object structure */
  266. typedef struct _DIR_ {
  267. FATFS* fs; /* Pointer to the owner file system object */
  268. WORD id; /* Owner file system mount ID */
  269. WORD index; /* Current read/write index number */
  270. DWORD sclust; /* Table start cluster (0:Static table) */
  271. DWORD clust; /* Current cluster */
  272. DWORD sect; /* Current sector */
  273. BYTE* dir; /* Pointer to the current SFN entry in the win[] */
  274. BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
  275. #if _USE_LFN
  276. WCHAR* lfn; /* Pointer to the LFN working buffer */
  277. WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
  278. #endif
  279. } DIR;
  280. /* File object structure */
  281. typedef struct _FIL_ {
  282. FATFS* fs; /* Pointer to the owner file system object */
  283. WORD id; /* Owner file system mount ID */
  284. BYTE flag; /* File status flags */
  285. BYTE csect; /* Sector address in the cluster */
  286. DWORD fptr; /* File R/W pointer */
  287. DWORD fsize; /* File size */
  288. DWORD org_clust; /* File start cluster */
  289. DWORD curr_clust; /* Current cluster */
  290. DWORD dsect; /* Current data sector */
  291. #if !_FS_READONLY
  292. DWORD dir_sect; /* Sector containing the directory entry */
  293. BYTE* dir_ptr; /* Ponter to the directory entry in the window */
  294. #endif
  295. #if !_FS_TINY
  296. BYTE buf[_MAX_SS];/* File R/W buffer */
  297. #endif
  298. } FIL;
  299. /* File status structure */
  300. typedef struct _FILINFO_ {
  301. DWORD fsize; /* File size */
  302. WORD fdate; /* Last modified date */
  303. WORD ftime; /* Last modified time */
  304. BYTE fattrib; /* Attribute */
  305. char fname[13]; /* Short file name (8.3 format) */
  306. #if _USE_LFN
  307. XCHAR* lfname; /* Pointer to the LFN buffer */
  308. int lfsize; /* Size of LFN buffer [chrs] */
  309. #endif
  310. } FILINFO;
  311. /* File function return code (FRESULT) */
  312. typedef enum {
  313. FR_OK = 0, /* 0 */
  314. FR_DISK_ERR, /* 1 */
  315. FR_INT_ERR, /* 2 */
  316. FR_NOT_READY, /* 3 */
  317. FR_NO_FILE, /* 4 */
  318. FR_NO_PATH, /* 5 */
  319. FR_INVALID_NAME, /* 6 */
  320. FR_DENIED, /* 7 */
  321. FR_EXIST, /* 8 */
  322. FR_INVALID_OBJECT, /* 9 */
  323. FR_WRITE_PROTECTED, /* 10 */
  324. FR_INVALID_DRIVE, /* 11 */
  325. FR_NOT_ENABLED, /* 12 */
  326. FR_NO_FILESYSTEM, /* 13 */
  327. FR_MKFS_ABORTED, /* 14 */
  328. FR_TIMEOUT /* 15 */
  329. } FRESULT;
  330. /*--------------------------------------------------------------*/
  331. /* FatFs module application interface */
  332. FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
  333. FRESULT f_open (FIL*, const XCHAR*, BYTE); /* Open or create a file */
  334. FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
  335. FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
  336. FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
  337. FRESULT f_close (FIL*); /* Close an open file object */
  338. FRESULT f_opendir (DIR*, const XCHAR*); /* Open an existing directory */
  339. FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
  340. FRESULT f_stat (const XCHAR*, FILINFO*); /* Get file status */
  341. FRESULT f_getfree (const XCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
  342. FRESULT f_truncate (FIL*); /* Truncate file */
  343. FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
  344. FRESULT f_unlink (const XCHAR*); /* Delete an existing file or directory */
  345. FRESULT f_mkdir (const XCHAR*); /* Create a new directory */
  346. FRESULT f_chmod (const XCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */
  347. FRESULT f_utime (const XCHAR*, const FILINFO*); /* Change timestamp of the file/dir */
  348. FRESULT f_rename (const XCHAR*, const XCHAR*); /* Rename/Move a file or directory */
  349. FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
  350. FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */
  351. FRESULT f_chdir (const XCHAR*); /* Change current directory */
  352. FRESULT f_chdrive (BYTE); /* Change current drive */
  353. #if _USE_STRFUNC
  354. int f_putc (int, FIL*); /* Put a character to the file */
  355. int f_puts (const char*, FIL*); /* Put a string to the file */
  356. int f_printf (FIL*, const char*, ...); /* Put a formatted string to the file */
  357. char* f_gets (char*, int, FIL*); /* Get a string from the file */
  358. #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
  359. #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
  360. #ifndef EOF
  361. #define EOF -1
  362. #endif
  363. #endif
  364. /*--------------------------------------------------------------*/
  365. /* User defined functions */
  366. /* Real time clock */
  367. #if !_FS_READONLY
  368. DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
  369. /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
  370. #endif
  371. /* Unicode - OEM code conversion */
  372. #if _USE_LFN
  373. WCHAR ff_convert (WCHAR, UINT);
  374. WCHAR ff_wtoupper (WCHAR);
  375. #endif
  376. /* Sync functions */
  377. #if _FS_REENTRANT
  378. BOOL ff_cre_syncobj(BYTE, _SYNC_t*);
  379. BOOL ff_del_syncobj(_SYNC_t);
  380. BOOL ff_req_grant(_SYNC_t);
  381. void ff_rel_grant(_SYNC_t);
  382. #endif
  383. /*--------------------------------------------------------------*/
  384. /* Flags and offset address */
  385. /* File access control and file status flags (FIL.flag) */
  386. #define FA_READ 0x01
  387. #define FA_OPEN_EXISTING 0x00
  388. #if _FS_READONLY == 0
  389. #define FA_WRITE 0x02
  390. #define FA_CREATE_NEW 0x04
  391. #define FA_CREATE_ALWAYS 0x08
  392. #define FA_OPEN_ALWAYS 0x10
  393. #define FA__WRITTEN 0x20
  394. #define FA__DIRTY 0x40
  395. #endif
  396. #define FA__ERROR 0x80
  397. /* FAT sub type (FATFS.fs_type) */
  398. #define FS_FAT12 1
  399. #define FS_FAT16 2
  400. #define FS_FAT32 3
  401. /* File attribute bits for directory entry */
  402. #define AM_RDO 0x01 /* Read only */
  403. #define AM_HID 0x02 /* Hidden */
  404. #define AM_SYS 0x04 /* System */
  405. #define AM_VOL 0x08 /* Volume label */
  406. #define AM_LFN 0x0F /* LFN entry */
  407. #define AM_DIR 0x10 /* Directory */
  408. #define AM_ARC 0x20 /* Archive */
  409. #define AM_MASK 0x3F /* Mask of defined bits */
  410. /* FatFs refers the members in the FAT structures with byte offset instead
  411. / of structure member because there are incompatibility of the packing option
  412. / between various compilers. */
  413. #define BS_jmpBoot 0
  414. #define BS_OEMName 3
  415. #define BPB_BytsPerSec 11
  416. #define BPB_SecPerClus 13
  417. #define BPB_RsvdSecCnt 14
  418. #define BPB_NumFATs 16
  419. #define BPB_RootEntCnt 17
  420. #define BPB_TotSec16 19
  421. #define BPB_Media 21
  422. #define BPB_FATSz16 22
  423. #define BPB_SecPerTrk 24
  424. #define BPB_NumHeads 26
  425. #define BPB_HiddSec 28
  426. #define BPB_TotSec32 32
  427. #define BS_55AA 510
  428. #define BS_DrvNum 36
  429. #define BS_BootSig 38
  430. #define BS_VolID 39
  431. #define BS_VolLab 43
  432. #define BS_FilSysType 54
  433. #define BPB_FATSz32 36
  434. #define BPB_ExtFlags 40
  435. #define BPB_FSVer 42
  436. #define BPB_RootClus 44
  437. #define BPB_FSInfo 48
  438. #define BPB_BkBootSec 50
  439. #define BS_DrvNum32 64
  440. #define BS_BootSig32 66
  441. #define BS_VolID32 67
  442. #define BS_VolLab32 71
  443. #define BS_FilSysType32 82
  444. #define FSI_LeadSig 0
  445. #define FSI_StrucSig 484
  446. #define FSI_Free_Count 488
  447. #define FSI_Nxt_Free 492
  448. #define MBR_Table 446
  449. #define DIR_Name 0
  450. #define DIR_Attr 11
  451. #define DIR_NTres 12
  452. #define DIR_CrtTime 14
  453. #define DIR_CrtDate 16
  454. #define DIR_FstClusHI 20
  455. #define DIR_WrtTime 22
  456. #define DIR_WrtDate 24
  457. #define DIR_FstClusLO 26
  458. #define DIR_FileSize 28
  459. #define LDIR_Ord 0
  460. #define LDIR_Attr 11
  461. #define LDIR_Type 12
  462. #define LDIR_Chksum 13
  463. #define LDIR_FstClusLO 26
  464. /*--------------------------------*/
  465. /* Multi-byte word access macros */
  466. #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
  467. #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
  468. #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
  469. #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
  470. #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
  471. #else /* Use byte-by-byte access to the FAT structure */
  472. #define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
  473. #define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
  474. #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
  475. #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)
  476. #endif
  477. #endif /* _FATFS */