From 3619c820f8ff5918cf122a031bde6305d32f6528 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 10 Jan 2021 13:19:50 +0100 Subject: Started procfs --- kernel/features/fs.c | 8 +++----- kernel/features/proc.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) (limited to 'kernel/features') diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 14e6a9c..ab2e236 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -185,14 +185,12 @@ void device_install(void) { devices = list_new(); - struct vfs *vfs; - struct device *dev; - - vfs = malloc(sizeof(*vfs)); + struct vfs *vfs = malloc(sizeof(*vfs)); vfs->type = VFS_DEVFS; vfs->read = devfs_read; - dev = malloc(sizeof(*dev)); + struct device *dev = malloc(sizeof(*dev)); dev->name = "dev"; + dev->type = DEV_CHAR; dev->vfs = vfs; device_add(dev); vfs_mount(dev, "/dev/"); diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 93e97f1..499be81 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,7 @@ struct proc *proc_make(void) { struct proc *proc = malloc(sizeof(*proc)); proc->pid = current_pid++; + proc->messages = list_new(); proc->state = PROC_RUNNING; if (current) @@ -137,6 +139,31 @@ struct proc *proc_make(void) return proc; } +u32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struct device *dev) +{ + while (*path == '/') + path++; + + int pid = 0; + while (path[0] >= '0' && path[0] <= '9') { + pid = pid * 10 + (path[0] - '0'); + path++; + } + + if (pid) { + struct proc *p = proc_from_pid(pid); + if (!p) + return 0; + + if (!memcmp(path, "/status", 8)) { + printf("STATUS!\n"); + } + } + + printf("%s - off: %d, cnt: %d, buf: %x, dev %x\n", path, offset, count, buf, dev); + return count; +} + extern void proc_jump_userspace(void); u32 _esp, _eip; @@ -149,6 +176,17 @@ void proc_init(void) scheduler_enable(); proc_list = list_new(); + // Procfs + struct vfs *vfs = malloc(sizeof(*vfs)); + vfs->type = VFS_PROCFS; + vfs->read = procfs_read; + struct device *dev = malloc(sizeof(*dev)); + dev->name = "proc"; + dev->type = DEV_CHAR; + dev->vfs = vfs; + device_add(dev); + vfs_mount(dev, "/proc/"); + kernel_proc = proc_make(); struct node *new = list_add(proc_list, proc_make()); -- cgit v1.2.3