From 8291f86520608ea2237374944b477548bbb1097f Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 11 May 2017 20:43:06 +0900 Subject: [PATCH 01/16] Use tzplatform-config for storage_get_directory Change-Id: Ic079a84945fa0c6f55367c9d4c90321b7b2133cc Signed-off-by: pr.jung --- src/storage.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/storage.c b/src/storage.c index fa719ec..598a289 100644 --- a/src/storage.c +++ b/src/storage.c @@ -20,22 +20,24 @@ #include #include #include +#include #include "common.h" #include "list.h" #include "log.h" #include "storage-external.h" -const char *dir_path[STORAGE_DIRECTORY_MAX] = { - [STORAGE_DIRECTORY_IMAGES] = "Images", - [STORAGE_DIRECTORY_SOUNDS] = "Sounds", - [STORAGE_DIRECTORY_VIDEOS] = "Videos", - [STORAGE_DIRECTORY_CAMERA] = "DCIM", - [STORAGE_DIRECTORY_DOWNLOADS] = "Downloads", - [STORAGE_DIRECTORY_MUSIC] = "Music", - [STORAGE_DIRECTORY_DOCUMENTS] = "Documents", - [STORAGE_DIRECTORY_OTHERS] = "Others", - [STORAGE_DIRECTORY_SYSTEM_RINGTONES] = "", +const char *dir_path[STORAGE_DIRECTORY_MAX]; + +const int tz_id[STORAGE_DIRECTORY_MAX] = { + [STORAGE_DIRECTORY_IMAGES] = TZ_USER_IMAGES, + [STORAGE_DIRECTORY_SOUNDS] = TZ_USER_SOUNDS, + [STORAGE_DIRECTORY_VIDEOS] = TZ_USER_VIDEOS, + [STORAGE_DIRECTORY_CAMERA] = TZ_USER_CAMERA, + [STORAGE_DIRECTORY_DOWNLOADS] = TZ_USER_DOWNLOADS, + [STORAGE_DIRECTORY_MUSIC] = TZ_USER_MUSIC, + [STORAGE_DIRECTORY_DOCUMENTS] = TZ_USER_DOCUMENTS, + [STORAGE_DIRECTORY_OTHERS] = TZ_USER_OTHERS, }; static dd_list *st_int_head; /* Internal storage list */ @@ -525,3 +527,21 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac return STORAGE_ERROR_NONE; } + +static void __CONSTRUCTOR__ init(void) +{ + const char *tmp; + char *token; + int i; + + for (i = 0 ; i <= STORAGE_DIRECTORY_OTHERS ; i++) { + tmp = tzplatform_getenv(tz_id[i]); + if (tmp != NULL) { + token = rindex(tmp, '/'); + if (token != NULL) { + token++; + dir_path[i] = strdup(token); + } + } + } +} -- 2.7.4 From 2b4fc11bbac5e320f6ad3ce3e548e0bfcd7d17f5 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 13 Apr 2017 16:18:10 +0900 Subject: [PATCH 02/16] Add EXTENDED_INTERNAL type for extended internal storage Change-Id: I68d069cc718f3b735622fe20ee902b7c505f540e Signed-off-by: pr.jung --- include/storage-expand.h | 10 +++++---- include/storage-experimental.h | 4 ++-- src/storage-external-dbus.h | 1 + src/storage-external.c | 46 ++++++++++++++++++++++++++++++++++++------ src/storage-external.h | 2 +- src/storage.c | 28 +++++++++++++++++++------ 6 files changed, 72 insertions(+), 19 deletions(-) diff --git a/include/storage-expand.h b/include/storage-expand.h index b432382..5db5a9b 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -50,8 +50,9 @@ typedef enum { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ typedef enum { - STORAGE_TYPE_INTERNAL, /**< Internal device storage (built-in storage in a device, non-removable) */ - STORAGE_TYPE_EXTERNAL, /**< External storage */ + STORAGE_TYPE_INTERNAL, /**< Internal device storage (built-in storage in a device, non-removable) */ + STORAGE_TYPE_EXTERNAL, /**< External storage */ + STORAGE_TYPE_EXTENDED_INTERNAL, /**< Extended internal storage (External storage used as internal storage) (Since 4.0) */ } storage_type_e; @@ -249,8 +250,9 @@ int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb call * @since_tizen 3.0 */ typedef enum { - STORAGE_DEV_EXT_SDCARD = 1001, /**< sdcard device (external storage) */ - STORAGE_DEV_EXT_USB_MASS_STORAGE, /**< USB storage device (external storage) */ + STORAGE_DEV_EXT_SDCARD = 1001, /**< SD card device (external storage) */ + STORAGE_DEV_EXT_USB_MASS_STORAGE, /**< USB storage device (external storage) */ + STORAGE_DEV_EXTENDED_INTERNAL, /**< Extended internal storage device (External storage used as internal storage) (Since 4.0) */ } storage_dev_e; diff --git a/include/storage-experimental.h b/include/storage-experimental.h index a86b272..5f547be 100644 --- a/include/storage-experimental.h +++ b/include/storage-experimental.h @@ -39,8 +39,8 @@ extern "C" { * @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. + * @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 diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 0589959..a955aef 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -44,6 +44,7 @@ enum storage_ext_state { enum storage_ext_type { STORAGE_EXT_SCSI, STORAGE_EXT_MMC, + STORAGE_EXT_MMC_EXTENDED_INTERNAL, }; enum storage_ext_flags { diff --git a/src/storage-external.c b/src/storage-external.c index 42ea2e8..e498529 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -28,8 +28,9 @@ #include "log.h" #include "storage-external-dbus.h" -#define EXTERNAL_STORAGE_PATH "/run/external-storage" -#define PATH_LEN 55 +#define EXTERNAL_STORAGE_PATH "/run/external-storage" +#define EXTENDED_INTERNAL_PATH "/run/extended-internal-sd" +#define PATH_LEN 55 static dd_list *cb_list[STORAGE_CALLBACK_MAX]; @@ -151,8 +152,13 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * continue; } - ret_cb = callback(dev->storage_id, STORAGE_TYPE_EXTERNAL, - state, dev->mount_point, user_data); + if (dev->type == STORAGE_EXT_MMC_EXTENDED_INTERNAL) + ret_cb = callback(dev->storage_id, + STORAGE_TYPE_EXTENDED_INTERNAL, + state, dev->mount_point, user_data); + else + ret_cb = callback(dev->storage_id, STORAGE_TYPE_EXTERNAL, + state, dev->mount_point, user_data); if (!ret_cb) break; } @@ -215,6 +221,8 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st strdev = STORAGE_DEV_EXT_USB_MASS_STORAGE; else if (dev->type == STORAGE_EXT_MMC) strdev = STORAGE_DEV_EXT_SDCARD; + else if (dev->type == STORAGE_EXT_MMC_EXTENDED_INTERNAL) + strdev = STORAGE_DEV_EXTENDED_INTERNAL; else { _E("Invalid dev type (%d)", dev->type); return -EINVAL; @@ -354,11 +362,12 @@ int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info return 0; } -int storage_ext_get_root(int storage_id, char *path, size_t len) +int storage_ext_get_root(int storage_id, char *path, size_t len, bool *extendedinternal) { FILE *fp; storage_ext_device *dev; char file_name[PATH_LEN]; + char file_name2[PATH_LEN]; char *tmp; int ret = 0; @@ -367,8 +376,13 @@ int storage_ext_get_root(int storage_id, char *path, size_t len) if (!path) return -EINVAL; + if (!extendedinternal) + return -EINVAL; snprintf(file_name, PATH_LEN, EXTERNAL_STORAGE_PATH"/%d", storage_id); + snprintf(file_name2, PATH_LEN, EXTENDED_INTERNAL_PATH"/%d", storage_id); + + *extendedinternal = false; if (access(file_name, R_OK) == 0) { fp = fopen(file_name, "r"); @@ -385,7 +399,23 @@ int storage_ext_get_root(int storage_id, char *path, size_t len) _D("Failed to get path"); goto out; } + *extendedinternal = false; + } else if (access(file_name2, R_OK) == 0) { + fp = fopen(file_name2, "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; + } + *extendedinternal = true; } else { dev = calloc(1, sizeof(storage_ext_device)); if (!dev) { @@ -403,6 +433,10 @@ int storage_ext_get_root(int storage_id, char *path, size_t len) } snprintf(path, len, "%s", dev->mount_point); + if (dev->type == STORAGE_EXT_MMC_EXTENDED_INTERNAL) + *extendedinternal = true; + else + *extendedinternal = false; storage_ext_release_device(&dev); } @@ -441,7 +475,7 @@ int storage_ext_get_state(int storage_id, storage_state_e *state) if (ret < 0) _E("Failed to get state of storage id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE -out : +out: storage_ext_release_device(&dev); return ret; } diff --git a/src/storage-external.h b/src/storage-external.h index c7bd9fd..af36ed1 100755 --- a/src/storage-external.h +++ b/src/storage-external.h @@ -26,7 +26,7 @@ int storage_ext_get_space(int storage_id, 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); +int storage_ext_get_root(int storage_id, char *path, size_t len, bool *extendedinternal); int storage_ext_get_state(int storage_id, storage_state_e *state); int storage_ext_get_primary_mmc_path(char *path, size_t len); diff --git a/src/storage.c b/src/storage.c index 598a289..7b5a185 100644 --- a/src/storage.c +++ b/src/storage.c @@ -92,6 +92,7 @@ API int storage_get_root_directory(int storage_id, char **path) dd_list *elem; char root[PATH_MAX]; int ret; + bool extendedint; if (storage_id < 0) return STORAGE_ERROR_NOT_SUPPORTED; @@ -116,7 +117,7 @@ API int storage_get_root_directory(int storage_id, char **path) } /* external storage */ - ret = storage_ext_get_root(storage_id, root, sizeof(root)); + ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); if (ret < 0) { _E("Failed to get root path of external storage(%d, %d", storage_id, ret); //LCOV_EXCL_LINE return STORAGE_ERROR_INVALID_PARAMETER; @@ -140,6 +141,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p int ret; dd_list *elem; bool found; + bool extendedint; if (storage_id < 0) return STORAGE_ERROR_NOT_SUPPORTED; @@ -186,11 +188,14 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p return STORAGE_ERROR_NOT_SUPPORTED; } - ret = storage_ext_get_root(storage_id, root, sizeof(root)); + ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); if (ret < 0) { _E("Failed to get root dir for external storage(id:%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE - return STORAGE_ERROR_OPERATION_FAILED; + return STORAGE_ERROR_NOT_SUPPORTED; } + /* The operation is not decided */ + if (extendedint) + return STORAGE_ERROR_NOT_SUPPORTED; snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type]); @@ -208,6 +213,9 @@ API int storage_get_type(int storage_id, storage_type_e *type) { const struct storage_ops *st; dd_list *elem; + char root[PATH_MAX]; + int ret; + bool extendedint; if (storage_id < 0) return STORAGE_ERROR_NOT_SUPPORTED; @@ -226,7 +234,15 @@ API int storage_get_type(int storage_id, storage_type_e *type) } /* external storage */ - *type = STORAGE_TYPE_EXTERNAL; + ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); + if (ret < 0) { + _E("Failed to get type of external storage"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + if (extendedint) + *type = STORAGE_TYPE_EXTENDED_INTERNAL; + else + *type = STORAGE_TYPE_EXTERNAL; return STORAGE_ERROR_NONE; } @@ -471,7 +487,7 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, return STORAGE_ERROR_NOT_SUPPORTED; } - if (type != STORAGE_TYPE_EXTERNAL) { + if (type != STORAGE_TYPE_EXTERNAL && type != STORAGE_TYPE_EXTENDED_INTERNAL) { _E("Invalid type (%d)", type); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -505,7 +521,7 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac return STORAGE_ERROR_NOT_SUPPORTED; } - if (type != STORAGE_TYPE_EXTERNAL) { + if (type != STORAGE_TYPE_EXTERNAL && type != STORAGE_TYPE_EXTENDED_INTERNAL) { _E("Invalid type (%d)", type); return STORAGE_ERROR_INVALID_PARAMETER; } -- 2.7.4 From 2b7ef5a328bceb37cf518b80c7fbc72f55b0b660 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 20 Apr 2017 14:25:28 +0900 Subject: [PATCH 03/16] block: remove external-storage call if block module is not supported Do not send dbus method call for external storage if block module is not supported Change-Id: I05be8e80aba6e512067e1d5e9d0d6ba462a2aa1e Signed-off-by: pr.jung Signed-off-by: Jeong Donghwan --- src/statvfs.c | 8 ++++++++ src/storage-external-dbus.h | 1 + src/storage.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/statvfs.c b/src/statvfs.c index eda17bd..7b50dc4 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -346,6 +346,10 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) if (path) snprintf(ext_path, sizeof(ext_path), "%s", path); else { + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + goto out_nodev; + } ret = get_external_path(ext_path, sizeof(ext_path)); if (ret == -ENODEV) goto out_nodev; @@ -386,6 +390,10 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf if (path) snprintf(ext_path, sizeof(ext_path), "%s", path); else { + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + goto out_nodev; + } ret = get_external_path(ext_path, sizeof(ext_path)); if (ret == -ENODEV) goto out_nodev; diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index a955aef..c37881b 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -74,6 +74,7 @@ typedef struct _storage_ext_device { typedef int (*storage_ext_changed_cb)(storage_ext_device *dev, enum storage_ext_state state, void *data); +int storage_ext_is_supported(void); void storage_ext_release_device(storage_ext_device **dev); void storage_ext_release_list(dd_list **list); int storage_ext_get_list(dd_list **list); diff --git a/src/storage.c b/src/storage.c index 7b5a185..e644aec 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,6 +27,7 @@ #include "log.h" #include "storage-external.h" +#define BLOCK_CONF_FILE "/etc/deviced/block.conf" const char *dir_path[STORAGE_DIRECTORY_MAX]; const int tz_id[STORAGE_DIRECTORY_MAX] = { @@ -58,6 +59,21 @@ void remove_device(const struct storage_ops *st) DD_LIST_REMOVE(st_int_head, st); } +int storage_ext_is_supported(void) +{ + static int support = -1; + + if (support >= 0) + return support; + + if (access(BLOCK_CONF_FILE, R_OK) == 0) + support = 1; + else + support = 0; + + return support; +} + API int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data) { const struct storage_ops *st; @@ -77,6 +93,11 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v break; } + if (!storage_ext_is_supported()) { + _D("Block module is not enabled"); + return STORAGE_ERROR_NONE; + } + ret = storage_ext_foreach_device_list(callback, user_data); if (ret < 0) { _E("Failed to iterate external devices (%d)", ret); //LCOV_EXCL_LINE @@ -497,6 +518,11 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, return STORAGE_ERROR_INVALID_PARAMETER; } + if(!storage_ext_is_supported()) { + _E("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + /* external storage */ info.type = type; info.type_cb = callback; @@ -531,6 +557,11 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac return STORAGE_ERROR_INVALID_PARAMETER; } + if(!storage_ext_is_supported()) { + _E("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + } + /* external storage */ info.type = type; info.type_cb = callback; -- 2.7.4 From 720000d84cffc8face133b839dafc463c53d50ba Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 7 Sep 2017 17:03:05 +0900 Subject: [PATCH 04/16] storaged has block.conf from tizen 4.0 Change-Id: Ia633479c3cf86ac52b28342e248ce77fe5f5906f Signed-off-by: pr.jung --- src/storage.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/storage.c b/src/storage.c index e644aec..cd3e29a 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,7 +27,7 @@ #include "log.h" #include "storage-external.h" -#define BLOCK_CONF_FILE "/etc/deviced/block.conf" +#define BLOCK_CONF_FILE "/etc/storaged/block.conf" const char *dir_path[STORAGE_DIRECTORY_MAX]; const int tz_id[STORAGE_DIRECTORY_MAX] = { @@ -518,7 +518,7 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, return STORAGE_ERROR_INVALID_PARAMETER; } - if(!storage_ext_is_supported()) { + if (!storage_ext_is_supported()) { _E("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; } @@ -557,7 +557,7 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac return STORAGE_ERROR_INVALID_PARAMETER; } - if(!storage_ext_is_supported()) { + if (!storage_ext_is_supported()) { _E("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; } -- 2.7.4 From e75176390aba2c55c218e2b12037393a3babf805 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 20 Sep 2017 11:49:40 +0900 Subject: [PATCH 05/16] DD_LIST_FOREACH_SAFE should be used when there is node remove operation from list. Change-Id: I807635a8959bdc66a26f7b6544e01c56a0bcbdd5 Signed-off-by: pr.jung --- src/storage-external-dbus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index be20d3f..dcd1e9e 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -367,6 +367,7 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) GDBusConnection *conn; struct storage_ext_callback *callback; dd_list *elem; + dd_list *elem_n; if (!func) return; @@ -379,7 +380,7 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) //LCOV_EXCL_STOP } - DD_LIST_FOREACH(changed_list, elem, callback) { + DD_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) { if (callback->func != func) continue; if (callback->block_id > 0) -- 2.7.4 From fa8f2e4e89856d50005e95403e3d5c0002a99cb7 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 14 Dec 2017 17:13:31 +0900 Subject: [PATCH 06/16] Check type for registered callback - Storage type and registered callback type should be the same Change-Id: If9bc286b93595f5f92889b435bdeddfbfb7abc19 Signed-off-by: pr.jung --- src/storage-external.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/storage-external.c b/src/storage-external.c index e498529..aee5d6c 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -32,6 +32,8 @@ #define EXTENDED_INTERNAL_PATH "/run/extended-internal-sd" #define PATH_LEN 55 +#define LUKS_NAME "crypto_LUKS" + static dd_list *cb_list[STORAGE_CALLBACK_MAX]; static int storage_ext_get_dev_state(storage_ext_device *dev, @@ -203,6 +205,7 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st storage_state_e state; int ret; storage_dev_e strdev; + storage_type_e storage_type; const char *fstype, *fsuuid, *mountpath; if (!dev) @@ -217,13 +220,16 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st return ret; } - if (dev->type == STORAGE_EXT_SCSI) + if (dev->type == STORAGE_EXT_SCSI) { strdev = STORAGE_DEV_EXT_USB_MASS_STORAGE; - else if (dev->type == STORAGE_EXT_MMC) + storage_type = STORAGE_TYPE_EXTERNAL; + } else if (dev->type == STORAGE_EXT_MMC) { strdev = STORAGE_DEV_EXT_SDCARD; - else if (dev->type == STORAGE_EXT_MMC_EXTENDED_INTERNAL) + storage_type = STORAGE_TYPE_EXTERNAL; + } else if (dev->type == STORAGE_EXT_MMC_EXTENDED_INTERNAL) { strdev = STORAGE_DEV_EXTENDED_INTERNAL; - else { + storage_type = STORAGE_TYPE_EXTENDED_INTERNAL; + } else { _E("Invalid dev type (%d)", dev->type); return -EINVAL; } @@ -232,11 +238,17 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st fsuuid = (dev->fs_uuid ? (const char *)dev->fs_uuid : ""); mountpath = (dev->mount_point ? (const char *)dev->mount_point : ""); - DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) + if (!strncmp(fstype, LUKS_NAME, strlen(LUKS_NAME))) + storage_type = STORAGE_TYPE_EXTENDED_INTERNAL; + + DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) { + if (cb_info->type != storage_type) + continue; if (cb_info->type_cb) cb_info->type_cb(dev->storage_id, strdev, state, fstype, fsuuid, mountpath, dev->primary, dev->flags, cb_info->user_data); + } return 0; } -- 2.7.4 From fb66e415366c3c469cf3b1b4700a8b7ef305484d Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 13 Apr 2018 14:52:29 +0900 Subject: [PATCH 07/16] Add defense code for wrong use cases Only Tizen applications and user session daemons can use storage_get_root_directory(STORAGE_TYPE_INTERNAL, ...). Change-Id: I107b027a06843bbd88f7a1008f8051b6c5430b79 Signed-off-by: Hyotaek Shim (cherry picked from commit f47be2f7c4dc5e76912d814fb5dd72c1bf108090) --- src/storage.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/storage.c b/src/storage.c index cd3e29a..33bfc8e 100644 --- a/src/storage.c +++ b/src/storage.c @@ -28,6 +28,8 @@ #include "storage-external.h" #define BLOCK_CONF_FILE "/etc/storaged/block.conf" +#define USER_UID_START 5000 + const char *dir_path[STORAGE_DIRECTORY_MAX]; const int tz_id[STORAGE_DIRECTORY_MAX] = { @@ -123,6 +125,12 @@ API int storage_get_root_directory(int storage_id, char **path) return STORAGE_ERROR_INVALID_PARAMETER; } + if (storage_id == STORAGE_TYPE_INTERNAL && getuid() < USER_UID_START) { + _E("Only Tizen applications and user session daemons can use \ + storage_get_root_directory(STORAGE_TYPE_INTERNAL, ...)"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + /* internal storage */ DD_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) -- 2.7.4 From 7bc3514efd57a681f908fb8660f6200efd7473a2 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 26 Apr 2018 17:20:01 +0900 Subject: [PATCH 08/16] Only user session api calls can get internal storage root path Change-Id: Ifc044e9151a3b855c8a2ad1bddc82e55bd2e699b Signed-off-by: pr.jung --- src/storage.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/storage.c b/src/storage.c index 33bfc8e..d79a00d 100644 --- a/src/storage.c +++ b/src/storage.c @@ -81,18 +81,24 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v const struct storage_ops *st; dd_list *elem; int ret; + bool user = true; if (!callback) { _E("Invalid parameter"); return STORAGE_ERROR_INVALID_PARAMETER; } + if (getuid() < USER_UID_START) + user = false; + DD_LIST_FOREACH(st_int_head, elem, st) { - ret = callback(st->storage_id, st->type, st->get_state(), - st->root(), user_data); - /* if the return value is false, will be stop to iterate */ - if (!ret) - break; + if (user) { + ret = callback(st->storage_id, st->type, st->get_state(), + st->root(), user_data); + /* if the return value is false, will be stop to iterate */ + if (!ret) + break; + } } if (!storage_ext_is_supported()) { @@ -116,6 +122,7 @@ API int storage_get_root_directory(int storage_id, char **path) char root[PATH_MAX]; int ret; bool extendedint; + bool user = true; if (storage_id < 0) return STORAGE_ERROR_NOT_SUPPORTED; @@ -125,16 +132,19 @@ API int storage_get_root_directory(int storage_id, char **path) return STORAGE_ERROR_INVALID_PARAMETER; } - if (storage_id == STORAGE_TYPE_INTERNAL && getuid() < USER_UID_START) { - _E("Only Tizen applications and user session daemons can use \ - storage_get_root_directory(STORAGE_TYPE_INTERNAL, ...)"); - return STORAGE_ERROR_INVALID_PARAMETER; - } + if (getuid() < USER_UID_START) + user = false; /* internal storage */ DD_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; + if (!user) { + _E("Only Tizen applications and user session daemons can use \ + storage_get_root_directory(id , ...)"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + *path = strdup(st->root()); if (!*path) { //LCOV_EXCL_START System Error @@ -171,6 +181,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p dd_list *elem; bool found; bool extendedint; + bool user = true; if (storage_id < 0) return STORAGE_ERROR_NOT_SUPPORTED; @@ -194,7 +205,16 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p break; } + if (getuid() < USER_UID_START) + user = false; + if (found && st) { + if (!user) { + _E("Only Tizen applications and user session daemons can use \ + storage_get_directory(id, ...)"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + snprintf(root, sizeof(root), "%s", st->root()); if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) { temp2 = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR); -- 2.7.4 From 1d58b3a8ee4e75eca7df2e26dfd2f9cee5267c67 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 12 Jul 2018 13:29:48 +0900 Subject: [PATCH 09/16] Check block module enabled before sending GetMmcPrimary dbus method Change-Id: I2634ba2130c35f7c3ccca9e8164ac9c73a9d47a3 Signed-off-by: pr.jung (cherry picked from commit 924ade1b560e5798eb261dc1187df77eaa8f3410) --- include/common.h | 1 + src/storage-common.c | 20 +++++++++++++++++++- src/storage-inhouse.c | 3 +++ src/storage.c | 16 ---------------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/common.h b/include/common.h index f208338..dd6f966 100644 --- a/include/common.h +++ b/include/common.h @@ -84,6 +84,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf #define COMPAT_DIR "/opt/usr/media" int is_compat_bind_mount(void); +int storage_ext_is_supported(void); #ifdef __cplusplus } diff --git a/src/storage-common.c b/src/storage-common.c index ba76cc8..ea8e174 100644 --- a/src/storage-common.c +++ b/src/storage-common.c @@ -16,10 +16,12 @@ * limitations under the License. */ - +#include #include #include "common.h" +#define BLOCK_CONF_FILE "/etc/storaged/block.conf" + int is_compat_bind_mount(void) { struct libmnt_table *t = NULL; @@ -50,3 +52,19 @@ int is_compat_bind_mount(void) return 0; //LCOV_EXCL_STOP } + +int storage_ext_is_supported(void) +{ + static int support = -1; + + if (support >= 0) + return support; + + if (access(BLOCK_CONF_FILE, R_OK) == 0) + support = 1; + else + support = 0; + + return support; +} + diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index a736890..2c13dad 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -148,6 +148,9 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) if (!storage_id || !path) return STORAGE_ERROR_INVALID_PARAMETER; + if (!storage_ext_is_supported()) + return STORAGE_ERROR_NO_DEVICE; + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, diff --git a/src/storage.c b/src/storage.c index d79a00d..6fdc8f9 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,7 +27,6 @@ #include "log.h" #include "storage-external.h" -#define BLOCK_CONF_FILE "/etc/storaged/block.conf" #define USER_UID_START 5000 const char *dir_path[STORAGE_DIRECTORY_MAX]; @@ -61,21 +60,6 @@ void remove_device(const struct storage_ops *st) DD_LIST_REMOVE(st_int_head, st); } -int storage_ext_is_supported(void) -{ - static int support = -1; - - if (support >= 0) - return support; - - if (access(BLOCK_CONF_FILE, R_OK) == 0) - support = 1; - else - support = 0; - - return support; -} - API int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data) { const struct storage_ops *st; -- 2.7.4 From ed75692997a0034cc065aa7a144a09a04efd6e03 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 19 Jul 2018 11:16:24 +0900 Subject: [PATCH 10/16] Change internal storage media path in storage_get_directory() Before: /opt/usr/media After: /opt/usr/home/UID/media Change-Id: Ida39777ac40587719beb8d28b8f04172c98900e5 Signed-off-by: Hyotaek Shim --- src/storage-internal.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/storage-internal.c b/src/storage-internal.c index 7f5d359..0dadec9 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -15,6 +15,8 @@ */ +#include +#include #include #include #include @@ -61,11 +63,7 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava static const char *internal_get_root(void) { const char *ret; - - if (is_compat_bind_mount()) - ret = COMPAT_DIR; - else - ret = tzplatform_getenv(TZ_USER_CONTENT); + ret = tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT); return ret; } -- 2.7.4 From f3464b1c974aed47df9bb300f6d1aff6beb11e2f Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 19 Jul 2018 13:31:41 +0900 Subject: [PATCH 11/16] Minor fix on USER checking Change-Id: I861137d16ac40792a542247dc412aad74ad26045 Signed-off-by: Hyotaek Shim --- src/storage.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/storage.c b/src/storage.c index 6fdc8f9..93bb85c 100644 --- a/src/storage.c +++ b/src/storage.c @@ -72,7 +72,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v return STORAGE_ERROR_INVALID_PARAMETER; } - if (getuid() < USER_UID_START) + if (getuid() <= USER_UID_START) user = false; DD_LIST_FOREACH(st_int_head, elem, st) { @@ -116,7 +116,7 @@ API int storage_get_root_directory(int storage_id, char **path) return STORAGE_ERROR_INVALID_PARAMETER; } - if (getuid() < USER_UID_START) + if (getuid() <= USER_UID_START) user = false; /* internal storage */ @@ -124,8 +124,8 @@ API int storage_get_root_directory(int storage_id, char **path) if (st->storage_id != storage_id) continue; if (!user) { - _E("Only Tizen applications and user session daemons can use \ - storage_get_root_directory(id , ...)"); + _E("Only Tizen applications and user session daemons can use\ + storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -189,13 +189,13 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p break; } - if (getuid() < USER_UID_START) + if (getuid() <= USER_UID_START) user = false; if (found && st) { if (!user) { - _E("Only Tizen applications and user session daemons can use \ - storage_get_directory(id, ...)"); + _E("Only Tizen applications and user session daemons can use\ + storage_get_directory(INTERNAL_STORAGE_ID, ...)"); return STORAGE_ERROR_INVALID_PARAMETER; } -- 2.7.4 From d3af4819768727762b672f1557ca3d56a343dcda Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 19 Jul 2018 14:19:20 +0900 Subject: [PATCH 12/16] Add .gitignore Change-Id: I7cd08fc9b397d917391675f36df939b6f56de39b Signed-off-by: Hyotaek Shim --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9306ae6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cscope.files +cscope.out +tags -- 2.7.4 From f2de6606d32ec1b7dcbeb86b38de3b0cdfb62cb6 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 20 Jul 2018 10:57:16 +0900 Subject: [PATCH 13/16] Minor fixes: comments, license .. Change-Id: I09d102eae0b5990057c0492f52d5155243deff24 Signed-off-by: Hyotaek Shim (cherry picked from commit 5c437ddef63be7a6aa22966f7da70b3380441294) --- LICENSE => LICENSE.Apache-2.0 | 0 packaging/libstorage.spec | 5 ++--- src/storage.c | 9 +++++---- 3 files changed, 7 insertions(+), 7 deletions(-) rename LICENSE => LICENSE.Apache-2.0 (100%) diff --git a/LICENSE b/LICENSE.Apache-2.0 similarity index 100% rename from LICENSE rename to LICENSE.Apache-2.0 diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 57611e7..f050da4 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -1,6 +1,6 @@ Name: libstorage Summary: Library to get storage information -Version: 0.1.1 +Version: 1.0.0 Release: 0 Group: System/Libraries License: Apache-2.0 @@ -26,7 +26,6 @@ Requires: %{name} = %{version}-%{release} %description devel Library to get storage information (devel) - %prep %setup -q cp %{SOURCE1} . @@ -45,7 +44,7 @@ make %{?jobs:-j%jobs} %files %{_libdir}/*.so.* %{_sysconfdir}/storage/libstorage.conf -%license LICENSE +%license LICENSE.Apache-2.0 %manifest %{name}.manifest %files devel diff --git a/src/storage.c b/src/storage.c index 93bb85c..4197ec4 100644 --- a/src/storage.c +++ b/src/storage.c @@ -124,8 +124,8 @@ API int storage_get_root_directory(int storage_id, char **path) if (st->storage_id != storage_id) continue; if (!user) { - _E("Only Tizen applications and user session daemons can use\ - storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); + _E("Only apps and user session daemons are allowed " + "to use storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); return STORAGE_ERROR_INVALID_PARAMETER; } @@ -194,8 +194,9 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p if (found && st) { if (!user) { - _E("Only Tizen applications and user session daemons can use\ - storage_get_directory(INTERNAL_STORAGE_ID, ...)"); + _E("Only apps and user session daemons are allowed " + "to use storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); + return STORAGE_ERROR_INVALID_PARAMETER; } -- 2.7.4 From 472b06f2e08c48e391cc25bcf73254e6e9e66e21 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 23 Jul 2018 15:52:22 +0900 Subject: [PATCH 14/16] Change tzplatform_getenv to tzplatform_uid_getenv - Cover multi-user case Change-Id: I82cb6a0621ca1e87ae4009d7797cdd963ebf57a6 Signed-off-by: pr.jung --- include/common.h | 2 ++ src/storage-inhouse.c | 22 ++++++++++++++++++++-- src/storage.c | 2 -- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/common.h b/include/common.h index dd6f966..0e8f4a7 100644 --- a/include/common.h +++ b/include/common.h @@ -86,6 +86,8 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf int is_compat_bind_mount(void); int storage_ext_is_supported(void); +#define USER_UID_START 5000 + #ifdef __cplusplus } #endif diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 2c13dad..4031dec 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -15,6 +15,8 @@ */ +#include +#include #include #include #include @@ -59,6 +61,14 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp return -1; } + if (getuid() <= USER_UID_START) { + //LCOV_EXCL_START System Error + _E("Only apps and user session daemons are allowed " + "to use storage_get_compat_internal_path()"); + return -1; + //LCOV_EXCL_STOP + } + // this API works on place where compat path is bind-mounted if (!is_compat_bind_mount()) { //LCOV_EXCL_START System Error @@ -67,7 +77,7 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp //LCOV_EXCL_STOP } - str = tzplatform_getenv(TZ_USER_CONTENT); + str = tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT); str_len = strlen(str); if (strncmp(origin, str, str_len) != 0) { _E("Failed to match TZ_USER_CONTENT"); @@ -115,6 +125,14 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig return -1; } + if (getuid() <= USER_UID_START) { + //LCOV_EXCL_START System Error + _E("Only apps and user session daemons are allowed " + "to use storage_get_origin_internal_path()"); + return -1; + //LCOV_EXCL_STOP + } + // this API works on place where compat path is bind-mounted if (!is_compat_bind_mount()) { //LCOV_EXCL_START System Error @@ -129,7 +147,7 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig return -1; } - r = snprintf(origin, len, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), compat + compat_len); + r = snprintf(origin, len, "%s%s", tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT), compat + compat_len); if (r < 0) { //LCOV_EXCL_START System Error _E("failed to create new path"); diff --git a/src/storage.c b/src/storage.c index 4197ec4..a92e519 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,8 +27,6 @@ #include "log.h" #include "storage-external.h" -#define USER_UID_START 5000 - const char *dir_path[STORAGE_DIRECTORY_MAX]; const int tz_id[STORAGE_DIRECTORY_MAX] = { -- 2.7.4 From 09d286b1dfc0d7f50fe4355f83364ccfe2ff3603 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 10 Aug 2018 11:12:15 +0900 Subject: [PATCH 15/16] Fix some #define and add comments regarding _FILE_OFFSET_BITS=32/64 Change-Id: I7849e96b6a1e006685e2c6be953b0092dc953f86 Signed-off-by: Hyotaek Shim (cherry picked from commit 49e6771fa096c14cb5feab95ad68e7bedee19cb4) --- include/storage.h | 24 +++++++++--------------- src/statvfs.c | 4 ++++ src/storage-external.c | 6 +++--- src/storage-internal.c | 12 ++++++------ 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/storage.h b/include/storage.h index 0665cf3..1b3cbec 100644 --- a/include/storage.h +++ b/include/storage.h @@ -63,14 +63,11 @@ extern "C" { * ... * @endcode */ -#ifndef __USE_FILE_OFFSET64 -extern int storage_get_internal_memory_size(struct statvfs *buf); -#else -# define storage_get_internal_memory_size storage_get_internal_memory_size64 -#endif - #ifdef __USE_FILE_OFFSET64 +#define storage_get_internal_memory_size storage_get_internal_memory_size64 extern int storage_get_internal_memory_size64(struct statvfs *buf); +#else +extern int storage_get_internal_memory_size(struct statvfs *buf); #endif @@ -93,20 +90,17 @@ extern int storage_get_internal_memory_size64(struct statvfs *buf); * ... * @endcode */ -#ifndef __USE_FILE_OFFSET64 -extern int storage_get_external_memory_size(struct statvfs *buf); -#else -# ifdef __REDIRECT_NTH +#ifdef __USE_FILE_OFFSET64 +#ifdef __REDIRECT_NTH extern int __REDIRECT_NTH(storage_get_external_memory_size, (struct statvfs *buf), storage_get_external_memory_size64) __nonnull((1)); -# else -# define storage_get_external_memory_size storage_get_external_memory_size64 -# endif +#else +#define storage_get_external_memory_size storage_get_external_memory_size64 #endif - -#ifdef __USE_FILE_OFFSET64 extern int storage_get_external_memory_size64(struct statvfs *buf); +#else +extern int storage_get_external_memory_size(struct statvfs *buf); #endif diff --git a/src/statvfs.c b/src/statvfs.c index 7b50dc4..4e5df2f 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -241,6 +241,7 @@ static int get_memory_size(const char *path, struct statvfs_32 *buf) return 0; } +/* This api is intended for binaries built with _FILE_OFFSET_BITS=32 */ API int storage_get_internal_memory_size(struct statvfs *buf) { struct statvfs_32 temp; @@ -275,6 +276,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) return 0; } +/* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ API int storage_get_internal_memory_size64(struct statvfs *buf) { static unsigned long reserved = 0; @@ -331,6 +333,7 @@ static int get_external_path(char *path, size_t len) return storage_ext_get_primary_mmc_path(path, len); } +/* This api is intended for binaries built with _FILE_OFFSET_BITS=32 */ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) { struct statvfs_32 temp; @@ -376,6 +379,7 @@ out_nodev: return 0; } +/* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf) { int ret; diff --git a/src/storage-external.c b/src/storage-external.c index aee5d6c..a0647a5 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -105,10 +105,10 @@ int storage_ext_get_space(int storage_id, } if (state >= STORAGE_STATE_MOUNTED) { -#ifndef __USE_FILE_OFFSET64 - ret = storage_get_external_memory_size_with_path(dev->mount_point, &s); -#else +#ifdef __USE_FILE_OFFSET64 ret = storage_get_external_memory_size64_with_path(dev->mount_point, &s); +#else + ret = storage_get_external_memory_size_with_path(dev->mount_point, &s); #endif if (ret < 0) { _E("Failed to get external memory size of (%s)(ret:%d)", dev->mount_point, ret); //LCOV_EXCL_LINE diff --git a/src/storage-internal.c b/src/storage-internal.c index 0dadec9..2f8a796 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -29,10 +29,10 @@ #include "common.h" #include "log.h" -#ifndef __USE_FILE_OFFSET64 -int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); -#else +#ifdef __USE_FILE_OFFSET64 int __WEAK__ storage_get_internal_memory_size64(struct statvfs *buf); +#else +int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf); #endif static int internal_get_state(void) @@ -45,10 +45,10 @@ static int internal_get_space(unsigned long long *total, unsigned long long *ava struct statvfs s; int ret; -#ifndef __USE_FILE_OFFSET64 - ret = storage_get_internal_memory_size(&s); -#else +#ifdef __USE_FILE_OFFSET64 ret = storage_get_internal_memory_size64(&s); +#else + ret = storage_get_internal_memory_size(&s); #endif if (ret < 0) return -EPERM; -- 2.7.4 From 430860f71b8758e1a9fd29d8bc9555a39ebf6cd4 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 10 Aug 2018 15:23:02 +0900 Subject: [PATCH 16/16] Fix documentation for storage_get_internal_memory_size and storage_get_external_memory_size Change-Id: Ic71b471508ce6598a181775468aaf597e1e1668f Signed-off-by: pr.jung --- include/storage.h | 14 +++++++++----- src/statvfs.c | 30 +++++++++++++++--------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/include/storage.h b/include/storage.h index 1b3cbec..992497e 100644 --- a/include/storage.h +++ b/include/storage.h @@ -41,16 +41,18 @@ extern "C" { #include -#include "storage-expand.h" +#include /** - * @brief int storage_get_internal_memory_size(struct statvfs *buf). - * @brief This generic API is used to get the internal memory size. + * @brief Gets the internal memory size. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @param[out] buf A pointer to a statvfs structure * @return @c 0 on success, * otherwise a negative error value on failure + * @retval #STORAGE_ERROR_NONE Successful + * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @par Example: * @code * ... @@ -72,12 +74,14 @@ extern int storage_get_internal_memory_size(struct statvfs *buf); /** - * @brief int storage_get_external_memory_size(struct statvfs *buf). - * @brief This generic API is used to get the external memory size. + * @brief Gets the external memory size. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @param[out] buf A pointer to a statvfs structure * @return @c 0 on success, * otherwise a negative error value on failure + * @retval #STORAGE_ERROR_NONE Successful + * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed * @par Example: * @code * ... diff --git a/src/statvfs.c b/src/statvfs.c index 4e5df2f..13c5561 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -250,13 +250,13 @@ API int storage_get_internal_memory_size(struct statvfs *buf) if (!buf) { _E("input param error"); - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp); if (ret || temp.f_bsize == 0) { - _E("fail to get memory size"); //LCOV_EXCL_LINE - return -errno; //LCOV_EXCL_LINE System Error + _E("fail to get memory size %d", ret); //LCOV_EXCL_LINE + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } if (reserved == 0) { @@ -273,7 +273,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) temp.f_bavail -= reserved; memcpy(buf, &temp, sizeof(temp)); - return 0; + return STORAGE_ERROR_NONE; } /* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ @@ -284,13 +284,13 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) if (!buf) { _E("input param error"); //LCOV_EXCL_LINE - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } ret = statvfs(tzplatform_getenv(TZ_SYS_HOME), buf); if (ret) { _E("fail to get memory size"); //LCOV_EXCL_LINE - return -errno; //LCOV_EXCL_LINE System Error + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } if (reserved == 0) { @@ -305,7 +305,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) buf->f_bavail = 0; else buf->f_bavail -= reserved; - return 0; + return STORAGE_ERROR_NONE; } static int mount_check(char *path) @@ -343,7 +343,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) _D("storage_get_external_memory_size"); if (!buf) { _E("input param error"); - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } if (path) @@ -358,7 +358,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) goto out_nodev; if (ret < 0) { _E("Failed to get external path(%d)", ret); //LCOV_EXCL_LINE - return ret; + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } } @@ -368,7 +368,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) ret = get_memory_size(ext_path, &temp); if (ret) { _E("fail to get memory size"); //LCOV_EXCL_LINE - return -errno; //LCOV_EXCL_LINE System Error + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } memcpy(buf, &temp, sizeof(temp)); @@ -376,7 +376,7 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) out_nodev: memset(buf, 0, sizeof(struct statvfs_32)); - return 0; + return STORAGE_ERROR_NONE; } /* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ @@ -388,7 +388,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf _D("storage_get_external_memory_size64"); if (!buf) { _E("input param error"); - return -EINVAL; + return STORAGE_ERROR_INVALID_PARAMETER; } if (path) @@ -403,7 +403,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf goto out_nodev; if (ret < 0) { _E("Failed to get external path(%d)", ret); - return ret; + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } } @@ -414,11 +414,11 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf if (ret) { //LCOV_EXCL_START System Error _E("fail to get memory size"); - return -errno; + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE //LCOV_EXCL_STOP } - return 0; + return STORAGE_ERROR_NONE; out_nodev: memset(buf, 0, sizeof(struct statvfs)); -- 2.7.4