Skip to content

Commit ea64612

Browse files
authored
df: add binfmt_misc to is_dummy_filesystem (#9975)
* df: add binfmt_misc to is_dummy_filesystem * df: add spell-checker ignore for binfmt * uucore: rmaix flag
1 parent d28cb30 commit ea64612

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl From<StatFs> for MountInfo {
380380
}
381381
}
382382

383-
#[cfg(all(unix, not(any(target_os = "aix", target_os = "redox"))))]
383+
#[cfg(all(unix, not(target_os = "redox")))]
384384
fn is_dummy_filesystem(fs_type: &str, mount_option: &str) -> bool {
385385
// spell-checker:disable
386386
match fs_type {
@@ -392,7 +392,9 @@ 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
397+
| "binfmt_misc" => true,
396398
_ => fs_type == "none"
397399
&& !mount_option.contains(MOUNT_OPT_BIND)
398400
}
@@ -1220,4 +1222,12 @@ mod tests {
12201222
crate::os_str_from_bytes(b"/mnt/some- -dir-\xf3").unwrap()
12211223
);
12221224
}
1225+
1226+
#[test]
1227+
#[cfg(all(unix, not(target_os = "redox")))]
1228+
// spell-checker:ignore (word) binfmt
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: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5-
// spell-checker:ignore udev pcent iuse itotal iused ipcent
5+
// spell-checker:ignore udev pcent iuse itotal iused ipcent binfmt
66
#![allow(
77
clippy::similar_names,
88
clippy::cast_possible_truncation,
@@ -1046,3 +1046,48 @@ 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
1054+
let is_mounted = std::fs::read_to_string("/proc/self/mountinfo")
1055+
.map(|content| content.lines().any(|line| line.contains("binfmt_misc")))
1056+
.unwrap_or(false);
1057+
1058+
if is_mounted {
1059+
let output = new_ucmd!()
1060+
.args(&["--all", "--output=fstype,target"])
1061+
.succeeds()
1062+
.stdout_str_lossy();
1063+
1064+
assert!(
1065+
output.contains("binfmt_misc"),
1066+
"Expected binfmt_misc filesystem to appear in df --all output when it's mounted"
1067+
);
1068+
}
1069+
// If binfmt_misc is not mounted, skip the test silently
1070+
}
1071+
1072+
#[test]
1073+
#[cfg(target_os = "linux")]
1074+
fn test_df_hides_binfmt_misc_by_default() {
1075+
// Check if binfmt_misc is mounted
1076+
let is_mounted = std::fs::read_to_string("/proc/self/mountinfo")
1077+
.map(|content| content.lines().any(|line| line.contains("binfmt_misc")))
1078+
.unwrap_or(false);
1079+
1080+
if is_mounted {
1081+
let output = new_ucmd!()
1082+
.args(&["--output=fstype,target"])
1083+
.succeeds()
1084+
.stdout_str_lossy();
1085+
1086+
// binfmt_misc should NOT appear in the output without --all
1087+
assert!(
1088+
!output.contains("binfmt_misc"),
1089+
"Expected binfmt_misc filesystem to be hidden in df output without --all"
1090+
);
1091+
}
1092+
// If binfmt_misc is not mounted, skip the test silently
1093+
}

0 commit comments

Comments
 (0)