Crate simple_fatfs

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

§Usage

The library uses embedded-io for IO operations. Most notably, the storage medium is expected to implement at least the Read and Seek traits (RO storage), while Write is optional (R/W storage). Furthermore, ROFile & RWFile both implement Read & Seek, while RWFile also implements Write

To use std::io’s respective traits, use the embedded-io-adapters crate.

§Examples

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

use embedded_io_adapters::std::FromStd;

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

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

    // We can either pass by value or by (mutable) reference
    // (Yes, the storage medium might be Read-Only, but reading is a mutable action)
    let mut fs = FileSystem::new(&mut cursor, FSOptions::new()).unwrap();

    // Let's see what entries there are in the root directory
    for entry in fs.read_dir("/").unwrap() {
        // in a real world example, you probably don't wanna unwrap this
        let entry = entry.unwrap();

        if entry.is_dir() {
            println!("Directory: {}", entry.path())
        } else if entry.is_file() {
            println!("File: {}", entry.path())
        } else {
            unreachable!()
        }
    }

    // the disk image we currently use has a file named "root.txt"
    // in the root directory. Let's read it
    let mut file = fs.get_ro_file("/root.txt").unwrap();
    let mut file_buf = vec![0; file.file_size() as usize];
    file.read_exact(&mut file_buf).unwrap();
    let string = str::from_utf8(&file_buf).unwrap();
    println!("root.txt contents:\n{}", string);
}

Re-exports§

pub use embedded_io as io;

Structs§

Attributes
A list of the various attributes specified for a file/directory
DefaultClock
The default Clock component
DirEntry
A thin wrapper for Properties representing a directory entry
FSOptions
FileSystem mount options
FileSystem
An API to process a FAT filesystem
Properties
A container for file/directory properties
ROFile
A read-only file within a FAT filesystem
RWFile
A read-write file within a FAT filesystem
ReadDir
Iterator over the entries in a directory.

Enums§

BincodeError
An encode/decode-related error
Codepage
Windows codepage to use for encoding/decoding short filenames
FATType
An enum representing different variants of the FAT filesystem
FSError
An error indicating that a filesystem-related operation has failed
InternalFSError
An error type that denotes that there is something wrong with the filesystem’s structure itself (perhaps the FS itself is malformed/corrupted)
RWFileError
A RWFile-exclusive IO error struct

Constants§

EPOCH
The earliest datetime that FAT can use as a creation, access or modification time
MAX_SECTOR_SIZE
The maximum size (in bytes) a sector is allowed to have
MIN_SECTOR_SIZE
The minimum size (in bytes) a sector is allowed to have

Traits§

Clock
An object that can measure and return the current time

Type Aliases§

FSResult
An alias for a Result with a FSError error type
Path
Represents a Windows-specific Utf8Path
PathBuf
Represents a Windows-specific Utf8PathBuf