FAT File System Module
by Alexei A. Frounze


All the code provided herein is made for the illustrative purpose, so the newbies and OS dev starters can learn from something.

The main thing in this package is the FAT file system module, which is the biggest and the most complicated. To show how it works (and to test it as well!) one needs lots of the other things, so the FAT module has actually led to writing a custom implementation of the standard C library (incomplete though), which is a big piece of code itself. I also wrote a test suite with a unit test and additional tools, which helped to test the code, find and fix bugs. Testing turned out to be very interesting as it made me understand better my own code and reveal testability issues.

The FAT code can be built with the freeware 16-bit-capable compilers available on the internet. The test suite can also be built with freeware compilers, though, I actually built it as 32-bit code.

The FAT code is well-commented and structured. It doesn't do any direct disk I/O because the I/O functions are callback functions specified by the user. There're a few other callback functions used for separation of the FAT module from the rest (i.e. I/O and the standard library). So, in general, the code is quite independent of the other stuff. The FAT code is also quite portable as it's built successfully with several different compilers for 16-bit and 32-bit modes of the CPU.

The FAT module features:

For the full information on the status of the module, please see the source code in the files stdio\FAT.c and stdio\FAT.h.

So, here it goes...

Toolset required to build the FAT module, standard C library and sample apps:

1. GNU make utility (from the DJGPP or Cygwin/MinGW package)
Make sure it is this make.exe you run, not the Borland's or anything else.
2. Either of:
a. Borland/Turbo C/C++ and NASM
b. Open Watcom C/C++

Toolset required to build the FAT module and test suite:

1. Either of:
b. Open Watcom C/C++

Building the 16-bit C library (including FAT module) and startup code:

Building the sample 16-bit applications:

Before building the sample 16-bit applications, the C library must be built.

Building the FAT FS module test suite:

Go to the directory stdio\test. Build the test suite with either DJGPP or Open Watcom using the batch files located in that directory (see readme.txt in that directory on how to build the test and tools).

Making a bootable test floppy:

1. Prepare a 3 or 5 inch floppy formatted for use with MSDOS/MSWindows. The floppy doesn't have to be clean, it may still contain some files, they shouldn't be damaged nor should their presence make any problem.
2. Insert the floppy into the drive A:, then run in the subdirectory _boot:
this should put a bootsector capable of loading and running a .COM/.EXE application from a floppy.
3. Copy your application (or FATCMD*.COM or FATCMD*.EXE) to A: under the name of STARTUP.BIN. The bootsector will find this file, load and run.

Making a bootable floppy image:

Use the following batch files to create a bootable 3.5" 1.44 MB floppy image containing the FAT Commander:

mkimage.bat - this will use disk tools built with DJGPP
wmkimage.bat - this will use disk tools built with Open Watcom

The created image (fddab.img or fddaw.img) can either be written to a floppy disk as-is using some other disk tools not contained in this package (e.g. rawwrite) or be used with virtualization software such as Bochs, VMWare Workstation/Server, Virtual PC/Server.

Finally, a bootable CD can be made of the bootable floppy image...

Making a bootable CD (image):

Once you've created a bootable floppy image, you can make a bootable CD out of it. Many CD/DVD burning programs (such as Nero, Sonic Record Now!, etc) can take in the floppy image file when creating a CD/DVD. When this bootable CD is booted, the BIOS creates a virtual/fake floppy drive from the image contained on the CD and boots from it as if it was a real A: drive with a floppy in it.

Alternatively, one can create a bootable ISO CD image from the floppy image. There're also programs for this (such as freeware mkisofs).

You can use the following sample batch files to create the ISO CD images with mkisofs:

mkiso.bat - makes fddab.iso out of fddab.img
wmkiso.bat - makes fddaw.iso out of fddaw.img

The CD images can also be used with the virtualization software or they can be burned onto the CDs.

Enabling/Disabling HDD access and FAT32 writing:

In stdio\mystdio.c macro ONLY_FLOPPIES_SUPPORTED prohibits HDD access In stdio\FAT.c macro WRITING_TO_FAT32_ENABLED enables FAT32 writing

PLEASE NOTE: from now on the HDD ACCESS and FAT32 WRITING ARE ENABLED by default!!!

You will have to rebuild the C library and relink/rebuild your application after making changes in the C library source code.

In closing:

If you find bugs, feel free to report them. The best thing you can do is find a repro and maybe even make a test case in the test suite to show that the problem is indeed in there.


FAT and Standard C library Code fat-2005-01-24.zip
fat-2006-12-03.zip at Ben's page

Have fun

If you want to contact me regarding this doc or anything else, please post a message on the usenet: news:alt.os.development.
To post, use http://groups.google.com/ or http://news.individual.de/.
You can also use the info from the contact information page of this site.

Alexei A. Frounze
December the 3rd, 2006

Hosted by uCoz