1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-29 13:49:21 +08:00

follow the psutil principles, do nothing if can not find root device

This commit is contained in:
arstercz 2022-05-01 02:33:09 +00:00
parent d52b97cd25
commit f6dc96c30e

View File

@ -349,12 +349,11 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
// /dev/root is not the real device name // /dev/root is not the real device name
// so we get the real device name from its major/minor number // so we get the real device name from its major/minor number
if d.Device == "/dev/root" && d.Fstype != "nfs" { if d.Device == "/dev/root" {
devpath, err := os.Readlink(common.HostSys("/dev/block/" + blockDeviceID)) devpath, err := os.Readlink(common.HostSys("/dev/block/" + blockDeviceID))
if err != nil { if err == nil {
return nil, err d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1)
} }
d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1)
} }
} }
ret = append(ret, d) ret = append(ret, d)