#include "core.h"
#include "cache.h"
-
+#include "disk.h"
#include <stdio.h>
#include <string.h>
-/*
+/**
* Each CachePtr contains:
* - Block pointer
* - LRU previous pointer
* 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;
}
-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:
*
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;
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
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#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);
+}
+
+
#include <stdio.h>
#include <string.h>
-
#include "core.h"
+#include "disk.h"
#include "ext2_fs.h"
*/
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);
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;
}
--- /dev/null
+#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 */