Skip to content

Commit

Permalink
[block] remove unnecessary /dev prefix in Windows
Browse files Browse the repository at this point in the history
Removes the /dev prefix of a `ghw.Disk` when printing to stdout. Also
sets the physical block size for the disk on Windows (retrievable via
the `Win32_DiskDrive.DefaultBlockSize` field) for Windows disk drives.

Issue #165
  • Loading branch information
jaypipes committed Mar 22, 2020
1 parent 5e73a85 commit e532803
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ Example output from my personal workstation:

```
block storage (1 disk, 2TB physical storage)
/dev/sda HDD (2TB) SCSI [@pci-0000:04:00.0-scsi-0:1:0:0 (node #0)] vendor=LSI model=Logical_Volume serial=600508e000000000f8253aac9a1abd0c WWN=0x600508e000000000f8253aac9a1abd0c
sda HDD (2TB) SCSI [@pci-0000:04:00.0-scsi-0:1:0:0 (node #0)] vendor=LSI model=Logical_Volume serial=600508e000000000f8253aac9a1abd0c WWN=0x600508e000000000f8253aac9a1abd0c
/dev/sda1 (100MB)
/dev/sda2 (187GB)
/dev/sda3 (449MB)
Expand Down
2 changes: 1 addition & 1 deletion block.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (d *Disk) String() string {
removable = " removable=true"
}
return fmt.Sprintf(
"/dev/%s %s (%s) %s [@%s%s]%s%s%s%s%s",
"%s %s (%s) %s [@%s%s]%s%s%s%s%s",
d.Name,
d.DriveType.String(),
sizeStr,
Expand Down
11 changes: 6 additions & 5 deletions block_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"github.com/StackExchange/wmi"
)

const wqlDiskDrive = "SELECT Caption, CreationClassName, Description, DeviceID, Index, InterfaceType, Manufacturer, MediaType, Model, Name, Partitions, SerialNumber, Size, TotalCylinders, TotalHeads, TotalSectors, TotalTracks, TracksPerCylinder FROM Win32_DiskDrive"
const wqlDiskDrive = "SELECT Caption, CreationClassName, DefaultBlockSize, Description, DeviceID, Index, InterfaceType, Manufacturer, MediaType, Model, Name, Partitions, SerialNumber, Size, TotalCylinders, TotalHeads, TotalSectors, TotalTracks, TracksPerCylinder FROM Win32_DiskDrive"

type win32DiskDrive struct {
Caption string
CreationClassName string
DefaultBlockSize uint64
Description string
DeviceID string
Index uint32 // Used to link with partition
Expand Down Expand Up @@ -97,14 +98,14 @@ func (ctx *context) blockFillInfo(info *BlockInfo) error {
disks := make([]*Disk, 0)
for _, diskdrive := range win32DiskDriveDescriptions {
disk := &Disk{
Name: diskdrive.Name,
Name: strings.TrimSpace(diskdrive.DeviceID),
SizeBytes: diskdrive.Size,
PhysicalBlockSizeBytes: 0,
PhysicalBlockSizeBytes: diskdrive.DefaultBlockSize,
DriveType: toDriveType(diskdrive.MediaType, diskdrive.Caption),
StorageController: toStorageController(diskdrive.InterfaceType),
BusType: toBusType(diskdrive.InterfaceType),
BusPath: UNKNOWN, // TODO: add information
Vendor: UNKNOWN, // TODO: add information
Vendor: strings.TrimSpace(diskdrive.Manufacturer),
Model: strings.TrimSpace(diskdrive.Caption),
SerialNumber: strings.TrimSpace(diskdrive.SerialNumber),
WWN: UNKNOWN, // TODO: add information
Expand All @@ -127,7 +128,7 @@ func (ctx *context) blockFillInfo(info *BlockInfo) error {
SizeBytes: logicaldisk.Size,
MountPoint: logicaldisk.DeviceID,
Type: diskpartition.Type,
IsReadOnly: toReadOnly(diskpartition.Access), // TODO: add information
IsReadOnly: toReadOnly(diskpartition.Access),
}
disk.Partitions = append(disk.Partitions, p)
break
Expand Down

0 comments on commit e532803

Please sign in to comment.