From fe7d0332267ef1e62153b685d2b5574ce624a4bc Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 15 Sep 2018 00:30:36 +0200 Subject: reading ext2 files and using our abstractions --- kernel/syscalls.c | 79 ++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 41 deletions(-) (limited to 'kernel/syscalls.c') 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=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; } -- cgit v1.2.3