Skip to content

Commit 5e28694

Browse files
fix find devices
1 parent bef3705 commit 5e28694

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

pkg/common/common.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,32 @@ 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) {
57+
// Check if the deviceName matches the pattern
58+
deviceName := filepath.Base(path)
59+
if !regex.MatchString(deviceName) {
6060
return nil
6161
}
6262

63-
// Check if the deviceName matches the pattern
64-
deviceName := filepath.Base(path)
65-
if regex.MatchString(deviceName) {
66-
// Retrieve major/minor numbers
67-
statT, ok := info.Sys().(*syscall.Stat_t)
68-
if !ok {
69-
return nil
70-
}
71-
72-
// Extract major and minor numbers
73-
major := (statT.Rdev >> 8) & 0xFFF
74-
minor := (statT.Rdev & 0xFF) | ((statT.Rdev >> 12) & 0xFFF00)
75-
76-
// Skip "misc" devices (major 10)
77-
if major == 10 {
78-
return nil
79-
}
80-
81-
// Add to result map
82-
result[deviceName] = fmt.Sprintf("%d:%d", major, minor)
63+
stat, err := os.Stat(path)
64+
if err != nil {
65+
return nil
66+
}
67+
68+
statT, ok := stat.Sys().(*syscall.Stat_t)
69+
if !ok {
70+
return nil
8371
}
8472

73+
major := (statT.Rdev >> 8) & 0xFFF
74+
minor := (statT.Rdev & 0xFF) | ((statT.Rdev >> 12) & 0xFFF00)
75+
76+
// Skip "misc" devices (major 10)
77+
if major == 10 {
78+
return nil
79+
}
80+
81+
result[deviceName] = fmt.Sprintf("%d:%d", major, minor)
82+
8583
return nil
8684
})
8785

0 commit comments

Comments
 (0)