Calculate device major/minor using bitshift

Previously, devices with a major/minor number >256 would fail to be
detected.  Switch to using bitwise conversion (similar to
sys/sysmacros in C).

[NO NEW TESTS NEEDED]

Signed-off-by: Robb Manes <robbmanes@protonmail.com>
This commit is contained in:
Robb Manes
2022-02-16 15:08:41 -05:00
parent f918a9418f
commit 90066af62e

View File

@ -39,8 +39,10 @@ func FindDeviceNodes() (map[string]string, error) {
if !ok {
return errors.Errorf("Could not convert stat output for use")
}
major := sysstat.Rdev / 256
minor := sysstat.Rdev % 256
// We must typeconvert sysstat.Rdev from uint64->int to avoid constant overflow
rdev := int(sysstat.Rdev)
major := ((rdev >> 8) & 0xfff) | ((rdev >> 32) & ^0xfff)
minor := (rdev & 0xff) | ((rdev >> 12) & ^0xff)
nodes[fmt.Sprintf("%d:%d", major, minor)] = path