/*----------------------------------------------------------------------------/\r
-/ FatFs - Generic FAT Filesystem module R0.13b /\r
+/ FatFs - Generic FAT Filesystem module R0.15 /\r
/-----------------------------------------------------------------------------/\r
/\r
-/ Copyright (C) 2018, ChaN, all right reserved.\r
+/ Copyright (C) 2022, ChaN, all right reserved.\r
/\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
\r
\r
#ifndef FF_DEFINED\r
-#define FF_DEFINED 63463 /* Revision ID */\r
+#define FF_DEFINED 80286 /* Revision ID */\r
\r
#ifdef __cplusplus\r
extern "C" {\r
#endif\r
\r
-#include "integer.h" /* Basic integer types */\r
#include "ffconf.h" /* FatFs configuration options */\r
\r
#if FF_DEFINED != FFCONF_DEF\r
#endif\r
\r
\r
+/* Integer types used for FatFs API */\r
+\r
+#if defined(_WIN32) /* Windows VC++ (for development only) */\r
+#define FF_INTDEF 2\r
+#include <windows.h>\r
+typedef unsigned __int64 QWORD;\r
+#include <float.h>\r
+#define isnan(v) _isnan(v)\r
+#define isinf(v) (!_finite(v))\r
+\r
+#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */\r
+#define FF_INTDEF 2\r
+#include <stdint.h>\r
+typedef unsigned int UINT; /* int must be 16-bit or 32-bit */\r
+typedef unsigned char BYTE; /* char must be 8-bit */\r
+typedef uint16_t WORD; /* 16-bit unsigned integer */\r
+typedef uint32_t DWORD; /* 32-bit unsigned integer */\r
+typedef uint64_t QWORD; /* 64-bit unsigned integer */\r
+typedef WORD WCHAR; /* UTF-16 character type */\r
+\r
+#else /* Earlier than C99 */\r
+#define FF_INTDEF 1\r
+typedef unsigned int UINT; /* int must be 16-bit or 32-bit */\r
+typedef unsigned char BYTE; /* char must be 8-bit */\r
+typedef unsigned short WORD; /* 16-bit unsigned integer */\r
+typedef unsigned long DWORD; /* 32-bit unsigned integer */\r
+typedef WORD WCHAR; /* UTF-16 character type */\r
+#endif\r
\r
-/* Definitions of volume management */\r
\r
-#if FF_MULTI_PARTITION /* Multiple partition configuration */\r
-typedef struct {\r
- BYTE pd; /* Physical drive number */\r
- BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */\r
-} PARTITION;\r
-extern PARTITION VolToPart[]; /* Volume - Partition resolution table */\r
-#endif\r
+/* Type of file size and LBA variables */\r
\r
-#if FF_STR_VOLUME_ID\r
-#ifndef FF_VOLUME_STRS\r
-extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */\r
+#if FF_FS_EXFAT\r
+#if FF_INTDEF != 2\r
+#error exFAT feature wants C99 or later\r
#endif\r
+typedef QWORD FSIZE_t;\r
+#if FF_LBA64\r
+typedef QWORD LBA_t;\r
+#else\r
+typedef DWORD LBA_t;\r
+#endif\r
+#else\r
+#if FF_LBA64\r
+#error exFAT needs to be enabled when enable 64-bit LBA\r
+#endif\r
+typedef DWORD FSIZE_t;\r
+typedef DWORD LBA_t;\r
#endif\r
\r
\r
\r
-/* Type of path name strings on FatFs API */\r
-\r
-#ifndef _INC_TCHAR\r
-#define _INC_TCHAR\r
+/* Type of path name strings on FatFs API (TCHAR) */\r
\r
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */\r
typedef WCHAR TCHAR;\r
#define _TEXT(x) x\r
#endif\r
\r
-#endif\r
\r
\r
+/* Definitions of volume management */\r
\r
-/* Type of file size variables */\r
+#if FF_MULTI_PARTITION /* Multiple partition configuration */\r
+typedef struct {\r
+ BYTE pd; /* Physical drive number */\r
+ BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */\r
+} PARTITION;\r
+extern PARTITION VolToPart[]; /* Volume - Partition mapping table */\r
+#endif\r
\r
-#if FF_FS_EXFAT\r
-typedef QWORD FSIZE_t;\r
-#else\r
-typedef DWORD FSIZE_t;\r
+#if FF_STR_VOLUME_ID\r
+#ifndef FF_VOLUME_STRS\r
+extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */\r
+#endif\r
#endif\r
\r
\r
/* Filesystem object structure (FATFS) */\r
\r
typedef struct {\r
- BYTE fs_type; /* Filesystem type (0:N/A) */\r
- BYTE pdrv; /* Physical drive number */\r
+ BYTE fs_type; /* Filesystem type (0:not mounted) */\r
+ BYTE pdrv; /* Volume hosting physical drive */\r
+ BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */\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
+ BYTE wflag; /* win[] status (b0:dirty) */\r
+ BYTE fsi_flag; /* FSINFO status (b7:disabled, b0:dirty) */\r
WORD id; /* Volume mount ID */\r
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */\r
WORD csize; /* Cluster size [sectors] */\r
#if FF_FS_EXFAT\r
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */\r
#endif\r
-#if FF_FS_REENTRANT\r
- FF_SYNC_t sobj; /* Identifier of sync object */\r
-#endif\r
#if !FF_FS_READONLY\r
DWORD last_clst; /* Last allocated cluster */\r
DWORD free_clst; /* Number of free clusters */\r
#endif\r
#endif\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
+ DWORD fsize; /* Number of sectors per FAT */\r
+ LBA_t volbase; /* Volume base sector */\r
+ LBA_t fatbase; /* FAT base sector */\r
+ LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */\r
+ LBA_t database; /* Data base sector */\r
+#if FF_FS_EXFAT\r
+ LBA_t bitbase; /* Allocation bitmap base sector */\r
+#endif\r
+ LBA_t winsect; /* Current sector appearing in the win[] */\r
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */\r
} FATFS;\r
\r
\r
typedef struct {\r
FATFS* fs; /* Pointer to the hosting volume of this object */\r
- WORD id; /* Hosting volume mount ID */\r
+ WORD id; /* Hosting volume's mount ID */\r
BYTE attr; /* Object attribute */\r
- BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:flagmented in this session, b2:sub-directory stretched) */\r
+ BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */\r
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */\r
FSIZE_t objsize; /* Object size (valid when sclust != 0) */\r
#if FF_FS_EXFAT\r
BYTE err; /* Abort flag (error code) */\r
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */\r
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */\r
- DWORD sect; /* Sector number appearing in buf[] (0:invalid) */\r
+ LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */\r
#if !FF_FS_READONLY\r
- DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */\r
+ LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */\r
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */\r
#endif\r
#if FF_USE_FASTSEEK\r
FFOBJID obj; /* Object identifier */\r
DWORD dptr; /* Current read/write offset */\r
DWORD clust; /* Current cluster */\r
- DWORD sect; /* Current sector (0:Read operation has terminated) */\r
+ LBA_t sect; /* Current sector (0:Read operation has terminated) */\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 FF_USE_LFN\r
WORD ftime; /* Modified time */\r
BYTE fattrib; /* File attribute */\r
#if FF_USE_LFN\r
- TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */\r
+ TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */\r
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */\r
#else\r
TCHAR fname[12 + 1]; /* File name */\r
\r
\r
\r
+/* Format parameter structure (MKFS_PARM) */\r
+\r
+typedef struct {\r
+ BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */\r
+ BYTE n_fat; /* Number of FATs */\r
+ UINT align; /* Data area alignment (sector) */\r
+ UINT n_root; /* Number of root directory entries */\r
+ DWORD au_size; /* Cluster size (byte) */\r
+} MKFS_PARM;\r
+\r
+\r
+\r
/* File function return code (FRESULT) */\r
\r
typedef enum {\r
\r
\r
\r
+\r
+/*--------------------------------------------------------------*/\r
+/* FatFs Module Application Interface */\r
/*--------------------------------------------------------------*/\r
-/* FatFs module application interface */\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_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_expand (FIL* fp, FSIZE_t fsz, 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 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
+FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */\r
+FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */\r
FRESULT f_setcp (WORD cp); /* Set current code page */\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
+/* Some API fucntions are implemented as macro */\r
+\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_rmdir(path) f_unlink(path)\r
#define f_unmount(path) f_mount(0, path, 0)\r
\r
-#ifndef EOF\r
-#define EOF (-1)\r
-#endif\r
-\r
\r
\r
\r
/*--------------------------------------------------------------*/\r
-/* Additional user defined functions */\r
+/* Additional Functions */\r
+/*--------------------------------------------------------------*/\r
\r
-/* RTC function */\r
+/* RTC function (provided by user) */\r
#if !FF_FS_READONLY && !FF_FS_NORTC\r
-DWORD get_fattime (void);\r
+DWORD get_fattime (void); /* Get current time */\r
#endif\r
\r
-/* LFN support functions */\r
-#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */\r
+\r
+/* LFN support functions (defined in ffunicode.c) */\r
+\r
+#if FF_USE_LFN >= 1\r
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */\r
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */\r
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */\r
#endif\r
-#if FF_USE_LFN == 3 /* Dynamic memory allocation */\r
-void* ff_memalloc (UINT msize); /* Allocate memory block */\r
-void ff_memfree (void* mblock); /* Free memory block */\r
-#endif\r
\r
-/* Sync functions */\r
-#if FF_FS_REENTRANT\r
-int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */\r
-int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */\r
-void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */\r
-int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */\r
+\r
+/* O/S dependent functions (samples available in ffsystem.c) */\r
+\r
+#if FF_USE_LFN == 3 /* Dynamic memory allocation */\r
+void* ff_memalloc (UINT msize); /* Allocate memory block */\r
+void ff_memfree (void* mblock); /* Free memory block */\r
+#endif\r
+#if FF_FS_REENTRANT /* Sync functions */\r
+int ff_mutex_create (int vol); /* Create a sync object */\r
+void ff_mutex_delete (int vol); /* Delete a sync object */\r
+int ff_mutex_take (int vol); /* Lock sync object */\r
+void ff_mutex_give (int vol); /* Unlock sync object */\r
#endif\r
\r
\r
\r
\r
/*--------------------------------------------------------------*/\r
-/* Flags and offset address */\r
-\r
+/* Flags and Offset Address */\r
+/*--------------------------------------------------------------*/\r
\r
/* File access mode and open method flags (3rd argument of f_open) */\r
#define FA_READ 0x01\r