|
| 1 | +// +build aix |
| 2 | + |
| 3 | +package disk |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "fmt" |
| 8 | + |
| 9 | + "github.com/power-devops/perfstat" |
| 10 | + "github.com/shirou/gopsutil/v3/internal/common" |
| 11 | +) |
| 12 | + |
| 13 | +var FSType map[int]string |
| 14 | + |
| 15 | +func init() { |
| 16 | + FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc", |
| 17 | + 16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs", |
| 18 | + 33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs", |
| 19 | + 39: "ahafs", 40: "sterm-nfs", 41: "asmfs" } |
| 20 | +} |
| 21 | + |
| 22 | +func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { |
| 23 | + f, err := perfstat.FileSystemStat() |
| 24 | + if err != nil { |
| 25 | + return nil, err |
| 26 | + } |
| 27 | + ret := make([]PartitionStat, len(f)) |
| 28 | + |
| 29 | + for _, fs := range f { |
| 30 | + fstyp, exists := FSType[fs.FSType] |
| 31 | + if ! exists { |
| 32 | + fstyp = "unknown" |
| 33 | + } |
| 34 | + info := PartitionStat{ |
| 35 | + Device: fs.Device, |
| 36 | + Mountpoint: fs.MountPoint, |
| 37 | + Fstype: fstyp, |
| 38 | + } |
| 39 | + ret = append(ret,info) |
| 40 | + } |
| 41 | + |
| 42 | + return ret, err |
| 43 | +} |
| 44 | + |
| 45 | +func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { |
| 46 | + return nil, common.ErrNotImplementedError |
| 47 | +} |
| 48 | + |
| 49 | +func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { |
| 50 | + f, err := perfstat.FileSystemStat() |
| 51 | + if err != nil { |
| 52 | + return nil, err |
| 53 | + } |
| 54 | + |
| 55 | + blocksize := uint64(512) |
| 56 | + for _, fs := range f { |
| 57 | + if path == fs.MountPoint { |
| 58 | + fstyp, exists := FSType[fs.FSType] |
| 59 | + if ! exists { |
| 60 | + fstyp = "unknown" |
| 61 | + } |
| 62 | + info := UsageStat{ |
| 63 | + Path: path, |
| 64 | + Fstype: fstyp, |
| 65 | + Total: uint64(fs.TotalBlocks) * blocksize, |
| 66 | + Free: uint64(fs.FreeBlocks) * blocksize, |
| 67 | + Used: uint64(fs.TotalBlocks - fs.FreeBlocks) * blocksize, |
| 68 | + InodesTotal: uint64(fs.TotalInodes), |
| 69 | + InodesFree: uint64(fs.FreeInodes), |
| 70 | + InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes), |
| 71 | + } |
| 72 | + info.UsedPercent = (float64(info.Used) / float64(info.Total)) * 100.0 |
| 73 | + info.InodesUsedPercent = (float64(info.InodesUsed) / float64(info.InodesTotal)) * 100.0 |
| 74 | + return &info, nil |
| 75 | + } |
| 76 | + } |
| 77 | + return nil, fmt.Errorf("mountpoint %s not found", path) |
| 78 | +} |
| 79 | + |
| 80 | +func SerialNumberWithContext(ctx context.Context, name string) (string, error) { |
| 81 | + return "", common.ErrNotImplementedError |
| 82 | +} |
| 83 | + |
| 84 | +func LabelWithContext(ctx context.Context, name string) (string, error) { |
| 85 | + return "", common.ErrNotImplementedError |
| 86 | +} |
0 commit comments