Skip to content

Commit 8daf10a

Browse files
committed
df: Add a mount_dev_id to use id's instead of paths
foo
1 parent 603d374 commit 8daf10a

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/uu/df/src/filesystem.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,25 @@ pub(crate) enum FsError {
4545
MountMissing,
4646
}
4747

48+
// spell-checker:ignore (fs) autofs binfmt
49+
4850
/// Check whether `mount` has been over-mounted.
4951
///
50-
/// `mount` is considered over-mounted if it there is an element in
51-
/// `mounts` after mount that has the same `mount_dir`.
52+
/// `mount` is considered over-mounted if there is a later element in
53+
/// `mounts` that has the same `mount_dir` and a different `dev_name`.
54+
///
55+
/// Special case: autofs mounts are NOT considered over-mounted even if
56+
/// there's a different filesystem at the same path, because autofs acts
57+
/// as a trigger that mounts other filesystems. Both the autofs entry and
58+
/// the triggered mount (e.g., binfmt_misc) should be shown.
5259
#[cfg(not(windows))]
5360
fn is_over_mounted(mounts: &[MountInfo], mount: &MountInfo) -> bool {
61+
// autofs mounts are never considered over-mounted - they coexist with
62+
// the filesystems they trigger (e.g., systemd-1 autofs + binfmt_misc)
63+
if mount.fs_type == "autofs" {
64+
return false;
65+
}
66+
5467
let last_mount_for_dir = mounts.iter().rfind(|m| m.mount_dir == mount.mount_dir);
5568

5669
if let Some(lmi) = last_mount_for_dir {
@@ -355,5 +368,32 @@ mod tests {
355368
FsError::OverMounted
356369
);
357370
}
371+
372+
/// Test for issue #9952: autofs mounts should NOT be considered over-mounted
373+
/// even when there's a different filesystem at the same path.
374+
/// autofs acts as a trigger that mounts other filesystems (like binfmt_misc),
375+
/// and both should be shown in df --all output.
376+
#[test]
377+
fn test_autofs_not_over_mounted() {
378+
// Simulates: systemd-1 (autofs) and binfmt_misc at /proc/sys/fs/binfmt_misc
379+
let mut mount_info1 =
380+
mount_info_with_dev_name("/proc/sys/fs/binfmt_misc", Some("systemd-1"));
381+
mount_info1.fs_type = "autofs".to_string();
382+
let mut mount_info2 =
383+
mount_info_with_dev_name("/proc/sys/fs/binfmt_misc", Some("binfmt_misc"));
384+
mount_info2.fs_type = "binfmt_misc".to_string();
385+
let mounts = [mount_info1, mount_info2];
386+
387+
// autofs mount should NOT be considered over-mounted
388+
assert!(
389+
!is_over_mounted(&mounts, &mounts[0]),
390+
"autofs mount should not be considered over-mounted"
391+
);
392+
// And neither should the second one (it's the last at this path)
393+
assert!(
394+
!is_over_mounted(&mounts, &mounts[1]),
395+
"Last mount at path should not be considered over-mounted"
396+
);
397+
}
358398
}
359399
}

src/uucore/src/lib/features/fsext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
//! Set of functions to manage file systems
77
8-
// spell-checker:ignore DATETIME getmntinfo subsecond (fs) cifs smbfs
8+
// spell-checker:ignore DATETIME getmntinfo subsecond (fs) cifs smbfs autofs binfmt
99

1010
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
1111
const LINUX_MTAB: &str = "/etc/mtab";

0 commit comments

Comments
 (0)