+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "common.h"
-#include "list.h"
-#include "log.h"
-#include "storage-internal.h"
-#include "storage-external-dbus.h"
-
-API int storage_get_primary_sdcard(int *storage_id, char **path)
-{
- GVariant *result;
- storage_ext_device info;
-
- if (!storage_id || !path)
- return STORAGE_ERROR_INVALID_PARAMETER;
-
- result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
- STORAGE_EXT_PATH_MANAGER,
- STORAGE_EXT_IFACE_MANAGER,
- "GetMmcPrimary",
- NULL);
- if (!result) {
- _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE
- return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
- }
-
- g_variant_get(result, "(issssssisibii)",
- &info.type, &info.devnode, &info.syspath,
- &info.fs_usage, &info.fs_type,
- &info.fs_version, &info.fs_uuid,
- &info.readonly, &info.mount_point,
- &info.state, &info.primary,
- &info.flags, &info.storage_id);
-
- g_variant_unref(result);
-
- if (info.storage_id < 0)
- return STORAGE_ERROR_NO_DEVICE;
-
- *path = strdup(info.mount_point);
- if (*path == NULL)
- return STORAGE_ERROR_OUT_OF_MEMORY;
-
- *storage_id = info.storage_id;
-
- return STORAGE_ERROR_NONE;
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <tzplatform_config.h>
+
+#include "common.h"
+#include "list.h"
+#include "log.h"
+#include "storage-internal.h"
+#include "storage-external-dbus.h"
+
+/*
+ Get compat path from origin Multi-user path
+ from TZ_USER_CONTENT/.. to /opt/usr/media/..
+ Input should be normalized path like /opt/usr/home/owner/media (TODO: internal normalization)
+
+ Why this API should be provided?
+ In multi-user environment, each user has own compat content direcotry.(/opt/usr/media)
+ However, although system daemon operates real path,
+ system daemon needs to provide compat path to App if the real path is converted.
+
+ Usage:
+ #include <storage-internal.h>
+
+ char dest[100];
+ if(storage_get_compat_internal_path(src, sizeof(dest), dest) < 0)
+ // cannot convert. use src path
+ else
+ // can convert. use dest path
+ */
+API int storage_get_compat_internal_path(const char* origin, int len, char* compat)
+{
+ int r=-1;
+ const char* str;
+
+ // this API works on place where compat path is bind-mounted
+ if(!is_compat_bind_mount()){
+ _E("no compat bind mount");
+ return -1;
+ }
+
+ str = tzplatform_getenv(TZ_USER_CONTENT);
+ if(strncmp(origin,str,strlen(str))!=0){
+ _E("failed to match TZ_USER_CONTENT");
+ return -1;
+ }
+
+ r = snprintf(compat,len,"%s/%s",COMPAT_DIR,origin+strlen(str));
+ if(r < 0){
+ _E("failed to create new path");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ Get Multi-user path from compat path
+ from /opt/usr/media/.. to TZ_USER_CONTENT/..
+ Input should be normalized path like /opt/usr/media (TODO: internal normalization)
+
+ Why this API should be provided?
+ In multi-user environment, each user has own compat content direcotry.(/opt/usr/media)
+ However, although some APIs send the compat path to system daemon,
+ system daemon should access real path.
+
+ Usage:
+ #include <storage-internal.h>
+
+ char dest[100];
+ if(storage_get_origin_internal_path(src, sizeof(dest), dest) < 0)
+ // cannot convert. use src path
+ else
+ // can convert. use dest path
+*/
+API int storage_get_origin_internal_path(const char* compat, int len, char* origin)
+{
+ int r;
+
+ // this API works on place where compat path is bind-mounted
+ if(!is_compat_bind_mount()){
+ _E("no compat bind mount");
+ return -1;
+ }
+
+ if(strncmp(compat,COMPAT_DIR,strlen(COMPAT_DIR))!=0){
+ _E("failed to match COMPAT_DIR");
+ return -1;
+ }
+
+ r = snprintf(origin,len,"%s/%s",tzplatform_getenv(TZ_USER_CONTENT),compat+strlen(COMPAT_DIR));
+ if(r < 0){
+ _E("failed to create new path");
+ return -1;
+ }
+
+ return 0;
+}
+
+API int storage_get_primary_sdcard(int *storage_id, char **path)
+{
+ GVariant *result;
+ storage_ext_device info;
+
+ if (!storage_id || !path)
+ return STORAGE_ERROR_INVALID_PARAMETER;
+
+ result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+ STORAGE_EXT_PATH_MANAGER,
+ STORAGE_EXT_IFACE_MANAGER,
+ "GetMmcPrimary",
+ NULL);
+ if (!result) {
+ _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE
+ return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+ }
+
+ g_variant_get(result, "(issssssisibii)",
+ &info.type, &info.devnode, &info.syspath,
+ &info.fs_usage, &info.fs_type,
+ &info.fs_version, &info.fs_uuid,
+ &info.readonly, &info.mount_point,
+ &info.state, &info.primary,
+ &info.flags, &info.storage_id);
+
+ g_variant_unref(result);
+
+ if (info.storage_id < 0)
+ return STORAGE_ERROR_NO_DEVICE;
+
+ *path = strdup(info.mount_point);
+ if (*path == NULL)
+ return STORAGE_ERROR_OUT_OF_MEMORY;
+
+ *storage_id = info.storage_id;
+
+ return STORAGE_ERROR_NONE;
+}