File tree Expand file tree Collapse file tree 1 file changed +21
-23
lines changed Expand file tree Collapse file tree 1 file changed +21
-23
lines changed Original file line number Diff line number Diff line change @@ -54,34 +54,32 @@ func GetDeviceNumbers(patternStr string) (map[string]string, error) {
54
54
return nil
55
55
}
56
56
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 ) {
60
60
return nil
61
61
}
62
62
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
83
71
}
84
72
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
+
85
83
return nil
86
84
})
87
85
You can’t perform that action at this time.
0 commit comments