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.
22 #include <tzplatform_config.h>
27 #include "storage-internal.h"
28 #include "storage-external-dbus.h"
31 Get compat path from origin Multi-user path
32 from TZ_USER_CONTENT/.. to /opt/usr/media/..
33 Input should be normalized path like /opt/usr/home/owner/media (TODO: internal normalization)
35 Why this API should be provided?
36 In multi-user environment, each user has own compat content direcotry.(/opt/usr/media)
37 However, although system daemon operates real path,
38 system daemon needs to provide compat path to App if the real path is converted.
41 #include <storage-internal.h>
44 if(storage_get_compat_internal_path(src, sizeof(dest), dest) < 0)
45 // cannot convert. use src path
47 // can convert. use dest path
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 _E("No compat bind mount");
66 str = tzplatform_getenv(TZ_USER_CONTENT);
67 str_len = strlen(str);
68 if (strncmp(origin, str, str_len) != 0) {
69 _E("Failed to match TZ_USER_CONTENT");
73 r = snprintf(compat, len, "%s%s", COMPAT_DIR, origin + str_len);
75 _E("Failed to create new path");
83 Get Multi-user path from compat path
84 from /opt/usr/media/.. to TZ_USER_CONTENT/..
85 Input should be normalized path like /opt/usr/media (TODO: internal normalization)
87 Why this API should be provided?
88 In multi-user environment, each user has own compat content direcotry.(/opt/usr/media)
89 However, although some APIs send the compat path to system daemon,
90 system daemon should access real path.
93 #include <storage-internal.h>
96 if(storage_get_origin_internal_path(src, sizeof(dest), dest) < 0)
97 // cannot convert. use src path
99 // can convert. use dest path
101 API int storage_get_origin_internal_path(const char* compat, int len, char* origin)
106 if (!compat || !origin) {
107 _E("Invalid parameter");
111 // this API works on place where compat path is bind-mounted
112 if (!is_compat_bind_mount()) {
113 _E("no compat bind mount");
117 compat_len = strlen(COMPAT_DIR);
118 if (strncmp(compat, COMPAT_DIR, compat_len) != 0) {
119 _E("failed to match COMPAT_DIR");
123 r = snprintf(origin, len, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), compat + compat_len);
125 _E("failed to create new path");
132 API int storage_get_primary_sdcard(int *storage_id, char **path)
135 storage_ext_device info;
137 if (!storage_id || !path)
138 return STORAGE_ERROR_INVALID_PARAMETER;
140 result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
141 STORAGE_EXT_PATH_MANAGER,
142 STORAGE_EXT_IFACE_MANAGER,
146 _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE
147 return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
150 g_variant_get(result, "(issssssisibii)",
151 &info.type, &info.devnode, &info.syspath,
152 &info.fs_usage, &info.fs_type,
153 &info.fs_version, &info.fs_uuid,
154 &info.readonly, &info.mount_point,
155 &info.state, &info.primary,
156 &info.flags, &info.storage_id);
158 g_variant_unref(result);
160 if (info.storage_id < 0)
161 return STORAGE_ERROR_NO_DEVICE;
163 *path = strdup(info.mount_point);
165 return STORAGE_ERROR_OUT_OF_MEMORY;
167 *storage_id = info.storage_id;
169 return STORAGE_ERROR_NONE;
172 API int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev)
174 storage_ext_device *ext_dev;
177 if (storage_id < 0) {
178 _E("Invalid parameger");
179 return STORAGE_ERROR_NOT_SUPPORTED;
183 _E("Invalid parameger");
184 return STORAGE_ERROR_INVALID_PARAMETER;
188 _E("Invalid parameger");
189 return STORAGE_ERROR_INVALID_PARAMETER;
192 ret = storage_get_type(storage_id, type);
193 if (ret != STORAGE_ERROR_NONE) {
194 _E("Failed to get storage type: %d", ret);
198 ext_dev = calloc(1, sizeof(storage_ext_device));
200 //LCOV_EXCL_START System Error
202 return STORAGE_ERROR_OUT_OF_MEMORY;
206 ret = storage_ext_get_device_info(storage_id, ext_dev);
208 _E("Cannot get the storage with id (%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE
209 ret = STORAGE_ERROR_NOT_SUPPORTED;
213 if (ext_dev->type == STORAGE_EXT_SCSI)
214 *dev = STORAGE_DEV_EXT_USB_MASS_STORAGE;
215 else if (ext_dev->type == STORAGE_EXT_MMC)
216 *dev = STORAGE_DEV_EXT_SDCARD;
217 ret = STORAGE_ERROR_NONE;
218 _I("type: %d(internal:0, external:1) dev: %d(sdcard: 1001, usb: 1002)", *type, *dev);
221 storage_ext_release_device(&ext_dev);