#ext4 #data-source #path #reading #access

no-std ext4-view

No-std compatible Rust library for reading ext2/ext4 filesystems

9 releases (4 breaking)

new 0.6.1 Nov 14, 2024
0.6.0 Nov 11, 2024
0.5.1 Sep 19, 2024
0.4.2 Aug 8, 2024
0.2.0 Jun 27, 2024

#70 in Embedded development

Download history 288/week @ 2024-07-29 147/week @ 2024-08-05 78/week @ 2024-08-12 27/week @ 2024-08-19 43/week @ 2024-08-26 155/week @ 2024-09-02 102/week @ 2024-09-09 618/week @ 2024-09-16 78/week @ 2024-09-23 396/week @ 2024-09-30 130/week @ 2024-10-07 86/week @ 2024-10-14 26/week @ 2024-10-21 21/week @ 2024-10-28 280/week @ 2024-11-04 462/week @ 2024-11-11

791 downloads per month

MIT/Apache

205KB
4K SLoC

ext4-view-rs

Crates.io Docs.rs codecov.io

This repository provides a Rust crate that allows read-only access to an ext4 filesystem. It also works with ext2 filesystems. Write access is an explicit non-goal. The crate is no_std, so it can be used in embedded contexts. However, it does require alloc.

Usage

Add the dependency:

cargo add ext4-view

Basic example:

use ext4_view::{Ext4, Metadata};

// Load the filesystem. The data source can be be anything that
// implements the `Ext4Read` trait. The simplest source is a
// `Vec<u8>` containing the whole filesystem.
let fs_data: Vec<u8> = get_fs_data_from_somewhere();
let fs = Ext4::load(Box::new(fs_data))?;

// If the `std` feature is enabled, you can load a filesystem by path:
let fs = Ext4::load_from_path(std::path::Path::new("some-fs.bin"))?;

// The `Ext4` type has methods very similar to `std::fs`:
let path = "/some/file/path";
let file_data: Vec<u8> = fs.read(path)?;
let file_str: String = fs.read_to_string(path)?;
let exists: bool = fs.exists(path)?;
let metadata: Metadata = fs.metadata(path)?;
for entry in fs.read_dir("/some/dir")? {
    let entry = entry?;
    println!("{}", entry.path().display());
}

Design Goals

In order of importance:

  1. Correct
    • All valid ext2/ext4 filesystems should be readable.
    • Invalid data should never cause crashes, panics, or non-terminating loops.
    • No unsafe code in the main package (it is allowed in dependencies).
    • Well tested.
  2. Easy to use
    • The API should follow the conventions of std::fs where possible.
  3. Good performance
    • Performance should not come at the expense of correctness or ease of use.

Non-goals:

  • Write support.
  • Recovery of corrupt filesystems.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Contributing

See the code of conduct and contributing.md.

Bug reports and PRs are welcome!

Disclaimer

This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.

Dependencies

~205KB