From 2b4fc11bbac5e320f6ad3ce3e548e0bfcd7d17f5 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 13 Apr 2017 16:18:10 +0900 Subject: [PATCH 01/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 4697eec5bb58ad027b94987fe9f30db9762558f8 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 30 Aug 2017 14:37:45 +0900 Subject: [PATCH 02/16] block: remove external-storage call if block module is not supported Change-Id: Ia9bbe4f66609ff566fffe3b7c4aa0e4a2698cffe Signed-off-by: pr.jung --- 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..d5cc86a 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 aa8167f2a5a00c4c6dba4ab6947d6e6c39ebebf2 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 7 Sep 2017 17:04:43 +0900 Subject: [PATCH 03/16] storaged has block.conf from tizen 4.0 Change-Id: I1cf7579be57b837e6b372c6a2412a42503ca0410 Signed-off-by: pr.jung --- src/storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage.c b/src/storage.c index d5cc86a..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] = { -- 2.7.4 From 17dbfca55b15268e7e0ca171e34070af60ad650c Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 20 Sep 2017 11:49:40 +0900 Subject: [PATCH 04/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 4588a995068752e0867acfc0fbca39a237d56a40 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 14 Dec 2017 17:13:31 +0900 Subject: [PATCH 05/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 2ebbfb2eda46299a06b79552e84eac9f0d39b0d8 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 27 Feb 2018 17:31:51 +0900 Subject: [PATCH 06/16] Call GetStatvfs dbus method for external storage size Change-Id: I43f8f7ec1b8f4214c6d03d64f5667449e3b94d55 Signed-off-by: pr.jung --- src/statvfs.c | 26 +++------------- src/storage-external-dbus.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ src/storage-external-dbus.h | 23 ++++++++++++++ 3 files changed, 102 insertions(+), 22 deletions(-) diff --git a/src/statvfs.c b/src/statvfs.c index 7b50dc4..e920cb6 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -37,24 +37,6 @@ #define EXTERNAL_MEMORY_NODE "sdcard" #define STORAGE_CONF_FILE "/etc/storage/libstorage.conf" -/* it's for 32bit file offset */ -struct statvfs_32 { - unsigned long int f_bsize; - unsigned long int f_frsize; - unsigned long int f_blocks; - unsigned long int f_bfree; - unsigned long int f_bavail; - unsigned long int f_files; - unsigned long int f_ffree; - unsigned long int f_favail; - unsigned long int f_fsid; -#ifdef _STATVFSBUF_F_UNUSED - int __f_unused; -#endif - unsigned long int f_flag; - unsigned long int f_namemax; - int __f_spare[6]; -}; #define MAX_LINE 128 #define MAX_SECTION 64 @@ -254,7 +236,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) 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 + _E("fail to get memory size %d", ret); //LCOV_EXCL_LINE return -errno; //LCOV_EXCL_LINE System Error } @@ -362,10 +344,10 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) if (!mount_check(ext_path)) goto out_nodev; - ret = get_memory_size(ext_path, &temp); + ret = storage_ext_get_statvfs(ext_path, &temp); if (ret) { _E("fail to get memory size"); //LCOV_EXCL_LINE - return -errno; //LCOV_EXCL_LINE System Error + return ret; //LCOV_EXCL_LINE System Error } memcpy(buf, &temp, sizeof(temp)); @@ -406,7 +388,7 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf if (!mount_check(ext_path)) goto out_nodev; - ret = statvfs(ext_path, buf); + ret = storage_ext_get_statvfs_size64(ext_path, buf); if (ret) { //LCOV_EXCL_START System Error _E("fail to get memory size"); diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index dcd1e9e..4568371 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include #include "log.h" #include "storage-external-dbus.h" @@ -32,6 +34,7 @@ #define CHECK_STR(a) (a ? a : "") #define STORAGE_EXT_GET_LIST "GetDeviceList" +#define STORAGE_EXT_GET_STATVFS "GetStatvfs" #define STORAGE_EXT_DEVICE_CHANGED "DeviceChanged" #define STORAGE_EXT_DEVICE_ADDED "DeviceAdded" @@ -211,6 +214,78 @@ out: return ret; } +int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) +{ + GVariant *result; + guint64 bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax; + + assert(buf); + + memset(buf, 0, sizeof(struct statvfs_32)); + + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_STORAGE, + STORAGE_EXT_IFACE_STORAGE, + STORAGE_EXT_GET_STATVFS, + g_variant_new("(s)", path)); + if (!result) { + _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE + return -EIO; + } + + g_variant_get(result, "(ttttttttttt)", + &bsize, &frsize, &blocks, + &bfree, &bavail, &files, + &ffree, &favail, &fsid, + &flag, &namemax); +// %llu bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax + + buf->f_bsize = (unsigned long)bsize; + buf->f_frsize = (unsigned long)frsize; + buf->f_blocks = (unsigned long)blocks; + buf->f_bfree = (unsigned long)bfree; + buf->f_bavail = (unsigned long)bavail; + buf->f_files = (unsigned long)files; + buf->f_ffree = (unsigned long)ffree; + buf->f_favail = (unsigned long)favail; + buf->f_fsid = (unsigned long)fsid; + buf->f_flag = (unsigned long)flag; + buf->f_namemax = (unsigned long)namemax; + +// %lu buf->f_bsize, buf->f_frsize, buf->f_blocks, buf->f_bfree, buf->f_bavail, buf->f_files, buf->f_ffree, buf->f_favail, buf->f_fsid, buf->f_flag, buf->f_namemax + return 0; +} + +int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) +{ + GVariant *result; + + assert(buf); + + memset(buf, 0, sizeof(struct statvfs)); + + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_STORAGE, + STORAGE_EXT_IFACE_STORAGE, + STORAGE_EXT_GET_STATVFS, + g_variant_new("(s)", path)); + if (!result) { + _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE + return -EIO; + } + + g_variant_get(result, "(ttttttttttt)", + &(buf->f_bsize), &(buf->f_frsize), &(buf->f_blocks), + &(buf->f_bfree), &(buf->f_bavail), &(buf->f_files), + &(buf->f_ffree), &(buf->f_favail), &(buf->f_fsid), + &(buf->f_flag), &(buf->f_namemax)); + +// %lu buf->f_bsize, buf->f_frsize, buf->f_fsid, buf->f_flag, buf->f_namemax +// %llu buf->f_blocks, buf->f_bfree, buf->f_bavail, buf->f_files, buf->f_ffree, buf->f_favail + + return 0; +} + //LCOV_EXCL_START Not called Callback static void storage_ext_device_changed(GVariant *params, enum storage_ext_state state, gpointer user_data) { diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index c37881b..195d72e 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -28,6 +28,8 @@ #define STORAGE_EXT_BUS_NAME "org.tizen.system.storage" #define STORAGE_EXT_PATH_MANAGER "/Org/Tizen/System/Storage/Block/Manager" #define STORAGE_EXT_IFACE_MANAGER STORAGE_EXT_BUS_NAME".BlockManager" +#define STORAGE_EXT_PATH_STORAGE "/Org/Tizen/System/Storage/Storage" +#define STORAGE_EXT_IFACE_STORAGE STORAGE_EXT_BUS_NAME".storage" enum mount_state { STORAGE_EXT_UNMOUNTED, @@ -72,12 +74,33 @@ typedef struct _storage_ext_device { int storage_id; } storage_ext_device; +/* it's for 32bit file offset */ +struct statvfs_32 { + unsigned long int f_bsize; + unsigned long int f_frsize; + unsigned long int f_blocks; + unsigned long int f_bfree; + unsigned long int f_bavail; + unsigned long int f_files; + unsigned long int f_ffree; + unsigned long int f_favail; + unsigned long int f_fsid; +#ifdef _STATVFSBUF_F_UNUSED + int __f_unused; +#endif + unsigned long int f_flag; + unsigned long int f_namemax; + int __f_spare[6]; +}; + 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); +int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf); +int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf); int storage_ext_register_device_change(storage_ext_changed_cb func, void *data); void storage_ext_unregister_device_change(storage_ext_changed_cb func); -- 2.7.4 From f47be2f7c4dc5e76912d814fb5dd72c1bf108090 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 --- 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 9c5066282e6e28ea3a4ae061f7a6527087f44f86 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 e2ce4b26cd01e0e3a96fcbe1d7f05fab4b91505d Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 8 May 2018 16:30:50 +0900 Subject: [PATCH 09/16] When storage id is invalid GetDeviceInfo return with id which is less than 0 Change-Id: I851d7d457c2e341a753adb4dfc951a150c4fee1e Signed-off-by: pr.jung --- src/storage-external-dbus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 4568371..8b66ca3 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -493,6 +493,11 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) return -ENODEV; } + if (info->storage_id < 0) { + _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE + return -ENODEV; + } + g_variant_unref(result); return 0; -- 2.7.4 From 6e5c758d6678b5906952d6ef253ed9107ba61b49 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 12 Jun 2018 11:30:07 +0900 Subject: [PATCH 10/16] 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 From 77ea1cf801171f2ba5fab03fdc9f41ab01bec54c Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 20 Jun 2018 14:56:52 +0900 Subject: [PATCH 11/16] Add new internal api - storage_get_storage_level - Get the current storage level Change-Id: I9be56c1c98a38cc210582aee1072b0b9d340badd Signed-off-by: pr.jung --- include/storage-internal.h | 2 ++ src/storage-external-dbus.c | 36 ++++++++++++++++++---- src/storage-external-dbus.h | 2 ++ src/storage-inhouse.c | 74 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 107 insertions(+), 7 deletions(-) diff --git a/include/storage-internal.h b/include/storage-internal.h index 391a721..1b14798 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -30,6 +30,7 @@ extern "C" { */ #include +#include #include "storage.h" #define STORAGE_ERROR_NO_DEVICE TIZEN_ERROR_NO_SUCH_DEVICE @@ -55,6 +56,7 @@ int storage_get_primary_sdcard(int *storage_id, char **path); 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); +int storage_get_storage_level(enum tzplatform_variable id, char **level); /** * @} diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 8b66ca3..d335ca7 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -33,13 +33,14 @@ #define CHECK_STR(a) (a ? a : "") -#define STORAGE_EXT_GET_LIST "GetDeviceList" -#define STORAGE_EXT_GET_STATVFS "GetStatvfs" +#define STORAGE_EXT_GET_LIST "GetDeviceList" +#define STORAGE_EXT_GET_STATVFS "GetStatvfs" +#define STORAGE_EXT_GET_STORAGE_LEVEL "GetStorageLevel" -#define STORAGE_EXT_DEVICE_CHANGED "DeviceChanged" -#define STORAGE_EXT_DEVICE_ADDED "DeviceAdded" -#define STORAGE_EXT_DEVICE_REMOVED "DeviceRemoved" -#define STORAGE_EXT_DEVICE_BLOCKED "DeviceBlocked" +#define STORAGE_EXT_DEVICE_CHANGED "DeviceChanged" +#define STORAGE_EXT_DEVICE_ADDED "DeviceAdded" +#define STORAGE_EXT_DEVICE_REMOVED "DeviceRemoved" +#define STORAGE_EXT_DEVICE_BLOCKED "DeviceBlocked" #define DBUS_REPLY_TIMEOUT (-1) @@ -286,6 +287,29 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) return 0; } +int storage_ext_get_storage_level(enum tzplatform_variable id, char **level) +{ + GVariant *result; + char *tmp; + + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_STORAGE, + STORAGE_EXT_IFACE_STORAGE, + STORAGE_EXT_GET_STORAGE_LEVEL, + g_variant_new("(i)", id)); + if (!result) { + _E("Failed to get %d level", id); + return -EIO; + } + + g_variant_get(result, "(s)", &tmp); + *level = strdup(tmp); + if (*level == NULL) + return -ENOMEM; + + return 0; +} + //LCOV_EXCL_START Not called Callback static void storage_ext_device_changed(GVariant *params, enum storage_ext_state state, gpointer user_data) { diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 195d72e..24800f8 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "list.h" #define STORAGE_EXT_BUS_NAME "org.tizen.system.storage" @@ -106,6 +107,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data); void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); +int storage_ext_get_storage_level(enum tzplatform_variable id, char **level); /* storage-internal.c */ GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 34ec31d..a522ee9 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -19,7 +19,6 @@ #include #include #include -#include #include "common.h" #include "list.h" @@ -181,3 +180,76 @@ 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; +} + +API int storage_get_storage_level(enum tzplatform_variable id, char **level) +{ + int ret; + + if (!level) + return STORAGE_ERROR_INVALID_PARAMETER; + + if (id != TZ_SYS_USER || id != TZ_SYS_TMP || id != TZ_SYS_OPT) + return STORAGE_ERROR_INVALID_PARAMETER; + + ret = storage_ext_get_storage_level(id, level); + if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + else if (ret < 0) + return STORAGE_ERROR_OPERATION_FAILED; + + return STORAGE_ERROR_NONE; +} -- 2.7.4 From 93e5212a3c6ab4877f57b92a2e71dad432644b2d Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 25 Jun 2018 17:57:12 +0900 Subject: [PATCH 12/16] Remove unused code Change-Id: I64ac16874dcbfda72f88ad9ed001e67b064083b3 Signed-off-by: pr.jung --- src/storage-inhouse.c | 55 --------------------------------------------------- 1 file changed, 55 deletions(-) diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index a522ee9..d3e30d3 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -180,61 +180,6 @@ 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; -} - API int storage_get_storage_level(enum tzplatform_variable id, char **level) { int ret; -- 2.7.4 From f56285beeafc8ec250f04fc6e57559c41baef266 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 27 Jun 2018 14:49:14 +0900 Subject: [PATCH 13/16] Change TZ_SYS_HOME to TZ_SYS_USER - TZ_SYS_HOME : "/opt/usr/home" - TZ_SYS_USER: "/opt/usr" Change-Id: I67e1c179d31559d79dc2ff0edf4f8db0f6c82580 Signed-off-by: pr.jung --- src/statvfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/statvfs.c b/src/statvfs.c index e920cb6..99ed755 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -234,7 +234,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf) return -EINVAL; } - ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp); + ret = get_memory_size(tzplatform_getenv(TZ_SYS_USER), &temp); if (ret || temp.f_bsize == 0) { _E("fail to get memory size %d", ret); //LCOV_EXCL_LINE return -errno; //LCOV_EXCL_LINE System Error @@ -267,7 +267,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) return -EINVAL; } - ret = statvfs(tzplatform_getenv(TZ_SYS_HOME), buf); + ret = statvfs(tzplatform_getenv(TZ_SYS_USER), buf); if (ret) { _E("fail to get memory size"); //LCOV_EXCL_LINE return -errno; //LCOV_EXCL_LINE System Error -- 2.7.4 From a61e011e03a39091e6f66b21a00f1d9d25e43db6 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 28 Jun 2018 15:00:31 +0900 Subject: [PATCH 14/16] Add .gitignore Change-Id: I71ff3c054b7ac9f8c006841ef683e79decee0796 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 ebe8d117ef1e8c593ecd1db932a2931d8aba7b50 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 28 Jun 2018 16:27:54 +0900 Subject: [PATCH 15/16] Modify storage_get_storage_level - Change fist parameter of storage_get_storage_level enum tzplatform_variable -> char * - Remove tzplatform_config.h in storage-internal.h Change-Id: I3f5ac4d6ff47aad5cccce101c7775cb1ce3e0379 Signed-off-by: pr.jung --- include/storage-internal.h | 3 +-- src/storage-external-dbus.c | 15 ++++++++++++++- src/storage-external-dbus.h | 3 +-- src/storage-inhouse.c | 12 ++++++------ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/storage-internal.h b/include/storage-internal.h index 1b14798..53795d2 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -30,7 +30,6 @@ extern "C" { */ #include -#include #include "storage.h" #define STORAGE_ERROR_NO_DEVICE TIZEN_ERROR_NO_SUCH_DEVICE @@ -56,7 +55,7 @@ int storage_get_primary_sdcard(int *storage_id, char **path); 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); -int storage_get_storage_level(enum tzplatform_variable id, char **level); +int storage_get_storage_level(const char *path, char **level); /** * @} diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index d335ca7..f070e8f 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "log.h" #include "storage-external-dbus.h" @@ -287,10 +288,22 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) return 0; } -int storage_ext_get_storage_level(enum tzplatform_variable id, char **level) +int storage_ext_get_storage_level(const char *path, char **level) { GVariant *result; char *tmp; + enum tzplatform_variable id; + + if (!strcmp(path, tzplatform_getenv(TZ_SYS_USER))) + id = TZ_SYS_USER; + else if (!strcmp(path, tzplatform_getenv(TZ_SYS_TMP))) + id = TZ_SYS_TMP; + else if (!strcmp(path, tzplatform_getenv(TZ_SYS_OPT))) + id = TZ_SYS_OPT; + else { + _E("Invalid path"); + return -EINVAL; + } result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 24800f8..b71d2e4 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -23,7 +23,6 @@ #include #include #include -#include #include "list.h" #define STORAGE_EXT_BUS_NAME "org.tizen.system.storage" @@ -107,7 +106,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data); void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); -int storage_ext_get_storage_level(enum tzplatform_variable id, char **level); +int storage_ext_get_storage_level(const char *path, char **level); /* storage-internal.c */ GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index d3e30d3..051b6b9 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "common.h" #include "list.h" @@ -180,19 +181,18 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) return STORAGE_ERROR_NONE; } -API int storage_get_storage_level(enum tzplatform_variable id, char **level) +API int storage_get_storage_level(const char *path, char **level) { int ret; - if (!level) + if (!level || !path) return STORAGE_ERROR_INVALID_PARAMETER; - if (id != TZ_SYS_USER || id != TZ_SYS_TMP || id != TZ_SYS_OPT) - return STORAGE_ERROR_INVALID_PARAMETER; - - ret = storage_ext_get_storage_level(id, level); + ret = storage_ext_get_storage_level(path, level); if (ret == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + else if (ret == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; else if (ret < 0) return STORAGE_ERROR_OPERATION_FAILED; -- 2.7.4 From 4306eaee52ee3fcd853fb2b9f08ce69c8e8e7093 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Tue, 3 Jul 2018 11:44:20 +0900 Subject: [PATCH 16/16] Add internal apis to mount/unmount/format primary sdcard - storage_request_mount_mmc - storage_request_unmount_mmc - storage_request_format_mmc - storage_format_mmc Change-Id: I48bef7b586da884d314bbc64a5938e363c7ca00f Signed-off-by: pr.jung --- include/storage-internal.h | 82 +++++++++++++++++++ src/storage-external-dbus.c | 78 ++++++++++++++++++ src/storage-external-dbus.h | 4 + src/storage-inhouse.c | 193 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 357 insertions(+) diff --git a/include/storage-internal.h b/include/storage-internal.h index 53795d2..e3bd50a 100644 --- a/include/storage-internal.h +++ b/include/storage-internal.h @@ -50,6 +50,8 @@ extern "C" { * @retval #STORAGE_ERROR_NONE Successful * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #STORAGE_ERROR_NO_DEVICE No such device + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory */ int storage_get_primary_sdcard(int *storage_id, char **path); @@ -58,6 +60,86 @@ int storage_get_origin_internal_path(const char* compat, int len, char* origin); int storage_get_storage_level(const char *path, char **level); /** + * @brief This structure defines the data for receive result of mmc operations(mount/unmount/format) + */ +struct mmc_contents { + void (*mmc_cb) (int result, void* data); /**< user callback function for receive result of mmc operations */ + void* user_data; /**< input data for callback function's second-param(data) */ +}; + +/** + * @brief This API is used to mount mmc.\n + * + * @param[in] mmc_data for receive result of mount operation + * + * @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_NO_DEVICE No such device + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + */ +int storage_request_mount_mmc(struct mmc_contents *mmc_data); + +/** + * @brief This API is used to unmount mmc.\n + * + * @param[in] mmc_data for receive result of unmount operation + * @param[in] option type of unmount option \n + * 0 : Normal unmount \n + * (if other process still access a sdcard, \n + * unmount will be failed.) \n + * 1 : Force unmount \n + * (if other process still access a sdcard, \n + * this process will be received SIGTERM or SIGKILL.) + * + * @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_NO_DEVICE No such device + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + */ +int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option); + +/** + * @brief This API is used to format mmc.\n + * + * @param[in] mmc_data for receive result of format operation + * + * @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_NO_DEVICE No such device + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + */ +int storage_request_format_mmc(struct mmc_contents *mmc_data); + +/** + * @brief This API is used to format mmc.\n + * + * @param[in] mmc_data for receive result of format operation + * @param[in] option FMT_NORMAL is 0, FMT_FORCE is 1 + * + * @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_NO_DEVICE No such device + * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed + * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory + */ +int storage_format_mmc(struct mmc_contents *mmc_data, int option); + +/** * @} */ diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index f070e8f..5d45189 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -51,6 +51,11 @@ struct storage_ext_callback { guint block_id; }; +typedef struct { + dbus_pending_cb func; + void *data; +} pending_call_data; + static dd_list *changed_list; static void storage_ext_release_internal(storage_ext_device *dev) @@ -118,6 +123,79 @@ static GDBusConnection *get_dbus_connection(void) return conn; } +static void _cb_pending(GDBusConnection *conn, + GAsyncResult *res, + gpointer user_data) +{ + GVariant *reply = NULL; + GError *err = NULL; + pending_call_data *data = (pending_call_data *)user_data; + + reply = g_dbus_connection_call_finish(conn, res, &err); + if (!reply || err) { + if (!err) + g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED, + "Error during g_dbus_connection_call"); + + if (data && data->func) + data->func(NULL, data->data, err); + goto out; + } + + if (data && data->func) + data->func(reply, data->data, err); +out: + if (err) + g_error_free(err); + if (data) + free(data); +} + +int dbus_method_async_with_reply_var(const char *dest, const char *path, + const char *iface, const char *method, GVariant *param, + dbus_pending_cb cb, int timeout, void *data) +{ + GDBusConnection *conn; + pending_call_data *pdata = NULL; + int ret = 0; + + if (!dest || !path || !iface || !method) + return -EINVAL; + + if (timeout < -1) { + _E("wrong timeout %d", timeout); + return -EINVAL; + } + + conn = get_dbus_connection(); + if (!conn) { + _E("fail to get dbus connection"); //LCOV_EXCL_LINE + return -1; + } + + if (cb) { + pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); + if (!pdata) { + ret = -ENOMEM; + goto err; + } + + pdata->func = cb; + pdata->data = data; + } + + g_dbus_connection_call(conn, dest, path, iface, method, + param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, + (GAsyncReadyCallback)_cb_pending, + pdata); + + return ret; +err: + if (param) + g_variant_unref(param); + return ret; +} + GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, const gchar *iface, const gchar *method, GVariant *param) { diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index b71d2e4..273e388 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -108,6 +108,10 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); int storage_ext_get_storage_level(const char *path, char **level); +typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err); +int dbus_method_async_with_reply_var(const char *dest, const char *path, + const char *iface, const char *method, GVariant *param, + dbus_pending_cb cb, int timeout, void *data); /* storage-internal.c */ GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, const gchar *iface, const gchar *method, GVariant *param); diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 051b6b9..d5ed6b5 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -27,6 +27,8 @@ #include "storage-internal.h" #include "storage-external-dbus.h" +#define FORMAT_TIMEOUT (120*1000) + /* Get compat path from origin Multi-user path from TZ_USER_CONTENT/.. to /opt/usr/media/.. @@ -198,3 +200,194 @@ API int storage_get_storage_level(const char *path, char **level) return STORAGE_ERROR_NONE; } + +static void mount_mmc_cb(GVariant *var, void *user_data, GError *err) +{ + struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; + int mmc_ret = -1; + + _D("mount_mmc_cb called"); + + if (!var) { + _E("no message [%s]", err->message); + mmc_ret = -EBADMSG; + goto exit; + } + + g_variant_get(var, "(i)", &mmc_ret); + + _I("Mount State : %d", mmc_ret); + +exit: + if (var) + g_variant_unref(var); + (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); +} + +API int storage_request_mount_mmc(struct mmc_contents *mmc_data) +{ + void (*mount_cb)(GVariant *, void *, GError *) = NULL; + void *data = NULL; + char *path; + int ret; + int id; + + if (mmc_data && mmc_data->mmc_cb) { + _I("Mount callback exists"); + mount_cb = mount_mmc_cb; + data = mmc_data; + } + + ret = storage_get_primary_sdcard(&id, &path); + if (ret != STORAGE_ERROR_NONE) + return ret; + + ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "Mount", + g_variant_new("(is)", id, ""), + mount_cb, + -1, + data); + + _I("Mount Request %s", ret == 0 ? "Success" : "Failed"); + + if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + if (ret < 0) + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + + return STORAGE_ERROR_NONE; +} + +static void unmount_mmc_cb(GVariant *var, void *user_data, GError *err) +{ + struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; + int mmc_ret; + + _D("unmount_mmc_cb called"); + + if (!var) { + _E("no message [%s]", err->message); + mmc_ret = -EBADMSG; + goto exit; + } + + g_variant_get(var, "(i)", &mmc_ret); + + _I("Unmount State : %d", mmc_ret); + +exit: + if (var) + g_variant_unref(var); + (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); +} + +API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) +{ + void (*unmount_cb)(GVariant *, void *, GError *) = NULL; + void *data = NULL; + char *path; + int ret; + int id; + + if (option < 0 || option > 1) + return STORAGE_ERROR_INVALID_PARAMETER; + + if (mmc_data && mmc_data->mmc_cb) { + _I("Unmount callback exists"); + unmount_cb = unmount_mmc_cb; + data = mmc_data; + } + + ret = storage_get_primary_sdcard(&id, &path); + if (ret != STORAGE_ERROR_NONE) + return ret; + + ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "Unmount", + g_variant_new("(ii)", id, option), + unmount_cb, + -1, + data); + + _I("Unmount Request %s", ret == 0 ? "Success" : "Failed"); + + if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + if (ret < 0) + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + + return STORAGE_ERROR_NONE; +} + +static void format_mmc_cb(GVariant *var, void *user_data, GError *err) +{ + struct mmc_contents *mmc_data = (struct mmc_contents*)user_data; + int mmc_ret; + + _D("format_mmc_cb called"); + + if (!var) { + _E("no message [%s]", err->message); + mmc_ret = -EBADMSG; + goto exit; + } + + g_variant_get(var, "(i)", &mmc_ret); + + _I("Format State : %d", mmc_ret); + +exit: + if (var) + g_variant_unref(var); + (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data); +} + +API int storage_request_format_mmc(struct mmc_contents *mmc_data) +{ + return storage_format_mmc(mmc_data, 1); +} + +API int storage_format_mmc(struct mmc_contents *mmc_data, int option) +{ + void (*format_cb)(GVariant *, void *, GError *) = NULL; + void *data = NULL; + char *path; + int ret; + int id; + + if (option < 0 || option > 1) + return STORAGE_ERROR_INVALID_PARAMETER; + + if (mmc_data && mmc_data->mmc_cb) { + _I("Format callback exists"); + format_cb = format_mmc_cb; + data = mmc_data; + } + + ret = storage_get_primary_sdcard(&id, &path); + if (ret != STORAGE_ERROR_NONE) + return ret; + + ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "Format", + g_variant_new("(ii)", id, option), + format_cb, + FORMAT_TIMEOUT, + data); + + _I("Format Request %s", ret == 0 ? "Success" : "Failed"); + + if (ret == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + if (ret < 0) + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + + return STORAGE_ERROR_NONE; +} -- 2.7.4