CARME-M4 BSP  V1.5
ff.c File Reference
#include "ff.h"
#include "diskio.h"
+ Include dependency graph for ff.c:

Go to the source code of this file.

Macros

#define SS(fs)   ((fs)->ssize)
 
#define ENTER_FF(fs)
 Enter in a thread-safe state.
 
#define LEAVE_FF(fs, res)   return res
 Exit from a thread-safe state.
 
#define ABORT(fs, res)   { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
 Abort.
 
#define IsUpper(c)   (((c)>='A')&&((c)<='Z'))
 
#define IsLower(c)   (((c)>='a')&&((c)<='z'))
 
#define IsDigit(c)   (((c)>='0')&&((c)<='9'))
 
#define IsDBCS1(c)   0
 
#define IsDBCS2(c)   0
 
#define NS   11
 
#define NS_LOSS   0x01
 
#define NS_LFN   0x02
 
#define NS_LAST   0x04
 
#define NS_BODY   0x08
 
#define NS_EXT   0x10
 
#define NS_DOT   0x20
 
#define MIN_FAT16   4086U
 
#define MIN_FAT32   65526U
 
#define BS_jmpBoot   0
 
#define BS_OEMName   3
 
#define BPB_BytsPerSec   11
 
#define BPB_SecPerClus   13
 
#define BPB_RsvdSecCnt   14
 
#define BPB_NumFATs   16
 
#define BPB_RootEntCnt   17
 
#define BPB_TotSec16   19
 
#define BPB_Media   21
 
#define BPB_FATSz16   22
 
#define BPB_SecPerTrk   24
 
#define BPB_NumHeads   26
 
#define BPB_HiddSec   28
 
#define BPB_TotSec32   32
 
#define BS_DrvNum   36
 
#define BS_BootSig   38
 
#define BS_VolID   39
 
#define BS_VolLab   43
 
#define BS_FilSysType   54
 
#define BPB_FATSz32   36
 
#define BPB_ExtFlags   40
 
#define BPB_FSVer   42
 
#define BPB_RootClus   44
 
#define BPB_FSInfo   48
 
#define BPB_BkBootSec   50
 
#define BS_DrvNum32   64
 
#define BS_BootSig32   66
 
#define BS_VolID32   67
 
#define BS_VolLab32   71
 
#define BS_FilSysType32   82
 
#define FSI_LeadSig   0
 
#define FSI_StrucSig   484
 
#define FSI_Free_Count   488
 
#define FSI_Nxt_Free   492
 
#define MBR_Table   446
 
#define SZ_PTE   16
 
#define BS_55AA   510
 
#define DIR_Name   0
 
#define DIR_Attr   11
 
#define DIR_NTres   12
 
#define DIR_CrtTimeTenth   13
 
#define DIR_CrtTime   14
 
#define DIR_CrtDate   16
 
#define DIR_LstAccDate   18
 
#define DIR_FstClusHI   20
 
#define DIR_WrtTime   22
 
#define DIR_WrtDate   24
 
#define DIR_FstClusLO   26
 
#define DIR_FileSize   28
 
#define LDIR_Ord   0
 
#define LDIR_Attr   11
 
#define LDIR_Type   12
 
#define LDIR_Chksum   13
 
#define LDIR_FstClusLO   26
 
#define SZ_DIR   32
 
#define LLE   0x40
 
#define DDE   0xE5
 
#define NDDE   0x05
 
#define DEF_NAMEBUF   BYTE sfn[12]
 
#define INIT_BUF(dobj)   (dobj).fn = sfn
 
#define FREE_BUF()
 

Functions

static void mem_cpy (void *dst, const void *src, UINT cnt)
 Copy memory to memory. More...
 
static void mem_set (void *dst, int val, UINT cnt)
 Fill memory. More...
 
static int mem_cmp (const void *dst, const void *src, UINT cnt)
 Compare memory to memory. More...
 
static int chk_chr (const char *str, int chr)
 Check if chr is contained in the string. More...
 
static FRESULT sync_window (FATFS *fs)
 Sync window. More...
 
static FRESULT move_window (FATFS *fs, DWORD sector)
 Move window. More...
 
static FRESULT sync_fs (FATFS *fs)
 Synchronize file system and storage device. More...
 
DWORD clust2sect (FATFS *fs, DWORD clst)
 Synchronize file system and storage device. More...
 
DWORD get_fat (FATFS *fs, DWORD clst)
 Read value of a FAT entry. More...
 
FRESULT put_fat (FATFS *fs, DWORD clst, DWORD val)
 Change value of a FAT entry. More...
 
static FRESULT remove_chain (FATFS *fs, DWORD clst)
 Remove a cluster chain. More...
 
static DWORD create_chain (FATFS *fs, DWORD clst)
 Stretch or Create a cluster chain. More...
 
static FRESULT dir_sdi (DIR *dp, WORD idx)
 Set directory index. More...
 
static FRESULT dir_next (DIR *dp, int stretch)
 Move directory table index next. More...
 
static FRESULT dir_alloc (DIR *dp, UINT nent)
 Reserve directory entry. More...
 
static DWORD ld_clust (FATFS *fs, BYTE *dir)
 Load/Store start cluster number. More...
 
static void st_clust (BYTE *dir, DWORD cl)
 
static FRESULT dir_find (DIR *dp)
 Find an object in the directory. More...
 
static FRESULT dir_read (DIR *dp, int vol)
 Read an object from the directory. More...
 
static FRESULT dir_register (DIR *dp)
 Register an object to the directory. More...
 
static FRESULT dir_remove (DIR *dp)
 Remove an object from the directory. More...
 
static FRESULT create_name (DIR *dp, const TCHAR **path)
 Pick a segment and create the object name in directory form. More...
 
static void get_fileinfo (DIR *dp, FILINFO *fno)
 Get file information from directory entry. More...
 
static int get_ldnumber (const TCHAR **path)
 Get logical drive number from path name. More...
 
static FRESULT follow_path (DIR *dp, const TCHAR *path)
 Follow a file path. More...
 
static BYTE check_fs (FATFS *fs, DWORD sect)
 Load a sector and check if it is an FAT boot sector. More...
 
static FRESULT find_volume (FATFS **rfs, const TCHAR **path, BYTE wmode)
 Find logical drive and check if the volume is mounted. More...
 
static FRESULT validate (void *obj)
 Check if the file/directory object is valid or not. More...
 
FRESULT f_mount (FATFS *fs, const TCHAR *path, BYTE opt)
 Mount/Unmount a Logical Drive. More...
 
FRESULT f_open (FIL *fp, const TCHAR *path, BYTE mode)
 Open or Create a File. More...
 
FRESULT f_read (FIL *fp, void *buff, UINT btr, UINT *br)
 Read File. More...
 
FRESULT f_write (FIL *fp, const void *buff, UINT btw, UINT *bw)
 Write File. More...
 
FRESULT f_sync (FIL *fp)
 Synchronize the File. More...
 
FRESULT f_close (FIL *fp)
 Close File. More...
 
FRESULT f_lseek (FIL *fp, DWORD ofs)
 Seek File R/W Pointer. More...
 
FRESULT f_opendir (DIR *dp, const TCHAR *path)
 Create a Directory Object. More...
 
FRESULT f_closedir (DIR *dp)
 Close Directory. More...
 
FRESULT f_readdir (DIR *dp, FILINFO *fno)
 Read Directory Entries in Sequence. More...
 
FRESULT f_stat (const TCHAR *path, FILINFO *fno)
 Get File Status. More...
 
FRESULT f_getfree (const TCHAR *path, DWORD *nclst, FATFS **fatfs)
 Get Number of Free Clusters. More...
 
FRESULT f_truncate (FIL *fp)
 Truncate File. More...
 
FRESULT f_unlink (const TCHAR *path)
 Delete a File or Directory. More...
 
FRESULT f_mkdir (const TCHAR *path)
 Create a Directory. More...
 
FRESULT f_chmod (const TCHAR *path, BYTE value, BYTE mask)
 Change Attribute. More...
 
FRESULT f_utime (const TCHAR *path, const FILINFO *fno)
 Change Timestamp. More...
 
FRESULT f_rename (const TCHAR *path_old, const TCHAR *path_new)
 Rename File/Directory. More...
 

Variables

static WORD Fsid
 

Detailed Description

Version
R0.10
Date
2013-10-02
Author
ChaN

Feb 26,'06 R0.00 Prototype.

Apr 29,'06 R0.01 First stable version.

Jun 01,'06 R0.02 Added FAT12 support. Removed unbuffered mode. Fixed a problem on small (<32M) partition. Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM).

Sep 22,'06 R0.03 Added f_rename(). Changed option _FS_MINIMUM to _FS_MINIMIZE. Dec 11,'06 R0.03a Improved cluster scan algorithm to write files fast. Fixed f_mkdir() creates incorrect directory on FAT32.

Feb 04,'07 R0.04 Supported multiple drive system. Changed some interfaces for multiple drive system. Changed f_mountdrv() to f_mount(). Added f_mkfs(). Apr 01,'07 R0.04a Supported multiple partitions on a physical drive. Added a capability of extending file size to f_lseek(). Added minimization level 3. Fixed an endian sensitive code in f_mkfs(). May 05,'07 R0.04b Added a configuration option _USE_NTFLAG. Added FSINFO support. Fixed DBCS name can result FR_INVALID_NAME. Fixed short seek (<= csize) collapses the file object.

Aug 25,'07 R0.05 Changed arguments of f_read(), f_write() and f_mkfs(). Fixed f_mkfs() on FAT32 creates incorrect FSINFO. Fixed f_mkdir() on FAT32 creates incorrect directory. Feb 03,'08 R0.05a Added f_truncate() and f_utime(). Fixed off by one error at FAT sub-type determination. Fixed btr in f_read() can be mistruncated. Fixed cached sector is not flushed when create and close without write.

Apr 01,'08 R0.06 Added fputc(), fputs(), fprintf() and fgets(). Improved performance of f_lseek() on moving to the same or following cluster.

Apr 01,'09 R0.07 Merged Tiny-FatFs as a configuration option. (_FS_TINY) Added long file name feature. Added multiple code page feature. Added re-entrancy for multitask operation. Added auto cluster size selection to f_mkfs(). Added rewind option to f_readdir(). Changed result code of critical errors. Renamed string functions to avoid name collision. Apr 14,'09 R0.07a Separated out OS dependent code on reentrant cfg. Added multiple sector size feature. Jun 21,'09 R0.07c Fixed f_unlink() can return FR_OK on error. Fixed wrong cache control in f_lseek(). Added relative path feature. Added f_chdir() and f_chdrive(). Added proper case conversion to extended character. Nov 03,'09 R0.07e Separated out configuration options from ff.h to ffconf.h. Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH. Fixed name matching error on the 13 character boundary. Added a configuration option, _LFN_UNICODE. Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.

May 15,'10 R0.08 Added a memory configuration option. (_USE_LFN = 3) Added file lock feature. (_FS_SHARE) Added fast seek feature. (_USE_FASTSEEK) Changed some types on the API, XCHAR->TCHAR. Changed .fname in the FILINFO structure on Unicode cfg. String functions support UTF-8 encoding files on Unicode cfg. Aug 16,'10 R0.08a Added f_getcwd(). Added sector erase feature. (_USE_ERASE) Moved file lock semaphore table from fs object to the bss. Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'. Fixed f_mkfs() creates wrong FAT32 volume. Jan 15,'11 R0.08b Fast seek feature is also applied to f_read() and f_write(). f_lseek() reports required table size on creating CLMP. Extended format syntax of f_printf(). Ignores duplicated directory separators in given path name.

Sep 06,'11 R0.09 f_mkfs() supports multiple partition to complete the multiple partition feature. Added f_fdisk(). Aug 27,'12 R0.09a Changed f_open() and f_opendir() reject null object pointer to avoid crash. Changed option name _FS_SHARE to _FS_LOCK. Fixed assertion failure due to OS/2 EA on FAT12/16 volume. Jan 24,'13 R0.09b Added f_setlabel() and f_getlabel().

Oct 02,'13 R0.10 Added selection of character encoding on the file. (_STRF_ENCODE) Added f_closedir(). Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO) Added forced mount feature with changes of f_mount(). Improved behavior of volume auto detection. Improved write throughput of f_puts() and f_printf(). Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write(). Fixed f_write() can be truncated when the file size is close to 4GB. Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.

Copyright © 2013, ChaN, all right reserved.

FatFs module is a generic FAT file system module for small embedded systems. This is a free software that opened for education, research and commercial developments under license policy of following terms.

  • The FatFs module is a free software and there is NO WARRANTY.
  • No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
  • Redistributions of source code must retain the above copyright notice.

Definition in file ff.c.