Open SteveLauC opened 2 years ago
Seems that I found the reason, DeviceID
is defined as following:
pub struct DeviceIDs {
pub major: u8,
pub minor: u8,
}
u8
is apparently not sufficient for those IDs...
For someone who is interested in implementing this, you need major()
and minor()
functions from libc
. These two functions for apple platforms are added in libc#2937, and included in release 0.2.135
.
The impl is basically something like this:
f::Size::DeviceIDs(f::DeviceIDs {
major: unsafe{major(device_ids as dev_t)},
minor: unsafe{minor(device_ids as dev_t)},
})
#[derive(Copy, Clone)]
pub struct DeviceIDs {
pub major: u32,
pub minor: u32,
}
What you need to fight is the difference between Linux's major()/minor()` definitions and the macOS one:
# Linux
pub type dev_t = u64;
pub fn major(dev: ::dev_t) -> ::c_uint;
pub fn minor(dev: ::dev_t) -> ::c_uint;
# macOS
pub type dev_t = i32;
pub fn major(dev: dev_t) -> i32;
pub fn minor(dev: dev_t) -> i32;
I noticed that the device ID returned by
exa
is wrong:And this behavior is actually documented in the source code: https://github.com/ogham/exa/blob/master/src/fs/file.rs#L321~L332
Any reason why it is not correctly decomposed and returned?