Expand description
vfat-rs is a simple vfat (fat32) implementation in Rust. Use it in your custom kernel or integrate it in your user level application.
§VFAT / FAT32
A simple VFAT implementation written in rust, and mostly tested against Linux’s vfat driver.
It aims to be straightforward to understand and easy to use in a custom kernel.
It supports all the basic operations:
- File and directory creation,
- File reading and writing,
- Directory and file deletion,
- Metadata updates,
- Backup FAT writing
- Deleted clusters and directory entry slots are reused.
It needs better support for defragmentation — there is no defragmentation tool to consolidate free space.
§no_std
This component was first developed with no_std in mind. std is supported behind a feature flag, and it is used
for integration testing.
§Using it in your kernel
The exported apis are in the api module. The OS should provide:
- An implementation for the
TimeManagerTrait. This is used for timestamping file creation and update. - An implementation for the device trait. This is used to interact with the disk.
allocsupport — the library relies on thealloccrate (but notstd) for heap-allocated types; like Box, Arc and String.
§Run example
The example runs in userspace. To run the example, first create a vfat fs using the script tests/setup.sh. This script:
- creates a vfat fs,
- mounts it,
- writes a bunch of files and directories (using your kernel’s driver)
- unmounts it.
This file is also used for running integration tests. Your user needs sudo access for mount and unmount commands:
fponzi ALL=(ALL) NOPASSWD: /usr/bin/mount,/usr/bin/umountThen, you’re ready to run the example file using:
cargo run --example simple --features std§Benchmarks
CI runs benchmarks on every push to master and publishes historical results with trend charts to the benchmark dashboard. If a benchmark regresses by more than 50%, an alert comment is created automatically.
Re-exports§
pub use traits::BlockDevice;pub use traits::TimeManagerTrait;
Modules§
- io
- I/O traits and error types.
I/O traits. With
stdit uses the std io module’s types, otherwise uses a custom no_std-compatible implementation. - mbr
- Master Boot Record parsing. A simple Master Booot Record implementation.
- traits
- OS-integration traits (
BlockDevice,TimeManagerTrait). Traits that the user must implement.
Macros§
- const_
assert - A const time assertion.
- const_
assert_ eq - A compile time equality assertion
- const_
assert_ size - A compile time size assertion. Can be used to check the actual struct size.
usage:
const_assert_size!(
, ); const_assert_size!(FatEntry, 8); - defbit
- Given a type bit, ease the bit fields manipulation.
- define_
bitfield - Used in Defreg and Defbit for creating fields.
- define_
mask - Generates a bitmask.
Structs§
- Directory
- A directory is composed of “DirectoryEntry” elements. Every directory has at least two pseudo directories: “.” (current directory) and “..” (parent directory)
- Directory
Entry - A directory entry: either a file or a directory.
- Metadata
- Metadatas are common to every entry type.
- PathBuf
- A simple implementation of PathBuf. Vfat uses utf8/utf16 for encoding: https://wiki.gentoo.org/wiki/FAT/en#UTF-8.2FUTF-16_character_hardware_bugs therefore it’s ok to use a String as a baking data structure.
- Sector
Id - The sector’s index on the block device. TODO: this is fine for now, but the wrapped type should change to usize
- Time
Manager Noop - A no-op implementation of TimeManagerTrait. It will use 0 as the current timestamp. Useful if you don’t care about timestamps or don’t have a timer implementation yet.
- VfatFS
- Main entry point for your VFAT filesystem.
Enums§
- Entry
Type - The kind of entry to create inside a directory.
- Vfat
RsError - Errors that can occur during VFAT filesystem operations.
Constants§
- SECTOR_
SIZE - Sector size in bytes. Hardcoded to 512 as virtually all FAT32 media uses this size.
Traits§
- Vfat
Metadata Trait - Common metadata accessors shared by [
File],Directory, andDirectoryEntry.
Type Aliases§
- Result
- VfatRS result type