How abbrev/fatfs works
Project type and purpose
– Project type: A low-level, open-source file-system library for small embedded systems (FAT12/16/32).
– Purpose: Provide a generic, portable FAT file-system API for applications, abstracting away hardware differences.
File structure
Top-level directories:
• documents/ : HTML user manual, example apps, and reference.
• source/ : Core C modules (ff.c, ffsystem.c, ffunicode.c) and disk I/O stub (diskio.c/.h), plus configuration (ffconf.h).
• LICENSE.txt, README.asc
Key modules in source/:
• ff.c – Public API handlers (f_open, f_read, f_write, etc.)
• ffsystem.c – Internal FS logic (cluster chains, FAT table updates)
• ffunicode.c – Unicode path support
• diskio.c/.h – Abstraction layer to physical media (SD card, SPI flash, etc.)
• ffconf.h – Compile-time configuration (sector size, code page, feature toggles)
README for insights
– Confirms “generic FAT file-system module for small embedded systems.”
– Directs users to a forum for bug reports.
– No built-in example apps in the code tree; examples reside in documents/res as .c files.
Main components to illustrate
A. Application Layer (User Code)
• Example apps (documents/res/*.c) or any embedded application
• Invokes FatFs API: f_mount(), f_open(), f_read(), f_write(), f_close(), etc.
B. FatFs Core Library
• API Interface module (ff.c)
• File-system engine (ffsystem.c)
• Unicode support (ffunicode.c)
C. Configuration
• ffconf.h – Controls features (long-file name support, reentrancy, code page)
D. Disk I/O Abstraction Layer
• diskio.h – Defines drive number, data types, I/O function prototypes
• diskio.c – Weak stub implementations; to be overridden by hardware-specific drivers
E. Hardware/Media
• Physical block devices (SD card, SPI Flash, USB Mass Storage)
• Platform driver code (outside this repo) that implements disk_read(), disk_write(), disk_ioctl()
Relationships and interactions
1. The Application makes calls to the FatFs API in ff.c
2. ff.c calls into ffsystem.c and ffunicode.c, depending on configuration
3. ffsystem.c processes file allocation, directory scanning, FAT updates
4. When ffsystem.c needs to read/write raw sectors, it calls the disk I/O interface functions (disk_read, disk_write, disk_ioctl) defined in diskio.h
5. The target platform provides a diskio.c override or hardware driver to perform actual I/O on the block device
Architectural patterns and design principles
– Layered architecture (API → FS engine → I/O abstraction → Hardware)
– Dependency inversion: FS engine depends on abstract I/O interface, not on concrete hardware
– Single‐responsibility modules: each C file encapsulates a distinct concern
– Configurable features via compile-time flags in ffconf.h