4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Garima Shrivastava<garima.s@samsung.com>
7 * Jyotsna Dhumale <jyotsna.a@samsung.com>
8 * Venkatesha Sarpangala <sarpangala.v@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 #ifndef _APP2SD_INTERNAL_H
25 #define _APP2SD_INTERNAL_H
31 #ifndef _DEFAULT_SOURCE
32 #define _DEFAULT_SOURCE
44 #include <sys/statvfs.h>
45 #include <sys/types.h>
46 #include <sys/mount.h>
48 #include <sys/xattr.h>
54 #include "app2sd_interface.h"
57 #define MEM_BUF_SIZE 5 /* Memory buffer size in MB */
58 #define PKG_BUF_SIZE 2 /* Memory buffer size in MB */
60 /*Device entry defines*/
63 #define FS_TYPE "ext4"
64 #define INTERNAL_STORAGE_PATH "/opt"
66 typedef enum mount_type_t {
70 MOUNT_TYPE_RD_REMOUNT,
74 /*Checks whether mmc is present or not*/
75 int _app2sd_check_mmc_status(void);
77 /*this function is similar to system()*/
78 int _xsystem(const char *argv[]);
80 /*this function will return the free available memory on the SD Card*/
81 int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem);
83 /*Function to move the application from/to SD Card*/
84 int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_cmd,
85 GList *dir_list, uid_t uid);
87 /*utility to delete symbolic link*/
88 void _app2sd_delete_symlink(const char *dirname);
90 /*utility to calculate the size of a directory in MB*/
91 unsigned long long _app2sd_calculate_dir_size(char *dirname);
93 /*utility to calculate the size of a file in MB*/
94 unsigned long long _app2sd_calculate_file_size(const char *filename);
96 /*Utility to copy a directory*/
97 int _app2sd_copy_dir(const char *src, const char *dest);
99 /*Utility to rename a directory*/
100 int _app2sd_rename_dir(const char *old_name, const char *new_name);
102 /* Utility to create symlinks */
103 int _app2sd_create_symlink(char *pkgid);
105 /*This function finds the associated device node for the app*/
106 char *_app2sd_find_associated_device_node(const char *loopback_device);
108 /*This function does the loopback encryption for app*/
109 char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
110 const char *loopback_device, uid_t uid);
112 /*This function detaches the loopback device*/
113 char *_app2sd_detach_loop_device(const char *device);
115 /*This function finds loopback device associated with the app*/
116 char *_app2sd_find_associated_device(const char *loopback_device);
118 /*This function creates loopback device*/
119 int _app2sd_create_loopback_device(const char *pkgid,
120 const char *loopback_device, int size);
122 /*This function deletes loopback device associated with the app*/
123 int _app2sd_delete_loopback_device(const char *loopback_device);
125 /*This function creates ext4 FS on the device path*/
126 int _app2sd_create_file_system(const char *device_path);
128 /*This function mounts the app content on the device node*/
129 int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
130 const char *dev, int mount_type, GList* dir_list,
131 app2sd_cmd cmd, uid_t uid);
133 /*This function unmounts the app content */
134 int _app2sd_unmount_app_content(const char *application_path);
136 /*This function removes the loopbck encryption setup for the app*/
137 int _app2sd_remove_loopback_encryption_setup(const char *loopback_device);
139 /*This function removes all of loopbck encryption setup for the app*/
140 int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device);
142 /*This function updates loopback device size*/
143 int _app2sd_update_loopback_device_size(const char *pkgid,
144 const char *loopback_device, const char *application_path,
145 const char *temp_pkgid, const char *temp_loopback_device,
146 const char *temp_application_path, int size, GList* dir_list,
149 /* This generates password */
150 char *_app2sd_generate_password(const char *pkgid);
152 /*This function encrypts device*/
153 char *_app2sd_encrypt_device(const char *device, const char *loopback_device,
156 /*This function finds free device*/
157 char *_app2sd_find_free_device(void);
159 /*This function initializes app2sd DB*/
160 int _app2sd_initialize_db();
162 /*This function is used to get password from db*/
163 char *_app2sd_get_password_from_db(const char *pkgid, uid_t uid);
165 /*This function removes info from db */
166 int _app2sd_remove_info_from_db(const char *pkgid, uid_t uid);
168 /* This functions save info in db */
169 int _app2sd_set_info_in_db(const char *pkgid, const char *passwd,
170 const char *loopback_device, uid_t uid);
172 int _app2sd_get_info_from_db(const char *filename, char **pkgid, uid_t *uid);
174 int _app2sd_force_clean(const char *pkgid, const char *application_path,
175 const char *loopback_device, uid_t uid);
177 #ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
178 /*This function setup dmcrypt header in the app2sd file */
179 int _app2sd_dmcrypt_setup_device(const char *pkgid,
180 const char *loopback_device, bool is_dup, uid_t uid);
182 /*This function maps the app2sd file with a dmcrypt device node */
183 int _app2sd_dmcrypt_open_device(const char *pkgid, const char *loopback_device,
184 bool is_dup, uid_t uid, char **dev_node);
186 /*This function remove dmcrypt device node */
187 int _app2sd_dmcrypt_close_device(const char *pkgid, uid_t uid);
189 /*This function find associated dmcrypt device node */
190 char *_app2sd_find_associated_dmcrypt_device_node(const char *pkgid, uid_t uid);