Skip to main content

Reader

Struct Reader 

Source
pub struct Reader {
    pub hardlinks: HashMap<String, InodeNumber>,
    /* private fields */
}
Expand description

Read-only ext4 filesystem reader.

Parses the superblock, lazily reads group descriptors and inodes, and maintains a FileTree that mirrors the on-disk directory hierarchy.

Fields§

§hardlinks: HashMap<String, InodeNumber>

Paths that are hard links to already-seen inodes. Key: path string (e.g. “usr/bin/link”), Value: target inode number.

Implementations§

Source§

impl Reader

Source

pub fn new(path: &Path) -> ReadResult<Self>

Open an ext4 disk image at path and build the in-memory file tree.

The constructor:

  1. Reads and validates the superblock.
  2. BFS-traverses the directory tree from the root inode.
  3. Records hard links (paths whose inode was already visited).
  4. Reads extent information for every discovered entry.
Source

pub fn superblock(&self) -> &SuperBlock

Borrow the parsed superblock.

Source

pub fn tree(&self) -> &FileTree

Borrow the in-memory file tree.

Source

pub fn get_group_descriptor( &mut self, number: u32, ) -> ReadResult<GroupDescriptor>

Get a group descriptor, reading from disk on first access.

Source

pub fn get_inode(&mut self, number: u32) -> ReadResult<Inode>

Get an inode, reading from disk on first access.

Source

pub fn children_of( &mut self, number: InodeNumber, ) -> ReadResult<Vec<(String, InodeNumber)>>

List the children of a directory inode (public wrapper around [get_dir_entries]).

Source§

impl Reader

Source

pub fn exists(&mut self, path: &str) -> bool

Check whether path exists in this ext4 filesystem.

Source

pub fn stat(&mut self, path: &str) -> ReadResult<(InodeNumber, Inode)>

Return (inode_number, inode) for the given path, following symlinks.

Source

pub fn stat_no_follow(&mut self, path: &str) -> ReadResult<(InodeNumber, Inode)>

Return (inode_number, inode) for the given path without following the final symlink component.

Source

pub fn list_dir(&mut self, path: &str) -> ReadResult<Vec<String>>

List a directory’s entries (names only, excluding “.” and “..”).

Source

pub fn read_file( &mut self, path: &str, offset: u64, count: Option<usize>, ) -> ReadResult<Vec<u8>>

Read file contents at path starting at offset.

If count is None, reads to EOF. Returns the bytes read (may be shorter than requested if the file is smaller).

Source

pub fn read_file_into( &mut self, path: &str, buf: &mut [u8], offset: u64, ) -> ReadResult<usize>

Read file contents into a pre-allocated buffer. Returns the number of bytes actually written to buf (may be less than buf.len() at EOF).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.