summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flash.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/flash.c b/flash.c
index 719b4b1..6017d75 100644
--- a/flash.c
+++ b/flash.c
@@ -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 {