From: Lukasz Pawelczyk Date: Tue, 12 Sep 2017 12:13:55 +0000 (+0200) Subject: ExtensionEncryption: handle encrypted external sd while formatting X-Git-Tag: submit/tizen_4.0/20170922.051801~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=395ef5fa8c3420d8f974b4c87799f89df252b113;p=platform%2Fcore%2Fsecurity%2Fode.git ExtensionEncryption: handle encrypted external sd while formatting There will be two different things mounted as /opt/media/SDCardA1 while external sd card is encrypted and mounted. Handle this case. TODO for the findKillAndUmount() usage is still valid, this is just an immediate workaround for the issue. Change-Id: If0209165401e9fb88895c417b127aad2fcb75828 --- diff --git a/server/extension-encryption.cpp b/server/extension-encryption.cpp index 65a7b94..aa5e176 100644 --- a/server/extension-encryption.cpp +++ b/server/extension-encryption.cpp @@ -61,16 +61,23 @@ std::condition_variable storagedCv; bool findKillAndUmount(const std::string &devPath) { - std::string realMntPath = findMntPath(devPath); - if (!realMntPath.empty()) { + for(;;) { + std::string mntPath = findMntPath(devPath); + + if (mntPath.empty()) { + break; + } + INFO(SINK, "Closing all applications using an SD card..."); - killDependentApplications(realMntPath); + killDependentApplications(mntPath); - int ret = ::umount(realMntPath.c_str()); - if (ret != 0) { - ERROR(SINK, "The card is still mounted, umount failed with: " - + std::to_string(ret)); - return false; + while (::umount(mntPath.c_str()) == -1) { + if (errno != EBUSY) { + ERROR(SINK, "The card is still mounted, umount failed with: " + + std::to_string(errno)); + return false; + } + killDependentApplications(mntPath); } } @@ -262,9 +269,10 @@ int ExtensionEncryption::format(const std::string &password) // TODO: this probably needs a rework, some sort of communication // and/or merge with External. The use case for it might be: // 1. The mmc is mounted by something else, somewhere else. Do we care? - // 2. We take over the cd card from External. - if (!findKillAndUmount(EXTENSION_DEV_PATH)) + // 2. We take over the (possibly mounted and/or encrypted) cd card from External. + if (!findKillAndUmount(EXTENSION_DEV_PATH)) { return; + } INFO(SINK, "Creating LUKS..."); engine->format(CryptsetupEngine::DeviceType::LUKS, masterKey);