diff options
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/ext2.c | 3 | ||||
| -rw-r--r-- | fs/fd.c | 59 | ||||
| -rw-r--r-- | fs/fd.h | 22 | ||||
| -rw-r--r-- | fs/mount.c | 8 | ||||
| -rw-r--r-- | fs/pipe.c | 37 | ||||
| -rw-r--r-- | fs/pipe.h | 1 | ||||
| -rw-r--r-- | fs/sysfs.c | 16 |
7 files changed, 113 insertions, 33 deletions
@@ -315,6 +315,9 @@ fd ext2_mount_file_open(mount *m,char *path) int ext2_mount_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos) { uint32_t inode= ext2_filename_to_inode(VMEM_EXT2_RAMIMAGE,path); + if(inode==0)return -1; + ext2_inode *inode_current=ext2_get_inode(VMEM_EXT2_RAMIMAGE,inode); + if(!(inode_current->permissions&0x4000))return -1; return ext2_read_dir(m->data, inode, dirs, pos); } @@ -40,11 +40,10 @@ void* ext2_init(char *path) uint32_t inode= ext2_filename_to_inode(VMEM_EXT2_RAMIMAGE,path); data[0]=inode;// inode data[1]=0; //pos - return data; } -void ext2_write(void* x) +void ext2_write(void* x,uint8_t b) { kpanic("not impl"); } @@ -79,6 +78,21 @@ uint8_t sysfs_get(uint32_t *data) return ringbuffer_get(data); } +void sysfs_write(void* x,uint8_t b) +{ + uint32_t **pp=x+sizeof(ringbuffer); + void (*p)(uint32_t v)=*pp; + + uint32_t *val=x+sizeof(ringbuffer)+4; + val[val[0]]=b; + if(val[0]==4) // 4bytes / 32bit + { + val[0]=1; + p(val[1]+256*val[2]+256*256*val[3]+256*256*256*val[4]); + } + val[0]+=1; +} + bool sysfs_has(uint32_t *data) { return true; @@ -91,6 +105,12 @@ bool sysfs_eof(uint32_t *data) void sysfs_close(uint32_t *data) { + ringbuffer_free(data); // free ringbuffer buffer + kbfree(data); // free memory holding ringbuffer information +} + +void pipe_close(uint32_t *data) +{ ringbuffer *r=data; ringbuffer_free(data); // free ringbuffer buffer kbfree(data); // free memory holding ringbuffer information @@ -114,6 +134,8 @@ bool fifo_eof(uint32_t* data) { return false; } + +// TODO remove and use fd_from_ringbuffer? fd fd_from_fifo(fifo* fif) { fd f; @@ -127,6 +149,27 @@ fd fd_from_fifo(fifo* fif) return f; } +fd fd_from_pipe() +{ + fd f; + f.type=FD_TYPE_PIPE; + f.data=kballoc(1); + ringbuffer r=ringbuffer_init(1); + + memcpy(f.data,&r,sizeof(ringbuffer)); + + /* + f.read=sysfs_get; + f.write=0; + f.has=sysfs_has; + f.eof=sysfs_eof; + */ + + f.close=pipe_close; + + return f; +} + fd fd_from_path(char* path) { fd f; @@ -140,22 +183,28 @@ fd fd_from_path(char* path) return f; } -fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...))) +fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...)),void (*h)(uint32_t in)) { fd f; f.type=FD_TYPE_SYSFS; f.data=kballoc(1); + + uint32_t **pp=f.data+sizeof(ringbuffer); + *pp=h; + + uint32_t *val=f.data+sizeof(ringbuffer)+4; + val[0]=1; // waiting for first byte of the 32bit value + ringbuffer r=ringbuffer_init(1); g(&r,get_sysfs_data); memcpy(f.data,&r,sizeof(ringbuffer)); f.read=sysfs_get; - f.write=0; + f.write=sysfs_write; f.close=sysfs_close; f.has=sysfs_has; f.eof=sysfs_eof; return f; } - @@ -9,27 +9,12 @@ #include "fifo.h" #include "ringbuffer.h" -/* -typedef struct -{ - int(* seek)(int offset, int whence); - - int(* read)(char *buf, int len); - int(* wrtie)(char *buf, int len); - - int(* close)(); - int(* stat)(void *buf); - - void *data; //opaque - -}file; -*/ - enum FD_TYPE{ FD_TYPE_FIFO_BUFFERED=1, FD_TYPE_EXT2_FILE=2, FD_TYPE_EXT2_DIR=3, - FD_TYPE_SYSFS=4 + FD_TYPE_SYSFS=4, + FD_TYPE_PIPE=5 }; typedef struct fd_struct @@ -52,5 +37,6 @@ bool fd_close(fd*); fd fd_from_fifo(fifo* f); fd fd_from_path(char *path); -fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...))); +fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...)),void(*h)(uint32_t in)); + #endif @@ -27,7 +27,7 @@ void mount_add(mount mnt) { if(mounts_count==MAX_MOUNTS)kpanic("maxium number of mounts exceeded. increase MAX_MOUNTS in kernel.h and recomplie kernel."); mounts[mounts_count++]=mnt; - klog("mounted %s",mnt.path); + klog("Mounted %s at %s",mount_type_to_str(mnt.type),mnt.path); } void mount_dump() @@ -70,8 +70,9 @@ static char* get_mount_for_path(char *path,mount *mnt) { if(path[0]!='/')kpanic("this works only for absolute paths!"); + // start with root as default uint32_t best=0; - uint32_t best_len=0; + uint32_t best_len=1; for(int i=0;i<mounts_count;i++) { @@ -83,9 +84,8 @@ static char* get_mount_for_path(char *path,mount *mnt) best=i; best_len=len; } - } - if(best_len==0)return 0; + *mnt=mounts[best]; return path+best_len-1; } diff --git a/fs/pipe.c b/fs/pipe.c new file mode 100644 index 0000000..cbba7a9 --- /dev/null +++ b/fs/pipe.c @@ -0,0 +1,37 @@ +#include "kernel.h" +#include "mount.h" +#include "pipe.h" +#include "log.h" + +#include "lib/string/string.h" + +/* mount interface */ + +fd pipe_file_open(mount *m,char *path) +{ + fd a; + a.type=FD_TYPE_PIPE; +// return fd_from_ + return a; +} + +int pipe_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos) +{ + /* + if(*pos>=count)return 0; + memcpy(dirs->name,names[*pos],strlen(names[*pos])+1); + *pos+=1; + return 1; + */ + return 0; +} + +void pipe_mount(char* path) +{ + mount m; + m.type=MOUNT_TYPE_PIPES; + memcpy(m.path,path,strlen(path)+1); + m.mount_file_open=pipe_file_open; + m.mount_read_dir=pipe_read_dir; + mount_add(m); +} diff --git a/fs/pipe.h b/fs/pipe.h new file mode 100644 index 0000000..49f7f13 --- /dev/null +++ b/fs/pipe.h @@ -0,0 +1 @@ +void pipe_mount(char* path); @@ -1,6 +1,6 @@ #include "mount.h" +#include <stdlib.h> #include "sysfs.h" - #include "mem.h" #include "kmalloc.h" #include "mount.h" @@ -9,10 +9,13 @@ #include "lib/string/string.h" -static const char* names[] = {"/mem","/kmalloc","/mount"}; -static uint32_t map[]={mem_sysfs,kmalloc_sysfs,mount_sysfs}; -static uint32_t count=3; +static const char* names[] = {"mem","kmalloc","mount"}; +static uint32_t map[]={mem_sysfs,mem_sysfs_set, + kmalloc_sysfs,NULL, + mount_sysfs,NULL, + }; +static uint32_t count=3; /* mount interface */ @@ -22,15 +25,16 @@ fd sysfs_file_open(mount *m,char *path) for (int i=0;i<count;i++) { if(!strcmp(path,names[i])) - return fd_from_sysfs(map[i]); + return fd_from_sysfs(map[2*i],map[2*i+1]); } - return fd_from_sysfs(map[0]); + return fd_from_sysfs(map[0],map[1]); } int sysfs_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos) { if(*pos>=count)return 0; memcpy(dirs->name,names[*pos],strlen(names[*pos])+1); + dirs->inode=0; *pos+=1; return 1; } |
