From ebc865a7f34020f47d65aac30aa97782b88d05f4 Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 28 Apr 2016 15:40:48 +0900 Subject: [PATCH 01/16] external: add storage change handler - Storage change handler functions are added. They trace dbus signal from deviced. If storages are added/removed/changed, dbus signal is broadcasted. Thus the callbacks can be called according to the storage state change. Change-Id: Ib60f9f5b3bc316bb1c276dc0a7d30b881ca9da3a Signed-off-by: Taeyoung Kim --- src/storage-external-dbus.c | 251 ++++++++++++++++++++++++++++++++++++++++++++ src/storage-external-dbus.h | 5 + src/storage-external.c | 100 ++++++++++++++++++ src/storage-external.h | 2 + src/storage.c | 23 ++++ 5 files changed, 381 insertions(+) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 1f39362..2c63d76 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -33,8 +33,23 @@ #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 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; + static void storage_ext_release_internal(storage_ext_device *dev) { if (!dev) @@ -193,3 +208,239 @@ out: g_variant_unref(result); return ret; } + +static char *get_devnode_from_path(char *path) +{ + if (!path) + return NULL; + /* 1 means '/' */ + return path + strlen(STORAGE_EXT_PATH_DEVICES) + 1; +} + +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); +} + +static void storage_ext_device_added(GVariant *params, gpointer user_data) +{ + storage_ext_object_path_changed(STORAGE_EXT_ADDED, params, user_data); +} + +static void storage_ext_device_removed(GVariant *params, gpointer user_data) +{ + storage_ext_object_path_changed(STORAGE_EXT_REMOVED, params, user_data); +} + +static void storage_ext_device_changed(GVariant *params, gpointer user_data) +{ + storage_ext_device *dev; + dd_list *elem; + struct storage_ext_callback *callback; + int ret; + + if (!params) + return; + + dev = calloc(1, sizeof(storage_ext_device)); + if (!dev) + return; + + g_variant_get(params, "(issssssisibii)", + &dev->type, + &dev->devnode, + &dev->syspath, + &dev->fs_usage, + &dev->fs_type, + &dev->fs_version, + &dev->fs_uuid, + &dev->readonly, + &dev->mount_point, + &dev->state, + &dev->primary, + &dev->flags, + &dev->storage_id); + + DD_LIST_FOREACH(changed_list, elem, callback) { + if (!callback->func) + continue; + ret = callback->func(dev, STORAGE_EXT_CHANGED, callback->data); + if (ret < 0) + _E("Failed to call callback for devnode(%s, %d)", dev->devnode, ret); + } + + storage_ext_release_device(&dev); +} + +static void storage_ext_changed(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *signal, + GVariant *params, + gpointer user_data) +{ + size_t iface_len, signal_len; + + if (!params || !sender || !path || !iface || !signal) + return; + + 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); + return; + } + + if (!strncmp(iface, STORAGE_EXT_IFACE, iface_len) && + !strncmp(signal, STORAGE_EXT_DEVICE_CHANGED, signal_len)) { + storage_ext_device_changed(params, user_data); + return; + } +} + +int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) +{ + GDBusConnection *conn; + guint block_id = NULL, blockmanager_id = NULL; + struct storage_ext_callback *callback; + dd_list *elem; + + if (!func) + return -EINVAL; + + DD_LIST_FOREACH(changed_list, elem, callback) { + if (callback->func != func) + continue; + if (callback->block_id == 0 || callback->blockmanager_id == 0) + continue; + + return -EEXIST; + } + + callback = (struct storage_ext_callback *)malloc(sizeof(struct storage_ext_callback)); + if (!callback) { + _E("malloc() failed"); + return -ENOMEM; + } + + conn = get_dbus_connection(); + if (!conn) { + free(callback); + _E("Failed to get dbus connection"); + return -EPERM; + } + + 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) { + free(callback); + _E("Failed to subscrive bus signal"); + return -EPERM; + } + + callback->func = func; + callback->data = data; + callback->block_id = block_id; + callback->blockmanager_id = blockmanager_id; + + DD_LIST_APPEND(changed_list, callback); + + return 0; +} + +void storage_ext_unregister_device_change(storage_ext_changed_cb func) +{ + GDBusConnection *conn; + struct storage_ext_callback *callback; + dd_list *elem; + + if (!func) + return; + + conn = get_dbus_connection(); + if (!conn) { + _E("fail to get dbus connection"); + return; + } + + DD_LIST_FOREACH(changed_list, elem, callback) { + if (callback->func != 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-dbus.h b/src/storage-external-dbus.h index 7a0867a..98522d5 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -73,8 +73,13 @@ typedef struct _storage_ext_device { int storage_id; } storage_ext_device; +typedef int (*storage_ext_changed_cb)(storage_ext_device *dev, enum storage_ext_state state, void *data); + void storage_ext_release_device(storage_ext_device **dev); void storage_ext_release_list(dd_list **list); int storage_ext_get_list(dd_list **list); +int storage_ext_register_device_change(storage_ext_changed_cb func, void *data); +void storage_ext_unregister_device_change(storage_ext_changed_cb func); + #endif /* __STORAGE_EXTERNAL_DBUS_H__ */ diff --git a/src/storage-external.c b/src/storage-external.c index c671645..6308c3b 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -28,6 +28,8 @@ #include "log.h" #include "storage-external-dbus.h" +static dd_list *cb_list[STORAGE_CALLBACK_MAX]; + static int storage_ext_get_dev_state(storage_ext_device *dev, enum storage_ext_state blk_state, storage_state_e *state) @@ -91,4 +93,102 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * if (list) storage_ext_release_list(&list); return 0; +} + +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; + struct storage_cb_info *cb_info; + dd_list *elem; + storage_state_e state; + int ret; + + if (!dev) + return -EINVAL; + + if (type != STORAGE_CALLBACK_STATE) + return 0; + + 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; + } + + DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_STATE], elem, cb_info) + cb_info->state_cb(cb_info->id, state, cb_info->user_data); + + return 0; +} + +int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info) +{ + struct storage_cb_info *cb_info; + dd_list *elem; + int ret, n; + + if (type < 0 || type >= STORAGE_CALLBACK_MAX) + return -EINVAL; + + if (!info) + 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); + 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; + } + + /* add device changed callback to list (local) */ + cb_info = malloc(sizeof(struct storage_cb_info)); + if (!cb_info) + return -errno; + + memcpy(cb_info, info, sizeof(struct storage_cb_info)); + DD_LIST_APPEND(cb_list[type], cb_info); + + return 0; +} + +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; + + 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; + } + + if (!cb_info) + return -EINVAL; + + /* remove device callback from list (local) */ + 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); + + return 0; } \ No newline at end of file diff --git a/src/storage-external.h b/src/storage-external.h index 45c4167..cf5217b 100755 --- a/src/storage-external.h +++ b/src/storage-external.h @@ -22,5 +22,7 @@ #include "storage-external-dbus.h" int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *user_data); +int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info); +int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info *info); #endif /* __STORAGE_EXTERNAL_H__ */ diff --git a/src/storage.c b/src/storage.c index cc04ab5..e6a54f7 100644 --- a/src/storage.c +++ b/src/storage.c @@ -215,6 +215,8 @@ API int storage_get_state(int storage_id, storage_state_e *state) API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callback, void *user_data) { const struct storage_ops *st; + struct storage_cb_info info; + int ret; dd_list *elem; if (!callback) { @@ -228,6 +230,15 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca return STORAGE_ERROR_NONE; /* external storage */ + info.id = storage_id; + info.state_cb = callback; + info.user_data = user_data; + + ret = storage_ext_register_cb(STORAGE_CALLBACK_STATE, &info); + if (ret < 0) { + _E("Failed to register callback : id(%d)", storage_id); + return STORAGE_ERROR_OPERATION_FAILED; + } return STORAGE_ERROR_NONE; } @@ -235,6 +246,8 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb callback) { const struct storage_ops *st; + struct storage_cb_info info; + int ret; dd_list *elem; if (!callback) { @@ -247,6 +260,16 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb if (st->storage_id == storage_id) return STORAGE_ERROR_NONE; + /* external storage */ + info.id = storage_id; + info.state_cb = callback; + + ret = storage_ext_unregister_cb(STORAGE_CALLBACK_STATE, &info); + if (ret < 0) { + _E("Failed to unregister callback : id(%d)", storage_id); + return STORAGE_ERROR_OPERATION_FAILED; + } + return STORAGE_ERROR_NONE; } -- 2.7.4 From f417cc7beddef2029c733c1a524eb823134fc28c Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 28 Apr 2016 15:46:24 +0900 Subject: [PATCH 02/16] external: add function to get root path - External storages are handled by deviced, and deviced knows the information about root paths of storages. Thus dbus method from deviced is used to get root path information. Change-Id: I5ca86c1c9280bacc78d7f07fc55617ac9c397bb4 Signed-off-by: Taeyoung Kim --- src/storage-external-dbus.c | 27 +++++++++++++++++++++++++++ src/storage-external-dbus.h | 2 ++ src/storage-external.c | 30 +++++++++++++++++++++++++++++- src/storage-external.h | 1 + src/storage.c | 15 ++++++++++++++- 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 2c63d76..e4f4c49 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -444,3 +444,30 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) free(callback); } } + +int storage_ext_get_device_info(int storage_id, storage_ext_device *info) +{ + GVariant *result; + + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "GetDeviceInfoByID", + g_variant_new("(i)", storage_id)); + if (!result) { + _E("There is no storage with the storage id (%d)", storage_id); + return -ENODEV; + } + + 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); + + return 0; +} diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 98522d5..e9db898 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -82,4 +82,6 @@ int storage_ext_get_list(dd_list **list); 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); + #endif /* __STORAGE_EXTERNAL_DBUS_H__ */ diff --git a/src/storage-external.c b/src/storage-external.c index 6308c3b..63d564a 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -191,4 +191,32 @@ int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info storage_ext_unregister_device_change(storage_ext_state_changed); return 0; -} \ No newline at end of file +} + +int storage_ext_get_root(int storage_id, char *path, size_t len) +{ + storage_ext_device *dev; + int ret; + + if (storage_id < 0 || !path) + return -EINVAL; + + dev = calloc(1, sizeof(storage_ext_device)); + if (!dev) { + _E("calloc failed"); + return -ENOMEM; + } + + 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); + goto out; + } + + snprintf(path, len, "%s", dev->mount_point); + ret = 0; + +out: + storage_ext_release_device(&dev); + return ret; +} diff --git a/src/storage-external.h b/src/storage-external.h index cf5217b..a002c0b 100755 --- a/src/storage-external.h +++ b/src/storage-external.h @@ -24,5 +24,6 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *user_data); int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info); int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info *info); +int storage_ext_get_root(int storage_id, char *path, size_t len); #endif /* __STORAGE_EXTERNAL_H__ */ diff --git a/src/storage.c b/src/storage.c index e6a54f7..275b8a9 100644 --- a/src/storage.c +++ b/src/storage.c @@ -82,6 +82,8 @@ API int storage_get_root_directory(int storage_id, char **path) { const struct storage_ops *st; dd_list *elem; + char root[PATH_MAX]; + int ret; if (!path || storage_id < 0) { _E("Invalid parameger"); @@ -100,7 +102,18 @@ API int storage_get_root_directory(int storage_id, char **path) return STORAGE_ERROR_NONE; } - /* TODO external storage */ + /* 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); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + *path = strdup(root); + if (!*path) { + _E("Failed to copy the root string : %d", errno); + return STORAGE_ERROR_OUT_OF_MEMORY; + } return STORAGE_ERROR_NONE; } -- 2.7.4 From dd4cb30512c937ca15e6899edadb4f5d1b672d0b Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 28 Apr 2016 15:51:26 +0900 Subject: [PATCH 03/16] external: add function to get state of storages - Storage states are delivered from deviced. To get the information, dbus method is used. Change-Id: Ib6c03dae93e428cadd6f484cc5b84e2e12bf1050 Signed-off-by: Taeyoung Kim --- src/storage-external.c | 29 +++++++++++++++++++++++++++++ src/storage-external.h | 1 + src/storage.c | 10 +++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/storage-external.c b/src/storage-external.c index 63d564a..8fdde8c 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -220,3 +220,32 @@ out: storage_ext_release_device(&dev); return ret; } + +int storage_ext_get_state(int storage_id, storage_state_e *state) +{ + storage_ext_device *dev; + int ret; + + if (storage_id < 0 || !state) + return -EINVAL; + + dev = calloc(1, sizeof(storage_ext_device)); + if (!dev) { + _E("calloc failed"); + return -ENOMEM; + } + + 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); + 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); + +out: + storage_ext_release_device(&dev); + return ret; +} diff --git a/src/storage-external.h b/src/storage-external.h index a002c0b..a9046af 100755 --- a/src/storage-external.h +++ b/src/storage-external.h @@ -25,5 +25,6 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info); int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info *info); int storage_ext_get_root(int storage_id, char *path, size_t len); +int storage_ext_get_state(int storage_id, storage_state_e *state); #endif /* __STORAGE_EXTERNAL_H__ */ diff --git a/src/storage.c b/src/storage.c index 275b8a9..3e372a8 100644 --- a/src/storage.c +++ b/src/storage.c @@ -205,9 +205,11 @@ API int storage_get_type(int storage_id, storage_type_e *type) API int storage_get_state(int storage_id, storage_state_e *state) { const struct storage_ops *ops; + storage_state_e st; dd_list *elem; + int ret; - if (!state) { + if (!state || storage_id < 0) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -221,7 +223,13 @@ 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); + return STORAGE_ERROR_OPERATION_FAILED; + } + *state = st; return STORAGE_ERROR_NONE; } -- 2.7.4 From 35f081ba2bbe21fb2423dcd85605332f91b82d56 Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 28 Apr 2016 15:54:36 +0900 Subject: [PATCH 04/16] external: add function to get type - If a storage is not the one of internal storages, it is external storage. Change-Id: Idd2e4bac3c398c91ccb0f3b2891a143c9fa95100 Signed-off-by: Taeyoung Kim --- src/storage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/storage.c b/src/storage.c index 3e372a8..7f56f52 100644 --- a/src/storage.c +++ b/src/storage.c @@ -198,6 +198,7 @@ API int storage_get_type(int storage_id, storage_type_e *type) } /* external storage */ + *type = STORAGE_TYPE_EXTERNAL; return STORAGE_ERROR_NONE; } -- 2.7.4 From eebcfd39a817a7e2cb89ae2a1deb9f7beedd414b Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 28 Apr 2016 15:57:17 +0900 Subject: [PATCH 05/16] external: add function to get specific directories - The specific directories are under the root path of external storage. - Ringtone path is not supported on external storages. Change-Id: Ie7e13d19a30dbe8e6b874eba98f498c81c5da0a0 Signed-off-by: Taeyoung Kim --- src/storage.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/storage.c b/src/storage.c index 7f56f52..41a3b3b 100644 --- a/src/storage.c +++ b/src/storage.c @@ -167,7 +167,18 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p } /* external storage */ - return STORAGE_ERROR_NONE; + if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) { + _E("Not support directory : id(%d) type(%d)", storage_id, type); + 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); + return STORAGE_ERROR_OPERATION_FAILED; + } + + snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type]); out: *path = strdup(temp); -- 2.7.4 From fe84aaecd0ea19e055dbfc1b6f7d671e0da07920 Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 28 Apr 2016 17:54:52 +0900 Subject: [PATCH 06/16] external: add functions to get storage size - The functions to get storage size of given path are added. - For the following apis, default path is set to primary sdcard. int storage_get_external_memory_size(struct statvfs *buf) int storage_get_external_memory_size64(struct statvfs *buf) Change-Id: I0cfdcf2496849520cf0ef00a3ee2c3a70ec3c06c Signed-off-by: Taeyoung Kim --- include/common.h | 4 +++ src/statvfs.c | 52 +++++++++++++++++++++++++------ src/storage-external.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/storage-external.h | 3 ++ src/storage.c | 4 +-- 5 files changed, 135 insertions(+), 12 deletions(-) diff --git a/include/common.h b/include/common.h index 7ff5ce9..ec9ca67 100644 --- a/include/common.h +++ b/include/common.h @@ -24,6 +24,7 @@ extern "C" { #endif #include "storage-expand.h" +#include #ifndef API #define API __attribute__ ((visibility("default"))) @@ -75,6 +76,9 @@ static void __DESTRUCTOR__ module_exit(void) \ void add_device(const struct storage_ops *st); 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); + #ifdef __cplusplus } #endif diff --git a/src/statvfs.c b/src/statvfs.c index 52e030c..6ccdb5e 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -29,6 +29,7 @@ #include "log.h" #include "common.h" +#include "storage-external.h" #define MEMORY_GIGABYTE_VALUE 1073741824 #define MEMORY_MEGABYTE_VALUE 1048576 @@ -305,7 +306,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) return 0; } -static int mount_check(const char *path) +static int mount_check(char *path) { int ret = false; struct mntent *mnt; @@ -325,16 +326,16 @@ static int mount_check(const char *path) return ret; } -static const char *get_external_path(void) +static int get_external_path(char *path, size_t len) { - return tzplatform_mkpath(TZ_SYS_MEDIA, - EXTERNAL_MEMORY_NODE); + return storage_ext_get_primary_mmc_path(path, len); } -API int storage_get_external_memory_size(struct statvfs *buf) +int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) { struct statvfs_32 temp; int ret; + char ext_path[32]; _D("storage_get_external_memory_size"); if (!buf) { @@ -342,12 +343,22 @@ API int storage_get_external_memory_size(struct statvfs *buf) return -EINVAL; } - if (!mount_check(get_external_path())) { + if (path) + snprintf(ext_path, sizeof(ext_path), "%s", path); + else { + ret = get_external_path(ext_path, sizeof(ext_path)); + if (ret < 0) { + _E("Failed to get external path(%d)", ret); + return ret; + } + } + + if (!mount_check(ext_path)) { memset(buf, 0, sizeof(struct statvfs_32)); return 0; } - ret = get_memory_size(get_external_path(), &temp); + ret = get_memory_size(ext_path, &temp); if (ret) { _E("fail to get memory size"); return -errno; @@ -357,9 +368,10 @@ API int storage_get_external_memory_size(struct statvfs *buf) return 0; } -API int storage_get_external_memory_size64(struct statvfs *buf) +int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf) { int ret; + char ext_path[32]; _D("storage_get_external_memory_size64"); if (!buf) { @@ -367,12 +379,22 @@ API int storage_get_external_memory_size64(struct statvfs *buf) return -EINVAL; } - if (!mount_check(get_external_path())) { + if (path) + snprintf(ext_path, sizeof(ext_path), "%s", path); + else { + ret = get_external_path(ext_path, sizeof(ext_path)); + if (ret < 0) { + _E("Failed to get external path(%d)", ret); + return ret; + } + } + + if (!mount_check(ext_path)) { memset(buf, 0, sizeof(struct statvfs)); return 0; } - ret = statvfs(get_external_path(), buf); + ret = statvfs(ext_path, buf); if (ret) { _E("fail to get memory size"); return -errno; @@ -380,3 +402,13 @@ API int storage_get_external_memory_size64(struct statvfs *buf) return 0; } + +API int storage_get_external_memory_size(struct statvfs *buf) +{ + return storage_get_external_memory_size_with_path(NULL, buf); +} + +API int storage_get_external_memory_size64(struct statvfs *buf) +{ + return storage_get_external_memory_size64_with_path(NULL, buf); +} diff --git a/src/storage-external.c b/src/storage-external.c index 8fdde8c..d6d6bca 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -60,6 +60,62 @@ static int storage_ext_get_dev_state(storage_ext_device *dev, } } +int storage_ext_get_space(int storage_id, + unsigned long long *total, unsigned long long *available) +{ + storage_state_e state; + struct statvfs s; + int ret; + unsigned long long t = 0, a = 0; + storage_ext_device *dev; + + if (storage_id < 0) + return -EINVAL; + + dev = calloc(1, sizeof(storage_ext_device)); + if (!dev) { + _E("calloc failed"); + return -ENOMEM; + } + + 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); + 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); + goto out; + } + + if (state >= STORAGE_STATE_MOUNTED) { +#ifndef __USE_FILE_OFFSET64 + ret = storage_get_external_memory_size_with_path(dev->mount_point, &s); +#else + 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); + goto out; + } + + t = (unsigned long long)s.f_frsize*s.f_blocks; + a = (unsigned long long)s.f_bsize*s.f_bavail; + } + + if (total) + *total = t; + if (available) + *available = a; + + ret = 0; +out: + storage_ext_release_device(&dev); + return ret; +} + int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *user_data) { int ret; @@ -249,3 +305,31 @@ out: storage_ext_release_device(&dev); return ret; } + +int storage_ext_get_primary_mmc_path(char *path, size_t len) +{ + dd_list *list = NULL, *elem; + storage_ext_device *dev; + int ret; + + ret = storage_ext_get_list(&list); + if (ret < 0) { + _E("Failed to get external storage list from deviced (%d)", errno); + return ret; + } + + DD_LIST_FOREACH(list, elem, dev) { + if (dev->primary) { + snprintf(path, len, "%s", dev->mount_point); + ret = 0; + goto out; + } + } + + ret = -ENODEV; + +out: + if (list) + storage_ext_release_list(&list); + return ret; +} diff --git a/src/storage-external.h b/src/storage-external.h index a9046af..c7bd9fd 100755 --- a/src/storage-external.h +++ b/src/storage-external.h @@ -21,10 +21,13 @@ #include "common.h" #include "storage-external-dbus.h" +int storage_ext_get_space(int storage_id, + unsigned long long *total, unsigned long long *available); int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *user_data); int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info); int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info *info); int storage_ext_get_root(int storage_id, char *path, size_t len); int storage_ext_get_state(int storage_id, storage_state_e *state); +int storage_ext_get_primary_mmc_path(char *path, size_t len); #endif /* __STORAGE_EXTERNAL_H__ */ diff --git a/src/storage.c b/src/storage.c index 41a3b3b..c71af5c 100644 --- a/src/storage.c +++ b/src/storage.c @@ -327,7 +327,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) } /* external storage */ - ret = 0; + ret = storage_ext_get_space(storage_id, &total, NULL); out: if (ret < 0) { @@ -360,7 +360,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) } /* external storage */ - ret = 0; + ret = storage_ext_get_space(storage_id,NULL, &avail); out: if (ret < 0) { -- 2.7.4 From 04377774d7c6e597fb572bf78a11746c882f419b Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Tue, 10 May 2016 19:36:12 +0900 Subject: [PATCH 07/16] storage id: return NOT_SUPPORTED if storage id is invalid - When storage id is invalid, the apis should return NOT_SUPPORTED. This is for backward compatibility. Change-Id: I5c54f0675072979dfc42242e5ce9b8efc438190d Signed-off-by: Taeyoung Kim --- src/storage-external.c | 12 +++++++++--- src/storage.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/storage-external.c b/src/storage-external.c index d6d6bca..bd9a8e1 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -70,7 +70,7 @@ int storage_ext_get_space(int storage_id, storage_ext_device *dev; if (storage_id < 0) - return -EINVAL; + return -ENOTSUP; dev = calloc(1, sizeof(storage_ext_device)); if (!dev) { @@ -254,7 +254,10 @@ int storage_ext_get_root(int storage_id, char *path, size_t len) storage_ext_device *dev; int ret; - if (storage_id < 0 || !path) + if (storage_id < 0) + return -ENOTSUP; + + if (!path) return -EINVAL; dev = calloc(1, sizeof(storage_ext_device)); @@ -282,7 +285,10 @@ int storage_ext_get_state(int storage_id, storage_state_e *state) storage_ext_device *dev; int ret; - if (storage_id < 0 || !state) + if (storage_id < 0) + return -ENOTSUP; + + if (!state) return -EINVAL; dev = calloc(1, sizeof(storage_ext_device)); diff --git a/src/storage.c b/src/storage.c index c71af5c..b98fded 100644 --- a/src/storage.c +++ b/src/storage.c @@ -85,7 +85,10 @@ API int storage_get_root_directory(int storage_id, char **path) char root[PATH_MAX]; int ret; - if (!path || storage_id < 0) { + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + + if (!path) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -128,7 +131,10 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p dd_list *elem; bool found; - if (!path || storage_id < 0) { + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + + if (!path) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -195,7 +201,10 @@ API int storage_get_type(int storage_id, storage_type_e *type) const struct storage_ops *st; dd_list *elem; - if (!type || storage_id < 0) { + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + + if (!type) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -221,7 +230,10 @@ API int storage_get_state(int storage_id, storage_state_e *state) dd_list *elem; int ret; - if (!state || storage_id < 0) { + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + + if (!state) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -252,6 +264,9 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca int ret; dd_list *elem; + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + if (!callback) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; @@ -283,6 +298,9 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb int ret; dd_list *elem; + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + if (!callback) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; @@ -313,7 +331,10 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) int ret; dd_list *elem; - if (!bytes || storage_id < 0) { + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + + if (!bytes) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -332,6 +353,8 @@ 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); + if (ret == -ENOTSUP) + return STORAGE_ERROR_NOT_SUPPORTED; return STORAGE_ERROR_OPERATION_FAILED; } @@ -346,6 +369,9 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) int ret; dd_list *elem; + if (storage_id < 0) + return STORAGE_ERROR_NOT_SUPPORTED; + if (!bytes) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; @@ -365,6 +391,8 @@ 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); + if (ret == -ENOTSUP) + return STORAGE_ERROR_NOT_SUPPORTED; return STORAGE_ERROR_OPERATION_FAILED; } -- 2.7.4 From c075e0569c9f8059dbda2a7d8111143a35e7569d Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Tue, 10 May 2016 20:46:15 +0900 Subject: [PATCH 08/16] external: return storage size 0 if external storage does not exist - Previously, error was returned if external storage does not exist when getting storage size. But it is fixed to return size 0 for the backward compatibility. Change-Id: I84eca101a740729cc038f7e02b6db97536913ca9 Signed-off-by: Taeyoung Kim --- src/statvfs.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/statvfs.c b/src/statvfs.c index 6ccdb5e..dd038af 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -347,16 +347,16 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) snprintf(ext_path, sizeof(ext_path), "%s", path); else { ret = get_external_path(ext_path, sizeof(ext_path)); + if (ret == -ENODEV) + goto out_nodev; if (ret < 0) { _E("Failed to get external path(%d)", ret); return ret; } } - if (!mount_check(ext_path)) { - memset(buf, 0, sizeof(struct statvfs_32)); - return 0; - } + if (!mount_check(ext_path)) + goto out_nodev; ret = get_memory_size(ext_path, &temp); if (ret) { @@ -366,6 +366,10 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) memcpy(buf, &temp, sizeof(temp)); return 0; + +out_nodev: + memset(buf, 0, sizeof(struct statvfs_32)); + return 0; } int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf) @@ -383,16 +387,16 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf snprintf(ext_path, sizeof(ext_path), "%s", path); else { ret = get_external_path(ext_path, sizeof(ext_path)); + if (ret == -ENODEV) + goto out_nodev; if (ret < 0) { _E("Failed to get external path(%d)", ret); return ret; } } - if (!mount_check(ext_path)) { - memset(buf, 0, sizeof(struct statvfs)); - return 0; - } + if (!mount_check(ext_path)) + goto out_nodev; ret = statvfs(ext_path, buf); if (ret) { @@ -401,6 +405,10 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf } return 0; + +out_nodev: + memset(buf, 0, sizeof(struct statvfs)); + return 0; } API int storage_get_external_memory_size(struct statvfs *buf) -- 2.7.4 From 5f688b4cd7e379075443f5af6cbaa8ad11414dcb Mon Sep 17 00:00:00 2001 From: "sunm.lee" Date: Thu, 12 May 2016 17:11:44 +0900 Subject: [PATCH 09/16] storage: fix allocation mismatch The pointer variable 'dev' should be assinged to pointer of storage_ext_device, not pointer of (storage_ext_device *). Change-Id: Ic9a82c0849b411bca44b95db564f0fd731ea6eba Signed-off-by: sunm.lee --- src/storage-external-dbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index e4f4c49..2d86e3c 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -236,7 +236,7 @@ static void storage_ext_object_path_changed(enum storage_ext_state state, if (!devnode) goto out; - dev = calloc(1, sizeof(storage_ext_device *)); + dev = calloc(1, sizeof(storage_ext_device)); if (!dev) goto out; -- 2.7.4 From 1e01e45514db486e6ae3191b00ef1b2b29b827e9 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 20 May 2016 17:21:46 +0900 Subject: [PATCH 10/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 11/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 12/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 13/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 14/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 15/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 16/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