diff options
| author | Miguel <m.i@gmx.at> | 2018-09-19 01:52:14 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-19 01:52:14 +0200 |
| commit | 1e08b64b43bf9c50b644da3f76d5a8bcc73f62da (patch) | |
| tree | 53aca729b7faeb781b04b9c62a7b1b13efa21991 /fs/fd.c | |
| parent | 2d91384197847a7e8fe2c3f548918a8277d3086d (diff) | |
addding sysfs and pipes etc
Diffstat (limited to 'fs/fd.c')
| -rw-r--r-- | fs/fd.c | 59 |
1 files changed, 54 insertions, 5 deletions
@@ -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; } - |
