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 reader is kept until Self::write is called. For a file on disk, use
Self::push_file_from_path instead, which keeps only the path and thus does not use an
open file descriptor for each file.
The uid and gid in header are added to FilesystemWriters id’s
Sourcepub fn push_file_from_path<S, P>(
&mut self,
source: S,
path: P,
header: NodeHeader,
) -> Result<(), BackhandError>
pub fn push_file_from_path<S, P>( &mut self, source: S, path: P, header: NodeHeader, ) -> Result<(), BackhandError>
Insert the file at source into filesystem with path and metadata header.
The file is opened when Self::write is called, not now. Use this instead of
Self::push_file for files on disk: Self::push_file holds the reader, and thus an
open file descriptor, until the write. The source file must still exist at the time of
the write.
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 replace_file_from_path<S, P>(
&mut self,
find_path: S,
source: P,
) -> Result<(), BackhandError>
pub fn replace_file_from_path<S, P>( &mut self, find_path: S, source: P, ) -> Result<(), BackhandError>
Replace an existing file with the file at source, which is opened at write time
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> !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> !UnwindSafe for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> Freeze for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> Unpin for FilesystemWriter<'a, 'b, 'c>
impl<'a, 'b, 'c> UnsafeUnpin 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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.