adjust app2sd-server capability
[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
53 #include "app2sd_interface.h"
54
55 #define BUF_SIZE 256
56 #define MEM_BUF_SIZE    5       /*Memory buffer size in MB*/
57 #define PKG_BUF_SIZE    2       /*Memory buffer size in MB*/
58
59 /*Device entry defines*/
60 #define DEV_MAJOR               7
61
62 #define FS_TYPE         "ext4"
63 #define INTERNAL_STORAGE_PATH "/opt"
64
65 typedef enum mount_type_t {
66         MOUNT_TYPE_RD = 0,
67         MOUNT_TYPE_RW,
68         MOUNT_TYPE_RW_NOEXEC,
69         MOUNT_TYPE_RD_REMOUNT,
70         MOUNT_TYPE_RW_REMOUNT
71 } mount_type;
72
73 /*Checks whether mmc is present or not*/
74 int _app2sd_check_mmc_status(void);
75
76 /*this function is similar to system()*/
77 int _xsystem(const char *argv[]);
78
79 /*this function will return the free available memory on the SD Card*/
80 int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem);
81
82 /*Function to move the application from/to SD Card*/
83 int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_cmd,
84                 GList* dir_list, uid_t uid);
85
86 /*utility to delete the directory*/
87 int _app2sd_delete_directory(const char *dirname);
88
89 /*utility to delete symbolic link*/
90 void _app2sd_delete_symlink(const char *dirname);
91
92 /*utility to calculate the size of a directory in MB*/
93 unsigned long long _app2sd_calculate_dir_size(char *dirname);
94
95 /*utility to calculate the size of a file in MB*/
96 unsigned long long _app2sd_calculate_file_size(const char *filename);
97
98 /*Utility to copy a directory*/
99 int _app2sd_copy_dir(const char *src, const char *dest);
100
101 /*Utility to rename a directory*/
102 int _app2sd_rename_dir(const char *old_name, const char *new_name);
103
104 /* Utility to create symlinks */
105 int _app2sd_create_symlink(char *pkgid);
106
107 /*This function finds the associated device node for the app*/
108 char *_app2sd_find_associated_device_node(const char *loopback_device);
109
110 /*This function does the loopback encryption for app*/
111 char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
112                 const char *loopback_device, uid_t uid);
113
114 /*This function detaches the loopback device*/
115 char *_app2sd_detach_loop_device(const char *device);
116
117 /*This function finds loopback device associated with the app*/
118 char *_app2sd_find_associated_device(const char *loopback_device);
119
120 /*This function creates loopback device*/
121 int _app2sd_create_loopback_device(const char *pkgid,
122                 const char *loopback_device, int size);
123
124 /*This function deletes loopback device associated with the app*/
125 int _app2sd_delete_loopback_device(const char *loopback_device);
126
127 /*This function creates ext4 FS on the device path*/
128 int _app2sd_create_file_system(const char *device_path);
129
130 /*This function mounts the app content on the device node*/
131 int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
132                 const char *dev, int mount_type, GList* dir_list,
133                 app2sd_cmd cmd, uid_t uid);
134
135 /*This function unmounts the app content */
136 int _app2sd_unmount_app_content(const char *application_path);
137
138 /*This function removes the loopbck encryption setup for the app*/
139 int _app2sd_remove_loopback_encryption_setup(const char *loopback_device);
140
141 /*This function removes all of loopbck encryption setup for the app*/
142 int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device);
143
144 /*This function updates loopback device size*/
145 int _app2sd_update_loopback_device_size(const char *pkgid,
146                 const char *loopback_device, const char *application_path,
147                 const char *temp_pkgid, const char *temp_loopback_device,
148                 const char *temp_application_path, int size, GList* dir_list,
149                 uid_t uid);
150
151 /* This generates password */
152 char *_app2sd_generate_password(const char *pkgid);
153
154 /*This function encrypts device*/
155 char *_app2sd_encrypt_device(const char *device, const char *loopback_device,
156                 char *passwd);
157
158 /*This function finds free device*/
159 char *_app2sd_find_free_device(void);
160
161 /*This function initializes app2sd DB*/
162 int _app2sd_initialize_db();
163
164 /*This function is used to get password from db*/
165 char *_app2sd_get_password_from_db(const char *pkgid);
166
167 /*This function removes password from db */
168 int _app2sd_remove_password_from_db(const char *pkgid);
169
170 /* This functions saved password in db */
171 int _app2sd_set_password_in_db(const char *pkgid, const char *passwd);
172
173 int _app2sd_force_clean(const char *pkgid, const char *application_path,
174                 const char *loopback_device);
175
176 #endif