From: H. Peter Anvin Date: Tue, 16 Feb 2010 21:36:59 +0000 (-0800) Subject: cache: fix cache initialization X-Git-Tag: syslinux-4.00-pre24~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa7f4f0af8027e72914a12d12c6799e9243dfa69;p=platform%2Fupstream%2Fsyslinux.git 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 --- diff --git a/core/fs/cache.c b/core/fs/cache.c index 1dc4c30..0d7891b 100644 --- a/core/fs/cache.c +++ b/core/fs/cache.c @@ -5,6 +5,7 @@ #include #include +#include #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;