From 5d5542981d5c22a841fcdfe222a17e42b7a9954d Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 29 May 2011 03:16:19 +0200 Subject: [PATCH 6/7] Dircache: Move struct maindata declaration to dircache.c and actually check for DIRCACHE_MAGIC when loading from disk. --- firmware/common/dircache.c | 13 ++++++++++++- firmware/include/dircache.h | 10 ---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 56c408e..0f3c453 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c @@ -503,6 +503,17 @@ static struct dircache_entry* dircache_get_entry(const char *path, bool go_down) } #ifdef HAVE_EEPROM_SETTINGS + +#define DIRCACHE_MAGIC 0x00d0c0a1 +struct dircache_maindata { + long magic; + long size; + long entry_count; + long appflags; + struct dircache_entry *root_entry; + char *d_names_start; +}; + /** * Function to load the internal cache structure from disk to initialize * the dircache really fast and little disk access. @@ -525,7 +536,7 @@ int dircache_load(void) bytes_read = read(fd, &maindata, sizeof(struct dircache_maindata)); if (bytes_read != sizeof(struct dircache_maindata) - || maindata.size <= 0) + || maindata.magic != DIRCACHE_MAGIC || maindata.size <= 0) { logf("Dircache file header error"); close(fd); diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h index d04c176..908165c 100644 --- a/firmware/include/dircache.h +++ b/firmware/include/dircache.h @@ -47,16 +47,6 @@ struct travel_data { int pathpos; }; -#define DIRCACHE_MAGIC 0x00d0c0a1 -struct dircache_maindata { - long magic; - long size; - long entry_count; - long appflags; - struct dircache_entry *root_entry; - char *d_names_start; -}; - #define MAX_PENDING_BINDINGS 2 struct fdbind_queue { char path[MAX_PATH]; -- 1.7.4.4