RDCF2 - Re-entrant DOS Compatible Filesystem
I came across the mention of
fat-filesystem-rdcf2.txt
while on a special interest mailing list of
the Philips LPC2000 series processors. RDCF2 was written by Philip J. Erdelsky,
apparently in September of 1992,
and he then placed it into Public Domain. While the source is written
for an early TurboC (?) MSDOS development system, it ports rather easily
to a GNU gcc compiler.
While this DOS filesystem is fairly complete, it did lack some refinements
needed before it can be used in an embedded system. Source for a sector
cache was part of the original release.
Unfortunately, we don't have a lot of spare RAM in most controllers, so I had to throw the cache code away. without a cache, the performance is quite acceptable, a 512K file can be written in slightly less than 4 seconds.
However, it must be noted that this is a rather complete implementation of a
DOS (Disk Operating System) as it also has simple commands such as: copy, dir, del, etc.. While these commands are not immediately usefull to me, I've retained
a copy of the original source so that others may benefit from it.
TopNot all cards are the same!
Interesting to note that the write times for SD/MMC cards appears to vary widely.
These are the times to delete a 512K file, then write a new 512K file:
SanDisk 1Gig capacity: 4 seconds
Lexar 128Meg capacity: 5 seconds
Memorex 128Meg capacity: 27 seconds!
I did expect some variation but not this
huge difference between brands!
TopThe implemented functions
fopen() - open file for reading / writing
fclose() - close file
unlink() - delete a file
rename() - rename file to a new name
fputs() - write string to file
fputc() - write character to file
fwrite() - write a block of data to file
fgets() - read string from file
fgetc() - read character from file
fread() - read a block of data from file
fseek() - seek to position in file (SEEK_SET)
ftell() - report of position within file
fflushdir((FILE *)fp) - flushes cached data to directory
note: above functions are standard calls, except where shown with parameter list
TopNewLib, file streams and RDCF2
The original idea was to take NewLib and connect up the re-entrant stubs of
the file streams to some DOS layer to implement an SD/MMC filesystem.
Something to store files on so that the controller can read and write to
the SD/MMC drive.
I started to write my own FAT filesystem layer, while tedious to do,
it is not that complex. However, when I discovered the RDCF2 and examined the
quality of the source, it was quickly apparent that it would meet my needs!
TopThe Device Module Layer
Between the NewLib stubs and the devices (SD/MMC, UARTs, etc.) is a device layer.
The device layer does the task of qualifying parms handed it by NewLib,
translates them into actions and posts errno back to NewLib.
The code that I've come up with should be a clean interface between NewLib,
RDCF2 and the SD/MMC card. The re-entrant stub code passes through a device
layer I've written, is qualified, then passes to the appropriate device
module handler. Device Module code implements only the common basics:
open, close, read, write, init, and ioctl. The ioctl entry is the
point at which uncommon functionality, such as fseek() and unlink(), gets done.
As to the development environment: binutils-2.15, gcc-4.0.2, newlib-1.13.0,
and Insight-6.1 were used.
Refer to my page on how to replicate my development environment.
I use Mandriva Linux 10.2 (Limited Edition 2005) as a development host,
you probably can use cygwin, however YMMV. ;-)
views: