Increase line coverage using LCOV_EXCL
[platform/core/system/libstorage.git] / src / storage.c
index 26b4036..01ec1fb 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <system_settings.h>
+#include <vconf.h>
+#include <tzplatform_config.h>
+#include <libsyscommon/list.h>
 
 #include "common.h"
-#include "list.h"
 #include "log.h"
 #include "storage-external.h"
 
-const char *dir_path[STORAGE_DIRECTORY_MAX] = {
-       [STORAGE_DIRECTORY_IMAGES] = "Images",
-       [STORAGE_DIRECTORY_SOUNDS] = "Sounds",
-       [STORAGE_DIRECTORY_VIDEOS] = "Videos",
-       [STORAGE_DIRECTORY_CAMERA] = "Camera",
-       [STORAGE_DIRECTORY_DOWNLOADS] = "Downloads",
-       [STORAGE_DIRECTORY_MUSIC] = "Music",
-       [STORAGE_DIRECTORY_DOCUMENTS] = "Documents",
-       [STORAGE_DIRECTORY_OTHERS] = "Others",
-       [STORAGE_DIRECTORY_SYSTEM_RINGTONES] = "",
+const char *dir_path[STORAGE_DIRECTORY_MAX];
+
+const int tz_id[STORAGE_DIRECTORY_MAX] = {
+       [STORAGE_DIRECTORY_IMAGES] = TZ_USER_IMAGES,
+       [STORAGE_DIRECTORY_SOUNDS] = TZ_USER_SOUNDS,
+       [STORAGE_DIRECTORY_VIDEOS] = TZ_USER_VIDEOS,
+       [STORAGE_DIRECTORY_CAMERA] = TZ_USER_CAMERA,
+       [STORAGE_DIRECTORY_DOWNLOADS] = TZ_USER_DOWNLOADS,
+       [STORAGE_DIRECTORY_MUSIC] = TZ_USER_MUSIC,
+       [STORAGE_DIRECTORY_DOCUMENTS] = TZ_USER_DOCUMENTS,
+       [STORAGE_DIRECTORY_OTHERS] = TZ_USER_OTHERS,
 };
 
-static dd_list *st_int_head; /* Internal storage list */
+static GList *st_int_head; /* Internal storage list */
 
-static dd_list *compat_cb_list;
+static GList *compat_cb_list;
 struct compat_cb_info {
        storage_state_changed_cb user_cb;
        void *user_data;
@@ -48,37 +50,50 @@ struct compat_cb_info {
 
 void add_device(const struct storage_ops *st)
 {
-       DD_LIST_APPEND(st_int_head, st);
+       SYS_G_LIST_APPEND(st_int_head, st);
 }
 
 void remove_device(const struct storage_ops *st)
 {
-       DD_LIST_REMOVE(st_int_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 ret;
+       GList *elem;
+       int ret_val;
+       bool user = true;
 
        if (!callback) {
                _E("Invalid parameter");
                return STORAGE_ERROR_INVALID_PARAMETER;
        }
 
-       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 (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;
+               }
        }
 
-       ret = storage_ext_foreach_device_list(callback, user_data);
-       if (ret < 0) {
-               _E("Failed to iterate external devices (%d)", ret); //LCOV_EXCL_LINE
-               return STORAGE_ERROR_OPERATION_FAILED;
+       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;
@@ -87,22 +102,33 @@ 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;
-       dd_list *elem;
+       GList *elem;
        char root[PATH_MAX];
-       int ret;
+       int ret_val;
+       bool extendedint;
+       bool user = true;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!path) {
                _E("Invalid parameger");
                return STORAGE_ERROR_INVALID_PARAMETER;
        }
 
+       if (getuid() <= USER_UID_START)
+               user = false;
+
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       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
@@ -114,16 +140,32 @@ API int storage_get_root_directory(int storage_id, char **path)
        }
 
        /* external storage */
-       ret = storage_ext_get_root(storage_id, root, sizeof(root));
-       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;
+       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(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;
@@ -135,12 +177,14 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
        char root[PATH_MAX];
        char temp[PATH_MAX];
        char *temp2, *end;
-       int ret;
-       dd_list *elem;
+       int ret_val;
+       GList *elem;
        bool found;
+       bool extendedint;
+       bool user = true;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!path) {
                _E("Invalid parameger");
@@ -154,51 +198,89 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
 
        /* internal storage */
        found = false;
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       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) {
-                       ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &temp2);
-                       if (ret < 0) {
-                               _E("Failed to get ringtone path : %d", ret); //LCOV_EXCL_LINE
+                       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
-                       snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type]);
+               } 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 (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) {
-               _E("Not support directory : id(%d) type(%d)", storage_id, type); //LCOV_EXCL_LINE
+       if (!storage_ext_is_supported()) {
+               //LCOV_EXCL_START
+               _D("Block module is not enabled");
                return STORAGE_ERROR_NOT_SUPPORTED;
+               //LCOV_EXCL_STOP
        }
 
-       ret = storage_ext_get_root(storage_id, root, sizeof(root));
-       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;
+       if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) {
+               _E("Not support directory : id(%d) type(%d)", storage_id, type);
+               return STORAGE_ERROR_INVALID_PARAMETER;
+       }
+
+       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;
 
-       snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type]);
+       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) {
-               _E("Failed to copy the directory(%d) string : %d", type, errno); //LCOV_EXCL_LINE
+               //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;
@@ -207,10 +289,13 @@ out:
 API int storage_get_type(int storage_id, storage_type_e *type)
 {
        const struct storage_ops *st;
-       dd_list *elem;
+       GList *elem;
+       char root[PATH_MAX];
+       int ret_val;
+       bool extendedint;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!type) {
                _E("Invalid parameger");
@@ -218,7 +303,7 @@ API int storage_get_type(int storage_id, storage_type_e *type)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
                *type = st->type;
@@ -226,7 +311,29 @@ API int storage_get_type(int storage_id, storage_type_e *type)
        }
 
        /* external storage */
-       *type = 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
+       }
+
+       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;
 }
@@ -235,11 +342,11 @@ API int storage_get_state(int storage_id, storage_state_e *state)
 {
        const struct storage_ops *ops;
        storage_state_e st;
-       dd_list *elem;
-       int ret;
+       GList *elem;
+       int ret_val;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!state) {
                _E("Invalid parameger");
@@ -247,7 +354,7 @@ API int storage_get_state(int storage_id, storage_state_e *state)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, ops) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, ops) {
                if (ops->storage_id != storage_id)
                        continue;
                *state = ops->get_state();
@@ -255,41 +362,57 @@ API int storage_get_state(int storage_id, storage_state_e *state)
        }
 
        /* external storage */
-       ret = storage_ext_get_state(storage_id, &st);
-       if (ret < 0) {
-               _E("Failed to get state (storage id(%d), ret(%d))", storage_id, ret); //LCOV_EXCL_LINE
-               return STORAGE_ERROR_OPERATION_FAILED;
+       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_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;
-       dd_list *elem;
+       GList *elem;
 
        if (storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD)
-               DD_LIST_FOREACH(compat_cb_list, elem, ccb_info)
+               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;
-       dd_list *elem;
+       GList *elem;
 
        struct compat_cb_info* ccb_info;
        static int compat_cb_init = 0;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!callback) {
                _E("Invalid parameger");
@@ -298,6 +421,13 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca
 
        /* 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)
@@ -311,25 +441,34 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca
                        return STORAGE_ERROR_OPERATION_FAILED;
                ccb_info->user_cb = callback;
                ccb_info->user_data = user_data;
-               DD_LIST_APPEND(compat_cb_list, ccb_info);
+               SYS_G_LIST_APPEND(compat_cb_list, ccb_info);
 
                return STORAGE_ERROR_NONE;
        }
 
        /* Internal storage does not support registering changed callback */
-       DD_LIST_FOREACH(st_int_head, elem, st)
+       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 = storage_ext_register_cb(STORAGE_CALLBACK_ID, &info);
        if (ret < 0) {
-               _E("Failed to register callback : id(%d)", storage_id); //LCOV_EXCL_LINE
+               //LCOV_EXCL_START
+               _E("Failed to register callback : id(%d)", storage_id);
                return STORAGE_ERROR_OPERATION_FAILED;
+               //LCOV_EXCL_STOP
        }
 
        return STORAGE_ERROR_NONE;
@@ -339,11 +478,11 @@ 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;
-       dd_list *elem;
+       int ret_val;
+       GList *elem;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!callback) {
                _E("Invalid parameger");
@@ -352,12 +491,19 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb
 
        /* For backward compatability */
        if (storage_id == STORAGE_TYPE_EXTERNAL) {
-               dd_list *elem_n;
+               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;
 
-               DD_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) {
+               SYS_G_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) {
                        if (ccb_info->user_cb == callback) {
-                               DD_LIST_REMOVE(compat_cb_list, ccb_info);
+                               SYS_G_LIST_REMOVE(compat_cb_list, ccb_info);
                                free(ccb_info);
                                return STORAGE_ERROR_NONE;
                        }
@@ -366,18 +512,27 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb
        }
 
        /* Internal storage does not support registering changed callback */
-       DD_LIST_FOREACH(st_int_head, elem, st)
+       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 = storage_ext_unregister_cb(STORAGE_CALLBACK_ID, &info);
-       if (ret < 0) {
-               _E("Failed to unregister callback : id(%d)", storage_id); //LCOV_EXCL_LINE
+       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;
@@ -387,11 +542,11 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes)
 {
        const struct storage_ops *st;
        unsigned long long total;
-       int ret;
-       dd_list *elem;
+       int ret_val;
+       GList *elem;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!bytes) {
                _E("Invalid parameger");
@@ -399,22 +554,34 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
-               ret = st->get_space(&total, NULL);
+               ret_val = st->get_space(&total, NULL);
                goto out;
        }
 
        /* external storage */
-       ret = storage_ext_get_space(storage_id, &total, NULL);
+       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_space(storage_id, &total, NULL);
 
 out:
-       if (ret < 0) {
-               _E("Failed to get total memory : id(%d)", storage_id); //LCOV_EXCL_LINE
-               if (ret == -ENOTSUP)
-                       return STORAGE_ERROR_NOT_SUPPORTED;
-               return STORAGE_ERROR_OPERATION_FAILED;
+       if (ret_val < 0) {
+               _E("Failed to get total memory : id(%d)", storage_id);
+               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;
@@ -425,11 +592,11 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes)
 {
        const struct storage_ops *st;
        unsigned long long avail;
-       int ret;
-       dd_list *elem;
+       int ret_val;
+       GList *elem;
 
        if (storage_id < 0)
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
 
        if (!bytes) {
                _E("Invalid parameger");
@@ -437,22 +604,34 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
-               ret = st->get_space(NULL, &avail);
+               ret_val = st->get_space(NULL, &avail);
                goto out;
        }
 
        /* external storage */
-       ret = storage_ext_get_space(storage_id, NULL, &avail);
+       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_space(storage_id, NULL, &avail);
 
 out:
-       if (ret < 0) {
-               _E("Failed to get available memory : id(%d)", storage_id); //LCOV_EXCL_LINE
-               if (ret == -ENOTSUP)
-                       return STORAGE_ERROR_NOT_SUPPORTED;
-               return STORAGE_ERROR_OPERATION_FAILED;
+       if (ret_val < 0) {
+               _E("Failed to get available memory : id(%d)", storage_id);
+               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;
@@ -461,15 +640,15 @@ out:
 
 API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data)
 {
-       int ret;
+       int ret_val;
        struct storage_cb_info info;
 
        if (type == STORAGE_TYPE_INTERNAL) {
                _E("Internal storage is not supported");
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
        }
 
-       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;
        }
@@ -479,15 +658,24 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback,
                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 = storage_ext_register_cb(STORAGE_CALLBACK_TYPE, &info);
-       if (ret < 0) {
-               _E("Failed to register storage callback(ret:%d)", ret); //LCOV_EXCL_LINE
+       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;
@@ -496,14 +684,14 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback,
 API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback)
 {
        struct storage_cb_info info;
-       int ret;
+       int ret_val;
 
        if (type == STORAGE_TYPE_INTERNAL) {
                _E("Internal storage is not supported");
-               return STORAGE_ERROR_NOT_SUPPORTED;
+               return STORAGE_ERROR_INVALID_PARAMETER;
        }
 
-       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;
        }
@@ -513,15 +701,102 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac
                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 = storage_ext_unregister_cb(STORAGE_CALLBACK_TYPE, &info);
-       if (ret < 0) {
-               _E("Failed to unregister storage callback(ret:%d)", ret); //LCOV_EXCL_LINE
+       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);
+                       }
+               }
+       }
+}