From: Taeyoung Kim Date: Thu, 28 Apr 2016 06:46:24 +0000 (+0900) Subject: external: add function to get root path X-Git-Tag: submit/tizen/20160510.075001~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f417cc7beddef2029c733c1a524eb823134fc28c;p=platform%2Fcore%2Fsystem%2Flibstorage.git 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 --- 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; }