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

Implement major/minor macros, correct mkdev #508

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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

Expand Down
18 changes: 15 additions & 3 deletions src/sys/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down