X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstorage.c;h=a1367d3f35b4e239c69d2d55489891226eb1a24d;hb=3b6a43d4ea8be2ace977b722993dcbeebb7d0ddf;hp=cbe34b5a02d8ad99424e27662d9d975b6b084f63;hpb=fbb974d6a6eda4d3ed1fc6975e2b0dd77b72f3dd;p=platform%2Fcore%2Fsystem%2Flibstorage.git diff --git a/src/storage.c b/src/storage.c index cbe34b5..a1367d3 100644 --- a/src/storage.c +++ b/src/storage.c @@ -19,53 +19,81 @@ #include #include #include +#include +#include +#include #include "common.h" -#include "list.h" #include "log.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] = "/opt/usr/share/settings/Ringtones", +#include "storage-external.h" + +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_head; +static GList *st_int_head; /* Internal storage list */ + +static GList *compat_cb_list; +struct compat_cb_info { + storage_state_changed_cb user_cb; + void *user_data; +}; void add_device(const struct storage_ops *st) { - DD_LIST_APPEND(st_head, st); + SYS_G_LIST_APPEND(st_int_head, st); } void remove_device(const struct storage_ops *st) { - DD_LIST_REMOVE(st_head, st); + SYS_G_LIST_REMOVE(st_int_head, st); } API int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data) { const struct storage_ops *st; - dd_list *elem; - int storage_id = 0, ret; + GList *elem; + int ret_val; + bool user = true; if (!callback) { _E("Invalid parameter"); return STORAGE_ERROR_INVALID_PARAMETER; } - DD_LIST_FOREACH(st_head, elem, st) { - ret = callback(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; - storage_id++; + if (getuid() <= USER_UID_START) + user = false; + + SYS_G_LIST_FOREACH(st_int_head, elem, st) { + if (user) { + ret_val = 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_val) + break; + } + } + + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); + return STORAGE_ERROR_NONE; + //LCOV_EXCL_STOP + } + + ret_val = storage_ext_foreach_device_list(callback, user_data); + if (ret_val < 0) { + _E("Failed to iterate external devices (%d)", ret_val); //LCOV_EXCL_LINE + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } return STORAGE_ERROR_NONE; @@ -74,22 +102,70 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v API int storage_get_root_directory(int storage_id, char **path) { const struct storage_ops *st; + GList *elem; + char root[PATH_MAX]; + int ret_val; + bool extendedint; + bool user = true; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!path) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); + if (getuid() <= USER_UID_START) + user = false; + + /* internal storage */ + SYS_G_LIST_FOREACH(st_int_head, elem, st) { + if (st->storage_id != storage_id) + continue; + if (!user) { + _E("Only apps and user session daemons are allowed " + "to use storage_get_root_directory(INTERNAL_STORAGE_ID, ...)"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + *path = strdup(st->root()); + if (!*path) { +//LCOV_EXCL_START System Error + _E("Failed to copy the root string : %d", errno); + return STORAGE_ERROR_OUT_OF_MEMORY; +//LCOV_EXCL_STOP + } + return STORAGE_ERROR_NONE; + } + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + ret_val = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); + if (ret_val < 0) { + _E("Failed to get root path of external storage(%d, %d", storage_id, ret_val); + if (ret_val == -ENODEV || ret_val == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + //LCOV_EXCL_START + else if (ret_val == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP } - *path = strdup(st->root()); + *path = strdup(root); if (!*path) { + //LCOV_EXCL_START System error _E("Failed to copy the root string : %d", errno); return STORAGE_ERROR_OUT_OF_MEMORY; + //LCOV_EXCL_STOP } return STORAGE_ERROR_NONE; @@ -98,8 +174,17 @@ API int storage_get_root_directory(int storage_id, char **path) API int storage_get_directory(int storage_id, storage_directory_e type, char **path) { const struct storage_ops *st; - const char *root; + char root[PATH_MAX]; char temp[PATH_MAX]; + char *temp2, *end; + int ret_val; + GList *elem; + bool found; + bool extendedint; + bool user = true; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!path) { _E("Invalid parameger"); @@ -111,28 +196,91 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); + /* internal storage */ + found = false; + SYS_G_LIST_FOREACH(st_int_head, elem, st) { + if (st->storage_id != storage_id) + continue; + found = true; + break; + } + + if (getuid() <= USER_UID_START) + user = false; + + if (found && st) { + if (!user) { + _E("Only apps and user session daemons are allowed " + "to use storage_get_root_directory(INTERNAL_STORAGE_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); + if (temp2 == NULL) + return STORAGE_ERROR_OPERATION_FAILED; + end = strrchr(temp2, '/'); + if (end) + *end = '\0'; + snprintf(temp, PATH_MAX, "%s", temp2); + free(temp2); + } else { + if ((ret_val = snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type])) > PATH_MAX - 1) { + //LCOV_EXCL_START + _E("Path is longer than buffer. Need %d size of buffer.", ret_val + 1); + return STORAGE_ERROR_OUT_OF_MEMORY; + //LCOV_EXCL_STOP + } + } + + goto out; + } + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP } - if (st->type != STORAGE_TYPE_INTERNAL - && type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) { + if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) { _E("Not support directory : id(%d) type(%d)", storage_id, type); - return STORAGE_ERROR_NOT_SUPPORTED; + return STORAGE_ERROR_INVALID_PARAMETER; } - root = st->root(); - if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) - snprintf(temp, PATH_MAX, "%s", dir_path[type]); - else - snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type]); + ret_val = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); + if (ret_val < 0) { + _E("Failed to get root dir for external storage(id:%d, ret:%d)", storage_id, ret_val); + if (ret_val == -ENODEV || ret_val == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + //LCOV_EXCL_START + else if (ret_val == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP + } + /* The operation is not decided */ + if (extendedint) + return STORAGE_ERROR_INVALID_PARAMETER; + if ((ret_val = snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type])) > sizeof(temp) - 1) { + //LCOV_EXCL_START + _E("Path is longer than buffer. Need %d size of buffer.", ret_val + 1); + return STORAGE_ERROR_OUT_OF_MEMORY; + //LCOV_EXCL_STOP + } + +out: *path = strdup(temp); if (!*path) { + //LCOV_EXCL_START System error _E("Failed to copy the directory(%d) string : %d", type, errno); return STORAGE_ERROR_OUT_OF_MEMORY; + //LCOV_EXCL_STOP } return STORAGE_ERROR_NONE; @@ -141,72 +289,190 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p API int storage_get_type(int storage_id, storage_type_e *type) { const struct storage_ops *st; + GList *elem; + char root[PATH_MAX]; + int ret_val; + bool extendedint; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!type) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); + /* internal storage */ + SYS_G_LIST_FOREACH(st_int_head, elem, st) { + if (st->storage_id != storage_id) + continue; + *type = st->type; + return STORAGE_ERROR_NONE; + } + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP } - *type = st->type; + ret_val = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); + if (ret_val < 0) { + _E("Failed to get type of external storage"); + if (ret_val == -ENODEV || ret_val == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + //LCOV_EXCL_START + else if (ret_val == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP + } + if (extendedint) + *type = STORAGE_TYPE_EXTENDED_INTERNAL; + else + *type = STORAGE_TYPE_EXTERNAL; return STORAGE_ERROR_NONE; } API int storage_get_state(int storage_id, storage_state_e *state) { - const struct storage_ops *st; + const struct storage_ops *ops; + storage_state_e st; + GList *elem; + int ret_val; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!state) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); + /* internal storage */ + SYS_G_LIST_FOREACH(st_int_head, elem, ops) { + if (ops->storage_id != storage_id) + continue; + *state = ops->get_state(); + return STORAGE_ERROR_NONE; + } + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP } - *state = st->get_state(); + ret_val = storage_ext_get_state(storage_id, &st); + if (ret_val < 0) { + _E("Failed to get state (storage id(%d), ret_val(%d))", storage_id, ret_val); + if (ret_val == -ENODEV || ret_val == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + //LCOV_EXCL_START + else if (ret_val == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP + } + *state = st; return STORAGE_ERROR_NONE; } +//LCOV_EXCL_START Not called Callback +static void compat_cb(int storage_id, + storage_dev_e dev, storage_state_e state, + const char *fstype, const char *fsuuid, const char *mountpath, + bool primary, int flags, void *user_data) +{ + struct compat_cb_info* ccb_info; + GList *elem; + + if (storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD) + SYS_G_LIST_FOREACH(compat_cb_list, elem, ccb_info) + ccb_info->user_cb(storage_id, state, ccb_info->user_data); +} +//LCOV_EXCL_STOP + API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callback, void *user_data) { const struct storage_ops *st; struct storage_cb_info info; int ret; + GList *elem; + + struct compat_cb_info* ccb_info; + static int compat_cb_init = 0; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!callback) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); - return STORAGE_ERROR_NOT_SUPPORTED; - } + /** + * storage_id is different from storage type, but this code handles + * incorrect storage_id usage (pass storage type instead of storage id) + * For backward compatability. + */ + if (storage_id == STORAGE_TYPE_EXTERNAL) { + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + if (!compat_cb_init) { + ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, compat_cb, NULL); + if (ret == STORAGE_ERROR_NONE) + compat_cb_init = 1; + else + return ret; + } + + ccb_info = malloc(sizeof(struct compat_cb_info)); + if (ccb_info == NULL) + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + ccb_info->user_cb = callback; + ccb_info->user_data = user_data; + SYS_G_LIST_APPEND(compat_cb_list, ccb_info); - /* do not register changed callback in case of internal memory */ - if (st->type == STORAGE_TYPE_INTERNAL) return STORAGE_ERROR_NONE; + } + + /* Internal storage does not support registering changed callback */ + SYS_G_LIST_FOREACH(st_int_head, elem, st) + if (st->storage_id == storage_id) + return STORAGE_ERROR_NONE; + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } info.id = storage_id; info.state_cb = callback; info.user_data = user_data; - ret = st->register_cb(STORAGE_CALLBACK_STATE, &info); + ret = storage_ext_register_cb(STORAGE_CALLBACK_ID, &info); if (ret < 0) { + //LCOV_EXCL_START _E("Failed to register callback : id(%d)", storage_id); return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP } return STORAGE_ERROR_NONE; @@ -216,30 +482,66 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb { const struct storage_ops *st; struct storage_cb_info info; - int ret; + int ret_val; + GList *elem; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!callback) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); - return STORAGE_ERROR_NOT_SUPPORTED; + /** + * storage_id is different from storage type, but this code handles + * incorrect storage_id usage (pass storage type instead of storage id) + * For backward compatability. + */ + if (storage_id == STORAGE_TYPE_EXTERNAL) { + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + GList *elem_n; + struct compat_cb_info* ccb_info; + + SYS_G_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) { + if (ccb_info->user_cb == callback) { + SYS_G_LIST_REMOVE(compat_cb_list, ccb_info); + free(ccb_info); + return STORAGE_ERROR_NONE; + } + } + + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } - /* in case of internal memory, it does not register changed callback */ - if (st->type == STORAGE_TYPE_INTERNAL) - return STORAGE_ERROR_NONE; + /* Internal storage does not support registering changed callback */ + SYS_G_LIST_FOREACH(st_int_head, elem, st) + if (st->storage_id == storage_id) + return STORAGE_ERROR_NONE; + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } info.id = storage_id; info.state_cb = callback; - ret = st->unregister_cb(STORAGE_CALLBACK_STATE, &info); - if (ret < 0) { + ret_val = storage_ext_unregister_cb(STORAGE_CALLBACK_ID, &info); + if (ret_val < 0) { + //LCOV_EXCL_START _E("Failed to unregister callback : id(%d)", storage_id); return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP } return STORAGE_ERROR_NONE; @@ -249,27 +551,49 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) { const struct storage_ops *st; unsigned long long total; - int ret; + int ret_val; + GList *elem; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!bytes) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); + /* internal storage */ + SYS_G_LIST_FOREACH(st_int_head, elem, st) { + if (st->storage_id != storage_id) + continue; + ret_val = st->get_space(&total, NULL); + goto out; + } + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP } - ret = st->get_space(&total, NULL); - if (ret < 0) { + ret_val = storage_ext_get_space(storage_id, &total, NULL); + +out: + if (ret_val < 0) { _E("Failed to get total memory : id(%d)", storage_id); - return STORAGE_ERROR_OPERATION_FAILED; + if (ret_val == -ENODEV || ret_val == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + //LCOV_EXCL_START + else if (ret_val == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP } *bytes = total; - return STORAGE_ERROR_NONE; } @@ -277,26 +601,211 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) { const struct storage_ops *st; unsigned long long avail; - int ret; + int ret_val; + GList *elem; + + if (storage_id < 0) + return STORAGE_ERROR_INVALID_PARAMETER; if (!bytes) { _E("Invalid parameger"); return STORAGE_ERROR_INVALID_PARAMETER; } - st = DD_LIST_NTH(st_head, storage_id); - if (!st) { - _E("Not supported storage : id(%d)", storage_id); + /* internal storage */ + SYS_G_LIST_FOREACH(st_int_head, elem, st) { + if (st->storage_id != storage_id) + continue; + ret_val = st->get_space(NULL, &avail); + goto out; + } + + /* external storage */ + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP } - ret = st->get_space(NULL, &avail); - if (ret < 0) { + ret_val = storage_ext_get_space(storage_id, NULL, &avail); + +out: + if (ret_val < 0) { _E("Failed to get available memory : id(%d)", storage_id); - return STORAGE_ERROR_OPERATION_FAILED; + if (ret_val == -ENODEV || ret_val == -EINVAL) + return STORAGE_ERROR_INVALID_PARAMETER; + //LCOV_EXCL_START + else if (ret_val == -ENOMEM) + return STORAGE_ERROR_OUT_OF_MEMORY; + else + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP } *bytes = avail; + return STORAGE_ERROR_NONE; +} + +API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data) +{ + int ret_val; + struct storage_cb_info info; + + if (type == STORAGE_TYPE_INTERNAL) { + _E("Internal storage is not supported"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (type != STORAGE_TYPE_EXTERNAL && type != STORAGE_TYPE_EXTENDED_INTERNAL) { + _E("Invalid type (%d)", type); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (!callback) { + _E("Callback is NULL"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _E("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + /* external storage */ + info.type = type; + info.type_cb = callback; + info.user_data = user_data; + + ret_val = storage_ext_register_cb(STORAGE_CALLBACK_TYPE, &info); + if (ret_val < 0) { + //LCOV_EXCL_START + _E("Failed to register storage callback(ret:%d)", ret_val); + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP + } return STORAGE_ERROR_NONE; } + +API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback) +{ + struct storage_cb_info info; + int ret_val; + + if (type == STORAGE_TYPE_INTERNAL) { + _E("Internal storage is not supported"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (type != STORAGE_TYPE_EXTERNAL && type != STORAGE_TYPE_EXTENDED_INTERNAL) { + _E("Invalid type (%d)", type); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (!callback) { + _E("Callback is NULL"); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _E("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + /* external storage */ + info.type = type; + info.type_cb = callback; + + ret_val = storage_ext_unregister_cb(STORAGE_CALLBACK_TYPE, &info); + if (ret_val < 0) { + //LCOV_EXCL_START + _E("Failed to unregister storage callback(ret:%d)", ret_val); + return STORAGE_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP + } + + 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) { + //LCOV_EXCL_START + _E("Failed to get storage type: %d", ret); + return ret; + //LCOV_EXCL_STOP + } + if (*type == STORAGE_TYPE_INTERNAL || *type == STORAGE_TYPE_EXTENDED_INTERNAL) + return STORAGE_ERROR_INVALID_PARAMETER; + + if (!storage_ext_is_supported()) { + //LCOV_EXCL_START + _D("Block module is not enabled"); + return STORAGE_ERROR_NOT_SUPPORTED; + //LCOV_EXCL_STOP + } + + 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 + if (ret == -ENODEV) { + ret = STORAGE_ERROR_INVALID_PARAMETER; + goto out; + } + //LCOV_EXCL_START + ret = STORAGE_ERROR_OPERATION_FAILED; + goto out; + //LCOV_EXCL_STOP + } + + 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; + 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); + } + } + } +}