@@ -2240,6 +2240,7 @@ func (d *disk) getDiskLimits() (map[string]diskBlockLimit, error) {
2240
2240
2241
2241
// Build a list of all valid block devices
2242
2242
validBlocks := []string {}
2243
+ parentBlocks := map [string ]string {}
2243
2244
2244
2245
dents , err := os .ReadDir ("/sys/class/block/" )
2245
2246
if err != nil {
@@ -2248,10 +2249,13 @@ func (d *disk) getDiskLimits() (map[string]diskBlockLimit, error) {
2248
2249
2249
2250
for _ , f := range dents {
2250
2251
fPath := filepath .Join ("/sys/class/block/" , f .Name ())
2252
+
2253
+ // Ignore partitions.
2251
2254
if util .PathExists (fmt .Sprintf ("%s/partition" , fPath )) {
2252
2255
continue
2253
2256
}
2254
2257
2258
+ // Only select real block devices.
2255
2259
if ! util .PathExists (fmt .Sprintf ("%s/dev" , fPath )) {
2256
2260
continue
2257
2261
}
@@ -2261,7 +2265,37 @@ func (d *disk) getDiskLimits() (map[string]diskBlockLimit, error) {
2261
2265
return nil , err
2262
2266
}
2263
2267
2264
- validBlocks = append (validBlocks , strings .TrimSuffix (string (block ), "\n " ))
2268
+ // Add the block to the list.
2269
+ blockIdentifier := strings .TrimSuffix (string (block ), "\n " )
2270
+ validBlocks = append (validBlocks , blockIdentifier )
2271
+
2272
+ // Look for partitions.
2273
+ subDents , err := os .ReadDir (fPath )
2274
+ if err != nil {
2275
+ return nil , err
2276
+ }
2277
+
2278
+ for _ , sub := range subDents {
2279
+ // Skip files.
2280
+ if ! sub .IsDir () {
2281
+ continue
2282
+ }
2283
+
2284
+ // Select partitions.
2285
+ if ! util .PathExists (filepath .Join (fPath , sub .Name (), "partition" )) {
2286
+ continue
2287
+ }
2288
+
2289
+ // Get the block identifier for the partition.
2290
+ partition , err := os .ReadFile (filepath .Join (fPath , sub .Name (), "dev" ))
2291
+ if err != nil {
2292
+ return nil , err
2293
+ }
2294
+
2295
+ // Add the partition to the map.
2296
+ partitionIdentifier := strings .TrimSuffix (string (partition ), "\n " )
2297
+ parentBlocks [partitionIdentifier ] = blockIdentifier
2298
+ }
2265
2299
}
2266
2300
2267
2301
// Process all the limits
@@ -2310,6 +2344,9 @@ func (d *disk) getDiskLimits() (map[string]diskBlockLimit, error) {
2310
2344
if slices .Contains (validBlocks , block ) {
2311
2345
// Straightforward entry (full block device)
2312
2346
blockStr = block
2347
+ } else if parentBlocks [block ] != "" {
2348
+ // Known partition.
2349
+ blockStr = parentBlocks [block ]
2313
2350
} else {
2314
2351
// Attempt to deal with a partition (guess its parent)
2315
2352
fields := strings .SplitN (block , ":" , 2 )
0 commit comments