disk: new interface UniqueEntity for Entities with UUID

This is for all entities that have a uniquely identifiable via a UUID.
Currently the interface only contains a single function, GenUUID(),
that should generate a new UUID via a random source (`rand.Rand`).
NB: Partitions are uniquely identifiable if and only if the layout is
GPT.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
Christian Kellner 2022-02-19 13:36:45 +01:00 committed by Tom Gundersen
parent 126c23cb13
commit b0899c5c59
5 changed files with 55 additions and 5 deletions

View file

@ -1,5 +1,11 @@
package disk
import (
"math/rand"
"github.com/google/uuid"
)
// Filesystem related functions
type Filesystem struct {
Type string
@ -59,3 +65,9 @@ func (fs *Filesystem) GetFSTabOptions() FSTabOptions {
PassNo: fs.FSTabPassNo,
}
}
func (fs *Filesystem) GenUUID(rng *rand.Rand) {
if fs.UUID == "" {
fs.UUID = uuid.Must(newRandomUUIDFromReader(rng)).String()
}
}