vfs: remove kernel file descriptor numbers
This commit is contained in:
parent
18bcf40094
commit
f8b801236a
6 changed files with 119 additions and 87 deletions
20
sched/load.c
20
sched/load.c
|
|
@ -38,20 +38,24 @@ int elf_check_compat(char *buf)
|
|||
|
||||
pid_t elf_load_proc(char *fname)
|
||||
{
|
||||
int fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
struct file_descriptor *fdesc = open(fname, 0);
|
||||
|
||||
seek(fd, 0, SEEK_END);
|
||||
size_t size = tell(fd);
|
||||
seek(fd, 0, SEEK_SET);
|
||||
if (!fdesc)
|
||||
return -ENOENT;
|
||||
|
||||
if (fdesc->fd < 0)
|
||||
return fdesc->fd;
|
||||
|
||||
seek(fdesc, 0, SEEK_END);
|
||||
size_t size = tell(fdesc);
|
||||
seek(fdesc, 0, SEEK_SET);
|
||||
|
||||
char *buf = kmalloc(size, ALLOC_KERN);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
read(fd, buf, size);
|
||||
close(fd);
|
||||
read(fdesc, buf, size);
|
||||
close(fdesc);
|
||||
|
||||
int ret;
|
||||
|
||||
|
|
|
|||
26
sched/proc.c
26
sched/proc.c
|
|
@ -3,8 +3,11 @@
|
|||
#include <kernel/proc.h>
|
||||
#include <kernel/rbtree.h>
|
||||
#include <kernel/slab.h>
|
||||
|
||||
#include <dev/apic.h>
|
||||
|
||||
#include <fs/vfs.h>
|
||||
|
||||
static struct rbtree *proc_tree;
|
||||
static pid_t *proc_current;
|
||||
|
||||
|
|
@ -81,6 +84,24 @@ void schedule()
|
|||
}
|
||||
}
|
||||
|
||||
static int proc_insert_charfd(struct proc *proc, int fdno, int flags)
|
||||
{
|
||||
struct file_descriptor *fd = fd_special();
|
||||
fd->vnode = (struct vnode){ 0 };
|
||||
fd->pos = 0;
|
||||
fd->fd = fdno;
|
||||
fd->flags = flags;
|
||||
fd->mode = FD_TYPE_CHARDEV;
|
||||
fd->buf = NULL;
|
||||
fd->buf_size = 0;
|
||||
fd->fs = NULL;
|
||||
|
||||
struct rbnode *fd_node = rbt_insert(&proc->fd_map, fdno);
|
||||
fd_node->value = (uintptr_t)fd;
|
||||
|
||||
return fdno;
|
||||
}
|
||||
|
||||
struct proc *proc_create()
|
||||
{
|
||||
struct proc *proc = kzalloc(sizeof(struct proc), ALLOC_KERN);
|
||||
|
|
@ -91,6 +112,11 @@ struct proc *proc_create()
|
|||
struct rbnode *proc_node = rbt_insert(proc_tree, proc->pid);
|
||||
proc_node->value = (uintptr_t)proc;
|
||||
|
||||
/* insert stdin, stdout, stderr */
|
||||
proc_insert_charfd(proc, 0, O_RDONLY); /* stdin */
|
||||
proc_insert_charfd(proc, 1, O_WRONLY); /* stdout */
|
||||
proc_insert_charfd(proc, 2, O_WRONLY); /* stderr */
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue