diff options
| author | Miguel <m.i@gmx.at> | 2018-09-15 00:30:36 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-15 00:30:36 +0200 |
| commit | fe7d0332267ef1e62153b685d2b5574ce624a4bc (patch) | |
| tree | 0c5bb5af4275b55b141ff598d9daedd99eb12603 /kernel | |
| parent | c4b20a0ebbde1348e1e085e2ea3be35345d92b7c (diff) | |
reading ext2 files and using our abstractions
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/fd.c | 33 | ||||
| -rw-r--r-- | kernel/fd.h | 29 | ||||
| -rw-r--r-- | kernel/kernel.c | 8 | ||||
| -rw-r--r-- | kernel/syscalls.c | 79 |
4 files changed, 42 insertions, 107 deletions
diff --git a/kernel/fd.c b/kernel/fd.c deleted file mode 100644 index 524737e..0000000 --- a/kernel/fd.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "fd.h" -#include "fifo.h" - -bool fd_write(fd* f,uint8_t c) -{ - return f->write(f->data,c); -} - -uint8_t fd_read(fd* f) -{ - return f->read(f->data); -} - -bool fd_has(fd* f) -{ - return f->has(f->data); -} - -bool fd_close(fd* f) -{ - return f->close(f->data); -} - -fd fd_from_fifo(fifo* fif) -{ - fd f; - f.data=fif; - f.read=fifo_get; - f.write=fifo_put; -// f.close=fd_close; - f.has=fifo_has; - return f; -} diff --git a/kernel/fd.h b/kernel/fd.h deleted file mode 100644 index 8c7ea45..0000000 --- a/kernel/fd.h +++ /dev/null @@ -1,29 +0,0 @@ -// SIMPLE FILE DESCRIPTOR // - -#ifndef FD_H -#define FD_H - -#include <stdint.h> -#include <stdbool.h> - -#include "fifo.h" - -typedef struct fd_struct -{ - bool (*write)(struct fd_struct*,uint8_t); - uint8_t (*read)(struct fd_struct*); - bool (*has)(struct fd_struct*); - bool (*close)(struct fd_struct*); - - void *data; // opaque data -}fd; - -uint8_t fd_read(fd*); -bool fd_has(fd*); -bool fd_write(fd*,uint8_t); -bool fd_close(fd*); - -fd fd_from_fifo(fifo* f); -//fd fd_from_path(char *path); - -#endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 9088d00..5caed04 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -112,17 +112,17 @@ void kernel_main(uint32_t eax,uint32_t ebx) // -- STDIN/STDOUT -- // fixme("do not force order"); // now needed since ids are allocated 0,1,2... klog("stdin/stdout init ..."); - uint32_t sstderr = syscall_open("stderr",0,0); // stderr 2 + uint32_t sstderr = syscall_open("~stderr",0,0); // stderr 2 uint32_t sstdout; if(cfg_multiboot->framebuffer_type==2) // EGA-standard text mode { - sstdout = syscall_open("term",0,0); // stdout 1 + sstdout = syscall_open("~term",0,0); // stdout 1 } else { - sstdout = syscall_open("xterm",0,0); // stdout 1 + sstdout = syscall_open("~xterm",0,0); // stdout 1 } - uint32_t sstdin = syscall_open("stdin",0,0); // stdin 0 + uint32_t sstdin = syscall_open("~stdin",0,0); // stdin 0 klog("Keyboard init ..."); keyboard_init(0); 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; } |
