Skip to content

Commit

Permalink
feat: add ReadOnly attribute to Disk
Browse files Browse the repository at this point in the history
Adds support for reading the ReadOnly disk attribute.
Necessary for siderolabs/sidero#860.

Signed-off-by: Seán C McCord <ulexus@gmail.com>
  • Loading branch information
Ulexus committed Jul 11, 2022
1 parent fccee8b commit 9fa801c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions blockdevice/util/disk/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ type Disk struct {
Type Type
// BusPath PCI bus path.
BusPath string
// ReadOnly indicates that the kernel has marked this disk as read-only.
ReadOnly bool
}

// List returns list of disks by reading /sys/block.
Expand Down Expand Up @@ -209,6 +211,13 @@ func Get(dev string) *Disk {
serial = readFile(sysblock, dev, "device/serial")
}

var readOnlyBool bool

readOnly := readFile(sysblock, dev, "ro")
if readOnly == "1" {
readOnlyBool = true
}

return &Disk{
DeviceName: fmt.Sprintf("/dev/%s", dev),
Size: size,
Expand All @@ -220,6 +229,7 @@ func Get(dev string) *Disk {
UUID: uuid,
Type: diskType,
BusPath: busPath,
ReadOnly: readOnlyBool,
}
}

Expand Down

0 comments on commit 9fa801c

Please sign in to comment.