diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tagcache.c | 13 | ||||
-rw-r--r-- | apps/tagcache.h | 3 |
2 files changed, 10 insertions, 6 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index f2423243b7..089bba13aa 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -206,15 +206,16 @@ static struct master_header current_tcmh; | |||
206 | #ifdef HAVE_TC_RAMCACHE | 206 | #ifdef HAVE_TC_RAMCACHE |
207 | /* Header is created when loading database to ram. */ | 207 | /* Header is created when loading database to ram. */ |
208 | struct ramcache_header { | 208 | struct ramcache_header { |
209 | struct index_entry *indices; /* Master index file content */ | ||
210 | char *tags[TAG_COUNT]; /* Tag file content (not including filename tag) */ | 209 | char *tags[TAG_COUNT]; /* Tag file content (not including filename tag) */ |
211 | int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ | 210 | int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ |
211 | struct index_entry indices[0]; /* Master index file content */ | ||
212 | }; | 212 | }; |
213 | 213 | ||
214 | # ifdef HAVE_EEPROM_SETTINGS | 214 | # ifdef HAVE_EEPROM_SETTINGS |
215 | struct statefile_header { | 215 | struct statefile_header { |
216 | int32_t magic; /* Statefile version number */ | ||
216 | struct master_header mh; /* Header from the master index */ | 217 | struct master_header mh; /* Header from the master index */ |
217 | struct ramcache_header *hdr; | 218 | struct ramcache_header *hdr; /* Old load address of hdr for relocation */ |
218 | struct tagcache_stat tc_stat; | 219 | struct tagcache_stat tc_stat; |
219 | }; | 220 | }; |
220 | # endif | 221 | # endif |
@@ -3793,7 +3794,6 @@ static bool allocate_tagcache(void) | |||
3793 | hdr = buffer_alloc(tc_stat.ramcache_allocated + 128); | 3794 | hdr = buffer_alloc(tc_stat.ramcache_allocated + 128); |
3794 | memset(hdr, 0, sizeof(struct ramcache_header)); | 3795 | memset(hdr, 0, sizeof(struct ramcache_header)); |
3795 | memcpy(¤t_tcmh, &tcmh, sizeof current_tcmh); | 3796 | memcpy(¤t_tcmh, &tcmh, sizeof current_tcmh); |
3796 | hdr->indices = (struct index_entry *)(hdr + 1); | ||
3797 | logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); | 3797 | logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); |
3798 | 3798 | ||
3799 | return true; | 3799 | return true; |
@@ -3818,6 +3818,7 @@ static bool tagcache_dumpload(void) | |||
3818 | hdr = buffer_alloc(0); | 3818 | hdr = buffer_alloc(0); |
3819 | rc = read(fd, &shdr, sizeof(struct statefile_header)); | 3819 | rc = read(fd, &shdr, sizeof(struct statefile_header)); |
3820 | if (rc != sizeof(struct statefile_header) | 3820 | if (rc != sizeof(struct statefile_header) |
3821 | || shdr.magic != TAGCACHE_STATEFILE_MAGIC | ||
3821 | || shdr.mh.tch.magic != TAGCACHE_MAGIC) | 3822 | || shdr.mh.tch.magic != TAGCACHE_MAGIC) |
3822 | { | 3823 | { |
3823 | logf("incorrect statefile"); | 3824 | logf("incorrect statefile"); |
@@ -3843,7 +3844,6 @@ static bool tagcache_dumpload(void) | |||
3843 | memcpy(&tc_stat, &shdr.tc_stat, sizeof(struct tagcache_stat)); | 3844 | memcpy(&tc_stat, &shdr.tc_stat, sizeof(struct tagcache_stat)); |
3844 | 3845 | ||
3845 | /* Now fix the pointers */ | 3846 | /* Now fix the pointers */ |
3846 | hdr->indices = (struct index_entry *)((long)hdr->indices + offpos); | ||
3847 | for (i = 0; i < TAG_COUNT; i++) | 3847 | for (i = 0; i < TAG_COUNT; i++) |
3848 | hdr->tags[i] += offpos; | 3848 | hdr->tags[i] += offpos; |
3849 | 3849 | ||
@@ -3869,6 +3869,7 @@ static bool tagcache_dumpsave(void) | |||
3869 | } | 3869 | } |
3870 | 3870 | ||
3871 | /* Create the header */ | 3871 | /* Create the header */ |
3872 | shdr.magic = TAGCACHE_STATEFILE_MAGIC; | ||
3872 | shdr.hdr = hdr; | 3873 | shdr.hdr = hdr; |
3873 | memcpy(&shdr.mh, ¤t_tcmh, sizeof current_tcmh); | 3874 | memcpy(&shdr.mh, ¤t_tcmh, sizeof current_tcmh); |
3874 | memcpy(&shdr.tc_stat, &tc_stat, sizeof tc_stat); | 3875 | memcpy(&shdr.tc_stat, &tc_stat, sizeof tc_stat); |
@@ -3924,6 +3925,8 @@ static bool load_tagcache(void) | |||
3924 | /* Load the master index table. */ | 3925 | /* Load the master index table. */ |
3925 | for (i = 0; i < tcmh.tch.entry_count; i++) | 3926 | for (i = 0; i < tcmh.tch.entry_count; i++) |
3926 | { | 3927 | { |
3928 | /* DEBUG: After tagcache commit and dircache rebuild, hdr-sturcture | ||
3929 | * may become corrupt. */ | ||
3927 | rc = ecread_index_entry(fd, idx); | 3930 | rc = ecread_index_entry(fd, idx); |
3928 | if (rc != sizeof(struct index_entry)) | 3931 | if (rc != sizeof(struct index_entry)) |
3929 | { | 3932 | { |
@@ -3997,8 +4000,6 @@ static bool load_tagcache(void) | |||
3997 | int dc; | 4000 | int dc; |
3998 | # endif | 4001 | # endif |
3999 | 4002 | ||
4000 | // FIXME: This is wrong! | ||
4001 | // idx = &hdr->indices[hdr->entry_count[i]]; | ||
4002 | idx = &hdr->indices[fe->idx_id]; | 4003 | idx = &hdr->indices[fe->idx_id]; |
4003 | 4004 | ||
4004 | if (fe->tag_length >= (long)sizeof(buf)-1) | 4005 | if (fe->tag_length >= (long)sizeof(buf)-1) |
diff --git a/apps/tagcache.h b/apps/tagcache.h index 6f23bfcb0d..1dad012ebe 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h | |||
@@ -52,6 +52,9 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, | |||
52 | /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */ | 52 | /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */ |
53 | #define TAGCACHE_MAGIC 0x5443480e | 53 | #define TAGCACHE_MAGIC 0x5443480e |
54 | 54 | ||
55 | /* Dump store/restore header version 'TCSxx'. */ | ||
56 | #define TAGCACHE_STATEFILE_MAGIC 0x54435301 | ||
57 | |||
55 | /* How much to allocate extra space for ramcache. */ | 58 | /* How much to allocate extra space for ramcache. */ |
56 | #define TAGCACHE_RESERVE 32768 | 59 | #define TAGCACHE_RESERVE 32768 |
57 | 60 | ||