Skip to content

Commit

Permalink
use all pointer types for receiving fields in WMI
Browse files Browse the repository at this point in the history
Apparently WMI will return `<nil>` type even for integer fields like
DefaultBlockSize :(

Issue #189
  • Loading branch information
jaypipes committed May 23, 2020
1 parent 591c46d commit 82e05bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
42 changes: 21 additions & 21 deletions block_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,38 @@ const wqlDiskDrive = "SELECT Caption, CreationClassName, DefaultBlockSize, Descr
type win32DiskDrive struct {
Caption *string
CreationClassName *string
DefaultBlockSize uint64
DefaultBlockSize *uint64
Description *string
DeviceID *string
Index uint32 // Used to link with partition
Index *uint32 // Used to link with partition
InterfaceType *string
Manufacturer *string
MediaType *string
Model *string
Name *string
Partitions int32
Partitions *int32
SerialNumber *string
Size uint64
TotalCylinders int64
TotalHeads int32
TotalSectors int64
TotalTracks int64
TracksPerCylinder int32
Size *uint64
TotalCylinders *int64
TotalHeads *int32
TotalSectors *int64
TotalTracks *int64
TracksPerCylinder *int32
}

const wqlDiskPartition = "SELECT Access, BlockSize, Caption, CreationClassName, Description, DeviceID, DiskIndex, Index, Name, Size, SystemName, Type FROM Win32_DiskPartition"

type win32DiskPartition struct {
Access uint16
BlockSize uint64
Access *uint16
BlockSize *uint64
Caption *string
CreationClassName *string
Description *string
DeviceID *string
DiskIndex uint32 // Used to link with Disk Drive
Index uint32
DiskIndex *uint32 // Used to link with Disk Drive
Index *uint32
Name *string
Size int64
Size *int64
SystemName *string
Type *string
}
Expand All @@ -67,9 +67,9 @@ type win32LogicalDisk struct {
Description *string
DeviceID *string
FileSystem *string
FreeSpace uint64
FreeSpace *uint64
Name *string
Size uint64
Size *uint64
SystemName *string
}

Expand Down Expand Up @@ -99,8 +99,8 @@ func (ctx *context) blockFillInfo(info *BlockInfo) error {
for _, diskdrive := range win32DiskDriveDescriptions {
disk := &Disk{
Name: strings.TrimSpace(*diskdrive.DeviceID),
SizeBytes: diskdrive.Size,
PhysicalBlockSizeBytes: diskdrive.DefaultBlockSize,
SizeBytes: *diskdrive.Size,
PhysicalBlockSizeBytes: *diskdrive.DefaultBlockSize,
DriveType: toDriveType(*diskdrive.MediaType, *diskdrive.Caption),
StorageController: toStorageController(*diskdrive.InterfaceType),
BusType: toBusType(*diskdrive.InterfaceType),
Expand All @@ -115,7 +115,7 @@ func (ctx *context) blockFillInfo(info *BlockInfo) error {
for _, diskpartition := range win32DiskPartitionDescriptions {
// Finding disk partition linked to current disk drive
if diskdrive.Index == diskpartition.DiskIndex {
disk.PhysicalBlockSizeBytes = diskpartition.BlockSize
disk.PhysicalBlockSizeBytes = *diskpartition.BlockSize
// Finding logical partition linked to current disk partition
for _, logicaldisk := range win32LogicalDiskDescriptions {
for _, logicaldisktodiskpartition := range win32LogicalDiskToPartitionDescriptions {
Expand All @@ -126,10 +126,10 @@ func (ctx *context) blockFillInfo(info *BlockInfo) error {
p := &Partition{
Name: strings.TrimSpace(*logicaldisk.Caption),
Label: strings.TrimSpace(*logicaldisk.Caption),
SizeBytes: logicaldisk.Size,
SizeBytes: *logicaldisk.Size,
MountPoint: *logicaldisk.DeviceID,
Type: *diskpartition.Type,
IsReadOnly: toReadOnly(diskpartition.Access),
IsReadOnly: toReadOnly(*diskpartition.Access),
}
disk.Partitions = append(disk.Partitions, p)
break
Expand Down
18 changes: 9 additions & 9 deletions memory_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ import (
const wqlOperatingSystem = "SELECT TotalVisibleMemorySize FROM Win32_OperatingSystem"

type win32OperatingSystem struct {
TotalVisibleMemorySize uint64
TotalVisibleMemorySize *uint64
}

const wqlPhysicalMemory = "SELECT BankLabel, Capacity, DataWidth, Description, DeviceLocator, Manufacturer, Model, Name, PartNumber, PositionInRow, SerialNumber, Speed, Tag, TotalWidth FROM Win32_PhysicalMemory"

type win32PhysicalMemory struct {
BankLabel *string
Capacity uint64
DataWidth uint16
Capacity *uint64
DataWidth *uint16
Description *string
DeviceLocator *string
Manufacturer *string
Model *string
Name *string
PartNumber *string
PositionInRow uint32
PositionInRow *uint32
SerialNumber *string
Speed uint32
Speed *uint32
Tag *string
TotalWidth uint16
TotalWidth *uint16
}

func (ctx *context) memFillInfo(info *MemoryInfo) error {
Expand All @@ -49,20 +49,20 @@ func (ctx *context) memFillInfo(info *MemoryInfo) error {
var totalPhysicalBytes uint64
info.Modules = make([]*MemoryModule, 0, len(win32MemDescriptions))
for _, description := range win32MemDescriptions {
totalPhysicalBytes += description.Capacity
totalPhysicalBytes += *description.Capacity
info.Modules = append(info.Modules, &MemoryModule{
Label: *description.BankLabel,
Location: *description.DeviceLocator,
SerialNumber: *description.SerialNumber,
SizeBytes: int64(description.Capacity),
SizeBytes: int64(*description.Capacity),
Vendor: *description.Manufacturer,
})
}
var totalUsableBytes uint64
for _, description := range win32OSDescriptions {
// TotalVisibleMemorySize is the amount of memory available for us by
// the operating system **in Kilobytes**
totalUsableBytes += description.TotalVisibleMemorySize * uint64(KB)
totalUsableBytes += *description.TotalVisibleMemorySize * uint64(KB)
}
info.TotalUsableBytes = int64(totalUsableBytes)
info.TotalPhysicalBytes = int64(totalPhysicalBytes)
Expand Down
4 changes: 2 additions & 2 deletions net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const wqlNetworkAdapter = "SELECT Description, DeviceID, Index, InterfaceIndex,
type win32NetworkAdapter struct {
Description *string
DeviceID *string
Index uint32
InterfaceIndex uint32
Index *uint32
InterfaceIndex *uint32
MACAddress *string
Manufacturer *string
Name *string
Expand Down

0 comments on commit 82e05bd

Please sign in to comment.