|
@@ -1,8 +1,8 @@
|
|
/*----------------------------------------------------------------------------/
|
|
/*----------------------------------------------------------------------------/
|
|
-/ FatFs - Generic FAT Filesystem module R0.14b /
|
|
|
|
|
|
+/ FatFs - Generic FAT Filesystem module R0.15 /
|
|
/-----------------------------------------------------------------------------/
|
|
/-----------------------------------------------------------------------------/
|
|
/
|
|
/
|
|
-/ Copyright (C) 2021, ChaN, all right reserved.
|
|
|
|
|
|
+/ Copyright (C) 2022, ChaN, all right reserved.
|
|
/
|
|
/
|
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
|
/ source and binary forms, with or without modification, are permitted provided
|
|
/ source and binary forms, with or without modification, are permitted provided
|
|
@@ -20,7 +20,7 @@
|
|
|
|
|
|
|
|
|
|
#ifndef FF_DEFINED
|
|
#ifndef FF_DEFINED
|
|
-#define FF_DEFINED 86631 /* Revision ID */
|
|
|
|
|
|
+#define FF_DEFINED 80286 /* Revision ID */
|
|
|
|
|
|
#ifdef __cplusplus
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
extern "C" {
|
|
@@ -53,7 +53,7 @@ typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
|
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
|
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
|
typedef WORD WCHAR; /* UTF-16 character type */
|
|
typedef WORD WCHAR; /* UTF-16 character type */
|
|
|
|
|
|
-#else /* Earlier than C99 */
|
|
|
|
|
|
+#else /* Earlier than C99 */
|
|
#define FF_INTDEF 1
|
|
#define FF_INTDEF 1
|
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
|
typedef unsigned char BYTE; /* char must be 8-bit */
|
|
typedef unsigned char BYTE; /* char must be 8-bit */
|
|
@@ -87,7 +87,7 @@ typedef DWORD LBA_t;
|
|
|
|
|
|
/* Type of path name strings on FatFs API (TCHAR) */
|
|
/* Type of path name strings on FatFs API (TCHAR) */
|
|
|
|
|
|
-#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
|
|
|
|
|
+#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
|
typedef WCHAR TCHAR;
|
|
typedef WCHAR TCHAR;
|
|
#define _T(x) L ## x
|
|
#define _T(x) L ## x
|
|
#define _TEXT(x) L ## x
|
|
#define _TEXT(x) L ## x
|
|
@@ -131,10 +131,11 @@ extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
|
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
|
- BYTE pdrv; /* Associated physical drive */
|
|
|
|
|
|
+ BYTE pdrv; /* Volume hosting physical drive */
|
|
|
|
+ BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */
|
|
BYTE n_fats; /* Number of FATs (1 or 2) */
|
|
BYTE n_fats; /* Number of FATs (1 or 2) */
|
|
- BYTE wflag; /* win[] flag (b0:dirty) */
|
|
|
|
- BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
|
|
|
|
|
+ BYTE wflag; /* win[] status (b0:dirty) */
|
|
|
|
+ BYTE fsi_flag; /* FSINFO status (b7:disabled, b0:dirty) */
|
|
WORD id; /* Volume mount ID */
|
|
WORD id; /* Volume mount ID */
|
|
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
|
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
|
WORD csize; /* Cluster size [sectors] */
|
|
WORD csize; /* Cluster size [sectors] */
|
|
@@ -147,9 +148,6 @@ typedef struct {
|
|
#if FF_FS_EXFAT
|
|
#if FF_FS_EXFAT
|
|
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
|
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
|
#endif
|
|
#endif
|
|
-#if FF_FS_REENTRANT
|
|
|
|
- FF_SYNC_t sobj; /* Identifier of sync object */
|
|
|
|
-#endif
|
|
|
|
#if !FF_FS_READONLY
|
|
#if !FF_FS_READONLY
|
|
DWORD last_clst; /* Last allocated cluster */
|
|
DWORD last_clst; /* Last allocated cluster */
|
|
DWORD free_clst; /* Number of free clusters */
|
|
DWORD free_clst; /* Number of free clusters */
|
|
@@ -163,10 +161,10 @@ typedef struct {
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
|
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
|
- DWORD fsize; /* Size of an FAT [sectors] */
|
|
|
|
|
|
+ DWORD fsize; /* Number of sectors per FAT */
|
|
LBA_t volbase; /* Volume base sector */
|
|
LBA_t volbase; /* Volume base sector */
|
|
LBA_t fatbase; /* FAT base sector */
|
|
LBA_t fatbase; /* FAT base sector */
|
|
- LBA_t dirbase; /* Root directory base sector/cluster */
|
|
|
|
|
|
+ LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */
|
|
LBA_t database; /* Data base sector */
|
|
LBA_t database; /* Data base sector */
|
|
#if FF_FS_EXFAT
|
|
#if FF_FS_EXFAT
|
|
LBA_t bitbase; /* Allocation bitmap base sector */
|
|
LBA_t bitbase; /* Allocation bitmap base sector */
|
|
@@ -181,7 +179,7 @@ typedef struct {
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
FATFS* fs; /* Pointer to the hosting volume of this object */
|
|
FATFS* fs; /* Pointer to the hosting volume of this object */
|
|
- WORD id; /* Hosting volume mount ID */
|
|
|
|
|
|
+ WORD id; /* Hosting volume's mount ID */
|
|
BYTE attr; /* Object attribute */
|
|
BYTE attr; /* Object attribute */
|
|
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
|
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
|
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
|
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
|
@@ -250,7 +248,7 @@ typedef struct {
|
|
WORD ftime; /* Modified time */
|
|
WORD ftime; /* Modified time */
|
|
BYTE fattrib; /* File attribute */
|
|
BYTE fattrib; /* File attribute */
|
|
#if FF_USE_LFN
|
|
#if FF_USE_LFN
|
|
- TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
|
|
|
|
|
|
+ TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */
|
|
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
|
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
|
#else
|
|
#else
|
|
TCHAR fname[12 + 1]; /* File name */
|
|
TCHAR fname[12 + 1]; /* File name */
|
|
@@ -298,8 +296,10 @@ typedef enum {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+/*--------------------------------------------------------------*/
|
|
|
|
+/* FatFs Module Application Interface */
|
|
/*--------------------------------------------------------------*/
|
|
/*--------------------------------------------------------------*/
|
|
-/* FatFs module application interface */
|
|
|
|
|
|
|
|
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
|
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
|
FRESULT f_close (FIL* fp); /* Close an open file object */
|
|
FRESULT f_close (FIL* fp); /* Close an open file object */
|
|
@@ -336,6 +336,8 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
|
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
|
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
|
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
|
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
|
|
|
|
|
|
|
+/* Some API fucntions are implemented as macro */
|
|
|
|
+
|
|
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
|
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
|
#define f_error(fp) ((fp)->err)
|
|
#define f_error(fp) ((fp)->err)
|
|
#define f_tell(fp) ((fp)->fptr)
|
|
#define f_tell(fp) ((fp)->fptr)
|
|
@@ -349,60 +351,43 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------*/
|
|
/*--------------------------------------------------------------*/
|
|
-/* Additional user defined functions */
|
|
|
|
|
|
+/* Additional Functions */
|
|
|
|
+/*--------------------------------------------------------------*/
|
|
|
|
|
|
-/* RTC function */
|
|
|
|
|
|
+/* RTC function (provided by user) */
|
|
#if !FF_FS_READONLY && !FF_FS_NORTC
|
|
#if !FF_FS_READONLY && !FF_FS_NORTC
|
|
-DWORD get_fattime (void);
|
|
|
|
|
|
+DWORD get_fattime (void); /* Get current time */
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-/* LFN support functions */
|
|
|
|
-#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
|
|
|
-# if FF_CODE_PAGE == 819
|
|
|
|
- static inline WCHAR ff_oem2uni (WCHAR oem, WORD cp)
|
|
|
|
- {
|
|
|
|
- return oem;
|
|
|
|
- }
|
|
|
|
- static inline WCHAR ff_uni2oem (WCHAR uni, WORD cp)
|
|
|
|
- {
|
|
|
|
- if (cp != FF_CODE_PAGE) /* Should never happen */
|
|
|
|
- return uni < 0x80 ? uni : 0;
|
|
|
|
- else
|
|
|
|
- return uni < 0x100 ? uni : 0;
|
|
|
|
- }
|
|
|
|
- static inline DWORD ff_wtoupper (DWORD uni)
|
|
|
|
- {
|
|
|
|
- if (((uni >= 'a' && uni <= 'z') ||
|
|
|
|
- (uni >= 0xe0 && uni <= 0xfe && uni != 0xf7)))
|
|
|
|
- return uni - 0x20;
|
|
|
|
- else
|
|
|
|
- return uni;
|
|
|
|
- }
|
|
|
|
-# else
|
|
|
|
|
|
+
|
|
|
|
+/* LFN support functions (defined in ffunicode.c) */
|
|
|
|
+
|
|
|
|
+#if FF_USE_LFN >= 1
|
|
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
|
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
|
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
|
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
|
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
|
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
|
-# endif
|
|
|
|
-#endif
|
|
|
|
-#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
|
|
|
-void* ff_memalloc (UINT msize); /* Allocate memory block */
|
|
|
|
-void ff_memfree (void* mblock); /* Free memory block */
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-/* Sync functions */
|
|
|
|
-#if FF_FS_REENTRANT
|
|
|
|
-int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
|
|
|
|
-int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
|
|
|
|
-void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
|
|
|
|
-int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
|
|
|
|
|
+
|
|
|
|
+/* O/S dependent functions (samples available in ffsystem.c) */
|
|
|
|
+
|
|
|
|
+#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
|
|
|
+void* ff_memalloc (UINT msize); /* Allocate memory block */
|
|
|
|
+void ff_memfree (void* mblock); /* Free memory block */
|
|
|
|
+#endif
|
|
|
|
+#if FF_FS_REENTRANT /* Sync functions */
|
|
|
|
+int ff_mutex_create (int vol); /* Create a sync object */
|
|
|
|
+void ff_mutex_delete (int vol); /* Delete a sync object */
|
|
|
|
+int ff_mutex_take (int vol); /* Lock sync object */
|
|
|
|
+void ff_mutex_give (int vol); /* Unlock sync object */
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------*/
|
|
/*--------------------------------------------------------------*/
|
|
-/* Flags and offset address */
|
|
|
|
-
|
|
|
|
|
|
+/* Flags and Offset Address */
|
|
|
|
+/*--------------------------------------------------------------*/
|
|
|
|
|
|
/* File access mode and open method flags (3rd argument of f_open) */
|
|
/* File access mode and open method flags (3rd argument of f_open) */
|
|
#define FA_READ 0x01
|
|
#define FA_READ 0x01
|