From: pr.jung Date: Thu, 13 Apr 2017 07:18:10 +0000 (+0900) Subject: Add EXTENDED_INTERNAL type for extended internal storage X-Git-Tag: submit/tizen/20170607.084951^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2b4fc11bbac5e320f6ad3ce3e548e0bfcd7d17f5;p=platform%2Fcore%2Fsystem%2Flibstorage.git Add EXTENDED_INTERNAL type for extended internal storage Change-Id: I68d069cc718f3b735622fe20ee902b7c505f540e Signed-off-by: pr.jung --- 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; }