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);