Work on ext2 directory support

This commit is contained in:
pjht 2019-04-07 15:14:46 -05:00
parent 37532000a0
commit 4b3384e45d
2 changed files with 46 additions and 20 deletions

View File

@ -116,6 +116,7 @@ char** get_dir_listing(uint32_t inode_num,FILE* f,int num) {
names[num_entries_used]=malloc(current_entry->name_len+1);
strcpy(names[num_entries_used],current_entry->file_name);
names[num_entries_used][(int)current_entry->name_len]='\0';
klog("INFO","Found entry with name %s",names[num_entries_used]);
num_entries_used++;
tot_size+=current_entry->rec_len;
current_entry=(dir_entry*)(((uint32_t)current_entry)+current_entry->rec_len);
@ -125,6 +126,7 @@ char** get_dir_listing(uint32_t inode_num,FILE* f,int num) {
names=realloc(names,sizeof(char*)*max_len);
}
names[num_entries_used]=NULL;
klog("INFO","Parsed directory");
return names;
}
@ -233,16 +235,40 @@ 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;
for (char* tok=strtok(stream->path,"/");tok!=NULL;tok=strtok(NULL,"/")) {
char got_inode;
uint32_t inode_num=inode_for_fname(2,stream->path,&got_inode,f,data->num);
inode_num=inode_for_fname(inode_num,tok,&got_inode,f,data->num);
if (got_inode) {
data->inode=read_inode(inode_num,f,data->num);
inode inode=read_inode(inode_num,f,data->num);
if ((inode.i_mode&EXT2_S_IFDIR)==0) {
char* next_tok=strtok(NULL,"/");
if (tok) {
klog("INFO","%s: Not a directory",tok);
fclose(f);
return 1;
return 0;
} else {
break;
}
}
} else {
klog("INFO","%s: No such file or directory",tok);
fclose(f);
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;
// }
} else {
return 0;
}

View File

@ -91,10 +91,10 @@ static void init() {
uint32_t word=port_long_in(0xCFC);
port_long_out(0xCF8,(1<<31)|0x4);
if (word!=port_long_in(0xCFC)) {
pci_init();
// pci_init();
}
// Detect and initailize serial ports
serial_init();
//serial_init();
FILE* file=fopen("/initrd/prog.elf","r");
elf_header header;
fread(&header,sizeof(elf_header),1,file);
@ -116,15 +116,15 @@ static void init() {
ide_init();
init_ext2();
mount("/","/dev/hda","ext2");
FILE* f=fopen("/file","r");
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);
fclose(f);
FILE* f=fopen("/mydir/myfile","r");
// 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);
// fclose(f);
// ext2_parse();
// char** names=get_dir_listing(2);
// for(int i=0;names[i]!=NULL;i++) {