image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
ff.c File Reference
#include <string.h>
#include "ff.h"
#include "diskio.h"
#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct  FILESEM
 
struct  putbuff
 

Macros

#define MAX_DIR   0x200000 /* Max size of FAT directory */
 
#define MAX_DIR_EX   0x10000000 /* Max size of exFAT directory */
 
#define MAX_FAT12   0xFF5 /* Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) */
 
#define MAX_FAT16   0xFFF5 /* Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) */
 
#define MAX_FAT32   0x0FFFFFF5 /* Max FAT32 clusters (not specified, practical limit) */
 
#define MAX_EXFAT   0x7FFFFFFD /* Max exFAT clusters (differs from specs, implementation limit) */
 
#define IsUpper(c)   ((c) >= 'A' && (c) <= 'Z')
 
#define IsLower(c)   ((c) >= 'a' && (c) <= 'z')
 
#define IsDigit(c)   ((c) >= '0' && (c) <= '9')
 
#define IsSeparator(c)   ((c) == '/' || (c) == '\\')
 
#define IsTerminator(c)   ((UINT)(c) < (FF_USE_LFN ? ' ' : '!'))
 
#define IsSurrogate(c)   ((c) >= 0xD800 && (c) <= 0xDFFF)
 
#define IsSurrogateH(c)   ((c) >= 0xD800 && (c) <= 0xDBFF)
 
#define IsSurrogateL(c)   ((c) >= 0xDC00 && (c) <= 0xDFFF)
 
#define FA_SEEKEND   0x20 /* Seek to end of the file on file open */
 
#define FA_MODIFIED   0x40 /* File has been modified */
 
#define FA_DIRTY   0x80 /* FIL.buf[] needs to be written-back */
 
#define AM_VOL   0x08 /* Volume label */
 
#define AM_LFN   0x0F /* LFN entry */
 
#define AM_MASK   0x3F /* Mask of defined bits in FAT */
 
#define AM_MASKX   0x37 /* Mask of defined bits in exFAT */
 
#define NSFLAG   11 /* Index of the name status byte */
 
#define NS_LOSS   0x01 /* Out of 8.3 format */
 
#define NS_LFN   0x02 /* Force to create LFN entry */
 
#define NS_LAST   0x04 /* Last segment */
 
#define NS_BODY   0x08 /* Lower case flag (body) */
 
#define NS_EXT   0x10 /* Lower case flag (ext) */
 
#define NS_DOT   0x20 /* Dot entry */
 
#define NS_NOLFN   0x40 /* Do not find LFN */
 
#define NS_NONAME   0x80 /* Not followed */
 
#define ET_BITMAP   0x81 /* Allocation bitmap */
 
#define ET_UPCASE   0x82 /* Up-case table */
 
#define ET_VLABEL   0x83 /* Volume label */
 
#define ET_FILEDIR   0x85 /* File and directory */
 
#define ET_STREAM   0xC0 /* Stream extension */
 
#define ET_FILENAME   0xC1 /* Name extension */
 
#define BS_JmpBoot   0 /* x86 jump instruction (3-byte) */
 
#define BS_OEMName   3 /* OEM name (8-byte) */
 
#define BPB_BytsPerSec   11 /* Sector size [byte] (WORD) */
 
#define BPB_SecPerClus   13 /* Cluster size [sector] (BYTE) */
 
#define BPB_RsvdSecCnt   14 /* Size of reserved area [sector] (WORD) */
 
#define BPB_NumFATs   16 /* Number of FATs (BYTE) */
 
#define BPB_RootEntCnt   17 /* Size of root directory area for FAT [entry] (WORD) */
 
#define BPB_TotSec16   19 /* Volume size (16-bit) [sector] (WORD) */
 
#define BPB_Media   21 /* Media descriptor byte (BYTE) */
 
#define BPB_FATSz16   22 /* FAT size (16-bit) [sector] (WORD) */
 
#define BPB_SecPerTrk   24 /* Number of sectors per track for int13h [sector] (WORD) */
 
#define BPB_NumHeads   26 /* Number of heads for int13h (WORD) */
 
#define BPB_HiddSec   28 /* Volume offset from top of the drive (DWORD) */
 
#define BPB_TotSec32   32 /* Volume size (32-bit) [sector] (DWORD) */
 
#define BS_DrvNum   36 /* Physical drive number for int13h (BYTE) */
 
#define BS_NTres   37 /* WindowsNT error flag (BYTE) */
 
#define BS_BootSig   38 /* Extended boot signature (BYTE) */
 
#define BS_VolID   39 /* Volume serial number (DWORD) */
 
#define BS_VolLab   43 /* Volume label string (8-byte) */
 
#define BS_FilSysType   54 /* Filesystem type string (8-byte) */
 
#define BS_BootCode   62 /* Boot code (448-byte) */
 
#define BS_55AA   510 /* Signature word (WORD) */
 
#define BPB_FATSz32   36 /* FAT32: FAT size [sector] (DWORD) */
 
#define BPB_ExtFlags32   40 /* FAT32: Extended flags (WORD) */
 
#define BPB_FSVer32   42 /* FAT32: Filesystem version (WORD) */
 
#define BPB_RootClus32   44 /* FAT32: Root directory cluster (DWORD) */
 
#define BPB_FSInfo32   48 /* FAT32: Offset of FSINFO sector (WORD) */
 
#define BPB_BkBootSec32   50 /* FAT32: Offset of backup boot sector (WORD) */
 
#define BS_DrvNum32   64 /* FAT32: Physical drive number for int13h (BYTE) */
 
#define BS_NTres32   65 /* FAT32: Error flag (BYTE) */
 
#define BS_BootSig32   66 /* FAT32: Extended boot signature (BYTE) */
 
#define BS_VolID32   67 /* FAT32: Volume serial number (DWORD) */
 
#define BS_VolLab32   71 /* FAT32: Volume label string (8-byte) */
 
#define BS_FilSysType32   82 /* FAT32: Filesystem type string (8-byte) */
 
#define BS_BootCode32   90 /* FAT32: Boot code (420-byte) */
 
#define BPB_ZeroedEx   11 /* exFAT: MBZ field (53-byte) */
 
#define BPB_VolOfsEx   64 /* exFAT: Volume offset from top of the drive [sector] (QWORD) */
 
#define BPB_TotSecEx   72 /* exFAT: Volume size [sector] (QWORD) */
 
#define BPB_FatOfsEx   80 /* exFAT: FAT offset from top of the volume [sector] (DWORD) */
 
#define BPB_FatSzEx   84 /* exFAT: FAT size [sector] (DWORD) */
 
#define BPB_DataOfsEx   88 /* exFAT: Data offset from top of the volume [sector] (DWORD) */
 
#define BPB_NumClusEx   92 /* exFAT: Number of clusters (DWORD) */
 
#define BPB_RootClusEx   96 /* exFAT: Root directory start cluster (DWORD) */
 
#define BPB_VolIDEx   100 /* exFAT: Volume serial number (DWORD) */
 
#define BPB_FSVerEx   104 /* exFAT: Filesystem version (WORD) */
 
#define BPB_VolFlagEx   106 /* exFAT: Volume flags (WORD) */
 
#define BPB_BytsPerSecEx   108 /* exFAT: Log2 of sector size in unit of byte (BYTE) */
 
#define BPB_SecPerClusEx   109 /* exFAT: Log2 of cluster size in unit of sector (BYTE) */
 
#define BPB_NumFATsEx   110 /* exFAT: Number of FATs (BYTE) */
 
#define BPB_DrvNumEx   111 /* exFAT: Physical drive number for int13h (BYTE) */
 
#define BPB_PercInUseEx   112 /* exFAT: Percent in use (BYTE) */
 
#define BPB_RsvdEx   113 /* exFAT: Reserved (7-byte) */
 
#define BS_BootCodeEx   120 /* exFAT: Boot code (390-byte) */
 
#define DIR_Name   0 /* Short file name (11-byte) */
 
#define DIR_Attr   11 /* Attribute (BYTE) */
 
#define DIR_NTres   12 /* Lower case flag (BYTE) */
 
#define DIR_CrtTime10   13 /* Created time sub-second (BYTE) */
 
#define DIR_CrtTime   14 /* Created time (DWORD) */
 
#define DIR_LstAccDate   18 /* Last accessed date (WORD) */
 
#define DIR_FstClusHI   20 /* Higher 16-bit of first cluster (WORD) */
 
#define DIR_ModTime   22 /* Modified time (DWORD) */
 
#define DIR_FstClusLO   26 /* Lower 16-bit of first cluster (WORD) */
 
#define DIR_FileSize   28 /* File size (DWORD) */
 
#define LDIR_Ord   0 /* LFN: LFN order and LLE flag (BYTE) */
 
#define LDIR_Attr   11 /* LFN: LFN attribute (BYTE) */
 
#define LDIR_Type   12 /* LFN: Entry type (BYTE) */
 
#define LDIR_Chksum   13 /* LFN: Checksum of the SFN (BYTE) */
 
#define LDIR_FstClusLO   26 /* LFN: MBZ field (WORD) */
 
#define XDIR_Type   0 /* exFAT: Type of exFAT directory entry (BYTE) */
 
#define XDIR_NumLabel   1 /* exFAT: Number of volume label characters (BYTE) */
 
#define XDIR_Label   2 /* exFAT: Volume label (11-WORD) */
 
#define XDIR_CaseSum   4 /* exFAT: Sum of case conversion table (DWORD) */
 
#define XDIR_NumSec   1 /* exFAT: Number of secondary entries (BYTE) */
 
#define XDIR_SetSum   2 /* exFAT: Sum of the set of directory entries (WORD) */
 
#define XDIR_Attr   4 /* exFAT: File attribute (WORD) */
 
#define XDIR_CrtTime   8 /* exFAT: Created time (DWORD) */
 
#define XDIR_ModTime   12 /* exFAT: Modified time (DWORD) */
 
#define XDIR_AccTime   16 /* exFAT: Last accessed time (DWORD) */
 
#define XDIR_CrtTime10   20 /* exFAT: Created time subsecond (BYTE) */
 
#define XDIR_ModTime10   21 /* exFAT: Modified time subsecond (BYTE) */
 
#define XDIR_CrtTZ   22 /* exFAT: Created timezone (BYTE) */
 
#define XDIR_ModTZ   23 /* exFAT: Modified timezone (BYTE) */
 
#define XDIR_AccTZ   24 /* exFAT: Last accessed timezone (BYTE) */
 
#define XDIR_GenFlags   33 /* exFAT: General secondary flags (BYTE) */
 
#define XDIR_NumName   35 /* exFAT: Number of file name characters (BYTE) */
 
#define XDIR_NameHash   36 /* exFAT: Hash of file name (WORD) */
 
#define XDIR_ValidFileSize   40 /* exFAT: Valid file size (QWORD) */
 
#define XDIR_FstClus   52 /* exFAT: First cluster of the file data (DWORD) */
 
#define XDIR_FileSize   56 /* exFAT: File/Directory size (QWORD) */
 
#define SZDIRE   32 /* Size of a directory entry */
 
#define DDEM   0xE5 /* Deleted directory entry mark set to DIR_Name[0] */
 
#define RDDEM   0x05 /* Replacement of the character collides with DDEM */
 
#define LLEF   0x40 /* Last long entry flag in LDIR_Ord */
 
#define FSI_LeadSig   0 /* FAT32 FSI: Leading signature (DWORD) */
 
#define FSI_StrucSig   484 /* FAT32 FSI: Structure signature (DWORD) */
 
#define FSI_Free_Count   488 /* FAT32 FSI: Number of free clusters (DWORD) */
 
#define FSI_Nxt_Free   492 /* FAT32 FSI: Last allocated cluster (DWORD) */
 
#define MBR_Table   446 /* MBR: Offset of partition table in the MBR */
 
#define SZ_PTE   16 /* MBR: Size of a partition table entry */
 
#define PTE_Boot   0 /* MBR PTE: Boot indicator */
 
#define PTE_StHead   1 /* MBR PTE: Start head */
 
#define PTE_StSec   2 /* MBR PTE: Start sector */
 
#define PTE_StCyl   3 /* MBR PTE: Start cylinder */
 
#define PTE_System   4 /* MBR PTE: System ID */
 
#define PTE_EdHead   5 /* MBR PTE: End head */
 
#define PTE_EdSec   6 /* MBR PTE: End sector */
 
#define PTE_EdCyl   7 /* MBR PTE: End cylinder */
 
#define PTE_StLba   8 /* MBR PTE: Start in LBA */
 
#define PTE_SizLba   12 /* MBR PTE: Size in LBA */
 
#define GPTH_Sign   0 /* GPT: Header signature (8-byte) */
 
#define GPTH_Rev   8 /* GPT: Revision (DWORD) */
 
#define GPTH_Size   12 /* GPT: Header size (DWORD) */
 
#define GPTH_Bcc   16 /* GPT: Header BCC (DWORD) */
 
#define GPTH_CurLba   24 /* GPT: Main header LBA (QWORD) */
 
#define GPTH_BakLba   32 /* GPT: Backup header LBA (QWORD) */
 
#define GPTH_FstLba   40 /* GPT: First LBA for partitions (QWORD) */
 
#define GPTH_LstLba   48 /* GPT: Last LBA for partitions (QWORD) */
 
#define GPTH_DskGuid   56 /* GPT: Disk GUID (16-byte) */
 
#define GPTH_PtOfs   72 /* GPT: Partation table LBA (QWORD) */
 
#define GPTH_PtNum   80 /* GPT: Number of table entries (DWORD) */
 
#define GPTH_PteSize   84 /* GPT: Size of table entry (DWORD) */
 
#define GPTH_PtBcc   88 /* GPT: Partation table BCC (DWORD) */
 
#define SZ_GPTE   128 /* GPT: Size of partition table entry */
 
#define GPTE_PtGuid   0 /* GPT PTE: Partition type GUID (16-byte) */
 
#define GPTE_UpGuid   16 /* GPT PTE: Partition unique GUID (16-byte) */
 
#define GPTE_FstLba   32 /* GPT PTE: First LBA (QWORD) */
 
#define GPTE_LstLba   40 /* GPT PTE: Last LBA inclusive (QWORD) */
 
#define GPTE_Flags   48 /* GPT PTE: Flags (QWORD) */
 
#define GPTE_Name   56 /* GPT PTE: Name */
 
#define ABORT(fs, res)   { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
 
#define LEAVE_FF(fs, res)   return res
 
#define LD2PD(vol)   (BYTE)(vol) /* Each logical drive is associated with the same physical drive number */
 
#define LD2PT(vol)   0 /* Auto partition search */
 
#define SS(fs)   ((UINT)FF_MAX_SS) /* Fixed sector size */
 
#define GET_FATTIME()   ((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16)
 
#define TBL_CT437
 
#define TBL_CT720
 
#define TBL_CT737
 
#define TBL_CT771
 
#define TBL_CT775
 
#define TBL_CT850
 
#define TBL_CT852
 
#define TBL_CT855
 
#define TBL_CT857
 
#define TBL_CT860
 
#define TBL_CT861
 
#define TBL_CT862
 
#define TBL_CT863
 
#define TBL_CT864
 
#define TBL_CT865
 
#define TBL_CT866
 
#define TBL_CT869
 
#define TBL_DC932   {0x81, 0x9F, 0xE0, 0xFC, 0x40, 0x7E, 0x80, 0xFC, 0x00, 0x00}
 
#define TBL_DC936   {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0x80, 0xFE, 0x00, 0x00}
 
#define TBL_DC949   {0x81, 0xFE, 0x00, 0x00, 0x41, 0x5A, 0x61, 0x7A, 0x81, 0xFE}
 
#define TBL_DC950   {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0xA1, 0xFE, 0x00, 0x00}
 
#define MERGE_2STR(a, b)   a ## b
 
#define MKCVTBL(hd, cp)   MERGE_2STR(hd, cp)
 
#define MAXDIRB(nc)   ((nc + 44U) / 15 * SZDIRE) /* exFAT: Size of directory entry block scratchpad buffer needed for the name length */
 
#define DEF_NAMBUF   WCHAR *lfn; /* Pointer to LFN working buffer */
 
#define INIT_NAMBUF(fs)   { lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; }
 
#define FREE_NAMBUF()   ff_memfree(lfn)
 
#define LEAVE_MKFS(res)   { if (!work) ff_memfree(buf); return res; }
 
#define MAX_MALLOC   0x8000 /* Must be >=FF_MAX_SS */
 
#define CODEPAGE   FF_CODE_PAGE
 
#define DIR_READ_FILE(dp)   dir_read(dp, 0)
 
#define DIR_READ_LABEL(dp)   dir_read(dp, 1)
 
#define SZ_PUTC_BUF   64
 
#define SZ_NUM_BUF   32
 

Functions

static WORD ld_word (const BYTE *ptr)
 
static DWORD ld_dword (const BYTE *ptr)
 
static void st_word (BYTE *ptr, WORD val)
 
static void st_dword (BYTE *ptr, DWORD val)
 
static int dbc_1st (BYTE c)
 
static int dbc_2nd (BYTE c)
 
static DWORD tchar2uni (const TCHAR **str)
 
static UINT put_utf (DWORD chr, TCHAR *buf, UINT szb)
 
static FRESULT chk_lock (DIR *dp, int acc)
 
static int enq_lock (void)
 
static UINT inc_lock (DIR *dp, int acc)
 
static FRESULT dec_lock (UINT i)
 
static void clear_lock (FATFS *fs)
 
static FRESULT sync_window (FATFS *fs)
 
static FRESULT move_window (FATFS *fs, LBA_t sect)
 
static FRESULT sync_fs (FATFS *fs)
 
static LBA_t clst2sect (FATFS *fs, DWORD clst)
 
static DWORD get_fat (FFOBJID *obj, DWORD clst)
 
static FRESULT put_fat (FATFS *fs, DWORD clst, DWORD val)
 
static FRESULT remove_chain (FFOBJID *obj, DWORD clst, DWORD pclst)
 
static DWORD create_chain (FFOBJID *obj, DWORD clst)
 
static FRESULT dir_clear (FATFS *fs, DWORD clst)
 
static FRESULT dir_sdi (DIR *dp, DWORD ofs)
 
static FRESULT dir_next (DIR *dp, int stretch)
 
static FRESULT dir_alloc (DIR *dp, UINT n_ent)
 
static DWORD ld_clust (FATFS *fs, const BYTE *dir)
 
static void st_clust (FATFS *fs, BYTE *dir, DWORD cl)
 
static int cmp_lfn (const WCHAR *lfnbuf, BYTE *dir)
 
static int pick_lfn (WCHAR *lfnbuf, BYTE *dir)
 
static void put_lfn (const WCHAR *lfn, BYTE *dir, BYTE ord, BYTE sum)
 
static void gen_numname (BYTE *dst, const BYTE *src, const WCHAR *lfn, UINT seq)
 
static BYTE sum_sfn (const BYTE *dir)
 
static FRESULT dir_read (DIR *dp, int vol)
 
static FRESULT dir_find (DIR *dp)
 
static FRESULT dir_register (DIR *dp)
 
static FRESULT dir_remove (DIR *dp)
 
static void get_fileinfo (DIR *dp, FILINFO *fno)
 
static FRESULT create_name (DIR *dp, const TCHAR **path)
 
static FRESULT follow_path (DIR *dp, const TCHAR *path)
 
static int get_ldnumber (const TCHAR **path)
 
static UINT check_fs (FATFS *fs, LBA_t sect)
 
static UINT find_volume (FATFS *fs, UINT part)
 
static FRESULT mount_volume (const TCHAR **path, FATFS **rfs, BYTE mode)
 
static FRESULT validate (FFOBJID *obj, FATFS **rfs)
 
FRESULT f_mount (FATFS *fs, const TCHAR *path, BYTE opt)
 
FRESULT f_open (FIL *fp, const TCHAR *path, BYTE mode)
 
FRESULT f_read (FIL *fp, void *buff, UINT btr, UINT *br)
 
FRESULT f_write (FIL *fp, const void *buff, UINT btw, UINT *bw)
 
FRESULT f_sync (FIL *fp)
 
FRESULT f_close (FIL *fp)
 
FRESULT f_chdrive (const TCHAR *path)
 
FRESULT f_chdir (const TCHAR *path)
 
FRESULT f_lseek (FIL *fp, FSIZE_t ofs)
 
FRESULT f_opendir (DIR *dp, const TCHAR *path)
 
FRESULT f_closedir (DIR *dp)
 
FRESULT f_readdir (DIR *dp, FILINFO *fno)
 
FRESULT f_stat (const TCHAR *path, FILINFO *fno)
 
FRESULT f_getfree (const TCHAR *path, DWORD *nclst, FATFS **fatfs)
 
FRESULT f_truncate (FIL *fp)
 
FRESULT f_unlink (const TCHAR *path)
 
FRESULT f_mkdir (const TCHAR *path)
 
FRESULT f_rename (const TCHAR *path_old, const TCHAR *path_new)
 
TCHARf_gets (TCHAR *buff, int len, FIL *fp)
 
static void putc_bfd (putbuff *pb, TCHAR c)
 
static int putc_flush (putbuff *pb)
 
static void putc_init (putbuff *pb, FIL *fp)
 
int f_putc (TCHAR c, FIL *fp)
 
int f_puts (const TCHAR *str, FIL *fp)
 
int f_printf (FIL *fp, const TCHAR *fmt,...)
 

Variables

static FATFSFatFs [FF_VOLUMES]
 
static WORD Fsid
 
static BYTE CurrVol
 
static FILESEM Files [FF_FS_LOCK]
 
static const BYTE LfnOfs [] = {1,3,5,7,9,14,16,18,20,22,24,28,30}
 
static const BYTE ExCvt [] = MKCVTBL(TBL_CT, FF_CODE_PAGE)
 

Macro Definition Documentation

◆ ABORT

#define ABORT (   fs,
  res 
)    { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }

Definition at line 234 of file ff.c.

◆ AM_LFN

#define AM_LFN   0x0F /* LFN entry */

Definition at line 66 of file ff.c.

◆ AM_MASK

#define AM_MASK   0x3F /* Mask of defined bits in FAT */

Definition at line 67 of file ff.c.

◆ AM_MASKX

#define AM_MASKX   0x37 /* Mask of defined bits in exFAT */

Definition at line 68 of file ff.c.

◆ AM_VOL

#define AM_VOL   0x08 /* Volume label */

Definition at line 65 of file ff.c.

◆ BPB_BkBootSec32

#define BPB_BkBootSec32   50 /* FAT32: Offset of backup boot sector (WORD) */

Definition at line 123 of file ff.c.

◆ BPB_BytsPerSec

#define BPB_BytsPerSec   11 /* Sector size [byte] (WORD) */

Definition at line 97 of file ff.c.

◆ BPB_BytsPerSecEx

#define BPB_BytsPerSecEx   108 /* exFAT: Log2 of sector size in unit of byte (BYTE) */

Definition at line 143 of file ff.c.

◆ BPB_DataOfsEx

#define BPB_DataOfsEx   88 /* exFAT: Data offset from top of the volume [sector] (DWORD) */

Definition at line 137 of file ff.c.

◆ BPB_DrvNumEx

#define BPB_DrvNumEx   111 /* exFAT: Physical drive number for int13h (BYTE) */

Definition at line 146 of file ff.c.

◆ BPB_ExtFlags32

#define BPB_ExtFlags32   40 /* FAT32: Extended flags (WORD) */

Definition at line 119 of file ff.c.

◆ BPB_FatOfsEx

#define BPB_FatOfsEx   80 /* exFAT: FAT offset from top of the volume [sector] (DWORD) */

Definition at line 135 of file ff.c.

◆ BPB_FATSz16

#define BPB_FATSz16   22 /* FAT size (16-bit) [sector] (WORD) */

Definition at line 104 of file ff.c.

◆ BPB_FATSz32

#define BPB_FATSz32   36 /* FAT32: FAT size [sector] (DWORD) */

Definition at line 118 of file ff.c.

◆ BPB_FatSzEx

#define BPB_FatSzEx   84 /* exFAT: FAT size [sector] (DWORD) */

Definition at line 136 of file ff.c.

◆ BPB_FSInfo32

#define BPB_FSInfo32   48 /* FAT32: Offset of FSINFO sector (WORD) */

Definition at line 122 of file ff.c.

◆ BPB_FSVer32

#define BPB_FSVer32   42 /* FAT32: Filesystem version (WORD) */

Definition at line 120 of file ff.c.

◆ BPB_FSVerEx

#define BPB_FSVerEx   104 /* exFAT: Filesystem version (WORD) */

Definition at line 141 of file ff.c.

◆ BPB_HiddSec

#define BPB_HiddSec   28 /* Volume offset from top of the drive (DWORD) */

Definition at line 107 of file ff.c.

◆ BPB_Media

#define BPB_Media   21 /* Media descriptor byte (BYTE) */

Definition at line 103 of file ff.c.

◆ BPB_NumClusEx

#define BPB_NumClusEx   92 /* exFAT: Number of clusters (DWORD) */

Definition at line 138 of file ff.c.

◆ BPB_NumFATs

#define BPB_NumFATs   16 /* Number of FATs (BYTE) */

Definition at line 100 of file ff.c.

◆ BPB_NumFATsEx

#define BPB_NumFATsEx   110 /* exFAT: Number of FATs (BYTE) */

Definition at line 145 of file ff.c.

◆ BPB_NumHeads

#define BPB_NumHeads   26 /* Number of heads for int13h (WORD) */

Definition at line 106 of file ff.c.

◆ BPB_PercInUseEx

#define BPB_PercInUseEx   112 /* exFAT: Percent in use (BYTE) */

Definition at line 147 of file ff.c.

◆ BPB_RootClus32

#define BPB_RootClus32   44 /* FAT32: Root directory cluster (DWORD) */

Definition at line 121 of file ff.c.

◆ BPB_RootClusEx

#define BPB_RootClusEx   96 /* exFAT: Root directory start cluster (DWORD) */

Definition at line 139 of file ff.c.

◆ BPB_RootEntCnt

#define BPB_RootEntCnt   17 /* Size of root directory area for FAT [entry] (WORD) */

Definition at line 101 of file ff.c.

◆ BPB_RsvdEx

#define BPB_RsvdEx   113 /* exFAT: Reserved (7-byte) */

Definition at line 148 of file ff.c.

◆ BPB_RsvdSecCnt

#define BPB_RsvdSecCnt   14 /* Size of reserved area [sector] (WORD) */

Definition at line 99 of file ff.c.

◆ BPB_SecPerClus

#define BPB_SecPerClus   13 /* Cluster size [sector] (BYTE) */

Definition at line 98 of file ff.c.

◆ BPB_SecPerClusEx

#define BPB_SecPerClusEx   109 /* exFAT: Log2 of cluster size in unit of sector (BYTE) */

Definition at line 144 of file ff.c.

◆ BPB_SecPerTrk

#define BPB_SecPerTrk   24 /* Number of sectors per track for int13h [sector] (WORD) */

Definition at line 105 of file ff.c.

◆ BPB_TotSec16

#define BPB_TotSec16   19 /* Volume size (16-bit) [sector] (WORD) */

Definition at line 102 of file ff.c.

◆ BPB_TotSec32

#define BPB_TotSec32   32 /* Volume size (32-bit) [sector] (DWORD) */

Definition at line 108 of file ff.c.

◆ BPB_TotSecEx

#define BPB_TotSecEx   72 /* exFAT: Volume size [sector] (QWORD) */

Definition at line 134 of file ff.c.

◆ BPB_VolFlagEx

#define BPB_VolFlagEx   106 /* exFAT: Volume flags (WORD) */

Definition at line 142 of file ff.c.

◆ BPB_VolIDEx

#define BPB_VolIDEx   100 /* exFAT: Volume serial number (DWORD) */

Definition at line 140 of file ff.c.

◆ BPB_VolOfsEx

#define BPB_VolOfsEx   64 /* exFAT: Volume offset from top of the drive [sector] (QWORD) */

Definition at line 133 of file ff.c.

◆ BPB_ZeroedEx

#define BPB_ZeroedEx   11 /* exFAT: MBZ field (53-byte) */

Definition at line 132 of file ff.c.

◆ BS_55AA

#define BS_55AA   510 /* Signature word (WORD) */

Definition at line 116 of file ff.c.

◆ BS_BootCode

#define BS_BootCode   62 /* Boot code (448-byte) */

Definition at line 115 of file ff.c.

◆ BS_BootCode32

#define BS_BootCode32   90 /* FAT32: Boot code (420-byte) */

Definition at line 130 of file ff.c.

◆ BS_BootCodeEx

#define BS_BootCodeEx   120 /* exFAT: Boot code (390-byte) */

Definition at line 149 of file ff.c.

◆ BS_BootSig

#define BS_BootSig   38 /* Extended boot signature (BYTE) */

Definition at line 111 of file ff.c.

◆ BS_BootSig32

#define BS_BootSig32   66 /* FAT32: Extended boot signature (BYTE) */

Definition at line 126 of file ff.c.

◆ BS_DrvNum

#define BS_DrvNum   36 /* Physical drive number for int13h (BYTE) */

Definition at line 109 of file ff.c.

◆ BS_DrvNum32

#define BS_DrvNum32   64 /* FAT32: Physical drive number for int13h (BYTE) */

Definition at line 124 of file ff.c.

◆ BS_FilSysType

#define BS_FilSysType   54 /* Filesystem type string (8-byte) */

Definition at line 114 of file ff.c.

◆ BS_FilSysType32

#define BS_FilSysType32   82 /* FAT32: Filesystem type string (8-byte) */

Definition at line 129 of file ff.c.

◆ BS_JmpBoot

#define BS_JmpBoot   0 /* x86 jump instruction (3-byte) */

Definition at line 95 of file ff.c.

◆ BS_NTres

#define BS_NTres   37 /* WindowsNT error flag (BYTE) */

Definition at line 110 of file ff.c.

◆ BS_NTres32

#define BS_NTres32   65 /* FAT32: Error flag (BYTE) */

Definition at line 125 of file ff.c.

◆ BS_OEMName

#define BS_OEMName   3 /* OEM name (8-byte) */

Definition at line 96 of file ff.c.

◆ BS_VolID

#define BS_VolID   39 /* Volume serial number (DWORD) */

Definition at line 112 of file ff.c.

◆ BS_VolID32

#define BS_VolID32   67 /* FAT32: Volume serial number (DWORD) */

Definition at line 127 of file ff.c.

◆ BS_VolLab

#define BS_VolLab   43 /* Volume label string (8-byte) */

Definition at line 113 of file ff.c.

◆ BS_VolLab32

#define BS_VolLab32   71 /* FAT32: Volume label string (8-byte) */

Definition at line 128 of file ff.c.

◆ CODEPAGE

#define CODEPAGE   FF_CODE_PAGE

Definition at line 591 of file ff.c.

◆ DDEM

#define DDEM   0xE5 /* Deleted directory entry mark set to DIR_Name[0] */

Definition at line 189 of file ff.c.

◆ DEF_NAMBUF

#define DEF_NAMBUF   WCHAR *lfn; /* Pointer to LFN working buffer */

Definition at line 544 of file ff.c.

◆ DIR_Attr

#define DIR_Attr   11 /* Attribute (BYTE) */

Definition at line 152 of file ff.c.

◆ DIR_CrtTime

#define DIR_CrtTime   14 /* Created time (DWORD) */

Definition at line 155 of file ff.c.

◆ DIR_CrtTime10

#define DIR_CrtTime10   13 /* Created time sub-second (BYTE) */

Definition at line 154 of file ff.c.

◆ DIR_FileSize

#define DIR_FileSize   28 /* File size (DWORD) */

Definition at line 160 of file ff.c.

◆ DIR_FstClusHI

#define DIR_FstClusHI   20 /* Higher 16-bit of first cluster (WORD) */

Definition at line 157 of file ff.c.

◆ DIR_FstClusLO

#define DIR_FstClusLO   26 /* Lower 16-bit of first cluster (WORD) */

Definition at line 159 of file ff.c.

◆ DIR_LstAccDate

#define DIR_LstAccDate   18 /* Last accessed date (WORD) */

Definition at line 156 of file ff.c.

◆ DIR_ModTime

#define DIR_ModTime   22 /* Modified time (DWORD) */

Definition at line 158 of file ff.c.

◆ DIR_Name

#define DIR_Name   0 /* Short file name (11-byte) */

Definition at line 151 of file ff.c.

◆ DIR_NTres

#define DIR_NTres   12 /* Lower case flag (BYTE) */

Definition at line 153 of file ff.c.

◆ DIR_READ_FILE

#define DIR_READ_FILE (   dp)    dir_read(dp, 0)

Definition at line 2272 of file ff.c.

◆ DIR_READ_LABEL

#define DIR_READ_LABEL (   dp)    dir_read(dp, 1)

Definition at line 2273 of file ff.c.

◆ ET_BITMAP

#define ET_BITMAP   0x81 /* Allocation bitmap */

Definition at line 84 of file ff.c.

◆ ET_FILEDIR

#define ET_FILEDIR   0x85 /* File and directory */

Definition at line 87 of file ff.c.

◆ ET_FILENAME

#define ET_FILENAME   0xC1 /* Name extension */

Definition at line 89 of file ff.c.

◆ ET_STREAM

#define ET_STREAM   0xC0 /* Stream extension */

Definition at line 88 of file ff.c.

◆ ET_UPCASE

#define ET_UPCASE   0x82 /* Up-case table */

Definition at line 85 of file ff.c.

◆ ET_VLABEL

#define ET_VLABEL   0x83 /* Volume label */

Definition at line 86 of file ff.c.

◆ FA_DIRTY

#define FA_DIRTY   0x80 /* FIL.buf[] needs to be written-back */

Definition at line 61 of file ff.c.

◆ FA_MODIFIED

#define FA_MODIFIED   0x40 /* File has been modified */

Definition at line 60 of file ff.c.

◆ FA_SEEKEND

#define FA_SEEKEND   0x20 /* Seek to end of the file on file open */

Definition at line 59 of file ff.c.

◆ FREE_NAMBUF

#define FREE_NAMBUF ( )    ff_memfree(lfn)

Definition at line 546 of file ff.c.

◆ FSI_Free_Count

#define FSI_Free_Count   488 /* FAT32 FSI: Number of free clusters (DWORD) */

Definition at line 195 of file ff.c.

◆ FSI_LeadSig

#define FSI_LeadSig   0 /* FAT32 FSI: Leading signature (DWORD) */

Definition at line 193 of file ff.c.

◆ FSI_Nxt_Free

#define FSI_Nxt_Free   492 /* FAT32 FSI: Last allocated cluster (DWORD) */

Definition at line 196 of file ff.c.

◆ FSI_StrucSig

#define FSI_StrucSig   484 /* FAT32 FSI: Structure signature (DWORD) */

Definition at line 194 of file ff.c.

◆ GET_FATTIME

#define GET_FATTIME ( )    ((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16)

Definition at line 274 of file ff.c.

◆ GPTE_Flags

#define GPTE_Flags   48 /* GPT PTE: Flags (QWORD) */

Definition at line 229 of file ff.c.

◆ GPTE_FstLba

#define GPTE_FstLba   32 /* GPT PTE: First LBA (QWORD) */

Definition at line 227 of file ff.c.

◆ GPTE_LstLba

#define GPTE_LstLba   40 /* GPT PTE: Last LBA inclusive (QWORD) */

Definition at line 228 of file ff.c.

◆ GPTE_Name

#define GPTE_Name   56 /* GPT PTE: Name */

Definition at line 230 of file ff.c.

◆ GPTE_PtGuid

#define GPTE_PtGuid   0 /* GPT PTE: Partition type GUID (16-byte) */

Definition at line 225 of file ff.c.

◆ GPTE_UpGuid

#define GPTE_UpGuid   16 /* GPT PTE: Partition unique GUID (16-byte) */

Definition at line 226 of file ff.c.

◆ GPTH_BakLba

#define GPTH_BakLba   32 /* GPT: Backup header LBA (QWORD) */

Definition at line 216 of file ff.c.

◆ GPTH_Bcc

#define GPTH_Bcc   16 /* GPT: Header BCC (DWORD) */

Definition at line 214 of file ff.c.

◆ GPTH_CurLba

#define GPTH_CurLba   24 /* GPT: Main header LBA (QWORD) */

Definition at line 215 of file ff.c.

◆ GPTH_DskGuid

#define GPTH_DskGuid   56 /* GPT: Disk GUID (16-byte) */

Definition at line 219 of file ff.c.

◆ GPTH_FstLba

#define GPTH_FstLba   40 /* GPT: First LBA for partitions (QWORD) */

Definition at line 217 of file ff.c.

◆ GPTH_LstLba

#define GPTH_LstLba   48 /* GPT: Last LBA for partitions (QWORD) */

Definition at line 218 of file ff.c.

◆ GPTH_PtBcc

#define GPTH_PtBcc   88 /* GPT: Partation table BCC (DWORD) */

Definition at line 223 of file ff.c.

◆ GPTH_PteSize

#define GPTH_PteSize   84 /* GPT: Size of table entry (DWORD) */

Definition at line 222 of file ff.c.

◆ GPTH_PtNum

#define GPTH_PtNum   80 /* GPT: Number of table entries (DWORD) */

Definition at line 221 of file ff.c.

◆ GPTH_PtOfs

#define GPTH_PtOfs   72 /* GPT: Partation table LBA (QWORD) */

Definition at line 220 of file ff.c.

◆ GPTH_Rev

#define GPTH_Rev   8 /* GPT: Revision (DWORD) */

Definition at line 212 of file ff.c.

◆ GPTH_Sign

#define GPTH_Sign   0 /* GPT: Header signature (8-byte) */

Definition at line 211 of file ff.c.

◆ GPTH_Size

#define GPTH_Size   12 /* GPT: Header size (DWORD) */

Definition at line 213 of file ff.c.

◆ INIT_NAMBUF

#define INIT_NAMBUF (   fs)    { lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; }

Definition at line 545 of file ff.c.

◆ IsDigit

#define IsDigit (   c)    ((c) >= '0' && (c) <= '9')

Definition at line 50 of file ff.c.

◆ IsLower

#define IsLower (   c)    ((c) >= 'a' && (c) <= 'z')

Definition at line 49 of file ff.c.

◆ IsSeparator

#define IsSeparator (   c)    ((c) == '/' || (c) == '\\')

Definition at line 51 of file ff.c.

◆ IsSurrogate

#define IsSurrogate (   c)    ((c) >= 0xD800 && (c) <= 0xDFFF)

Definition at line 53 of file ff.c.

◆ IsSurrogateH

#define IsSurrogateH (   c)    ((c) >= 0xD800 && (c) <= 0xDBFF)

Definition at line 54 of file ff.c.

◆ IsSurrogateL

#define IsSurrogateL (   c)    ((c) >= 0xDC00 && (c) <= 0xDFFF)

Definition at line 55 of file ff.c.

◆ IsTerminator

#define IsTerminator (   c)    ((UINT)(c) < (FF_USE_LFN ? ' ' : '!'))

Definition at line 52 of file ff.c.

◆ IsUpper

#define IsUpper (   c)    ((c) >= 'A' && (c) <= 'Z')

Definition at line 48 of file ff.c.

◆ LD2PD

#define LD2PD (   vol)    (BYTE)(vol) /* Each logical drive is associated with the same physical drive number */

Definition at line 253 of file ff.c.

◆ LD2PT

#define LD2PT (   vol)    0 /* Auto partition search */

Definition at line 254 of file ff.c.

◆ LDIR_Attr

#define LDIR_Attr   11 /* LFN: LFN attribute (BYTE) */

Definition at line 162 of file ff.c.

◆ LDIR_Chksum

#define LDIR_Chksum   13 /* LFN: Checksum of the SFN (BYTE) */

Definition at line 164 of file ff.c.

◆ LDIR_FstClusLO

#define LDIR_FstClusLO   26 /* LFN: MBZ field (WORD) */

Definition at line 165 of file ff.c.

◆ LDIR_Ord

#define LDIR_Ord   0 /* LFN: LFN order and LLE flag (BYTE) */

Definition at line 161 of file ff.c.

◆ LDIR_Type

#define LDIR_Type   12 /* LFN: Entry type (BYTE) */

Definition at line 163 of file ff.c.

◆ LEAVE_FF

#define LEAVE_FF (   fs,
  res 
)    return res

Definition at line 244 of file ff.c.

◆ LEAVE_MKFS

#define LEAVE_MKFS (   res)    { if (!work) ff_memfree(buf); return res; }

Definition at line 548 of file ff.c.

◆ LLEF

#define LLEF   0x40 /* Last long entry flag in LDIR_Ord */

Definition at line 191 of file ff.c.

◆ MAX_DIR

#define MAX_DIR   0x200000 /* Max size of FAT directory */

Definition at line 39 of file ff.c.

◆ MAX_DIR_EX

#define MAX_DIR_EX   0x10000000 /* Max size of exFAT directory */

Definition at line 40 of file ff.c.

◆ MAX_EXFAT

#define MAX_EXFAT   0x7FFFFFFD /* Max exFAT clusters (differs from specs, implementation limit) */

Definition at line 44 of file ff.c.

◆ MAX_FAT12

#define MAX_FAT12   0xFF5 /* Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) */

Definition at line 41 of file ff.c.

◆ MAX_FAT16

#define MAX_FAT16   0xFFF5 /* Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) */

Definition at line 42 of file ff.c.

◆ MAX_FAT32

#define MAX_FAT32   0x0FFFFFF5 /* Max FAT32 clusters (not specified, practical limit) */

Definition at line 43 of file ff.c.

◆ MAX_MALLOC

#define MAX_MALLOC   0x8000 /* Must be >=FF_MAX_SS */

Definition at line 549 of file ff.c.

◆ MAXDIRB

#define MAXDIRB (   nc)    ((nc + 44U) / 15 * SZDIRE) /* exFAT: Size of directory entry block scratchpad buffer needed for the name length */

Definition at line 514 of file ff.c.

◆ MBR_Table

#define MBR_Table   446 /* MBR: Offset of partition table in the MBR */

Definition at line 198 of file ff.c.

◆ MERGE_2STR

#define MERGE_2STR (   a,
  b 
)    a ## b

Definition at line 442 of file ff.c.

◆ MKCVTBL

#define MKCVTBL (   hd,
  cp 
)    MERGE_2STR(hd, cp)

Definition at line 443 of file ff.c.

◆ NS_BODY

#define NS_BODY   0x08 /* Lower case flag (body) */

Definition at line 76 of file ff.c.

◆ NS_DOT

#define NS_DOT   0x20 /* Dot entry */

Definition at line 78 of file ff.c.

◆ NS_EXT

#define NS_EXT   0x10 /* Lower case flag (ext) */

Definition at line 77 of file ff.c.

◆ NS_LAST

#define NS_LAST   0x04 /* Last segment */

Definition at line 75 of file ff.c.

◆ NS_LFN

#define NS_LFN   0x02 /* Force to create LFN entry */

Definition at line 74 of file ff.c.

◆ NS_LOSS

#define NS_LOSS   0x01 /* Out of 8.3 format */

Definition at line 73 of file ff.c.

◆ NS_NOLFN

#define NS_NOLFN   0x40 /* Do not find LFN */

Definition at line 79 of file ff.c.

◆ NS_NONAME

#define NS_NONAME   0x80 /* Not followed */

Definition at line 80 of file ff.c.

◆ NSFLAG

#define NSFLAG   11 /* Index of the name status byte */

Definition at line 72 of file ff.c.

◆ PTE_Boot

#define PTE_Boot   0 /* MBR PTE: Boot indicator */

Definition at line 200 of file ff.c.

◆ PTE_EdCyl

#define PTE_EdCyl   7 /* MBR PTE: End cylinder */

Definition at line 207 of file ff.c.

◆ PTE_EdHead

#define PTE_EdHead   5 /* MBR PTE: End head */

Definition at line 205 of file ff.c.

◆ PTE_EdSec

#define PTE_EdSec   6 /* MBR PTE: End sector */

Definition at line 206 of file ff.c.

◆ PTE_SizLba

#define PTE_SizLba   12 /* MBR PTE: Size in LBA */

Definition at line 209 of file ff.c.

◆ PTE_StCyl

#define PTE_StCyl   3 /* MBR PTE: Start cylinder */

Definition at line 203 of file ff.c.

◆ PTE_StHead

#define PTE_StHead   1 /* MBR PTE: Start head */

Definition at line 201 of file ff.c.

◆ PTE_StLba

#define PTE_StLba   8 /* MBR PTE: Start in LBA */

Definition at line 208 of file ff.c.

◆ PTE_StSec

#define PTE_StSec   2 /* MBR PTE: Start sector */

Definition at line 202 of file ff.c.

◆ PTE_System

#define PTE_System   4 /* MBR PTE: System ID */

Definition at line 204 of file ff.c.

◆ RDDEM

#define RDDEM   0x05 /* Replacement of the character collides with DDEM */

Definition at line 190 of file ff.c.

◆ SS

#define SS (   fs)    ((UINT)FF_MAX_SS) /* Fixed sector size */

Definition at line 263 of file ff.c.

◆ SZ_GPTE

#define SZ_GPTE   128 /* GPT: Size of partition table entry */

Definition at line 224 of file ff.c.

◆ SZ_NUM_BUF

#define SZ_NUM_BUF   32

Definition at line 6465 of file ff.c.

◆ SZ_PTE

#define SZ_PTE   16 /* MBR: Size of a partition table entry */

Definition at line 199 of file ff.c.

◆ SZ_PUTC_BUF

#define SZ_PUTC_BUF   64

Definition at line 6464 of file ff.c.

◆ SZDIRE

#define SZDIRE   32 /* Size of a directory entry */

Definition at line 188 of file ff.c.

◆ TBL_CT437

#define TBL_CT437
Value:
{0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

Definition at line 295 of file ff.c.

295 {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
296 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
297 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
298 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
299 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0x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0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xEF,0xF5,0xF0,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

Definition at line 311 of file ff.c.

311 {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
312 0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \
313 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96, \
314 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
315 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
316 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
317 0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xEF,0xF5,0xF0,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
318 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

◆ TBL_CT771

#define TBL_CT771
Value:
{0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC,0xDE,0xDE, \
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}

Definition at line 319 of file ff.c.

319 {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
320 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
321 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
322 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
323 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
324 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC,0xDE,0xDE, \
325 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x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0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

Definition at line 335 of file ff.c.

335 {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \
336 0x45,0x92,0x92,0x4F,0x4F,0x4F,0x55,0x55,0x59,0x4F,0x55,0x4F,0x9C,0x4F,0x9E,0x9F, \
337 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
338 0xB0,0xB1,0xB2,0xB3,0xB4,0x41,0x41,0x41,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
339 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0x41,0x41,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
340 0xD1,0xD1,0x45,0x45,0x45,0x49,0x49,0x49,0x49,0xD9,0xDA,0xDB,0xDC,0xDD,0x49,0xDF, \
341 0x4F,0xE1,0x4F,0x4F,0x4F,0x4F,0xE6,0xE8,0xE8,0x55,0x55,0x55,0x59,0x59,0xEE,0xEF, \
342 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

◆ TBL_CT852

#define TBL_CT852
Value:
{0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \
0x90,0x91,0x91,0xE2,0x99,0x95,0x95,0x97,0x97,0x99,0x9A,0x9B,0x9B,0x9D,0x9E,0xAC, \
0xB5,0xD6,0xE0,0xE9,0xA4,0xA4,0xA6,0xA6,0xA8,0xA8,0xAA,0x8D,0xAC,0xB8,0xAE,0xAF, \
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBD,0xBF, \
0xC0,0x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0xDC,0xDD,0xDE,0xDF, \
381 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
382 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

◆ TBL_CT862

#define TBL_CT862
Value:
{0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

Definition at line 383 of file ff.c.

383 {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
384 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
385 0x41,0x49,0x4F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9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

Definition at line 391 of file ff.c.

391 {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \
392 0x45,0x45,0x45,0x4F,0x45,0x49,0x55,0x55,0x98,0x4F,0x55,0x9B,0x9C,0x55,0x55,0x9F, \
393 0xA0,0xA1,0x4F,0x55,0xA4,0xA5,0xA6,0xA7,0x49,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
394 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
395 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
396 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
397 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
398 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

◆ TBL_CT864

#define TBL_CT864
Value:
{0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
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D,0xBE,0xBF, \
411 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
412 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
413 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
414 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

◆ TBL_CT866

#define TBL_CT866
Value:
{0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

Definition at line 415 of file ff.c.

415 {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
416 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
417 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
418 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
419 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
420 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
421 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
422 0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}

◆ TBL_CT869

#define TBL_CT869
Value:
{0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x86,0x9C,0x8D,0x8F,0x90, \
0x91,0x90,0x92,0x95,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xA4,0xA5,0xA6,0xD9,0xDA,0xDB,0xDC,0xA7,0xA8,0xDF, \
0xA9,0xAA,0xAC,0xAD,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xCF,0xCF,0xD0,0xEF, \
0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}

Definition at line 423 of file ff.c.

423 {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
424 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x86,0x9C,0x8D,0x8F,0x90, \
425 0x91,0x90,0x92,0x95,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
426 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
427 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
428 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xA4,0xA5,0xA6,0xD9,0xDA,0xDB,0xDC,0xA7,0xA8,0xDF, \
429 0xA9,0xAA,0xAC,0xAD,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xCF,0xCF,0xD0,0xEF, \
430 0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}

◆ TBL_DC932

#define TBL_DC932   {0x81, 0x9F, 0xE0, 0xFC, 0x40, 0x7E, 0x80, 0xFC, 0x00, 0x00}

Definition at line 435 of file ff.c.

◆ TBL_DC936

#define TBL_DC936   {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0x80, 0xFE, 0x00, 0x00}

Definition at line 436 of file ff.c.

◆ TBL_DC949

#define TBL_DC949   {0x81, 0xFE, 0x00, 0x00, 0x41, 0x5A, 0x61, 0x7A, 0x81, 0xFE}

Definition at line 437 of file ff.c.

◆ TBL_DC950

#define TBL_DC950   {0x81, 0xFE, 0x00, 0x00, 0x40, 0x7E, 0xA1, 0xFE, 0x00, 0x00}

Definition at line 438 of file ff.c.

◆ XDIR_AccTime

#define XDIR_AccTime   16 /* exFAT: Last accessed time (DWORD) */

Definition at line 175 of file ff.c.

◆ XDIR_AccTZ

#define XDIR_AccTZ   24 /* exFAT: Last accessed timezone (BYTE) */

Definition at line 180 of file ff.c.

◆ XDIR_Attr

#define XDIR_Attr   4 /* exFAT: File attribute (WORD) */

Definition at line 172 of file ff.c.

◆ XDIR_CaseSum

#define XDIR_CaseSum   4 /* exFAT: Sum of case conversion table (DWORD) */

Definition at line 169 of file ff.c.

◆ XDIR_CrtTime

#define XDIR_CrtTime   8 /* exFAT: Created time (DWORD) */

Definition at line 173 of file ff.c.

◆ XDIR_CrtTime10

#define XDIR_CrtTime10   20 /* exFAT: Created time subsecond (BYTE) */

Definition at line 176 of file ff.c.

◆ XDIR_CrtTZ

#define XDIR_CrtTZ   22 /* exFAT: Created timezone (BYTE) */

Definition at line 178 of file ff.c.

◆ XDIR_FileSize

#define XDIR_FileSize   56 /* exFAT: File/Directory size (QWORD) */

Definition at line 186 of file ff.c.

◆ XDIR_FstClus

#define XDIR_FstClus   52 /* exFAT: First cluster of the file data (DWORD) */

Definition at line 185 of file ff.c.

◆ XDIR_GenFlags

#define XDIR_GenFlags   33 /* exFAT: General secondary flags (BYTE) */

Definition at line 181 of file ff.c.

◆ XDIR_Label

#define XDIR_Label   2 /* exFAT: Volume label (11-WORD) */

Definition at line 168 of file ff.c.

◆ XDIR_ModTime

#define XDIR_ModTime   12 /* exFAT: Modified time (DWORD) */

Definition at line 174 of file ff.c.

◆ XDIR_ModTime10

#define XDIR_ModTime10   21 /* exFAT: Modified time subsecond (BYTE) */

Definition at line 177 of file ff.c.

◆ XDIR_ModTZ

#define XDIR_ModTZ   23 /* exFAT: Modified timezone (BYTE) */

Definition at line 179 of file ff.c.

◆ XDIR_NameHash

#define XDIR_NameHash   36 /* exFAT: Hash of file name (WORD) */

Definition at line 183 of file ff.c.

◆ XDIR_NumLabel

#define XDIR_NumLabel   1 /* exFAT: Number of volume label characters (BYTE) */

Definition at line 167 of file ff.c.

◆ XDIR_NumName

#define XDIR_NumName   35 /* exFAT: Number of file name characters (BYTE) */

Definition at line 182 of file ff.c.

◆ XDIR_NumSec

#define XDIR_NumSec   1 /* exFAT: Number of secondary entries (BYTE) */

Definition at line 170 of file ff.c.

◆ XDIR_SetSum

#define XDIR_SetSum   2 /* exFAT: Sum of the set of directory entries (WORD) */

Definition at line 171 of file ff.c.

◆ XDIR_Type

#define XDIR_Type   0 /* exFAT: Type of exFAT directory entry (BYTE) */

Definition at line 166 of file ff.c.

◆ XDIR_ValidFileSize

#define XDIR_ValidFileSize   40 /* exFAT: Valid file size (QWORD) */

Definition at line 184 of file ff.c.

Function Documentation

◆ check_fs()

static UINT check_fs ( FATFS fs,
LBA_t  sect 
)
static

Definition at line 3238 of file ff.c.

3242{
3243 WORD w, sign;
3244 BYTE b;
3245
3246
3247 fs->wflag = 0; fs->winsect = (LBA_t)0 - 1; /* Invaidate window */
3248 if (move_window(fs, sect) != FR_OK) return 4; /* Load the boot sector */
3249 sign = ld_word(fs->win + BS_55AA);
3250#if FF_FS_EXFAT
3251 if (sign == 0xAA55 && !memcmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11)) return 1; /* It is an exFAT VBR */
3252#endif
3253 b = fs->win[BS_JmpBoot];
3254 if (b == 0xEB || b == 0xE9 || b == 0xE8) { /* Valid JumpBoot code? (short jump, near jump or near call) */
3255 if (sign == 0xAA55 && !memcmp(fs->win + BS_FilSysType32, "FAT32 ", 8)) {
3256 return 0; /* It is an FAT32 VBR */
3257 }
3258 /* FAT volumes formatted with early MS-DOS lack BS_55AA and BS_FilSysType, so FAT VBR needs to be identified without them. */
3259 w = ld_word(fs->win + BPB_BytsPerSec);
3260 b = fs->win[BPB_SecPerClus];
3261 if ((w & (w - 1)) == 0 && w >= FF_MIN_SS && w <= FF_MAX_SS /* Properness of sector size (512-4096 and 2^n) */
3262 && b != 0 && (b & (b - 1)) == 0 /* Properness of cluster size (2^n) */
3263 && ld_word(fs->win + BPB_RsvdSecCnt) != 0 /* Properness of reserved sectors (MNBZ) */
3264 && (UINT)fs->win[BPB_NumFATs] - 1 <= 1 /* Properness of FATs (1 or 2) */
3265 && ld_word(fs->win + BPB_RootEntCnt) != 0 /* Properness of root dir entries (MNBZ) */
3266 && (ld_word(fs->win + BPB_TotSec16) >= 128 || ld_dword(fs->win + BPB_TotSec32) >= 0x10000) /* Properness of volume sectors (>=128) */
3267 && ld_word(fs->win + BPB_FATSz16) != 0) { /* Properness of FAT size (MNBZ) */
3268 return 0; /* It can be presumed an FAT VBR */
3269 }
3270 }
3271 return sign == 0xAA55 ? 2 : 3; /* Not an FAT VBR (valid or invalid BS) */
3272}
static uint32_t b
Definition Common.c:37
static FRESULT move_window(FATFS *fs, LBA_t sect)
Definition ff.c:1047
#define BPB_TotSec16
Definition ff.c:102
#define BPB_FATSz16
Definition ff.c:104
#define BS_JmpBoot
Definition ff.c:95
#define BS_55AA
Definition ff.c:116
#define BPB_TotSec32
Definition ff.c:108
#define BPB_BytsPerSec
Definition ff.c:97
#define BS_FilSysType32
Definition ff.c:129
static DWORD ld_dword(const BYTE *ptr)
Definition ff.c:623
#define BPB_RootEntCnt
Definition ff.c:101
#define BPB_SecPerClus
Definition ff.c:98
#define BPB_RsvdSecCnt
Definition ff.c:99
#define BPB_NumFATs
Definition ff.c:100
static WORD ld_word(const BYTE *ptr)
Definition ff.c:614
unsigned short WORD
Definition ff.h:60
DWORD LBA_t
Definition ff.h:83
unsigned int UINT
Definition ff.h:58
@ FR_OK
Definition ff.h:277
unsigned char BYTE
Definition ff.h:59
#define FF_MAX_SS
Definition ffconf.h:200
#define FF_MIN_SS
Definition ffconf.h:199
BYTE win[FF_MAX_SS]
Definition ff.h:175
BYTE wflag
Definition ff.h:136
LBA_t winsect
Definition ff.h:174

◆ chk_lock()

static FRESULT chk_lock ( DIR dp,
int  acc 
)
static

Definition at line 917 of file ff.c.

921{
922 UINT i, be;
923
924 /* Search open object table for the object */
925 be = 0;
926 for (i = 0; i < FF_FS_LOCK; i++) {
927 if (Files[i].fs) { /* Existing entry */
928 if (Files[i].fs == dp->obj.fs && /* Check if the object matches with an open object */
929 Files[i].clu == dp->obj.sclust &&
930 Files[i].ofs == dp->dptr) break;
931 } else { /* Blank entry */
932 be = 1;
933 }
934 }
935 if (i == FF_FS_LOCK) { /* The object has not been opened */
936 return (!be && acc != 2) ? FR_TOO_MANY_OPEN_FILES : FR_OK; /* Is there a blank entry for new object? */
937 }
938
939 /* The object was opened. Reject any open against writing file and all write mode open */
940 return (acc != 0 || Files[i].ctr == 0x100) ? FR_LOCKED : FR_OK;
941}
static FILESEM Files[FF_FS_LOCK]
Definition ff.c:472
@ FR_TOO_MANY_OPEN_FILES
Definition ff.h:295
@ FR_LOCKED
Definition ff.h:293
#define FF_FS_LOCK
Definition ffconf.h:269
DWORD dptr
Definition ff.h:230
FFOBJID obj
Definition ff.h:229
FATFS * fs
Definition ff.h:183
DWORD sclust
Definition ff.h:187
DWORD clu
Definition ff.c:287
DWORD ofs
Definition ff.c:288

◆ clear_lock()

static void clear_lock ( FATFS fs)
static

Definition at line 1006 of file ff.c.

1009{
1010 UINT i;
1011
1012 for (i = 0; i < FF_FS_LOCK; i++) {
1013 if (Files[i].fs == fs) Files[i].fs = 0;
1014 }
1015}
FATFS * fs
Definition ff.c:286

◆ clst2sect()

static LBA_t clst2sect ( FATFS fs,
DWORD  clst 
)
static

Definition at line 1114 of file ff.c.

1118{
1119 clst -= 2; /* Cluster number is origin from 2 */
1120 if (clst >= fs->n_fatent - 2) return 0; /* Is it invalid cluster number? */
1121 return fs->database + (LBA_t)fs->csize * clst; /* Start sector number of the cluster */
1122}
LBA_t database
Definition ff.h:170
DWORD n_fatent
Definition ff.h:165
WORD csize
Definition ff.h:140

◆ cmp_lfn()

static int cmp_lfn ( const WCHAR lfnbuf,
BYTE dir 
)
static

Definition at line 1854 of file ff.c.

1858{
1859 UINT i, s;
1860 WCHAR wc, uc;
1861
1862
1863 if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO */
1864
1865 i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */
1866
1867 for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */
1868 uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */
1869 if (wc != 0) {
1870 if (i >= FF_MAX_LFN + 1 || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) { /* Compare it */
1871 return 0; /* Not matched */
1872 }
1873 wc = uc;
1874 } else {
1875 if (uc != 0xFFFF) return 0; /* Check filler */
1876 }
1877 }
1878
1879 if ((dir[LDIR_Ord] & LLEF) && wc && lfnbuf[i]) return 0; /* Last segment matched but different length */
1880
1881 return 1; /* The part of LFN matched */
1882}
#define LLEF
Definition ff.c:191
static const BYTE LfnOfs[]
Definition ff.c:513
#define LDIR_Ord
Definition ff.c:161
#define LDIR_FstClusLO
Definition ff.c:165
WORD WCHAR
Definition ff.h:62
DWORD ff_wtoupper(DWORD uni)
#define FF_MAX_LFN
Definition ffconf.h:120

◆ create_chain()

static DWORD create_chain ( FFOBJID obj,
DWORD  clst 
)
static

Definition at line 1494 of file ff.c.

1498{
1499 DWORD cs, ncl, scl;
1500 FRESULT res;
1501 FATFS *fs = obj->fs;
1502
1503
1504 if (clst == 0) { /* Create a new chain */
1505 scl = fs->last_clst; /* Suggested cluster to start to find */
1506 if (scl == 0 || scl >= fs->n_fatent) scl = 1;
1507 }
1508 else { /* Stretch a chain */
1509 cs = get_fat(obj, clst); /* Check the cluster status */
1510 if (cs < 2) return 1; /* Test for insanity */
1511 if (cs == 0xFFFFFFFF) return cs; /* Test for disk error */
1512 if (cs < fs->n_fatent) return cs; /* It is already followed by next cluster */
1513 scl = clst; /* Cluster to start to find */
1514 }
1515 if (fs->free_clst == 0) return 0; /* No free cluster */
1516
1517#if FF_FS_EXFAT
1518 if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
1519 ncl = find_bitmap(fs, scl, 1); /* Find a free cluster */
1520 if (ncl == 0 || ncl == 0xFFFFFFFF) return ncl; /* No free cluster or hard error? */
1521 res = change_bitmap(fs, ncl, 1, 1); /* Mark the cluster 'in use' */
1522 if (res == FR_INT_ERR) return 1;
1523 if (res == FR_DISK_ERR) return 0xFFFFFFFF;
1524 if (clst == 0) { /* Is it a new chain? */
1525 obj->stat = 2; /* Set status 'contiguous' */
1526 } else { /* It is a stretched chain */
1527 if (obj->stat == 2 && ncl != scl + 1) { /* Is the chain got fragmented? */
1528 obj->n_cont = scl - obj->sclust; /* Set size of the contiguous part */
1529 obj->stat = 3; /* Change status 'just fragmented' */
1530 }
1531 }
1532 if (obj->stat != 2) { /* Is the file non-contiguous? */
1533 if (ncl == clst + 1) { /* Is the cluster next to previous one? */
1534 obj->n_frag = obj->n_frag ? obj->n_frag + 1 : 2; /* Increment size of last framgent */
1535 } else { /* New fragment */
1536 if (obj->n_frag == 0) obj->n_frag = 1;
1537 res = fill_last_frag(obj, clst, ncl); /* Fill last fragment on the FAT and link it to new one */
1538 if (res == FR_OK) obj->n_frag = 1;
1539 }
1540 }
1541 } else
1542#endif
1543 { /* On the FAT/FAT32 volume */
1544 ncl = 0;
1545 if (scl == clst) { /* Stretching an existing chain? */
1546 ncl = scl + 1; /* Test if next cluster is free */
1547 if (ncl >= fs->n_fatent) ncl = 2;
1548 cs = get_fat(obj, ncl); /* Get next cluster status */
1549 if (cs == 1 || cs == 0xFFFFFFFF) return cs; /* Test for error */
1550 if (cs != 0) { /* Not free? */
1551 cs = fs->last_clst; /* Start at suggested cluster if it is valid */
1552 if (cs >= 2 && cs < fs->n_fatent) scl = cs;
1553 ncl = 0;
1554 }
1555 }
1556 if (ncl == 0) { /* The new cluster cannot be contiguous and find another fragment */
1557 ncl = scl; /* Start cluster */
1558 for (;;) {
1559 ncl++; /* Next cluster */
1560 if (ncl >= fs->n_fatent) { /* Check wrap-around */
1561 ncl = 2;
1562 if (ncl > scl) return 0; /* No free cluster found? */
1563 }
1564 cs = get_fat(obj, ncl); /* Get the cluster status */
1565 if (cs == 0) break; /* Found a free cluster? */
1566 if (cs == 1 || cs == 0xFFFFFFFF) return cs; /* Test for error */
1567 if (ncl == scl) return 0; /* No free cluster found? */
1568 }
1569 }
1570 res = put_fat(fs, ncl, 0xFFFFFFFF); /* Mark the new cluster 'EOC' */
1571 if (res == FR_OK && clst != 0) {
1572 res = put_fat(fs, clst, ncl); /* Link it from the previous one if needed */
1573 }
1574 }
1575
1576 if (res == FR_OK) { /* Update FSINFO if function succeeded. */
1577 fs->last_clst = ncl;
1578 if (fs->free_clst <= fs->n_fatent - 2) fs->free_clst--;
1579 fs->fsi_flag |= 1;
1580 } else {
1581 ncl = (res == FR_DISK_ERR) ? 0xFFFFFFFF : 1; /* Failed. Generate error status */
1582 }
1583
1584 return ncl; /* Return new cluster number or error status */
1585}
static FRESULT put_fat(FATFS *fs, DWORD clst, DWORD val)
Definition ff.c:1209
static DWORD get_fat(FFOBJID *obj, DWORD clst)
Definition ff.c:1131
FRESULT
Definition ff.h:276
@ FR_DISK_ERR
Definition ff.h:278
@ FR_INT_ERR
Definition ff.h:279
#define FS_EXFAT
Definition ff.h:408
unsigned long DWORD
Definition ff.h:61
Definition ff.h:132
BYTE fsi_flag
Definition ff.h:137
DWORD last_clst
Definition ff.h:154
DWORD free_clst
Definition ff.h:155
BYTE fs_type
Definition ff.h:133
BYTE stat
Definition ff.h:186

◆ create_name()

static FRESULT create_name ( DIR dp,
const TCHAR **  path 
)
static

Definition at line 2801 of file ff.c.

2805{
2806#if FF_USE_LFN /* LFN configuration */
2807 BYTE b, cf;
2808 WCHAR wc, *lfn;
2809 DWORD uc;
2810 UINT i, ni, si, di;
2811 const TCHAR *p;
2812
2813
2814 /* Create LFN into LFN working buffer */
2815 p = *path; lfn = dp->obj.fs->lfnbuf; di = 0;
2816 for (;;) {
2817 uc = tchar2uni(&p); /* Get a character */
2818 if (uc == 0xFFFFFFFF) return FR_INVALID_NAME; /* Invalid code or UTF decode error */
2819 if (uc >= 0x10000) lfn[di++] = (WCHAR)(uc >> 16); /* Store high surrogate if needed */
2820 wc = (WCHAR)uc;
2821 if (wc < ' ' || IsSeparator(wc)) break; /* Break if end of the path or a separator is found */
2822 if (wc < 0x80 && strchr("*:<>|\"\?\x7F", (int)wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */
2823 if (di >= FF_MAX_LFN) return FR_INVALID_NAME; /* Reject too long name */
2824 lfn[di++] = wc; /* Store the Unicode character */
2825 }
2826 if (wc < ' ') { /* Stopped at end of the path? */
2827 cf = NS_LAST; /* Last segment */
2828 } else { /* Stopped at a separator */
2829 while (IsSeparator(*p)) p++; /* Skip duplicated separators if exist */
2830 cf = 0; /* Next segment may follow */
2831 if (IsTerminator(*p)) cf = NS_LAST; /* Ignore terminating separator */
2832 }
2833 *path = p; /* Return pointer to the next segment */
2834
2835#if FF_FS_RPATH != 0
2836 if ((di == 1 && lfn[di - 1] == '.') ||
2837 (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot name? */
2838 lfn[di] = 0;
2839 for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */
2840 dp->fn[i] = (i < di) ? '.' : ' ';
2841 }
2842 dp->fn[i] = cf | NS_DOT; /* This is a dot entry */
2843 return FR_OK;
2844 }
2845#endif
2846 while (di) { /* Snip off trailing spaces and dots if exist */
2847 wc = lfn[di - 1];
2848 if (wc != ' ' && wc != '.') break;
2849 di--;
2850 }
2851 lfn[di] = 0; /* LFN is created into the working buffer */
2852 if (di == 0) return FR_INVALID_NAME; /* Reject null name */
2853
2854 /* Create SFN in directory form */
2855 for (si = 0; lfn[si] == ' '; si++) ; /* Remove leading spaces */
2856 if (si > 0 || lfn[si] == '.') cf |= NS_LOSS | NS_LFN; /* Is there any leading space or dot? */
2857 while (di > 0 && lfn[di - 1] != '.') di--; /* Find last dot (di<=si: no extension) */
2858
2859 memset(dp->fn, ' ', 11);
2860 i = b = 0; ni = 8;
2861 for (;;) {
2862 wc = lfn[si++]; /* Get an LFN character */
2863 if (wc == 0) break; /* Break on end of the LFN */
2864 if (wc == ' ' || (wc == '.' && si != di)) { /* Remove embedded spaces and dots */
2865 cf |= NS_LOSS | NS_LFN;
2866 continue;
2867 }
2868
2869 if (i >= ni || si == di) { /* End of field? */
2870 if (ni == 11) { /* Name extension overflow? */
2871 cf |= NS_LOSS | NS_LFN;
2872 break;
2873 }
2874 if (si != di) cf |= NS_LOSS | NS_LFN; /* Name body overflow? */
2875 if (si > di) break; /* No name extension? */
2876 si = di; i = 8; ni = 11; b <<= 2; /* Enter name extension */
2877 continue;
2878 }
2879
2880 if (wc >= 0x80) { /* Is this an extended character? */
2881 cf |= NS_LFN; /* LFN entry needs to be created */
2882#if FF_CODE_PAGE == 0
2883 if (ExCvt) { /* In SBCS cfg */
2884 wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */
2885 if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */
2886 } else { /* In DBCS cfg */
2887 wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */
2888 }
2889#elif FF_CODE_PAGE < 900 /* In SBCS cfg */
2890 wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */
2891 if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */
2892#else /* In DBCS cfg */
2893 wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */
2894#endif
2895 }
2896
2897 if (wc >= 0x100) { /* Is this a DBC? */
2898 if (i >= ni - 1) { /* Field overflow? */
2899 cf |= NS_LOSS | NS_LFN;
2900 i = ni; continue; /* Next field */
2901 }
2902 dp->fn[i++] = (BYTE)(wc >> 8); /* Put 1st byte */
2903 } else { /* SBC */
2904 if (wc == 0 || strchr("+,;=[]", (int)wc)) { /* Replace illegal characters for SFN */
2905 wc = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */
2906 } else {
2907 if (IsUpper(wc)) { /* ASCII upper case? */
2908 b |= 2;
2909 }
2910 if (IsLower(wc)) { /* ASCII lower case? */
2911 b |= 1; wc -= 0x20;
2912 }
2913 }
2914 }
2915 dp->fn[i++] = (BYTE)wc;
2916 }
2917
2918 if (dp->fn[0] == DDEM) dp->fn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */
2919
2920 if (ni == 8) b <<= 2; /* Shift capital flags if no extension */
2921 if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03) cf |= NS_LFN; /* LFN entry needs to be created if composite capitals */
2922 if (!(cf & NS_LFN)) { /* When LFN is in 8.3 format without extended character, NT flags are created */
2923 if (b & 0x01) cf |= NS_EXT; /* NT flag (Extension has small capital letters only) */
2924 if (b & 0x04) cf |= NS_BODY; /* NT flag (Body has small capital letters only) */
2925 }
2926
2927 dp->fn[NSFLAG] = cf; /* SFN is created into dp->fn[] */
2928
2929 return FR_OK;
2930
2931
2932#else /* FF_USE_LFN : Non-LFN configuration */
2933 BYTE c, d, *sfn;
2934 UINT ni, si, i;
2935 const char *p;
2936
2937 /* Create file name in directory form */
2938 p = *path; sfn = dp->fn;
2939 memset(sfn, ' ', 11);
2940 si = i = 0; ni = 8;
2941#if FF_FS_RPATH != 0
2942 if (p[si] == '.') { /* Is this a dot entry? */
2943 for (;;) {
2944 c = (BYTE)p[si++];
2945 if (c != '.' || si >= 3) break;
2946 sfn[i++] = c;
2947 }
2948 if (!IsSeparator(c) && c > ' ') return FR_INVALID_NAME;
2949 *path = p + si; /* Return pointer to the next segment */
2950 sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of the path */
2951 return FR_OK;
2952 }
2953#endif
2954 for (;;) {
2955 c = (BYTE)p[si++]; /* Get a byte */
2956 if (c <= ' ') break; /* Break if end of the path name */
2957 if (IsSeparator(c)) { /* Break if a separator is found */
2958 while (IsSeparator(p[si])) si++; /* Skip duplicated separator if exist */
2959 break;
2960 }
2961 if (c == '.' || i >= ni) { /* End of body or field overflow? */
2962 if (ni == 11 || c != '.') return FR_INVALID_NAME; /* Field overflow or invalid dot? */
2963 i = 8; ni = 11; /* Enter file extension field */
2964 continue;
2965 }
2966#if FF_CODE_PAGE == 0
2967 if (ExCvt && c >= 0x80) { /* Is SBC extended character? */
2968 c = ExCvt[c & 0x7F]; /* To upper SBC extended character */
2969 }
2970#elif FF_CODE_PAGE < 900
2971 if (c >= 0x80) { /* Is SBC extended character? */
2972 c = ExCvt[c & 0x7F]; /* To upper SBC extended character */
2973 }
2974#endif
2975 if (dbc_1st(c)) { /* Check if it is a DBC 1st byte */
2976 d = (BYTE)p[si++]; /* Get 2nd byte */
2977 if (!dbc_2nd(d) || i >= ni - 1) return FR_INVALID_NAME; /* Reject invalid DBC */
2978 sfn[i++] = c;
2979 sfn[i++] = d;
2980 } else { /* SBC */
2981 if (strchr("*+,:;<=>[]|\"\?\x7F", (int)c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */
2982 if (IsLower(c)) c -= 0x20; /* To upper */
2983 sfn[i++] = c;
2984 }
2985 }
2986 *path = &p[si]; /* Return pointer to the next segment */
2987 if (i == 0) return FR_INVALID_NAME; /* Reject nul string */
2988
2989 if (sfn[0] == DDEM) sfn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */
2990 sfn[NSFLAG] = (c <= ' ' || p[si] <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */
2991
2992 return FR_OK;
2993#endif /* FF_USE_LFN */
2994}
static uint32_t d
Definition Common.c:39
static uint32_t c
Definition Common.c:38
#define CODEPAGE
Definition ff.c:591
#define DDEM
Definition ff.c:189
#define RDDEM
Definition ff.c:190
static int dbc_1st(BYTE c)
Definition ff.c:688
#define NS_DOT
Definition ff.c:78
#define NS_EXT
Definition ff.c:77
#define NS_BODY
Definition ff.c:76
#define IsLower(c)
Definition ff.c:49
#define IsTerminator(c)
Definition ff.c:52
#define NS_LAST
Definition ff.c:75
#define IsUpper(c)
Definition ff.c:48
static DWORD tchar2uni(const TCHAR **str)
Definition ff.c:732
#define NS_LOSS
Definition ff.c:73
#define NSFLAG
Definition ff.c:72
#define IsSeparator(c)
Definition ff.c:51
static const BYTE ExCvt[]
Definition ff.c:592
#define NS_LFN
Definition ff.c:74
static int dbc_2nd(BYTE c)
Definition ff.c:708
char TCHAR
Definition ff.h:105
@ FR_INVALID_NAME
Definition ff.h:283
WCHAR ff_uni2oem(DWORD uni, WORD cp)
BYTE fn[12]
Definition ff.h:234
WCHAR * lfnbuf
Definition ff.h:145

◆ dbc_1st()

static int dbc_1st ( BYTE  c)
static

Definition at line 688 of file ff.c.

689{
690#if FF_CODE_PAGE == 0 /* Variable code page */
691 if (DbcTbl && c >= DbcTbl[0]) {
692 if (c <= DbcTbl[1]) return 1; /* 1st byte range 1 */
693 if (c >= DbcTbl[2] && c <= DbcTbl[3]) return 1; /* 1st byte range 2 */
694 }
695#elif FF_CODE_PAGE >= 900 /* DBCS fixed code page */
696 if (c >= DbcTbl[0]) {
697 if (c <= DbcTbl[1]) return 1;
698 if (c >= DbcTbl[2] && c <= DbcTbl[3]) return 1;
699 }
700#else /* SBCS fixed code page */
701 if (c != 0) return 0; /* Always false */
702#endif
703 return 0;
704}

◆ dbc_2nd()

static int dbc_2nd ( BYTE  c)
static

Definition at line 708 of file ff.c.

709{
710#if FF_CODE_PAGE == 0 /* Variable code page */
711 if (DbcTbl && c >= DbcTbl[4]) {
712 if (c <= DbcTbl[5]) return 1; /* 2nd byte range 1 */
713 if (c >= DbcTbl[6] && c <= DbcTbl[7]) return 1; /* 2nd byte range 2 */
714 if (c >= DbcTbl[8] && c <= DbcTbl[9]) return 1; /* 2nd byte range 3 */
715 }
716#elif FF_CODE_PAGE >= 900 /* DBCS fixed code page */
717 if (c >= DbcTbl[4]) {
718 if (c <= DbcTbl[5]) return 1;
719 if (c >= DbcTbl[6] && c <= DbcTbl[7]) return 1;
720 if (c >= DbcTbl[8] && c <= DbcTbl[9]) return 1;
721 }
722#else /* SBCS fixed code page */
723 if (c != 0) return 0; /* Always false */
724#endif
725 return 0;
726}

◆ dec_lock()

static FRESULT dec_lock ( UINT  i)
static

Definition at line 984 of file ff.c.

987{
988 WORD n;
989 FRESULT res;
990
991
992 if (--i < FF_FS_LOCK) { /* Index number origin from 0 */
993 n = Files[i].ctr;
994 if (n == 0x100) n = 0; /* If write mode open, delete the entry */
995 if (n > 0) n--; /* Decrement read mode open count */
996 Files[i].ctr = n;
997 if (n == 0) Files[i].fs = 0; /* Delete the entry if open count gets zero */
998 res = FR_OK;
999 } else {
1000 res = FR_INT_ERR; /* Invalid index nunber */
1001 }
1002 return res;
1003}
WORD ctr
Definition ff.c:289

◆ dir_alloc()

static FRESULT dir_alloc ( DIR dp,
UINT  n_ent 
)
static

Definition at line 1775 of file ff.c.

1779{
1780 FRESULT res;
1781 UINT n;
1782 FATFS *fs = dp->obj.fs;
1783
1784
1785 res = dir_sdi(dp, 0);
1786 if (res == FR_OK) {
1787 n = 0;
1788 do {
1789 res = move_window(fs, dp->sect);
1790 if (res != FR_OK) break;
1791#if FF_FS_EXFAT
1792 if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) { /* Is the entry free? */
1793#else
1794 if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) { /* Is the entry free? */
1795#endif
1796 if (++n == n_ent) break; /* Is a block of contiguous free entries found? */
1797 } else {
1798 n = 0; /* Not a free entry, restart to search */
1799 }
1800 res = dir_next(dp, 1); /* Next entry with table stretch enabled */
1801 } while (res == FR_OK);
1802 }
1803
1804 if (res == FR_NO_FILE) res = FR_DENIED; /* No directory entry to allocate */
1805 return res;
1806}
static FRESULT dir_next(DIR *dp, int stretch)
Definition ff.c:1714
#define XDIR_Type
Definition ff.c:166
static FRESULT dir_sdi(DIR *dp, DWORD ofs)
Definition ff.c:1666
#define DIR_Name
Definition ff.c:151
@ FR_DENIED
Definition ff.h:284
@ FR_NO_FILE
Definition ff.h:281
BYTE * dir
Definition ff.h:233
LBA_t sect
Definition ff.h:232

◆ dir_clear()

static FRESULT dir_clear ( FATFS fs,
DWORD  clst 
)
static

Definition at line 1627 of file ff.c.

1631{
1632 LBA_t sect;
1633 UINT n, szb;
1634 BYTE *ibuf;
1635
1636
1637 if (sync_window(fs) != FR_OK) return FR_DISK_ERR; /* Flush disk access window */
1638 sect = clst2sect(fs, clst); /* Top of the cluster */
1639 fs->winsect = sect; /* Set window to top of the cluster */
1640 memset(fs->win, 0, sizeof fs->win); /* Clear window buffer */
1641#if FF_USE_LFN == 3 /* Quick table clear by using multi-secter write */
1642 /* Allocate a temporary buffer */
1643 for (szb = ((DWORD)fs->csize * SS(fs) >= MAX_MALLOC) ? MAX_MALLOC : fs->csize * SS(fs), ibuf = 0; szb > SS(fs) && (ibuf = ff_memalloc(szb)) == 0; szb /= 2) ;
1644 if (szb > SS(fs)) { /* Buffer allocated? */
1645 memset(ibuf, 0, szb);
1646 szb /= SS(fs); /* Bytes -> Sectors */
1647 for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ; /* Fill the cluster with 0 */
1648 ff_memfree(ibuf);
1649 } else
1650#endif
1651 {
1652 ibuf = fs->win; szb = 1; /* Use window buffer (many single-sector writes may take a time) */
1653 for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ; /* Fill the cluster with 0 */
1654 }
1655 return (n == fs->csize) ? FR_OK : FR_DISK_ERR;
1656}
@ RES_OK
Definition diskio.h:17
DRESULT disk_write(BYTE pdrv, const BYTE *buff, LBA_t sector, UINT count)
#define SS(fs)
Definition ff.c:263
static LBA_t clst2sect(FATFS *fs, DWORD clst)
Definition ff.c:1114
static FRESULT sync_window(FATFS *fs)
Definition ff.c:1025
#define MAX_MALLOC
Definition ff.c:549
void ff_memfree(void *mblock)
Definition ffsystem.c:28
void * ff_memalloc(UINT msize)
Definition ffsystem.c:16
BYTE pdrv
Definition ff.h:134

◆ dir_find()

static FRESULT dir_find ( DIR dp)
static

Definition at line 2353 of file ff.c.

2356{
2357 FRESULT res;
2358 FATFS *fs = dp->obj.fs;
2359 BYTE c;
2360#if FF_USE_LFN
2361 BYTE a, ord, sum;
2362#endif
2363
2364 res = dir_sdi(dp, 0); /* Rewind directory object */
2365 if (res != FR_OK) return res;
2366#if FF_FS_EXFAT
2367 if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
2368 BYTE nc;
2369 UINT di, ni;
2370 WORD hash = xname_sum(fs->lfnbuf); /* Hash value of the name to find */
2371
2372 while ((res = DIR_READ_FILE(dp)) == FR_OK) { /* Read an item */
2373#if FF_MAX_LFN < 255
2374 if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue; /* Skip comparison if inaccessible object name */
2375#endif
2376 if (ld_word(fs->dirbuf + XDIR_NameHash) != hash) continue; /* Skip comparison if hash mismatched */
2377 for (nc = fs->dirbuf[XDIR_NumName], di = SZDIRE * 2, ni = 0; nc; nc--, di += 2, ni++) { /* Compare the name */
2378 if ((di % SZDIRE) == 0) di += 2;
2379 if (ff_wtoupper(ld_word(fs->dirbuf + di)) != ff_wtoupper(fs->lfnbuf[ni])) break;
2380 }
2381 if (nc == 0 && !fs->lfnbuf[ni]) break; /* Name matched? */
2382 }
2383 return res;
2384 }
2385#endif
2386 /* On the FAT/FAT32 volume */
2387#if FF_USE_LFN
2388 ord = sum = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */
2389#endif
2390 do {
2391 res = move_window(fs, dp->sect);
2392 if (res != FR_OK) break;
2393 c = dp->dir[DIR_Name];
2394 if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */
2395#if FF_USE_LFN /* LFN configuration */
2396 dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK;
2397 if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */
2398 ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */
2399 } else {
2400 if (a == AM_LFN) { /* An LFN entry is found */
2401 if (!(dp->fn[NSFLAG] & NS_NOLFN)) {
2402 if (c & LLEF) { /* Is it start of LFN sequence? */
2403 sum = dp->dir[LDIR_Chksum];
2404 c &= (BYTE)~LLEF; ord = c; /* LFN start order */
2405 dp->blk_ofs = dp->dptr; /* Start offset of LFN */
2406 }
2407 /* Check validity of the LFN entry and compare it with given name */
2408 ord = (c == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
2409 }
2410 } else { /* An SFN entry is found */
2411 if (ord == 0 && sum == sum_sfn(dp->dir)) break; /* LFN matched? */
2412 if (!(dp->fn[NSFLAG] & NS_LOSS) && !memcmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */
2413 ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */
2414 }
2415 }
2416#else /* Non LFN configuration */
2417 dp->obj.attr = dp->dir[DIR_Attr] & AM_MASK;
2418 if (!(dp->dir[DIR_Attr] & AM_VOL) && !memcmp(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */
2419#endif
2420 res = dir_next(dp, 0); /* Next entry */
2421 } while (res == FR_OK);
2422
2423 return res;
2424}
static uint32_t a
Definition Common.c:36
#define XDIR_NumName
Definition ff.c:182
#define NS_NOLFN
Definition ff.c:79
#define AM_VOL
Definition ff.c:65
static BYTE sum_sfn(const BYTE *dir)
Definition ff.c:2022
#define XDIR_NameHash
Definition ff.c:183
#define DIR_READ_FILE(dp)
Definition ff.c:2272
#define SZDIRE
Definition ff.c:188
#define AM_LFN
Definition ff.c:66
static int cmp_lfn(const WCHAR *lfnbuf, BYTE *dir)
Definition ff.c:1854
#define DIR_Attr
Definition ff.c:152
#define LDIR_Chksum
Definition ff.c:164
#define AM_MASK
Definition ff.c:67
DWORD blk_ofs
Definition ff.h:236
BYTE attr
Definition ff.h:185

◆ dir_next()

static FRESULT dir_next ( DIR dp,
int  stretch 
)
static

Definition at line 1714 of file ff.c.

1718{
1719 DWORD ofs, clst;
1720 FATFS *fs = dp->obj.fs;
1721
1722
1723 ofs = dp->dptr + SZDIRE; /* Next entry */
1724 if (ofs >= (DWORD)((FF_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR)) dp->sect = 0; /* Disable it if the offset reached the max value */
1725 if (dp->sect == 0) return FR_NO_FILE; /* Report EOT if it has been disabled */
1726
1727 if (ofs % SS(fs) == 0) { /* Sector changed? */
1728 dp->sect++; /* Next sector */
1729
1730 if (dp->clust == 0) { /* Static table */
1731 if (ofs / SZDIRE >= fs->n_rootdir) { /* Report EOT if it reached end of static table */
1732 dp->sect = 0; return FR_NO_FILE;
1733 }
1734 }
1735 else { /* Dynamic table */
1736 if ((ofs / SS(fs) & (fs->csize - 1)) == 0) { /* Cluster changed? */
1737 clst = get_fat(&dp->obj, dp->clust); /* Get next cluster */
1738 if (clst <= 1) return FR_INT_ERR; /* Internal error */
1739 if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */
1740 if (clst >= fs->n_fatent) { /* It reached end of dynamic table */
1741#if !FF_FS_READONLY
1742 if (!stretch) { /* If no stretch, report EOT */
1743 dp->sect = 0; return FR_NO_FILE;
1744 }
1745 clst = create_chain(&dp->obj, dp->clust); /* Allocate a cluster */
1746 if (clst == 0) return FR_DENIED; /* No free cluster */
1747 if (clst == 1) return FR_INT_ERR; /* Internal error */
1748 if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */
1749 if (dir_clear(fs, clst) != FR_OK) return FR_DISK_ERR; /* Clean up the stretched table */
1750 if (FF_FS_EXFAT) dp->obj.stat |= 4; /* exFAT: The directory has been stretched */
1751#else
1752 if (!stretch) dp->sect = 0; /* (this line is to suppress compiler warning) */
1753 dp->sect = 0; return FR_NO_FILE; /* Report EOT */
1754#endif
1755 }
1756 dp->clust = clst; /* Initialize data for new cluster */
1757 dp->sect = clst2sect(fs, clst);
1758 }
1759 }
1760 }
1761 dp->dptr = ofs; /* Current entry */
1762 dp->dir = fs->win + ofs % SS(fs); /* Pointer to the entry in the win[] */
1763
1764 return FR_OK;
1765}
static DWORD create_chain(FFOBJID *obj, DWORD clst)
Definition ff.c:1494
#define MAX_DIR
Definition ff.c:39
static FRESULT dir_clear(FATFS *fs, DWORD clst)
Definition ff.c:1627
#define MAX_DIR_EX
Definition ff.c:40
#define FF_FS_EXFAT
Definition ffconf.h:237
DWORD clust
Definition ff.h:231
WORD n_rootdir
Definition ff.h:139

◆ dir_read()

static FRESULT dir_read ( DIR dp,
int  vol 
)
static

Definition at line 2275 of file ff.c.

2279{
2280 FRESULT res = FR_NO_FILE;
2281 FATFS *fs = dp->obj.fs;
2282 BYTE attr, b;
2283#if FF_USE_LFN
2284 BYTE ord = 0xFF, sum = 0xFF;
2285#endif
2286
2287 while (dp->sect) {
2288 res = move_window(fs, dp->sect);
2289 if (res != FR_OK) break;
2290 b = dp->dir[DIR_Name]; /* Test for the entry type */
2291 if (b == 0) {
2292 res = FR_NO_FILE; break; /* Reached to end of the directory */
2293 }
2294#if FF_FS_EXFAT
2295 if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
2296 if (FF_USE_LABEL && vol) {
2297 if (b == ET_VLABEL) break; /* Volume label entry? */
2298 } else {
2299 if (b == ET_FILEDIR) { /* Start of the file entry block? */
2300 dp->blk_ofs = dp->dptr; /* Get location of the block */
2301 res = load_xdir(dp); /* Load the entry block */
2302 if (res == FR_OK) {
2303 dp->obj.attr = fs->dirbuf[XDIR_Attr] & AM_MASK; /* Get attribute */
2304 }
2305 break;
2306 }
2307 }
2308 } else
2309#endif
2310 { /* On the FAT/FAT32 volume */
2311 dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */
2312#if FF_USE_LFN /* LFN configuration */
2313 if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
2314 ord = 0xFF;
2315 } else {
2316 if (attr == AM_LFN) { /* An LFN entry is found */
2317 if (b & LLEF) { /* Is it start of an LFN sequence? */
2318 sum = dp->dir[LDIR_Chksum];
2319 b &= (BYTE)~LLEF; ord = b;
2320 dp->blk_ofs = dp->dptr;
2321 }
2322 /* Check LFN validity and capture it */
2323 ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
2324 } else { /* An SFN entry is found */
2325 if (ord != 0 || sum != sum_sfn(dp->dir)) { /* Is there a valid LFN? */
2326 dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */
2327 }
2328 break;
2329 }
2330 }
2331#else /* Non LFN configuration */
2332 if (b != DDEM && b != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */
2333 break;
2334 }
2335#endif
2336 }
2337 res = dir_next(dp, 0); /* Next entry */
2338 if (res != FR_OK) break;
2339 }
2340
2341 if (res != FR_OK) dp->sect = 0; /* Terminate the read operation on error or EOT */
2342 return res;
2343}
static int pick_lfn(WCHAR *lfnbuf, BYTE *dir)
Definition ff.c:1890
#define ET_FILEDIR
Definition ff.c:87
#define ET_VLABEL
Definition ff.c:86
#define XDIR_Attr
Definition ff.c:172
#define AM_ARC
Definition ff.h:415
#define FF_USE_LABEL
Definition ffconf.h:53

◆ dir_register()

static FRESULT dir_register ( DIR dp)
static

Definition at line 2434 of file ff.c.

2437{
2438 FRESULT res;
2439 FATFS *fs = dp->obj.fs;
2440#if FF_USE_LFN /* LFN configuration */
2441 UINT n, len, n_ent;
2442 BYTE sn[12], sum;
2443
2444
2445 if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME; /* Check name validity */
2446 for (len = 0; fs->lfnbuf[len]; len++) ; /* Get lfn length */
2447
2448#if FF_FS_EXFAT
2449 if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
2450 n_ent = (len + 14) / 15 + 2; /* Number of entries to allocate (85+C0+C1s) */
2451 res = dir_alloc(dp, n_ent); /* Allocate directory entries */
2452 if (res != FR_OK) return res;
2453 dp->blk_ofs = dp->dptr - SZDIRE * (n_ent - 1); /* Set the allocated entry block offset */
2454
2455 if (dp->obj.stat & 4) { /* Has the directory been stretched by new allocation? */
2456 dp->obj.stat &= ~4;
2457 res = fill_first_frag(&dp->obj); /* Fill the first fragment on the FAT if needed */
2458 if (res != FR_OK) return res;
2459 res = fill_last_frag(&dp->obj, dp->clust, 0xFFFFFFFF); /* Fill the last fragment on the FAT if needed */
2460 if (res != FR_OK) return res;
2461 if (dp->obj.sclust != 0) { /* Is it a sub-directory? */
2462 DIR dj;
2463
2464 res = load_obj_xdir(&dj, &dp->obj); /* Load the object status */
2465 if (res != FR_OK) return res;
2466 dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
2467 st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize);
2468 st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
2469 fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */
2470 res = store_xdir(&dj); /* Store the object status */
2471 if (res != FR_OK) return res;
2472 }
2473 }
2474
2475 create_xdir(fs->dirbuf, fs->lfnbuf); /* Create on-memory directory block to be written later */
2476 return FR_OK;
2477 }
2478#endif
2479 /* On the FAT/FAT32 volume */
2480 memcpy(sn, dp->fn, 12);
2481 if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */
2482 dp->fn[NSFLAG] = NS_NOLFN; /* Find only SFN */
2483 for (n = 1; n < 100; n++) {
2484 gen_numname(dp->fn, sn, fs->lfnbuf, n); /* Generate a numbered name */
2485 res = dir_find(dp); /* Check if the name collides with existing SFN */
2486 if (res != FR_OK) break;
2487 }
2488 if (n == 100) return FR_DENIED; /* Abort if too many collisions */
2489 if (res != FR_NO_FILE) return res; /* Abort if the result is other than 'not collided' */
2490 dp->fn[NSFLAG] = sn[NSFLAG];
2491 }
2492
2493 /* Create an SFN with/without LFNs. */
2494 n_ent = (sn[NSFLAG] & NS_LFN) ? (len + 12) / 13 + 1 : 1; /* Number of entries to allocate */
2495 res = dir_alloc(dp, n_ent); /* Allocate entries */
2496 if (res == FR_OK && --n_ent) { /* Set LFN entry if needed */
2497 res = dir_sdi(dp, dp->dptr - n_ent * SZDIRE);
2498 if (res == FR_OK) {
2499 sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */
2500 do { /* Store LFN entries in bottom first */
2501 res = move_window(fs, dp->sect);
2502 if (res != FR_OK) break;
2503 put_lfn(fs->lfnbuf, dp->dir, (BYTE)n_ent, sum);
2504 fs->wflag = 1;
2505 res = dir_next(dp, 0); /* Next entry */
2506 } while (res == FR_OK && --n_ent);
2507 }
2508 }
2509
2510#else /* Non LFN configuration */
2511 res = dir_alloc(dp, 1); /* Allocate an entry for SFN */
2512
2513#endif
2514
2515 /* Set SFN entry */
2516 if (res == FR_OK) {
2517 res = move_window(fs, dp->sect);
2518 if (res == FR_OK) {
2519 memset(dp->dir, 0, SZDIRE); /* Clean the entry */
2520 memcpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */
2521#if FF_USE_LFN
2522 dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */
2523#endif
2524 fs->wflag = 1;
2525 }
2526 }
2527
2528 return res;
2529}
static void gen_numname(BYTE *dst, const BYTE *src, const WCHAR *lfn, UINT seq)
Definition ff.c:1965
#define NS_NONAME
Definition ff.c:80
static FRESULT dir_alloc(DIR *dp, UINT n_ent)
Definition ff.c:1775
#define XDIR_ValidFileSize
Definition ff.c:184
#define DIR_NTres
Definition ff.c:153
#define XDIR_FileSize
Definition ff.c:186
static void put_lfn(const WCHAR *lfn, BYTE *dir, BYTE ord, BYTE sum)
Definition ff.c:1928
static FRESULT dir_find(DIR *dp)
Definition ff.c:2353
#define XDIR_GenFlags
Definition ff.c:181
Definition ff.h:228
FSIZE_t objsize
Definition ff.h:188

◆ dir_remove()

static FRESULT dir_remove ( DIR dp)
static

Definition at line 2540 of file ff.c.

2543{
2544 FRESULT res;
2545 FATFS *fs = dp->obj.fs;
2546#if FF_USE_LFN /* LFN configuration */
2547 DWORD last = dp->dptr;
2548
2549 res = (dp->blk_ofs == 0xFFFFFFFF) ? FR_OK : dir_sdi(dp, dp->blk_ofs); /* Goto top of the entry block if LFN is exist */
2550 if (res == FR_OK) {
2551 do {
2552 res = move_window(fs, dp->sect);
2553 if (res != FR_OK) break;
2554 if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
2555 dp->dir[XDIR_Type] &= 0x7F; /* Clear the entry InUse flag. */
2556 } else { /* On the FAT/FAT32 volume */
2557 dp->dir[DIR_Name] = DDEM; /* Mark the entry 'deleted'. */
2558 }
2559 fs->wflag = 1;
2560 if (dp->dptr >= last) break; /* If reached last entry then all entries of the object has been deleted. */
2561 res = dir_next(dp, 0); /* Next entry */
2562 } while (res == FR_OK);
2563 if (res == FR_NO_FILE) res = FR_INT_ERR;
2564 }
2565#else /* Non LFN configuration */
2566
2567 res = move_window(fs, dp->sect);
2568 if (res == FR_OK) {
2569 dp->dir[DIR_Name] = DDEM; /* Mark the entry 'deleted'.*/
2570 fs->wflag = 1;
2571 }
2572#endif
2573
2574 return res;
2575}

◆ dir_sdi()

static FRESULT dir_sdi ( DIR dp,
DWORD  ofs 
)
static

Definition at line 1666 of file ff.c.

1670{
1671 DWORD csz, clst;
1672 FATFS *fs = dp->obj.fs;
1673
1674
1675 if (ofs >= (DWORD)((FF_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR) || ofs % SZDIRE) { /* Check range of offset and alignment */
1676 return FR_INT_ERR;
1677 }
1678 dp->dptr = ofs; /* Set current offset */
1679 clst = dp->obj.sclust; /* Table start cluster (0:root) */
1680 if (clst == 0 && fs->fs_type >= FS_FAT32) { /* Replace cluster# 0 with root cluster# */
1681 clst = (DWORD)fs->dirbase;
1682 if (FF_FS_EXFAT) dp->obj.stat = 0; /* exFAT: Root dir has an FAT chain */
1683 }
1684
1685 if (clst == 0) { /* Static table (root-directory on the FAT volume) */
1686 if (ofs / SZDIRE >= fs->n_rootdir) return FR_INT_ERR; /* Is index out of range? */
1687 dp->sect = fs->dirbase;
1688
1689 } else { /* Dynamic table (sub-directory or root-directory on the FAT32/exFAT volume) */
1690 csz = (DWORD)fs->csize * SS(fs); /* Bytes per cluster */
1691 while (ofs >= csz) { /* Follow cluster chain */
1692 clst = get_fat(&dp->obj, clst); /* Get next cluster */
1693 if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */
1694 if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR; /* Reached to end of table or internal error */
1695 ofs -= csz;
1696 }
1697 dp->sect = clst2sect(fs, clst);
1698 }
1699 dp->clust = clst; /* Current cluster# */
1700 if (dp->sect == 0) return FR_INT_ERR;
1701 dp->sect += ofs / SS(fs); /* Sector# of the directory entry */
1702 dp->dir = fs->win + (ofs % SS(fs)); /* Pointer to the entry in the win[] */
1703
1704 return FR_OK;
1705}
#define FS_FAT32
Definition ff.h:407
LBA_t dirbase
Definition ff.h:169

◆ enq_lock()

static int enq_lock ( void  )
static

Definition at line 944 of file ff.c.

945{
946 UINT i;
947
948 for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
949 return (i == FF_FS_LOCK) ? 0 : 1;
950}

◆ f_chdir()

FRESULT f_chdir ( const TCHAR path)

Definition at line 4205 of file ff.c.

4208{
4209#if FF_STR_VOLUME_ID == 2
4210 UINT i;
4211#endif
4212 FRESULT res;
4213 DIR dj;
4214 FATFS *fs;
4216
4217
4218 /* Get logical drive */
4219 res = mount_volume(&path, &fs, 0);
4220 if (res == FR_OK) {
4221 dj.obj.fs = fs;
4222 INIT_NAMBUF(fs);
4223 res = follow_path(&dj, path); /* Follow the path */
4224 if (res == FR_OK) { /* Follow completed */
4225 if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it the start directory itself? */
4226 fs->cdir = dj.obj.sclust;
4227#if FF_FS_EXFAT
4228 if (fs->fs_type == FS_EXFAT) {
4229 fs->cdc_scl = dj.obj.c_scl;
4230 fs->cdc_size = dj.obj.c_size;
4231 fs->cdc_ofs = dj.obj.c_ofs;
4232 }
4233#endif
4234 } else {
4235 if (dj.obj.attr & AM_DIR) { /* It is a sub-directory */
4236#if FF_FS_EXFAT
4237 if (fs->fs_type == FS_EXFAT) {
4238 fs->cdir = ld_dword(fs->dirbuf + XDIR_FstClus); /* Sub-directory cluster */
4239 fs->cdc_scl = dj.obj.sclust; /* Save containing directory information */
4240 fs->cdc_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat;
4241 fs->cdc_ofs = dj.blk_ofs;
4242 } else
4243#endif
4244 {
4245 fs->cdir = ld_clust(fs, dj.dir); /* Sub-directory cluster */
4246 }
4247 } else {
4248 res = FR_NO_PATH; /* Reached but a file */
4249 }
4250 }
4251 }
4252 FREE_NAMBUF();
4253 if (res == FR_NO_FILE) res = FR_NO_PATH;
4254#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed if in Unix style volume ID */
4255 if (res == FR_OK) {
4256 for (i = FF_VOLUMES - 1; i && fs != FatFs[i]; i--) ; /* Set current drive */
4257 CurrVol = (BYTE)i;
4258 }
4259#endif
4260 }
4261
4262 LEAVE_FF(fs, res);
4263}
static FATFS * FatFs[FF_VOLUMES]
Definition ff.c:464
static FRESULT mount_volume(const TCHAR **path, FATFS **rfs, BYTE mode)
Definition ff.c:3332
#define LEAVE_FF(fs, res)
Definition ff.c:244
#define INIT_NAMBUF(fs)
Definition ff.c:545
#define FREE_NAMBUF()
Definition ff.c:546
static DWORD ld_clust(FATFS *fs, const BYTE *dir)
Definition ff.c:1817
static BYTE CurrVol
Definition ff.c:468
#define DEF_NAMBUF
Definition ff.c:544
#define XDIR_FstClus
Definition ff.c:185
static FRESULT follow_path(DIR *dp, const TCHAR *path)
Definition ff.c:3003
#define AM_DIR
Definition ff.h:414
@ FR_NO_PATH
Definition ff.h:282
#define FF_VOLUMES
Definition ffconf.h:172
DWORD cdir
Definition ff.h:158

◆ f_chdrive()

FRESULT f_chdrive ( const TCHAR path)

Definition at line 4188 of file ff.c.

4191{
4192 int vol;
4193
4194
4195 /* Get logical drive number */
4196 vol = get_ldnumber(&path);
4197 if (vol < 0) return FR_INVALID_DRIVE;
4198 CurrVol = (BYTE)vol; /* Set it as current volume */
4199
4200 return FR_OK;
4201}
static int get_ldnumber(const TCHAR **path)
Definition ff.c:3090
@ FR_INVALID_DRIVE
Definition ff.h:288

◆ f_close()

FRESULT f_close ( FIL fp)

Definition at line 4152 of file ff.c.

4155{
4156 FRESULT res;
4157 FATFS *fs;
4158
4159#if !FF_FS_READONLY
4160 res = f_sync(fp); /* Flush cached data */
4161 if (res == FR_OK)
4162#endif
4163 {
4164 res = validate(&fp->obj, &fs); /* Lock volume */
4165 if (res == FR_OK) {
4166#if FF_FS_LOCK != 0
4167 res = dec_lock(fp->obj.lockid); /* Decrement file open counter */
4168 if (res == FR_OK) fp->obj.fs = 0; /* Invalidate file object */
4169#else
4170 fp->obj.fs = 0; /* Invalidate file object */
4171#endif
4172#if FF_FS_REENTRANT
4173 unlock_fs(fs, FR_OK); /* Unlock volume */
4174#endif
4175 }
4176 }
4177 return res;
4178}
FILE * fp
Definition FileIo.c:56
FRESULT f_sync(FIL *fp)
Definition ff.c:4071
static FRESULT validate(FFOBJID *obj, FATFS **rfs)
Definition ff.c:3561
static FRESULT dec_lock(UINT i)
Definition ff.c:984

◆ f_closedir()

FRESULT f_closedir ( DIR dp)

Definition at line 4597 of file ff.c.

4600{
4601 FRESULT res;
4602 FATFS *fs;
4603
4604
4605 res = validate(&dp->obj, &fs); /* Check validity of the file object */
4606 if (res == FR_OK) {
4607#if FF_FS_LOCK != 0
4608 if (dp->obj.lockid) res = dec_lock(dp->obj.lockid); /* Decrement sub-directory open counter */
4609 if (res == FR_OK) dp->obj.fs = 0; /* Invalidate directory object */
4610#else
4611 dp->obj.fs = 0; /* Invalidate directory object */
4612#endif
4613#if FF_FS_REENTRANT
4614 unlock_fs(fs, FR_OK); /* Unlock volume */
4615#endif
4616 }
4617 return res;
4618}
UINT lockid
Definition ff.h:197

◆ f_getfree()

FRESULT f_getfree ( const TCHAR path,
DWORD nclst,
FATFS **  fatfs 
)

Definition at line 4750 of file ff.c.

4755{
4756 FRESULT res;
4757 FATFS *fs;
4758 DWORD nfree, clst, stat;
4759 LBA_t sect;
4760 UINT i;
4761 FFOBJID obj;
4762
4763
4764 /* Get logical drive */
4765 res = mount_volume(&path, &fs, 0);
4766 if (res == FR_OK) {
4767 *fatfs = fs; /* Return ptr to the fs object */
4768 /* If free_clst is valid, return it without full FAT scan */
4769 if (fs->free_clst <= fs->n_fatent - 2) {
4770 *nclst = fs->free_clst;
4771 } else {
4772 /* Scan FAT to obtain number of free clusters */
4773 nfree = 0;
4774 if (fs->fs_type == FS_FAT12) { /* FAT12: Scan bit field FAT entries */
4775 clst = 2; obj.fs = fs;
4776 do {
4777 stat = get_fat(&obj, clst);
4778 if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }
4779 if (stat == 1) { res = FR_INT_ERR; break; }
4780 if (stat == 0) nfree++;
4781 } while (++clst < fs->n_fatent);
4782 } else {
4783#if FF_FS_EXFAT
4784 if (fs->fs_type == FS_EXFAT) { /* exFAT: Scan allocation bitmap */
4785 BYTE bm;
4786 UINT b;
4787
4788 clst = fs->n_fatent - 2; /* Number of clusters */
4789 sect = fs->bitbase; /* Bitmap sector */
4790 i = 0; /* Offset in the sector */
4791 do { /* Counts numbuer of bits with zero in the bitmap */
4792 if (i == 0) {
4793 res = move_window(fs, sect++);
4794 if (res != FR_OK) break;
4795 }
4796 for (b = 8, bm = fs->win[i]; b && clst; b--, clst--) {
4797 if (!(bm & 1)) nfree++;
4798 bm >>= 1;
4799 }
4800 i = (i + 1) % SS(fs);
4801 } while (clst);
4802 } else
4803#endif
4804 { /* FAT16/32: Scan WORD/DWORD FAT entries */
4805 clst = fs->n_fatent; /* Number of entries */
4806 sect = fs->fatbase; /* Top of the FAT */
4807 i = 0; /* Offset in the sector */
4808 do { /* Counts numbuer of entries with zero in the FAT */
4809 if (i == 0) {
4810 res = move_window(fs, sect++);
4811 if (res != FR_OK) break;
4812 }
4813 if (fs->fs_type == FS_FAT16) {
4814 if (ld_word(fs->win + i) == 0) nfree++;
4815 i += 2;
4816 } else {
4817 if ((ld_dword(fs->win + i) & 0x0FFFFFFF) == 0) nfree++;
4818 i += 4;
4819 }
4820 i %= SS(fs);
4821 } while (--clst);
4822 }
4823 }
4824 if (res == FR_OK) { /* Update parameters if succeeded */
4825 *nclst = nfree; /* Return the free clusters */
4826 fs->free_clst = nfree; /* Now free_clst is valid */
4827 fs->fsi_flag |= 1; /* FAT32: FSInfo is to be updated */
4828 }
4829 }
4830 }
4831
4832 LEAVE_FF(fs, res);
4833}
#define FS_FAT16
Definition ff.h:406
#define FS_FAT12
Definition ff.h:405
LBA_t fatbase
Definition ff.h:168
Definition ff.h:182

◆ f_gets()

TCHAR * f_gets ( TCHAR buff,
int  len,
FIL fp 
)

Definition at line 6338 of file ff.c.

6343{
6344 int nc = 0;
6345 TCHAR *p = buff;
6346 BYTE s[4];
6347 UINT rc;
6348 DWORD dc;
6349#if FF_USE_LFN && FF_LFN_UNICODE && FF_STRF_ENCODE <= 2
6350 WCHAR wc;
6351#endif
6352#if FF_USE_LFN && FF_LFN_UNICODE && FF_STRF_ENCODE == 3
6353 UINT ct;
6354#endif
6355
6356#if FF_USE_LFN && FF_LFN_UNICODE /* With code conversion (Unicode API) */
6357 /* Make a room for the character and terminator */
6358 if (FF_LFN_UNICODE == 1) len -= (FF_STRF_ENCODE == 0) ? 1 : 2;
6359 if (FF_LFN_UNICODE == 2) len -= (FF_STRF_ENCODE == 0) ? 3 : 4;
6360 if (FF_LFN_UNICODE == 3) len -= 1;
6361 while (nc < len) {
6362#if FF_STRF_ENCODE == 0 /* Read a character in ANSI/OEM */
6363 f_read(fp, s, 1, &rc); /* Get a code unit */
6364 if (rc != 1) break; /* EOF? */
6365 wc = s[0];
6366 if (dbc_1st((BYTE)wc)) { /* DBC 1st byte? */
6367 f_read(fp, s, 1, &rc); /* Get 2nd byte */
6368 if (rc != 1 || !dbc_2nd(s[0])) continue; /* Wrong code? */
6369 wc = wc << 8 | s[0];
6370 }
6371 dc = ff_oem2uni(wc, CODEPAGE); /* Convert ANSI/OEM into Unicode */
6372 if (dc == 0) continue; /* Conversion error? */
6373#elif FF_STRF_ENCODE == 1 || FF_STRF_ENCODE == 2 /* Read a character in UTF-16LE/BE */
6374 f_read(fp, s, 2, &rc); /* Get a code unit */
6375 if (rc != 2) break; /* EOF? */
6376 dc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1];
6377 if (IsSurrogateL(dc)) continue; /* Broken surrogate pair? */
6378 if (IsSurrogateH(dc)) { /* High surrogate? */
6379 f_read(fp, s, 2, &rc); /* Get low surrogate */
6380 if (rc != 2) break; /* EOF? */
6381 wc = (FF_STRF_ENCODE == 1) ? ld_word(s) : s[0] << 8 | s[1];
6382 if (!IsSurrogateL(wc)) continue; /* Broken surrogate pair? */
6383 dc = ((dc & 0x3FF) + 0x40) << 10 | (wc & 0x3FF); /* Merge surrogate pair */
6384 }
6385#else /* Read a character in UTF-8 */
6386 f_read(fp, s, 1, &rc); /* Get a code unit */
6387 if (rc != 1) break; /* EOF? */
6388 dc = s[0];
6389 if (dc >= 0x80) { /* Multi-byte sequence? */
6390 ct = 0;
6391 if ((dc & 0xE0) == 0xC0) { dc &= 0x1F; ct = 1; } /* 2-byte sequence? */
6392 if ((dc & 0xF0) == 0xE0) { dc &= 0x0F; ct = 2; } /* 3-byte sequence? */
6393 if ((dc & 0xF8) == 0xF0) { dc &= 0x07; ct = 3; } /* 4-byte sequence? */
6394 if (ct == 0) continue;
6395 f_read(fp, s, ct, &rc); /* Get trailing bytes */
6396 if (rc != ct) break;
6397 rc = 0;
6398 do { /* Merge the byte sequence */
6399 if ((s[rc] & 0xC0) != 0x80) break;
6400 dc = dc << 6 | (s[rc] & 0x3F);
6401 } while (++rc < ct);
6402 if (rc != ct || dc < 0x80 || IsSurrogate(dc) || dc >= 0x110000) continue; /* Wrong encoding? */
6403 }
6404#endif
6405 /* A code point is avaialble in dc to be output */
6406
6407 if (FF_USE_STRFUNC == 2 && dc == '\r') continue; /* Strip \r off if needed */
6408#if FF_LFN_UNICODE == 1 || FF_LFN_UNICODE == 3 /* Output it in UTF-16/32 encoding */
6409 if (FF_LFN_UNICODE == 1 && dc >= 0x10000) { /* Out of BMP at UTF-16? */
6410 *p++ = (TCHAR)(0xD800 | ((dc >> 10) - 0x40)); nc++; /* Make and output high surrogate */
6411 dc = 0xDC00 | (dc & 0x3FF); /* Make low surrogate */
6412 }
6413 *p++ = (TCHAR)dc; nc++;
6414 if (dc == '\n') break; /* End of line? */
6415#elif FF_LFN_UNICODE == 2 /* Output it in UTF-8 encoding */
6416 if (dc < 0x80) { /* Single byte? */
6417 *p++ = (TCHAR)dc;
6418 nc++;
6419 if (dc == '\n') break; /* End of line? */
6420 } else {
6421 if (dc < 0x800) { /* 2-byte sequence? */
6422 *p++ = (TCHAR)(0xC0 | (dc >> 6 & 0x1F));
6423 *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
6424 nc += 2;
6425 } else {
6426 if (dc < 0x10000) { /* 3-byte sequence? */
6427 *p++ = (TCHAR)(0xE0 | (dc >> 12 & 0x0F));
6428 *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F));
6429 *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
6430 nc += 3;
6431 } else { /* 4-byte sequence? */
6432 *p++ = (TCHAR)(0xF0 | (dc >> 18 & 0x07));
6433 *p++ = (TCHAR)(0x80 | (dc >> 12 & 0x3F));
6434 *p++ = (TCHAR)(0x80 | (dc >> 6 & 0x3F));
6435 *p++ = (TCHAR)(0x80 | (dc >> 0 & 0x3F));
6436 nc += 4;
6437 }
6438 }
6439 }
6440#endif
6441 }
6442
6443#else /* Byte-by-byte read without any conversion (ANSI/OEM API) */
6444 len -= 1; /* Make a room for the terminator */
6445 while (nc < len) {
6446 f_read(fp, s, 1, &rc); /* Get a byte */
6447 if (rc != 1) break; /* EOF? */
6448 dc = s[0];
6449 if (FF_USE_STRFUNC == 2 && dc == '\r') continue;
6450 *p++ = (TCHAR)dc; nc++;
6451 if (dc == '\n') break;
6452 }
6453#endif
6454
6455 *p = 0; /* Terminate the string */
6456 return nc ? buff : 0; /* When no data read due to EOF or error, return with error. */
6457}
#define IsSurrogate(c)
Definition ff.c:53
#define IsSurrogateL(c)
Definition ff.c:55
FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br)
Definition ff.c:3850
#define IsSurrogateH(c)
Definition ff.c:54
WCHAR ff_oem2uni(WCHAR oem, WORD cp)
#define FF_STRF_ENCODE
Definition ffconf.h:65
#define FF_LFN_UNICODE
Definition ffconf.h:139
#define FF_USE_STRFUNC
Definition ffconf.h:62

◆ f_lseek()

FRESULT f_lseek ( FIL fp,
FSIZE_t  ofs 
)

Definition at line 4367 of file ff.c.

4371{
4372 FRESULT res;
4373 FATFS *fs;
4374 DWORD clst, bcs;
4375 LBA_t nsect;
4376 FSIZE_t ifptr;
4377#if FF_USE_FASTSEEK
4378 DWORD cl, pcl, ncl, tcl, tlen, ulen;
4379 DWORD *tbl;
4380 LBA_t dsc;
4381#endif
4382
4383 res = validate(&fp->obj, &fs); /* Check validity of the file object */
4384 if (res == FR_OK) res = (FRESULT)fp->err;
4385#if FF_FS_EXFAT && !FF_FS_READONLY
4386 if (res == FR_OK && fs->fs_type == FS_EXFAT) {
4387 res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed */
4388 }
4389#endif
4390 if (res != FR_OK) LEAVE_FF(fs, res);
4391
4392#if FF_USE_FASTSEEK
4393 if (fp->cltbl) { /* Fast seek */
4394 if (ofs == CREATE_LINKMAP) { /* Create CLMT */
4395 tbl = fp->cltbl;
4396 tlen = *tbl++; ulen = 2; /* Given table size and required table size */
4397 cl = fp->obj.sclust; /* Origin of the chain */
4398 if (cl != 0) {
4399 do {
4400 /* Get a fragment */
4401 tcl = cl; ncl = 0; ulen += 2; /* Top, length and used items */
4402 do {
4403 pcl = cl; ncl++;
4404 cl = get_fat(&fp->obj, cl);
4405 if (cl <= 1) ABORT(fs, FR_INT_ERR);
4406 if (cl == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);
4407 } while (cl == pcl + 1);
4408 if (ulen <= tlen) { /* Store the length and top of the fragment */
4409 *tbl++ = ncl; *tbl++ = tcl;
4410 }
4411 } while (cl < fs->n_fatent); /* Repeat until end of chain */
4412 }
4413 *fp->cltbl = ulen; /* Number of items used */
4414 if (ulen <= tlen) {
4415 *tbl = 0; /* Terminate table */
4416 } else {
4417 res = FR_NOT_ENOUGH_CORE; /* Given table size is smaller than required */
4418 }
4419 } else { /* Fast seek */
4420 if (ofs > fp->obj.objsize) ofs = fp->obj.objsize; /* Clip offset at the file size */
4421 fp->fptr = ofs; /* Set file pointer */
4422 if (ofs > 0) {
4423 fp->clust = clmt_clust(fp, ofs - 1);
4424 dsc = clst2sect(fs, fp->clust);
4425 if (dsc == 0) ABORT(fs, FR_INT_ERR);
4426 dsc += (DWORD)((ofs - 1) / SS(fs)) & (fs->csize - 1);
4427 if (fp->fptr % SS(fs) && dsc != fp->sect) { /* Refill sector cache if needed */
4428#if !FF_FS_TINY
4429#if !FF_FS_READONLY
4430 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
4431 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
4432 fp->flag &= (BYTE)~FA_DIRTY;
4433 }
4434#endif
4435 if (disk_read(fs->pdrv, fp->buf, dsc, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Load current sector */
4436#endif
4437 fp->sect = dsc;
4438 }
4439 }
4440 }
4441 } else
4442#endif
4443
4444 /* Normal Seek */
4445 {
4446#if FF_FS_EXFAT
4447 if (fs->fs_type != FS_EXFAT && ofs >= 0x100000000) ofs = 0xFFFFFFFF; /* Clip at 4 GiB - 1 if at FATxx */
4448#endif
4449 if (ofs > fp->obj.objsize && (FF_FS_READONLY || !(fp->flag & FA_WRITE))) { /* In read-only mode, clip offset with the file size */
4450 ofs = fp->obj.objsize;
4451 }
4452 ifptr = fp->fptr;
4453 fp->fptr = nsect = 0;
4454 if (ofs > 0) {
4455 bcs = (DWORD)fs->csize * SS(fs); /* Cluster size (byte) */
4456 if (ifptr > 0 &&
4457 (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */
4458 fp->fptr = (ifptr - 1) & ~(FSIZE_t)(bcs - 1); /* start from the current cluster */
4459 ofs -= fp->fptr;
4460 clst = fp->clust;
4461 } else { /* When seek to back cluster, */
4462 clst = fp->obj.sclust; /* start from the first cluster */
4463#if !FF_FS_READONLY
4464 if (clst == 0) { /* If no cluster chain, create a new chain */
4465 clst = create_chain(&fp->obj, 0);
4466 if (clst == 1) ABORT(fs, FR_INT_ERR);
4467 if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);
4468 fp->obj.sclust = clst;
4469 }
4470#endif
4471 fp->clust = clst;
4472 }
4473 if (clst != 0) {
4474 while (ofs > bcs) { /* Cluster following loop */
4475 ofs -= bcs; fp->fptr += bcs;
4476#if !FF_FS_READONLY
4477 if (fp->flag & FA_WRITE) { /* Check if in write mode or not */
4478 if (FF_FS_EXFAT && fp->fptr > fp->obj.objsize) { /* No FAT chain object needs correct objsize to generate FAT value */
4479 fp->obj.objsize = fp->fptr;
4480 fp->flag |= FA_MODIFIED;
4481 }
4482 clst = create_chain(&fp->obj, clst); /* Follow chain with forceed stretch */
4483 if (clst == 0) { /* Clip file size in case of disk full */
4484 ofs = 0; break;
4485 }
4486 } else
4487#endif
4488 {
4489 clst = get_fat(&fp->obj, clst); /* Follow cluster chain if not in write mode */
4490 }
4491 if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);
4492 if (clst <= 1 || clst >= fs->n_fatent) ABORT(fs, FR_INT_ERR);
4493 fp->clust = clst;
4494 }
4495 fp->fptr += ofs;
4496 if (ofs % SS(fs)) {
4497 nsect = clst2sect(fs, clst); /* Current sector */
4498 if (nsect == 0) ABORT(fs, FR_INT_ERR);
4499 nsect += (DWORD)(ofs / SS(fs));
4500 }
4501 }
4502 }
4503 if (!FF_FS_READONLY && fp->fptr > fp->obj.objsize) { /* Set file change flag if the file size is extended */
4504 fp->obj.objsize = fp->fptr;
4505 fp->flag |= FA_MODIFIED;
4506 }
4507 if (fp->fptr % SS(fs) && nsect != fp->sect) { /* Fill sector cache if needed */
4508#if !FF_FS_TINY
4509#if !FF_FS_READONLY
4510 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
4511 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
4512 fp->flag &= (BYTE)~FA_DIRTY;
4513 }
4514#endif
4515 if (disk_read(fs->pdrv, fp->buf, nsect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache */
4516#endif
4517 fp->sect = nsect;
4518 }
4519 }
4520
4521 LEAVE_FF(fs, res);
4522}
DRESULT disk_read(BYTE pdrv, BYTE *buff, LBA_t sector, UINT count)
#define ABORT(fs, res)
Definition ff.c:234
#define FA_MODIFIED
Definition ff.c:60
#define FA_DIRTY
Definition ff.c:61
DWORD FSIZE_t
Definition ff.h:82
@ FR_NOT_ENOUGH_CORE
Definition ff.h:294
#define CREATE_LINKMAP
Definition ff.h:395
#define FA_WRITE
Definition ff.h:387
#define FF_FS_READONLY
Definition ffconf.h:14

◆ f_mkdir()

FRESULT f_mkdir ( const TCHAR path)

Definition at line 4986 of file ff.c.

4989{
4990 FRESULT res;
4991 DIR dj;
4992 FFOBJID sobj;
4993 FATFS *fs;
4994 DWORD dcl, pcl, tm;
4996
4997
4998 res = mount_volume(&path, &fs, FA_WRITE); /* Get logical drive */
4999 if (res == FR_OK) {
5000 dj.obj.fs = fs;
5001 INIT_NAMBUF(fs);
5002 res = follow_path(&dj, path); /* Follow the file path */
5003 if (res == FR_OK) res = FR_EXIST; /* Name collision? */
5004 if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) { /* Invalid name? */
5005 res = FR_INVALID_NAME;
5006 }
5007 if (res == FR_NO_FILE) { /* It is clear to create a new directory */
5008 sobj.fs = fs; /* New object id to create a new chain */
5009 dcl = create_chain(&sobj, 0); /* Allocate a cluster for the new directory */
5010 res = FR_OK;
5011 if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster? */
5012 if (dcl == 1) res = FR_INT_ERR; /* Any insanity? */
5013 if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR; /* Disk error? */
5014 tm = GET_FATTIME();
5015 if (res == FR_OK) {
5016 res = dir_clear(fs, dcl); /* Clean up the new table */
5017 if (res == FR_OK) {
5018 if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* Create dot entries (FAT only) */
5019 memset(fs->win + DIR_Name, ' ', 11); /* Create "." entry */
5020 fs->win[DIR_Name] = '.';
5021 fs->win[DIR_Attr] = AM_DIR;
5022 st_dword(fs->win + DIR_ModTime, tm);
5023 st_clust(fs, fs->win, dcl);
5024 memcpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */
5025 fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust;
5026 st_clust(fs, fs->win + SZDIRE, pcl);
5027 fs->wflag = 1;
5028 }
5029 res = dir_register(&dj); /* Register the object to the parent directoy */
5030 }
5031 }
5032 if (res == FR_OK) {
5033#if FF_FS_EXFAT
5034 if (fs->fs_type == FS_EXFAT) { /* Initialize directory entry block */
5035 st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Created time */
5036 st_dword(fs->dirbuf + XDIR_FstClus, dcl); /* Table start cluster */
5037 st_dword(fs->dirbuf + XDIR_FileSize, (DWORD)fs->csize * SS(fs)); /* Directory size needs to be valid */
5038 st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)fs->csize * SS(fs));
5039 fs->dirbuf[XDIR_GenFlags] = 3; /* Initialize the object flag */
5040 fs->dirbuf[XDIR_Attr] = AM_DIR; /* Attribute */
5041 res = store_xdir(&dj);
5042 } else
5043#endif
5044 {
5045 st_dword(dj.dir + DIR_ModTime, tm); /* Created time */
5046 st_clust(fs, dj.dir, dcl); /* Table start cluster */
5047 dj.dir[DIR_Attr] = AM_DIR; /* Attribute */
5048 fs->wflag = 1;
5049 }
5050 if (res == FR_OK) {
5051 res = sync_fs(fs);
5052 }
5053 } else {
5054 remove_chain(&sobj, dcl, 0); /* Could not register, remove the allocated cluster */
5055 }
5056 }
5057 FREE_NAMBUF();
5058 }
5059
5060 LEAVE_FF(fs, res);
5061}
static void st_clust(FATFS *fs, BYTE *dir, DWORD cl)
Definition ff.c:1834
#define GET_FATTIME()
Definition ff.c:274
#define DIR_ModTime
Definition ff.c:158
static FRESULT dir_register(DIR *dp)
Definition ff.c:2434
static FRESULT sync_fs(FATFS *fs)
Definition ff.c:1078
#define XDIR_ModTime
Definition ff.c:174
static void st_dword(BYTE *ptr, DWORD val)
Definition ff.c:658
static FRESULT remove_chain(FFOBJID *obj, DWORD clst, DWORD pclst)
Definition ff.c:1399
@ FR_EXIST
Definition ff.h:285
#define FF_FS_RPATH
Definition ffconf.h:159

◆ f_mount()

FRESULT f_mount ( FATFS fs,
const TCHAR path,
BYTE  opt 
)

Definition at line 3605 of file ff.c.

3610{
3611 FATFS *cfs;
3612 int vol;
3613 FRESULT res;
3614 const TCHAR *rp = path;
3615
3616
3617 /* Get logical drive number */
3618 vol = get_ldnumber(&rp);
3619 if (vol < 0) return FR_INVALID_DRIVE;
3620 cfs = FatFs[vol]; /* Pointer to fs object */
3621
3622 if (cfs) {
3623#if FF_FS_LOCK != 0
3624 clear_lock(cfs);
3625#endif
3626#if FF_FS_REENTRANT /* Discard sync object of the current volume */
3627 if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;
3628#endif
3629 cfs->fs_type = 0; /* Clear old fs object */
3630 }
3631
3632 if (fs) {
3633 fs->fs_type = 0; /* Clear new fs object */
3634#if FF_FS_REENTRANT /* Create sync object for the new volume */
3635 if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
3636#endif
3637 }
3638 FatFs[vol] = fs; /* Register new fs object */
3639
3640 if (opt == 0) return FR_OK; /* Do not mount now, it will be mounted later */
3641
3642 res = mount_volume(&path, &fs, 0); /* Force mounted the volume */
3643 LEAVE_FF(fs, res);
3644}
static void clear_lock(FATFS *fs)
Definition ff.c:1006

◆ f_open()

FRESULT f_open ( FIL fp,
const TCHAR path,
BYTE  mode 
)

Definition at line 3653 of file ff.c.

3658{
3659 FRESULT res;
3660 DIR dj;
3661 FATFS *fs;
3662#if !FF_FS_READONLY
3663 DWORD cl, bcs, clst, tm;
3664 LBA_t sc;
3665 FSIZE_t ofs;
3666#endif
3668
3669
3670 if (!fp) return FR_INVALID_OBJECT;
3671
3672 /* Get logical drive number */
3674 res = mount_volume(&path, &fs, mode);
3675 if (res == FR_OK) {
3676 dj.obj.fs = fs;
3677 INIT_NAMBUF(fs);
3678 res = follow_path(&dj, path); /* Follow the file path */
3679#if !FF_FS_READONLY /* Read/Write configuration */
3680 if (res == FR_OK) {
3681 if (dj.fn[NSFLAG] & NS_NONAME) { /* Origin directory itself? */
3682 res = FR_INVALID_NAME;
3683 }
3684#if FF_FS_LOCK != 0
3685 else {
3686 res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Check if the file can be used */
3687 }
3688#endif
3689 }
3690 /* Create or Open a file */
3692 if (res != FR_OK) { /* No file, create new */
3693 if (res == FR_NO_FILE) { /* There is no file to open, create a new entry */
3694#if FF_FS_LOCK != 0
3696#else
3697 res = dir_register(&dj);
3698#endif
3699 }
3700 mode |= FA_CREATE_ALWAYS; /* File is created */
3701 }
3702 else { /* Any object with the same name is already existing */
3703 if (dj.obj.attr & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or DIR) */
3704 res = FR_DENIED;
3705 } else {
3706 if (mode & FA_CREATE_NEW) res = FR_EXIST; /* Cannot create as new file */
3707 }
3708 }
3709 if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate the file if overwrite mode */
3710#if FF_FS_EXFAT
3711 if (fs->fs_type == FS_EXFAT) {
3712 /* Get current allocation info */
3713 fp->obj.fs = fs;
3714 init_alloc_info(fs, &fp->obj);
3715 /* Set directory entry block initial state */
3716 memset(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */
3717 memset(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */
3718 fs->dirbuf[XDIR_Attr] = AM_ARC;
3719 st_dword(fs->dirbuf + XDIR_CrtTime, GET_FATTIME());
3720 fs->dirbuf[XDIR_GenFlags] = 1;
3721 res = store_xdir(&dj);
3722 if (res == FR_OK && fp->obj.sclust != 0) { /* Remove the cluster chain if exist */
3723 res = remove_chain(&fp->obj, fp->obj.sclust, 0);
3724 fs->last_clst = fp->obj.sclust - 1; /* Reuse the cluster hole */
3725 }
3726 } else
3727#endif
3728 {
3729 /* Set directory entry initial state */
3730 tm = GET_FATTIME(); /* Set created time */
3731 st_dword(dj.dir + DIR_CrtTime, tm);
3732 st_dword(dj.dir + DIR_ModTime, tm);
3733 cl = ld_clust(fs, dj.dir); /* Get current cluster chain */
3734 dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */
3735 st_clust(fs, dj.dir, 0); /* Reset file allocation info */
3736 st_dword(dj.dir + DIR_FileSize, 0);
3737 fs->wflag = 1;
3738 if (cl != 0) { /* Remove the cluster chain if exist */
3739 sc = fs->winsect;
3740 res = remove_chain(&dj.obj, cl, 0);
3741 if (res == FR_OK) {
3742 res = move_window(fs, sc);
3743 fs->last_clst = cl - 1; /* Reuse the cluster hole */
3744 }
3745 }
3746 }
3747 }
3748 }
3749 else { /* Open an existing file */
3750 if (res == FR_OK) { /* Is the object exsiting? */
3751 if (dj.obj.attr & AM_DIR) { /* File open against a directory */
3752 res = FR_NO_FILE;
3753 } else {
3754 if ((mode & FA_WRITE) && (dj.obj.attr & AM_RDO)) { /* Write mode open against R/O file */
3755 res = FR_DENIED;
3756 }
3757 }
3758 }
3759 }
3760 if (res == FR_OK) {
3761 if (mode & FA_CREATE_ALWAYS) mode |= FA_MODIFIED; /* Set file change flag if created or overwritten */
3762 fp->dir_sect = fs->winsect; /* Pointer to the directory entry */
3763 fp->dir_ptr = dj.dir;
3764#if FF_FS_LOCK != 0
3765 fp->obj.lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0); /* Lock the file for this session */
3766 if (fp->obj.lockid == 0) res = FR_INT_ERR;
3767#endif
3768 }
3769#else /* R/O configuration */
3770 if (res == FR_OK) {
3771 if (dj.fn[NSFLAG] & NS_NONAME) { /* Is it origin directory itself? */
3772 res = FR_INVALID_NAME;
3773 } else {
3774 if (dj.obj.attr & AM_DIR) { /* Is it a directory? */
3775 res = FR_NO_FILE;
3776 }
3777 }
3778 }
3779#endif
3780
3781 if (res == FR_OK) {
3782#if FF_FS_EXFAT
3783 if (fs->fs_type == FS_EXFAT) {
3784 fp->obj.c_scl = dj.obj.sclust; /* Get containing directory info */
3785 fp->obj.c_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat;
3786 fp->obj.c_ofs = dj.blk_ofs;
3787 init_alloc_info(fs, &fp->obj);
3788 } else
3789#endif
3790 {
3791 fp->obj.sclust = ld_clust(fs, dj.dir); /* Get object allocation info */
3792 fp->obj.objsize = ld_dword(dj.dir + DIR_FileSize);
3793 }
3794#if FF_USE_FASTSEEK
3795 fp->cltbl = 0; /* Disable fast seek mode */
3796#endif
3797 fp->obj.fs = fs; /* Validate the file object */
3798 fp->obj.id = fs->id;
3799 fp->flag = mode; /* Set file access mode */
3800 fp->err = 0; /* Clear error flag */
3801 fp->sect = 0; /* Invalidate current data sector */
3802 fp->fptr = 0; /* Set file pointer top of the file */
3803#if !FF_FS_READONLY
3804#if !FF_FS_TINY
3805 memset(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */
3806#endif
3807 if ((mode & FA_SEEKEND) && fp->obj.objsize > 0) { /* Seek to end of file if FA_OPEN_APPEND is specified */
3808 fp->fptr = fp->obj.objsize; /* Offset to seek */
3809 bcs = (DWORD)fs->csize * SS(fs); /* Cluster size in byte */
3810 clst = fp->obj.sclust; /* Follow the cluster chain */
3811 for (ofs = fp->obj.objsize; res == FR_OK && ofs > bcs; ofs -= bcs) {
3812 clst = get_fat(&fp->obj, clst);
3813 if (clst <= 1) res = FR_INT_ERR;
3814 if (clst == 0xFFFFFFFF) res = FR_DISK_ERR;
3815 }
3816 fp->clust = clst;
3817 if (res == FR_OK && ofs % SS(fs)) { /* Fill sector buffer if not on the sector boundary */
3818 sc = clst2sect(fs, clst);
3819 if (sc == 0) {
3820 res = FR_INT_ERR;
3821 } else {
3822 fp->sect = sc + (DWORD)(ofs / SS(fs));
3823#if !FF_FS_TINY
3824 if (disk_read(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) res = FR_DISK_ERR;
3825#endif
3826 }
3827 }
3828#if FF_FS_LOCK != 0
3829 if (res != FR_OK) dec_lock(fp->obj.lockid); /* Decrement file open counter if seek failed */
3830#endif
3831 }
3832#endif
3833 }
3834
3835 FREE_NAMBUF();
3836 }
3837
3838 if (res != FR_OK) fp->obj.fs = 0; /* Invalidate file object on error */
3839
3840 LEAVE_FF(fs, res);
3841}
static UINT inc_lock(DIR *dp, int acc)
Definition ff.c:953
#define DIR_CrtTime
Definition ff.c:155
#define XDIR_CrtTime
Definition ff.c:173
static int enq_lock(void)
Definition ff.c:944
#define DIR_FileSize
Definition ff.c:160
#define FA_SEEKEND
Definition ff.c:59
static FRESULT chk_lock(DIR *dp, int acc)
Definition ff.c:917
#define FA_OPEN_ALWAYS
Definition ff.h:391
#define FA_READ
Definition ff.h:386
#define FA_CREATE_NEW
Definition ff.h:389
@ FR_INVALID_OBJECT
Definition ff.h:286
#define FA_OPEN_APPEND
Definition ff.h:392
#define AM_RDO
Definition ff.h:411
#define FA_CREATE_ALWAYS
Definition ff.h:390
WORD id
Definition ff.h:138

◆ f_opendir()

FRESULT f_opendir ( DIR dp,
const TCHAR path 
)

Definition at line 4531 of file ff.c.

4535{
4536 FRESULT res;
4537 FATFS *fs;
4539
4540
4541 if (!dp) return FR_INVALID_OBJECT;
4542
4543 /* Get logical drive */
4544 res = mount_volume(&path, &fs, 0);
4545 if (res == FR_OK) {
4546 dp->obj.fs = fs;
4547 INIT_NAMBUF(fs);
4548 res = follow_path(dp, path); /* Follow the path to the directory */
4549 if (res == FR_OK) { /* Follow completed */
4550 if (!(dp->fn[NSFLAG] & NS_NONAME)) { /* It is not the origin directory itself */
4551 if (dp->obj.attr & AM_DIR) { /* This object is a sub-directory */
4552#if FF_FS_EXFAT
4553 if (fs->fs_type == FS_EXFAT) {
4554 dp->obj.c_scl = dp->obj.sclust; /* Get containing directory inforamation */
4555 dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat;
4556 dp->obj.c_ofs = dp->blk_ofs;
4557 init_alloc_info(fs, &dp->obj); /* Get object allocation info */
4558 } else
4559#endif
4560 {
4561 dp->obj.sclust = ld_clust(fs, dp->dir); /* Get object allocation info */
4562 }
4563 } else { /* This object is a file */
4564 res = FR_NO_PATH;
4565 }
4566 }
4567 if (res == FR_OK) {
4568 dp->obj.id = fs->id;
4569 res = dir_sdi(dp, 0); /* Rewind directory */
4570#if FF_FS_LOCK != 0
4571 if (res == FR_OK) {
4572 if (dp->obj.sclust != 0) {
4573 dp->obj.lockid = inc_lock(dp, 0); /* Lock the sub directory */
4574 if (!dp->obj.lockid) res = FR_TOO_MANY_OPEN_FILES;
4575 } else {
4576 dp->obj.lockid = 0; /* Root directory need not to be locked */
4577 }
4578 }
4579#endif
4580 }
4581 }
4582 FREE_NAMBUF();
4583 if (res == FR_NO_FILE) res = FR_NO_PATH;
4584 }
4585 if (res != FR_OK) dp->obj.fs = 0; /* Invalidate the directory object if function faild */
4586
4587 LEAVE_FF(fs, res);
4588}
WORD id
Definition ff.h:184

◆ f_printf()

int f_printf ( FIL fp,
const TCHAR fmt,
  ... 
)

Definition at line 6801 of file ff.c.

6806{
6807 va_list arp;
6808 putbuff pb;
6809 UINT i, j, w, f, r;
6810 int prec;
6811#if FF_PRINT_LLI && FF_INTDEF == 2
6812 QWORD v;
6813#else
6814 DWORD v;
6815#endif
6816 TCHAR tc, pad, *tp;
6817 TCHAR nul = 0;
6818 char d, str[SZ_NUM_BUF];
6819
6820
6821 putc_init(&pb, fp);
6822
6823 va_start(arp, fmt);
6824
6825 for (;;) {
6826 tc = *fmt++;
6827 if (tc == 0) break; /* End of format string */
6828 if (tc != '%') { /* Not an escape character (pass-through) */
6829 putc_bfd(&pb, tc);
6830 continue;
6831 }
6832 f = w = 0; pad = ' '; prec = -1; /* Initialize parms */
6833 tc = *fmt++;
6834 if (tc == '0') { /* Flag: '0' padded */
6835 pad = '0'; tc = *fmt++;
6836 } else if (tc == '-') { /* Flag: Left aligned */
6837 f = 2; tc = *fmt++;
6838 }
6839 if (tc == '*') { /* Minimum width from an argument */
6840 w = va_arg(arp, int);
6841 tc = *fmt++;
6842 } else {
6843 while (IsDigit(tc)) { /* Minimum width */
6844 w = w * 10 + tc - '0';
6845 tc = *fmt++;
6846 }
6847 }
6848 if (tc == '.') { /* Precision */
6849 tc = *fmt++;
6850 if (tc == '*') { /* Precision from an argument */
6851 prec = va_arg(arp, int);
6852 tc = *fmt++;
6853 } else {
6854 prec = 0;
6855 while (IsDigit(tc)) { /* Precision */
6856 prec = prec * 10 + tc - '0';
6857 tc = *fmt++;
6858 }
6859 }
6860 }
6861 if (tc == 'l') { /* Size: long int */
6862 f |= 4; tc = *fmt++;
6863#if FF_PRINT_LLI && FF_INTDEF == 2
6864 if (tc == 'l') { /* Size: long long int */
6865 f |= 8; tc = *fmt++;
6866 }
6867#endif
6868 }
6869 if (tc == 0) break; /* End of format string */
6870 switch (tc) { /* Atgument type is... */
6871 case 'b': /* Unsigned binary */
6872 r = 2; break;
6873 case 'o': /* Unsigned octal */
6874 r = 8; break;
6875 case 'd': /* Signed decimal */
6876 case 'u': /* Unsigned decimal */
6877 r = 10; break;
6878 case 'x': /* Unsigned hexdecimal (lower case) */
6879 case 'X': /* Unsigned hexdecimal (upper case) */
6880 r = 16; break;
6881 case 'c': /* Character */
6882 putc_bfd(&pb, (TCHAR)va_arg(arp, int));
6883 continue;
6884 case 's': /* String */
6885 tp = va_arg(arp, TCHAR*); /* Get a pointer argument */
6886 if (!tp) tp = &nul; /* Null ptr generates a null string */
6887 for (j = 0; tp[j]; j++) ; /* j = tcslen(tp) */
6888 if (prec >= 0 && j > (UINT)prec) j = prec; /* Limited length of string body */
6889 for ( ; !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
6890 while (*tp && prec--) putc_bfd(&pb, *tp++); /* Body */
6891 while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
6892 continue;
6893#if FF_PRINT_FLOAT && FF_INTDEF == 2
6894 case 'f': /* Floating point (decimal) */
6895 case 'e': /* Floating point (e) */
6896 case 'E': /* Floating point (E) */
6897 ftoa(str, va_arg(arp, double), prec, tc); /* Make a flaoting point string */
6898 for (j = strlen(str); !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
6899 for (i = 0; str[i]; putc_bfd(&pb, str[i++])) ; /* Body */
6900 while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
6901 continue;
6902#endif
6903 default: /* Unknown type (pass-through) */
6904 putc_bfd(&pb, tc); continue;
6905 }
6906
6907 /* Get an integer argument and put it in numeral */
6908#if FF_PRINT_LLI && FF_INTDEF == 2
6909 if (f & 8) { /* long long argument? */
6910 v = (QWORD)va_arg(arp, LONGLONG);
6911 } else {
6912 if (f & 4) { /* long argument? */
6913 v = (tc == 'd') ? (QWORD)(LONGLONG)va_arg(arp, long) : (QWORD)va_arg(arp, unsigned long);
6914 } else { /* int/short/char argument */
6915 v = (tc == 'd') ? (QWORD)(LONGLONG)va_arg(arp, int) : (QWORD)va_arg(arp, unsigned int);
6916 }
6917 }
6918 if (tc == 'd' && (v & 0x8000000000000000)) { /* Negative value? */
6919 v = 0 - v; f |= 1;
6920 }
6921#else
6922 if (f & 4) { /* long argument? */
6923 v = (DWORD)va_arg(arp, long);
6924 } else { /* int/short/char argument */
6925 v = (tc == 'd') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int);
6926 }
6927 if (tc == 'd' && (v & 0x80000000)) { /* Negative value? */
6928 v = 0 - v; f |= 1;
6929 }
6930#endif
6931 i = 0;
6932 do { /* Make an integer number string */
6933 d = (char)(v % r); v /= r;
6934 if (d > 9) d += (tc == 'x') ? 0x27 : 0x07;
6935 str[i++] = d + '0';
6936 } while (v && i < SZ_NUM_BUF);
6937 if (f & 1) str[i++] = '-'; /* Sign */
6938 /* Write it */
6939 for (j = i; !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
6940 do putc_bfd(&pb, (TCHAR)str[--i]); while (i); /* Body */
6941 while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
6942 }
6943
6944 va_end(arp);
6945
6946 return putc_flush(&pb);
6947}
static uint32_t f
Definition Common.c:41
static void putc_bfd(putbuff *pb, TCHAR c)
Definition ff.c:6488
static int putc_flush(putbuff *pb)
Definition ff.c:6619
#define IsDigit(c)
Definition ff.c:50
#define SZ_NUM_BUF
Definition ff.c:6465
static void putc_init(putbuff *pb, FIL *fp)
Definition ff.c:6632
Definition ff.c:6473

◆ f_putc()

int f_putc ( TCHAR  c,
FIL fp 
)

Definition at line 6640 of file ff.c.

6644{
6645 putbuff pb;
6646
6647
6648 putc_init(&pb, fp);
6649 putc_bfd(&pb, c); /* Put the character */
6650 return putc_flush(&pb);
6651}

◆ f_puts()

int f_puts ( const TCHAR str,
FIL fp 
)

Definition at line 6660 of file ff.c.

6664{
6665 putbuff pb;
6666
6667
6668 putc_init(&pb, fp);
6669 while (*str) putc_bfd(&pb, *str++); /* Put the string */
6670 return putc_flush(&pb);
6671}

◆ f_read()

FRESULT f_read ( FIL fp,
void *  buff,
UINT  btr,
UINT br 
)

Definition at line 3850 of file ff.c.

3856{
3857 FRESULT res;
3858 FATFS *fs;
3859 DWORD clst;
3860 LBA_t sect;
3861 FSIZE_t remain;
3862 UINT rcnt, cc, csect;
3863 BYTE *rbuff = (BYTE*)buff;
3864
3865
3866 *br = 0; /* Clear read byte counter */
3867 res = validate(&fp->obj, &fs); /* Check validity of the file object */
3868 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); /* Check validity */
3869 if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
3870 remain = fp->obj.objsize - fp->fptr;
3871 if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */
3872
3873 for ( ; btr > 0; btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) { /* Repeat until btr bytes read */
3874 if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
3875 csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */
3876 if (csect == 0) { /* On the cluster boundary? */
3877 if (fp->fptr == 0) { /* On the top of the file? */
3878 clst = fp->obj.sclust; /* Follow cluster chain from the origin */
3879 } else { /* Middle or end of the file */
3880#if FF_USE_FASTSEEK
3881 if (fp->cltbl) {
3882 clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
3883 } else
3884#endif
3885 {
3886 clst = get_fat(&fp->obj, fp->clust); /* Follow cluster chain on the FAT */
3887 }
3888 }
3889 if (clst < 2) ABORT(fs, FR_INT_ERR);
3890 if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);
3891 fp->clust = clst; /* Update current cluster */
3892 }
3893 sect = clst2sect(fs, fp->clust); /* Get current sector */
3894 if (sect == 0) ABORT(fs, FR_INT_ERR);
3895 sect += csect;
3896 cc = btr / SS(fs); /* When remaining bytes >= sector size, */
3897 if (cc > 0) { /* Read maximum contiguous sectors directly */
3898 if (csect + cc > fs->csize) { /* Clip at cluster boundary */
3899 cc = fs->csize - csect;
3900 }
3901 if (disk_read(fs->pdrv, rbuff, sect, cc) != RES_OK) ABORT(fs, FR_DISK_ERR);
3902#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */
3903#if FF_FS_TINY
3904 if (fs->wflag && fs->winsect - sect < cc) {
3905 memcpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs));
3906 }
3907#else
3908 if ((fp->flag & FA_DIRTY) && fp->sect - sect < cc) {
3909 memcpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));
3910 }
3911#endif
3912#endif
3913 rcnt = SS(fs) * cc; /* Number of bytes transferred */
3914 continue;
3915 }
3916#if !FF_FS_TINY
3917 if (fp->sect != sect) { /* Load data sector if not in cache */
3918#if !FF_FS_READONLY
3919 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
3920 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
3921 fp->flag &= (BYTE)~FA_DIRTY;
3922 }
3923#endif
3924 if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache */
3925 }
3926#endif
3927 fp->sect = sect;
3928 }
3929 rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
3930 if (rcnt > btr) rcnt = btr; /* Clip it by btr if needed */
3931#if FF_FS_TINY
3932 if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
3933 memcpy(rbuff, fs->win + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
3934#else
3935 memcpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
3936#endif
3937 }
3938
3939 LEAVE_FF(fs, FR_OK);
3940}

◆ f_readdir()

FRESULT f_readdir ( DIR dp,
FILINFO fno 
)

Definition at line 4627 of file ff.c.

4631{
4632 FRESULT res;
4633 FATFS *fs;
4635
4636
4637 res = validate(&dp->obj, &fs); /* Check validity of the directory object */
4638 if (res == FR_OK) {
4639 if (!fno) {
4640 res = dir_sdi(dp, 0); /* Rewind the directory object */
4641 } else {
4642 INIT_NAMBUF(fs);
4643 res = DIR_READ_FILE(dp); /* Read an item */
4644 if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory */
4645 if (res == FR_OK) { /* A valid entry is found */
4646 get_fileinfo(dp, fno); /* Get the object information */
4647 res = dir_next(dp, 0); /* Increment index for next */
4648 if (res == FR_NO_FILE) res = FR_OK; /* Ignore end of directory now */
4649 }
4650 FREE_NAMBUF();
4651 }
4652 }
4653 LEAVE_FF(fs, res);
4654}
static void get_fileinfo(DIR *dp, FILINFO *fno)
Definition ff.c:2586

◆ f_rename()

FRESULT f_rename ( const TCHAR path_old,
const TCHAR path_new 
)

Definition at line 5070 of file ff.c.

5074{
5075 FRESULT res;
5076 DIR djo, djn;
5077 FATFS *fs;
5078 BYTE buf[FF_FS_EXFAT ? SZDIRE * 2 : SZDIRE], *dir;
5079 LBA_t sect;
5081
5082
5083 get_ldnumber(&path_new); /* Snip the drive number of new name off */
5084 res = mount_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */
5085 if (res == FR_OK) {
5086 djo.obj.fs = fs;
5087 INIT_NAMBUF(fs);
5088 res = follow_path(&djo, path_old); /* Check old object */
5089 if (res == FR_OK && (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check validity of name */
5090#if FF_FS_LOCK != 0
5091 if (res == FR_OK) {
5092 res = chk_lock(&djo, 2);
5093 }
5094#endif
5095 if (res == FR_OK) { /* Object to be renamed is found */
5096#if FF_FS_EXFAT
5097 if (fs->fs_type == FS_EXFAT) { /* At exFAT volume */
5098 BYTE nf, nn;
5099 WORD nh;
5100
5101 memcpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */
5102 memcpy(&djn, &djo, sizeof djo);
5103 res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
5104 if (res == FR_OK) { /* Is new name already in use by any other object? */
5105 res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
5106 }
5107 if (res == FR_NO_FILE) { /* It is a valid path and no name collision */
5108 res = dir_register(&djn); /* Register the new entry */
5109 if (res == FR_OK) {
5110 nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName];
5111 nh = ld_word(fs->dirbuf + XDIR_NameHash);
5112 memcpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */
5113 fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn;
5114 st_word(fs->dirbuf + XDIR_NameHash, nh);
5115 if (!(fs->dirbuf[XDIR_Attr] & AM_DIR)) fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */
5116/* Start of critical section where an interruption can cause a cross-link */
5117 res = store_xdir(&djn);
5118 }
5119 }
5120 } else
5121#endif
5122 { /* At FAT/FAT32 volume */
5123 memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */
5124 memcpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
5125 res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
5126 if (res == FR_OK) { /* Is new name already in use by any other object? */
5127 res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
5128 }
5129 if (res == FR_NO_FILE) { /* It is a valid path and no name collision */
5130 res = dir_register(&djn); /* Register the new entry */
5131 if (res == FR_OK) {
5132 dir = djn.dir; /* Copy directory entry of the object except name */
5133 memcpy(dir + 13, buf + 13, SZDIRE - 13);
5134 dir[DIR_Attr] = buf[DIR_Attr];
5135 if (!(dir[DIR_Attr] & AM_DIR)) dir[DIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */
5136 fs->wflag = 1;
5137 if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) { /* Update .. entry in the sub-directory if needed */
5138 sect = clst2sect(fs, ld_clust(fs, dir));
5139 if (sect == 0) {
5140 res = FR_INT_ERR;
5141 } else {
5142/* Start of critical section where an interruption can cause a cross-link */
5143 res = move_window(fs, sect);
5144 dir = fs->win + SZDIRE * 1; /* Ptr to .. entry */
5145 if (res == FR_OK && dir[1] == '.') {
5146 st_clust(fs, dir, djn.obj.sclust);
5147 fs->wflag = 1;
5148 }
5149 }
5150 }
5151 }
5152 }
5153 }
5154 if (res == FR_OK) {
5155 res = dir_remove(&djo); /* Remove old entry */
5156 if (res == FR_OK) {
5157 res = sync_fs(fs);
5158 }
5159 }
5160/* End of the critical section */
5161 }
5162 FREE_NAMBUF();
5163 }
5164
5165 LEAVE_FF(fs, res);
5166}
static void st_word(BYTE *ptr, WORD val)
Definition ff.c:652
#define XDIR_NumSec
Definition ff.c:170
static FRESULT dir_remove(DIR *dp)
Definition ff.c:2540

◆ f_stat()

FRESULT f_stat ( const TCHAR path,
FILINFO fno 
)

Definition at line 4715 of file ff.c.

4719{
4720 FRESULT res;
4721 DIR dj;
4723
4724
4725 /* Get logical drive */
4726 res = mount_volume(&path, &dj.obj.fs, 0);
4727 if (res == FR_OK) {
4728 INIT_NAMBUF(dj.obj.fs);
4729 res = follow_path(&dj, path); /* Follow the file path */
4730 if (res == FR_OK) { /* Follow completed */
4731 if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */
4732 res = FR_INVALID_NAME;
4733 } else { /* Found an object */
4734 if (fno) get_fileinfo(&dj, fno);
4735 }
4736 }
4737 FREE_NAMBUF();
4738 }
4739
4740 LEAVE_FF(dj.obj.fs, res);
4741}

◆ f_sync()

FRESULT f_sync ( FIL fp)

Definition at line 4071 of file ff.c.

4074{
4075 FRESULT res;
4076 FATFS *fs;
4077 DWORD tm;
4078 BYTE *dir;
4079
4080
4081 res = validate(&fp->obj, &fs); /* Check validity of the file object */
4082 if (res == FR_OK) {
4083 if (fp->flag & FA_MODIFIED) { /* Is there any change to the file? */
4084#if !FF_FS_TINY
4085 if (fp->flag & FA_DIRTY) { /* Write-back cached data if needed */
4086 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) LEAVE_FF(fs, FR_DISK_ERR);
4087 fp->flag &= (BYTE)~FA_DIRTY;
4088 }
4089#endif
4090 /* Update the directory entry */
4091 tm = GET_FATTIME(); /* Modified time */
4092#if FF_FS_EXFAT
4093 if (fs->fs_type == FS_EXFAT) {
4094 res = fill_first_frag(&fp->obj); /* Fill first fragment on the FAT if needed */
4095 if (res == FR_OK) {
4096 res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed */
4097 }
4098 if (res == FR_OK) {
4099 DIR dj;
4101
4102 INIT_NAMBUF(fs);
4103 res = load_obj_xdir(&dj, &fp->obj); /* Load directory entry block */
4104 if (res == FR_OK) {
4105 fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */
4106 fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1; /* Update file allocation information */
4107 st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust); /* Update start cluster */
4108 st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize); /* Update file size */
4109 st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize); /* (FatFs does not support Valid File Size feature) */
4110 st_dword(fs->dirbuf + XDIR_ModTime, tm); /* Update modified time */
4111 fs->dirbuf[XDIR_ModTime10] = 0;
4112 st_dword(fs->dirbuf + XDIR_AccTime, 0);
4113 res = store_xdir(&dj); /* Restore it to the directory */
4114 if (res == FR_OK) {
4115 res = sync_fs(fs);
4116 fp->flag &= (BYTE)~FA_MODIFIED;
4117 }
4118 }
4119 FREE_NAMBUF();
4120 }
4121 } else
4122#endif
4123 {
4124 res = move_window(fs, fp->dir_sect);
4125 if (res == FR_OK) {
4126 dir = fp->dir_ptr;
4127 dir[DIR_Attr] |= AM_ARC; /* Set archive attribute to indicate that the file has been changed */
4128 st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */
4129 st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */
4130 st_dword(dir + DIR_ModTime, tm); /* Update modified time */
4131 st_word(dir + DIR_LstAccDate, 0);
4132 fs->wflag = 1;
4133 res = sync_fs(fs); /* Restore it to the directory */
4134 fp->flag &= (BYTE)~FA_MODIFIED;
4135 }
4136 }
4137 }
4138 }
4139
4140 LEAVE_FF(fs, res);
4141}
#define XDIR_ModTime10
Definition ff.c:177
#define XDIR_AccTime
Definition ff.c:175
#define DIR_LstAccDate
Definition ff.c:156

◆ f_truncate()

FRESULT f_truncate ( FIL fp)

Definition at line 4842 of file ff.c.

4845{
4846 FRESULT res;
4847 FATFS *fs;
4848 DWORD ncl;
4849
4850
4851 res = validate(&fp->obj, &fs); /* Check validity of the file object */
4852 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);
4853 if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
4854
4855 if (fp->fptr < fp->obj.objsize) { /* Process when fptr is not on the eof */
4856 if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */
4857 res = remove_chain(&fp->obj, fp->obj.sclust, 0);
4858 fp->obj.sclust = 0;
4859 } else { /* When truncate a part of the file, remove remaining clusters */
4860 ncl = get_fat(&fp->obj, fp->clust);
4861 res = FR_OK;
4862 if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR;
4863 if (ncl == 1) res = FR_INT_ERR;
4864 if (res == FR_OK && ncl < fs->n_fatent) {
4865 res = remove_chain(&fp->obj, ncl, fp->clust);
4866 }
4867 }
4868 fp->obj.objsize = fp->fptr; /* Set file size to current read/write point */
4869 fp->flag |= FA_MODIFIED;
4870#if !FF_FS_TINY
4871 if (res == FR_OK && (fp->flag & FA_DIRTY)) {
4872 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) {
4873 res = FR_DISK_ERR;
4874 } else {
4875 fp->flag &= (BYTE)~FA_DIRTY;
4876 }
4877 }
4878#endif
4879 if (res != FR_OK) ABORT(fs, res);
4880 }
4881
4882 LEAVE_FF(fs, res);
4883}

◆ f_unlink()

FRESULT f_unlink ( const TCHAR path)

Definition at line 4892 of file ff.c.

4895{
4896 FRESULT res;
4897 DIR dj, sdj;
4898 DWORD dclst = 0;
4899 FATFS *fs;
4900#if FF_FS_EXFAT
4901 FFOBJID obj;
4902#endif
4904
4905
4906 /* Get logical drive */
4907 res = mount_volume(&path, &fs, FA_WRITE);
4908 if (res == FR_OK) {
4909 dj.obj.fs = fs;
4910 INIT_NAMBUF(fs);
4911 res = follow_path(&dj, path); /* Follow the file path */
4912 if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) {
4913 res = FR_INVALID_NAME; /* Cannot remove dot entry */
4914 }
4915#if FF_FS_LOCK != 0
4916 if (res == FR_OK) res = chk_lock(&dj, 2); /* Check if it is an open object */
4917#endif
4918 if (res == FR_OK) { /* The object is accessible */
4919 if (dj.fn[NSFLAG] & NS_NONAME) {
4920 res = FR_INVALID_NAME; /* Cannot remove the origin directory */
4921 } else {
4922 if (dj.obj.attr & AM_RDO) {
4923 res = FR_DENIED; /* Cannot remove R/O object */
4924 }
4925 }
4926 if (res == FR_OK) {
4927#if FF_FS_EXFAT
4928 obj.fs = fs;
4929 if (fs->fs_type == FS_EXFAT) {
4930 init_alloc_info(fs, &obj);
4931 dclst = obj.sclust;
4932 } else
4933#endif
4934 {
4935 dclst = ld_clust(fs, dj.dir);
4936 }
4937 if (dj.obj.attr & AM_DIR) { /* Is it a sub-directory? */
4938#if FF_FS_RPATH != 0
4939 if (dclst == fs->cdir) { /* Is it the current directory? */
4940 res = FR_DENIED;
4941 } else
4942#endif
4943 {
4944 sdj.obj.fs = fs; /* Open the sub-directory */
4945 sdj.obj.sclust = dclst;
4946#if FF_FS_EXFAT
4947 if (fs->fs_type == FS_EXFAT) {
4948 sdj.obj.objsize = obj.objsize;
4949 sdj.obj.stat = obj.stat;
4950 }
4951#endif
4952 res = dir_sdi(&sdj, 0);
4953 if (res == FR_OK) {
4954 res = DIR_READ_FILE(&sdj); /* Test if the directory is empty */
4955 if (res == FR_OK) res = FR_DENIED; /* Not empty? */
4956 if (res == FR_NO_FILE) res = FR_OK; /* Empty? */
4957 }
4958 }
4959 }
4960 }
4961 if (res == FR_OK) {
4962 res = dir_remove(&dj); /* Remove the directory entry */
4963 if (res == FR_OK && dclst != 0) { /* Remove the cluster chain if exist */
4964#if FF_FS_EXFAT
4965 res = remove_chain(&obj, dclst, 0);
4966#else
4967 res = remove_chain(&dj.obj, dclst, 0);
4968#endif
4969 }
4970 if (res == FR_OK) res = sync_fs(fs);
4971 }
4972 }
4973 FREE_NAMBUF();
4974 }
4975
4976 LEAVE_FF(fs, res);
4977}

◆ f_write()

FRESULT f_write ( FIL fp,
const void *  buff,
UINT  btw,
UINT bw 
)

Definition at line 3950 of file ff.c.

3956{
3957 FRESULT res;
3958 FATFS *fs;
3959 DWORD clst;
3960 LBA_t sect;
3961 UINT wcnt, cc, csect;
3962 const BYTE *wbuff = (const BYTE*)buff;
3963
3964
3965 *bw = 0; /* Clear write byte counter */
3966 res = validate(&fp->obj, &fs); /* Check validity of the file object */
3967 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); /* Check validity */
3968 if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
3969
3970 /* Check fptr wrap-around (file size cannot reach 4 GiB at FAT volume) */
3971 if ((!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) && (DWORD)(fp->fptr + btw) < (DWORD)fp->fptr) {
3972 btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr);
3973 }
3974
3975 for ( ; btw > 0; btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) { /* Repeat until all data written */
3976 if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
3977 csect = (UINT)(fp->fptr / SS(fs)) & (fs->csize - 1); /* Sector offset in the cluster */
3978 if (csect == 0) { /* On the cluster boundary? */
3979 if (fp->fptr == 0) { /* On the top of the file? */
3980 clst = fp->obj.sclust; /* Follow from the origin */
3981 if (clst == 0) { /* If no cluster is allocated, */
3982 clst = create_chain(&fp->obj, 0); /* create a new cluster chain */
3983 }
3984 } else { /* On the middle or end of the file */
3985#if FF_USE_FASTSEEK
3986 if (fp->cltbl) {
3987 clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
3988 } else
3989#endif
3990 {
3991 clst = create_chain(&fp->obj, fp->clust); /* Follow or stretch cluster chain on the FAT */
3992 }
3993 }
3994 if (clst == 0) break; /* Could not allocate a new cluster (disk full) */
3995 if (clst == 1) ABORT(fs, FR_INT_ERR);
3996 if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);
3997 fp->clust = clst; /* Update current cluster */
3998 if (fp->obj.sclust == 0) fp->obj.sclust = clst; /* Set start cluster if the first write */
3999 }
4000#if FF_FS_TINY
4001 if (fs->winsect == fp->sect && sync_window(fs) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Write-back sector cache */
4002#else
4003 if (fp->flag & FA_DIRTY) { /* Write-back sector cache */
4004 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
4005 fp->flag &= (BYTE)~FA_DIRTY;
4006 }
4007#endif
4008 sect = clst2sect(fs, fp->clust); /* Get current sector */
4009 if (sect == 0) ABORT(fs, FR_INT_ERR);
4010 sect += csect;
4011 cc = btw / SS(fs); /* When remaining bytes >= sector size, */
4012 if (cc > 0) { /* Write maximum contiguous sectors directly */
4013 if (csect + cc > fs->csize) { /* Clip at cluster boundary */
4014 cc = fs->csize - csect;
4015 }
4016 if (disk_write(fs->pdrv, wbuff, sect, cc) != RES_OK) ABORT(fs, FR_DISK_ERR);
4017#if FF_FS_MINIMIZE <= 2
4018#if FF_FS_TINY
4019 if (fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
4020 memcpy(fs->win, wbuff + ((fs->winsect - sect) * SS(fs)), SS(fs));
4021 fs->wflag = 0;
4022 }
4023#else
4024 if (fp->sect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
4025 memcpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
4026 fp->flag &= (BYTE)~FA_DIRTY;
4027 }
4028#endif
4029#endif
4030 wcnt = SS(fs) * cc; /* Number of bytes transferred */
4031 continue;
4032 }
4033#if FF_FS_TINY
4034 if (fp->fptr >= fp->obj.objsize) { /* Avoid silly cache filling on the growing edge */
4035 if (sync_window(fs) != FR_OK) ABORT(fs, FR_DISK_ERR);
4036 fs->winsect = sect;
4037 }
4038#else
4039 if (fp->sect != sect && /* Fill sector cache with file data */
4040 fp->fptr < fp->obj.objsize &&
4041 disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) {
4042 ABORT(fs, FR_DISK_ERR);
4043 }
4044#endif
4045 fp->sect = sect;
4046 }
4047 wcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
4048 if (wcnt > btw) wcnt = btw; /* Clip it by btw if needed */
4049#if FF_FS_TINY
4050 if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
4051 memcpy(fs->win + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
4052 fs->wflag = 1;
4053#else
4054 memcpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
4055 fp->flag |= FA_DIRTY;
4056#endif
4057 }
4058
4059 fp->flag |= FA_MODIFIED; /* Set file change flag */
4060
4061 LEAVE_FF(fs, FR_OK);
4062}

◆ find_volume()

static UINT find_volume ( FATFS fs,
UINT  part 
)
static

Definition at line 3278 of file ff.c.

3282{
3283 UINT fmt, i;
3284 DWORD mbr_pt[4];
3285
3286
3287 fmt = check_fs(fs, 0); /* Load sector 0 and check if it is an FAT VBR as SFD format */
3288 if (fmt != 2 && (fmt >= 3 || part == 0)) return fmt; /* Returns if it is an FAT VBR as auto scan, not a BS or disk error */
3289
3290 /* Sector 0 is not an FAT VBR or forced partition number wants a partition */
3291
3292#if FF_LBA64
3293 if (fs->win[MBR_Table + PTE_System] == 0xEE) { /* GPT protective MBR? */
3294 DWORD n_ent, v_ent, ofs;
3295 QWORD pt_lba;
3296
3297 if (move_window(fs, 1) != FR_OK) return 4; /* Load GPT header sector (next to MBR) */
3298 if (!test_gpt_header(fs->win)) return 3; /* Check if GPT header is valid */
3299 n_ent = ld_dword(fs->win + GPTH_PtNum); /* Number of entries */
3300 pt_lba = ld_qword(fs->win + GPTH_PtOfs); /* Table location */
3301 for (v_ent = i = 0; i < n_ent; i++) { /* Find FAT partition */
3302 if (move_window(fs, pt_lba + i * SZ_GPTE / SS(fs)) != FR_OK) return 4; /* PT sector */
3303 ofs = i * SZ_GPTE % SS(fs); /* Offset in the sector */
3304 if (!memcmp(fs->win + ofs + GPTE_PtGuid, GUID_MS_Basic, 16)) { /* MS basic data partition? */
3305 v_ent++;
3306 fmt = check_fs(fs, ld_qword(fs->win + ofs + GPTE_FstLba)); /* Load VBR and check status */
3307 if (part == 0 && fmt <= 1) return fmt; /* Auto search (valid FAT volume found first) */
3308 if (part != 0 && v_ent == part) return fmt; /* Forced partition order (regardless of it is valid or not) */
3309 }
3310 }
3311 return 3; /* Not found */
3312 }
3313#endif
3314 if (FF_MULTI_PARTITION && part > 4) return 3; /* MBR has 4 partitions max */
3315 for (i = 0; i < 4; i++) { /* Load partition offset in the MBR */
3316 mbr_pt[i] = ld_dword(fs->win + MBR_Table + i * SZ_PTE + PTE_StLba);
3317 }
3318 i = part ? part - 1 : 0; /* Table index to find first */
3319 do { /* Find an FAT volume */
3320 fmt = mbr_pt[i] ? check_fs(fs, mbr_pt[i]) : 3; /* Check if the partition is FAT */
3321 } while (part == 0 && fmt >= 2 && ++i < 4);
3322 return fmt;
3323}
#define GPTE_FstLba
Definition ff.c:227
#define PTE_System
Definition ff.c:204
static UINT check_fs(FATFS *fs, LBA_t sect)
Definition ff.c:3238
#define GPTE_PtGuid
Definition ff.c:225
#define GPTH_PtNum
Definition ff.c:221
#define SZ_GPTE
Definition ff.c:224
#define MBR_Table
Definition ff.c:198
#define GPTH_PtOfs
Definition ff.c:220
#define PTE_StLba
Definition ff.c:208
#define SZ_PTE
Definition ff.c:199
#define FF_MULTI_PARTITION
Definition ffconf.h:190

◆ follow_path()

static FRESULT follow_path ( DIR dp,
const TCHAR path 
)
static

Definition at line 3003 of file ff.c.

3007{
3008 FRESULT res;
3009 BYTE ns;
3010 FATFS *fs = dp->obj.fs;
3011
3012
3013#if FF_FS_RPATH != 0
3014 if (!IsSeparator(*path) && (FF_STR_VOLUME_ID != 2 || !IsTerminator(*path))) { /* Without heading separator */
3015 dp->obj.sclust = fs->cdir; /* Start at the current directory */
3016 } else
3017#endif
3018 { /* With heading separator */
3019 while (IsSeparator(*path)) path++; /* Strip separators */
3020 dp->obj.sclust = 0; /* Start from the root directory */
3021 }
3022#if FF_FS_EXFAT
3023 dp->obj.n_frag = 0; /* Invalidate last fragment counter of the object */
3024#if FF_FS_RPATH != 0
3025 if (fs->fs_type == FS_EXFAT && dp->obj.sclust) { /* exFAT: Retrieve the sub-directory's status */
3026 DIR dj;
3027
3028 dp->obj.c_scl = fs->cdc_scl;
3029 dp->obj.c_size = fs->cdc_size;
3030 dp->obj.c_ofs = fs->cdc_ofs;
3031 res = load_obj_xdir(&dj, &dp->obj);
3032 if (res != FR_OK) return res;
3033 dp->obj.objsize = ld_dword(fs->dirbuf + XDIR_FileSize);
3034 dp->obj.stat = fs->dirbuf[XDIR_GenFlags] & 2;
3035 }
3036#endif
3037#endif
3038
3039 if ((UINT)*path < ' ') { /* Null path name is the origin directory itself */
3040 dp->fn[NSFLAG] = NS_NONAME;
3041 res = dir_sdi(dp, 0);
3042
3043 } else { /* Follow path */
3044 for (;;) {
3045 res = create_name(dp, &path); /* Get a segment name of the path */
3046 if (res != FR_OK) break;
3047 res = dir_find(dp); /* Find an object with the segment name */
3048 ns = dp->fn[NSFLAG];
3049 if (res != FR_OK) { /* Failed to find the object */
3050 if (res == FR_NO_FILE) { /* Object is not found */
3051 if (FF_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, stay there */
3052 if (!(ns & NS_LAST)) continue; /* Continue to follow if not last segment */
3053 dp->fn[NSFLAG] = NS_NONAME;
3054 res = FR_OK;
3055 } else { /* Could not find the object */
3056 if (!(ns & NS_LAST)) res = FR_NO_PATH; /* Adjust error code if not last segment */
3057 }
3058 }
3059 break;
3060 }
3061 if (ns & NS_LAST) break; /* Last segment matched. Function completed. */
3062 /* Get into the sub-directory */
3063 if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */
3064 res = FR_NO_PATH; break;
3065 }
3066#if FF_FS_EXFAT
3067 if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */
3068 dp->obj.c_scl = dp->obj.sclust;
3069 dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat;
3070 dp->obj.c_ofs = dp->blk_ofs;
3071 init_alloc_info(fs, &dp->obj); /* Open next directory */
3072 } else
3073#endif
3074 {
3075 dp->obj.sclust = ld_clust(fs, fs->win + dp->dptr % SS(fs)); /* Open next directory */
3076 }
3077 }
3078 }
3079
3080 return res;
3081}
static FRESULT create_name(DIR *dp, const TCHAR **path)
Definition ff.c:2801
#define FF_STR_VOLUME_ID
Definition ffconf.h:176

◆ gen_numname()

static void gen_numname ( BYTE dst,
const BYTE src,
const WCHAR lfn,
UINT  seq 
)
static

Definition at line 1965 of file ff.c.

1971{
1972 BYTE ns[8], c;
1973 UINT i, j;
1974 WCHAR wc;
1975 DWORD sreg;
1976
1977
1978 memcpy(dst, src, 11); /* Prepare the SFN to be modified */
1979
1980 if (seq > 5) { /* In case of many collisions, generate a hash number instead of sequential number */
1981 sreg = seq;
1982 while (*lfn) { /* Create a CRC as hash value */
1983 wc = *lfn++;
1984 for (i = 0; i < 16; i++) {
1985 sreg = (sreg << 1) + (wc & 1);
1986 wc >>= 1;
1987 if (sreg & 0x10000) sreg ^= 0x11021;
1988 }
1989 }
1990 seq = (UINT)sreg;
1991 }
1992
1993 /* Make suffix (~ + hexdecimal) */
1994 i = 7;
1995 do {
1996 c = (BYTE)((seq % 16) + '0'); seq /= 16;
1997 if (c > '9') c += 7;
1998 ns[i--] = c;
1999 } while (i && seq);
2000 ns[i] = '~';
2001
2002 /* Append the suffix to the SFN body */
2003 for (j = 0; j < i && dst[j] != ' '; j++) { /* Find the offset to append */
2004 if (dbc_1st(dst[j])) { /* To avoid DBC break up */
2005 if (j == i - 1) break;
2006 j++;
2007 }
2008 }
2009 do { /* Append the suffix */
2010 dst[j++] = (i < 8) ? ns[i++] : ' ';
2011 } while (j < 8);
2012}

◆ get_fat()

static DWORD get_fat ( FFOBJID obj,
DWORD  clst 
)
static

Definition at line 1131 of file ff.c.

1135{
1136 UINT wc, bc;
1137 DWORD val;
1138 FATFS *fs = obj->fs;
1139
1140
1141 if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */
1142 val = 1; /* Internal error */
1143
1144 } else {
1145 val = 0xFFFFFFFF; /* Default value falls on disk error */
1146
1147 switch (fs->fs_type) {
1148 case FS_FAT12 :
1149 bc = (UINT)clst; bc += bc / 2;
1150 if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
1151 wc = fs->win[bc++ % SS(fs)]; /* Get 1st byte of the entry */
1152 if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
1153 wc |= fs->win[bc % SS(fs)] << 8; /* Merge 2nd byte of the entry */
1154 val = (clst & 1) ? (wc >> 4) : (wc & 0xFFF); /* Adjust bit position */
1155 break;
1156
1157 case FS_FAT16 :
1158 if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break;
1159 val = ld_word(fs->win + clst * 2 % SS(fs)); /* Simple WORD array */
1160 break;
1161
1162 case FS_FAT32 :
1163 if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break;
1164 val = ld_dword(fs->win + clst * 4 % SS(fs)) & 0x0FFFFFFF; /* Simple DWORD array but mask out upper 4 bits */
1165 break;
1166#if FF_FS_EXFAT
1167 case FS_EXFAT :
1168 if ((obj->objsize != 0 && obj->sclust != 0) || obj->stat == 0) { /* Object except root dir must have valid data length */
1169 DWORD cofs = clst - obj->sclust; /* Offset from start cluster */
1170 DWORD clen = (DWORD)((LBA_t)((obj->objsize - 1) / SS(fs)) / fs->csize); /* Number of clusters - 1 */
1171
1172 if (obj->stat == 2 && cofs <= clen) { /* Is it a contiguous chain? */
1173 val = (cofs == clen) ? 0x7FFFFFFF : clst + 1; /* No data on the FAT, generate the value */
1174 break;
1175 }
1176 if (obj->stat == 3 && cofs < obj->n_cont) { /* Is it in the 1st fragment? */
1177 val = clst + 1; /* Generate the value */
1178 break;
1179 }
1180 if (obj->stat != 2) { /* Get value from FAT if FAT chain is valid */
1181 if (obj->n_frag != 0) { /* Is it on the growing edge? */
1182 val = 0x7FFFFFFF; /* Generate EOC */
1183 } else {
1184 if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break;
1185 val = ld_dword(fs->win + clst * 4 % SS(fs)) & 0x7FFFFFFF;
1186 }
1187 break;
1188 }
1189 }
1190 val = 1; /* Internal error */
1191 break;
1192#endif
1193 default:
1194 val = 1; /* Internal error */
1195 }
1196 }
1197
1198 return val;
1199}

◆ get_fileinfo()

static void get_fileinfo ( DIR dp,
FILINFO fno 
)
static

Definition at line 2586 of file ff.c.

2590{
2591 UINT si, di;
2592#if FF_USE_LFN
2593 BYTE lcf;
2594 WCHAR wc, hs;
2595 FATFS *fs = dp->obj.fs;
2596 UINT nw;
2597#else
2598 TCHAR c;
2599#endif
2600
2601
2602 fno->fname[0] = 0; /* Invaidate file info */
2603 if (dp->sect == 0) return; /* Exit if read pointer has reached end of directory */
2604
2605#if FF_USE_LFN /* LFN configuration */
2606#if FF_FS_EXFAT
2607 if (fs->fs_type == FS_EXFAT) { /* exFAT volume */
2608 UINT nc = 0;
2609
2610 si = SZDIRE * 2; di = 0; /* 1st C1 entry in the entry block */
2611 hs = 0;
2612 while (nc < fs->dirbuf[XDIR_NumName]) {
2613 if (si >= MAXDIRB(FF_MAX_LFN)) { di = 0; break; } /* Truncated directory block? */
2614 if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */
2615 wc = ld_word(fs->dirbuf + si); si += 2; nc++; /* Get a character */
2616 if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
2617 hs = wc; continue; /* Get low surrogate */
2618 }
2619 nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
2620 if (nw == 0) { di = 0; break; } /* Buffer overflow or wrong char? */
2621 di += nw;
2622 hs = 0;
2623 }
2624 if (hs != 0) di = 0; /* Broken surrogate pair? */
2625 if (di == 0) fno->fname[di++] = '?'; /* Inaccessible object name? */
2626 fno->fname[di] = 0; /* Terminate the name */
2627 fno->altname[0] = 0; /* exFAT does not support SFN */
2628
2629 fno->fattrib = fs->dirbuf[XDIR_Attr] & AM_MASKX; /* Attribute */
2630 fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(fs->dirbuf + XDIR_FileSize); /* Size */
2631 fno->ftime = ld_word(fs->dirbuf + XDIR_ModTime + 0); /* Time */
2632 fno->fdate = ld_word(fs->dirbuf + XDIR_ModTime + 2); /* Date */
2633 return;
2634 } else
2635#endif
2636 { /* FAT/FAT32 volume */
2637 if (dp->blk_ofs != 0xFFFFFFFF) { /* Get LFN if available */
2638 si = di = 0;
2639 hs = 0;
2640 while (fs->lfnbuf[si] != 0) {
2641 wc = fs->lfnbuf[si++]; /* Get an LFN character (UTF-16) */
2642 if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
2643 hs = wc; continue; /* Get low surrogate */
2644 }
2645 nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
2646 if (nw == 0) { di = 0; break; } /* Buffer overflow or wrong char? */
2647 di += nw;
2648 hs = 0;
2649 }
2650 if (hs != 0) di = 0; /* Broken surrogate pair? */
2651 fno->fname[di] = 0; /* Terminate the LFN (null string means LFN is invalid) */
2652 }
2653 }
2654
2655 si = di = 0;
2656 while (si < 11) { /* Get SFN from SFN entry */
2657 wc = dp->dir[si++]; /* Get a char */
2658 if (wc == ' ') continue; /* Skip padding spaces */
2659 if (wc == RDDEM) wc = DDEM; /* Restore replaced DDEM character */
2660 if (si == 9 && di < FF_SFN_BUF) fno->altname[di++] = '.'; /* Insert a . if extension is exist */
2661#if FF_LFN_UNICODE >= 1 /* Unicode output */
2662 if (dbc_1st((BYTE)wc) && si != 8 && si != 11 && dbc_2nd(dp->dir[si])) { /* Make a DBC if needed */
2663 wc = wc << 8 | dp->dir[si++];
2664 }
2665 wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM -> Unicode */
2666 if (wc == 0) { di = 0; break; } /* Wrong char in the current code page? */
2667 nw = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in API encoding */
2668 if (nw == 0) { di = 0; break; } /* Buffer overflow? */
2669 di += nw;
2670#else /* ANSI/OEM output */
2671 fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */
2672#endif
2673 }
2674 fno->altname[di] = 0; /* Terminate the SFN (null string means SFN is invalid) */
2675
2676 if (fno->fname[0] == 0) { /* If LFN is invalid, altname[] needs to be copied to fname[] */
2677 if (di == 0) { /* If LFN and SFN both are invalid, this object is inaccesible */
2678 fno->fname[di++] = '?';
2679 } else {
2680 for (si = di = 0, lcf = NS_BODY; fno->altname[si]; si++, di++) { /* Copy altname[] to fname[] with case information */
2681 wc = (WCHAR)fno->altname[si];
2682 if (wc == '.') lcf = NS_EXT;
2683 if (IsUpper(wc) && (dp->dir[DIR_NTres] & lcf)) wc += 0x20;
2684 fno->fname[di] = (TCHAR)wc;
2685 }
2686 }
2687 fno->fname[di] = 0; /* Terminate the LFN */
2688 if (!dp->dir[DIR_NTres]) fno->altname[0] = 0; /* Altname is not needed if neither LFN nor case info is exist. */
2689 }
2690
2691#else /* Non-LFN configuration */
2692 si = di = 0;
2693 while (si < 11) { /* Copy name body and extension */
2694 c = (TCHAR)dp->dir[si++];
2695 if (c == ' ') continue; /* Skip padding spaces */
2696 if (c == RDDEM) c = DDEM; /* Restore replaced DDEM character */
2697 if (si == 9) fno->fname[di++] = '.';/* Insert a . if extension is exist */
2698 fno->fname[di++] = c;
2699 }
2700 fno->fname[di] = 0; /* Terminate the SFN */
2701#endif
2702
2703 fno->fattrib = dp->dir[DIR_Attr] & AM_MASK; /* Attribute */
2704 fno->fsize = ld_dword(dp->dir + DIR_FileSize); /* Size */
2705 fno->ftime = ld_word(dp->dir + DIR_ModTime + 0); /* Time */
2706 fno->fdate = ld_word(dp->dir + DIR_ModTime + 2); /* Date */
2707}
#define MAXDIRB(nc)
Definition ff.c:514
static UINT put_utf(DWORD chr, TCHAR *buf, UINT szb)
Definition ff.c:801
#define AM_MASKX
Definition ff.c:68
#define FF_LFN_BUF
Definition ffconf.h:151
#define FF_SFN_BUF
Definition ffconf.h:152
WORD fdate
Definition ff.h:249
BYTE fattrib
Definition ff.h:251
FSIZE_t fsize
Definition ff.h:248
TCHAR fname[FF_LFN_BUF+1]
Definition ff.h:254
TCHAR altname[FF_SFN_BUF+1]
Definition ff.h:253
WORD ftime
Definition ff.h:250

◆ get_ldnumber()

static int get_ldnumber ( const TCHAR **  path)
static

Definition at line 3090 of file ff.c.

3093{
3094 const TCHAR *tp, *tt;
3095 TCHAR tc;
3096 int i;
3097 int vol = -1;
3098#if FF_STR_VOLUME_ID /* Find string volume ID */
3099 const char *sp;
3100 char c;
3101#endif
3102
3103 tt = tp = *path;
3104 if (!tp) return vol; /* Invalid path name? */
3105 do tc = *tt++; while (!IsTerminator(tc) && tc != ':'); /* Find a colon in the path */
3106
3107 if (tc == ':') { /* DOS/Windows style volume ID? */
3108 i = FF_VOLUMES;
3109 if (IsDigit(*tp) && tp + 2 == tt) { /* Is there a numeric volume ID + colon? */
3110 i = (int)*tp - '0'; /* Get the LD number */
3111 }
3112#if FF_STR_VOLUME_ID == 1 /* Arbitrary string is enabled */
3113 else {
3114 i = 0;
3115 do {
3116 sp = VolumeStr[i]; tp = *path; /* This string volume ID and path name */
3117 do { /* Compare the volume ID with path name */
3118 c = *sp++; tc = *tp++;
3119 if (IsLower(c)) c -= 0x20;
3120 if (IsLower(tc)) tc -= 0x20;
3121 } while (c && (TCHAR)c == tc);
3122 } while ((c || tp != tt) && ++i < FF_VOLUMES); /* Repeat for each id until pattern match */
3123 }
3124#endif
3125 if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */
3126 vol = i; /* Drive number */
3127 *path = tt; /* Snip the drive prefix off */
3128 }
3129 return vol;
3130 }
3131#if FF_STR_VOLUME_ID == 2 /* Unix style volume ID is enabled */
3132 if (*tp == '/') { /* Is there a volume ID? */
3133 while (*(tp + 1) == '/') tp++; /* Skip duplicated separator */
3134 i = 0;
3135 do {
3136 tt = tp; sp = VolumeStr[i]; /* Path name and this string volume ID */
3137 do { /* Compare the volume ID with path name */
3138 c = *sp++; tc = *(++tt);
3139 if (IsLower(c)) c -= 0x20;
3140 if (IsLower(tc)) tc -= 0x20;
3141 } while (c && (TCHAR)c == tc);
3142 } while ((c || (tc != '/' && !IsTerminator(tc))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */
3143 if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */
3144 vol = i; /* Drive number */
3145 *path = tt; /* Snip the drive prefix off */
3146 }
3147 return vol;
3148 }
3149#endif
3150 /* No drive prefix is found */
3151#if FF_FS_RPATH != 0
3152 vol = CurrVol; /* Default drive is current drive */
3153#else
3154 vol = 0; /* Default drive is 0 */
3155#endif
3156 return vol; /* Return the default drive */
3157}

◆ inc_lock()

static UINT inc_lock ( DIR dp,
int  acc 
)
static

Definition at line 953 of file ff.c.

957{
958 UINT i;
959
960
961 for (i = 0; i < FF_FS_LOCK; i++) { /* Find the object */
962 if (Files[i].fs == dp->obj.fs
963 && Files[i].clu == dp->obj.sclust
964 && Files[i].ofs == dp->dptr) break;
965 }
966
967 if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */
968 for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
969 if (i == FF_FS_LOCK) return 0; /* No free entry to register (int err) */
970 Files[i].fs = dp->obj.fs;
971 Files[i].clu = dp->obj.sclust;
972 Files[i].ofs = dp->dptr;
973 Files[i].ctr = 0;
974 }
975
976 if (acc >= 1 && Files[i].ctr) return 0; /* Access violation (int err) */
977
978 Files[i].ctr = acc ? 0x100 : Files[i].ctr + 1; /* Set semaphore value */
979
980 return i + 1; /* Index number origin from 1 */
981}

◆ ld_clust()

static DWORD ld_clust ( FATFS fs,
const BYTE dir 
)
static

Definition at line 1817 of file ff.c.

1821{
1822 DWORD cl;
1823
1824 cl = ld_word(dir + DIR_FstClusLO);
1825 if (fs->fs_type == FS_FAT32) {
1826 cl |= (DWORD)ld_word(dir + DIR_FstClusHI) << 16;
1827 }
1828
1829 return cl;
1830}
#define DIR_FstClusHI
Definition ff.c:157
#define DIR_FstClusLO
Definition ff.c:159

◆ ld_dword()

static DWORD ld_dword ( const BYTE ptr)
static

Definition at line 623 of file ff.c.

624{
625 DWORD rv;
626
627 rv = ptr[3];
628 rv = rv << 8 | ptr[2];
629 rv = rv << 8 | ptr[1];
630 rv = rv << 8 | ptr[0];
631 return rv;
632}

◆ ld_word()

static WORD ld_word ( const BYTE ptr)
static

Definition at line 614 of file ff.c.

615{
616 WORD rv;
617
618 rv = ptr[1];
619 rv = rv << 8 | ptr[0];
620 return rv;
621}

◆ mount_volume()

static FRESULT mount_volume ( const TCHAR **  path,
FATFS **  rfs,
BYTE  mode 
)
static

Definition at line 3332 of file ff.c.

3337{
3338 int vol;
3339 DSTATUS stat;
3340 LBA_t bsect;
3341 DWORD tsect, sysect, fasize, nclst, szbfat;
3342 WORD nrsv;
3343 FATFS *fs;
3344 UINT fmt;
3345
3346
3347 /* Get logical drive number */
3348 *rfs = 0;
3349 vol = get_ldnumber(path);
3350 if (vol < 0) return FR_INVALID_DRIVE;
3351
3352 /* Check if the filesystem object is valid or not */
3353 fs = FatFs[vol]; /* Get pointer to the filesystem object */
3354 if (!fs) return FR_NOT_ENABLED; /* Is the filesystem object available? */
3355#if FF_FS_REENTRANT
3356 if (!lock_fs(fs)) return FR_TIMEOUT; /* Lock the volume */
3357#endif
3358 *rfs = fs; /* Return pointer to the filesystem object */
3359
3360 mode &= (BYTE)~FA_READ; /* Desired access mode, write access or not */
3361 if (fs->fs_type != 0) { /* If the volume has been mounted */
3362 stat = disk_status(fs->pdrv);
3363 if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized */
3364 if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check write protection if needed */
3365 return FR_WRITE_PROTECTED;
3366 }
3367 return FR_OK; /* The filesystem object is already valid */
3368 }
3369 }
3370
3371 /* The filesystem object is not valid. */
3372 /* Following code attempts to mount the volume. (find an FAT volume, analyze the BPB and initialize the filesystem object) */
3373
3374 fs->fs_type = 0; /* Clear the filesystem object */
3375 fs->pdrv = LD2PD(vol); /* Volume hosting physical drive */
3376 stat = disk_initialize(fs->pdrv); /* Initialize the physical drive */
3377 if (stat & STA_NOINIT) { /* Check if the initialization succeeded */
3378 return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */
3379 }
3380 if (!FF_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check disk write protection if needed */
3381 return FR_WRITE_PROTECTED;
3382 }
3383#if FF_MAX_SS != FF_MIN_SS /* Get sector size (multiple sector size cfg only) */
3384 if (disk_ioctl(fs->pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK) return FR_DISK_ERR;
3385 if (SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS || (SS(fs) & (SS(fs) - 1))) return FR_DISK_ERR;
3386#endif
3387
3388 /* Find an FAT volume on the drive */
3389 fmt = find_volume(fs, LD2PT(vol));
3390 if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */
3391 if (fmt >= 2) return FR_NO_FILESYSTEM; /* No FAT volume is found */
3392 bsect = fs->winsect; /* Volume offset */
3393
3394 /* An FAT volume is found (bsect). Following code initializes the filesystem object */
3395
3396#if FF_FS_EXFAT
3397 if (fmt == 1) {
3398 QWORD maxlba;
3399 DWORD so, cv, bcl, i;
3400
3401 for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && fs->win[i] == 0; i++) ; /* Check zero filler */
3402 if (i < BPB_ZeroedEx + 53) return FR_NO_FILESYSTEM;
3403
3404 if (ld_word(fs->win + BPB_FSVerEx) != 0x100) return FR_NO_FILESYSTEM; /* Check exFAT version (must be version 1.0) */
3405
3406 if (1 << fs->win[BPB_BytsPerSecEx] != SS(fs)) { /* (BPB_BytsPerSecEx must be equal to the physical sector size) */
3407 return FR_NO_FILESYSTEM;
3408 }
3409
3410 maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA of the volume + 1 */
3411 if (!FF_LBA64 && maxlba >= 0x100000000) return FR_NO_FILESYSTEM; /* (It cannot be accessed in 32-bit LBA) */
3412
3413 fs->fsize = ld_dword(fs->win + BPB_FatSzEx); /* Number of sectors per FAT */
3414
3415 fs->n_fats = fs->win[BPB_NumFATsEx]; /* Number of FATs */
3416 if (fs->n_fats != 1) return FR_NO_FILESYSTEM; /* (Supports only 1 FAT) */
3417
3418 fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */
3419 if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768 sectors) */
3420
3421 nclst = ld_dword(fs->win + BPB_NumClusEx); /* Number of clusters */
3422 if (nclst > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */
3423 fs->n_fatent = nclst + 2;
3424
3425 /* Boundaries and Limits */
3426 fs->volbase = bsect;
3427 fs->database = bsect + ld_dword(fs->win + BPB_DataOfsEx);
3428 fs->fatbase = bsect + ld_dword(fs->win + BPB_FatOfsEx);
3429 if (maxlba < (QWORD)fs->database + nclst * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size requiered) */
3430 fs->dirbase = ld_dword(fs->win + BPB_RootClusEx);
3431
3432 /* Get bitmap location and check if it is contiguous (implementation assumption) */
3433 so = i = 0;
3434 for (;;) { /* Find the bitmap entry in the root directory (in only first cluster) */
3435 if (i == 0) {
3436 if (so >= fs->csize) return FR_NO_FILESYSTEM; /* Not found? */
3437 if (move_window(fs, clst2sect(fs, (DWORD)fs->dirbase) + so) != FR_OK) return FR_DISK_ERR;
3438 so++;
3439 }
3440 if (fs->win[i] == ET_BITMAP) break; /* Is it a bitmap entry? */
3441 i = (i + SZDIRE) % SS(fs); /* Next entry */
3442 }
3443 bcl = ld_dword(fs->win + i + 20); /* Bitmap cluster */
3444 if (bcl < 2 || bcl >= fs->n_fatent) return FR_NO_FILESYSTEM; /* (Wrong cluster#) */
3445 fs->bitbase = fs->database + fs->csize * (bcl - 2); /* Bitmap sector */
3446 for (;;) { /* Check if bitmap is contiguous */
3447 if (move_window(fs, fs->fatbase + bcl / (SS(fs) / 4)) != FR_OK) return FR_DISK_ERR;
3448 cv = ld_dword(fs->win + bcl % (SS(fs) / 4) * 4);
3449 if (cv == 0xFFFFFFFF) break; /* Last link? */
3450 if (cv != ++bcl) return FR_NO_FILESYSTEM; /* Fragmented? */
3451 }
3452
3453#if !FF_FS_READONLY
3454 fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */
3455#endif
3456 fmt = FS_EXFAT; /* FAT sub-type */
3457 } else
3458#endif /* FF_FS_EXFAT */
3459 {
3460 if (ld_word(fs->win + BPB_BytsPerSec) != SS(fs)) return FR_NO_FILESYSTEM; /* (BPB_BytsPerSec must be equal to the physical sector size) */
3461
3462 fasize = ld_word(fs->win + BPB_FATSz16); /* Number of sectors per FAT */
3463 if (fasize == 0) fasize = ld_dword(fs->win + BPB_FATSz32);
3464 fs->fsize = fasize;
3465
3466 fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FATs */
3467 if (fs->n_fats != 1 && fs->n_fats != 2) return FR_NO_FILESYSTEM; /* (Must be 1 or 2) */
3468 fasize *= fs->n_fats; /* Number of sectors for FAT area */
3469
3470 fs->csize = fs->win[BPB_SecPerClus]; /* Cluster size */
3471 if (fs->csize == 0 || (fs->csize & (fs->csize - 1))) return FR_NO_FILESYSTEM; /* (Must be power of 2) */
3472
3473 fs->n_rootdir = ld_word(fs->win + BPB_RootEntCnt); /* Number of root directory entries */
3474 if (fs->n_rootdir % (SS(fs) / SZDIRE)) return FR_NO_FILESYSTEM; /* (Must be sector aligned) */
3475
3476 tsect = ld_word(fs->win + BPB_TotSec16); /* Number of sectors on the volume */
3477 if (tsect == 0) tsect = ld_dword(fs->win + BPB_TotSec32);
3478
3479 nrsv = ld_word(fs->win + BPB_RsvdSecCnt); /* Number of reserved sectors */
3480 if (nrsv == 0) return FR_NO_FILESYSTEM; /* (Must not be 0) */
3481
3482 /* Determine the FAT sub type */
3483 sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZDIRE); /* RSV + FAT + DIR */
3484 if (tsect < sysect) return FR_NO_FILESYSTEM; /* (Invalid volume size) */
3485 nclst = (tsect - sysect) / fs->csize; /* Number of clusters */
3486 if (nclst == 0) return FR_NO_FILESYSTEM; /* (Invalid volume size) */
3487 fmt = 0;
3488 if (nclst <= MAX_FAT32) fmt = FS_FAT32;
3489 if (nclst <= MAX_FAT16) fmt = FS_FAT16;
3490 if (nclst <= MAX_FAT12) fmt = FS_FAT12;
3491 if (fmt == 0) return FR_NO_FILESYSTEM;
3492
3493 /* Boundaries and Limits */
3494 fs->n_fatent = nclst + 2; /* Number of FAT entries */
3495 fs->volbase = bsect; /* Volume start sector */
3496 fs->fatbase = bsect + nrsv; /* FAT start sector */
3497 fs->database = bsect + sysect; /* Data start sector */
3498 if (fmt == FS_FAT32) {
3499 if (ld_word(fs->win + BPB_FSVer32) != 0) return FR_NO_FILESYSTEM; /* (Must be FAT32 revision 0.0) */
3500 if (fs->n_rootdir != 0) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */
3501 fs->dirbase = ld_dword(fs->win + BPB_RootClus32); /* Root directory start cluster */
3502 szbfat = fs->n_fatent * 4; /* (Needed FAT size) */
3503 } else {
3504 if (fs->n_rootdir == 0) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */
3505 fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */
3506 szbfat = (fmt == FS_FAT16) ? /* (Needed FAT size) */
3507 fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1);
3508 }
3509 if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) return FR_NO_FILESYSTEM; /* (BPB_FATSz must not be less than the size needed) */
3510
3511#if !FF_FS_READONLY
3512 /* Get FSInfo if available */
3513 fs->last_clst = fs->free_clst = 0xFFFFFFFF; /* Initialize cluster allocation information */
3514 fs->fsi_flag = 0x80;
3515#if (FF_FS_NOFSINFO & 3) != 3
3516 if (fmt == FS_FAT32 /* Allow to update FSInfo only if BPB_FSInfo32 == 1 */
3517 && ld_word(fs->win + BPB_FSInfo32) == 1
3518 && move_window(fs, bsect + 1) == FR_OK)
3519 {
3520 fs->fsi_flag = 0;
3521 if (ld_word(fs->win + BS_55AA) == 0xAA55 /* Load FSInfo data if available */
3522 && ld_dword(fs->win + FSI_LeadSig) == 0x41615252
3523 && ld_dword(fs->win + FSI_StrucSig) == 0x61417272)
3524 {
3525#if (FF_FS_NOFSINFO & 1) == 0
3526 fs->free_clst = ld_dword(fs->win + FSI_Free_Count);
3527#endif
3528#if (FF_FS_NOFSINFO & 2) == 0
3529 fs->last_clst = ld_dword(fs->win + FSI_Nxt_Free);
3530#endif
3531 }
3532 }
3533#endif /* (FF_FS_NOFSINFO & 3) != 3 */
3534#endif /* !FF_FS_READONLY */
3535 }
3536
3537 fs->fs_type = (BYTE)fmt;/* FAT sub-type */
3538 fs->id = ++Fsid; /* Volume mount ID */
3539#if FF_USE_LFN == 1
3540 fs->lfnbuf = LfnBuf; /* Static LFN working buffer */
3541#if FF_FS_EXFAT
3542 fs->dirbuf = DirBuf; /* Static directory block scratchpad buuffer */
3543#endif
3544#endif
3545#if FF_FS_RPATH != 0
3546 fs->cdir = 0; /* Initialize current directory */
3547#endif
3548#if FF_FS_LOCK != 0 /* Clear file lock semaphores */
3549 clear_lock(fs);
3550#endif
3551 return FR_OK;
3552}
DSTATUS disk_initialize(BYTE pdrv)
DSTATUS disk_status(BYTE pdrv)
#define STA_PROTECT
Definition diskio.h:40
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
#define STA_NOINIT
Definition diskio.h:38
#define GET_SECTOR_SIZE
Definition diskio.h:48
BYTE DSTATUS
Definition diskio.h:13
#define MAX_FAT12
Definition ff.c:41
static WORD Fsid
Definition ff.c:465
#define BPB_FatOfsEx
Definition ff.c:135
#define BPB_NumFATsEx
Definition ff.c:145
#define MAX_FAT16
Definition ff.c:42
#define FSI_LeadSig
Definition ff.c:193
#define FSI_Nxt_Free
Definition ff.c:196
#define FSI_StrucSig
Definition ff.c:194
#define BPB_BytsPerSecEx
Definition ff.c:143
#define MAX_FAT32
Definition ff.c:43
#define BPB_RootClus32
Definition ff.c:121
#define BPB_FatSzEx
Definition ff.c:136
#define BPB_NumClusEx
Definition ff.c:138
#define BPB_SecPerClusEx
Definition ff.c:144
#define LD2PD(vol)
Definition ff.c:253
#define BPB_FATSz32
Definition ff.c:118
#define BPB_RootClusEx
Definition ff.c:139
#define BPB_FSInfo32
Definition ff.c:122
#define BPB_FSVerEx
Definition ff.c:141
#define BPB_ZeroedEx
Definition ff.c:132
#define LD2PT(vol)
Definition ff.c:254
#define FSI_Free_Count
Definition ff.c:195
#define ET_BITMAP
Definition ff.c:84
#define BPB_TotSecEx
Definition ff.c:134
#define BPB_DataOfsEx
Definition ff.c:137
#define MAX_EXFAT
Definition ff.c:44
#define BPB_FSVer32
Definition ff.c:120
static UINT find_volume(FATFS *fs, UINT part)
Definition ff.c:3278
@ FR_NO_FILESYSTEM
Definition ff.h:290
@ FR_TIMEOUT
Definition ff.h:292
@ FR_WRITE_PROTECTED
Definition ff.h:287
@ FR_NOT_READY
Definition ff.h:280
@ FR_NOT_ENABLED
Definition ff.h:289
#define FF_LBA64
Definition ffconf.h:209
DWORD fsize
Definition ff.h:166
BYTE n_fats
Definition ff.h:135
LBA_t volbase
Definition ff.h:167

◆ move_window()

static FRESULT move_window ( FATFS fs,
LBA_t  sect 
)
static

Definition at line 1047 of file ff.c.

1051{
1052 FRESULT res = FR_OK;
1053
1054
1055 if (sect != fs->winsect) { /* Window offset changed? */
1056#if !FF_FS_READONLY
1057 res = sync_window(fs); /* Flush the window */
1058#endif
1059 if (res == FR_OK) { /* Fill sector window with new data */
1060 if (disk_read(fs->pdrv, fs->win, sect, 1) != RES_OK) {
1061 sect = (LBA_t)0 - 1; /* Invalidate window if read data is not valid */
1062 res = FR_DISK_ERR;
1063 }
1064 fs->winsect = sect;
1065 }
1066 }
1067 return res;
1068}

◆ pick_lfn()

static int pick_lfn ( WCHAR lfnbuf,
BYTE dir 
)
static

Definition at line 1890 of file ff.c.

1894{
1895 UINT i, s;
1896 WCHAR wc, uc;
1897
1898
1899 if (ld_word(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO is 0 */
1900
1901 i = ((dir[LDIR_Ord] & ~LLEF) - 1) * 13; /* Offset in the LFN buffer */
1902
1903 for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */
1904 uc = ld_word(dir + LfnOfs[s]); /* Pick an LFN character */
1905 if (wc != 0) {
1906 if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */
1907 lfnbuf[i++] = wc = uc; /* Store it */
1908 } else {
1909 if (uc != 0xFFFF) return 0; /* Check filler */
1910 }
1911 }
1912
1913 if (dir[LDIR_Ord] & LLEF && wc != 0) { /* Put terminator if it is the last LFN part and not terminated */
1914 if (i >= FF_MAX_LFN + 1) return 0; /* Buffer overflow? */
1915 lfnbuf[i] = 0;
1916 }
1917
1918 return 1; /* The part of LFN is valid */
1919}

◆ put_fat()

static FRESULT put_fat ( FATFS fs,
DWORD  clst,
DWORD  val 
)
static

Definition at line 1209 of file ff.c.

1214{
1215 UINT bc;
1216 BYTE *p;
1217 FRESULT res = FR_INT_ERR;
1218
1219
1220 if (clst >= 2 && clst < fs->n_fatent) { /* Check if in valid range */
1221 switch (fs->fs_type) {
1222 case FS_FAT12:
1223 bc = (UINT)clst; bc += bc / 2; /* bc: byte offset of the entry */
1224 res = move_window(fs, fs->fatbase + (bc / SS(fs)));
1225 if (res != FR_OK) break;
1226 p = fs->win + bc++ % SS(fs);
1227 *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Update 1st byte */
1228 fs->wflag = 1;
1229 res = move_window(fs, fs->fatbase + (bc / SS(fs)));
1230 if (res != FR_OK) break;
1231 p = fs->win + bc % SS(fs);
1232 *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); /* Update 2nd byte */
1233 fs->wflag = 1;
1234 break;
1235
1236 case FS_FAT16:
1237 res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)));
1238 if (res != FR_OK) break;
1239 st_word(fs->win + clst * 2 % SS(fs), (WORD)val); /* Simple WORD array */
1240 fs->wflag = 1;
1241 break;
1242
1243 case FS_FAT32:
1244#if FF_FS_EXFAT
1245 case FS_EXFAT:
1246#endif
1247 res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)));
1248 if (res != FR_OK) break;
1249 if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) {
1250 val = (val & 0x0FFFFFFF) | (ld_dword(fs->win + clst * 4 % SS(fs)) & 0xF0000000);
1251 }
1252 st_dword(fs->win + clst * 4 % SS(fs), val);
1253 fs->wflag = 1;
1254 break;
1255 }
1256 }
1257 return res;
1258}

◆ put_lfn()

static void put_lfn ( const WCHAR lfn,
BYTE dir,
BYTE  ord,
BYTE  sum 
)
static

Definition at line 1928 of file ff.c.

1934{
1935 UINT i, s;
1936 WCHAR wc;
1937
1938
1939 dir[LDIR_Chksum] = sum; /* Set checksum */
1940 dir[LDIR_Attr] = AM_LFN; /* Set attribute. LFN entry */
1941 dir[LDIR_Type] = 0;
1942 st_word(dir + LDIR_FstClusLO, 0);
1943
1944 i = (ord - 1) * 13; /* Get offset in the LFN working buffer */
1945 s = wc = 0;
1946 do {
1947 if (wc != 0xFFFF) wc = lfn[i++]; /* Get an effective character */
1948 st_word(dir + LfnOfs[s], wc); /* Put it */
1949 if (wc == 0) wc = 0xFFFF; /* Padding characters for following items */
1950 } while (++s < 13);
1951 if (wc == 0xFFFF || !lfn[i]) ord |= LLEF; /* Last LFN part is the start of LFN sequence */
1952 dir[LDIR_Ord] = ord; /* Set the LFN order */
1953}
#define LDIR_Attr
Definition ff.c:162
#define LDIR_Type
Definition ff.c:163

◆ put_utf()

static UINT put_utf ( DWORD  chr,
TCHAR buf,
UINT  szb 
)
static

Definition at line 801 of file ff.c.

806{
807#if FF_LFN_UNICODE == 1 /* UTF-16 output */
808 WCHAR hs, wc;
809
810 hs = (WCHAR)(chr >> 16);
811 wc = (WCHAR)chr;
812 if (hs == 0) { /* Single encoding unit? */
813 if (szb < 1 || IsSurrogate(wc)) return 0; /* Buffer overflow or wrong code? */
814 *buf = wc;
815 return 1;
816 }
817 if (szb < 2 || !IsSurrogateH(hs) || !IsSurrogateL(wc)) return 0; /* Buffer overflow or wrong surrogate? */
818 *buf++ = hs;
819 *buf++ = wc;
820 return 2;
821
822#elif FF_LFN_UNICODE == 2 /* UTF-8 output */
823 DWORD hc;
824
825 if (chr < 0x80) { /* Single byte code? */
826 if (szb < 1) return 0; /* Buffer overflow? */
827 *buf = (TCHAR)chr;
828 return 1;
829 }
830 if (chr < 0x800) { /* 2-byte sequence? */
831 if (szb < 2) return 0; /* Buffer overflow? */
832 *buf++ = (TCHAR)(0xC0 | (chr >> 6 & 0x1F));
833 *buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F));
834 return 2;
835 }
836 if (chr < 0x10000) { /* 3-byte sequence? */
837 if (szb < 3 || IsSurrogate(chr)) return 0; /* Buffer overflow or wrong code? */
838 *buf++ = (TCHAR)(0xE0 | (chr >> 12 & 0x0F));
839 *buf++ = (TCHAR)(0x80 | (chr >> 6 & 0x3F));
840 *buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F));
841 return 3;
842 }
843 /* 4-byte sequence */
844 if (szb < 4) return 0; /* Buffer overflow? */
845 hc = ((chr & 0xFFFF0000) - 0xD8000000) >> 6; /* Get high 10 bits */
846 chr = (chr & 0xFFFF) - 0xDC00; /* Get low 10 bits */
847 if (hc >= 0x100000 || chr >= 0x400) return 0; /* Wrong surrogate? */
848 chr = (hc | chr) + 0x10000;
849 *buf++ = (TCHAR)(0xF0 | (chr >> 18 & 0x07));
850 *buf++ = (TCHAR)(0x80 | (chr >> 12 & 0x3F));
851 *buf++ = (TCHAR)(0x80 | (chr >> 6 & 0x3F));
852 *buf++ = (TCHAR)(0x80 | (chr >> 0 & 0x3F));
853 return 4;
854
855#elif FF_LFN_UNICODE == 3 /* UTF-32 output */
856 DWORD hc;
857
858 if (szb < 1) return 0; /* Buffer overflow? */
859 if (chr >= 0x10000) { /* Out of BMP? */
860 hc = ((chr & 0xFFFF0000) - 0xD8000000) >> 6; /* Get high 10 bits */
861 chr = (chr & 0xFFFF) - 0xDC00; /* Get low 10 bits */
862 if (hc >= 0x100000 || chr >= 0x400) return 0; /* Wrong surrogate? */
863 chr = (hc | chr) + 0x10000;
864 }
865 *buf++ = (TCHAR)chr;
866 return 1;
867
868#else /* ANSI/OEM output */
869 WCHAR wc;
870
871 wc = ff_uni2oem(chr, CODEPAGE);
872 if (wc >= 0x100) { /* Is this a DBC? */
873 if (szb < 2) return 0;
874 *buf++ = (char)(wc >> 8); /* Store DBC 1st byte */
875 *buf++ = (TCHAR)wc; /* Store DBC 2nd byte */
876 return 2;
877 }
878 if (wc == 0 || szb < 1) return 0; /* Invalid char or buffer overflow? */
879 *buf++ = (TCHAR)wc; /* Store the character */
880 return 1;
881#endif
882}

◆ putc_bfd()

static void putc_bfd ( putbuff pb,
TCHAR  c 
)
static

Definition at line 6488 of file ff.c.

6489{
6490 UINT n;
6491 int i, nc;
6492#if FF_USE_LFN && FF_LFN_UNICODE
6493 WCHAR hs, wc;
6494#if FF_LFN_UNICODE == 2
6495 DWORD dc;
6496 const TCHAR *tp;
6497#endif
6498#endif
6499
6500 if (FF_USE_STRFUNC == 2 && c == '\n') { /* LF -> CRLF conversion */
6501 putc_bfd(pb, '\r');
6502 }
6503
6504 i = pb->idx; /* Write index of pb->buf[] */
6505 if (i < 0) return; /* In write error? */
6506 nc = pb->nchr; /* Write unit counter */
6507
6508#if FF_USE_LFN && FF_LFN_UNICODE
6509#if FF_LFN_UNICODE == 1 /* UTF-16 input */
6510 if (IsSurrogateH(c)) { /* High surrogate? */
6511 pb->hs = c; return; /* Save it for next */
6512 }
6513 hs = pb->hs; pb->hs = 0;
6514 if (hs != 0) { /* There is a leading high surrogate */
6515 if (!IsSurrogateL(c)) hs = 0; /* Discard high surrogate if not a surrogate pair */
6516 } else {
6517 if (IsSurrogateL(c)) return; /* Discard stray low surrogate */
6518 }
6519 wc = c;
6520#elif FF_LFN_UNICODE == 2 /* UTF-8 input */
6521 for (;;) {
6522 if (pb->ct == 0) { /* Out of multi-byte sequence? */
6523 pb->bs[pb->wi = 0] = (BYTE)c; /* Save 1st byte */
6524 if ((BYTE)c < 0x80) break; /* Single byte? */
6525 if (((BYTE)c & 0xE0) == 0xC0) pb->ct = 1; /* 2-byte sequence? */
6526 if (((BYTE)c & 0xF0) == 0xE0) pb->ct = 2; /* 3-byte sequence? */
6527 if (((BYTE)c & 0xF1) == 0xF0) pb->ct = 3; /* 4-byte sequence? */
6528 return;
6529 } else { /* In the multi-byte sequence */
6530 if (((BYTE)c & 0xC0) != 0x80) { /* Broken sequence? */
6531 pb->ct = 0; continue;
6532 }
6533 pb->bs[++pb->wi] = (BYTE)c; /* Save the trailing byte */
6534 if (--pb->ct == 0) break; /* End of multi-byte sequence? */
6535 return;
6536 }
6537 }
6538 tp = (const TCHAR*)pb->bs;
6539 dc = tchar2uni(&tp); /* UTF-8 ==> UTF-16 */
6540 if (dc == 0xFFFFFFFF) return; /* Wrong code? */
6541 wc = (WCHAR)dc;
6542 hs = (WCHAR)(dc >> 16);
6543#elif FF_LFN_UNICODE == 3 /* UTF-32 input */
6544 if (IsSurrogate(c) || c >= 0x110000) return; /* Discard invalid code */
6545 if (c >= 0x10000) { /* Out of BMP? */
6546 hs = (WCHAR)(0xD800 | ((c >> 10) - 0x40)); /* Make high surrogate */
6547 wc = 0xDC00 | (c & 0x3FF); /* Make low surrogate */
6548 } else {
6549 hs = 0;
6550 wc = (WCHAR)c;
6551 }
6552#endif
6553 /* A code point in UTF-16 is available in hs and wc */
6554
6555#if FF_STRF_ENCODE == 1 /* Write a code point in UTF-16LE */
6556 if (hs != 0) { /* Surrogate pair? */
6557 st_word(&pb->buf[i], hs);
6558 i += 2;
6559 nc++;
6560 }
6561 st_word(&pb->buf[i], wc);
6562 i += 2;
6563#elif FF_STRF_ENCODE == 2 /* Write a code point in UTF-16BE */
6564 if (hs != 0) { /* Surrogate pair? */
6565 pb->buf[i++] = (BYTE)(hs >> 8);
6566 pb->buf[i++] = (BYTE)hs;
6567 nc++;
6568 }
6569 pb->buf[i++] = (BYTE)(wc >> 8);
6570 pb->buf[i++] = (BYTE)wc;
6571#elif FF_STRF_ENCODE == 3 /* Write a code point in UTF-8 */
6572 if (hs != 0) { /* 4-byte sequence? */
6573 nc += 3;
6574 hs = (hs & 0x3FF) + 0x40;
6575 pb->buf[i++] = (BYTE)(0xF0 | hs >> 8);
6576 pb->buf[i++] = (BYTE)(0x80 | (hs >> 2 & 0x3F));
6577 pb->buf[i++] = (BYTE)(0x80 | (hs & 3) << 4 | (wc >> 6 & 0x0F));
6578 pb->buf[i++] = (BYTE)(0x80 | (wc & 0x3F));
6579 } else {
6580 if (wc < 0x80) { /* Single byte? */
6581 pb->buf[i++] = (BYTE)wc;
6582 } else {
6583 if (wc < 0x800) { /* 2-byte sequence? */
6584 nc += 1;
6585 pb->buf[i++] = (BYTE)(0xC0 | wc >> 6);
6586 } else { /* 3-byte sequence */
6587 nc += 2;
6588 pb->buf[i++] = (BYTE)(0xE0 | wc >> 12);
6589 pb->buf[i++] = (BYTE)(0x80 | (wc >> 6 & 0x3F));
6590 }
6591 pb->buf[i++] = (BYTE)(0x80 | (wc & 0x3F));
6592 }
6593 }
6594#else /* Write a code point in ANSI/OEM */
6595 if (hs != 0) return;
6596 wc = ff_uni2oem(wc, CODEPAGE); /* UTF-16 ==> ANSI/OEM */
6597 if (wc == 0) return;
6598 if (wc >= 0x100) {
6599 pb->buf[i++] = (BYTE)(wc >> 8); nc++;
6600 }
6601 pb->buf[i++] = (BYTE)wc;
6602#endif
6603
6604#else /* ANSI/OEM input (without re-encoding) */
6605 pb->buf[i++] = (BYTE)c;
6606#endif
6607
6608 if (i >= (int)(sizeof pb->buf) - 4) { /* Write buffered characters to the file */
6609 f_write(pb->fp, pb->buf, (UINT)i, &n);
6610 i = (n == (UINT)i) ? 0 : -1;
6611 }
6612 pb->idx = i;
6613 pb->nchr = nc + 1;
6614}
FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw)
Definition ff.c:3950
int idx
Definition ff.c:6475
int nchr
Definition ff.c:6475
FIL * fp
Definition ff.c:6474
BYTE buf[SZ_PUTC_BUF]
Definition ff.c:6482

◆ putc_flush()

static int putc_flush ( putbuff pb)
static

Definition at line 6619 of file ff.c.

6620{
6621 UINT nw;
6622
6623 if ( pb->idx >= 0 /* Flush buffered characters to the file */
6624 && f_write(pb->fp, pb->buf, (UINT)pb->idx, &nw) == FR_OK
6625 && (UINT)pb->idx == nw) return pb->nchr;
6626 return -1;
6627}

◆ putc_init()

static void putc_init ( putbuff pb,
FIL fp 
)
static

Definition at line 6632 of file ff.c.

6633{
6634 memset(pb, 0, sizeof (putbuff));
6635 pb->fp = fp;
6636}

◆ remove_chain()

static FRESULT remove_chain ( FFOBJID obj,
DWORD  clst,
DWORD  pclst 
)
static

Definition at line 1399 of file ff.c.

1404{
1405 FRESULT res = FR_OK;
1406 DWORD nxt;
1407 FATFS *fs = obj->fs;
1408#if FF_FS_EXFAT || FF_USE_TRIM
1409 DWORD scl = clst, ecl = clst;
1410#endif
1411#if FF_USE_TRIM
1412 LBA_t rt[2];
1413#endif
1414
1415 if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR; /* Check if in valid range */
1416
1417 /* Mark the previous cluster 'EOC' on the FAT if it exists */
1418 if (pclst != 0 && (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT || obj->stat != 2)) {
1419 res = put_fat(fs, pclst, 0xFFFFFFFF);
1420 if (res != FR_OK) return res;
1421 }
1422
1423 /* Remove the chain */
1424 do {
1425 nxt = get_fat(obj, clst); /* Get cluster status */
1426 if (nxt == 0) break; /* Empty cluster? */
1427 if (nxt == 1) return FR_INT_ERR; /* Internal error? */
1428 if (nxt == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error? */
1429 if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) {
1430 res = put_fat(fs, clst, 0); /* Mark the cluster 'free' on the FAT */
1431 if (res != FR_OK) return res;
1432 }
1433 if (fs->free_clst < fs->n_fatent - 2) { /* Update FSINFO */
1434 fs->free_clst++;
1435 fs->fsi_flag |= 1;
1436 }
1437#if FF_FS_EXFAT || FF_USE_TRIM
1438 if (ecl + 1 == nxt) { /* Is next cluster contiguous? */
1439 ecl = nxt;
1440 } else { /* End of contiguous cluster block */
1441#if FF_FS_EXFAT
1442 if (fs->fs_type == FS_EXFAT) {
1443 res = change_bitmap(fs, scl, ecl - scl + 1, 0); /* Mark the cluster block 'free' on the bitmap */
1444 if (res != FR_OK) return res;
1445 }
1446#endif
1447#if FF_USE_TRIM
1448 rt[0] = clst2sect(fs, scl); /* Start of data area to be freed */
1449 rt[1] = clst2sect(fs, ecl) + fs->csize - 1; /* End of data area to be freed */
1450 disk_ioctl(fs->pdrv, CTRL_TRIM, rt); /* Inform storage device that the data in the block may be erased */
1451#endif
1452 scl = ecl = nxt;
1453 }
1454#endif
1455 clst = nxt; /* Next cluster */
1456 } while (clst < fs->n_fatent); /* Repeat while not the last link */
1457
1458#if FF_FS_EXFAT
1459 /* Some post processes for chain status */
1460 if (fs->fs_type == FS_EXFAT) {
1461 if (pclst == 0) { /* Has the entire chain been removed? */
1462 obj->stat = 0; /* Change the chain status 'initial' */
1463 } else {
1464 if (obj->stat == 0) { /* Is it a fragmented chain from the beginning of this session? */
1465 clst = obj->sclust; /* Follow the chain to check if it gets contiguous */
1466 while (clst != pclst) {
1467 nxt = get_fat(obj, clst);
1468 if (nxt < 2) return FR_INT_ERR;
1469 if (nxt == 0xFFFFFFFF) return FR_DISK_ERR;
1470 if (nxt != clst + 1) break; /* Not contiguous? */
1471 clst++;
1472 }
1473 if (clst == pclst) { /* Has the chain got contiguous again? */
1474 obj->stat = 2; /* Change the chain status 'contiguous' */
1475 }
1476 } else {
1477 if (obj->stat == 3 && pclst >= obj->sclust && pclst <= obj->sclust + obj->n_cont) { /* Was the chain fragmented in this session and got contiguous again? */
1478 obj->stat = 2; /* Change the chain status 'contiguous' */
1479 }
1480 }
1481 }
1482 }
1483#endif
1484 return FR_OK;
1485}
#define CTRL_TRIM
Definition diskio.h:50

◆ st_clust()

static void st_clust ( FATFS fs,
BYTE dir,
DWORD  cl 
)
static

Definition at line 1834 of file ff.c.

1839{
1840 st_word(dir + DIR_FstClusLO, (WORD)cl);
1841 if (fs->fs_type == FS_FAT32) {
1842 st_word(dir + DIR_FstClusHI, (WORD)(cl >> 16));
1843 }
1844}

◆ st_dword()

static void st_dword ( BYTE ptr,
DWORD  val 
)
static

Definition at line 658 of file ff.c.

659{
660 *ptr++ = (BYTE)val; val >>= 8;
661 *ptr++ = (BYTE)val; val >>= 8;
662 *ptr++ = (BYTE)val; val >>= 8;
663 *ptr++ = (BYTE)val;
664}

◆ st_word()

static void st_word ( BYTE ptr,
WORD  val 
)
static

Definition at line 652 of file ff.c.

653{
654 *ptr++ = (BYTE)val; val >>= 8;
655 *ptr++ = (BYTE)val;
656}

◆ sum_sfn()

static BYTE sum_sfn ( const BYTE dir)
static

Definition at line 2022 of file ff.c.

2025{
2026 BYTE sum = 0;
2027 UINT n = 11;
2028
2029 do {
2030 sum = (sum >> 1) + (sum << 7) + *dir++;
2031 } while (--n);
2032 return sum;
2033}

◆ sync_fs()

static FRESULT sync_fs ( FATFS fs)
static

Definition at line 1078 of file ff.c.

1081{
1082 FRESULT res;
1083
1084
1085 res = sync_window(fs);
1086 if (res == FR_OK) {
1087 if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) { /* FAT32: Update FSInfo sector if needed */
1088 /* Create FSInfo structure */
1089 memset(fs->win, 0, sizeof fs->win);
1090 st_word(fs->win + BS_55AA, 0xAA55); /* Boot signature */
1091 st_dword(fs->win + FSI_LeadSig, 0x41615252); /* Leading signature */
1092 st_dword(fs->win + FSI_StrucSig, 0x61417272); /* Structure signature */
1093 st_dword(fs->win + FSI_Free_Count, fs->free_clst); /* Number of free clusters */
1094 st_dword(fs->win + FSI_Nxt_Free, fs->last_clst); /* Last allocated culuster */
1095 fs->winsect = fs->volbase + 1; /* Write it into the FSInfo sector (Next to VBR) */
1096 disk_write(fs->pdrv, fs->win, fs->winsect, 1);
1097 fs->fsi_flag = 0;
1098 }
1099 /* Make sure that no pending write process in the lower layer */
1100 if (disk_ioctl(fs->pdrv, CTRL_SYNC, 0) != RES_OK) res = FR_DISK_ERR;
1101 }
1102
1103 return res;
1104}
#define CTRL_SYNC
Definition diskio.h:46

◆ sync_window()

static FRESULT sync_window ( FATFS fs)
static

Definition at line 1025 of file ff.c.

1028{
1029 FRESULT res = FR_OK;
1030
1031
1032 if (fs->wflag) { /* Is the disk access window dirty? */
1033 if (disk_write(fs->pdrv, fs->win, fs->winsect, 1) == RES_OK) { /* Write it back into the volume */
1034 fs->wflag = 0; /* Clear window dirty flag */
1035 if (fs->winsect - fs->fatbase < fs->fsize) { /* Is it in the 1st FAT? */
1036 if (fs->n_fats == 2) disk_write(fs->pdrv, fs->win, fs->winsect + fs->fsize, 1); /* Reflect it to 2nd FAT if needed */
1037 }
1038 } else {
1039 res = FR_DISK_ERR;
1040 }
1041 }
1042 return res;
1043}

◆ tchar2uni()

static DWORD tchar2uni ( const TCHAR **  str)
static

Definition at line 732 of file ff.c.

735{
736 DWORD uc;
737 const TCHAR *p = *str;
738
739#if FF_LFN_UNICODE == 1 /* UTF-16 input */
740 WCHAR wc;
741
742 uc = *p++; /* Get a unit */
743 if (IsSurrogate(uc)) { /* Surrogate? */
744 wc = *p++; /* Get low surrogate */
745 if (!IsSurrogateH(uc) || !IsSurrogateL(wc)) return 0xFFFFFFFF; /* Wrong surrogate? */
746 uc = uc << 16 | wc;
747 }
748
749#elif FF_LFN_UNICODE == 2 /* UTF-8 input */
750 BYTE b;
751 int nf;
752
753 uc = (BYTE)*p++; /* Get an encoding unit */
754 if (uc & 0x80) { /* Multiple byte code? */
755 if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */
756 uc &= 0x1F; nf = 1;
757 } else if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */
758 uc &= 0x0F; nf = 2;
759 } else if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */
760 uc &= 0x07; nf = 3;
761 } else { /* Wrong sequence */
762 return 0xFFFFFFFF;
763 }
764 do { /* Get trailing bytes */
765 b = (BYTE)*p++;
766 if ((b & 0xC0) != 0x80) return 0xFFFFFFFF; /* Wrong sequence? */
767 uc = uc << 6 | (b & 0x3F);
768 } while (--nf != 0);
769 if (uc < 0x80 || IsSurrogate(uc) || uc >= 0x110000) return 0xFFFFFFFF; /* Wrong code? */
770 if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); /* Make a surrogate pair if needed */
771 }
772
773#elif FF_LFN_UNICODE == 3 /* UTF-32 input */
774 uc = (TCHAR)*p++; /* Get a unit */
775 if (uc >= 0x110000 || IsSurrogate(uc)) return 0xFFFFFFFF; /* Wrong code? */
776 if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF); /* Make a surrogate pair if needed */
777
778#else /* ANSI/OEM input */
779 BYTE b;
780 WCHAR wc;
781
782 wc = (BYTE)*p++; /* Get a byte */
783 if (dbc_1st((BYTE)wc)) { /* Is it a DBC 1st byte? */
784 b = (BYTE)*p++; /* Get 2nd byte */
785 if (!dbc_2nd(b)) return 0xFFFFFFFF; /* Invalid code? */
786 wc = (wc << 8) + b; /* Make a DBC */
787 }
788 if (wc != 0) {
789 wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM ==> Unicode */
790 if (wc == 0) return 0xFFFFFFFF; /* Invalid code? */
791 }
792 uc = wc;
793
794#endif
795 *str = p; /* Next read pointer */
796 return uc;
797}

◆ validate()

static FRESULT validate ( FFOBJID obj,
FATFS **  rfs 
)
static

Definition at line 3561 of file ff.c.

3565{
3567
3568
3569 if (obj && obj->fs && obj->fs->fs_type && obj->id == obj->fs->id) { /* Test if the object is valid */
3570#if FF_FS_REENTRANT
3571 if (lock_fs(obj->fs)) { /* Obtain the filesystem object */
3572 if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */
3573 res = FR_OK;
3574 } else {
3575 unlock_fs(obj->fs, FR_OK);
3576 }
3577 } else {
3578 res = FR_TIMEOUT;
3579 }
3580#else
3581 if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */
3582 res = FR_OK;
3583 }
3584#endif
3585 }
3586 *rfs = (res == FR_OK) ? obj->fs : 0; /* Corresponding filesystem object */
3587 return res;
3588}

Variable Documentation

◆ CurrVol

BYTE CurrVol
static

Definition at line 468 of file ff.c.

◆ ExCvt

const BYTE ExCvt[] = MKCVTBL(TBL_CT, FF_CODE_PAGE)
static

Definition at line 592 of file ff.c.

◆ FatFs

FATFS* FatFs[FF_VOLUMES]
static

Definition at line 464 of file ff.c.

◆ Files

FILESEM Files[FF_FS_LOCK]
static

Definition at line 472 of file ff.c.

◆ Fsid

WORD Fsid
static

Definition at line 465 of file ff.c.

◆ LfnOfs

const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}
static

Definition at line 513 of file ff.c.

513{1,3,5,7,9,14,16,18,20,22,24,28,30}; /* FAT: Offset of LFN characters in the directory entry */