Add an internal api: storage_is_mounted_opt_usr 87/185987/4 accepted/tizen/unified/20180810.132529 submit/tizen/20180810.001302
authorpr.jung <pr.jung@samsung.com>
Mon, 6 Aug 2018 06:32:13 +0000 (15:32 +0900)
committerpr.jung <pr.jung@samsung.com>
Wed, 8 Aug 2018 01:56:06 +0000 (10:56 +0900)
Change-Id: I341f6ac3b481b827ccb381b883dddd559f040c5b
Signed-off-by: pr.jung <pr.jung@samsung.com>
CMakeLists.txt
include/common.h
include/storage-internal.h
packaging/libstorage.spec
src/statvfs.c
src/storage-inhouse.c

index 3169d78..83b6ea6 100644 (file)
@@ -18,6 +18,7 @@ SET(dependents
                gio-2.0
                libtzplatform-config
                mount
+               blkid
 )
 SET(pc_dependents "capi-base-common")
 
index af8bc3f..5c5a8ac 100644 (file)
@@ -85,7 +85,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf
 #define COMPAT_DIR "/opt/usr/media"
 int is_compat_bind_mount(void);
 int storage_ext_is_supported(void);
-int mount_check(char *path);
+int mount_check(const char *path);
 
 #define USER_UID_START         5000
 
index 5548d84..9aba117 100644 (file)
@@ -139,18 +139,26 @@ int storage_request_format_mmc(struct mmc_contents *mmc_data);
  */
 int storage_format_mmc(struct mmc_contents *mmc_data, int option);
 
+typedef enum {
+       STORAGE_PART_ERROR = -1, /**< Checking partition is failed */
+       STORAGE_PART_NOT_MOUNTED = 0, /**< Partition is not mounted */
+       STORAGE_PART_MOUNTED = 1, /**< Partition is mounted */
+       STORAGE_PART_NOT_SUPPORTED = 2, /**< Partition is not supported */
+} storage_part_mount_e;
+
 /**
- * @brief This API is used to format mmc.\n
+ * @brief This API is used to check user data partition is mounted.\n
  *
- * @param[in] path for checking mounted
- * @param[out] mounted True when path is mounted
+ * @param[out] mounted 1 when user partition is mounted, 0 when user partition is not mounted, 2 when user partition is not supported(2 partitions), and Less then 0 when error return.
  *
  * @return @c 0 on success,
  *         otherwise a negative error value
  *
  * @retval #STORAGE_ERROR_NONE               Successful
+ * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
+ * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory
  */
-int storage_is_mounted(char *path, bool *mounted);
+int storage_is_mounted_opt_usr(storage_part_mount_e *mounted);
 
 /**
  * @}
index f050da4..59de131 100644 (file)
@@ -14,6 +14,7 @@ BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(mount)
+BuildRequires:  pkgconfig(blkid)
 
 %description
 development package of library to get storage
index 2c470cc..3ec9ace 100644 (file)
@@ -288,7 +288,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf)
        return 0;
 }
 
-int mount_check(char *path)
+int mount_check(const char *path)
 {
        int ret = false;
        struct mntent *mnt;
@@ -341,7 +341,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf)
                }
        }
 
-       if (!mount_check(ext_path))
+       if (!mount_check((const char *)ext_path))
                goto out_nodev;
 
        ret = storage_ext_get_statvfs(ext_path, &temp);
@@ -385,7 +385,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf
                }
        }
 
-       if (!mount_check(ext_path))
+       if (!mount_check((const char *)ext_path))
                goto out_nodev;
 
        ret = storage_ext_get_statvfs_size64(ext_path, buf);
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;
 }