From 97c5c3ffdf80b38508bf67bb4f86420f9dd76313 Mon Sep 17 00:00:00 2001 From: boreddevnl Date: Sat, 9 May 2026 23:53:50 +0200 Subject: [PATCH] feat: add datetime to procfs --- src/fs/procfs.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/fs/procfs.c b/src/fs/procfs.c index a45022f..5b621fb 100644 --- a/src/fs/procfs.c +++ b/src/fs/procfs.c @@ -200,6 +200,35 @@ int procfs_read(void *fs_private, void *handle, void *buf, int size) { k_strcpy(out + k_strlen(out), "\n"); } } + } else if (k_strcmp(h->type, "datetime") == 0) { + extern void rtc_get_datetime(int *year, int *month, int *day, int *hour, int *minute, int *second); + int y, m, d, h_val, min, s; + rtc_get_datetime(&y, &m, &d, &h_val, &min, &s); + + char buf[16]; + k_itoa(y, buf); + k_strcpy(out, buf); + k_strcpy(out + k_strlen(out), "-"); + if (m < 10) k_strcpy(out + k_strlen(out), "0"); + k_itoa(m, buf); + k_strcpy(out + k_strlen(out), buf); + k_strcpy(out + k_strlen(out), "-"); + if (d < 10) k_strcpy(out + k_strlen(out), "0"); + k_itoa(d, buf); + k_strcpy(out + k_strlen(out), buf); + k_strcpy(out + k_strlen(out), " "); + if (h_val < 10) k_strcpy(out + k_strlen(out), "0"); + k_itoa(h_val, buf); + k_strcpy(out + k_strlen(out), buf); + k_strcpy(out + k_strlen(out), ":"); + if (min < 10) k_strcpy(out + k_strlen(out), "0"); + k_itoa(min, buf); + k_strcpy(out + k_strlen(out), buf); + k_strcpy(out + k_strlen(out), ":"); + if (s < 10) k_strcpy(out + k_strlen(out), "0"); + k_itoa(s, buf); + k_strcpy(out + k_strlen(out), buf); + k_strcpy(out + k_strlen(out), "\n"); } else if (k_strcmp(h->type, "meminfo") == 0) { extern MemStats memory_get_stats(void); MemStats stats = memory_get_stats(); @@ -370,6 +399,8 @@ int procfs_readdir(void *fs_private, const char *path, vfs_dirent_t *entries, in entries[out-1].is_directory = 0; k_strcpy(entries[out++].name, "meminfo"); entries[out-1].is_directory = 0; + k_strcpy(entries[out++].name, "datetime"); + entries[out-1].is_directory = 0; k_strcpy(entries[out++].name, "devices"); entries[out-1].is_directory = 0; @@ -417,7 +448,7 @@ bool procfs_exists(void *fs_private, const char *path) { if (k_strcmp(path, "version") == 0 || k_strcmp(path, "uptime") == 0) return true; if (k_strcmp(path, "cpuinfo") == 0 || k_strcmp(path, "meminfo") == 0) return true; - if (k_strcmp(path, "devices") == 0) return true; + if (k_strcmp(path, "datetime") == 0 || k_strcmp(path, "devices") == 0) return true; return false; }