From 885eb9695a0ef17f929589777eb2b0eeeec61459 Mon Sep 17 00:00:00 2001 From: Yuanhan Liu Date: Tue, 20 Oct 2009 21:03:16 +0800 Subject: [PATCH] Last code cleanup I really hope it's thelast code cleanup:) Signed-off-by: Yuanhan Liu --- core/cache.c | 49 ++++++++++++++--------------------------------- core/diskio.c | 38 ++++-------------------------------- core/fs.c | 6 +++--- core/fs/ext2/ext2.c | 19 +++--------------- core/fs/iso9660/iso9660.c | 8 ++------ core/fs/pxe/dhcp_option.c | 40 ++++++++++++++++++-------------------- 6 files changed, 45 insertions(+), 115 deletions(-) diff --git a/core/cache.c b/core/cache.c index c55f160..4307b78 100644 --- a/core/cache.c +++ b/core/cache.c @@ -1,24 +1,18 @@ -#include "core.h" -#include "cache.h" +/* + * core/cache.c: A simple LRU-based cache implementation. + * + */ + #include #include +#include "core.h" +#include "cache.h" -/** - * Each CachePtr contains: - * - Block pointer - * - LRU previous pointer - * - LRU next pointer - * - Block data buffer address - * - * The cache buffer are pointed to by a cache_head structure. - */ - -/** - * cache_init: - * - * Initialize the cache data structres. - * regs->eax.l stores the block size(in bits not bytes) +/* + * Initialize the cache data structres. the _block_size_shift_ specify + * the block size, which is 512 byte for FAT fs of the current + * implementation since the block(cluster) size in FAT is a bit big. * */ void cache_init(struct device *dev, int block_size_shift) @@ -50,25 +44,10 @@ void cache_init(struct device *dev, int block_size_shift) } -/** - * get_cache_block: - * +/* * Check for a particular BLOCK in the block cache, * and if it is already there, just do nothing and return; - * otherwise load it and updata the relative cache - * structre with data pointer. - * - * it's a test version for my start of merging extlinux into core. - * and after I have figured out how to handle the relations between - * rm and pm, c and asm, we call call it from C file, so no need - * com32sys_t *regs any more. - * - * I just found that I was tring to do a stupid thing! - * I haven't change the fs code to c, so for now the cache is based - * on SECTOR SIZE but not block size. While we can fix it easily by - * make the block size be the sector size. - * - * @return: the data stores at gs:si + * otherwise load it from disk and updata the LRU link. * */ struct cache_struct* get_cache_block(struct device *dev, block_t block) @@ -136,7 +115,7 @@ struct cache_struct* get_cache_block(struct device *dev, block_t block) } -/** +/* * Just print the sector, and according the LRU algorithm, * Left most value is the most least secotr, and Right most * value is the most Recent sector. I see it's a Left Right Used diff --git a/core/diskio.c b/core/diskio.c index c51f722..b34d82f 100644 --- a/core/diskio.c +++ b/core/diskio.c @@ -2,9 +2,9 @@ #include #include #include -#include "core.h" -#include "fs.h" -#include "disk.h" +#include +#include +#include #define RETRY_COUNT 6 @@ -17,7 +17,7 @@ static int chs_rdwr_sectors(struct disk *disk, void *buf, char *tptr; size_t chunk, freeseg; int sector_shift = disk->sector_shift; - uint32_t xlba = lba + disk->part_start; /* Truncated LBA (CHS is << 2 TB) */ + uint32_t xlba = lba + disk->part_start; /* Truncated LBA (CHS is << 2 TB) */ uint32_t t; uint16_t c, h, s; com32sys_t ireg, oreg; @@ -232,20 +232,6 @@ void getoneblk(struct disk *disk, char *buf, block_t block, int block_size) disk->rdwr_sectors(disk, buf, block * sec_per_block, sec_per_block, 0); } -static void dump_disk(struct disk *disk) -{ - printf("drive number: 0x%x\n", disk->disk_number); - printf("disk type: %s(%d)\n", disk->type ? "EDD" : "CHS", disk->type); - printf("sector size: %d(%d)\n", disk->sector_size, disk->sector_shift); - printf("h: %d\ts: %d\n", disk->h, disk->s); - printf("offset: %d\n", disk->part_start); - printf("%s\n", disk->rdwr_sectors == edd_rdwr_sectors ? "EDD_RDWR_SECTORS" : - "CHS_RDWR_SECTORS"); - printf("--------------------------------\n"); - printf("disk->rdwr_sectors@: %p\n", disk->rdwr_sectors); - printf("edd_rdwr_sectors @: %p\n", edd_rdwr_sectors); - printf("chs_rdwr_sectors @: %p\n", chs_rdwr_sectors); -} struct disk *disk_init(uint8_t devno, bool cdrom, sector_t part_start, uint16_t bsHeads, uint16_t bsSecPerTrack) @@ -305,9 +291,6 @@ struct disk *disk_init(uint8_t devno, bool cdrom, sector_t part_start, disk.part_start = part_start; disk.rdwr_sectors = ebios ? edd_rdwr_sectors : chs_rdwr_sectors; -#if 0 - dump_disk(&disk); -#endif return &disk; } @@ -337,16 +320,3 @@ struct device * device_init(uint8_t devno, bool cdrom, sector_t part_start, return &dev; } - - -/* debug function */ -static void dump_dev(struct device *dev) -{ - printf("device type:%s\n", dev->disk->type ? "EDD" : "CHS"); - printf("drive number: 0x%x\n", dev->disk->disk_number); - printf("cache_data: %p\n", dev->cache_data); - printf("cache_head: %p\n", dev->cache_head); - printf("cache_block_size: %d\n", dev->cache_block_size); - printf("cache_entries: %d\n", dev->cache_entries); - printf("cache_size: %d\n", dev->cache_size); -} diff --git a/core/fs.c b/core/fs.c index a3407cf..ed023af 100644 --- a/core/fs.c +++ b/core/fs.c @@ -1,8 +1,8 @@ #include #include #include -#include "fs.h" -#include "cache.h" +#include +#include /* The currently mounted filesystem */ struct fs_info *this_fs = NULL; @@ -161,7 +161,7 @@ void close_file(com32sys_t *regs) * set up the vfs fs structure; * initialize the device structure; * invoke the fs-specific init function; - * finally, initialize the cache + * finally, initialize the cache if we need one * */ void fs_init(com32sys_t *regs) diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c index 8c44b3a..e0f289e 100644 --- a/core/fs/ext2/ext2.c +++ b/core/fs/ext2/ext2.c @@ -403,9 +403,7 @@ static void getlinsec_ext(struct fs_info *fs, char *buf, disk->rdwr_sectors(disk, buf, sector, sector_cnt, 0); } -/** - * getfssec: - * +/* * Get multiple sectors from a file * * Alought we have made the buffer data based on block size, @@ -413,15 +411,6 @@ static void getlinsec_ext(struct fs_info *fs, char *buf, * sectors (then can be multiple blocks) is what the function * do. So, let it be based on sectors. * - * This function can be called from C function, and either from - * ASM function. - * - * @param: ES:BX(of regs), the buffer to store data - * @param: DS:SI(of regs), the pointer to open_file_t - * @param: CX(of regs), number of sectors to read - * - * @return: ECX(of regs), number of bytes read - * */ static uint32_t ext2_getfssec(struct file *gfile, char *buf, int sectors, bool *have_more) @@ -481,10 +470,8 @@ static uint32_t ext2_getfssec(struct file *gfile, char *buf, -/** - * find_dir_entry: - * - * find a dir entry, if find return it or return NULL +/* + * find a dir entry, return it if found, or return NULL. * */ static struct ext2_dir_entry* diff --git a/core/fs/iso9660/iso9660.c b/core/fs/iso9660/iso9660.c index e060b13..6918a7f 100644 --- a/core/fs/iso9660/iso9660.c +++ b/core/fs/iso9660/iso9660.c @@ -58,9 +58,7 @@ static struct open_file_t *allocate_file(void) } -/** - * close_file: - * +/* * Deallocates a file structure * */ @@ -372,9 +370,7 @@ static int do_search_dir(struct fs_info *fs, struct dir_t *dir, /* * open a file * - * searchdir_iso is a special entry point for ISOLINUX only. In addition - * to the above, searchdir_iso passes a file flag mask in AL. This is - * useful for searching for directories. + * searchdir_iso is a special entry point for ISOLINUX only. * * well, it's not like the searchidr function in EXT fs or FAT fs; it also * can read a diretory.(Just thought of mine, liu) diff --git a/core/fs/pxe/dhcp_option.c b/core/fs/pxe/dhcp_option.c index 7935f8b..0787078 100644 --- a/core/fs/pxe/dhcp_option.c +++ b/core/fs/pxe/dhcp_option.c @@ -224,28 +224,26 @@ void parse_dhcp_options(void *option, int size, int filter) } /* + * parse_dhcp * - ; - ; parse_dhcp - ; - ; Parse a DHCP packet. This includes dealing with "overloaded" - ; option fields (see RFC 2132, section 9.3) - ; - ; This should fill in the following global variables, if the - ; information is present: - ; - ; MyIP - client IP address - ; server_ip - boot server IP address - ; net_mask - network mask - ; gate_way - default gateway router IP - ; boot_file - boot file name - ; DNSServers - DNS server IPs - ; LocalDomain - Local domain name - ; MAC_len, MAC - Client identifier, if MAC_len == 0 - ; - ; This assumes the DHCP packet is in "trackbuf". - ; -*/ + * Parse a DHCP packet. This includes dealing with "overloaded" + * option fields (see RFC 2132, section 9.3) + * + * This should fill in the following global variables, if the + * information is present: + * + * MyIP - client IP address + * server_ip - boot server IP address + * net_mask - network mask + * gate_way - default gateway router IP + * boot_file - boot file name + * DNSServers - DNS server IPs + * LocalDomain - Local domain name + * MAC_len, MAC - Client identifier, if MAC_len == 0 + * + * This assumes the DHCP packet is in "trackbuf". + * + */ void parse_dhcp(int pkt_len) { struct bootp_t *dhcp = (struct bootp_t *)trackbuf; -- 2.7.4