From ef145d51e7761b2b093300cf2b9e4dde7487abb4 Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzelewski Date: Thu, 11 Dec 2014 15:38:08 +0100 Subject: [PATCH] Prevent desynchronization in "battery remove test". This commit force to save encrypted data as soon as possible. There is still small time window then desynhronization may happen. Desynchronization may occure if you take out battery exectly after the data was saved by ckm and the confirmation was not send to security-server yet. Change-Id: Ib4d4f0299001d9c71b13acdcfa136298d942ab6c --- src/manager/dpl/core/include/dpl/fstream_accessors.h | 8 ++++---- src/manager/service/file-system.cpp | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/manager/dpl/core/include/dpl/fstream_accessors.h b/src/manager/dpl/core/include/dpl/fstream_accessors.h index 1f6b7a3..b1aa17c 100644 --- a/src/manager/dpl/core/include/dpl/fstream_accessors.h +++ b/src/manager/dpl/core/include/dpl/fstream_accessors.h @@ -15,17 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License * - * @file fstream-helper.h + * @file fstream-accessors.h * @author Marek Smolinski (m.smolinski@samsung.com) * @version 1.0 - * @brief This file is the implementation file of fstream-helper + * @brief This file is the implementation file of fstream-accessors * */ #ifndef CENT_KEY_FSTREAM_ACCESSORS_H #define CENT_KEY_FSTREAM_ACCESSORS_H -namespace DPL { +namespace CKM { /* * Bypass lack of public member function to get file @@ -43,6 +43,6 @@ public: } }; -} // namespace DPL +} // namespace CKM #endif // CENT_KEY_FSTREAM_ACCESSORS_H diff --git a/src/manager/service/file-system.cpp b/src/manager/service/file-system.cpp index 0c59753..cefea59 100644 --- a/src/manager/service/file-system.cpp +++ b/src/manager/service/file-system.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -104,8 +105,15 @@ RawBuffer FileSystem::getDBDEK() const } bool FileSystem::saveFile(const std::string &path, const RawBuffer &buffer) const { - std::ofstream os(path, std::ios::out | std::ofstream::binary); + std::ofstream os(path, std::ios::out | std::ofstream::binary | std::ofstream::trunc); std::copy(buffer.begin(), buffer.end(), std::ostreambuf_iterator(os)); + if (os.fail()) + return false; + + // Prevent desynchronization in batter remove test. + os.flush(); + fsync(FstreamAccessors::GetFd(os)); // flush kernel space buffer + os.close(); return !os.fail(); } -- 2.7.4