summaryrefslogtreecommitdiff
path: root/firmware/common/dircache.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/dircache.c')
-rw-r--r--firmware/common/dircache.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 6167aa3933..d2c77a2e25 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -402,7 +402,7 @@ static struct dircache_entry* dircache_get_entry(const char *path,
402 return cache_entry; 402 return cache_entry;
403} 403}
404 404
405#if 0 405#if 1
406/** 406/**
407 * Function to load the internal cache structure from disk to initialize 407 * Function to load the internal cache structure from disk to initialize
408 * the dircache really fast and little disk access. 408 * the dircache really fast and little disk access.
@@ -423,32 +423,41 @@ int dircache_load(const char *path)
423 if (fd < 0) 423 if (fd < 0)
424 return -2; 424 return -2;
425 425
426 dircache_root = (struct dircache_entry *)(((long)audiobuf & ~0x03) + 0x04);
427 bytes_read = read(fd, &maindata, sizeof(struct dircache_maindata)); 426 bytes_read = read(fd, &maindata, sizeof(struct dircache_maindata));
428 if (bytes_read != sizeof(struct dircache_maindata) 427 if (bytes_read != sizeof(struct dircache_maindata)
429 || (long)maindata.root_entry != (long)dircache_root
430 || maindata.size <= 0) 428 || maindata.size <= 0)
431 { 429 {
430 logf("Dircache file header error");
432 close(fd); 431 close(fd);
433 return -3; 432 return -3;
434 } 433 }
435 434
435 dircache_root = buffer_alloc(0);
436 if ((long)maindata.root_entry != (long)dircache_root)
437 {
438 logf("Position missmatch");
439 close(fd);
440 return -4;
441 }
442
443 dircache_root = buffer_alloc(maindata.size + DIRCACHE_RESERVE);
436 entry_count = maindata.entry_count; 444 entry_count = maindata.entry_count;
437 bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size)); 445 bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size));
438 close(fd); 446 close(fd);
439 447
440 if (bytes_read != maindata.size) 448 if (bytes_read != maindata.size)
449 {
450 logf("Dircache read failed");
441 return -6; 451 return -6;
452 }
442 453
443 /* Cache successfully loaded. */ 454 /* Cache successfully loaded. */
444 dircache_size = maindata.size; 455 dircache_size = maindata.size;
456 allocated_size = dircache_size + DIRCACHE_RESERVE;
457 reserve_used = 0;
445 logf("Done, %d KiB used", dircache_size / 1024); 458 logf("Done, %d KiB used", dircache_size / 1024);
446 dircache_initialized = true; 459 dircache_initialized = true;
447 memset(fd_bindings, 0, sizeof(fd_bindings)); 460 memset(fd_bindings, 0, sizeof(fd_bindings));
448
449 /* We have to long align the audiobuf to keep the buffer access fast. */
450 audiobuf += (long)((dircache_size & ~0x03) + 0x04);
451 audiobuf += DIRCACHE_RESERVE;
452 461
453 return 0; 462 return 0;
454} 463}
@@ -472,7 +481,7 @@ int dircache_save(const char *path)
472 return -1; 481 return -1;
473 482
474 logf("Saving directory cache"); 483 logf("Saving directory cache");
475 fd = open(path, O_WRONLY | O_CREAT); 484 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC);
476 485
477 maindata.magic = DIRCACHE_MAGIC; 486 maindata.magic = DIRCACHE_MAGIC;
478 maindata.size = dircache_size; 487 maindata.size = dircache_size;
@@ -484,6 +493,7 @@ int dircache_save(const char *path)
484 if (bytes_written != sizeof(struct dircache_maindata)) 493 if (bytes_written != sizeof(struct dircache_maindata))
485 { 494 {
486 close(fd); 495 close(fd);
496 logf("dircache: write failed #1");
487 return -2; 497 return -2;
488 } 498 }
489 499
@@ -491,8 +501,11 @@ int dircache_save(const char *path)
491 bytes_written = write(fd, dircache_root, dircache_size); 501 bytes_written = write(fd, dircache_root, dircache_size);
492 close(fd); 502 close(fd);
493 if (bytes_written != dircache_size) 503 if (bytes_written != dircache_size)
504 {
505 logf("dircache: write failed #2");
494 return -3; 506 return -3;
495 507 }
508
496 return 0; 509 return 0;
497} 510}
498#endif /* #if 0 */ 511#endif /* #if 0 */
@@ -616,6 +629,7 @@ int dircache_build(int last_size)
616 return -3; 629 return -3;
617 630
618 logf("Building directory cache"); 631 logf("Building directory cache");
632 /* Background build, dircache has been previously allocated */
619 if (dircache_size > 0) 633 if (dircache_size > 0)
620 { 634 {
621 thread_enabled = true; 635 thread_enabled = true;