Skip to main content

read_file

Function read_file 

Source
pub fn read_file(
    partition: &[u8],
    sb: &Superblock,
    ino: u64,
) -> Result<Vec<u8>, UfsError>
Expand description

Assemble the full byte content of the file inode ino, walking its block map (direct di_db[0..12], then single/double/triple indirect via di_ib[0..3]) up to di_size. A hole (a 0 pointer, at any level of the tree) reads as zeros; the last block is sized to the remaining di_size (fragment tail).

The assembled buffer is exactly di_size bytes.

§Errors

  • UfsError::ImpossibleGeometry if di_size exceeds the partition length (an allocation bomb — the file cannot possibly be that large), or if fs_bsize / fs_fsize are non-positive so block addressing is undefined.
  • Propagates UfsError from locating/decoding ino.