disk: random volume ID generator for FAT
Generate a random 32-bit hex string
This commit is contained in:
parent
2b34e4003c
commit
05cc6b98c2
1 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue