Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(exa PR) 1190: Fix device major minor numbers #13

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ name = "exa"
ansi_term = "0.12"
glob = "0.3"
lazy_static = "1.3"
libc = "0.2"
libc = "0.2.135"
locale = "0.2"
log = "0.4"
natord = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions src/fs/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ pub enum Size {
/// - <http://www.lanana.org/docs/device-list/devices-2.6+.txt>
#[derive(Copy, Clone)]
pub struct DeviceIDs {
pub major: u8,
pub minor: u8,
pub major: i64,
pub minor: i64,
Comment on lines +197 to +198
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering libc defines pub type c_uint = u32;, I don't see the reason for using i64, would this ever be negative? https://docs.rs/libc/latest/libc/type.c_uint.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be to make space for this difference:

# 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;

ogham/exa#1126 (comment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this ever be negative?

For glibc, I guess it won't be.

Ref: how to interpret the dev_t type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this ever be negative?

For glibc, I guess it won't be.

Ref: how to interpret the dev_t type

I guess the original intent might have been to have space enough for both pub fn major(dev: dev_t) -> i32; and pub fn major(dev: ::dev_t) -> ::c_uint; (u32)?

}


Expand Down
13 changes: 6 additions & 7 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::os::windows::fs::MetadataExt;
use std::path::{Path, PathBuf};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

use libc::{major, minor};
use log::*;

use crate::fs::dir::Dir;
Expand Down Expand Up @@ -333,15 +334,13 @@ impl<'dir> File<'dir> {
f::Size::None
}
else if self.is_char_device() || self.is_block_device() {
let device_ids = self.metadata.rdev().to_be_bytes();
let device_ids = self.metadata.rdev();

// In C-land, getting the major and minor device IDs is done with
// preprocessor macros called `major` and `minor` that depend on
// the size of `dev_t`, but we just take the second-to-last and
// last bytes.
// SAFETY: `major()` and `minor()` can return an unsigned integer
// of at most 32bits, so an `i64` is going to accomodate them well
f::Size::DeviceIDs(f::DeviceIDs {
major: device_ids[6],
minor: device_ids[7],
major: unsafe { major(device_ids) as i64 },
minor: unsafe { minor(device_ids) as i64 },
cafkafk marked this conversation as resolved.
Show resolved Hide resolved
})
}
else {
Expand Down