Skip to content

Commit c546b66

Browse files
committed
lib/fatfs: Upgrade to new FatFs driver, put in lib/ for common use.
Patches to fatfs for our use will follow.
1 parent 83204f3 commit c546b66

14 files changed

Lines changed: 36633 additions & 0 deletions

File tree

lib/fatfs/00readme.txt

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
FatFs Module Source Files R0.10c (C)ChaN, 2014
2+
3+
4+
FILES
5+
6+
ffconf.h Configuration file for FatFs module.
7+
ff.h Common include file for FatFs and application module.
8+
ff.c FatFs module.
9+
diskio.h Common include file for FatFs and disk I/O module.
10+
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
11+
integer.h Integer type definitions for FatFs.
12+
option Optional external functions.
13+
14+
Low level disk I/O module is not included in this archive because the FatFs
15+
module is only a generic file system layer and not depend on any specific
16+
storage device. You have to provide a low level disk I/O module that written
17+
to control your storage device.
18+
19+
20+
21+
AGREEMENTS
22+
23+
FatFs module is an open source software to implement FAT file system to
24+
small embedded systems. This is a free software and is opened for education,
25+
research and commercial developments under license policy of following trems.
26+
27+
Copyright (C) 2014, ChaN, all right reserved.
28+
29+
* The FatFs module is a free software and there is NO WARRANTY.
30+
* No restriction on use. You can use, modify and redistribute it for
31+
personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
32+
* Redistributions of source code must retain the above copyright notice.
33+
34+
35+
36+
REVISION HISTORY
37+
38+
Feb 26, 2006 R0.00 Prototype
39+
40+
Apr 29, 2006 R0.01 First release.
41+
42+
Jun 01, 2006 R0.02 Added FAT12.
43+
Removed unbuffered mode.
44+
Fixed a problem on small (<32M) patition.
45+
46+
Jun 10, 2006 R0.02a Added a configuration option _FS_MINIMUM.
47+
48+
Sep 22, 2006 R0.03 Added f_rename.
49+
Changed option _FS_MINIMUM to _FS_MINIMIZE.
50+
51+
Dec 11, 2006 R0.03a Improved cluster scan algolithm to write files fast.
52+
Fixed f_mkdir creates incorrect directory on FAT32.
53+
54+
Feb 04, 2007 R0.04 Supported multiple drive system. (FatFs)
55+
Changed some APIs for multiple drive system.
56+
Added f_mkfs. (FatFs)
57+
Added _USE_FAT32 option. (Tiny-FatFs)
58+
59+
Apr 01, 2007 R0.04a Supported multiple partitions on a plysical drive. (FatFs)
60+
Fixed an endian sensitive code in f_mkfs. (FatFs)
61+
Added a capability of extending the file size to f_lseek.
62+
Added minimization level 3.
63+
Fixed a problem that can collapse a sector when recreate an
64+
existing file in any sub-directory at non FAT32 cfg. (Tiny-FatFs)
65+
66+
May 05, 2007 R0.04b Added _USE_NTFLAG option.
67+
Added FSInfo support.
68+
Fixed some problems corresponds to FAT32. (Tiny-FatFs)
69+
Fixed DBCS name can result FR_INVALID_NAME.
70+
Fixed short seek (0 < ofs <= csize) collapses the file object.
71+
72+
Aug 25, 2007 R0.05 Changed arguments of f_read, f_write.
73+
Changed arguments of f_mkfs. (FatFs)
74+
Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
75+
Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs)
76+
77+
Feb 03, 2008 R0.05a Added f_truncate().
78+
Added f_utime().
79+
Fixed off by one error at FAT sub-type determination.
80+
Fixed btr in f_read() can be mistruncated.
81+
Fixed cached sector is not flushed when create and close without write.
82+
83+
Apr 01, 2008 R0.06 Added f_forward(). (Tiny-FatFs)
84+
Added string functions: fputc(), fputs(), fprintf() and fgets().
85+
Improved performance of f_lseek() on move to the same or following cluster.
86+
87+
Apr 01, 2009, R0.07 Merged Tiny-FatFs as a buffer configuration option.
88+
Added long file name support.
89+
Added multiple code page support.
90+
Added re-entrancy for multitask operation.
91+
Added auto cluster size selection to f_mkfs().
92+
Added rewind option to f_readdir().
93+
Changed result code of critical errors.
94+
Renamed string functions to avoid name collision.
95+
96+
Apr 14, 2009, R0.07a Separated out OS dependent code on reentrant cfg.
97+
Added multiple sector size support.
98+
99+
Jun 21, 2009, R0.07c Fixed f_unlink() may return FR_OK on error.
100+
Fixed wrong cache control in f_lseek().
101+
Added relative path feature.
102+
Added f_chdir().
103+
Added f_chdrive().
104+
Added proper case conversion for extended characters.
105+
106+
Nov 03, 2009 R0.07e Separated out configuration options from ff.h to ffconf.h.
107+
Added a configuration option, _LFN_UNICODE.
108+
Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH.
109+
Fixed name matching error on the 13 char boundary.
110+
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
111+
112+
May 15, 2010, R0.08 Added a memory configuration option. (_USE_LFN)
113+
Added file lock feature. (_FS_SHARE)
114+
Added fast seek feature. (_USE_FASTSEEK)
115+
Changed some types on the API, XCHAR->TCHAR.
116+
Changed fname member in the FILINFO structure on Unicode cfg.
117+
String functions support UTF-8 encoding files on Unicode cfg.
118+
119+
Aug 16,'10 R0.08a Added f_getcwd(). (_FS_RPATH = 2)
120+
Added sector erase feature. (_USE_ERASE)
121+
Moved file lock semaphore table from fs object to the bss.
122+
Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
123+
Fixed f_mkfs() creates wrong FAT32 volume.
124+
125+
Jan 15,'11 R0.08b Fast seek feature is also applied to f_read() and f_write().
126+
f_lseek() reports required table size on creating CLMP.
127+
Extended format syntax of f_printf function.
128+
Ignores duplicated directory separators in given path names.
129+
130+
Sep 06,'11 R0.09 f_mkfs() supports multiple partition to finish the multiple partition feature.
131+
Added f_fdisk(). (_MULTI_PARTITION = 2)
132+
133+
Aug 27,'12 R0.09a Fixed assertion failure due to OS/2 EA on FAT12/16.
134+
Changed f_open() and f_opendir() reject null object pointer to avoid crash.
135+
Changed option name _FS_SHARE to _FS_LOCK.
136+
137+
Jan 23,'13 R0.09b Added f_getlabel() and f_setlabel(). (_USE_LABEL)
138+
139+
Oct 02,'13 R0.10 Added selection of character encoding on the file. (_STRF_ENCODE)
140+
Added f_closedir().
141+
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
142+
Added forced mount feature with changes of f_mount().
143+
Improved behavior of volume auto detection.
144+
Improved write throughput of f_puts() and f_printf().
145+
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
146+
Fixed f_write() can be truncated when the file size is close to 4GB.
147+
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
148+
149+
Jan 15,'14 R0.10a Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
150+
Added a configuration option of minimum sector size. (_MIN_SS)
151+
2nd argument of f_rename() can have a drive number and it will be ignored.
152+
Fixed f_mount() with forced mount fails when drive number is >= 1.
153+
Fixed f_close() invalidates the file object without volume lock.
154+
Fixed f_closedir() returns but the volume lock is left acquired.
155+
Fixed creation of an entry with LFN fails on too many SFN collisions.
156+
157+
Mar 19,'14 R0.10b Fixed a hard error in the disk I/O layer can collapse the directory entry.
158+
Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN.
159+
160+
Nov 09,'14 R0.10c Added a configuration option for the platforms without RTC. (_FS_NORTC)
161+
Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel().
162+
Fixed a potential problem of FAT access that can appear on disk error.
163+
Fixed null pointer dereference on attempting to delete the root direcotry.

lib/fatfs/diskio.c

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*-----------------------------------------------------------------------*/
2+
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
3+
/*-----------------------------------------------------------------------*/
4+
/* If a working storage control module is available, it should be */
5+
/* attached to the FatFs via a glue function rather than modifying it. */
6+
/* This is an example of glue functions to attach various exsisting */
7+
/* storage control modules to the FatFs module with a defined API. */
8+
/*-----------------------------------------------------------------------*/
9+
10+
#include "diskio.h" /* FatFs lower layer API */
11+
#include "usbdisk.h" /* Example: USB drive control */
12+
#include "atadrive.h" /* Example: ATA drive control */
13+
#include "sdcard.h" /* Example: MMC/SDC contorl */
14+
15+
/* Definitions of physical drive number for each drive */
16+
#define ATA 0 /* Example: Map ATA drive to drive number 0 */
17+
#define MMC 1 /* Example: Map MMC/SD card to drive number 1 */
18+
#define USB 2 /* Example: Map USB drive to drive number 2 */
19+
20+
21+
/*-----------------------------------------------------------------------*/
22+
/* Get Drive Status */
23+
/*-----------------------------------------------------------------------*/
24+
25+
DSTATUS disk_status (
26+
BYTE pdrv /* Physical drive nmuber to identify the drive */
27+
)
28+
{
29+
DSTATUS stat;
30+
int result;
31+
32+
switch (pdrv) {
33+
case ATA :
34+
result = ATA_disk_status();
35+
36+
// translate the reslut code here
37+
38+
return stat;
39+
40+
case MMC :
41+
result = MMC_disk_status();
42+
43+
// translate the reslut code here
44+
45+
return stat;
46+
47+
case USB :
48+
result = USB_disk_status();
49+
50+
// translate the reslut code here
51+
52+
return stat;
53+
}
54+
return STA_NOINIT;
55+
}
56+
57+
58+
59+
/*-----------------------------------------------------------------------*/
60+
/* Inidialize a Drive */
61+
/*-----------------------------------------------------------------------*/
62+
63+
DSTATUS disk_initialize (
64+
BYTE pdrv /* Physical drive nmuber to identify the drive */
65+
)
66+
{
67+
DSTATUS stat;
68+
int result;
69+
70+
switch (pdrv) {
71+
case ATA :
72+
result = ATA_disk_initialize();
73+
74+
// translate the reslut code here
75+
76+
return stat;
77+
78+
case MMC :
79+
result = MMC_disk_initialize();
80+
81+
// translate the reslut code here
82+
83+
return stat;
84+
85+
case USB :
86+
result = USB_disk_initialize();
87+
88+
// translate the reslut code here
89+
90+
return stat;
91+
}
92+
return STA_NOINIT;
93+
}
94+
95+
96+
97+
/*-----------------------------------------------------------------------*/
98+
/* Read Sector(s) */
99+
/*-----------------------------------------------------------------------*/
100+
101+
DRESULT disk_read (
102+
BYTE pdrv, /* Physical drive nmuber to identify the drive */
103+
BYTE *buff, /* Data buffer to store read data */
104+
DWORD sector, /* Sector address in LBA */
105+
UINT count /* Number of sectors to read */
106+
)
107+
{
108+
DRESULT res;
109+
int result;
110+
111+
switch (pdrv) {
112+
case ATA :
113+
// translate the arguments here
114+
115+
result = ATA_disk_read(buff, sector, count);
116+
117+
// translate the reslut code here
118+
119+
return res;
120+
121+
case MMC :
122+
// translate the arguments here
123+
124+
result = MMC_disk_read(buff, sector, count);
125+
126+
// translate the reslut code here
127+
128+
return res;
129+
130+
case USB :
131+
// translate the arguments here
132+
133+
result = USB_disk_read(buff, sector, count);
134+
135+
// translate the reslut code here
136+
137+
return res;
138+
}
139+
140+
return RES_PARERR;
141+
}
142+
143+
144+
145+
/*-----------------------------------------------------------------------*/
146+
/* Write Sector(s) */
147+
/*-----------------------------------------------------------------------*/
148+
149+
#if _USE_WRITE
150+
DRESULT disk_write (
151+
BYTE pdrv, /* Physical drive nmuber to identify the drive */
152+
const BYTE *buff, /* Data to be written */
153+
DWORD sector, /* Sector address in LBA */
154+
UINT count /* Number of sectors to write */
155+
)
156+
{
157+
DRESULT res;
158+
int result;
159+
160+
switch (pdrv) {
161+
case ATA :
162+
// translate the arguments here
163+
164+
result = ATA_disk_write(buff, sector, count);
165+
166+
// translate the reslut code here
167+
168+
return res;
169+
170+
case MMC :
171+
// translate the arguments here
172+
173+
result = MMC_disk_write(buff, sector, count);
174+
175+
// translate the reslut code here
176+
177+
return res;
178+
179+
case USB :
180+
// translate the arguments here
181+
182+
result = USB_disk_write(buff, sector, count);
183+
184+
// translate the reslut code here
185+
186+
return res;
187+
}
188+
189+
return RES_PARERR;
190+
}
191+
#endif
192+
193+
194+
/*-----------------------------------------------------------------------*/
195+
/* Miscellaneous Functions */
196+
/*-----------------------------------------------------------------------*/
197+
198+
#if _USE_IOCTL
199+
DRESULT disk_ioctl (
200+
BYTE pdrv, /* Physical drive nmuber (0..) */
201+
BYTE cmd, /* Control code */
202+
void *buff /* Buffer to send/receive control data */
203+
)
204+
{
205+
DRESULT res;
206+
int result;
207+
208+
switch (pdrv) {
209+
case ATA :
210+
211+
// Process of the command for the ATA drive
212+
213+
return res;
214+
215+
case MMC :
216+
217+
// Process of the command for the MMC/SD card
218+
219+
return res;
220+
221+
case USB :
222+
223+
// Process of the command the USB drive
224+
225+
return res;
226+
}
227+
228+
return RES_PARERR;
229+
}
230+
#endif

0 commit comments

Comments
 (0)