mirror of
https://github.com/tobi/disktree.git
synced 2026-11-28 08:00:53 +00:00
Merge pull request #106 from bet4it/fix/filter-pseudo-volumes
This commit is contained in:
@@ -864,15 +864,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"
|
||||
@@ -881,6 +893,7 @@ fn is_volume_candidate(mount: &Mount) -> bool {
|
||||
| "overlay"
|
||||
| "proc"
|
||||
| "pstore"
|
||||
| "ramfs"
|
||||
| "securityfs"
|
||||
| "sysfs"
|
||||
| "tmpfs"
|
||||
@@ -1175,6 +1188,31 @@ portal /run/user/1000/doc fuse.portal rw 0 0
|
||||
assert!(points.contains(&PathBuf::from("/var/log")), "{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(
|
||||
|
||||
Reference in New Issue
Block a user