FAT16/32 File System Library


Designed for low memory embedded systems, this project is a multi-purpose platform independent C code implementation of a FAT16 & FAT32 driver with read write support.
The library provides stdio like interface functions such as fopen(), fgetc(), fputc(), fread(), fwrite() etc, allowing existing applications to be ported easily using a familiar API.
The project is aimed at applications which require file system support such as MP3 playersdata loggers, etc and has a low memory footprint with customizable build options to enable it to run on platforms such as the Atmel AVR, ARM & PIC microcontrollers.

The source code is available for free under GPL license, or alternatively, with a commercial compatible license for a small donation to the project.


– Standard file I/O API (fopen(), fread(), fwrite(), etc)
– FAT16/FAT32 support (read + write)
– Long filename support (optional)
– Format function (optional)
– Directory listing (optional)
– Optional buffering & caching for higher performance
– Open source (Free!)


The following file IO API is provided:

– fopen
– fclose
– fread
– fwrite
– fputc
– fputs
– fgetc
– fflush
– fgetpos
– fseek
– ftell
– feof
– remove

Just add sector read & write functions for the media/platform you are using for a complete file system!


Each release of the project is tested using self verifying test benches to ensure validity and to protect against regressions.


If you would like to use this code in a commercial project with a closed source compatible licence, please contact me…


v2.6.11 – Fix compilation with GCC on 64-bit machines
v2.6.10 – Added support for FAT32 format.
v2.6.9 – Added support for time & date handling.
v2.6.8 – Fixed error with FSINFO sector write.
v2.6.7 – Added fgets(). Fixed C warnings, removed dependency on some string.h functions.
v2.6.6 – Massive read + write performance  improvements.
v2.6.5 – Bug fixes for big endian systems.
v2.6.4 – Further bug fixes and performance improvements for write operations.
v2.6.3 – Performance improvements, FAT16 formatting support. Various bug fixes
v2.6 – Basic support for FAT16 added
v2.5 – Code cleaned up. Many bugs fixed. Thread safety functions added.
v2.x – Write support added as well as better stdio like API.
v1.0 – Rewrite of all code to enable multiple files to be opened and provides a better file API.
v0.1b – fopen(), fgetc(), fopenDIR() using new software stack for IDE drives and FAT32 access.
v0.1a – First release; fopen(), fgetc() unbuffered reads…. (27/12/03)

16 thoughts on “FAT16/32 File System Library

  1. Artem Borisovskiy

    Man, thanks a lot for you great library (:
    I tested about a half of dozen of libraries for FAT32, and none of them worked correctly (if ever worked), but your library required just 2 functions and it’s easy to use. Great job!

  2. Cian O'Mahony

    Hi there,
    I am interested in using this library for a project I am working on which uses Cypress’ Programmable System on Chip 5 (PSoC 5). This chip contains on it an ARM Cortex-M3 processor which this library claims to support. Unfortunately, I am quite inexperienced with incorporating libraries such as this onto a design. Could you perhaps point me in the direction of some useful material which would allow me to easily configure the PSoC to support this library?
    The PSoC has its own IDE called PSoC Creator, which also supports the schematic design of the surrounding logic of the chip. One of the components supported by it is an SPI data transfer component, should I use this or is the SPI transfer dealt with in this library (thus requiring me to simply configure a few input/output pins on the chip)?
    Thank you for your time,
    Cian O’Mahony

  3. Ryan

    I wanted to throw my thanks out there too. This is a wonderful library that is easy to use and works as documented. Thanks for putting it out here for general consumption. I didn’t have any issues getting it to work with my mcu or media drivers.

  4. niosman

    Great job :o)
    Ported it for my NIOS processor in 2 hours, only needed to hook my SPI routines.

    Works like a charm.

    Many thanks.

  5. Tom

    Hi niosman,
    I would like to use the fat library with a PIC32 and a SD Card. When you say you just had to hook in the SPI routines, can you explain further please? Are you referring to byte level transfer?


  6. William

    Great library. Thank you.
    I am a newbie and was wondering if this library supports USB file system. Once again, thank you.

  7. Florent

    Hi, I’m quite new at this. My aim is to use this on Coldfire V2. How the read & write functions should look like ?

    Thanks for your help

  8. Coto

    Everything works as intended… well that was until I wanted to remove a directory.

    So I checked fat_filelib.h:

    #define rmdir(a) 0

    Definitely useful but lacking this makes it about 90% usefull. I Will take a look and see if that could be implemented.


Leave a Reply

Your email address will not be published. Required fields are marked *