Skip to content

Commit da529f3

Browse files
authored
Merge pull request #1341 from chbuescher/master
implement aix nocgo disk usage
2 parents 38732e0 + 9ef87ea commit da529f3

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

disk/disk_aix_nocgo.go

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,78 @@ package disk
55

66
import (
77
"context"
8+
"regexp"
9+
"strings"
810

11+
"golang.org/x/sys/unix"
912
"github.com/shirou/gopsutil/v3/internal/common"
1013
)
1114

15+
var whiteSpaces = regexp.MustCompile(`\s+`)
16+
var startBlank = regexp.MustCompile(`^\s+`)
17+
18+
var ignoreFSType = map[string]bool{"procfs": true}
19+
var FSType = map[int]string{
20+
0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc",
21+
16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs",
22+
33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
23+
39: "ahafs", 40: "sterm-nfs", 41: "asmfs",
24+
}
25+
1226
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
13-
return []PartitionStat{}, common.ErrNotImplementedError
27+
var ret []PartitionStat
28+
29+
out, err := invoke.CommandWithContext(ctx, "mount")
30+
if err != nil {
31+
return nil, err
32+
}
33+
34+
// parse head lines for column names
35+
colidx := make(map[string]int)
36+
lines := strings.Split(string(out), "\n")
37+
if len(lines) < 3 {
38+
return nil, common.ErrNotImplementedError
39+
}
40+
41+
idx := 0
42+
start := 0
43+
finished := false
44+
for pos, ch := range lines[1] {
45+
if ch == ' ' && ! finished {
46+
name := strings.TrimSpace(lines[0][start:pos])
47+
colidx[name] = idx
48+
finished = true
49+
} else if ch == '-' && finished {
50+
idx++
51+
start = pos
52+
finished = false
53+
}
54+
}
55+
name := strings.TrimSpace(lines[0][start:len(lines[1])])
56+
colidx[name] = idx
57+
58+
for idx := 2; idx < len(lines); idx++ {
59+
line := lines[idx]
60+
if startBlank.MatchString(line) {
61+
line = "localhost" + line
62+
}
63+
p := whiteSpaces.Split(lines[idx], 6)
64+
if len(p) < 5 || ignoreFSType[p[colidx["vfs"]]] {
65+
continue
66+
}
67+
d := PartitionStat{
68+
Device: p[colidx["mounted"]],
69+
Mountpoint: p[colidx["mounted over"]],
70+
Fstype: p[colidx["vfs"]],
71+
Opts: strings.Split(p[colidx["options"]], ","),
72+
}
73+
74+
ret = append(ret, d)
75+
}
76+
77+
return ret, nil
1478
}
1579

16-
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
17-
return nil, common.ErrNotImplementedError
80+
func getFsType(stat unix.Statfs_t) string {
81+
return FSType[int(stat.Vfstype)]
1882
}

disk/disk_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build freebsd || linux || darwin
2-
// +build freebsd linux darwin
1+
//go:build freebsd || linux || darwin || (aix && !cgo)
2+
// +build freebsd linux darwin aix,!cgo
33

44
package disk
55

0 commit comments

Comments
 (0)