@@ -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,7 +157,7 @@ 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
160
+ // Clear the label. sfdisk doesn't escape control characters. This makes parsing easier
161
161
part .Label = nil
162
162
op .CreatePartition (part )
163
163
}
@@ -177,12 +177,12 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
177
177
return nil , err
178
178
}
179
179
180
- realDimensions , err := parseSgdiskPretend (output , partitionsToInspect )
180
+ realDimensions , err := parsesfdiskPretend (output , partitionsToInspect )
181
181
if err != nil {
182
182
return nil , err
183
183
}
184
184
185
- result := []sgdisk .Partition {}
185
+ result := []sfdisk .Partition {}
186
186
for _ , part := range partitions {
187
187
if dims , ok := realDimensions [part .Number ]; ok {
188
188
if part .StartSector != nil {
@@ -197,7 +197,7 @@ func (s stage) getRealStartAndSize(dev types.Disk, devAlias string, diskInfo uti
197
197
return result , nil
198
198
}
199
199
200
- type sgdiskOutput struct {
200
+ type sfdiskOutput struct {
201
201
start int64
202
202
size int64
203
203
}
@@ -213,17 +213,17 @@ func parseLine(r *regexp.Regexp, line string) (int64, error) {
213
213
case 2 :
214
214
return strconv .ParseInt (matches [1 ], 10 , 64 )
215
215
default :
216
- return 0 , ErrBadSgdiskOutput
216
+ return 0 , ErrBadsfdiskOutput
217
217
}
218
218
}
219
219
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
220
+ // parsesfdiskPretend parses the output of running sfdisk 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 sfdisk
222
+ // output was from running `sfdisk --pretend <commands> --info=1 --info=4 --info=5`. It assumes the the
223
223
// 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 ) {
224
+ // matching the partition numbers specified, but with the start and size information as determined by sfdisk .
225
+ // The partition numbers need to passed in because sfdisk includes them in its output.
226
+ func parsesfdiskPretend ( sfdiskOut string , partitionNumbers []int ) (map [int ]sfdiskOutput , error ) {
227
227
if len (partitionNumbers ) == 0 {
228
228
return nil , nil
229
229
}
@@ -235,12 +235,12 @@ func parseSgdiskPretend(sgdiskOut string, partitionNumbers []int) (map[int]sgdis
235
235
FAIL_ON_START_END = iota
236
236
)
237
237
238
- output := map [int ]sgdiskOutput {}
238
+ output := map [int ]sfdiskOutput {}
239
239
state := START
240
- current := sgdiskOutput {}
240
+ current := sfdiskOutput {}
241
241
i := 0
242
242
243
- lines := strings .Split (sgdiskOut , "\n " )
243
+ lines := strings .Split (sfdiskOut , "\n " )
244
244
for _ , line := range lines {
245
245
switch state {
246
246
case START :
@@ -264,29 +264,29 @@ func parseSgdiskPretend(sgdiskOut string, partitionNumbers []int) (map[int]sgdis
264
264
if i == len (partitionNumbers ) {
265
265
state = FAIL_ON_START_END
266
266
} else {
267
- current = sgdiskOutput {}
267
+ current = sfdiskOutput {}
268
268
state = START
269
269
}
270
270
}
271
271
case FAIL_ON_START_END :
272
272
if len (startRegex .FindStringSubmatch (line )) != 0 ||
273
273
len (endRegex .FindStringSubmatch (line )) != 0 {
274
- return nil , ErrBadSgdiskOutput
274
+ return nil , ErrBadsfdiskOutput
275
275
}
276
276
}
277
277
}
278
278
279
279
if state != FAIL_ON_START_END {
280
280
// We stopped parsing in the middle of a info block. Something is wrong
281
- return nil , ErrBadSgdiskOutput
281
+ return nil , ErrBadsfdiskOutput
282
282
}
283
283
284
284
return output , nil
285
285
}
286
286
287
287
// partitionShouldExist returns whether a bool is indicating if a partition should exist or not.
288
288
// nil (unspecified in json) is treated the same as true.
289
- func partitionShouldExist (part sgdisk .Partition ) bool {
289
+ func partitionShouldExist (part sfdisk .Partition ) bool {
290
290
return ! cutil .IsFalse (part .ShouldExist )
291
291
}
292
292
@@ -438,14 +438,14 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
438
438
return fmt .Errorf ("refusing to operate on directly active disk %q" , devAlias )
439
439
}
440
440
if cutil .IsTrue (dev .WipeTable ) {
441
- op := sgdisk .Begin (s .Logger , devAlias )
441
+ op := sfdisk .Begin (s .Logger , devAlias )
442
442
s .Logger .Info ("wiping partition table requested on %q" , devAlias )
443
443
if len (activeParts ) > 0 {
444
444
return fmt .Errorf ("refusing to wipe active disk %q" , devAlias )
445
445
}
446
446
op .WipeTable (true )
447
447
if err := op .Commit (); err != nil {
448
- // `sgdisk --zap-all` will exit code 2 if the table was corrupted; retry it
448
+ // `sfdisk --zap-all` will exit code 2 if the table was corrupted; retry it
449
449
// https://github.com/coreos/fedora-coreos-tracker/issues/1596
450
450
s .Logger .Info ("potential error encountered while wiping table... retrying" )
451
451
if err := op .Commit (); err != nil {
@@ -457,7 +457,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
457
457
// Ensure all partitions with number 0 are last
458
458
sort .Stable (PartitionList (dev .Partitions ))
459
459
460
- op := sgdisk .Begin (s .Logger , devAlias )
460
+ op := sfdisk .Begin (s .Logger , devAlias )
461
461
462
462
diskInfo , err := s .getPartitionMap (devAlias )
463
463
if err != nil {
@@ -542,7 +542,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
542
542
return fmt .Errorf ("commit failure: %v" , err )
543
543
}
544
544
545
- // In contrast to similar tools, sgdisk does not trigger the update of the
545
+ // In contrast to similar tools, sfdisk does not trigger the update of the
546
546
// kernel partition table with BLKPG but only uses BLKRRPART which fails
547
547
// as soon as one partition of the disk is mounted
548
548
if len (activeParts ) > 0 {
0 commit comments