From 38d52d37ae9cf5f07a4e105e6a05a11eb733740c Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 20 Nov 2018 14:48:47 +0900 Subject: [PATCH] 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