summaryrefslogtreecommitdiff
path: root/src/sys/stat.rs
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2017-02-18 02:29:01 +0900
committerHomu <homu@barosl.com>2017-02-18 02:29:01 +0900
commite7629f3e91535464c5857820dfc18ac0795a6893 (patch)
tree68a68cf56e0b7097cbb786cca2637f0e9de4607d /src/sys/stat.rs
parent54e6197b32dc3583bde9df797b620b255a75885e (diff)
parentdbd3b16508f103c9567d32ee784731e95ab40493 (diff)
downloadnix-e7629f3e91535464c5857820dfc18ac0795a6893.zip
Auto merge of #508 - aidanhs:aphs-major-minor-macros, r=posborne
Implement major/minor macros, correct mkdev It appears that the previous `mkdev` was based on the kernel headers (https://github.com/torvalds/linux/blob/v4.7/include/linux/kdev_t.h#L6) which (I guess) is the internal kernel dev_t. Scrolling down the file you can see some bitshifting operations to do conversions. The new implementation(s) are based on [musl](http://git.musl-libc.org/cgit/musl/tree/include/sys/sysmacros.h?id=dbbb3734d8c0176feabd6c46e2e85bbc3b8a60af) and [glibc](https://github.molgen.mpg.de/git-mirror/glibc/blob/20003c49884422da7ffbc459cdeee768a6fee07b/sysdeps/unix/sysv/linux/sys/sysmacros.h#L38), which are in agreement about how dev_t should be handled. (as it happens I suspect we could omit the shift by 32 since I don't see that in the kernel headers, but doesn't hurt to take the conservative route and mimic the libcs)
Diffstat (limited to 'src/sys/stat.rs')
-rw-r--r--src/sys/stat.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index 1beb349e..4bb4927a 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 {