From 3476831246d3098bb0f563fe57603bd1bf59dd99 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Fri, 8 Sep 2023 10:16:24 -0400 Subject: [PATCH] dataman: explicitly check file existence to init - on NuttX if the SD card was just cleared (quick format) it's possible for the newly created uninitialized dataman file to still have the previous compatibility key, which causes the initialization to be skipped --- src/modules/dataman/dataman.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/dataman/dataman.cpp b/src/modules/dataman/dataman.cpp index eb25328a5b..fc42770a96 100644 --- a/src/modules/dataman/dataman.cpp +++ b/src/modules/dataman/dataman.cpp @@ -529,6 +529,8 @@ _file_clear(dm_item_t item) static int _file_initialize(unsigned max_offset) { + const bool file_existed = (access(k_data_manager_device_path, F_OK) == 0); + /* Open or create the data manager file */ dm_operations_data.file.fd = open(k_data_manager_device_path, O_RDWR | O_CREAT | O_BINARY, PX4_O_MODE_666); @@ -553,7 +555,7 @@ _file_initialize(unsigned max_offset) dm_operations_data.silence = false; - if (compat_state.key != DM_COMPAT_KEY) { + if (!file_existed || (compat_state.key != DM_COMPAT_KEY)) { /* Write current compat info */ compat_state.key = DM_COMPAT_KEY;