Skip to main content

Formatter

Struct Formatter 

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

Single-pass ext4 image builder.

Implementations§

Source§

impl Formatter

Source

pub fn with_options(path: &Path, opts: FormatOptions) -> FormatResult<Self>

Create a new formatter that writes an ext4 image to path.

The file is truncated and re-created as a sparse file of opts.size bytes. The root directory (inode 2) and the /lost+found directory (required by e2fsck) are created automatically.

Only opts.block_size == 4096 is currently accepted; other values return FormatError::UnsupportedBlockSize. Labels are validated eagerly — an oversize or NUL-containing label returns FormatError::InvalidLabel before any file work happens.

Source

pub fn new( path: &Path, block_size: u32, min_disk_size: u64, ) -> FormatResult<Self>

Create a new formatter with defaults for UUID (random) and label (empty).

Thin shim over Formatter::with_options for the common case where only the image size matters. Callers that need a specific UUID or volume label should use with_options directly.

Source

pub fn create( &mut self, path: &str, mode: u16, link: Option<&str>, ts: Option<FileTimestamps>, data: Option<&mut dyn Read>, uid: Option<u32>, gid: Option<u32>, xattrs: Option<&HashMap<String, Vec<u8>>>, ) -> FormatResult<()>

Create a file, directory, or symlink at path.

Parent directories are created recursively with mode 0755, inheriting uid/gid from the nearest existing parent (like mkdir -p).

Source

pub fn exists(&self, path: &str) -> bool

Check whether path exists in the in-memory file tree.

Source

pub fn is_dir(&self, path: &str) -> bool

Check whether path exists and is a directory.

Source

pub fn list_dir(&self, path: &str) -> Vec<String>

List the names of immediate children of a directory (excluding . and ..). Returns an empty vec if path is not a directory.

Source

pub fn set_permissions(&mut self, path: &str, mode: u16) -> FormatResult<()>

Update the permission bits of an existing entry.

Source

pub fn set_owner(&mut self, path: &str, uid: u32, gid: u32) -> FormatResult<()>

Update the owner uid/gid of an existing entry.

Create a hard link at link_path pointing to target_path.

Remove the entry at path.

When directory_whiteout is true, only children are removed and the directory entry itself is kept (used for overlay whiteouts).

Source

pub fn close(self) -> FormatResult<()>

Finalize the ext4 image.

Writes directory entries (BFS order), the inode table, block/inode bitmaps, group descriptors, and the superblock. Consumes self.

Source§

impl Formatter

Source

pub fn unpack_tar<R: Read>(&mut self, reader: R) -> FormatResult<()>

Unpack a tar archive onto this ext4 filesystem.

Handles:

  • Regular files, directories, and symbolic links
  • OCI whiteout files (.wh.<name> deletes <name>, .wh..wh..opq deletes all children of the containing directory)
  • Hard links with cycle detection
  • Preservation of uid/gid, permissions, and timestamps

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> 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, 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.