mikroSDK Reference Manual
ff_types.h
1/*----------------------------------------------------------------------------/
2/ FatFs - Generic FAT Filesystem module R0.15 /
3/-----------------------------------------------------------------------------/
4/
5/ Copyright (C) 2022, ChaN, all right reserved.
6/
7/ FatFs module is an open source software. Redistribution and use of FatFs in
8/ source and binary forms, with or without modification, are permitted provided
9/ that the following condition is met:
10
11/ 1. Redistributions of source code must retain the above copyright notice,
12/ this condition and the following disclaimer.
13/
14/ This software is provided by the copyright holder and contributors "AS IS"
15/ and any warranties related to this software are DISCLAIMED.
16/ The copyright owner or contributors be NOT LIABLE for any damages caused
17/ by use of this software.
18/
19/----------------------------------------------------------------------------*/
20
21
22#ifndef FF_TYPES_DEFINED
23#define FF_TYPES_DEFINED
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#include "ffconf.h" /* FatFs configuration options */
30
31// #if FF_TYPES_DEFINED != FFCONF_DEF
32// #error Wrong configuration file (ffconf.h).
33// #endif
34
35
36/* Integer types used for FatFs API */
37
38#define FF_INTDEF 2
39#include <stdint.h>
40typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
41typedef unsigned char BYTE; /* char must be 8-bit */
42typedef uint16_t WORD; /* 16-bit unsigned integer */
43typedef uint32_t DWORD; /* 32-bit unsigned integer */
44// typedef uint64_t QWORD; /* 64-bit unsigned integer */
45typedef WORD WCHAR; /* UTF-16 character type */
46
47
48/* Type of file size and LBA variables */
49
50#if FF_FS_EXFAT
51#if FF_INTDEF != 2
52#error exFAT feature wants C99 or later
53#endif
54typedef QWORD FSIZE_t;
55#if FF_LBA64
56typedef QWORD LBA_t;
57#else
58typedef DWORD LBA_t;
59#endif
60#else
61#if FF_LBA64
62#error exFAT needs to be enabled when enable 64-bit LBA
63#endif
64typedef DWORD FSIZE_t;
65typedef DWORD LBA_t;
66#endif
67
68
69
70/* Type of path name strings on FatFs API (TCHAR) */
71
72#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
73typedef WCHAR TCHAR;
74#define _T(x) L ## x
75#define _TEXT(x) L ## x
76#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
77typedef char TCHAR;
78#define _T(x) u8 ## x
79#define _TEXT(x) u8 ## x
80#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
81typedef DWORD TCHAR;
82#define _T(x) U ## x
83#define _TEXT(x) U ## x
84#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
85#error Wrong FF_LFN_UNICODE setting
86#else /* ANSI/OEM code in SBCS/DBCS */
87typedef char TCHAR;
88#define _T(x) x
89#define _TEXT(x) x
90#endif
91
92
93
94/* Definitions of volume management */
95
96#if FF_MULTI_PARTITION /* Multiple partition configuration */
97typedef struct {
98 BYTE pd; /* Physical drive number */
99 BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
100} PARTITION;
101extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
102#endif
103
104#if FF_STR_VOLUME_ID
105#ifndef FF_VOLUME_STRS
106extern const char* __generic_ptr VolumeStr[FF_VOLUMES]; /* User defied volume ID */
107#endif
108#endif
109
110
111
112/* Filesystem object structure (FATFS) */
113
114typedef struct {
115 BYTE fs_type; /* Filesystem type (0:not mounted) */
116 BYTE pdrv; /* Volume hosting physical drive */
117 BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */
118 BYTE n_fats; /* Number of FATs (1 or 2) */
119 BYTE wflag; /* win[] status (b0:dirty) */
120 BYTE fsi_flag; /* FSINFO status (b7:disabled, b0:dirty) */
121 WORD id; /* Volume mount ID */
122 WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
123 WORD csize; /* Cluster size [sectors] */
124#if FF_MAX_SS != FF_MIN_SS
125 WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
126#endif
127#if FF_USE_LFN
128 WCHAR* lfnbuf; /* LFN working buffer */
129#endif
130#if FF_FS_EXFAT
131 BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
132#endif
133#if !FF_FS_READONLY
134 DWORD last_clst; /* Last allocated cluster */
135 DWORD free_clst; /* Number of free clusters */
136#endif
137#if FF_FS_RPATH
138 DWORD cdir; /* Current directory start cluster (0:root) */
139#if FF_FS_EXFAT
140 DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
141 DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
142 DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
143#endif
144#endif
145 DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
146 DWORD fsize; /* Number of sectors per FAT */
147 LBA_t volbase; /* Volume base sector */
148 LBA_t fatbase; /* FAT base sector */
149 LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */
150 LBA_t database; /* Data base sector */
151#if FF_FS_EXFAT
152 LBA_t bitbase; /* Allocation bitmap base sector */
153#endif
154 LBA_t winsect; /* Current sector appearing in the win[] */
155 BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
156} FATFS;
157
158
159
160/* Object ID and allocation information (FFOBJID) */
161
162typedef struct {
163 FATFS* fs; /* Pointer to the hosting volume of this object */
164 WORD id; /* Hosting volume's mount ID */
165 BYTE attr; /* Object attribute */
166 BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
167 DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
168 FSIZE_t objsize; /* Object size (valid when sclust != 0) */
169#if FF_FS_EXFAT
170 DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
171 DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
172 DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
173 DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
174 DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
175#endif
176#if FF_FS_LOCK
177 UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
178#endif
179} FFOBJID;
180
181
182
183/* File object structure (FIL) */
184
185typedef struct {
186 FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
187 BYTE flag; /* File status flags */
188 BYTE err; /* Abort flag (error code) */
189 FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
190 DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
191 LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
192#if !FF_FS_READONLY
193 LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
194 BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
195#endif
196#if FF_USE_FASTSEEK
197 DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
198#endif
199#if !FF_FS_TINY
200 BYTE buf[FF_MAX_SS]; /* File private data read/write window */
201#endif
202} FIL;
203
204
205
206/* Directory object structure (DIR) */
207
208typedef struct {
209 FFOBJID obj; /* Object identifier */
210 DWORD dptr; /* Current read/write offset */
211 DWORD clust; /* Current cluster */
212 LBA_t sect; /* Current sector (0:Read operation has terminated) */
213 BYTE* dir; /* Pointer to the directory item in the win[] */
214 BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
215#if FF_USE_LFN
216 DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
217#endif
218#if FF_USE_FIND
219 const TCHAR* __generic_ptr pat; /* Pointer to the name matching pattern */
220#endif
221} DIR;
222
223
224
225/* File information structure (FILINFO) */
226
227typedef struct {
228 FSIZE_t fsize; /* File size */
229 WORD fdate; /* Modified date */
230 WORD ftime; /* Modified time */
231 BYTE fattrib; /* File attribute */
232#if FF_USE_LFN
233 TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */
234 TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
235#else
236 TCHAR fname[12 + 1]; /* File name */
237#endif
238} FILINFO;
239
240
241
242/* Format parameter structure (MKFS_PARM) */
243
244typedef struct {
245 BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
246 BYTE n_fat; /* Number of FATs */
247 UINT align; /* Data area alignment (sector) */
248 UINT n_root; /* Number of root directory entries */
249 DWORD au_size; /* Cluster size (byte) */
250} MKFS_PARM;
251
252
253
254/* File function return code (FRESULT) */
255
256typedef enum {
257 FR_OK = 0, /* (0) Succeeded */
258 FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
259 FR_INT_ERR, /* (2) Assertion failed */
260 FR_NOT_READY, /* (3) The physical drive cannot work */
261 FR_NO_FILE, /* (4) Could not find the file */
262 FR_NO_PATH, /* (5) Could not find the path */
263 FR_INVALID_NAME, /* (6) The path name format is invalid */
264 FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
265 FR_EXIST, /* (8) Access denied due to prohibited access */
266 FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
267 FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
268 FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
269 FR_NOT_ENABLED, /* (12) The volume has no work area */
270 FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
271 FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
272 FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
273 FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
274 FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
275 FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
276 FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
277} FRESULT;
278
279
280
281
282/*--------------------------------------------------------------*/
283/* FatFs Module Application Interface */
284/*--------------------------------------------------------------*/
285
286
287
288/*--------------------------------------------------------------*/
289/* Additional Functions */
290/*--------------------------------------------------------------*/
291
292/* RTC function (provided by user) */
293#if !FF_FS_READONLY && !FF_FS_NORTC
294DWORD get_fattime (void); /* Get current time */
295#endif
296
297
298/* LFN support functions (defined in ffunicode.c) */
299
300#if FF_USE_LFN >= 1
301WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
302WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
303DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
304#endif
305
306
307/* O/S dependent functions (samples available in ffsystem.c) */
308
309#if FF_USE_LFN == 3 /* Dynamic memory allocation */
310void* ff_memalloc (UINT msize); /* Allocate memory block */
311void ff_memfree (void* mblock); /* Free memory block */
312#endif
313#if FF_FS_REENTRANT /* Sync functions */
314int ff_mutex_create (int vol); /* Create a sync object */
315void ff_mutex_delete (int vol); /* Delete a sync object */
316int ff_mutex_take (int vol); /* Lock sync object */
317void ff_mutex_give (int vol); /* Unlock sync object */
318#endif
319
320
321
322
323/*--------------------------------------------------------------*/
324/* Flags and Offset Address */
325/*--------------------------------------------------------------*/
326
327/* File access mode and open method flags (3rd argument of f_open) */
328#define FA_READ 0x01
329#define FA_WRITE 0x02
330#define FA_OPEN_EXISTING 0x00
331#define FA_CREATE_NEW 0x04
332#define FA_CREATE_ALWAYS 0x08
333#define FA_OPEN_ALWAYS 0x10
334#define FA_OPEN_APPEND 0x30
335
336/* Fast seek controls (2nd argument of f_lseek) */
337#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
338
339/* Format options (2nd argument of f_mkfs) */
340#define FM_FAT 0x01
341#define FM_FAT32 0x02
342#define FM_EXFAT 0x04
343#define FM_ANY 0x07
344#define FM_SFD 0x08
345
346/* Filesystem type (FATFS.fs_type) */
347#define FS_FAT12 1
348#define FS_FAT16 2
349#define FS_FAT32 3
350#define FS_EXFAT 4
351
352/* File attribute bits for directory entry (FILINFO.fattrib) */
353#define AM_RDO 0x01 /* Read only */
354#define AM_HID 0x02 /* Hidden */
355#define AM_SYS 0x04 /* System */
356#define AM_DIR 0x10 /* Directory */
357#define AM_ARC 0x20 /* Archive */
358
359
360#ifdef __cplusplus
361}
362#endif
363
364#endif /* FF_TYPES_DEFINED */
Definition ff_types.h:208
Definition ff_types.h:114
Definition ff_types.h:162
Definition ff_types.h:227
Definition ff_types.h:185
Definition ff_types.h:244