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 7baf6e5..30b88fc 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 45efeee..3c8d5f3 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 b7d2161..b4a1c03 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 983ed6d..1adeec7 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 4e47551..351266a 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 dd69b70..f1aecec 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 82d2690..0033904 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 f1a1a0d..63c0f24 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...");