Skip to main content

Crate vfat_rs

Crate vfat_rs 

Source
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

CI

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.
  • alloc support — the library relies on the alloc crate (but not std) 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/umount

Then, 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 std it 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)
DirectoryEntry
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.
SectorId
The sector’s index on the block device. TODO: this is fine for now, but the wrapped type should change to usize
TimeManagerNoop
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§

EntryType
The kind of entry to create inside a directory.
VfatRsError
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§

VfatMetadataTrait
Common metadata accessors shared by [File], Directory, and DirectoryEntry.

Type Aliases§

Result
VfatRS result type