From 50f8d81235a4fc0781a13ff59e376df941b9af75 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 8 Nov 2016 15:08:26 +0900 Subject: [PATCH] Add inhouse api to get storage type and the kind of external device Change-Id: Iac21489f726cda37c148522d34163e97f04066a3 Signed-off-by: pr.jung --- include/storage-internal.h | 20 ++++++++++++++++++ src/storage-external-dbus.c | 17 ++++++++------- src/storage-inhouse.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 7 deletions(-) diff --git a/include/storage-internal.h b/include/storage-internal.h index 391a721..14e81cb 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -53,6 +53,26 @@ extern "C" { */ int storage_get_primary_sdcard(int *storage_id, char **path); +/** + * @brief Get the type and the kind of external device for given storage id. + * + * @since_tizen 3.0 + * + * @param[in] storage_id The storage id + * @param[out] storage type (internal, external). + * @param[out] the kind of storage device for external type (sdcard, usb). + * + * @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_OUT_OF_MEMORY Out of memory + * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported + * @retval #STORAGE_ERROR_NO_DEVICE No such device + */ +int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev); + int storage_get_compat_internal_path(const char* origin, int len, char* compat); int storage_get_origin_internal_path(const char* compat, int len, char* origin); diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 92c4dc1..f389391 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -402,13 +402,16 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) 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); + if (g_variant_check_format_string(result, "(issssssisibii)", true)) { + 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); + } else + return -ENODEV; g_variant_unref(result); diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index a8031bb..72eddac 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -168,3 +168,53 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) return STORAGE_ERROR_NONE; } + +API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev) +{ + storage_ext_device *ext_dev; + int ret; + + if (storage_id < 0) { + _E("Invalid parameger"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + if (!type) { + _E("Invalid parameger"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (!dev) { + _E("Invalid parameger"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + ret = storage_get_type(storage_id, type); + if (ret != STORAGE_ERROR_NONE) { + _E("Failed to get storage type: %d", ret); + return ret; + } + + ext_dev = calloc(1, sizeof(storage_ext_device)); + if (!ext_dev) { +//LCOV_EXCL_START System Error + _E("calloc failed"); + return STORAGE_ERROR_OUT_OF_MEMORY; +//LCOV_EXCL_STOP + } + + ret = storage_ext_get_device_info(storage_id, ext_dev); + if (ret < 0) { + _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE + ret = STORAGE_ERROR_NOT_SUPPORTED; + goto out; + } + + *dev = ext_dev->type; + ret = STORAGE_ERROR_NONE; + _I("type: %d(internal:0, external:1) dev: %d(sdcard: 1001, usb: 1002)", *type, *dev); + +out: + storage_ext_release_device(&ext_dev); + return ret; +} -- 2.7.4