From c60acb22860c4ac69855f84bf77d9e0dd3f7c17a Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Thu, 23 Aug 2012 09:38:50 -0400 Subject: implement flash suspend --- flash.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'flash.c') diff --git a/flash.c b/flash.c index 9861b84..f358ee2 100644 --- a/flash.c +++ b/flash.c @@ -284,24 +284,26 @@ int readUserBlock(FlashStruct *mem) void writeUserBlock(FlashStruct *mem, int addr, int numbytes) { - // *** There is a potential issue here.. if the mainfile is corrupt *** // *** and this gets called before readUserBlock then the *** // *** potentially workable backup will be lost .. we could check *** // *** that the main file is valid before backing it up I guess... *** // *** but I don't think this situation should arise. *** - // backup the main copy of the file - if (persistence_copyfile(MAINFILE, BACKUPFILE)) { - 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); - } else { - printf("Error while writing data to disk. **File is potentially corrupt!**\n"); + if (!globals.flash_writes_suspended) { + + // backup the main copy of the file + if (persistence_copyfile(MAINFILE, BACKUPFILE)) { + 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); + } else { + printf("Error while writing data to disk. **File is potentially corrupt!**\n"); + } } + } else { + printf("Could not backup current file. **Write did not happen!!!**\n"); } - } else { - printf("Could not backup current file. **Write did not happen!!!**\n"); } } -- cgit