diff --git a/crates/disktree-core/src/space.rs b/crates/disktree-core/src/space.rs index 8a2bc4ee..611233a3 100644 --- a/crates/disktree-core/src/space.rs +++ b/crates/disktree-core/src/space.rs @@ -778,15 +778,27 @@ fn is_volume_candidate(mount: &Mount) -> bool { { return false; } + // Sub-mounts under `/proc`, `/sys` and `/dev` (such as + // `/proc/sys/fs/binfmt_misc` or `/sys/fs/bpf`) are kernel and device + // interfaces, not storage volumes to offer for a scan. + if mount.point.starts_with("/proc") + || mount.point.starts_with("/sys") + || mount.point.starts_with("/dev") + { + return false; + } !matches!( mount.fstype.as_str(), "autofs" + | "binfmt_misc" + | "bpf" | "cgroup" | "cgroup2" | "configfs" | "debugfs" | "devpts" | "devtmpfs" + | "efivarfs" | "fuse.portal" | "fusectl" | "hugetlbfs" @@ -795,6 +807,7 @@ fn is_volume_candidate(mount: &Mount) -> bool { | "overlay" | "proc" | "pstore" + | "ramfs" | "securityfs" | "sysfs" | "tmpfs" @@ -1055,6 +1068,31 @@ portal /run/user/1000/doc fuse.portal rw 0 0 assert_eq!(points.len(), 2, "{points:?}"); } + #[test] + fn kernel_pseudo_filesystems_are_excluded_from_volume_candidates() { + let table = "\ +/dev/sda1 / ext4 rw 0 0 +/dev/sdb1 /home ext4 rw 0 0 +proc /proc proc rw 0 0 +binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0 +sysfs /sys sysfs rw 0 0 +bpf /sys/fs/bpf bpf rw 0 0 +efivarfs /sys/firmware/efi/efivars efivarfs rw 0 0 +devtmpfs /dev devtmpfs rw 0 0 +devpts /dev/pts devpts rw 0 0 +none /mnt/ramdisk ramfs rw 0 0 +"; + let points: Vec = volumes_in(&parse_mounts(table)) + .iter() + .map(|volume| volume.point.clone()) + .collect(); + assert_eq!( + points, + [PathBuf::from("/"), PathBuf::from("/home")], + "only real storage disks remain as volume candidates" + ); + } + #[test] fn separate_home_disk_is_its_own_volume() { let separate = parse_mounts(