#include <string.h>
#include <errno.h>
#include <vconf.h>
+#include <tzplatform_config.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] = "DCIM",
- [STORAGE_DIRECTORY_DOWNLOADS] = "Downloads",
- [STORAGE_DIRECTORY_MUSIC] = "Music",
- [STORAGE_DIRECTORY_DOCUMENTS] = "Documents",
- [STORAGE_DIRECTORY_OTHERS] = "Others",
- [STORAGE_DIRECTORY_SYSTEM_RINGTONES] = "",
+#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] = {
+ [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 */
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;
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()) {
+ _D("Block module is not enabled");
+ return STORAGE_ERROR_NONE;
}
ret = storage_ext_foreach_device_list(callback, user_data);
dd_list *elem;
char root[PATH_MAX];
int ret;
+ bool extendedint;
+ bool user = true;
if (storage_id < 0)
return STORAGE_ERROR_NOT_SUPPORTED;
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
}
/* 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;
int ret;
dd_list *elem;
bool found;
+ bool extendedint;
+ bool user = true;
if (storage_id < 0)
return STORAGE_ERROR_NOT_SUPPORTED;
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);
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]);
{
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;
}
/* 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;
}
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;
}
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;
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;
}
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;
return STORAGE_ERROR_NONE;
}
+
+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);
+ }
+ }
+ }
+}