A fully featured Rust library for direct work with FAT32 partitions and images. Provides low-level access to the FAT32 file system with support for reading, writing, creating and deleting files and directories.
- Direct partition access: Native support for ESP (EFI System Partition), SD cards, USB flash drives
- Cross‑platform: Full support for Windows and Linux with handling of OS‑specific nuances
- Full FAT32 feature set: Read, write, create, delete files and directories
- Nested directories: Support for creating and navigating deeply nested directory structures
- Long file names (LFN): Full Unicode name support up to 255 characters
- Auto parameter detection: Automatic parsing of BPB (BIOS Parameter Block)
- Safety: Minimal use of
unsafecode, strong typing - Performance: Optimized read/write operations with buffering
- Reliability: Proper error handling, protection against data corruption
- Windows specifics: Solves access rights issues (OS Error 5) via special file opening flags
use fat32_raw::Fat32Volume;
fn main() -> std::io::Result<()> {
// Open a FAT32 image
let mut volume = Fat32Volume::open_esp(Some("esp.img"))?
.expect("Failed to open FAT32 image");
// Create directories
volume.create_dir_lfn("config")?;
// Create and write a file
volume.create_file_lfn("test.txt")?;
let content = b"Hello from fat32-raw!";
volume.write_file("test.txt", content)?;
// Read the file back
if let Some(data) = volume.read_file("test.txt")? {
println!("Content: {}", String::from_utf8_lossy(&data));
}
// Delete the file
volume.delete_file_lfn("test.txt")?;
Ok(())
}use fat32_raw::Fat32Volume;
fn main() -> std::io::Result<()> {
// Automatic search and opening of the ESP partition
// On Windows, administrator rights are required
// On Linux, sudo may be required
let mut volume = Fat32Volume::open_esp(None::<&str>)?
.expect("ESP partition not found");
// Work with the partition the same way as with an image
volume.create_dir_lfn("MyApp")?;
volume.create_file_lfn("MyApp_config.txt")?;
volume.write_file("MyApp_config.txt", b"Configuration")?;
// List files in the root
let entries = volume.list_root()?;
for entry in entries {
println!("{} - {}",
entry.name,
if entry.is_directory { "DIR" } else { "FILE" }
);
}
Ok(())
}Add to Cargo.toml:
[dependencies]
fat32-raw = "1.0"The project includes a test suite that covers all operations:
# Run regular tests
cargo test
# Run tests on a real ESP (requires sudo/Administrator)
# WARNING: this test works with a real ESP partition!
sudo cargo test --test real_esp_testfat32-raw/
├── src/
│ ├── lib.rs # Main library module
│ ├── error.rs # Error handling
│ ├── fat32/
│ │ ├── mod.rs # FAT32 module
│ │ ├── volume.rs # Core volume logic
│ │ ├── directory.rs # Directory operations
│ │ ├── file.rs # File operations
│ │ ├── fat_table.rs # FAT table handling
│ │ ├── lfn.rs # Long file name support
│ │ └── utils.rs # Helper functions
│ └── platform/
│ ├── mod.rs # Platform abstractions
│ ├── windows/ # Windows‑specific code
│ └── unix/ # Unix/Linux‑specific code
└── tests/
└── real_esp_test.rs # Integration tests with real ESP
- Support for creating and deleting files and directories
- Automatic ESP partition discovery on disks
- Working with nested directories
- Full integration with Windows and Linux
- Handling access rights issues on Windows
- ⏳ MBR partition support
- ⏳ Defragmentation and optimization
- ⏳ FAT12/FAT16 support
- ⏳ Integration with GitHub Actions CI/CD
Contributions are welcome! Please:
- Fork the repository
- Create a branch for your changes
- Make sure all tests pass
- Open a pull request
This project is distributed under the GPLv3 license.
- The Rust community for great tools and documentation
- The authors of the FAT32 specification from Microsoft
- All project contributors and users
