isatty syscall

This commit is contained in:
Matheus
2022-08-20 12:18:54 -03:00
parent fce640c0f9
commit b3b5981f7a
6 changed files with 62 additions and 1 deletions
+9
View File
@@ -47,6 +47,15 @@ int devman_read(int *error, int dev, void* buff, size_t count, size_t offset){
}
int devman_isatty(int dev){
if(major(dev) > highestmajor)
return ENOTTY;
return majorcalls[major(dev)]->isatty(minor(dev));
}
void devman_init(){
devfs_init();
+38
View File
@@ -0,0 +1,38 @@
#include <kernel/syscalls.h>
#include <kernel/fd.h>
#include <kernel/vfs.h>
#include <arch/cls.h>
#include <kernel/sched.h>
#include <arch/spinlock.h>
syscallret syscall_isatty(int ifd){
syscallret retv;
retv.ret = -1;
proc_t* proc = arch_getcls()->thread->proc;
fd_t* fd = proc->fds + ifd;
spinlock_acquire(&proc->fdlock);
if(proc->fdcount <= ifd || fd->node == NULL){
spinlock_release(&proc->fdlock);
retv.errno = EBADF;
return retv;
}
spinlock_acquire(&fd->lock);
spinlock_release(&proc->fdlock);
int ret = vfs_isatty(fd->node);
retv.errno = ret;
retv.ret = retv.errno == ENOTTY ? 0 : 1;
spinlock_release(&fd->lock);
return retv;
}