Skip to content

Commit

Permalink
convert block device to partition info method
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp committed Dec 20, 2024
1 parent 2e86cd2 commit cc236c0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions providers/os/connection/snapshot/blockdevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"math"
"os"
"path"
"sort"
"strconv"
"strings"
Expand All @@ -32,6 +33,17 @@ type BlockDevice struct {
Aliases []string `json:"-"`
}

func (b BlockDevice) PartitionInfo(devPath string) *PartitionInfo {
return &PartitionInfo{
Name: path.Join(devPath, b.Name),
FsType: b.FsType,
Label: b.Label,
Uuid: b.Uuid,
MountPoint: b.MountPoint,
Aliases: b.Aliases,
}
}

type Size int64

func (s *Size) UnmarshalJSON(data []byte) error {
Expand Down Expand Up @@ -211,13 +223,7 @@ func (device BlockDevice) GetPartitions(includeBoot bool, includeMounted bool) (
partitions = append(partitions, mapLVM2Partitions(partition)...)
continue
}
devFsName := "/dev/" + partition.Name
partitions = append(partitions, &PartitionInfo{
Name: devFsName, FsType: partition.FsType,
Label: partition.Label, Uuid: partition.Uuid,
Aliases: partition.Aliases,
MountPoint: partition.MountPoint,
})
partitions = append(partitions, partition.PartitionInfo("/dev"))
} else {
log.Debug().
Str("name", partition.Name).
Expand All @@ -236,11 +242,7 @@ func (device BlockDevice) GetPartitions(includeBoot bool, includeMounted bool) (

func mapLVM2Partitions(part BlockDevice) (partitions []*PartitionInfo) {
for _, p := range part.Children {
devFsName := "/dev/mapper/" + p.Name
partitions = append(partitions, &PartitionInfo{
Name: devFsName, FsType: p.FsType,
Label: p.Label, Uuid: p.Uuid,
})
partitions = append(partitions, p.PartitionInfo("/dev/mapper"))
}

return partitions
Expand Down

0 comments on commit cc236c0

Please sign in to comment.