summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-11-10 08:03:33 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-11-10 08:03:33 +0000
commit0dd7ea2d712944b21ede9f57bebd1009b03932e6 (patch)
treedc6065067aa862cc6a71c206b67554270fe507bd
parentae221f140231cb2fd4833443d7810dfce03c606a (diff)
downloadrockbox-0dd7ea2d712944b21ede9f57bebd1009b03932e6.tar.gz
rockbox-0dd7ea2d712944b21ede9f57bebd1009b03932e6.zip
Support building tagcache db natively on PC using the core of the
Rockbox tagcache database engine. Only host endian support at the moment and no command line parameters. Mainly for developers for debugging at the moment. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11497 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/settings.h6
-rw-r--r--apps/tagcache.c270
-rw-r--r--apps/tagcache.h9
-rw-r--r--firmware/common/dircache.c23
-rw-r--r--firmware/export/config.h2
-rw-r--r--firmware/export/debug.h2
-rw-r--r--firmware/export/logf.h10
-rw-r--r--firmware/id3.c12
-rw-r--r--firmware/include/dir.h2
-rw-r--r--firmware/include/dircache.h2
-rw-r--r--firmware/logf.c17
-rw-r--r--firmware/mp3data.c5
-rw-r--r--tools/Makefile9
-rw-r--r--tools/database.c13
-rw-r--r--uisimulator/common/io.c53
15 files changed, 298 insertions, 137 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. */
78static struct event_queue tagcache_queue; 88static struct event_queue tagcache_queue;
79static long tagcache_stack[(DEFAULT_STACK_SIZE + 0x4000)/sizeof(long)]; 89static long tagcache_stack[(DEFAULT_STACK_SIZE + 0x4000)/sizeof(long)];
80static const char tagcache_thread_name[] = "tagcache"; 90static 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. */
83static char curpath[MAX_PATH*2]; 94static char curpath[TAG_MAXLEN+32];
84static long curpath_size = sizeof(curpath); 95static 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. */
108static struct tagcache_stat stat; 119static struct tagcache_stat tc_stat;
109 120
110/* Queue commands. */ 121/* Queue commands. */
111enum tagcache_queue { 122enum tagcache_queue {
@@ -158,7 +169,7 @@ struct ramcache_header {
158# ifdef HAVE_EEPROM_SETTINGS 169# ifdef HAVE_EEPROM_SETTINGS
159struct statefile_header { 170struct 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
855static bool add_uniqbuf(struct tagcache_search *tcs, long id) 866static 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
1147static bool get_next(struct tagcache_search *tcs) 1158static 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
1634static int tempbuf_sort(int fd) 1654static 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)
2497static void allocate_tempbuf(void) 2518static 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
2505static void free_tempbuf(void) 2531static 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
2539long tagcache_increase_serial(void) 2569long 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,
2691static int parse_changelog_line(int line_n, const char *buf, void *parameters) 2721static 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__
2755bool tagcache_import_changelog(void) 2786bool 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
2802bool tagcache_create_changelog(struct tagcache_search *tcs) 2834bool 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
3013static bool allocate_tagcache(void) 3047static 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)
3121static bool load_tagcache(void) 3155static 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)
3351static bool check_deleted_files(void) 3385static 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
3457static void build_tagcache(void) 3499void 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
3562void tagcache_unload_ramcache(void) 3611void 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__
3597static void tagcache_thread(void) 3647static 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)
3711void tagcache_shutdown(void) 3761void 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
3743struct tagcache_stat* tagcache_get_stat(void) 3793struct 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
3751void tagcache_start_scan(void) 3801void 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
3756bool tagcache_update(void) 3806bool 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
3781bool tagcache_is_ramcache(void) 3831bool 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
3788void tagcache_init(void) 3840void 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
3801bool tagcache_is_initialized(void) 3861bool tagcache_is_initialized(void)
3802{ 3862{
3803 return stat.initialized; 3863 return tc_stat.initialized;
3804} 3864}
3805 3865
3806int tagcache_get_commit_step(void) 3866int 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__
140void build_tagcache(const char *path);
141#endif
142
136int tagcache_str_to_tag(const char *str); 143int tagcache_str_to_tag(const char *str);
137const char* tagcache_tag_to_str(int tag); 144const char* tagcache_tag_to_str(int tag);
138 145
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 7222a41221..7227704ffc 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -57,7 +57,7 @@ static unsigned long dircache_size = 0;
57static unsigned long entry_count = 0; 57static unsigned long entry_count = 0;
58static unsigned long reserve_used = 0; 58static unsigned long reserve_used = 0;
59static unsigned int cache_build_ticks = 0; 59static unsigned int cache_build_ticks = 0;
60static char dircache_cur_path[MAX_PATH]; 60static char dircache_cur_path[MAX_PATH*2];
61 61
62static struct event_queue dircache_queue; 62static struct event_queue dircache_queue;
63static long dircache_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; 63static long dircache_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)];
@@ -178,7 +178,7 @@ static int dircache_scan(struct travel_data *td)
178 } 178 }
179 179
180 td->ce->attribute = td->entry->attribute; 180 td->ce->attribute = td->entry->attribute;
181 td->ce->name_len = MIN(254, strlen(td->entry->d_name)) + 1; 181 td->ce->name_len = strlen(td->entry->d_name);
182 td->ce->d_name = ((char *)dircache_root+dircache_size); 182 td->ce->d_name = ((char *)dircache_root+dircache_size);
183 td->ce->size = td->entry->size; 183 td->ce->size = td->entry->size;
184 td->ce->wrtdate = td->entry->wrtdate; 184 td->ce->wrtdate = td->entry->wrtdate;
@@ -192,7 +192,7 @@ static int dircache_scan(struct travel_data *td)
192 } 192 }
193 193
194 td->ce->attribute = td->entry.attr; 194 td->ce->attribute = td->entry.attr;
195 td->ce->name_len = MIN(254, strlen(td->entry.name)) + 1; 195 td->ce->name_len = strlen(td->entry.name) + 1;
196 td->ce->d_name = ((char *)dircache_root+dircache_size); 196 td->ce->d_name = ((char *)dircache_root+dircache_size);
197 td->ce->startcluster = td->entry.firstcluster; 197 td->ce->startcluster = td->entry.firstcluster;
198 td->ce->size = td->entry.filesize; 198 td->ce->size = td->entry.filesize;
@@ -215,9 +215,11 @@ static int dircache_scan(struct travel_data *td)
215 return -2; 215 return -2;
216 216
217 td->pathpos = strlen(dircache_cur_path); 217 td->pathpos = strlen(dircache_cur_path);
218 strncpy(&dircache_cur_path[td->pathpos], "/", MAX_PATH - td->pathpos - 1); 218 strncpy(&dircache_cur_path[td->pathpos], "/",
219 sizeof(dircache_cur_path) - td->pathpos - 1);
219#ifdef SIMULATOR 220#ifdef SIMULATOR
220 strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, MAX_PATH - td->pathpos - 2); 221 strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name,
222 sizeof(dircache_cur_path) - td->pathpos - 2);
221 223
222 td->newdir = opendir(dircache_cur_path); 224 td->newdir = opendir(dircache_cur_path);
223 if (td->newdir == NULL) 225 if (td->newdir == NULL)
@@ -226,7 +228,8 @@ static int dircache_scan(struct travel_data *td)
226 return -3; 228 return -3;
227 } 229 }
228#else 230#else
229 strncpy(&dircache_cur_path[td->pathpos+1], td->entry.name, MAX_PATH - td->pathpos - 2); 231 strncpy(&dircache_cur_path[td->pathpos+1], td->entry.name,
232 sizeof(dircache_cur_path) - td->pathpos - 2);
230 233
231 td->newdir = *td->dir; 234 td->newdir = *td->dir;
232 if (fat_opendir(IF_MV2(volume,) &td->newdir, 235 if (fat_opendir(IF_MV2(volume,) &td->newdir,
@@ -360,7 +363,7 @@ static struct dircache_entry* dircache_get_entry(const char *path,
360 bool get_before, bool only_directories) 363 bool get_before, bool only_directories)
361{ 364{
362 struct dircache_entry *cache_entry, *before; 365 struct dircache_entry *cache_entry, *before;
363 char namecopy[MAX_PATH]; 366 char namecopy[MAX_PATH*2];
364 char* part; 367 char* part;
365 char* end; 368 char* end;
366 369
@@ -543,7 +546,7 @@ static int dircache_do_rebuild(void)
543 pdir = &dir; 546 pdir = &dir;
544#endif 547#endif
545 548
546 memset(dircache_cur_path, 0, MAX_PATH); 549 memset(dircache_cur_path, 0, sizeof(dircache_cur_path));
547 dircache_size = sizeof(struct dircache_entry); 550 dircache_size = sizeof(struct dircache_entry);
548 551
549 cpu_boost_id(true, CPUBOOSTID_DIRCACHE); 552 cpu_boost_id(true, CPUBOOSTID_DIRCACHE);
@@ -837,7 +840,7 @@ static int block_until_ready(void)
837static struct dircache_entry* dircache_new_entry(const char *path, int attribute) 840static struct dircache_entry* dircache_new_entry(const char *path, int attribute)
838{ 841{
839 struct dircache_entry *entry; 842 struct dircache_entry *entry;
840 char basedir[MAX_PATH]; 843 char basedir[MAX_PATH*2];
841 char *new; 844 char *new;
842 long last_cache_size = dircache_size; 845 long last_cache_size = dircache_size;
843 846
@@ -1005,7 +1008,7 @@ void dircache_rename(const char *oldpath, const char *newpath)
1005{ /* Test ok. */ 1008{ /* Test ok. */
1006 struct dircache_entry *entry, *newentry; 1009 struct dircache_entry *entry, *newentry;
1007 struct dircache_entry oldentry; 1010 struct dircache_entry oldentry;
1008 char absolute_path[MAX_PATH]; 1011 char absolute_path[MAX_PATH*2];
1009 char *p; 1012 char *p;
1010 1013
1011 if (block_until_ready()) 1014 if (block_until_ready())
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 18c0ef7d17..45d974a96f 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -20,7 +20,9 @@
20#ifndef __CONFIG_H__ 20#ifndef __CONFIG_H__
21#define __CONFIG_H__ 21#define __CONFIG_H__
22 22
23#ifndef __PCTOOL__
23#include "autoconf.h" 24#include "autoconf.h"
25#endif
24 26
25/* symbolic names for multiple choice configurations: */ 27/* symbolic names for multiple choice configurations: */
26 28
diff --git a/firmware/export/debug.h b/firmware/export/debug.h
index 52b6687c6b..ce556d6418 100644
--- a/firmware/export/debug.h
+++ b/firmware/export/debug.h
@@ -26,7 +26,7 @@ extern void ldebugf(const char* file, int line, const char *fmt, ...);
26#ifdef __GNUC__ 26#ifdef __GNUC__
27 27
28/* */ 28/* */
29#if defined(SIMULATOR) 29#if defined(SIMULATOR) && !defined(__PCTOOL__)
30#define DEBUGF debugf 30#define DEBUGF debugf
31#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__) 31#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__)
32#else 32#else
diff --git a/firmware/export/logf.h b/firmware/export/logf.h
index 4206173596..35cb7127e4 100644
--- a/firmware/export/logf.h
+++ b/firmware/export/logf.h
@@ -23,6 +23,7 @@
23 23
24#ifdef ROCKBOX_HAS_LOGF 24#ifdef ROCKBOX_HAS_LOGF
25 25
26#ifndef __PCTOOL__
26#define MAX_LOGF_LINES 1000 27#define MAX_LOGF_LINES 1000
27#define MAX_LOGF_ENTRY 30 28#define MAX_LOGF_ENTRY 30
28#define MAX_LOGF_DATASIZE (MAX_LOGF_ENTRY*MAX_LOGF_LINES) 29#define MAX_LOGF_DATASIZE (MAX_LOGF_ENTRY*MAX_LOGF_LINES)
@@ -30,11 +31,14 @@
30extern unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY]; 31extern unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY];
31extern int logfindex; 32extern int logfindex;
32extern bool logfwrap; 33extern bool logfwrap;
34#endif /* __PCTOOL__ */
33 35
34void logf(const char *format, ...); 36#define logf _logf
35#else 37void _logf(const char *format, ...);
38
39#else /* !ROCKBOX_HAS_LOGF */
36/* built without logf() support enabled */ 40/* built without logf() support enabled */
37#define logf(...) 41#define logf(...)
38#endif 42#endif /* !ROCKBOX_HAS_LOGF */
39 43
40#endif /* LOGF_H */ 44#endif /* LOGF_H */
diff --git a/firmware/id3.c b/firmware/id3.c
index 470f4dc352..90b5b3bdee 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -457,9 +457,9 @@ static int unicode_munge(char* string, char* utf8buf, int *len) {
457 long tmp; 457 long tmp;
458 bool le = false; 458 bool le = false;
459 int i = 0; 459 int i = 0;
460 char *str = string; 460 unsigned char *str = (unsigned char *)string;
461 int templen = 0; 461 int templen = 0;
462 char* utf8 = utf8buf; 462 unsigned char* utf8 = (unsigned char *)utf8buf;
463 463
464 switch (str[0]) { 464 switch (str[0]) {
465 case 0x00: /* Type 0x00 is ordinary ISO 8859-1 */ 465 case 0x00: /* Type 0x00 is ordinary ISO 8859-1 */
@@ -467,7 +467,7 @@ static int unicode_munge(char* string, char* utf8buf, int *len) {
467 (*len)--; 467 (*len)--;
468 utf8 = iso_decode(str, utf8, -1, *len); 468 utf8 = iso_decode(str, utf8, -1, *len);
469 *utf8 = 0; 469 *utf8 = 0;
470 *len = utf8 - utf8buf; 470 *len = (unsigned long)utf8 - (unsigned long)utf8buf;
471 break; 471 break;
472 472
473 case 0x01: /* Unicode with or without BOM */ 473 case 0x01: /* Unicode with or without BOM */
@@ -524,7 +524,7 @@ static int unicode_munge(char* string, char* utf8buf, int *len) {
524 default: /* Plain old string */ 524 default: /* Plain old string */
525 utf8 = iso_decode(str, utf8, -1, *len); 525 utf8 = iso_decode(str, utf8, -1, *len);
526 *utf8 = 0; 526 *utf8 = 0;
527 *len = utf8 - utf8buf; 527 *len = (unsigned long)utf8 - (unsigned long)utf8buf;
528 break; 528 break;
529 } 529 }
530 return 0; 530 return 0;
@@ -571,7 +571,7 @@ static bool setid3v1title(int fd, struct mp3entry *entry)
571 case 1: 571 case 1:
572 case 2: 572 case 2:
573 /* convert string to utf8 */ 573 /* convert string to utf8 */
574 utf8 = entry->id3v1buf[i]; 574 utf8 = (unsigned char *)entry->id3v1buf[i];
575 utf8 = iso_decode(ptr, utf8, -1, 30); 575 utf8 = iso_decode(ptr, utf8, -1, 30);
576 /* make sure string is terminated */ 576 /* make sure string is terminated */
577 *utf8 = 0; 577 *utf8 = 0;
@@ -579,7 +579,7 @@ static bool setid3v1title(int fd, struct mp3entry *entry)
579 579
580 case 3: 580 case 3:
581 ptr[4] = 0; 581 ptr[4] = 0;
582 entry->year = atoi(ptr); 582 entry->year = atoi((char *)ptr);
583 break; 583 break;
584 584
585 case 4: 585 case 4:
diff --git a/firmware/include/dir.h b/firmware/include/dir.h
index 948b30ffe2..c10640199f 100644
--- a/firmware/include/dir.h
+++ b/firmware/include/dir.h
@@ -20,7 +20,7 @@
20#define _DIR_H_ 20#define _DIR_H_
21 21
22#include <stdbool.h> 22#include <stdbool.h>
23#include <file.h> 23#include "file.h"
24 24
25#define ATTR_READ_ONLY 0x01 25#define ATTR_READ_ONLY 0x01
26#define ATTR_HIDDEN 0x02 26#define ATTR_HIDDEN 0x02
diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h
index f6bc153faf..9c3bc68ddc 100644
--- a/firmware/include/dircache.h
+++ b/firmware/include/dircache.h
@@ -67,7 +67,7 @@ struct dircache_entry {
67 long startcluster; 67 long startcluster;
68 unsigned short wrtdate; 68 unsigned short wrtdate;
69 unsigned short wrttime; 69 unsigned short wrttime;
70 unsigned char name_len; 70 unsigned long name_len;
71 char *d_name; 71 char *d_name;
72}; 72};
73 73
diff --git a/firmware/logf.c b/firmware/logf.c
index fc57bd85bf..2056db5cc4 100644
--- a/firmware/logf.c
+++ b/firmware/logf.c
@@ -27,7 +27,6 @@
27#include <string.h> 27#include <string.h>
28#include <stdio.h> 28#include <stdio.h>
29#include <stdarg.h> 29#include <stdarg.h>
30#include <sprintf.h>
31#include "config.h" 30#include "config.h"
32#include "lcd-remote.h" 31#include "lcd-remote.h"
33#include "logf.h" 32#include "logf.h"
@@ -36,9 +35,11 @@
36/* Only provide all this if asked to */ 35/* Only provide all this if asked to */
37#ifdef ROCKBOX_HAS_LOGF 36#ifdef ROCKBOX_HAS_LOGF
38 37
38#ifndef __PCTOOL__
39unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY]; 39unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY];
40int logfindex; 40int logfindex;
41bool logfwrap; 41bool logfwrap;
42#endif
42 43
43#ifdef HAVE_REMOTE_LCD 44#ifdef HAVE_REMOTE_LCD
44static void displayremote(void) 45static void displayremote(void)
@@ -77,7 +78,18 @@ static void displayremote(void)
77#define displayremote() 78#define displayremote()
78#endif 79#endif
79 80
80void logf(const char *format, ...) 81#ifdef __PCTOOL__
82void _logf(const char *format, ...)
83{
84 char buf[1024];
85 va_list ap;
86 va_start(ap, format);
87
88 vsnprintf(buf, sizeof buf, format, ap);
89 printf("DEBUG: %s\n", buf);
90}
91#else
92void _logf(const char *format, ...)
81{ 93{
82 int len; 94 int len;
83 unsigned char *ptr; 95 unsigned char *ptr;
@@ -104,5 +116,6 @@ void logf(const char *format, ...)
104 116
105 displayremote(); 117 displayremote();
106} 118}
119#endif
107 120
108#endif 121#endif
diff --git a/firmware/mp3data.c b/firmware/mp3data.c
index 0710090b37..49b95f2d9e 100644
--- a/firmware/mp3data.c
+++ b/firmware/mp3data.c
@@ -242,6 +242,7 @@ unsigned long find_next_frame(int fd, long *offset, long max_offset, unsigned lo
242 return __find_next_frame(fd, offset, max_offset, last_header, fileread); 242 return __find_next_frame(fd, offset, max_offset, last_header, fileread);
243} 243}
244 244
245#ifndef __PCTOOL__
245static int fnf_read_index; 246static int fnf_read_index;
246static int fnf_buf_len; 247static int fnf_buf_len;
247 248
@@ -335,6 +336,7 @@ unsigned long mem_find_next_frame(int startpos, long *offset, long max_offset,
335 336
336 return __find_next_frame(0, offset, max_offset, last_header, mem_getbyte); 337 return __find_next_frame(0, offset, max_offset, last_header, mem_getbyte);
337} 338}
339#endif
338 340
339int get_mp3file_info(int fd, struct mp3info *info) 341int get_mp3file_info(int fd, struct mp3info *info)
340{ 342{
@@ -543,6 +545,7 @@ static void long2bytes(unsigned char *buf, long val)
543 buf[3] = val & 0xff; 545 buf[3] = val & 0xff;
544} 546}
545 547
548#ifndef __PCTOOL__
546int count_mp3_frames(int fd, int startpos, int filesize, 549int count_mp3_frames(int fd, int startpos, int filesize,
547 void (*progressfunc)(int)) 550 void (*progressfunc)(int))
548{ 551{
@@ -762,3 +765,5 @@ int create_xing_header(int fd, long startpos, long filesize,
762 765
763 return info.frame_size; 766 return info.frame_size;
764} 767}
768
769#endif
diff --git a/tools/Makefile b/tools/Makefile
index 1f8be87370..d6c885d85b 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -10,7 +10,7 @@ CFLAGS := -O -ansi -g
10LDFLAGS := -g 10LDFLAGS := -g
11 11
12CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \ 12CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \
13 generate_rocklatin mkboot ipod_fw codepages uclpack mi4 gigabeat 13 generate_rocklatin mkboot ipod_fw codepages uclpack mi4 gigabeat database
14 14
15all: 15all:
16 @echo "Run make in your build directory!" 16 @echo "Run make in your build directory!"
@@ -38,6 +38,13 @@ mkboot: mkboot.c
38ipod_fw: ipod_fw.c 38ipod_fw: ipod_fw.c
39 $(SILENT)$(CC) -g $+ -o $@ 39 $(SILENT)$(CC) -g $+ -o $@
40 40
41database: database.c ../apps/tagcache.c ../apps/metadata.c \
42../firmware/id3.c ../firmware/common/unicode.c \
43../firmware/common/crc32.c ../uisimulator/common/io.c \
44../firmware/mp3data.c ../firmware/logf.c
45 $(SILENT)$(CC) -g -I../firmware/export -iquote ../firmware/include \
46-D__PCTOOL__ -DHAVE_TAGCACHE -DROCKBOX_HAS_LOGF -DSIMULATOR -ldl -I../apps $+ -o $@
47
41convbdf: convbdf.c 48convbdf: convbdf.c
42 $(SILENT)$(CC) -g $+ -o $@ 49 $(SILENT)$(CC) -g $+ -o $@
43 50
diff --git a/tools/database.c b/tools/database.c
new file mode 100644
index 0000000000..780586ea90
--- /dev/null
+++ b/tools/database.c
@@ -0,0 +1,13 @@
1/* A _very_ skeleton file to demonstrate building tagcache db on host. */
2
3#include <stdio.h>
4#include "tagcache.h"
5
6int main(int argc, char **argv)
7{
8 tagcache_init();
9 build_tagcache("/export/stuff/mp3");
10
11 return 0;
12}
13
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index c4f8840cc5..ca64affa8c 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -106,11 +106,14 @@ MYDIR *sim_opendir(const char *name)
106 char buffer[256]; /* sufficiently big */ 106 char buffer[256]; /* sufficiently big */
107 DIR *dir; 107 DIR *dir;
108 108
109 if(name[0] == '/') { 109#ifndef __PCTOOL__
110 if(name[0] == '/')
111 {
110 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); 112 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
111 dir=(DIR *)opendir(buffer); 113 dir=(DIR *)opendir(buffer);
112 } 114 }
113 else 115 else
116#endif
114 dir=(DIR *)opendir(name); 117 dir=(DIR *)opendir(name);
115 118
116 if(dir) { 119 if(dir) {
@@ -137,8 +140,12 @@ struct sim_dirent *sim_readdir(MYDIR *dir)
137 strcpy((char *)secret.d_name, x11->d_name); 140 strcpy((char *)secret.d_name, x11->d_name);
138 141
139 /* build file name */ 142 /* build file name */
143#ifdef __PCTOOL__
144 sprintf(buffer, "%s/%s", dir->name, x11->d_name);
145#else
140 sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s", 146 sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s",
141 dir->name, x11->d_name); 147 dir->name, x11->d_name);
148#endif
142 stat(buffer, &s); /* get info */ 149 stat(buffer, &s); /* get info */
143 150
144#define ATTR_DIRECTORY 0x10 151#define ATTR_DIRECTORY 0x10
@@ -164,22 +171,32 @@ int sim_open(const char *name, int o)
164 char buffer[256]; /* sufficiently big */ 171 char buffer[256]; /* sufficiently big */
165 int opts = rockbox2sim(o); 172 int opts = rockbox2sim(o);
166 173
167 if(name[0] == '/') { 174#ifndef __PCTOOL__
175 if(name[0] == '/')
176 {
168 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); 177 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
169 178
170 debugf("We open the real file '%s'\n", buffer); 179 debugf("We open the real file '%s'\n", buffer);
171 return open(buffer, opts, 0666); 180 return open(buffer, opts, 0666);
172 } 181 }
182
173 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", 183 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
174 name); 184 name);
175 return -1; 185 return -1;
186#else
187 return open(name, opts, 0666);
188#endif
189
176} 190}
177 191
178int sim_creat(const char *name, mode_t mode) 192int sim_creat(const char *name, mode_t mode)
179{ 193{
180 char buffer[256]; /* sufficiently big */
181 int opts = rockbox2sim(mode); 194 int opts = rockbox2sim(mode);
182 if(name[0] == '/') { 195
196#ifndef __PCTOOL__
197 char buffer[256]; /* sufficiently big */
198 if(name[0] == '/')
199 {
183 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); 200 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
184 201
185 debugf("We create the real file '%s'\n", buffer); 202 debugf("We create the real file '%s'\n", buffer);
@@ -188,12 +205,22 @@ int sim_creat(const char *name, mode_t mode)
188 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", 205 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
189 name); 206 name);
190 return -1; 207 return -1;
208#else
209 return open(name, opts | O_CREAT | O_TRUNC, 0666);
210#endif
191} 211}
192 212
193int sim_mkdir(const char *name, mode_t mode) 213int sim_mkdir(const char *name, mode_t mode)
194{ 214{
195 char buffer[256]; /* sufficiently big */
196 (void)mode; 215 (void)mode;
216#ifdef __PCTOOL__
217# ifdef WIN32
218 return mkdir(name);
219# else
220 return mkdir(name, 0777);
221# endif
222#else
223 char buffer[256]; /* sufficiently big */
197 224
198 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); 225 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
199 226
@@ -204,22 +231,31 @@ int sim_mkdir(const char *name, mode_t mode)
204#else 231#else
205 return mkdir(buffer, 0777); 232 return mkdir(buffer, 0777);
206#endif 233#endif
234#endif
207} 235}
208 236
209int sim_rmdir(const char *name) 237int sim_rmdir(const char *name)
210{ 238{
239#ifdef __PCTOOL__
240 return rmdir(name);
241#else
211 char buffer[256]; /* sufficiently big */ 242 char buffer[256]; /* sufficiently big */
212 if(name[0] == '/') { 243 if(name[0] == '/')
244 {
213 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); 245 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
214 246
215 debugf("We remove the real directory '%s'\n", buffer); 247 debugf("We remove the real directory '%s'\n", buffer);
216 return rmdir(buffer); 248 return rmdir(buffer);
217 } 249 }
218 return rmdir(name); 250 return rmdir(name);
251#endif
219} 252}
220 253
221int sim_remove(const char *name) 254int sim_remove(const char *name)
222{ 255{
256#ifdef __PCTOOL__
257 return remove(name);
258#else
223 char buffer[256]; /* sufficiently big */ 259 char buffer[256]; /* sufficiently big */
224 260
225#ifdef HAVE_DIRCACHE 261#ifdef HAVE_DIRCACHE
@@ -233,10 +269,14 @@ int sim_remove(const char *name)
233 return remove(buffer); 269 return remove(buffer);
234 } 270 }
235 return remove(name); 271 return remove(name);
272#endif
236} 273}
237 274
238int sim_rename(const char *oldpath, const char* newpath) 275int sim_rename(const char *oldpath, const char* newpath)
239{ 276{
277#ifdef __PCTOOL__
278 return rename(oldpath, newpath);
279#else
240 char buffer1[256]; 280 char buffer1[256];
241 char buffer2[256]; 281 char buffer2[256];
242 282
@@ -252,6 +292,7 @@ int sim_rename(const char *oldpath, const char* newpath)
252 return rename(buffer1, buffer2); 292 return rename(buffer1, buffer2);
253 } 293 }
254 return -1; 294 return -1;
295#endif
255} 296}
256 297
257/* rockbox off_t may be different from system off_t */ 298/* rockbox off_t may be different from system off_t */