Crate simple_fatfs

source ·
Expand description

§simple-fatfs

An easy-to-use FAT filesystem library designed for usage in embedded systems

§Features

  • no_std support
  • FAT12/16/32 support
  • VFAT/LFN (long filenames) support
  • Auto-impls for std::io traits and structs
  • Easy-to-implement io traits

§Examples

extern crate simple_fatfs;
use simple_fatfs::*;
use simple_fatfs::io::prelude::*;

const FAT_IMG: &[u8] = include_bytes!("../imgs/fat12.img");

fn main() {
    let mut cursor = std::io::Cursor::new(FAT_IMG.to_owned());

    // We can either pass by value of by (mutable) reference
    let mut fs = FileSystem::from_storage(&mut cursor).unwrap();

    // Let's see what entries are in the root directory
    for entry in fs.read_dir(PathBuf::from("/")).unwrap() {
        if entry.path().is_dir() {
            println!("Directory: {}", entry.path())
        } else if entry.path().is_file() {
            println!("File: {}", entry.path())
        } else {
            unreachable!()
        }
    }

    // the image we currently use has a file named "root.txt"
    // in the root directory. Let's read it

    // please keep in mind that opening a `File` borrows
    // the parent `FileSystem` until that `File` is dropped
    let mut file = fs.get_file(PathBuf::from("/root.txt")).unwrap();
    let mut string = String::new();
    file.read_to_string(&mut string);
    println!("root.txt contents:\n{}", string);
}

Modules§

  • This module contains all the IO-related objects of the crate

Structs§

  • A list of the various attributes specified for a file/directory
  • A thin wrapper for Properties represing a directory entry
  • A file within the FAT filesystem
  • An API to process a FAT filesystem
  • Represents an owned, mutable path
  • A container for file/directory properties

Enums§

  • An enum representing different versions of the FAT filesystem
  • An error indicating that a filesystem-related operation has failed
  • An error type that denotes that there is something wrong with the filesystem’s structure itself (perhaps the FS itself is malformed/corrupted)

Constants§

  • A list of all the characters that are forbidden to exist in a filename
  • A list of all filenames that are reserved in Windows (and should probably also not be used by FAT)

Traits§

Type Aliases§