fs: fix bugs that broke processes in userspace

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-21 05:50:22 -04:00
commit b603eacbb7
3 changed files with 6 additions and 7 deletions

View file

@ -84,25 +84,24 @@ static int sys_open(const char *path, int flags)
struct file *fd = proc->fdt + i;
if (!fd->dirent) {
memset(fd, 0, sizeof(struct file));
fd->dirent = f;
fd->flags = flags;
fd->refcount = 1;
fdno = i;
break;
}
}
if (fdno == -1) {
size_t osize = proc->fd_array_size;
size_t newsize = MIN(osize * 2, 32);
size_t newsize = MAX(osize * 2, 32);
void *new = krealloc(proc->fdt, newsize, ALLOC_KERN);
if (!new) {
vfs_close(f);
return -ENOMEM;
}
proc->fd_array_size = newsize;
proc->fdt = new;
memset(proc->fdt + osize, 0, osize);
memset(proc->fdt + osize, 0, newsize - osize);
struct file *fd = proc->fdt + osize;
fd->dirent = f;
fd->flags = flags;