Add ode-fota umount and fix DMCryptEngine::umount,mount 83/183483/8
authorseolheui kim <s414.kim@samsung.com>
Fri, 6 Jul 2018 02:42:42 +0000 (11:42 +0900)
committerseolheui kim <s414.kim@samsung.com>
Fri, 6 Jul 2018 07:24:20 +0000 (16:24 +0900)
- fix DMCryptEngine::umount : ignore exception on umount /opt/usr/apps
- fix DMCryptEngine::mount : check if target mapper exists or not

Change-Id: Ibbbbce89eb269841a904a65b1dd601370e249443
Signed-off-by: seolheui kim <s414.kim@samsung.com>
fota/fota.cpp
server/engine/encryption/dmcrypt-engine.cpp

index b71f6d9..499ff94 100644 (file)
@@ -118,6 +118,7 @@ void ProgressBar::done(void) {}
 namespace {
 
 const std::string MOUNT = "mount";
+const std::string UMOUNT = "umount";
 const std::string REMOVE = "remove";
 
 void usage()
@@ -126,8 +127,9 @@ void usage()
                "Usage: ode-fota [Operation]" << std::endl <<
                std::endl <<
                "Operations :" << std::endl <<
-               "  mount [path]  Mount internal memory using stored master key" << std::endl <<
-               "  remove        Remove stored internal memory master key" << std::endl;
+               "  mount [path]   Mount internal memory using stored master key" << std::endl <<
+               "  umount [path]  Unmount internal memory" << std::endl <<
+               "  remove         Remove stored internal memory master key" << std::endl;
 }
 
 } // anonymous namespace
@@ -155,6 +157,13 @@ int main(int argc, char* argv[])
 
                        // mount options are ignored by mount()
                        dmcrypt.mount(masterKey, 0);
+               } else if (UMOUNT == argv[1]) {
+                       std::string path = INTERNAL_PATH;
+                       if (argc == 3)
+                               path = argv[2];
+
+                       DMCryptEngine dmcrypt(devpath, path, ProgressBar([](int){}));
+                       dmcrypt.umount();
                } else if (REMOVE == argv[1]) {
                        UpgradeSupport::removeMasterKey(devpath);
                } else {
index 1e2d920..6c1121f 100644 (file)
@@ -111,7 +111,7 @@ const std::string createCryptoBlkDev(const std::string &realBlkDev,
 
        // Create Device (mount_name)
        initDMIoctl(dmBuf, DM_MAX_BUFFER_SIZE, mountName, 0);
-       if (ioctl(fd, DM_DEV_CREATE, dmBuf)) {
+       if (ioctl(fd, DM_DEV_CREATE, dmBuf) && errno != EBUSY) {
                close(fd);
                throw runtime::Exception("Cannot create dm-crypt device");
        }
@@ -286,8 +286,9 @@ void DMCryptEngine::mount(const BinaryData &key, unsigned int options)
 
 void DMCryptEngine::umount()
 {
+       //TODO umount("/opt/usr/"apps") will be removed
        if (::umount("/opt/usr/apps") && errno != EINVAL)
-               throw runtime::Exception(runtime::GetSystemErrorMessage());
+               ERROR(SINK, runtime::GetSystemErrorMessage());
 
        if (::umount(destination.c_str()) && errno != EINVAL)
                throw runtime::Exception(runtime::GetSystemErrorMessage());