m/p/{efivars,sysfs}: use typed UUIDs
The functions ReadLoaderDevicePartUUID and DeviceByPartUUID passed
around UUIDs as strings. This is inconvenient as UUID strings are not
normalized and thus require special care.
Switch to Google's uuid library and use their type, same as most other
things in the monorepo.
Change-Id: I19deed804cff7036f756257fbf5689570cccc812
Reviewed-on: https://review.monogon.dev/c/monogon/+/1640
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/metropolis/pkg/sysfs/BUILD.bazel b/metropolis/pkg/sysfs/BUILD.bazel
index 068f9f6..06995e2 100644
--- a/metropolis/pkg/sysfs/BUILD.bazel
+++ b/metropolis/pkg/sysfs/BUILD.bazel
@@ -8,4 +8,5 @@
],
importpath = "source.monogon.dev/metropolis/pkg/sysfs",
visibility = ["//metropolis:__subpackages__"],
+ deps = ["@com_github_google_uuid//:uuid"],
)
diff --git a/metropolis/pkg/sysfs/block.go b/metropolis/pkg/sysfs/block.go
index 9f9ebf8..c7cbbd7 100644
--- a/metropolis/pkg/sysfs/block.go
+++ b/metropolis/pkg/sysfs/block.go
@@ -26,6 +26,8 @@
"path/filepath"
"strconv"
"strings"
+
+ "github.com/google/uuid"
)
// PartUUIDMap returns a mapping between partition UUIDs and block device
@@ -60,12 +62,12 @@
// DeviceByPartUUID returns a block device name, given its corresponding
// partition UUID.
-func DeviceByPartUUID(uuid string) (string, error) {
+func DeviceByPartUUID(id uuid.UUID) (string, error) {
pm, err := PartUUIDMap()
if err != nil {
return "", err
}
- if bdev, ok := pm[strings.ToLower(uuid)]; ok {
+ if bdev, ok := pm[id.String()]; ok {
return bdev, nil
}
return "", ErrDevNotFound