aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-08-11 13:20:04 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-08-11 13:20:04 -0700
commit0202356bab69a17bf9620432da4339348c0833b7 (patch)
tree41f5e3ca14e7946e252e39ca9473d22004f017cb
parent6a1f8b6a4d1b61b43a14b17b4f88319a03b97250 (diff)
parent37003eb7e984370fad9407ce5db341b720e9d4cd (diff)
downloadsyslinux-4.00-pre2.tar.gz
syslinux-4.00-pre2.tar.xz
syslinux-4.00-pre2.zip
Merge commit 'liu/master' into fscsyslinux-4.00-pre2
-rw-r--r--com32/rosh/rosh.c10
-rw-r--r--com32/rosh/rosh.h2
-rw-r--r--core/comboot.inc9
-rw-r--r--core/extern.inc2
-rw-r--r--core/fat.c77
-rw-r--r--core/fs.c4
6 files changed, 54 insertions, 50 deletions
diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c
index 9a4edae2..631c780e 100644
--- a/com32/rosh/rosh.c
+++ b/com32/rosh/rosh.c
@@ -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,12 +423,12 @@ 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' %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) {
diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h
index 64b0564c..0c41bac9 100644
--- a/com32/rosh/rosh.h
+++ b/com32/rosh/rosh.h
@@ -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
diff --git a/core/comboot.inc b/core/comboot.inc
index da3c2399..007c3836 100644
--- a/core/comboot.inc
+++ b/core/comboot.inc
@@ -907,12 +907,11 @@ 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
- ;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
@@ -929,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
diff --git a/core/extern.inc b/core/extern.inc
index 4c7b149a..eb238be0 100644
--- a/core/extern.inc
+++ b/core/extern.inc
@@ -18,7 +18,7 @@
%if IS_SYSLINUX
; fat.c
- extern alloc_fill_dir, readdir
+ extern vfat_readdir
%endif
%endif ; EXTERN_INC
diff --git a/core/fat.c b/core/fat.c
index 57278d03..c1847308 100644
--- a/core/fat.c
+++ b/core/fat.c
@@ -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;
}
@@ -679,41 +675,44 @@ 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;
}
-
+
while ( *filename ) {
+ if (*filename == '/')
+ filename++; /* skip '/' */
p = filename;
+ if (*p == 0)
+ break;
+ 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;
+ }
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 != '/' ) /* 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 */
+ filename = p;
}
- 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;
@@ -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)
diff --git a/core/fs.c b/core/fs.c
index 03abfd6f..0bfa1557 100644
--- 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;