aboutsummaryrefslogtreecommitdiff
path: root/src/modules/dataman
diff options
context:
space:
mode:
authorJean Cyr <jcyr@dillobits.com>2014-04-22 01:19:01 -0400
committerJean Cyr <jcyr@dillobits.com>2014-04-22 01:19:01 -0400
commitbf4558c31b46bb5d7b30729dd23302048447a890 (patch)
tree82bb45047dfe13732dba98c06b22102e3249805e /src/modules/dataman
parentaf336603517a32b86481c5f57d9be51657eb3f0d (diff)
downloadpx4-firmware-bf4558c31b46bb5d7b30729dd23302048447a890.tar.gz
px4-firmware-bf4558c31b46bb5d7b30729dd23302048447a890.tar.bz2
px4-firmware-bf4558c31b46bb5d7b30729dd23302048447a890.zip
Reduce data manager SD card wear and tear
When the data manager was first designed each file record contained a 2 byte header and an 126 byte data section, resulting in a record length of 128 bytes. Along the way it was decided to add 2 spare bytes to the record header, but regrettably the data section was not correspondingly reduced in size so we end up with a record length of 130 bytes. This is bad since it does not align with SD card flash sectors and results in more erase/write flash cycles than necessary thus reducing the SD cards life. This update reduced the data section of the data manager to 124, resulting in an optimal record length of 128 bytes. In order to avoid the reuse of data previously written data in the old format, which could result in catastrophic misinterpretation, the data manager file is checked at startup. If it is found to be in the old format, it is deleted and recreated with in the new record length. In this case previously stored data is lost, but that is far safer than the unpredictable result of using the old file.
Diffstat (limited to 'src/modules/dataman')
-rw-r--r--src/modules/dataman/dataman.c19
-rw-r--r--src/modules/dataman/dataman.h2
2 files changed, 18 insertions, 3 deletions
diff --git a/src/modules/dataman/dataman.c b/src/modules/dataman/dataman.c
index 34d20e485..c132b0040 100644
--- a/src/modules/dataman/dataman.c
+++ b/src/modules/dataman/dataman.c
@@ -44,7 +44,9 @@
#include <stdlib.h>
#include <fcntl.h>
#include <systemlib/systemlib.h>
+#include <systemlib/err.h>
#include <queue.h>
+#include <string.h>
#include "dataman.h"
@@ -594,6 +596,20 @@ task_main(int argc, char *argv[])
sem_init(&g_work_queued_sema, 1, 0);
+ /* See if the data manage file exists and is a multiple of the sector size */
+ g_task_fd = open(k_data_manager_device_path, O_RDONLY | O_BINARY);
+ if (g_task_fd >= 0) {
+ /* File exists, check its size */
+ int file_size = lseek(g_task_fd, 0, SEEK_END);
+ if ((file_size % k_sector_size) != 0) {
+ warnx("Incompatible data manager file %s, resetting it", k_data_manager_device_path);
+ close(g_task_fd);
+ unlink(k_data_manager_device_path);
+ }
+ else
+ close(g_task_fd);
+ }
+
/* Open or create the data manager file */
g_task_fd = open(k_data_manager_device_path, O_RDWR | O_CREAT | O_BINARY);
@@ -603,7 +619,7 @@ task_main(int argc, char *argv[])
return -1;
}
- if (lseek(g_task_fd, max_offset, SEEK_SET) != max_offset) {
+ if ((unsigned)lseek(g_task_fd, max_offset, SEEK_SET) != max_offset) {
close(g_task_fd);
warnx("Could not seek data manager file %s", k_data_manager_device_path);
sem_post(&g_init_sema); /* Don't want to hang startup */
@@ -776,4 +792,3 @@ dataman_main(int argc, char *argv[])
exit(1);
}
-
diff --git a/src/modules/dataman/dataman.h b/src/modules/dataman/dataman.h
index a70638ccc..33c9fcd15 100644
--- a/src/modules/dataman/dataman.h
+++ b/src/modules/dataman/dataman.h
@@ -79,7 +79,7 @@ extern "C" {
} dm_reset_reason;
/* Maximum size in bytes of a single item instance */
- #define DM_MAX_DATA_SIZE 126
+ #define DM_MAX_DATA_SIZE 124
/* Retrieve from the data manager store */
__EXPORT ssize_t