#include "log.h"
#include "storage-external-dbus.h"
+#define EXTERNAL_STORAGE_PATH "/run/external-storage"
+#define PATH_LEN 55
+
static dd_list *cb_list[STORAGE_CALLBACK_MAX];
static int storage_ext_get_dev_state(storage_ext_device *dev,
int storage_ext_get_root(int storage_id, char *path, size_t len)
{
+ FILE *fp;
storage_ext_device *dev;
- int ret;
+ char file_name[PATH_LEN];
+ int ret = 0;
if (storage_id < 0)
return -ENOTSUP;
if (!path)
return -EINVAL;
- dev = calloc(1, sizeof(storage_ext_device));
- if (!dev) {
+ snprintf(file_name, PATH_LEN, EXTERNAL_STORAGE_PATH"/%d", storage_id);
+
+ if (access(file_name, R_OK) == 0) {
+ fp = fopen(file_name, "r");
+ if (!fp) {
+ _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE
+ ret = -ENODEV;
+ goto out;
+ }
+
+ ret = fscanf(fp, "%s", path);
+ if (ret <= 0) {
+ ret = -ENODEV;
+ _D("Failed to get path");
+ fclose(fp);
+ goto out;
+ }
+ fclose(fp);
+ } else {
+ dev = calloc(1, sizeof(storage_ext_device));
+ if (!dev) {
//LCOV_EXCL_START System Error
- _E("calloc failed");
- return -ENOMEM;
+ _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); //LCOV_EXCL_LINE
- goto out;
+ 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); //LCOV_EXCL_LINE
+ storage_ext_release_device(&dev);
+ goto out;
+ }
+
+ snprintf(path, len, "%s", dev->mount_point);
+ storage_ext_release_device(&dev);
}
- snprintf(path, len, "%s", dev->mount_point);
ret = 0;
out:
- storage_ext_release_device(&dev);
return ret;
}