Core:SYSLINUX: make searchdir do work
authorLiu Aleaxander <Aleaxander@gmail.com>
Tue, 11 Aug 2009 09:18:38 +0000 (17:18 +0800)
committerLiu Aleaxander <Aleaxander@gmail.com>
Tue, 11 Aug 2009 09:18:38 +0000 (17:18 +0800)
well, still get lots of bugs, like when we execute
dir /boot/syslinux
in fact, it will list the file in /boot/ directory but not in /boot/syslinux/

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

index fe37d72..631c780 100644 (file)
@@ -391,10 +391,10 @@ void rosh_dir_arg(const char *ifilstr, const char *pwdstr)
     fd = open(filestr, O_RDONLY);
     if (fd != -1) {
        status = fstat(fd, &fdstat);
-       if (S_ISDIR(fdstat.st_mode)) {
+        if (S_ISDIR(fdstat.st_mode)) {
            ROSH_DEBUG("PATH '%s' is a directory\n", ifilstr);
            d = fdopendir(fd);
-           de = readdir(d);
+            de = readdir(d);
            while (de != NULL) {
 #ifdef DO_DEBUG
                filestr2[0] = 0;
@@ -423,10 +423,10 @@ void rosh_dir_arg(const char *ifilstr, const char *pwdstr)
        }
     } else {
 #ifdef __COM32__
-       if (filestr[strlen(filestr) - 1] == SEP) {
+        if (filestr[strlen(filestr) - 1] == SEP) {
            /* Directory */
            filepos = 0;
-           d = opendir(filestr);
+            d = opendir(filestr);
            if (d != NULL) {
                printf("DIR:'%s'    %08x %8d\n", d->dd_name, d->dd_fd,
                       d->dd_sect);
index a8c8323..007c383 100644 (file)
@@ -907,7 +907,7 @@ comapi_opendir:
                pm_call mangle_name
                pop ds
                pm_call searchdir
-               jnz comapi_err  ; Didn't find a directory
+               jz 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
@@ -928,7 +928,7 @@ comapi_readdir:
                mov es,P_ES
                mov di,P_DI
                mov si,P_SI
-               pm_call readdir
+               pm_call vfat_readdir
                mov P_EAX,eax
                mov P_DL,dl
                mov P_EBX,ebx
index 1e011c9..eb238be 100644 (file)
@@ -18,7 +18,7 @@
 
 %if IS_SYSLINUX
         ; fat.c
-        extern readdir
+        extern vfat_readdir
 %endif
 
 %endif ; EXTERN_INC
index 3cf9594..c184730 100644 (file)
@@ -675,13 +675,16 @@ static void vfat_searchdir(char *filename, struct file *file)
     dir_sector = CurrentDir;
     if ( *filename == '/' ) {
         dir_sector = RootDir;
-        filename ++;
+        if (*(filename + 1) == 0) /* root dir is what we need */
+            goto found_dir;
     }
-    if (*filename == 0) /* root dir is what we need */
-        goto found_dir;
-    
+        
     while ( *filename ) {
+        if (*filename == '/')
+            filename++;               /* skip '/' */
         p = filename;
+        if (*p == 0)
+            break;
         PrevDir = dir_sector;
         
         /* try to find the end */
@@ -694,19 +697,15 @@ static void vfat_searchdir(char *filename, struct file *file)
             goto found_dir;           
         }
         
-        //*p = 0; /* null-terminate the current path part */
         mangle_dos_name(MangleBuf, filename);
+        /* close it before open a new dir file */
+        close_file(open_file);
         open_file = search_dos_dir(file->fs, MangleBuf, dir_sector, &file_len, &attr);
         if (! open_file) 
             goto fail;
 
-        if ( *p == 0 )   /* we got a file */                        
-            break;
-        
         dir_sector = open_file->file_sector;
-        close_file(open_file);
-        
-        filename = p + 1; /* search again */                
+        filename = p;
     }
     
     if (attr & 0x10) {
@@ -740,21 +739,20 @@ static void vfat_searchdir(char *filename, struct file *file)
  * @param: file
  *
  */
-static void readdir(com32sys_t *regs)/*
+void vfat_readdir(com32sys_t *regs)/*
                                 struct fs_info *fs, struct open_file_t* dir_file,
                                 char* filename, uint32_t *file_len, uint8_t *attr)
                               */
 {
-    uint32_t sector, sec_off;       
-    
+    uint32_t sector, sec_off;      
     /* make it to be 1 to check if we have met a long name entry before */
     uint8_t  id = 1;
     uint8_t  init_id, next_id;
     uint8_t  entries_left;  
     int i;
 
-    char *filename = (char *)MK_PTR(regs->es, regs->edi.w[0]);
-    struct open_file_t *dir_file = (struct open_file_t *)MK_PTR(regs->ds, regs->esi.w[0]);
+    char *filename = MK_PTR(regs->es, regs->edi.w[0]);
+    struct open_file_t *dir_file = MK_PTR(regs->ds, regs->esi.w[0]);
     
     struct cache_struct  *cs;
     struct fat_dir_entry *dir;
@@ -763,7 +761,7 @@ static void readdir(com32sys_t *regs)/*
     
     sector  = dir_file->file_sector;
     sec_off = dir_file->file_bytesleft;
-    if ( !sector )
+    if (!sector)
         goto fail;
     
     entries_left = (SECTOR_SIZE - sec_off) >> 5;
@@ -813,7 +811,7 @@ static void readdir(com32sys_t *regs)/*
             }
             
             *filename++ = '.';
-            
+                        
             for ( i = 8; i < 11; i ++) {
                 if ( dir->name[i] == ' ' )
                     break;
@@ -821,8 +819,8 @@ static void readdir(com32sys_t *regs)/*
             }
             
             /* check if we have got an extention */
-            if ( ! *(filename - 1) 
-                *(filename -2) = '\0';
+            if (*(filename - 1) == '.'
+                *(filename - 1) = '\0';
             else
                 *filename = '\0';      
             
@@ -848,7 +846,10 @@ static void readdir(com32sys_t *regs)/*
         sector = nextsector(this_fs, sector);
         if ( !sector )
             goto fail;
-    }
+        dir_file->file_bytesleft = 0;
+    } else 
+        dir_file->file_bytesleft = SECTOR_SIZE - (entries_left << 5);
+    dir_file->file_sector = sector;
 
     file.file_sector = sector;
     file.file_bytesleft = (SECTOR_SIZE - (entries_left << DIRENT_SHIFT) ) & 0xffff;
@@ -862,6 +863,8 @@ static void readdir(com32sys_t *regs)/*
  fail:
     //close_dir(dir);
     regs->eax.l = 0;
+    regs->esi.w[0] = 0;
+    regs->eflags.l |= EFLAGS_CF;
 }
 
 static void vfat_load_config(com32sys_t *regs)