From: Wolfgang Bumiller Date: Mon, 4 Feb 2019 09:42:03 +0000 (+0100) Subject: tools: add dev_t_major/minor X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=243c4e5892e34d902ff6e9e65d01e8912430dea1 tools: add dev_t_major/minor 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 --- 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;