From c12e87d88168f043020a4891adb6da2c960f21b2 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Tue, 28 Sep 2004 18:09:10 +0000 Subject: The config sector number is now calculated from the lowest partition start sector. Needed for disks with sectors_per_track < 63, e.g. flash cards. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5124 a1c6a512-1295-4272-9138-f99709370657 --- apps/main.c | 6 ++++-- apps/settings.c | 38 ++++++++++++++++++++++++++++++++++---- apps/settings.h | 1 + 3 files changed, 39 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/main.c b/apps/main.c index 1a163ebd72..38bbd71177 100644 --- a/apps/main.c +++ b/apps/main.c @@ -79,6 +79,7 @@ void init(void) font_init(); show_logo(); settings_reset(); + settings_calc_config_sector(); settings_load(SETTINGS_ALL); settings_apply(); sleep(HZ/2); @@ -224,11 +225,12 @@ void init(void) } } + settings_calc_config_sector(); settings_load(SETTINGS_ALL); settings_apply(); - + status_init(); - playlist_init(); + playlist_init(); tree_init(); /* No buffer allocation (see buffer.c) may take place after the call to diff --git a/apps/settings.c b/apps/settings.c index 708a38b678..bb8deb0cb4 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -82,6 +82,7 @@ const char rec_base_directory[] = REC_BASE_DIR; #endif long lasttime = 0; +static int config_sector = 0; /* mark uninitialized */ static unsigned char config_block[CONFIG_BLOCK_SIZE]; @@ -481,8 +482,8 @@ static int save_config_buffer( void ) #endif - if (fat_startsector() != 0) - ata_delayed_write( 61, config_block); + if (config_sector != 0) + ata_delayed_write( config_sector, config_block); else return -1; @@ -502,8 +503,8 @@ static int load_config_buffer(int which) if (which & SETTINGS_HD) { - if (fat_startsector() != 0) { - ata_read_sectors( 61, 1, config_block); + if (config_sector != 0) { + ata_read_sectors( config_sector, 1, config_block); /* calculate the checksum, check it and the header */ chksum = calculate_config_checksum(config_block); @@ -601,6 +602,35 @@ static void save_bit_table(const struct bit_entry* p_table, int count, int bitst curr_bit); /* = position after last element */ } +/* + * figure out the config sector from the partition table and the + * mounted file system + */ +void settings_calc_config_sector(void) +{ +#ifdef SIMULATOR + config_sector = 61; +#else + int i, partition_start; + int sector = 0; + + if (fat_startsector != 0) /* There is a partition table */ + { + sector = 61; + for (i = 0; i < 4; i++) + { + partition_start = disk_partinfo(i)->start; + if (partition_start != 0 && (partition_start - 2) < sector) + sector = partition_start - 2; + } + if (sector < 0) + sector = 0; + } + + splash(HZ, true, "CfgSec: %d", sector); + config_sector = sector; +#endif +} /* * persist all runtime user settings to disk or RTC RAM diff --git a/apps/settings.h b/apps/settings.h index 0af466c5f7..aa408ea2cc 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -281,6 +281,7 @@ struct opt_items { /* prototypes */ +void settings_calc_config_sector(void); int settings_save(void); void settings_load(int which); void settings_reset(void); -- cgit v1.2.3