}
-unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode)
+unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode, unsigned int *file_type)
{
unsigned int ino = 0;
+ *file_type = EXT2_FT_UNKNOWN;
void *blk = ext2_alloc_block();
assert(blk != 0);
if(strcmp(name, tmp) == 0)
{
ino = dirent->inode;
+ *file_type = dirent->file_type;
break;
}
dirent = (ext2_dirent_t *) (((unsigned int)dirent) + dirent->rec_len);
+
+ if(((unsigned long) dirent - (unsigned long)blk) >= EXT2_BLOCK_SIZE)
+ {
+ ino = 0;
+ break;
+ }
}
ext2_free_block(blk);
unsigned int ext2_search_inpath(const char *path)
{
+ if(path == 0 || strlen(path) == 0 || path[0] != '/')
+ return 0;
+
assert(path != 0);
assert(strlen(path) > 0);
assert(path[0] == '/');
char file[MAX_FILE_NAME];
int len;
+ unsigned int file_type = EXT2_FT_UNKNOWN;
while((len=get_filename_from_path(path, file)) != 0)
{
- ino = ext2_search_indir(file, inode);
+ ino = ext2_search_indir(file, inode, &file_type);
+ if(ino == 0)
+ return 0;
//assert(ino != 0);
path += len;
ext2_read_inode(ino, inode);
}
else
+ {
+ return 0;
assert(0);
+ }
}
+ if(file_type != EXT2_FT_REG_FILE)
+ return 0;
+
return ino;
}
}
ext2_read_inode(2, &ext2_root_inode);
-#if 0
- printk("root inode.i_size %u \n", ext2_root_inode.i_size);
- printk("root blocks %u \n", ext2_root_inode.i_blocks);
-
- ext2_read_inode(ext2_search_indir("boot", &ext2_root_inode), &boot_inode);
- ext2_read_inode(ext2_search_indir("Kernel", &boot_inode), &krnl_inode);
- printk("krnl inode.i_size %u \n", krnl_inode.i_size);
- printk("krnl blocks %u \n", krnl_inode.i_blocks);
-#endif
-
-
- //printk("----- ino %u\n", ext2_search_inpath("/bin/test/test.txt"));
- //printk("----- ino %u\n", ext2_search_inpath("/bin/hello"));
- //printk("----- ino %u\n", ext2_search_inpath("/boot/Kernel"));
- //printk("----- ino %u\n", ext2_search_inpath("/boot/grub2/fonts/unicode.pf2"));
}