starting to work on pty drivers, fork(), and scheduler redesign

This commit is contained in:
2026-07-07 00:13:24 -05:00
parent 6d7a23d747
commit 177a0b8fe9
29 changed files with 859 additions and 111 deletions

View File

@@ -1,9 +1,8 @@
#include "vfs.h"
#include <vfs.h>
#include <process.h>
#include <scheduler.h>
#include "lib/memory.h"
#define MAX_PROCESS_FDS 32
file_t fd_table[MAX_PROCESS_FDS];
#include <lib/memory.h>
vfs_node_t* root = NULL;
@@ -46,23 +45,22 @@ static vfs_node_t* lookup(const char* path) {
int open(const char* _path, int flags) {
vfs_node_t* file = lookup(_path);
if (!file) return -1;
for (int i = 0; i < MAX_PROCESS_FDS; i++) {
if (fd_table[i].node == NULL) {
fd_table[i].node = file;
fd_table[i].offset = 0;
fd_table[i].flags = flags;
return i;
}
}
return -1;
file_t* f = (file_t*)kalloc(sizeof(file_t));
f->node = file;
f->offset = 0;
f->flags = flags;
return alloc_fd(f);
}
int read(int fd, void* buf, size_t sz) {
if (fd < 0 || fd >= MAX_PROCESS_FDS || !fd_table[fd].node) {
process_t* curr_p = current_task();
if (fd < 0 || fd >= MAX_PROCESS_FDS || !curr_p->fd_table[fd]->node) {
return -1;
}
file_t* file = &fd_table[fd];
file_t* file = curr_p->fd_table[fd];
if (!file->node->read) return -1;
@@ -73,21 +71,37 @@ int read(int fd, void* buf, size_t sz) {
}
int fstat(int fd, file_t* dst) {
if (fd < 0 || fd >= MAX_PROCESS_FDS || !fd_table[fd].node) {
process_t* curr_p = current_task();
if (fd < 0 || fd >= MAX_PROCESS_FDS || !curr_p->fd_table[fd]->node) {
return 0;
}
file_t* src = &fd_table[fd];
file_t* src = curr_p->fd_table[fd];
memcpy(src, dst, sizeof(file_t));
return 1;
}
int fseek(int fd, size_t offset) {
if (fd < 0 || fd >= MAX_PROCESS_FDS || !fd_table[fd].node) {
process_t* curr_p = current_task();
if (fd < 0 || fd >= MAX_PROCESS_FDS || !curr_p->fd_table[fd]->node) {
return 0;
}
file_t* file = &fd_table[fd];
file_t* file = curr_p->fd_table[fd];
file->offset = offset;
return 1;
}
}
int alloc_fd(file_t* f) {
process_t* curr_p = current_task();
if (!curr_p) return -1;
for (int i = 0; i < MAX_PROCESS_FDS; i++) {
if (curr_p->fd_table[i] == NULL) {
curr_p->fd_table[i] = f;
return i;
}
}
return -1;
}