diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-06-22 14:18:22 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-06-22 14:18:22 +0000 |
commit | 88234fa9214870e618bacc94506fdbe0fc58acc1 (patch) | |
tree | 0187cc8dc5a0211e726425040f811b07a53fe714 /firmware/common | |
parent | 35cd408196c1fec3e576591a7698e8a87226fdb6 (diff) |
Fix loading dircache stat on h100. Relocating the data was broken due to struct alignment problems.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30051 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
-rw-r--r-- | firmware/common/dircache.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 27784ae369..375ffa63ec 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c @@ -567,7 +567,10 @@ int dircache_load(void) return -3; } - dircache_root = buffer_alloc(maindata.size + DIRCACHE_RESERVE); + allocated_size = maindata.size + DIRCACHE_RESERVE; + dircache_root = buffer_alloc(allocated_size); + /* needs to be struct-size aligned so that the pointer arithmetic below works */ + ALIGN_BUFFER(dircache_root, allocated_size, sizeof(struct dircache_entry)); entry_count = maindata.entry_count; appflags = maindata.appflags; @@ -583,8 +586,8 @@ int dircache_load(void) } /* continue with the d_names. Fix up pointers to them if needed */ - d_names_start = ((char*)&dircache_root[entry_count] + DIRCACHE_RESERVE); bytes_to_read = maindata.size - bytes_to_read; + d_names_start = (char*)dircache_root + allocated_size - bytes_to_read; bytes_read = read(fd, d_names_start, bytes_to_read); close(fd); remove_dircache_file(); @@ -594,7 +597,7 @@ int dircache_load(void) return -7; } - d_names_end = &d_names_start[bytes_read]; + d_names_end = d_names_start + bytes_read; dot = d_names_end - sizeof("."); dotdot = dot - sizeof(".."); @@ -627,7 +630,6 @@ int dircache_load(void) /* Cache successfully loaded. */ dircache_size = maindata.size; - allocated_size = dircache_size + DIRCACHE_RESERVE; reserve_used = 0; logf("Done, %ld KiB used", dircache_size / 1024); dircache_initialized = true; @@ -835,6 +837,7 @@ int dircache_build(int last_size) { allocated_size = last_size + DIRCACHE_RESERVE; dircache_root = buffer_alloc(allocated_size); + ALIGN_BUFFER(dircache_root, allocated_size, sizeof(struct dircache_entry)); d_names_start = d_names_end = ((char*)dircache_root)+allocated_size-1; dircache_size = 0; @@ -851,7 +854,7 @@ int dircache_build(int last_size) * and their corresponding d_name from the end * after generation the buffer will be compacted with DIRCACHE_RESERVE * free bytes inbetween */ - audiobuf = ALIGN_UP(audiobuf, sizeof(struct dircache_entry*)); + audiobuf = ALIGN_UP(audiobuf, sizeof(struct dircache_entry)); dircache_root = (struct dircache_entry*)audiobuf; d_names_start = d_names_end = audiobufend - 1; dircache_size = 0; |