fat32-raw

Crates.iofat32-raw
lib.rsfat32-raw
version1.0.1
created_at2025-06-20 20:36:07.512984+00
updated_at2025-11-14 14:08:50.798108+00
descriptionCross-platform Rust library for direct FAT32 partition manipulation with ESP support
homepagehttps://github.com/meowrch/fat32-raw
repositoryhttps://github.com/meowrch/fat32-raw
max_upload_size
id1720191
size214,519
DIMFLIX (DIMFLIX)

documentation

https://docs.rs/fat32-raw

README

FAT32-Raw πŸš€



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.

✨ Key features

🎯 Core capabilities

  • 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)

πŸ”§ Technical advantages

  • Safety: Minimal use of unsafe code, 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

πŸš€ Quick start

Working with a disk image

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(())
}

Working with a real ESP partition

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(())
}

πŸ“¦ Installation

Add to Cargo.toml:

[dependencies]
fat32-raw = "1.0"

πŸ§ͺ Testing

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_test

πŸ—οΈ Project structure

fat32-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

🚧 Roadmap

  • 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

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a branch for your changes
  3. Make sure all tests pass
  4. Open a pull request

πŸ“„ License

This project is distributed under the GPLv3 license.

πŸ™ Acknowledgements

  • The Rust community for great tools and documentation
  • The authors of the FAT32 specification from Microsoft
  • All project contributors and users

Made with ❀️ using Rust
Commit count: 0

cargo fmt