#ifdef _USE_TVPD_MODE
#include <sys/prctl.h>
+#include <usb-device.h>
#endif
#include <system_info.h>
#include <device/power.h>
-#ifndef _USE_DEVICED_DBUS
-#include <usb-device.h>
-#endif
-
#include "media-util.h"
#include "media-server-ipc.h"
#include "media-common-dbg.h"
return false;
}
-bool ms_config_get_str(const char *key, char **value)
-{
- char *res = NULL;
-
- if (key == NULL || value == NULL) {
- MS_DBG_ERR("Arguments key or value is NULL");
- return false;
- }
-
- res = vconf_get_str(key);
- if (MS_STRING_VALID(res)) {
- *value = g_strdup(res);
- MS_SAFE_FREE(res);
- return true;
- }
-
- return false;
-}
-
-int ms_get_remain_space(double *free_space)
+int ms_get_remain_space(uint64_t *free_space)
{
int ret = MS_MEDIA_ERR_NONE;
const char *path = "/opt";
}
/* f_bsize:unsigned long, f_bavail:fsblkcnt_t(unsigned long) */
- *free_space = (double)(s.f_bsize * s.f_bavail);
+ *free_space = (uint64_t)s.f_bsize * (uint64_t)s.f_bavail;
return MS_MEDIA_ERR_NONE;
}
}
#endif
+bool ms_is_valid_symlink(const char *path)
+{
+#ifdef _USE_TVPD_MODE
+ return false;
+#else
+ g_autofree char *real_path = realpath(path, NULL);
+
+ if (!real_path)
+ return false;
+
+ return (g_strcmp0(real_path, MEDIA_SHARE_PATH) == 0);
+#endif
+}
+
int ms_check_file_path(const char *file_path, uid_t uid)
{
ms_user_storage_type_e storage_type = -1;
{
int ret = MS_MEDIA_ERR_NONE;
char *dir_path = NULL;
- char *leaf_path = NULL;
- char *usr_path = NULL;
+ char *next = NULL;
+ int next_pos = 0;
ret = ms_check_file_path(full_path, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("invalid path : %s", full_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
- dir_path = g_path_get_dirname(full_path);
- if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
- MS_DBG_ERR("getting directory path is failed : %s", full_path);
- g_free(dir_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && !strncmp(full_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB))) {
+ next_pos = strlen(MEDIA_ROOT_PATH_USB) + 1;
+ } else {
+ ret = ms_user_get_internal_root_path(uid, &dir_path);
+ MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_internal_root_path() fail");
- ret = ms_user_get_internal_root_path(uid, &usr_path);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_user_get_internal_root_path() fail");
+ next_pos = strlen(dir_path);
g_free(dir_path);
- return MS_MEDIA_ERR_INTERNAL;
+ dir_path = NULL;
}
- while (1) {
- if (ms_check_scan_ignore(dir_path, uid) != MS_MEDIA_ERR_NONE) {
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- break;
- }
-
- if (strcmp(dir_path, usr_path) == 0)
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
- break;
- else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
- break;
+ while ((next = strstr(full_path + next_pos, "/"))) {
+ next_pos = (next - full_path);
+ dir_path = g_strndup(full_path, next_pos);
+ next_pos++;
- leaf_path = strrchr(dir_path, '/');
- if (leaf_path != NULL) {
- int seek_len = leaf_path -dir_path;
- dir_path[seek_len] = '\0';
- } else {
- MS_DBG_ERR("Fail to find leaf path");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ ret = ms_check_scan_ignore(dir_path, uid);
+ g_free(dir_path);
+ if (ret != MS_MEDIA_ERR_NONE)
break;
- }
}
- g_free(dir_path);
- g_free(usr_path);
-
return ret;
}
-static void __ms_trim_path(const char *input_path, char **output_path)
-{
- char buf[4096] = {0, };
- char tmp[4096] = {0, };
- char *pos = NULL;
-
- SAFE_STRLCPY(buf, input_path, sizeof(buf));
-
- while ((pos = strstr(buf, "//")) != NULL) {
- memset(tmp, 0, sizeof(tmp));
- SAFE_STRLCPY(tmp, buf, pos - buf + 1);
- SAFE_STRLCAT(tmp, pos + 1, sizeof(tmp));
-
- memset(buf, 0, sizeof(buf));
- SAFE_STRLCPY(buf, tmp, sizeof(buf));
- }
-
- if (g_str_has_suffix(buf, "/"))
- *output_path = g_strndup(buf, strlen(buf) - 1);
- else
- *output_path = g_strdup(buf);
-}
-
int ms_check_scan_ignore(char * path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
/* Check for symbolic link */
tmp_path = realpath(path, NULL);
/* Get trimmed path */
- __ms_trim_path(path, &org_path);
+ org_path = g_canonicalize_filename(path, NULL);
#ifdef _USE_TVPD_MODE
if (g_strcmp0(tmp_path, org_path) != 0) {
return ret;
}
-#ifndef _USE_DEVICED_DBUS
-
+#ifdef _USE_TVPD_MODE
typedef struct storage_result {
char *storage_path;
bool result;
bool ms_storage_mount_status(const char *start_path)
{
bool ret = false;
-#ifndef _USE_DEVICED_DBUS
+#ifdef _USE_TVPD_MODE
storage_result_s res = {0, };
char *remain_path = NULL;
int remain_len = 0;
dir_path[len -1] = '\0';
}
-int ms_check_size_mediadb(uid_t uid, double *db_size)
+int ms_check_size_mediadb(uid_t uid, uint64_t *db_size)
{
int ret = MS_MEDIA_ERR_NONE;
char *db_path = NULL;
ret = ms_user_get_media_db_path(uid, &db_path);
if (stat(db_path, &buf) == 0) {
- *db_size = buf.st_size;
+ *db_size = (uint64_t)buf.st_size;
} else {
MS_DBG_STRERROR("stat failed");
ret = MS_MEDIA_ERR_INTERNAL;