// SPDX-License-Identifier: BSD-3-Clause //go:build aix package disk import ( "context" "errors" "strings" "golang.org/x/sys/unix" "github.com/shirou/gopsutil/v4/internal/common" ) func LabelWithContext(_ context.Context, _ string) (string, error) { return "", common.ErrNotImplementedError } // FSType maps AIX filesystem type numbers (as reported by statfs and perfstat) // to their string name. Shared by the cgo and nocgo build variants. var FSType = map[int]string{ 0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc", 16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs", 33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs", 39: "ahafs", 40: "sterm-nfs", 41: "asmfs", } func getFsType(stat unix.Statfs_t) string { return FSType[int(stat.Vfstype)] } // Using lscfg and a device name, we can get the device information // This is a pure go implementation, and should be moved to disk_aix_nocgo.go // if a more efficient CGO method is introduced in disk_aix_cgo.go func SerialNumberWithContext(ctx context.Context, name string) (string, error) { // This isn't linux, these aren't actual disk devices if strings.HasPrefix(name, "/dev/") { return "", errors.New("devices on /dev are not physical disks on aix") } // Reject names that would be interpreted as command-line options by lscfg. if strings.HasPrefix(name, "-") { return "", errors.New("invalid device name") } out, err := invoke.CommandWithContext(ctx, "lscfg", "-vl", name) if err != nil { return "", err } ret := "" // Kind of inefficient, but it works lines := strings.Split(string(out), "\n") for line := 1; line < len(lines); line++ { v := strings.TrimSpace(lines[line]) if strings.HasPrefix(v, "Serial Number...............") { ret = strings.TrimPrefix(v, "Serial Number...............") if ret == "" { return "", errors.New("empty serial for disk") } return ret, nil } } return ret, errors.New("serial entry not found for disk") }