ff.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*---------------------------------------------------------------------------/
  2. / FatFs - FAT file system module include file R0.07a (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 use 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
  25. #define _WORD_ACCESS 1
  26. /*
  27. * The _WORD_ACCESS option defines which access method is used to the word / data in the FAT structure. / / 0: Byte-by-byte access. Always
  28. * compatible with all platforms. / 1: Word access. Do not choose this unless following condition is met. / / When the byte order on the
  29. * memory is big-endian or address miss-aligned / word access results incorrect behavior, the _WORD_ACCESS must be set to 0. / If it is not
  30. * the case, the value can also be set to 1 to improve the / performance and code efficiency.
  31. */
  32. #define _FS_READONLY 0
  33. /*
  34. * Setting _FS_READONLY to 1 defines read only configuration. This removes / writing functions, f_write, f_sync, f_unlink, f_mkdir,
  35. * f_chmod, f_rename, / f_truncate and useless f_getfree.
  36. */
  37. #define _FS_MINIMIZE 0
  38. /*
  39. * The _FS_MINIMIZE option defines minimization level to remove some functions. / / 0: Full function. / 1: f_stat, f_getfree, f_unlink,
  40. * f_mkdir, f_chmod, f_truncate and f_rename / are removed. / 2: f_opendir and f_readdir are removed in addition to level 1. / 3: f_lseek
  41. * is removed in addition to level 2.
  42. */
  43. #define _FS_TINY 0
  44. /*
  45. * When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system / object instead of the sector buffer in the individual file
  46. * object for file / data transfer. This reduces memory consumption 512 bytes each file object.
  47. */
  48. #define _USE_STRFUNC 0
  49. /*
  50. * To enable string functions, set _USE_STRFUNC to 1 or 2.
  51. */
  52. #define _USE_MKFS 0
  53. /*
  54. * To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0
  55. */
  56. #define _USE_FORWARD 0
  57. /*
  58. * To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1.
  59. */
  60. #define _DRIVES 1
  61. /*
  62. * Number of volumes (logical drives) to be used.
  63. */
  64. #define _MAX_SS 512
  65. /*
  66. * Maximum sector size to be handled. (512/1024/2048/4096)
  67. */
  68. /*
  69. * 512 for memroy card and hard disk, 1024 for floppy disk, 2048 for MO disk
  70. */
  71. #define _MULTI_PARTITION 0
  72. /*
  73. * When _MULTI_PARTITION is set to 0, each volume is bound to the same physical / drive number and can mount only first primaly partition.
  74. * When it is set to 1, / each volume is tied to the partitions listed in Drives[].
  75. */
  76. #define _CODE_PAGE 437
  77. /*
  78. * The _CODE_PAGE specifies the OEM code page to be used on the target system. / When it is non LFN configuration, there is no difference
  79. * between SBCS code / pages. When LFN is enabled, the code page must always be set correctly. / 437 - U.S. / 720 - Arabic / 737 - Greek /
  80. * 775 - Baltic / 850 - Multilingual Latin 1 / 852 - Latin 2 / 855 - Cyrillic / 857 - Turkish / 858 - Multilingual Latin 1 + Euro / 862 -
  81. * Hebrew / 866 - Russian / 874 - Thai / 932 - Japanese Shift-JIS (DBCS) / 936 - Simplified Chinese GBK (DBCS) / 949 - Korean (DBCS) / 950
  82. * - Traditional Chinese Big5 (DBCS) / 1258 - Vietnam
  83. */
  84. #define _USE_LFN 0
  85. #define _MAX_LFN 255 /* Maximum LFN length to handle (max:255) */
  86. /*
  87. * The _USE_LFN option switches the LFN support. / / 0: Disable LFN. / 1: Enable LFN with static working buffer on the bss. NOT REENTRANT.
  88. * / 2: Enable LFN with dynamic working buffer on the caller's STACK. / / The working buffer occupies (_MAX_LFN + 1) * 2 bytes. When enable
  89. * LFN, / a Unicode - OEM code conversion function ff_convert() must be added to / the project.
  90. */
  91. #define _FS_REENTRANT 0
  92. #define _TIMEOUT 1000 /* Timeout period in unit of time ticks */
  93. #define _SYNC_t HANDLE /* Type of sync object used on the OS. */
  94. /*
  95. * e.g. HANDLE, OS_EVENT*, ID and etc..
  96. */
  97. /*
  98. * To make the FatFs module re-entrant, set _FS_REENTRANT to 1 and add user / provided synchronization handlers, ff_req_grant,
  99. * ff_rel_grant, / ff_del_syncobj and ff_cre_syncobj function to the project.
  100. */
  101. /*
  102. * End of configuration options. Do not change followings without care.
  103. */
  104. /*--------------------------------------------------------------------------*/
  105. /*
  106. * Definitions corresponds to multiple sector size
  107. */
  108. #if _MAX_SS == 512
  109. #define SS(fs) 512
  110. #else
  111. #if _MAX_SS == 1024 || _MAX_SS == 2048 || _MAX_SS == 4096
  112. #define SS(fs) ((fs)->s_size)
  113. #else
  114. #error Sector size must be 512, 1024, 2048 or 4096.
  115. #endif
  116. #endif
  117. /*
  118. * File system object structure
  119. */
  120. typedef struct _FATFS {
  121. BYTE fs_type; /* FAT sub type */
  122. BYTE drive; /* Physical drive number */
  123. BYTE csize; /* Number of sectors per cluster */
  124. BYTE n_fats; /* Number of FAT copies */
  125. BYTE wflag; /* win[] dirty flag (1:must be written back) */
  126. BYTE pad1;
  127. WORD id; /* File system mount ID */
  128. WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
  129. #if _FS_REENTRANT
  130. _SYNC_t sobj; /* Identifier of sync object */
  131. #endif
  132. #if _MAX_SS != 512U
  133. WORD s_size; /* Sector size */
  134. #endif
  135. #if !_FS_READONLY
  136. BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
  137. BYTE pad2;
  138. DWORD last_clust; /* Last allocated cluster */
  139. DWORD free_clust; /* Number of free clusters */
  140. DWORD fsi_sector; /* fsinfo sector */
  141. #endif
  142. DWORD sects_fat; /* Sectors per fat */
  143. DWORD max_clust; /* Maximum cluster# + 1. Number of clusters is max_clust - 2 */
  144. DWORD fatbase; /* FAT start sector */
  145. DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
  146. DWORD database; /* Data start sector */
  147. DWORD winsect; /* Current sector appearing in the win[] */
  148. BYTE win[_MAX_SS]; /* Disk access window for Directory/FAT */
  149. } FATFS;
  150. /*
  151. * Directory object structure
  152. */
  153. typedef struct _DIR {
  154. WORD id; /* Owner file system mount ID */
  155. WORD index; /* Current index number */
  156. FATFS *fs; /* Pointer to the owner file system object */
  157. DWORD sclust; /* Table start cluster (0:Static table) */
  158. DWORD clust; /* Current cluster */
  159. DWORD sect; /* Current sector */
  160. BYTE *dir; /* Pointer to the current SFN entry in the win[] */
  161. BYTE *fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
  162. #if _USE_LFN
  163. WCHAR *lfn; /* Pointer to the LFN working buffer */
  164. WORD lfn_idx; /* Last matched LFN index (0xFFFF:No LFN) */
  165. #endif
  166. } DIR;
  167. /*
  168. * File object structure
  169. */
  170. typedef struct _FIL {
  171. FATFS *fs; /* Pointer to the owner file system object */
  172. WORD id; /* Owner file system mount ID */
  173. BYTE flag; /* File status flags */
  174. BYTE csect; /* Sector address in the cluster */
  175. DWORD fptr; /* File R/W pointer */
  176. DWORD fsize; /* File size */
  177. DWORD org_clust; /* File start cluster */
  178. DWORD curr_clust; /* Current cluster */
  179. DWORD dsect; /* Current data sector */
  180. #if !_FS_READONLY
  181. DWORD dir_sect; /* Sector containing the directory entry */
  182. BYTE *dir_ptr; /* Ponter to the directory entry in the window */
  183. #endif
  184. #if !_FS_TINY
  185. BYTE buf[_MAX_SS]; /* File R/W buffer */
  186. #endif
  187. } FIL;
  188. /*
  189. * File status structure
  190. */
  191. typedef struct _FILINFO {
  192. DWORD fsize; /* File size */
  193. WORD fdate; /* Last modified date */
  194. WORD ftime; /* Last modified time */
  195. BYTE fattrib; /* Attribute */
  196. char fname[13]; /* Short file name (8.3 format) */
  197. #if _USE_LFN
  198. char *lfname; /* Pointer to the LFN buffer */
  199. int lfsize; /* Size of LFN buffer [bytes] */
  200. #endif
  201. } FILINFO;
  202. /*
  203. * DBCS code ranges
  204. */
  205. #if _CODE_PAGE == 932 /* CP932 (Japanese Shift-JIS) */
  206. #define _DF1S 0x81 /* DBC 1st byte range 1 start */
  207. #define _DF1E 0x9F /* DBC 1st byte range 1 end */
  208. #define _DF2S 0xE0 /* DBC 1st byte range 2 start */
  209. #define _DF2E 0xFC /* DBC 1st byte range 2 end */
  210. #define _DS1S 0x40 /* DBC 2nd byte range 1 start */
  211. #define _DS1E 0x7E /* DBC 2nd byte range 1 end */
  212. #define _DS2S 0x80 /* DBC 2nd byte range 2 start */
  213. #define _DS2E 0xFC /* DBC 2nd byte range 2 end */
  214. #elif _CODE_PAGE == 936 /* CP936 (Simplified Chinese GBK) */
  215. #define _DF1S 0x81
  216. #define _DF1E 0xFE
  217. #define _DS1S 0x40
  218. #define _DS1E 0x7E
  219. #define _DS2S 0x80
  220. #define _DS2E 0xFE
  221. #elif _CODE_PAGE == 949 /* CP949 (Korean) */
  222. #define _DF1S 0x81
  223. #define _DF1E 0xFE
  224. #define _DS1S 0x41
  225. #define _DS1E 0x5A
  226. #define _DS2S 0x61
  227. #define _DS2E 0x7A
  228. #define _DS3S 0x81
  229. #define _DS3E 0xFE
  230. #elif _CODE_PAGE == 950 /* CP950 (Traditional Chinese Big5) */
  231. #define _DF1S 0x81
  232. #define _DF1E 0xFE
  233. #define _DS1S 0x40
  234. #define _DS1E 0x7E
  235. #define _DS2S 0xA1
  236. #define _DS2E 0xFE
  237. #else /* SBCS code pages */
  238. #define _DF1S 0
  239. #endif
  240. /*
  241. * Character code support macros
  242. */
  243. #define IsUpper(c) (((c)>='A')&&((c)<='Z'))
  244. #define IsLower(c) (((c)>='a')&&((c)<='z'))
  245. #define IsDigit(c) (((c)>='0')&&((c)<='9'))
  246. #if _DF1S /* DBCS configuration */
  247. #if _DF2S /* Two 1st byte areas */
  248. #define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))
  249. #else /* One 1st byte area */
  250. #define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)
  251. #endif
  252. #if _DS3S /* Three 2nd byte areas */
  253. #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))
  254. #else /* Two 2nd byte areas */
  255. #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))
  256. #endif
  257. #else /* SBCS configuration */
  258. #define IsDBCS1(c) 0
  259. #define IsDBCS2(c) 0
  260. #endif /* _DF1S */
  261. /*
  262. * Definitions corresponds to multi partition
  263. */
  264. #if _MULTI_PARTITION /* Multiple partition configuration */
  265. typedef struct _PARTITION {
  266. BYTE pd; /* Physical drive# */
  267. BYTE pt; /* Partition # (0-3) */
  268. } PARTITION;
  269. extern
  270. const PARTITION Drives[]; /* Logical drive# to physical location conversion table */
  271. #define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */
  272. #define LD2PT(drv) (Drives[drv].pt) /* Get partition# */
  273. #else /* Single partition configuration */
  274. #define LD2PD(drv) (drv) /* Physical drive# is equal to the logical drive# */
  275. #define LD2PT(drv) 0 /* Always mounts the 1st partition */
  276. #endif
  277. /*
  278. * File function return code (FRESULT)
  279. */
  280. typedef enum {
  281. FR_OK = 0, /* 0 */
  282. FR_DISK_ERR, /* 1 */
  283. FR_INT_ERR, /* 2 */
  284. FR_NOT_READY, /* 3 */
  285. FR_NO_FILE, /* 4 */
  286. FR_NO_PATH, /* 5 */
  287. FR_INVALID_NAME, /* 6 */
  288. FR_DENIED, /* 7 */
  289. FR_EXIST, /* 8 */
  290. FR_INVALID_OBJECT, /* 9 */
  291. FR_WRITE_PROTECTED, /* 10 */
  292. FR_INVALID_DRIVE, /* 11 */
  293. FR_NOT_ENABLED, /* 12 */
  294. FR_NO_FILESYSTEM, /* 13 */
  295. FR_MKFS_ABORTED, /* 14 */
  296. FR_TIMEOUT /* 15 */
  297. } FRESULT;
  298. /*--------------------------------------------------------------*/
  299. /*
  300. * FatFs module application interface
  301. */
  302. FRESULT f_mount(BYTE, FATFS *); /* Mount/Unmount a logical drive */
  303. FRESULT f_open(FIL *, const char *, BYTE); /* Open or create a file */
  304. FRESULT f_read(FIL *, void *, UINT, UINT *); /* Read data from a file */
  305. FRESULT f_write(FIL *, const void *, UINT, UINT *); /* Write data to a file */
  306. FRESULT f_lseek(FIL *, DWORD); /* Move file pointer of a file object */
  307. FRESULT f_close(FIL *); /* Close an open file object */
  308. FRESULT f_opendir(DIR *, const char *); /* Open an existing directory */
  309. FRESULT f_readdir(DIR *, FILINFO *); /* Read a directory item */
  310. FRESULT f_stat(const char *, FILINFO *); /* Get file status */
  311. FRESULT f_getfree(const char *, DWORD *, FATFS **); /* Get number of free clusters on the drive */
  312. FRESULT f_truncate(FIL *); /* Truncate file */
  313. FRESULT f_sync(FIL *); /* Flush cached data of a writing file */
  314. FRESULT f_unlink(const char *); /* Delete an existing file or directory */
  315. FRESULT f_mkdir(const char *); /* Create a new directory */
  316. FRESULT f_chmod(const char *, BYTE, BYTE); /* Change attriburte of the file/dir */
  317. FRESULT f_utime(const char *, const FILINFO *); /* Change timestamp of the file/dir */
  318. FRESULT f_rename(const char *, const char *); /* Rename/Move a file or directory */
  319. FRESULT f_forward(FIL *, UINT(*)(const BYTE *, UINT), UINT, UINT *); /* Forward data to the stream */
  320. FRESULT f_mkfs(BYTE, BYTE, WORD); /* Create a file system on the drive */
  321. #if _USE_STRFUNC
  322. int f_putc(int, FIL *); /* Put a character to the file */
  323. int f_puts(const char *, FIL *); /* Put a string to the file */
  324. int f_printf(FIL *, const char *, ...); /* Put a formatted string to the file */
  325. char *f_gets(char *, int, FIL *); /* Get a string from the file */
  326. #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
  327. #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
  328. #ifndef EOF
  329. #define EOF -1
  330. #endif
  331. #endif
  332. /*--------------------------------------------------------------*/
  333. /*
  334. * User defined functions
  335. */
  336. /*
  337. * Real time clock
  338. */
  339. #if !_FS_READONLY
  340. DWORD get_fattime(void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
  341. /*
  342. * 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2)
  343. */
  344. #endif
  345. /*
  346. * Unicode - OEM code conversion
  347. */
  348. #if _USE_LFN
  349. WCHAR ff_convert(WCHAR, UINT);
  350. #endif
  351. /*
  352. * Sync functions
  353. */
  354. #if _FS_REENTRANT
  355. BOOL ff_cre_syncobj(BYTE, _SYNC_t *);
  356. BOOL ff_del_syncobj(_SYNC_t);
  357. BOOL ff_req_grant(_SYNC_t);
  358. void ff_rel_grant(_SYNC_t);
  359. #endif
  360. /*--------------------------------------------------------------*/
  361. /*
  362. * Flags and offset address
  363. */
  364. /*
  365. * File access control and file status flags (FIL.flag)
  366. */
  367. #define FA_READ 0x01
  368. #define FA_OPEN_EXISTING 0x00
  369. #if _FS_READONLY == 0
  370. #define FA_WRITE 0x02
  371. #define FA_CREATE_NEW 0x04
  372. #define FA_CREATE_ALWAYS 0x08
  373. #define FA_OPEN_ALWAYS 0x10
  374. #define FA__WRITTEN 0x20
  375. #define FA__DIRTY 0x40
  376. #endif
  377. #define FA__ERROR 0x80
  378. /*
  379. * FAT sub type (FATFS.fs_type)
  380. */
  381. #define FS_FAT12 1
  382. #define FS_FAT16 2
  383. #define FS_FAT32 3
  384. /*
  385. * File attribute bits for directory entry
  386. */
  387. #define AM_RDO 0x01 /* Read only */
  388. #define AM_HID 0x02 /* Hidden */
  389. #define AM_SYS 0x04 /* System */
  390. #define AM_VOL 0x08 /* Volume label */
  391. #define AM_LFN 0x0F /* LFN entry */
  392. #define AM_DIR 0x10 /* Directory */
  393. #define AM_ARC 0x20 /* Archive */
  394. #define AM_MASK 0x3F /* Mask of defined bits */
  395. /*
  396. * FatFs refers the members in the FAT structures with byte offset instead / of structure member because there are incompatibility of the
  397. * packing option / between various compilers.
  398. */
  399. #define BS_jmpBoot 0
  400. #define BS_OEMName 3
  401. #define BPB_BytsPerSec 11
  402. #define BPB_SecPerClus 13
  403. #define BPB_RsvdSecCnt 14
  404. #define BPB_NumFATs 16
  405. #define BPB_RootEntCnt 17
  406. #define BPB_TotSec16 19
  407. #define BPB_Media 21
  408. #define BPB_FATSz16 22
  409. #define BPB_SecPerTrk 24
  410. #define BPB_NumHeads 26
  411. #define BPB_HiddSec 28
  412. #define BPB_TotSec32 32
  413. #define BS_55AA 510
  414. #define BS_DrvNum 36
  415. #define BS_BootSig 38
  416. #define BS_VolID 39
  417. #define BS_VolLab 43
  418. #define BS_FilSysType 54
  419. #define BPB_FATSz32 36
  420. #define BPB_ExtFlags 40
  421. #define BPB_FSVer 42
  422. #define BPB_RootClus 44
  423. #define BPB_FSInfo 48
  424. #define BPB_BkBootSec 50
  425. #define BS_DrvNum32 64
  426. #define BS_BootSig32 66
  427. #define BS_VolID32 67
  428. #define BS_VolLab32 71
  429. #define BS_FilSysType32 82
  430. #define FSI_LeadSig 0
  431. #define FSI_StrucSig 484
  432. #define FSI_Free_Count 488
  433. #define FSI_Nxt_Free 492
  434. #define MBR_Table 446
  435. #define DIR_Name 0
  436. #define DIR_Attr 11
  437. #define DIR_NTres 12
  438. #define DIR_CrtTime 14
  439. #define DIR_CrtDate 16
  440. #define DIR_FstClusHI 20
  441. #define DIR_WrtTime 22
  442. #define DIR_WrtDate 24
  443. #define DIR_FstClusLO 26
  444. #define DIR_FileSize 28
  445. #define LDIR_Ord 0
  446. #define LDIR_Attr 11
  447. #define LDIR_Type 12
  448. #define LDIR_Chksum 13
  449. #define LDIR_FstClusLO 26
  450. /*--------------------------------*/
  451. /*
  452. * Multi-byte word access macros
  453. */
  454. #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
  455. #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
  456. #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
  457. #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
  458. #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
  459. #else /* Use byte-by-byte access to the FAT structure */
  460. #define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
  461. #define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
  462. #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
  463. #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)
  464. #endif
  465. #endif /* _FATFS */