summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-07-26 13:41:47 +0000
committerThomas Martitz <kugel@rockbox.org>2010-07-26 13:41:47 +0000
commit74085d21031c77194958f71f5e3f565e4d66534b (patch)
treef06641c22f92ceac35c3ebae787ce15a6a739e0f
parentbd77d021f0a7dfa8dc9ee9ac3bdc84a54ac87537 (diff)
downloadrockbox-74085d21031c77194958f71f5e3f565e4d66534b.tar.gz
rockbox-74085d21031c77194958f71f5e3f565e4d66534b.zip
Factor out opening and removing DIRCACHE_FILE into separate functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27575 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/dircache.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 0a58175d53..906527f8f2 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -82,6 +82,26 @@ static int fdbind_idx = 0;
82 82
83/* --- Internal cache structure control functions --- */ 83/* --- Internal cache structure control functions --- */
84 84
85#ifdef HAVE_EEPROM_SETTINGS
86/**
87 * Open the dircache file to save a snapshot on disk
88 */
89static int open_dircache_file(unsigned flags, int permissions)
90{
91 if (permissions != 0)
92 return open(DIRCACHE_FILE, flags, permissions);
93
94 return open(DIRCACHE_FILE, flags);
95}
96
97/**
98 * Remove the snapshot file
99 */
100static int remove_dircache_file(void)
101{
102 return remove(DIRCACHE_FILE);
103}
104#endif
85/** 105/**
86 * Internal function to allocate a new dircache_entry from memory. 106 * Internal function to allocate a new dircache_entry from memory.
87 */ 107 */
@@ -494,7 +514,7 @@ int dircache_load(void)
494 logf("Loading directory cache"); 514 logf("Loading directory cache");
495 dircache_size = 0; 515 dircache_size = 0;
496 516
497 fd = open(DIRCACHE_FILE, O_RDONLY); 517 fd = open_dircache_file(O_RDONLY, 0);
498 if (fd < 0) 518 if (fd < 0)
499 return -2; 519 return -2;
500 520
@@ -504,7 +524,7 @@ int dircache_load(void)
504 { 524 {
505 logf("Dircache file header error"); 525 logf("Dircache file header error");
506 close(fd); 526 close(fd);
507 remove(DIRCACHE_FILE); 527 remove_dircache_file();
508 return -3; 528 return -3;
509 } 529 }
510 530
@@ -513,7 +533,7 @@ int dircache_load(void)
513 { 533 {
514 logf("Position missmatch"); 534 logf("Position missmatch");
515 close(fd); 535 close(fd);
516 remove(DIRCACHE_FILE); 536 remove_dircache_file();
517 return -4; 537 return -4;
518 } 538 }
519 539
@@ -522,7 +542,7 @@ int dircache_load(void)
522 appflags = maindata.appflags; 542 appflags = maindata.appflags;
523 bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size)); 543 bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size));
524 close(fd); 544 close(fd);
525 remove(DIRCACHE_FILE); 545 remove_dircache_file();
526 546
527 if (bytes_read != maindata.size) 547 if (bytes_read != maindata.size)
528 { 548 {
@@ -551,13 +571,13 @@ int dircache_save(void)
551 int fd; 571 int fd;
552 unsigned long bytes_written; 572 unsigned long bytes_written;
553 573
554 remove(DIRCACHE_FILE); 574 remove_dircache_file();
555 575
556 if (!dircache_initialized) 576 if (!dircache_initialized)
557 return -1; 577 return -1;
558 578
559 logf("Saving directory cache"); 579 logf("Saving directory cache");
560 fd = open(DIRCACHE_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666); 580 fd = open_dircache_file(O_WRONLY | O_CREAT | O_TRUNC, 0666);
561 581
562 maindata.magic = DIRCACHE_MAGIC; 582 maindata.magic = DIRCACHE_MAGIC;
563 maindata.size = dircache_size; 583 maindata.size = dircache_size;
@@ -585,7 +605,7 @@ int dircache_save(void)
585 605
586 return 0; 606 return 0;
587} 607}
588#endif /* #if 0 */ 608#endif /* HAVE_EEPROM_SETTINGS */
589 609
590/** 610/**
591 * Internal function which scans the disk and creates the dircache structure. 611 * Internal function which scans the disk and creates the dircache structure.
@@ -709,8 +729,10 @@ int dircache_build(int last_size)
709 return -3; 729 return -3;
710 730
711 logf("Building directory cache"); 731 logf("Building directory cache");
712 remove(DIRCACHE_FILE); 732#ifdef HAVE_EEPROM_SETTINGS
713 733 remove_dircache_file();
734#endif
735
714 /* Background build, dircache has been previously allocated */ 736 /* Background build, dircache has been previously allocated */
715 if (dircache_size > 0) 737 if (dircache_size > 0)
716 { 738 {