Work on ext2 directory support
This commit is contained in:
parent
37532000a0
commit
4b3384e45d
44
fs/ext2.c
44
fs/ext2.c
@ -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);
|
names[num_entries_used]=malloc(current_entry->name_len+1);
|
||||||
strcpy(names[num_entries_used],current_entry->file_name);
|
strcpy(names[num_entries_used],current_entry->file_name);
|
||||||
names[num_entries_used][(int)current_entry->name_len]='\0';
|
names[num_entries_used][(int)current_entry->name_len]='\0';
|
||||||
|
klog("INFO","Found entry with name %s",names[num_entries_used]);
|
||||||
num_entries_used++;
|
num_entries_used++;
|
||||||
tot_size+=current_entry->rec_len;
|
tot_size+=current_entry->rec_len;
|
||||||
current_entry=(dir_entry*)(((uint32_t)current_entry)+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=realloc(names,sizeof(char*)*max_len);
|
||||||
}
|
}
|
||||||
names[num_entries_used]=NULL;
|
names[num_entries_used]=NULL;
|
||||||
|
klog("INFO","Parsed directory");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,16 +235,40 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
|||||||
}
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
FILE* f=fopen(devs[data->num],"r");
|
FILE* f=fopen(devs[data->num],"r");
|
||||||
char got_inode;
|
uint32_t inode_num=2;
|
||||||
uint32_t inode_num=inode_for_fname(2,stream->path,&got_inode,f,data->num);
|
for (char* tok=strtok(stream->path,"/");tok!=NULL;tok=strtok(NULL,"/")) {
|
||||||
if (got_inode) {
|
char got_inode;
|
||||||
data->inode=read_inode(inode_num,f,data->num);
|
inode_num=inode_for_fname(inode_num,tok,&got_inode,f,data->num);
|
||||||
fclose(f);
|
if (got_inode) {
|
||||||
return 1;
|
inode inode=read_inode(inode_num,f,data->num);
|
||||||
} else {
|
if ((inode.i_mode&EXT2_S_IFDIR)==0) {
|
||||||
fclose(f);
|
char* next_tok=strtok(NULL,"/");
|
||||||
return 0;
|
if (tok) {
|
||||||
|
klog("INFO","%s: Not a directory",tok);
|
||||||
|
fclose(f);
|
||||||
|
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 {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -91,10 +91,10 @@ static void init() {
|
|||||||
uint32_t word=port_long_in(0xCFC);
|
uint32_t word=port_long_in(0xCFC);
|
||||||
port_long_out(0xCF8,(1<<31)|0x4);
|
port_long_out(0xCF8,(1<<31)|0x4);
|
||||||
if (word!=port_long_in(0xCFC)) {
|
if (word!=port_long_in(0xCFC)) {
|
||||||
pci_init();
|
// pci_init();
|
||||||
}
|
}
|
||||||
// Detect and initailize serial ports
|
// Detect and initailize serial ports
|
||||||
serial_init();
|
//serial_init();
|
||||||
FILE* file=fopen("/initrd/prog.elf","r");
|
FILE* file=fopen("/initrd/prog.elf","r");
|
||||||
elf_header header;
|
elf_header header;
|
||||||
fread(&header,sizeof(elf_header),1,file);
|
fread(&header,sizeof(elf_header),1,file);
|
||||||
@ -116,15 +116,15 @@ static void init() {
|
|||||||
ide_init();
|
ide_init();
|
||||||
init_ext2();
|
init_ext2();
|
||||||
mount("/","/dev/hda","ext2");
|
mount("/","/dev/hda","ext2");
|
||||||
FILE* f=fopen("/file","r");
|
FILE* f=fopen("/mydir/myfile","r");
|
||||||
char str[256];
|
// char str[256];
|
||||||
fgets(str,256,f);
|
// fgets(str,256,f);
|
||||||
str[strlen(str)-1]='\0';
|
// str[strlen(str)-1]='\0';
|
||||||
klog("INFO","Got string %s",str);
|
// klog("INFO","Got string %s",str);
|
||||||
fgets(str,256,f);
|
// fgets(str,256,f);
|
||||||
str[strlen(str)-1]='\0';
|
// str[strlen(str)-1]='\0';
|
||||||
klog("INFO","Got string %s",str);
|
// klog("INFO","Got string %s",str);
|
||||||
fclose(f);
|
// fclose(f);
|
||||||
// ext2_parse();
|
// ext2_parse();
|
||||||
// char** names=get_dir_listing(2);
|
// char** names=get_dir_listing(2);
|
||||||
// for(int i=0;names[i]!=NULL;i++) {
|
// for(int i=0;names[i]!=NULL;i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user