Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions crates/disktree-core/src/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -795,6 +807,7 @@ fn is_volume_candidate(mount: &Mount) -> bool {
| "overlay"
| "proc"
| "pstore"
| "ramfs"
| "securityfs"
| "sysfs"
| "tmpfs"
Expand Down Expand Up @@ -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<PathBuf> = 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(
Expand Down