Skip to content

Commit

Permalink
Merge pull request #363 from zaneb/wwn-no-extension
Browse files Browse the repository at this point in the history
Allow separating the WWN vendor extension
  • Loading branch information
jaypipes committed Mar 13, 2024
2 parents 835f6a2 + bb68466 commit 2650af7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ type Disk struct {
Model string `json:"model"`
// SerialNumber is the serial number of the disk.
SerialNumber string `json:"serial_number"`
// WWN is the World-wide Number of the disk.
// WWN is the World-wide Name of the disk.
// See: https://en.wikipedia.org/wiki/World_Wide_Name
WWN string `json:"wwn"`
// WWNNoExtension is the World-wide Name of the disk with any vendor
// extensions excluded.
// See: https://en.wikipedia.org/wiki/World_Wide_Name
WWNNoExtension string `json:"wwnNoExtension"`
// Partitions contains an array of pointers to `Partition` structs, one for
// each partition on the disk.
Partitions []*Partition `json:"partitions"`
Expand Down
1 change: 1 addition & 0 deletions pkg/block/block_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func (info *Info) load() error {
Model: ioregPlist.ModelNumber,
SerialNumber: ioregPlist.SerialNumber,
WWN: "",
WWNNoExtension: "",
Partitions: make([]*Partition, 0, len(disk.Partitions)+len(disk.APFSVolumes)),
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/block/block_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ func diskBusPath(paths *linuxpath.Paths, disk string) string {
return util.UNKNOWN
}

func diskWWNNoExtension(paths *linuxpath.Paths, disk string) string {
info, err := udevInfoDisk(paths, disk)
if err != nil {
return util.UNKNOWN
}

if wwn, ok := info["ID_WWN"]; ok {
return wwn
}
return util.UNKNOWN
}

func diskWWN(paths *linuxpath.Paths, disk string) string {
info, err := udevInfoDisk(paths, disk)
if err != nil {
Expand Down Expand Up @@ -326,6 +338,7 @@ func disks(ctx *context.Context, paths *linuxpath.Paths) []*Disk {
model := diskModel(paths, dname)
serialNo := diskSerialNumber(paths, dname)
wwn := diskWWN(paths, dname)
wwnNoExtension := diskWWNNoExtension(paths, dname)
removable := diskIsRemovable(paths, dname)

if storageController == STORAGE_CONTROLLER_LOOP && size == 0 {
Expand All @@ -345,6 +358,7 @@ func disks(ctx *context.Context, paths *linuxpath.Paths) []*Disk {
Model: model,
SerialNumber: serialNo,
WWN: wwn,
WWNNoExtension: wwnNoExtension,
}

parts := diskPartitions(ctx, paths, dname)
Expand Down
1 change: 1 addition & 0 deletions pkg/block/block_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (i *Info) load() error {
Model: strings.TrimSpace(*diskdrive.Caption),
SerialNumber: strings.TrimSpace(*diskdrive.SerialNumber),
WWN: util.UNKNOWN, // TODO: add information
WWNNoExtension: util.UNKNOWN, // TODO: add information
Partitions: make([]*Partition, 0),
}
for _, diskpartition := range win32DiskPartitionDescriptions {
Expand Down

0 comments on commit 2650af7

Please sign in to comment.