From: Liu Aleaxander Date: Wed, 3 Jun 2009 20:50:06 +0000 (+0800) Subject: CORE: Add two new file, disk.c, disk.h X-Git-Tag: syslinux-4.00-pre1~40 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3dff5c8ba164f7c244cf72a49ac5997efe06e07a;p=profile%2Fivi%2Fsyslinux.git CORE: Add two new file, disk.c, disk.h extract the sector read functions to disk.c, and add SECTOR_SHIFT, SECTOR_SIZE stuff in the disk.h as asked by hpa. --- diff --git a/core/cache.c b/core/cache.c index 0ddf944..debd5b5 100644 --- a/core/cache.c +++ b/core/cache.c @@ -1,11 +1,11 @@ #include "core.h" #include "cache.h" - +#include "disk.h" #include #include -/* +/** * Each CachePtr contains: * - Block pointer * - LRU previous pointer @@ -15,7 +15,6 @@ * The cache buffer are pointed to by a cache_head structure. */ - static struct cache_struct cache_head, cache[MAX_CACHE_ENTRIES]; static int cache_block_size; static int cache_entries; @@ -55,31 +54,6 @@ void cache_init(com32sys_t * regs) } -void read_sectors(char *buf, int sector_num, int sectors) -{ - com32sys_t regs; - - memset(®s, 0, sizeof(regs) ); - regs.eax.l = sector_num; - regs.ebp.l = sectors; - regs.es = SEG(core_xfer_buf); - regs.ebx.w[0] = OFFS(core_xfer_buf); - - call16(getlinsec, ®s, NULL); - - memcpy(buf, core_xfer_buf, sectors << 9); -} - - -void getoneblk(char *buf, uint32_t block, int block_size) -{ - int sec_per_block = block_size >> 9; /* 512==sector size */ - - read_sectors(buf, block * sec_per_block, sec_per_block); -} - - - /** * get_cache_block: * @@ -132,24 +106,19 @@ void get_cache_block(com32sys_t * regs) cs = cs->prev; } - if ( i == cache_entries ) { - /* missed, so we need to load it */ - + /* missed, so we need to load it */ + if ( i == cache_entries ) { /* store it at the head of real cache */ - cs = cache_head.next; - + cs = cache_head.next; cs->block = block; getoneblk(cs->data, block, cache_block_size); missed ++; } - - /* remove cs from current position in list */ cs->prev->next = cs->next; - cs->next->prev = cs->prev; - + cs->next->prev = cs->prev; /* add to just before head node */ last = cache_head.prev; @@ -158,13 +127,11 @@ void get_cache_block(com32sys_t * regs) last->next = cs; cs->prev = last; head->prev = cs; - cs->next = head; + cs->next = head; out: - - total_read ++; - #if 0 /* testing how efficiency the cache is */ + total_read ++; if ( total_read % 5 == 0 ) printf("total_read %d\tmissed %d\n", total_read, missed); #endif diff --git a/core/disk.c b/core/disk.c new file mode 100644 index 0000000..1a25d87 --- /dev/null +++ b/core/disk.c @@ -0,0 +1,28 @@ +#include +#include +#include "core.h" +#include "disk.h" + +void read_sectors(char *buf, int sector_num, int sectors) +{ + com32sys_t regs; + + memset(®s, 0, sizeof regs); + regs.eax.l = sector_num; + regs.ebp.l = sectors; + regs.es = SEG(core_xfer_buf); + regs.ebx.w[0] = OFFS(core_xfer_buf); + call16(getlinsec, ®s, NULL); + + memcpy(buf, core_xfer_buf, sectors << SECTOR_SHIFT); +} + + +void getoneblk(char *buf, uint32_t block, int block_size) +{ + int sec_per_block = block_size >> SECTOR_SHIFT; + + read_sectors(buf, block * sec_per_block, sec_per_block); +} + + diff --git a/core/ext2.c b/core/ext2.c index 5491f81..3cd2782 100644 --- a/core/ext2.c +++ b/core/ext2.c @@ -1,7 +1,7 @@ #include #include - #include "core.h" +#include "disk.h" #include "ext2_fs.h" @@ -11,14 +11,11 @@ */ void init_fs(com32sys_t *regs) { - extern uint16_t ClustByteShift, ClustShift; extern uint32_t SecPerClust, ClustSize, ClustMask; extern uint32_t PtrsPerBlock1, PtrsPerBlock2; extern char SuperBlock[1024]; - - struct ext2_super_block *sb; - + struct ext2_super_block *sb; /* read the super block */ read_sectors(SuperBlock, 2, 2); @@ -26,17 +23,17 @@ void init_fs(com32sys_t *regs) ClustByteShift = sb->s_log_block_size + 10; ClustSize = 1 << ClustByteShift; - ClustShift = ClustByteShift - 9; + ClustShift = ClustByteShift - SECTOR_SHIFT; //DescPerBlock = ClustSize >> ext2_group_desc_lg2size; //InodePerBlock = ClustSize / sb->s_inode_size; - SecPerClust = ClustSize >> 9; + SecPerClust = ClustSize >> SECTOR_SHIFT; ClustMask = SecPerClust - 1; PtrsPerBlock1 = 1 << ( ClustByteShift - 2 ); PtrsPerBlock2 = 1 << ( (ClustByteShift - 2) * 2); //PtrsPerBlock3 = 1 << ( (ClustByteShift - 2) * 3); - regs->eax.l = 9; + regs->eax.l = SECTOR_SHIFT; } diff --git a/core/include/disk.h b/core/include/disk.h new file mode 100644 index 0000000..e99e3cb --- /dev/null +++ b/core/include/disk.h @@ -0,0 +1,11 @@ +#ifndef DISK_H +#define DISK_H + +#define SECTOR_SHIFT 9 +#define SECTOR_SIZE (1 << SECTOR_SHIFT) + + +extern void read_sectors(char *, int, int); +extern void get_cache_block(com32sys_t *); + +#endif /* DISK_H */