forked from hpe-storage/common-host-libs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
msft_partition.go
68 lines (58 loc) · 2.05 KB
/
msft_partition.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// (c) Copyright 2019 Hewlett Packard Enterprise Development LP
// +build windows
// Package wmi handles WMI queries
package wmi
import (
"fmt"
log "github.com/hpe-storage/common-host-libs/logger"
)
// MSFT_Partition WMI class
type MSFT_Partition struct {
// MSFT_StorageObject base class (in the future we might moved supported contained objects)
ObjectId string
PassThroughClass string
PassThroughIds string
PassThroughNamespace string
PassThroughServer string
UniqueId string
// MSFT_Partition
DiskId string
DiskNumber uint32 `wmi:",nil=0xFFFFFFFF"` // If property not available, use 0xFFFFFFFF
PartitionNumber uint32 `wmi:",nil=0xFFFFFFFF"` // If property not available, use 0xFFFFFFFF
DriveLetter uint16
AccessPaths []string
OperationalStatus uint16
TransitionState uint16
Offset uint64
Size uint64
MbrType uint16
GptType string
Guid string
IsReadOnly bool
IsOffline bool
IsSystem bool
IsBoot bool
IsActive bool
IsHidden bool
IsShadowCopy bool
IsDAX bool
NoDefaultDriveLetter bool
}
// GetMSFTPartition enumerates this host's MSFTPartition objects
func GetMSFTPartition(whereOperator string) (diskPartitions []*MSFT_Partition, err error) {
log.Tracef(">>>>> GetMSFTPartition, whereOperator=%v", whereOperator)
defer log.Trace("<<<<< GetMSFTPartition")
// Form the WMI query
wmiQuery := "SELECT * FROM MSFT_Partition"
if whereOperator != "" {
wmiQuery += " WHERE " + whereOperator
}
// Execute the WMI query
err = ExecQuery(wmiQuery, rootMicrosoftWindowsStorage, &diskPartitions)
return diskPartitions, err
}
// GetMSFTPartitionForDiskNumber enumerates only the given disk's partitions
func GetMSFTPartitionForDiskNumber(diskNumber uint32) (diskPartitions []*MSFT_Partition, err error) {
whereOperator := fmt.Sprintf("DiskNumber=%v", diskNumber)
return GetMSFTPartition(whereOperator)
}