[STORAGE_DIRECTORY_SYSTEM_RINGTONES] = "",
};
-static dd_list *st_head;
+static dd_list *st_int_head; /* Internal storage list */
void add_device(const struct storage_ops *st)
{
- DD_LIST_APPEND(st_head, st);
+ DD_LIST_APPEND(st_int_head, st);
}
void remove_device(const struct storage_ops *st)
{
- DD_LIST_REMOVE(st_head, st);
+ DD_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;
+ int ret;
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(),
+ 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;
- storage_id++;
}
+ /* TODO external storage */
+
return STORAGE_ERROR_NONE;
}
API int storage_get_root_directory(int storage_id, char **path)
{
const struct storage_ops *st;
+ dd_list *elem;
- if (!path) {
+ if (!path || storage_id < 0) {
_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;
+ /* internal storage */
+ DD_LIST_FOREACH(st_int_head, elem, st) {
+ if (st->storage_id != storage_id)
+ continue;
+ *path = strdup(st->root());
+ if (!*path) {
+ _E("Failed to copy the root string : %d", errno);
+ return STORAGE_ERROR_OUT_OF_MEMORY;
+ }
+ return STORAGE_ERROR_NONE;
}
- *path = strdup(st->root());
- if (!*path) {
- _E("Failed to copy the root string : %d", errno);
- return STORAGE_ERROR_OUT_OF_MEMORY;
- }
+ /* TODO external storage */
return STORAGE_ERROR_NONE;
}
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;
+ dd_list *elem;
+ bool found;
- if (!path) {
+ if (!path || storage_id < 0) {
_E("Invalid parameger");
return STORAGE_ERROR_INVALID_PARAMETER;
}
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;
+ /* internal storage */
+ found = false;
+ DD_LIST_FOREACH(st_int_head, elem, st) {
+ if (st->storage_id != storage_id)
+ continue;
+ found = true;
+ break;
}
- if (st->type != STORAGE_TYPE_INTERNAL
- && type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) {
- _E("Not support directory : id(%d) type(%d)", storage_id, type);
- return STORAGE_ERROR_NOT_SUPPORTED;
+ if (found && st) {
+ 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);
+ 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]);
+
+ goto out;
}
- root = 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);
- 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]);
+ /* external storage */
+ return STORAGE_ERROR_NONE;
+out:
*path = strdup(temp);
if (!*path) {
_E("Failed to copy the directory(%d) string : %d", type, errno);
API int storage_get_type(int storage_id, storage_type_e *type)
{
const struct storage_ops *st;
+ dd_list *elem;
- if (!type) {
+ if (!type || storage_id < 0) {
_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;
+ /* internal storage */
+ DD_LIST_FOREACH(st_int_head, elem, st) {
+ if (st->storage_id != storage_id)
+ continue;
+ *type = st->type;
+ return STORAGE_ERROR_NONE;
}
- *type = st->type;
+ /* external storage */
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;
+ dd_list *elem;
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);
- return STORAGE_ERROR_NOT_SUPPORTED;
+ /* internal storage */
+ DD_LIST_FOREACH(st_int_head, elem, ops) {
+ if (ops->storage_id != storage_id)
+ continue;
+ *state = ops->get_state();
+ return STORAGE_ERROR_NONE;
}
- *state = st->get_state();
+ /* external storage */
return STORAGE_ERROR_NONE;
}
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;
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;
- }
-
- /* do not register changed callback in case of internal memory */
- if (st->type == STORAGE_TYPE_INTERNAL)
- return STORAGE_ERROR_NONE;
-
- info.id = storage_id;
- info.state_cb = callback;
- info.user_data = user_data;
+ /* Internal storage does not support registering changed callback */
+ DD_LIST_FOREACH(st_int_head, elem, st)
+ if (st->storage_id == storage_id)
+ return STORAGE_ERROR_NONE;
- ret = st->register_cb(STORAGE_CALLBACK_STATE, &info);
- if (ret < 0) {
- _E("Failed to register callback : id(%d)", storage_id);
- return STORAGE_ERROR_OPERATION_FAILED;
- }
+ /* external storage */
return STORAGE_ERROR_NONE;
}
API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb callback)
{
const struct storage_ops *st;
- struct storage_cb_info info;
- int ret;
+ dd_list *elem;
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;
- }
-
- /* in case of internal memory, it does not register changed callback */
- if (st->type == STORAGE_TYPE_INTERNAL)
- return STORAGE_ERROR_NONE;
-
- info.id = storage_id;
- info.state_cb = callback;
-
- ret = st->unregister_cb(STORAGE_CALLBACK_STATE, &info);
- if (ret < 0) {
- _E("Failed to unregister callback : id(%d)", storage_id);
- return STORAGE_ERROR_OPERATION_FAILED;
- }
+ /* Internal storage does not support registering changed callback */
+ DD_LIST_FOREACH(st_int_head, elem, st)
+ if (st->storage_id == storage_id)
+ return STORAGE_ERROR_NONE;
return STORAGE_ERROR_NONE;
}
const struct storage_ops *st;
unsigned long long total;
int ret;
+ dd_list *elem;
- if (!bytes) {
+ if (!bytes || storage_id < 0) {
_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;
+ /* internal storage */
+ DD_LIST_FOREACH(st_int_head, elem, st) {
+ if (st->storage_id != storage_id)
+ continue;
+ ret = st->get_space(&total, NULL);
+ goto out;
}
- ret = st->get_space(&total, NULL);
+ /* external storage */
+ ret = 0;
+
+out:
if (ret < 0) {
_E("Failed to get total memory : id(%d)", storage_id);
return STORAGE_ERROR_OPERATION_FAILED;
}
*bytes = total;
-
return STORAGE_ERROR_NONE;
}
const struct storage_ops *st;
unsigned long long avail;
int ret;
+ dd_list *elem;
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);
- return STORAGE_ERROR_NOT_SUPPORTED;
+ /* internal storage */
+ DD_LIST_FOREACH(st_int_head, elem, st) {
+ if (st->storage_id != storage_id)
+ continue;
+ ret = st->get_space(NULL, &avail);
+ goto out;
}
- ret = st->get_space(NULL, &avail);
+ /* external storage */
+ ret = 0;
+
+out:
if (ret < 0) {
_E("Failed to get available memory : id(%d)", storage_id);
return STORAGE_ERROR_OPERATION_FAILED;
}
*bytes = avail;
-
return STORAGE_ERROR_NONE;
}