Skip to content

Commit

Permalink
feat: make disk utils read subsystem information from the /sys/block
Browse files Browse the repository at this point in the history
This way it will be possible to tell what kind of block device is that.

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Mar 30, 2023
1 parent 8c7ea19 commit b4386f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 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
// SubSystem is the dest path of symlink /sys/block/<dev>/subsystem.
SubSystem string
// ReadOnly indicates that the kernel has marked this disk as read-only.
ReadOnly bool
}
Expand Down Expand Up @@ -209,7 +211,7 @@ func Get(dev string) *Disk {
readOnlyBool = true
}

return &Disk{
disk := &Disk{
DeviceName: fmt.Sprintf("/dev/%s", dev),
Size: size,
Model: readFile(sysblock, dev, "device/model"),
Expand All @@ -222,6 +224,13 @@ func Get(dev string) *Disk {
BusPath: busPath,
ReadOnly: readOnlyBool,
}

path, err := filepath.EvalSymlinks(filepath.Join(sysblock, dev, "subsystem"))
if err == nil {
disk.SubSystem = path
}

return disk
}

// Find disk matching provided spec.
Expand Down
1 change: 1 addition & 0 deletions blockdevice/util/disk/disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (suite *DisksSuite) TestDisks() {
for _, d := range disks {
suite.Require().NotEmpty(d.DeviceName)
suite.Require().NotEmpty(d.Model)
suite.Require().NotEmpty(d.SubSystem)
}
}
}
Expand Down

0 comments on commit b4386f3

Please sign in to comment.