LDLINUX:vfat: Improve the fat fs relative path searching
authorLiu Aleaxander <Aleaxander@gmail.com>
Thu, 10 Dec 2009 07:30:21 +0000 (15:30 +0800)
committerLiu Aleaxander <Aleaxander@gmail.com>
Thu, 10 Dec 2009 07:30:21 +0000 (15:30 +0800)
Added a new flag, FS_THISIND, used in the fat and iso fs relative path
searching. It means tries to get the last directory of the config file
path in the 'this_inode' variable to do a relative searching while loading
the kernel images in after.

And also fixed a bug in fs.c which wouldn't close the file structure when
doing path searching failed! And as a result, we could just run a few com32
programs.

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

index 4307b78..415becf 100644 (file)
@@ -127,7 +127,7 @@ void print_cache(struct device *dev)
         struct cache_struct *cs = dev->cache_head;
         for (; i < dev->cache_entries; i++) {
                 cs = cs->next;
-                printf("%d(%p) ", cs->block, cs->data);
+                printf("%d(%p)\n", cs->block, cs->data);
         }
 
         printf("\n");
index a821f95..31b5465 100644 (file)
--- a/core/fs.c
+++ b/core/fs.c
@@ -127,12 +127,12 @@ void searchdir(com32sys_t *regs)
     char *p;
     int symlink_count = 6;
     
-#if 1
+#if 0
     printf("filename: %s\n", name);
 #endif
 
     if (!(file = alloc_file()))
-       goto err;
+       goto err_no_close;
     file->fs = this_fs;
 
     /* if we have ->searchdir method, call it */
@@ -177,6 +177,15 @@ void searchdir(com32sys_t *regs)
            free_inode(inode);
            continue;
        }
+
+       /* 
+        * For the relative path searching used in FAT and ISO fs.
+        */
+       if ((this_fs->fs_ops->fs_flags & FS_THISIND) && (this_inode != parent)){
+               if (this_inode)
+                   free_inode(this_inode);
+               this_inode = parent;
+       }
        
        if (parent != this_inode)
            free_inode(parent);
@@ -196,6 +205,8 @@ void searchdir(com32sys_t *regs)
     return;
     
 err:
+    _close_file(file);
+err_no_close:    
     regs->esi.w[0]  = 0;
     regs->eax.l     = 0;
     regs->eflags.l |= EFLAGS_ZF;
@@ -254,4 +265,6 @@ void fs_init(com32sys_t *regs)
 
     if (fs.fs_ops->iget_current)
        this_inode = fs.fs_ops->iget_current();
+
+    print_cache(fs.fs_dev);
 }
index cc9b48b..b272da7 100644 (file)
@@ -524,21 +524,6 @@ static struct inode *vfat_iget(char *dname, struct inode *parent)
     return vfat_find_entry(dname, parent);
 }
 
-static char current_dir_name[32];
-static struct inode *vfat_iget_current(void)
-{
-    com32sys_t regs;
-    /* 
-     * Use ConfigName again.
-     */
-    memset(&regs, 0, sizeof regs);
-    regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
-    strcpy((void *)regs.edi.w[0], current_dir_name);
-    call16(core_open, &regs, &regs);
-    
-    return handle_to_file(regs.esi.w[0])->inode;
-}
-
 /*
  * The open dir function, just call the searchdir function  directly. 
  * I don't think we need call the mangle_name function first 
@@ -583,22 +568,6 @@ static int vfat_load_config(void)
         return 1;  /* no config file */
     }
     
-     /* Build the Current inode */
-    strcpy(current_dir_name, syslinux_cfg[i]);
-    current_dir_name[strlen(syslinux_cfg[i]) - strlen(config_name)] = '\0';
-    this_inode = vfat_iget_current();
-
-    memset(&regs, 0, sizeof regs);
-    regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
-    for (; i < 3; i++) {
-        strcpy(ConfigName, syslinux_cfg[i]);
-        call16(core_open, &regs, &regs);
-
-        /* if zf flag set, then failed; try another */
-        if (! (regs.eflags.l & EFLAGS_ZF))
-            break;
-    }
-    
     strcpy(ConfigName, config_name);
     return 0;
 }
@@ -655,7 +624,7 @@ static int vfat_fs_init(struct fs_info *fs)
         
 const struct fs_ops vfat_fs_ops = {
     .fs_name       = "vfat",
-    .fs_flags      = FS_USEMEM,
+    .fs_flags      = FS_USEMEM | FS_THISIND,
     .fs_init       = vfat_fs_init,
     .searchdir     = NULL,
     .getfssec      = vfat_getfssec,
@@ -666,6 +635,6 @@ const struct fs_ops vfat_fs_ops = {
     .opendir       = vfat_opendir,
     .readdir       = NULL,
     .iget_root     = vfat_iget_root,
-    .iget_current  = vfat_iget_current,
+    .iget_current  = NULL,
     .iget          = vfat_iget,
 };
index 31d6885..bee6318 100644 (file)
@@ -32,8 +32,14 @@ extern struct fs_info *this_fs;
 struct dirent;                  /* Directory entry structure */
 struct file;
 enum fs_flags {
-    FS_NODEV  = 1 << 0,
-    FS_USEMEM = 1 << 1,         /* If we need a malloc routine, set it */
+    FS_NODEV   = 1 << 0,
+    FS_USEMEM  = 1 << 1,         /* If we need a malloc routine, set it */
+
+ /* 
+  * Update the this_inode pointer at each part of path searching. This 
+  * flag is just used for FAT and ISO fs for now.
+  */
+    FS_THISIND = 1 << 2,        
 };
 
 struct fs_ops {