disk: random volume ID generator for FAT

Generate a random 32-bit hex string
This commit is contained in:
Achilleas Koutsou 2021-11-26 16:37:56 +01:00
parent 2b34e4003c
commit 05cc6b98c2

View file

@ -1,6 +1,7 @@
package disk
import (
"encoding/hex"
"io"
"math/rand"
@ -97,3 +98,11 @@ func newRandomUUIDFromReader(r io.Reader) (uuid.UUID, error) {
id[8] = (id[8] & 0x3f) | 0x80 // Variant is 10
return id, nil
}
// NewRandomVolIDFromReader creates a random 32 bit hex string to use as a
// volume ID for FAT filesystems
func NewRandomVolIDFromReader(r io.Reader) (string, error) {
volid := make([]byte, 4)
_, err := r.Read(volid)
return hex.EncodeToString(volid), err
}