mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2145 from tertsdiepraam/ls/device_information
`ls`: implement device symbol and id
This commit is contained in:
commit
d43af35147
1 changed files with 21 additions and 6 deletions
|
@ -1332,7 +1332,7 @@ fn display_dir_entry_size(entry: &PathData, config: &Config) -> (usize, usize) {
|
|||
if let Some(md) = entry.md() {
|
||||
(
|
||||
display_symlink_count(&md).len(),
|
||||
display_size(md.len(), config).len(),
|
||||
display_size_or_rdev(&md, config).len(),
|
||||
)
|
||||
} else {
|
||||
(0, 0)
|
||||
|
@ -1502,7 +1502,7 @@ fn display_item_long(
|
|||
let _ = writeln!(
|
||||
out,
|
||||
" {} {} {}",
|
||||
pad_left(display_size(md.len(), config), max_size),
|
||||
pad_left(display_size_or_rdev(md, config), max_size),
|
||||
display_date(&md, config),
|
||||
// unwrap is fine because it fails when metadata is not available
|
||||
// but we already know that it is because it's checked at the
|
||||
|
@ -1657,13 +1657,28 @@ fn format_prefixed(prefixed: NumberPrefix<f64>) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
fn display_size(len: u64, config: &Config) -> String {
|
||||
fn display_size_or_rdev(metadata: &Metadata, config: &Config) -> String {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let ft = metadata.file_type();
|
||||
if ft.is_char_device() || ft.is_block_device() {
|
||||
let dev: u64 = metadata.rdev();
|
||||
let major = (dev >> 8) as u8;
|
||||
let minor = dev as u8;
|
||||
return format!("{}, {}", major, minor);
|
||||
}
|
||||
}
|
||||
|
||||
display_size(metadata.len(), config)
|
||||
}
|
||||
|
||||
fn display_size(size: u64, config: &Config) -> String {
|
||||
// NOTE: The human-readable behaviour deviates from the GNU ls.
|
||||
// The GNU ls uses binary prefixes by default.
|
||||
match config.size_format {
|
||||
SizeFormat::Binary => format_prefixed(NumberPrefix::binary(len as f64)),
|
||||
SizeFormat::Decimal => format_prefixed(NumberPrefix::decimal(len as f64)),
|
||||
SizeFormat::Bytes => len.to_string(),
|
||||
SizeFormat::Binary => format_prefixed(NumberPrefix::binary(size as f64)),
|
||||
SizeFormat::Decimal => format_prefixed(NumberPrefix::decimal(size as f64)),
|
||||
SizeFormat::Bytes => size.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue