diff options
Diffstat (limited to 'kernel/syscalls.c')
| -rw-r--r-- | kernel/syscalls.c | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 4d1c29d..57ebc54 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -15,15 +15,13 @@ #include "syscalls.h" #include "scheduler.h" #include "log.h" - -// TODO: use includes!!! -uint64_t timer_get_ms(); +#include "timer.h" static fd fds[MAX_FD]; static uint32_t next_fd=0; +// fifos for backing up some file descrpitors static fifo fifos[MAX_FIFOS]; -static uint32_t fifo_data_len[MAX_FIFOS]; static uint32_t next_fifo=0; // screen / terminal @@ -121,7 +119,6 @@ int syscall_write(int file, char *buf, int len) for(int i=0;i<len;i++) { fd_write(&fds[file],buf[i]); - fifo_data_len[file]++; } return len; } @@ -132,19 +129,9 @@ int syscall_write(int file, char *buf, int len) */ int syscall_read(int file, char *buf, int len) { - //file 0 = stdin , file 1 = stdout , file 2 = stderr - char c; - int l=0; - - c=fd_read(&fds[file]); - fifo_data_len[file]--; - *buf=c; - buf++; - l++; - - return l; - if(l==len)return l; - if(c=='\n')return l; + if(fds[file].type==FD_TYPE_EXT2_FILE && !fd_has(&fds[file]))return 0; + *buf=fd_read(&fds[file]); + return 1; } //TODO: replace with dirent! @@ -283,44 +270,53 @@ int get_max_fd() // TODO: allow opening existing files/named pipes int syscall_open(char *name, int flags, int mode) { - if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)kpanic("we ran out of fd's or fifo's"); - if(!strcmp(name,"term")) + bool create_fifo=true; + if(name[0]!='~')create_fifo=false; + + if(create_fifo) { - screen.put_char=console_put_char; - screen.update_cursor=update_cursor; - tty1=terminal_init(&screen,NULL); + if(!strcmp(name,"~term")) + { + screen.put_char=console_put_char; + screen.update_cursor=update_cursor; - fifos[next_fifo].data=&tty1; - fifos[next_fifo].put=terminal_put; + tty1=terminal_init(&screen,NULL); - fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); - } - else if(!strcmp(name,"xterm")) - { - screen.put_char=vesa_console_put_char; - screen.update_cursor=vesa_update_cursor; + fifos[next_fifo].data=&tty1; + fifos[next_fifo].put=terminal_put; + + fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + } + else if(!strcmp(name,"~xterm")) + { + screen.put_char=vesa_console_put_char; + screen.update_cursor=vesa_update_cursor; - tty1=terminal_init(&screen,NULL); + tty1=terminal_init(&screen,NULL); - fifos[next_fifo].data=&tty1; - fifos[next_fifo].put=terminal_put; + fifos[next_fifo].data=&tty1; + fifos[next_fifo].put=terminal_put; + fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + } + else + { + fifos[next_fifo]=fifo_create_buffered(1); fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + } + + next_fifo++; } else { - fifos[next_fifo]=fifo_create_buffered(1); - fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + + fds[next_fd]=fd_from_path(name); } - fifo_data_len[next_fifo]=0; - - next_fifo++; next_fd++; - return next_fd-1; } uint32_t syscall_fork(int pid) @@ -389,7 +385,8 @@ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, case SYSCALL_WAIT : return !task_runs(p1); case SYSCALL_READ : - return p3 <= fifo_data_len[p1]; + if(fds[p1].type==FD_TYPE_EXT2_FILE)return 1; + return fd_has(&fds[p1]); case SYSCALL_EXIT : return 1; } |
