diff options
author | Aidan Hobson Sayers <aidanhs@cantab.net> | 2017-02-13 19:34:17 +0000 |
---|---|---|
committer | Aidan Hobson Sayers <aidanhs@cantab.net> | 2017-02-17 15:32:32 +0000 |
commit | dbd3b16508f103c9567d32ee784731e95ab40493 (patch) | |
tree | 9bff5302ebde00428c6e9f6c4a770e8150a0d837 | |
parent | 109b0e867757f377029af84499369812e41cc595 (diff) | |
download | nix-dbd3b16508f103c9567d32ee784731e95ab40493.zip |
Implement major/minor macros, correct mkdev
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/sys/stat.rs | 18 |
2 files changed, 19 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 335098bf..3b5e85bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#491](https://github.com/nix-rust/nix/pull/491)) - Added `fchdir` in `::nix::unistd` ([#497](https://github.com/nix-rust/nix/pull/497)) +- Added `major` and `minor` in `::nix::sys::stat` for decomposing `dev_t` + ([#508](https://github.com/nix-rust/nix/pull/508)) ### Changed - `epoll_ctl` now could accept None as argument `event` @@ -89,6 +91,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#429](https://github.com/nix-rust/nix/pull/429)) - Fixed clone passing a potentially unaligned stack. ([#490](https://github.com/nix-rust/nix/pull/490)) +- Fixed mkdev not creating a `dev_t` the same way as libc. + ([#508](https://github.com/nix-rust/nix/pull/508)) ## [0.7.0] 2016-09-09 diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 076fe933..5bd63005 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -63,11 +63,23 @@ pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) } #[cfg(target_os = "linux")] -const MINORBITS: usize = 20; +pub fn major(dev: dev_t) -> u64 { + ((dev >> 32) & 0xfffff000) | + ((dev >> 8) & 0x00000fff) +} + +#[cfg(target_os = "linux")] +pub fn minor(dev: dev_t) -> u64 { + ((dev >> 12) & 0xffffff00) | + ((dev ) & 0x000000ff) +} #[cfg(target_os = "linux")] -pub fn mkdev(major: u64, minor: u64) -> dev_t { - (major << MINORBITS) | minor +pub fn makedev(major: u64, minor: u64) -> dev_t { + ((major & 0xfffff000) << 32) | + ((major & 0x00000fff) << 8) | + ((minor & 0xffffff00) << 12) | + ((minor & 0x000000ff) ) } pub fn umask(mode: Mode) -> Mode { |