Hadris FAT
A comprehensive Rust implementation of the FAT filesystem family with support for FAT12, FAT16, FAT32, long filenames (VFAT), and no-std environments.
Features
- FAT12/16/32 Support - Full read and write support for all FAT variants
- Volume Formatting - Create new FAT12/16/32 volumes with automatic type selection
- Long Filenames (VFAT/LFN) - Support for filenames beyond 8.3 format
- No-std Compatible - Use in bootloaders and custom kernels
- FAT Caching - Optional sector caching for improved performance
- Analysis Tools - Filesystem verification and diagnostic utilities
- ExFAT - Experimental support for exFAT (work in progress)
Quick Start
Reading a FAT Filesystem
use File;
use BufReader;
use Fat;
let file = open?;
let reader = new;
let fat = open?;
// Read root directory
let root = fat.root_dir;
for entry in root.iter
Writing to a FAT Filesystem
use Fat;
let mut fat = open?;
// Create a new file
let root = fat.root_dir_mut;
let mut file = root.create_file?;
file.write_all?;
Formatting a New FAT Volume
use ;
use Cursor;
// Create a 64 MB in-memory volume
let mut buffer = vec!;
let cursor = new;
// Format with automatic FAT type selection
let options = new
.with_label;
let fs = format?;
println!;
// Or force a specific FAT type
let options = new
.with_fat_type
.with_label;
Feature Flags
| Feature | Description | Dependencies |
|---|---|---|
read |
Read operations | None |
write |
Write operations | alloc, read |
lfn |
Long filename (VFAT) support | None |
cache |
FAT sector caching for performance | alloc |
tool |
Analysis and verification utilities | alloc, read |
exfat |
ExFAT filesystem support (WIP) | alloc |
alloc |
Heap allocation without full std | alloc crate |
std |
Full standard library support | std, alloc |
Default features: read, write, lfn, std
Volume Formatting
The format module (requires write feature) provides volume formatting capabilities:
use ;
let options = new
.with_label
.with_sector_size
.with_fat_copies;
// Calculate parameters without formatting (for validation)
let params = calculate_params?;
println!;
// Format the volume
let fs = format?;
Automatic FAT type selection follows Microsoft recommendations:
- < 16 MB: FAT12
- 16 MB - 512 MB: FAT16
- > 512 MB: FAT32
For Bootloaders (minimal footprint)
[]
= { = "0.3", = false, = ["read"] }
For Embedded Systems with Heap
[]
= { = "0.3", = false, = ["read", "write", "alloc", "lfn"] }
For Desktop Applications (full features)
[]
= { = "0.3" } # Uses default features
FAT Variant Support
| Variant | Max Volume Size | Max File Size | Cluster Size | Status |
|---|---|---|---|---|
| FAT12 | 32 MB | 32 MB | 512B - 8KB | Supported |
| FAT16 | 2 GB | 2 GB | 2KB - 32KB | Supported |
| FAT32 | 2 TB | 4 GB | 4KB - 32KB | Supported |
| ExFAT | 128 PB | 128 PB | 4KB - 32MB | Experimental |
Long Filename Support
When the lfn feature is enabled, the crate supports VFAT long filenames:
- Filenames up to 255 characters
- Unicode character support
- Automatic fallback to 8.3 short names
- Maintains compatibility with non-LFN implementations
FAT Caching
The cache feature enables intelligent FAT sector caching:
- Reduces redundant disk reads
- Configurable cache size
- Write-through or write-back strategies
- Significant performance improvement for fragmented files
Analysis Tools
The tool feature provides filesystem analysis capabilities:
- Filesystem integrity verification
- Cluster chain validation
- Lost cluster detection
- Fragmentation analysis
- Disk space statistics
Example:
use FatAnalyzer;
let analyzer = new;
let report = analyzer.analyze?;
println!;
println!;
println!;
No-std Compatibility
The crate is designed for no-std environments:
- Core reading functionality requires only
readfeature (no allocations) - Write operations require
allocfeature for buffering - All I/O uses
hadris-iotraits instead ofstd::io - Suitable for bootloaders, embedded systems, and custom kernels
Specification Compliance
Implements the following specifications:
- Microsoft FAT specification
- VFAT (Long Filename) extension
- exFAT specification (partial, experimental)
License
This project is licensed under the MIT license.