b2e1a9101bf1a257b36d3198cc6848923f9a3e4b
[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 _BSD_SOURCE
32 #define _BSD_SOURCE
33 #endif
34
35 /*Include Headers*/
36 #include <stdio.h>
37 #include <fcntl.h>
38 #include <errno.h>
39 #include <string.h>
40 #include <stdarg.h>
41 #include <dirent.h>
42 #include <unistd.h>
43 #include <malloc.h>
44 #include <stdlib.h>
45 #include <sys/stat.h>
46 #include <sys/types.h>
47 #include <errno.h>
48 #include <sys/mount.h>
49 #include <app2sd_interface.h>
50
51 #define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
52
53 #define BUF_SIZE 256
54 #define MEM_BUF_SIZE    5       /*Memory buffer size in MB*/
55 #define PKG_BUF_SIZE    2       /*Memory buffer size in MB*/
56
57 /*Device entry defines*/
58 #define DEV_MAJOR               7
59
60 #define FS_TYPE         "ext4"
61
62 typedef enum mount_type_t {
63         MOUNT_TYPE_RD = 0,
64         MOUNT_TYPE_RW,
65         MOUNT_TYPE_RW_NOEXEC,
66         MOUNT_TYPE_RD_REMOUNT,
67         MOUNT_TYPE_RW_REMOUNT
68 } mount_type;
69
70 typedef enum app2sd_cmd_t {
71         APP2SD_PRE_INSTALL = 1,
72         APP2SD_POST_INSTALL,
73         APP2SD_PRE_UNINSTALL,
74         APP2SD_POST_UNINSTALL,
75         APP2SD_PRE_UPGRADE,
76         APP2SD_POST_UPGRADE,
77         APP2SD_APP_LAUNCH,
78         APP2SD_APP_TERMINATE,
79         APP2SD_MOVE_APP_TO_MMC,
80         APP2SD_MOVE_APP_TO_PHONE
81 } app2sd_cmd;
82
83 /*This will store password in DB*/
84 int _app2sd_set_passwod_in_db(const char *pkgid, const char *password);
85
86 /*This will remove password from db*/
87 int _app2sd_remove_password_from_db(const char *pkgid);
88
89 /*This will fetch password from db*/
90 char *_app2sd_get_passowrd_from_db(const char *pkgid);
91
92 /*Checks whether mmc is present or not*/
93 int _app2sd_check_mmc_status(void);
94
95 /*this function is similar to system()*/
96 int _xsystem(const char *argv[]);
97
98 /*this function will return the free available memory on the SD Card*/
99 int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem);
100
101 /*Function to move the application from/to SD Card*/
102 int _app2sd_move_app(const char *pkgid, app2ext_move_type move_cmd, GList* dir_list);
103
104 /*utility to delete the directory*/
105 int _app2sd_delete_directory(char *dirname);
106
107 /*utility to calculate the size of a directory in MB*/
108 unsigned long long _app2sd_calculate_dir_size(char *dirname);
109
110 /*utility to calculate the size of a file in MB*/
111 unsigned long long _app2sd_calculate_file_size(const char *filename);
112
113 /*Utility to copy a directory*/
114 int _app2sd_copy_dir(const char *src, const char *dest);
115
116 /*Utility to rename a directory*/
117 int _app2sd_rename_dir(const char *old_name, const char *new_name);
118
119 /*Utility to create application directory structure entry as per package type*/
120 int _app2sd_create_directory_entry(const char *pkgid, GList* dir_list);
121
122 /* Utility to create symlinks */
123 int _app2sd_create_symlink(char *pkgid);
124
125 /*This function finds the associated device node for the app*/
126 char *_app2sd_find_associated_device_node(const char *pkgid);
127
128 /*This function does the loopback encryption for app*/
129 char *_app2sd_do_loopback_encryption_setup(const char *pkgid);
130
131 /*This function detaches the loopback device*/
132 char *_app2sd_detach_loop_device(const char *device);
133
134 /*This function finds loopback device associated with the app*/
135 char *_app2sd_find_associated_device(const char *mmc_app_path);
136
137 /*This function creates loopback device*/
138 int _app2sd_create_loopback_device(const char *pkgid, int size);
139
140 /*This function deletes loopback device associated with the app*/
141 int _app2sd_delete_loopback_device(const char *pkgid);
142
143 /*This function creates ext4 FS on the device path*/
144 int _app2sd_create_file_system(const char *device_path);
145
146 /*This function mounts the app content on the device node*/
147 int _app2sd_mount_app_content(const char *pkgid, const char *dev,
148                         int mount_type, GList* dir_list, app2sd_cmd cmd);
149
150 /*This function unmounts the app content */
151 int _app2sd_unmount_app_content(const char *pkgid);
152
153 /*This function removes the loopbck encryption setup for the app*/
154 int _app2sd_remove_loopback_encryption_setup(const char *pkgid);
155
156 /*This function updates loopback device size*/
157 int _app2sd_update_loopback_device_size(const char *pkgid,
158         int size, GList* dir_list);
159
160 /* This generates password */
161 char *_app2sd_generate_password(const char *pkgid);
162
163 /*This function encrypts device*/
164 char *_app2sd_encrypt_device(const char *device, const char *pkgid,
165                               char *passwd);
166
167 /*This function finds free device*/
168 char *_app2sd_find_free_device(void);
169
170 /*This function initializes app2sd DB*/
171 int _app2sd_initialize_db();
172
173 /*This function is used to get password from db*/
174 char *_app2sd_get_password_from_db(const char *pkgid);
175
176 /*This function removes password from db */
177 int _app2sd_remove_password_from_db(const char *pkgid);
178
179 /* This functions saved password in db */
180 int _app2sd_set_password_in_db(const char *pkgid,
181                                       const char *passwd);
182
183 /* This functions setup path for smack */
184 int _app2sd_setup_path(const char *pkgid, const char *dirpath,
185                                                 int apppathtype, const char *groupid);
186
187 #endif