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) {
* 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;
}
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;
char *filename = (char *)MK_PTR(regs->ds, regs->edi.w[0]);;
struct file file;
-#if 0
+#if 1
printf("filename: %s\n", filename);
#endif
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;