[syslinux:pathbased] cache: fix cache initialization

syslinux-bot for H. Peter Anvin hpa at zytor.com
Tue Feb 16 13:39:19 PST 2010


Commit-ID:  aa7f4f0af8027e72914a12d12c6799e9243dfa69
Gitweb:     http://syslinux.zytor.com/commit/aa7f4f0af8027e72914a12d12c6799e9243dfa69
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Tue, 16 Feb 2010 13:36:59 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Tue, 16 Feb 2010 13:36:59 -0800

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 at zytor.com>


---
 core/fs/cache.c |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

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 <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;



More information about the Syslinux-commits mailing list