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