MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / createPartition

Function createPartition

pkg/extend/extend.go:187–229  ·  view source on GitHub ↗
(d string, partition Partition)

Source from the content-addressed store, hash-verified

185}
186
187func createPartition(d string, partition Partition) error {
188 if err := exec.Command("sfdisk", "-q", "--delete", d).Run(); err != nil {
189 return fmt.Errorf("Error erasing partition table: %v", err.Error())
190 }
191
192 createCmd := exec.Command("sfdisk", "-q", d)
193 createCmd.Stdin = strings.NewReader(fmt.Sprintf("%d,,%s;", partition.Start, partition.Type))
194 if err := createCmd.Run(); err != nil {
195 return fmt.Errorf("Error creating partition table: %v", err)
196 }
197
198 if err := exec.Command("sfdisk", "-A", d, "1").Run(); err != nil {
199 return fmt.Errorf("Error making %s bootable: %v", d, err)
200 }
201
202 // update status
203 if err := rereadPartitions(d); err != nil {
204 return fmt.Errorf("Error re-reading partition using ioctl: %v", err)
205 }
206
207 exec.Command("mdev", "-s").Run()
208
209 // wait for device
210 var done bool
211 for i := 0; i < timeout; i++ {
212 stat, err := os.Stat(partition.Node)
213 if err == nil {
214 mode := stat.Sys().(*syscall.Stat_t).Mode
215 if (mode & syscall.S_IFMT) == syscall.S_IFBLK {
216 done = true
217 break
218 }
219 }
220 time.Sleep(100 * time.Millisecond)
221 exec.Command("mdev", "-s").Run()
222 }
223 if !done {
224 return fmt.Errorf("Error waiting for device %s", partition.Node)
225 }
226 // even after the device appears we still have a race
227 time.Sleep(1 * time.Second)
228 return nil
229}
230
231func deviceSize(device string) (int64, error) {
232 file, err := os.Open(device)

Callers 1

extendFunction · 0.85

Calls 2

rereadPartitionsFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected