4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <device/power.h>
22 #include "media-util.h"
23 #include "media-common-dbg.h"
24 #include "media-common-system.h"
25 #include "media-common-utils.h"
27 int ms_verify_all_parent_dirs(const char *full_path, uid_t uid)
29 int ret = MS_MEDIA_ERR_NONE;
30 char *dir_path = NULL;
33 ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
35 ret = ms_user_get_storage_type(uid, full_path, &storage_type);
36 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Invalid path");
38 if (storage_type == MS_USER_STORAGE_INTERNAL) {
39 ret = ms_user_get_internal_root_path(uid, &dir_path);
40 MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_internal_root_path() fail");
42 next_pos = strlen(dir_path);
46 next_pos = strlen(MEDIA_ROOT_PATH_USB) + 1;
49 while ((next = strstr(full_path + next_pos, "/"))) {
50 next_pos = (next - full_path);
51 dir_path = g_strndup(full_path, next_pos);
54 ret = ms_check_scan_ignore(dir_path, uid);
56 if (ret != MS_MEDIA_ERR_NONE)
63 int ms_set_power_mode(ms_db_status_type_t status)
65 int res = MS_MEDIA_ERR_NONE;
70 err = device_power_request_lock(POWER_LOCK_CPU, 0);
72 res = MS_MEDIA_ERR_INTERNAL;
75 err = device_power_release_lock(POWER_LOCK_CPU);
77 res = MS_MEDIA_ERR_INTERNAL;
80 MS_DBG_ERR("Unacceptable type : %d", status);
87 void ms_trim_dir_path(char *dir_path)
89 /* need implementation */
90 /* if dir_path is not NULL terminated, this function will occure crash */
91 int len = strlen(dir_path);
93 if (dir_path[len -1] == '/')
94 dir_path[len -1] = '\0';
98 /* See media-common-utils-tv.c for common functions with a TV product implementation */
100 /* Public implementation */
101 bool ms_is_valid_symlink(const char *path)
103 g_autofree char *real_path = realpath(path, NULL);
108 return (g_strcmp0(real_path, MEDIA_SHARE_PATH) == 0);
111 int ms_check_scan_ignore(char *path, uid_t uid)
113 int ret = MS_MEDIA_ERR_NONE;
114 const char *ignore_file = ".scan_ignore";
115 char *tmp_path = NULL;
116 char *org_path = NULL;
117 char ignore_path[MS_FILE_PATH_LEN_MAX] = {0, };
119 char replace[MS_FILE_PATH_LEN_MAX] = {0, };
120 char *mediashared = NULL;
122 /* Check for symbolic link */
123 tmp_path = realpath(path, NULL);
124 /* Get trimmed path */
125 org_path = g_canonicalize_filename(path, NULL);
127 if (g_str_has_prefix(tmp_path, MEDIA_SHARE_PATH)) {
128 ms_user_get_mediashared_path(uid, &mediashared);
129 snprintf(replace, MS_FILE_PATH_LEN_MAX, "%s%s", mediashared, tmp_path + strlen(MEDIA_SHARE_PATH));
130 MS_SAFE_FREE(mediashared);
131 if (g_strcmp0(replace, org_path) != 0) {
132 MS_SAFE_FREE(tmp_path);
134 MS_DBG_ERR("symbolic link(directory)");
135 return MS_MEDIA_ERR_INVALID_PARAMETER;
138 if (g_strcmp0(tmp_path, org_path) != 0) {
139 MS_SAFE_FREE(tmp_path);
141 MS_DBG_ERR("symbolic link(directory)");
142 return MS_MEDIA_ERR_INVALID_PARAMETER;
146 MS_SAFE_FREE(tmp_path);
149 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
150 snprintf(ignore_path, sizeof(ignore_path), "%s/%s", path, ignore_file);
152 if (g_file_test(ignore_path, G_FILE_TEST_EXISTS)) {
153 MS_DBG_WARN("scan ignore file exist [%s]", ignore_path);
154 return MS_MEDIA_ERR_INVALID_PARAMETER;
157 MS_DBG_ERR("g_file_test fails[%s]", path);
158 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
163 #endif /* _USE_TVPD_MODE */