diff options
author | Simon Busch <morphis@gravedo.de> | 2012-02-17 16:10:13 +0100 |
---|---|---|
committer | Simon Busch <morphis@gravedo.de> | 2012-02-17 16:10:13 +0100 |
commit | 6f57cb2128394a90f4924264e4f6eaf67e21d976 (patch) | |
tree | 01ca62b9983f46e7da72b31c242bec705a055941 /samsung-ipc | |
parent | c82cf76cb6df7a4d204c28915c96ead342fa2eca (diff) | |
download | external_libsamsung-ipc-6f57cb2128394a90f4924264e4f6eaf67e21d976.zip external_libsamsung-ipc-6f57cb2128394a90f4924264e4f6eaf67e21d976.tar.gz external_libsamsung-ipc-6f57cb2128394a90f4924264e4f6eaf67e21d976.tar.bz2 |
Cleanup indentation in rfs.c
Signed-off-by: Simon Busch <morphis@gravedo.de>
Diffstat (limited to 'samsung-ipc')
-rw-r--r-- | samsung-ipc/rfs.c | 552 |
1 files changed, 276 insertions, 276 deletions
diff --git a/samsung-ipc/rfs.c b/samsung-ipc/rfs.c index 61659b8..26e8c08 100644 --- a/samsung-ipc/rfs.c +++ b/samsung-ipc/rfs.c @@ -35,64 +35,64 @@ void md5hash2string(char *out, uint8_t *in) { - int i; - - for(i=0 ; i < MD5_DIGEST_LENGTH ; i++) - { - /* After the first iteration, we override \0. */ - if(*in < 0x10) - sprintf(out, "0%x", *in); - else - sprintf(out, "%x", *in); - in++; - out+=2; - } + int i; + + for(i=0 ; i < MD5_DIGEST_LENGTH ; i++) + { + /* After the first iteration, we override \0. */ + if(*in < 0x10) + sprintf(out, "0%x", *in); + else + sprintf(out, "%x", *in); + in++; + out+=2; + } } void nv_data_generate(struct ipc_client *client) { - ipc_client_log(client, "This feature isn't present yet\n"); + ipc_client_log(client, "This feature isn't present yet\n"); -// nv_data_backup_create(); +// nv_data_backup_create(); } void nv_data_md5_compute(void *data_p, int size, void *hash) { - MD5_CTX ctx; + MD5_CTX ctx; -// MD5((unsigned char *)nv_data_p, nv_data_stat.st_size, nv_data_md5_hash); +// MD5((unsigned char *)nv_data_p, nv_data_stat.st_size, nv_data_md5_hash); - MD5_Init(&ctx); - MD5_Update(&ctx, data_p, size); - MD5_Update(&ctx, NV_DATA_MD5_SECRET, sizeof(NV_DATA_MD5_SECRET) - 1); - MD5_Final(hash, &ctx); + MD5_Init(&ctx); + MD5_Update(&ctx, data_p, size); + MD5_Update(&ctx, NV_DATA_MD5_SECRET, sizeof(NV_DATA_MD5_SECRET) - 1); + MD5_Final(hash, &ctx); } void nv_data_md5_generate(struct ipc_client *client) { - uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; - char *nv_data_md5_hash_string; - void *nv_data_p; + uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; + char *nv_data_md5_hash_string; + void *nv_data_p; int fd; - ipc_client_log(client, "nv_data_md5_generate: enter\n"); + ipc_client_log(client, "nv_data_md5_generate: enter\n"); - ipc_client_log(client, "nv_data_md5_generate: generating MD5 hash\n"); - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); - nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); - free(nv_data_p); + ipc_client_log(client, "nv_data_md5_generate: generating MD5 hash\n"); + nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); + nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); + free(nv_data_p); - /* Alloc the memory for the md5 hash string. */ - nv_data_md5_hash_string = malloc(MD5_STRING_SIZE); - memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); + /* Alloc the memory for the md5 hash string. */ + nv_data_md5_hash_string = malloc(MD5_STRING_SIZE); + memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); - md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); + md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); - ipc_client_log(client, "nv_data_md5_generate: new MD5 hash is %s\n", nv_data_md5_hash_string); + ipc_client_log(client, "nv_data_md5_generate: new MD5 hash is %s\n", nv_data_md5_hash_string); ipc_client_log(client, "nv_data_md5_generate: writing MD5 hash\n"); - /* Write the MD5 hash in nv_data.bin.md5. */ - fd = open("/efs/nv_data.bin.md5", O_RDWR | O_CREAT | O_TRUNC, 0644); + /* Write the MD5 hash in nv_data.bin.md5. */ + fd = open("/efs/nv_data.bin.md5", O_RDWR | O_CREAT | O_TRUNC, 0644); if(fd < 0) { @@ -100,86 +100,86 @@ void nv_data_md5_generate(struct ipc_client *client) goto exit; } - write(fd, nv_data_md5_hash_string, MD5_STRING_SIZE); + write(fd, nv_data_md5_hash_string, MD5_STRING_SIZE); close(fd); exit: - free(nv_data_md5_hash_string); + free(nv_data_md5_hash_string); - ipc_client_log(client, "nv_data_md5_generate: exit\n"); + ipc_client_log(client, "nv_data_md5_generate: exit\n"); } void nv_data_backup_create(struct ipc_client *client) { - uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; - char *nv_data_md5_hash_string; - char *nv_data_md5_hash_read; + uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; + char *nv_data_md5_hash_string; + char *nv_data_md5_hash_read; int nv_data_write_tries = 0; - struct stat nv_stat; - void *nv_data_p; - void *nv_data_bak_p; - uint8_t data; + struct stat nv_stat; + void *nv_data_p; + void *nv_data_bak_p; + uint8_t data; - int fd; + int fd; int rc; - int i; + int i; - ipc_client_log(client, "nv_data_backup_create: enter\n"); + ipc_client_log(client, "nv_data_backup_create: enter\n"); - if(stat("/efs/nv_data.bin", &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_backup_create: nv_data.bin missing\n"); - nv_data_generate(client); - } + if(stat("/efs/nv_data.bin", &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_backup_create: nv_data.bin missing\n"); + nv_data_generate(client); + } - if(nv_stat.st_size != NV_DATA_SIZE) - { - ipc_client_log(client, "nv_data_backup_create: wrong nv_data.bin size\n"); - nv_data_generate(client); - return; - } + if(nv_stat.st_size != NV_DATA_SIZE) + { + ipc_client_log(client, "nv_data_backup_create: wrong nv_data.bin size\n"); + nv_data_generate(client); + return; + } - if(stat("/efs/nv_data.bin.md5", &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_backup_create: nv_data.bin.md5 missing\n"); - nv_data_generate(client); - return; - } + if(stat("/efs/nv_data.bin.md5", &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_backup_create: nv_data.bin.md5 missing\n"); + nv_data_generate(client); + return; + } - /* Alloc the memory for the md5 hashes strings. */ - nv_data_md5_hash_string=malloc(MD5_STRING_SIZE); - nv_data_md5_hash_read=malloc(MD5_STRING_SIZE); + /* Alloc the memory for the md5 hashes strings. */ + nv_data_md5_hash_string=malloc(MD5_STRING_SIZE); + nv_data_md5_hash_read=malloc(MD5_STRING_SIZE); - memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE); - memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); + memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE); + memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); - /* Read the content of the backup file. */ - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); + /* Read the content of the backup file. */ + nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); /* Compute the backup file MD5 hash. */ - nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); - md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); + nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); + md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); /* Read the stored backup file MD5 hash. */ fd=open("/efs/nv_data.bin.md5", O_RDONLY); read(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); - close(fd); + close(fd); - /* Add 0x0 to end the string: not sure this is always part of the file. */ - nv_data_md5_hash_read[MD5_STRING_SIZE - 1]='\0'; + /* Add 0x0 to end the string: not sure this is always part of the file. */ + nv_data_md5_hash_read[MD5_STRING_SIZE - 1]='\0'; - ipc_client_log(client, "nv_data_backup_create: backup file computed MD5: %s read MD5: %s\n", - nv_data_md5_hash_string, nv_data_md5_hash_read); + ipc_client_log(client, "nv_data_backup_create: backup file computed MD5: %s read MD5: %s\n", + nv_data_md5_hash_string, nv_data_md5_hash_read); if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) { - ipc_client_log(client, "nv_data_backup_create: MD5 hash mismatch on backup file\n"); - ipc_client_log(client, "nv_data_backup_create: Consider the computed one as correct\n"); + ipc_client_log(client, "nv_data_backup_create: MD5 hash mismatch on backup file\n"); + ipc_client_log(client, "nv_data_backup_create: Consider the computed one as correct\n"); fd=open("/efs/nv_data.bin.md5", O_WRONLY); read(fd, nv_data_md5_hash_string, MD5_STRING_SIZE); - close(fd); + close(fd); /* nv_data_backup_generate(client); @@ -190,7 +190,7 @@ void nv_data_backup_create(struct ipc_client *client) /* Assume the read string is the computated one */ memcpy(nv_data_md5_hash_read, nv_data_md5_hash_string, MD5_STRING_SIZE); - memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); + memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); nv_data_backup_create_write: while(nv_data_write_tries < 5) @@ -226,121 +226,121 @@ nv_data_backup_create_write: } - /* Read the newly-written .nv_data.bak. */ - nv_data_bak_p=ipc_file_read(client, "/efs/.nv_data.bak", NV_DATA_SIZE, NV_DATA_SIZE / 10); + /* Read the newly-written .nv_data.bak. */ + nv_data_bak_p=ipc_file_read(client, "/efs/.nv_data.bak", NV_DATA_SIZE, NV_DATA_SIZE / 10); - /* Compute the MD5 hash for nv_data.bin. */ - nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash); - md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); + /* Compute the MD5 hash for nv_data.bin. */ + nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash); + md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); free(nv_data_bak_p); - ipc_client_log(client, "nv_data_backup_create: written file computed MD5: %s read MD5: %s\n", - nv_data_md5_hash_string, nv_data_md5_hash_read); + ipc_client_log(client, "nv_data_backup_create: written file computed MD5: %s read MD5: %s\n", + nv_data_md5_hash_string, nv_data_md5_hash_read); - /* Make sure both hashes are the same. */ - if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) - { - ipc_client_log(client, "nv_data_backup_create: MD5 hash mismatch on written file\n"); - ipc_client_log(client, "nv_data_backup_create: Writing again\n"); + /* Make sure both hashes are the same. */ + if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) + { + ipc_client_log(client, "nv_data_backup_create: MD5 hash mismatch on written file\n"); + ipc_client_log(client, "nv_data_backup_create: Writing again\n"); goto nv_data_backup_create_write; - } + } - /* Write the MD5 hash in .nv_data.bak.md5. */ - fd=open("/efs/.nv_data.bak.md5", O_WRONLY | O_CREAT | O_TRUNC, 0644); - write(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); - close(fd); + /* Write the MD5 hash in .nv_data.bak.md5. */ + fd=open("/efs/.nv_data.bak.md5", O_WRONLY | O_CREAT | O_TRUNC, 0644); + write(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); + close(fd); /* Write the correct .nv_state. */ - fd=open("/efs/.nv_state", O_WRONLY | O_CREAT | O_TRUNC, 0644); - data='1'; - write(fd, &data, sizeof(data)); - close(fd); + fd=open("/efs/.nv_state", O_WRONLY | O_CREAT | O_TRUNC, 0644); + data='1'; + write(fd, &data, sizeof(data)); + close(fd); exit: - free(nv_data_p); - free(nv_data_md5_hash_string); - free(nv_data_md5_hash_read); + free(nv_data_p); + free(nv_data_md5_hash_string); + free(nv_data_md5_hash_read); - ipc_client_log(client, "nv_data_backup_create: exit\n"); + ipc_client_log(client, "nv_data_backup_create: exit\n"); } void nv_data_backup_restore(struct ipc_client *client) { - uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; - char *nv_data_md5_hash_string; - char *nv_data_md5_hash_read; + uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; + char *nv_data_md5_hash_string; + char *nv_data_md5_hash_read; int nv_data_write_tries = 0; - struct stat nv_stat; - void *nv_data_p; - void *nv_data_bak_p; - uint8_t data; + struct stat nv_stat; + void *nv_data_p; + void *nv_data_bak_p; + uint8_t data; - int fd; + int fd; int rc; - int i; - - ipc_client_log(client, "nv_data_backup_restore: enter\n"); - - if(stat("/efs/.nv_data.bak", &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_backup_restore: .nv_data.bak missing\n"); - nv_data_generate(client); - nv_data_backup_create(client); - return; - } - - if(nv_stat.st_size != NV_DATA_SIZE) - { - ipc_client_log(client, "nv_data_backup_restore: wrong .nv_data.bak size\n"); - nv_data_generate(client); - nv_data_backup_create(client); - return; - } - - if(stat("/efs/.nv_data.bak.md5", &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_backup_restore: .nv_data.bak.md5 missing\n"); - nv_data_generate(client); - nv_data_backup_create(client); - return; - } - - /* Alloc the memory for the md5 hashes strings. */ - nv_data_md5_hash_string=malloc(MD5_STRING_SIZE); - nv_data_md5_hash_read=malloc(MD5_STRING_SIZE); - - memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE); - memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); - - /* Read the content of the backup file. */ - nv_data_bak_p=ipc_file_read(client, "/efs/.nv_data.bak", NV_DATA_SIZE, NV_DATA_SIZE / 10); + int i; + + ipc_client_log(client, "nv_data_backup_restore: enter\n"); + + if(stat("/efs/.nv_data.bak", &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_backup_restore: .nv_data.bak missing\n"); + nv_data_generate(client); + nv_data_backup_create(client); + return; + } + + if(nv_stat.st_size != NV_DATA_SIZE) + { + ipc_client_log(client, "nv_data_backup_restore: wrong .nv_data.bak size\n"); + nv_data_generate(client); + nv_data_backup_create(client); + return; + } + + if(stat("/efs/.nv_data.bak.md5", &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_backup_restore: .nv_data.bak.md5 missing\n"); + nv_data_generate(client); + nv_data_backup_create(client); + return; + } + + /* Alloc the memory for the md5 hashes strings. */ + nv_data_md5_hash_string=malloc(MD5_STRING_SIZE); + nv_data_md5_hash_read=malloc(MD5_STRING_SIZE); + + memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE); + memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); + + /* Read the content of the backup file. */ + nv_data_bak_p=ipc_file_read(client, "/efs/.nv_data.bak", NV_DATA_SIZE, NV_DATA_SIZE / 10); /* Compute the backup file MD5 hash. */ - nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash); - md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); + nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash); + md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); /* Read the stored backup file MD5 hash. */ fd=open("/efs/.nv_data.bak.md5", O_RDONLY); read(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); - close(fd); + close(fd); - /* Add 0x0 to end the string: not sure this is always part of the file. */ - nv_data_md5_hash_read[MD5_STRING_SIZE - 1]='\0'; + /* Add 0x0 to end the string: not sure this is always part of the file. */ + nv_data_md5_hash_read[MD5_STRING_SIZE - 1]='\0'; - ipc_client_log(client, "nv_data_backup_restore: backup file computed MD5: %s read MD5: %s\n", - nv_data_md5_hash_string, nv_data_md5_hash_read); + ipc_client_log(client, "nv_data_backup_restore: backup file computed MD5: %s read MD5: %s\n", + nv_data_md5_hash_string, nv_data_md5_hash_read); if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) { - ipc_client_log(client, "nv_data_backup_restore: MD5 hash mismatch on backup file\n"); - ipc_client_log(client, "nv_data_backup_restore: Consider the computed one as correct\n"); + ipc_client_log(client, "nv_data_backup_restore: MD5 hash mismatch on backup file\n"); + ipc_client_log(client, "nv_data_backup_restore: Consider the computed one as correct\n"); fd=open("/efs/.nv_data.bak.md5", O_WRONLY); read(fd, nv_data_md5_hash_string, MD5_STRING_SIZE); - close(fd); + close(fd); /* nv_data_backup_generate(client); @@ -351,7 +351,7 @@ void nv_data_backup_restore(struct ipc_client *client) /* Assume the read string is the computated one */ memcpy(nv_data_md5_hash_read, nv_data_md5_hash_string, MD5_STRING_SIZE); - memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); + memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); nv_data_backup_restore_write: while(nv_data_write_tries < 5) @@ -387,150 +387,150 @@ nv_data_backup_restore_write: } - /* Read the newly-written nv_data.bin. */ - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); + /* Read the newly-written nv_data.bin. */ + nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); - /* Compute the MD5 hash for nv_data.bin. */ - nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); - md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); + /* Compute the MD5 hash for nv_data.bin. */ + nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); + md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); free(nv_data_p); - ipc_client_log(client, "nv_data_backup_restore: written file computed MD5: %s read MD5: %s\n", - nv_data_md5_hash_string, nv_data_md5_hash_read); + ipc_client_log(client, "nv_data_backup_restore: written file computed MD5: %s read MD5: %s\n", + nv_data_md5_hash_string, nv_data_md5_hash_read); - /* Make sure both hashes are the same. */ - if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) - { - ipc_client_log(client, "nv_data_backup_restore: MD5 hash mismatch on written file\n"); - ipc_client_log(client, "nv_data_backup_restore: Writing again\n"); + /* Make sure both hashes are the same. */ + if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) + { + ipc_client_log(client, "nv_data_backup_restore: MD5 hash mismatch on written file\n"); + ipc_client_log(client, "nv_data_backup_restore: Writing again\n"); goto nv_data_backup_restore_write; - } + } - /* Write the MD5 hash in nv_data.bin.md5. */ - fd=open("/efs/nv_data.bin.md5", O_WRONLY | O_CREAT | O_TRUNC, 0644); - write(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); - close(fd); + /* Write the MD5 hash in nv_data.bin.md5. */ + fd=open("/efs/nv_data.bin.md5", O_WRONLY | O_CREAT | O_TRUNC, 0644); + write(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); + close(fd); /* Write the correct .nv_state. */ - fd=open("/efs/.nv_state", O_WRONLY | O_CREAT | O_TRUNC, 0644); - data='1'; - write(fd, &data, sizeof(data)); - close(fd); + fd=open("/efs/.nv_state", O_WRONLY | O_CREAT | O_TRUNC, 0644); + data='1'; + write(fd, &data, sizeof(data)); + close(fd); exit: - free(nv_data_bak_p); - free(nv_data_md5_hash_string); - free(nv_data_md5_hash_read); + free(nv_data_bak_p); + free(nv_data_md5_hash_string); + free(nv_data_md5_hash_read); - ipc_client_log(client, "nv_data_backup_restore: exit\n"); + ipc_client_log(client, "nv_data_backup_restore: exit\n"); } void nv_data_check(struct ipc_client *client) { - struct stat nv_stat; - int nv_state_fd=-1; - int nv_state=0; - - ipc_client_log(client, "nv_data_check: enter\n"); - - if(stat("/efs/nv_data.bin", &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_check: nv_data.bin missing\n"); - nv_data_backup_restore(client); - stat("/efs/nv_data.bin", &nv_stat); - } - - if(nv_stat.st_size != NV_DATA_SIZE) - { - ipc_client_log(client, "nv_data_check: wrong nv_data.bin size\n"); - nv_data_backup_restore(client); - } - - if(stat("/efs/nv_data.bin.md5", &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_check: nv_data.bin.md5 missing\n"); - nv_data_backup_restore(client); - } - - if(stat("/efs/.nv_data.bak", &nv_stat) < 0 || stat("/efs/.nv_data.bak.md5", &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_check: .nv_data.bak or .nv_data.bak.md5 missing\n"); - nv_data_backup_create(client); - } - - nv_state_fd=open("/efs/.nv_state", O_RDONLY); - - if(nv_state_fd < 0 || fstat(nv_state_fd, &nv_stat) < 0) - { - ipc_client_log(client, "nv_data_check: .nv_state missing\n"); - nv_data_backup_restore(client); - } - - read(nv_state_fd, &nv_state, sizeof(nv_state)); - - close(nv_state_fd); - - if(nv_state != '1') - { - ipc_client_log(client, "nv_data_check: bad nv_state\n"); - nv_data_backup_restore(client); - } - - ipc_client_log(client, "nv_data_check: everything should be alright\n"); - ipc_client_log(client, "nv_data_check: exit\n"); + struct stat nv_stat; + int nv_state_fd=-1; + int nv_state=0; + + ipc_client_log(client, "nv_data_check: enter\n"); + + if(stat("/efs/nv_data.bin", &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_check: nv_data.bin missing\n"); + nv_data_backup_restore(client); + stat("/efs/nv_data.bin", &nv_stat); + } + + if(nv_stat.st_size != NV_DATA_SIZE) + { + ipc_client_log(client, "nv_data_check: wrong nv_data.bin size\n"); + nv_data_backup_restore(client); + } + + if(stat("/efs/nv_data.bin.md5", &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_check: nv_data.bin.md5 missing\n"); + nv_data_backup_restore(client); + } + + if(stat("/efs/.nv_data.bak", &nv_stat) < 0 || stat("/efs/.nv_data.bak.md5", &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_check: .nv_data.bak or .nv_data.bak.md5 missing\n"); + nv_data_backup_create(client); + } + + nv_state_fd=open("/efs/.nv_state", O_RDONLY); + + if(nv_state_fd < 0 || fstat(nv_state_fd, &nv_stat) < 0) + { + ipc_client_log(client, "nv_data_check: .nv_state missing\n"); + nv_data_backup_restore(client); + } + + read(nv_state_fd, &nv_state, sizeof(nv_state)); + + close(nv_state_fd); + + if(nv_state != '1') + { + ipc_client_log(client, "nv_data_check: bad nv_state\n"); + nv_data_backup_restore(client); + } + + ipc_client_log(client, "nv_data_check: everything should be alright\n"); + ipc_client_log(client, "nv_data_check: exit\n"); } void nv_data_md5_check(struct ipc_client *client) { - struct stat nv_stat; - uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; - char *nv_data_md5_hash_string; - char *nv_data_md5_hash_read; - void *nv_data_p; + struct stat nv_stat; + uint8_t nv_data_md5_hash[MD5_DIGEST_LENGTH]; + char *nv_data_md5_hash_string; + char *nv_data_md5_hash_read; + void *nv_data_p; - int fd; - uint8_t *data_p; + int fd; + uint8_t *data_p; - ipc_client_log(client, "nv_data_md5_check: enter\n"); + ipc_client_log(client, "nv_data_md5_check: enter\n"); - nv_data_md5_hash_string=malloc(MD5_STRING_SIZE); - nv_data_md5_hash_read=malloc(MD5_STRING_SIZE); + nv_data_md5_hash_string=malloc(MD5_STRING_SIZE); + nv_data_md5_hash_read=malloc(MD5_STRING_SIZE); - memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE); - memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); + memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE); + memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, 1024); - data_p=nv_data_p; + nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, 1024); + data_p=nv_data_p; - nv_data_md5_compute(data_p, NV_DATA_SIZE, nv_data_md5_hash); + nv_data_md5_compute(data_p, NV_DATA_SIZE, nv_data_md5_hash); - md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); + md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); - free(nv_data_p); + free(nv_data_p); - fd=open("/efs/nv_data.bin.md5", O_RDONLY); + fd=open("/efs/nv_data.bin.md5", O_RDONLY); - /* Read the md5 stored in the file. */ - read(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); + /* Read the md5 stored in the file. */ + read(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); - /* Add 0x0 to end the string: not sure this is part of the file. */ - nv_data_md5_hash_read[MD5_STRING_SIZE - 1]='\0'; + /* Add 0x0 to end the string: not sure this is part of the file. */ + nv_data_md5_hash_read[MD5_STRING_SIZE - 1]='\0'; - ipc_client_log(client, "nv_data_md5_check: computed MD5: %s read MD5: %s\n", - nv_data_md5_hash_string, nv_data_md5_hash_read); + ipc_client_log(client, "nv_data_md5_check: computed MD5: %s read MD5: %s\n", + nv_data_md5_hash_string, nv_data_md5_hash_read); - if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) - { - ipc_client_log(client, "nv_data_md5_check: MD5 hash mismatch\n"); - nv_data_backup_restore(client); - } + if(strcmp(nv_data_md5_hash_string, nv_data_md5_hash_read) != 0) + { + ipc_client_log(client, "nv_data_md5_check: MD5 hash mismatch\n"); + nv_data_backup_restore(client); + } - free(nv_data_md5_hash_string); - free(nv_data_md5_hash_read); + free(nv_data_md5_hash_string); + free(nv_data_md5_hash_read); - ipc_client_log(client, "nv_data_md5_check: exit\n"); + ipc_client_log(client, "nv_data_md5_check: exit\n"); } int nv_data_read(struct ipc_client *client, int offset, int length, char *buf) @@ -538,7 +538,7 @@ int nv_data_read(struct ipc_client *client, int offset, int length, char *buf) int fd; int rc; - ipc_client_log(client, "nv_data_read: enter\n"); + ipc_client_log(client, "nv_data_read: enter\n"); if(offset <= 0 || length <= 0) { ipc_client_log(client, "nv_data_read: offset or length <= 0\n"); @@ -568,7 +568,7 @@ int nv_data_read(struct ipc_client *client, int offset, int length, char *buf) return -1; } - ipc_client_log(client, "nv_data_read: exit\n"); + ipc_client_log(client, "nv_data_read: exit\n"); return 0; } @@ -578,7 +578,7 @@ int nv_data_write(struct ipc_client *client, int offset, int length, char *buf) int fd; int rc; - ipc_client_log(client, "nv_data_write: enter\n"); + ipc_client_log(client, "nv_data_write: enter\n"); if(offset <= 0 || length <= 0) { ipc_client_log(client, "nv_data_write: offset or length <= 0\n"); @@ -614,7 +614,7 @@ int nv_data_write(struct ipc_client *client, int offset, int length, char *buf) ipc_client_log(client, "nv_data_write: writing new md5sum\n"); nv_data_md5_generate(client); - ipc_client_log(client, "nv_data_write: exit\n"); + ipc_client_log(client, "nv_data_write: exit\n"); return 0; } |