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>>
impl<ObjectID: FsVerityHashValue> FileSystem<RegularFile<ObjectID>>
Sourcepub fn commit_image(
&self,
repository: &Repository<ObjectID>,
image_name: Option<&str>,
) -> Result<ObjectID>
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().
Sourcepub fn compute_image_id(&self) -> ObjectID
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().
Sourcepub fn print_dumpfile(&self) -> Result<()>
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>
impl<T> FileSystem<T>
Sourcepub fn new(root_stat: Stat) -> Self
pub fn new(root_stat: Stat) -> Self
Creates a new filesystem with a root directory having the given metadata.
Sourcepub fn set_root_stat(&mut self, stat: Stat)
pub fn set_root_stat(&mut self, stat: Stat)
Sets the metadata for the root directory.
Sourcepub fn copy_root_metadata_from_usr(&mut self) -> Result<(), ImageError>
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.
Sourcepub fn for_each_stat<F>(&self, f: F)
pub fn for_each_stat<F>(&self, f: F)
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.
Sourcepub fn filter_xattrs<F>(&self, predicate: F)
pub fn filter_xattrs<F>(&self, predicate: F)
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).
Sourcepub fn canonicalize_run(&mut self) -> Result<(), ImageError>
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).
Sourcepub fn transform_for_oci(&mut self) -> Result<(), ImageError>
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:
Self::copy_root_metadata_from_usr- copies/usrmetadata to root directorySelf::canonicalize_run- empties/rundirectory
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.