pub struct FilesystemWriter<'a, 'b, 'c> { /* private fields */ }Expand description
Representation of SquashFS filesystem to be written back to an image
- Use
Self::from_fs_readerto write with the data from a previous SquashFS image - Use
Self::defaultto create an empty SquashFS image without an original image. For example:
// Add empty default FilesytemWriter
let mut fs = FilesystemWriter::default();
fs.set_current_time();
fs.set_block_size(DEFAULT_BLOCK_SIZE);
fs.set_only_root_id();
fs.set_kind(Kind::from_const(kind::LE_V4_0).unwrap());
// set root image permissions
let header = NodeHeader {
permissions: 0o755,
..NodeHeader::default()
};
fs.set_root_mode(0o777);
// set extra compression options
let mut xz_extra = ExtraXz::default();
xz_extra.level(9).unwrap();
let extra = CompressionExtra::Xz(xz_extra);
let mut compressor = FilesystemCompressor::new(Compressor::Xz, None).unwrap();
compressor.extra(extra).unwrap();
fs.set_compressor(compressor);
// push some dirs and a file
fs.push_dir("usr", header);
fs.push_dir("usr/bin", header);
fs.push_file(std::io::Cursor::new(vec![0x00, 0x01]), "usr/bin/file", header);Implementations§
Source§impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c>
Sourcepub fn set_block_size(&mut self, block_size: u32)
pub fn set_block_size(&mut self, block_size: u32)
Sourcepub fn set_time(&mut self, mod_time: u32)
pub fn set_time(&mut self, mod_time: u32)
Set time of image as mod_time
§Example: Set to Wed Oct 19 01:26:15 2022
let mut fs = FilesystemWriter::default();
fs.set_time(0x634f_5237);Sourcepub fn set_current_time(&mut self)
pub fn set_current_time(&mut self)
Set time of image as current time
Sourcepub fn set_kind(&mut self, kind: Kind)
pub fn set_kind(&mut self, kind: Kind)
Set kind as kind
§Example: Set kind to default V4.0
let mut fs = FilesystemWriter::default();
fs.set_kind(Kind::from_const(kind::LE_V4_0).unwrap());Sourcepub fn set_root_mode(&mut self, mode: u16)
pub fn set_root_mode(&mut self, mode: u16)
Sourcepub fn set_root_uid(&mut self, uid: u32)
pub fn set_root_uid(&mut self, uid: u32)
Set root uid as uid
Sourcepub fn set_root_gid(&mut self, gid: u32)
pub fn set_root_gid(&mut self, gid: u32)
Set root gid as gid
Sourcepub fn set_compressor(&mut self, compressor: FilesystemCompressor)
pub fn set_compressor(&mut self, compressor: FilesystemCompressor)
Set compressor as compressor
let mut compressor = FilesystemCompressor::new(Compressor::Xz, None).unwrap();Sourcepub fn set_only_root_id(&mut self)
pub fn set_only_root_id(&mut self)
Set id_table to Id::root, removing old entries
Sourcepub fn set_kib_padding(&mut self, pad_kib: u32)
pub fn set_kib_padding(&mut self, pad_kib: u32)
Set padding(zero bytes) added to the end of the image after calling write.
For example, if given pad_kib of 8; a 8K padding will be added to the end of the image.
Default: DEFAULT_PAD_LEN
Sourcepub fn set_no_padding(&mut self)
pub fn set_no_padding(&mut self)
Set no padding(zero bytes) added to the end of the image after calling write.
Sourcepub fn set_no_duplicate_files(&mut self, value: bool)
pub fn set_no_duplicate_files(&mut self, value: bool)
Set if we perform duplicate file checking, on by default
Sourcepub fn set_emit_compression_options(&mut self, value: bool)
pub fn set_emit_compression_options(&mut self, value: bool)
Set if compression options are written
Sourcepub fn from_fs_reader(
reader: &'a FilesystemReader<'b>,
) -> Result<Self, BackhandError>
pub fn from_fs_reader( reader: &'a FilesystemReader<'b>, ) -> Result<Self, BackhandError>
Inherit filesystem structure and properties from reader
Sourcepub fn push_file<P>(
&mut self,
reader: impl Read + 'c,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_file<P>( &mut self, reader: impl Read + 'c, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert reader into filesystem with path and metadata header.
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn mut_file<S>(
&mut self,
find_path: S,
) -> Option<&mut SquashfsFileWriter<'a, 'b, 'c>>
pub fn mut_file<S>( &mut self, find_path: S, ) -> Option<&mut SquashfsFileWriter<'a, 'b, 'c>>
Take a mutable reference to existing file at find_path
Sourcepub fn replace_file<S>(
&mut self,
find_path: S,
reader: impl Read + 'c,
) -> Result<(), BackhandError>
pub fn replace_file<S>( &mut self, find_path: S, reader: impl Read + 'c, ) -> Result<(), BackhandError>
Replace an existing file
Sourcepub fn push_symlink<P, S>(
&mut self,
link: S,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_symlink<P, S>( &mut self, link: S, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert symlink path -> link
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn push_dir<P>(
&mut self,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_dir<P>( &mut self, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert empty dir at path
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn push_dir_all<P>(
&mut self,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_dir_all<P>( &mut self, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Recursively create an empty directory and all of its parent components if they are missing.
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn push_char_device<P>(
&mut self,
device_number: u32,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_char_device<P>( &mut self, device_number: u32, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert character device with device_number at path
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn push_block_device<P>(
&mut self,
device_number: u32,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_block_device<P>( &mut self, device_number: u32, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert block device with device_number at path
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn push_fifo<P>(
&mut self,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_fifo<P>( &mut self, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert FIFO (named pipe)
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn push_socket<P>(
&mut self,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_socket<P>( &mut self, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert Socket (UNIX domain socket)
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn write_with_offset<W>(
&mut self,
w: W,
offset: u64,
) -> Result<(SuperBlock, u64), BackhandError>
pub fn write_with_offset<W>( &mut self, w: W, offset: u64, ) -> Result<(SuperBlock, u64), BackhandError>
Same as Self::write, but seek’ing to offset in w before reading. This offset
is treated as the base image offset.
Sourcepub fn write<W: Write + Seek>(
&mut self,
w: W,
) -> Result<(SuperBlock, u64), BackhandError>
pub fn write<W: Write + Seek>( &mut self, w: W, ) -> Result<(SuperBlock, u64), BackhandError>
Generate and write the resulting squashfs image to w
§Returns
(written populated SuperBlock, total amount of bytes written including padding)
Trait Implementations§
Source§impl<'a, 'b, 'c> Debug for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> Debug for FilesystemWriter<'a, 'b, 'c>
Source§impl Default for FilesystemWriter<'_, '_, '_>
impl Default for FilesystemWriter<'_, '_, '_>
Source§fn default() -> Self
fn default() -> Self
Create default FilesystemWriter
block_size: DEFAULT_BLOCK_SIZE, compressor: default XZ compression, no nodes,
kind: LE_V4_0, and mod_time: 0.
Auto Trait Implementations§
impl<'a, 'b, 'c> Freeze for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> !RefUnwindSafe for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> !Send for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> !Sync for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> Unpin for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> !UnwindSafe for FilesystemWriter<'a, 'b, 'c>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more