summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/tagcache.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 973cc9314e..6ad8f118a1 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -206,7 +206,6 @@ 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. */
208struct ramcache_header { 208struct ramcache_header {
209 struct master_header h; /* Header from the master index */
210 struct index_entry *indices; /* Master index file content */ 209 struct index_entry *indices; /* Master index file content */
211 char *tags[TAG_COUNT]; /* Tag file content (not including filename tag) */ 210 char *tags[TAG_COUNT]; /* Tag file content (not including filename tag) */
212 int entry_count[TAG_COUNT]; /* Number of entries in the indices. */ 211 int entry_count[TAG_COUNT]; /* Number of entries in the indices. */
@@ -214,6 +213,7 @@ struct ramcache_header {
214 213
215# ifdef HAVE_EEPROM_SETTINGS 214# ifdef HAVE_EEPROM_SETTINGS
216struct statefile_header { 215struct statefile_header {
216 struct master_header mh; /* Header from the master index */
217 struct ramcache_header *hdr; 217 struct ramcache_header *hdr;
218 struct tagcache_stat tc_stat; 218 struct tagcache_stat tc_stat;
219}; 219};
@@ -409,7 +409,7 @@ static long find_entry_ram(const char *filename,
409 else 409 else
410 i = 0; 410 i = 0;
411 411
412 for (; i < hdr->h.tch.entry_count; i++) 412 for (; i < current_tcmh.tch.entry_count; i++)
413 { 413 {
414 if (hdr->indices[i].tag_seek[tag_filename] == (long)dc) 414 if (hdr->indices[i].tag_seek[tag_filename] == (long)dc)
415 { 415 {
@@ -1119,7 +1119,7 @@ static bool build_lookup_list(struct tagcache_search *tcs)
1119# endif 1119# endif
1120 ) 1120 )
1121 { 1121 {
1122 for (i = tcs->seek_pos; i < hdr->h.tch.entry_count; i++) 1122 for (i = tcs->seek_pos; i < current_tcmh.tch.entry_count; i++)
1123 { 1123 {
1124 struct tagcache_seeklist_entry *seeklist; 1124 struct tagcache_seeklist_entry *seeklist;
1125 struct index_entry *idx = &hdr->indices[i]; 1125 struct index_entry *idx = &hdr->indices[i];
@@ -1596,15 +1596,6 @@ static bool update_master_header(void)
1596 ecwrite(fd, &myhdr, 1, master_header_ec, tc_stat.econ); 1596 ecwrite(fd, &myhdr, 1, master_header_ec, tc_stat.econ);
1597 close(fd); 1597 close(fd);
1598 1598
1599#ifdef HAVE_TC_RAMCACHE
1600 if (hdr)
1601 {
1602 hdr->h.serial = current_tcmh.serial;
1603 hdr->h.commitid = current_tcmh.commitid;
1604 hdr->h.dirty = current_tcmh.dirty;
1605 }
1606#endif
1607
1608 return true; 1599 return true;
1609} 1600}
1610 1601
@@ -3362,6 +3353,7 @@ static bool read_tag(char *dest, long size,
3362 3353
3363 src++; 3354 src++;
3364 } 3355 }
3356
3365 dest[pos] = '\0'; 3357 dest[pos] = '\0';
3366 3358
3367 if (!strcasecmp(tagstr, current_tag)) 3359 if (!strcasecmp(tagstr, current_tag))
@@ -3813,7 +3805,7 @@ static bool allocate_tagcache(void)
3813 sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); 3805 sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *);
3814 hdr = buffer_alloc(tc_stat.ramcache_allocated + 128); 3806 hdr = buffer_alloc(tc_stat.ramcache_allocated + 128);
3815 memset(hdr, 0, sizeof(struct ramcache_header)); 3807 memset(hdr, 0, sizeof(struct ramcache_header));
3816 memcpy(&hdr->h, &tcmh, sizeof(struct master_header)); 3808 memcpy(&current_tcmh, &tcmh, sizeof current_tcmh);
3817 hdr->indices = (struct index_entry *)(hdr + 1); 3809 hdr->indices = (struct index_entry *)(hdr + 1);
3818 logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); 3810 logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated);
3819 3811
@@ -3839,7 +3831,7 @@ static bool tagcache_dumpload(void)
3839 hdr = buffer_alloc(0); 3831 hdr = buffer_alloc(0);
3840 rc = read(fd, &shdr, sizeof(struct statefile_header)); 3832 rc = read(fd, &shdr, sizeof(struct statefile_header));
3841 if (rc != sizeof(struct statefile_header) 3833 if (rc != sizeof(struct statefile_header)
3842 /* || (long)hdr != (long)shdr.hdr */) 3834 || shdr.mh.tch.magic != TAGCACHE_MAGIC)
3843 { 3835 {
3844 logf("incorrect statefile"); 3836 logf("incorrect statefile");
3845 hdr = NULL; 3837 hdr = NULL;
@@ -3868,6 +3860,9 @@ static bool tagcache_dumpload(void)
3868 for (i = 0; i < TAG_COUNT; i++) 3860 for (i = 0; i < TAG_COUNT; i++)
3869 hdr->tags[i] += offpos; 3861 hdr->tags[i] += offpos;
3870 3862
3863 /* Load the tagcache master header (should match the actual DB file header). */
3864 memcpy(&current_tcmh, &shdr.mh, sizeof current_tcmh);
3865
3871 return true; 3866 return true;
3872} 3867}
3873 3868
@@ -3888,8 +3883,9 @@ static bool tagcache_dumpsave(void)
3888 3883
3889 /* Create the header */ 3884 /* Create the header */
3890 shdr.hdr = hdr; 3885 shdr.hdr = hdr;
3891 memcpy(&shdr.tc_stat, &tc_stat, sizeof(struct tagcache_stat)); 3886 memcpy(&shdr.mh, &current_tcmh, sizeof current_tcmh);
3892 write(fd, &shdr, sizeof(struct statefile_header)); 3887 memcpy(&shdr.tc_stat, &tc_stat, sizeof tc_stat);
3888 write(fd, &shdr, sizeof shdr);
3893 3889
3894 /* And dump the data too */ 3890 /* And dump the data too */
3895 write(fd, hdr, tc_stat.ramcache_allocated); 3891 write(fd, hdr, tc_stat.ramcache_allocated);
@@ -3902,6 +3898,7 @@ static bool tagcache_dumpsave(void)
3902static bool load_tagcache(void) 3898static bool load_tagcache(void)
3903{ 3899{
3904 struct tagcache_header *tch; 3900 struct tagcache_header *tch;
3901 struct master_header tcmh;
3905 long bytesleft = tc_stat.ramcache_allocated; 3902 long bytesleft = tc_stat.ramcache_allocated;
3906 struct index_entry *idx; 3903 struct index_entry *idx;
3907 int rc, fd; 3904 int rc, fd;
@@ -3924,18 +3921,21 @@ static bool load_tagcache(void)
3924 return false; 3921 return false;
3925 } 3922 }
3926 3923
3927 if (ecread(fd, &hdr->h, 1, master_header_ec, tc_stat.econ) 3924 if (ecread(fd, &tcmh, 1, master_header_ec, tc_stat.econ)
3928 != sizeof(struct master_header) 3925 != sizeof(struct master_header)
3929 || hdr->h.tch.magic != TAGCACHE_MAGIC) 3926 || tcmh.tch.magic != TAGCACHE_MAGIC)
3930 { 3927 {
3931 logf("incorrect header"); 3928 logf("incorrect header");
3932 return false; 3929 return false;
3933 } 3930 }
3934 3931
3932 /* Master header copy should already match, this can be redundant to do. */
3933 memcpy(&current_tcmh, &tcmh, sizeof current_tcmh);
3934
3935 idx = hdr->indices; 3935 idx = hdr->indices;
3936 3936
3937 /* Load the master index table. */ 3937 /* Load the master index table. */
3938 for (i = 0; i < hdr->h.tch.entry_count; i++) 3938 for (i = 0; i < tcmh.tch.entry_count; i++)
3939 { 3939 {
3940 rc = ecread_index_entry(fd, idx); 3940 rc = ecread_index_entry(fd, idx);
3941 if (rc != sizeof(struct index_entry)) 3941 if (rc != sizeof(struct index_entry))
@@ -4476,7 +4476,7 @@ void tagcache_build(const char *path)
4476 if (hdr) 4476 if (hdr)
4477 { 4477 {
4478 /* Import runtime statistics if we just initialized the db. */ 4478 /* Import runtime statistics if we just initialized the db. */
4479 if (hdr->h.serial == 0) 4479 if (current_tcmh.serial == 0)
4480 queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0); 4480 queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0);
4481 } 4481 }
4482#endif 4482#endif
@@ -4664,7 +4664,7 @@ static int get_progress(void)
4664#ifdef HAVE_TC_RAMCACHE 4664#ifdef HAVE_TC_RAMCACHE
4665 { 4665 {
4666 if (hdr && tc_stat.ramcache) 4666 if (hdr && tc_stat.ramcache)
4667 total_count = hdr->h.tch.entry_count; 4667 total_count = current_tcmh.tch.entry_count;
4668 } 4668 }
4669#endif 4669#endif
4670 4670