From 6e5c758d6678b5906952d6ef253ed9107ba61b49 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 12 Jun 2018 11:30:07 +0900 Subject: [PATCH] Make a new public api: storage_get_type_dev Change-Id: I318bd964d15b61bc0627b536e4a101ba27b4528a Signed-off-by: pr.jung --- CMakeLists.txt | 3 +- include/storage-expand.h | 24 ++++++++++++++++ include/storage-experimental.h | 62 ------------------------------------------ src/storage-inhouse.c | 55 ------------------------------------- src/storage.c | 45 ++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 119 deletions(-) delete mode 100644 include/storage-experimental.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 20f7f7e..3169d78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,7 @@ ENDFOREACH(flag) SET(HEADERS include/storage.h include/storage-expand.h - include/storage-internal.h - include/storage-experimental.h) + include/storage-internal.h) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g") diff --git a/include/storage-expand.h b/include/storage-expand.h index 5db5a9b..d5c0843 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -349,6 +349,30 @@ int storage_get_available_space(int storage_id, unsigned long long *bytes); /** + * @brief Gets the type and the kind of external device for the given storage id. + * + * @since_tizen 5.0 + * + * @remarks This function works only for external storages. + * If @a type is #STORAGE_TYPE_INTERNAL, this function returns #STORAGE_ERROR_INVALID_PARAMETER and @a dev is unchanged. + * + * @param[in] storage_id The storage id + * @param[out] type The storage @a type (internal or external). If @a type is #STORAGE_TYPE_INTERNAL, this function returns #STORAGE_ERROR_INVALID_PARAMETER and @a dev is unchanged. + * @param[out] dev The storage device for external storage. + * + * @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_OPERATION_FAILED Operation failed + */ +int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev); + + +/** * @} */ diff --git a/include/storage-experimental.h b/include/storage-experimental.h deleted file mode 100644 index 5f547be..0000000 --- a/include/storage-experimental.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * storage - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __STORAGE_EXPERIMENTAL_H__ -#define __STORAGE_EXPERIMENTAL_H__ - -#ifdef __cplusplus -extern "C" { -#endif - - -/** - * @addtogroup CAPI_SYSTEM_STORAGE_MODULE - * @{ - */ - -#include - -#define STORAGE_ERROR_NO_DEVICE TIZEN_ERROR_NO_SUCH_DEVICE - -/** - * @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] type The storage @a type (internal or external). - * @param[out] dev The storage device for external storage. If @a type is #STORAGE_TYPE_INTERNAL, then value of @a dev should be ignored. - * - * @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_NO_DEVICE No such device - */ -int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif -#endif /* __STORAGE_EXPERIMENTAL_H__ */ diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index a736890..34ec31d 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -26,7 +26,6 @@ #include "log.h" #include "storage-internal.h" #include "storage-external-dbus.h" -#include "storage-experimental.h" /* Get compat path from origin Multi-user path @@ -182,57 +181,3 @@ 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_NO_DEVICE; - } - - 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; - } - if (*type == STORAGE_TYPE_INTERNAL) - return STORAGE_ERROR_NONE; - - 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_NO_DEVICE; - goto out; - } - - if (ext_dev->type == STORAGE_EXT_SCSI) - *dev = STORAGE_DEV_EXT_USB_MASS_STORAGE; - else if (ext_dev->type == STORAGE_EXT_MMC) - *dev = STORAGE_DEV_EXT_SDCARD; - 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; -} diff --git a/src/storage.c b/src/storage.c index d79a00d..9a45507 100644 --- a/src/storage.c +++ b/src/storage.c @@ -603,6 +603,51 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac 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 || !type || !dev) { + _E("Invalid parameter"); + 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; + } + if (*type == STORAGE_TYPE_INTERNAL || *type == STORAGE_TYPE_EXTENDED_INTERNAL) + return STORAGE_ERROR_INVALID_PARAMETER; + + 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_OPERATION_FAILED; + goto out; + } + + if (ext_dev->type == STORAGE_EXT_SCSI) + *dev = STORAGE_DEV_EXT_USB_MASS_STORAGE; + else if (ext_dev->type == STORAGE_EXT_MMC) + *dev = STORAGE_DEV_EXT_SDCARD; + 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; +} + static void __CONSTRUCTOR__ init(void) { const char *tmp; -- 2.7.4