forked from len0rd/rockbox
Try to make sure dircache state file on flashed H1xx targets is
handled correctly and no old state is never used. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11833 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
7258b5e51a
commit
c8a9ca748d
4 changed files with 44 additions and 31 deletions
49
apps/main.c
49
apps/main.c
|
@ -128,25 +128,32 @@ static int init_dircache(bool preinit)
|
||||||
if (preinit)
|
if (preinit)
|
||||||
dircache_init();
|
dircache_init();
|
||||||
|
|
||||||
if (global_settings.dircache)
|
if (!global_settings.dircache)
|
||||||
{
|
return 0;
|
||||||
|
|
||||||
# ifdef HAVE_EEPROM_SETTINGS
|
# ifdef HAVE_EEPROM_SETTINGS
|
||||||
if (firmware_settings.initialized && firmware_settings.disk_clean
|
if (firmware_settings.initialized && firmware_settings.disk_clean
|
||||||
&& preinit)
|
&& preinit)
|
||||||
{
|
{
|
||||||
result = dircache_load(DIRCACHE_FILE);
|
result = dircache_load();
|
||||||
remove(DIRCACHE_FILE);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
firmware_settings.disk_clean = false;
|
|
||||||
if (global_settings.dircache_size >= 0)
|
|
||||||
dircache_build(global_settings.dircache_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
if (result < 0)
|
||||||
|
{
|
||||||
|
firmware_settings.disk_clean = false;
|
||||||
|
if (global_settings.dircache_size <= 0)
|
||||||
|
{
|
||||||
|
/* This will be in default language, settings are not
|
||||||
|
applied yet. Not really any easy way to fix that. */
|
||||||
|
gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING));
|
||||||
|
clear = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
dircache_build(global_settings.dircache_size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
# endif
|
# endif
|
||||||
|
{
|
||||||
if (preinit)
|
if (preinit)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -163,12 +170,12 @@ static int init_dircache(bool preinit)
|
||||||
|
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
gui_syncsplash(0, true, "Failed! Result: %d", result);
|
gui_syncsplash(0, true, "Failed! Result: %d", result);
|
||||||
|
}
|
||||||
if (clear)
|
|
||||||
{
|
if (clear)
|
||||||
backlight_on();
|
{
|
||||||
show_logo();
|
backlight_on();
|
||||||
}
|
show_logo();
|
||||||
global_settings.dircache_size = dircache_get_cache_size();
|
global_settings.dircache_size = dircache_get_cache_size();
|
||||||
settings_save();
|
settings_save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1443,8 +1443,7 @@ void tree_flush(void)
|
||||||
{
|
{
|
||||||
global_settings.dircache_size = dircache_get_cache_size();
|
global_settings.dircache_size = dircache_get_cache_size();
|
||||||
# ifdef HAVE_EEPROM_SETTINGS
|
# ifdef HAVE_EEPROM_SETTINGS
|
||||||
if (dircache_is_enabled() && firmware_settings.initialized)
|
dircache_save();
|
||||||
dircache_save(DIRCACHE_FILE);
|
|
||||||
# endif
|
# endif
|
||||||
dircache_disable();
|
dircache_disable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,7 +410,7 @@ static struct dircache_entry* dircache_get_entry(const char *path,
|
||||||
* Function to load the internal cache structure from disk to initialize
|
* Function to load the internal cache structure from disk to initialize
|
||||||
* the dircache really fast and little disk access.
|
* the dircache really fast and little disk access.
|
||||||
*/
|
*/
|
||||||
int dircache_load(const char *path)
|
int dircache_load(void)
|
||||||
{
|
{
|
||||||
struct dircache_maindata maindata;
|
struct dircache_maindata maindata;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
|
@ -422,7 +422,7 @@ int dircache_load(const char *path)
|
||||||
logf("Loading directory cache");
|
logf("Loading directory cache");
|
||||||
dircache_size = 0;
|
dircache_size = 0;
|
||||||
|
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(DIRCACHE_FILE, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
|
@ -432,6 +432,7 @@ int dircache_load(const char *path)
|
||||||
{
|
{
|
||||||
logf("Dircache file header error");
|
logf("Dircache file header error");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
remove(DIRCACHE_FILE);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,6 +441,7 @@ int dircache_load(const char *path)
|
||||||
{
|
{
|
||||||
logf("Position missmatch");
|
logf("Position missmatch");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
remove(DIRCACHE_FILE);
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,6 +449,7 @@ int dircache_load(const char *path)
|
||||||
entry_count = maindata.entry_count;
|
entry_count = maindata.entry_count;
|
||||||
bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size));
|
bytes_read = read(fd, dircache_root, MIN(DIRCACHE_LIMIT, maindata.size));
|
||||||
close(fd);
|
close(fd);
|
||||||
|
remove(DIRCACHE_FILE);
|
||||||
|
|
||||||
if (bytes_read != maindata.size)
|
if (bytes_read != maindata.size)
|
||||||
{
|
{
|
||||||
|
@ -469,13 +472,13 @@ int dircache_load(const char *path)
|
||||||
* Function to save the internal cache stucture to disk for fast loading
|
* Function to save the internal cache stucture to disk for fast loading
|
||||||
* on boot.
|
* on boot.
|
||||||
*/
|
*/
|
||||||
int dircache_save(const char *path)
|
int dircache_save(void)
|
||||||
{
|
{
|
||||||
struct dircache_maindata maindata;
|
struct dircache_maindata maindata;
|
||||||
int fd;
|
int fd;
|
||||||
unsigned long bytes_written;
|
unsigned long bytes_written;
|
||||||
|
|
||||||
remove(path);
|
remove(DIRCACHE_FILE);
|
||||||
|
|
||||||
while (thread_enabled)
|
while (thread_enabled)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
@ -484,7 +487,7 @@ int dircache_save(const char *path)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
logf("Saving directory cache");
|
logf("Saving directory cache");
|
||||||
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC);
|
fd = open(DIRCACHE_FILE, O_WRONLY | O_CREAT | O_TRUNC);
|
||||||
|
|
||||||
maindata.magic = DIRCACHE_MAGIC;
|
maindata.magic = DIRCACHE_MAGIC;
|
||||||
maindata.size = dircache_size;
|
maindata.size = dircache_size;
|
||||||
|
@ -529,6 +532,7 @@ static int dircache_do_rebuild(void)
|
||||||
/* Measure how long it takes build the cache. */
|
/* Measure how long it takes build the cache. */
|
||||||
start_tick = current_tick;
|
start_tick = current_tick;
|
||||||
dircache_initializing = true;
|
dircache_initializing = true;
|
||||||
|
remove(DIRCACHE_FILE);
|
||||||
|
|
||||||
#ifdef SIMULATOR
|
#ifdef SIMULATOR
|
||||||
pdir = opendir("/");
|
pdir = opendir("/");
|
||||||
|
@ -633,6 +637,8 @@ int dircache_build(int last_size)
|
||||||
return -3;
|
return -3;
|
||||||
|
|
||||||
logf("Building directory cache");
|
logf("Building directory cache");
|
||||||
|
remove(DIRCACHE_FILE);
|
||||||
|
|
||||||
/* Background build, dircache has been previously allocated */
|
/* Background build, dircache has been previously allocated */
|
||||||
if (dircache_size > 0)
|
if (dircache_size > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
|
|
||||||
#define DIRCACHE_RESERVE (1024*64)
|
#define DIRCACHE_RESERVE (1024*64)
|
||||||
#define DIRCACHE_LIMIT (1024*1024*6)
|
#define DIRCACHE_LIMIT (1024*1024*6)
|
||||||
#define DIRCACHE_FILE ROCKBOX_DIR "/dircache.dat"
|
/* FIXME: We should use ROCKBOX_DIR here but it's defined in apps/ */
|
||||||
|
#define DIRCACHE_FILE "/.rockbox/dircache.dat"
|
||||||
|
|
||||||
/* Internal structures. */
|
/* Internal structures. */
|
||||||
struct travel_data {
|
struct travel_data {
|
||||||
|
@ -80,8 +81,8 @@ typedef struct {
|
||||||
} DIRCACHED;
|
} DIRCACHED;
|
||||||
|
|
||||||
void dircache_init(void);
|
void dircache_init(void);
|
||||||
int dircache_load(const char *path);
|
int dircache_load(void);
|
||||||
int dircache_save(const char *path);
|
int dircache_save(void);
|
||||||
int dircache_build(int last_size);
|
int dircache_build(int last_size);
|
||||||
void* dircache_steal_buffer(long *size);
|
void* dircache_steal_buffer(long *size);
|
||||||
bool dircache_is_enabled(void);
|
bool dircache_is_enabled(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue