Sauvegarde sur carte microSD

Dependents:   microSD_Card

Committer:
adrevong
Date:
Tue Jan 28 11:11:57 2020 +0000
Revision:
0:c9f6f3f0cd78

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adrevong 0:c9f6f3f0cd78 1 /*---------------------------------------------------------------------------/
adrevong 0:c9f6f3f0cd78 2 / FatFs - FAT file system module include R0.11a (C)ChaN, 2015
adrevong 0:c9f6f3f0cd78 3 /----------------------------------------------------------------------------/
adrevong 0:c9f6f3f0cd78 4 / FatFs module is a free software that opened under license policy of
adrevong 0:c9f6f3f0cd78 5 / following conditions.
adrevong 0:c9f6f3f0cd78 6 /
adrevong 0:c9f6f3f0cd78 7 / Copyright (C) 2015, ChaN, all right reserved.
adrevong 0:c9f6f3f0cd78 8 /
adrevong 0:c9f6f3f0cd78 9 / 1. Redistributions of source code must retain the above copyright notice,
adrevong 0:c9f6f3f0cd78 10 / this condition and the following disclaimer.
adrevong 0:c9f6f3f0cd78 11 /
adrevong 0:c9f6f3f0cd78 12 / This software is provided by the copyright holder and contributors "AS IS"
adrevong 0:c9f6f3f0cd78 13 / and any warranties related to this software are DISCLAIMED.
adrevong 0:c9f6f3f0cd78 14 / The copyright owner or contributors be NOT LIABLE for any damages caused
adrevong 0:c9f6f3f0cd78 15 / by use of this software.
adrevong 0:c9f6f3f0cd78 16 /---------------------------------------------------------------------------*/
adrevong 0:c9f6f3f0cd78 17
adrevong 0:c9f6f3f0cd78 18
adrevong 0:c9f6f3f0cd78 19 #ifndef _FATFS
adrevong 0:c9f6f3f0cd78 20 #define _FATFS 64180 /* Revision ID */
adrevong 0:c9f6f3f0cd78 21
adrevong 0:c9f6f3f0cd78 22 #ifdef __cplusplus
adrevong 0:c9f6f3f0cd78 23 extern "C" {
adrevong 0:c9f6f3f0cd78 24 #endif
adrevong 0:c9f6f3f0cd78 25
adrevong 0:c9f6f3f0cd78 26 #include "integer.h" /* Basic integer types */
adrevong 0:c9f6f3f0cd78 27 #include "ffconf.h" /* FatFs configuration options */
adrevong 0:c9f6f3f0cd78 28 #if _FATFS != _FFCONF
adrevong 0:c9f6f3f0cd78 29 #error Wrong configuration file (ffconf.h).
adrevong 0:c9f6f3f0cd78 30 #endif
adrevong 0:c9f6f3f0cd78 31
adrevong 0:c9f6f3f0cd78 32
adrevong 0:c9f6f3f0cd78 33
adrevong 0:c9f6f3f0cd78 34 /* Definitions of volume management */
adrevong 0:c9f6f3f0cd78 35
adrevong 0:c9f6f3f0cd78 36 #if _MULTI_PARTITION /* Multiple partition configuration */
adrevong 0:c9f6f3f0cd78 37 typedef struct {
adrevong 0:c9f6f3f0cd78 38 BYTE pd; /* Physical drive number */
adrevong 0:c9f6f3f0cd78 39 BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
adrevong 0:c9f6f3f0cd78 40 } PARTITION;
adrevong 0:c9f6f3f0cd78 41 extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
adrevong 0:c9f6f3f0cd78 42 #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
adrevong 0:c9f6f3f0cd78 43 #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
adrevong 0:c9f6f3f0cd78 44
adrevong 0:c9f6f3f0cd78 45 #else /* Single partition configuration */
adrevong 0:c9f6f3f0cd78 46 #define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
adrevong 0:c9f6f3f0cd78 47 #define LD2PT(vol) 0 /* Find first valid partition or in SFD */
adrevong 0:c9f6f3f0cd78 48
adrevong 0:c9f6f3f0cd78 49 #endif
adrevong 0:c9f6f3f0cd78 50
adrevong 0:c9f6f3f0cd78 51
adrevong 0:c9f6f3f0cd78 52
adrevong 0:c9f6f3f0cd78 53 /* Type of path name strings on FatFs API */
adrevong 0:c9f6f3f0cd78 54
adrevong 0:c9f6f3f0cd78 55 #if _LFN_UNICODE /* Unicode string */
adrevong 0:c9f6f3f0cd78 56 #if !_USE_LFN
adrevong 0:c9f6f3f0cd78 57 #error _LFN_UNICODE must be 0 at non-LFN cfg.
adrevong 0:c9f6f3f0cd78 58 #endif
adrevong 0:c9f6f3f0cd78 59 #ifndef _INC_TCHAR
adrevong 0:c9f6f3f0cd78 60 typedef WCHAR TCHAR;
adrevong 0:c9f6f3f0cd78 61 #define _T(x) L ## x
adrevong 0:c9f6f3f0cd78 62 #define _TEXT(x) L ## x
adrevong 0:c9f6f3f0cd78 63 #endif
adrevong 0:c9f6f3f0cd78 64
adrevong 0:c9f6f3f0cd78 65 #else /* ANSI/OEM string */
adrevong 0:c9f6f3f0cd78 66 #ifndef _INC_TCHAR
adrevong 0:c9f6f3f0cd78 67 typedef char TCHAR;
adrevong 0:c9f6f3f0cd78 68 #define _T(x) x
adrevong 0:c9f6f3f0cd78 69 #define _TEXT(x) x
adrevong 0:c9f6f3f0cd78 70 #endif
adrevong 0:c9f6f3f0cd78 71
adrevong 0:c9f6f3f0cd78 72 #endif
adrevong 0:c9f6f3f0cd78 73
adrevong 0:c9f6f3f0cd78 74
adrevong 0:c9f6f3f0cd78 75
adrevong 0:c9f6f3f0cd78 76 /* File system object structure (FATFS) */
adrevong 0:c9f6f3f0cd78 77
adrevong 0:c9f6f3f0cd78 78 typedef struct {
adrevong 0:c9f6f3f0cd78 79 BYTE fs_type; /* FAT sub-type (0:Not mounted) */
adrevong 0:c9f6f3f0cd78 80 BYTE drv; /* Physical drive number */
adrevong 0:c9f6f3f0cd78 81 BYTE csize; /* Sectors per cluster (1,2,4...128) */
adrevong 0:c9f6f3f0cd78 82 BYTE n_fats; /* Number of FAT copies (1 or 2) */
adrevong 0:c9f6f3f0cd78 83 BYTE wflag; /* win[] flag (b0:dirty) */
adrevong 0:c9f6f3f0cd78 84 BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
adrevong 0:c9f6f3f0cd78 85 WORD id; /* File system mount ID */
adrevong 0:c9f6f3f0cd78 86 WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
adrevong 0:c9f6f3f0cd78 87 #if _MAX_SS != _MIN_SS
adrevong 0:c9f6f3f0cd78 88 WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
adrevong 0:c9f6f3f0cd78 89 #endif
adrevong 0:c9f6f3f0cd78 90 #if _FS_REENTRANT
adrevong 0:c9f6f3f0cd78 91 _SYNC_t sobj; /* Identifier of sync object */
adrevong 0:c9f6f3f0cd78 92 #endif
adrevong 0:c9f6f3f0cd78 93 #if !_FS_READONLY
adrevong 0:c9f6f3f0cd78 94 DWORD last_clust; /* Last allocated cluster */
adrevong 0:c9f6f3f0cd78 95 DWORD free_clust; /* Number of free clusters */
adrevong 0:c9f6f3f0cd78 96 #endif
adrevong 0:c9f6f3f0cd78 97 #if _FS_RPATH
adrevong 0:c9f6f3f0cd78 98 DWORD cdir; /* Current directory start cluster (0:root) */
adrevong 0:c9f6f3f0cd78 99 #endif
adrevong 0:c9f6f3f0cd78 100 DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */
adrevong 0:c9f6f3f0cd78 101 DWORD fsize; /* Sectors per FAT */
adrevong 0:c9f6f3f0cd78 102 DWORD volbase; /* Volume start sector */
adrevong 0:c9f6f3f0cd78 103 DWORD fatbase; /* FAT start sector */
adrevong 0:c9f6f3f0cd78 104 DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
adrevong 0:c9f6f3f0cd78 105 DWORD database; /* Data start sector */
adrevong 0:c9f6f3f0cd78 106 DWORD winsect; /* Current sector appearing in the win[] */
adrevong 0:c9f6f3f0cd78 107 BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
adrevong 0:c9f6f3f0cd78 108 } FATFS;
adrevong 0:c9f6f3f0cd78 109
adrevong 0:c9f6f3f0cd78 110
adrevong 0:c9f6f3f0cd78 111
adrevong 0:c9f6f3f0cd78 112 /* File object structure (FIL) */
adrevong 0:c9f6f3f0cd78 113
adrevong 0:c9f6f3f0cd78 114 typedef struct {
adrevong 0:c9f6f3f0cd78 115 FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
adrevong 0:c9f6f3f0cd78 116 WORD id; /* Owner file system mount ID (**do not change order**) */
adrevong 0:c9f6f3f0cd78 117 BYTE flag; /* Status flags */
adrevong 0:c9f6f3f0cd78 118 BYTE err; /* Abort flag (error code) */
adrevong 0:c9f6f3f0cd78 119 DWORD fptr; /* File read/write pointer (Zeroed on file open) */
adrevong 0:c9f6f3f0cd78 120 DWORD fsize; /* File size */
adrevong 0:c9f6f3f0cd78 121 DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
adrevong 0:c9f6f3f0cd78 122 DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
adrevong 0:c9f6f3f0cd78 123 DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */
adrevong 0:c9f6f3f0cd78 124 #if !_FS_READONLY
adrevong 0:c9f6f3f0cd78 125 DWORD dir_sect; /* Sector number containing the directory entry */
adrevong 0:c9f6f3f0cd78 126 BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
adrevong 0:c9f6f3f0cd78 127 #endif
adrevong 0:c9f6f3f0cd78 128 #if _USE_FASTSEEK
adrevong 0:c9f6f3f0cd78 129 DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
adrevong 0:c9f6f3f0cd78 130 #endif
adrevong 0:c9f6f3f0cd78 131 #if _FS_LOCK
adrevong 0:c9f6f3f0cd78 132 UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
adrevong 0:c9f6f3f0cd78 133 #endif
adrevong 0:c9f6f3f0cd78 134 #if !_FS_TINY
adrevong 0:c9f6f3f0cd78 135 BYTE buf[_MAX_SS]; /* File private data read/write window */
adrevong 0:c9f6f3f0cd78 136 #endif
adrevong 0:c9f6f3f0cd78 137 } FIL;
adrevong 0:c9f6f3f0cd78 138
adrevong 0:c9f6f3f0cd78 139
adrevong 0:c9f6f3f0cd78 140
adrevong 0:c9f6f3f0cd78 141 /* Directory object structure (FATFS_DIR) */
adrevong 0:c9f6f3f0cd78 142
adrevong 0:c9f6f3f0cd78 143 typedef struct {
adrevong 0:c9f6f3f0cd78 144 FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */
adrevong 0:c9f6f3f0cd78 145 WORD id; /* Owner file system mount ID (**do not change order**) */
adrevong 0:c9f6f3f0cd78 146 WORD index; /* Current read/write index number */
adrevong 0:c9f6f3f0cd78 147 DWORD sclust; /* Table start cluster (0:Root dir) */
adrevong 0:c9f6f3f0cd78 148 DWORD clust; /* Current cluster */
adrevong 0:c9f6f3f0cd78 149 DWORD sect; /* Current sector */
adrevong 0:c9f6f3f0cd78 150 BYTE* dir; /* Pointer to the current SFN entry in the win[] */
adrevong 0:c9f6f3f0cd78 151 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
adrevong 0:c9f6f3f0cd78 152 #if _FS_LOCK
adrevong 0:c9f6f3f0cd78 153 UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
adrevong 0:c9f6f3f0cd78 154 #endif
adrevong 0:c9f6f3f0cd78 155 #if _USE_LFN
adrevong 0:c9f6f3f0cd78 156 WCHAR* lfn; /* Pointer to the LFN working buffer */
adrevong 0:c9f6f3f0cd78 157 WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
adrevong 0:c9f6f3f0cd78 158 #endif
adrevong 0:c9f6f3f0cd78 159 #if _USE_FIND
adrevong 0:c9f6f3f0cd78 160 const TCHAR* pat; /* Pointer to the name matching pattern */
adrevong 0:c9f6f3f0cd78 161 #endif
adrevong 0:c9f6f3f0cd78 162 } FATFS_DIR;
adrevong 0:c9f6f3f0cd78 163
adrevong 0:c9f6f3f0cd78 164
adrevong 0:c9f6f3f0cd78 165
adrevong 0:c9f6f3f0cd78 166 /* File information structure (FILINFO) */
adrevong 0:c9f6f3f0cd78 167
adrevong 0:c9f6f3f0cd78 168 typedef struct {
adrevong 0:c9f6f3f0cd78 169 DWORD fsize; /* File size */
adrevong 0:c9f6f3f0cd78 170 WORD fdate; /* Last modified date */
adrevong 0:c9f6f3f0cd78 171 WORD ftime; /* Last modified time */
adrevong 0:c9f6f3f0cd78 172 BYTE fattrib; /* Attribute */
adrevong 0:c9f6f3f0cd78 173 TCHAR fname[13]; /* Short file name (8.3 format) */
adrevong 0:c9f6f3f0cd78 174 #if _USE_LFN
adrevong 0:c9f6f3f0cd78 175 TCHAR* lfname; /* Pointer to the LFN buffer */
adrevong 0:c9f6f3f0cd78 176 UINT lfsize; /* Size of LFN buffer in TCHAR */
adrevong 0:c9f6f3f0cd78 177 #endif
adrevong 0:c9f6f3f0cd78 178 } FILINFO;
adrevong 0:c9f6f3f0cd78 179
adrevong 0:c9f6f3f0cd78 180
adrevong 0:c9f6f3f0cd78 181
adrevong 0:c9f6f3f0cd78 182 /* File function return code (FRESULT) */
adrevong 0:c9f6f3f0cd78 183
adrevong 0:c9f6f3f0cd78 184 typedef enum {
adrevong 0:c9f6f3f0cd78 185 FR_OK = 0, /* (0) Succeeded */
adrevong 0:c9f6f3f0cd78 186 FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
adrevong 0:c9f6f3f0cd78 187 FR_INT_ERR, /* (2) Assertion failed */
adrevong 0:c9f6f3f0cd78 188 FR_NOT_READY, /* (3) The physical drive cannot work */
adrevong 0:c9f6f3f0cd78 189 FR_NO_FILE, /* (4) Could not find the file */
adrevong 0:c9f6f3f0cd78 190 FR_NO_PATH, /* (5) Could not find the path */
adrevong 0:c9f6f3f0cd78 191 FR_INVALID_NAME, /* (6) The path name format is invalid */
adrevong 0:c9f6f3f0cd78 192 FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
adrevong 0:c9f6f3f0cd78 193 FR_EXIST, /* (8) Access denied due to prohibited access */
adrevong 0:c9f6f3f0cd78 194 FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
adrevong 0:c9f6f3f0cd78 195 FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
adrevong 0:c9f6f3f0cd78 196 FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
adrevong 0:c9f6f3f0cd78 197 FR_NOT_ENABLED, /* (12) The volume has no work area */
adrevong 0:c9f6f3f0cd78 198 FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
adrevong 0:c9f6f3f0cd78 199 FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
adrevong 0:c9f6f3f0cd78 200 FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
adrevong 0:c9f6f3f0cd78 201 FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
adrevong 0:c9f6f3f0cd78 202 FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
adrevong 0:c9f6f3f0cd78 203 FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */
adrevong 0:c9f6f3f0cd78 204 FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
adrevong 0:c9f6f3f0cd78 205 } FRESULT;
adrevong 0:c9f6f3f0cd78 206
adrevong 0:c9f6f3f0cd78 207
adrevong 0:c9f6f3f0cd78 208
adrevong 0:c9f6f3f0cd78 209 /*--------------------------------------------------------------*/
adrevong 0:c9f6f3f0cd78 210 /* FatFs module application interface */
adrevong 0:c9f6f3f0cd78 211
adrevong 0:c9f6f3f0cd78 212 FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
adrevong 0:c9f6f3f0cd78 213 FRESULT f_close (FIL* fp); /* Close an open file object */
adrevong 0:c9f6f3f0cd78 214 FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
adrevong 0:c9f6f3f0cd78 215 FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
adrevong 0:c9f6f3f0cd78 216 FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
adrevong 0:c9f6f3f0cd78 217 FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
adrevong 0:c9f6f3f0cd78 218 FRESULT f_truncate (FIL* fp); /* Truncate file */
adrevong 0:c9f6f3f0cd78 219 FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
adrevong 0:c9f6f3f0cd78 220 FRESULT f_opendir (FATFS_DIR* dp, const TCHAR* path); /* Open a directory */
adrevong 0:c9f6f3f0cd78 221 FRESULT f_closedir (FATFS_DIR* dp); /* Close an open directory */
adrevong 0:c9f6f3f0cd78 222 FRESULT f_readdir (FATFS_DIR* dp, FILINFO* fno); /* Read a directory item */
adrevong 0:c9f6f3f0cd78 223 FRESULT f_findfirst (FATFS_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
adrevong 0:c9f6f3f0cd78 224 FRESULT f_findnext (FATFS_DIR* dp, FILINFO* fno); /* Find next file */
adrevong 0:c9f6f3f0cd78 225 FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
adrevong 0:c9f6f3f0cd78 226 FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
adrevong 0:c9f6f3f0cd78 227 FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
adrevong 0:c9f6f3f0cd78 228 FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
adrevong 0:c9f6f3f0cd78 229 FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */
adrevong 0:c9f6f3f0cd78 230 FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
adrevong 0:c9f6f3f0cd78 231 FRESULT f_chdir (const TCHAR* path); /* Change current directory */
adrevong 0:c9f6f3f0cd78 232 FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
adrevong 0:c9f6f3f0cd78 233 FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
adrevong 0:c9f6f3f0cd78 234 FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
adrevong 0:c9f6f3f0cd78 235 FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
adrevong 0:c9f6f3f0cd78 236 FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
adrevong 0:c9f6f3f0cd78 237 FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
adrevong 0:c9f6f3f0cd78 238 FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
adrevong 0:c9f6f3f0cd78 239 FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
adrevong 0:c9f6f3f0cd78 240 int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
adrevong 0:c9f6f3f0cd78 241 int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
adrevong 0:c9f6f3f0cd78 242 int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
adrevong 0:c9f6f3f0cd78 243 TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
adrevong 0:c9f6f3f0cd78 244
adrevong 0:c9f6f3f0cd78 245 #define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
adrevong 0:c9f6f3f0cd78 246 #define f_error(fp) ((fp)->err)
adrevong 0:c9f6f3f0cd78 247 #define f_tell(fp) ((fp)->fptr)
adrevong 0:c9f6f3f0cd78 248 #define f_size(fp) ((fp)->fsize)
adrevong 0:c9f6f3f0cd78 249 #define f_rewind(fp) f_lseek((fp), 0)
adrevong 0:c9f6f3f0cd78 250 #define f_rewinddir(dp) f_readdir((dp), 0)
adrevong 0:c9f6f3f0cd78 251
adrevong 0:c9f6f3f0cd78 252 #ifndef EOF
adrevong 0:c9f6f3f0cd78 253 #define EOF (-1)
adrevong 0:c9f6f3f0cd78 254 #endif
adrevong 0:c9f6f3f0cd78 255
adrevong 0:c9f6f3f0cd78 256
adrevong 0:c9f6f3f0cd78 257
adrevong 0:c9f6f3f0cd78 258
adrevong 0:c9f6f3f0cd78 259 /*--------------------------------------------------------------*/
adrevong 0:c9f6f3f0cd78 260 /* Additional user defined functions */
adrevong 0:c9f6f3f0cd78 261
adrevong 0:c9f6f3f0cd78 262 /* RTC function */
adrevong 0:c9f6f3f0cd78 263 #if !_FS_READONLY && !_FS_NORTC
adrevong 0:c9f6f3f0cd78 264 DWORD get_fattime (void);
adrevong 0:c9f6f3f0cd78 265 #endif
adrevong 0:c9f6f3f0cd78 266
adrevong 0:c9f6f3f0cd78 267 /* Unicode support functions */
adrevong 0:c9f6f3f0cd78 268 #if _USE_LFN /* Unicode - OEM code conversion */
adrevong 0:c9f6f3f0cd78 269 WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
adrevong 0:c9f6f3f0cd78 270 WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
adrevong 0:c9f6f3f0cd78 271 #if _USE_LFN == 3 /* Memory functions */
adrevong 0:c9f6f3f0cd78 272 void* ff_memalloc (UINT msize); /* Allocate memory block */
adrevong 0:c9f6f3f0cd78 273 void ff_memfree (void* mblock); /* Free memory block */
adrevong 0:c9f6f3f0cd78 274 #endif
adrevong 0:c9f6f3f0cd78 275 #endif
adrevong 0:c9f6f3f0cd78 276
adrevong 0:c9f6f3f0cd78 277 /* Sync functions */
adrevong 0:c9f6f3f0cd78 278 #if _FS_REENTRANT
adrevong 0:c9f6f3f0cd78 279 int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */
adrevong 0:c9f6f3f0cd78 280 int ff_req_grant (_SYNC_t sobj); /* Lock sync object */
adrevong 0:c9f6f3f0cd78 281 void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */
adrevong 0:c9f6f3f0cd78 282 int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
adrevong 0:c9f6f3f0cd78 283 #endif
adrevong 0:c9f6f3f0cd78 284
adrevong 0:c9f6f3f0cd78 285
adrevong 0:c9f6f3f0cd78 286
adrevong 0:c9f6f3f0cd78 287
adrevong 0:c9f6f3f0cd78 288 /*--------------------------------------------------------------*/
adrevong 0:c9f6f3f0cd78 289 /* Flags and offset address */
adrevong 0:c9f6f3f0cd78 290
adrevong 0:c9f6f3f0cd78 291
adrevong 0:c9f6f3f0cd78 292 /* File access control and file status flags (FIL.flag) */
adrevong 0:c9f6f3f0cd78 293
adrevong 0:c9f6f3f0cd78 294 #define FA_READ 0x01
adrevong 0:c9f6f3f0cd78 295 #define FA_OPEN_EXISTING 0x00
adrevong 0:c9f6f3f0cd78 296
adrevong 0:c9f6f3f0cd78 297 #if !_FS_READONLY
adrevong 0:c9f6f3f0cd78 298 #define FA_WRITE 0x02
adrevong 0:c9f6f3f0cd78 299 #define FA_CREATE_NEW 0x04
adrevong 0:c9f6f3f0cd78 300 #define FA_CREATE_ALWAYS 0x08
adrevong 0:c9f6f3f0cd78 301 #define FA_OPEN_ALWAYS 0x10
adrevong 0:c9f6f3f0cd78 302 #define FA__WRITTEN 0x20
adrevong 0:c9f6f3f0cd78 303 #define FA__DIRTY 0x40
adrevong 0:c9f6f3f0cd78 304 #endif
adrevong 0:c9f6f3f0cd78 305
adrevong 0:c9f6f3f0cd78 306
adrevong 0:c9f6f3f0cd78 307 /* FAT sub type (FATFS.fs_type) */
adrevong 0:c9f6f3f0cd78 308
adrevong 0:c9f6f3f0cd78 309 #define FS_FAT12 1
adrevong 0:c9f6f3f0cd78 310 #define FS_FAT16 2
adrevong 0:c9f6f3f0cd78 311 #define FS_FAT32 3
adrevong 0:c9f6f3f0cd78 312
adrevong 0:c9f6f3f0cd78 313
adrevong 0:c9f6f3f0cd78 314 /* File attribute bits for directory entry */
adrevong 0:c9f6f3f0cd78 315
adrevong 0:c9f6f3f0cd78 316 #define AM_RDO 0x01 /* Read only */
adrevong 0:c9f6f3f0cd78 317 #define AM_HID 0x02 /* Hidden */
adrevong 0:c9f6f3f0cd78 318 #define AM_SYS 0x04 /* System */
adrevong 0:c9f6f3f0cd78 319 #define AM_VOL 0x08 /* Volume label */
adrevong 0:c9f6f3f0cd78 320 #define AM_LFN 0x0F /* LFN entry */
adrevong 0:c9f6f3f0cd78 321 #define AM_DIR 0x10 /* Directory */
adrevong 0:c9f6f3f0cd78 322 #define AM_ARC 0x20 /* Archive */
adrevong 0:c9f6f3f0cd78 323 #define AM_MASK 0x3F /* Mask of defined bits */
adrevong 0:c9f6f3f0cd78 324
adrevong 0:c9f6f3f0cd78 325
adrevong 0:c9f6f3f0cd78 326 /* Fast seek feature */
adrevong 0:c9f6f3f0cd78 327 #define CREATE_LINKMAP 0xFFFFFFFF
adrevong 0:c9f6f3f0cd78 328
adrevong 0:c9f6f3f0cd78 329
adrevong 0:c9f6f3f0cd78 330
adrevong 0:c9f6f3f0cd78 331 /*--------------------------------*/
adrevong 0:c9f6f3f0cd78 332 /* Multi-byte word access macros */
adrevong 0:c9f6f3f0cd78 333
adrevong 0:c9f6f3f0cd78 334 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
adrevong 0:c9f6f3f0cd78 335 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
adrevong 0:c9f6f3f0cd78 336 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
adrevong 0:c9f6f3f0cd78 337 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
adrevong 0:c9f6f3f0cd78 338 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
adrevong 0:c9f6f3f0cd78 339 #else /* Use byte-by-byte access to the FAT structure */
adrevong 0:c9f6f3f0cd78 340 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
adrevong 0:c9f6f3f0cd78 341 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
adrevong 0:c9f6f3f0cd78 342 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
adrevong 0:c9f6f3f0cd78 343 #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
adrevong 0:c9f6f3f0cd78 344 #endif
adrevong 0:c9f6f3f0cd78 345
adrevong 0:c9f6f3f0cd78 346 #ifdef __cplusplus
adrevong 0:c9f6f3f0cd78 347 }
adrevong 0:c9f6f3f0cd78 348 #endif
adrevong 0:c9f6f3f0cd78 349
adrevong 0:c9f6f3f0cd78 350 #endif /* _FATFS */