Skip to content

Commit d0c7dc2

Browse files
fix find device id
1 parent 4723145 commit d0c7dc2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg/common/common.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,24 @@ func GetDeviceNumbers(patternStr string) (map[string]string, error) {
5454
return nil
5555
}
5656

57+
// Skip if not device
58+
mode := info.Mode()
59+
if !(mode&os.ModeDevice != 0 || mode&os.ModeCharDevice != 0) {
60+
return nil
61+
}
62+
5763
// Check if the deviceName matches the pattern
5864
deviceName := filepath.Base(path)
5965
if regex.MatchString(deviceName) {
6066
// Retrieve major/minor numbers
6167
statT, ok := info.Sys().(*syscall.Stat_t)
6268
if !ok {
63-
return nil // Skip files if syscall.Stat_t is not available
69+
return nil
6470
}
6571

6672
// Extract major and minor numbers
67-
major := (statT.Rdev >> 8) & 0xFF
68-
minor := statT.Rdev & 0xFF
73+
major := (statT.Rdev >> 8) & 0xFFF
74+
minor := (statT.Rdev & 0xFF) | ((statT.Rdev >> 12) & 0xFFF00)
6975

7076
// Add to result map
7177
result[deviceName] = fmt.Sprintf("%d:%d", major, minor)

0 commit comments

Comments
 (0)