]> git.proxmox.com Git - pxar.git/commitdiff
add Device::to_dev_t
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 20 Apr 2020 13:24:34 +0000 (15:24 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 20 Apr 2020 13:24:34 +0000 (15:24 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/format.rs

index 62fb51a8ddecd9b4cf9bc3986712ecce113d3c5a..f8927fff78254f6959e6c04c62a37ad44476d66b 100644 (file)
@@ -324,6 +324,19 @@ pub struct Device {
     pub minor: u64,
 }
 
+#[cfg(target_os = "linux")]
+impl Device {
+    /// Get a `dev_t` value for this device.
+    #[rustfmt::skip]
+    pub fn to_dev_t(&self) -> u64 {
+        // see bits/sysmacros.h
+        ((self.major & 0x0000_0fff) << 8) |
+        ((self.major & 0xffff_f000) << 32) |
+         (self.minor & 0x0000_00ff) |
+        ((self.minor & 0xffff_ff00) << 12)
+    }
+}
+
 #[derive(Clone, Debug)]
 #[repr(C)]
 pub struct FCaps {