Add an internal api: storage_is_mounted_opt_usr
[platform/core/system/libstorage.git] / src / storage-inhouse.c
index efd62db..3c06157 100755 (executable)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <errno.h>
 #include <tzplatform_config.h>
+#include <blkid.h>
 
 #include "common.h"
 #include "list.h"
@@ -30,6 +31,7 @@
 #include "storage-external-dbus.h"
 
 #define FORMAT_TIMEOUT (120*1000)
+#define USER_PARTITION "user"
 
 /*
        Get compat path from origin Multi-user path
@@ -419,12 +421,74 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option)
        return STORAGE_ERROR_NONE;
 }
 
-int storage_is_mounted(char *path, bool *mounted)
+API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted)
 {
+       blkid_cache cache = NULL;
+       blkid_dev_iterate iter;
+       blkid_dev dev;
        int ret;
+       bool found = false;
 
-       ret = mount_check(path);
+       ret = blkid_get_cache(&cache, NULL);
+       if (ret < 0) {
+               _E("Failed to get cache"); //LCOV_EXCL_LINE
+               *mounted = STORAGE_PART_ERROR; //LCOV_EXCL_LINE
+               return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       ret = blkid_probe_all(cache);
+       if (ret < 0) {
+               _E("Failed to probe all block devices"); //LCOV_EXCL_LINE
+               *mounted = STORAGE_PART_ERROR; //LCOV_EXCL_LINE
+               return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       iter = blkid_dev_iterate_begin(cache);
+       if (!iter) {
+               _E("Failed to get iterate"); //LCOV_EXCL_LINE
+               *mounted = STORAGE_PART_ERROR; //LCOV_EXCL_LINE
+               return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+       }
+
+       ret = blkid_dev_set_search(iter, "LABEL", USER_PARTITION);
+       if (blkid_dev_next(iter, &dev) == 0) {
+               dev = blkid_verify(cache, dev);
+               if (dev) {
+                       found = true;
+                       _D("Partition for user data is found(LABEL=user)");
+               }
+       }
+       blkid_dev_iterate_end(iter);
+
+       if (!found) {
+               iter = blkid_dev_iterate_begin(cache);
+               if (!iter) {
+                       _E("Failed to get iterate"); //LCOV_EXCL_LINE
+                       *mounted = STORAGE_PART_ERROR; //LCOV_EXCL_LINE
+                       return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+               }
+
+               ret = blkid_dev_set_search(iter, "PARTLABEL", USER_PARTITION);
+               if (blkid_dev_next(iter, &dev) == 0) {
+                       dev = blkid_verify(cache, dev);
+                       if (dev) {
+                               found = true;
+                               _D("Partition for user data is found(PARTLABEL=user)");
+                       }
+               }
+               blkid_dev_iterate_end(iter);
+       }
+
+       blkid_put_cache(cache);
+
+       if (found) {
+               ret = mount_check(tzplatform_getenv(TZ_SYS_USER));
+               if (ret)
+                       *mounted = STORAGE_PART_MOUNTED;
+               else
+                       *mounted = STORAGE_PART_NOT_MOUNTED;
+       } else
+               *mounted = STORAGE_PART_NOT_SUPPORTED;
 
-       *mounted = ret;
        return STORAGE_ERROR_NONE;
 }