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