sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
ff.h
Go to the documentation of this file.
1
/*----------------------------------------------------------------------------/
2
/ FatFs - Generic FAT Filesystem module R0.16 /
3
/-----------------------------------------------------------------------------/
4
/
5
/ Copyright (C) 2025, 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
26
#ifndef FF_DEFINED
27
#define FF_DEFINED 80386
/* Revision ID */
28
29
#ifdef __cplusplus
30
extern
"C"
{
31
#endif
32
33
#if !defined(FFCONF_DEF)
34
#include "
ffconf.h
"
/* FatFs configuration options */
35
#endif
36
#if FF_DEFINED != FFCONF_DEF
37
#error Wrong configuration file (ffconf.h).
38
#endif
39
40
41
/* Integer types used for FatFs API */
42
43
#if defined(_WIN32)
/* Windows VC++ (for development only) */
44
#define FF_INTDEF 2
45
#include <windows.h>
46
typedef
unsigned
__int64
QWORD
;
47
#include <float.h>
48
#define isnan(v) _isnan(v)
49
#define isinf(v) (!_finite(v))
50
51
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus)
/* C99 or later */
52
#define FF_INTDEF 2
53
#include <stdint.h>
54
typedef
unsigned
int
UINT;
/* int must be 16-bit or 32-bit */
55
typedef
unsigned
char
BYTE;
/* char must be 8-bit */
56
typedef
uint16_t WORD;
/* 16-bit unsigned */
57
typedef
uint32_t DWORD;
/* 32-bit unsigned */
58
typedef
uint64_t
QWORD
;
/* 64-bit unsigned */
59
typedef
WORD WCHAR;
/* UTF-16 code unit */
60
61
#else
/* Earlier than C99 */
62
#define FF_INTDEF 1
63
typedef
unsigned
int
UINT;
/* int must be 16-bit or 32-bit */
64
typedef
unsigned
char
BYTE;
/* char must be 8-bit */
65
typedef
unsigned
short
WORD;
/* short must be 16-bit */
66
typedef
unsigned
long
DWORD;
/* long must be 32-bit */
67
typedef
WORD WCHAR;
/* UTF-16 code unit */
68
#endif
69
70
71
/* Type of file size and LBA variables */
72
73
#if FF_FS_EXFAT
74
#if FF_INTDEF != 2
75
#error exFAT feature wants C99 or later
76
#endif
77
typedef
QWORD
FSIZE_t;
78
#if FF_LBA64
79
typedef
QWORD
LBA_t;
80
#else
81
typedef
DWORD LBA_t;
82
#endif
83
#else
84
#if FF_LBA64
85
#error exFAT needs to be enabled when enable 64-bit LBA
86
#endif
87
typedef
DWORD FSIZE_t;
88
typedef
DWORD LBA_t;
89
#endif
90
91
92
93
/* Type of path name strings on FatFs API (TCHAR) */
94
95
#if FF_USE_LFN && FF_LFN_UNICODE == 1
/* Unicode in UTF-16 encoding */
96
typedef
WCHAR TCHAR;
97
#define _T(x) L ## x
98
#define _TEXT(x) L ## x
99
#elif FF_USE_LFN && FF_LFN_UNICODE == 2
/* Unicode in UTF-8 encoding */
100
typedef
char
TCHAR;
101
#define _T(x) u8 ## x
102
#define _TEXT(x) u8 ## x
103
#elif FF_USE_LFN && FF_LFN_UNICODE == 3
/* Unicode in UTF-32 encoding */
104
typedef
DWORD TCHAR;
105
#define _T(x) U ## x
106
#define _TEXT(x) U ## x
107
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
108
#error Wrong FF_LFN_UNICODE setting
109
#else
/* ANSI/OEM code in SBCS/DBCS */
110
typedef
char
TCHAR;
111
#define _T(x) x
112
#define _TEXT(x) x
113
#endif
114
115
116
117
/* Definitions of volume management */
118
119
#if FF_MULTI_PARTITION
/* Multiple partition configuration */
120
typedef
struct
{
121
BYTE pd;
/* Associated physical drive */
122
BYTE pt;
/* Associated partition (0:Auto detect, 1-4:Forced partition) */
123
} PARTITION;
124
extern
PARTITION VolToPart[];
/* Volume to partition mapping table */
125
#endif
126
127
#if FF_STR_VOLUME_ID
128
#ifndef FF_VOLUME_STRS
129
extern
const
char
* VolumeStr[FF_VOLUMES];
/* User defined volume ID table */
130
#endif
131
#endif
132
133
134
/* Current working directory structure (FFXCWDS) */
135
136
#if FF_FS_EXFAT && FF_FS_RPATH
137
#if FF_PATH_DEPTH < 1
138
#error FF_PATH_DEPTH must not be zero
139
#endif
140
typedef
struct
{
141
DWORD d_scl;
/* Directory start cluster (0:root dir) */
142
DWORD d_size;
/* Size of directory (b7-b0: cluster chain status) (invalid if d_scl == 0) */
143
DWORD nxt_ofs;
/* Offset of entry of next dir in this directory (invalid if last link) */
144
} FFXCWDL;
145
typedef
struct
{
146
UINT depth;
/* Current directory depth (0:root dir) */
147
FFXCWDL tbl[FF_PATH_DEPTH + 1];
/* Directory chain of current working directory path */
148
} FFXCWDS;
149
#endif
150
151
152
/* Filesystem object structure (FATFS) */
153
154
typedef
struct
{
155
BYTE fs_type;
/* Filesystem type (0:not mounted) */
156
BYTE pdrv;
/* Physical drive that holds this volume */
157
BYTE ldrv;
/* Logical drive number (used only when FF_FS_REENTRANT) */
158
BYTE n_fats;
/* Number of FATs (1 or 2) */
159
BYTE wflag;
/* win[] status (b0:dirty) */
160
BYTE fsi_flag;
/* Allocation information control (b7:disabled, b0:dirty) */
161
WORD id;
/* Volume mount ID */
162
WORD n_rootdir;
/* Number of root directory entries (FAT12/16) */
163
WORD csize;
/* Cluster size [sectors] */
164
#if FF_MAX_SS != FF_MIN_SS
165
WORD ssize;
/* Sector size (512, 1024, 2048 or 4096) */
166
#endif
167
#if FF_USE_LFN
168
WCHAR* lfnbuf;
/* Pointer to LFN working buffer */
169
#endif
170
#if !FF_FS_READONLY
171
DWORD last_clst;
/* Last allocated cluster (invalid if >=n_fatent) */
172
DWORD free_clst;
/* Number of free clusters (invalid if >=fs->n_fatent-2) */
173
#endif
174
#if FF_FS_RPATH
175
DWORD cdir;
/* Current directory start cluster (0:root) */
176
#endif
177
DWORD n_fatent;
/* Number of FAT entries (number of clusters + 2) */
178
DWORD fsize;
/* Number of sectors per FAT */
179
LBA_t winsect;
/* Current sector appearing in the win[] */
180
LBA_t volbase;
/* Volume base sector */
181
LBA_t fatbase;
/* FAT base sector */
182
LBA_t dirbase;
/* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */
183
LBA_t database;
/* Data base sector */
184
#if FF_FS_EXFAT
185
LBA_t bitbase;
/* Allocation bitmap base sector */
186
BYTE* dirbuf;
/* Pointer to directory entry block buffer */
187
#if FF_FS_RPATH
188
FFXCWDS xcwds;
/* Crrent working directory structure */
189
FFXCWDS xcwds2;
/* Working buffer to follow the path */
190
#endif
191
#endif
192
BYTE win[FF_MAX_SS];
/* Disk access window for directory, FAT (and file data in tiny cfg) */
193
}
FATFS
;
194
195
196
197
/* Object ID and allocation information (FFOBJID) */
198
199
typedef
struct
{
200
FATFS
* fs;
/* Pointer to the volume holding this object */
201
WORD id;
/* Volume mount ID when this object was opened */
202
BYTE attr;
/* Object attribute */
203
BYTE stat;
/* Object chain status (exFAT: b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
204
DWORD sclust;
/* Object data cluster (0:no data or root directory) */
205
FSIZE_t objsize;
/* Object size (valid when sclust != 0) */
206
#if FF_FS_EXFAT
207
DWORD n_cont;
/* Size of first fragment - 1 (valid when stat == 3) */
208
DWORD n_frag;
/* Size of last fragment needs to be written to FAT (valid when not zero) */
209
DWORD c_scl;
/* Cluster of directory holding this object (valid when sclust != 0) */
210
DWORD c_size;
/* Size of directory holding this object (b7-b0: allocation status, valid when c_scl != 0) */
211
DWORD c_ofs;
/* Offset of entry in the holding directory */
212
#endif
213
#if FF_FS_LOCK
214
UINT lockid;
/* File lock ID origin from 1 (index of file semaphore table Files[]) */
215
#endif
216
}
FFOBJID
;
217
218
219
220
/* File object structure (FIL) */
221
222
typedef
struct
{
223
FFOBJID
obj;
/* Object identifier (must be the 1st member to detect invalid object pointer) */
224
BYTE flag;
/* File status flags */
225
BYTE err;
/* Abort flag (error code) */
226
FSIZE_t fptr;
/* File read/write pointer (0 on open) */
227
DWORD clust;
/* Current cluster of fptr (invalid when fptr is 0) */
228
LBA_t sect;
/* Sector number appearing in buf[] (0:invalid) */
229
#if !FF_FS_READONLY
230
LBA_t dir_sect;
/* Sector number containing the directory entry (not used in exFAT) */
231
BYTE* dir_ptr;
/* Pointer to the directory entry in the win[] (not used in exFAT) */
232
#endif
233
#if FF_USE_FASTSEEK
234
DWORD* cltbl;
/* Pointer to the cluster link map table (nulled on open; set by application) */
235
#endif
236
#if !FF_FS_TINY
237
BYTE buf[FF_MAX_SS];
/* File private data read/write window */
238
#endif
239
}
FIL
;
240
241
242
243
/* Directory object structure (DIR) */
244
245
typedef
struct
{
246
FFOBJID
obj;
/* Object identifier (must be the 1st member to detect invalid object pointer) */
247
DWORD dptr;
/* Current read/write offset */
248
DWORD clust;
/* Current cluster */
249
LBA_t sect;
/* Current sector (0:no more item to read) */
250
BYTE* dir;
/* Pointer to the directory item in the win[] in filesystem object */
251
BYTE fn[12];
/* SFN (in/out) {body[0-7],ext[8-10],status[11]} */
252
#if FF_USE_LFN
253
DWORD blk_ofs;
/* Offset of current entry block being processed (0xFFFFFFFF:invalid) */
254
#endif
255
#if FF_USE_FIND
256
const
TCHAR *pat;
/* Pointer to the name matching pattern */
257
#endif
258
}
DIR
;
259
260
261
262
/* File/directory information structure (FILINFO) */
263
264
typedef
struct
{
265
FSIZE_t fsize;
/* File size (invalid for directory) */
266
WORD fdate;
/* Date of file modification or directory creation */
267
WORD ftime;
/* Time of file modification or directory creation */
268
#if FF_FS_CRTIME
269
WORD crdate;
/* Date of object createion */
270
WORD crtime;
/* Time of object createion */
271
#endif
272
BYTE fattrib;
/* Object attribute */
273
#if FF_USE_LFN
274
TCHAR altname[FF_SFN_BUF + 1];
/* Alternative object name */
275
TCHAR fname[FF_LFN_BUF + 1];
/* Primary object name */
276
#else
277
TCHAR fname[12 + 1];
/* Object name */
278
#endif
279
}
FILINFO
;
280
281
282
283
/* Format parameter structure (MKFS_PARM) used for f_mkfs() */
284
285
typedef
struct
{
286
BYTE fmt;
/* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
287
BYTE n_fat;
/* Number of FATs */
288
UINT align;
/* Data area alignment (sector) */
289
UINT n_root;
/* Number of root directory entries */
290
DWORD au_size;
/* Cluster size (byte) */
291
}
MKFS_PARM
;
292
293
294
295
/* File function return code (FRESULT) */
296
297
typedef
enum
{
298
FR_OK = 0,
/* (0) Function succeeded */
299
FR_DISK_ERR,
/* (1) A hard error occurred in the low level disk I/O layer */
300
FR_INT_ERR,
/* (2) Assertion failed */
301
FR_NOT_READY,
/* (3) The physical drive does not work */
302
FR_NO_FILE,
/* (4) Could not find the file */
303
FR_NO_PATH,
/* (5) Could not find the path */
304
FR_INVALID_NAME,
/* (6) The path name format is invalid */
305
FR_DENIED,
/* (7) Access denied due to a prohibited access or directory full */
306
FR_EXIST,
/* (8) Access denied due to a prohibited access */
307
FR_INVALID_OBJECT,
/* (9) The file/directory object is invalid */
308
FR_WRITE_PROTECTED,
/* (10) The physical drive is write protected */
309
FR_INVALID_DRIVE,
/* (11) The logical drive number is invalid */
310
FR_NOT_ENABLED,
/* (12) The volume has no work area */
311
FR_NO_FILESYSTEM,
/* (13) Could not find a valid FAT volume */
312
FR_MKFS_ABORTED,
/* (14) The f_mkfs function aborted due to some problem */
313
FR_TIMEOUT,
/* (15) Could not take control of the volume within defined period */
314
FR_LOCKED,
/* (16) The operation is rejected according to the file sharing policy */
315
FR_NOT_ENOUGH_CORE,
/* (17) LFN working buffer could not be allocated, given buffer size is insufficient or too deep path */
316
FR_TOO_MANY_OPEN_FILES,
/* (18) Number of open files > FF_FS_LOCK */
317
FR_INVALID_PARAMETER
/* (19) Given parameter is invalid */
318
} FRESULT;
319
320
321
322
323
/*--------------------------------------------------------------*/
324
/* FatFs Module Application Interface */
325
/*--------------------------------------------------------------*/
326
327
FRESULT f_open (
FIL
* fp,
const
TCHAR* path, BYTE mode);
/* Open or create a file */
328
FRESULT f_close (
FIL
* fp);
/* Close an open file object */
329
FRESULT f_read (
FIL
* fp,
void
* buff, UINT btr, UINT* br);
/* Read data from the file */
330
FRESULT f_write (
FIL
* fp,
const
void
* buff, UINT btw, UINT* bw);
/* Write data to the file */
331
FRESULT f_lseek (
FIL
* fp, FSIZE_t ofs);
/* Move file pointer of the file object */
332
FRESULT f_truncate (
FIL
* fp);
/* Truncate the file */
333
FRESULT f_sync (
FIL
* fp);
/* Flush cached data of the writing file */
334
FRESULT f_opendir (
DIR
* dp,
const
TCHAR* path);
/* Open a directory */
335
FRESULT f_closedir (
DIR
* dp);
/* Close an open directory */
336
FRESULT f_readdir (
DIR
* dp,
FILINFO
* fno);
/* Read a directory item */
337
FRESULT f_findfirst (
DIR
* dp,
FILINFO
* fno,
const
TCHAR* path,
const
TCHAR* pattern);
/* Find first file */
338
FRESULT f_findnext (
DIR
* dp,
FILINFO
* fno);
/* Find next file */
339
FRESULT f_mkdir (
const
TCHAR* path);
/* Create a sub directory */
340
FRESULT f_unlink (
const
TCHAR* path);
/* Delete an existing file or directory */
341
FRESULT f_rename (
const
TCHAR* path_old,
const
TCHAR* path_new);
/* Rename/Move a file or directory */
342
FRESULT f_stat (
const
TCHAR* path,
FILINFO
* fno);
/* Get file status */
343
FRESULT f_chmod (
const
TCHAR* path, BYTE attr, BYTE mask);
/* Change attribute of a file/dir */
344
FRESULT f_utime (
const
TCHAR* path,
const
FILINFO
* fno);
/* Change timestamp of a file/dir */
345
FRESULT f_chdir (
const
TCHAR* path);
/* Change current directory */
346
FRESULT f_chdrive (
const
TCHAR* path);
/* Change current drive */
347
FRESULT f_getcwd (TCHAR* buff, UINT len);
/* Get current directory */
348
FRESULT f_getfree (
const
TCHAR* path, DWORD* nclst,
FATFS
** fatfs);
/* Get number of free clusters on the drive */
349
FRESULT f_getlabel (
const
TCHAR* path, TCHAR* label, DWORD* vsn);
/* Get volume label */
350
FRESULT f_setlabel (
const
TCHAR* label);
/* Set volume label */
351
FRESULT f_forward (
FIL
* fp, UINT(*func)(
const
BYTE*,UINT), UINT btf, UINT* bf);
/* Forward data to the stream */
352
FRESULT f_expand (
FIL
* fp, FSIZE_t fsz, BYTE opt);
/* Allocate a contiguous block to the file */
353
FRESULT f_mount (
FATFS
* fs,
const
TCHAR* path, BYTE opt);
/* Mount/Unmount a logical drive */
354
FRESULT f_mkfs (
const
TCHAR* path,
const
MKFS_PARM
* opt,
void
* work, UINT len);
/* Create a FAT volume */
355
FRESULT f_fdisk (BYTE pdrv,
const
LBA_t ptbl[],
void
* work);
/* Divide a physical drive into some partitions */
356
FRESULT f_setcp (WORD cp);
/* Set current code page */
357
int
f_putc (TCHAR c,
FIL
* fp);
/* Put a character to the file */
358
int
f_puts (
const
TCHAR* str,
FIL
* cp);
/* Put a string to the file */
359
int
f_printf (
FIL
* fp,
const
TCHAR* str, ...);
/* Put a formatted string to the file */
360
TCHAR* f_gets (TCHAR* buff,
int
len,
FIL
* fp);
/* Get a string from the file */
361
362
/* Some API fucntions are implemented as macro */
363
364
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
365
#define f_error(fp) ((fp)->err)
366
#define f_tell(fp) ((fp)->fptr)
367
#define f_size(fp) ((fp)->obj.objsize)
368
#define f_rewind(fp) f_lseek((fp), 0)
369
#define f_rewinddir(dp) f_readdir((dp), 0)
370
#define f_rmdir(path) f_unlink(path)
371
#define f_unmount(path) f_mount(0, path, 0)
372
373
374
375
LBA_t clst2sect (
/* !=0:Sector number, 0:Failed (invalid cluster#) */
376
FATFS
* fs,
/* Filesystem object */
377
DWORD clst
/* Cluster# to be converted */
378
);
379
380
DWORD get_fat (
/* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFFF:Cluster status */
381
FFOBJID
* obj,
/* Corresponding object */
382
DWORD clst
/* Cluster number to get the value */
383
);
384
385
/*--------------------------------------------------------------*/
386
/* Additional Functions */
387
/*--------------------------------------------------------------*/
388
389
/* RTC function (provided by user) */
390
#if !FF_FS_READONLY && !FF_FS_NORTC
391
DWORD get_fattime (
void
);
/* Get current time */
392
#endif
393
394
395
/* LFN support functions (defined in ffunicode.c) */
396
397
#if FF_USE_LFN >= 1
398
WCHAR ff_oem2uni (WCHAR oem, WORD cp);
/* OEM code to Unicode conversion */
399
WCHAR ff_uni2oem (DWORD uni, WORD cp);
/* Unicode to OEM code conversion */
400
DWORD ff_wtoupper (DWORD uni);
/* Unicode upper-case conversion */
401
#endif
402
403
404
/* O/S dependent functions (samples available in ffsystem.c) */
405
406
#if FF_USE_LFN == 3
/* Dynamic memory allocation */
407
void
* ff_memalloc (UINT msize);
/* Allocate memory block */
408
void
ff_memfree (
void
* mblock);
/* Free memory block */
409
#endif
410
#if FF_FS_REENTRANT
/* Sync functions */
411
int
ff_mutex_create (
int
vol);
/* Create a sync object */
412
void
ff_mutex_delete (
int
vol);
/* Delete a sync object */
413
int
ff_mutex_take (
int
vol);
/* Lock sync object */
414
void
ff_mutex_give (
int
vol);
/* Unlock sync object */
415
#endif
416
417
418
419
420
/*--------------------------------------------------------------*/
421
/* Flags and Offset Address */
422
/*--------------------------------------------------------------*/
423
424
/* File access mode and open method flags (3rd argument of f_open function) */
425
#define FA_READ 0x01
426
#define FA_WRITE 0x02
427
#define FA_OPEN_EXISTING 0x00
428
#define FA_CREATE_NEW 0x04
429
#define FA_CREATE_ALWAYS 0x08
430
#define FA_OPEN_ALWAYS 0x10
431
#define FA_OPEN_APPEND 0x30
432
433
/* Fast seek controls (2nd argument of f_lseek function) */
434
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
435
436
/* Format options (2nd argument of f_mkfs function) */
437
#define FM_FAT 0x01
438
#define FM_FAT32 0x02
439
#define FM_EXFAT 0x04
440
#define FM_ANY 0x07
441
#define FM_SFD 0x08
442
443
/* Filesystem type (FATFS.fs_type) */
444
#define FS_FAT12 1
445
#define FS_FAT16 2
446
#define FS_FAT32 3
447
#define FS_EXFAT 4
448
449
/* File attribute bits for directory entry (FILINFO.fattrib) */
450
#define AM_RDO 0x01
/* Read only */
451
#define AM_HID 0x02
/* Hidden */
452
#define AM_SYS 0x04
/* System */
453
#define AM_DIR 0x10
/* Directory */
454
#define AM_ARC 0x20
/* Archive */
455
456
457
#ifdef __cplusplus
458
}
459
#endif
460
461
#endif
/* FF_DEFINED */
ffconf.h
DIR
Definition
ff.h:245
FATFS
Definition
ff.h:154
FFOBJID
Definition
ff.h:199
FILINFO
Definition
ff.h:264
FIL
Definition
ff.h:222
MKFS_PARM
Definition
ff.h:285
QWORD
Definition
libgs.h:334
core
bdmfs_fatfs
src
fatfs
include
ff.h
Generated by
1.18.0