diff options
| author | Miguel <m.i@gmx.at> | 2018-10-12 00:30:44 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-12 00:30:44 +0200 |
| commit | b461c3558b2fe765a4bac512638b0acf5185b4bb (patch) | |
| tree | 62d025135865f1752c7d884ac92fdcdd39b21654 /kernel | |
| parent | 2e8d1bc3b6aa0671995860ca8a09c97523f3538d (diff) | |
imeplemented /dev/tty and minimalistic "less"
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/syscalls.c | 51 | ||||
| -rw-r--r-- | kernel/syscalls.h | 2 |
2 files changed, 17 insertions, 36 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 29b5b6b..507be13 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -28,12 +28,14 @@ #define MAX_PID 200 //TODO move to process.c and implement per process // -static fd fds[MAX_PID][MAX_FD]; +static fd fds[MAX_PID][MAX_FD]; +static int tty[MAX_PID]; // keep track of /dev/tty fd for each process :P + static bool open_fd[MAX_PID][MAX_FD]; -fd *get_fd(uint32_t pid,uint32_t file) +fd *get_tty(uint32_t pid) { - return &(fds[pid][file]); + return &(fds[pid][tty[pid]]); } void fd_init_std_streams(uint32_t pid) @@ -48,37 +50,6 @@ void fd_init_std_streams(uint32_t pid) open_fd[pid][2]=true; return; - - static bool first=true; - if(pid==0&&first) - { - first=false; - //stdin / stdout /stderr - fds[0][0]=fd_from_ringbuffer(); - -// if(!fb) // ega text mode - { - // fds[0][1]=fd_from_term(); - // fds[0][2]=fd_from_term(); - } -// else - { - //fds[0][1]=fd_from_fb_term(); - //fds[0][2]=fd_from_fb_term(); - } - open_fd[0][0]=true; -// open_fd[0][1]=true; -// open_fd[0][2]=true; - } - else - { - fds[pid][0]=fds[0][0]; -// fds[pid][1]=fds[0][1]; -// fds[pid][2]=fds[0][2]; - open_fd[pid][0]=true; -// open_fd[pid][1]=true; -// open_fd[pid][2]=true; - } } // @@ -308,6 +279,8 @@ int nextfd(int pid) int syscall_open(char *name, int flags, int mode,uint32_t pid) { + if(!strcmp("/dev/tty",name))return tty[pid]; + uint32_t fdn=nextfd(pid); fds[pid][fdn]=mount_file_open(name); if(*(uint32_t *)fds[pid][fdn].data==0)return -1; @@ -325,8 +298,9 @@ uint32_t syscall_fork(int none1, int none2, int none3, int pid) fds[newpid][i]=fd_dupl(&fds[pid][i]); open_fd[newpid][i]=true; } + tty[newpid]=tty[pid]; // fds[newpid][0]=fd_from_ringbuffer(); // TODO fix - open_fd[newpid][0]=true; +// open_fd[newpid][0]=true; return newpid; } @@ -341,6 +315,7 @@ uint32_t syscall_clone(int none1, int none2, int none3, int pid) fds[newpid][i]=fd_dupl(&fds[pid][i]); open_fd[newpid][i]=true; } + tty[newpid]=tty[pid]; return newpid; } @@ -383,6 +358,7 @@ int syscall_close(int file,int none1,int none2,int pid) // TODO: check if file is a termminal! int syscall_isatty(int file,int none1,int none2,int pid) { + return 1; if(fds[pid][file].type==FD_TYPE_FIFO)return 1; return 0; } @@ -438,7 +414,12 @@ uint32_t syscall_gui_rect(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) } uint32_t syscall_gui_win(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) { + uint32_t fdn=nextfd(pid); + fds[pid][fdn]=fd_from_ringbuffer(); + tty[pid]=fdn; + task_add_win(pid); + return 1; } diff --git a/kernel/syscalls.h b/kernel/syscalls.h index b79e6b3..5579dd7 100644 --- a/kernel/syscalls.h +++ b/kernel/syscalls.h @@ -48,7 +48,7 @@ /** Todo move somewhere else and init per process , think how to make thread safe */ void fd_init_std_streams(uint32_t pid); -fd *get_fd(uint32_t pid,uint32_t file); +fd *get_tty(uint32_t pid); /** returns string representation of the syscall from its number */ char* syscall_get_name(uint32_t num); |
