From 0f406b1f01d366c85ec34900e25e3e7f93c613f2 Mon Sep 17 00:00:00 2001 From: pjht Date: Mon, 8 Apr 2019 11:24:03 -0500 Subject: [PATCH] Got ext2 directory support working --- fs/ext2.c | 20 ++++++-------------- kernel/kernel.c | 8 ++++---- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/fs/ext2.c b/fs/ext2.c index 8929f5d..15349f7 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -234,14 +234,15 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) { if (data) { FILE* f=fopen(devs[data->num],"r"); uint32_t inode_num=2; + inode inode; for (char* tok=strtok(stream->path,"/");tok!=NULL;tok=strtok(NULL,"/")) { char got_inode; inode_num=inode_for_fname(inode_num,tok,&got_inode,f,data->num); if (got_inode) { - inode inode=read_inode(inode_num,f,data->num); + inode=read_inode(inode_num,f,data->num); if ((inode.i_mode&EXT2_S_IFDIR)==0) { char* next_tok=strtok(NULL,"/"); - if (tok) { + if (next_tok) { klog("INFO","%s: Not a directory",tok); fclose(f); return 0; @@ -255,18 +256,9 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) { return 0; } } - klog("INFO","File inode:%d",inode_num); - return 0; - // char got_inode; - // uint32_t inode_num=inode_for_fname(2,stream->path,&got_inode,f,data->num); - // if (got_inode) { - // data->inode=read_inode(inode_num,f,data->num); - // fclose(f); - // return 1; - // } else { - // fclose(f); - // return 0; - // } + data->inode=inode; + fclose(f); + return 1; } else { return 0; } diff --git a/kernel/kernel.c b/kernel/kernel.c index 1db7739..e2b5147 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -117,10 +117,10 @@ static void init() { init_ext2(); mount("/","/dev/hda","ext2"); FILE* f=fopen("/mydir/myfile","r"); - // char str[256]; - // fgets(str,256,f); - // str[strlen(str)-1]='\0'; - // klog("INFO","Got string %s",str); + char str[256]; + fgets(str,256,f); + str[strlen(str)-1]='\0'; + klog("INFO","Got string %s",str); // fgets(str,256,f); // str[strlen(str)-1]='\0'; // klog("INFO","Got string %s",str);