1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

df: fix calculation of IUse%

Fixes #3355
This commit is contained in:
Daniel Hofstetter 2022-04-04 15:16:31 +02:00 committed by Sylvestre Ledru
parent 7d14961235
commit 56e8dda606
2 changed files with 34 additions and 3 deletions

View file

@ -154,6 +154,7 @@ impl From<Filesystem> for Row {
..
} = fs.usage;
let bused = blocks - bfree;
let fused = files - ffree;
Self {
file: fs.file,
fs_device: dev_name,
@ -177,12 +178,12 @@ impl From<Filesystem> for Row {
Some(bavail as f64 / ((bused + bavail) as f64))
},
inodes: files,
inodes_used: files - ffree,
inodes_used: fused,
inodes_free: ffree,
inodes_usage: if files == 0 {
None
} else {
Some(ffree as f64 / files as f64)
Some(fused as f64 / files as f64)
},
}
}

View file

@ -1,4 +1,4 @@
// spell-checker:ignore udev pcent
// spell-checker:ignore udev pcent iuse itotal iused ipcent
use crate::common::util::*;
#[test]
@ -179,6 +179,36 @@ fn test_use_percentage() {
}
}
#[test]
fn test_iuse_percentage() {
let output = new_ucmd!()
.args(&["--total", "--output=itotal,iused,ipcent"])
.succeeds()
.stdout_move_str();
// Skip the header line.
let lines: Vec<&str> = output.lines().skip(1).collect();
for line in lines {
let mut iter = line.split_whitespace();
let reported_inodes = iter.next().unwrap().parse::<f64>().unwrap();
let reported_iused = iter.next().unwrap().parse::<f64>().unwrap();
let reported_percentage = iter.next().unwrap();
if reported_percentage == "-" {
assert_eq!(0.0, reported_inodes);
assert_eq!(0.0, reported_iused);
} else {
let reported_percentage = reported_percentage[..reported_percentage.len() - 1]
.parse::<u8>()
.unwrap();
let computed_percentage = (100.0 * (reported_iused / reported_inodes)).ceil() as u8;
assert_eq!(computed_percentage, reported_percentage);
}
}
}
#[test]
fn test_block_size_1024() {
fn get_header(block_size: u64) -> String {