forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_linux.go
62 lines (50 loc) · 1.6 KB
/
path_linux.go
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
51
52
53
54
55
56
57
58
59
60
61
62
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package ghw
import (
"os"
"path/filepath"
)
const (
DEFAULT_ROOT_PATH = "/"
)
// To facilitate querying of sysfs filesystems that are bind-mounted to a
// non-default root mountpoint, we allow users to set the GHW_CHROOT environ
// vairable to an alternate mountpoint. For instance, assume that the user of
// ghw is a Golang binary being executed from an application container that has
// certain host filesystems bind-mounted into the container at /host. The user
// would ensure the GHW_CHROOT environ variable is set to "/host" and ghw will
// build its paths from that location instead of /
func pathRoot() string {
path := DEFAULT_ROOT_PATH
if override, exists := os.LookupEnv("GHW_CHROOT"); exists {
path = override
}
return path
}
func pathProcCpuinfo() string {
return filepath.Join(pathRoot(), "proc", "cpuinfo")
}
func pathEtcMtab() string {
return filepath.Join(pathRoot(), "etc", "mtab")
}
func pathSysBlock() string {
return filepath.Join(pathRoot(), "sys", "block")
}
func pathSysDevicesSystemNode() string {
return filepath.Join(pathRoot(), "sys", "devices", "system", "node")
}
func pathSysBusPciDevices() string {
return filepath.Join(pathRoot(), "sys", "bus", "pci", "devices")
}
func pathSysClassDrm() string {
return filepath.Join(pathRoot(), "sys", "class", "drm")
}
func pathSysClassNet() string {
return filepath.Join(pathRoot(), "sys", "class", "net")
}
func pathRunUdevData() string {
return filepath.Join(pathRoot(), "run", "udev", "data")
}