-/*---------------------------------------------------------------------------/\r
-/ FatFs - FAT file system module include file R0.10c (C)ChaN, 2014\r
-/----------------------------------------------------------------------------/\r
-/ FatFs module is a generic FAT file system module for small embedded systems.\r
-/ This is a free software that opened for education, research and commercial\r
-/ developments under license policy of following terms.\r
+/*----------------------------------------------------------------------------/\r
+/ FatFs - Generic FAT file system module R0.12b /\r
+/-----------------------------------------------------------------------------/\r
/\r
-/ Copyright (C) 2014, ChaN, all right reserved.\r
+/ Copyright (C) 2016, ChaN, all right reserved.\r
/\r
-/ * The FatFs module is a free software and there is NO WARRANTY.\r
-/ * No restriction on use. You can use, modify and redistribute it for\r
-/ personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.\r
-/ * Redistributions of source code must retain the above copyright notice.\r
+/ FatFs module is an open source software. Redistribution and use of FatFs in\r
+/ source and binary forms, with or without modification, are permitted provided\r
+/ that the following condition is met:\r
+\r
+/ 1. Redistributions of source code must retain the above copyright notice,\r
+/ this condition and the following disclaimer.\r
/\r
+/ This software is provided by the copyright holder and contributors "AS IS"\r
+/ and any warranties related to this software are DISCLAIMED.\r
+/ The copyright owner or contributors be NOT LIABLE for any damages caused\r
+/ by use of this software.\r
/----------------------------------------------------------------------------*/\r
\r
+\r
#ifndef _FATFS\r
-#define _FATFS 80376 /* Revision ID */\r
+#define _FATFS 68020 /* Revision ID */\r
\r
#ifdef __cplusplus\r
extern "C" {\r
\r
#include "integer.h" /* Basic integer types */\r
#include "ffconf.h" /* FatFs configuration options */\r
+\r
#if _FATFS != _FFCONF\r
#error Wrong configuration file (ffconf.h).\r
#endif\r
\r
/* Type of path name strings on FatFs API */\r
\r
-#if _LFN_UNICODE /* Unicode string */\r
-#if !_USE_LFN\r
+#if _LFN_UNICODE /* Unicode (UTF-16) string */\r
+#if _USE_LFN == 0\r
#error _LFN_UNICODE must be 0 at non-LFN cfg.\r
#endif\r
#ifndef _INC_TCHAR\r
#define _T(x) L ## x\r
#define _TEXT(x) L ## x\r
#endif\r
-\r
#else /* ANSI/OEM string */\r
#ifndef _INC_TCHAR\r
typedef char TCHAR;\r
#define _T(x) x\r
#define _TEXT(x) x\r
#endif\r
+#endif\r
\r
+\r
+\r
+/* Type of file size variables */\r
+\r
+#if _FS_EXFAT\r
+#if _USE_LFN == 0\r
+#error LFN must be enabled when enable exFAT\r
+#endif\r
+typedef QWORD FSIZE_t;\r
+#else\r
+typedef DWORD FSIZE_t;\r
#endif\r
\r
\r
/* File system object structure (FATFS) */\r
\r
typedef struct {\r
- BYTE fs_type; /* FAT sub-type (0:Not mounted) */\r
+ BYTE fs_type; /* File system type (0:N/A) */\r
BYTE drv; /* Physical drive number */\r
- BYTE csize; /* Sectors per cluster (1,2,4...128) */\r
- BYTE n_fats; /* Number of FAT copies (1 or 2) */\r
+ BYTE n_fats; /* Number of FATs (1 or 2) */\r
BYTE wflag; /* win[] flag (b0:dirty) */\r
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */\r
WORD id; /* File system mount ID */\r
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */\r
+ WORD csize; /* Cluster size [sectors] */\r
#if _MAX_SS != _MIN_SS\r
- WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */\r
+ WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */\r
+#endif\r
+#if _USE_LFN != 0\r
+ WCHAR* lfnbuf; /* LFN working buffer */\r
+#endif\r
+#if _FS_EXFAT\r
+ BYTE* dirbuf; /* Directory entry block scratchpad buffer */\r
#endif\r
#if _FS_REENTRANT\r
_SYNC_t sobj; /* Identifier of sync object */\r
#endif\r
#if !_FS_READONLY\r
- DWORD last_clust; /* Last allocated cluster */\r
- DWORD free_clust; /* Number of free clusters */\r
+ DWORD last_clst; /* Last allocated cluster */\r
+ DWORD free_clst; /* Number of free clusters */\r
#endif\r
-#if _FS_RPATH\r
+#if _FS_RPATH != 0\r
DWORD cdir; /* Current directory start cluster (0:root) */\r
+#if _FS_EXFAT\r
+ DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */\r
+ DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */\r
+ DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */\r
+#endif\r
#endif\r
- DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */\r
- DWORD fsize; /* Sectors per FAT */\r
- DWORD volbase; /* Volume start sector */\r
- DWORD fatbase; /* FAT start sector */\r
- DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */\r
- DWORD database; /* Data start sector */\r
+ DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */\r
+ DWORD fsize; /* Size of an FAT [sectors] */\r
+ DWORD volbase; /* Volume base sector */\r
+ DWORD fatbase; /* FAT base sector */\r
+ DWORD dirbase; /* Root directory base sector/cluster */\r
+ DWORD database; /* Data base sector */\r
DWORD winsect; /* Current sector appearing in the win[] */\r
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */\r
} FATFS;\r
\r
\r
\r
+/* Object ID and allocation information (_FDID) */\r
+\r
+typedef struct {\r
+ FATFS* fs; /* Pointer to the owner file system object */\r
+ WORD id; /* Owner file system mount ID */\r
+ BYTE attr; /* Object attribute */\r
+ BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous (no data on FAT), =3:got flagmented, b2:sub-directory stretched) */\r
+ DWORD sclust; /* Object start cluster (0:no cluster or root directory) */\r
+ FSIZE_t objsize; /* Object size (valid when sclust != 0) */\r
+#if _FS_EXFAT\r
+ DWORD n_cont; /* Size of coutiguous part, clusters - 1 (valid when stat == 3) */\r
+ DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */\r
+ DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */\r
+ DWORD c_ofs; /* Offset in the containing directory (valid when sclust != 0) */\r
+#endif\r
+#if _FS_LOCK != 0\r
+ UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */\r
+#endif\r
+} _FDID;\r
+\r
+\r
+\r
/* File object structure (FIL) */\r
\r
typedef struct {\r
- FATFS* fs; /* Pointer to the related file system object (**do not change order**) */\r
- WORD id; /* Owner file system mount ID (**do not change order**) */\r
- BYTE flag; /* Status flags */\r
+ _FDID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */\r
+ BYTE flag; /* File status flags */\r
BYTE err; /* Abort flag (error code) */\r
- DWORD fptr; /* File read/write pointer (Zeroed on file open) */\r
- DWORD fsize; /* File size */\r
- DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */\r
- DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */\r
- DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */\r
+ FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */\r
+ DWORD clust; /* Current cluster of fpter (invalid when fprt is 0) */\r
+ DWORD sect; /* Sector number appearing in buf[] (0:invalid) */\r
#if !_FS_READONLY\r
DWORD dir_sect; /* Sector number containing the directory entry */\r
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */\r
#endif\r
#if _USE_FASTSEEK\r
- DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */\r
-#endif\r
-#if _FS_LOCK\r
- UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */\r
+ DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */\r
#endif\r
#if !_FS_TINY\r
BYTE buf[_MAX_SS]; /* File private data read/write window */\r
/* Directory object structure (DIR) */\r
\r
typedef struct {\r
- FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */\r
- WORD id; /* Owner file system mount ID (**do not change order**) */\r
- WORD index; /* Current read/write index number */\r
- DWORD sclust; /* Table start cluster (0:Root dir) */\r
+ _FDID obj; /* Object identifier */\r
+ DWORD dptr; /* Current read/write offset */\r
DWORD clust; /* Current cluster */\r
DWORD sect; /* Current sector */\r
- BYTE* dir; /* Pointer to the current SFN entry in the win[] */\r
- BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */\r
-#if _FS_LOCK\r
- UINT lockid; /* File lock ID (index of file semaphore table Files[]) */\r
+ BYTE* dir; /* Pointer to the directory item in the win[] */\r
+ BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */\r
+#if _USE_LFN != 0\r
+ DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */\r
#endif\r
-#if _USE_LFN\r
- WCHAR* lfn; /* Pointer to the LFN working buffer */\r
- WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */\r
+#if _USE_FIND\r
+ const TCHAR* pat; /* Pointer to the name matching pattern */\r
#endif\r
} DIR;\r
\r
\r
\r
-/* File status structure (FILINFO) */\r
+/* File information structure (FILINFO) */\r
\r
typedef struct {\r
- DWORD fsize; /* File size */\r
- WORD fdate; /* Last modified date */\r
- WORD ftime; /* Last modified time */\r
- BYTE fattrib; /* Attribute */\r
- TCHAR fname[13]; /* Short file name (8.3 format) */\r
-#if _USE_LFN\r
- TCHAR* lfname; /* Pointer to the LFN buffer */\r
- UINT lfsize; /* Size of LFN buffer in TCHAR */\r
+ FSIZE_t fsize; /* File size */\r
+ WORD fdate; /* Modified date */\r
+ WORD ftime; /* Modified time */\r
+ BYTE fattrib; /* File attribute */\r
+#if _USE_LFN != 0\r
+ TCHAR altname[13]; /* Altenative file name */\r
+ TCHAR fname[_MAX_LFN + 1]; /* Primary file name */\r
+#else\r
+ TCHAR fname[13]; /* File name */\r
#endif\r
} FILINFO;\r
\r
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */\r
FR_NOT_ENABLED, /* (12) The volume has no work area */\r
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */\r
- FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */\r
+ FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */\r
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */\r
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */\r
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */\r
- FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */\r
+ FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */\r
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */\r
} FRESULT;\r
\r
\r
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */\r
FRESULT f_close (FIL* fp); /* Close an open file object */\r
-FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */\r
-FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */\r
-FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */\r
-FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */\r
-FRESULT f_truncate (FIL* fp); /* Truncate file */\r
-FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */\r
+FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */\r
+FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */\r
+FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */\r
+FRESULT f_truncate (FIL* fp); /* Truncate the file */\r
+FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */\r
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */\r
FRESULT f_closedir (DIR* dp); /* Close an open directory */\r
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */\r
+FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */\r
+FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */\r
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */\r
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */\r
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */\r
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */\r
-FRESULT f_chmod (const TCHAR* path, BYTE value, BYTE mask); /* Change attribute of the file/dir */\r
-FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */\r
+FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */\r
+FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */\r
FRESULT f_chdir (const TCHAR* path); /* Change current directory */\r
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */\r
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */\r
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */\r
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */\r
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */\r
+FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */\r
+FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */\r
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */\r
-FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */\r
-FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */\r
+FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */\r
+FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */\r
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */\r
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */\r
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */\r
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */\r
\r
-#define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))\r
+#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))\r
#define f_error(fp) ((fp)->err)\r
#define f_tell(fp) ((fp)->fptr)\r
-#define f_size(fp) ((fp)->fsize)\r
+#define f_size(fp) ((fp)->obj.objsize)\r
+#define f_rewind(fp) f_lseek((fp), 0)\r
+#define f_rewinddir(dp) f_readdir((dp), 0)\r
\r
#ifndef EOF\r
#define EOF (-1)\r
#endif\r
\r
/* Unicode support functions */\r
-#if _USE_LFN /* Unicode - OEM code conversion */\r
+#if _USE_LFN != 0 /* Unicode - OEM code conversion */\r
WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */\r
WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */\r
#if _USE_LFN == 3 /* Memory functions */\r
/* Flags and offset address */\r
\r
\r
-/* File access control and file status flags (FIL.flag) */\r
-\r
+/* File access mode and open method flags (3rd argument of f_open) */\r
#define FA_READ 0x01\r
-#define FA_OPEN_EXISTING 0x00\r
-\r
-#if !_FS_READONLY\r
#define FA_WRITE 0x02\r
+#define FA_OPEN_EXISTING 0x00\r
#define FA_CREATE_NEW 0x04\r
#define FA_CREATE_ALWAYS 0x08\r
#define FA_OPEN_ALWAYS 0x10\r
-#define FA__WRITTEN 0x20\r
-#define FA__DIRTY 0x40\r
-#endif\r
+#define FA_OPEN_APPEND 0x30\r
\r
+/* Fast seek controls (2nd argument of f_lseek) */\r
+#define CREATE_LINKMAP ((FSIZE_t)0 - 1)\r
\r
-/* FAT sub type (FATFS.fs_type) */\r
+/* Format options (2nd argument of f_mkfs) */\r
+#define FM_FAT 0x01\r
+#define FM_FAT32 0x02\r
+#define FM_EXFAT 0x04\r
+#define FM_ANY 0x07\r
+#define FM_SFD 0x08\r
\r
+/* Filesystem type (FATFS.fs_type) */\r
#define FS_FAT12 1\r
#define FS_FAT16 2\r
#define FS_FAT32 3\r
+#define FS_EXFAT 4\r
\r
-\r
-/* File attribute bits for directory entry */\r
-\r
+/* File attribute bits for directory entry (FILINFO.fattrib) */\r
#define AM_RDO 0x01 /* Read only */\r
#define AM_HID 0x02 /* Hidden */\r
#define AM_SYS 0x04 /* System */\r
-#define AM_VOL 0x08 /* Volume label */\r
-#define AM_LFN 0x0F /* LFN entry */\r
#define AM_DIR 0x10 /* Directory */\r
#define AM_ARC 0x20 /* Archive */\r
-#define AM_MASK 0x3F /* Mask of defined bits */\r
-\r
-\r
-/* Fast seek feature */\r
-#define CREATE_LINKMAP 0xFFFFFFFF\r
\r
\r
-\r
-/*--------------------------------*/\r
-/* Multi-byte word access macros */\r
-\r
-#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */\r
-#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))\r
-#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))\r
-#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)\r
-#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)\r
-#else /* Use byte-by-byte access to the FAT structure */\r
-#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))\r
-#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))\r
-#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)\r
-#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)\r
-#endif\r
-\r
#ifdef __cplusplus\r
}\r
#endif\r