2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include "storage-internal.h"
27 #include "storage-external-dbus.h"
30 Get compat path from origin Multi-user path
31 from TZ_USER_CONTENT/.. to /opt/usr/media/..
32 Input should be normalized path like /opt/usr/home/owner/media (TODO: internal normalization)
34 Why this API should be provided?
35 In multi-user environment, each user has own compat content direcotry.(/opt/usr/media)
36 However, although system daemon operates real path,
37 system daemon needs to provide compat path to App if the real path is converted.
40 #include <storage-internal.h>
43 if(storage_get_compat_internal_path(src, sizeof(dest), dest) < 0)
44 // cannot convert. use src path
46 // can convert. use dest path
48 //LCOV_EXCL_START Untested function
49 API int storage_get_compat_internal_path(const char* origin, int len, char* compat)
55 if (!compat || !origin) {
56 _E("Invalid parameter");
60 // this API works on place where compat path is bind-mounted
61 if (!is_compat_bind_mount()) {
62 //LCOV_EXCL_START System Error
63 _E("No compat bind mount");
68 str = tzplatform_getenv(TZ_USER_CONTENT);
69 str_len = strlen(str);
70 if (strncmp(origin, str, str_len) != 0) {
71 _E("Failed to match TZ_USER_CONTENT");
75 r = snprintf(compat, len, "%s%s", COMPAT_DIR, origin + str_len);
77 //LCOV_EXCL_START System Error
78 _E("Failed to create new path");
88 Get Multi-user path from compat path
89 from /opt/usr/media/.. to TZ_USER_CONTENT/..
90 Input should be normalized path like /opt/usr/media (TODO: internal normalization)
92 Why this API should be provided?
93 In multi-user environment, each user has own compat content direcotry.(/opt/usr/media)
94 However, although some APIs send the compat path to system daemon,
95 system daemon should access real path.
98 #include <storage-internal.h>
101 if(storage_get_origin_internal_path(src, sizeof(dest), dest) < 0)
102 // cannot convert. use src path
104 // can convert. use dest path
106 API int storage_get_origin_internal_path(const char* compat, int len, char* origin)
111 if (!compat || !origin) {
112 _E("Invalid parameter");
116 // this API works on place where compat path is bind-mounted
117 if (!is_compat_bind_mount()) {
118 //LCOV_EXCL_START System Error
119 _E("no compat bind mount");
124 compat_len = strlen(COMPAT_DIR);
125 if (strncmp(compat, COMPAT_DIR, compat_len) != 0) {
126 _E("failed to match COMPAT_DIR");
130 r = snprintf(origin, len, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), compat + compat_len);
132 //LCOV_EXCL_START System Error
133 _E("failed to create new path");
141 API int storage_get_primary_sdcard(int *storage_id, char **path)
144 storage_ext_device info;
146 if (!storage_id || !path)
147 return STORAGE_ERROR_INVALID_PARAMETER;
149 result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
150 STORAGE_EXT_PATH_MANAGER,
151 STORAGE_EXT_IFACE_MANAGER,
155 //LCOV_EXCL_START System Error
156 _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE
157 return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
161 g_variant_get(result, "(issssssisibii)",
162 &info.type, &info.devnode, &info.syspath,
163 &info.fs_usage, &info.fs_type,
164 &info.fs_version, &info.fs_uuid,
165 &info.readonly, &info.mount_point,
166 &info.state, &info.primary,
167 &info.flags, &info.storage_id);
169 g_variant_unref(result);
171 if (info.storage_id < 0)
172 return STORAGE_ERROR_NO_DEVICE;
174 *path = strdup(info.mount_point);
176 return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error
178 *storage_id = info.storage_id;
180 return STORAGE_ERROR_NONE;
183 API int storage_get_storage_level(enum tzplatform_variable id, char **level)
188 return STORAGE_ERROR_INVALID_PARAMETER;
190 if (id != TZ_SYS_USER || id != TZ_SYS_TMP || id != TZ_SYS_OPT)
191 return STORAGE_ERROR_INVALID_PARAMETER;
193 ret = storage_ext_get_storage_level(id, level);
195 return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error
197 return STORAGE_ERROR_OPERATION_FAILED;
199 return STORAGE_ERROR_NONE;