Skip to main content

Crate ostrya_composefs

Crate ostrya_composefs 

Source
Expand description

A byte-exact writer of composefs EROFS images, with an fs-verity hasher.

A caller builds a tree of directories, symlinks, and regular files. The crate writes the EROFS image of the tree and returns the fs-verity digest of the image. The image is byte-identical to the composefs image of the ostree command, format version 0. The crate is synchronous and does not read a repository.

§Entry points

  • Directory is the root of a tree, and Node is one entry of it.
  • Metadata holds the mode, the owner, the mtime, and the xattrs of a node.
  • Content is the content of a Regular file: empty or a loose object.
  • build_image writes the image into an Image in memory.
  • write_image_to writes the image through a sink and does not keep it.
  • FsVerityHasher calculates an fs-verity digest of a byte stream.
  • Error is the error of the two image writers.

§Examples

use ostrya_composefs::{Content, Directory, FsVerityHasher, Metadata, Node, Regular};

let mut root = Directory::new(Metadata { mode: 0o755, ..Metadata::default() });
let meta = Metadata { mode: 0o644, ..Metadata::default() };
root.insert("empty", Node::Regular(Regular { meta, content: Content::Empty }));

let image = ostrya_composefs::build_image(&root)?;
assert_eq!(FsVerityHasher::hash(&image.bytes), image.fs_verity);

// The streaming writer writes the same bytes and returns the same digest.
let mut sink = Vec::new();
assert_eq!(ostrya_composefs::write_image_to(&root, &mut sink)?, image.fs_verity);
assert_eq!(sink, image.bytes);

Structs§

Directory
A directory and its named children.
FsVerityHasher
A streaming fs-verity hasher (SHA-256, 4096-byte blocks, no salt).
Image
A composefs EROFS image in memory, with its fs-verity digest.
Metadata
The logical metadata of a node.
Regular
A regular file.
Symlink
A symbolic link, with its target inline in the image.

Enums§

Content
The content of a Regular file in the image.
Error
The error of build_image and write_image_to.
Node
A node in the tree.

Functions§

build_image
Writes the composefs EROFS image of the tree at root into memory.
write_image_to
Writes the composefs EROFS image of the tree at root through out.