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