|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
// clang-format off
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------/
|
|
|
|
|
/ FatFs - Generic FAT Filesystem module R0.14 /
|
|
|
|
|
/ FatFs - Generic FAT Filesystem module R0.15 /
|
|
|
|
|
/-----------------------------------------------------------------------------/
|
|
|
|
|
/
|
|
|
|
|
/ Copyright (C) 2019, ChaN, all right reserved.
|
|
|
|
|
/ Copyright (C) 2022, ChaN, all right reserved.
|
|
|
|
|
/
|
|
|
|
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
|
|
|
|
/ source and binary forms, with or without modification, are permitted provided
|
|
|
|
@ -22,7 +22,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FF_DEFINED
|
|
|
|
|
#define FF_DEFINED 86606 /* Revision ID */
|
|
|
|
|
#define FF_DEFINED 80286 /* Revision ID */
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
@ -37,10 +37,14 @@ extern "C" {
|
|
|
|
|
|
|
|
|
|
/* Integer types used for FatFs API */
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) /* Main development platform */
|
|
|
|
|
#if defined(_WIN32) /* Windows VC++ (for development only) */
|
|
|
|
|
#define FF_INTDEF 2
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
typedef unsigned __int64 QWORD;
|
|
|
|
|
#include <float.h>
|
|
|
|
|
#define isnan(v) _isnan(v)
|
|
|
|
|
#define isinf(v) (!_finite(v))
|
|
|
|
|
|
|
|
|
|
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
|
|
|
|
#define FF_INTDEF 2
|
|
|
|
|
#include <stdint.h>
|
|
|
|
@ -50,6 +54,7 @@ typedef uint16_t WORD; /* 16-bit unsigned integer */
|
|
|
|
|
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
|
|
|
|
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
|
|
|
|
typedef WORD WCHAR; /* UTF-16 character type */
|
|
|
|
|
|
|
|
|
|
#else /* Earlier than C99 */
|
|
|
|
|
#define FF_INTDEF 1
|
|
|
|
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
|
|
|
@ -60,28 +65,29 @@ typedef WORD WCHAR; /* UTF-16 character type */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Definitions of volume management */
|
|
|
|
|
/* Type of file size and LBA variables */
|
|
|
|
|
|
|
|
|
|
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
|
|
|
|
typedef struct {
|
|
|
|
|
BYTE pd; /* Physical drive number */
|
|
|
|
|
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
|
|
|
|
} PARTITION;
|
|
|
|
|
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
|
|
|
|
|
#if FF_FS_EXFAT
|
|
|
|
|
#if FF_INTDEF != 2
|
|
|
|
|
#error exFAT feature wants C99 or later
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if FF_STR_VOLUME_ID
|
|
|
|
|
#ifndef FF_VOLUME_STRS
|
|
|
|
|
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
|
|
|
|
typedef QWORD FSIZE_t;
|
|
|
|
|
#if FF_LBA64
|
|
|
|
|
typedef QWORD LBA_t;
|
|
|
|
|
#else
|
|
|
|
|
typedef DWORD LBA_t;
|
|
|
|
|
#endif
|
|
|
|
|
#else
|
|
|
|
|
#if FF_LBA64
|
|
|
|
|
#error exFAT needs to be enabled when enable 64-bit LBA
|
|
|
|
|
#endif
|
|
|
|
|
typedef DWORD FSIZE_t;
|
|
|
|
|
typedef DWORD LBA_t;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Type of path name strings on FatFs API */
|
|
|
|
|
|
|
|
|
|
#ifndef _INC_TCHAR
|
|
|
|
|
#define _INC_TCHAR
|
|
|
|
|
/* Type of path name strings on FatFs API (TCHAR) */
|
|
|
|
|
|
|
|
|
|
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
|
|
|
|
typedef WCHAR TCHAR;
|
|
|
|
@ -103,28 +109,22 @@ typedef char TCHAR;
|
|
|
|
|
#define _TEXT(x) x
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Definitions of volume management */
|
|
|
|
|
|
|
|
|
|
/* Type of file size and LBA variables */
|
|
|
|
|
|
|
|
|
|
#if FF_FS_EXFAT
|
|
|
|
|
#if FF_INTDEF != 2
|
|
|
|
|
#error exFAT feature wants C99 or later
|
|
|
|
|
#endif
|
|
|
|
|
typedef QWORD FSIZE_t;
|
|
|
|
|
#if FF_LBA64
|
|
|
|
|
typedef QWORD LBA_t;
|
|
|
|
|
#else
|
|
|
|
|
typedef DWORD LBA_t;
|
|
|
|
|
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
|
|
|
|
typedef struct {
|
|
|
|
|
BYTE pd; /* Physical drive number */
|
|
|
|
|
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
|
|
|
|
} PARTITION;
|
|
|
|
|
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
|
|
|
|
|
#endif
|
|
|
|
|
#else
|
|
|
|
|
#if FF_LBA64
|
|
|
|
|
#error exFAT needs to be enabled when enable 64-bit LBA
|
|
|
|
|
|
|
|
|
|
#if FF_STR_VOLUME_ID
|
|
|
|
|
#ifndef FF_VOLUME_STRS
|
|
|
|
|
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
|
|
|
|
#endif
|
|
|
|
|
typedef DWORD FSIZE_t;
|
|
|
|
|
typedef DWORD LBA_t;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -133,10 +133,11 @@ typedef DWORD LBA_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
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 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 n_rootdir; /* Number of root directory entries (FAT12/16) */
|
|
|
|
|
WORD csize; /* Cluster size [sectors] */
|
|
|
|
@ -149,9 +150,6 @@ typedef struct {
|
|
|
|
|
#if FF_FS_EXFAT
|
|
|
|
|
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
|
|
|
|
#endif
|
|
|
|
|
#if FF_FS_REENTRANT
|
|
|
|
|
FF_SYNC_t sobj; /* Identifier of sync object */
|
|
|
|
|
#endif
|
|
|
|
|
#if !FF_FS_READONLY
|
|
|
|
|
DWORD last_clst; /* Last allocated cluster */
|
|
|
|
|
DWORD free_clst; /* Number of free clusters */
|
|
|
|
@ -165,10 +163,10 @@ typedef struct {
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
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 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 */
|
|
|
|
|
#if FF_FS_EXFAT
|
|
|
|
|
LBA_t bitbase; /* Allocation bitmap base sector */
|
|
|
|
@ -183,7 +181,7 @@ typedef struct {
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
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 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) */
|
|
|
|
@ -300,8 +298,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_close (FIL* fp); /* Close an open file object */
|
|
|
|
@ -338,6 +338,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 */
|
|
|
|
|
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_error(fp) ((fp)->err)
|
|
|
|
|
#define f_tell(fp) ((fp)->fptr)
|
|
|
|
@ -347,46 +349,47 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil
|
|
|
|
|
#define f_rmdir(path) f_unlink(path)
|
|
|
|
|
#define f_unmount(path) f_mount(0, path, 0)
|
|
|
|
|
|
|
|
|
|
#ifndef EOF
|
|
|
|
|
#define EOF (-1)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------*/
|
|
|
|
|
/* Additional user defined functions */
|
|
|
|
|
/* Additional Functions */
|
|
|
|
|
/*--------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/* RTC function */
|
|
|
|
|
/* RTC function (provided by user) */
|
|
|
|
|
#if !FF_FS_READONLY && !FF_FS_NORTC
|
|
|
|
|
DWORD get_fattime (void);
|
|
|
|
|
DWORD get_fattime (void); /* Get current time */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* LFN support functions */
|
|
|
|
|
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
|
|
|
|
|
|
|
|
|
/* 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_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
|
|
|
|
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------*/
|
|
|
|
|
/* Flags and offset address */
|
|
|
|
|
|
|
|
|
|
/* Flags and Offset Address */
|
|
|
|
|
/*--------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/* File access mode and open method flags (3rd argument of f_open) */
|
|
|
|
|
#define FA_READ 0x01
|
|
|
|
|