#define _GNU_SOURCE
#endif
-#ifndef _BSD_SOURCE
-#define _BSD_SOURCE
+#ifndef _DEFAULT_SOURCE
+#define _DEFAULT_SOURCE
#endif
/*Include Headers*/
#include <stdio.h>
+#include <stdlib.h>
#include <fcntl.h>
-#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <dirent.h>
#include <unistd.h>
-#include <malloc.h>
-#include <stdlib.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <sys/types.h>
-#include <errno.h>
#include <sys/mount.h>
-#include <app2sd_interface.h>
+#include <sys/wait.h>
+#include <sys/xattr.h>
+#include <malloc.h>
+#include <math.h>
+#include <errno.h>
+#include <stdbool.h>
-#define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
+#include "app2sd_interface.h"
#define BUF_SIZE 256
-#define MEM_BUF_SIZE 5 /*Memory buffer size in MB*/
-#define PKG_BUF_SIZE 2 /*Memory buffer size in MB*/
+#define MEM_BUF_SIZE 5 /* Memory buffer size in MB */
+#define PKG_BUF_SIZE 2 /* Memory buffer size in MB */
/*Device entry defines*/
-#define DEV_MAJOR 7
+#define DEV_MAJOR 7
-#define FS_TYPE "ext4"
+#define FS_TYPE "ext4"
+#define INTERNAL_STORAGE_PATH "/opt"
typedef enum mount_type_t {
MOUNT_TYPE_RD = 0,
MOUNT_TYPE_RW_REMOUNT
} mount_type;
-typedef enum app2sd_cmd_t {
- APP2SD_PRE_INSTALL = 1,
- APP2SD_POST_INSTALL,
- APP2SD_PRE_UNINSTALL,
- APP2SD_POST_UNINSTALL,
- APP2SD_PRE_UPGRADE,
- APP2SD_POST_UPGRADE,
- APP2SD_APP_LAUNCH,
- APP2SD_APP_TERMINATE,
- APP2SD_MOVE_APP_TO_MMC,
- APP2SD_MOVE_APP_TO_PHONE
-} app2sd_cmd;
-
-/*This will store password in DB*/
-int _app2sd_set_passwod_in_db(const char *pkgid, const char *password);
-
-/*This will remove password from db*/
-int _app2sd_remove_password_from_db(const char *pkgid);
-
-/*This will fetch password from db*/
-char *_app2sd_get_passowrd_from_db(const char *pkgid);
-
-/*Checks whether mmc is present or not*/
-int _app2sd_check_mmc_status(void);
+/* checks whether mmc is present or not */
+/* sd_path should be freed after use */
+int _app2sd_check_mmc_status(char **sd_path);
-/*this function is similar to system()*/
+/* this function is similar to system() */
int _xsystem(const char *argv[]);
-/*this function will return the free available memory on the SD Card*/
-int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem);
+/* this function will return the free available memory on the SD Card */
+int _app2sd_get_available_free_memory(char *mmc_path, int *free_mem);
-/*Function to move the application from/to SD Card*/
-int _app2sd_move_app(const char *pkgid, app2ext_move_type move_cmd, GList* dir_list);
+/* function to move the application from/to SD Card */
+int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_cmd,
+ GList *dir_list, uid_t uid, char *mmc_path);
-/*utility to delete the directory*/
-int _app2sd_delete_directory(char *dirname);
+/* utility to delete symbolic link */
+void _app2sd_delete_symlink(const char *dirname);
-/*utility to calculate the size of a directory in MB*/
+/* utility to calculate the size of a directory in MB */
unsigned long long _app2sd_calculate_dir_size(char *dirname);
-/*utility to calculate the size of a file in MB*/
+/* utility to calculate the size of a file in MB */
unsigned long long _app2sd_calculate_file_size(const char *filename);
-/*Utility to copy a directory*/
+/* utility to copy a directory */
int _app2sd_copy_dir(const char *src, const char *dest);
-/*Utility to rename a directory*/
+/* utility to rename a directory */
int _app2sd_rename_dir(const char *old_name, const char *new_name);
-/*Utility to create application directory structure entry as per package type*/
-int _app2sd_create_directory_entry(const char *pkgid, GList* dir_list);
-
-/* Utility to create symlinks */
+/* utility to create symlinks */
int _app2sd_create_symlink(char *pkgid);
-/*This function finds the associated device node for the app*/
-char *_app2sd_find_associated_device_node(const char *pkgid);
+/* this function finds the associated device node for the app */
+char *_app2sd_find_associated_device_node(const char *loopback_device);
-/*This function does the loopback encryption for app*/
-char *_app2sd_do_loopback_encryption_setup(const char *pkgid);
+/* this function does the loopback encryption for app */
+char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
+ const char *loopback_device, uid_t uid);
-/*This function detaches the loopback device*/
+/* this function detaches the loopback device */
char *_app2sd_detach_loop_device(const char *device);
-/*This function finds loopback device associated with the app*/
-char *_app2sd_find_associated_device(const char *mmc_app_path);
+/* this function finds loopback device associated with the app */
+char *_app2sd_find_associated_device(const char *loopback_device);
-/*This function creates loopback device*/
-int _app2sd_create_loopback_device(const char *pkgid, int size);
+/* this function creates loopback device */
+int _app2sd_create_loopback_device(const char *pkgid,
+ const char *loopback_device, int size);
-/*This function deletes loopback device associated with the app*/
-int _app2sd_delete_loopback_device(const char *pkgid);
+/* this function deletes loopback device associated with the app */
+int _app2sd_delete_loopback_device(const char *loopback_device);
-/*This function creates ext4 FS on the device path*/
+/* this function creates ext4 FS on the device path */
int _app2sd_create_file_system(const char *device_path);
-/*This function mounts the app content on the device node*/
-int _app2sd_mount_app_content(const char *pkgid, const char *dev,
- int mount_type, GList* dir_list, app2sd_cmd cmd);
+/* this function mounts the app content on the device node */
+int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
+ const char *dev, int mount_type, GList* dir_list,
+ app2sd_cmd cmd, uid_t uid);
+
+/* this function unmounts the app content */
+int _app2sd_unmount_app_content(const char *application_path);
-/*This function unmounts the app content */
-int _app2sd_unmount_app_content(const char *pkgid);
+/* this function removes the loopbck encryption setup for the app */
+int _app2sd_remove_loopback_encryption_setup(const char *loopback_device);
-/*This function removes the loopbck encryption setup for the app*/
-int _app2sd_remove_loopback_encryption_setup(const char *pkgid);
+/* this function removes all of loopbck encryption setup for the app */
+int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device);
-/*This function updates loopback device size*/
+/* this function updates loopback device size */
int _app2sd_update_loopback_device_size(const char *pkgid,
- int size, GList* dir_list);
+ const char *loopback_device, const char *application_path,
+ const char *temp_pkgid, const char *temp_loopback_device,
+ const char *temp_application_path, int size, GList* dir_list,
+ uid_t uid);
-/* This generates password */
+/* this generates password */
char *_app2sd_generate_password(const char *pkgid);
-/*This function encrypts device*/
-char *_app2sd_encrypt_device(const char *device, const char *pkgid,
- char *passwd);
+/* this function encrypts device */
+char *_app2sd_encrypt_device(const char *device, const char *loopback_device,
+ char *passwd);
-/*This function finds free device*/
+/* this function finds free device */
char *_app2sd_find_free_device(void);
-/*This function initializes app2sd DB*/
+/* this function initializes app2sd DB */
int _app2sd_initialize_db();
-/*This function is used to get password from db*/
-char *_app2sd_get_password_from_db(const char *pkgid);
+/* this function is used to get password from db */
+char *_app2sd_get_password_from_db(const char *pkgid, uid_t uid);
+
+/* this function removes info from db */
+int _app2sd_remove_info_from_db(const char *pkgid, uid_t uid);
+
+/* this functions save info in db */
+int _app2sd_set_info_in_db(const char *pkgid, const char *passwd,
+ const char *loopback_device, uid_t uid);
+
+int _app2sd_get_info_from_db(const char *filename, char **pkgid, uid_t *uid);
-/*This function removes password from db */
-int _app2sd_remove_password_from_db(const char *pkgid);
+typedef int (*app2sd_info_cb)(const char *pkgid, uid_t uid);
-/* This functions saved password in db */
-int _app2sd_set_password_in_db(const char *pkgid,
- const char *passwd);
+int _app2sd_get_foreach_info_from_db(app2sd_info_cb cb_func);
-/* This functions setup path for smack */
-int _app2sd_setup_path(const char *pkgid, const char *dirpath,
- int apppathtype, const char *groupid);
+int _app2sd_force_clean(const char *pkgid, const char *application_path,
+ const char *loopback_device, uid_t uid);
+
+#ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
+/* this function setup dmcrypt header in the app2sd file */
+int _app2sd_dmcrypt_setup_device(const char *pkgid,
+ const char *loopback_device, bool is_dup, uid_t uid);
+
+/* this function maps the app2sd file with a dmcrypt device node */
+int _app2sd_dmcrypt_open_device(const char *pkgid, const char *loopback_device,
+ bool is_dup, uid_t uid, char **dev_node);
+
+/* this function remove dmcrypt device node */
+int _app2sd_dmcrypt_close_device(const char *pkgid, uid_t uid);
+
+/* this function find associated dmcrypt device node */
+char *_app2sd_find_associated_dmcrypt_device_node(const char *pkgid, uid_t uid);
+#endif
#endif