diff --git a/sys/arch/armv6/sched.c b/sys/arch/armv6/sched.c index 8381715..e3b908e 100644 --- a/sys/arch/armv6/sched.c +++ b/sys/arch/armv6/sched.c @@ -146,13 +146,12 @@ tmpTask->state = NEW; /* HACK */ - /* XXX MrOlsen (2020-01-28): Why did I allocate them? This is not needed just waste of memory? for (i = 0; i < 3; i++) { fp = (void *) kmalloc(sizeof(struct file)); tmpTask->td.o_files[i] = (uint32_t) fp; fp->f_flag = 0x4; } - */ + spinLock(&schedulerSpinLock); tmpTask->id = nextID++; diff --git a/sys/arch/i386/sched.c b/sys/arch/i386/sched.c index 8eeb1ea..94e1b70 100644 --- a/sys/arch/i386/sched.c +++ b/sys/arch/i386/sched.c @@ -173,14 +173,12 @@ memcpy(tmpTask->username, "UbixOS", 6); /* HACK */ - /* XXX MrOlsen (2020-01-28): This is not needed? Waste of memory I think for (i = 0; i < 3; i++) { fp = (void *) kmalloc(sizeof(struct file)); //kprintf("DB: [0x%X]\n", (uint32_t) fp); tmpTask->td.o_files[i] = (void *) fp; fp->f_flag = 0x4; } - */ spinLock(&schedulerSpinLock); tmpTask->id = nextID++; diff --git a/sys/kernel/descrip.c b/sys/kernel/descrip.c index 241ac3c..de8cb73 100644 --- a/sys/kernel/descrip.c +++ b/sys/kernel/descrip.c @@ -39,16 +39,28 @@ int fcntl(struct thread *td, struct fcntl_args *uap) { struct file *fp = 0x0; + int i = 0; - if (uap->fd < 3) - kprintf("FD: %i, CMD: %i", uap->fd, uap->cmd); - else if (td->o_files[uap->fd] == 0x0) { + if (td->o_files[uap->fd] == 0x0) { kprintf("ERROR!!!\n"); return (-1); } - else { + + fp = (struct file*) td->o_files[uap->fd]; + switch (uap->cmd) { + case 17: + /* First 5 Descriptors Are Reserved */ + for (i = 5; i < MAX_FILES; i++) { + if (td->o_files[i] == 0x0) { + td->o_files[i] = (void*) fp; + td->td_retval[0] = i; + td->o_files[uap->fd] = 0; + break; + } + } + break; case 3: td->td_retval[0] = fp->f_flag; break; @@ -59,7 +71,7 @@ default: kprintf("ERROR DEFAULT: [%i]", uap->fd); } - } + return (0x0); }