From 03727a39a123574964a05b233df7227c16f22535 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 13 Apr 2022 11:27:34 +0200 Subject: [PATCH] Add fflush after program and erase operations This is needed to keep the file in sync during swap operations if reset occurs, because the file is closed only at the end of the swap process. --- app/fileblockdevice/FileBlockDevice.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/fileblockdevice/FileBlockDevice.cpp b/app/fileblockdevice/FileBlockDevice.cpp index c8bfc1b..b93b44b 100644 --- a/app/fileblockdevice/FileBlockDevice.cpp +++ b/app/fileblockdevice/FileBlockDevice.cpp @@ -121,6 +121,12 @@ int FileBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size) return BD_ERROR_DEVICE_ERROR; } + err = fflush(_file[0]); + if (err != 0u) { + printf("E-Program:flush\n"); + return BD_ERROR_DEVICE_ERROR; + } + return BD_ERROR_OK; } @@ -148,6 +154,12 @@ int FileBlockDevice::erase(bd_addr_t addr, bd_size_t size) } } + int err = fflush(_file[0]); + if (err != 0u) { + printf("E-Erase:flush\n"); + return BD_ERROR_DEVICE_ERROR; + } + return BD_ERROR_OK; }