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;
}
} 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);
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 */
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) {
* @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;
sector = dir_file->file_sector;
sec_off = dir_file->file_bytesleft;
- if ( !sector )
+ if (!sector)
goto fail;
entries_left = (SECTOR_SIZE - sec_off) >> 5;
}
*filename++ = '.';
-
+
for ( i = 8; i < 11; i ++) {
if ( dir->name[i] == ' ' )
break;
}
/* check if we have got an extention */
- if ( ! *(filename - 1) )
- *(filename -2) = '\0';
+ if (*(filename - 1) == '.')
+ *(filename - 1) = '\0';
else
*filename = '\0';
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;
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)