diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-22 12:34:15 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-22 12:34:15 -0400 |
commit | eee587b04dc46ade28b84fd9534c3358afb4f181 (patch) | |
tree | 0ea53a227a532d5692d68b6443d513132ff4cae4 /flash.c | |
parent | 1577811d579f1aa8213c62f7bfac3e94f500a0d6 (diff) |
spelling fix
Diffstat (limited to 'flash.c')
-rw-r--r-- | flash.c | 36 |
1 files changed, 18 insertions, 18 deletions
@@ -41,16 +41,16 @@ typedef struct { uint32_t version; uint32_t length; uint32_t crc32; -} persistancehdr; +} persistencehdr; -static void persistance_printheader(persistancehdr* hdr) +static void persistence_printheader(persistencehdr* hdr) { printf("Frozen struct has version %d, is %d bytes long and has the CRC32 0x%08"PRIx32"\n", hdr->version, hdr->length, hdr->crc32); } // copy a file from one place to another.. this is not portable, linux only -bool persistance_copyfile(char* source, char* dest) +bool persistence_copyfile(char* source, char* dest) { mode_t filemode = S_IRUSR | S_IWUSR; int src = open(source, O_RDONLY | O_CREAT); // should create the file for us if this is the first run @@ -72,7 +72,7 @@ bool persistance_copyfile(char* source, char* dest) } // store an object -bool persistance_freeze(char* dest, void* data, unsigned int offset, unsigned int len, unsigned int total, +bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned int len, unsigned int total, uint32_t version) { @@ -121,14 +121,14 @@ bool persistance_freeze(char* dest, void* data, unsigned int offset, unsigned in } // get the header - persistancehdr hdr; - if (read(fd, &hdr, sizeof(persistancehdr)) != sizeof(persistancehdr)) { + persistencehdr hdr; + if (read(fd, &hdr, sizeof(persistencehdr)) != sizeof(persistencehdr)) { errno = PERSIST_ERR_COULDNTREADHDR; return false; } // load the data - persistance_printheader(&hdr); + persistence_printheader(&hdr); if (read(fd, payload, total) != total) { errno = PERSIST_ERR_COULDNTREADDATA; return false; @@ -148,12 +148,12 @@ bool persistance_freeze(char* dest, void* data, unsigned int offset, unsigned in } // build the header - persistancehdr hdr; + persistencehdr hdr; hdr.version = version; hdr.length = total; hdr.crc32 = crc; - persistance_printheader(&hdr); + persistence_printheader(&hdr); // write the data to disk ftruncate(fd, sizeof(hdr) + total); // not really needed but if we did have a file thats bigger than it @@ -186,19 +186,19 @@ bool persistance_freeze(char* dest, void* data, unsigned int offset, unsigned in } // try to load an object from disk -bool persistance_unfreeze(char* dest, void* result, unsigned int len, uint32_t version) +bool persistence_unfreeze(char* dest, void* result, unsigned int len, uint32_t version) { int fd = open(dest, O_RDONLY); // get the header - persistancehdr hdr; - if (read(fd, &hdr, sizeof(persistancehdr)) != sizeof(persistancehdr)) { + persistencehdr hdr; + if (read(fd, &hdr, sizeof(persistencehdr)) != sizeof(persistencehdr)) { errno = PERSIST_ERR_COULDNTREADHDR; return false; } - persistance_printheader(&hdr); + persistence_printheader(&hdr); // check that the length of this frozen object is what we are expecting if (hdr.length != len) { @@ -236,16 +236,16 @@ int readUserBlock(FlashStruct *mem) { // try to unfreeze the main file - if (persistance_unfreeze(MAINFILE, mem, sizeof(*mem), 0)) { + if (persistence_unfreeze(MAINFILE, mem, sizeof(*mem), 0)) { return sizeof(*mem); } // something went wrong else { printf("Error unfreezing %d.. trying backup\n", errno); // hopefully we can use the backup.. - if (persistance_unfreeze(BACKUPFILE, mem, sizeof(*mem), 0)) { + if (persistence_unfreeze(BACKUPFILE, mem, sizeof(*mem), 0)) { // if the backup was good overwrite the main file - persistance_copyfile(BACKUPFILE, MAINFILE); + persistence_copyfile(BACKUPFILE, MAINFILE); return sizeof(*mem); } // deadend :( @@ -266,8 +266,8 @@ void writeUserBlock(FlashStruct *mem, int addr, int numbytes) // *** but I don't think this situation should arise. *** // backup the main copy of the file - if (persistance_copyfile(MAINFILE, BACKUPFILE)) { - if (!persistance_freeze(MAINFILE, mem, addr, numbytes, sizeof(*mem), 0)) { + 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 { |