struct file;
typedef struct {
- struct file *dd_dir;
+ struct file *dd_dir;
} DIR;
#define DIR_REC_LEN(name) (12 + strlen(name) + 1 + 3) & ~3
int rv = -1;
if (dir) {
- com32sys_t regs;
- memset(®s, 0, sizeof regs);
- regs.eax.w[0] = 0x0022;
- regs.esi.l = (uint32_t)dir;
- __com32.cs_intcall(0x22, ®s, ®s);
- free(dir);
- rv = 0;
- }
-
- return rv;
+ com32sys_t regs;
+ memset(®s, 0, sizeof regs);
+ regs.eax.w[0] = 0x0022;
+ regs.esi.l = (uint32_t)dir;
+ __com32.cs_intcall(0x22, ®s, ®s);
+ free(dir);
+ rv = 0;
+ }
+
+ return rv;
}
if (!(regs.eflags.l & EFLAGS_CF)) {
/* Initialization: malloc() then zero */
newdir = calloc(1, sizeof(DIR));
- newdir->dd_dir = (struct file *)regs.eax.l;
+ newdir->dd_dir = (struct file *)regs.eax.l;
}
/* We're done */
{
struct dirent *newde;
com32sys_t regs;
-
- memset(®s, 0, sizeof(regs));
- regs.eax.w[0] = 0x0021;
- regs.esi.l = (uint32_t)dir;
- __com32.cs_intcall(0x22, ®s, ®s);
- newde = (struct dirent *)(regs.eax.l);
-
+
+ memset(®s, 0, sizeof(regs));
+ regs.eax.w[0] = 0x0021;
+ regs.esi.l = (uint32_t)dir;
+ __com32.cs_intcall(0x22, ®s, ®s);
+ newde = (struct dirent *)(regs.eax.l);
+
return newde;
}
int main(int argc, char *argv[])
{
- DIR *dir;
- struct dirent *de;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- if (argc != 2) {
- printf("Usage: dir direcotry\n");
- return 0;
- }
-
- dir = opendir(argv[1]);
- if (dir == NULL) {
- printf("Unable to read dir: %s\n", argv[1]);
- return 0;
- }
-
- while ((de = readdir(dir)) != NULL)
- printf("%s\n", de->d_name);
-
- closedir(dir);
-
+ DIR *dir;
+ struct dirent *de;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc != 2) {
+ printf("Usage: dir direcotry\n");
+ return 0;
+ }
+
+ dir = opendir(argv[1]);
+ if (dir == NULL) {
+ printf("Unable to read dir: %s\n", argv[1]);
return 0;
+ }
+
+ while ((de = readdir(dir)) != NULL)
+ printf("%s\n", de->d_name);
+
+ closedir(dir);
+
+ return 0;
}
filepos = 0;
d = opendir(filestr);
if (d != NULL) {
- //printf("DIR:'%s' %08x %8d\n", d->dd_name, (int)d->dd_sect, d->dd_offset);
+ //printf("DIR:'%s' %08x %8d\n", d->dd_name, (int)d->dd_sect, d->dd_offset);
de = readdir(d);
while (de != NULL) {
filepos++;
*/
void opendir(com32sys_t *regs)
{
- this_fs->fs_ops->opendir(regs);
- regs->eax.l = (uint32_t)handle_to_file(regs->esi.w[0]);
+ this_fs->fs_ops->opendir(regs);
+ regs->eax.l = (uint32_t)handle_to_file(regs->esi.w[0]);
}
/*
*/
void readdir(com32sys_t *regs)
{
- DIR *dir = (DIR *)regs->esi.l;
+ DIR *dir = (DIR *)regs->esi.l;
struct dirent *de = NULL;
-
- if (dir->dd_dir)
- de = this_fs->fs_ops->readdir(dir->dd_dir);
- else
- de = NULL;
-
+
+ if (dir->dd_dir)
+ de = this_fs->fs_ops->readdir(dir->dd_dir);
+ else
+ de = NULL;
+
/* Return the newly read de in _eax_ register */
regs->eax.l = (uint32_t)de;
}
void closedir(com32sys_t *regs)
{
DIR *dir = (DIR *)regs->esi.l;
- _close_file(dir->dd_dir);
+ _close_file(dir->dd_dir);
}
{
const char *src = MK_PTR(regs->ds, regs->esi.w[0]);
char *dst = MK_PTR(regs->es, regs->edi.w[0]);
-
+
this_fs->fs_ops->mangle_name(dst, src);
}
{
const char *src = MK_PTR(regs->ds, regs->esi.w[0]);
char *dst = MK_PTR(regs->es, regs->edi.w[0]);
-
+
dst = this_fs->fs_ops->unmangle_name(dst, src);
/* Update the di register to point to the last null char */
handle = regs->esi.w[0];
file = handle_to_file(handle);
-
+
buf = MK_PTR(regs->es, regs->ebx.w[0]);
bytes_read = file->fs->fs_ops->getfssec(file, buf, sectors, &have_more);
#endif
file = alloc_file();
-
+
if (file) {
file->fs = this_fs;
file->fs->fs_ops->searchdir(filename, file);
-
+
if (file->open_file) {
regs->esi.w[0] = file_to_handle(file);
regs->eax.l = file->file_len;
return;
}
}
-
+
/* failure... */
regs->esi.w[0] = 0;
regs->eax.l = 0;
{
uint16_t handle = regs->esi.w[0];
struct file *file;
-
+
if (handle) {
file = handle_to_file(handle);
_close_file(file);
{
int blk_shift;
const struct fs_ops *ops = (const struct fs_ops *)regs->eax.l;
-
+
/* set up the fs stucture */
fs.fs_ops = ops;
regs->esi.w[0], regs->edi.w[0]);
this_fs = &fs;
-
+
/* invoke the fs-specific init code */
blk_shift = fs.fs_ops->fs_init(&fs);
static char *NameStart;
static int NameLen;
-/* do this for readdir, because it called from asm and don't know the fs structure */
-static struct fs_info *this_fs = NULL;
-
-
/*
* Allocate a file structure, if successful return the file pointer, or NULL.
*
uint8_t attr = 0;
char *p;
struct open_file_t *open_file = NULL;
-
- this_fs = file->fs;
dir_sector = CurrentDir;
if (*filename == '/') {
*/
void vfat_opendir(com32sys_t *regs)
{
- char *src = MK_PTR(regs->es, regs->esi.w[0]);
- char *dst = MK_PTR(regs->ds, regs->edi.w[0]);
- strcpy(dst, src);
- searchdir(regs);
+ char *src = MK_PTR(regs->es, regs->esi.w[0]);
+ char *dst = MK_PTR(regs->ds, regs->edi.w[0]);
+ strcpy(dst, src);
+ searchdir(regs);
}
/*
uint8_t checksum = 0;
uint8_t entries_left;
int i;
- static struct dirent de;
+ static struct dirent de;
char *de_name = de.d_name;
struct cache_struct *cs;
struct fat_dir_entry *fat_dir;
struct fat_long_name_entry *long_dir;
- struct open_file_t *file = dir->open_file;
- struct fs_info *fs = dir->fs;
-
+ struct open_file_t *file = dir->open_file;
+ struct fs_info *fs = dir->fs;
+
sector = file->file_sector;
sec_off = file->file_bytesleft;
if (!sector)
return NULL;
entries_left = (SECTOR_SIZE - sec_off) >> 5;
- cs = get_cache_block(this_fs->fs_dev, sector);
+ cs = get_cache_block(fs->fs_dev, sector);
fat_dir = (struct fat_dir_entry *)(cs->data + sec_off);/* resume last position in sector */
while (1) {
- if (!entries_left) {
+ if (!entries_left) {
sector = nextsector(fs, sector);
if (!sector)
return NULL;
}
if (fat_dir->name[0] == 0)
- return NULL;
+ return NULL;
if (fat_dir->attr == FAT_ATTR_LONG_NAME) {
/* it's a long name */
long_dir = (struct fat_long_name_entry *)fat_dir;
if (long_dir->id & 0x40) {
- checksum = long_dir->checksum;
+ checksum = long_dir->checksum;
init_id = id = long_dir->id & 0x3f;
id--;
} else {
long_entry_name(long_dir);
memcpy(de_name + id * 13, entry_name, 13);
- /*
+ /*
* we need go on with the next entry
* and we will fall through to next entry
*/
/* it's a short entry */
if (!id) {
- /* Got a long name match */
- if (get_checksum(fat_dir->name) != checksum)
- goto next_entry;
-
- break;
- }
+ /* Got a long name match */
+ if (get_checksum(fat_dir->name) != checksum)
+ goto next_entry;
+
+ break;
+ }
if (fat_dir->attr & FAT_ATTR_VOLUME_ID ||
- get_checksum(fat_dir->name) != checksum )
- goto next_entry;
+ get_checksum(fat_dir->name) != checksum )
+ goto next_entry;
for(i = 0; i < 8; i ++) {
if (fat_dir->name[i] == ' ')
else
*de_name = '\0';
- break;
+ break;
}
next_entry:
- entries_left --;
+ entries_left --;
fat_dir ++;
}
-
- /* found what we want, fill the de structure */
- de.d_reclen = DIR_REC_LEN(de.d_name);
- de.d_type = fat_dir->attr;
-
- /* update the DIR structure */
+
+ /* found what we want, fill the de structure */
+ de.d_reclen = DIR_REC_LEN(de.d_name);
+ de.d_type = fat_dir->attr;
+
+ /* update the DIR structure */
entries_left--;
- if (!entries_left) {
- sector = nextsector(fs, sector);
- file->file_bytesleft = 0;
+ if (!entries_left) {
+ sector = nextsector(fs, sector);
+ file->file_bytesleft = 0;
} else {
file->file_bytesleft = SECTOR_SIZE - (entries_left << 5);
- }
+ }
file->file_sector = sector;
-
- return &de;
+
+ return &de;
}
static void vfat_load_config(com32sys_t *regs)
.mangle_name = vfat_mangle_name,
.unmangle_name = generic_unmangle_name,
.load_config = vfat_load_config,
- .opendir = vfat_opendir,
- .readdir = vfat_readdir
+ .opendir = vfat_opendir,
+ .readdir = vfat_readdir
};
char * (*unmangle_name)(char *, const char *);
void (*load_config)(com32sys_t *);
- /* the _dir_ stuff */
- void (*opendir)(com32sys_t *);
- struct dirent * (*readdir)(struct file *);
+ /* the _dir_ stuff */
+ void (*opendir)(com32sys_t *);
+ struct dirent * (*readdir)(struct file *);
};
enum dev_type {CHS, EDD};