summaryrefslogtreecommitdiff
path: root/flash.c
diff options
context:
space:
mode:
authorroot <root@xena.domain.avtechpulse.com>2012-10-04 08:28:15 -0400
committerroot <root@xena.domain.avtechpulse.com>2012-10-04 08:28:15 -0400
commita0f966ce43e7286d7e033d0b17ab00d6ff6609b5 (patch)
tree171a1af32f28bf5cf52dde69fff91599af97b84b /flash.c
parentff3ecc0632fbe0671f000595604e7c1de77f33dc (diff)
wrap flash writes and shutdown sequence in flags
Diffstat (limited to 'flash.c')
-rw-r--r--flash.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/flash.c b/flash.c
index e3ce2ce..a242284 100644
--- a/flash.c
+++ b/flash.c
@@ -272,7 +272,11 @@ int readUserBlock(FlashStruct *mem)
// hopefully we can use the backup..
if (persistence_unfreeze(BACKUPFILE, mem, sizeof(*mem), 0)) {
// if the backup was good overwrite the main file
- persistence_copyfile(BACKUPFILE, MAINFILE);
+ if (!globals.Flags.shutdown_started) {
+ globals.Flags.flash_write_in_progress = TRUE;
+ persistence_copyfile(BACKUPFILE, MAINFILE);
+ globals.Flags.flash_write_in_progress = FALSE;
+ }
return sizeof(*mem);
}
// deadend :(
@@ -294,7 +298,16 @@ void writeUserBlock(FlashStruct *mem, int addr, int numbytes)
if (!globals.Flags.flash_writes_suspended) {
// backup the main copy of the file
- if (persistence_copyfile(MAINFILE, BACKUPFILE)) {
+ if (globals.Flags.shutdown_started) return;
+
+ globals.Flags.flash_write_in_progress = TRUE;
+ bool backup_ok = persistence_copyfile(MAINFILE, BACKUPFILE);
+ globals.Flags.flash_write_in_progress = FALSE;
+
+ if (backup_ok) {
+ if (globals.Flags.shutdown_started) return;
+ globals.Flags.flash_write_in_progress = TRUE;
+
if (!persistence_freeze(MAINFILE, mem, addr, numbytes, sizeof(*mem), 0)) {
if (errno != PERSIST_ERR_COULDNTWRITE) {
printf("Error while trying to write, %d. **Write did not happen!!!**\n", errno);
@@ -302,6 +315,7 @@ void writeUserBlock(FlashStruct *mem, int addr, int numbytes)
printf("Error while writing data to disk. **File is potentially corrupt!**\n");
}
}
+ globals.Flags.flash_write_in_progress = FALSE;
} else {
printf("Could not backup current file. **Write did not happen!!!**\n");
}