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
impl ImageBuilder
Sourcepub fn new(cfg: Config) -> Result<Self>
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.
Sourcepub fn new_with_options(cfg: Config, options: FilesystemOptions) -> Result<Self>
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.
Sourcepub fn add_inline_file(&mut self, path: &str, data: &[u8]) -> Result<&mut Self>
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.
Sourcepub fn add_ctz_file(&mut self, path: &str, data: &[u8]) -> Result<&mut Self>
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.
Sourcepub fn create_dir(&mut self, path: &str) -> Result<&mut Self>
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.
Sourcepub fn set_attr(
&mut self,
path: &str,
attr_type: u8,
data: &[u8],
) -> Result<&mut Self>
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.
Sourcepub fn update_inline_file(
&mut self,
path: &str,
data: &[u8],
) -> Result<&mut Self>
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.
Sourcepub fn update_file(&mut self, path: &str, data: &[u8]) -> Result<&mut Self>
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.
Sourcepub fn update_attr(
&mut self,
path: &str,
attr_type: u8,
data: &[u8],
) -> Result<&mut Self>
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.
Sourcepub fn delete_attr(&mut self, path: &str, attr_type: u8) -> Result<&mut Self>
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”.
Sourcepub fn delete_file(&mut self, path: &str) -> Result<&mut Self>
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.
Sourcepub fn delete_dir(&mut self, path: &str) -> Result<&mut Self>
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.
Sourcepub fn build(&self) -> Result<Vec<u8>>
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
impl Clone for ImageBuilder
Source§fn clone(&self) -> ImageBuilder
fn clone(&self) -> ImageBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more