Skip to content

Commit d068994

Browse files
brianmcgeeMic92
authored andcommitted
fix: nix cannot support uint64
Reduces the size of various fields from `uint` or `uint64` as an integer in Nix is always signed. Where required for true `uint64` values, we hex encode them instead. For other fields, I have made educated guesses as to their appropriate sizes. Signed-off-by: Brian McGee <[email protected]>
1 parent a12c32c commit d068994

33 files changed

+254
-245
lines changed

pkg/build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ var (
1010
// It is set via Nix to match the Nixpkgs system.
1111
System = ""
1212
// ReportVersion is used to indicate significant changes in the report output and is embedded JSON report produced.
13-
ReportVersion uint = 1
13+
ReportVersion uint16 = 1
1414
)

pkg/facter/facter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
type Report struct {
1818
// Version is a monotonically increasing number,
1919
// used to indicate breaking changes or new features in the report output.
20-
Version uint `json:"version"`
20+
Version uint16 `json:"version"`
2121

2222
// System indicates the system architecture e.g. x86_64-linux.
2323
System string `json:"system"`

pkg/hwinfo/detail.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ func NewDetail(detail *C.hd_detail_t) (Detail, error) {
9090
}
9191

9292
type MemoryRange struct {
93-
Start uint `json:"start"`
94-
Size uint `json:"size"`
93+
Start string `json:"start"`
94+
Size string `json:"size"`
9595
Data string `json:"-"` // hex encoded
9696
}
9797

9898
func NewMemoryRange(mem C.memory_range_t) MemoryRange {
9999
return MemoryRange{
100-
Start: uint(mem.start),
101-
Size: uint(mem.size),
100+
Start: fmt.Sprintf("0x%x", uint(mem.start)),
101+
Size: fmt.Sprintf("0x%x", uint(mem.size)),
102102
Data: hex.EncodeToString(C.GoBytes(unsafe.Pointer(&mem.data), C.int(mem.size))), //nolint:gocritic
103103
}
104104
}

pkg/hwinfo/detail_bios.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ bool bios_info_has_lba_support(bios_info_t *info) { return info->lba_support; }
1313
import "C"
1414

1515
type ApmInfo struct {
16-
Supported bool `json:"supported"`
17-
Enabled bool `json:"enabled"`
18-
Version uint `json:"version"`
19-
SubVersion uint `json:"sub_version"`
20-
BiosFlags uint `json:"bios_flags"`
16+
Supported bool `json:"supported"`
17+
Enabled bool `json:"enabled"`
18+
Version uint8 `json:"version"`
19+
SubVersion uint8 `json:"sub_version"`
20+
BiosFlags uint32 `json:"bios_flags"`
2121
}
2222

2323
type VbeInfo struct {
24-
Version uint `json:"version"`
25-
VideoMemory uint `json:"video_memory"`
24+
Version uint16 `json:"version"`
25+
VideoMemory uint32 `json:"video_memory"`
2626
}
2727

2828
type DetailBios struct {
@@ -31,14 +31,14 @@ type DetailBios struct {
3131
VbeInfo VbeInfo `json:"vbe_info"`
3232

3333
// todo par and ser ports
34-
PnP bool `json:"pnp"`
35-
PnPId uint `json:"pnp_id"` // it is still in big endian format
36-
LbaSupport bool `json:"lba_support"`
37-
LowMemorySize uint `json:"low_memory_size"`
34+
PnP bool `json:"pnp"`
35+
PnPId uint `json:"pnp_id"` // it is still in big endian format
36+
LbaSupport bool `json:"lba_support"`
37+
LowMemorySize uint32 `json:"low_memory_size"`
3838
// todo smp info
3939
// todo vbe info
4040

41-
SmbiosVersion uint `json:"smbios_version"`
41+
SmbiosVersion uint32 `json:"smbios_version"`
4242

4343
// todo lcd
4444
// todo mouse
@@ -58,18 +58,18 @@ func NewDetailBios(dev C.hd_detail_bios_t) (*DetailBios, error) {
5858
ApmInfo: ApmInfo{
5959
Supported: bool(C.bios_info_is_apm_supported(data)),
6060
Enabled: bool(C.bios_info_is_apm_enabled(data)),
61-
Version: uint(data.apm_ver),
62-
SubVersion: uint(data.apm_subver),
63-
BiosFlags: uint(data.apm_bios_flags),
61+
Version: uint8(data.apm_ver),
62+
SubVersion: uint8(data.apm_subver),
63+
BiosFlags: uint32(data.apm_bios_flags),
6464
},
6565
VbeInfo: VbeInfo{
66-
Version: uint(data.vbe_ver),
67-
VideoMemory: uint(data.vbe_video_mem),
66+
Version: uint16(data.vbe_ver),
67+
VideoMemory: uint32(data.vbe_video_mem),
6868
},
6969
PnP: bool(C.bios_info_is_pnp_bios(data)),
7070
PnPId: uint(data.pnp_id),
7171
LbaSupport: bool(C.bios_info_has_lba_support(data)),
72-
LowMemorySize: uint(data.low_mem_size),
73-
SmbiosVersion: uint(data.smbios_ver),
72+
LowMemorySize: uint32(data.low_mem_size),
73+
SmbiosVersion: uint32(data.smbios_ver),
7474
}, nil
7575
}

pkg/hwinfo/detail_cpu.go

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ bool cpu_info_fpu_exception(cpu_info_t *info) { return info->fpu_exception; }
1010
bool cpu_info_write_protect(cpu_info_t *info) { return info->write_protect; }
1111
*/
1212
import "C"
13-
import "regexp"
13+
14+
import (
15+
"fmt"
16+
"regexp"
17+
)
1418

1519
//go:generate enumer -type=CPUArch -json -transform=snake -trimprefix CPUArch -output=./detail_enum_cpu_arch.go
1620
type CPUArch uint //nolint:recvcheck
@@ -36,8 +40,8 @@ const (
3640
)
3741

3842
type AddressSizes struct {
39-
Physical uint `json:"physical,omitempty"`
40-
Virtual uint `json:"virtual,omitempty"`
43+
Physical string `json:"physical,omitempty"`
44+
Virtual string `json:"virtual,omitempty"`
4145
}
4246

4347
type DetailCPU struct {
@@ -48,9 +52,9 @@ type DetailCPU struct {
4852
VendorName string `json:"vendor_name,omitempty"`
4953
ModelName string `json:"model_name,omitempty"`
5054

51-
Family uint `json:"family"`
52-
Model uint `json:"model"`
53-
Stepping uint `json:"stepping"`
55+
Family uint16 `json:"family"`
56+
Model uint16 `json:"model"`
57+
Stepping uint32 `json:"stepping"`
5458

5559
Platform string `json:"platform,omitempty"`
5660

@@ -59,21 +63,21 @@ type DetailCPU struct {
5963
PowerManagement []string `json:"power_management,omitempty"`
6064

6165
Bogo float64 `json:"bogo"`
62-
Cache uint `json:"cache,omitempty"`
63-
Units uint `json:"units,omitempty"`
66+
Cache uint32 `json:"cache,omitempty"`
67+
Units uint32 `json:"units,omitempty"`
6468
Clock uint `json:"-"`
6569

6670
// x86 only fields
67-
PhysicalID uint `json:"physical_id"`
68-
Siblings uint `json:"siblings,omitempty"`
69-
Cores uint `json:"cores,omitempty"`
70-
CoreID uint `json:"-"`
71+
PhysicalID uint16 `json:"physical_id"`
72+
Siblings uint16 `json:"siblings,omitempty"`
73+
Cores uint16 `json:"cores,omitempty"`
74+
CoreID uint16 `json:"-"`
7175
Fpu bool `json:"fpu"`
7276
FpuException bool `json:"fpu_exception"`
73-
CpuidLevel uint `json:"cpuid_level,omitempty"`
77+
CpuidLevel uint8 `json:"cpuid_level,omitempty"`
7478
WriteProtect bool `json:"write_protect"`
75-
TlbSize uint `json:"tlb_size,omitempty"`
76-
ClflushSize uint `json:"clflush_size,omitempty"`
79+
TlbSize uint16 `json:"tlb_size,omitempty"`
80+
ClflushSize uint16 `json:"clflush_size,omitempty"`
7781
CacheAlignment int `json:"cache_alignment,omitempty"`
7882
AddressSizes AddressSizes `json:"address_sizes,omitempty"`
7983
Apicid uint `json:"-"`
@@ -97,9 +101,9 @@ func NewDetailCPU(cpu C.hd_detail_cpu_t) (*DetailCPU, error) {
97101
VendorName: C.GoString(data.vend_name),
98102
ModelName: stripCPUFreq(C.GoString(data.model_name)),
99103

100-
Family: uint(data.family),
101-
Model: uint(data.model),
102-
Stepping: uint(data.stepping),
104+
Family: uint16(data.family),
105+
Model: uint16(data.model),
106+
Stepping: uint32(data.stepping),
103107

104108
Platform: C.GoString(data.platform),
105109

@@ -109,25 +113,25 @@ func NewDetailCPU(cpu C.hd_detail_cpu_t) (*DetailCPU, error) {
109113

110114
Clock: uint(data.clock),
111115
Bogo: float64(data.bogo),
112-
Cache: uint(data.cache),
113-
Units: uint(data.units),
116+
Cache: uint32(data.cache),
117+
Units: uint32(data.units),
114118

115-
PhysicalID: uint(data.physical_id),
116-
Siblings: uint(data.siblings),
117-
Cores: uint(data.cores),
118-
CoreID: uint(data.core_id),
119+
PhysicalID: uint16(data.physical_id),
120+
Siblings: uint16(data.siblings),
121+
Cores: uint16(data.cores),
122+
CoreID: uint16(data.core_id),
119123
Apicid: uint(data.apicid),
120124
ApicidInitial: uint(data.apicid_initial),
121125
Fpu: bool(C.cpu_info_fpu(data)),
122126
FpuException: bool(C.cpu_info_fpu_exception(data)),
123-
CpuidLevel: uint(data.cpuid_level),
127+
CpuidLevel: uint8(data.cpuid_level),
124128
WriteProtect: bool(C.cpu_info_write_protect(data)),
125-
TlbSize: uint(data.tlb_size),
126-
ClflushSize: uint(data.clflush_size),
129+
TlbSize: uint16(data.tlb_size),
130+
ClflushSize: uint16(data.clflush_size),
127131
CacheAlignment: int(data.cache_alignment),
128132
AddressSizes: AddressSizes{
129-
Physical: uint(data.address_size_physical),
130-
Virtual: uint(data.address_size_virtual),
133+
Physical: fmt.Sprintf("0x%x", uint(data.address_size_physical)),
134+
Virtual: fmt.Sprintf("0x%x", uint(data.address_size_virtual)),
131135
},
132136
}, nil
133137
}

pkg/hwinfo/detail_isa_pnp_dev.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func NewIsaPnpCard(card *C.isapnp_card_t) (*IsaPnpCard, error) {
6464
type DetailIsaPnpDevice struct {
6565
Type DetailType `json:"-"`
6666
Card *IsaPnpCard `json:"card"`
67-
Device int `json:"device"`
68-
Flags uint `json:"flags"`
67+
Device uint32 `json:"device"`
68+
Flags uint32 `json:"flags"`
6969
}
7070

7171
func (d DetailIsaPnpDevice) DetailType() DetailType {
@@ -83,7 +83,7 @@ func NewDetailIsaPnpDevice(pnp C.hd_detail_isapnp_t) (*DetailIsaPnpDevice, error
8383
return &DetailIsaPnpDevice{
8484
Type: DetailTypeIsaPnp,
8585
Card: card,
86-
Device: int(data.dev),
87-
Flags: uint(data.flags),
86+
Device: uint32(data.dev),
87+
Flags: uint32(data.flags),
8888
}, nil
8989
}

pkg/hwinfo/detail_monitor.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ package hwinfo
77
import "C"
88

99
type SyncRange struct {
10-
Min uint `json:"min"`
11-
Max uint `json:"max"`
10+
Min uint16 `json:"min"`
11+
Max uint16 `json:"max"`
1212
}
1313

1414
type SyncTimings struct {
15-
Disp uint `json:"disp"` // todo what's the proper name for this?
16-
SyncStart uint `json:"sync_start"`
17-
SyncEnd uint `json:"sync_end"`
18-
Total uint `json:"total"` // todo what's a better name for this?
15+
Disp uint16 `json:"disp"` // todo what's the proper name for this?
16+
SyncStart uint16 `json:"sync_start"`
17+
SyncEnd uint16 `json:"sync_end"`
18+
Total uint32 `json:"total"` // todo what's a better name for this?
1919
}
2020

2121
type DetailMonitor struct {
2222
Type DetailType `json:"-"`
23-
ManufactureYear uint `json:"manufacture_year"`
24-
ManufactureWeek uint `json:"manufacture_week"`
23+
ManufactureYear uint16 `json:"manufacture_year"`
24+
ManufactureWeek uint8 `json:"manufacture_week"`
2525
VerticalSync SyncRange `json:"vertical_sync"`
2626
HorizontalSync SyncRange `json:"horizontal_sync"`
2727
HorizontalSyncTimings SyncTimings `json:"horizontal_sync_timings"`
2828
VerticalSyncTimings SyncTimings `json:"vertical_sync_timings"`
29-
Clock uint `json:"clock"`
30-
Width uint `json:"width"`
31-
Height uint `json:"height"`
32-
WidthMillimetres uint `json:"width_millimetres"`
33-
HeightMillimetres uint `json:"height_millimetres"`
29+
Clock uint32 `json:"clock"`
30+
Width uint32 `json:"width"`
31+
Height uint32 `json:"height"`
32+
WidthMillimetres uint32 `json:"width_millimetres"`
33+
HeightMillimetres uint32 `json:"height_millimetres"`
3434
HorizontalFlag byte `json:"horizontal_flag"`
3535
VerticalFlag byte `json:"vertical_flag"`
3636
Vendor string `json:"vendor"`
@@ -48,32 +48,32 @@ func NewDetailMonitor(mon C.hd_detail_monitor_t) (*DetailMonitor, error) {
4848

4949
return &DetailMonitor{
5050
Type: DetailTypeMonitor,
51-
ManufactureYear: uint(data.manu_year),
52-
ManufactureWeek: uint(data.manu_week),
51+
ManufactureYear: uint16(data.manu_year),
52+
ManufactureWeek: uint8(data.manu_week),
5353
VerticalSync: SyncRange{
54-
Min: uint(data.min_vsync),
55-
Max: uint(data.max_vsync),
54+
Min: uint16(data.min_vsync),
55+
Max: uint16(data.max_vsync),
5656
},
5757
HorizontalSync: SyncRange{
58-
Min: uint(data.min_hsync),
59-
Max: uint(data.max_hsync),
58+
Min: uint16(data.min_hsync),
59+
Max: uint16(data.max_hsync),
6060
},
61-
Clock: uint(data.clock),
62-
Width: uint(data.width),
63-
Height: uint(data.height),
64-
WidthMillimetres: uint(data.width_mm),
65-
HeightMillimetres: uint(data.height_mm),
61+
Clock: uint32(data.clock),
62+
Width: uint32(data.width),
63+
Height: uint32(data.height),
64+
WidthMillimetres: uint32(data.width_mm),
65+
HeightMillimetres: uint32(data.height_mm),
6666
HorizontalSyncTimings: SyncTimings{
67-
Disp: uint(data.hdisp),
68-
SyncStart: uint(data.hsyncstart),
69-
SyncEnd: uint(data.hsyncend),
70-
Total: uint(data.htotal),
67+
Disp: uint16(data.hdisp),
68+
SyncStart: uint16(data.hsyncstart),
69+
SyncEnd: uint16(data.hsyncend),
70+
Total: uint32(data.htotal),
7171
},
7272
VerticalSyncTimings: SyncTimings{
73-
Disp: uint(data.vdisp),
74-
SyncStart: uint(data.vsyncstart),
75-
SyncEnd: uint(data.vsyncend),
76-
Total: uint(data.vtotal),
73+
Disp: uint16(data.vdisp),
74+
SyncStart: uint16(data.vsyncstart),
75+
SyncEnd: uint16(data.vsyncend),
76+
Total: uint32(data.vtotal),
7777
},
7878
HorizontalFlag: byte(data.hflag),
7979
VerticalFlag: byte(data.vflag),

pkg/hwinfo/detail_pci.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ type DetailPci struct {
3939
Type DetailType `json:"-"`
4040

4141
Flags []PciFlag `json:"flags,omitempty"` //
42-
Function uint `json:"function"`
42+
Function uint32 `json:"function"`
4343

4444
// todo map pci constants from pci.h?
45-
Command uint `json:"command"` // PCI_COMMAND
46-
HeaderType uint `json:"header_type"` // PCI_HEADER_TYPE
47-
SecondaryBus uint `json:"secondary_bus"` // > 0 for PCI & CB bridges
45+
Command uint32 `json:"command"` // PCI_COMMAND
46+
HeaderType uint32 `json:"header_type"` // PCI_HEADER_TYPE
47+
SecondaryBus uint32 `json:"secondary_bus"` // > 0 for PCI & CB bridges
4848

49-
Irq uint `json:"irq"` // used irq if any
49+
Irq uint16 `json:"irq"` // used irq if any
5050
// Programming Interface Byte: a read-only register that specifies a register-level programming interface for the
5151
// device.
52-
ProgIf uint `json:"prog_if"`
52+
ProgIf uint16 `json:"prog_if"`
5353

5454
// already included in the parent model, so we omit from JSON output
5555
Bus uint `json:"-"`
@@ -97,21 +97,21 @@ func NewDetailPci(pci C.hd_detail_pci_t) (*DetailPci, error) {
9797
DataExtLength: uint(data.data_ext_len),
9898
Log: C.GoString(data.log),
9999
Flags: ParsePciFlags(uint(data.flags)),
100-
Command: uint(data.cmd),
101-
HeaderType: uint(data.hdr_type),
102-
SecondaryBus: uint(data.secondary_bus),
100+
Command: uint32(data.cmd),
101+
HeaderType: uint32(data.hdr_type),
102+
SecondaryBus: uint32(data.secondary_bus),
103103
Bus: uint(data.bus),
104104
Slot: uint(data.slot),
105-
Function: uint(data._func),
105+
Function: uint32(data._func),
106106
BaseClass: uint(data.base_class),
107107
SubClass: uint(data.sub_class),
108-
ProgIf: uint(data.prog_if),
108+
ProgIf: uint16(data.prog_if),
109109
Device: uint(data.dev),
110110
Vendor: uint(data.vend),
111111
SubDevice: uint(data.sub_dev),
112112
SubVendor: uint(data.sub_vend),
113113
Revision: uint(data.rev),
114-
Irq: uint(data.irq),
114+
Irq: uint16(data.irq),
115115
BaseAddress: [7]uint64(ReadUint64Array(unsafe.Pointer(&data.base_addr), 7)),
116116
BaseLength: [7]uint64(ReadUint64Array(unsafe.Pointer(&data.base_len), 7)),
117117
AddressFlags: [7]uint(ReadUintArray(unsafe.Pointer(&data.addr_flags), 7)),

0 commit comments

Comments
 (0)