[pve-devel] [PATCH common 1/1] tools: add dev_t_major/minor

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Feb 4 10:42:03 CET 2019


Extract major/minor from `dev_t` values as found in stat()
calls, with support for the full 32 bit values.

The device value returned by stat() is 32 bits long and encoded as
high 12 bit of the minor value as in the 12 MSBs, 12 bit major value,
then the low 8 bit of the minor value in the low byte.

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/Tools.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index cd236b5..189b552 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -1632,4 +1632,16 @@ sub get_host_arch {
     }
 }
 
+# Devices are: [ (12 bits minor) (12 bits major) (8 bits minor) ]
+sub dev_t_major($) {
+    my ($dev_t) = @_;
+    return (int($dev_t) & 0xfff00) >> 8;
+}
+
+sub dev_t_minor($) {
+    my ($dev_t) = @_;
+    $dev_t = int($dev_t);
+    return (($dev_t >> 12) & 0xfff00) | ($dev_t & 0xff);
+}
+
 1;
-- 
2.11.0





More information about the pve-devel mailing list