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
impl Reader
Sourcepub fn new(path: &Path) -> ReadResult<Self>
pub fn new(path: &Path) -> ReadResult<Self>
Open an ext4 disk image at path and build the in-memory file tree.
The constructor:
- Reads and validates the superblock.
- BFS-traverses the directory tree from the root inode.
- Records hard links (paths whose inode was already visited).
- Reads extent information for every discovered entry.
Sourcepub fn superblock(&self) -> &SuperBlock
pub fn superblock(&self) -> &SuperBlock
Borrow the parsed superblock.
Sourcepub fn get_group_descriptor(
&mut self,
number: u32,
) -> ReadResult<GroupDescriptor>
pub fn get_group_descriptor( &mut self, number: u32, ) -> ReadResult<GroupDescriptor>
Get a group descriptor, reading from disk on first access.
Sourcepub fn get_inode(&mut self, number: u32) -> ReadResult<Inode>
pub fn get_inode(&mut self, number: u32) -> ReadResult<Inode>
Get an inode, reading from disk on first access.
Sourcepub fn children_of(
&mut self,
number: InodeNumber,
) -> ReadResult<Vec<(String, InodeNumber)>>
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
impl Reader
Sourcepub fn exists(&mut self, path: &str) -> bool
pub fn exists(&mut self, path: &str) -> bool
Check whether path exists in this ext4 filesystem.
Sourcepub fn stat(&mut self, path: &str) -> ReadResult<(InodeNumber, Inode)>
pub fn stat(&mut self, path: &str) -> ReadResult<(InodeNumber, Inode)>
Return (inode_number, inode) for the given path, following symlinks.
Sourcepub fn stat_no_follow(&mut self, path: &str) -> ReadResult<(InodeNumber, Inode)>
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.
Sourcepub fn list_dir(&mut self, path: &str) -> ReadResult<Vec<String>>
pub fn list_dir(&mut self, path: &str) -> ReadResult<Vec<String>>
List a directory’s entries (names only, excluding “.” and “..”).
Sourcepub fn read_file(
&mut self,
path: &str,
offset: u64,
count: Option<usize>,
) -> ReadResult<Vec<u8>>
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).
Sourcepub fn read_file_into(
&mut self,
path: &str,
buf: &mut [u8],
offset: u64,
) -> ReadResult<usize>
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).