Skip to content

Commit dbd3b16

Browse files
committed
Implement major/minor macros, correct mkdev
1 parent 109b0e8 commit dbd3b16

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3333
([#491](https://github.com/nix-rust/nix/pull/491))
3434
- Added `fchdir` in `::nix::unistd`
3535
([#497](https://github.com/nix-rust/nix/pull/497))
36+
- Added `major` and `minor` in `::nix::sys::stat` for decomposing `dev_t`
37+
([#508](https://github.com/nix-rust/nix/pull/508))
3638

3739
### Changed
3840
- `epoll_ctl` now could accept None as argument `event`
@@ -89,6 +91,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
8991
([#429](https://github.com/nix-rust/nix/pull/429))
9092
- Fixed clone passing a potentially unaligned stack.
9193
([#490](https://github.com/nix-rust/nix/pull/490))
94+
- Fixed mkdev not creating a `dev_t` the same way as libc.
95+
([#508](https://github.com/nix-rust/nix/pull/508))
9296

9397
## [0.7.0] 2016-09-09
9498

src/sys/stat.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,23 @@ pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t)
6363
}
6464

6565
#[cfg(target_os = "linux")]
66-
const MINORBITS: usize = 20;
66+
pub fn major(dev: dev_t) -> u64 {
67+
((dev >> 32) & 0xfffff000) |
68+
((dev >> 8) & 0x00000fff)
69+
}
70+
71+
#[cfg(target_os = "linux")]
72+
pub fn minor(dev: dev_t) -> u64 {
73+
((dev >> 12) & 0xffffff00) |
74+
((dev ) & 0x000000ff)
75+
}
6776

6877
#[cfg(target_os = "linux")]
69-
pub fn mkdev(major: u64, minor: u64) -> dev_t {
70-
(major << MINORBITS) | minor
78+
pub fn makedev(major: u64, minor: u64) -> dev_t {
79+
((major & 0xfffff000) << 32) |
80+
((major & 0x00000fff) << 8) |
81+
((minor & 0xffffff00) << 12) |
82+
((minor & 0x000000ff) )
7183
}
7284

7385
pub fn umask(mode: Mode) -> Mode {

0 commit comments

Comments
 (0)