mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27:45 +00:00
ls: implement device symbol and id
This commit is contained in:
parent
b89978a4c9
commit
c69afa00ff
1 changed files with 16 additions and 4 deletions
|
@ -1623,18 +1623,30 @@ fn format_prefixed(prefixed: NumberPrefix<f64>) -> String {
|
||||||
fn display_file_size(metadata: &Metadata, config: &Config) -> String {
|
fn display_file_size(metadata: &Metadata, config: &Config) -> String {
|
||||||
// NOTE: The human-readable behaviour deviates from the GNU ls.
|
// NOTE: The human-readable behaviour deviates from the GNU ls.
|
||||||
// The GNU ls uses binary prefixes by default.
|
// The GNU ls uses binary prefixes by default.
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
match config.size_format {
|
match config.size_format {
|
||||||
SizeFormat::Binary => format_prefixed(NumberPrefix::binary(metadata.len() as f64)),
|
SizeFormat::Binary => format_prefixed(NumberPrefix::binary(metadata.len() as f64)),
|
||||||
SizeFormat::Decimal => format_prefixed(NumberPrefix::decimal(metadata.len() as f64)),
|
SizeFormat::Decimal => format_prefixed(NumberPrefix::decimal(metadata.len() as f64)),
|
||||||
SizeFormat::Bytes => metadata.len().to_string(),
|
SizeFormat::Bytes => metadata.len().to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn display_file_type(file_type: FileType) -> char {
|
fn display_file_type(file_type: FileType) -> char {
|
||||||
if file_type.is_dir() {
|
if file_type.is_dir() {
|
||||||
'd'
|
'd'
|
||||||
} else if file_type.is_symlink() {
|
} else if file_type.is_symlink() {
|
||||||
'l'
|
'l'
|
||||||
|
} else if file_type.is_block_device() {
|
||||||
|
'b'
|
||||||
|
} else if file_type.is_char_device() {
|
||||||
|
'c'
|
||||||
} else {
|
} else {
|
||||||
'-'
|
'-'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue