disk: implement VolumeContainer interface for PartitionTable
Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
parent
2b957a7de6
commit
3312323db1
2 changed files with 35 additions and 2 deletions
|
|
@ -66,9 +66,9 @@ func TestDisk_DynamicallyResizePartitionTable(t *testing.T) {
|
|||
// math/rand is good enough in this case
|
||||
/* #nosec G404 */
|
||||
rng := rand.New(rand.NewSource(0))
|
||||
pt, err := CreatePartitionTable(mountpoints, 1024, &pt, rng)
|
||||
newpt, err := NewPartitionTable(&pt, mountpoints, 1024, rng)
|
||||
assert.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, pt.SectorsToBytes(pt.Size), expectedSize)
|
||||
assert.GreaterOrEqual(t, newpt.Size, expectedSize)
|
||||
}
|
||||
|
||||
// common partition table that use used by tests
|
||||
|
|
|
|||
|
|
@ -283,6 +283,39 @@ func (pt *PartitionTable) EnsureSize(s uint64) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (pt *PartitionTable) CreateVolume(mountpoint string, size uint64) (Entity, error) {
|
||||
filesystem := Filesystem{
|
||||
Type: "xfs",
|
||||
Mountpoint: mountpoint,
|
||||
FSTabOptions: "defaults",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 0,
|
||||
}
|
||||
|
||||
partition := Partition{
|
||||
Size: size,
|
||||
Payload: &filesystem,
|
||||
}
|
||||
|
||||
n := len(pt.Partitions)
|
||||
var maxNo int
|
||||
|
||||
if pt.Type == "gpt" {
|
||||
partition.Type = FilesystemDataGUID
|
||||
maxNo = 128
|
||||
} else {
|
||||
maxNo = 4
|
||||
}
|
||||
|
||||
if n == maxNo {
|
||||
return nil, fmt.Errorf("maximum number of partitions reached (%d)", maxNo)
|
||||
}
|
||||
|
||||
pt.Partitions = append(pt.Partitions, partition)
|
||||
|
||||
return &pt.Partitions[len(pt.Partitions)-1], nil
|
||||
}
|
||||
|
||||
type EntityCallback func(e Entity, path []Entity) error
|
||||
|
||||
func forEachEntity(e Entity, path []Entity, cb EntityCallback) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue