From 1e08b64b43bf9c50b644da3f76d5a8bcc73f62da Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 19 Sep 2018 01:52:14 +0200 Subject: addding sysfs and pipes etc --- fs/fd.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) (limited to 'fs/fd.c') diff --git a/fs/fd.c b/fs/fd.c index 43ffb0d..fe34003 100644 --- a/fs/fd.c +++ b/fs/fd.c @@ -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; @@ -90,6 +104,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 @@ -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; } - -- cgit v1.2.3