From d1413496199dce7179f808ab8808f1d9db0c3ebc Mon Sep 17 00:00:00 2001 From: JHE Date: Tue, 5 Feb 2019 21:23:46 +0800 Subject: [PATCH] if mountinfo not found, use mounts --- disk/disk_linux.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/disk/disk_linux.go b/disk/disk_linux.go index 1713536..7dbb5a7 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -226,12 +226,13 @@ func Partitions(all bool) ([]PartitionStat, error) { func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { filename := common.HostProc("self/mountinfo") lines, err := common.ReadLines(filename) + UseMounts := false if err != nil { - UseMounts := true + UseMounts = true } //if kernel not support self/mountinfo - if UseMounts { + if UseMounts == true { filename := common.HostProc("self/mounts") lines, err := common.ReadLines(filename) if err != nil { @@ -252,7 +253,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro // (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) // split the mountinfo line by the separator hyphen - if UseMounts { + if UseMounts == true { fields := strings.Fields(line) d := PartitionStat{ @@ -284,12 +285,13 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro } } - if UseMounts { - if all == false { - if d.Device == "none" || !common.StringsHas(fs, d.Fstype) { - continue - } + if all == false { + if d.Device == "none" || !common.StringsHas(fs, d.Fstype) { + continue } + } + + if UseMounts == true { // /dev/root is not the real device name // so we get the real device name from its major/minor number if d.Device == "/dev/root" {