diff options
Diffstat (limited to 'flash.c')
-rw-r--r-- | flash.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -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"); } } |