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>
impl<'a> Filesystem<'a>
Sourcepub fn mount(image: &'a [u8], cfg: Config) -> Result<Self>
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.
Sourcepub fn mount_with_options(
image: &'a [u8],
cfg: Config,
options: FilesystemOptions,
) -> Result<Self>
pub fn mount_with_options( image: &'a [u8], cfg: Config, options: FilesystemOptions, ) -> Result<Self>
Mounts an existing image with explicit littlefs-style options.
Sourcepub fn mount_device<D: BlockDevice + 'a>(device: &'a D) -> Result<Self>
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.
Sourcepub fn mount_device_with_options<D: BlockDevice + 'a>(
device: &'a D,
options: FilesystemOptions,
) -> Result<Self>
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.
pub fn info(&self) -> &FsInfo
pub fn options(&self) -> FilesystemOptions
pub fn limits(&self) -> FilesystemLimits
pub fn directory_usage(&self, path: &str) -> Result<DirectoryUsage>
pub fn root_entries(&self) -> Result<Vec<DirEntry>>
pub fn read_dir(&self, path: &str) -> Result<Vec<DirEntry>>
Sourcepub fn read_dir_with<F>(&self, path: &str, visitor: F) -> Result<()>
pub fn read_dir_with<F>(&self, path: &str, visitor: F) -> 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.
pub fn open_dir<'fs>(&'fs self, path: &str) -> Result<DirHandle<'fs, 'a>>
pub fn stat(&self, path: &str) -> Result<DirEntry>
pub fn read_file(&self, path: &str) -> Result<Vec<u8>>
Sourcepub fn read_file_into(&self, path: &str, out: &mut [u8]) -> Result<usize>
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.
Sourcepub fn read_file_at(
&self,
path: &str,
offset: usize,
out: &mut [u8],
) -> Result<usize>
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.
pub fn read_attr(&self, path: &str, attr_type: u8) -> Result<Vec<u8>>
Sourcepub fn read_attr_into(
&self,
path: &str,
attr_type: u8,
out: &mut [u8],
) -> Result<usize>
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.
pub fn walk(&self, path: &str) -> Result<Vec<WalkEntry>>
Sourcepub fn walk_with<F>(&self, path: &str, visitor: F) -> Result<()>
pub fn walk_with<F>(&self, path: &str, visitor: F) -> 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.
Sourcepub fn used_blocks(&self) -> Result<Vec<bool>>
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>
impl Filesystem<'static>
Sourcepub fn format_device<D: BlockDevice>(device: &mut D) -> Result<()>
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.
Sourcepub fn format_device_with_options<D: BlockDevice>(
device: &mut D,
options: FilesystemOptions,
) -> Result<()>
pub fn format_device_with_options<D: BlockDevice>( device: &mut D, options: FilesystemOptions, ) -> Result<()>
Formats a block device using explicit littlefs-style options.
Sourcepub fn mount_device_mut<D: BlockDevice + 'static>(
device: D,
) -> Result<FilesystemMut<D>>
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.
Sourcepub fn mount_device_mut_with_options<D: BlockDevice + 'static>(
device: D,
options: FilesystemOptions,
) -> Result<FilesystemMut<D>>
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>
impl<'a> Clone for Filesystem<'a>
Source§fn clone(&self) -> Filesystem<'a>
fn clone(&self) -> Filesystem<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more