Expand description
§livedisk
Cross-platform enumeration of the live system’s physical disks and
partitions — diskutil list / lsblk / diskpart, but as a library with
one unified model across macOS, Linux, and Windows.
for disk in livedisk::enumerate()? {
println!("{} — {}", disk.name, livedisk::human_size(disk.size_bytes));
for part in &disk.partitions {
println!(" {} {}", part.name, livedisk::human_size(part.size_bytes));
}
}Discovery is the only OS-specific part. Each backend (sysfs on Linux, the
IOKit IOMedia registry on macOS, DeviceIoControl on Windows) fills the
same PhysicalDisk/Partition structs; everything downstream — the
render_overview bar chart, the per-disk render_disk_bar, the
render_listing view, and the JSON form — is platform-agnostic.
open_device opens a chosen device node as a sized Read + Seek so a
partition/filesystem analyzer can run on the live disk exactly as it would on
an image file.
Listing layout/metadata works unprivileged on all three platforms (it
reads the kernel’s device registry, not raw sectors); only reading a device
needs root/Administrator. Backends therefore never silently return an empty
list on a permission problem — they surface Error.
Structs§
- Partition
- A partition (slice/volume) within a
PhysicalDisk. - Physical
Disk - A whole physical (or, on macOS, synthesized) disk on the live system.
Enums§
- Error
- Failure enumerating live devices.
Functions§
- enumerate
- Enumerate every physical disk on the live system, each with its partitions.
- human_
size - Format a byte count the way disk utilities do — decimal (SI) units with one
fractional digit (
4.0 TB,524.3 MB,24.6 KB), matchingdiskutil/lsblkso output is recognisable. Bytes under 1000 render asN B. - open_
device - Open a live block device for reading and return it with its size in bytes.
- render_
disk_ bar - Render the proportional bar plus legend for one disk.
widthis the bar’s inner column count;colorselects ANSI-coloured solid blocks (TTY) versus ASCII glyphs (pipe-safe). The disk’s largest partition is drawn in the primary palette colour. - render_
disks - Render the enumerated disks as a unified, indented text table — the
disk4n6 listhuman view. Whole disks are flush-left; their partitions are indented beneath them, so the layout reads the same on every platform. - render_
listing - Render the full
disk4n6 listview: each disk as a header line followed by its proportional partition bar (seerender_disk_bar). Synthesized disks (macOS APFS containers, Linux device-mapper) whose volumes share space rather than occupy fixed extents get a plain volume list instead of a — misleading — proportional bar.colorselects ANSI vs ASCII (the caller passes whether stdout is a TTY). - render_
overview - Render an at-a-glance overview comparing the physical disks’ capacities — a horizontal bar chart, one disk per line, each bar’s length proportional to that disk’s size relative to the largest, so the biggest disk fills the row and the rest read as fractions of it. Each line also shows the absolute size and the disk’s share of total storage. Synthesized disks (APFS containers, device-mapper) are excluded because they overlay physical space rather than add to it. Returns empty when fewer than two physical disks exist.