Skip to content

Commit

Permalink
Get the mountpoint if any by readin /proc/mounts
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
  • Loading branch information
Itxaka committed Jun 23, 2023
1 parent a602517 commit 3ce69ce
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/utils/getpartitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func GetPartitionViaDM(fs v1.FS, label string) *v1.Partition {
}
// read dev number
devNo, err := fs.ReadFile(filepath.Join(lp.SysBlock, dev.Name(), "dev"))
// No slaves, empty dm?
// No device number, empty dm?
if err != nil || string(devNo) == "" {
continue
}
Expand Down Expand Up @@ -140,6 +140,7 @@ func GetPartitionViaDM(fs v1.FS, label string) *v1.Partition {
part.Size = uint(finalSize)
}
}

// Read slaves to get the device
slaves, err := fs.ReadDir(filepath.Join(lp.SysBlock, dev.Name(), "slaves"))
if err != nil {
Expand Down Expand Up @@ -183,6 +184,26 @@ func GetPartitionViaDM(fs v1.FS, label string) *v1.Partition {

}

// Read /proc/mounts to get the mountpoint if any
// We need the disk to be filled to get the mountpoint
if part.Disk != "" {
mounts, err := fs.ReadFile("/proc/mounts")
if err == nil {
for _, l := range strings.Split(string(mounts), "\n") {
entry := strings.Split(l, " ")
// entry is `device mountpoint fstype options unused unused`
// The unused fields are there for compatibility with mtab
if len(entry) > 1 {
// Check against the path as lvm devices are not mounted against /dev, they are mounted via label
if entry[0] == part.Path {
part.MountPoint = entry[1]
break
}
}
}
}
}

return part
}
}
Expand Down

0 comments on commit 3ce69ce

Please sign in to comment.