Skip to content

Commit

Permalink
Feature: Partitions and UsableBytes (Windows Only)
Browse files Browse the repository at this point in the history
When collecting HW informations about disks it's also very usefull to understand how much free space is available on each partition.

Here a quick example based on my "Windows support: block" jaypipes#156
  • Loading branch information
Riccardo Re committed Feb 7, 2020
1 parent 3aa043c commit 69aed94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
15 changes: 8 additions & 7 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ type Disk struct {

// Partition describes a logical division of a Disk.
type Partition struct {
Disk *Disk `json:"-"`
Name string `json:"name"`
Label string `json:"label"`
MountPoint string `json:"mount_point"`
SizeBytes uint64 `json:"size_bytes"`
Type string `json:"type"`
IsReadOnly bool `json:"read_only"`
Disk *Disk `json:"-"`
Name string `json:"name"`
Label string `json:"label"`
MountPoint string `json:"mount_point"`
SizeBytes uint64 `json:"size_bytes"`
UsableBytes uint64 `json:"usable_bytes"`
Type string `json:"type"`
IsReadOnly bool `json:"read_only"`
}

// BlockInfo describes all disk drives and partitions in the host system.
Expand Down
13 changes: 7 additions & 6 deletions block_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ func (ctx *context) blockFillInfo(info *BlockInfo) error {
if logicaldisktodiskpartition.Antecedent == desiredAntecedent && logicaldisktodiskpartition.Dependent == desiredDependent {
// Appending Partition
p := &Partition{
Name: logicaldisk.Caption,
Label: logicaldisk.Caption,
SizeBytes: logicaldisk.Size,
MountPoint: logicaldisk.DeviceID,
Type: diskpartition.Type,
IsReadOnly: toReadOnly(diskpartition.Access), // TODO: add information
Name: logicaldisk.Caption,
Label: logicaldisk.Caption,
SizeBytes: logicaldisk.Size,
UsableBytes: logicaldisk.FreeSpace,
MountPoint: logicaldisk.DeviceID,
Type: diskpartition.Type,
IsReadOnly: toReadOnly(diskpartition.Access), // TODO: add information
}
disk.Partitions = append(disk.Partitions, p)
break
Expand Down

0 comments on commit 69aed94

Please sign in to comment.