/
partition_options.go
82 lines (69 loc) · 1.96 KB
/
partition_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package gpt
import (
"github.com/google/uuid"
)
// PartitionOptions represent the options available for partitions.
//
//nolint:govet
type PartitionOptions struct {
Type uuid.UUID
Name string
Offset uint64
MaximumSize bool
Attibutes uint64
}
// PartitionOption is the functional option func.
type PartitionOption func(*PartitionOptions)
// WithPartitionType sets the partition type.
func WithPartitionType(id string) PartitionOption {
return func(args *PartitionOptions) {
// TODO: An Option should return an error.
//nolint: errcheck
guuid, _ := uuid.Parse(id)
args.Type = guuid
}
}
// WithPartitionName sets the partition name.
func WithPartitionName(o string) PartitionOption {
return func(args *PartitionOptions) {
args.Name = o
}
}
// WithOffset sets partition start offset in bytes.
func WithOffset(o uint64) PartitionOption {
return func(args *PartitionOptions) {
args.Offset = o
}
}
// WithMaximumSize indicates if the partition should be created with the maximum size possible.
func WithMaximumSize(o bool) PartitionOption {
return func(args *PartitionOptions) {
args.MaximumSize = o
}
}
// WithLegacyBIOSBootableAttribute marks the partition as bootable.
func WithLegacyBIOSBootableAttribute(o bool) PartitionOption {
return func(args *PartitionOptions) {
if o {
args.Attibutes |= (1 << 2)
}
}
}
// NewDefaultPartitionOptions initializes a Options struct with default values.
func NewDefaultPartitionOptions(setters ...PartitionOption) *PartitionOptions {
// TODO: An Option should return an error.
//nolint: errcheck
guuid, _ := uuid.Parse("0FC63DAF-8483-4772-8E79-3D69D8477DE4")
opts := &PartitionOptions{
Type: guuid,
Name: "",
Offset: 0,
}
for _, setter := range setters {
setter(opts)
}
return opts
}