Skip to content

Commit

Permalink
Revert "Fixed device major minor parse failure"
Browse files Browse the repository at this point in the history
This reverts commit 33b0cb2.

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Jun 25, 2024
1 parent be1bb81 commit 5525dc7
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions distrobuilder/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,19 @@ func (v *vm) mountImage() error {
return fmt.Errorf("Failed to list block devices: %w", err)
}

lsblkOutput := strings.TrimSpace(out.String())
deviceNumbers := strings.Split(lsblkOutput, "\n")
if len(deviceNumbers) != 2 {
return fmt.Errorf("Failed to list block devices: %s", lsblkOutput)
}
deviceNumbers := strings.Split(out.String(), "\n")

parseMajorMinor := func(i int) (major, minor uint32, err error) {
fields := strings.Split(deviceNumbers[i], ":")
if !incus.PathExists(v.getUEFIDevFile()) {
fields := strings.Split(deviceNumbers[1], ":")

num, err := strconv.Atoi(fields[0])
major, err := strconv.Atoi(fields[0])
if err != nil {
err = fmt.Errorf("Failed to parse %q: %w", fields[0], err)
return
return fmt.Errorf("Failed to parse %q: %w", fields[0], err)
}

major = uint32(num)
num, err = strconv.Atoi(fields[1])
minor, err := strconv.Atoi(fields[1])
if err != nil {
err = fmt.Errorf("Failed to parse %q: %w", fields[1], err)
return
}

minor = uint32(num)
return
}

if !incus.PathExists(v.getUEFIDevFile()) {
major, minor, err := parseMajorMinor(0)
if err != nil {
return err
return fmt.Errorf("Failed to parse %q: %w", fields[1], err)
}

dev := unix.Mkdev(uint32(major), uint32(minor))
Expand All @@ -194,9 +177,16 @@ func (v *vm) mountImage() error {
}

if !incus.PathExists(v.getRootfsDevFile()) {
major, minor, err := parseMajorMinor(1)
fields := strings.Split(deviceNumbers[2], ":")

major, err := strconv.Atoi(fields[0])
if err != nil {
return fmt.Errorf("Failed to parse %q: %w", fields[0], err)
}

minor, err := strconv.Atoi(fields[1])
if err != nil {
return err
return fmt.Errorf("Failed to parse %q: %w", fields[1], err)
}

dev := unix.Mkdev(uint32(major), uint32(minor))
Expand Down

0 comments on commit 5525dc7

Please sign in to comment.