• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEFINED
23 #define FF_DEFINED	80286	/* Revision ID */
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #include <dirent.h>
30 #include "integer.h"	/* Basic integer types */
31 #include "ffconf.h"		/* FatFs configuration options */
32 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
33 #include "virpart.h"
34 #endif
35 #ifndef __LITEOS_M__
36 #include "los_list.h"
37 #endif
38 #if FF_DEFINED != FFCONF_DEF
39 #error Wrong configuration file (ffconf.h).
40 #endif
41 
42 /*--------------------------------*/
43 /* LFN/Directory working buffer   */
44 /*--------------------------------*/
45 
46 #if FF_USE_LFN == 0		/* Non-LFN configuration */
47 #define DEF_NAMBUF
48 #define INIT_NAMBUF(fs)
49 #define FREE_NAMBUF()
50 #define LEAVE_MKFS(res)	return res
51 
52 #else					/* LFN configurations */
53 #if FF_MAX_LFN < 12 || FF_MAX_LFN > 255
54 #error Wrong setting of FF_MAX_LFN
55 #endif
56 #if FF_LFN_BUF < FF_SFN_BUF || FF_SFN_BUF < 12
57 #error Wrong setting of FF_LFN_BUF or FF_SFN_BUF
58 #endif
59 #if FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3
60 #error Wrong setting of FF_LFN_UNICODE
61 #endif
62 static const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};	/* FAT: Offset of LFN characters in the directory entry */
63 
64 #if FF_USE_LFN == 1		/* LFN enabled with static working buffer */
65 static WCHAR LfnBuf[FF_MAX_LFN + 1];		/* LFN working buffer */
66 #define DEF_NAMBUF
67 #define INIT_NAMBUF(fs)
68 #define FREE_NAMBUF()
69 #define LEAVE_MKFS(res)	return res
70 
71 #elif FF_USE_LFN == 2 	/* LFN enabled with dynamic working buffer on the stack */
72 #define DEF_NAMBUF		WCHAR lbuf[FF_MAX_LFN+1];	/* LFN working buffer */
73 #define INIT_NAMBUF(fs)	{ (fs)->lfnbuf = lbuf; }
74 #define FREE_NAMBUF()
75 #define LEAVE_MKFS(res)	return res
76 
77 #elif FF_USE_LFN == 3 	/* LFN enabled with dynamic working buffer on the heap */
78 #define DEF_NAMBUF		WCHAR *lfn;	/* Pointer to LFN working buffer and directory entry block scratchpad buffer */
79 #define INIT_NAMBUF(fs)	{ lfn = ff_memalloc((FF_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; }
80 #define FREE_NAMBUF()	ff_memfree(lfn)
81 #define LEAVE_MKFS(res)	{ if (!work) ff_memfree(buf); return res; }
82 #define MAX_MALLOC	0x8000	/* Must be >=FF_MAX_SS */
83 
84 #else
85 #error Wrong setting of FF_USE_LFN
86 
87 #endif	/* FF_USE_LFN == 1 */
88 #endif	/* FF_USE_LFN == 0 */
89 
90 
91 #define NS_NONAME	0x80	/* Not followed */
92 #define NSFLAG		11		/* Index of the name status byte */
93 
94 /* Definitions of volume management */
95 
96 typedef struct {
97 	BYTE di;	/* Physics disk id */
98 	BYTE pd;	/* Physical drive number */
99 	BYTE pt;	/* Partition: 0:Auto detect, 1-4:Forced partition) */
100 	QWORD ps;	/* Partition start sector */
101 	QWORD pc;	/* Partition sector count */
102 } PARTITION;
103 extern PARTITION VolToPart[];	/* Volume - Partition mapping table */
104 #define LD2DI(vol) (VolToPart[vol].di)	/* Get physical disk id */
105 #define LD2PD(vol) (VolToPart[vol].pd)	/* Get physical drive number */
106 
107 #if FF_MULTI_PARTITION	/* Multiple partition configuration */
108 #define LD2PT(vol) (VolToPart[vol].pt)	/* Get partition index */
109 #define LD2PS(vol) (VolToPart[vol].ps)	/* Get partition start sector */
110 #define LD2PC(vol) (VolToPart[vol].pc)	/* Get partition sector count */
111 
112 #else							/* Single partition configuration */
113 #define LD2PT(vol)	0			/* Find first valid partition or in SFD */
114 #define LD2PS(vol)	0
115 #define LD2PC(vol)	0
116 
117 #endif
118 /* Type of path name strings on FatFs API */
119 
120 
121 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
122 typedef struct FAT_VIRTUAL_PARTITION {
123 	virpartinfo	virtualinfo;
124 	BOOL		isparamset;
125 } FAT_VIR_PART;
126 
127 #define ISVIRPART(fs)	((fs)->vir_avail == FS_VIRENABLE)
128 #define ISNORMAL(fs)	((fs)->vir_avail != FS_VIRENABLE)
129 
130 #define ISPARENT(fs)	((fs)->vir_flag == FS_PARENT)
131 #define ISCHILD(fs)	((fs)->vir_flag != FS_PARENT)
132 
133 
134 #define VIRINFO_EXTERNAL	0
135 #define VIRINFO_BUILDIN		1
136 #endif
137 
138 
139 
140 /* Type of path name strings on FatFs API (TCHAR) */
141 #ifndef _INC_TCHAR
142 #define _INC_TCHAR
143 
144 #if FF_USE_LFN && FF_LFN_UNICODE == 1 	/* Unicode in UTF-16 encoding */
145 typedef WCHAR TCHAR;
146 #define _T(x) L ## x
147 #define _TEXT(x) L ## x
148 #elif FF_USE_LFN && FF_LFN_UNICODE == 2	/* Unicode in UTF-8 encoding */
149 typedef char TCHAR;
150 #define _T(x) u8 ## x
151 #define _TEXT(x) u8 ## x
152 #elif FF_USE_LFN && FF_LFN_UNICODE == 3	/* Unicode in UTF-32 encoding */
153 typedef DWORD TCHAR;
154 #define _T(x) U ## x
155 #define _TEXT(x) U ## x
156 #elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
157 #error Wrong FF_LFN_UNICODE setting
158 #else									/* ANSI/OEM code in SBCS/DBCS */
159 typedef char TCHAR;
160 #define _T(x) x
161 #define _TEXT(x) x
162 #endif
163 #endif
164 
165 #if (FF_MAX_SS == FF_MIN_SS)
166 #define SS(fs)	((UINT)FF_MAX_SS)	/* Fixed sector size */
167 #else
168 #define SS(fs)	((fs)->ssize)	/* Variable sector size */
169 #endif
170 
171 
172 /* Type of file size variables */
173 typedef DWORD FSIZE_t;
174 typedef QWORD LBA_t;
175 
176 /* DIR offset in fs win */
177 #define DIR_Name			0		/* Short file name (11-byte) */
178 #define DIR_Attr			11		/* Attribute (BYTE) */
179 #define DIR_NTres			12		/* Lower case flag (BYTE) */
180 #define DIR_CrtTime10		13		/* Created time sub-second (BYTE) */
181 #define DIR_CrtTime			14		/* Created time (DWORD) */
182 #define DIR_LstAccDate		18		/* Last accessed date (WORD) */
183 #define DIR_FstClusHI		20		/* Higher 16-bit of first cluster (WORD) */
184 #define DIR_ModTime			22		/* Modified time (DWORD) */
185 #define DIR_FstClusLO		26		/* Lower 16-bit of first cluster (WORD) */
186 #define DIR_FileSize		28		/* File size (DWORD) */
187 #define LDIR_Ord			0		/* LFN: LFN order and LLE flag (BYTE) */
188 #define LDIR_Attr			11		/* LFN: LFN attribute (BYTE) */
189 #define LDIR_Type			12		/* LFN: Entry type (BYTE) */
190 #define LDIR_Chksum			13		/* LFN: Checksum of the SFN (BYTE) */
191 #define LDIR_FstClusLO		26		/* LFN: MBZ field (WORD) */
192 
193 
194 /* Limits and boundaries */
195 #define MAX_DIR		0x200000		/* Max size of FAT directory */
196 #define MAX_FAT12	0xFF5			/* Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) */
197 #define MAX_FAT16	0xFFF5			/* Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) */
198 #define MAX_FAT32	0x0FFFFFF5		/* Max FAT32 clusters (not specified, practical limit) */
199 
200 
201 /* Timestamp */
202 #if FF_FS_NORTC == 1
203 #if FF_NORTC_YEAR < 1980 || FF_NORTC_YEAR > 2107 || FF_NORTC_MON < 1 || FF_NORTC_MON > 12 || FF_NORTC_MDAY < 1 || FF_NORTC_MDAY > 31
204 #error Invalid FF_FS_NORTC settings
205 #endif
206 #define GET_FATTIME()	((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16)
207 #else
208 #define GET_FATTIME()	get_fattime()
209 #endif
210 
211 extern UINT	time_status;
212 
213 /* Filesystem object structure (FATFS) */
214 
215 typedef struct {
216 	BYTE	fs_type;		/* Filesystem type (0:not mounted) */
217 	BYTE	pdrv;			/* Associated physical drive */
218 	BYTE	n_fats;			/* Number of FATs (1 or 2) */
219 	BYTE	wflag;			/* win[] flag (b0:dirty) */
220 	BYTE	fsi_flag;		/* FSINFO flags (b7:disabled, b0:dirty) */
221 	WORD	id;				/* Volume mount ID */
222 	WORD	n_rootdir;		/* Number of root directory entries (FAT12/16) */
223 	WORD	csize;			/* Cluster size [sectors] */
224 #if FF_MAX_SS != FF_MIN_SS
225 	size_t	ssize;			/* Sector size (512, 1024, 2048 or 4096) */
226 #endif
227 #if FF_USE_LFN
228 	WCHAR*	lfnbuf;			/* LFN working buffer */
229 #endif
230 #if FF_FS_REENTRANT
231 	FF_SYNC_t	sobj;		/* Identifier of sync object */
232 #endif
233 #if !FF_FS_READONLY
234 	DWORD	last_clst;		/* Last allocated cluster */
235 	DWORD	free_clst;		/* Number of free clusters */
236 #endif
237 #if FF_FS_RPATH
238 	DWORD	cdir;			/* Current directory start cluster (0:root) */
239 #endif
240 	DWORD	n_fatent;		/* Number of FAT entries, = number of clusters + 2 */
241 	DWORD	fsize;			/* Sectors per FAT */
242 	LBA_t	volbase;		/* Volume base sector */
243 	LBA_t	fatbase;		/* FAT base sector */
244 	LBA_t	dirbase;		/* Root directory base sector/cluster */
245 	LBA_t	database;		/* Data base sector */
246 	LBA_t	winsect;		/* Current sector appearing in the win[] */
247 	BYTE*	win;			/* Disk access window for Directory, FAT (and file data at tiny cfg) */
248 
249 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
250 	DWORD	st_clst;
251 	DWORD	ct_clst;
252 	BYTE	vir_flag;		/* Flag of Virtual Filesystem Object, b0 : 1 for virtual Fatfs object, 0 for reality Fatfs object */
253 	BYTE	vir_avail;
254 	DWORD	vir_amount;
255 	VOID*	parent_fs;		/* Point to the reality Fatfs object, only available in virtual Fatfs object */
256 	CHAR	namelabel[_MAX_ENTRYLENGTH + 1]; /* The name label point to the each virtual Fatfs object ,only available in virtual Fatfs obj */
257 	VOID**	child_fs;		/* Point to the child Fatfs object ,only available in reality Fatfs object */
258 #endif
259 #ifndef __LITEOS_M__
260 	int 	fs_uid;
261 	int 	fs_gid;
262 	mode_t 	fs_mode;
263 #endif
264 	unsigned short fs_dmask;
265 	unsigned short fs_fmask;
266 } FATFS;
267 
268 
269 
270 /* Object ID and allocation information (FFOBJID) */
271 
272 typedef struct {
273 	FATFS*	fs;				/* Pointer to the hosting volume of this object */
274 	WORD	id;				/* Hosting volume mount ID */
275 	BYTE	attr;			/* Object attribute */
276 	BYTE	stat;			/* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
277 	DWORD	sclust;			/* Object data start cluster (0:no cluster or root directory) */
278 	FSIZE_t	objsize;		/* Object size (valid when sclust != 0) */
279 #if FF_FS_LOCK
280 	UINT	lockid;			/* File lock ID origin from 1 (index of file semaphore table Files[]) */
281 #endif
282 } FFOBJID;
283 
284 
285 
286 /* File object structure (FIL) */
287 
288 typedef struct {
289 	FFOBJID	obj;			/* Object identifier (must be the 1st member to detect invalid object pointer) */
290 	BYTE	flag;			/* File status flags */
291 	BYTE	err;			/* Abort flag (error code) */
292 	FSIZE_t	fptr;			/* File read/write pointer (Zeroed on file open) */
293 	DWORD	clust;			/* Current cluster of fpter (invalid when fptr is 0) */
294 	LBA_t	sect;			/* Sector number appearing in buf[] (0:invalid) */
295 #if !FF_FS_READONLY
296 	LBA_t	dir_sect;		/* Sector number containing the directory entry */
297 	BYTE*	dir_ptr;		/* Pointer to the directory entry in the win[] */
298 #endif
299 #if FF_USE_FASTSEEK
300 	DWORD*	cltbl;			/* Pointer to the cluster link map table (nulled on open, set by application) */
301 #endif
302 #if !FF_FS_TINY
303 	BYTE*	buf;			/* File private data read/write window */
304 #endif
305 #ifndef __LITEOS_M__
306 	LOS_DL_LIST fp_entry;
307 #endif
308 } FIL;
309 
310 
311 
312 /* Directory object structure (DIR) */
313 
314 struct __dirstream {
315 	FFOBJID	obj;			/* Object identifier */
316 	DWORD	dptr;			/* Current read/write offset */
317 	DWORD	clust;			/* Current cluster */
318 	LBA_t	sect;			/* Current sector (0:Read operation has terminated) */
319 	BYTE*	dir;			/* Pointer to the directory item in the win[] */
320 	BYTE	fn[12];			/* SFN (in/out) {body[8],ext[3],status[1]} */
321 #if FF_USE_LFN
322 	DWORD	blk_ofs;		/* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
323 #endif
324 #if FF_USE_FIND
325 	const TCHAR* pat;		/* Pointer to the name matching pattern */
326 #endif
327 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
328 	BYTE			atrootdir;
329 #endif
330 };
331 
332 /* File information structure (FILINFO) */
333 
334 typedef struct {
335 	FSIZE_t	fsize;			/* File size */
336 	WORD	fdate;			/* Modified date */
337 	WORD	ftime;			/* Modified time */
338 	BYTE	fattrib;		/* File attribute */
339 #if FF_USE_LFN
340 	TCHAR	altname[FF_SFN_BUF + 1];/* Altenative file name */
341 	TCHAR	fname[FF_LFN_BUF + 1];	/* Primary file name */
342 #else
343 	TCHAR	fname[12 + 1];	/* File name */
344 #endif
345 	DWORD	sclst;
346 #ifndef __LITEOS_M__
347 	LOS_DL_LIST fp_list;
348 #endif
349 } FILINFO;
350 
351 #ifndef __LITEOS_M__
352 typedef struct {
353 	DWORD	clst;
354 	FSIZE_t	pos;
355 } FAT_ENTRY;
356 #endif
357 
358 /* Format parameter structure (MKFS_PARM) */
359 
360 typedef struct {
361 	BYTE fmt;			/* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
362 	BYTE n_fat;			/* Number of FATs */
363 	UINT align;			/* Data area alignment (sector) */
364 	UINT n_root;		/* Number of root directory entries */
365 	int n_sect;			/* Cluster size (sector) */
366 } MKFS_PARM;
367 
368 typedef struct {
369 	DIR	f_dir;
370 	FILINFO	fno;
371 #ifndef __LITEOS_M__
372 	FAT_ENTRY	fat_entry;
373 #endif
374 } DIR_FILE;
375 
376 /* File function return code (FRESULT) */
377 
378 typedef enum {
379 	FR_OK = 0,				/* (0) Succeeded */
380 	FR_DISK_ERR,			/* (1) A hard error occurred in the low level disk I/O layer */
381 	FR_INT_ERR,				/* (2) Assertion failed */
382 	FR_NOT_READY,			/* (3) The physical drive cannot work */
383 	FR_NO_FILE,				/* (4) Could not find the file */
384 	FR_NO_PATH,				/* (5) Could not find the path */
385 	FR_INVALID_NAME,		/* (6) The path name format is invalid */
386 	FR_DENIED,				/* (7) Access denied due to prohibited access or directory full */
387 	FR_EXIST,				/* (8) Access denied due to prohibited access */
388 	FR_INVALID_OBJECT,		/* (9) The file/directory object is invalid */
389 	FR_WRITE_PROTECTED,		/* (10) The physical drive is write protected */
390 	FR_INVALID_DRIVE,		/* (11) The logical drive number is invalid */
391 	FR_NOT_ENABLED,			/* (12) The volume has no work area */
392 	FR_NO_FILESYSTEM,		/* (13) There is no valid FAT volume */
393 	FR_MKFS_ABORTED,		/* (14) The f_mkfs() aborted due to any problem */
394 	FR_TIMEOUT,				/* (15) Could not get a grant to access the volume within defined period */
395 	FR_LOCKED,				/* (16) The operation is rejected according to the file sharing policy */
396 	FR_NOT_ENOUGH_CORE,		/* (17) LFN working buffer could not be allocated */
397 	FR_TOO_MANY_OPEN_FILES,	/* (18) Number of open files > FF_FS_LOCK */
398 	FR_INVALID_PARAMETER,	/* (19) Given parameter is invalid */
399 	FR_NO_SPACE_LEFT,		/* (20) No space left */
400 	FR_NO_DIRENTRY,			/* (21) No directory entry to allocate	*/
401 	FR_NO_EMPTY_DIR,		/* (22) Directory not empty  */
402 	FR_IS_DIR,				/* (23) Is a directory	*/
403 	FR_NO_DIR,				/* (24) Not a directory */
404 	FR_NO_EPERM,			/* (25) Operation not permitted */
405 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
406 	FR_MODIFIED,			/* (26) Virtual Partition Info has been modified by other fictions */
407 	FR_CHAIN_ERR,			/* (27) File cluster chain has been broken by the other enviornmnet */
408 	FR_INVAILD_FATFS,		/* (28) FATFS object error */
409 	FR_NOVIRPART,			/* (29) The external SD card has not been set a virtual partition configure */
410 	FR_OCCUPIED,			/* (30) The virtual partition has been illegally occupied. */
411 	FR_NOTCLEAR,			/* (31) The root directory is not clear */
412 	FR_NOTFIT,				/* (32) The partition does not fit the virtual partition feature */
413 #endif
414 } FRESULT;
415 
416 
417 
418 
419 /*--------------------------------------------------------------*/
420 /* FatFs Module Application Interface                           */
421 /*--------------------------------------------------------------*/
422 
423 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
424 FATFS*  f_getfatfs (int vol);
425 FRESULT f_scanfat (FATFS* fs);
426 FRESULT f_boundary (FATFS *fs, DWORD clust);
427 FRESULT f_disvirfs (FATFS* fs);
428 FRESULT f_unregvirfs (FATFS* fs);
429 FRESULT f_regvirfs (FATFS* fs);
430 FRESULT f_checkvirpart (FATFS* fs, const TCHAR* path, BYTE vol);
431 FRESULT f_makevirpart (FATFS* fs, const TCHAR* path, BYTE vol);
432 FRESULT f_getvirfree (const TCHAR* path, DWORD* nclst, DWORD* cclst);
433 FRESULT f_checkname (const TCHAR* path);
434 #endif
435 
436 FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode);				/* Open or create a file */
437 FRESULT f_close (FIL* fp);											/* Close an open file object */
438 FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br);			/* Read data from the file */
439 FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw);	/* Write data to the file */
440 FRESULT f_lseek (FIL* fp, FSIZE_t ofs);								/* Move file pointer of the file object */
441 FRESULT f_truncate (FIL* fp, FSIZE_t length);					   /* Truncate the file */
442 FRESULT f_sync (FIL* fp);											/* Flush cached data of the writing file */
443 FRESULT f_opendir (DIR* dp, const TCHAR* path);						/* Open a directory */
444 FRESULT f_closedir (DIR* dp);										/* Close an open directory */
445 FRESULT f_readdir (DIR* dp, FILINFO* fno);							/* Read a directory item */
446 FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);	/* Find first file */
447 FRESULT f_findnext (DIR* dp, FILINFO* fno);							/* Find next file */
448 FRESULT f_mkdir (const TCHAR* path);								/* Create a sub directory */
449 FRESULT f_unlink (const TCHAR* path);								/* Delete an existing file or directory */
450 FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new);	/* Rename/Move a file or directory */
451 FRESULT f_stat (const TCHAR* path, FILINFO* fno);					/* Get file status */
452 FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask);			/* Change attribute of a file/dir */
453 FRESULT f_utime (const TCHAR* path, const FILINFO* fno);			/* Change timestamp of a file/dir */
454 FRESULT f_chdir (const TCHAR* path);								/* Change current directory */
455 FRESULT f_chdrive (const TCHAR* path);								/* Change current drive */
456 FRESULT f_getcwd (TCHAR* buff, UINT len);							/* Get current directory */
457 FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs);	/* Get number of free clusters on the drive */
458 FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn);	/* Get volume label */
459 FRESULT f_setlabel (const TCHAR* label);							/* Set volume label */
460 FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);	/* Forward data to the stream */
461 FRESULT f_expand (FIL* fp, FSIZE_t offset, FSIZE_t fsz, int opt);	/* Allocate a contiguous block to the file */
462 FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);			/* Mount/Unmount a logical drive */
463 FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len);	/* Create a FAT volume */
464 FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work);		/* Divide a physical drive into some partitions */
465 FRESULT f_setcp (WORD cp);											/* Set current code page */
466 int f_putc (TCHAR c, FIL* fp);										/* Put a character to the file */
467 int f_puts (const TCHAR* str, FIL* cp);								/* Put a string to the file */
468 int f_printf (FIL* fp, const TCHAR* str, ...);						/* Put a formatted string to the file */
469 TCHAR* f_gets (TCHAR* buff, int len, FIL* fp);						/* Get a string from the file */
470 void f_clean (const TCHAR* path);									/* clean all opening file and directory */
471 void f_settimestatus (UINT status);									/* system time flag setting */
472 FRESULT f_fcheckfat (DIR_FILE* dir_info);							/* check file cluster list */
473 FRESULT f_getclustinfo (FIL* fp, DWORD* fclust, DWORD* fcount);	/* get the clusters information of the file */
474 FRESULT f_checkopenlock(int index);
475 FRESULT sync_fs (FATFS* fs);
476 FRESULT sync_window(FATFS *fs);
477 FRESULT move_window (FATFS* fs, QWORD sector);
478 FRESULT fat_count_free_entries(DWORD *nclst, FATFS *fs);
479 void get_fileinfo (DIR* dp, FILINFO* fno);
480 DWORD get_fat (FFOBJID *obj, DWORD clst);
481 FRESULT put_fat(FATFS *fs, DWORD clst, DWORD val);
482 FRESULT mount_volume (const TCHAR **path, FATFS **rfs, BYTE mode);
483 QWORD clst2sect (FATFS* fs, DWORD clst );
484 DWORD ld_clust(FATFS *fs, const BYTE *dir);
485 void st_clust(FATFS *fs, BYTE *dir, DWORD cl);
486 DWORD ld_dword (const BYTE *ptr);
487 WORD ld_word (const BYTE *ptr);
488 void st_dword (BYTE *ptr, DWORD val);
489 void st_word (BYTE *ptr, WORD val);
490 FRESULT create_name (DIR *dp, const TCHAR **path);
491 int lock_fs (FATFS *fs);
492 UINT check_fs(FATFS *fs, QWORD sect);
493 UINT inc_lock(DIR* dp, int acc);
494 void unlock_fs (FATFS *fs, FRESULT res);
495 FRESULT dir_sdi (DIR *dp, DWORD ofs);
496 FRESULT dir_find(DIR *dp);
497 FRESULT dir_read(DIR *dp, int vol);
498 #ifndef __LITEOS_M__
499 FRESULT dir_read_massive(DIR *dp, int vol);
500 #endif
501 FRESULT dir_remove(DIR *dp);
502 FRESULT dir_next(DIR *dp, int stretch);
503 DWORD dir_ofs(DIR* dp);
504 FRESULT dir_register(DIR *dp);
505 DWORD create_chain (FFOBJID* obj, DWORD clst);
506 FRESULT remove_chain (FFOBJID* obj, DWORD clst, DWORD pclst);
507 void mem_set (void* dst, int val, UINT cnt);
508 void mem_cpy (void* dst, const void* src, UINT cnt);
509 int fatfs_get_vol (FATFS *fat);
510 FRESULT set_volumn_label(FATFS *fs, const TCHAR *label);
511 
512 #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
513 #define f_error(fp) ((fp)->err)
514 #define f_tell(fp) ((fp)->fptr)
515 #define f_size(fp) ((fp)->obj.objsize)
516 #define f_rewind(fp) f_lseek((fp), 0)
517 #define f_rewinddir(dp) f_readdir((dp), 0)
518 #define f_rmdir(path) f_unlink(path)
519 #define f_unmount(path) f_mount(0, path, 0)
520 
521 
522 
523 
524 /*--------------------------------------------------------------*/
525 /* Additional Functions                                         */
526 /*--------------------------------------------------------------*/
527 
528 /* RTC function (provided by user) */
529 #if !FF_FS_READONLY && !FF_FS_NORTC
530 DWORD get_fattime (void);	/* Get current time */
531 #endif
532 
533 
534 /* LFN support functions (defined in ffunicode.c) */
535 
536 #if FF_USE_LFN >= 1
537 WCHAR ff_oem2uni (WCHAR oem, WORD cp);	/* OEM code to Unicode conversion */
538 WCHAR ff_uni2oem (DWORD uni, WORD cp);	/* Unicode to OEM code conversion */
539 DWORD ff_wtoupper (DWORD uni);			/* Unicode upper-case conversion */
540 #endif
541 /* O/S dependent functions (samples available in ffsystem.c) */
542 void* ff_memalloc (UINT msize);			/* Allocate memory block */
543 void ff_memfree (void* mblock);			/* Free memory block */
544 #ifndef __LITEOS_M__
545 int ff_strnlen(const void *str, size_t maxlen);
546 #endif
547 
548 /* Sync functions */
549 #if FF_FS_REENTRANT
550 int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj);	/* Create a sync object */
551 int ff_req_grant (FF_SYNC_t* sobj);		/* Lock sync object */
552 void ff_rel_grant (FF_SYNC_t* sobj);		/* Unlock sync object */
553 int ff_del_syncobj (FF_SYNC_t* sobj);	/* Delete a sync object */
554 #endif
555 
556 
557 
558 
559 /*--------------------------------------------------------------*/
560 /* Flags and Offset Address                                     */
561 /*--------------------------------------------------------------*/
562 
563 /* File access mode and open method flags (3rd argument of f_open) */
564 #define	FA_READ				0x01
565 #define	FA_WRITE			0x02
566 #define	FA_OPEN_EXISTING	0x00
567 #define	FA_CREATE_NEW		0x04
568 #define	FA_CREATE_ALWAYS	0x08
569 #define	FA_OPEN_ALWAYS		0x10
570 #define	FA_OPEN_APPEND		0x30
571 
572 /* Fast seek controls (2nd argument of f_lseek) */
573 #define CREATE_LINKMAP	((FSIZE_t)0 - 1)
574 
575 /* Format options (2nd argument of f_mkfs) */
576 #define FM_FAT		0x01
577 #define FM_FAT32	0x02
578 #define FM_ANY		0x07
579 #define FM_SFD		0x08
580 
581 /*System Time Flag */
582 #define SYSTEM_TIME_ENABLE	0x01
583 #define SYSTEM_TIME_DISABLE	0x00
584 
585 /* Filesystem type (FATFS.fs_type) */
586 #define FS_FAT12	1
587 #define FS_FAT16	2
588 #define FS_FAT32	3
589 
590 /* File attribute bits for directory entry (FILINFO.fattrib) */
591 #define	AM_RDO	0x01	/* Read only */
592 #define	AM_HID	0x02	/* Hidden */
593 #define	AM_SYS	0x04	/* System */
594 #define AM_DIR	0x10	/* Directory */
595 #define AM_ARC	0x20	/* Archive */
596 #define AM_LNK	0x80	/* Symbol link */
597 
598 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
599 #define FS_PARENT	0x00
600 #define FS_CHILD	0x01
601 
602 #define FS_VIRENABLE	0x01
603 #define FS_VIRDISABLE	0x00
604 
605 #define PARENTFS(fs)	((FATFS*)((fs)->parent_fs))
606 #define CHILDFS(fs, i)	((FATFS*)(*((fs)->child_fs + (i))))
607 #endif
608 
609 #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
610 /* Global Data Area @ 0x00 - 0x31 (32 Bytes) */
611 #define VR_ITEMSIZE				0x20
612 #define VR_GLOBAL				0x00
613 #define VR_PartitionCnt				0x00	/* Virtual Partition Amount */
614 #define VR_PartitionFSType			0x01	/* Filesystem Type (1 Byte) */
615 #define VR_PartitionStSec			0x02	/* Partition Start Sector (4 Bytes) */
616 #define VR_PartitionCtSec			0x06	/* Partition Sectors Count (4 Bytes) */
617 #define VR_PartitionClstSz			0x0A	/* Partition Clust Size (2 Bytes) */
618 #define VR_PartitionCtClst			0x0C	/* Partition Clust Amount (4 Bytes) */
619 /* Each Virtual Partition Area (32 Bytes) */
620 /* Start offset at 0x20, Each entry is at 32 Bytes */
621 #define VR_PARTITION				0x20
622 #define VR_Available				0x00	/* Vritual Partition Item Flag (1 Bytes) */
623 #define VR_StartClust				0x01	/* Vritual Partition Start Cluster (4 Bytes) */
624 #define VR_CountClust				0x05	/* Virtual Partition Cluster Count (4 Bytes) */
625 #define VR_Entry				0x10	/* Virtual Partition Entry Label (16 Bytes) */
626 
627 #define VR_VertifyString			0x1FC	/* Vertify String (4 Bytes), Must be "LITE" */
628 #endif
629 
630 #ifdef __cplusplus
631 }
632 #endif
633 
634 #endif /* FF_DEFINED */
635