diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings.h | 6 | ||||
-rw-r--r-- | apps/tagcache.c | 270 | ||||
-rw-r--r-- | apps/tagcache.h | 9 |
3 files changed, 179 insertions, 106 deletions
diff --git a/apps/settings.h b/apps/settings.h index 079fd29649..7b70ab748c 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -37,8 +37,14 @@ | |||
37 | #include "backlight.h" /* for [MIN|MAX]_BRIGHTNESS_SETTING */ | 37 | #include "backlight.h" /* for [MIN|MAX]_BRIGHTNESS_SETTING */ |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #ifdef __PCTOOL__ | ||
41 | #define ROCKBOX_DIR "." | ||
42 | #define ROCKBOX_DIR_LEN 1 | ||
43 | #else | ||
40 | #define ROCKBOX_DIR "/.rockbox" | 44 | #define ROCKBOX_DIR "/.rockbox" |
41 | #define ROCKBOX_DIR_LEN 9 | 45 | #define ROCKBOX_DIR_LEN 9 |
46 | #endif | ||
47 | |||
42 | #define FONT_DIR ROCKBOX_DIR "/fonts" | 48 | #define FONT_DIR ROCKBOX_DIR "/fonts" |
43 | #define LANG_DIR ROCKBOX_DIR "/langs" | 49 | #define LANG_DIR ROCKBOX_DIR "/langs" |
44 | #define WPS_DIR ROCKBOX_DIR "/wps" | 50 | #define WPS_DIR ROCKBOX_DIR "/wps" |
diff --git a/apps/tagcache.c b/apps/tagcache.c index d8684bd989..4739291aa8 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -61,26 +61,37 @@ | |||
61 | #include "logf.h" | 61 | #include "logf.h" |
62 | #include "string.h" | 62 | #include "string.h" |
63 | #include "usb.h" | 63 | #include "usb.h" |
64 | #include "dircache.h" | ||
65 | #include "metadata.h" | 64 | #include "metadata.h" |
66 | #include "id3.h" | 65 | #include "id3.h" |
67 | #include "settings.h" | ||
68 | #include "splash.h" | ||
69 | #include "lang.h" | ||
70 | #include "tagcache.h" | 66 | #include "tagcache.h" |
71 | #include "buffer.h" | 67 | #include "buffer.h" |
72 | #include "atoi.h" | ||
73 | #include "crc32.h" | 68 | #include "crc32.h" |
74 | #include "eeprom_settings.h" | ||
75 | #include "misc.h" | 69 | #include "misc.h" |
70 | #include "settings.h" | ||
71 | #include "dircache.h" | ||
72 | #ifndef __PCTOOL__ | ||
73 | #include "atoi.h" | ||
74 | #include "splash.h" | ||
75 | #include "lang.h" | ||
76 | #include "eeprom_settings.h" | ||
77 | #endif | ||
76 | 78 | ||
79 | #ifdef __PCTOOL__ | ||
80 | #include <ctype.h> | ||
81 | #define yield() do { } while(0) | ||
82 | #define sim_sleep(timeout) do { } while(0) | ||
83 | #endif | ||
84 | |||
85 | |||
86 | #ifndef __PCTOOL__ | ||
77 | /* Tag Cache thread. */ | 87 | /* Tag Cache thread. */ |
78 | static struct event_queue tagcache_queue; | 88 | static struct event_queue tagcache_queue; |
79 | static long tagcache_stack[(DEFAULT_STACK_SIZE + 0x4000)/sizeof(long)]; | 89 | static long tagcache_stack[(DEFAULT_STACK_SIZE + 0x4000)/sizeof(long)]; |
80 | static const char tagcache_thread_name[] = "tagcache"; | 90 | static const char tagcache_thread_name[] = "tagcache"; |
91 | #endif | ||
81 | 92 | ||
82 | /* Previous path when scanning directory tree recursively. */ | 93 | /* Previous path when scanning directory tree recursively. */ |
83 | static char curpath[MAX_PATH*2]; | 94 | static char curpath[TAG_MAXLEN+32]; |
84 | static long curpath_size = sizeof(curpath); | 95 | static long curpath_size = sizeof(curpath); |
85 | 96 | ||
86 | /* Used when removing duplicates. */ | 97 | /* Used when removing duplicates. */ |
@@ -105,7 +116,7 @@ static const char *tags_str[] = { "artist", "album", "genre", "title", | |||
105 | "playcount", "playtime", "lastplayed" }; | 116 | "playcount", "playtime", "lastplayed" }; |
106 | 117 | ||
107 | /* Status information of the tagcache. */ | 118 | /* Status information of the tagcache. */ |
108 | static struct tagcache_stat stat; | 119 | static struct tagcache_stat tc_stat; |
109 | 120 | ||
110 | /* Queue commands. */ | 121 | /* Queue commands. */ |
111 | enum tagcache_queue { | 122 | enum tagcache_queue { |
@@ -158,7 +169,7 @@ struct ramcache_header { | |||
158 | # ifdef HAVE_EEPROM_SETTINGS | 169 | # ifdef HAVE_EEPROM_SETTINGS |
159 | struct statefile_header { | 170 | struct statefile_header { |
160 | struct ramcache_header *hdr; | 171 | struct ramcache_header *hdr; |
161 | struct tagcache_stat stat; | 172 | struct tagcache_stat tc_stat; |
162 | }; | 173 | }; |
163 | # endif | 174 | # endif |
164 | 175 | ||
@@ -275,8 +286,8 @@ static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) | |||
275 | fd = open(buf, write ? O_RDWR : O_RDONLY); | 286 | fd = open(buf, write ? O_RDWR : O_RDONLY); |
276 | if (fd < 0) | 287 | if (fd < 0) |
277 | { | 288 | { |
278 | logf("tag file open failed: %d", tag); | 289 | logf("tag file open failed: tag=%d write=%d file=%s", tag, write, buf); |
279 | stat.ready = false; | 290 | tc_stat.ready = false; |
280 | return fd; | 291 | return fd; |
281 | } | 292 | } |
282 | 293 | ||
@@ -285,7 +296,7 @@ static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write) | |||
285 | if (hdr->magic != TAGCACHE_MAGIC || rc != sizeof(struct tagcache_header)) | 296 | if (hdr->magic != TAGCACHE_MAGIC || rc != sizeof(struct tagcache_header)) |
286 | { | 297 | { |
287 | logf("header error"); | 298 | logf("header error"); |
288 | stat.ready = false; | 299 | tc_stat.ready = false; |
289 | close(fd); | 300 | close(fd); |
290 | return -2; | 301 | return -2; |
291 | } | 302 | } |
@@ -302,7 +313,7 @@ static long find_entry_ram(const char *filename, | |||
302 | int i; | 313 | int i; |
303 | 314 | ||
304 | /* Check if we tagcache is loaded into ram. */ | 315 | /* Check if we tagcache is loaded into ram. */ |
305 | if (!stat.ramcache) | 316 | if (!tc_stat.ramcache) |
306 | return -1; | 317 | return -1; |
307 | 318 | ||
308 | if (dc == NULL) | 319 | if (dc == NULL) |
@@ -355,11 +366,11 @@ static long find_entry_disk(const char *filename) | |||
355 | bool found = false; | 366 | bool found = false; |
356 | struct tagfile_entry tfe; | 367 | struct tagfile_entry tfe; |
357 | int fd; | 368 | int fd; |
358 | char buf[MAX_PATH]; | 369 | char buf[TAG_MAXLEN+32]; |
359 | int i; | 370 | int i; |
360 | int pos = -1; | 371 | int pos = -1; |
361 | 372 | ||
362 | if (!stat.ready) | 373 | if (!tc_stat.ready) |
363 | return -2; | 374 | return -2; |
364 | 375 | ||
365 | fd = filenametag_fd; | 376 | fd = filenametag_fd; |
@@ -443,7 +454,7 @@ static int find_index(const char *filename) | |||
443 | long idx_id = -1; | 454 | long idx_id = -1; |
444 | 455 | ||
445 | #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) | 456 | #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) |
446 | if (stat.ramcache && dircache_is_enabled()) | 457 | if (tc_stat.ramcache && dircache_is_enabled()) |
447 | idx_id = find_entry_ram(filename, NULL); | 458 | idx_id = find_entry_ram(filename, NULL); |
448 | #endif | 459 | #endif |
449 | 460 | ||
@@ -457,7 +468,7 @@ bool tagcache_find_index(struct tagcache_search *tcs, const char *filename) | |||
457 | { | 468 | { |
458 | int idx_id; | 469 | int idx_id; |
459 | 470 | ||
460 | if (!stat.ready) | 471 | if (!tc_stat.ready) |
461 | return false; | 472 | return false; |
462 | 473 | ||
463 | idx_id = find_index(filename); | 474 | idx_id = find_index(filename); |
@@ -483,7 +494,7 @@ static bool get_index(int masterfd, int idxid, | |||
483 | } | 494 | } |
484 | 495 | ||
485 | #ifdef HAVE_TC_RAMCACHE | 496 | #ifdef HAVE_TC_RAMCACHE |
486 | if (stat.ramcache && use_ram) | 497 | if (tc_stat.ramcache && use_ram) |
487 | { | 498 | { |
488 | if (hdr->indices[idxid].flag & FLAG_DELETED) | 499 | if (hdr->indices[idxid].flag & FLAG_DELETED) |
489 | return false; | 500 | return false; |
@@ -520,7 +531,7 @@ static bool write_index(int masterfd, int idxid, struct index_entry *idx) | |||
520 | } | 531 | } |
521 | 532 | ||
522 | #ifdef HAVE_TC_RAMCACHE | 533 | #ifdef HAVE_TC_RAMCACHE |
523 | if (stat.ramcache) | 534 | if (tc_stat.ramcache) |
524 | { | 535 | { |
525 | memcpy(&hdr->indices[idxid], idx, sizeof(struct index_entry)); | 536 | memcpy(&hdr->indices[idxid], idx, sizeof(struct index_entry)); |
526 | } | 537 | } |
@@ -660,7 +671,7 @@ long tagcache_get_numeric(const struct tagcache_search *tcs, int tag) | |||
660 | { | 671 | { |
661 | struct index_entry idx; | 672 | struct index_entry idx; |
662 | 673 | ||
663 | if (!stat.ready) | 674 | if (!tc_stat.ready) |
664 | return false; | 675 | return false; |
665 | 676 | ||
666 | if (!tagcache_is_numeric_tag(tag)) | 677 | if (!tagcache_is_numeric_tag(tag)) |
@@ -852,7 +863,7 @@ bool tagcache_check_clauses(struct tagcache_search *tcs, | |||
852 | return check_clauses(tcs, &idx, clause, count); | 863 | return check_clauses(tcs, &idx, clause, count); |
853 | } | 864 | } |
854 | 865 | ||
855 | static bool add_uniqbuf(struct tagcache_search *tcs, long id) | 866 | static bool add_uniqbuf(struct tagcache_search *tcs, unsigned long id) |
856 | { | 867 | { |
857 | int i; | 868 | int i; |
858 | 869 | ||
@@ -984,8 +995,8 @@ static void remove_files(void) | |||
984 | int i; | 995 | int i; |
985 | char buf[MAX_PATH]; | 996 | char buf[MAX_PATH]; |
986 | 997 | ||
987 | stat.ready = false; | 998 | tc_stat.ready = false; |
988 | stat.ramcache = false; | 999 | tc_stat.ramcache = false; |
989 | remove(TAGCACHE_FILE_MASTER); | 1000 | remove(TAGCACHE_FILE_MASTER); |
990 | for (i = 0; i < TAG_COUNT; i++) | 1001 | for (i = 0; i < TAG_COUNT; i++) |
991 | { | 1002 | { |
@@ -1007,7 +1018,7 @@ static int open_master_fd(struct master_header *hdr, bool write) | |||
1007 | if (fd < 0) | 1018 | if (fd < 0) |
1008 | { | 1019 | { |
1009 | logf("master file open failed for R/W"); | 1020 | logf("master file open failed for R/W"); |
1010 | stat.ready = false; | 1021 | tc_stat.ready = false; |
1011 | return fd; | 1022 | return fd; |
1012 | } | 1023 | } |
1013 | 1024 | ||
@@ -1016,7 +1027,7 @@ static int open_master_fd(struct master_header *hdr, bool write) | |||
1016 | if (hdr->tch.magic != TAGCACHE_MAGIC || rc != sizeof(struct master_header)) | 1027 | if (hdr->tch.magic != TAGCACHE_MAGIC || rc != sizeof(struct master_header)) |
1017 | { | 1028 | { |
1018 | logf("header error"); | 1029 | logf("header error"); |
1019 | stat.ready = false; | 1030 | tc_stat.ready = false; |
1020 | close(fd); | 1031 | close(fd); |
1021 | return -2; | 1032 | return -2; |
1022 | } | 1033 | } |
@@ -1037,7 +1048,7 @@ bool tagcache_search(struct tagcache_search *tcs, int tag) | |||
1037 | sleep(1); | 1048 | sleep(1); |
1038 | 1049 | ||
1039 | memset(tcs, 0, sizeof(struct tagcache_search)); | 1050 | memset(tcs, 0, sizeof(struct tagcache_search)); |
1040 | if (stat.commit_step > 0 || !stat.ready) | 1051 | if (tc_stat.commit_step > 0 || !tc_stat.ready) |
1041 | return false; | 1052 | return false; |
1042 | 1053 | ||
1043 | tcs->position = sizeof(struct tagcache_header); | 1054 | tcs->position = sizeof(struct tagcache_header); |
@@ -1053,7 +1064,7 @@ bool tagcache_search(struct tagcache_search *tcs, int tag) | |||
1053 | #ifndef HAVE_TC_RAMCACHE | 1064 | #ifndef HAVE_TC_RAMCACHE |
1054 | tcs->ramsearch = false; | 1065 | tcs->ramsearch = false; |
1055 | #else | 1066 | #else |
1056 | tcs->ramsearch = stat.ramcache; | 1067 | tcs->ramsearch = tc_stat.ramcache; |
1057 | if (tcs->ramsearch) | 1068 | if (tcs->ramsearch) |
1058 | { | 1069 | { |
1059 | tcs->entry_count = hdr->entry_count[tcs->type]; | 1070 | tcs->entry_count = hdr->entry_count[tcs->type]; |
@@ -1146,11 +1157,11 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, | |||
1146 | 1157 | ||
1147 | static bool get_next(struct tagcache_search *tcs) | 1158 | static bool get_next(struct tagcache_search *tcs) |
1148 | { | 1159 | { |
1149 | static char buf[MAX_PATH]; | 1160 | static char buf[TAG_MAXLEN+32]; |
1150 | struct tagfile_entry entry; | 1161 | struct tagfile_entry entry; |
1151 | long flag = 0; | 1162 | long flag = 0; |
1152 | 1163 | ||
1153 | if (!tcs->valid || !stat.ready) | 1164 | if (!tcs->valid || !tc_stat.ready) |
1154 | return false; | 1165 | return false; |
1155 | 1166 | ||
1156 | if (tcs->idxfd[tcs->type] < 0 && !tagcache_is_numeric_tag(tcs->type) | 1167 | if (tcs->idxfd[tcs->type] < 0 && !tagcache_is_numeric_tag(tcs->type) |
@@ -1367,12 +1378,12 @@ bool tagcache_fill_tags(struct mp3entry *id3, const char *filename) | |||
1367 | struct index_entry *entry; | 1378 | struct index_entry *entry; |
1368 | int idx_id; | 1379 | int idx_id; |
1369 | 1380 | ||
1370 | if (!stat.ready) | 1381 | if (!tc_stat.ready) |
1371 | return false; | 1382 | return false; |
1372 | 1383 | ||
1373 | /* Find the corresponding entry in tagcache. */ | 1384 | /* Find the corresponding entry in tagcache. */ |
1374 | idx_id = find_entry_ram(filename, NULL); | 1385 | idx_id = find_entry_ram(filename, NULL); |
1375 | if (idx_id < 0 || !stat.ramcache) | 1386 | if (idx_id < 0 || !tc_stat.ramcache) |
1376 | return false; | 1387 | return false; |
1377 | 1388 | ||
1378 | entry = &hdr->indices[idx_id]; | 1389 | entry = &hdr->indices[idx_id]; |
@@ -1411,11 +1422,11 @@ static int check_if_empty(char **tag) | |||
1411 | } | 1422 | } |
1412 | 1423 | ||
1413 | length = strlen(*tag); | 1424 | length = strlen(*tag); |
1414 | if (length >= MAX_PATH-32) | 1425 | if (length > TAG_MAXLEN) |
1415 | { | 1426 | { |
1416 | logf("over length tag: %s", *tag); | 1427 | logf("over length tag: %s", *tag); |
1417 | *tag[MAX_PATH-32] = '\0'; | 1428 | length = TAG_MAXLEN; |
1418 | length = MAX_PATH-32; | 1429 | *tag[length] = '\0'; |
1419 | } | 1430 | } |
1420 | 1431 | ||
1421 | return length + 1; | 1432 | return length + 1; |
@@ -1440,17 +1451,26 @@ static void add_tagcache(char *path) | |||
1440 | char tracknumfix[3]; | 1451 | char tracknumfix[3]; |
1441 | char *genrestr; | 1452 | char *genrestr; |
1442 | int offset = 0; | 1453 | int offset = 0; |
1454 | int path_length = strlen(path); | ||
1443 | 1455 | ||
1444 | if (cachefd < 0) | 1456 | if (cachefd < 0) |
1445 | return ; | 1457 | return ; |
1446 | 1458 | ||
1459 | /* Check for overlength file path. */ | ||
1460 | if (path_length > TAG_MAXLEN) | ||
1461 | { | ||
1462 | /* Path can't be shortened. */ | ||
1463 | logf("Too long path: %s"); | ||
1464 | return ; | ||
1465 | } | ||
1466 | |||
1447 | /* Check if the file is supported. */ | 1467 | /* Check if the file is supported. */ |
1448 | if (probe_file_format(path) == AFMT_UNKNOWN) | 1468 | if (probe_file_format(path) == AFMT_UNKNOWN) |
1449 | return ; | 1469 | return ; |
1450 | 1470 | ||
1451 | /* Check if the file is already cached. */ | 1471 | /* Check if the file is already cached. */ |
1452 | #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) | 1472 | #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) |
1453 | if (stat.ramcache && dircache_is_enabled()) | 1473 | if (tc_stat.ramcache && dircache_is_enabled()) |
1454 | { | 1474 | { |
1455 | if (find_entry_ram(path, dc) >= 0) | 1475 | if (find_entry_ram(path, dc) >= 0) |
1456 | return ; | 1476 | return ; |
@@ -1552,7 +1572,7 @@ static bool tempbuf_insert(char *str, int id, int idx_id, bool unique) | |||
1552 | int i; | 1572 | int i; |
1553 | unsigned crc32; | 1573 | unsigned crc32; |
1554 | unsigned *crcbuf = (unsigned *)&tempbuf[tempbuf_size-4]; | 1574 | unsigned *crcbuf = (unsigned *)&tempbuf[tempbuf_size-4]; |
1555 | char buf[MAX_PATH]; | 1575 | char buf[TAG_MAXLEN+32]; |
1556 | 1576 | ||
1557 | for (i = 0; str[i] != '\0' && i < (int)sizeof(buf)-1; i++) | 1577 | for (i = 0; str[i] != '\0' && i < (int)sizeof(buf)-1; i++) |
1558 | buf[i] = tolower(str[i]); | 1578 | buf[i] = tolower(str[i]); |
@@ -1628,7 +1648,7 @@ static int compare(const void *p1, const void *p2) | |||
1628 | e2 = &e2[4]; | 1648 | e2 = &e2[4]; |
1629 | */ | 1649 | */ |
1630 | 1650 | ||
1631 | return strncasecmp(e1->str, e2->str, MAX_PATH); | 1651 | return strncasecmp(e1->str, e2->str, TAG_MAXLEN); |
1632 | } | 1652 | } |
1633 | 1653 | ||
1634 | static int tempbuf_sort(int fd) | 1654 | static int tempbuf_sort(int fd) |
@@ -1853,7 +1873,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
1853 | struct master_header tcmh; | 1873 | struct master_header tcmh; |
1854 | struct index_entry idxbuf[IDX_BUF_DEPTH]; | 1874 | struct index_entry idxbuf[IDX_BUF_DEPTH]; |
1855 | int idxbuf_pos; | 1875 | int idxbuf_pos; |
1856 | char buf[MAX_PATH]; | 1876 | char buf[TAG_MAXLEN+32]; |
1857 | int fd = -1, masterfd; | 1877 | int fd = -1, masterfd; |
1858 | bool error = false; | 1878 | bool error = false; |
1859 | int init; | 1879 | int init; |
@@ -2031,7 +2051,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2031 | 2051 | ||
2032 | if (masterfd < 0) | 2052 | if (masterfd < 0) |
2033 | { | 2053 | { |
2034 | logf("Failure to create index file"); | 2054 | logf("Failure to create index file (%s)", TAGCACHE_FILE_MASTER); |
2035 | close(fd); | 2055 | close(fd); |
2036 | return -2; | 2056 | return -2; |
2037 | } | 2057 | } |
@@ -2349,6 +2369,7 @@ static bool commit(void) | |||
2349 | return true; | 2369 | return true; |
2350 | } | 2370 | } |
2351 | 2371 | ||
2372 | |||
2352 | /* Load the header. */ | 2373 | /* Load the header. */ |
2353 | len = sizeof(struct tagcache_header); | 2374 | len = sizeof(struct tagcache_header); |
2354 | rc = read(tmpfd, &tch, len); | 2375 | rc = read(tmpfd, &tch, len); |
@@ -2375,7 +2396,7 @@ static bool commit(void) | |||
2375 | 2396 | ||
2376 | /* At first be sure to unload the ramcache! */ | 2397 | /* At first be sure to unload the ramcache! */ |
2377 | #ifdef HAVE_TC_RAMCACHE | 2398 | #ifdef HAVE_TC_RAMCACHE |
2378 | stat.ramcache = false; | 2399 | tc_stat.ramcache = false; |
2379 | #endif | 2400 | #endif |
2380 | 2401 | ||
2381 | read_lock++; | 2402 | read_lock++; |
@@ -2399,10 +2420,10 @@ static bool commit(void) | |||
2399 | #endif | 2420 | #endif |
2400 | 2421 | ||
2401 | #ifdef HAVE_TC_RAMCACHE | 2422 | #ifdef HAVE_TC_RAMCACHE |
2402 | if (tempbuf_size == 0 && stat.ramcache_allocated > 0) | 2423 | if (tempbuf_size == 0 && tc_stat.ramcache_allocated > 0) |
2403 | { | 2424 | { |
2404 | tempbuf = (char *)(hdr + 1); | 2425 | tempbuf = (char *)(hdr + 1); |
2405 | tempbuf_size = stat.ramcache_allocated - sizeof(struct ramcache_header) - 128; | 2426 | tempbuf_size = tc_stat.ramcache_allocated - sizeof(struct ramcache_header) - 128; |
2406 | tempbuf_size &= ~0x03; | 2427 | tempbuf_size &= ~0x03; |
2407 | } | 2428 | } |
2408 | #endif | 2429 | #endif |
@@ -2411,7 +2432,7 @@ static bool commit(void) | |||
2411 | if (tempbuf_size == 0) | 2432 | if (tempbuf_size == 0) |
2412 | { | 2433 | { |
2413 | logf("delaying commit until next boot"); | 2434 | logf("delaying commit until next boot"); |
2414 | stat.commit_delayed = true; | 2435 | tc_stat.commit_delayed = true; |
2415 | close(tmpfd); | 2436 | close(tmpfd); |
2416 | read_lock--; | 2437 | read_lock--; |
2417 | return false; | 2438 | return false; |
@@ -2420,9 +2441,9 @@ static bool commit(void) | |||
2420 | logf("commit %d entries...", tch.entry_count); | 2441 | logf("commit %d entries...", tch.entry_count); |
2421 | 2442 | ||
2422 | /* Now create the index files. */ | 2443 | /* Now create the index files. */ |
2423 | stat.commit_step = 0; | 2444 | tc_stat.commit_step = 0; |
2424 | tch.datasize = 0; | 2445 | tch.datasize = 0; |
2425 | stat.commit_delayed = false; | 2446 | tc_stat.commit_delayed = false; |
2426 | 2447 | ||
2427 | for (i = 0; i < TAG_COUNT; i++) | 2448 | for (i = 0; i < TAG_COUNT; i++) |
2428 | { | 2449 | { |
@@ -2431,7 +2452,7 @@ static bool commit(void) | |||
2431 | if (tagcache_is_numeric_tag(i)) | 2452 | if (tagcache_is_numeric_tag(i)) |
2432 | continue; | 2453 | continue; |
2433 | 2454 | ||
2434 | stat.commit_step++; | 2455 | tc_stat.commit_step++; |
2435 | ret = build_index(i, &tch, tmpfd); | 2456 | ret = build_index(i, &tch, tmpfd); |
2436 | if (ret <= 0) | 2457 | if (ret <= 0) |
2437 | { | 2458 | { |
@@ -2440,8 +2461,8 @@ static bool commit(void) | |||
2440 | if (ret < 0) | 2461 | if (ret < 0) |
2441 | remove_files(); | 2462 | remove_files(); |
2442 | else | 2463 | else |
2443 | stat.commit_delayed = true; | 2464 | tc_stat.commit_delayed = true; |
2444 | stat.commit_step = 0; | 2465 | tc_stat.commit_step = 0; |
2445 | read_lock--; | 2466 | read_lock--; |
2446 | return false; | 2467 | return false; |
2447 | } | 2468 | } |
@@ -2449,7 +2470,7 @@ static bool commit(void) | |||
2449 | 2470 | ||
2450 | build_numeric_indices(&tch, tmpfd); | 2471 | build_numeric_indices(&tch, tmpfd); |
2451 | close(tmpfd); | 2472 | close(tmpfd); |
2452 | stat.commit_step = 0; | 2473 | tc_stat.commit_step = 0; |
2453 | 2474 | ||
2454 | /* Update the master index headers. */ | 2475 | /* Update the master index headers. */ |
2455 | if ( (masterfd = open_master_fd(&tcmh, true)) < 0) | 2476 | if ( (masterfd = open_master_fd(&tcmh, true)) < 0) |
@@ -2469,7 +2490,7 @@ static bool commit(void) | |||
2469 | 2490 | ||
2470 | logf("tagcache committed"); | 2491 | logf("tagcache committed"); |
2471 | remove(TAGCACHE_FILE_TEMP); | 2492 | remove(TAGCACHE_FILE_TEMP); |
2472 | stat.ready = true; | 2493 | tc_stat.ready = true; |
2473 | 2494 | ||
2474 | if (local_allocation) | 2495 | if (local_allocation) |
2475 | { | 2496 | { |
@@ -2485,7 +2506,7 @@ static bool commit(void) | |||
2485 | 2506 | ||
2486 | #ifdef HAVE_TC_RAMCACHE | 2507 | #ifdef HAVE_TC_RAMCACHE |
2487 | /* Reload tagcache. */ | 2508 | /* Reload tagcache. */ |
2488 | if (stat.ramcache_allocated > 0) | 2509 | if (tc_stat.ramcache_allocated > 0) |
2489 | tagcache_start_scan(); | 2510 | tagcache_start_scan(); |
2490 | #endif | 2511 | #endif |
2491 | 2512 | ||
@@ -2497,9 +2518,14 @@ static bool commit(void) | |||
2497 | static void allocate_tempbuf(void) | 2518 | static void allocate_tempbuf(void) |
2498 | { | 2519 | { |
2499 | /* Yeah, malloc would be really nice now :) */ | 2520 | /* Yeah, malloc would be really nice now :) */ |
2521 | #ifdef __PCTOOL__ | ||
2522 | tempbuf_size = 32*1024*1024; | ||
2523 | tempbuf = malloc(tempbuf_size); | ||
2524 | #else | ||
2500 | tempbuf = (char *)(((long)audiobuf & ~0x03) + 0x04); | 2525 | tempbuf = (char *)(((long)audiobuf & ~0x03) + 0x04); |
2501 | tempbuf_size = (long)audiobufend - (long)audiobuf - 4; | 2526 | tempbuf_size = (long)audiobufend - (long)audiobuf - 4; |
2502 | audiobuf += tempbuf_size; | 2527 | audiobuf += tempbuf_size; |
2528 | #endif | ||
2503 | } | 2529 | } |
2504 | 2530 | ||
2505 | static void free_tempbuf(void) | 2531 | static void free_tempbuf(void) |
@@ -2507,7 +2533,11 @@ static void free_tempbuf(void) | |||
2507 | if (tempbuf_size == 0) | 2533 | if (tempbuf_size == 0) |
2508 | return ; | 2534 | return ; |
2509 | 2535 | ||
2536 | #ifdef __PCTOOL__ | ||
2537 | free(tempbuf); | ||
2538 | #else | ||
2510 | audiobuf -= tempbuf_size; | 2539 | audiobuf -= tempbuf_size; |
2540 | #endif | ||
2511 | tempbuf = NULL; | 2541 | tempbuf = NULL; |
2512 | tempbuf_size = 0; | 2542 | tempbuf_size = 0; |
2513 | } | 2543 | } |
@@ -2538,7 +2568,7 @@ static bool update_current_serial(long serial) | |||
2538 | 2568 | ||
2539 | long tagcache_increase_serial(void) | 2569 | long tagcache_increase_serial(void) |
2540 | { | 2570 | { |
2541 | if (!stat.ready) | 2571 | if (!tc_stat.ready) |
2542 | return -2; | 2572 | return -2; |
2543 | 2573 | ||
2544 | while (read_lock) | 2574 | while (read_lock) |
@@ -2559,7 +2589,7 @@ static bool modify_numeric_entry(int masterfd, int idx_id, int tag, long data) | |||
2559 | { | 2589 | { |
2560 | struct index_entry idx; | 2590 | struct index_entry idx; |
2561 | 2591 | ||
2562 | if (!stat.ready) | 2592 | if (!tc_stat.ready) |
2563 | return false; | 2593 | return false; |
2564 | 2594 | ||
2565 | if (!tagcache_is_numeric_tag(tag)) | 2595 | if (!tagcache_is_numeric_tag(tag)) |
@@ -2691,7 +2721,7 @@ static bool read_tag(char *dest, long size, | |||
2691 | static int parse_changelog_line(int line_n, const char *buf, void *parameters) | 2721 | static int parse_changelog_line(int line_n, const char *buf, void *parameters) |
2692 | { | 2722 | { |
2693 | struct index_entry idx; | 2723 | struct index_entry idx; |
2694 | char tag_data[MAX_PATH]; | 2724 | char tag_data[TAG_MAXLEN+32]; |
2695 | int idx_id; | 2725 | int idx_id; |
2696 | long masterfd = (long)parameters; | 2726 | long masterfd = (long)parameters; |
2697 | const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed }; | 2727 | const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed }; |
@@ -2752,6 +2782,7 @@ static int parse_changelog_line(int line_n, const char *buf, void *parameters) | |||
2752 | return write_index(masterfd, idx_id, &idx) ? 0 : -5; | 2782 | return write_index(masterfd, idx_id, &idx) ? 0 : -5; |
2753 | } | 2783 | } |
2754 | 2784 | ||
2785 | #ifndef __PCTOOL__ | ||
2755 | bool tagcache_import_changelog(void) | 2786 | bool tagcache_import_changelog(void) |
2756 | { | 2787 | { |
2757 | struct master_header myhdr; | 2788 | struct master_header myhdr; |
@@ -2760,7 +2791,7 @@ bool tagcache_import_changelog(void) | |||
2760 | long masterfd; | 2791 | long masterfd; |
2761 | char buf[2048]; | 2792 | char buf[2048]; |
2762 | 2793 | ||
2763 | if (!stat.ready) | 2794 | if (!tc_stat.ready) |
2764 | return false; | 2795 | return false; |
2765 | 2796 | ||
2766 | while (read_lock) | 2797 | while (read_lock) |
@@ -2798,17 +2829,18 @@ bool tagcache_import_changelog(void) | |||
2798 | 2829 | ||
2799 | return true; | 2830 | return true; |
2800 | } | 2831 | } |
2832 | #endif | ||
2801 | 2833 | ||
2802 | bool tagcache_create_changelog(struct tagcache_search *tcs) | 2834 | bool tagcache_create_changelog(struct tagcache_search *tcs) |
2803 | { | 2835 | { |
2804 | struct master_header myhdr; | 2836 | struct master_header myhdr; |
2805 | struct index_entry idx; | 2837 | struct index_entry idx; |
2806 | char buf[MAX_PATH]; | 2838 | char buf[TAG_MAXLEN+32]; |
2807 | char temp[32]; | 2839 | char temp[32]; |
2808 | int clfd; | 2840 | int clfd; |
2809 | int i, j; | 2841 | int i, j; |
2810 | 2842 | ||
2811 | if (!stat.ready) | 2843 | if (!tc_stat.ready) |
2812 | return false; | 2844 | return false; |
2813 | 2845 | ||
2814 | if (!tagcache_search(tcs, tag_filename)) | 2846 | if (!tagcache_search(tcs, tag_filename)) |
@@ -2882,7 +2914,7 @@ static bool delete_entry(long idx_id) | |||
2882 | int tag, i; | 2914 | int tag, i; |
2883 | struct index_entry idx, myidx; | 2915 | struct index_entry idx, myidx; |
2884 | struct master_header myhdr; | 2916 | struct master_header myhdr; |
2885 | char buf[MAX_PATH]; | 2917 | char buf[TAG_MAXLEN+32]; |
2886 | int in_use[TAG_COUNT]; | 2918 | int in_use[TAG_COUNT]; |
2887 | 2919 | ||
2888 | logf("delete_entry(): %d", idx_id); | 2920 | logf("delete_entry(): %d", idx_id); |
@@ -2987,6 +3019,7 @@ static bool delete_entry(long idx_id) | |||
2987 | return true; | 3019 | return true; |
2988 | } | 3020 | } |
2989 | 3021 | ||
3022 | #ifndef __PCTOOL__ | ||
2990 | /** | 3023 | /** |
2991 | * Returns true if there is an event waiting in the queue | 3024 | * Returns true if there is an event waiting in the queue |
2992 | * that requires the current operation to be aborted. | 3025 | * that requires the current operation to be aborted. |
@@ -3008,6 +3041,7 @@ static bool check_event_queue(void) | |||
3008 | 3041 | ||
3009 | return false; | 3042 | return false; |
3010 | } | 3043 | } |
3044 | #endif | ||
3011 | 3045 | ||
3012 | #ifdef HAVE_TC_RAMCACHE | 3046 | #ifdef HAVE_TC_RAMCACHE |
3013 | static bool allocate_tagcache(void) | 3047 | static bool allocate_tagcache(void) |
@@ -3028,13 +3062,13 @@ static bool allocate_tagcache(void) | |||
3028 | * Now calculate the required cache size plus | 3062 | * Now calculate the required cache size plus |
3029 | * some extra space for alignment fixes. | 3063 | * some extra space for alignment fixes. |
3030 | */ | 3064 | */ |
3031 | stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE + | 3065 | tc_stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE + |
3032 | sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); | 3066 | sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); |
3033 | hdr = buffer_alloc(stat.ramcache_allocated + 128); | 3067 | hdr = buffer_alloc(tc_stat.ramcache_allocated + 128); |
3034 | memset(hdr, 0, sizeof(struct ramcache_header)); | 3068 | memset(hdr, 0, sizeof(struct ramcache_header)); |
3035 | memcpy(&hdr->h, &tcmh, sizeof(struct master_header)); | 3069 | memcpy(&hdr->h, &tcmh, sizeof(struct master_header)); |
3036 | hdr->indices = (struct index_entry *)(hdr + 1); | 3070 | hdr->indices = (struct index_entry *)(hdr + 1); |
3037 | logf("tagcache: %d bytes allocated.", stat.ramcache_allocated); | 3071 | logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); |
3038 | 3072 | ||
3039 | return true; | 3073 | return true; |
3040 | } | 3074 | } |
@@ -3069,18 +3103,18 @@ static bool tagcache_dumpload(void) | |||
3069 | offpos = (long)hdr - (long)shdr.hdr; | 3103 | offpos = (long)hdr - (long)shdr.hdr; |
3070 | 3104 | ||
3071 | /* Lets allocate real memory and load it */ | 3105 | /* Lets allocate real memory and load it */ |
3072 | hdr = buffer_alloc(shdr.stat.ramcache_allocated); | 3106 | hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated); |
3073 | rc = read(fd, hdr, shdr.stat.ramcache_allocated); | 3107 | rc = read(fd, hdr, shdr.tc_stat.ramcache_allocated); |
3074 | close(fd); | 3108 | close(fd); |
3075 | 3109 | ||
3076 | if (rc != shdr.stat.ramcache_allocated) | 3110 | if (rc != shdr.tc_stat.ramcache_allocated) |
3077 | { | 3111 | { |
3078 | logf("read failure!"); | 3112 | logf("read failure!"); |
3079 | hdr = NULL; | 3113 | hdr = NULL; |
3080 | return false; | 3114 | return false; |
3081 | } | 3115 | } |
3082 | 3116 | ||
3083 | memcpy(&stat, &shdr.stat, sizeof(struct tagcache_stat)); | 3117 | memcpy(&tc_stat, &shdr.tc_stat, sizeof(struct tagcache_stat)); |
3084 | 3118 | ||
3085 | /* Now fix the pointers */ | 3119 | /* Now fix the pointers */ |
3086 | hdr->indices = (struct index_entry *)((long)hdr->indices + offpos); | 3120 | hdr->indices = (struct index_entry *)((long)hdr->indices + offpos); |
@@ -3095,7 +3129,7 @@ static bool tagcache_dumpsave(void) | |||
3095 | struct statefile_header shdr; | 3129 | struct statefile_header shdr; |
3096 | int fd; | 3130 | int fd; |
3097 | 3131 | ||
3098 | if (!stat.ramcache) | 3132 | if (!tc_stat.ramcache) |
3099 | return false; | 3133 | return false; |
3100 | 3134 | ||
3101 | fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC); | 3135 | fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC); |
@@ -3107,11 +3141,11 @@ static bool tagcache_dumpsave(void) | |||
3107 | 3141 | ||
3108 | /* Create the header */ | 3142 | /* Create the header */ |
3109 | shdr.hdr = hdr; | 3143 | shdr.hdr = hdr; |
3110 | memcpy(&shdr.stat, &stat, sizeof(struct tagcache_stat)); | 3144 | memcpy(&shdr.tc_stat, &tc_stat, sizeof(struct tagcache_stat)); |
3111 | write(fd, &shdr, sizeof(struct statefile_header)); | 3145 | write(fd, &shdr, sizeof(struct statefile_header)); |
3112 | 3146 | ||
3113 | /* And dump the data too */ | 3147 | /* And dump the data too */ |
3114 | write(fd, hdr, stat.ramcache_allocated); | 3148 | write(fd, hdr, tc_stat.ramcache_allocated); |
3115 | close(fd); | 3149 | close(fd); |
3116 | 3150 | ||
3117 | return true; | 3151 | return true; |
@@ -3121,7 +3155,7 @@ static bool tagcache_dumpsave(void) | |||
3121 | static bool load_tagcache(void) | 3155 | static bool load_tagcache(void) |
3122 | { | 3156 | { |
3123 | struct tagcache_header *tch; | 3157 | struct tagcache_header *tch; |
3124 | long bytesleft = stat.ramcache_allocated; | 3158 | long bytesleft = tc_stat.ramcache_allocated; |
3125 | struct index_entry *idx; | 3159 | struct index_entry *idx; |
3126 | int rc, fd; | 3160 | int rc, fd; |
3127 | char *p; | 3161 | char *p; |
@@ -3164,7 +3198,7 @@ static bool load_tagcache(void) | |||
3164 | } | 3198 | } |
3165 | 3199 | ||
3166 | bytesleft -= sizeof(struct index_entry); | 3200 | bytesleft -= sizeof(struct index_entry); |
3167 | if (bytesleft < 0 || ((long)idx - (long)hdr->indices) >= stat.ramcache_allocated) | 3201 | if (bytesleft < 0 || ((long)idx - (long)hdr->indices) >= tc_stat.ramcache_allocated) |
3168 | { | 3202 | { |
3169 | logf("too big tagcache."); | 3203 | logf("too big tagcache."); |
3170 | close(fd); | 3204 | close(fd); |
@@ -3181,7 +3215,7 @@ static bool load_tagcache(void) | |||
3181 | for (tag = 0; tag < TAG_COUNT; tag++) | 3215 | for (tag = 0; tag < TAG_COUNT; tag++) |
3182 | { | 3216 | { |
3183 | struct tagfile_entry *fe; | 3217 | struct tagfile_entry *fe; |
3184 | char buf[MAX_PATH]; | 3218 | char buf[TAG_MAXLEN+32]; |
3185 | 3219 | ||
3186 | if (tagcache_is_numeric_tag(tag)) | 3220 | if (tagcache_is_numeric_tag(tag)) |
3187 | continue ; | 3221 | continue ; |
@@ -3341,7 +3375,7 @@ static bool load_tagcache(void) | |||
3341 | close(fd); | 3375 | close(fd); |
3342 | } | 3376 | } |
3343 | 3377 | ||
3344 | stat.ramcache_used = stat.ramcache_allocated - bytesleft; | 3378 | tc_stat.ramcache_used = tc_stat.ramcache_allocated - bytesleft; |
3345 | logf("tagcache loaded into ram!"); | 3379 | logf("tagcache loaded into ram!"); |
3346 | 3380 | ||
3347 | return true; | 3381 | return true; |
@@ -3351,7 +3385,7 @@ static bool load_tagcache(void) | |||
3351 | static bool check_deleted_files(void) | 3385 | static bool check_deleted_files(void) |
3352 | { | 3386 | { |
3353 | int fd, testfd; | 3387 | int fd, testfd; |
3354 | char buf[MAX_PATH]; | 3388 | char buf[TAG_MAXLEN+32]; |
3355 | struct tagfile_entry tfe; | 3389 | struct tagfile_entry tfe; |
3356 | 3390 | ||
3357 | logf("reverse scan..."); | 3391 | logf("reverse scan..."); |
@@ -3366,7 +3400,11 @@ static bool check_deleted_files(void) | |||
3366 | 3400 | ||
3367 | lseek(fd, sizeof(struct tagcache_header), SEEK_SET); | 3401 | lseek(fd, sizeof(struct tagcache_header), SEEK_SET); |
3368 | while (read(fd, &tfe, sizeof(struct tagfile_entry)) | 3402 | while (read(fd, &tfe, sizeof(struct tagfile_entry)) |
3369 | == sizeof(struct tagfile_entry) && !check_event_queue()) | 3403 | == sizeof(struct tagfile_entry) |
3404 | #ifndef __PCTOOL__ | ||
3405 | && !check_event_queue() | ||
3406 | #endif | ||
3407 | ) | ||
3370 | { | 3408 | { |
3371 | if (tfe.tag_length >= (long)sizeof(buf)-1) | 3409 | if (tfe.tag_length >= (long)sizeof(buf)-1) |
3372 | { | 3410 | { |
@@ -3414,7 +3452,11 @@ static bool check_dir(const char *dirname) | |||
3414 | } | 3452 | } |
3415 | 3453 | ||
3416 | /* Recursively scan the dir. */ | 3454 | /* Recursively scan the dir. */ |
3455 | #ifdef __PCTOOL__ | ||
3456 | while (1) | ||
3457 | #else | ||
3417 | while (!check_event_queue()) | 3458 | while (!check_event_queue()) |
3459 | #endif | ||
3418 | { | 3460 | { |
3419 | struct dircache_entry *entry; | 3461 | struct dircache_entry *entry; |
3420 | 3462 | ||
@@ -3426,8 +3468,8 @@ static bool check_dir(const char *dirname) | |||
3426 | break ; | 3468 | break ; |
3427 | } | 3469 | } |
3428 | 3470 | ||
3429 | if (!strcmp(entry->d_name, ".") || | 3471 | if (!strcmp((char *)entry->d_name, ".") || |
3430 | !strcmp(entry->d_name, "..")) | 3472 | !strcmp((char *)entry->d_name, "..")) |
3431 | continue; | 3473 | continue; |
3432 | 3474 | ||
3433 | yield(); | 3475 | yield(); |
@@ -3454,7 +3496,7 @@ static bool check_dir(const char *dirname) | |||
3454 | return success; | 3496 | return success; |
3455 | } | 3497 | } |
3456 | 3498 | ||
3457 | static void build_tagcache(void) | 3499 | void build_tagcache(const char *path) |
3458 | { | 3500 | { |
3459 | struct tagcache_header header; | 3501 | struct tagcache_header header; |
3460 | bool ret; | 3502 | bool ret; |
@@ -3482,7 +3524,7 @@ static void build_tagcache(void) | |||
3482 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC); | 3524 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC); |
3483 | if (cachefd < 0) | 3525 | if (cachefd < 0) |
3484 | { | 3526 | { |
3485 | logf("master file open failed"); | 3527 | logf("master file open failed: %s", TAGCACHE_FILE_TEMP); |
3486 | return ; | 3528 | return ; |
3487 | } | 3529 | } |
3488 | 3530 | ||
@@ -3490,12 +3532,13 @@ static void build_tagcache(void) | |||
3490 | 3532 | ||
3491 | cpu_boost_id(true, CPUBOOSTID_TAGCACHE); | 3533 | cpu_boost_id(true, CPUBOOSTID_TAGCACHE); |
3492 | 3534 | ||
3535 | logf("Scanning files..."); | ||
3493 | /* Scan for new files. */ | 3536 | /* Scan for new files. */ |
3494 | memset(&header, 0, sizeof(struct tagcache_header)); | 3537 | memset(&header, 0, sizeof(struct tagcache_header)); |
3495 | write(cachefd, &header, sizeof(struct tagcache_header)); | 3538 | write(cachefd, &header, sizeof(struct tagcache_header)); |
3496 | 3539 | ||
3497 | //strcpy(curpath, "/Best"); | 3540 | strcpy(curpath, path); |
3498 | ret = check_dir("/"); | 3541 | ret = check_dir(path); |
3499 | 3542 | ||
3500 | /* Write the header. */ | 3543 | /* Write the header. */ |
3501 | header.magic = TAGCACHE_MAGIC; | 3544 | header.magic = TAGCACHE_MAGIC; |
@@ -3519,11 +3562,17 @@ static void build_tagcache(void) | |||
3519 | } | 3562 | } |
3520 | 3563 | ||
3521 | /* Commit changes to the database. */ | 3564 | /* Commit changes to the database. */ |
3565 | #ifdef __PCTOOL__ | ||
3566 | allocate_tempbuf(); | ||
3567 | #endif | ||
3522 | if (commit()) | 3568 | if (commit()) |
3523 | { | 3569 | { |
3524 | remove(TAGCACHE_FILE_TEMP); | 3570 | remove(TAGCACHE_FILE_TEMP); |
3525 | logf("tagcache built!"); | 3571 | logf("tagcache built!"); |
3526 | } | 3572 | } |
3573 | #ifdef __PCTOOL__ | ||
3574 | free_tempbuf(); | ||
3575 | #endif | ||
3527 | 3576 | ||
3528 | #ifdef HAVE_TC_RAMCACHE | 3577 | #ifdef HAVE_TC_RAMCACHE |
3529 | if (hdr) | 3578 | if (hdr) |
@@ -3546,13 +3595,13 @@ static void load_ramcache(void) | |||
3546 | cpu_boost_id(true, CPUBOOSTID_TAGCACHE); | 3595 | cpu_boost_id(true, CPUBOOSTID_TAGCACHE); |
3547 | 3596 | ||
3548 | /* At first we should load the cache (if exists). */ | 3597 | /* At first we should load the cache (if exists). */ |
3549 | stat.ramcache = load_tagcache(); | 3598 | tc_stat.ramcache = load_tagcache(); |
3550 | 3599 | ||
3551 | if (!stat.ramcache) | 3600 | if (!tc_stat.ramcache) |
3552 | { | 3601 | { |
3553 | /* If loading failed, it must indicate some problem with the db | 3602 | /* If loading failed, it must indicate some problem with the db |
3554 | * so disable it entirely to prevent further issues. */ | 3603 | * so disable it entirely to prevent further issues. */ |
3555 | stat.ready = false; | 3604 | tc_stat.ready = false; |
3556 | hdr = NULL; | 3605 | hdr = NULL; |
3557 | } | 3606 | } |
3558 | 3607 | ||
@@ -3561,7 +3610,7 @@ static void load_ramcache(void) | |||
3561 | 3610 | ||
3562 | void tagcache_unload_ramcache(void) | 3611 | void tagcache_unload_ramcache(void) |
3563 | { | 3612 | { |
3564 | stat.ramcache = false; | 3613 | tc_stat.ramcache = false; |
3565 | /* Just to make sure there is no statefile present. */ | 3614 | /* Just to make sure there is no statefile present. */ |
3566 | // remove(TAGCACHE_STATEFILE); | 3615 | // remove(TAGCACHE_STATEFILE); |
3567 | } | 3616 | } |
@@ -3594,6 +3643,7 @@ static bool check_all_headers(void) | |||
3594 | return true; | 3643 | return true; |
3595 | } | 3644 | } |
3596 | 3645 | ||
3646 | #ifndef __PCTOOL__ | ||
3597 | static void tagcache_thread(void) | 3647 | static void tagcache_thread(void) |
3598 | { | 3648 | { |
3599 | struct event ev; | 3649 | struct event ev; |
@@ -3615,16 +3665,16 @@ static void tagcache_thread(void) | |||
3615 | # endif | 3665 | # endif |
3616 | 3666 | ||
3617 | /* Allocate space for the tagcache if found on disk. */ | 3667 | /* Allocate space for the tagcache if found on disk. */ |
3618 | if (global_settings.tagcache_ram && !stat.ramcache) | 3668 | if (global_settings.tagcache_ram && !tc_stat.ramcache) |
3619 | allocate_tagcache(); | 3669 | allocate_tagcache(); |
3620 | #endif | 3670 | #endif |
3621 | 3671 | ||
3622 | cpu_boost_id(false, CPUBOOSTID_TAGCACHE); | 3672 | cpu_boost_id(false, CPUBOOSTID_TAGCACHE); |
3623 | stat.initialized = true; | 3673 | tc_stat.initialized = true; |
3624 | 3674 | ||
3625 | /* Don't delay bootup with the header check but do it on background. */ | 3675 | /* Don't delay bootup with the header check but do it on background. */ |
3626 | sleep(HZ); | 3676 | sleep(HZ); |
3627 | stat.ready = check_all_headers(); | 3677 | tc_stat.ready = check_all_headers(); |
3628 | 3678 | ||
3629 | while (1) | 3679 | while (1) |
3630 | { | 3680 | { |
@@ -3638,11 +3688,11 @@ static void tagcache_thread(void) | |||
3638 | 3688 | ||
3639 | case Q_REBUILD: | 3689 | case Q_REBUILD: |
3640 | remove_files(); | 3690 | remove_files(); |
3641 | build_tagcache(); | 3691 | build_tagcache("/"); |
3642 | break; | 3692 | break; |
3643 | 3693 | ||
3644 | case Q_UPDATE: | 3694 | case Q_UPDATE: |
3645 | build_tagcache(); | 3695 | build_tagcache("/"); |
3646 | #ifdef HAVE_TC_RAMCACHE | 3696 | #ifdef HAVE_TC_RAMCACHE |
3647 | load_ramcache(); | 3697 | load_ramcache(); |
3648 | #endif | 3698 | #endif |
@@ -3652,21 +3702,21 @@ static void tagcache_thread(void) | |||
3652 | case Q_START_SCAN: | 3702 | case Q_START_SCAN: |
3653 | check_done = false; | 3703 | check_done = false; |
3654 | case SYS_TIMEOUT: | 3704 | case SYS_TIMEOUT: |
3655 | if (check_done || !stat.ready) | 3705 | if (check_done || !tc_stat.ready) |
3656 | break ; | 3706 | break ; |
3657 | 3707 | ||
3658 | #ifdef HAVE_TC_RAMCACHE | 3708 | #ifdef HAVE_TC_RAMCACHE |
3659 | if (!stat.ramcache && global_settings.tagcache_ram) | 3709 | if (!tc_stat.ramcache && global_settings.tagcache_ram) |
3660 | { | 3710 | { |
3661 | load_ramcache(); | 3711 | load_ramcache(); |
3662 | if (stat.ramcache && global_settings.tagcache_autoupdate) | 3712 | if (tc_stat.ramcache && global_settings.tagcache_autoupdate) |
3663 | build_tagcache(); | 3713 | build_tagcache("/"); |
3664 | } | 3714 | } |
3665 | else | 3715 | else |
3666 | #endif | 3716 | #endif |
3667 | if (global_settings.tagcache_autoupdate) | 3717 | if (global_settings.tagcache_autoupdate) |
3668 | { | 3718 | { |
3669 | build_tagcache(); | 3719 | build_tagcache("/"); |
3670 | /* Don't do auto removal without dircache (very slow). */ | 3720 | /* Don't do auto removal without dircache (very slow). */ |
3671 | #ifdef HAVE_DIRCACHE | 3721 | #ifdef HAVE_DIRCACHE |
3672 | if (dircache_is_enabled()) | 3722 | if (dircache_is_enabled()) |
@@ -3711,7 +3761,7 @@ bool tagcache_prepare_shutdown(void) | |||
3711 | void tagcache_shutdown(void) | 3761 | void tagcache_shutdown(void) |
3712 | { | 3762 | { |
3713 | #ifdef HAVE_EEPROM_SETTINGS | 3763 | #ifdef HAVE_EEPROM_SETTINGS |
3714 | if (stat.ramcache) | 3764 | if (tc_stat.ramcache) |
3715 | tagcache_dumpsave(); | 3765 | tagcache_dumpsave(); |
3716 | #endif | 3766 | #endif |
3717 | } | 3767 | } |
@@ -3729,7 +3779,7 @@ static int get_progress(void) | |||
3729 | #endif | 3779 | #endif |
3730 | #ifdef HAVE_TC_RAMCACHE | 3780 | #ifdef HAVE_TC_RAMCACHE |
3731 | { | 3781 | { |
3732 | if (hdr && stat.ramcache) | 3782 | if (hdr && tc_stat.ramcache) |
3733 | total_count = hdr->h.tch.entry_count; | 3783 | total_count = hdr->h.tch.entry_count; |
3734 | } | 3784 | } |
3735 | #endif | 3785 | #endif |
@@ -3742,12 +3792,12 @@ static int get_progress(void) | |||
3742 | 3792 | ||
3743 | struct tagcache_stat* tagcache_get_stat(void) | 3793 | struct tagcache_stat* tagcache_get_stat(void) |
3744 | { | 3794 | { |
3745 | stat.progress = get_progress(); | 3795 | tc_stat.progress = get_progress(); |
3746 | stat.processed_entries = processed_dir_count; | 3796 | tc_stat.processed_entries = processed_dir_count; |
3747 | 3797 | ||
3748 | return &stat; | 3798 | return &tc_stat; |
3749 | } | 3799 | } |
3750 | 3800 | ||
3751 | void tagcache_start_scan(void) | 3801 | void tagcache_start_scan(void) |
3752 | { | 3802 | { |
3753 | queue_post(&tagcache_queue, Q_START_SCAN, 0); | 3803 | queue_post(&tagcache_queue, Q_START_SCAN, 0); |
@@ -3755,7 +3805,7 @@ void tagcache_start_scan(void) | |||
3755 | 3805 | ||
3756 | bool tagcache_update(void) | 3806 | bool tagcache_update(void) |
3757 | { | 3807 | { |
3758 | if (!stat.ready) | 3808 | if (!tc_stat.ready) |
3759 | return false; | 3809 | return false; |
3760 | 3810 | ||
3761 | queue_post(&tagcache_queue, Q_UPDATE, 0); | 3811 | queue_post(&tagcache_queue, Q_UPDATE, 0); |
@@ -3780,31 +3830,41 @@ void tagcache_stop_scan(void) | |||
3780 | #ifdef HAVE_TC_RAMCACHE | 3830 | #ifdef HAVE_TC_RAMCACHE |
3781 | bool tagcache_is_ramcache(void) | 3831 | bool tagcache_is_ramcache(void) |
3782 | { | 3832 | { |
3783 | return stat.ramcache; | 3833 | return tc_stat.ramcache; |
3784 | } | 3834 | } |
3785 | #endif | 3835 | #endif |
3786 | 3836 | ||
3837 | #endif /* !__PCTOOL__ */ | ||
3838 | |||
3787 | 3839 | ||
3788 | void tagcache_init(void) | 3840 | void tagcache_init(void) |
3789 | { | 3841 | { |
3790 | memset(&stat, 0, sizeof(struct tagcache_stat)); | 3842 | memset(&tc_stat, 0, sizeof(struct tagcache_stat)); |
3791 | filenametag_fd = -1; | 3843 | filenametag_fd = -1; |
3792 | current_serial = 0; | 3844 | current_serial = 0; |
3793 | write_lock = read_lock = 0; | 3845 | write_lock = read_lock = 0; |
3794 | 3846 | ||
3847 | #ifndef __PCTOOL__ | ||
3795 | queue_init(&tagcache_queue, true); | 3848 | queue_init(&tagcache_queue, true); |
3796 | create_thread(tagcache_thread, tagcache_stack, | 3849 | create_thread(tagcache_thread, tagcache_stack, |
3797 | sizeof(tagcache_stack), tagcache_thread_name | 3850 | sizeof(tagcache_stack), tagcache_thread_name |
3798 | IF_PRIO(, PRIORITY_BACKGROUND)); | 3851 | IF_PRIO(, PRIORITY_BACKGROUND)); |
3852 | #else | ||
3853 | tc_stat.initialized = true; | ||
3854 | allocate_tempbuf(); | ||
3855 | commit(); | ||
3856 | free_tempbuf(); | ||
3857 | tc_stat.ready = check_all_headers(); | ||
3858 | #endif | ||
3799 | } | 3859 | } |
3800 | 3860 | ||
3801 | bool tagcache_is_initialized(void) | 3861 | bool tagcache_is_initialized(void) |
3802 | { | 3862 | { |
3803 | return stat.initialized; | 3863 | return tc_stat.initialized; |
3804 | } | 3864 | } |
3805 | 3865 | ||
3806 | int tagcache_get_commit_step(void) | 3866 | int tagcache_get_commit_step(void) |
3807 | { | 3867 | { |
3808 | return stat.commit_step; | 3868 | return tc_stat.commit_step; |
3809 | } | 3869 | } |
3810 | 3870 | ||
diff --git a/apps/tagcache.h b/apps/tagcache.h index f1819855db..ea4d255630 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h | |||
@@ -30,6 +30,9 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, | |||
30 | 30 | ||
31 | #define TAG_COUNT 13 | 31 | #define TAG_COUNT 13 |
32 | 32 | ||
33 | /* Maximum length of a single tag. */ | ||
34 | #define TAG_MAXLEN (MAX_PATH*2) | ||
35 | |||
33 | /* Allow a little drift to the filename ordering (should not be too high/low). */ | 36 | /* Allow a little drift to the filename ordering (should not be too high/low). */ |
34 | #define POS_HISTORY_COUNT 4 | 37 | #define POS_HISTORY_COUNT 4 |
35 | 38 | ||
@@ -119,7 +122,7 @@ struct tagcache_search { | |||
119 | int entry_count; | 122 | int entry_count; |
120 | bool valid; | 123 | bool valid; |
121 | bool initialized; | 124 | bool initialized; |
122 | long *unique_list; | 125 | unsigned long *unique_list; |
123 | int unique_list_capacity; | 126 | int unique_list_capacity; |
124 | int unique_list_count; | 127 | int unique_list_count; |
125 | 128 | ||
@@ -133,6 +136,10 @@ struct tagcache_search { | |||
133 | int idx_id; | 136 | int idx_id; |
134 | }; | 137 | }; |
135 | 138 | ||
139 | #ifdef __PCTOOL__ | ||
140 | void build_tagcache(const char *path); | ||
141 | #endif | ||
142 | |||
136 | int tagcache_str_to_tag(const char *str); | 143 | int tagcache_str_to_tag(const char *str); |
137 | const char* tagcache_tag_to_str(int tag); | 144 | const char* tagcache_tag_to_str(int tag); |
138 | 145 | ||