Skip to main content

Crate xfs

Crate xfs 

Source
Expand description

xfs-core — a pure-Rust, from-scratch XFS filesystem reader.

Parses the on-disk XFS structures a forensic tool needs — superblock and geometry, allocation-group headers, inodes, extents, and the five directory formats — over any byte source. The reader targets both v4 (legacy) and v5 (self-describing CRC-stamped) filesystems.

Import path is xfs (see [lib] name): use xfs::Superblock;.

§Safety and robustness

This crate parses untrusted, attacker-controllable disk images. It is #![forbid(unsafe_code)] and every integer is read through bounds-checked big-endian helpers that yield 0/None out of range rather than panic (the Paranoid Gatekeeper standard).

Re-exports§

pub use crc::crc_status;
pub use crc::verify_crc;

Modules§

bytes
Bounds-checked big-endian readers (the Paranoid Gatekeeper standard).
crc
v5 CRC32c self-describing-metadata verification (xfs_verify_cksum).

Structs§

Agf
The AGF free-space header.
Agfl
The AGFL free-list block ring.
Agi
The AGI inode-allocation header.
BmbtRec
A decoded 16-byte xfs_bmbt_rec extent descriptor.
DirEntry
A single directory entry: a name, the inode it points at, and — when the filesystem’s ftype feature is on — the on-disk file-type byte.
Inode
A parsed XFS inode core (di_core), v2 or v3.
InodeLocation
The decoded location of an inode: its allocation group, in-AG coordinates, absolute filesystem block, and absolute byte position in the image.
Superblock
Parsed XFS superblock — geometry and the log2 shift fields the inode-number decode (P1) needs.
XfsTimestamp
A decoded inode timestamp: signed Unix seconds + nanoseconds.

Enums§

FileType
The S_IFMT file type decoded from di_mode.
InodeFormat
The data-fork format selector (di_format / di_aformat).
XfsError
Errors surfaced while parsing XFS on-disk structures.

Constants§

MAX_BMBT_LEVELS
Maximum bmbt tree depth followed. Real bmbt trees are at most a handful of levels deep (the fanout is hundreds per block); a claimed depth beyond this is corrupt/hostile and the walk stops rather than recurse unboundedly.
MAX_BMBT_PTRS
Maximum total block pointers the walk will follow across the whole tree — an allocation/DoS cap so a fabricated wide tree cannot make the walk run for an unbounded time or collect an unbounded number of records.
XFS_AGFL_MAGIC
AGFL magic (v5 only) — ASCII "XAFL".
XFS_AGF_MAGIC
AGF magic — ASCII "XAGF".
XFS_AGI_MAGIC
AGI magic — ASCII "XAGI".
XFS_AGI_UNLINKED_BUCKETS
Number of unlinked hash buckets in an AGI.
XFS_BMAP_CRC_MAGIC
XFS_BMAP_CRC_MAGIC — a v5 (CRC) bmbt block, ASCII "BMA3".
XFS_BMAP_MAGIC
XFS_BMAP_MAGIC — a v4 (non-CRC) bmbt block, ASCII "BMAP".
XFS_DIFLAG2_BIGTIME
XFS_DIFLAG2_BIGTIME (bit 3) — set in v3 di_flags2 when timestamps use the 64-bit bigtime counter instead of the legacy (sec:i32, nsec:i32) pair.
XFS_DINODE_MAGIC
The XFS inode magic number, ASCII "IN" at byte 0 (XFS_DINODE_MAGIC).
XFS_DIR2_BLOCK_MAGIC
The v4 single-block directory data-block magic (XFS_DIR2_BLOCK_MAGIC, "XD2B").
XFS_DIR2_DATA_MAGIC
The v4 multi-block directory data-block magic (XFS_DIR2_DATA_MAGIC, "XD2D").
XFS_DIR3_BLOCK_MAGIC
The v5 single-block directory data-block magic (XFS_DIR3_BLOCK_MAGIC, "XDB3").
XFS_DIR3_DATA_MAGIC
The v5 multi-block directory data-block magic (XFS_DIR3_DATA_MAGIC, "XDD3"). A leaf/node directory’s DATA blocks carry this (distinct from the single-block XDB3) and, unlike a single block, have NO block tail.
XFS_SB_MAGIC
The XFS superblock magic number, ASCII "XFSB" at byte 0.

Functions§

assemble_extents
Reconstruct a file’s bytes from an already-decoded extent list.
read_block_dir
Parse a single-block (block-format) directory from its raw data-block bytes.
read_btree_extents
Walk a bmap B+tree given its inline xfs_bmdr_block root (the inode data fork) and collect every leaf xfs_bmbt_rec in tree (startoff) order.
read_by_path
Read a file by its absolute path, navigating the directory tree from the root.
read_data_dir_block
Parse a MULTI-block directory data block (XDD3 v5 / XD2D v4) from its raw bytes.
read_dir
List a directory inode’s entries (free-function form of Superblock::read_dir).
read_extents
Decode up to nextents consecutive 16-byte xfs_bmbt_rec records from a data fork. Records past the end of fork are not read (bounds-stopping): a truncated or lying nextents yields only the records that fully fit, never an over-read.
read_file_from_fork
Reconstruct an extent-list file’s bytes from its raw data fork.
read_shortform_dir
Parse a short-form directory from its inode data fork.
verify_bmbt_block_crc
Verify the v5 CRC32c of an on-disk bmbt block, returning Some(true/false) on a v5 (BMA3) block and None on a v4 (BMAP) block (no CRC).
verify_dir_block_crc
Verify the v5 CRC32c of a directory block (data, single-block, leaf, node, or freeindex), returning Some(true/false) on a v5 block and None on a v4 block (which carries no CRC).