Skip to main content

Filesystem

Struct Filesystem 

Source
pub struct Filesystem<'a> { /* private fields */ }
Expand description

Read-only view over a littlefs disk image or block device.

Slice-backed mounts are still valuable for fixtures, corruption tests, and C-oracle artifacts that already exist as complete images. The block-device mount path, however, deliberately borrows the device and reads blocks on demand, so normal read-only user semantics do not require copying a whole flash image into RAM.

Implementations§

Source§

impl<'a> Filesystem<'a>

Source

pub fn mount(image: &'a [u8], cfg: Config) -> Result<Self>

Mounts an existing littlefs image by reading the root metadata pair {0, 1} and validating the superblock entry.

Source

pub fn mount_with_options( image: &'a [u8], cfg: Config, options: FilesystemOptions, ) -> Result<Self>

Mounts an existing image with explicit littlefs-style options.

Source

pub fn mount_device<D: BlockDevice + 'a>(device: &'a D) -> Result<Self>

Mounts a read-only view by borrowing a block device.

Unlike the fixture-oriented mount(&[u8]) path, this does not copy the complete device into an owned Vec. Metadata and CTZ data blocks are fetched through BlockDevice::read as user operations need them. The returned filesystem therefore cannot outlive the device reference.

Source

pub fn mount_device_with_options<D: BlockDevice + 'a>( device: &'a D, options: FilesystemOptions, ) -> Result<Self>

Mounts a read-only block-device view with explicit cache and limit options. The limit fields are used like C littlefs’ mount-time maximums: an image whose superblock advertises larger limits is rejected.

Source

pub fn info(&self) -> &FsInfo

Source

pub fn options(&self) -> FilesystemOptions

Source

pub fn limits(&self) -> FilesystemLimits

Source

pub fn directory_usage(&self, path: &str) -> Result<DirectoryUsage>

Source

pub fn root_entries(&self) -> Result<Vec<DirEntry>>

Source

pub fn read_dir(&self, path: &str) -> Result<Vec<DirEntry>>

Source

pub fn read_dir_with<F>(&self, path: &str, visitor: F) -> Result<()>
where F: FnMut(DirEntry) -> Result<()>,

Visits directory entries without allocating the public result Vec.

The parser still folds one metadata pair at a time internally, but callers that only need to stream names or count entries no longer have to materialize the complete directory listing. read_dir is intentionally kept as the convenient collecting wrapper.

Source

pub fn open_dir<'fs>(&'fs self, path: &str) -> Result<DirHandle<'fs, 'a>>

Source

pub fn stat(&self, path: &str) -> Result<DirEntry>

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>>

Source

pub fn read_file_into(&self, path: &str, out: &mut [u8]) -> Result<usize>

Reads a file into a caller-provided buffer and returns the byte count.

This is the embedded-facing full-file read shape. It uses the normal metadata/path machinery internally, but file contents do not require allocating a result Vec. If the buffer is too small, no partial-read contract is promised; callers get NoSpace and can retry with the size reported by stat.

Source

pub fn read_file_at( &self, path: &str, offset: usize, out: &mut [u8], ) -> Result<usize>

Reads a range from a file without materializing the whole file.

This is the read-only counterpart to the mutable file-handle streaming path. It follows littlefs’ visible read semantics: offsets at or beyond EOF return zero, and short tail reads return only the remaining bytes.

Source

pub fn read_attr(&self, path: &str, attr_type: u8) -> Result<Vec<u8>>

Source

pub fn read_attr_into( &self, path: &str, attr_type: u8, out: &mut [u8], ) -> Result<usize>

Reads a user attribute into caller-owned storage.

This mirrors read_file_into: a missing attr returns NotFound, and a too-small output buffer returns NoSpace without copying a truncated value. The return value is the number of bytes written.

Source

pub fn walk(&self, path: &str) -> Result<Vec<WalkEntry>>

Source

pub fn walk_with<F>(&self, path: &str, visitor: F) -> Result<()>
where F: FnMut(WalkEntry) -> Result<()>,

Recursively visits entries without allocating a full-tree result.

Each directory is still sorted with a short-lived local vector so the callback order matches walk. Avoiding a single full recursive result is enough for embedded callers that stream a manifest or stop early after a match.

Source

pub fn used_blocks(&self) -> Result<Vec<bool>>

Scans the mounted image and returns a bitmap of blocks reachable from metadata pairs, hardtail chains, directory structs, and CTZ files.

This is intentionally conservative: both sides of every metadata pair are marked used even if only one side currently contains the newest valid commit. That matches littlefs allocation semantics and gives the future mount-and-mutate writer a safe starting point.

Source§

impl Filesystem<'static>

Source

pub fn format_device<D: BlockDevice>(device: &mut D) -> Result<()>

Formats a block device as an empty littlefs image.

The formatted bytes are programmed into the caller’s real block device with erase/program/sync operations, so tests exercise the public device boundary instead of only comparing an in-memory Vec.

Source

pub fn format_device_with_options<D: BlockDevice>( device: &mut D, options: FilesystemOptions, ) -> Result<()>

Formats a block device using explicit littlefs-style options.

Source

pub fn mount_device_mut<D: BlockDevice + 'static>( device: D, ) -> Result<FilesystemMut<D>>

Mounts a block device for mutation.

Write methods will be added to FilesystemMut in small C-verified milestones. Today this establishes the API ownership model and ensures callers can format, mount, inspect, sync, and recover the underlying device without dropping down to image bytes.

Source

pub fn mount_device_mut_with_options<D: BlockDevice + 'static>( device: D, options: FilesystemOptions, ) -> Result<FilesystemMut<D>>

Mounts a block device for mutation with explicit littlefs-style options.

Trait Implementations§

Source§

impl<'a> Clone for Filesystem<'a>

Source§

fn clone(&self) -> Filesystem<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Filesystem<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Filesystem<'a>

§

impl<'a> !RefUnwindSafe for Filesystem<'a>

§

impl<'a> !Send for Filesystem<'a>

§

impl<'a> !Sync for Filesystem<'a>

§

impl<'a> Unpin for Filesystem<'a>

§

impl<'a> UnsafeUnpin for Filesystem<'a>

§

impl<'a> !UnwindSafe for Filesystem<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.