Core:SYSLINUX: fix the vfat_searchdir
authorLiu Aleaxander <Aleaxander@gmail.com>
Tue, 11 Aug 2009 06:16:23 +0000 (14:16 +0800)
committerLiu Aleaxander <Aleaxander@gmail.com>
Tue, 11 Aug 2009 06:16:23 +0000 (14:16 +0800)
This makes the searchdir can find a dir; it's also prepared for the readdir function used in rosh

Signed-off-by: Liu Aleaxander <Aleaxander@gmail.com>
com32/rosh/rosh.c
com32/rosh/rosh.h
core/comboot.inc
core/extern.inc
core/fat.c
core/fs.c

index 9a4edae..fe37d72 100644 (file)
@@ -428,7 +428,7 @@ void rosh_dir_arg(const char *ifilstr, const char *pwdstr)
            filepos = 0;
            d = opendir(filestr);
            if (d != NULL) {
-               printf("DIR:'%s'    %8d %8d\n", d->dd_name, d->dd_fd,
+               printf("DIR:'%s'    %08x %8d\n", d->dd_name, d->dd_fd,
                       d->dd_sect);
                de = readdir(d);
                while (de != NULL) {
index 64b0564..0c41bac 100644 (file)
@@ -47,6 +47,8 @@
 #error SYSLINUX (I believe) requires __GNUC__
 #endif /* __GNUC__ */
 
+#define DO_DEBUG 1
+
 #ifdef DO_DEBUG
 #define ROSH_DEBUG(f, ...)     printf (f, ## __VA_ARGS__)
 #ifdef DO_DEBUG2
index da3c239..a8c8323 100644 (file)
@@ -908,11 +908,10 @@ comapi_opendir:
                pop ds
                pm_call searchdir
                jnz comapi_err  ; Didn't find a directory
+                mov eax,[si]     ; the sector number where the dir stores
                cmp eax,0
                jz comapi_err   ; Found nothing
-                       ;ZF is unset
-               pm_call alloc_fill_dir
-               mov P_EAX,eax
+                mov P_EAX,eax
                mov P_CX,SECTOR_SIZE
                mov P_SI,si
                clc
index 4c7b149..1e011c9 100644 (file)
@@ -18,7 +18,7 @@
 
 %if IS_SYSLINUX
         ; fat.c
-        extern alloc_fill_dir, readdir
+        extern readdir
 %endif
 
 %endif ; EXTERN_INC
index 57278d0..3cf9594 100644 (file)
@@ -89,22 +89,18 @@ static struct open_file_t *allocate_file(void)
  * structure, or return NULL.
  *
  */
-void alloc_fill_dir(com32sys_t *regs)
+static struct open_file_t *alloc_fill_dir(sector_t sector)
 {
-    sector_t sector = regs->eax.l;
     struct open_file_t *file;
     
     file = allocate_file();
-    if ( !file ) {
-        regs->esi.w[0] = 0;
-        return;
-    }
+    if ( !file )
+        return NULL;        
     
     file->file_sector = sector; /* current sector */
     file->file_bytesleft = 0;   /* current offset */
     file->file_left = sector;   /* beginning sector */
-    
-    regs->esi.w[0] = OFFS_WRT(file, 0);
+    return file;
 }
 
 
@@ -681,39 +677,43 @@ static void vfat_searchdir(char *filename, struct file *file)
         dir_sector = RootDir;
         filename ++;
     }
+    if (*filename == 0) /* root dir is what we need */
+        goto found_dir;
     
     while ( *filename ) {
         p = filename;
+        PrevDir = dir_sector;
         
         /* try to find the end */
         while ( (*p > ' ') && (*p != '/') )
             p ++;
         
-        if (filename == p)
-            //return NULL;
-            goto fail;
-
-        PrevDir = dir_sector;
+        if (filename == p) {
+            /* found a dir */
+            dir_sector = PrevDir;
+            goto found_dir;           
+        }
         
+        //*p = 0; /* null-terminate the current path part */
         mangle_dos_name(MangleBuf, filename);
         open_file = search_dos_dir(file->fs, MangleBuf, dir_sector, &file_len, &attr);
         if (! open_file) 
             goto fail;
-        
-        if ( *p != '/' )   /* we got a file */                        
+
+        if ( *p == 0 )   /* we got a file */                        
             break;
         
-        if ( (attr & 0x10) == 0 ) /* subdirectory */
-            //return NULL;
-            goto fail;
-        
         dir_sector = open_file->file_sector;
         close_file(open_file);
         
         filename = p + 1; /* search again */                
     }
     
-    if ( (attr & 0x18) || (file_len == 0) ) {
+    if (attr & 0x10) {
+        dir_sector = PrevDir;
+    found_dir:
+        open_file = alloc_fill_dir(dir_sector);
+    } else if ( (attr & 0x18) || (file_len == 0) ) {
     fail:
         file_len = 0;
         open_file = NULL;
index 03abfd6..0bfa155 100644 (file)
--- a/core/fs.c
+++ b/core/fs.c
@@ -64,7 +64,7 @@ void searchdir(com32sys_t *regs)
     char *filename = (char *)MK_PTR(regs->ds, regs->edi.w[0]);;
     struct file file;
         
-#if 0    
+#if 1    
     printf("filename: %s\n", filename);
 #endif
 
@@ -74,7 +74,7 @@ void searchdir(com32sys_t *regs)
     this_fs->fs_ops->searchdir(filename, &file);
     regs->esi.w[0] = OFFS_WRT(file.open_file, 0);
     regs->eax.l = file.file_len;
-    if (file.file_len)
+    if (file.open_file)
         regs->eflags.l &= ~EFLAGS_ZF;
     else
         regs->eflags.l |= EFLAGS_ZF;