File: disk_aix.go

package info (click to toggle)
golang-github-shirou-gopsutil 4.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,824 kB
  • sloc: makefile: 76; ansic: 19; sh: 11
file content (50 lines) | stat: -rw-r--r-- 1,462 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix

package disk

import (
	"context"
	"errors"
	"strings"

	"github.com/shirou/gopsutil/v4/internal/common"
)

func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
	return nil, common.ErrNotImplementedError
}

func LabelWithContext(ctx context.Context, name string) (string, error) {
	return "", common.ErrNotImplementedError
}

// 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")
	}
	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")
}