From 46b035419e5ad082cbeba1098b7fcedb178f15e7 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 1 Nov 2018 09:53:57 +1100 Subject: [PATCH] DataFlash: add sanity checks around EraseAll --- libraries/DataFlash/DataFlash_File.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/DataFlash/DataFlash_File.cpp b/libraries/DataFlash/DataFlash_File.cpp index 6d46048156..8c68fbb46e 100644 --- a/libraries/DataFlash/DataFlash_File.cpp +++ b/libraries/DataFlash/DataFlash_File.cpp @@ -487,11 +487,18 @@ char *DataFlash_File::_lastlog_file_name(void) const // remove all log files void DataFlash_File::EraseAll() { - uint16_t log_num; + if (hal.util->get_soft_armed()) { + // do not want to do any filesystem operations while we are e.g. flying + return; + } + if (!_initialised) { + return; + } + const bool was_logging = (_write_fd != -1); stop_logging(); - for (log_num=1; log_num<=MAX_LOG_FILES; log_num++) { + for (uint16_t log_num=1; log_num<=MAX_LOG_FILES; log_num++) { char *fname = _log_file_name(log_num); if (fname == nullptr) { break;