Skip to content

Commit 5346ff8

Browse files
committed
df: add binfmt_misc to is_dummy_filesystem
1 parent 911bc15 commit 5346ff8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,10 @@ fn is_dummy_filesystem(fs_type: &str, mount_option: &str) -> bool {
392392
// for NetBSD 3.0
393393
| "kernfs"
394394
// for Irix 6.5
395-
| "ignore" => true,
395+
| "ignore"
396+
// Binary format support pseudo-filesystem (mounted as device "none")
397+
// https://docs.kernel.org/admin-guide/binfmt-misc.html
398+
| "binfmt_misc" => true,
396399
_ => fs_type == "none"
397400
&& !mount_option.contains(MOUNT_OPT_BIND)
398401
}
@@ -1220,4 +1223,11 @@ mod tests {
12201223
crate::os_str_from_bytes(b"/mnt/some- -dir-\xf3").unwrap()
12211224
);
12221225
}
1226+
1227+
#[test]
1228+
#[cfg(all(unix, not(any(target_os = "aix", target_os = "redox"))))]
1229+
fn test_binfmt_misc_is_dummy() {
1230+
use super::is_dummy_filesystem;
1231+
assert!(is_dummy_filesystem("binfmt_misc", ""));
1232+
}
12231233
}

tests/by-util/test_df.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,39 @@ fn test_nonexistent_file() {
10461046
.stderr_is("df: does-not-exist: No such file or directory\n")
10471047
.stdout_is("File\n.\n");
10481048
}
1049+
1050+
#[test]
1051+
#[cfg(target_os = "linux")]
1052+
fn test_df_all_shows_binfmt_misc() {
1053+
// Check if binfmt_misc is mounted on this system
1054+
if std::path::Path::new("/proc/sys/fs/binfmt_misc").exists() {
1055+
let output = new_ucmd!()
1056+
.args(&["--all", "--output=fstype,target"])
1057+
.succeeds()
1058+
.stdout_str_lossy();
1059+
1060+
// binfmt_misc should appear in the output when using --all
1061+
assert!(
1062+
output.contains("binfmt_misc"),
1063+
"Expected binfmt_misc filesystem to appear in df --all output"
1064+
);
1065+
}
1066+
}
1067+
1068+
#[test]
1069+
#[cfg(target_os = "linux")]
1070+
fn test_df_hides_binfmt_misc_by_default() {
1071+
// Check if binfmt_misc is mounted on this system
1072+
if std::path::Path::new("/proc/sys/fs/binfmt_misc").exists() {
1073+
let output = new_ucmd!()
1074+
.args(&["--output=fstype,target"])
1075+
.succeeds()
1076+
.stdout_str_lossy();
1077+
1078+
// binfmt_misc should NOT appear in the output without --all (it's a dummy filesystem)
1079+
assert!(
1080+
!output.contains("binfmt_misc"),
1081+
"Expected binfmt_misc filesystem to be hidden in df output without --all"
1082+
);
1083+
}
1084+
}

0 commit comments

Comments
 (0)