diff options
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/ext2.c | 6 | ||||
| -rw-r--r-- | fs/file.h | 7 | ||||
| -rw-r--r-- | fs/ringbuffer.c | 71 | ||||
| -rw-r--r-- | fs/ringbuffer.h | 27 |
4 files changed, 104 insertions, 7 deletions
@@ -6,7 +6,6 @@ #include <stdbool.h> #include <stdint.h> -#include "lib/string/string.h" #include "lib/logger/log.h" #include "fs.h" #include "ext2.h" @@ -272,7 +271,7 @@ int ext2_filename_to_inode_traverse(uint8_t *ram, char *path,int inode_start) for(int i=0;i<count;i++) { - if(true==strcmp(first,dirs[i].name,0)) + if(!strcmp_l(first,dirs[i].name,0)) { log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"found: %s (%s)",first,dirs[i].type==FS_FILE_TYPE_DIR?"dir":"file"); if(final)return dirs[i].inode; @@ -291,7 +290,8 @@ int ext2_filename_to_inode_traverse(uint8_t *ram, char *path,int inode_start) int ext2_filename_to_inode(uint8_t *ram, char *path) { - if(true==strcmp(path,"/",0))return 2; // root is inode 2 by definition + if(!strcmp_l(path,"/",0))return 2; // root is inode 2 by definition + char buf[256]; for(int i=0;i<256;i++) { @@ -5,11 +5,10 @@ typedef struct file_struct { - uint32_t file_id; + int fgetc(); + int fputc(); - void (*read)(); - void (*write)(); - void (*seek)(); + void *opaque; }file; diff --git a/fs/ringbuffer.c b/fs/ringbuffer.c new file mode 100644 index 0000000..ca5870f --- /dev/null +++ b/fs/ringbuffer.c @@ -0,0 +1,71 @@ +#define FOOLOS_MODULE_NAME "fifo" +#include "lib/logger/log.h" + +#include "fifo.h" + +static int sl=9; + +fifo fifo_init(uint32_t size) +{ + fifo f; + f.data=kballoc(size); + f.size=size*4096; + f.front=f.size-1; + f.back=f.size-1; + return f; +} + +bool fifo_put(fifo* f,uint8_t c) +{ + x86_int_disable(); + lock_spin(sl); + + if((f->back-1+f->size)%f->size==f->front) + { + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); + x86_int_enable(); + return false; + } + + f->data[f->back]=c; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put %d %d (%c)", f->back, f->front,c); + f->back--; + f->back+=f->size; + f->back%=f->size; + + lock_release(sl); + x86_int_enable(); + + return true; +} + +uint8_t fifo_get(fifo* f) // blocking +{ + + char c; + + x86_int_disable(); + lock_spin(sl); + + if(f->front==f->back) + { + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); + x86_int_enable(); + c='_'; + return false; + } + + c=f->data[f->front]; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get %d %d (%c)", f->back, f->front,c); + + f->front--; + f->front+=f->size; + f->front%=f->size; + + lock_release(sl); + x86_int_enable(); + + return true; +} diff --git a/fs/ringbuffer.h b/fs/ringbuffer.h new file mode 100644 index 0000000..31d00cf --- /dev/null +++ b/fs/ringbuffer.h @@ -0,0 +1,27 @@ +#ifndef RINGBUFFER_H +#define RINGBUFFER_H + +#include <stdint.h> +#include <stdbool.h> + +// Simple FIRST IN FIRST OUT +// requires kballoc - block allocation +typedef struct ringbuffer_struct +{ + uint32_t size; + uint32_t front; + uint32_t back; + + uint8_t *data; + +}ringbuffer; + +// create new fifo of given size (in blocks) +ringbuffer ringbuffer_init(uint32_t blocks); + +// true on success +bool ringbuffer_put(ringbuffer*,uint8_t); +uint8_t ringbuffer_get(ringbuffer*); // blocking +bool ringbuffer_has(ringbuffer*); // check if somehting waiting? + +#endif |
