summaryrefslogtreecommitdiff
path: root/firmware/common/dircache.c
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-08-05 20:19:10 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-08-05 20:19:10 +0000
commit954b73265404075ec4d379ddea14e626113a8677 (patch)
tree5c6ff0056ebd118aadb896856e7679a41c595cba /firmware/common/dircache.c
parent85ba65d2a3fa3d10799efadbe3a33f026bf354df (diff)
Initial support and use for EEPROM memory on H120 & H140 players when
Rockbox firmware has been flashed over original firmware (not yet possible to do). Dircache & tagcache serialization for fast bootup without the need to scan disk when Rockbox is in flash. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10464 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common/dircache.c')
-rw-r--r--firmware/common/dircache.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 6167aa3933..d2c77a2e25 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -402,7 +402,7 @@ static struct dircache_entry* dircache_get_entry(const char *path,
return cache_entry;
}
-#if 0
+#if 1
/**
* Function to load the internal cache structure from disk to initialize
* the dircache really fast and little disk access.
@@ -423,32 +423,41 @@ int dircache_load(const char *path)
if (fd < 0)
return -2;
- dircache_root = (struct dircache_entry *)(((long)audiobuf & ~0x03) + 0x04);
bytes_read = read(fd, &maindata, sizeof(struct dircache_maindata));
if (bytes_read != sizeof(struct dircache_maindata)
- || (long)maindata.root_entry != (long)dircache_root
|| maindata.size <= 0)
{
+ logf("Dircache file header error");
close(fd);
return -3;
}
+ dircache_root = buffer_alloc(0);
+ if ((long)maindata.root_entry != (long)dircache_root)
+ {
+ logf("Position missmatch");
+ close(fd);
+ return -4;
+ }
+
+ dircache_root = buffer_alloc(maindata.size + DIRCACHE_RESERVE);
entry_count = maindata.entry_count;
bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size));
close(fd);
if (bytes_read != maindata.size)
+ {
+ logf("Dircache read failed");
return -6;
+ }
/* Cache successfully loaded. */
dircache_size = maindata.size;
+ allocated_size = dircache_size + DIRCACHE_RESERVE;
+ reserve_used = 0;
logf("Done, %d KiB used", dircache_size / 1024);
dircache_initialized = true;
memset(fd_bindings, 0, sizeof(fd_bindings));
-
- /* We have to long align the audiobuf to keep the buffer access fast. */
- audiobuf += (long)((dircache_size & ~0x03) + 0x04);
- audiobuf += DIRCACHE_RESERVE;
return 0;
}
@@ -472,7 +481,7 @@ int dircache_save(const char *path)
return -1;
logf("Saving directory cache");
- fd = open(path, O_WRONLY | O_CREAT);
+ fd = open(path, O_WRONLY | O_CREAT | O_TRUNC);
maindata.magic = DIRCACHE_MAGIC;
maindata.size = dircache_size;
@@ -484,6 +493,7 @@ int dircache_save(const char *path)
if (bytes_written != sizeof(struct dircache_maindata))
{
close(fd);
+ logf("dircache: write failed #1");
return -2;
}
@@ -491,8 +501,11 @@ int dircache_save(const char *path)
bytes_written = write(fd, dircache_root, dircache_size);
close(fd);
if (bytes_written != dircache_size)
+ {
+ logf("dircache: write failed #2");
return -3;
-
+ }
+
return 0;
}
#endif /* #if 0 */
@@ -616,6 +629,7 @@ int dircache_build(int last_size)
return -3;
logf("Building directory cache");
+ /* Background build, dircache has been previously allocated */
if (dircache_size > 0)
{
thread_enabled = true;