summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c150
1 files changed, 78 insertions, 72 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 2b6041227b..df252ca0bc 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -90,6 +90,10 @@
90 90
91#undef HAVE_DIRCACHE 91#undef HAVE_DIRCACHE
92 92
93#ifdef HAVE_DIRCACHE
94#include "dircache.h"
95#endif
96
93#ifdef __PCTOOL__ 97#ifdef __PCTOOL__
94#define yield() do { } while(0) 98#define yield() do { } while(0)
95#define sim_sleep(timeout) do { } while(0) 99#define sim_sleep(timeout) do { } while(0)
@@ -112,6 +116,9 @@ static long tempbufidx; /* Current location in buffer. */
112static size_t tempbuf_size; /* Buffer size (TEMPBUF_SIZE). */ 116static size_t tempbuf_size; /* Buffer size (TEMPBUF_SIZE). */
113static long tempbuf_left; /* Buffer space left. */ 117static long tempbuf_left; /* Buffer space left. */
114static long tempbuf_pos; 118static long tempbuf_pos;
119#ifndef __PCTOOL__
120static int tempbuf_handle;
121#endif
115 122
116#define SORTED_TAGS_COUNT 8 123#define SORTED_TAGS_COUNT 8
117#define TAGCACHE_IS_UNIQUE(tag) (BIT_N(tag) & TAGCACHE_UNIQUE_TAGS) 124#define TAGCACHE_IS_UNIQUE(tag) (BIT_N(tag) & TAGCACHE_UNIQUE_TAGS)
@@ -289,17 +296,6 @@ static ssize_t ecwrite_index_entry(int fd, struct index_entry *buf)
289 return ecwrite(fd, buf, 1, index_entry_ec, tc_stat.econ); 296 return ecwrite(fd, buf, 1, index_entry_ec, tc_stat.econ);
290} 297}
291 298
292#ifdef HAVE_DIRCACHE
293/**
294 * Returns true if specified flag is still present, i.e., dircache
295 * has not been reloaded.
296 */
297static bool is_dircache_intact(void)
298{
299 return dircache_get_appflag(DIRCACHE_APPFLAG_TAGCACHE);
300}
301#endif
302
303static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) 299static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write)
304{ 300{
305 int fd; 301 int fd;
@@ -434,7 +430,7 @@ static long find_entry_ram(const char *filename, int dc)
434 430
435 return -1; 431 return -1;
436} 432}
437#endif 433#endif /* defined (HAVE_TC_RAMCACHE) && defined (HAVE_DIRCACHE) */
438 434
439static long find_entry_disk(const char *filename_raw, bool localfd) 435static long find_entry_disk(const char *filename_raw, bool localfd)
440{ 436{
@@ -590,7 +586,7 @@ static bool get_index(int masterfd, int idxid,
590 if (ramcache_hdr->indices[idxid].flag & FLAG_DELETED) 586 if (ramcache_hdr->indices[idxid].flag & FLAG_DELETED)
591 return false; 587 return false;
592 588
593# ifdef HAVE_DIRCACHE 589#ifdef HAVE_DIRCACHE
594 if (!(ramcache_hdr->indices[idxid].flag & FLAG_DIRCACHE) 590 if (!(ramcache_hdr->indices[idxid].flag & FLAG_DIRCACHE)
595 || is_dircache_intact()) 591 || is_dircache_intact())
596#endif 592#endif
@@ -599,8 +595,6 @@ static bool get_index(int masterfd, int idxid,
599 return true; 595 return true;
600 } 596 }
601 } 597 }
602#else
603 (void)use_ram;
604#endif 598#endif
605 599
606 if (masterfd < 0) 600 if (masterfd < 0)
@@ -632,6 +626,8 @@ static bool get_index(int masterfd, int idxid,
632 return false; 626 return false;
633 627
634 return true; 628 return true;
629
630 (void)use_ram;
635} 631}
636 632
637#ifndef __PCTOOL__ 633#ifndef __PCTOOL__
@@ -724,7 +720,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
724 { 720 {
725 struct tagfile_entry *ep; 721 struct tagfile_entry *ep;
726 722
727# ifdef HAVE_DIRCACHE 723#ifdef HAVE_DIRCACHE
728 if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE)) 724 if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE))
729 { 725 {
730 /* for tag_filename, seek is a dircache index */ 726 /* for tag_filename, seek is a dircache index */
@@ -745,7 +741,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
745 } 741 }
746 } 742 }
747 else 743 else
748# endif 744#endif /* HAVE_DIRCACHE */
749 if (tag != tag_filename) 745 if (tag != tag_filename)
750 { 746 {
751 ep = (struct tagfile_entry *)&ramcache_hdr->tags[tag][seek]; 747 ep = (struct tagfile_entry *)&ramcache_hdr->tags[tag][seek];
@@ -1511,8 +1507,7 @@ static bool get_next(struct tagcache_search *tcs)
1511#ifdef HAVE_TC_RAMCACHE 1507#ifdef HAVE_TC_RAMCACHE
1512 if (tcs->ramsearch) 1508 if (tcs->ramsearch)
1513 { 1509 {
1514 1510#ifdef HAVE_DIRCACHE
1515#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
1516 if (tcs->type == tag_filename && (flag & FLAG_DIRCACHE)) 1511 if (tcs->type == tag_filename && (flag & FLAG_DIRCACHE))
1517 { 1512 {
1518 if (is_dircache_intact()) 1513 if (is_dircache_intact())
@@ -1537,7 +1532,7 @@ static bool get_next(struct tagcache_search *tcs)
1537 } 1532 }
1538 } 1533 }
1539 else 1534 else
1540#endif 1535#endif /* HAVE_DIRCACHE */
1541 if (tcs->type != tag_filename) 1536 if (tcs->type != tag_filename)
1542 { 1537 {
1543 struct tagfile_entry *ep; 1538 struct tagfile_entry *ep;
@@ -1766,6 +1761,13 @@ bool tagcache_fill_tags(struct mp3entry *id3, const char *filename)
1766 1761
1767 return true; 1762 return true;
1768} 1763}
1764#elif defined (HAVE_TC_RAMCACHE)
1765/* temporary dummy function until integration is sorted out --jethead71 */
1766bool tagcache_fill_tags(struct mp3entry *id3, const char *filename)
1767{
1768 return false;
1769 (void)id3; (void)filename;
1770}
1769#endif 1771#endif
1770 1772
1771static inline void write_item(const char *item) 1773static inline void write_item(const char *item)
@@ -2982,27 +2984,25 @@ static bool commit(void)
2982#ifdef HAVE_TC_RAMCACHE 2984#ifdef HAVE_TC_RAMCACHE
2983 tc_stat.ramcache = false; 2985 tc_stat.ramcache = false;
2984#endif 2986#endif
2985 2987
2988 /* Beyond here, jump to commit_error to undo locks and restore dircache */
2989 rc = false;
2986 read_lock++; 2990 read_lock++;
2987 2991
2988 /* Try to steal every buffer we can :) */ 2992 /* Try to steal every buffer we can :) */
2989 if (tempbuf_size == 0) 2993 if (tempbuf_size == 0)
2990 local_allocation = true; 2994 local_allocation = true;
2991 2995
2992#if 0 /* FIXME: How much big? dircache buffer can no longer be taken but
2993 may be freed to make room and the cache resumed. --jethead71 */
2994#ifdef HAVE_DIRCACHE 2996#ifdef HAVE_DIRCACHE
2995 if (tempbuf_size == 0) 2997 if (tempbuf_size == 0)
2996 { 2998 {
2997 /* Shut down dircache to free its allocation. */ 2999 /* Suspend dircache to free its allocation. */
2998 dircache_free_buffer(); 3000 dircache_free_buffer();
2999 if (tempbuf_size > 0) 3001 dircache_buffer_stolen = true;
3000 { 3002
3001 dircache_buffer_stolen = true; 3003 allocate_tempbuf();
3002 }
3003 } 3004 }
3004#endif 3005#endif /* HAVE_DIRCACHE */
3005#endif
3006 3006
3007#ifdef HAVE_TC_RAMCACHE 3007#ifdef HAVE_TC_RAMCACHE
3008 if (tempbuf_size == 0 && tc_stat.ramcache_allocated > 0) 3008 if (tempbuf_size == 0 && tc_stat.ramcache_allocated > 0)
@@ -3021,8 +3021,7 @@ static bool commit(void)
3021 logf("delaying commit until next boot"); 3021 logf("delaying commit until next boot");
3022 tc_stat.commit_delayed = true; 3022 tc_stat.commit_delayed = true;
3023 close(tmpfd); 3023 close(tmpfd);
3024 read_lock--; 3024 goto commit_error;
3025 return false;
3026 } 3025 }
3027 3026
3028 logf("commit %ld entries...", tch.entry_count); 3027 logf("commit %ld entries...", tch.entry_count);
@@ -3053,8 +3052,7 @@ static bool commit(void)
3053 tc_stat.commit_delayed = true; 3052 tc_stat.commit_delayed = true;
3054 3053
3055 tc_stat.commit_step = 0; 3054 tc_stat.commit_step = 0;
3056 read_lock--; 3055 goto commit_error;
3057 return false;
3058 } 3056 }
3059 } 3057 }
3060 3058
@@ -3063,8 +3061,7 @@ static bool commit(void)
3063 logf("Failure to commit numeric indices"); 3061 logf("Failure to commit numeric indices");
3064 close(tmpfd); 3062 close(tmpfd);
3065 tc_stat.commit_step = 0; 3063 tc_stat.commit_step = 0;
3066 read_lock--; 3064 goto commit_error;
3067 return false;
3068 } 3065 }
3069 3066
3070 close(tmpfd); 3067 close(tmpfd);
@@ -3073,10 +3070,7 @@ static bool commit(void)
3073 3070
3074 /* Update the master index headers. */ 3071 /* Update the master index headers. */
3075 if ( (masterfd = open_master_fd(&tcmh, true)) < 0) 3072 if ( (masterfd = open_master_fd(&tcmh, true)) < 0)
3076 { 3073 goto commit_error;
3077 read_lock--;
3078 return false;
3079 }
3080 3074
3081 remove(TAGCACHE_FILE_TEMP); 3075 remove(TAGCACHE_FILE_TEMP);
3082 3076
@@ -3101,39 +3095,53 @@ static bool commit(void)
3101 tempbuf_size = 0; 3095 tempbuf_size = 0;
3102 } 3096 }
3103 3097
3104#ifdef HAVE_DIRCACHE
3105 /* Rebuild the dircache, if we stole the buffer. */
3106 if (dircache_buffer_stolen)
3107 dircache_resume();
3108#endif
3109
3110#ifdef HAVE_TC_RAMCACHE 3098#ifdef HAVE_TC_RAMCACHE
3111 if (ramcache_buffer_stolen) 3099 if (ramcache_buffer_stolen)
3100 {
3101 ramcache_buffer_stolen = false;
3112 move_lock--; 3102 move_lock--;
3103 }
3104
3113 /* Reload tagcache. */ 3105 /* Reload tagcache. */
3114 if (tc_stat.ramcache_allocated > 0) 3106 if (tc_stat.ramcache_allocated > 0)
3115 tagcache_start_scan(); 3107 tagcache_start_scan();
3116#endif 3108#endif
3117 3109
3110 rc = true;
3111
3112commit_error:
3113#ifdef HAVE_TC_RAMCACHE
3114 if (ramcache_buffer_stolen)
3115 move_lock--;
3116#endif
3117
3118 read_lock--; 3118 read_lock--;
3119
3120 return true;
3121}
3122 3119
3123#ifndef __PCTOOL__ 3120#ifdef HAVE_DIRCACHE
3124static int tempbuf_handle; 3121 /* Resume the dircache, if we stole the buffer. */
3122 if (dircache_buffer_stolen)
3123 dircache_resume();
3125#endif 3124#endif
3125
3126 return rc;
3127}
3126 3128
3127static void allocate_tempbuf(void) 3129static void allocate_tempbuf(void)
3128{ 3130{
3129 /* Yeah, malloc would be really nice now :) */ 3131 /* Yeah, malloc would be really nice now :) */
3132 size_t size;
3133 tempbuf_size = 0;
3134
3130#ifdef __PCTOOL__ 3135#ifdef __PCTOOL__
3131 tempbuf_size = 32*1024*1024; 3136 size = 32*1024*1024;
3132 tempbuf = malloc(tempbuf_size); 3137 tempbuf = malloc(size);
3133#else 3138#else
3134 tempbuf_handle = core_alloc_maximum("tc tempbuf", &tempbuf_size, NULL); 3139 tempbuf_handle = core_alloc_maximum("tc tempbuf", &size, NULL);
3135 tempbuf = core_get_data(tempbuf_handle); 3140 tempbuf = core_get_data(tempbuf_handle);
3136#endif 3141#endif
3142
3143 if (tempbuf)
3144 tempbuf_size = size;
3137} 3145}
3138 3146
3139static void free_tempbuf(void) 3147static void free_tempbuf(void)
@@ -4133,9 +4141,14 @@ static bool load_tagcache(void)
4133 goto failure; 4141 goto failure;
4134 } 4142 }
4135 4143
4136# ifdef HAVE_DIRCACHE 4144 if (global_settings.tagcache_autoupdate)
4137 if (dircache_is_enabled())
4138 { 4145 {
4146 /* Check if entry has been removed. */
4147 #ifdef HAVE_DIRCACHE
4148 /* This will be very slow unless dircache is enabled
4149 or target is flash based. */
4150##################
4151 if (dircache_search( /* will get this! -- jethead71 */
4139 dc = dircache_get_entry_id(buf); 4152 dc = dircache_get_entry_id(buf);
4140 if (dc < 0) 4153 if (dc < 0)
4141 { 4154 {
@@ -4148,24 +4161,17 @@ static bool load_tagcache(void)
4148 4161
4149 idx->flag |= FLAG_DIRCACHE; 4162 idx->flag |= FLAG_DIRCACHE;
4150 idx->tag_seek[tag_filename] = dc; 4163 idx->tag_seek[tag_filename] = dc;
4151 } 4164 #else /* ndef HAVE_DIRCACHE */
4152 else 4165 /* This will be very slow unless target is flash based;
4153# endif 4166 do it anyway for consistency. */
4154 { 4167 if (!file_exists(buf))
4155 /* This will be very slow unless dircache is enabled
4156 or target is flash based, but do it anyway for
4157 consistency. */
4158 /* Check if entry has been removed. */
4159 if (global_settings.tagcache_autoupdate)
4160 { 4168 {
4161 if (!file_exists(buf)) 4169 logf("Entry no longer valid.");
4162 { 4170 logf("-> %s", buf);
4163 logf("Entry no longer valid."); 4171 delete_entry(fe->idx_id);
4164 logf("-> %s", buf); 4172 continue;
4165 delete_entry(fe->idx_id);
4166 continue;
4167 }
4168 } 4173 }
4174 #endif /* HAVE_DIRCACHE */
4169 } 4175 }
4170 4176
4171 continue ; 4177 continue ;