FileSystem

Struct FileSystem 

Source
pub struct FileSystem<T> {
    pub root: Directory<T>,
}
Expand description

A complete filesystem tree with a root directory.

Fields§

§root: Directory<T>

The root directory of the filesystem.

Implementations§

Source§

impl<ObjectID: FsVerityHashValue> FileSystem<RegularFile<ObjectID>>

Source

pub fn commit_image( &self, repository: &Repository<ObjectID>, image_name: Option<&str>, ) -> Result<ObjectID>

Commits this filesystem as an EROFS image to the repository.

Generates an EROFS filesystem image and writes it to the repository with the optional name. Returns the fsverity digest of the committed image.

Note: Callers should ensure root metadata is set before calling this, typically via copy_root_metadata_from_usr() or set_root_stat().

Source

pub fn compute_image_id(&self) -> ObjectID

Computes the fsverity digest for this filesystem as an EROFS image.

Generates the EROFS image and returns its fsverity digest without writing to a repository.

Note: Callers should ensure root metadata is set before calling this, typically via copy_root_metadata_from_usr() or set_root_stat().

Source

pub fn print_dumpfile(&self) -> Result<()>

Prints this filesystem in dumpfile format to stdout.

Serializes the entire filesystem tree to stdout in composefs dumpfile text format.

Note: Callers should ensure root metadata is set before calling this, typically via copy_root_metadata_from_usr() or set_root_stat().

Source§

impl<T> FileSystem<T>

Source

pub fn new(root_stat: Stat) -> Self

Creates a new filesystem with a root directory having the given metadata.

Source

pub fn set_root_stat(&mut self, stat: Stat)

Sets the metadata for the root directory.

Source

pub fn copy_root_metadata_from_usr(&mut self) -> Result<(), ImageError>

Copies metadata from /usr to the root directory.

OCI container layer tars often don’t include a root directory entry, and when they do, container runtimes typically ignore it. This makes root metadata non-deterministic. This method provides a way to derive consistent root metadata by copying it from /usr, which is always present in standard filesystem layouts.

The copied metadata includes:

  • Mode (permissions)
  • Modification time
  • User ID (uid)
  • Group ID (gid)
  • Extended attributes (xattrs)

NOTE: If changing this behavior, also update doc/oci.md.

§Errors

Returns an error if /usr does not exist or is not a directory.

Source

pub fn for_each_stat<F>(&self, f: F)
where F: Fn(&Stat),

Applies a function to every Stat in the filesystem tree.

This visits the root directory and all descendants (directories and leaves), calling the provided function with each node’s Stat.

Source

pub fn filter_xattrs<F>(&self, predicate: F)
where F: Fn(&OsStr) -> bool,

Filters extended attributes across the entire filesystem tree.

Retains only xattrs whose names match the given predicate. This is useful for stripping build-time xattrs that shouldn’t leak into the final image (e.g., security.selinux labels from the build host).

Source

pub fn canonicalize_run(&mut self) -> Result<(), ImageError>

Empties the /run directory if present, using /usr’s mtime.

/run is a tmpfs at runtime and should always be empty in container images. This also works around podman/buildah’s RUN --mount behavior where bind mount targets leave directory stubs in the filesystem that shouldn’t be part of the image content.

The mtime is set to match /usr for consistency with Self::copy_root_metadata_from_usr.

NOTE: If changing this behavior, also update doc/oci.md.

§Errors

Returns an error if /usr does not exist (needed to get the mtime).

Source

pub fn transform_for_oci(&mut self) -> Result<(), ImageError>

Transforms the filesystem for OCI container image consistency.

This applies the standard transformations needed to ensure consistent composefs digests between build-time (mounted filesystem) and install-time (OCI tar layers) views:

  1. Self::copy_root_metadata_from_usr - copies /usr metadata to root directory
  2. Self::canonicalize_run - empties /run directory

This is the recommended single entry point for OCI container processing.

NOTE: If changing this behavior, also update doc/oci.md.

§Errors

Returns an error if /usr does not exist.

Trait Implementations§

Source§

impl<T: Debug> Debug for FileSystem<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for FileSystem<T>

§

impl<T> !RefUnwindSafe for FileSystem<T>

§

impl<T> !Send for FileSystem<T>

§

impl<T> !Sync for FileSystem<T>

§

impl<T> Unpin for FileSystem<T>

§

impl<T> !UnwindSafe for FileSystem<T>

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V