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