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