#include <debug.h>
#include <process.h>
#include "sched.h"
+#include "fd.h"
struct process {
struct pagedir *p_pgdir;
struct task *p_tasks;
u32_t p_privl;
+
+ struct fd p_fds[16];
};
extern int sched_enqueue(task_t*);
proc->p_tasks->t_kstack = kstack;
proc->p_tasks->t_tslice = 50;
proc->p_tasks->t_rslice = 50;
+ proc->p_tasks->t_proc = proc;
if(sched_enqueue(proc->p_tasks) != 0) {
PANIC("sched_enqueue() failed for a new task\n");
return(ret_val);
}
+
+int process_falloc(process_t *proc, int sock)
+{
+ int ret_val;
+ int i;
+
+ ret_val = -EMFILE;
+
+ for(i = 0; i < (sizeof(proc->p_fds) / sizeof(proc->p_fds[0])); i++) {
+ if(!(proc->p_fds[i].fd_flags & FD_VALID)) {
+ ret_val = i;
+ proc->p_fds[i].fd_socknum = sock;
+ proc->p_fds[i].fd_flags |= FD_VALID;
+ break;
+ }
+ }
+
+ return(ret_val);
+}
+
+int process_ffree(process_t *proc, int fd)
+{
+ int ret_val;
+
+ ret_val = -EINVAL;
+
+ if(fd >= 0 && fd < (sizeof(proc->p_fds) / sizeof(proc->p_fds[0]))) {
+ ret_val = -EBADF;
+
+ if(proc->p_fds[fd].fd_flags & FD_VALID) {
+ proc->p_fds[fd].fd_flags = 0;
+ proc->p_fds[fd].fd_socknum = -1;
+ ret_val = 0;
+ }
+ }
+
+ return(ret_val);
+}
int process_create(process_t**, u32_t, void*);
int process_switch(process_t*);
+int process_falloc(process_t*, int);
+int process_ffree(process_t*, int);
+
#endif /* __PROCESS_H */