Crate backhand

Source
Expand description

Library and binaries for the reading, creating, and modification of SquashFS file systems.

§Library

Add the following to your Cargo.toml file:

[dependencies]
backhand = "0.21.0"

§Reading

For reading an image and extracting its details and contents, use FilesystemReader::from_reader.

§Writing

For creating a modified or new image, use FilesystemWriter::from_fs_reader. FilesystemWriter can also be created from scratch, without a previous image to base itself on.

§Example

 // read
 let file = BufReader::new(File::open("file.squashfs").unwrap());
 let read_filesystem = FilesystemReader::from_reader(file).unwrap();

 // convert to writer
 let mut write_filesystem = FilesystemWriter::from_fs_reader(&read_filesystem).unwrap();

 // add file with data from slice
 let d = NodeHeader::default();
 let bytes = Cursor::new(b"Fear is the mind-killer.");
 write_filesystem.push_file(bytes, "a/d/e/new_file", d);

 // add file with data from file
 let new_file = File::open("dune").unwrap();
 write_filesystem.push_file(new_file, "/root/dune", d);

 // replace a existing file
 let bytes = Cursor::new(b"The sleeper must awaken.\n");
 write_filesystem
     .replace_file("/a/b/c/d/e/first_file", bytes)
     .unwrap();

 // write into a new file
 let mut output = File::create("modified.squashfs").unwrap();
 write_filesystem.write(&mut output).unwrap();

§Features

  • xz (enabled by default) — Enables xz compression inside library and binaries
  • xz-static — Enables xz compression and forces static build inside library and binaries
  • gzip (enabled by default) — Enables gzip compression inside library and binaries using flate2 library with zlib-rs
  • lzo — This library is licensed GPL and thus disabled by default
  • zstd (enabled by default) — Enables zstd compression inside library and binaries
  • lz4 (enabled by default) — Enables Lz4 compression
  • any-gzip (enabled by default) — Internal only
  • any-flate2 (enabled by default) — Internal only

Modules§

compression
Compression Choice and Options
kind
Support the wonderful world of vendor formats

Structs§

BasicFile
DataSize
Export
NFS export support
ExtraXz
Xz compression option for FilesystemWriter
FilesystemCompressor
All compression options for FilesystemWriter
FilesystemReader
Representation of SquashFS filesystem after read from image
FilesystemReaderFile
Filesystem handle for file
FilesystemWriter
Representation of SquashFS filesystem to be written back to an image
Fragment
Id
32 bit user and group IDs
Inode
Node
Filesystem Node
NodeHeader
File information for Node
Squashfs
Squashfs Image initial read information
SquashfsBlockDevice
Block Device for filesystem
SquashfsCharacterDevice
Character Device for filesystem
SquashfsDir
Directory for filesystem
SquashfsReadFile
SquashfsSymlink
Symlink for filesystem
SuperBlock
Contains important information about the archive, including the locations of other sections

Enums§

BackhandError
Errors generated from library
CompressionExtra
Compression options only for FilesystemWriter
Flags
InnerNode
Filesystem node
SquashfsFileReader
Unread file for filesystem
SquashfsFileWriter
Read file from other SquashfsFile or an user file

Constants§

DEFAULT_BLOCK_SIZE
128KiB
DEFAULT_PAD_LEN
4KiB
MAX_BLOCK_SIZE
1MiB
MIN_BLOCK_SIZE
4KiB

Traits§

BufReadSeek
Pseudo-Trait for BufRead + Seek