diff options
| author | Miguel <m.i@gmx.at> | 2018-09-20 20:51:57 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-20 20:51:57 +0200 |
| commit | aeefdb37d1fc1c0eb7953b9c196cab09460bc167 (patch) | |
| tree | 513789d7fd28b65afb594e9605975bd10ea06f74 /fs | |
| parent | 763f85c55fdb5a2c4f5bf98e4989a69d27da6e4f (diff) | |
we are now prepared for piping with _pipe and _dup2
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/fd.c | 2 | ||||
| -rw-r--r-- | fs/fifo.c | 16 | ||||
| -rw-r--r-- | fs/fifo.h | 23 | ||||
| -rw-r--r-- | fs/stdstreams.c | 56 | ||||
| -rw-r--r-- | fs/stdstreams.h | 5 |
5 files changed, 101 insertions, 1 deletions
@@ -178,7 +178,7 @@ int fds_from_pipe(fd pipefds[2]) wrt.type=FD_TYPE_PIPE; read.data=kballoc(1); - wrt.data=read.type; + wrt.data=read.data; ringbuffer r=ringbuffer_init(1); diff --git a/fs/fifo.c b/fs/fifo.c new file mode 100644 index 0000000..abd6c46 --- /dev/null +++ b/fs/fifo.c @@ -0,0 +1,16 @@ +#include "fifo.h" + +bool fifo_put(fifo* f,uint8_t c) +{ + return f->put(f->data,c); +} + +uint8_t fifo_get(fifo* f) +{ + return f->get(f->data); +} + +bool fifo_has(fifo* f) +{ + return f->has(f->data); +} diff --git a/fs/fifo.h b/fs/fifo.h new file mode 100644 index 0000000..92f3b75 --- /dev/null +++ b/fs/fifo.h @@ -0,0 +1,23 @@ +// SIMPLE FIFO DRIVER // + +#ifndef FIFO_H +#define FIFO_H + +#include <stdint.h> +#include <stdbool.h> + +typedef struct fifo_struct +{ + bool (*put)(struct fifo_struct*,uint8_t); + uint8_t (*get)(struct fifo_struct*); + bool (*has)(struct fifo_struct*); + void *data; // opaque data + +}fifo; + +bool fifo_put(fifo*,uint8_t); +uint8_t fifo_get(fifo*); +bool fifo_has(fifo*); + +fifo fifo_create_buffered(uint8_t size); +#endif diff --git a/fs/stdstreams.c b/fs/stdstreams.c new file mode 100644 index 0000000..1cb9402 --- /dev/null +++ b/fs/stdstreams.c @@ -0,0 +1,56 @@ +#include <stddef.h> + +#include "fd.h" +#include "terminal.h" +#include "screen.h" +#include "vesa.h" + +#include "kmalloc.h" + +fd fd_from_term() +{ + uint8_t *mem=kballoc(1); + term_out *screen=mem; + terminal_tty *tty1=mem+sizeof(term_out); + fifo *fif=tty1+sizeof(terminal_tty); + + screen->put_char=console_put_char; + screen->update_cursor=update_cursor; + + *tty1=terminal_init(screen,NULL); + + fif->data=tty1; + fif->put=terminal_put; + + return fd_from_fifo(fif); +} + +fd fd_from_fb_term() +{ + uint8_t *mem=kballoc(1); + term_out *screen=mem; + terminal_tty *tty1=mem+sizeof(term_out); + fifo *fif=tty1+sizeof(terminal_tty); + + screen->put_char=vesa_console_put_char; + screen->update_cursor=vesa_update_cursor; + + *tty1=terminal_init(screen,NULL); + + fif->data=tty1; + fif->put=terminal_put; + + return fd_from_fifo(fif); +} + +fd fd_from_ringbuffer() +{ + fifo *f=kballoc(1); + ringbuffer *r=kballoc(1); + *r=ringbuffer_init(1); + f->data=r; + f->put=ringbuffer_put; + f->get=ringbuffer_get; + f->has=ringbuffer_has; + return fd_from_fifo(f); +} diff --git a/fs/stdstreams.h b/fs/stdstreams.h new file mode 100644 index 0000000..06262c9 --- /dev/null +++ b/fs/stdstreams.h @@ -0,0 +1,5 @@ +#include "fd.h" + +fd fd_from_term(); +fd fd_from_fb_term(); +fd fd_from_ringbuffer(); |
