pub struct FilesystemReader<'b> {
pub kind: Kind,
pub block_size: u32,
pub block_log: u16,
pub compressor: Option<Compressor>,
pub mod_time: u32,
pub id_table: Vec<Id>,
pub fragments: Option<Vec<Fragment>>,
pub root: Nodes<SquashfsFileReader>,
/* private fields */
}v3 only.Expand description
Representation of SquashFS filesystem after read from image
- Use
Self::from_readerto read intoSelffrom areader
§Read direct into Self
Usual workflow, reading from image into a default squashfs Self. See InnerNode for more
details for .nodes.
// Read into filesystem
let file = BufReader::new(File::open("image.squashfs").unwrap());
let filesystem = FilesystemReader::from_reader(file).unwrap();
// Iterate through nodes
// (See src/bin/unsquashfs.rs for more examples on extraction)
for node in filesystem.files() {
// extract
match &node.inner {
InnerNode::File(_) => (),
InnerNode::Symlink(_) => (),
InnerNode::Dir(_) => (),
InnerNode::CharacterDevice(_) => (),
InnerNode::BlockDevice(_) => (),
InnerNode::NamedPipe => (),
InnerNode::Socket => (),
}
}§Read from Squashfs
Performance wise, you may want to read into a Squashfs first, if for instance you are
optionally not extracting and only listing some Superblock fields.
// Read into Squashfs
let file = BufReader::new(File::open("image.squashfs").unwrap());
let squashfs = Squashfs::from_reader_with_offset(file, 0).unwrap();
// Display the Superblock info
let superblock = squashfs.superblock;
println!("{superblock:#08x?}");
// Now read into filesystem
let filesystem = squashfs.into_filesystem_reader().unwrap();Fields§
§kind: Kind§block_size: u32The size of a data block in bytes. Must be a power of two between 4096 (4k) and 1048576 (1 MiB).
block_log: u16The log2 of the block size. If the two fields do not agree, the archive is considered corrupted.
compressor: Option<Compressor>Compressor used for data (Always None for v3.)
mod_time: u32Last modification time of the archive. Count seconds since 00:00, Jan 1st 1970 UTC (not counting leap seconds). This is unsigned, so it expires in the year 2106 (as opposed to 2038).
id_table: Vec<Id>ID’s stored for gui(s) and uid(s)
fragments: Option<Vec<Fragment>>Fragments Lookup Table
root: Nodes<SquashfsFileReader>All files and directories in filesystem
Implementations§
Source§impl<'b> FilesystemReader<'b>
impl<'b> FilesystemReader<'b>
Sourcepub fn from_reader<R>(reader: R) -> Result<Self, BackhandError>where
R: BufReadSeek + 'b,
pub fn from_reader<R>(reader: R) -> Result<Self, BackhandError>where
R: BufReadSeek + 'b,
Call Squashfs::from_reader, then Squashfs::into_filesystem_reader
With default kind: crate::kind::LE_V4_0 and offset 0.
Sourcepub fn from_reader_with_offset<R>(
reader: R,
offset: u64,
) -> Result<Self, BackhandError>where
R: BufReadSeek + 'b,
pub fn from_reader_with_offset<R>(
reader: R,
offset: u64,
) -> Result<Self, BackhandError>where
R: BufReadSeek + 'b,
Same as Self::from_reader, but seek’ing to offset in reader before reading
Sourcepub fn from_reader_with_offset_and_kind<R>(
reader: R,
offset: u64,
kind: Kind,
) -> Result<Self, BackhandError>where
R: BufReadSeek + 'b,
pub fn from_reader_with_offset_and_kind<R>(
reader: R,
offset: u64,
kind: Kind,
) -> Result<Self, BackhandError>where
R: BufReadSeek + 'b,
Same as Self::from_reader_with_offset, but setting custom kind
Sourcepub fn file<'a>(
&'a self,
file: &'a SquashfsFileReader,
) -> FilesystemReaderFile<'a, 'b>
pub fn file<'a>( &'a self, file: &'a SquashfsFileReader, ) -> FilesystemReaderFile<'a, 'b>
Return a file handler for this file
Sourcepub fn files(&self) -> impl Iterator<Item = &Node<SquashfsFileReader>>
pub fn files(&self) -> impl Iterator<Item = &Node<SquashfsFileReader>>
Iterator of all files, including the root
§Example
Used when extracting a file from the image, for example using FilesystemReaderFile:
// [snip: creating FilesystemReader]
for node in filesystem.files() {
// extract
match &node.inner {
InnerNode::File(file) => {
let mut reader = filesystem
.file(&file)
.reader();
// Then, do something with the reader
},
_ => (),
}
}Trait Implementations§
Source§impl<'b> FilesystemReaderTrait for FilesystemReader<'b>
impl<'b> FilesystemReaderTrait for FilesystemReader<'b>
Source§fn file_data(
&self,
file: &BackhandSquashfsFileReader,
) -> Result<Vec<u8>, BackhandError>
fn file_data( &self, file: &BackhandSquashfsFileReader, ) -> Result<Vec<u8>, BackhandError>
Source§fn file_data_to_writer(
&self,
file: &BackhandSquashfsFileReader,
writer: &mut dyn Write,
) -> Result<u64, BackhandError>
fn file_data_to_writer( &self, file: &BackhandSquashfsFileReader, writer: &mut dyn Write, ) -> Result<u64, BackhandError>
writer, without holding it all in memoryAuto Trait Implementations§
impl<'b> !Freeze for FilesystemReader<'b>
impl<'b> !RefUnwindSafe for FilesystemReader<'b>
impl<'b> !UnwindSafe for FilesystemReader<'b>
impl<'b> Send for FilesystemReader<'b>
impl<'b> Sync for FilesystemReader<'b>
impl<'b> Unpin for FilesystemReader<'b>
impl<'b> UnsafeUnpin for FilesystemReader<'b>
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.