disk: honour maximum number of partitions
Return an error if the maximum numbers of partitions has been reached and thus creating further partitions would result in errors. Currently we limit MBR partition types to 4 as we dont support logical partitions and GPT layouts to 128. According to the UEFI specificatio (2.8) a minimum of 16384 bytes are reserved for the partition entries array. Each entry is 128 bytes wide thus resulting in at least 128 entries; we choose this to be the maximum as well for now.
This commit is contained in:
parent
2ee3fd31a1
commit
b65ef74cb2
6 changed files with 42 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ package disk
|
|||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"sort"
|
||||
|
|
@ -279,7 +280,7 @@ func (pt *PartitionTable) BootFilesystem() *Filesystem {
|
|||
|
||||
// Create a new filesystem within the partition table at the given mountpoint
|
||||
// with the given minimum size in sectors.
|
||||
func (pt *PartitionTable) CreateFilesystem(mountpoint string, size uint64) {
|
||||
func (pt *PartitionTable) CreateFilesystem(mountpoint string, size uint64) error {
|
||||
filesystem := Filesystem{
|
||||
Type: "xfs",
|
||||
Mountpoint: mountpoint,
|
||||
|
|
@ -293,11 +294,23 @@ func (pt *PartitionTable) CreateFilesystem(mountpoint string, size uint64) {
|
|||
Filesystem: &filesystem,
|
||||
}
|
||||
|
||||
n := len(pt.Partitions)
|
||||
var maxNo int
|
||||
|
||||
if pt.Type == "gpt" {
|
||||
partition.Type = FilesystemDataGUID
|
||||
maxNo = 128
|
||||
} else {
|
||||
maxNo = 4
|
||||
}
|
||||
|
||||
if n == maxNo {
|
||||
return fmt.Errorf("maximum number of partitions reached (%d)", maxNo)
|
||||
}
|
||||
|
||||
pt.Partitions = append(pt.Partitions, partition)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Generate all needed UUIDs for all the partiton and filesystems
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue