generated from general-packages/pika-pkg-template
Update pikafetch version and improve disk information retrieval
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 51s
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 51s
- Incremented version number in changelog from 0.1.0-101pika7 to 0.1.0-101pika8. - Modified disk information retrieval to use `statfs` instead of `statvfs`, enhancing compatibility. - Removed unused filesystem type retrieval logic to streamline disk info processing. - Adjusted formatting in system info output for disk usage display.
This commit is contained in:
parent
9db38b0c4d
commit
5e51b5debd
2
.github/release-nest-v3
vendored
2
.github/release-nest-v3
vendored
@ -1 +1 @@
|
|||||||
2
|
1
|
@ -1,4 +1,4 @@
|
|||||||
pikafetch (0.1.0-101pika7) pika; urgency=medium
|
pikafetch (0.1.0-101pika8) pika; urgency=medium
|
||||||
|
|
||||||
* Initial release.
|
* Initial release.
|
||||||
|
|
||||||
|
@ -1,55 +1,27 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const os = std.os;
|
const os = std.os;
|
||||||
const c = @cImport({
|
const c = @cImport({
|
||||||
@cInclude("sys/statvfs.h");
|
@cInclude("sys/statfs.h");
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const DiskInfo = struct {
|
pub const DiskInfo = struct {
|
||||||
total: u64,
|
total: u64,
|
||||||
used: u64,
|
used: u64,
|
||||||
fs_type: []const u8,
|
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
|
||||||
pub fn deinit(self: *const DiskInfo) void {
|
|
||||||
self.allocator.free(self.fs_type);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn getDiskInfo(allocator: std.mem.Allocator, mount_point: []const u8) !DiskInfo {
|
pub fn getDiskInfo(allocator: std.mem.Allocator, mount_point: []const u8) !DiskInfo {
|
||||||
var stats: c.struct_statvfs = undefined;
|
var stats: c.struct_statfs = undefined;
|
||||||
const rc = c.statvfs(mount_point.ptr, &stats);
|
const rc = c.statfs(mount_point.ptr, &stats);
|
||||||
if (rc != 0) return error.StatFailed;
|
if (rc != 0) return error.StatFailed;
|
||||||
|
|
||||||
const total = stats.f_blocks * stats.f_frsize;
|
const total = @as(u64, @intCast(stats.f_blocks)) * @as(u64, @intCast(stats.f_bsize));
|
||||||
const free = stats.f_bfree * stats.f_frsize;
|
const free = @as(u64, @intCast(stats.f_bfree)) * @as(u64, @intCast(stats.f_bsize));
|
||||||
const used = total - free;
|
const used = total - free;
|
||||||
|
|
||||||
// Get filesystem type
|
|
||||||
const mtab = try std.fs.openFileAbsolute("/proc/mounts", .{});
|
|
||||||
defer mtab.close();
|
|
||||||
|
|
||||||
var buffer: [4096]u8 = undefined;
|
|
||||||
const bytes = try mtab.readAll(&buffer);
|
|
||||||
const content = buffer[0..bytes];
|
|
||||||
|
|
||||||
var fs_type: []const u8 = "unknown";
|
|
||||||
var lines = std.mem.split(u8, content, "\n");
|
|
||||||
while (lines.next()) |line| {
|
|
||||||
var fields = std.mem.split(u8, line, " ");
|
|
||||||
_ = fields.next() orelse continue; // device
|
|
||||||
const mount = fields.next() orelse continue;
|
|
||||||
const fs = fields.next() orelse continue;
|
|
||||||
|
|
||||||
if (std.mem.eql(u8, mount, "/")) {
|
|
||||||
fs_type = try allocator.dupe(u8, fs);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return DiskInfo{
|
return DiskInfo{
|
||||||
.total = total,
|
.total = total,
|
||||||
.used = used,
|
.used = used,
|
||||||
.fs_type = fs_type,
|
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,6 @@ pub const SystemInfo = struct {
|
|||||||
cpu_info = try cpu.getCPUInfo(allocator);
|
cpu_info = try cpu.getCPUInfo(allocator);
|
||||||
const swap_info = try memory.getSwapInfo();
|
const swap_info = try memory.getSwapInfo();
|
||||||
const disk_info = try disk.getDiskInfo(allocator, "/");
|
const disk_info = try disk.getDiskInfo(allocator, "/");
|
||||||
defer disk_info.deinit();
|
|
||||||
|
|
||||||
return SystemInfo{
|
return SystemInfo{
|
||||||
.username = username.?,
|
.username = username.?,
|
||||||
@ -192,7 +191,7 @@ pub const SystemInfo = struct {
|
|||||||
calculations.usage_colors[1], calculations.swap_percentage,
|
calculations.usage_colors[1], calculations.swap_percentage,
|
||||||
colors.Color.reset,
|
colors.Color.reset,
|
||||||
}),
|
}),
|
||||||
try std.fmt.allocPrint(self.allocator, "{s}Disk (/):{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s}) - xfs", .{
|
try std.fmt.allocPrint(self.allocator, "{s}Disk (/):{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s})", .{
|
||||||
colors.Color.bold, colors.Color.reset,
|
colors.Color.bold, colors.Color.reset,
|
||||||
calculations.disk_fmt.value, calculations.disk_fmt.unit,
|
calculations.disk_fmt.value, calculations.disk_fmt.unit,
|
||||||
calculations.disk_total_fmt.value, calculations.disk_total_fmt.unit,
|
calculations.disk_total_fmt.value, calculations.disk_total_fmt.unit,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user