Crate fatfs

source ·
Expand description

A FAT filesystem library implemented in Rust.


This crate is on and can be used by adding fatfs to the dependencies in your project’s Cargo.toml.

fatfs = "0.3"

And this in your crate root:

extern crate fatfs;


// Declare external crates
// Note: `fscommon` crate is used to speedup IO operations
extern crate fatfs;
extern crate fscommon;

use std::io::prelude::*;

fn main() -> std::io::Result<()> {
    // Initialize a filesystem object
    let img_file = std::fs::OpenOptions::new().read(true).write(true)
    let buf_stream = fscommon::BufStream::new(img_file);
    let fs = fatfs::FileSystem::new(buf_stream, fatfs::FsOptions::new())?;
    let root_dir = fs.root_dir();

    // Write a file
    let mut file = root_dir.create_file("foo/hello.txt")?;
    file.write_all(b"Hello World!")?;

    // Read a directory
    let dir = root_dir.open_dir("foo")?;
    for r in dir.iter() {
        let entry = r?;
        println!("{}", entry.file_name());


A DOS compatible date.
A DOS compatible date and time.
A FAT filesystem directory.
A FAT directory entry.
An iterator over the directory entries.
A FAT filesystem file object used for reading and writing data.
A FAT file attributes.
A FAT filesystem object.
A FAT volume statistics.
A FAT filesystem formatting options
A FAT filesystem mount options.
A FAT volume status flags retrived from the Boot Sector and the allocation table second entry.
A DOS compatible time.


A type of FAT filesystem.


An OEM code page encoder/decoder.
A sum of Read and Seek traits.
A sum of Read, Write and Seek traits.
A current time and date provider.


Create FAT filesystem on a disk or partition (format a volume)