-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisktype.go
More file actions
61 lines (53 loc) · 1.31 KB
/
Copy pathdisktype.go
File metadata and controls
61 lines (53 loc) · 1.31 KB
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
package osmgr
var (
disks []*Disk
)
func init() {
disks = ScanDisks()
}
type Disk struct {
Table string `json:"table,omitempty"`
Model string `json:"model,omitempty"`
Size string `json:"size,omitempty"`
Block string `json:"block,omitempty"`
ID string `json:"id,omitempty"`
Partitions []*Partition `json:"partitions,omitempty"`
}
func GetDisk(diskID string) *Disk {
for i := 0; i < len(disks); i++ {
if disks[i].ID == diskID {
return disks[i]
}
}
return nil
}
func GetDisks() []*Disk {
return disks
}
func (d *Disk) GetPartition(partID string) *Partition {
for i := 0; i < len(d.Partitions); i++ {
if d.Partitions[i].ID == partID {
return d.Partitions[i]
}
}
return nil
}
func (d *Disk) GetFreePartitionsAvailable() int {
switch d.Table {
case "gpt":
return 128 - len(d.Partitions)
case "dos":
return 4 - len(d.Partitions)
}
return 0 //We don't know how to operate on this disk yet
}
type Partition struct {
Disk *Disk `json:"-"`
FS string `json:"fs,omitempty"`
Size string `json:"size,omitempty"`
OffsetStart int64 `json:"offsetA"`
OffsetEnd int64 `json:"offsetB"`
Block string `json:"block,omitempty"`
Mount string `json:"mount,omitempty"`
ID string `json:"id,omitempty"`
}