|
|
|
@ -227,8 +227,17 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|
|
|
|
filename := common.HostProc("self/mountinfo")
|
|
|
|
|
lines, err := common.ReadLines(filename)
|
|
|
|
|
if err != nil {
|
|
|
|
|
UseMounts := true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if kernel not support self/mountinfo
|
|
|
|
|
if UseMounts {
|
|
|
|
|
filename := common.HostProc("self/mounts")
|
|
|
|
|
lines, err := common.ReadLines(filename)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs, err := getFileSystems()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -243,6 +252,16 @@ 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 {
|
|
|
|
|
fields := strings.Fields(line)
|
|
|
|
|
|
|
|
|
|
d := PartitionStat{
|
|
|
|
|
Device: fields[0],
|
|
|
|
|
Mountpoint: unescapeFstab(fields[1]),
|
|
|
|
|
Fstype: fields[2],
|
|
|
|
|
Opts: fields[3],
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
parts := strings.Split(line, " - ")
|
|
|
|
|
if len(parts) != 2 {
|
|
|
|
|
return nil, fmt.Errorf("found invalid mountinfo line in file %s: %s ", filename, line)
|
|
|
|
@ -263,6 +282,9 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|
|
|
|
Fstype: fstype,
|
|
|
|
|
Opts: mountOpts,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if UseMounts {
|
|
|
|
|
if all == false {
|
|
|
|
|
if d.Device == "none" || !common.StringsHas(fs, d.Fstype) {
|
|
|
|
|
continue
|
|
|
|
@ -277,6 +299,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|
|
|
|
}
|
|
|
|
|
d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ret = append(ret, d)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|