external: add function to get root path 24/67724/3
authorTaeyoung Kim <ty317.kim@samsung.com>
Thu, 28 Apr 2016 06:46:24 +0000 (15:46 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Fri, 29 Apr 2016 01:25:58 +0000 (10:25 +0900)
- 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 <ty317.kim@samsung.com>
src/storage-external-dbus.c
src/storage-external-dbus.h
src/storage-external.c
src/storage-external.h
src/storage.c

index 2c63d76f6668abae6c91792cf8eb7401c7d02b3d..e4f4c4920a0de18b621a4cb280c8664022ea4b19 100755 (executable)
@@ -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;
+}
index 98522d5bebf74b4d32c976061e0e318bc05f76b1..e9db89884f5cf158af55d70913c38e44a7d00bc2 100644 (file)
@@ -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__ */
index 6308c3b9c0caf643dda7e6286504302d3f8ad928..63d564aa92f19b4456f74c833c9a1bdc8fa7037c 100755 (executable)
@@ -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;
+}
index cf5217be55d4e8bff065b8bca9f6376121451d48..a002c0bfb1659146b6570a692cd17fe5e0bd3a4e 100755 (executable)
@@ -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__ */
index e6a54f7fbd8ea1eeb71f05c4c78240f16df9e06c..275b8a93aa268797a7d370253bc64fe1de8055c9 100644 (file)
@@ -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;
 }