diff options
-rw-r--r-- | apps/main.c | 45 | ||||
-rw-r--r-- | apps/tree.c | 3 | ||||
-rw-r--r-- | firmware/common/dircache.c | 16 | ||||
-rw-r--r-- | firmware/include/dircache.h | 7 |
4 files changed, 42 insertions, 29 deletions
diff --git a/apps/main.c b/apps/main.c index f9e6054973..0b35a61a75 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -128,25 +128,32 @@ static int init_dircache(bool preinit) | |||
128 | if (preinit) | 128 | if (preinit) |
129 | dircache_init(); | 129 | dircache_init(); |
130 | 130 | ||
131 | if (global_settings.dircache) | 131 | if (!global_settings.dircache) |
132 | { | 132 | return 0; |
133 | |||
133 | # ifdef HAVE_EEPROM_SETTINGS | 134 | # ifdef HAVE_EEPROM_SETTINGS |
134 | if (firmware_settings.initialized && firmware_settings.disk_clean | 135 | if (firmware_settings.initialized && firmware_settings.disk_clean |
135 | && preinit) | 136 | && preinit) |
137 | { | ||
138 | result = dircache_load(); | ||
139 | |||
140 | if (result < 0) | ||
136 | { | 141 | { |
137 | result = dircache_load(DIRCACHE_FILE); | 142 | firmware_settings.disk_clean = false; |
138 | remove(DIRCACHE_FILE); | 143 | if (global_settings.dircache_size <= 0) |
139 | if (result < 0) | ||
140 | { | 144 | { |
141 | firmware_settings.disk_clean = false; | 145 | /* This will be in default language, settings are not |
142 | if (global_settings.dircache_size >= 0) | 146 | applied yet. Not really any easy way to fix that. */ |
143 | dircache_build(global_settings.dircache_size); | 147 | gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING)); |
148 | clear = true; | ||
144 | } | 149 | } |
145 | 150 | ||
146 | return result; | 151 | dircache_build(global_settings.dircache_size); |
147 | } | 152 | } |
153 | } | ||
154 | else | ||
148 | # endif | 155 | # endif |
149 | 156 | { | |
150 | if (preinit) | 157 | if (preinit) |
151 | return -1; | 158 | return -1; |
152 | 159 | ||
@@ -163,12 +170,12 @@ static int init_dircache(bool preinit) | |||
163 | 170 | ||
164 | if (result < 0) | 171 | if (result < 0) |
165 | gui_syncsplash(0, true, "Failed! Result: %d", result); | 172 | gui_syncsplash(0, true, "Failed! Result: %d", result); |
166 | 173 | } | |
167 | if (clear) | 174 | |
168 | { | 175 | if (clear) |
169 | backlight_on(); | 176 | { |
170 | show_logo(); | 177 | backlight_on(); |
171 | } | 178 | show_logo(); |
172 | global_settings.dircache_size = dircache_get_cache_size(); | 179 | global_settings.dircache_size = dircache_get_cache_size(); |
173 | settings_save(); | 180 | settings_save(); |
174 | } | 181 | } |
diff --git a/apps/tree.c b/apps/tree.c index 104344ee59..f0cf377041 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -1443,8 +1443,7 @@ void tree_flush(void) | |||
1443 | { | 1443 | { |
1444 | global_settings.dircache_size = dircache_get_cache_size(); | 1444 | global_settings.dircache_size = dircache_get_cache_size(); |
1445 | # ifdef HAVE_EEPROM_SETTINGS | 1445 | # ifdef HAVE_EEPROM_SETTINGS |
1446 | if (dircache_is_enabled() && firmware_settings.initialized) | 1446 | dircache_save(); |
1447 | dircache_save(DIRCACHE_FILE); | ||
1448 | # endif | 1447 | # endif |
1449 | dircache_disable(); | 1448 | dircache_disable(); |
1450 | } | 1449 | } |
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 | */ |
413 | int dircache_load(const char *path) | 413 | int 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 | */ |
472 | int dircache_save(const char *path) | 475 | int 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 | { |
diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h index 9c3bc68ddc..1483843a73 100644 --- a/firmware/include/dircache.h +++ b/firmware/include/dircache.h | |||
@@ -25,7 +25,8 @@ | |||
25 | 25 | ||
26 | #define DIRCACHE_RESERVE (1024*64) | 26 | #define DIRCACHE_RESERVE (1024*64) |
27 | #define DIRCACHE_LIMIT (1024*1024*6) | 27 | #define DIRCACHE_LIMIT (1024*1024*6) |
28 | #define DIRCACHE_FILE ROCKBOX_DIR "/dircache.dat" | 28 | /* FIXME: We should use ROCKBOX_DIR here but it's defined in apps/ */ |
29 | #define DIRCACHE_FILE "/.rockbox/dircache.dat" | ||
29 | 30 | ||
30 | /* Internal structures. */ | 31 | /* Internal structures. */ |
31 | struct travel_data { | 32 | struct travel_data { |
@@ -80,8 +81,8 @@ typedef struct { | |||
80 | } DIRCACHED; | 81 | } DIRCACHED; |
81 | 82 | ||
82 | void dircache_init(void); | 83 | void dircache_init(void); |
83 | int dircache_load(const char *path); | 84 | int dircache_load(void); |
84 | int dircache_save(const char *path); | 85 | int dircache_save(void); |
85 | int dircache_build(int last_size); | 86 | int dircache_build(int last_size); |
86 | void* dircache_steal_buffer(long *size); | 87 | void* dircache_steal_buffer(long *size); |
87 | bool dircache_is_enabled(void); | 88 | bool dircache_is_enabled(void); |