FS: add a new fs flag and do a better searchdir-check
authorLiu Aleaxander <Aleaxander@gmail.com>
Fri, 20 Nov 2009 06:14:48 +0000 (14:14 +0800)
committerLiu Aleaxander <Aleaxander@gmail.com>
Fri, 20 Nov 2009 06:14:48 +0000 (14:14 +0800)
If we want use the malloc/free functions, set the FS_USEMEM flag
in the (fs)_ops.flags, and in the fs_init phase, it will init the
memory management system.

And it would be little better to do a check base on if we have searchdir
method or not instead of the fs name in the searchdir function.

Signed-off-by: Liu Aleaxander <Aleaxander@gmail.com>
core/fs.c
core/fs/ext2/ext2.c
core/include/fs.h

index a733d58..ee9488f 100644 (file)
--- a/core/fs.c
+++ b/core/fs.c
@@ -135,8 +135,8 @@ void searchdir(com32sys_t *regs)
        goto err;
     file->fs = this_fs;
 
-    /* for now, we just applied the universal path_lookup to EXTLINUX */
-    if (strcmp(this_fs->fs_ops->fs_name, "ext2") != 0) {
+    /* if we have ->searchdir method, call it */
+    if (file->fs->fs_ops->searchdir) {
        file->fs->fs_ops->searchdir(name, file);
        
        if (file->open_file) {
@@ -150,7 +150,7 @@ void searchdir(com32sys_t *regs)
     }
 
 
-
+    /* else, try the generic-path-lookup method */
     if (*name == '/') {
        inode = this_fs->fs_ops->iget_root();
        while(*name == '/')
@@ -227,7 +227,7 @@ void fs_init(com32sys_t *regs)
     int blk_shift;
     const struct fs_ops *ops = (const struct fs_ops *)regs->eax.l;
     
-    if (strcmp(ops->fs_name, "ext2") == 0)
+    if (ops->fs_flags & FS_USEMEM)
        mem_init();
 
     /* set up the fs stucture */    
index 799f1db..e4374b6 100644 (file)
@@ -443,7 +443,7 @@ static int ext2_fs_init(struct fs_info *fs)
 
 const struct fs_ops ext2_fs_ops = {
     .fs_name       = "ext2",
-    .fs_flags      = 0,
+    .fs_flags      = FS_USEMEM,
     .fs_init       = ext2_fs_init,
     .searchdir     = NULL,
     .getfssec      = ext2_getfssec,
index 72138be..31d6885 100644 (file)
@@ -32,7 +32,8 @@ extern struct fs_info *this_fs;
 struct dirent;                  /* Directory entry structure */
 struct file;
 enum fs_flags {
-    FS_NODEV = 1,
+    FS_NODEV  = 1 << 0,
+    FS_USEMEM = 1 << 1,         /* If we need a malloc routine, set it */
 };
 
 struct fs_ops {