summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-12-14 15:35:40 +0100
committerAnton Kling <anton@kling.gg>2024-12-14 15:35:40 +0100
commit79d326a7eface8e79b76c6584c4beba935159a45 (patch)
tree74ecf6809082c03e72868195da03400b93c69089
parent0495bfb0d64bb2b318b629fd1c821dc8e2c8647d (diff)
procfs: Add `self` and `id`
-rw-r--r--kernel/fs/procfs.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/kernel/fs/procfs.c b/kernel/fs/procfs.c
index bfe3aac..dd995b4 100644
--- a/kernel/fs/procfs.c
+++ b/kernel/fs/procfs.c
@@ -36,12 +36,21 @@ int procfs_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
}
}
+ {
+ struct dirent entry;
+ entry.d_ino = current_task->pid;
+ ksnprintf(entry.d_name, sizeof(entry.d_name), "self");
+
+ (void)sb_append_buffer(&builder, (u8 *)&entry, sizeof(entry));
+ }
+
return sv_length(SB_TO_SV(builder));
}
#define PROCESS_ROOT 0
-#define PROCESS_SIGNAL 1
-#define PROCESS_NAME 2
+#define PROCESS_ID 1
+#define PROCESS_SIGNAL 2
+#define PROCESS_NAME 3
struct dirent process_entries[] = {
{
@@ -53,6 +62,10 @@ struct dirent process_entries[] = {
.d_name = ".",
},
{
+ .d_ino = PROCESS_ID,
+ .d_name = "id",
+ },
+ {
.d_ino = PROCESS_SIGNAL,
.d_name = "signal",
},
@@ -87,6 +100,13 @@ int process_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
sb_append_sv(&builder, program_name);
return sv_length(SB_TO_SV(builder));
}
+ if (PROCESS_ID == id) {
+ char buffer[256];
+ int rc = kbnprintf(buffer, sizeof(buffer), "%llu", p->pid);
+
+ sb_append_buffer(&builder, buffer, rc);
+ return sv_length(SB_TO_SV(builder));
+ }
return -EBADF;
}
@@ -151,7 +171,11 @@ vfs_inode_t *procfs_open(const char *p) {
int got_num;
u64 pid = sv_parse_unsigned_number(path, &path, &got_num);
if (!got_num) {
- return NULL;
+ struct sv file = sv_split_delim(path, &path, '/');
+ if (!sv_eq(file, C_TO_SV("self"))) {
+ return NULL;
+ }
+ pid = current_task->pid;
}
// NOTE: There should only be one '/' since the previous vfs_open will