diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-10-22 21:21:32 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-10-22 21:21:32 +0200 |
| commit | 55365e593c27b57c50a7369597bd14f110ba8cb6 (patch) | |
| tree | c88de36646fd9ebee7ed270fbd35285417715fe7 /fs | |
| parent | 95450710a8b8290a110686d78c2357d3920bcda5 (diff) | |
reading userprogramm from ext2 ramimage!
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/Makefile | 16 | ||||
| -rw-r--r-- | fs/ext2.c | 143 | ||||
| -rw-r--r-- | fs/fs.c | 2 |
3 files changed, 143 insertions, 18 deletions
diff --git a/fs/Makefile b/fs/Makefile deleted file mode 100644 index d339621..0000000 --- a/fs/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -run: a.out - ./a.out < ext2.img -a.out: ext2.c - gcc ext2.c -std=c11 -filesys: - dd if=/dev/zero of=ext2.img bs=512 count=10000 - sudo mkfs.ext2 -O none ext2.img - mkdir mnt - sudo mount ext2.img mnt - sudo chown miguel mnt - mkdir mnt/miguel - echo "hello one" > mnt/miguel/test1.txt - echo "hello two" > mnt/test2.txt - sync - - @@ -1,7 +1,10 @@ // ext2 minidriver // based on osdev wiki article: http://wiki.osdev.org/Ext2 +#define FOOLOS_MODULE_NAME "ext2" + #include "lib/int/stdint.h" +#include "lib/logger/log.h" typedef struct ext2_superblock_struct { @@ -95,13 +98,149 @@ typedef struct ext2_inode_struct }ext2_inode; +void ram_read(char *in,char *out,int size, int count) +{ + for(int i=0;i<size*count;i++) + { + out[i]=in[i]; + } - /* -int main() +} + +int ext2_check(uint8_t *ram) { ext2_superblock super; ext2_superblock_ext super_ext; + uint8_t *ptr=ram+1024; + ram_read(ptr,&super,sizeof(super),1); + if(super.ext2_sig!=0xef53)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"no ext2 signature found, where ram-image expected!"); + //check version and req features. + // +} + +ext2_inode ext2_get_inode(uint8_t *ram,int inode_num) +{ + + // get basic shit from superblock! + ext2_superblock super; + ext2_blockgroup_desc desc; + ext2_inode inode; + + uint8_t *ptr=ram+1024; + ram_read(ptr,&super,sizeof(super),1); + if(super.ext2_sig!=0xef53)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"no ext2 signature found, where ram-image expected!"); + + int block_group=(inode_num-1)/super.inodes_per_group; + + // get descrtptor for our blockgroup! + //TODO: only correct for 1024bytes/block. read more than one!!! + int block_size=1024; + int descriptor_start_block=2; + + ptr=ram+block_size*descriptor_start_block; + ptr+=sizeof(desc)*block_group; // skip to our descriptor; + + ram_read(ptr,&desc,sizeof(desc),1); // read descriptor + + // read our inode; + ptr=ram+block_size*desc.addr_inode_table; + ptr+=128*((inode_num-1)%super.inodes_per_group); + + ram_read(ptr,&inode,sizeof(inode),1); //get inode 2 (rood-directory) + + return inode; + +} + + +int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max) +{ + ext2_inode inode=ext2_get_inode(ram,inode_nr); + + int pos=0; + int block=0; + int block_size=1024; + int block_counter=0; + uint8_t *ptr=ram+block_size*inode.direct_pointer[0]; + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Loading %d %d bytes",inode.size_high, inode.size_low); + while(pos<inode.size_low) // use size high? + { + ramdest[pos]=*ptr; + ptr++; + block_counter++; + pos++; + if(block_counter>=block_size) + { + block++; + + if(block>=12) + { + int indirect_block=block-12; + uint32_t *indirect_ptr=ram+block_size*inode.indirect1; + ptr=ram+block_size*indirect_ptr[indirect_block]; + + } + else + { + ptr=ram+block_size*inode.direct_pointer[block]; + } + + block_counter=0; + } + + + + } +// if(block>=12)panic(FOOLOS_MODULE_NAME,"such big files unsupported yet"); + + +} + + + +int ext2_read_root_dir(uint8_t *ram) +{ + + ext2_inode inode=ext2_get_inode(ram,2); + + char buf[256]; + int block_size=1024; + uint8_t *ptr=ram+block_size*inode.direct_pointer[0]; //use other pointers in future! + + int pos=0; + while(pos<inode.size_low) // use size high? + { + + ext2_dir dir; + ram_read(ptr,&dir,sizeof(dir),1); + ptr+=sizeof(dir); + + /* + printf("inode: %i\n",dir.inode); + printf("total size: %i\n",dir.size); + printf("length low/high: %i/%i\n\n",dir.name_length_low,dir.name_length_high); + */ + +// int l=fread(buf,sizeof(char),dir.name_length_low,stdin); + ram_read(ptr,&buf,sizeof(char),dir.name_length_low); + ptr+=dir.name_length_low; + + buf[dir.name_length_low]=0; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d %s",dir.inode,buf); + ptr+=dir.size-8-dir.name_length_low; + pos+=dir.size; + + } + +} + +/* +int main() +{ + ext2_superblock super; + ext2_superblock_ext super_ext; printf("ext2 fools driver\n"); printf("reading superblock...\n\n"); @@ -24,3 +24,5 @@ int fs_readdir(const char *name,fs_dirent *dirs,int max) } + + |
