diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index ce734ff2d32..f2ae59a76f3 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -380,7 +380,7 @@ impl From for MountInfo { } } -#[cfg(all(unix, not(any(target_os = "aix", target_os = "redox"))))] +#[cfg(all(unix, not(target_os = "redox")))] fn is_dummy_filesystem(fs_type: &str, mount_option: &str) -> bool { // spell-checker:disable match fs_type { @@ -392,7 +392,9 @@ fn is_dummy_filesystem(fs_type: &str, mount_option: &str) -> bool { // for NetBSD 3.0 | "kernfs" // for Irix 6.5 - | "ignore" => true, + | "ignore" + // Binary format support pseudo-filesystem + | "binfmt_misc" => true, _ => fs_type == "none" && !mount_option.contains(MOUNT_OPT_BIND) } @@ -1220,4 +1222,12 @@ mod tests { crate::os_str_from_bytes(b"/mnt/some- -dir-\xf3").unwrap() ); } + + #[test] + #[cfg(all(unix, not(target_os = "redox")))] + // spell-checker:ignore (word) binfmt + fn test_binfmt_misc_is_dummy() { + use super::is_dummy_filesystem; + assert!(is_dummy_filesystem("binfmt_misc", "")); + } } diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 8b305ce4273..4754acbfe41 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -2,7 +2,7 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore udev pcent iuse itotal iused ipcent +// spell-checker:ignore udev pcent iuse itotal iused ipcent binfmt #![allow( clippy::similar_names, clippy::cast_possible_truncation, @@ -1046,3 +1046,48 @@ fn test_nonexistent_file() { .stderr_is("df: does-not-exist: No such file or directory\n") .stdout_is("File\n.\n"); } + +#[test] +#[cfg(target_os = "linux")] +fn test_df_all_shows_binfmt_misc() { + // Check if binfmt_misc is mounted + let is_mounted = std::fs::read_to_string("/proc/self/mountinfo") + .map(|content| content.lines().any(|line| line.contains("binfmt_misc"))) + .unwrap_or(false); + + if is_mounted { + let output = new_ucmd!() + .args(&["--all", "--output=fstype,target"]) + .succeeds() + .stdout_str_lossy(); + + assert!( + output.contains("binfmt_misc"), + "Expected binfmt_misc filesystem to appear in df --all output when it's mounted" + ); + } + // If binfmt_misc is not mounted, skip the test silently +} + +#[test] +#[cfg(target_os = "linux")] +fn test_df_hides_binfmt_misc_by_default() { + // Check if binfmt_misc is mounted + let is_mounted = std::fs::read_to_string("/proc/self/mountinfo") + .map(|content| content.lines().any(|line| line.contains("binfmt_misc"))) + .unwrap_or(false); + + if is_mounted { + let output = new_ucmd!() + .args(&["--output=fstype,target"]) + .succeeds() + .stdout_str_lossy(); + + // binfmt_misc should NOT appear in the output without --all + assert!( + !output.contains("binfmt_misc"), + "Expected binfmt_misc filesystem to be hidden in df output without --all" + ); + } + // If binfmt_misc is not mounted, skip the test silently +}