aboutsummaryrefslogtreecommitdiffstats
path: root/cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/cache.c b/cache.c
index bfcdf29..6fdbd25 100644
--- a/cache.c
+++ b/cache.c
@@ -1,5 +1,6 @@
#include "cache.h"
#include <stdio.h>
+#include <fcntl.h>
#include <malloc.h>
@@ -13,6 +14,7 @@
*/
struct cache_struct cache[CACHE_ENTRIES + 1] = {0,};
+extern int blk_size;
/**
* cache_init:
@@ -29,7 +31,7 @@ void cache_init(void)
prev = &cache[CACHE_ENTRIES];
for ( i = 0; i < CACHE_ENTRIES + 1; i++ ) {
- cur->sector = 0;
+ cur->block = 0;
cur->prev = prev;
prev->next = cur;
cur->data = NULL;
@@ -43,25 +45,25 @@ void cache_init(void)
/**
- * get_cache_sector:
+ * get_cache_block:
*
- * Check for a particular SECTOR in the sector cache,
+ * 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.
*
- * @param: sector, the sector number we want check.
+ * @param: block, the block number we want check.
* @retrun: return the most recent cache structure pointer
*
*/
-struct cache_struct * get_cache_sector(int sector)
+struct cache_struct * get_cache_block(__u32 block)
{
struct cache_struct *cs = &cache[1];
struct cache_struct *head, *last;
int i;
for ( i = 0; i < CACHE_ENTRIES; i ++ ) {
- if ( cs->sector == sector )
+ if ( cs->block == block )
goto hit;
else
cs = &cache[i + 1];
@@ -69,14 +71,11 @@ struct cache_struct * get_cache_sector(int sector)
/* we missed it here, so we need to load it */
miss:
- /* free the first cache's buffer first */
- if ( cache[0].next->data)
- free(cache[0].next->data);
/* store it at head of real cache */
cs = cache[0].next;
- cs->sector = sector;
- cs->data = (void*)getonesec(sector);
+ cs->block = block;
+ cs->data = (void*)getoneblk(block);
hit:
/* remove cs from current position in list */