Skip to content

Commit

Permalink
fix(gpt): do not inform kernel of partition when writing (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored Nov 30, 2018
1 parent 79c96cf commit fa9f77e
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions src/initramfs/pkg/blockdevice/table/gpt/gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,6 @@ func (gpt *GPT) Write() error {
return errors.Errorf("failed to write secondary table: %v", err)
}

for _, p := range gpt.Partitions() {
var gptpartition *partition.Partition
var ok bool

if gptpartition, ok = p.(*partition.Partition); !ok {
return errors.New("not a GPT partition")
}
if gptpartition.IsNew {
if err := gpt.InformKernelOfAdd(p); err != nil {
return errors.Errorf("failed to inform kernel of new partition: %v", err)
}
}
if gptpartition.IsResized {
if err := gpt.InformKernelOfResize(p); err != nil {
return errors.Errorf("failed to inform kernel of resized partition: %v", err)
}
}
}

return gpt.Read()
}

Expand Down Expand Up @@ -447,38 +428,17 @@ func (gpt *GPT) deserializePartitions() ([]byte, error) {

// InformKernelOfAdd invokes the BLKPG_ADD_PARTITION ioctl.
func (gpt *GPT) InformKernelOfAdd(partition table.Partition) error {
f, err := os.Open(gpt.devname)
if err != nil {
return err
}
// nolint: errcheck
defer f.Close()

return inform(f.Fd(), partition, unix.BLKPG_ADD_PARTITION, int64(gpt.lba.PhysicalBlockSize))
return inform(gpt.f.Fd(), partition, unix.BLKPG_ADD_PARTITION, int64(gpt.lba.PhysicalBlockSize))
}

// InformKernelOfResize invokes the BLKPG_RESIZE_PARTITION ioctl.
func (gpt *GPT) InformKernelOfResize(partition table.Partition) error {
f, err := os.Open(gpt.devname)
if err != nil {
return err
}
// nolint: errcheck
defer f.Close()

return inform(f.Fd(), partition, unix.BLKPG_RESIZE_PARTITION, int64(gpt.lba.PhysicalBlockSize))
return inform(gpt.f.Fd(), partition, unix.BLKPG_RESIZE_PARTITION, int64(gpt.lba.PhysicalBlockSize))
}

// InformKernelOfDelete invokes the BLKPG_DEL_PARTITION ioctl.
func (gpt *GPT) InformKernelOfDelete(partition table.Partition) error {
f, err := os.Open(gpt.devname)
if err != nil {
return err
}
// nolint: errcheck
defer f.Close()

return inform(f.Fd(), partition, unix.BLKPG_DEL_PARTITION, int64(gpt.lba.PhysicalBlockSize))
return inform(gpt.f.Fd(), partition, unix.BLKPG_DEL_PARTITION, int64(gpt.lba.PhysicalBlockSize))
}

func inform(fd uintptr, partition table.Partition, op int32, blocksize int64) error {
Expand Down

0 comments on commit fa9f77e

Please sign in to comment.