From f508857ecc798a8634ba5e97968c1c987c4a6e39 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 26 Jul 2018 18:09:28 +0900 Subject: [PATCH 01/16] Add comments for line coverage Change-Id: I3d1b8a61d718608eec06736191961ea8fa4a8a04 Signed-off-by: pr.jung --- src/storage-inhouse.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 3c36f58..060a36d 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -222,6 +222,7 @@ API int storage_get_storage_level(const char *path, char **level) return STORAGE_ERROR_NONE; } +//LCOV_EXCL_START Not called callback static void mount_mmc_cb(GVariant *var, void *user_data, GError *err) { struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; @@ -244,6 +245,7 @@ exit: g_variant_unref(var); (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); } +//LCOV_EXCL_STOP API int storage_request_mount_mmc(struct mmc_contents *mmc_data) { @@ -282,6 +284,7 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data) return STORAGE_ERROR_NONE; } +//LCOV_EXCL_START Not called callback static void unmount_mmc_cb(GVariant *var, void *user_data, GError *err) { struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; @@ -304,6 +307,7 @@ exit: g_variant_unref(var); (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); } +//LCOV_EXCL_STOP API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) { @@ -345,6 +349,7 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) return STORAGE_ERROR_NONE; } +//LCOV_EXCL_START Not called callback static void format_mmc_cb(GVariant *var, void *user_data, GError *err) { struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; @@ -367,6 +372,7 @@ exit: g_variant_unref(var); (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); } +//LCOV_EXCL_STOP API int storage_request_format_mmc(struct mmc_contents *mmc_data) { -- 2.7.4 From b5be274f3310695f24d748b1f26a186089f423d5 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 31 Jul 2018 14:32:45 +0900 Subject: [PATCH 02/16] Add storage_is_mounted api - Check input param path is mounted Change-Id: Ief2f3d1703273d93dcd873c17defda7b6bd6c80e Signed-off-by: pr.jung --- include/common.h | 1 + include/storage-internal.h | 13 +++++++++++++ src/statvfs.c | 2 +- src/storage-inhouse.c | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 0e8f4a7..af8bc3f 100644 --- a/include/common.h +++ b/include/common.h @@ -85,6 +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); #define USER_UID_START 5000 diff --git a/include/storage-internal.h b/include/storage-internal.h index e3bd50a..5548d84 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -140,6 +140,19 @@ int storage_request_format_mmc(struct mmc_contents *mmc_data); int storage_format_mmc(struct mmc_contents *mmc_data, int option); /** + * @brief This API is used to format mmc.\n + * + * @param[in] path for checking mounted + * @param[out] mounted True when path is mounted + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #STORAGE_ERROR_NONE Successful + */ +int storage_is_mounted(char *path, bool *mounted); + +/** * @} */ diff --git a/src/statvfs.c b/src/statvfs.c index 99ed755..2c470cc 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -288,7 +288,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) return 0; } -static int mount_check(char *path) +int mount_check(char *path) { int ret = false; struct mntent *mnt; diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 060a36d..efd62db 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -418,3 +418,13 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option) return STORAGE_ERROR_NONE; } + +int storage_is_mounted(char *path, bool *mounted) +{ + int ret; + + ret = mount_check(path); + + *mounted = ret; + return STORAGE_ERROR_NONE; +} -- 2.7.4 From e385cee34928900da2ac0cc90bc231a55fd69cc0 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 6 Aug 2018 15:32:13 +0900 Subject: [PATCH 03/16] Add an internal api: storage_is_mounted_opt_usr Change-Id: I341f6ac3b481b827ccb381b883dddd559f040c5b Signed-off-by: pr.jung --- CMakeLists.txt | 1 + include/common.h | 2 +- include/storage-internal.h | 16 ++++++++--- packaging/libstorage.spec | 1 + src/statvfs.c | 6 ++-- src/storage-inhouse.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 85 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3169d78..83b6ea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ SET(dependents gio-2.0 libtzplatform-config mount + blkid ) SET(pc_dependents "capi-base-common") diff --git a/include/common.h b/include/common.h index af8bc3f..5c5a8ac 100644 --- a/include/common.h +++ b/include/common.h @@ -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 diff --git a/include/storage-internal.h b/include/storage-internal.h index 5548d84..9aba117 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -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); /** * @} diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index f050da4..59de131 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -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 diff --git a/src/statvfs.c b/src/statvfs.c index 2c470cc..3ec9ace 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -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); diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index efd62db..3c06157 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -22,6 +22,7 @@ #include #include #include +#include #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; } -- 2.7.4 From 49e6771fa096c14cb5feab95ad68e7bedee19cb4 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 10 Aug 2018 11:12:15 +0900 Subject: [PATCH 04/16] Fix some #define and add comments regarding _FILE_OFFSET_BITS=32/64 Change-Id: I7849e96b6a1e006685e2c6be953b0092dc953f86 Signed-off-by: Hyotaek Shim --- include/storage.h | 24 +++++++++--------------- src/statvfs.c | 4 ++++ src/storage-external.c | 6 +++--- src/storage-internal.c | 12 ++++++------ 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/storage.h b/include/storage.h index 0665cf3..1b3cbec 100644 --- a/include/storage.h +++ b/include/storage.h @@ -63,14 +63,11 @@ extern "C" { * ... * @endcode */ -#ifndef __USE_FILE_OFFSET64 -extern int storage_get_internal_memory_size(struct statvfs *buf); -#else -# define storage_get_internal_memory_size storage_get_internal_memory_size64 -#endif - #ifdef __USE_FILE_OFFSET64 +#define storage_get_internal_memory_size storage_get_internal_memory_size64 extern int storage_get_internal_memory_size64(struct statvfs *buf); +#else +extern int storage_get_internal_memory_size(struct statvfs *buf); #endif @@ -93,20 +90,17 @@ extern int storage_get_internal_memory_size64(struct statvfs *buf); * ... * @endcode */ -#ifndef __USE_FILE_OFFSET64 -extern int storage_get_external_memory_size(struct statvfs *buf); -#else -# ifdef __REDIRECT_NTH +#ifdef __USE_FILE_OFFSET64 +#ifdef __REDIRECT_NTH extern int __REDIRECT_NTH(storage_get_external_memory_size, (struct statvfs *buf), storage_get_external_memory_size64) __nonnull((1)); -# else -# define storage_get_external_memory_size storage_get_external_memory_size64 -# endif +#else +#define storage_get_external_memory_size storage_get_external_memory_size64 #endif - -#ifdef __USE_FILE_OFFSET64 extern int storage_get_external_memory_size64(struct statvfs *buf); +#else +extern int storage_get_external_memory_size(struct statvfs *buf); #endif diff --git a/src/statvfs.c b/src/statvfs.c index 3ec9ace..0085d49 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -223,6 +223,7 @@ static int get_memory_size(const char *path, struct statvfs_32 *buf) return 0; } +/* This api is intended for binaries built with _FILE_OFFSET_BITS=32 */ API int storage_get_internal_memory_size(struct statvfs *buf) { struct statvfs_32 temp; @@ -257,6 +258,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) return 0; } +/* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ API int storage_get_internal_memory_size64(struct statvfs *buf) { static unsigned long reserved = 0; @@ -313,6 +315,7 @@ static int get_external_path(char *path, size_t len) return storage_ext_get_primary_mmc_path(path, len); } +/* This api is intended for binaries built with _FILE_OFFSET_BITS=32 */ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) { struct statvfs_32 temp; @@ -358,6 +361,7 @@ out_nodev: return 0; } +/* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf) { int ret; diff --git a/src/storage-external.c b/src/storage-external.c index aee5d6c..a0647a5 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -105,10 +105,10 @@ int storage_ext_get_space(int storage_id, } if (state >= STORAGE_STATE_MOUNTED) { -#ifndef __USE_FILE_OFFSET64 - ret = storage_get_external_memory_size_with_path(dev->mount_point, &s); -#else +#ifdef __USE_FILE_OFFSET64 ret = storage_get_external_memory_size64_with_path(dev->mount_point, &s); +#else + ret = storage_get_external_memory_size_with_path(dev->mount_point, &s); #endif if (ret < 0) { _E("Failed to get external memory size of (%s)(ret:%d)", dev->mount_point, ret); //LCOV_EXCL_LINE diff --git a/src/storage-internal.c b/src/storage-internal.c index 0dadec9..2f8a796 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -29,10 +29,10 @@ #include "common.h" #include "log.h" -#ifndef __USE_FILE_OFFSET64 -int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); -#else +#ifdef __USE_FILE_OFFSET64 int __WEAK__ storage_get_internal_memory_size64(struct statvfs *buf); +#else +int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); #endif static int internal_get_state(void) @@ -45,10 +45,10 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava struct statvfs s; int ret; -#ifndef __USE_FILE_OFFSET64 - ret = storage_get_internal_memory_size(&s); -#else +#ifdef __USE_FILE_OFFSET64 ret = storage_get_internal_memory_size64(&s); +#else + ret = storage_get_internal_memory_size(&s); #endif if (ret < 0) return -EPERM; -- 2.7.4 From d271b70ebbd43fa434faee15f8a6ddff609dc668 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 10 Aug 2018 15:23:02 +0900 Subject: [PATCH 05/16] Fix documentation for storage_get_internal_memory_size and storage_get_external_memory_size Change-Id: Ic71b471508ce6598a181775468aaf597e1e1668f Signed-off-by: pr.jung --- include/storage.h | 14 +++++++++----- src/statvfs.c | 28 ++++++++++++++-------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/include/storage.h b/include/storage.h index 1b3cbec..992497e 100644 --- a/include/storage.h +++ b/include/storage.h @@ -41,16 +41,18 @@ extern "C" { #include -#include "storage-expand.h" +#include /** - * @brief int storage_get_internal_memory_size(struct statvfs *buf). - * @brief This generic API is used to get the internal memory size. + * @brief Gets the internal memory size. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @param[out] buf A pointer to a statvfs structure * @return @c 0 on success, * otherwise a negative error value on failure + * @retval #STORAGE_ERROR_NONE Successful + * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @par Example: * @code * ... @@ -72,12 +74,14 @@ extern int storage_get_internal_memory_size(struct statvfs *buf); /** - * @brief int storage_get_external_memory_size(struct statvfs *buf). - * @brief This generic API is used to get the external memory size. + * @brief Gets the external memory size. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @param[out] buf A pointer to a statvfs structure * @return @c 0 on success, * otherwise a negative error value on failure + * @retval #STORAGE_ERROR_NONE Successful + * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @par Example: * @code * ... diff --git a/src/statvfs.c b/src/statvfs.c index 0085d49..75c9b03 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -232,13 +232,13 @@ API int storage_get_internal_memory_size(struct statvfs *buf) if (!buf) { _E("input param error"); - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } ret = get_memory_size(tzplatform_getenv(TZ_SYS_USER), &temp); if (ret || temp.f_bsize == 0) { _E("fail to get memory size %d", ret); //LCOV_EXCL_LINE - return -errno; //LCOV_EXCL_LINE System Error + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } if (reserved == 0) { @@ -255,7 +255,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) temp.f_bavail -= reserved; memcpy(buf, &temp, sizeof(temp)); - return 0; + return STORAGE_ERROR_NONE; } /* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ @@ -266,13 +266,13 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) if (!buf) { _E("input param error"); //LCOV_EXCL_LINE - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } ret = statvfs(tzplatform_getenv(TZ_SYS_USER), buf); if (ret) { _E("fail to get memory size"); //LCOV_EXCL_LINE - return -errno; //LCOV_EXCL_LINE System Error + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } if (reserved == 0) { @@ -287,7 +287,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) buf->f_bavail = 0; else buf->f_bavail -= reserved; - return 0; + return STORAGE_ERROR_NONE; } int mount_check(const char *path) @@ -325,7 +325,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) _D("storage_get_external_memory_size"); if (!buf) { _E("input param error"); - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } if (path) @@ -340,7 +340,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) goto out_nodev; if (ret < 0) { _E("Failed to get external path(%d)", ret); //LCOV_EXCL_LINE - return ret; + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } } @@ -350,7 +350,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) ret = storage_ext_get_statvfs(ext_path, &temp); if (ret) { _E("fail to get memory size"); //LCOV_EXCL_LINE - return ret; //LCOV_EXCL_LINE System Error + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } memcpy(buf, &temp, sizeof(temp)); @@ -358,7 +358,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) out_nodev: memset(buf, 0, sizeof(struct statvfs_32)); - return 0; + return STORAGE_ERROR_NONE; } /* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ @@ -370,7 +370,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf _D("storage_get_external_memory_size64"); if (!buf) { _E("input param error"); - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } if (path) @@ -385,7 +385,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf goto out_nodev; if (ret < 0) { _E("Failed to get external path(%d)", ret); - return ret; + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } } @@ -396,11 +396,11 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf if (ret) { //LCOV_EXCL_START System Error _E("fail to get memory size"); - return -errno; + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE //LCOV_EXCL_STOP } - return 0; + return STORAGE_ERROR_NONE; out_nodev: memset(buf, 0, sizeof(struct statvfs)); -- 2.7.4 From 034b16452aaffdbdd5e44fe8cf02102bb4df4b23 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 11 Sep 2018 14:45:06 +0900 Subject: [PATCH 06/16] Add license file on all rpm packages Change-Id: I17687df79b90eb6820e1e8a867fc7fdc7be4276c Signed-off-by: pr.jung --- packaging/libstorage.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 59de131..4c7601b 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -52,3 +52,4 @@ make %{?jobs:-j%jobs} %{_includedir}/storage/*.h %{_libdir}/*.so %{_libdir}/pkgconfig/*.pc +%license LICENSE.Apache-2.0 -- 2.7.4 From 55d055938c2a84182b30f81cd4d5863c8d1b1ee9 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 11 Sep 2018 16:25:44 +0900 Subject: [PATCH 07/16] Minor fix on license Change-Id: Id19d794bd15b6c0b3406ec27c8916a756cb82cf8 Signed-off-by: Hyotaek Shim --- packaging/libstorage.spec | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 4c7601b..eda0eea 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -43,13 +43,14 @@ make %{?jobs:-j%jobs} %postun -p /sbin/ldconfig %files +%manifest %{name}.manifest +%license LICENSE.Apache-2.0 %{_libdir}/*.so.* %{_sysconfdir}/storage/libstorage.conf -%license LICENSE.Apache-2.0 -%manifest %{name}.manifest %files devel +%manifest %{name}.manifest +%license LICENSE.Apache-2.0 %{_includedir}/storage/*.h %{_libdir}/*.so %{_libdir}/pkgconfig/*.pc -%license LICENSE.Apache-2.0 -- 2.7.4 From 38d52d37ae9cf5f07a4e105e6a05a11eb733740c Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 20 Nov 2018 14:48:47 +0900 Subject: [PATCH 08/16] Add http://tizen.org/feature/storage.external feature for external storage - Add http://tizen.org/feature/storage.external feature for block module - Return STORAGE_ERROR_NOT_SUPPORTED for not supported error Change-Id: I76a9e85b3ae60165cedb9a3ceae53a11ed6d0d95 Signed-off-by: pr.jung --- CMakeLists.txt | 1 + include/storage-expand.h | 8 +++++ include/storage-internal.h | 26 ++++++++-------- packaging/libstorage.spec | 1 + src/statvfs.c | 4 +-- src/storage-common.c | 14 ++++++--- src/storage-external.c | 6 ++-- src/storage-inhouse.c | 2 +- src/storage.c | 74 ++++++++++++++++++++++++++++++++-------------- 9 files changed, 91 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 83b6ea6..cbdb21f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ SET(dependents libtzplatform-config mount blkid + capi-system-info ) SET(pc_dependents "capi-base-common") diff --git a/include/storage-expand.h b/include/storage-expand.h index d5c0843..9cf079b 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -118,6 +118,7 @@ int storage_foreach_device_supported(storage_device_supported_cb callback, void * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @see storage_get_state() */ int storage_get_root_directory(int storage_id, char **path); @@ -160,6 +161,7 @@ typedef enum { * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @see storage_get_state() */ int storage_get_directory(int storage_id, storage_directory_e type, char **path); @@ -174,7 +176,9 @@ int storage_get_directory(int storage_id, storage_directory_e type, char **path) * otherwise a negative error value * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed */ int storage_get_type(int storage_id, storage_type_e *type); @@ -188,7 +192,9 @@ int storage_get_type(int storage_id, storage_type_e *type); * otherwise a negative error value * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @see storage_get_root_directory() * @see storage_get_total_space() * @see storage_get_available_space() @@ -323,6 +329,7 @@ int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback); * otherwise a negative error value * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @see storage_get_state() @@ -340,6 +347,7 @@ int storage_get_total_space(int storage_id, unsigned long long *bytes); * otherwise a negative error value * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @see storage_get_state() diff --git a/include/storage-internal.h b/include/storage-internal.h index 9aba117..609ebf5 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -49,9 +49,9 @@ extern "C" { * * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STORAGE_ERROR_NO_DEVICE No such device - * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed - * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ int storage_get_primary_sdcard(int *storage_id, char **path); @@ -78,8 +78,8 @@ struct mmc_contents { * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_NO_DEVICE No such device - * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed - * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ int storage_request_mount_mmc(struct mmc_contents *mmc_data); @@ -101,8 +101,8 @@ int storage_request_mount_mmc(struct mmc_contents *mmc_data); * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_NO_DEVICE No such device - * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed - * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option); @@ -117,8 +117,8 @@ int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option); * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_NO_DEVICE No such device - * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed - * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ int storage_request_format_mmc(struct mmc_contents *mmc_data); @@ -134,8 +134,8 @@ int storage_request_format_mmc(struct mmc_contents *mmc_data); * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_NO_DEVICE No such device - * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed - * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ int storage_format_mmc(struct mmc_contents *mmc_data, int option); @@ -155,8 +155,8 @@ typedef enum { * 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 + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ int storage_is_mounted_opt_usr(storage_part_mount_e *mounted); diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index eda0eea..2a5d891 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(mount) BuildRequires: pkgconfig(blkid) +BuildRequires: pkgconfig(capi-system-info) %description development package of library to get storage diff --git a/src/statvfs.c b/src/statvfs.c index 75c9b03..cf4fb5a 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -348,7 +348,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) goto out_nodev; ret = storage_ext_get_statvfs(ext_path, &temp); - if (ret) { + if (ret != 0) { _E("fail to get memory size"); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } @@ -393,7 +393,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf goto out_nodev; ret = storage_ext_get_statvfs_size64(ext_path, buf); - if (ret) { + if (ret != 0) { //LCOV_EXCL_START System Error _E("fail to get memory size"); return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE diff --git a/src/storage-common.c b/src/storage-common.c index ea8e174..cc6ea2e 100644 --- a/src/storage-common.c +++ b/src/storage-common.c @@ -18,9 +18,10 @@ #include #include +#include #include "common.h" -#define BLOCK_CONF_FILE "/etc/storaged/block.conf" +#define EXTERNAL_FEATURE "http://tizen.org/feature/storage.external" int is_compat_bind_mount(void) { @@ -56,14 +57,19 @@ int is_compat_bind_mount(void) int storage_ext_is_supported(void) { static int support = -1; + int ret; + bool ext_avail; if (support >= 0) return support; - if (access(BLOCK_CONF_FILE, R_OK) == 0) - support = 1; - else + ret = system_info_get_platform_bool(EXTERNAL_FEATURE, &ext_avail); + if (ret < 0) + support = 0; + else if (ret == 0 && !ext_avail) support = 0; + else + support = 1; return support; } diff --git a/src/storage-external.c b/src/storage-external.c index a0647a5..eb7ec44 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -82,7 +82,7 @@ int storage_ext_get_space(int storage_id, storage_ext_device *dev; if (storage_id < 0) - return -ENOTSUP; + return -ENODEV; dev = calloc(1, sizeof(storage_ext_device)); if (!dev) { @@ -384,7 +384,7 @@ int storage_ext_get_root(int storage_id, char *path, size_t len, bool *extendedi int ret = 0; if (storage_id < 0) - return -ENOTSUP; + return -ENODEV; if (!path) return -EINVAL; @@ -464,7 +464,7 @@ int storage_ext_get_state(int storage_id, storage_state_e *state) int ret; if (storage_id < 0) - return -ENOTSUP; + return -ENODEV; if (!state) return -EINVAL; diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 3c06157..946b4d8 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -170,7 +170,7 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) return STORAGE_ERROR_INVALID_PARAMETER; if (!storage_ext_is_supported()) - return STORAGE_ERROR_NO_DEVICE; + return STORAGE_ERROR_NOT_SUPPORTED; result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, diff --git a/src/storage.c b/src/storage.c index 4e178f5..d11e38a 100644 --- a/src/storage.c +++ b/src/storage.c @@ -107,7 +107,7 @@ API int storage_get_root_directory(int storage_id, char **path) bool user = true; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!path) { _E("Invalid parameger"); @@ -141,7 +141,12 @@ API int storage_get_root_directory(int storage_id, char **path) ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); if (ret < 0) { _E("Failed to get root path of external storage(%d, %d", storage_id, ret); //LCOV_EXCL_LINE - return STORAGE_ERROR_INVALID_PARAMETER; + if (ret == -ENODEV || ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + else if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; } *path = strdup(root); @@ -166,7 +171,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p bool user = true; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!path) { _E("Invalid parameger"); @@ -217,17 +222,22 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p /* external storage */ if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) { _E("Not support directory : id(%d) type(%d)", storage_id, type); //LCOV_EXCL_LINE - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; } ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); if (ret < 0) { _E("Failed to get root dir for external storage(id:%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE - return STORAGE_ERROR_NOT_SUPPORTED; + if (ret == -ENODEV || ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + else if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; } /* The operation is not decided */ if (extendedint) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type]); @@ -250,7 +260,7 @@ API int storage_get_type(int storage_id, storage_type_e *type) bool extendedint; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!type) { _E("Invalid parameger"); @@ -269,7 +279,12 @@ API int storage_get_type(int storage_id, storage_type_e *type) ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); if (ret < 0) { _E("Failed to get type of external storage"); - return STORAGE_ERROR_NOT_SUPPORTED; + if (ret == -ENODEV || ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + else if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; } if (extendedint) *type = STORAGE_TYPE_EXTENDED_INTERNAL; @@ -287,7 +302,7 @@ API int storage_get_state(int storage_id, storage_state_e *state) int ret; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!state) { _E("Invalid parameger"); @@ -306,7 +321,12 @@ API int storage_get_state(int storage_id, storage_state_e *state) ret = storage_ext_get_state(storage_id, &st); if (ret < 0) { _E("Failed to get state (storage id(%d), ret(%d))", storage_id, ret); //LCOV_EXCL_LINE - return STORAGE_ERROR_OPERATION_FAILED; + if (ret == -ENODEV || ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + else if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; } *state = st; @@ -339,7 +359,7 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca static int compat_cb_init = 0; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!callback) { _E("Invalid parameger"); @@ -393,7 +413,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb dd_list *elem; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!callback) { _E("Invalid parameger"); @@ -441,7 +461,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) dd_list *elem; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!bytes) { _E("Invalid parameger"); @@ -462,9 +482,12 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) out: if (ret < 0) { _E("Failed to get total memory : id(%d)", storage_id); //LCOV_EXCL_LINE - if (ret == -ENOTSUP) - return STORAGE_ERROR_NOT_SUPPORTED; - return STORAGE_ERROR_OPERATION_FAILED; + if (ret == -ENODEV || ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + else if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; } *bytes = total; @@ -479,7 +502,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) dd_list *elem; if (storage_id < 0) - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; if (!bytes) { _E("Invalid parameger"); @@ -500,9 +523,12 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) out: if (ret < 0) { _E("Failed to get available memory : id(%d)", storage_id); //LCOV_EXCL_LINE - if (ret == -ENOTSUP) - return STORAGE_ERROR_NOT_SUPPORTED; - return STORAGE_ERROR_OPERATION_FAILED; + if (ret == -ENODEV || ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + else if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; } *bytes = avail; @@ -516,7 +542,7 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, if (type == STORAGE_TYPE_INTERNAL) { _E("Internal storage is not supported"); - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; } if (type != STORAGE_TYPE_EXTERNAL && type != STORAGE_TYPE_EXTENDED_INTERNAL) { @@ -555,7 +581,7 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac if (type == STORAGE_TYPE_INTERNAL) { _E("Internal storage is not supported"); - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; } if (type != STORAGE_TYPE_EXTERNAL && type != STORAGE_TYPE_EXTENDED_INTERNAL) { @@ -615,6 +641,10 @@ API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e ret = storage_ext_get_device_info(storage_id, ext_dev); if (ret < 0) { _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE + if (ret == -ENODEV) { + ret = STORAGE_ERROR_INVALID_PARAMETER; + goto out; + } ret = STORAGE_ERROR_OPERATION_FAILED; goto out; } -- 2.7.4 From fea661f88c5b3ab2c66ed5cafdabed2f2a219e2c Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 25 Jan 2019 11:27:41 +0900 Subject: [PATCH 09/16] Add description for http://tizen.org/feature/storage.external Change-Id: I534b9d1f0fad8469350680563f778b65255cda3d Signed-off-by: pr.jung --- doc/storage_doc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/storage_doc.h b/doc/storage_doc.h index 40fe64f..0260fa3 100755 --- a/doc/storage_doc.h +++ b/doc/storage_doc.h @@ -46,6 +46,19 @@ * - Others * - System ringtones * + * @section CAPI_SYSTEM_STORAGE_MODULE_OVERVIEW Related Features + * This API is related with the following features:\n + * - %http://tizen.org/feature/storage.external\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from feature element description. + * + * */ #endif /* __TIZEN_SYSTEM_STORAGE_DOC_H__ */ -- 2.7.4 From 1c85e6a17c99ac7db3309c8ce77bd91abc1181a7 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 11 Feb 2019 14:24:09 +0900 Subject: [PATCH 10/16] Return NOT_SUPPORTED error when block module is disabled Change-Id: I33c0aeb2520c0414cd61e37a73a18bc687823b1a Signed-off-by: pr.jung --- src/storage.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/storage.c b/src/storage.c index d11e38a..314f622 100644 --- a/src/storage.c +++ b/src/storage.c @@ -138,6 +138,11 @@ API int storage_get_root_directory(int storage_id, char **path) } /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); if (ret < 0) { _E("Failed to get root path of external storage(%d, %d", storage_id, ret); //LCOV_EXCL_LINE @@ -220,6 +225,11 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p } /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) { _E("Not support directory : id(%d) type(%d)", storage_id, type); //LCOV_EXCL_LINE return STORAGE_ERROR_INVALID_PARAMETER; @@ -276,6 +286,11 @@ API int storage_get_type(int storage_id, storage_type_e *type) } /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); if (ret < 0) { _E("Failed to get type of external storage"); @@ -318,6 +333,11 @@ API int storage_get_state(int storage_id, storage_state_e *state) } /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + ret = storage_ext_get_state(storage_id, &st); if (ret < 0) { _E("Failed to get state (storage id(%d), ret(%d))", storage_id, ret); //LCOV_EXCL_LINE @@ -368,6 +388,11 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca /* For backward compatability */ if (storage_id == STORAGE_TYPE_EXTERNAL) { + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + if (!compat_cb_init) { ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, compat_cb, NULL); if (ret == STORAGE_ERROR_NONE) @@ -392,6 +417,11 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca return STORAGE_ERROR_NONE; /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + info.id = storage_id; info.state_cb = callback; info.user_data = user_data; @@ -422,6 +452,11 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb /* For backward compatability */ if (storage_id == STORAGE_TYPE_EXTERNAL) { + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + dd_list *elem_n; struct compat_cb_info* ccb_info; @@ -441,6 +476,11 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb return STORAGE_ERROR_NONE; /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + info.id = storage_id; info.state_cb = callback; @@ -477,6 +517,11 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) } /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + ret = storage_ext_get_space(storage_id, &total, NULL); out: @@ -518,6 +563,11 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) } /* external storage */ + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + ret = storage_ext_get_space(storage_id, NULL, &avail); out: @@ -630,6 +680,11 @@ API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e if (*type == STORAGE_TYPE_INTERNAL || *type == STORAGE_TYPE_EXTENDED_INTERNAL) return STORAGE_ERROR_INVALID_PARAMETER; + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + ext_dev = calloc(1, sizeof(storage_ext_device)); if (!ext_dev) { //LCOV_EXCL_START System Error -- 2.7.4 From 4faba256021f00663177ceb8dfcc76d4b0347109 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 12 Feb 2019 16:15:10 +0900 Subject: [PATCH 11/16] Return NOT_SUPPORTED error when block module is disabled Change-Id: I5bae529b243b85da8916de94eb6df1186d0a40a9 Signed-off-by: pr.jung --- src/statvfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/statvfs.c b/src/statvfs.c index cf4fb5a..976e1d0 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -333,7 +333,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) else { if (!storage_ext_is_supported()) { _D("Block module is not enabled"); - goto out_nodev; + return STORAGE_ERROR_NOT_SUPPORTED; } ret = get_external_path(ext_path, sizeof(ext_path)); if (ret == -ENODEV) @@ -378,7 +378,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf else { if (!storage_ext_is_supported()) { _D("Block module is not enabled"); - goto out_nodev; + return STORAGE_ERROR_NOT_SUPPORTED; } ret = get_external_path(ext_path, sizeof(ext_path)); if (ret == -ENODEV) -- 2.7.4 From 893a2a428b3c400c78cf9e883a2faec52dc60687 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 13 Feb 2019 16:29:48 +0900 Subject: [PATCH 12/16] Check parameter and return error Change-Id: Id539067762144bfdbf34b1b419d2126f5f8ac76e Signed-off-by: pr.jung --- include/storage-internal.h | 1 + src/storage-inhouse.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/storage-internal.h b/include/storage-internal.h index 609ebf5..a7ac3f8 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -155,6 +155,7 @@ typedef enum { * otherwise a negative error value * * @retval #STORAGE_ERROR_NONE Successful + * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 946b4d8..5a9ca1f 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -429,6 +429,9 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) int ret; bool found = false; + if (!mounted) + return STORAGE_ERROR_INVALID_PARAMETER; + ret = blkid_get_cache(&cache, NULL); if (ret < 0) { _E("Failed to get cache"); //LCOV_EXCL_LINE -- 2.7.4 From 548ae991a1f1dec3d2d4f43c440fe931bcf1e6f6 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 13 Feb 2019 16:43:57 +0900 Subject: [PATCH 13/16] Remove resource leak Change-Id: If9959d9b79061f9c0042a57174a95bdff2898c37 Signed-off-by: pr.jung --- src/storage-inhouse.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 5a9ca1f..2ec6f08 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -266,6 +266,10 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data) ret = storage_get_primary_sdcard(&id, &path); if (ret != STORAGE_ERROR_NONE) return ret; +//LCOV_EXCL_START System Error + if (path) + free(path); +//LCOV_EXCL_STOP ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, @@ -331,6 +335,10 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) ret = storage_get_primary_sdcard(&id, &path); if (ret != STORAGE_ERROR_NONE) return ret; +//LCOV_EXCL_START System Error + if (path) + free(path); +//LCOV_EXCL_STOP ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, @@ -401,6 +409,10 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option) ret = storage_get_primary_sdcard(&id, &path); if (ret != STORAGE_ERROR_NONE) return ret; +//LCOV_EXCL_START System Error + if (path) + free(path); +//LCOV_EXCL_STOP ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, -- 2.7.4 From 194686582f1a68c41607baca6e4311e052f3f9f9 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 15 Feb 2019 17:55:53 +0900 Subject: [PATCH 14/16] Modify the path of external-storage and extended-internal-sd directories Change-Id: I4dfb0d9f9a93f44c0d0adfca59efee4864482073 Signed-off-by: pr.jung --- src/storage-external.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage-external.c b/src/storage-external.c index eb7ec44..3033915 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -28,8 +28,8 @@ #include "log.h" #include "storage-external-dbus.h" -#define EXTERNAL_STORAGE_PATH "/run/external-storage" -#define EXTENDED_INTERNAL_PATH "/run/extended-internal-sd" +#define EXTERNAL_STORAGE_PATH "/run/storaged/external-storage" +#define EXTENDED_INTERNAL_PATH "/run/storaged/extended-internal-sd" #define PATH_LEN 55 #define LUKS_NAME "crypto_LUKS" -- 2.7.4 From fa5e28bf7c9c762dd294cc9beabaf310dc4f23b7 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 23 Jul 2019 16:51:41 +0900 Subject: [PATCH 15/16] Add comment for privacy-related privilege Change-Id: I2187c3930838364ff3afe8364a0ee99a2e4431d7 Signed-off-by: Yunmi Ha --- include/storage-expand.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/storage-expand.h b/include/storage-expand.h index 9cf079b..e519566 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -109,6 +109,7 @@ int storage_foreach_device_supported(storage_device_supported_cb callback, void * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[out] path The absolute path to the storage directory @@ -148,9 +149,9 @@ typedef enum { * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n * The directory path may not exist, so you must make sure that it exists before using it.\n - * If you want to access files or directories in internal storage except #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare http://tizen.org/privilege/mediastorage.\n - * If you want to access files or directories in #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare %http://tizen.org/privilege/systemsettings.\n + * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[in] type The directory type -- 2.7.4 From 6962c4b2b42131604bbc78cf67fe703140868747 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 24 Jul 2019 14:35:55 +0900 Subject: [PATCH 16/16] Change reference page url Change-Id: I3a4217159e4ce9f5981980dd2cc99c71a45c4f01 Signed-off-by: Yunmi Ha --- include/storage-expand.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/storage-expand.h b/include/storage-expand.h index e519566..2be363e 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -109,7 +109,7 @@ int storage_foreach_device_supported(storage_device_supported_cb callback, void * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n - * Refer to Privacy-related Permissions.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[out] path The absolute path to the storage directory @@ -151,7 +151,7 @@ typedef enum { * The directory path may not exist, so you must make sure that it exists before using it.\n * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n - * Refer to Privacy-related Permissions.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[in] type The directory type -- 2.7.4