Skip to main content

ufs/
lib.rs

1//! `ufs-core` — a pure-Rust, from-scratch UFS/FFS filesystem reader.
2//!
3//! UFS = the Unix File System, a.k.a. the Berkeley Fast File System (FFS).
4//! Parses the on-disk UFS structures a forensic tool needs — superblock and
5//! geometry, cylinder-group headers and allocation bitmaps, inodes,
6//! directories, and file content — over any byte source. The reader targets
7//! both **UFS1** (4.4BSD/FreeBSD legacy, 128-byte inodes, 32-bit block pointers,
8//! superblock at byte 8192, magic `0x00011954`) and **UFS2** (FreeBSD 5+,
9//! 256-byte inodes, 64-bit block pointers, superblock at byte 65536, magic
10//! `0x19540119`).
11//!
12//! Import path is `ufs` (see `[lib] name`): `use ufs::Superblock;`.
13//!
14//! UFS is endianness-agnostic on disk — the byte order is that of the host that
15//! created the filesystem, and the superblock magic disambiguates it. The
16//! reader supports both little- and big-endian images, selecting the order by
17//! which interpretation makes the magic match (see [`Endian`]).
18//!
19//! # Safety and robustness
20//!
21//! This crate parses untrusted, attacker-controllable disk images. It is
22//! `#![forbid(unsafe_code)]` and every integer is read through bounds-checked
23//! readers that yield `0`/`None` out of range rather than panic (the Paranoid
24//! Gatekeeper standard).
25
26#![forbid(unsafe_code)]
27#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
28
29pub mod bytes;
30mod cg;
31mod dir;
32mod error;
33mod file;
34mod inode;
35mod superblock;
36
37pub use bytes::Endian;
38pub use cg::{CylinderGroup, CG_MAGIC};
39pub use dir::{
40    list_dir, list_dir_all, read_block, read_by_path, DirEntry, DirEntryType, DIRBLKSIZ,
41    DIR_ROUNDUP,
42};
43pub use error::UfsError;
44pub use file::{read_file, read_inode_file, read_path_content, read_symlink_target};
45pub use inode::{
46    read_inode, FileType, Inode, Timespec, UFS1_DINODE_SIZE, UFS2_DINODE_SIZE, UFS_NDADDR,
47    UFS_NIADDR,
48};
49pub use superblock::{
50    Superblock, UfsVersion, FS_UFS1_MAGIC, FS_UFS2_MAGIC, SBLOCK_UFS1, SBLOCK_UFS2, UFS_ROOTINO,
51};