get mount path of sdcard using storage api instead of hard-coded path.
[platform/core/appfw/app2sd.git] / plugin / app2sd / inc / app2sd_internals.h
1 /*
2  * app2ext
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Garima Shrivastava<garima.s@samsung.com>
7  *      Jyotsna Dhumale <jyotsna.a@samsung.com>
8  *      Venkatesha Sarpangala <sarpangala.v@samsung.com>
9  *
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
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
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.
21  *
22  */
23
24 #ifndef _APP2SD_INTERNAL_H
25 #define _APP2SD_INTERNAL_H
26
27 #ifndef _GNU_SOURCE
28 #define _GNU_SOURCE
29 #endif
30
31 #ifndef _DEFAULT_SOURCE
32 #define _DEFAULT_SOURCE
33 #endif
34
35 /*Include Headers*/
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <fcntl.h>
39 #include <string.h>
40 #include <stdarg.h>
41 #include <dirent.h>
42 #include <unistd.h>
43 #include <sys/stat.h>
44 #include <sys/statvfs.h>
45 #include <sys/types.h>
46 #include <sys/mount.h>
47 #include <sys/wait.h>
48 #include <sys/xattr.h>
49 #include <malloc.h>
50 #include <math.h>
51 #include <errno.h>
52 #include <stdbool.h>
53
54 #include "app2sd_interface.h"
55
56 #define BUF_SIZE 256
57 #define MEM_BUF_SIZE 5 /* Memory buffer size in MB */
58 #define PKG_BUF_SIZE 2 /* Memory buffer size in MB */
59
60 /*Device entry defines*/
61 #define DEV_MAJOR 7
62
63 #define FS_TYPE "ext4"
64 #define INTERNAL_STORAGE_PATH "/opt"
65
66 typedef enum mount_type_t {
67         MOUNT_TYPE_RD = 0,
68         MOUNT_TYPE_RW,
69         MOUNT_TYPE_RW_NOEXEC,
70         MOUNT_TYPE_RD_REMOUNT,
71         MOUNT_TYPE_RW_REMOUNT
72 } mount_type;
73
74 /* checks whether mmc is present or not */
75 /* sd_path should be freed after use */
76 int _app2sd_check_mmc_status(char **sd_path);
77
78 /* this function is similar to system() */
79 int _xsystem(const char *argv[]);
80
81 /* this function will return the free available memory on the SD Card */
82 int _app2sd_get_available_free_memory(char *mmc_path, int *free_mem);
83
84 /* function to move the application from/to SD Card */
85 int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_cmd,
86                 GList *dir_list, uid_t uid, char *mmc_path);
87
88 /* utility to delete symbolic link */
89 void _app2sd_delete_symlink(const char *dirname);
90
91 /* utility to calculate the size of a directory in MB */
92 unsigned long long _app2sd_calculate_dir_size(char *dirname);
93
94 /* utility to calculate the size of a file in MB */
95 unsigned long long _app2sd_calculate_file_size(const char *filename);
96
97 /* utility to copy a directory */
98 int _app2sd_copy_dir(const char *src, const char *dest);
99
100 /* utility to rename a directory */
101 int _app2sd_rename_dir(const char *old_name, const char *new_name);
102
103 /* utility to create symlinks */
104 int _app2sd_create_symlink(char *pkgid);
105
106 /* this function finds the associated device node for the app */
107 char *_app2sd_find_associated_device_node(const char *loopback_device);
108
109 /* this function does the loopback encryption for app */
110 char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
111                 const char *loopback_device, uid_t uid);
112
113 /* this function detaches the loopback device */
114 char *_app2sd_detach_loop_device(const char *device);
115
116 /* this function finds loopback device associated with the app */
117 char *_app2sd_find_associated_device(const char *loopback_device);
118
119 /* this function creates loopback device */
120 int _app2sd_create_loopback_device(const char *pkgid,
121                 const char *loopback_device, int size);
122
123 /* this function deletes loopback device associated with the app */
124 int _app2sd_delete_loopback_device(const char *loopback_device);
125
126 /* this function creates ext4 FS on the device path */
127 int _app2sd_create_file_system(const char *device_path);
128
129 /* this function mounts the app content on the device node */
130 int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
131                 const char *dev, int mount_type, GList* dir_list,
132                 app2sd_cmd cmd, uid_t uid);
133
134 /* this function unmounts the app content */
135 int _app2sd_unmount_app_content(const char *application_path);
136
137 /* this function removes the loopbck encryption setup for the app */
138 int _app2sd_remove_loopback_encryption_setup(const char *loopback_device);
139
140 /* this function removes all of loopbck encryption setup for the app */
141 int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device);
142
143 /* this function updates loopback device size */
144 int _app2sd_update_loopback_device_size(const char *pkgid,
145                 const char *loopback_device, const char *application_path,
146                 const char *temp_pkgid, const char *temp_loopback_device,
147                 const char *temp_application_path, int size, GList* dir_list,
148                 uid_t uid);
149
150 /* this generates password */
151 char *_app2sd_generate_password(const char *pkgid);
152
153 /* this function encrypts device */
154 char *_app2sd_encrypt_device(const char *device, const char *loopback_device,
155                 char *passwd);
156
157 /* this function finds free device */
158 char *_app2sd_find_free_device(void);
159
160 /* this function initializes app2sd DB */
161 int _app2sd_initialize_db();
162
163 /* this function is used to get password from db */
164 char *_app2sd_get_password_from_db(const char *pkgid, uid_t uid);
165
166 /* this function removes info from db */
167 int _app2sd_remove_info_from_db(const char *pkgid, uid_t uid);
168
169 /* this functions save info in db */
170 int _app2sd_set_info_in_db(const char *pkgid, const char *passwd,
171                 const char *loopback_device, uid_t uid);
172
173 int _app2sd_get_info_from_db(const char *filename, char **pkgid, uid_t *uid);
174
175 typedef int (*app2sd_info_cb)(const char *pkgid, uid_t uid);
176
177 int _app2sd_get_foreach_info_from_db(app2sd_info_cb cb_func);
178
179 int _app2sd_force_clean(const char *pkgid, const char *application_path,
180                 const char *loopback_device, uid_t uid);
181
182 #ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
183 /* this function setup dmcrypt header in the app2sd file */
184 int _app2sd_dmcrypt_setup_device(const char *pkgid,
185                 const char *loopback_device, bool is_dup, uid_t uid);
186
187 /* this function maps the app2sd file with a dmcrypt device node */
188 int _app2sd_dmcrypt_open_device(const char *pkgid, const char *loopback_device,
189                 bool is_dup, uid_t uid, char **dev_node);
190
191 /* this function remove dmcrypt device node */
192 int _app2sd_dmcrypt_close_device(const char *pkgid, uid_t uid);
193
194 /* this function find associated dmcrypt device node */
195 char *_app2sd_find_associated_dmcrypt_device_node(const char *pkgid, uid_t uid);
196 #endif
197
198 #endif