From f56285beeafc8ec250f04fc6e57559c41baef266 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 27 Jun 2018 14:49:14 +0900 Subject: [PATCH 01/16] Change TZ_SYS_HOME to TZ_SYS_USER - TZ_SYS_HOME : "/opt/usr/home" - TZ_SYS_USER: "/opt/usr" Change-Id: I67e1c179d31559d79dc2ff0edf4f8db0f6c82580 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 e920cb6..99ed755 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -234,7 +234,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) return -EINVAL; } - ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp); + 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 @@ -267,7 +267,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) return -EINVAL; } - ret = statvfs(tzplatform_getenv(TZ_SYS_HOME), buf); + 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 -- 2.7.4 From a61e011e03a39091e6f66b21a00f1d9d25e43db6 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 28 Jun 2018 15:00:31 +0900 Subject: [PATCH 02/16] Add .gitignore Change-Id: I71ff3c054b7ac9f8c006841ef683e79decee0796 Signed-off-by: Hyotaek Shim --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9306ae6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cscope.files +cscope.out +tags -- 2.7.4 From ebe8d117ef1e8c593ecd1db932a2931d8aba7b50 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 28 Jun 2018 16:27:54 +0900 Subject: [PATCH 03/16] Modify storage_get_storage_level - Change fist parameter of storage_get_storage_level enum tzplatform_variable -> char * - Remove tzplatform_config.h in storage-internal.h Change-Id: I3f5ac4d6ff47aad5cccce101c7775cb1ce3e0379 Signed-off-by: pr.jung --- include/storage-internal.h | 3 +-- src/storage-external-dbus.c | 15 ++++++++++++++- src/storage-external-dbus.h | 3 +-- src/storage-inhouse.c | 12 ++++++------ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/storage-internal.h b/include/storage-internal.h index 1b14798..53795d2 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -30,7 +30,6 @@ extern "C" { */ #include -#include #include "storage.h" #define STORAGE_ERROR_NO_DEVICE TIZEN_ERROR_NO_SUCH_DEVICE @@ -56,7 +55,7 @@ int storage_get_primary_sdcard(int *storage_id, char **path); int storage_get_compat_internal_path(const char* origin, int len, char* compat); int storage_get_origin_internal_path(const char* compat, int len, char* origin); -int storage_get_storage_level(enum tzplatform_variable id, char **level); +int storage_get_storage_level(const char *path, char **level); /** * @} diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index d335ca7..f070e8f 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "log.h" #include "storage-external-dbus.h" @@ -287,10 +288,22 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) return 0; } -int storage_ext_get_storage_level(enum tzplatform_variable id, char **level) +int storage_ext_get_storage_level(const char *path, char **level) { GVariant *result; char *tmp; + enum tzplatform_variable id; + + if (!strcmp(path, tzplatform_getenv(TZ_SYS_USER))) + id = TZ_SYS_USER; + else if (!strcmp(path, tzplatform_getenv(TZ_SYS_TMP))) + id = TZ_SYS_TMP; + else if (!strcmp(path, tzplatform_getenv(TZ_SYS_OPT))) + id = TZ_SYS_OPT; + else { + _E("Invalid path"); + return -EINVAL; + } result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 24800f8..b71d2e4 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -23,7 +23,6 @@ #include #include #include -#include #include "list.h" #define STORAGE_EXT_BUS_NAME "org.tizen.system.storage" @@ -107,7 +106,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data); void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); -int storage_ext_get_storage_level(enum tzplatform_variable id, char **level); +int storage_ext_get_storage_level(const char *path, char **level); /* storage-internal.c */ GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index d3e30d3..051b6b9 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "common.h" #include "list.h" @@ -180,19 +181,18 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) return STORAGE_ERROR_NONE; } -API int storage_get_storage_level(enum tzplatform_variable id, char **level) +API int storage_get_storage_level(const char *path, char **level) { int ret; - if (!level) + if (!level || !path) return STORAGE_ERROR_INVALID_PARAMETER; - if (id != TZ_SYS_USER || id != TZ_SYS_TMP || id != TZ_SYS_OPT) - return STORAGE_ERROR_INVALID_PARAMETER; - - ret = storage_ext_get_storage_level(id, level); + ret = storage_ext_get_storage_level(path, level); if (ret == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + else if (ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; else if (ret < 0) return STORAGE_ERROR_OPERATION_FAILED; -- 2.7.4 From 4306eaee52ee3fcd853fb2b9f08ce69c8e8e7093 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 3 Jul 2018 11:44:20 +0900 Subject: [PATCH 04/16] Add internal apis to mount/unmount/format primary sdcard - storage_request_mount_mmc - storage_request_unmount_mmc - storage_request_format_mmc - storage_format_mmc Change-Id: I48bef7b586da884d314bbc64a5938e363c7ca00f Signed-off-by: pr.jung --- include/storage-internal.h | 82 +++++++++++++++++++ src/storage-external-dbus.c | 78 ++++++++++++++++++ src/storage-external-dbus.h | 4 + src/storage-inhouse.c | 193 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 357 insertions(+) diff --git a/include/storage-internal.h b/include/storage-internal.h index 53795d2..e3bd50a 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -50,6 +50,8 @@ 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 */ int storage_get_primary_sdcard(int *storage_id, char **path); @@ -58,6 +60,86 @@ int storage_get_origin_internal_path(const char* compat, int len, char* origin); int storage_get_storage_level(const char *path, char **level); /** + * @brief This structure defines the data for receive result of mmc operations(mount/unmount/format) + */ +struct mmc_contents { + void (*mmc_cb) (int result, void* data); /**< user callback function for receive result of mmc operations */ + void* user_data; /**< input data for callback function's second-param(data) */ +}; + +/** + * @brief This API is used to mount mmc.\n + * + * @param[in] mmc_data for receive result of mount operation + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @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 + */ +int storage_request_mount_mmc(struct mmc_contents *mmc_data); + +/** + * @brief This API is used to unmount mmc.\n + * + * @param[in] mmc_data for receive result of unmount operation + * @param[in] option type of unmount option \n + * 0 : Normal unmount \n + * (if other process still access a sdcard, \n + * unmount will be failed.) \n + * 1 : Force unmount \n + * (if other process still access a sdcard, \n + * this process will be received SIGTERM or SIGKILL.) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @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 + */ +int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option); + +/** + * @brief This API is used to format mmc.\n + * + * @param[in] mmc_data for receive result of format operation + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @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 + */ +int storage_request_format_mmc(struct mmc_contents *mmc_data); + +/** + * @brief This API is used to format mmc.\n + * + * @param[in] mmc_data for receive result of format operation + * @param[in] option FMT_NORMAL is 0, FMT_FORCE is 1 + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @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 + */ +int storage_format_mmc(struct mmc_contents *mmc_data, int option); + +/** * @} */ diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index f070e8f..5d45189 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -51,6 +51,11 @@ struct storage_ext_callback { guint block_id; }; +typedef struct { + dbus_pending_cb func; + void *data; +} pending_call_data; + static dd_list *changed_list; static void storage_ext_release_internal(storage_ext_device *dev) @@ -118,6 +123,79 @@ static GDBusConnection *get_dbus_connection(void) return conn; } +static void _cb_pending(GDBusConnection *conn, + GAsyncResult *res, + gpointer user_data) +{ + GVariant *reply = NULL; + GError *err = NULL; + pending_call_data *data = (pending_call_data *)user_data; + + reply = g_dbus_connection_call_finish(conn, res, &err); + if (!reply || err) { + if (!err) + g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED, + "Error during g_dbus_connection_call"); + + if (data && data->func) + data->func(NULL, data->data, err); + goto out; + } + + if (data && data->func) + data->func(reply, data->data, err); +out: + if (err) + g_error_free(err); + if (data) + free(data); +} + +int dbus_method_async_with_reply_var(const char *dest, const char *path, + const char *iface, const char *method, GVariant *param, + dbus_pending_cb cb, int timeout, void *data) +{ + GDBusConnection *conn; + pending_call_data *pdata = NULL; + int ret = 0; + + if (!dest || !path || !iface || !method) + return -EINVAL; + + if (timeout < -1) { + _E("wrong timeout %d", timeout); + return -EINVAL; + } + + conn = get_dbus_connection(); + if (!conn) { + _E("fail to get dbus connection"); //LCOV_EXCL_LINE + return -1; + } + + if (cb) { + pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); + if (!pdata) { + ret = -ENOMEM; + goto err; + } + + pdata->func = cb; + pdata->data = data; + } + + g_dbus_connection_call(conn, dest, path, iface, method, + param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, + (GAsyncReadyCallback)_cb_pending, + pdata); + + return ret; +err: + if (param) + g_variant_unref(param); + return ret; +} + GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, const gchar *iface, const gchar *method, GVariant *param) { diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index b71d2e4..273e388 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -108,6 +108,10 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); int storage_ext_get_storage_level(const char *path, char **level); +typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err); +int dbus_method_async_with_reply_var(const char *dest, const char *path, + const char *iface, const char *method, GVariant *param, + dbus_pending_cb cb, int timeout, void *data); /* storage-internal.c */ GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, const gchar *iface, const gchar *method, GVariant *param); diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 051b6b9..d5ed6b5 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -27,6 +27,8 @@ #include "storage-internal.h" #include "storage-external-dbus.h" +#define FORMAT_TIMEOUT (120*1000) + /* Get compat path from origin Multi-user path from TZ_USER_CONTENT/.. to /opt/usr/media/.. @@ -198,3 +200,194 @@ API int storage_get_storage_level(const char *path, char **level) return STORAGE_ERROR_NONE; } + +static void mount_mmc_cb(GVariant *var, void *user_data, GError *err) +{ + struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; + int mmc_ret = -1; + + _D("mount_mmc_cb called"); + + if (!var) { + _E("no message [%s]", err->message); + mmc_ret = -EBADMSG; + goto exit; + } + + g_variant_get(var, "(i)", &mmc_ret); + + _I("Mount State : %d", mmc_ret); + +exit: + if (var) + g_variant_unref(var); + (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); +} + +API int storage_request_mount_mmc(struct mmc_contents *mmc_data) +{ + void (*mount_cb)(GVariant *, void *, GError *) = NULL; + void *data = NULL; + char *path; + int ret; + int id; + + if (mmc_data && mmc_data->mmc_cb) { + _I("Mount callback exists"); + mount_cb = mount_mmc_cb; + data = mmc_data; + } + + ret = storage_get_primary_sdcard(&id, &path); + if (ret != STORAGE_ERROR_NONE) + return ret; + + ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "Mount", + g_variant_new("(is)", id, ""), + mount_cb, + -1, + data); + + _I("Mount Request %s", ret == 0 ? "Success" : "Failed"); + + if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + if (ret < 0) + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + + return STORAGE_ERROR_NONE; +} + +static void unmount_mmc_cb(GVariant *var, void *user_data, GError *err) +{ + struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; + int mmc_ret; + + _D("unmount_mmc_cb called"); + + if (!var) { + _E("no message [%s]", err->message); + mmc_ret = -EBADMSG; + goto exit; + } + + g_variant_get(var, "(i)", &mmc_ret); + + _I("Unmount State : %d", mmc_ret); + +exit: + if (var) + g_variant_unref(var); + (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); +} + +API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) +{ + void (*unmount_cb)(GVariant *, void *, GError *) = NULL; + void *data = NULL; + char *path; + int ret; + int id; + + if (option < 0 || option > 1) + return STORAGE_ERROR_INVALID_PARAMETER; + + if (mmc_data && mmc_data->mmc_cb) { + _I("Unmount callback exists"); + unmount_cb = unmount_mmc_cb; + data = mmc_data; + } + + ret = storage_get_primary_sdcard(&id, &path); + if (ret != STORAGE_ERROR_NONE) + return ret; + + ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "Unmount", + g_variant_new("(ii)", id, option), + unmount_cb, + -1, + data); + + _I("Unmount Request %s", ret == 0 ? "Success" : "Failed"); + + if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + if (ret < 0) + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + + return STORAGE_ERROR_NONE; +} + +static void format_mmc_cb(GVariant *var, void *user_data, GError *err) +{ + struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; + int mmc_ret; + + _D("format_mmc_cb called"); + + if (!var) { + _E("no message [%s]", err->message); + mmc_ret = -EBADMSG; + goto exit; + } + + g_variant_get(var, "(i)", &mmc_ret); + + _I("Format State : %d", mmc_ret); + +exit: + if (var) + g_variant_unref(var); + (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); +} + +API int storage_request_format_mmc(struct mmc_contents *mmc_data) +{ + return storage_format_mmc(mmc_data, 1); +} + +API int storage_format_mmc(struct mmc_contents *mmc_data, int option) +{ + void (*format_cb)(GVariant *, void *, GError *) = NULL; + void *data = NULL; + char *path; + int ret; + int id; + + if (option < 0 || option > 1) + return STORAGE_ERROR_INVALID_PARAMETER; + + if (mmc_data && mmc_data->mmc_cb) { + _I("Format callback exists"); + format_cb = format_mmc_cb; + data = mmc_data; + } + + ret = storage_get_primary_sdcard(&id, &path); + if (ret != STORAGE_ERROR_NONE) + return ret; + + ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "Format", + g_variant_new("(ii)", id, option), + format_cb, + FORMAT_TIMEOUT, + data); + + _I("Format Request %s", ret == 0 ? "Success" : "Failed"); + + if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + if (ret < 0) + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + + return STORAGE_ERROR_NONE; +} -- 2.7.4 From 924ade1b560e5798eb261dc1187df77eaa8f3410 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 12 Jul 2018 13:29:48 +0900 Subject: [PATCH 05/16] Check block module enabled before sending GetMmcPrimary dbus method Change-Id: I2634ba2130c35f7c3ccca9e8164ac9c73a9d47a3 Signed-off-by: pr.jung --- include/common.h | 1 + src/storage-common.c | 20 +++++++++++++++++++- src/storage-inhouse.c | 3 +++ src/storage.c | 16 ---------------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/common.h b/include/common.h index f208338..dd6f966 100644 --- a/include/common.h +++ b/include/common.h @@ -84,6 +84,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); #ifdef __cplusplus } diff --git a/src/storage-common.c b/src/storage-common.c index ba76cc8..ea8e174 100644 --- a/src/storage-common.c +++ b/src/storage-common.c @@ -16,10 +16,12 @@ * limitations under the License. */ - +#include #include #include "common.h" +#define BLOCK_CONF_FILE "/etc/storaged/block.conf" + int is_compat_bind_mount(void) { struct libmnt_table *t = NULL; @@ -50,3 +52,19 @@ int is_compat_bind_mount(void) return 0; //LCOV_EXCL_STOP } + +int storage_ext_is_supported(void) +{ + static int support = -1; + + if (support >= 0) + return support; + + if (access(BLOCK_CONF_FILE, R_OK) == 0) + support = 1; + else + support = 0; + + return support; +} + diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index d5ed6b5..2023a56 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -149,6 +149,9 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) if (!storage_id || !path) return STORAGE_ERROR_INVALID_PARAMETER; + if (!storage_ext_is_supported()) + return STORAGE_ERROR_NO_DEVICE; + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, diff --git a/src/storage.c b/src/storage.c index 9a45507..6dfef6d 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,7 +27,6 @@ #include "log.h" #include "storage-external.h" -#define BLOCK_CONF_FILE "/etc/storaged/block.conf" #define USER_UID_START 5000 const char *dir_path[STORAGE_DIRECTORY_MAX]; @@ -61,21 +60,6 @@ void remove_device(const struct storage_ops *st) DD_LIST_REMOVE(st_int_head, st); } -int storage_ext_is_supported(void) -{ - static int support = -1; - - if (support >= 0) - return support; - - if (access(BLOCK_CONF_FILE, R_OK) == 0) - support = 1; - else - support = 0; - - return support; -} - API int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data) { const struct storage_ops *st; -- 2.7.4 From d719c4229080290e5000e3d51b7f69cd8c54543f Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 19 Jul 2018 11:16:24 +0900 Subject: [PATCH 06/16] Change internal storage media path returned from storage_get_directory() (Before) /opt/usr/media/XXX (After) /opt/usr/home/USER/media/XXX /opt/usr/media bind-mounted by /opt/usr/home/USER/media is workaround for supporting legacy Tizen applications based on /opt/usr/media hard coding. Strictly, public apis do not need to use legacy path (/opt/usr/media). Change-Id: Ida39777ac40587719beb8d28b8f04172c98900e5 Signed-off-by: Hyotaek Shim --- src/storage-internal.c | 8 +++----- src/storage.c | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/storage-internal.c b/src/storage-internal.c index 7f5d359..0dadec9 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -15,6 +15,8 @@ */ +#include +#include #include #include #include @@ -61,11 +63,7 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava static const char *internal_get_root(void) { const char *ret; - - if (is_compat_bind_mount()) - ret = COMPAT_DIR; - else - ret = tzplatform_getenv(TZ_USER_CONTENT); + ret = tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT); return ret; } diff --git a/src/storage.c b/src/storage.c index 6dfef6d..b0d6465 100644 --- a/src/storage.c +++ b/src/storage.c @@ -72,7 +72,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v return STORAGE_ERROR_INVALID_PARAMETER; } - if (getuid() < USER_UID_START) + if (getuid() <= USER_UID_START) user = false; DD_LIST_FOREACH(st_int_head, elem, st) { @@ -116,7 +116,7 @@ API int storage_get_root_directory(int storage_id, char **path) return STORAGE_ERROR_INVALID_PARAMETER; } - if (getuid() < USER_UID_START) + if (getuid() <= USER_UID_START) user = false; /* internal storage */ @@ -124,8 +124,8 @@ API int storage_get_root_directory(int storage_id, char **path) if (st->storage_id != storage_id) continue; if (!user) { - _E("Only Tizen applications and user session daemons can use \ - storage_get_root_directory(id , ...)"); + _E("Only Tizen applications and user session daemons can use\ + storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -189,13 +189,13 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p break; } - if (getuid() < USER_UID_START) + if (getuid() <= USER_UID_START) user = false; if (found && st) { if (!user) { - _E("Only Tizen applications and user session daemons can use \ - storage_get_directory(id, ...)"); + _E("Only Tizen applications and user session daemons can use\ + storage_get_directory(INTERNAL_STORAGE_ID, ...)"); return STORAGE_ERROR_INVALID_PARAMETER; } -- 2.7.4 From 5c437ddef63be7a6aa22966f7da70b3380441294 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 20 Jul 2018 10:57:16 +0900 Subject: [PATCH 07/16] Minor fixes: comments, license .. Change-Id: I09d102eae0b5990057c0492f52d5155243deff24 Signed-off-by: Hyotaek Shim --- LICENSE => LICENSE.Apache-2.0 | 0 packaging/libstorage.spec | 5 ++--- src/storage.c | 9 +++++---- 3 files changed, 7 insertions(+), 7 deletions(-) rename LICENSE => LICENSE.Apache-2.0 (100%) diff --git a/LICENSE b/LICENSE.Apache-2.0 similarity index 100% rename from LICENSE rename to LICENSE.Apache-2.0 diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 57611e7..f050da4 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -1,6 +1,6 @@ Name: libstorage Summary: Library to get storage information -Version: 0.1.1 +Version: 1.0.0 Release: 0 Group: System/Libraries License: Apache-2.0 @@ -26,7 +26,6 @@ Requires: %{name} = %{version}-%{release} %description devel Library to get storage information (devel) - %prep %setup -q cp %{SOURCE1} . @@ -45,7 +44,7 @@ make %{?jobs:-j%jobs} %files %{_libdir}/*.so.* %{_sysconfdir}/storage/libstorage.conf -%license LICENSE +%license LICENSE.Apache-2.0 %manifest %{name}.manifest %files devel diff --git a/src/storage.c b/src/storage.c index b0d6465..5272b57 100644 --- a/src/storage.c +++ b/src/storage.c @@ -124,8 +124,8 @@ API int storage_get_root_directory(int storage_id, char **path) if (st->storage_id != storage_id) continue; if (!user) { - _E("Only Tizen applications and user session daemons can use\ - storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); + _E("Only apps and user session daemons are allowed " + "to use storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -194,8 +194,9 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p if (found && st) { if (!user) { - _E("Only Tizen applications and user session daemons can use\ - storage_get_directory(INTERNAL_STORAGE_ID, ...)"); + _E("Only apps and user session daemons are allowed " + "to use storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); + return STORAGE_ERROR_INVALID_PARAMETER; } -- 2.7.4 From 22ecb430332ba5660624ecc9cfc36ac7f84e8fcc Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 23 Jul 2018 15:52:22 +0900 Subject: [PATCH 08/16] Change tzplatform_getenv to tzplatform_uid_getenv - Cover multi-user case Change-Id: I82cb6a0621ca1e87ae4009d7797cdd963ebf57a6 Signed-off-by: pr.jung --- include/common.h | 2 ++ src/storage-inhouse.c | 22 ++++++++++++++++++++-- src/storage.c | 2 -- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/common.h b/include/common.h index dd6f966..0e8f4a7 100644 --- a/include/common.h +++ b/include/common.h @@ -86,6 +86,8 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf int is_compat_bind_mount(void); int storage_ext_is_supported(void); +#define USER_UID_START 5000 + #ifdef __cplusplus } #endif diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 2023a56..3c36f58 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -15,6 +15,8 @@ */ +#include +#include #include #include #include @@ -60,6 +62,14 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp return -1; } + if (getuid() <= USER_UID_START) { + //LCOV_EXCL_START System Error + _E("Only apps and user session daemons are allowed " + "to use storage_get_compat_internal_path()"); + return -1; + //LCOV_EXCL_STOP + } + // this API works on place where compat path is bind-mounted if (!is_compat_bind_mount()) { //LCOV_EXCL_START System Error @@ -68,7 +78,7 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp //LCOV_EXCL_STOP } - str = tzplatform_getenv(TZ_USER_CONTENT); + str = tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT); str_len = strlen(str); if (strncmp(origin, str, str_len) != 0) { _E("Failed to match TZ_USER_CONTENT"); @@ -116,6 +126,14 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig return -1; } + if (getuid() <= USER_UID_START) { + //LCOV_EXCL_START System Error + _E("Only apps and user session daemons are allowed " + "to use storage_get_origin_internal_path()"); + return -1; + //LCOV_EXCL_STOP + } + // this API works on place where compat path is bind-mounted if (!is_compat_bind_mount()) { //LCOV_EXCL_START System Error @@ -130,7 +148,7 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig return -1; } - r = snprintf(origin, len, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), compat + compat_len); + r = snprintf(origin, len, "%s%s", tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT), compat + compat_len); if (r < 0) { //LCOV_EXCL_START System Error _E("failed to create new path"); diff --git a/src/storage.c b/src/storage.c index 5272b57..4e178f5 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,8 +27,6 @@ #include "log.h" #include "storage-external.h" -#define USER_UID_START 5000 - const char *dir_path[STORAGE_DIRECTORY_MAX]; const int tz_id[STORAGE_DIRECTORY_MAX] = { -- 2.7.4 From f508857ecc798a8634ba5e97968c1c987c4a6e39 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 26 Jul 2018 18:09:28 +0900 Subject: [PATCH 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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