summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-02-16 13:36:59 -0800
committerH. Peter Anvin <hpa@zytor.com>2010-02-16 13:36:59 -0800
commitaa7f4f0af8027e72914a12d12c6799e9243dfa69 (patch)
treecc6b18900f14dbddee9265b5d3a000508e423a97
parent362daa623200248b789ec6d4703070cb001cc929 (diff)
downloadsyslinux-aa7f4f0af8027e72914a12d12c6799e9243dfa69.tar.gz
cache: fix cache initialization
Fix the cache initialization; in particular make sure dev->cache_head actually gets set. Also, just use a plain division to figure out how many entries we can fit in the cache. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--core/fs/cache.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/core/fs/cache.c b/core/fs/cache.c
index 1dc4c300..0d7891be 100644
--- a/core/fs/cache.c
+++ b/core/fs/cache.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <string.h>
+#include <dprintf.h>
#include "core.h"
#include "cache.h"
@@ -19,37 +20,36 @@ void cache_init(struct device *dev, int block_size_shift)
{
struct cache *prev, *cur;
char *data = dev->cache_data;
- struct cache *cache_head, *cache;
+ struct cache *head, *cache;
int i;
dev->cache_block_size = 1 << block_size_shift;
- dev->cache_entries = dev->cache_size >> block_size_shift;
if (dev->cache_size < dev->cache_block_size + 2*sizeof(struct cache)) {
dev->cache_head = NULL;
return; /* Cache unusably small */
}
- while ((dev->cache_entries << block_size_shift) +
- ((dev->cache_entries+1) * sizeof(struct cache))
- > dev->cache_size)
- dev->cache_entries--;
+ /* We need one struct cache for the headnode plus one for each block */
+ dev->cache_entries =
+ (dev->cache_size - sizeof(struct cache))/
+ (dev->cache_block_size + sizeof(struct cache));
- cache_head = (struct cache *)
+ dev->cache_head = head = (struct cache *)
(data + (dev->cache_entries << block_size_shift));
- cache = cache_head + 1;
+ cache = dev->cache_head + 1; /* First cache descriptor */
- cache_head->prev = &cache[dev->cache_entries-1];
- cache_head->next->prev = cache_head;
- cache_head->block = (block_t)-1;
- cache_head->data = NULL;
+ head->prev = &cache[dev->cache_entries-1];
+ head->next->prev = dev->cache_head;
+ head->block = -1;
+ head->data = NULL;
- prev = cache_head;
+ prev = head;
for (i = 0; i < dev->cache_entries; i++) {
cur = &cache[i];
cur->data = data;
- cur->block = (block_t)-1;
+ cur->block = -1;
cur->prev = prev;
prev->next = cur;
data += dev->cache_block_size;