@@ -34,12 +34,12 @@ import (
34
34
"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
35
35
"github.com/coreos/ignition/v2/internal/distro"
36
36
"github.com/coreos/ignition/v2/internal/exec/util"
37
- "github.com/coreos/ignition/v2/internal/sgdisk "
37
+ "github.com/coreos/ignition/v2/internal/sfdisk "
38
38
iutil "github.com/coreos/ignition/v2/internal/util"
39
39
)
40
40
41
41
var (
42
- ErrBadSgdiskOutput = errors .New ("sgdisk had unexpected output" )
42
+ ErrBadsfdiskOutput = errors .New ("sfdisk had unexpected output" )
43
43
)
44
44
45
45
// createPartitions creates the partitions described in config.Storage.Disks.
@@ -75,7 +75,7 @@ func (s stage) createPartitions(config types.Config) error {
75
75
76
76
// partitionMatches determines if the existing partition matches the spec given. See doc/operator notes for what
77
77
// what it means for an existing partition to match the spec. spec must have non-zero Start and Size.
78
- func partitionMatches (existing util.PartitionInfo , spec sgdisk .Partition ) error {
78
+ func partitionMatches (existing util.PartitionInfo , spec sfdisk .Partition ) error {
79
79
if err := partitionMatchesCommon (existing , spec ); err != nil {
80
80
return err
81
81
}
@@ -87,13 +87,13 @@ func partitionMatches(existing util.PartitionInfo, spec sgdisk.Partition) error
87
87
88
88
// partitionMatchesResize returns if the existing partition should be resized by evaluating if
89
89
// `resize`field is true and partition matches in all respects except size.
90
- func partitionMatchesResize (existing util.PartitionInfo , spec sgdisk .Partition ) bool {
90
+ func partitionMatchesResize (existing util.PartitionInfo , spec sfdisk .Partition ) bool {
91
91
return cutil .IsTrue (spec .Resize ) && partitionMatchesCommon (existing , spec ) == nil
92
92
}
93
93
94
94
// partitionMatchesCommon handles the common tests (excluding the partition size) to determine
95
95
// if the existing partition matches the spec given.
96
- func partitionMatchesCommon (existing util.PartitionInfo , spec sgdisk .Partition ) error {
96
+ func partitionMatchesCommon (existing util.PartitionInfo , spec sfdisk .Partition ) error {
97
97
if spec .Number != existing .Number {
98
98
return fmt .Errorf ("partition numbers did not match (specified %d, got %d). This should not happen, please file a bug." , spec .Number , existing .Number )
99
99
}
@@ -113,7 +113,7 @@ func partitionMatchesCommon(existing util.PartitionInfo, spec sgdisk.Partition)
113
113
}
114
114
115
115
// partitionShouldBeInspected returns if the partition has zeroes that need to be resolved to sectors.
116
- func partitionShouldBeInspected (part sgdisk .Partition ) bool {
116
+ func partitionShouldBeInspected (part sfdisk .Partition ) bool {
117
117
if part .Number == 0 {
118
118
return false
119
119
}
@@ -131,19 +131,19 @@ func convertMiBToSectors(mib *int, sectorSize int) *int64 {
131
131
}
132
132
133
133
// getRealStartAndSize returns a map of partition numbers to a struct that contains what their real start
134
- // and end sector should be. It runs sgdisk --pretend to determine what the partitions would look like if
134
+ // and end sector should be. It runs sfdisk --pretend to determine what the partitions would look like if
135
135
// everything specified were to be (re)created.
136
- func (s stage ) getRealStartAndSize (dev types.Disk , devAlias string , diskInfo util.DiskInfo ) ([]sgdisk .Partition , error ) {
137
- partitions := []sgdisk .Partition {}
136
+ func (s stage ) getRealStartAndSize (dev types.Disk , devAlias string , diskInfo util.DiskInfo ) ([]sfdisk .Partition , error ) {
137
+ partitions := []sfdisk .Partition {}
138
138
for _ , cpart := range dev .Partitions {
139
- partitions = append (partitions , sgdisk .Partition {
139
+ partitions = append (partitions , sfdisk .Partition {
140
140
Partition : cpart ,
141
141
StartSector : convertMiBToSectors (cpart .StartMiB , diskInfo .LogicalSectorSize ),
142
142
SizeInSectors : convertMiBToSectors (cpart .SizeMiB , diskInfo .LogicalSectorSize ),
143
143
})
144
144
}
145
145
146
- op := sgdisk .Begin (s .Logger , devAlias )
146
+ op := sfdisk .Begin (s .Logger , devAlias )
147
147
for _ , part := range partitions {
148
148
if info , exists := diskInfo .GetPartition (part .Number ); exists {
149
149
// delete all existing partitions
@@ -157,8 +157,6 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
157
157
}
158
158
}
159
159
if partitionShouldExist (part ) {
160
- // Clear the label. sgdisk doesn't escape control characters. This makes parsing easier
161
- part .Label = nil
162
160
op .CreatePartition (part )
163
161
}
164
162
}
@@ -177,12 +175,12 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
177
175
return nil , err
178
176
}
179
177
180
- realDimensions , err := parseSgdiskPretend (output , partitionsToInspect )
178
+ realDimensions , err := parsesfdiskPretend (output , partitionsToInspect )
181
179
if err != nil {
182
180
return nil , err
183
181
}
184
182
185
- result := []sgdisk .Partition {}
183
+ result := []sfdisk .Partition {}
186
184
for _ , part := range partitions {
187
185
if dims , ok := realDimensions [part .Number ]; ok {
188
186
if part .StartSector != nil {
@@ -197,7 +195,7 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
197
195
return result , nil
198
196
}
199
197
200
- type sgdiskOutput struct {
198
+ type sfdiskOutput struct {
201
199
start int64
202
200
size int64
203
201
}
@@ -213,17 +211,17 @@ func parseLine(r *regexp.Regexp, line string) (int64, error) {
213
211
case 2 :
214
212
return strconv .ParseInt (matches [1 ], 10 , 64 )
215
213
default :
216
- return 0 , ErrBadSgdiskOutput
214
+ return 0 , ErrBadsfdiskOutput
217
215
}
218
216
}
219
217
220
- // parseSgdiskPretend parses the output of running sgdisk pretend with --info specified for each partition
221
- // number specified in partitionNumbers. E.g. if paritionNumbers is [1,4,5], it is expected that the sgdisk
222
- // output was from running `sgdisk --pretend <commands> --info=1 --info=4 --info=5`. It assumes the the
218
+ // parsesfdiskPretend parses the output of running sfdisk pretend with --info specified for each partition
219
+ // number specified in partitionNumbers. E.g. if paritionNumbers is [1,4,5], it is expected that the sfdisk
220
+ // output was from running `sfdisk --pretend <commands> --info=1 --info=4 --info=5`. It assumes the the
223
221
// partition labels are well behaved (i.e. contain no control characters). It returns a list of partitions
224
- // matching the partition numbers specified, but with the start and size information as determined by sgdisk .
225
- // The partition numbers need to passed in because sgdisk includes them in its output.
226
- func parseSgdiskPretend ( sgdiskOut string , partitionNumbers []int ) (map [int ]sgdiskOutput , error ) {
222
+ // matching the partition numbers specified, but with the start and size information as determined by sfdisk .
223
+ // The partition numbers need to passed in because sfdisk includes them in its output.
224
+ func parsesfdiskPretend ( sfdiskOut string , partitionNumbers []int ) (map [int ]sfdiskOutput , error ) {
227
225
if len (partitionNumbers ) == 0 {
228
226
return nil , nil
229
227
}
@@ -235,12 +233,12 @@ func parseSgdiskPretend(sgdiskOut string, partitionNumbers []int) (map[int]sgdis
235
233
FAIL_ON_START_END = iota
236
234
)
237
235
238
- output := map [int ]sgdiskOutput {}
236
+ output := map [int ]sfdiskOutput {}
239
237
state := START
240
- current := sgdiskOutput {}
238
+ current := sfdiskOutput {}
241
239
i := 0
242
240
243
- lines := strings .Split (sgdiskOut , "\n " )
241
+ lines := strings .Split (sfdiskOut , "\n " )
244
242
for _ , line := range lines {
245
243
switch state {
246
244
case START :
@@ -264,29 +262,29 @@ func parseSgdiskPretend(sgdiskOut string, partitionNumbers []int) (map[int]sgdis
264
262
if i == len (partitionNumbers ) {
265
263
state = FAIL_ON_START_END
266
264
} else {
267
- current = sgdiskOutput {}
265
+ current = sfdiskOutput {}
268
266
state = START
269
267
}
270
268
}
271
269
case FAIL_ON_START_END :
272
270
if len (startRegex .FindStringSubmatch (line )) != 0 ||
273
271
len (endRegex .FindStringSubmatch (line )) != 0 {
274
- return nil , ErrBadSgdiskOutput
272
+ return nil , ErrBadsfdiskOutput
275
273
}
276
274
}
277
275
}
278
276
279
277
if state != FAIL_ON_START_END {
280
278
// We stopped parsing in the middle of a info block. Something is wrong
281
- return nil , ErrBadSgdiskOutput
279
+ return nil , ErrBadsfdiskOutput
282
280
}
283
281
284
282
return output , nil
285
283
}
286
284
287
285
// partitionShouldExist returns whether a bool is indicating if a partition should exist or not.
288
286
// nil (unspecified in json) is treated the same as true.
289
- func partitionShouldExist (part sgdisk .Partition ) bool {
287
+ func partitionShouldExist (part sfdisk .Partition ) bool {
290
288
return ! cutil .IsFalse (part .ShouldExist )
291
289
}
292
290
@@ -438,17 +436,17 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
438
436
return fmt .Errorf ("refusing to operate on directly active disk %q" , devAlias )
439
437
}
440
438
if cutil .IsTrue (dev .WipeTable ) {
441
- op := sgdisk .Begin (s .Logger , devAlias )
439
+ op := sfdisk .Begin (s .Logger , devAlias )
442
440
s .Logger .Info ("wiping partition table requested on %q" , devAlias )
443
441
if len (activeParts ) > 0 {
444
442
return fmt .Errorf ("refusing to wipe active disk %q" , devAlias )
445
443
}
446
444
op .WipeTable (true )
447
- if err := op .Commit (); err != nil {
448
- // `sgdisk --zap-all` will exit code 2 if the table was corrupted; retry it
445
+ if err := op .SgdiskCommit (); err != nil {
446
+ // `sfdisk --zap-all` will exit code 2 if the table was corrupted; retry it
449
447
// https://github.com/coreos/fedora-coreos-tracker/issues/1596
450
448
s .Logger .Info ("potential error encountered while wiping table... retrying" )
451
- if err := op .Commit (); err != nil {
449
+ if err := op .SgdiskCommit (); err != nil {
452
450
return err
453
451
}
454
452
}
@@ -457,7 +455,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
457
455
// Ensure all partitions with number 0 are last
458
456
sort .Stable (PartitionList (dev .Partitions ))
459
457
460
- op := sgdisk .Begin (s .Logger , devAlias )
458
+ op := sfdisk .Begin (s .Logger , devAlias )
461
459
462
460
diskInfo , err := s .getPartitionMap (devAlias )
463
461
if err != nil {
@@ -538,11 +536,11 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
538
536
}
539
537
}
540
538
541
- if err := op .Commit (); err != nil {
539
+ if err := op .SgdiskCommit (); err != nil {
542
540
return fmt .Errorf ("commit failure: %v" , err )
543
541
}
544
542
545
- // In contrast to similar tools, sgdisk does not trigger the update of the
543
+ // In contrast to similar tools, sfdisk does not trigger the update of the
546
544
// kernel partition table with BLKPG but only uses BLKRRPART which fails
547
545
// as soon as one partition of the disk is mounted
548
546
if len (activeParts ) > 0 {
0 commit comments