1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 055f439..540f403 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -168,12 +168,6 @@ struct tagfile_entry {
     char tag_data[0];  /* Begin of the tag data */
 };

-/* Fixed-size tag entry in master db index. */
-struct index_entry {
-    int32_t tag_seek[TAG_COUNT]; /* Location of tag data or numeric tag data */
-    int32_t flag;                /* Status flags */
-};
-
 /* Header is the same in every file. */
 struct tagcache_header {
     int32_t magic;       /* Header version number */
@@ -204,7 +198,7 @@ static struct master_header current_tcmh;
 /* Header is created when loading database to ram. */
 struct ramcache_header {
     struct master_header h;      /* Header from the master index */
-    struct index_entry *indices; /* Master index file content */
+    struct tagcache_index_entry *indices; /* Master index file content */
     char *tags[TAG_COUNT];       /* Tag file content (not including filename tag) */
     int entry_count[TAG_COUNT];  /* Number of entries in the indices. */
 };
@@ -578,7 +572,7 @@ bool tagcache_find_index(struct tagcache_search *tcs, const char *filename)
 }

 static bool get_index(int masterfd, int idxid, 
-                      struct index_entry *idx, bool use_ram)
+                      struct tagcache_index_entry *idx, bool use_ram)
 {
     bool localfd = false;

@@ -594,7 +588,7 @@ static bool get_index(int masterfd, int idxid,
         if (hdr->indices[idxid].flag & FLAG_DELETED)
             return false;

-        memcpy(idx, &hdr->indices[idxid], sizeof(struct index_entry));
+        memcpy(idx, &hdr->indices[idxid], sizeof(struct tagcache_index_entry));
         return true;
     }
 #else
@@ -611,10 +605,10 @@ static bool get_index(int masterfd, int idxid,
             return false;
     }

-    lseek(masterfd, idxid * sizeof(struct index_entry) 
+    lseek(masterfd, idxid * sizeof(struct tagcache_index_entry)
           + sizeof(struct master_header), SEEK_SET);
     if (ecread(masterfd, idx, 1, index_entry_ec, tc_stat.econ) 
-        != sizeof(struct index_entry))
+        != sizeof(struct tagcache_index_entry))
     {
         logf("read error #3");
         if (localfd)
@@ -634,7 +628,7 @@ static bool get_index(int masterfd, int idxid,

 #ifndef __PCTOOL__

-static bool write_index(int masterfd, int idxid, struct index_entry *idx)
+static bool write_index(int masterfd, int idxid, struct tagcache_index_entry *idx)
 {
     /* We need to exclude all memory only flags & tags when writing to disk. */
     if (idx->flag & FLAG_DIRCACHE)
@@ -650,7 +644,7 @@ static bool write_index(int masterfd, int idxid, struct index_entry *idx)
     if (tc_stat.ramcache)
     {
         int tag;
-        struct index_entry *idx_ram = &hdr->indices[idxid];
+        struct tagcache_index_entry *idx_ram = &hdr->indices[idxid];

         for (tag = 0; tag < TAG_COUNT; tag++)
         {
@@ -666,10 +660,10 @@ static bool write_index(int masterfd, int idxid, struct index_entry *idx)
     }
 #endif

-    lseek(masterfd, idxid * sizeof(struct index_entry) 
+    lseek(masterfd, idxid * sizeof(struct tagcache_index_entry) 
           + sizeof(struct master_header), SEEK_SET);
     if (ecwrite(masterfd, idx, 1, index_entry_ec, tc_stat.econ) 
-        != sizeof(struct index_entry))
+        != sizeof(struct tagcache_index_entry))
     {
         logf("write error #3");
         logf("idxid: %d", idxid);
@@ -685,10 +679,8 @@ static bool open_files(struct tagcache_search *tcs, int tag)
 {
     if (tcs->idxfd[tag] < 0)
     {
-        char fn[MAX_PATH];
-
-        snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag);
-        tcs->idxfd[tag] = open(fn, O_RDONLY);
+        struct tagcache_header hdr;
+        tcs->idxfd[tag] = open_tag_fd(&hdr, tag, false);
     }

     if (tcs->idxfd[tag] < 0)
@@ -700,8 +692,9 @@ static bool open_files(struct tagcache_search *tcs, int tag)
     return true;
 }

-static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx, 
-                     int tag, char *buf, long size)
+bool tagcache_retrieve_index(struct tagcache_search *tcs,
+                             struct tagcache_index_entry *idx, int tag,
+                             char *buf, long size)
 {
     struct tagfile_entry tfe;
     long seek;
@@ -772,7 +765,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
     return true;
 }

-static long check_virtual_tags(int tag, const struct index_entry *idx)
+static long check_virtual_tags(int tag, const struct tagcache_index_entry *idx)
 {
     long data = 0;

@@ -822,7 +815,7 @@ static long check_virtual_tags(int tag, const struct index_entry *idx)

 long tagcache_get_numeric(const struct tagcache_search *tcs, int tag)
 {
-    struct index_entry idx;
+    struct tagcache_index_entry idx;

     if (!tc_stat.ready)
         return false;
@@ -927,7 +920,7 @@ static bool check_against_clause(long numeric, const char *str,
 }

 static bool check_clauses(struct tagcache_search *tcs,
-                          struct index_entry *idx,
+                          struct tagcache_index_entry *idx,
                           struct tagcache_search_clause **clause, int count)
 {
     int i;
@@ -949,7 +942,8 @@ static bool check_clauses(struct tagcache_search *tcs,
             {
                 if (clause[i]->tag == tag_filename)
                 {
-                    retrieve(tcs, idx, tag_filename, buf, sizeof buf);
+                    tagcache_retrieve_index(tcs, idx, tag_filename, buf,
+                                            sizeof buf);
                     str = buf;
                 }
                 else
@@ -1005,7 +999,7 @@ static bool check_clauses(struct tagcache_search *tcs,
 bool tagcache_check_clauses(struct tagcache_search *tcs,
                             struct tagcache_search_clause **clause, int count)
 {
-    struct index_entry idx;
+    struct tagcache_index_entry idx;

     if (count == 0)
         return true;
@@ -1046,7 +1040,7 @@ static bool add_uniqbuf(struct tagcache_search *tcs, unsigned long id)

 static bool build_lookup_list(struct tagcache_search *tcs)
 {
-    struct index_entry entry;
+    struct tagcache_index_entry entry;
     int i;

     tcs->seek_list_count = 0;
@@ -1058,7 +1052,7 @@ static bool build_lookup_list(struct tagcache_search *tcs)

         for (i = tcs->seek_pos; i < hdr->h.tch.entry_count; i++)
         {
-            struct index_entry *idx = &hdr->indices[i];
+            struct tagcache_index_entry *idx = &hdr->indices[i];
             if (tcs->seek_list_count == SEEK_LIST_SIZE)
                 break ;

@@ -1098,11 +1092,11 @@ static bool build_lookup_list(struct tagcache_search *tcs)
     }
 #endif

-    lseek(tcs->masterfd, tcs->seek_pos * sizeof(struct index_entry) +
+    lseek(tcs->masterfd, tcs->seek_pos * sizeof(struct tagcache_index_entry) +
             sizeof(struct master_header), SEEK_SET);

     while (ecread(tcs->masterfd, &entry, 1, index_entry_ec, tc_stat.econ) 
-           == sizeof(struct index_entry))
+           == sizeof(struct tagcache_index_entry))
     {
         if (tcs->seek_list_count == SEEK_LIST_SIZE)
             break ;
@@ -1464,16 +1458,22 @@ bool tagcache_get_next(struct tagcache_search *tcs)
     return false;
 }

+bool tagcache_get_index(struct tagcache_search *tcs, int idxid,
+                        struct tagcache_index_entry *idx)
+{
+    return get_index(tcs->masterfd, idxid, idx, true);
+}
+
 bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, 
                        int tag, char *buf, long size)
 {
-    struct index_entry idx;
+    struct tagcache_index_entry idx;

     *buf = '\0';
     if (!get_index(tcs->masterfd, idxid, &idx, true))
         return false;

-    return retrieve(tcs, &idx, tag, buf, size);
+    return tagcache_retrieve_index(tcs, &idx, tag, buf, size);
 }

 static bool update_master_header(void)
@@ -1561,17 +1561,17 @@ void tagcache_search_finish(struct tagcache_search *tcs)
 }

 #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
-static struct tagfile_entry *get_tag(const struct index_entry *entry, int tag)
+static struct tagfile_entry *get_tag(const struct tagcache_index_entry *entry, int tag)
 {
     return (struct tagfile_entry *)&hdr->tags[tag][entry->tag_seek[tag]];
 }

-static long get_tag_numeric(const struct index_entry *entry, int tag)
+static long get_tag_numeric(const struct tagcache_index_entry *entry, int tag)
 {
     return check_virtual_tags(tag, entry);
 }

-static char* get_tag_string(const struct index_entry *entry, int tag)
+static char* get_tag_string(const struct tagcache_index_entry *entry, int tag)
 {
     char* s = get_tag(entry, tag)->tag_data;
     return strcmp(s, UNTAGGED) ? s : NULL;
@@ -1579,7 +1579,7 @@ static char* get_tag_string(const struct index_entry *entry, int tag)

 bool tagcache_fill_tags(struct mp3entry *id3, const char *filename)
 {
-    struct index_entry *entry;
+    struct tagcache_index_entry *entry;
     int idx_id;

     if (!tc_stat.ready)
@@ -1702,7 +1702,7 @@ static void add_tagcache(char *path, unsigned long mtime
     /* Check if file has been modified. */
     if (idx_id >= 0)
     {
-        struct index_entry idx;
+        struct tagcache_index_entry idx;

         /* TODO: Mark that the index exists (for fast reverse scan) */
         //found_idx[idx_id/8] |= idx_id%8;
@@ -2061,7 +2061,7 @@ inline static int tempbuf_find_location(int id)
 static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
 {
     struct master_header tcmh;
-    struct index_entry idx;
+    struct tagcache_index_entry idx;
     int masterfd;
     int masterfd_pos;
     struct temp_file_entry *entrybuf = (struct temp_file_entry *)tempbuf;
@@ -2078,7 +2078,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
     if ( (masterfd = open_master_fd(&tcmh, true)) < 0)
         return false;

-    masterfd_pos = lseek(masterfd, tcmh.tch.entry_count * sizeof(struct index_entry),
+    masterfd_pos = lseek(masterfd, tcmh.tch.entry_count * sizeof(struct tagcache_index_entry),
                          SEEK_CUR);
     if (masterfd_pos == filesize(masterfd))
     {
@@ -2156,7 +2156,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
         {
             /* Read the index entry. */
             if (ecread(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 
-                != sizeof(struct index_entry))
+                != sizeof(struct tagcache_index_entry))
             {
                 logf("read fail #3");
                 close(masterfd);
@@ -2225,9 +2225,9 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
                 /* Avoid processing this entry again. */
                 idx.flag |= FLAG_RESURRECTED;

-                lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR);
+                lseek(masterfd, -sizeof(struct tagcache_index_entry), SEEK_CUR);
                 if (ecwrite(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 
-                    != sizeof(struct index_entry))
+                    != sizeof(struct tagcache_index_entry))
                 {
                     logf("masterfd writeback fail #1");
                     close(masterfd);
@@ -2248,7 +2248,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
             int loc = lseek(masterfd, 0, SEEK_CUR);

             if (ecread(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 
-                != sizeof(struct index_entry))
+                != sizeof(struct tagcache_index_entry))
             {
                 logf("read fail #3");
                 close(masterfd);
@@ -2278,7 +2278,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
             /* Write back the updated index. */
             lseek(masterfd, loc, SEEK_SET);
             if (ecwrite(masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 
-                != sizeof(struct index_entry))
+                != sizeof(struct tagcache_index_entry))
             {
                 logf("write fail");
                 close(masterfd);
@@ -2306,7 +2306,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
     int i;
     struct tagcache_header tch;
     struct master_header   tcmh;
-    struct index_entry idxbuf[IDX_BUF_DEPTH];
+    struct tagcache_index_entry idxbuf[IDX_BUF_DEPTH];
     int idxbuf_pos;
     char buf[TAG_MAXLEN+32];
     int fd = -1, masterfd;
@@ -2527,7 +2527,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
          * However, if the index is sorted, we need to update all tag
          * pointers in the master file for the current index.
          */
-        masterfd_pos = lseek(masterfd, tcmh.tch.entry_count * sizeof(struct index_entry),
+        masterfd_pos = lseek(masterfd, tcmh.tch.entry_count * sizeof(struct tagcache_index_entry),
             SEEK_CUR);
         if (masterfd_pos == filesize(masterfd))
         {
@@ -2612,7 +2612,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
             idxbuf_pos = MIN(tcmh.tch.entry_count - i, IDX_BUF_DEPTH);

             if (ecread(masterfd, idxbuf, idxbuf_pos, index_entry_ec, tc_stat.econ) 
-                != (int)sizeof(struct index_entry)*idxbuf_pos)
+                != (int)sizeof(struct tagcache_index_entry)*idxbuf_pos)
             {
                 logf("read fail #5");
                 error = true;
@@ -2647,7 +2647,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
             /* Write back the updated index. */
             if (ecwrite(masterfd, idxbuf, idxbuf_pos,
                         index_entry_ec, tc_stat.econ) !=
-                (int)sizeof(struct index_entry)*idxbuf_pos)
+                (int)sizeof(struct tagcache_index_entry)*idxbuf_pos)
             {
                 logf("write fail");
                 error = true;
@@ -2672,14 +2672,14 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
         idxbuf_pos = MIN(h->entry_count - i, IDX_BUF_DEPTH);
         if (init)
         {
-            memset(idxbuf, 0, sizeof(struct index_entry)*IDX_BUF_DEPTH);
+            memset(idxbuf, 0, sizeof(struct tagcache_index_entry)*IDX_BUF_DEPTH);
         }
         else
         {
             int loc = lseek(masterfd, 0, SEEK_CUR);

             if (ecread(masterfd, idxbuf, idxbuf_pos, index_entry_ec, tc_stat.econ) 
-                != (int)sizeof(struct index_entry)*idxbuf_pos)
+                != (int)sizeof(struct tagcache_index_entry)*idxbuf_pos)
             {
                 logf("read fail #6");
                 error = true;
@@ -2753,7 +2753,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
         /* Write index. */
         if (ecwrite(masterfd, idxbuf, idxbuf_pos,
                   index_entry_ec, tc_stat.econ) !=
-            (int)sizeof(struct index_entry)*idxbuf_pos)
+            (int)sizeof(struct tagcache_index_entry)*idxbuf_pos)
         {
             logf("tagcache: write fail #4");
             error = true;
@@ -2934,7 +2934,7 @@ static bool commit(void)

     tcmh.tch.entry_count += tch.entry_count;
     tcmh.tch.datasize = sizeof(struct master_header) 
-        + sizeof(struct index_entry) * tcmh.tch.entry_count
+        + sizeof(struct tagcache_index_entry) * tcmh.tch.entry_count
         + tch.datasize;
     tcmh.dirty = false;
     tcmh.commitid++;
@@ -3001,7 +3001,7 @@ static void free_tempbuf(void)

 static bool modify_numeric_entry(int masterfd, int idx_id, int tag, long data)
 {
-    struct index_entry idx;
+    struct tagcache_index_entry idx;

     if (!tc_stat.ready)
         return false;
@@ -3271,7 +3271,7 @@ static bool read_tag(char *dest, long size,

 static int parse_changelog_line(int line_n, const char *buf, void *parameters)
 {
-    struct index_entry idx;
+    struct tagcache_index_entry idx;
     char tag_data[TAG_MAXLEN+32];
     int idx_id;
     long masterfd = (long)parameters;
@@ -3388,7 +3388,7 @@ bool tagcache_import_changelog(void)
 bool tagcache_create_changelog(struct tagcache_search *tcs)
 {
     struct master_header myhdr;
-    struct index_entry idx;
+    struct tagcache_index_entry idx;
     char buf[TAG_MAXLEN+32];
     char temp[32];
     int clfd;
@@ -3424,7 +3424,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
     for (i = 0; i < myhdr.tch.entry_count; i++)
     {
         if (ecread(tcs->masterfd, &idx, 1, index_entry_ec, tc_stat.econ) 
-            != sizeof(struct index_entry))
+            != sizeof(struct tagcache_index_entry))
         {
             logf("read error #9");
             tagcache_search_finish(tcs);
@@ -3471,7 +3471,7 @@ static bool delete_entry(long idx_id)
     int fd = -1;
     int masterfd = -1;
     int tag, i;
-    struct index_entry idx, myidx;
+    struct tagcache_index_entry idx, myidx;
     struct master_header myhdr;
     char buf[TAG_MAXLEN+32];
     int in_use[TAG_COUNT];
@@ -3487,9 +3487,9 @@ static bool delete_entry(long idx_id)
     if ( (masterfd = open_master_fd(&myhdr, true) ) < 0)
         return false;

-    lseek(masterfd, idx_id * sizeof(struct index_entry), SEEK_CUR);
+    lseek(masterfd, idx_id * sizeof(struct tagcache_index_entry), SEEK_CUR);
     if (ecread(masterfd, &myidx, 1, index_entry_ec, tc_stat.econ)
-        != sizeof(struct index_entry))
+        != sizeof(struct tagcache_index_entry))
     {
         logf("delete_entry(): read error");
         goto cleanup;
@@ -3502,9 +3502,9 @@ static bool delete_entry(long idx_id)
     }

     myidx.flag |= FLAG_DELETED;
-    lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR);
+    lseek(masterfd, -sizeof(struct tagcache_index_entry), SEEK_CUR);
     if (ecwrite(masterfd, &myidx, 1, index_entry_ec, tc_stat.econ)
-        != sizeof(struct index_entry))
+        != sizeof(struct tagcache_index_entry))
     {
         logf("delete_entry(): write_error #1");
         goto cleanup;
@@ -3517,7 +3517,7 @@ static bool delete_entry(long idx_id)
     lseek(masterfd, sizeof(struct master_header), SEEK_SET);
     for (i = 0; i < myhdr.tch.entry_count; i++)
     {
-        struct index_entry *idxp;
+        struct tagcache_index_entry *idxp;

 #ifdef HAVE_TC_RAMCACHE
         /* Use RAM DB if available for greater speed */
@@ -3527,7 +3527,7 @@ static bool delete_entry(long idx_id)
 #endif
         {
             if (ecread(masterfd, &idx, 1, index_entry_ec, tc_stat.econ)
-                != sizeof(struct index_entry))
+                != sizeof(struct tagcache_index_entry))
             {
                 logf("delete_entry(): read error #2");
                 goto cleanup;
@@ -3646,9 +3646,9 @@ static bool delete_entry(long idx_id)

     /* Write index entry back into master index. */
     lseek(masterfd, sizeof(struct master_header) +
-          (idx_id * sizeof(struct index_entry)), SEEK_SET);
+          (idx_id * sizeof(struct tagcache_index_entry)), SEEK_SET);
     if (ecwrite(masterfd, &myidx, 1, index_entry_ec, tc_stat.econ)
-        != sizeof(struct index_entry))
+        != sizeof(struct tagcache_index_entry))
     {
         logf("delete_entry(): write_error #2");
         goto cleanup;
@@ -3715,7 +3715,7 @@ static bool allocate_tagcache(void)
     hdr = buffer_alloc(tc_stat.ramcache_allocated + 128);
     memset(hdr, 0, sizeof(struct ramcache_header));
     memcpy(&hdr->h, &tcmh, sizeof(struct master_header));
-    hdr->indices = (struct index_entry *)(hdr + 1);
+    hdr->indices = (struct tagcache_index_entry *)(hdr + 1);
     logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated);

     return true;
@@ -3765,7 +3765,7 @@ static bool tagcache_dumpload(void)
     memcpy(&tc_stat, &shdr.tc_stat, sizeof(struct tagcache_stat));

     /* Now fix the pointers */
-    hdr->indices = (struct index_entry *)((long)hdr->indices + offpos);
+    hdr->indices = (struct tagcache_index_entry *)((long)hdr->indices + offpos);
     for (i = 0; i < TAG_COUNT; i++)
         hdr->tags[i] += offpos;

@@ -3804,7 +3804,7 @@ static bool load_tagcache(void)
 {
     struct tagcache_header *tch;
     long bytesleft = tc_stat.ramcache_allocated;
-    struct index_entry *idx;
+    struct tagcache_index_entry *idx;
     int rc, fd;
     char *p;
     int i, tag;
@@ -3839,14 +3839,14 @@ static bool load_tagcache(void)
     for (i = 0; i < hdr->h.tch.entry_count; i++)
     {
         rc = ecread(fd, idx, 1, index_entry_ec, tc_stat.econ);
-        if (rc != sizeof(struct index_entry))
+        if (rc != sizeof(struct tagcache_index_entry))
         {
             logf("read error #10");
             close(fd);
             return false;
         }

-        bytesleft -= sizeof(struct index_entry);
+        bytesleft -= sizeof(struct tagcache_index_entry);
         if (bytesleft < 0 || ((long)idx - (long)hdr->indices) >= tc_stat.ramcache_allocated)
         {
             logf("too big tagcache.");
diff --git a/apps/tagcache.h b/apps/tagcache.h
index e995784..812af2a 100644
--- a/apps/tagcache.h
+++ b/apps/tagcache.h
@@ -144,6 +144,12 @@ struct tagcache_search_clause
     char *str;
 };

+/* Fixed-size tag entry in master db index. */
+struct tagcache_index_entry {
+    int32_t tag_seek[TAG_COUNT]; /* Location of tag data or numeric tag data */
+    int32_t flag;                /* Status flags */
+};
+
 struct tagcache_search {
     /* For internal use only. */
     int fd, masterfd;
@@ -216,6 +222,11 @@ void tagcache_shutdown(void);

 void tagcache_screensync_event(void);
 void tagcache_screensync_enable(bool state);
+bool tagcache_get_index(struct tagcache_search *tcs, int idxid,
+                        struct tagcache_index_entry *idx);
+bool tagcache_retrieve_index(struct tagcache_search *tcs,
+                             struct tagcache_index_entry *idx, int tag,
+                             char *buf, long size);

 #ifdef HAVE_TC_RAMCACHE
 bool tagcache_is_ramcache(void);