+/*
+ * libstorage
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * 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 <libmount.h>
#include "common.h"
int is_compat_bind_mount(void)
{
- struct libmnt_table *t = NULL;
- int r = 0;
- struct libmnt_fs *fs;
+ struct libmnt_table *t = NULL;
+ int r = 0;
+ struct libmnt_fs *fs;
- t = mnt_new_table();
- if(!t)
- return 0;
+ t = mnt_new_table();
+ if (!t)
+ return 0;
- r = mnt_table_parse_mtab(t, NULL);
- if (r < 0) {
- mnt_free_table(t);
- return 0;
- }
+ r = mnt_table_parse_mtab(t, NULL);
+ if (r < 0) {
+ mnt_free_table(t);
+ return 0;
+ }
- fs = mnt_table_find_target(t, COMPAT_DIR, MNT_ITER_BACKWARD);
- if (fs) {
+ fs = mnt_table_find_target(t, COMPAT_DIR, MNT_ITER_BACKWARD);
+ if (fs) {
// TODO : mnt_fs_get_root(fs) should be matched to tzplatform_getenv(TZ_USER_CONTENT).
mnt_free_table(t);
return 1;
- }
+ }
- mnt_free_table(t);
- return 0;
+ mnt_free_table(t);
+ return 0;
}
*/
API int storage_get_compat_internal_path(const char* origin, int len, char* compat)
{
- int r=-1;
+ int r = -1;
+ int str_len;
const char* str;
+ if (!compat || !origin) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
// this API works on place where compat path is bind-mounted
- if(!is_compat_bind_mount()){
- _E("no compat bind mount");
+ 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");
+ str_len = strlen(str);
+ if (strncmp(origin, str, str_len) != 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");
+ r = snprintf(compat, len, "%s/%s", COMPAT_DIR, origin + str_len);
+ if (r < 0) {
+ _E("Failed to create new path");
return -1;
}
API int storage_get_origin_internal_path(const char* compat, int len, char* origin)
{
int r;
+ int compat_len;
+
+ if (!compat || !origin) {
+ _E("Invalid parameter");
+ return -1;
+ }
// this API works on place where compat path is bind-mounted
- if(!is_compat_bind_mount()){
+ if (!is_compat_bind_mount()) {
_E("no compat bind mount");
return -1;
}
- if(strncmp(compat,COMPAT_DIR,strlen(COMPAT_DIR))!=0){
+ compat_len = strlen(COMPAT_DIR);
+ if (strncmp(compat, COMPAT_DIR, compat_len) != 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){
+ r = snprintf(origin, len, "%s/%s", tzplatform_getenv(TZ_USER_CONTENT), compat + compat_len);
+ if (r < 0) {
_E("failed to create new path");
return -1;
}