diff options
author | taeyoung <ty317.kim@samsung.com> | 2016-12-29 10:37:59 +0900 |
---|---|---|
committer | taeyoung <ty317.kim@samsung.com> | 2016-12-29 10:37:59 +0900 |
commit | 4131a226d2ee25123a0bc6bf6a27a8d697dd248e (patch) | |
tree | 683abe512ab96404169dcc28a2ce2af6b38c93de | |
parent | 923dc023a0ec3604c1c3a76ee63b421d773dc173 (diff) | |
parent | c9a2ee5ed1ae526d970ea84e5b9795456242c444 (diff) | |
download | libstorage-4131a226d2ee25123a0bc6bf6a27a8d697dd248e.tar.gz libstorage-4131a226d2ee25123a0bc6bf6a27a8d697dd248e.tar.bz2 libstorage-4131a226d2ee25123a0bc6bf6a27a8d697dd248e.zip |
Merge branch 'tizen_3.0' into tizensubmit/tizen/20161229.040631accepted/tizen/wearable/20161229.233136accepted/tizen/tv/20161229.233117accepted/tizen/mobile/20161229.233048accepted/tizen/ivi/20161229.233155accepted/tizen/common/20161229.140119
Signed-off-by: taeyoung <ty317.kim@samsung.com>
Change-Id: Ife2facb5e34e5d7684935a59a13562c4bee61d7c
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | include/storage-experimental.h | 62 | ||||
-rw-r--r-- | include/storage-internal.h | 20 | ||||
-rwxr-xr-x | src/storage-external-dbus.c | 4 | ||||
-rwxr-xr-x | src/storage-external.c | 52 | ||||
-rwxr-xr-x | src/storage-inhouse.c | 7 |
6 files changed, 112 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3169d78..20f7f7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,8 @@ ENDFOREACH(flag) SET(HEADERS include/storage.h include/storage-expand.h - include/storage-internal.h) + include/storage-internal.h + include/storage-experimental.h) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g") diff --git a/include/storage-experimental.h b/include/storage-experimental.h new file mode 100644 index 0000000..a86b272 --- /dev/null +++ b/include/storage-experimental.h @@ -0,0 +1,62 @@ +/* + * 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 <tizen.h> + +#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 storage type (internal or external). + * @param[out] dev the kind of storage device for external type (sdcard, usb). If type is #STORAGE_TYPE_EXTERNAL, then value of this param is invalid. + * + * @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/include/storage-internal.h b/include/storage-internal.h index 14e81cb..391a721 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -53,26 +53,6 @@ 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 f389391..a3a7c52 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -410,8 +410,10 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) &info->readonly, &info->mount_point, &info->state, &info->primary, &info->flags, &info->storage_id); - } else + } else { + _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE return -ENODEV; + } g_variant_unref(result); diff --git a/src/storage-external.c b/src/storage-external.c index 9eba26d..42ea2e8 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -28,6 +28,9 @@ #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, @@ -353,8 +356,11 @@ int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info 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]; + char *tmp; + int ret = 0; if (storage_id < 0) return -ENOTSUP; @@ -362,25 +368,47 @@ int storage_ext_get_root(int storage_id, char *path, size_t len) 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; + } + + tmp = fgets(path, len, fp); + fclose(fp); + if (!tmp) { + ret = -ENODEV; + _D("Failed to get path"); + goto out; + } + + } 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; } diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 7b89923..6dfd4f1 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -26,6 +26,7 @@ #include "log.h" #include "storage-internal.h" #include "storage-external-dbus.h" +#include "storage-experimental.h" /* Get compat path from origin Multi-user path @@ -176,7 +177,7 @@ API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e if (storage_id < 0) { _E("Invalid parameger"); - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_NO_DEVICE; } if (!type) { @@ -194,6 +195,8 @@ API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e _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) { @@ -206,7 +209,7 @@ API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e 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; + ret = STORAGE_ERROR_NO_DEVICE; goto out; } |