Repository navigation
Category Hardware
Home › All Categories › Hardware
The std/hardware module says what computer a program is running on: who made it and which model it is, its serial number and UUID, its firmware, its processor and its disks. The same calls work on Windows, Linux and macOS, each reading its own system's sources, and none of them needs administrator or root rights except where a system keeps a value back (see Rights).
#import "std/hardware"
using hardware
var machine = GetSystem( )
if machine.IsOk( ) then print "machine: "; machine.Value( ).Manufacturer; " "; machine.Value( ).Model
var fw = GetFirmware( )
if fw.IsOk( ) then print "firmware: "; fw.Value( ).Vendor; " "; fw.Value( ).Version
var cpu = GetCpu( )
if cpu.IsOk( ) then print "cpu: "; cpu.Value( ).Name; ", "; str( cpu.Value( ).Cores ); " cores, "; str( cpu.Value( ).Threads ); " threads"
var disks = GetDisks( )
if disks.IsOk( ) then
for each d as DiskInfo in disks.Value( )
print "disk: "; d.Id; " "; d.Model; ", "; str( d.SizeBytes \ 1000000000 ); " GB, "; DiskBusName( d.Bus )
next
end ifOn a Windows desktop it prints:
machine: ASUS System Product Name
firmware: American Megatrends Inc. 2214
cpu: AMD Ryzen 9 7950X3D 16-Core Processor, 16 cores, 32 threads
disk: PhysicalDrive0 P3-2TB, 2048 GB, SATA
disk: PhysicalDrive1 WD_BLACK SN850X 2000GB, 2000 GB, NVMe
disk: PhysicalDrive2 Samsung SSD 990 PRO 2TB, 2000 GB, NVMe
disk: PhysicalDrive3 Samsung SSD 970 EVO Plus 1TB, 1000 GB, NVMe
and on a MacBook Air:
machine: Apple Inc. MacBookAir10,1
firmware: Apple Inc. 20457.41.3
cpu: Apple M1, 8 cores, 8 threads
disk: disk0 APPLE SSD AP0256Q, 251 GB, internal
"System Product Name" is a placeholder the board's maker left in the firmware. The module returns what the system says, placeholders included.
Every call returns a Result: check IsOk( ) before Value( ). A call fails when the system has no such source at all, as the firmware calls do in WSL2 and the raw table does on a Mac (see Errors).
These are identifiers. A serial number and a UUID name one machine, and so its owner. Do not log them or send them anywhere without saying so.
#import "std/hardware"
using hardwareWithout using, write the module name first: hardware.GetCpu( ).
GetSystem( ) returns a SystemInfo:
| Field | Holds |
|---|---|
Manufacturer |
"ASUS", "Apple Inc."
|
Model |
"System Product Name", "MacBookAir10,1"
|
Family |
the product line where the firmware gives one; on a Mac the model's name, "MacBook Air (M1, 2020)"
|
SerialNumber |
the system's serial number |
Uuid |
the system UUID, upper case, in the order Windows, Linux and macOS print it: "78563412-BC9A-F0DE-0123-456789ABCDEF"
|
BoardManufacturer, BoardModel
|
the motherboard; empty on a Mac and in many virtual machines |
Restricted |
TRUE when the system kept a field above from this user |
A field the system does not fill in is empty, and so is a UUID the firmware left as all zeros or all ones.
#import "std/hardware"
using hardware
var r = GetSystem( )
if r.IsOk( ) = FALSE then
print r.Failure( ).Message( )
else
dim as SystemInfo s = r.Value( )
print s.Manufacturer; " | "; s.Model; " | "; s.Family
print "board: "; s.BoardManufacturer; " "; s.BoardModel
if s.Restricted then print "the serial number and UUID need root"
if len( s.Uuid ) > 0 then print "this machine has a UUID"
end ifOn the Windows desktop it prints:
ASUS | System Product Name | To be filled by O.E.M.
board: ASUSTeK COMPUTER INC. ROG STRIX B650-A GAMING WIFI
this machine has a UUID
In a Linux virtual machine, run as an ordinary user, it prints:
Apple Inc. | Apple Virtualization Generic Platform |
board:
the serial number and UUID need root
GetFirmware( ) returns a FirmwareInfo: Vendor, Version and ReleaseDate. The date is ISO 8601, "2024-01-02", and empty when the system gives none, as on a Mac.
#import "std/hardware"
using hardware
var r = GetFirmware( )
if r.IsOk( ) then
dim as FirmwareInfo f = r.Value( )
print f.Vendor; ", version "; f.Version
if len( f.ReleaseDate ) > 0 then print "released "; f.ReleaseDate else print "no release date"
else
print r.Failure( ).Message( )
end ifIt prints American Megatrends Inc., version 2214 and released 2024-01-02 on the Windows desktop, and Apple Inc., version 20457.41.3 and no release date on the Mac. In WSL2, which has no firmware tables, it prints GetFirmware '/sys/class/dmi/id/': not available on this platform.
GetCpu( ) returns a CpuInfo:
| Field | Holds |
|---|---|
Name |
"AMD Ryzen 9 7950X3D 16-Core Processor", "Apple M1"; empty where the system gives none |
Vendor |
"Advanced Micro Devices, Inc.", "AMD", "Apple"; may be empty |
Cores |
physical cores, every socket counted |
Threads |
logical processors |
PerformanceCores, EfficiencyCores
|
on a hybrid CPU the two kinds of core; both 0 otherwise |
MaxMhz |
the highest clock speed; 0 where the system does not say, as on Apple Silicon |
Threads counts the whole machine. os.CpuCount( ) counts the processors this program may run on, which can be fewer.
#import "std/hardware"
using hardware
var r = GetCpu( )
if r.IsOk( ) then
dim as CpuInfo c = r.Value( )
if len( c.Name ) > 0 then print c.Name else print "(the system gives no name)"
if len( c.Vendor ) > 0 then print "made by "; c.Vendor
print str( c.Cores ); " cores, "; str( c.Threads ); " threads"
if c.PerformanceCores > 0 then print str( c.PerformanceCores ); " performance and "; str( c.EfficiencyCores ); " efficiency cores"
if c.MaxMhz > 0 then print "up to "; str( c.MaxMhz ); " MHz"
end ifOn the Mac it prints:
Apple M1
made by Apple
8 cores, 8 threads
4 performance and 4 efficiency cores
The Windows desktop prints the AMD name, made by Advanced Micro Devices, Inc., 16 cores, 32 threads and up to 5750 MHz. Linux on an ARM processor gives no processor name to an ordinary user, so there the first line is (the system gives no name).
GetDisks( ) returns an Array( of DiskInfo ), one for each physical disk, in order of name. It leaves out what is not a disk of its own: partitions and volumes, loop and RAM devices, CD and DVD drives, mounted disk images and VHDs, and the containers macOS makes for APFS.
| Field | Holds |
|---|---|
Id |
"PhysicalDrive0", "nvme0n1", "disk0"
|
DevicePath |
"\\.\PhysicalDrive0", "/dev/nvme0n1", "/dev/disk0"
|
Model |
"Samsung SSD 990 PRO 2TB"; may be empty, as for a virtual machine's disk |
SerialNumber |
as the drive reports it, punctuation included; may be empty |
Revision |
the drive's firmware revision; may be empty |
SizeBytes |
the size in bytes |
LogicalSectorBytes |
the sector size the system addresses, 512 or 4096 |
PhysicalSectorBytes |
the sector size the drive writes, often 4096 behind a 512 logical size |
Bus |
a DiskBus, below |
Removable |
whether the medium can be taken out, as in a card reader |
SolidState |
1 for a solid-state drive, 0 for a spinning one, -1 when the system cannot tell (a virtual machine's disk) |
DiskBus |
DiskBusName( ) |
The disk is on |
|---|---|---|
DISK_BUS_SATA |
"SATA" |
SATA, ATA or ATAPI |
DISK_BUS_NVME |
"NVMe" |
NVMe |
DISK_BUS_USB |
"USB" |
USB |
DISK_BUS_SCSI |
"SCSI" |
SCSI, SAS, Fibre Channel or iSCSI |
DISK_BUS_SD |
"SD" |
an SD or MMC card |
DISK_BUS_VIRTUAL |
"virtual" |
a virtual machine's disk, or Windows Storage Spaces |
DISK_BUS_INTERNAL |
"internal" |
a Mac's internal storage |
DISK_BUS_UNKNOWN |
"unknown" |
anything else |
DiskOf( path ) returns the DiskInfo of the disk a file or folder is on, following a volume down to the disk under it: through its partition, and on a Mac through its APFS container. A path on no disk fails with HW_NOT_FOUND, such as a file under /proc on Linux or /dev on a Mac.
#import "std/hardware"
using hardware
var r = GetDisks( )
if r.IsOk( ) then
for each d as DiskInfo in r.Value( )
print d.DevicePath; ": ";
if len( d.Model ) > 0 then print d.Model else print "(no model)"
print " "; str( d.SizeBytes \ ( 1024 * 1024 * 1024 ) ); " GiB, "; str( d.LogicalSectorBytes ); "/"; _
str( d.PhysicalSectorBytes ); " bytes a sector, "; DiskBusName( d.Bus ); _
iif( d.Removable, ", removable", "" ); _
iif( d.SolidState = 1, ", solid state", iif( d.SolidState = 0, ", spinning", "" ) )
next
end if
var here = DiskOf( command( 0 ) )
if here.IsOk( ) then print "this program is on "; here.Value( ).Id else print here.Failure( ).Message( )On the Windows desktop it starts:
\\.\PhysicalDrive0: P3-2TB
1907 GiB, 512/512 bytes a sector, SATA, solid state
\\.\PhysicalDrive1: WD_BLACK SN850X 2000GB
1863 GiB, 512/4096 bytes a sector, NVMe, solid state
and ends this program is on PhysicalDrive1. On the Mac it prints:
/dev/disk0: APPLE SSD AP0256Q
233 GiB, 4096/4096 bytes a sector, internal, solid state
this program is on disk0
The program's own folder there is on an APFS volume, disk3s5; DiskOf follows it through its container to disk0. In WSL2 the disks are /dev/sda to /dev/sdc, each a Msft Virtual Disk on the virtual bus.
A PC's firmware describes its hardware in SMBIOS tables: structures for the firmware, the system, the board, every processor and memory module, with names, serial numbers and settings. GetSystem and GetFirmware decode the fields above from them. A program that wants more takes the table itself:
| Call | Does |
|---|---|
GetSmbios( ) |
returns an SmbiosData: MajorVersion, MinorVersion and Table, an Array( of ubyte ) of the structures |
SystemFromSmbios( s ) |
decodes a SystemInfo from an SmbiosData
|
FirmwareFromSmbios( s ) |
decodes a FirmwareInfo from an SmbiosData
|
#import "std/hardware"
using hardware
var t = GetSmbios( )
if t.IsOk( ) then
print "SMBIOS "; str( t.Value( ).MajorVersion ); "."; str( t.Value( ).MinorVersion ); ", "; str( t.Value( ).Table.Count( ) ); " bytes"
print "model: "; SystemFromSmbios( t.Value( ) ).Model
print "firmware: "; FirmwareFromSmbios( t.Value( ) ).Version
else
print t.Failure( ).Message( )
end ifOn the Windows desktop it prints SMBIOS 3.5, 3449 bytes, model: System Product Name and firmware: 2214. Only Windows gives the table to everyone:
-
Linux gives it to root alone. An ordinary user gets
GetSmbios '/sys/firmware/dmi/tables/DMI': access denied (os error 13). -
macOS on Apple Silicon has no SMBIOS:
GetSmbios: not available on this platform.
The layout of every structure is in the SMBIOS specification. CBiosTable, in sys/win/dmi, reads any field of it on Windows, with a table of the common offsets.
Nothing here needs administrator or root rights, with these exceptions on Linux, where the system keeps some values for root:
| Value | As an ordinary user on Linux |
|---|---|
SystemInfo.SerialNumber, SystemInfo.Uuid
|
empty, and Restricted is TRUE
|
GetSmbios( ) |
fails with HW_ACCESS_DENIED
|
CpuInfo.Name on an ARM processor |
empty: as root it comes from the SMBIOS table, when the firmware fills it in |
Windows and macOS give everything to every user.
| Windows | Linux | macOS | |
|---|---|---|---|
| System, firmware | the SMBIOS table | the kernel's copy of it, /sys/class/dmi/id
|
the IOKit registry |
| CPU | the processor topology, and SMBIOS for the name and speed |
/proc/cpuinfo and /sys/devices/system/cpu
|
sysctl |
| Disks | the storage driver of each \\.\PhysicalDriveN
|
/sys/block |
the IOKit registry |
| Raw SMBIOS | GetSystemFirmwareTable |
/sys/firmware/dmi/tables |
— |
WSL2 has no firmware tables at all, so GetSystem, GetFirmware and GetSmbios fail there with HW_UNSUPPORTED; GetCpu, GetDisks and DiskOf work. Android is not supported: every call fails with HW_UNSUPPORTED.
Every call reads the system again: nothing is kept between calls.
A failure is an HwError: Code( ), OsCode( ) (the system's own error number, or 0), Operation( ), Subject( ) (the file or source it was about) and Message( ), such as GetSmbios '/sys/firmware/dmi/tables/DMI': access denied (os error 13). HwErrorMessage( code ) gives the text of a code alone.
HwErrorCode |
Means |
|---|---|
HW_UNSUPPORTED |
the system has no such source: the raw table on a Mac, firmware tables in WSL2, anything on Android |
HW_ACCESS_DENIED |
the system keeps it from this user: the raw table on Linux |
HW_NOT_FOUND |
nothing to report: DiskOf on a path on no local disk |
HW_SYSTEM |
a system call failed; OsCode( ) says why |
-
OS — the operating system's version, the host name,
CpuCount( )andTotalMemory( ) - sys/win/dmi — Windows only: any SMBIOS field through CBiosTable, and disk geometry
- Filesystem Library — free space and volume information
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Android (experimental)
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Move Semantics
- Match
- Lambdas
- Block Strings
- String Interpolation
- Partial Types
- String Slices
- Array Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Hardware
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- tiko test
- tiko doc
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing