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