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:
parent
126c23cb13
commit
b0899c5c59
5 changed files with 55 additions and 5 deletions
|
|
@ -2,7 +2,10 @@ package disk
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Btrfs struct {
|
||||
|
|
@ -64,6 +67,12 @@ func (b *Btrfs) CreateVolume(mountpoint string, size uint64) (Entity, error) {
|
|||
return &b.Subvolumes[len(b.Subvolumes)-1], nil
|
||||
}
|
||||
|
||||
func (b *Btrfs) GenUUID(rng *rand.Rand) {
|
||||
if b.UUID == "" {
|
||||
b.UUID = uuid.Must(newRandomUUIDFromReader(rng)).String()
|
||||
}
|
||||
}
|
||||
|
||||
type BtrfsSubvolume struct {
|
||||
Name string
|
||||
Size uint64
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue