/mfat

A minimal FAT I/O library for embedded systems

Primary LanguageCBSD 2-Clause "Simplified" LicenseBSD-2-Clause

⚠️ This repository has moved to: https://gitlab.com/mbitsnbites/mfat

MFAT

MFAT is a minimal I/O library for FAT (File Allocation Table) volumes.

The library has been designed for embedded systems, and its small code and memory footprint makes it suitable for inclusion in firmware/ROM and/or small OS kernels.

Features

  • Works with any storage medium that supports random access block I/O (SD cards, hard drives, raw disk image files, etc).
  • Supports both FAT16 and FAT32.
  • Supports multiple partitions (both MBR and GPT partition tables are supported).
  • Cached I/O (configurable cache size).
  • Small memory footprint.
  • No dynamic memory allocation (only static/BSS).
  • Configurable to tune code and memory requirements.
  • Completely dependency-free.
  • Implemented in portable C99.
  • Easy to integrate into your project (only two files are needed: mfat.h and mfat.c).
  • Familiar and easy-to-use POSIX-like API.
  • Liberal license (BSD-2-Clause).

Limitations

The internal MFAT context is statically allocated, meaning:

  • Only a single device may be mounted at any time.
  • The API is not thread safe.

Also: MFAT is still work-in-progress.

  • Writing is not supported yet.
  • Long file names are not supported yet.

POSIX compatibility

The API of this library is modelled after the POSIX.1-2017 file I/O C API:s.

These are the MFAT functions that are inspired by POSIX functions:

MFAT function POSIX prototype
mfat_close() close()
mfat_closedir() closedir()
mfat_fdopendir() fdopendir()
mfat_fstat() fstat()
mfat_lseek() lseek()
mfat_open() open()
mfat_opendir() opendir()
mfat_read() read()
mfat_readdir() readdir()
mfat_stat() stat()
mfat_sync() sync()
mfat_write() write()

Note that the library is not fully POSIX compliant. For instance:

  • Names of functions, types, and macros differ (an mfat_/MFAT_ prefix is used).
  • Some types are different (e.g. date/time types and sizes/names of integral types).
  • Some semantics are slightly different.
  • Some functionality is missing.
  • errno is not supported.

While the library itself is not fully POSIX compliant, it is suitable as a low level I/O implementation layer for higher level libraries, such as newlib.

It is also easy to modify existing programs that use POSIX I/O routines to use the MFAT library instead.

FAT Documentation

FAT.md