From e0b07793a4cccc6921170ad83d292a9aa4895efb Mon Sep 17 00:00:00 2001 From: Liu Aleaxander Date: Fri, 28 Aug 2009 22:55:52 +0800 Subject: [PATCH] Core: code clean -- re-style the unstyle code With the emacs config given by hpa, which is really powfull, I restyled the unsytled code. Signed-off-by: Liu Aleaxander --- com32/include/sys/dirent.h | 2 +- com32/lib/closedir.c | 20 ++++++------ com32/lib/opendir.c | 2 +- com32/lib/readdir.c | 14 ++++---- com32/modules/dir.c | 42 ++++++++++++------------ com32/rosh/rosh.c | 2 +- core/dir.c | 20 ++++++------ core/fs.c | 18 +++++------ core/fs/fat/fat.c | 80 +++++++++++++++++++++------------------------- core/include/fs.h | 6 ++-- 10 files changed, 100 insertions(+), 106 deletions(-) diff --git a/com32/include/sys/dirent.h b/com32/include/sys/dirent.h index bfdbb9b..cc2916e 100644 --- a/com32/include/sys/dirent.h +++ b/com32/include/sys/dirent.h @@ -22,7 +22,7 @@ struct dirent { struct file; typedef struct { - struct file *dd_dir; + struct file *dd_dir; } DIR; #define DIR_REC_LEN(name) (12 + strlen(name) + 1 + 3) & ~3 diff --git a/com32/lib/closedir.c b/com32/lib/closedir.c index 9e43dd4..b3f5564 100644 --- a/com32/lib/closedir.c +++ b/com32/lib/closedir.c @@ -16,14 +16,14 @@ int closedir(DIR * dir) 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; } diff --git a/com32/lib/opendir.c b/com32/lib/opendir.c index 70f74c1..6f91032 100644 --- a/com32/lib/opendir.c +++ b/com32/lib/opendir.c @@ -27,7 +27,7 @@ DIR *opendir(const char *pathname) 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 */ diff --git a/com32/lib/readdir.c b/com32/lib/readdir.c index 6c95bd6..07ca395 100644 --- a/com32/lib/readdir.c +++ b/com32/lib/readdir.c @@ -15,12 +15,12 @@ struct dirent *readdir(DIR * dir) { 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; } diff --git a/com32/modules/dir.c b/com32/modules/dir.c index a3c9815..913c2ca 100644 --- a/com32/modules/dir.c +++ b/com32/modules/dir.c @@ -9,27 +9,27 @@ 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; } diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c index 862497b..2221bb0 100644 --- a/com32/rosh/rosh.c +++ b/com32/rosh/rosh.c @@ -428,7 +428,7 @@ void rosh_dir_arg(const char *ifilstr, const char *pwdstr) 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++; diff --git a/core/dir.c b/core/dir.c index a8d5805..42400c9 100644 --- a/core/dir.c +++ b/core/dir.c @@ -11,8 +11,8 @@ extern struct fs_info *this_fs; */ 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]); } /* @@ -23,14 +23,14 @@ void opendir(com32sys_t *regs) */ 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; } @@ -38,7 +38,7 @@ void readdir(com32sys_t *regs) void closedir(com32sys_t *regs) { DIR *dir = (DIR *)regs->esi.l; - _close_file(dir->dd_dir); + _close_file(dir->dd_dir); } diff --git a/core/fs.c b/core/fs.c index 9a812d5..f7bf68c 100644 --- a/core/fs.c +++ b/core/fs.c @@ -64,7 +64,7 @@ void mangle_name(com32sys_t *regs) { 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); } @@ -73,7 +73,7 @@ void unmangle_name(com32sys_t *regs) { 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 */ @@ -94,7 +94,7 @@ void getfssec(com32sys_t *regs) 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); @@ -121,11 +121,11 @@ void searchdir(com32sys_t *regs) #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; @@ -133,7 +133,7 @@ void searchdir(com32sys_t *regs) return; } } - + /* failure... */ regs->esi.w[0] = 0; regs->eax.l = 0; @@ -144,7 +144,7 @@ void close_file(com32sys_t *regs) { uint16_t handle = regs->esi.w[0]; struct file *file; - + if (handle) { file = handle_to_file(handle); _close_file(file); @@ -163,7 +163,7 @@ void fs_init(com32sys_t *regs) { int blk_shift; const struct fs_ops *ops = (const struct fs_ops *)regs->eax.l; - + /* set up the fs stucture */ fs.fs_ops = ops; @@ -175,7 +175,7 @@ void fs_init(com32sys_t *regs) 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); diff --git a/core/fs/fat/fat.c b/core/fs/fat/fat.c index 3efba4c..58226a7 100644 --- a/core/fs/fat/fat.c +++ b/core/fs/fat/fat.c @@ -47,10 +47,6 @@ static char long_name[0x40 * 13]; 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. * @@ -616,8 +612,6 @@ static void vfat_searchdir(char *filename, struct file *file) uint8_t attr = 0; char *p; struct open_file_t *open_file = NULL; - - this_fs = file->fs; dir_sector = CurrentDir; if (*filename == '/') { @@ -678,10 +672,10 @@ static void vfat_searchdir(char *filename, struct file *file) */ 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); } /* @@ -696,24 +690,24 @@ struct dirent* vfat_readdir(struct file *dir) 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; @@ -722,13 +716,13 @@ struct dirent* vfat_readdir(struct file *dir) } 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 { @@ -741,7 +735,7 @@ struct dirent* vfat_readdir(struct file *dir) 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 */ @@ -750,16 +744,16 @@ struct dirent* vfat_readdir(struct file *dir) /* 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] == ' ') @@ -778,29 +772,29 @@ struct dirent* vfat_readdir(struct file *dir) 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) @@ -895,6 +889,6 @@ const struct fs_ops vfat_fs_ops = { .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 }; diff --git a/core/include/fs.h b/core/include/fs.h index a668759..e66c3bd 100644 --- a/core/include/fs.h +++ b/core/include/fs.h @@ -51,9 +51,9 @@ struct fs_ops { 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}; -- 2.7.4