-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdisk-list.go
43 lines (39 loc) · 1.5 KB
/
fdisk-list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* fdisk-list.go - Test for disks/.
* Mimics util-linux fdisk's '-l' option.
*/
package main
import (
"fmt"
"pindorama.net.br/libcmon/disks"
"pindorama.net.br/libcmon/porcelana"
)
/* major:min (int:int): /sys/block/<basename /dev/xxx>/dev */
/* sysfs_blkdev: /sys/dev/block/major(devno):minor(devno) */
func main() {
disks, err := disks.GetAllDisksInfo()
fmt.Printf("Erros: %v\n", err)
for d := 0; d < len(disks); d++ {
disk := disks[d]
disksiz, unit := prcl.DiskSectorsToHuman(disk.QueueLimits.Logical_Block_Size, disk.NSectors)
fmt.Printf(("Disk %s: %.1f %s, %d bytes, %d sectors\nDisk model: %s\n" +
"Units: sectors of 1 * %d = %d\nSector size (logical/physical): %d / %d\n" +
"I/O size (minimum/optimal): %d bytes / %d bytes\n" +
"Disklabel type: %s\nDisk identifier: %s\n"),
disk.DevPath, disksiz, unit,
disk.NBytes, disk.NSectors, disk.ModelName,
disk.QueueLimits.Logical_Block_Size, disk.QueueLimits.Logical_Block_Size,
disk.QueueLimits.Logical_Block_Size, disk.QueueLimits.Physical_Block_Size,
disk.QueueLimits.Minimum_IO_Size, disk.QueueLimits.Optimal_IO_Size,
disk.LabelType, disk.Identifier)
blknamsiz := len(disk.DevPath)
fmt.Printf("%*s Boot Start End Sectors%10s %10s\n", (blknamsiz + 1), "Device", "Size", "Type")
for b := 0; b < len(disk.Blocks); b++ {
block := disk.Blocks[b]
fmt.Printf("%*s %v %d%5d%15d%15d %s\n",
blknamsiz, block.Device, block.IsBootable,
block.Range.Start, block.Range.End,
block.NSectors, block.Size, block.FSType)
}
}
}