Skip to main content

ImageBuilder

Struct ImageBuilder 

Source
pub struct ImageBuilder { /* private fields */ }
Expand description

Explicit full-image builder for host-side fixtures and interop tests.

Mounted block-device users should prefer Filesystem::format_device and Filesystem::mount_device_mut. This builder is still useful when a caller already wants a complete image in memory.

Implementations§

Source§

impl ImageBuilder

Source

pub fn new(cfg: Config) -> Result<Self>

Creates a builder for a fresh littlefs image.

The writer currently emits one root metadata pair and no data blocks, so it only accepts geometries large enough to contain the root pair. More constraints will move into a richer writer config once CTZ files and a real allocator appear.

Source

pub fn new_with_options(cfg: Config, options: FilesystemOptions) -> Result<Self>

Creates a fresh-image builder with explicit littlefs-style options.

The options decide which limits are recorded in the superblock and which program boundary the metadata commit writer pads to. They intentionally share validation with mounted formatting so a hand-built test image does not quietly use a shape the top-level formatter would reject.

Source

pub fn add_inline_file(&mut self, path: &str, data: &[u8]) -> Result<&mut Self>

Adds or replaces an inline file.

Root files and files inside already-created directories are supported. The writer resolves the parent directory first, then inserts the file in that directory’s sorted id space.

Source

pub fn add_ctz_file(&mut self, path: &str, data: &[u8]) -> Result<&mut Self>

Adds a CTZ file.

CTZ data blocks are allocated monotonically in the fresh image and are linked with littlefs skip pointers. Root files and files inside existing directories share the same CTZ data-block writer.

Source

pub fn create_dir(&mut self, path: &str) -> Result<&mut Self>

Adds an empty directory before append-style updates are emitted.

Each directory receives a fresh metadata pair from the builder’s monotonic allocator.

Source

pub fn set_attr( &mut self, path: &str, attr_type: u8, data: &[u8], ) -> Result<&mut Self>

Sets a user attribute on an already-added root-level inline file.

littlefs encodes user attributes as metadata tags with type LFS_TYPE_USERATTR + attr_type. Keeping this method tied to files that already exist avoids accidentally emitting orphan attributes that C would ignore or reject in later operations.

Source

pub fn update_inline_file( &mut self, path: &str, data: &[u8], ) -> Result<&mut Self>

Appends a later root metadata commit that overwrites an inline file.

The original create/name tags remain in the first commit, while this method writes a later struct tag for the same id. littlefs’s normal supersede rules make the later inline payload visible.

Source

pub fn update_file(&mut self, path: &str, data: &[u8]) -> Result<&mut Self>

Updates an existing file, selecting inline or CTZ storage by payload size.

A later littlefs struct tag supersedes the previous one even when the struct type changes. That lets this builder model inline-to-CTZ and CTZ-to-inline conversion as ordinary append commits. Old CTZ blocks are left unreachable until the allocator learns real free-space tracking.

Source

pub fn update_attr( &mut self, path: &str, attr_type: u8, data: &[u8], ) -> Result<&mut Self>

Appends a later root metadata commit that overwrites a user attribute.

Empty attributes are represented as normal zero-length userattr tags. Deletion uses a different tag shape and is handled by delete_attr.

Source

pub fn delete_attr(&mut self, path: &str, attr_type: u8) -> Result<&mut Self>

Appends a later root metadata commit that deletes a user attribute.

C’s lfs_removeattr is just a normal metadata commit with a userattr tag whose size field is 0x3ff. In littlefs tag terminology that means “delete the latest matching tag” rather than “write a 1023-byte value”.

Source

pub fn delete_file(&mut self, path: &str) -> Result<&mut Self>

Appends a later root metadata commit that deletes a root inline file.

File deletion is a splice operation in littlefs. The LFS_TYPE_DELETE tag removes the current id and shifts later ids down by one, so the builder updates visible_entries immediately. Later update/delete calls therefore compute ids against the same state that C will see.

Source

pub fn delete_dir(&mut self, path: &str) -> Result<&mut Self>

Appends a parent-directory commit that removes an empty directory.

littlefs uses the same splice/delete tag for files and directories in a parent directory. The safety rule lives above the tag writer: only a directory whose final visible child map is empty may be unlinked here. Its old metadata pair remains allocated but unreachable until a real free-space tracker exists.

Source

pub fn build(&self) -> Result<Vec<u8>>

Builds the erased flash image and writes the root metadata commit.

Blocks start as 0xff, the erased NOR-flash state. We then program only block 0 with a complete metadata commit. A valid single side of the root pair is sufficient for both littlefs and our parser; block 1 remains an erased power-loss-style alternate copy.

Trait Implementations§

Source§

impl Clone for ImageBuilder

Source§

fn clone(&self) -> ImageBuilder

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 Debug for ImageBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.