diff options
author | Liu Aleaxander <Aleaxander@gmail.com> | 2009-11-20 13:08:42 +0800 |
---|---|---|
committer | Liu Aleaxander <Aleaxander@gmail.com> | 2009-11-20 13:08:42 +0800 |
commit | 7acda33d12dea2117bbfd9ba138104d680efcd85 (patch) | |
tree | 117fe252a8d4a70d156466f6bcb8fbb3bf836e75 /core | |
parent | 84b1443afbfe24eb6e338e8636e8e3759b9093d5 (diff) | |
download | syslinux-7acda33d12dea2117bbfd9ba138104d680efcd85.tar.gz |
core:fs: Use a much better union structure in file structure
Remove the u1 and u2 union, and merge the related fileds as a group, and
then make a big union. Then we don't need to use u1 or u2 to reference
these fileds any more but use it directly just like there are no union
structures here:)
Signed-off-by: Liu Aleaxander <Aleaxander@gmail.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/fs.c | 8 | ||||
-rw-r--r-- | core/fs/ext2/ext2.c | 14 | ||||
-rw-r--r-- | core/fs/fat/fat.c | 10 | ||||
-rw-r--r-- | core/fs/iso9660/iso9660.c | 16 | ||||
-rw-r--r-- | core/fs/pxe/pxe.c | 16 | ||||
-rw-r--r-- | core/include/fs.h | 19 |
6 files changed, 44 insertions, 39 deletions
@@ -139,9 +139,9 @@ void searchdir(com32sys_t *regs) if (strcmp(this_fs->fs_ops->fs_name, "ext2") != 0) { file->fs->fs_ops->searchdir(name, file); - if (file->u1.open_file) { + if (file->open_file) { regs->esi.w[0] = file_to_handle(file); - regs->eax.l = file->u2.file_len; + regs->eax.l = file->file_len; regs->eflags.l &= ~EFLAGS_ZF; return; } @@ -187,8 +187,8 @@ void searchdir(com32sys_t *regs) name++; } - file->u1.inode = inode; - file->u2.offset = 0; + file->inode = inode; + file->offset = 0; regs->esi.w[0] = file_to_handle(file); regs->eax.l = inode->size; diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c index a416a886..385cacf2 100644 --- a/core/fs/ext2/ext2.c +++ b/core/fs/ext2/ext2.c @@ -24,9 +24,9 @@ static int strecpy(char *dst, const char *src, char *end) static void ext2_close_file(struct file *file) { - if (file->u1.inode) { - file->u2.offset = 0; - free_inode(file->u1.inode); + if (file->inode) { + file->offset = 0; + free_inode(file->inode); } } @@ -114,15 +114,15 @@ static uint32_t ext2_getfssec(struct file *file, char *buf, int sector_left, next_sector, sector_idx; int frag_start, con_sec_cnt; int bytes_read = sectors << SECTOR_SHIFT; - struct inode *inode = file->u1.inode; + struct inode *inode = file->inode; struct fs_info *fs = file->fs; - uint32_t bytesleft = inode->size - file->u2.offset; + uint32_t bytesleft = inode->size - file->offset; sector_left = (bytesleft + SECTOR_SIZE - 1) >> SECTOR_SHIFT; if (sectors > sector_left) sectors = sector_left; - sector_idx = file->u2.offset >> SECTOR_SHIFT; + sector_idx = file->offset >> SECTOR_SHIFT; while (sectors) { /* * get the frament @@ -159,7 +159,7 @@ static uint32_t ext2_getfssec(struct file *file, char *buf, } else { *have_more = 1; } - file->u2.offset += bytes_read; + file->offset += bytes_read; return bytes_read; } diff --git a/core/fs/fat/fat.c b/core/fs/fat/fat.c index e8a82acc..0c3b5b91 100644 --- a/core/fs/fat/fat.c +++ b/core/fs/fat/fat.c @@ -95,7 +95,7 @@ static inline void close_pvt(struct open_file_t *of) static void vfat_close_file(struct file *file) { - close_pvt(file->u1.open_file); + close_pvt(file->open_file); } @@ -290,7 +290,7 @@ static uint32_t vfat_getfssec(struct file *gfile, char *buf, int sectors, bool *have_more) { uint32_t bytes_read = sectors << SECTOR_SHIFT; - struct open_file_t *file = gfile->u1.open_file; + struct open_file_t *file = gfile->open_file; struct fs_info *fs = gfile->fs; if (sectors > file->file_left) @@ -662,8 +662,8 @@ static void vfat_searchdir(char *filename, struct file *file) open_file->file_left = (file_len + SECTOR_SIZE -1) >> SECTOR_SHIFT; } - file->u2.file_len = file_len; - file->u1.open_file = open_file; + file->file_len = file_len; + file->open_file = open_file; } /* @@ -695,7 +695,7 @@ struct dirent* vfat_readdir(struct file *dir) struct cache_struct *cs; struct fat_dir_entry *fat_dir; struct fat_long_name_entry *long_dir; - struct open_file_t *file = dir->u1.open_file; + struct open_file_t *file = dir->open_file; struct fs_info *fs = dir->fs; sector = file->file_sector; diff --git a/core/fs/iso9660/iso9660.c b/core/fs/iso9660/iso9660.c index 1ab6d049..f6f876f0 100644 --- a/core/fs/iso9660/iso9660.c +++ b/core/fs/iso9660/iso9660.c @@ -69,7 +69,7 @@ static inline void close_pvt(struct open_file_t *file) static void iso_close_file(struct file *file) { - close_pvt(file->u1.open_file); + close_pvt(file->open_file); } /* @@ -205,7 +205,7 @@ static uint32_t iso_getfssec(struct file *gfile, char *buf, int sectors, bool *have_more) { uint32_t bytes_read = sectors << ISO_SECTOR_SHIFT; - struct open_file_t *file = gfile->u1.open_file; + struct open_file_t *file = gfile->open_file; struct disk *disk = gfile->fs->fs_dev->disk; if ( sectors > file->file_left ) @@ -258,7 +258,7 @@ static int do_search_dir(struct fs_info *fs, struct dir_t *dir, file->file_sector = dir->dir_lba; xfile.fs = fs; - xfile.u1.open_file = file; + xfile.open_file = file; iso_getfssec(&xfile, trackbuf, BufSafe, &have_more); de = (struct iso_dir_entry *)trackbuf; @@ -428,8 +428,8 @@ static void iso_searchdir(char *filename, struct file *file) open_file = NULL; found: - file->u2.file_len = file_len; - file->u1.open_file = (void*)open_file; + file->file_len = file_len; + file->open_file = (void*)open_file; #if 0 if (open_file) { @@ -490,10 +490,10 @@ static int iso_fs_init(struct fs_info *fs) iso_dir = boot_dir; file.fs = fs; iso_searchdir(boot_dir, &file); /* search for /boot/isolinux */ - if ( !file.u2.file_len ) { + if ( !file.file_len ) { iso_dir = isolinux_dir; iso_searchdir(isolinux_dir, &file); /* search for /isolinux */ - if ( !file.u2.file_len ) { + if ( !file.file_len ) { printf("No isolinux directory found!\n"); return 0; } @@ -504,7 +504,7 @@ static int iso_fs_init(struct fs_info *fs) CurrentDirName[len] = '/'; CurrentDirName[len+1] = '\0'; - open_file = (struct open_file_t *)file.u1.open_file; + open_file = (struct open_file_t *)file.open_file; CurrentDir.dir_len = open_file->file_bytesleft; CurrentDir.dir_clust = open_file->file_left; CurrentDir.dir_lba = open_file->file_sector; diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c index 237f9430..eb8277b0 100644 --- a/core/fs/pxe/pxe.c +++ b/core/fs/pxe/pxe.c @@ -119,7 +119,7 @@ static void free_socket(struct open_file_t *file) static void pxe_close_file(struct file *file) { - struct open_file_t *open_file = file->u1.open_file; + struct open_file_t *open_file = file->open_file; if (open_file->tftp_localport && !open_file->tftp_goteof) tftp_error(open_file, 0, "No error, file close"); @@ -662,7 +662,7 @@ static void fill_buffer(struct open_file_t *file) static uint32_t pxe_getfssec(struct file *gfile, char *buf, int blocks, bool *have_more) { - struct open_file_t *file = gfile->u1.open_file; + struct open_file_t *file = gfile->open_file; int count = blocks; int chunk; int bytes_read = 0; @@ -748,8 +748,8 @@ static void pxe_searchdir(char *filename, struct file *file) open_file = allocate_socket(); if (!open_file) { - file->u2.file_len = 0; - file->u1.open_file = NULL; + file->file_len = 0; + file->open_file = NULL; return; } @@ -980,12 +980,12 @@ static void pxe_searchdir(char *filename, struct file *file) done: if (!open_file->tftp_filesize) { free_socket(open_file); - file->u2.file_len = 0; - file->u1.open_file = NULL; + file->file_len = 0; + file->open_file = NULL; return; } - file->u1.open_file = (void *)open_file; - file->u2.file_len = open_file->tftp_filesize; + file->open_file = (void *)open_file; + file->file_len = open_file->tftp_filesize; return; err_reply: diff --git a/core/include/fs.h b/core/include/fs.h index 35d46ed4..28b66793 100644 --- a/core/include/fs.h +++ b/core/include/fs.h @@ -86,13 +86,18 @@ struct open_file_t; struct file { struct fs_info *fs; union { - struct inode *inode; /* the file-specific information */ - struct open_file_t *open_file; - } u1; - union { - uint32_t offset; /* for next read */ - uint32_t file_len; - } u2; + /* For the new universal-path_lookup */ + struct { + struct inode *inode; /* The file-specific information */ + uint32_t offset; /* for next read */ + }; + + /* For the old searhdir method */ + struct { + struct open_file_t *open_file;/* The fs-specific open file struct */ + uint32_t file_len; + }; + }; }; |