A FAT filesystem library implemented in Rust

Rust FAT FS

.

Features:

  • read/write file using standard Read/Write traits
  • read directory contents
  • create/remove file or directory
  • rename/move file or directory
  • read/write file timestamps (updated automatically if chrono feature is enabled)
  • format volume
  • FAT12, FAT16, FAT32 compatibility
  • LFN (Long File Names) extension is supported
  • Basic no_std environment support

Usage

Add this to your Cargo.toml:

[dependencies]
fatfs = "0.4"

and this to your crate root:

extern crate fatfs;

You can start using the fatfs library now:

let img_file = File::open("fat.img")?;
let fs = fatfs::FileSystem::new(img_file, fatfs::FsOptions::new())?;
let root_dir = fs.root_dir();
let mut file = root_dir.create_file("hello.txt")?;
file.write_all(b"Hello World!")?;

Note: it is recommended to wrap the underlying file struct in a buffering/caching object like BufStream from fscommon crate. For example:

extern crate fscommon;
let buf_stream = BufStream::new(img_file);
let fs = fatfs::FileSystem::new(buf_stream, fatfs::FsOptions::new())?;

See more examples in the examples subdirectory.

no_std usage

Add this to your Cargo.toml:

[dependencies]
fatfs = { version = "0.4", default-features = false }

Additional features:

  • lfn - LFN (long file name) support
  • alloc - use alloc crate for dynamic allocation. Needed for API which uses String type. You may have to provide a memory allocator implementation.
  • unicode - use Unicode-compatible case conversion in file names - you may want to have it disabled for lower memory footprint

Note: above features are enabled by default and were designed primarily for no_std usage.

License

The MIT license. See LICENSE.txt.

Issues

Collection of the latest Issues

MathiasKoch

MathiasKoch

2

The current implementation makes it impossible to recover from a CorruptedFileSystem error by formatting filesystem, unless the storage argument of Filesystem::new() implements Clone or similar.

It is also impossible to fix it by implementing Read, Write & friends for &mut storage due to the current IntoStorage that will consume by self...

Another related issue is that storage is not returned in unmount, resulting in it being lost forever in e.g. an embedded system where storage directly correlates to a peripheral.

I have played around with one possible solution, that would be able to fix all of the above issues, but i am not sure if it is a direction you want to go? https://github.com/MathiasKoch/rust-fatfs/commit/6ed236a431a8ec50bcd253bb22be038aa3f60678

If so, i would love to finish it up and make a PR.

Currently it is missing the return of storage on unmounts, an Into implementation for StdIoWrapper and fixing the examples & tests.

MathiasKoch

MathiasKoch

1

Hi!

Could you make a new release to crates.io, with the recent LFN changes?

rafalh

rafalh

enhancement
0

Issue #47 would probably be detected by CI if tests for no_std specific feature sets were run. To make it possible tests needs to be decorated with #[cfg(feature = "foobar")] where needed.

MabezDev

MabezDev

enhancement
8

Currently dropping the fs also drops the inner disk. I think its fairly reasonable to expect to be able remount a filesystem, would you consider adding a non consuming unmount?

Quick demo of what I was thinking:

I suspect a mount function would also have to be added too.

Any suggestions alternative suggestions are welcome.

henrygab

henrygab

enhancement
0

Currently, the long file name (LFN) directory entries are always created. This issue is to track the feature that avoids creating the LFN entries when not needed. Conditions:

  • The file name fits in 8.3 naming convention (e.g., The file name is equal to the generated SFN)
  • Neither the SFN nor the LFN exist in the directory (e.g., no collision of names, likely does not need any change, but need to verify)

(putting TODO list into issues for easier tracking and referencing in pull requests)

Information - Updated Dec 30, 2021

Stars: 115
Forks: 16
Issues: 9

Repositories & Extras

Rust bindings for libinjection

Add libinjection to dependencies of Cargo

Rust bindings for libinjection

Rust bindings for the C++ api of PyTorch

LIghtweight wrapper for pytorch eg libtorch in rust

Rust bindings for the C++ api of PyTorch

Rust leveldb bindings

Almost-complete bindings for leveldb for Rust

Rust leveldb bindings

Rust FUSE - Filesystem in Userspace

Rust library crate for easy implementation of Crate documentation

Rust FUSE - Filesystem in Userspace

Cross-platform filesystem notification library for Rust

Add file-system notifications via this library for Rust

Cross-platform filesystem notification library for Rust

Catfs is a caching filesystem written in Rust

Catfs allows you to have cached access to another (possibly remote)

Catfs is a caching filesystem written in Rust

a tool to analyze file system usage written in Rust

coloured output, according to the LS_COLORS environment variable

a tool to analyze file system usage written in Rust

FUSE (Filesystem in Userspace) for Rust

FUSE-Rust is a FUSE filesystems in userspace

FUSE (Filesystem in Userspace) for Rust

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

This module provides two high level functions, getfacl and setfacl

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

A file abstraction system for Rust

Chicon is a library meant to provide a simple, uniform and universal API interacting with any filesystem

A file abstraction system for Rust

Raw Filesystem API for Rust — enable simpler browsing with ease

RFSAPI requests are made by setting a GET request's X-Raw-Filesystem-API header to 1

Raw Filesystem API for Rust — enable simpler browsing with ease
Facebook Instagram Twitter GitHub Dribbble
Privacy