summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst@digdash.com>2024-10-24 14:14:18 +0200
committerJulian Hurst <julian.hurst@digdash.com>2024-10-24 14:14:18 +0200
commit1bb0ea153abd99d470659b2ee018f341774238f9 (patch)
tree309002f4fa2747785289653fc7965ed87d5f7cdd
parent68b7830d5b20653d2335037814ee94e6f4fd495d (diff)
downloadstatusdaemon-1bb0ea153abd99d470659b2ee018f341774238f9.tar.gz
Forgot disk.ha
-rw-r--r--cmd/statusdaemon/disk.ha53
1 files changed, 53 insertions, 0 deletions
diff --git a/cmd/statusdaemon/disk.ha b/cmd/statusdaemon/disk.ha
new file mode 100644
index 0000000..19367a1
--- /dev/null
+++ b/cmd/statusdaemon/disk.ha
@@ -0,0 +1,53 @@
+use os;
+use io;
+use fs;
+use memio;
+use strings;
+use strconv;
+use log;
+use rt;
+
+type disk = struct {
+ section: section,
+ value: str,
+ mounts: []str,
+};
+
+fn builddisk(mounts: str...) disk = {
+ let d = disk {
+ section = section {
+ label = "disk: ",
+ },
+ mounts = strings::dupall(mounts),
+ ...
+ };
+ updatedisk(&d);
+ return d;
+};
+
+fn updatedisk(d: *disk) void = {
+ const stream = memio::dynamic();
+ defer io::close(&stream)!;
+ for (const mount .. d.mounts) {
+ memio::concat(&stream, mount, ": ")!;
+ let c = rt::st {
+ ...
+ };
+ rt::syscall(rt::SYS_statfs, &mount: uintptr: u64, &c: uintptr: u64);
+ log::println(c.blocks);
+ match (os::stat(mount)) {
+ case let st: fs::filestat =>
+ memio::concat(&stream, strconv::ztos(st.sz))!;
+ case let e: fs::error =>
+ log::printfln("{}: {}", mount, fs::strerror(e));
+ memio::concat(&stream, "No such mount: ")!;
+ };
+ };
+ free(d.value);
+ d.value = strings::dup(memio::string(&stream)!);
+};
+
+fn finishdisk(d: *disk) void = {
+ free(d.value);
+ strings::freeall(d.mounts);
+};