From bb68466d7800f9dbfcf997381a72f0bf71c267a2 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Fri, 1 Mar 2024 18:08:41 +1300 Subject: [PATCH] Allow separating the WWN vendor extension Provide a way to get the disk WWN without the vendor extension. Signed-off-by: Zane Bitter --- pkg/block/block.go | 6 +++++- pkg/block/block_darwin.go | 1 + pkg/block/block_linux.go | 14 ++++++++++++++ pkg/block/block_windows.go | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/block/block.go b/pkg/block/block.go index 7a0dbde1..5e75eea6 100644 --- a/pkg/block/block.go +++ b/pkg/block/block.go @@ -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"` diff --git a/pkg/block/block_darwin.go b/pkg/block/block_darwin.go index 9b026253..c6b6c266 100644 --- a/pkg/block/block_darwin.go +++ b/pkg/block/block_darwin.go @@ -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)), } diff --git a/pkg/block/block_linux.go b/pkg/block/block_linux.go index 3c24cf86..376b5ff5 100644 --- a/pkg/block/block_linux.go +++ b/pkg/block/block_linux.go @@ -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 { @@ -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 { @@ -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) diff --git a/pkg/block/block_windows.go b/pkg/block/block_windows.go index be39f6c0..270e19f9 100644 --- a/pkg/block/block_windows.go +++ b/pkg/block/block_windows.go @@ -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 {