...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package sysfs
18
19 import (
20 "fmt"
21 "os"
22 "path/filepath"
23
24 "github.com/prometheus/procfs/internal/util"
25 )
26
27 const dmiClassPath = "class/dmi/id"
28
29
30 type DMIClass struct {
31 BiosDate *string
32 BiosRelease *string
33 BiosVendor *string
34 BiosVersion *string
35 BoardAssetTag *string
36 BoardName *string
37 BoardSerial *string
38 BoardVendor *string
39 BoardVersion *string
40 ChassisAssetTag *string
41 ChassisSerial *string
42 ChassisType *string
43 ChassisVendor *string
44 ChassisVersion *string
45 ProductFamily *string
46 ProductName *string
47 ProductSerial *string
48 ProductSKU *string
49 ProductUUID *string
50 ProductVersion *string
51 SystemVendor *string
52 }
53
54
55 func (fs FS) DMIClass() (*DMIClass, error) {
56 path := fs.sys.Path(dmiClassPath)
57
58 files, err := os.ReadDir(path)
59 if err != nil {
60 return nil, fmt.Errorf("failed to read directory %q: %w", path, err)
61 }
62
63 var dmi DMIClass
64 for _, f := range files {
65 if !f.Type().IsRegular() {
66 continue
67 }
68
69 name := f.Name()
70 if name == "modalias" || name == "uevent" {
71 continue
72 }
73
74 filename := filepath.Join(path, name)
75 value, err := util.SysReadFile(filename)
76 if err != nil {
77 if os.IsPermission(err) {
78
79 continue
80 }
81 return nil, fmt.Errorf("failed to read file %q: %w", filename, err)
82 }
83
84 switch name {
85 case "bios_date":
86 dmi.BiosDate = &value
87 case "bios_release":
88 dmi.BiosRelease = &value
89 case "bios_vendor":
90 dmi.BiosVendor = &value
91 case "bios_version":
92 dmi.BiosVersion = &value
93 case "board_asset_tag":
94 dmi.BoardAssetTag = &value
95 case "board_name":
96 dmi.BoardName = &value
97 case "board_serial":
98 dmi.BoardSerial = &value
99 case "board_vendor":
100 dmi.BoardVendor = &value
101 case "board_version":
102 dmi.BoardVersion = &value
103 case "chassis_asset_tag":
104 dmi.ChassisAssetTag = &value
105 case "chassis_serial":
106 dmi.ChassisSerial = &value
107 case "chassis_type":
108 dmi.ChassisType = &value
109 case "chassis_vendor":
110 dmi.ChassisVendor = &value
111 case "chassis_version":
112 dmi.ChassisVersion = &value
113 case "product_family":
114 dmi.ProductFamily = &value
115 case "product_name":
116 dmi.ProductName = &value
117 case "product_serial":
118 dmi.ProductSerial = &value
119 case "product_sku":
120 dmi.ProductSKU = &value
121 case "product_uuid":
122 dmi.ProductUUID = &value
123 case "product_version":
124 dmi.ProductVersion = &value
125 case "sys_vendor":
126 dmi.SystemVendor = &value
127 }
128 }
129
130 return &dmi, nil
131 }
132
View as plain text