refactor(linux-hardware): use new Io

This commit is contained in:
utox39
2026-02-12 17:59:53 +01:00
parent a62eece487
commit 20d33b165e

View File

@@ -46,7 +46,7 @@ pub fn getCpuInfo(allocator: std.mem.Allocator, io: std.Io) !CpuInfo {
// Reads /proc/cpuinfo // Reads /proc/cpuinfo
const cpuinfo_path = "/proc/cpuinfo"; const cpuinfo_path = "/proc/cpuinfo";
const cpuinfo_file = try std.Io.Dir.cwd().openFile(io, cpuinfo_path, .{ .mode = .read_only }); const cpuinfo_file = try std.Io.Dir.cwd().openFile(io, cpuinfo_path, .{ .mode = .read_only });
defer cpuinfo_file.close(); defer cpuinfo_file.close(io);
// NOTE: procfs is a pseudo-filesystem, so it is not possible to determine the size of a file // NOTE: procfs is a pseudo-filesystem, so it is not possible to determine the size of a file
// https://docs.kernel.org/filesystems/proc.html // https://docs.kernel.org/filesystems/proc.html
@@ -54,7 +54,7 @@ pub fn getCpuInfo(allocator: std.mem.Allocator, io: std.Io) !CpuInfo {
// //
// Only the first section (core 0) will be parsed // Only the first section (core 0) will be parsed
// 512 is more than enough // 512 is more than enough
const cpuinfo_data = try utils.readFile(allocator, cpuinfo_file, 512); const cpuinfo_data = try utils.readFile(allocator, io, cpuinfo_file, 512);
defer allocator.free(cpuinfo_data); defer allocator.free(cpuinfo_data);
// Parsing /proc/cpuinfo // Parsing /proc/cpuinfo
@@ -90,8 +90,8 @@ pub fn getCpuInfo(allocator: std.mem.Allocator, io: std.Io) !CpuInfo {
var cmf_exists: bool = true; var cmf_exists: bool = true;
// Checks if /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq exists // Checks if /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq exists
_ = std.fs.accessAbsolute(cpuinfo_max_freq_path, .{ .mode = .read_only }) catch |err| { _ = std.Io.Dir.accessAbsolute(io, cpuinfo_max_freq_path, .{ .read = true }) catch |err| {
if (err == std.posix.AccessError.FileNotFound) { if (err == std.Io.Dir.AccessError.FileNotFound) {
cmf_exists = false; cmf_exists = false;
} }
}; };
@@ -99,8 +99,8 @@ pub fn getCpuInfo(allocator: std.mem.Allocator, io: std.Io) !CpuInfo {
if (cmf_exists) { if (cmf_exists) {
// Reads /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq // Reads /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
const maxfreq_file = try std.Io.Dir.cwd().openFile(io, cpuinfo_max_freq_path, .{ .mode = .read_only }); const maxfreq_file = try std.Io.Dir.cwd().openFile(io, cpuinfo_max_freq_path, .{ .mode = .read_only });
defer maxfreq_file.close(); defer maxfreq_file.close(io);
const maxfreq_data = try utils.readFile(allocator, maxfreq_file, 32); const maxfreq_data = try utils.readFile(allocator, io, maxfreq_file, 32);
defer allocator.free(maxfreq_data); defer allocator.free(maxfreq_data);
// Parsing /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq // Parsing /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq