Skip to content

Latest commit

 

History

History
448 lines (396 loc) · 17.7 KB

README.md

File metadata and controls

448 lines (396 loc) · 17.7 KB

Rootwatch logo

Read-only Linux filesystem scanner with a SOC-style disk TUI.

Showcase

Rootwatch v0.4.0 scanned with sudo (in Coverage)


Overview

rootwatch [OPTIONS] [PATH]
PATH defaults to /

Option Description
--scope root|all|select which filesystems are entered (default: root)
--include MOUNT enter this mountpoint too (repeatable)
--exclude PATH never descend into PATH (repeatable)
--no-prune do not prune /proc /sys /dev /run
--privileged measure what permissions hide (re-runs via sudo)
--elevate-with CMD elevation command (default: sudo)
--nix-gc ask Nix for the garbage-collectable size using trusted helper paths when running as root
--tui interactive terminal UI instead of the text report (see Interactive TUI)
--top N rows per ranking in the text report

Pipeline and complexity

N = entries, D = directories, M = mounts, K = rows shown, H = depth.

stage cost how
mount discovery O(M) /proc/self/mountinfo read once
traversal O(N) iterative DFS, openat + raw getdents64, O(H) open fds
metadata O(N) one statx per entry, relative to the parent dir fd (inode, blocks, mtime, uid, nlink, mount id)
hard-link dedup O(1)/entry Fx-hashed (dev, ino) set, only for nlink > 1
classification O(1)/dir component trie stepped during the DFS; no path matching afterwards
aggregation O(D) arena of dir nodes, children always have larger ids than parents, one reverse pass
scoring O(D) one pass; reason strings built only for retained rows
ranking O(D log K) bounded min-heaps, no global sort
report / TUI O(rows shown) consumes the model, never touches the filesystem

Total: O(N + D log K + M). Paths are rebuilt (O(depth)) only for rows that are displayed.

Analysis of the tree takes 1 ms for the analysis pass and 0.13 ms for top-20 ranking in the benchmark environment. The remaining scan time is dominated by the kernel answering statx. Byte totals equal du exactly. Scanning is still single-threaded on purpose: profile first, parallelise only if benchmarks on real hardware justify it (the walker is isolated in scanner.rs).

Filesystem model

  • ScanScope::Root (default): only the filesystem holding the scan root; other mounts are listed with the reason they were skipped.
  • ScanScope::All: plus recognized local disk-backed or tmpfs mounts. Pseudo (proc, sysfs, ...), network/FUSE and shared storage (virtiofs, gfs2, ocfs2, fuseblk), unrecognized mount types, overlay and squashfs/erofs image mounts are never entered implicitly. Local NTFS-3G mounts reported as fuseblk also require an explicit --include. Filesystem type alone cannot prove a block device is physically local.
  • ScanScope::Selected: plus the mounts named with --include. An include forces a mount in regardless of kind, and implies its ancestor mounts.
  • Mount identity per directory comes from statx's stx_mnt_id, so bind mounts are detected (a bind of content that is scanned elsewhere is skipped, not double counted). Self binds - NixOS's read-only /nix/store - are recognised and traversed.
  • Filesystems are grouped into storage pools. On btrfs every subvolume reports the whole pool through statvfs, so /, /nix and /home must be judged together. This is what turns "95 GiB used, 520 MiB observed" from a mystery into an explicit "these sibling mounts share the pool and were not walked".

Scan accuracy

Coverage is computed per pool. The report states a completeness level (COMPLETE ≥95%, SUBSTANTIAL ≥80%, PARTIAL ≥40%, MINIMAL), a confidence, and a list of causes for used − walked: skipped sibling mounts, permission-denied paths, I/O errors, pruned paths, shared extents (walked > used), or unattributed metadata/snapshots/deleted-open files. Separate disks that were not scanned are listed but do not count against coverage. Subtree scans (rootwatch /home/your-username) are judged by errors only; whole-filesystem coverage is not applicable.

When coverage is low the report says so next to every ranking ([PROVISIONAL] / [UNRELIABLE]), findings are marked as lower bounds (>=), and the overall verdict becomes at least X or UNDETERMINED - never "healthy".

Scoring

Metric Formula / value
share bytes on the pool / pool used * 100
urgency 0.1 up to 50% full, linear to 1.0 at 90%, 1.3 at 100%
weight path class: /tmp 2.0, /home 1.5, /var 1.25, generic 1.0, /nix 0.75, system 0.5
expected 0.8 expected, 1.0 notable, 1.5 suspicious
age 1 + 0.5 * stale fraction (temp, 7d) | 1 + 0.25 * stale fraction (home, 90d)
growth up to +40 when a Baseline is supplied: 40 * sat(rate %/day / 5) * sat(relative growth / 2)
score min(100, share * urgency * weight * expected * age + growth)
severity LOW < 5 <= MEDIUM < 15 <= HIGH < 35 <= CRITICAL

Directories whose single child holds ≥90% of their bytes are pass-through containers and are not reported themselves; the frontier is. A combined risk score is a bounded noisy-OR of capacity, concentration, temporary data, growth and blind-spot components. Per-pool scores, severity counters and per-node score/severity vectors (for a tree view) are in AnalysisResult.

Specialised zones

  • Temporary data (/tmp, /var/tmp): per-zone age distribution, stale bytes (7 d / 30 d), owners, largest children and files, RAM-backed (tmpfs) detection, assessment (normal / large / stale).
  • Home (/home/*, /root, each a zone): buckets (Downloads, .cache, .local, .cargo, .config, toolchains, other hidden, other), user-owned vs root-owned vs other-owned bytes, age distribution, largest files, detected projects (git, Cargo, Node, Python, Go, Nix, JVM, CMake) and their regenerable artifact directories (target, node_modules, .venv, ...).
  • Nix: store size, path count, database/profile sizes, generations per profile, largest paths, largest packages with version counts, and with --nix-gc the garbage-collectable size from nix-store --gc --print-dead (falls back to nix-collect-garbage --dry-run). The estimate is read-only and rootwatch never runs a collection. When the process is already running as root, rootwatch resolves these helper commands only from absolute, root-owned paths whose canonical path and ancestors are not group- or other-writable; unsafe PATH entries are ignored.

Permissions

Rootwatch never needs root. --privileged re-runs the selected scan configuration as a worker via sudo (or --elevate-with) and compares: bytes and entries hidden, coverage before/after, and the denied directories with their real sizes. The elevated worker receives the scan root plus the explicit scope, include, exclude, and pruning options selected by the user; it is not a separate arbitrary filesystem-query interface.

Library layout

lib.rs exposes scanner, model, mounts, zones, coverage, analysis, temp, home, nix, privilege, output, cli and tui. The TUI consumes ScanResult (DirectoryIndex with children(), path(), usage) and AnalysisResult; nothing in the core depends on it.

Security: see SECURITY.md for the reporting process and security-sensitive behavior.

Interactive TUI (--tui)

Command Description
rootwatch --tui scan / and explore
rootwatch --tui --scope all / scan / with the same scope options as the report
rootwatch --tui /home/your-username scan and explore /home/your-username

The text report remains the default; the TUI is opt-in. The scan runs on a worker thread, so the interface stays responsive while it works and shows live counters (entries, directories, allocated bytes, current path). r rescans without restarting.

TUI architecture

Component Role
CLI -> report mode -> output.rs text report output
CLI -> TUI mode -> tui/ interactive terminal UI
event.rs one channel for keys, mouse, ticks and worker results
command.rs raw keys -> semantic Commands; the only key map
state.rs AppState + per-view state; results are Arc and immutable
update.rs events/commands -> state; pure, no I/O
worker.rs scan + analysis off the UI thread
ui.rs header / tabs / footer layout
widgets/ one render function per view, read-only
scanner -> ScanResult -> analysis -> AnalysisResult -> tui data flow; the TUI never does filesystem I/O

Views (number keys jump directly): 1 Overview, 2 Findings, 3 Tree, 4 Files, 5 Coverage, 6 Pools, 7 Zones (temporary / home / Nix).

Text captures of real renders are in docs/screenshots/.

Keys

key action
j k / ↑ ↓ move selection
h l / ← → tree: collapse / expand · zones: switch type
Enter open details; in tree search, show the hit in the tree
Esc close details / clear filter
Tab / Shift-Tab, 1-7 next / previous view, jump to a view
g G, PgUp PgDn top / bottom, page (Ctrl-u / Ctrl-d)
Space + - tree: toggle / expand / collapse
/ search the current view (live; Enter keeps, Esc clears)
s change sort (tree: size/name; files: size/age/path)
r rescan
? help
CtrL-L redraw
q / Ctrl-C quit

The mouse works (wheel, click a row, click a tab) but is never required.

Reading coverage in the UI

Rootwatch compares what it walked with what the filesystem says is used.

The result is shown as a badge everywhere it matters:

level meaning
COMPLETE >= 95% of used space was seen
SUBSTANTIAL >= 80%
PARTIAL >= 40%
MINIMAL < 40%: rankings say little about where the space went

Anything below COMPLETE puts a banner at the top of the Overview. Rankings are marked PROVISIONAL (PARTIAL/SUBSTANTIAL) or UNRELIABLE (MINIMAL) in the text report, and sizes are shown as lower bounds (≥) in the TUI. The overall verdict is then "at least HIGH" or UNDETERMINED rather than "healthy". The Coverage view explains the gap: skipped sibling mounts that share a btrfs pool, permission-denied paths, pruned paths, I/O errors, shared extents. Scans of a directory (not a whole filesystem) are judged by errors only and say n/a (subtree scan).

Terminal requirements

At least 80x24, a UTF-8 locale and a terminal that supports the alternate screen (any modern emulator, tmux, screen). Mouse reporting is optional. Below 80x24 the UI shows "Terminal too small" instead of drawing. stdin and stdout must be a tty.

--privileged cannot be combined with the TUI. To run the TUI as root, invoke sudo rootwatch --tui directly.

Checks

Command Description
cargo test unit, scanner, analysis and TUI tests
cargo build --release && python3 scripts/pty_smoke.py real binary on a pty
cargo build --release --example panic_probe && python3 scripts/pty_panic.py run the panic probe on a pty
cargo run --release --example tui_screens -- docs/screenshots regenerate TUI screenshot captures
cargo run --release --example tui_bench -- /some/big/tree measure per-frame TUI cost