From 1e01e45514db486e6ae3191b00ef1b2b29b827e9 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 20 May 2016 17:21:46 +0900 Subject: [PATCH 01/16] Devide dbus connection of block from other deviced modules Change-Id: Ibcb3c2c1a1899ce74663a6633be50c67870c5906 Signed-off-by: pr.jung --- src/storage-external-dbus.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index e9db898..d279c65 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -25,8 +25,8 @@ #include #include "list.h" -#define STORAGE_EXT_BUS_NAME "org.tizen.system.deviced" -#define STORAGE_EXT_PATH "/Org/Tizen/System/DeviceD/Block" +#define STORAGE_EXT_BUS_NAME "org.tizen.system.storage" +#define STORAGE_EXT_PATH "/Org/Tizen/System/Storage/Block" #define STORAGE_EXT_PATH_DEVICES STORAGE_EXT_PATH"/Devices" #define STORAGE_EXT_PATH_MANAGER STORAGE_EXT_PATH"/Manager" #define STORAGE_EXT_IFACE STORAGE_EXT_BUS_NAME".Block" -- 2.7.4 From 439c578510d5cca23a9b3488cf0bc4a27fd100a8 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 24 May 2016 16:34:34 +0900 Subject: [PATCH 02/16] Add comments for line/function coverage analysis - Remove system error, not called callback and logs. - Drops the exclusion reason for Logs Change-Id: Iaf43a37cfd62be23bd9799feac7c64fc6161edbe Signed-off-by: pr.jung --- src/statvfs.c | 16 ++++++++-------- src/storage-external-dbus.c | 32 ++++++++++++++++++++++++++++---- src/storage-external.c | 26 +++++++++++++++++--------- src/storage.c | 24 +++++++++++++----------- 4 files changed, 66 insertions(+), 32 deletions(-) diff --git a/src/statvfs.c b/src/statvfs.c index dd038af..80984d1 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -112,7 +112,7 @@ static int config_parse(const char *file_name, int cb(struct parse_result *resul /* open conf file */ f = fopen(file_name, "r"); if (!f) { - _E("Failed to open file %s", file_name); + _E("Failed to open file %s", file_name); //LCOV_EXCL_LINE ret = -EIO; goto error; } @@ -172,7 +172,7 @@ static int config_parse(const char *file_name, int cb(struct parse_result *resul error: if (f) fclose(f); - _E("Failed to read %s:%d!", file_name, lineno); + _E("Failed to read %s:%d!", file_name, lineno); //LCOV_EXCL_LINE return ret; } @@ -210,7 +210,7 @@ static void storage_config_load(struct storage_config_info *info) ret = config_parse(STORAGE_CONF_FILE, load_config, info); if (ret < 0) - _E("Failed to load %s, %d Use default value!", STORAGE_CONF_FILE, ret); + _E("Failed to load %s, %d Use default value!", STORAGE_CONF_FILE, ret); //LCOV_EXCL_LINE } static int get_memory_size(const char *path, struct statvfs_32 *buf) @@ -254,7 +254,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp); if (ret || temp.f_bsize == 0) { - _E("fail to get memory size"); + _E("fail to get memory size"); //LCOV_EXCL_LINE return -errno; } @@ -281,13 +281,13 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) int ret; if (!buf) { - _E("input param error"); + _E("input param error"); //LCOV_EXCL_LINE return -EINVAL; } ret = statvfs(tzplatform_getenv(TZ_SYS_HOME), buf); if (ret) { - _E("fail to get memory size"); + _E("fail to get memory size"); //LCOV_EXCL_LINE return -errno; } @@ -350,7 +350,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) if (ret == -ENODEV) goto out_nodev; if (ret < 0) { - _E("Failed to get external path(%d)", ret); + _E("Failed to get external path(%d)", ret); //LCOV_EXCL_LINE return ret; } } @@ -360,7 +360,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) ret = get_memory_size(ext_path, &temp); if (ret) { - _E("fail to get memory size"); + _E("fail to get memory size"); //LCOV_EXCL_LINE return -errno; } diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 2d86e3c..60a439e 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -103,12 +103,14 @@ static GDBusConnection *get_dbus_connection(void) conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); if (!conn) { +//LCOV_EXCL_START System Error if (err) { _E("fail to get dbus connection : %s", err->message); g_clear_error(&err); } else _E("fail to get dbus connection"); return NULL; +//LCOV_EXCL_STOP } return conn; } @@ -125,7 +127,7 @@ static GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, conn = get_dbus_connection(); if (!conn) { - _E("fail to get dbus connection"); + _E("fail to get dbus connection"); //LCOV_EXCL_LINE return NULL; } @@ -134,12 +136,14 @@ static GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); if (!ret) { +//LCOV_EXCL_START System Error if (err) { _E("dbus method sync call failed(%s)", err->message); g_clear_error(&err); } else _E("g_dbus_connection_call_sync() failed"); return NULL; +//LCOV_EXCL_STOP } return ret; @@ -161,7 +165,7 @@ int storage_ext_get_list(dd_list **list) STORAGE_EXT_GET_LIST, g_variant_new("(s)", "all")); if (!result) { - _E("Failed to get storage_ext device info"); + _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE return -EIO; } @@ -177,7 +181,7 @@ int storage_ext_get_list(dd_list **list) elem = (storage_ext_device *)malloc(sizeof(storage_ext_device)); if (!elem) { - _E("malloc() failed"); + _E("malloc() failed"); //LCOV_EXCL_LINE ret = -ENOMEM; goto out; } @@ -209,6 +213,7 @@ out: return ret; } +//LCOV_EXCL_START Not called Callback static char *get_devnode_from_path(char *path) { if (!path) @@ -216,7 +221,9 @@ static char *get_devnode_from_path(char *path) /* 1 means '/' */ return path + strlen(STORAGE_EXT_PATH_DEVICES) + 1; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Not called Callback static void storage_ext_object_path_changed(enum storage_ext_state state, GVariant *params, gpointer user_data) { @@ -261,17 +268,23 @@ out: } free(path); } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Not called Callback static void storage_ext_device_added(GVariant *params, gpointer user_data) { storage_ext_object_path_changed(STORAGE_EXT_ADDED, params, user_data); } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Not called Callback static void storage_ext_device_removed(GVariant *params, gpointer user_data) { storage_ext_object_path_changed(STORAGE_EXT_REMOVED, params, user_data); } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Not called Callback static void storage_ext_device_changed(GVariant *params, gpointer user_data) { storage_ext_device *dev; @@ -311,7 +324,9 @@ static void storage_ext_device_changed(GVariant *params, gpointer user_data) storage_ext_release_device(&dev); } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Not called Callback static void storage_ext_changed(GDBusConnection *conn, const gchar *sender, const gchar *path, @@ -342,6 +357,7 @@ static void storage_ext_changed(GDBusConnection *conn, return; } } +//LCOV_EXCL_STOP int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) { @@ -364,15 +380,19 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) callback = (struct storage_ext_callback *)malloc(sizeof(struct storage_ext_callback)); if (!callback) { +//LCOV_EXCL_START System Error _E("malloc() failed"); return -ENOMEM; +//LCOV_EXCL_STOP } conn = get_dbus_connection(); if (!conn) { +//LCOV_EXCL_START System Error free(callback); _E("Failed to get dbus connection"); return -EPERM; +//LCOV_EXCL_STOP } block_id = g_dbus_connection_signal_subscribe(conn, @@ -402,9 +422,11 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) NULL, NULL); if (blockmanager_id == 0) { +//LCOV_EXCL_START System Error free(callback); _E("Failed to subscrive bus signal"); return -EPERM; +//LCOV_EXCL_STOP } callback->func = func; @@ -428,8 +450,10 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) conn = get_dbus_connection(); if (!conn) { +//LCOV_EXCL_START System Error _E("fail to get dbus connection"); return; +//LCOV_EXCL_STOP } DD_LIST_FOREACH(changed_list, elem, callback) { @@ -455,7 +479,7 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) "GetDeviceInfoByID", g_variant_new("(i)", storage_id)); if (!result) { - _E("There is no storage with the storage id (%d)", storage_id); + _E("There is no storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE return -ENODEV; } diff --git a/src/storage-external.c b/src/storage-external.c index bd9a8e1..c23153d 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -74,19 +74,21 @@ int storage_ext_get_space(int storage_id, dev = calloc(1, sizeof(storage_ext_device)); if (!dev) { +//LCOV_EXCL_START System Error _E("calloc failed"); return -ENOMEM; +//LCOV_EXCL_STOP } ret = storage_ext_get_device_info(storage_id, dev); if (ret < 0) { - _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); + _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE goto out; } ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, &state); if (ret < 0) { - _E("Failed to get state of storage (id:%d, ret:%d)", storage_id, ret); + _E("Failed to get state of storage (id:%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE goto out; } @@ -97,7 +99,7 @@ int storage_ext_get_space(int storage_id, ret = storage_get_external_memory_size64_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); + _E("Failed to get external memory size of (%s)(ret:%d)", dev->mount_point, ret); //LCOV_EXCL_LINE goto out; } @@ -129,14 +131,14 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * ret = storage_ext_get_list(&list); if (ret < 0) { - _E("Failed to get external storage list from deviced (%d)", errno); + _E("Failed to get external storage list from deviced (%d)", errno); //LCOV_EXCL_LINE return ret; } DD_LIST_FOREACH(list, elem, dev) { ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, &state); if (ret < 0) { - _E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); + _E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); //LCOV_EXCL_LINE continue; } @@ -151,6 +153,7 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * return 0; } +//LCOV_EXCL_START Not called Callback static int storage_ext_state_changed(storage_ext_device *dev, enum storage_ext_state blk_state, void *data) { enum storage_cb_type type = (enum storage_cb_type)data; @@ -176,6 +179,7 @@ static int storage_ext_state_changed(storage_ext_device *dev, enum storage_ext_s return 0; } +//LCOV_EXCL_STOP int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info) { @@ -262,13 +266,15 @@ int storage_ext_get_root(int storage_id, char *path, size_t len) dev = calloc(1, sizeof(storage_ext_device)); if (!dev) { +//LCOV_EXCL_START System Error _E("calloc failed"); return -ENOMEM; +//LCOV_EXCL_STOP } ret = storage_ext_get_device_info(storage_id, dev); if (ret < 0) { - _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); + _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE goto out; } @@ -293,19 +299,21 @@ int storage_ext_get_state(int storage_id, storage_state_e *state) dev = calloc(1, sizeof(storage_ext_device)); if (!dev) { +//LCOV_EXCL_START System Error _E("calloc failed"); return -ENOMEM; +//LCOV_EXCL_STOP } ret = storage_ext_get_device_info(storage_id, dev); if (ret < 0) { - _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); + _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE goto out; } ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, state); if (ret < 0) - _E("Failed to get state of storage id (%d, ret:%d)", storage_id, ret); + _E("Failed to get state of storage id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE out: storage_ext_release_device(&dev); @@ -320,7 +328,7 @@ int storage_ext_get_primary_mmc_path(char *path, size_t len) ret = storage_ext_get_list(&list); if (ret < 0) { - _E("Failed to get external storage list from deviced (%d)", errno); + _E("Failed to get external storage list from deviced (%d)", errno); //LCOV_EXCL_LINE return ret; } diff --git a/src/storage.c b/src/storage.c index b98fded..c8cfc11 100644 --- a/src/storage.c +++ b/src/storage.c @@ -71,7 +71,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v ret = storage_ext_foreach_device_list(callback, user_data); if (ret < 0) { - _E("Failed to iterate external devices (%d)", ret); + _E("Failed to iterate external devices (%d)", ret); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -99,8 +99,10 @@ API int storage_get_root_directory(int storage_id, char **path) continue; *path = strdup(st->root()); if (!*path) { +//LCOV_EXCL_START System Error _E("Failed to copy the root string : %d", errno); return STORAGE_ERROR_OUT_OF_MEMORY; +//LCOV_EXCL_STOP } return STORAGE_ERROR_NONE; } @@ -108,7 +110,7 @@ API int storage_get_root_directory(int storage_id, char **path) /* external storage */ ret = storage_ext_get_root(storage_id, root, sizeof(root)); if (ret < 0) { - _E("Failed to get root path of external storage(%d, %d", storage_id, ret); + _E("Failed to get root path of external storage(%d, %d", storage_id, ret); //LCOV_EXCL_LINE return STORAGE_ERROR_INVALID_PARAMETER; } @@ -158,7 +160,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) { ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &temp2); if (ret < 0) { - _E("Failed to get ringtone path : %d", ret); + _E("Failed to get ringtone path : %d", ret); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } end = strrchr(temp2, '/'); @@ -174,13 +176,13 @@ 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); + _E("Not support directory : id(%d) type(%d)", storage_id, type); //LCOV_EXCL_LINE return STORAGE_ERROR_NOT_SUPPORTED; } ret = storage_ext_get_root(storage_id, root, sizeof(root)); if (ret < 0) { - _E("Failed to get root dir for external storage(id:%d, ret:%d)", storage_id, ret); + _E("Failed to get root dir for external storage(id:%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -189,7 +191,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p out: *path = strdup(temp); if (!*path) { - _E("Failed to copy the directory(%d) string : %d", type, errno); + _E("Failed to copy the directory(%d) string : %d", type, errno); //LCOV_EXCL_LINE return STORAGE_ERROR_OUT_OF_MEMORY; } @@ -249,7 +251,7 @@ API int storage_get_state(int storage_id, storage_state_e *state) /* external storage */ ret = storage_ext_get_state(storage_id, &st); if (ret < 0) { - _E("Failed to get state (storage id(%d), ret(%d))", storage_id, ret); + _E("Failed to get state (storage id(%d), ret(%d))", storage_id, ret); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -284,7 +286,7 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca ret = storage_ext_register_cb(STORAGE_CALLBACK_STATE, &info); if (ret < 0) { - _E("Failed to register callback : id(%d)", storage_id); + _E("Failed to register callback : id(%d)", storage_id); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -317,7 +319,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb ret = storage_ext_unregister_cb(STORAGE_CALLBACK_STATE, &info); if (ret < 0) { - _E("Failed to unregister callback : id(%d)", storage_id); + _E("Failed to unregister callback : id(%d)", storage_id); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -352,7 +354,7 @@ 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); + _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; @@ -390,7 +392,7 @@ 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); + _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; -- 2.7.4 From beb1dca036d038def39efb82373a11c3ab3f0988 Mon Sep 17 00:00:00 2001 From: "sunm.lee" Date: Wed, 25 May 2016 14:37:36 +0900 Subject: [PATCH 03/16] storage.c: Apply Tizen coding rule Apply Tizen coding rule. Change-Id: I1fe0ed420d8ee936451a87fc189437ed6666008f Signed-off-by: sunm.lee --- src/storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage.c b/src/storage.c index c8cfc11..be647ca 100644 --- a/src/storage.c +++ b/src/storage.c @@ -388,7 +388,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) } /* external storage */ - ret = storage_ext_get_space(storage_id,NULL, &avail); + ret = storage_ext_get_space(storage_id, NULL, &avail); out: if (ret < 0) { -- 2.7.4 From e8821fefeb67d6cfcbc203ff40112a455be576ca Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Mon, 13 Jun 2016 14:58:08 +0900 Subject: [PATCH 04/16] api: add new api to register insert/remove callback - Previously, storage event register apis get the storage ID by the input parameter. Storage IDs are created when storages are connected, and storage IDs are changed even if same storage is re-connected. Thus Previous apis cannot support "insert" event. - Now, new apis are added. They get storage type to register events. Thus they can support "insert" event too. = int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data); = int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback); Change-Id: Icbc6513f2777f8df760365c5c65512714b295590 Signed-off-by: taeyoung --- include/common.h | 5 +- include/storage-expand.h | 91 +++++++++++++++++++++++--- src/storage-external-dbus.c | 133 ++++++-------------------------------- src/storage-external.c | 151 ++++++++++++++++++++++++++++++++++++-------- src/storage.c | 71 ++++++++++++++++++++- 5 files changed, 300 insertions(+), 151 deletions(-) diff --git a/include/common.h b/include/common.h index ec9ca67..a819ecc 100644 --- a/include/common.h +++ b/include/common.h @@ -43,13 +43,16 @@ extern "C" { #endif enum storage_cb_type { - STORAGE_CALLBACK_STATE, + STORAGE_CALLBACK_ID, + STORAGE_CALLBACK_TYPE, STORAGE_CALLBACK_MAX, }; struct storage_cb_info { int id; + storage_type_e type; storage_state_changed_cb state_cb; + storage_changed_cb type_cb; void *user_data; }; diff --git a/include/storage-expand.h b/include/storage-expand.h index c7b67a1..f0e5382 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -108,12 +108,11 @@ int storage_foreach_device_supported(storage_device_supported_cb callback, void /** * @brief Gets the absolute path to the root directory of the given storage. - * @details Files saved on the internal/external storage are readable or writeable by all applications. - * When an application is uninstalled, the files written by that application are not removed from the internal/external storage. - * * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * - * @remarks If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n + * @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 + * 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 * You must release @a path using free(). * @@ -151,12 +150,11 @@ typedef enum { /** * @brief Gets the absolute path to the each directory of the given storage. - * @details Files saved on the internal/external storage are readable or writeable by all applications. - * When an application is uninstalled, the files written by that application are not removed from the internal/external storage. - * * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * - * @remarks The directory path may not exist, so you must make sure that it exists before using it.\n + * @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 external storage, you must declare http://tizen.org/privilege/externalstorage.\n @@ -276,6 +274,83 @@ int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callba int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb callback); /** + * @brief Enumeration of storage device types + * @since_tizen 3.0 + */ +typedef enum { + STORAGE_DEV_EXT_SDCARD = 1001, /**< sdcard device (external storage) */ + STORAGE_DEV_EXT_USB_MASS_STORAGE, /**< USB storage device (external storage) */ +} storage_dev_e; + +/** + * @brief Called when the state of a storage type changes. + * + * @since_tizen 3.0 + * + * @param[in] storage_id The unique storage ID + * @param[in] type The type of the storage device + * @param[in] state The state of the storage + * @param[in] fstype The type of the file system + * @param[in] fsuuid The uuid of the file system + * @param[in] mountpath The mount path of the file system + * @param[in] primary The primary partition + * @param[in] flags The flags for the storage status + * @param[in] user_data The user data + * + * @pre storage_set_changed_cb() will invoke this callback function. + * @see storage_set_changed_cb() + * @see storage_unset_changed_cb() + */ +typedef void (*storage_changed_cb)(int storage_id, + storage_dev_e dev, storage_state_e state, + const char *fstype, const char *fsuuid, const char *mountpath, + bool primary, int flags, void *user_data); + +/** + * @brief Registers a callback function to be invoked when the state of the specified storage device type changes. + * + * @since_tizen 3.0 + * + * @param[in] type The type of the storage device + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @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_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * + * @post storage_changed_cb() will be invoked if the state of the registered storage type changes. + * @see storage_changed_cb() + * @see storage_unset_changed_cb() + */ +int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data); + +/** + * @brief Unregisters the callback function for storage type state changes. + * + * @since_tizen 3.0 + * + * @param[in] type The type of the the storage device + * @param[in] callback The callback function to unregister + * + * @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_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * + * @see storage_changed_cb() + * @see storage_set_changed_cb() + */ +int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback); + +/** * @brief Gets the total space of the given storage in bytes. * * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 60a439e..2793e40 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -33,19 +33,16 @@ #define STORAGE_EXT_GET_LIST "GetDeviceList" -#define STORAGE_EXT_OBJECT_ADDED "ObjectAdded" -#define STORAGE_EXT_OBJECT_REMOVED "ObjectRemoved" #define STORAGE_EXT_DEVICE_CHANGED "DeviceChanged" +#define STORAGE_EXT_DEVICE_ADDED "DeviceAdded" +#define STORAGE_EXT_DEVICE_REMOVED "DeviceRemoved" #define DBUS_REPLY_TIMEOUT (-1) -#define DEV_PREFIX "/dev/" - struct storage_ext_callback { storage_ext_changed_cb func; void *data; guint block_id; - guint blockmanager_id; }; static dd_list *changed_list; @@ -214,78 +211,7 @@ out: } //LCOV_EXCL_START Not called Callback -static char *get_devnode_from_path(char *path) -{ - if (!path) - return NULL; - /* 1 means '/' */ - return path + strlen(STORAGE_EXT_PATH_DEVICES) + 1; -} -//LCOV_EXCL_STOP - -//LCOV_EXCL_START Not called Callback -static void storage_ext_object_path_changed(enum storage_ext_state state, - GVariant *params, gpointer user_data) -{ - storage_ext_device *dev = NULL; - dd_list *elem; - struct storage_ext_callback *callback; - char *path = NULL; - char *devnode; - int ret; - - if (!params) - return; - - g_variant_get(params, "(s)", &path); - - devnode = get_devnode_from_path(path); - if (!devnode) - goto out; - - dev = calloc(1, sizeof(storage_ext_device)); - if (!dev) - goto out; - - dev->devnode = strdup(devnode); - if (dev->devnode == NULL) { - _E("strdup() failed"); - goto out; - } - - DD_LIST_FOREACH(changed_list, elem, callback) { - if (!callback->func) - continue; - ret = callback->func(dev, state, callback->data); - if (ret < 0) - _E("Failed to call callback for devnode(%s, %d)", devnode, ret); - } - -out: - if (dev) { - free(dev->devnode); - free(dev); - } - free(path); -} -//LCOV_EXCL_STOP - -//LCOV_EXCL_START Not called Callback -static void storage_ext_device_added(GVariant *params, gpointer user_data) -{ - storage_ext_object_path_changed(STORAGE_EXT_ADDED, params, user_data); -} -//LCOV_EXCL_STOP - -//LCOV_EXCL_START Not called Callback -static void storage_ext_device_removed(GVariant *params, gpointer user_data) -{ - storage_ext_object_path_changed(STORAGE_EXT_REMOVED, params, user_data); -} -//LCOV_EXCL_STOP - -//LCOV_EXCL_START Not called Callback -static void storage_ext_device_changed(GVariant *params, gpointer user_data) +static void storage_ext_device_changed(GVariant *params, enum storage_ext_state state, gpointer user_data) { storage_ext_device *dev; dd_list *elem; @@ -317,7 +243,7 @@ static void storage_ext_device_changed(GVariant *params, gpointer user_data) DD_LIST_FOREACH(changed_list, elem, callback) { if (!callback->func) continue; - ret = callback->func(dev, STORAGE_EXT_CHANGED, callback->data); + ret = callback->func(dev, state, callback->data); if (ret < 0) _E("Failed to call callback for devnode(%s, %d)", dev->devnode, ret); } @@ -336,6 +262,7 @@ static void storage_ext_changed(GDBusConnection *conn, gpointer user_data) { size_t iface_len, signal_len; + enum storage_ext_state state; if (!params || !sender || !path || !iface || !signal) return; @@ -343,26 +270,29 @@ static void storage_ext_changed(GDBusConnection *conn, iface_len = strlen(iface) + 1; signal_len = strlen(signal) + 1; - if (!strncmp(iface, STORAGE_EXT_IFACE_MANAGER, iface_len)) { - if (!strncmp(signal, STORAGE_EXT_OBJECT_ADDED, signal_len)) - storage_ext_device_added(params, user_data); - else if (!strncmp(signal, STORAGE_EXT_OBJECT_REMOVED, signal_len)) - storage_ext_device_removed(params, user_data); + if (strncmp(iface, STORAGE_EXT_IFACE, iface_len)) return; - } - if (!strncmp(iface, STORAGE_EXT_IFACE, iface_len) && - !strncmp(signal, STORAGE_EXT_DEVICE_CHANGED, signal_len)) { - storage_ext_device_changed(params, user_data); + if (!strncmp(signal, STORAGE_EXT_DEVICE_CHANGED, signal_len)) + state = STORAGE_EXT_CHANGED; + + else if (!strncmp(signal, STORAGE_EXT_DEVICE_ADDED, signal_len)) + state = STORAGE_EXT_ADDED; + + else if (!strncmp(signal, STORAGE_EXT_DEVICE_REMOVED, signal_len)) + state = STORAGE_EXT_REMOVED; + + else return; - } + + storage_ext_device_changed(params, state, user_data); } //LCOV_EXCL_STOP int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) { GDBusConnection *conn; - guint block_id = NULL, blockmanager_id = NULL; + guint block_id = 0; struct storage_ext_callback *callback; dd_list *elem; @@ -372,7 +302,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) DD_LIST_FOREACH(changed_list, elem, callback) { if (callback->func != func) continue; - if (callback->block_id == 0 || callback->blockmanager_id == 0) + if (callback->block_id == 0) continue; return -EEXIST; @@ -398,41 +328,22 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) block_id = g_dbus_connection_signal_subscribe(conn, STORAGE_EXT_BUS_NAME, STORAGE_EXT_IFACE, - STORAGE_EXT_DEVICE_CHANGED, NULL, NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - storage_ext_changed, - NULL, - NULL); - if (block_id == 0) { - free(callback); - _E("Failed to subscrive bus signal"); - return -EPERM; - } - - blockmanager_id = g_dbus_connection_signal_subscribe(conn, - STORAGE_EXT_BUS_NAME, - STORAGE_EXT_IFACE_MANAGER, - NULL, - STORAGE_EXT_PATH_MANAGER, NULL, G_DBUS_SIGNAL_FLAGS_NONE, storage_ext_changed, NULL, NULL); - if (blockmanager_id == 0) { -//LCOV_EXCL_START System Error + if (block_id == 0) { free(callback); _E("Failed to subscrive bus signal"); return -EPERM; -//LCOV_EXCL_STOP } callback->func = func; callback->data = data; callback->block_id = block_id; - callback->blockmanager_id = blockmanager_id; DD_LIST_APPEND(changed_list, callback); @@ -461,8 +372,6 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) continue; if (callback->block_id > 0) g_dbus_connection_signal_unsubscribe(conn, callback->block_id); - if (callback->blockmanager_id > 0) - g_dbus_connection_signal_unsubscribe(conn, callback->blockmanager_id); DD_LIST_REMOVE(changed_list, callback); free(callback); diff --git a/src/storage-external.c b/src/storage-external.c index c23153d..695c211 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -38,6 +38,9 @@ static int storage_ext_get_dev_state(storage_ext_device *dev, return -EINVAL; switch (blk_state) { + case STORAGE_EXT_ADDED: + *state = STORAGE_STATE_UNMOUNTABLE; + return 0; case STORAGE_EXT_REMOVED: *state = STORAGE_STATE_REMOVED; return 0; @@ -154,7 +157,7 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * } //LCOV_EXCL_START Not called Callback -static int storage_ext_state_changed(storage_ext_device *dev, enum storage_ext_state blk_state, void *data) +static int storage_ext_id_changed(storage_ext_device *dev, enum storage_ext_state blk_state, void *data) { enum storage_cb_type type = (enum storage_cb_type)data; struct storage_cb_info *cb_info; @@ -165,7 +168,7 @@ static int storage_ext_state_changed(storage_ext_device *dev, enum storage_ext_s if (!dev) return -EINVAL; - if (type != STORAGE_CALLBACK_STATE) + if (type != STORAGE_CALLBACK_ID) return 0; ret = storage_ext_get_dev_state(dev, blk_state, &state); @@ -174,38 +177,124 @@ static int storage_ext_state_changed(storage_ext_device *dev, enum storage_ext_s return ret; } - DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_STATE], elem, cb_info) + DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_ID], elem, cb_info) cb_info->state_cb(cb_info->id, state, cb_info->user_data); return 0; } -//LCOV_EXCL_STOP -int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info) +static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_state blk_state, void *data) { + enum storage_cb_type type = (enum storage_cb_type)data; struct storage_cb_info *cb_info; dd_list *elem; - int ret, n; + storage_state_e state; + int ret; + storage_dev_e strdev; + const char *fstype, *fsuuid, *mountpath; + + if (!dev) + return -EINVAL; - if (type < 0 || type >= STORAGE_CALLBACK_MAX) + if (type != STORAGE_CALLBACK_TYPE) return -EINVAL; + ret = storage_ext_get_dev_state(dev, blk_state, &state); + if (ret < 0) { + _E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); + return ret; + } + + if (dev->type == STORAGE_EXT_SCSI) + strdev = STORAGE_DEV_EXT_USB_MASS_STORAGE; + else if (dev->type == STORAGE_EXT_MMC) + strdev = STORAGE_DEV_EXT_SDCARD; + else { + _E("Invalid dev type (%d)", dev->type); + return -EINVAL; + } + + fstype = (dev->fs_type ? (const char *)dev->fs_type : ""); + fsuuid = (dev->fs_uuid ? (const char *)dev->fs_uuid : ""); + mountpath = (dev->mount_point ? (const char *)dev->mount_point : ""); + + DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) + if (cb_info->type_cb) + cb_info->type_cb(dev->storage_id, strdev, state, + fstype, fsuuid, mountpath, dev->primary, + dev->flags, cb_info->user_data); + + return 0; +} + +//LCOV_EXCL_STOP + +static bool check_if_callback_exist(enum storage_cb_type type, + struct storage_cb_info *info, struct storage_cb_info **cb_data) +{ + struct storage_cb_info *cb_info; + dd_list *elem; + if (!info) + return false; + + if (type == STORAGE_CALLBACK_ID) { + DD_LIST_FOREACH(cb_list[type], elem, cb_info) { + if (cb_info->id == info->id && + cb_info->state_cb == info->state_cb) { + goto out; + } + } + } + + if (type == STORAGE_CALLBACK_TYPE) { + DD_LIST_FOREACH(cb_list[type], elem, cb_info) { + if (cb_info->type == info->type && + cb_info->type_cb == info->type_cb) + goto out; + } + } + + return false; + +out: + if (cb_data) + *cb_data = cb_info; + + return true; +} + +int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info) +{ + struct storage_cb_info *cb_info; + int n, ret; + storage_ext_changed_cb callback; + + if (!info) + return -EINVAL; + + switch (type) { + case STORAGE_CALLBACK_ID: + callback = storage_ext_id_changed; + break; + case STORAGE_CALLBACK_TYPE: + callback = storage_ext_type_changed; + break; + default: + _E("Invalid callback type (%d)", type); return -EINVAL; + } - /* check if it is the first request */ n = DD_LIST_LENGTH(cb_list[type]); if (n == 0) { - ret = storage_ext_register_device_change(storage_ext_state_changed, (void *)type); + ret = storage_ext_register_device_change(callback, (void *)type); if (ret < 0) return -EPERM; } - /* check for the same request */ - DD_LIST_FOREACH(cb_list[type], elem, cb_info) { - if (cb_info->id == info->id && - cb_info->state_cb == info->state_cb) - return -EEXIST; + if (check_if_callback_exist(type, info, NULL)) { + _E("The callback is already registered"); + return 0; } /* add device changed callback to list (local) */ @@ -222,33 +311,39 @@ int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *i int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info *info) { struct storage_cb_info *cb_info; - dd_list *elem; int n; - - if (type < 0 || type >= STORAGE_CALLBACK_MAX) - return -EINVAL; + storage_ext_changed_cb callback; if (!info) return -EINVAL; - /* search for the same element with callback */ - DD_LIST_FOREACH(cb_list[type], elem, cb_info) { - if (cb_info->id == info->id && - cb_info->state_cb == info->state_cb) - break; + switch (type) { + case STORAGE_CALLBACK_ID: + callback = storage_ext_id_changed; + break; + case STORAGE_CALLBACK_TYPE: + callback = storage_ext_type_changed; + break; + default: + _E("Invalid callback type (%d)", type); + return -EINVAL; } - if (!cb_info) - return -EINVAL; + if (!check_if_callback_exist(type, info, &cb_info)) { + _E("The callback is not registered"); + return 0; + } /* remove device callback from list (local) */ - DD_LIST_REMOVE(cb_list[type], cb_info); - free(cb_info); + if (cb_info) { + DD_LIST_REMOVE(cb_list[type], cb_info); + free(cb_info); + } /* check if this callback is last element */ n = DD_LIST_LENGTH(cb_list[type]); if (n == 0) - storage_ext_unregister_device_change(storage_ext_state_changed); + storage_ext_unregister_device_change(callback); return 0; } diff --git a/src/storage.c b/src/storage.c index be647ca..7a35693 100644 --- a/src/storage.c +++ b/src/storage.c @@ -284,7 +284,7 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca info.state_cb = callback; info.user_data = user_data; - ret = storage_ext_register_cb(STORAGE_CALLBACK_STATE, &info); + ret = storage_ext_register_cb(STORAGE_CALLBACK_ID, &info); if (ret < 0) { _E("Failed to register callback : id(%d)", storage_id); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; @@ -317,7 +317,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb info.id = storage_id; info.state_cb = callback; - ret = storage_ext_unregister_cb(STORAGE_CALLBACK_STATE, &info); + ret = storage_ext_unregister_cb(STORAGE_CALLBACK_ID, &info); if (ret < 0) { _E("Failed to unregister callback : id(%d)", storage_id); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; @@ -401,3 +401,70 @@ out: *bytes = avail; return STORAGE_ERROR_NONE; } + +API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data) +{ + int ret; + struct storage_cb_info info; + + if (type == STORAGE_TYPE_INTERNAL) { + _E("Internal storage is not supported"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + if (type != STORAGE_TYPE_EXTERNAL) { + _E("Invalid type (%d)", type); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (!callback) { + _E("Callback is NULL"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + /* external storage */ + info.type = type; + info.type_cb = callback; + info.user_data = user_data; + + ret = storage_ext_register_cb(STORAGE_CALLBACK_TYPE, &info); + if (ret < 0) { + _E("Failed to register storage callback(ret:%d)", ret); //LCOV_EXCL_LINE + return STORAGE_ERROR_OPERATION_FAILED; + } + + return STORAGE_ERROR_NONE; +} + +API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback) +{ + struct storage_cb_info info; + int ret; + + if (type == STORAGE_TYPE_INTERNAL) { + _E("Internal storage is not supported"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + if (type != STORAGE_TYPE_EXTERNAL) { + _E("Invalid type (%d)", type); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (!callback) { + _E("Callback is NULL"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + /* external storage */ + info.type = type; + info.type_cb = callback; + + ret = storage_ext_unregister_cb(STORAGE_CALLBACK_TYPE, &info); + if (ret < 0) { + _E("Failed to unregister storage callback(ret:%d)", ret); //LCOV_EXCL_LINE + return STORAGE_ERROR_OPERATION_FAILED; + } + + return STORAGE_ERROR_NONE; +} -- 2.7.4 From 1dfe8712cb8465b84b2271d216fc88d1688b4a16 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Fri, 17 Jun 2016 14:08:50 +0900 Subject: [PATCH 05/16] Providing backward compatibility for APPs in the store which use libstorage APIs incorrectly. Change-Id: I31e265900f9087123fe1e6a0d31d3c67c7d8cd6b --- src/storage.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/storage.c b/src/storage.c index 7a35693..452c230 100644 --- a/src/storage.c +++ b/src/storage.c @@ -40,6 +40,12 @@ const char *dir_path[STORAGE_DIRECTORY_MAX] = { static dd_list *st_int_head; /* Internal storage list */ +static dd_list *compat_cb_list; +struct compat_cb_info { + storage_state_changed_cb user_cb; + void *user_data; +}; + void add_device(const struct storage_ops *st) { DD_LIST_APPEND(st_int_head, st); @@ -259,6 +265,20 @@ API int storage_get_state(int storage_id, storage_state_e *state) return STORAGE_ERROR_NONE; } +static void compat_cb(int storage_id, + storage_dev_e dev, storage_state_e state, + const char *fstype, const char *fsuuid, const char *mountpath, + bool primary, int flags, void *user_data) +{ + struct compat_cb_info* ccb_info; + dd_list *elem; + + if(storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD){ + DD_LIST_FOREACH(compat_cb_list, elem, ccb_info) + ccb_info->user_cb(storage_id, state, ccb_info->user_data); + } +} + API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callback, void *user_data) { const struct storage_ops *st; @@ -266,6 +286,9 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca int ret; dd_list *elem; + struct compat_cb_info* ccb_info; + static int compat_cb_init = 0; + if (storage_id < 0) return STORAGE_ERROR_NOT_SUPPORTED; @@ -274,6 +297,26 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca return STORAGE_ERROR_INVALID_PARAMETER; } + /* For backward compatability */ + if (storage_id == STORAGE_TYPE_EXTERNAL) { + if(!compat_cb_init){ + ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, compat_cb, NULL); + if(ret == STORAGE_ERROR_NONE) + compat_cb_init = 1; + else + return ret; + } + + ccb_info = malloc(sizeof(struct compat_cb_info)); + if(ccb_info == NULL) + return STORAGE_ERROR_OPERATION_FAILED; + ccb_info->user_cb = callback; + ccb_info->user_data = user_data; + DD_LIST_APPEND(compat_cb_list, ccb_info); + + return STORAGE_ERROR_NONE; + } + /* Internal storage does not support registering changed callback */ DD_LIST_FOREACH(st_int_head, elem, st) if (st->storage_id == storage_id) @@ -308,6 +351,21 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb return STORAGE_ERROR_INVALID_PARAMETER; } + /* For backward compatability */ + if (storage_id == STORAGE_TYPE_EXTERNAL) { + dd_list *elem_n; + struct compat_cb_info* ccb_info; + + DD_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) { + if(ccb_info->user_cb == callback){ + DD_LIST_REMOVE(compat_cb_list, ccb_info); + free(ccb_info); + return STORAGE_ERROR_NONE; + } + } + return STORAGE_ERROR_OPERATION_FAILED; + } + /* Internal storage does not support registering changed callback */ DD_LIST_FOREACH(st_int_head, elem, st) if (st->storage_id == storage_id) -- 2.7.4 From 912e5bb97f862f12e27e06b2b60839a1b49880b4 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 29 Jun 2016 08:33:09 +0900 Subject: [PATCH 06/16] common: apply Tizen coding rule Signed-off-by: taeyoung Change-Id: I7b6a4e580dc1e2e615cd3c39ec4762150156b09e --- src/storage.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/storage.c b/src/storage.c index 452c230..26b4036 100644 --- a/src/storage.c +++ b/src/storage.c @@ -266,17 +266,16 @@ API int storage_get_state(int storage_id, storage_state_e *state) } static void compat_cb(int storage_id, - storage_dev_e dev, storage_state_e state, - const char *fstype, const char *fsuuid, const char *mountpath, - bool primary, int flags, void *user_data) + storage_dev_e dev, storage_state_e state, + const char *fstype, const char *fsuuid, const char *mountpath, + bool primary, int flags, void *user_data) { struct compat_cb_info* ccb_info; dd_list *elem; - if(storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD){ + if (storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD) DD_LIST_FOREACH(compat_cb_list, elem, ccb_info) ccb_info->user_cb(storage_id, state, ccb_info->user_data); - } } API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callback, void *user_data) @@ -299,16 +298,16 @@ 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(!compat_cb_init){ + if (!compat_cb_init) { ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, compat_cb, NULL); - if(ret == STORAGE_ERROR_NONE) + if (ret == STORAGE_ERROR_NONE) compat_cb_init = 1; else return ret; } ccb_info = malloc(sizeof(struct compat_cb_info)); - if(ccb_info == NULL) + if (ccb_info == NULL) return STORAGE_ERROR_OPERATION_FAILED; ccb_info->user_cb = callback; ccb_info->user_data = user_data; @@ -357,7 +356,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb struct compat_cb_info* ccb_info; DD_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) { - if(ccb_info->user_cb == callback){ + if (ccb_info->user_cb == callback) { DD_LIST_REMOVE(compat_cb_list, ccb_info); free(ccb_info); return STORAGE_ERROR_NONE; -- 2.7.4 From 1b3d7ecec520670c1f9bb6f774bf35843a67b1ac Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 13 Jul 2016 18:35:13 +0900 Subject: [PATCH 07/16] common: Apply Tizen coding rule Change-Id: I1e3eca3ace0f3ae5d686df42dd434c7800eaa759 Signed-off-by: pr.jung --- include/storage-expand.h | 22 +++++++++++----------- include/storage.h | 24 ++++++++++++------------ src/storage-external.c | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/storage-expand.h b/include/storage-expand.h index f0e5382..bd134ac 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -36,11 +36,11 @@ extern "C" { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ typedef enum { - STORAGE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - STORAGE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - STORAGE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - STORAGE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NO_SUCH_DEVICE, /**< Storage not supported */ - STORAGE_ERROR_OPERATION_FAILED = TIZEN_ERROR_SYSTEM_CLASS | 0x12, /**< Operation failed */ + STORAGE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + STORAGE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + STORAGE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + STORAGE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NO_SUCH_DEVICE, /**< Storage not supported */ + STORAGE_ERROR_OPERATION_FAILED = TIZEN_ERROR_SYSTEM_CLASS | 0x12, /**< Operation failed */ } storage_error_e; @@ -49,8 +49,8 @@ typedef enum { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ typedef enum { - STORAGE_TYPE_INTERNAL, /**< Internal device storage (built-in storage in a device, non-removable) */ - STORAGE_TYPE_EXTERNAL, /**< External storage */ + STORAGE_TYPE_INTERNAL, /**< Internal device storage (built-in storage in a device, non-removable) */ + STORAGE_TYPE_EXTERNAL, /**< External storage */ } storage_type_e; @@ -59,10 +59,10 @@ typedef enum { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ typedef enum { - STORAGE_STATE_UNMOUNTABLE = -2, /**< Storage is present but cannot be mounted. Typically it happens if the file system of the storage is corrupted */ - STORAGE_STATE_REMOVED = -1, /**< Storage is not present */ - STORAGE_STATE_MOUNTED = 0, /**< Storage is present and mounted with read/write access */ - STORAGE_STATE_MOUNTED_READ_ONLY = 1, /**< Storage is present and mounted with read only access */ + STORAGE_STATE_UNMOUNTABLE = -2, /**< Storage is present but cannot be mounted. Typically it happens if the file system of the storage is corrupted */ + STORAGE_STATE_REMOVED = -1, /**< Storage is not present */ + STORAGE_STATE_MOUNTED = 0, /**< Storage is present and mounted with read/write access */ + STORAGE_STATE_MOUNTED_READ_ONLY = 1, /**< Storage is present and mounted with read only access */ } storage_state_e; /** diff --git a/include/storage.h b/include/storage.h index 5df9a26..235c72b 100644 --- a/include/storage.h +++ b/include/storage.h @@ -52,14 +52,14 @@ extern "C" { * @see * @par Example: * @code - * ... + * ... * struct statvfs s; - * if (storage_get_internal_memory_size(&s) < 0) - * dlog_print(DLOG_DEBUG, LOG_TAG, "Fail to get internal memory size"); - * else - * dlog_print(DLOG_DEBUG, LOG_TAG, "Total mem : %lf, Avail mem : %lf", + * if (storage_get_internal_memory_size(&s) < 0) + * dlog_print(DLOG_DEBUG, LOG_TAG, "Fail to get internal memory size"); + * else + * dlog_print(DLOG_DEBUG, LOG_TAG, "Total mem : %lf, Avail mem : %lf", * (double)s.f_frsize*s.f_blocks, (double)s.f_bsize*s.f_bavail); - * ... + * ... * @endcode */ #ifndef __USE_FILE_OFFSET64 @@ -84,14 +84,14 @@ extern int storage_get_internal_memory_size64(struct statvfs *buf); * @see * @par Example: * @code - * ... + * ... * struct statvfs s; - * if (storage_get_external_memory_size(&s) < 0) - * dlog_print(DLOG_DEBUG, LOG_TAG, "Fail to get external memory size"); - * else - * dlog_print(DLOG_DEBUG, LOG_TAG, "Total mem : %lf, Avail mem : %lf", + * if (storage_get_external_memory_size(&s) < 0) + * dlog_print(DLOG_DEBUG, LOG_TAG, "Fail to get external memory size"); + * else + * dlog_print(DLOG_DEBUG, LOG_TAG, "Total mem : %lf, Avail mem : %lf", * (double)s.f_frsize*s.f_blocks, (double)s.f_bsize*s.f_bavail); - * ... + * ... * @endcode */ #ifndef __USE_FILE_OFFSET64 diff --git a/src/storage-external.c b/src/storage-external.c index 695c211..980c94b 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -410,7 +410,7 @@ int storage_ext_get_state(int storage_id, storage_state_e *state) if (ret < 0) _E("Failed to get state of storage id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE -out: +out : storage_ext_release_device(&dev); return ret; } -- 2.7.4 From bccbe0277184d6f26b259da0f21e2c90b1121ebd Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 14 Jul 2016 20:59:55 +0900 Subject: [PATCH 08/16] mmc: add the internal api to return primary mmc information - Primary mmc information is used to install apps on the mmc. Thus primary mmc information api is necessary to avoid iterations with previous apis Change-Id: Id27f575d0442225d0cb909220716e5d527ad506d Signed-off-by: taeyoung --- CMakeLists.txt | 6 ++-- include/storage-internal.h | 63 +++++++++++++++++++++++++++++++++++++++ src/storage-external-dbus.c | 4 +-- src/storage-external-dbus.h | 4 +++ src/storage-external-inhouse.c | 67 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 include/storage-internal.h create mode 100755 src/storage-external-inhouse.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 56482b0..55924cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,8 @@ ENDFOREACH(flag) SET(HEADERS include/storage.h - include/storage-expand.h) + include/storage-expand.h + include/storage-internal.h) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g") @@ -45,7 +46,8 @@ SET(SRCS src/storage.c src/storage-internal.c src/storage-external.c - src/storage-external-dbus.c) + src/storage-external-dbus.c + src/storage-external-inhouse.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${TARGET_SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS}) diff --git a/include/storage-internal.h b/include/storage-internal.h new file mode 100644 index 0000000..2040fc9 --- /dev/null +++ b/include/storage-internal.h @@ -0,0 +1,63 @@ +/* + * storage + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __STORAGE_INTERNAL_H__ +#define __STORAGE_INTERNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_STORAGE_MODULE + * @{ + */ + +#include +#include "storage.h" + +#define STORAGE_ERROR_NO_DEVICE TIZEN_ERROR_NO_SUCH_DEVICE + +/** + * @brief Get the mount path for the primary partition of sdcard. + * + * @since_tizen 3.0 + * + * @remarks You must release the path using free() after use + * + * @param[out] storage_id The storage id + * @param[out] path The mount path of sdcard primary partition. + * + * @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 + */ +int storage_get_primary_sdcard(int *storage_id, char **path); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* __STORAGE_INTERNAL_H__ */ diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 2793e40..012044c 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -112,14 +112,14 @@ static GDBusConnection *get_dbus_connection(void) return conn; } -static GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, +GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, const gchar *iface, const gchar *method, GVariant *param) { GDBusConnection *conn; GError *err = NULL; GVariant *ret; - if (!dest || !path || !iface || !method || !param) + if (!dest || !path || !iface || !method) return NULL; conn = get_dbus_connection(); diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index d279c65..06153ee 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -84,4 +84,8 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); +/* storage-internal.c */ +GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, + const gchar *iface, const gchar *method, GVariant *param); + #endif /* __STORAGE_EXTERNAL_DBUS_H__ */ diff --git a/src/storage-external-inhouse.c b/src/storage-external-inhouse.c new file mode 100755 index 0000000..6e7f5c4 --- /dev/null +++ b/src/storage-external-inhouse.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include + +#include "common.h" +#include "list.h" +#include "log.h" +#include "storage-internal.h" +#include "storage-external-dbus.h" + +API int storage_get_primary_sdcard(int *storage_id, char **path) +{ + GVariant *result; + storage_ext_device info; + + if (!storage_id || !path) + return STORAGE_ERROR_INVALID_PARAMETER; + + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "GetMmcPrimary", + NULL); + if (!result) { + _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + g_variant_get(result, "(issssssisibii)", + &info.type, &info.devnode, &info.syspath, + &info.fs_usage, &info.fs_type, + &info.fs_version, &info.fs_uuid, + &info.readonly, &info.mount_point, + &info.state, &info.primary, + &info.flags, &info.storage_id); + + g_variant_unref(result); + + if (info.storage_id < 0) + return STORAGE_ERROR_NO_DEVICE; + + *path = strdup(info.mount_point); + if (*path == NULL) + return STORAGE_ERROR_OUT_OF_MEMORY; + + *storage_id = info.storage_id; + + return STORAGE_ERROR_NONE; +} -- 2.7.4 From c8bf03894d812fed9a8c33a0cf6789e07550686e Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 8 Aug 2016 10:46:57 +0900 Subject: [PATCH 09/16] Modify block signal interface and object path Change-Id: I636e63e2494f0675d4d4a6ecab067fb3766602e5 Signed-off-by: pr.jung --- src/storage-external-dbus.c | 6 +++--- src/storage-external-dbus.h | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 012044c..bf032b1 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -270,7 +270,7 @@ static void storage_ext_changed(GDBusConnection *conn, iface_len = strlen(iface) + 1; signal_len = strlen(signal) + 1; - if (strncmp(iface, STORAGE_EXT_IFACE, iface_len)) + if (strncmp(iface, STORAGE_EXT_IFACE_MANAGER, iface_len)) return; if (!strncmp(signal, STORAGE_EXT_DEVICE_CHANGED, signal_len)) @@ -327,7 +327,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) block_id = g_dbus_connection_signal_subscribe(conn, STORAGE_EXT_BUS_NAME, - STORAGE_EXT_IFACE, + STORAGE_EXT_IFACE_MANAGER, NULL, NULL, NULL, @@ -385,7 +385,7 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, - "GetDeviceInfoByID", + "GetDeviceInfo", g_variant_new("(i)", storage_id)); if (!result) { _E("There is no storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 06153ee..7ae0d1f 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -26,10 +26,7 @@ #include "list.h" #define STORAGE_EXT_BUS_NAME "org.tizen.system.storage" -#define STORAGE_EXT_PATH "/Org/Tizen/System/Storage/Block" -#define STORAGE_EXT_PATH_DEVICES STORAGE_EXT_PATH"/Devices" -#define STORAGE_EXT_PATH_MANAGER STORAGE_EXT_PATH"/Manager" -#define STORAGE_EXT_IFACE STORAGE_EXT_BUS_NAME".Block" +#define STORAGE_EXT_PATH_MANAGER "/Org/Tizen/System/Storage/Block/Manager" #define STORAGE_EXT_IFACE_MANAGER STORAGE_EXT_BUS_NAME".BlockManager" enum mount_state { -- 2.7.4 From 23de75841e9bb1a712b06352b71d9107302c06e9 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Tue, 23 Aug 2016 13:38:54 +0900 Subject: [PATCH 10/16] Supporting Internal Media Path Compatibility Internal compatibility media path is available, libstorage returns the path. Related to : https://review.tizen.org/gerrit/#/c/84834/ Change-Id: Id5e0eaa1d6f7913ef6a7106448bcefaf527cf6c5 --- CMakeLists.txt | 1 + packaging/libstorage.spec | 1 + src/storage-internal.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55924cd..a8c5f4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ SET(dependents gio-2.0 libtzplatform-config capi-system-system-settings + mount ) SET(pc_dependents "capi-base-common") diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 0204e53..ee26b84 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(capi-system-system-settings) +BuildRequires: pkgconfig(mount) %description development package of library to get storage diff --git a/src/storage-internal.c b/src/storage-internal.c index 1867def..8713a12 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -22,10 +22,12 @@ #include #include #include +#include #include "common.h" #include "log.h" +#define COMPAT_DIR "/opt/usr/media" #ifndef __USE_FILE_OFFSET64 int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); @@ -60,7 +62,32 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava static const char *internal_get_root(void) { - return tzplatform_getenv(TZ_USER_CONTENT); + struct libmnt_table *t = NULL; + int r = 0; + struct libmnt_fs *fs; + const char *ret; + + ret = tzplatform_getenv(TZ_USER_CONTENT); + + t = mnt_new_table(); + if(!t) + return ret; + + r = mnt_table_parse_mtab(t, NULL); + if(r < 0){ + mnt_free_table(t); + return ret; + } + + fs = mnt_table_find_target(t,COMPAT_DIR,MNT_ITER_BACKWARD); + if(fs){ + // TODO : mnt_fs_get_root(fs) should be matched to tzplatform_getenv(TZ_USER_CONTENT). + ret = COMPAT_DIR; + } + + mnt_free_table(t); + + return ret; } const struct storage_ops internal = { -- 2.7.4 From 516c6d12ac23e924de40b8b876cd0f0b380c1a60 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 20 Jul 2016 18:40:23 +0900 Subject: [PATCH 11/16] Add DeviceBlocked signal for storage callback Change-Id: I629060f98ce5ca907f0b8e3ce869b5657ecf3a10 Signed-off-by: pr.jung --- src/storage-external-dbus.c | 10 ++++++++++ src/storage-external-dbus.h | 1 + src/storage-external.c | 3 +++ 3 files changed, 14 insertions(+) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index bf032b1..626feb9 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -36,6 +36,7 @@ #define STORAGE_EXT_DEVICE_CHANGED "DeviceChanged" #define STORAGE_EXT_DEVICE_ADDED "DeviceAdded" #define STORAGE_EXT_DEVICE_REMOVED "DeviceRemoved" +#define STORAGE_EXT_DEVICE_BLOCKED "DeviceBlocked" #define DBUS_REPLY_TIMEOUT (-1) @@ -240,6 +241,12 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state &dev->flags, &dev->storage_id); + /* Callback is called when unmount is started(DeviceBlocked signal) */ + if (state == STORAGE_EXT_CHANGED && dev->state == STORAGE_EXT_UNMOUNTED) { + storage_ext_release_device(&dev); + return; + } + DD_LIST_FOREACH(changed_list, elem, callback) { if (!callback->func) continue; @@ -282,6 +289,9 @@ static void storage_ext_changed(GDBusConnection *conn, else if (!strncmp(signal, STORAGE_EXT_DEVICE_REMOVED, signal_len)) state = STORAGE_EXT_REMOVED; + else if (!strncmp(signal, STORAGE_EXT_DEVICE_BLOCKED, signal_len)) + state = STORAGE_EXT_BLOCKED; + else return; diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 7ae0d1f..0589959 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -38,6 +38,7 @@ enum storage_ext_state { STORAGE_EXT_REMOVED, STORAGE_EXT_ADDED, STORAGE_EXT_CHANGED, + STORAGE_EXT_BLOCKED, }; enum storage_ext_type { diff --git a/src/storage-external.c b/src/storage-external.c index 980c94b..9eba26d 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -58,6 +58,9 @@ static int storage_ext_get_dev_state(storage_ext_device *dev, default: return -EINVAL; } + case STORAGE_EXT_BLOCKED: + *state = STORAGE_STATE_UNMOUNTABLE; + return 0; default: return -EINVAL; } -- 2.7.4 From ea3ccd13aa047b695a4a5a56d9f9c43c31e75042 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Tue, 6 Sep 2016 21:09:48 -0700 Subject: [PATCH 12/16] Revert "Supporting Internal Media Path Compatibility" This reverts commit 23de75841e9bb1a712b06352b71d9107302c06e9. Change-Id: Id20c18851b7dfd2aa3f4d8dd14b446f7e7f7cc30 --- CMakeLists.txt | 1 - packaging/libstorage.spec | 1 - src/storage-internal.c | 29 +---------------------------- 3 files changed, 1 insertion(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8c5f4b..55924cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,6 @@ SET(dependents gio-2.0 libtzplatform-config capi-system-system-settings - mount ) SET(pc_dependents "capi-base-common") diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index ee26b84..0204e53 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -14,7 +14,6 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-system-system-settings) -BuildRequires: pkgconfig(mount) %description development package of library to get storage diff --git a/src/storage-internal.c b/src/storage-internal.c index 8713a12..1867def 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -22,12 +22,10 @@ #include #include #include -#include #include "common.h" #include "log.h" -#define COMPAT_DIR "/opt/usr/media" #ifndef __USE_FILE_OFFSET64 int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); @@ -62,32 +60,7 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava static const char *internal_get_root(void) { - struct libmnt_table *t = NULL; - int r = 0; - struct libmnt_fs *fs; - const char *ret; - - ret = tzplatform_getenv(TZ_USER_CONTENT); - - t = mnt_new_table(); - if(!t) - return ret; - - r = mnt_table_parse_mtab(t, NULL); - if(r < 0){ - mnt_free_table(t); - return ret; - } - - fs = mnt_table_find_target(t,COMPAT_DIR,MNT_ITER_BACKWARD); - if(fs){ - // TODO : mnt_fs_get_root(fs) should be matched to tzplatform_getenv(TZ_USER_CONTENT). - ret = COMPAT_DIR; - } - - mnt_free_table(t); - - return ret; + return tzplatform_getenv(TZ_USER_CONTENT); } const struct storage_ops internal = { -- 2.7.4 From 9ec1a4f0bfdc76fd11f387b974871d0928d21c90 Mon Sep 17 00:00:00 2001 From: Jung Date: Mon, 19 Sep 2016 20:55:46 -0700 Subject: [PATCH 13/16] Revert "Revert "Supporting Internal Media Path Compatibility"" This reverts commit ea3ccd13aa047b695a4a5a56d9f9c43c31e75042. Change-Id: I63a2a0152be707b36deba35ffc94b1c32f97538f --- CMakeLists.txt | 1 + packaging/libstorage.spec | 1 + src/storage-internal.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55924cd..a8c5f4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ SET(dependents gio-2.0 libtzplatform-config capi-system-system-settings + mount ) SET(pc_dependents "capi-base-common") diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 0204e53..ee26b84 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(capi-system-system-settings) +BuildRequires: pkgconfig(mount) %description development package of library to get storage diff --git a/src/storage-internal.c b/src/storage-internal.c index 1867def..9be1060 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -22,10 +22,12 @@ #include #include #include +#include #include "common.h" #include "log.h" +#define COMPAT_DIR "/opt/usr/media" #ifndef __USE_FILE_OFFSET64 int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); @@ -60,7 +62,32 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava static const char *internal_get_root(void) { - return tzplatform_getenv(TZ_USER_CONTENT); + struct libmnt_table *t = NULL; + int r = 0; + struct libmnt_fs *fs; + const char *ret; + + ret = tzplatform_getenv(TZ_USER_CONTENT); + + t = mnt_new_table(); + if(!t) + return ret; + + r = mnt_table_parse_mtab(t, NULL); + if (r < 0) { + mnt_free_table(t); + return ret; + } + + fs = mnt_table_find_target(t, COMPAT_DIR, MNT_ITER_BACKWARD); + if (fs) { + // TODO : mnt_fs_get_root(fs) should be matched to tzplatform_getenv(TZ_USER_CONTENT). + ret = COMPAT_DIR; + } + + mnt_free_table(t); + + return ret; } const struct storage_ops internal = { -- 2.7.4 From 709a88f8c3f9ad24eafc2788ffa50a444f274795 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Thu, 29 Sep 2016 09:38:48 +0900 Subject: [PATCH 14/16] Provide internal APIs for converting compat path Change-Id: I81aad2364f5c99a4ea252374cce4d6497093f08d --- CMakeLists.txt | 4 +- include/common.h | 3 + include/storage-internal.h | 3 + packaging/libstorage.spec | 2 +- src/storage-common.c | 29 ++++++++ src/storage-external-inhouse.c | 67 ------------------ src/storage-inhouse.c | 156 +++++++++++++++++++++++++++++++++++++++++ src/storage-internal.c | 26 +------ 8 files changed, 198 insertions(+), 92 deletions(-) create mode 100644 src/storage-common.c delete mode 100755 src/storage-external-inhouse.c create mode 100755 src/storage-inhouse.c diff --git a/CMakeLists.txt b/CMakeLists.txt index a8c5f4b..a4feb38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,9 @@ SET(SRCS src/storage-internal.c src/storage-external.c src/storage-external-dbus.c - src/storage-external-inhouse.c) + src/storage-inhouse.c + src/storage-common.c + ) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${TARGET_SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS}) diff --git a/include/common.h b/include/common.h index a819ecc..f208338 100644 --- a/include/common.h +++ b/include/common.h @@ -82,6 +82,9 @@ void remove_device(const struct storage_ops *st); int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf); 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); + #ifdef __cplusplus } #endif diff --git a/include/storage-internal.h b/include/storage-internal.h index 2040fc9..391a721 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -53,6 +53,9 @@ extern "C" { */ 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); + /** * @} */ diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index ee26b84..90eae50 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -1,6 +1,6 @@ Name: libstorage Summary: Library to get storage information -Version: 0.1.0 +Version: 0.1.1 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/src/storage-common.c b/src/storage-common.c new file mode 100644 index 0000000..d6d1216 --- /dev/null +++ b/src/storage-common.c @@ -0,0 +1,29 @@ +#include +#include "common.h" + +int is_compat_bind_mount(void) +{ + struct libmnt_table *t = NULL; + int r = 0; + struct libmnt_fs *fs; + + t = mnt_new_table(); + if(!t) + return 0; + + r = mnt_table_parse_mtab(t, NULL); + if (r < 0) { + mnt_free_table(t); + return 0; + } + + fs = mnt_table_find_target(t, COMPAT_DIR, MNT_ITER_BACKWARD); + if (fs) { + // TODO : mnt_fs_get_root(fs) should be matched to tzplatform_getenv(TZ_USER_CONTENT). + mnt_free_table(t); + return 1; + } + + mnt_free_table(t); + return 0; +} diff --git a/src/storage-external-inhouse.c b/src/storage-external-inhouse.c deleted file mode 100755 index 6e7f5c4..0000000 --- a/src/storage-external-inhouse.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -#include "common.h" -#include "list.h" -#include "log.h" -#include "storage-internal.h" -#include "storage-external-dbus.h" - -API int storage_get_primary_sdcard(int *storage_id, char **path) -{ - GVariant *result; - storage_ext_device info; - - if (!storage_id || !path) - return STORAGE_ERROR_INVALID_PARAMETER; - - result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, - STORAGE_EXT_PATH_MANAGER, - STORAGE_EXT_IFACE_MANAGER, - "GetMmcPrimary", - NULL); - if (!result) { - _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE - return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE - } - - g_variant_get(result, "(issssssisibii)", - &info.type, &info.devnode, &info.syspath, - &info.fs_usage, &info.fs_type, - &info.fs_version, &info.fs_uuid, - &info.readonly, &info.mount_point, - &info.state, &info.primary, - &info.flags, &info.storage_id); - - g_variant_unref(result); - - if (info.storage_id < 0) - return STORAGE_ERROR_NO_DEVICE; - - *path = strdup(info.mount_point); - if (*path == NULL) - return STORAGE_ERROR_OUT_OF_MEMORY; - - *storage_id = info.storage_id; - - return STORAGE_ERROR_NONE; -} diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c new file mode 100755 index 0000000..e589b14 --- /dev/null +++ b/src/storage-inhouse.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include + +#include "common.h" +#include "list.h" +#include "log.h" +#include "storage-internal.h" +#include "storage-external-dbus.h" + +/* + Get compat path from origin Multi-user path + from TZ_USER_CONTENT/.. to /opt/usr/media/.. + Input should be normalized path like /opt/usr/home/owner/media (TODO: internal normalization) + + Why this API should be provided? + In multi-user environment, each user has own compat content direcotry.(/opt/usr/media) + However, although system daemon operates real path, + system daemon needs to provide compat path to App if the real path is converted. + + Usage: + #include + + char dest[100]; + if(storage_get_compat_internal_path(src, sizeof(dest), dest) < 0) + // cannot convert. use src path + else + // can convert. use dest path + */ +API int storage_get_compat_internal_path(const char* origin, int len, char* compat) +{ + int r=-1; + const char* str; + + // this API works on place where compat path is bind-mounted + if(!is_compat_bind_mount()){ + _E("no compat bind mount"); + return -1; + } + + str = tzplatform_getenv(TZ_USER_CONTENT); + if(strncmp(origin,str,strlen(str))!=0){ + _E("failed to match TZ_USER_CONTENT"); + return -1; + } + + r = snprintf(compat,len,"%s/%s",COMPAT_DIR,origin+strlen(str)); + if(r < 0){ + _E("failed to create new path"); + return -1; + } + + return 0; +} + +/* + Get Multi-user path from compat path + from /opt/usr/media/.. to TZ_USER_CONTENT/.. + Input should be normalized path like /opt/usr/media (TODO: internal normalization) + + Why this API should be provided? + In multi-user environment, each user has own compat content direcotry.(/opt/usr/media) + However, although some APIs send the compat path to system daemon, + system daemon should access real path. + + Usage: + #include + + char dest[100]; + if(storage_get_origin_internal_path(src, sizeof(dest), dest) < 0) + // cannot convert. use src path + else + // can convert. use dest path +*/ +API int storage_get_origin_internal_path(const char* compat, int len, char* origin) +{ + int r; + + // this API works on place where compat path is bind-mounted + if(!is_compat_bind_mount()){ + _E("no compat bind mount"); + return -1; + } + + if(strncmp(compat,COMPAT_DIR,strlen(COMPAT_DIR))!=0){ + _E("failed to match COMPAT_DIR"); + return -1; + } + + r = snprintf(origin,len,"%s/%s",tzplatform_getenv(TZ_USER_CONTENT),compat+strlen(COMPAT_DIR)); + if(r < 0){ + _E("failed to create new path"); + return -1; + } + + return 0; +} + +API int storage_get_primary_sdcard(int *storage_id, char **path) +{ + GVariant *result; + storage_ext_device info; + + if (!storage_id || !path) + return STORAGE_ERROR_INVALID_PARAMETER; + + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "GetMmcPrimary", + NULL); + if (!result) { + _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + g_variant_get(result, "(issssssisibii)", + &info.type, &info.devnode, &info.syspath, + &info.fs_usage, &info.fs_type, + &info.fs_version, &info.fs_uuid, + &info.readonly, &info.mount_point, + &info.state, &info.primary, + &info.flags, &info.storage_id); + + g_variant_unref(result); + + if (info.storage_id < 0) + return STORAGE_ERROR_NO_DEVICE; + + *path = strdup(info.mount_point); + if (*path == NULL) + return STORAGE_ERROR_OUT_OF_MEMORY; + + *storage_id = info.storage_id; + + return STORAGE_ERROR_NONE; +} diff --git a/src/storage-internal.c b/src/storage-internal.c index 9be1060..a177878 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -27,8 +27,6 @@ #include "common.h" #include "log.h" -#define COMPAT_DIR "/opt/usr/media" - #ifndef __USE_FILE_OFFSET64 int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); #else @@ -62,30 +60,12 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava static const char *internal_get_root(void) { - struct libmnt_table *t = NULL; - int r = 0; - struct libmnt_fs *fs; const char *ret; - ret = tzplatform_getenv(TZ_USER_CONTENT); - - t = mnt_new_table(); - if(!t) - return ret; - - r = mnt_table_parse_mtab(t, NULL); - if (r < 0) { - mnt_free_table(t); - return ret; - } - - fs = mnt_table_find_target(t, COMPAT_DIR, MNT_ITER_BACKWARD); - if (fs) { - // TODO : mnt_fs_get_root(fs) should be matched to tzplatform_getenv(TZ_USER_CONTENT). + if(is_compat_bind_mount()) ret = COMPAT_DIR; - } - - mnt_free_table(t); + else + ret = tzplatform_getenv(TZ_USER_CONTENT); return ret; } -- 2.7.4 From 80b30d81b08c8d110108ec3b9e575482b6b96c2d Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 29 Sep 2016 11:52:25 +0900 Subject: [PATCH 15/16] Apply Tizen coding rule Change-Id: Ib8a1a4d008989f12eeff5956a9afda767cfa364a Signed-off-by: pr.jung --- src/storage-common.c | 51 ++++++++++++++++++++++++++++++++++---------------- src/storage-inhouse.c | 38 +++++++++++++++++++++++++------------ src/storage-internal.c | 2 +- 3 files changed, 62 insertions(+), 29 deletions(-) diff --git a/src/storage-common.c b/src/storage-common.c index d6d1216..3885dca 100644 --- a/src/storage-common.c +++ b/src/storage-common.c @@ -1,29 +1,48 @@ +/* + * libstorage + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include #include "common.h" int is_compat_bind_mount(void) { - struct libmnt_table *t = NULL; - int r = 0; - struct libmnt_fs *fs; + struct libmnt_table *t = NULL; + int r = 0; + struct libmnt_fs *fs; - t = mnt_new_table(); - if(!t) - return 0; + t = mnt_new_table(); + if (!t) + return 0; - r = mnt_table_parse_mtab(t, NULL); - if (r < 0) { - mnt_free_table(t); - return 0; - } + r = mnt_table_parse_mtab(t, NULL); + if (r < 0) { + mnt_free_table(t); + return 0; + } - fs = mnt_table_find_target(t, COMPAT_DIR, MNT_ITER_BACKWARD); - if (fs) { + fs = mnt_table_find_target(t, COMPAT_DIR, MNT_ITER_BACKWARD); + if (fs) { // TODO : mnt_fs_get_root(fs) should be matched to tzplatform_getenv(TZ_USER_CONTENT). mnt_free_table(t); return 1; - } + } - mnt_free_table(t); - return 0; + mnt_free_table(t); + return 0; } diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index e589b14..9216393 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -48,24 +48,31 @@ */ API int storage_get_compat_internal_path(const char* origin, int len, char* compat) { - int r=-1; + int r = -1; + int str_len; const char* str; + if (!compat || !origin) { + _E("Invalid parameter"); + return -1; + } + // this API works on place where compat path is bind-mounted - if(!is_compat_bind_mount()){ - _E("no compat bind mount"); + if (!is_compat_bind_mount()) { + _E("No compat bind mount"); return -1; } str = tzplatform_getenv(TZ_USER_CONTENT); - if(strncmp(origin,str,strlen(str))!=0){ - _E("failed to match TZ_USER_CONTENT"); + str_len = strlen(str); + if (strncmp(origin, str, str_len) != 0) { + _E("Failed to match TZ_USER_CONTENT"); return -1; } - r = snprintf(compat,len,"%s/%s",COMPAT_DIR,origin+strlen(str)); - if(r < 0){ - _E("failed to create new path"); + r = snprintf(compat, len, "%s/%s", COMPAT_DIR, origin + str_len); + if (r < 0) { + _E("Failed to create new path"); return -1; } @@ -94,20 +101,27 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp API int storage_get_origin_internal_path(const char* compat, int len, char* origin) { int r; + int compat_len; + + if (!compat || !origin) { + _E("Invalid parameter"); + return -1; + } // this API works on place where compat path is bind-mounted - if(!is_compat_bind_mount()){ + if (!is_compat_bind_mount()) { _E("no compat bind mount"); return -1; } - if(strncmp(compat,COMPAT_DIR,strlen(COMPAT_DIR))!=0){ + compat_len = strlen(COMPAT_DIR); + if (strncmp(compat, COMPAT_DIR, compat_len) != 0) { _E("failed to match COMPAT_DIR"); return -1; } - r = snprintf(origin,len,"%s/%s",tzplatform_getenv(TZ_USER_CONTENT),compat+strlen(COMPAT_DIR)); - if(r < 0){ + r = snprintf(origin, len, "%s/%s", tzplatform_getenv(TZ_USER_CONTENT), compat + compat_len); + if (r < 0) { _E("failed to create new path"); return -1; } diff --git a/src/storage-internal.c b/src/storage-internal.c index a177878..7f5d359 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -62,7 +62,7 @@ static const char *internal_get_root(void) { const char *ret; - if(is_compat_bind_mount()) + if (is_compat_bind_mount()) ret = COMPAT_DIR; else ret = tzplatform_getenv(TZ_USER_CONTENT); -- 2.7.4 From 60b453bfda7162a373fd2c1c1b66fd7975b610e6 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 29 Sep 2016 16:19:25 +0900 Subject: [PATCH 16/16] remove unnecessary '/' from the path Change-Id: I79d42621397c468238f7c4955725fba82a897b3f Signed-off-by: taeyoung --- src/storage-inhouse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 9216393..f4698de 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -70,7 +70,7 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp return -1; } - r = snprintf(compat, len, "%s/%s", COMPAT_DIR, origin + str_len); + r = snprintf(compat, len, "%s%s", COMPAT_DIR, origin + str_len); if (r < 0) { _E("Failed to create new path"); return -1; @@ -120,7 +120,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_getenv(TZ_USER_CONTENT), compat + compat_len); if (r < 0) { _E("failed to create new path"); return -1; -- 2.7.4