Change to allow duplicated mount/umount API calls for lockscreen 88/120188/2 accepted/tizen/common/20170322.154121 accepted/tizen/ivi/20170322.235811 accepted/tizen/mobile/20170322.235723 accepted/tizen/tv/20170322.235745 accepted/tizen/unified/20170322.235840 accepted/tizen/wearable/20170322.235751 submit/tizen/20170322.105714
authorSungbae Yoo <sungbae.yoo@samsung.com>
Wed, 22 Mar 2017 05:06:08 +0000 (14:06 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Wed, 22 Mar 2017 05:52:57 +0000 (14:52 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: Ieab8aea8507a9138645ec2a991a08e3981be4a22

server/engine/encryption/dmcrypt-engine.cpp
server/engine/encryption/dmcrypt-engine.h
server/engine/encryption/ecryptfs-engine.cpp
server/engine/encryption/ecryptfs-engine.h
server/engine/encryption/ext4-engine.cpp
server/engine/encryption/ext4-engine.h
server/external-encryption.cpp
server/internal-encryption.cpp

index 7baf6e506d023cbe27abf718b954482c14934a59..30b88fcadfb3305213503428243e2f3c054159b6 100644 (file)
@@ -246,6 +246,8 @@ void DMCryptEngine::mount(const DMCryptEngine::data &key, unsigned int options)
 
        if (::mount(cryptoBlkDev.c_str(), destination.c_str(), "ext4", 0, 0) < 0)
                throw runtime::Exception(runtime::GetSystemErrorMessage());
+
+       mounted = true;
 }
 
 void DMCryptEngine::umount()
@@ -254,6 +256,13 @@ void DMCryptEngine::umount()
                throw runtime::Exception(runtime::GetSystemErrorMessage());
 
        destroyCryptoBlkDev(DM_DEFAULT_LABEL_NAME);
+
+       mounted = false;
+}
+
+bool DMCryptEngine::isMounted()
+{
+       return mounted;
 }
 
 void DMCryptEngine::encrypt(const DMCryptEngine::data &key, unsigned int options)
index 45efeeebf0b015a00d9c31a1c42654071ac30583..3c8d5f3744d78d2d71803ba18154cfa8874761e4 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <vector>
 #include <string>
+#include <atomic>
 
 #include "progress-bar.h"
 
@@ -48,6 +49,7 @@ public:
 
        void mount(const data &key, unsigned int options);
        void umount();
+       bool isMounted();
 
        void encrypt(const data &key, unsigned int options);
        void decrypt(const data &key, unsigned int options);
@@ -62,6 +64,7 @@ public:
 private:
        std::string source, destination;
        ProgressBar progress;
+       std::atomic<bool> mounted;
 };
 
 } // namespace ode
index b7d2161b192e97042c85228d304e77c62f8a7326..b4a1c03ab7e3dd895c6d851a8dd0282e6f74a9b4 100644 (file)
@@ -325,11 +325,20 @@ EcryptfsEngine::~EcryptfsEngine()
 void EcryptfsEngine::mount(const data &key, unsigned int options)
 {
        ecryptfsMount(source, destination, key, options);
+
+       mounted = true;
 }
 
 void EcryptfsEngine::umount()
 {
        ecryptfsUmount(destination);
+
+       mounted = false;
+}
+
+bool EcryptfsEngine::isMounted()
+{
+       return mounted;
 }
 
 void EcryptfsEngine::encrypt(const data &key, unsigned int options)
index 983ed6d2542574ac6102842ffc89d566717579b2..1adeec76a48441f99a8b91c3a8b4043c664f4316 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <vector>
 #include <string>
+#include <atomic>
 
 #include "progress-bar.h"
 
@@ -48,6 +49,7 @@ public:
 
        void mount(const data& key, unsigned int);
        void umount();
+       bool isMounted();
 
        void encrypt(const data& key, unsigned int);
        void decrypt(const data& key, unsigned int);
@@ -62,6 +64,7 @@ public:
 private:
        std::string source, destination;
        ProgressBar progress;
+       std::atomic<bool> mounted;
 };
 
 } // namespace ode
index 4e47551643769f5705b9ead2742ee9bf0a9abeac..351266a1f40b4e1b2867e1c46ab8de0f4d991467 100644 (file)
@@ -310,6 +310,8 @@ void Ext4Engine::mount(const Ext4Engine::data& key, unsigned int options)
        if (::mount(encryptedPath.c_str(), destination.c_str(), NULL, MS_BIND, 0) < 0) {
                throw runtime::Exception("Mount error - " + runtime::GetSystemErrorMessage());
        }
+
+       mounted = true;
 }
 
 void Ext4Engine::umount()
@@ -319,6 +321,13 @@ void Ext4Engine::umount()
        if (::umount(destination.c_str())) {
                throw runtime::Exception(runtime::GetSystemErrorMessage());
        }
+
+       mounted = false;
+}
+
+bool Ext4Engine::isMounted()
+{
+       return mounted;
 }
 
 void Ext4Engine::encrypt(const Ext4Engine::data& key, unsigned int options)
index dd69b7073b6a69e767cca5355c9636b6dd647ceb..f1aecec3d483c22e021e17cec0b3a1fd23f6bec8 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <vector>
 #include <string>
+#include <atomic>
 
 #include "progress-bar.h"
 
@@ -48,6 +49,7 @@ public:
 
        void mount(const data &key, unsigned int options);
        void umount();
+       bool isMounted();
 
        void encrypt(const data &key, unsigned int options);
        void decrypt(const data &key, unsigned int options);
@@ -62,6 +64,7 @@ public:
 private:
        std::string source, destination;
        ProgressBar progress;
+       std::atomic<bool> mounted;
 };
 
 } // namespace ode
index 82d2690117efb42d99ac6d4ebb110e67370f075a..003390402cec9599eec44e9b27acab909bf02710 100644 (file)
@@ -201,6 +201,11 @@ int ExternalEncryption::mount(const std::string &password)
                return -2;
        }
 
+       if (engine->isMounted()) {
+               INFO("Already mounted");
+               return 0;
+       }
+
        engine->mount(keyManager.getMasterKey(data), getOptions());
        context.notify("ExternalEncryption::mount");
 
@@ -213,6 +218,11 @@ int ExternalEncryption::umount()
                return -1;
        }
 
+       if (!engine->isMounted()) {
+               INFO("Already umounted");
+               return 0;
+       }
+
        INFO("Close all applications using external storage...");
        killDependedApplications();
        INFO("Umount external storage...");
index f1a1a0d73be64926ae803c1fe919cc355e61287a..63c0f2460f8150e41a167e7642ea64b53104caf5 100644 (file)
@@ -234,6 +234,11 @@ int InternalEncryption::mount(const std::string& password)
                return -2;
        }
 
+    if (engine->isMounted()) {
+               INFO("Already mounted");
+               return 0;
+       }
+
        engine->mount(keyManager.getMasterKey(pwData), getOptions());
        context.notify("InternalEncryption::mount");
 
@@ -246,6 +251,11 @@ int InternalEncryption::umount()
                return -1;
        }
 
+       if (!engine->isMounted()) {
+               INFO("Already umounted");
+               return 0;
+       }
+
        INFO("Close all processes using internal storage...");
        stopDependedSystemdServices();
        INFO("Umount internal storage...");