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.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 18039ee038..0523493a32 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -410,7 +410,7 @@ static struct dircache_entry* dircache_get_entry(const char *path,
410 * Function to load the internal cache structure from disk to initialize 410 * Function to load the internal cache structure from disk to initialize
411 * the dircache really fast and little disk access. 411 * the dircache really fast and little disk access.
412 */ 412 */
413int dircache_load(const char *path) 413int dircache_load(void)
414{ 414{
415 struct dircache_maindata maindata; 415 struct dircache_maindata maindata;
416 int bytes_read; 416 int bytes_read;
@@ -422,7 +422,7 @@ int dircache_load(const char *path)
422 logf("Loading directory cache"); 422 logf("Loading directory cache");
423 dircache_size = 0; 423 dircache_size = 0;
424 424
425 fd = open(path, O_RDONLY); 425 fd = open(DIRCACHE_FILE, O_RDONLY);
426 if (fd < 0) 426 if (fd < 0)
427 return -2; 427 return -2;
428 428
@@ -432,6 +432,7 @@ int dircache_load(const char *path)
432 { 432 {
433 logf("Dircache file header error"); 433 logf("Dircache file header error");
434 close(fd); 434 close(fd);
435 remove(DIRCACHE_FILE);
435 return -3; 436 return -3;
436 } 437 }
437 438
@@ -440,6 +441,7 @@ int dircache_load(const char *path)
440 { 441 {
441 logf("Position missmatch"); 442 logf("Position missmatch");
442 close(fd); 443 close(fd);
444 remove(DIRCACHE_FILE);
443 return -4; 445 return -4;
444 } 446 }
445 447
@@ -447,6 +449,7 @@ int dircache_load(const char *path)
447 entry_count = maindata.entry_count; 449 entry_count = maindata.entry_count;
448 bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size)); 450 bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size));
449 close(fd); 451 close(fd);
452 remove(DIRCACHE_FILE);
450 453
451 if (bytes_read != maindata.size) 454 if (bytes_read != maindata.size)
452 { 455 {
@@ -469,13 +472,13 @@ int dircache_load(const char *path)
469 * Function to save the internal cache stucture to disk for fast loading 472 * Function to save the internal cache stucture to disk for fast loading
470 * on boot. 473 * on boot.
471 */ 474 */
472int dircache_save(const char *path) 475int dircache_save(void)
473{ 476{
474 struct dircache_maindata maindata; 477 struct dircache_maindata maindata;
475 int fd; 478 int fd;
476 unsigned long bytes_written; 479 unsigned long bytes_written;
477 480
478 remove(path); 481 remove(DIRCACHE_FILE);
479 482
480 while (thread_enabled) 483 while (thread_enabled)
481 sleep(1); 484 sleep(1);
@@ -484,7 +487,7 @@ int dircache_save(const char *path)
484 return -1; 487 return -1;
485 488
486 logf("Saving directory cache"); 489 logf("Saving directory cache");
487 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC); 490 fd = open(DIRCACHE_FILE, O_WRONLY | O_CREAT | O_TRUNC);
488 491
489 maindata.magic = DIRCACHE_MAGIC; 492 maindata.magic = DIRCACHE_MAGIC;
490 maindata.size = dircache_size; 493 maindata.size = dircache_size;
@@ -529,6 +532,7 @@ static int dircache_do_rebuild(void)
529 /* Measure how long it takes build the cache. */ 532 /* Measure how long it takes build the cache. */
530 start_tick = current_tick; 533 start_tick = current_tick;
531 dircache_initializing = true; 534 dircache_initializing = true;
535 remove(DIRCACHE_FILE);
532 536
533#ifdef SIMULATOR 537#ifdef SIMULATOR
534 pdir = opendir("/"); 538 pdir = opendir("/");
@@ -633,6 +637,8 @@ int dircache_build(int last_size)
633 return -3; 637 return -3;
634 638
635 logf("Building directory cache"); 639 logf("Building directory cache");
640 remove(DIRCACHE_FILE);
641
636 /* Background build, dircache has been previously allocated */ 642 /* Background build, dircache has been previously allocated */
637 if (dircache_size > 0) 643 if (dircache_size > 0)
638 { 644 {