ret = _app2sd_set_info_in_db(pkgid, passwd, loopback_device,
uid);
- if (ret < 0) {
+ if (ret != 0) {
_E("unable to save password");
free(passwd);
return APP2EXT_ERROR_SQLITE_REGISTRY;
snprintf(dmcrypt_setup_cmd, sizeof(dmcrypt_setup_cmd),
"/bin/echo '%s' | /sbin/cryptsetup -q -i %d "
- "-c aes-cbc-lmk -s %d --align-payload=8 luksFormat %s",
+ "-c aes-cbc-lmk -s %d --align-payload=8 luksFormat "
+ "--type luks1 %s",
passwd, DMCRYPT_ITER_TIME, DMCRYPT_KEY_LEN,
loopback_device);
memset(passwd, 0, strlen(passwd));
return ret;
}
+static int __check_storage_availability(
+ const char *loopback_device, int free_internal_mem) {
+ unsigned long long temp;
+ int reqd_size;
+
+ temp = _app2sd_calculate_file_size(loopback_device);
+ reqd_size = (int)((temp) / (1024 * 1024));
+ _D("reqd size is (%d)", reqd_size);
+
+ if (reqd_size == 0) {
+ _E("app entry is not present in SD Card");
+ return APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE;
+ }
+
+ _I("reqd size: (%d)MB, free internal mem: (%d)MB",
+ reqd_size, free_internal_mem);
+
+ /* if avaialalbe free memory in internal storage is
+ * less than required size, return error
+ */
+ if (reqd_size > free_internal_mem) {
+ _E("innsufficient memory in internal storage"
+ " for application installation");
+ return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY;
+ }
+
+ return 0;
+}
+
+static int __copy_directories(const char *app_mmc_path, const char *app_archive_path,
+ const char *application_path, app2ext_dir_details *dir_detail)
+{
+ int ret;
+ char temp_dir_path[FILENAME_MAX];
+ char err_buf[1024];
+ const char *err_str;
+
+ ret = snprintf(temp_dir_path, sizeof(temp_dir_path), "%s/%s",
+ app_mmc_path, dir_detail->name);
+ if (ret < 0 || ret > sizeof(temp_dir_path)) {
+ _E("snprintf fail");
+ return -1;
+ }
+ _D("mmc2archive, temp_dir_path(%s)", temp_dir_path);
+ ret = _app2sd_copy_dir(temp_dir_path, app_archive_path);
+ if (ret) {
+ if (ret == APP2EXT_ERROR_ACCESS_FILE) {
+ _E("unable to access (%s)", temp_dir_path);
+ } else {
+ err_str = strerror_r(errno, err_buf,
+ sizeof(err_buf));
+ _E("unable to copy from (%s) to (%s),"
+ "error is (%s)", temp_dir_path,
+ app_archive_path, err_str);
+ }
+ return -1;
+ }
+ /* delete the symbolic link files [bin, lib, res]*/
+ ret = snprintf(temp_dir_path, sizeof(temp_dir_path), "%s/%s",
+ application_path, dir_detail->name);
+ if (ret < 0 || ret > sizeof(temp_dir_path)) {
+ _E("snprintf fail");
+ return -1;
+ }
+ _D("unlink, temp_dir_path(%s)", temp_dir_path);
+ ret = unlink(temp_dir_path);
+ if (ret) {
+ if (errno == ENOENT) {
+ _W("(%s) does not exist", temp_dir_path);
+ } else {
+ _E("unable to remove the symbolic link file "
+ "(%s), it is already unlinked",
+ temp_dir_path);
+ return -1;
+ }
+ }
+ /* Copy content to destination */
+ ret = snprintf(temp_dir_path, sizeof(temp_dir_path), "%s/%s",
+ app_archive_path, dir_detail->name);
+ if (ret < 0 || ret > sizeof(temp_dir_path)) {
+ _E("snprintf fail");
+ return -1;
+ }
+ _D("archive2app, temp_dir_path(%s)", temp_dir_path);
+ ret = _app2sd_copy_dir(temp_dir_path, application_path);
+ if (ret) {
+ if (ret == APP2EXT_ERROR_ACCESS_FILE) {
+ _E("unable to access (%s)", temp_dir_path);
+ } else {
+ err_str = strerror_r(errno, err_buf,
+ sizeof(err_buf));
+ _E("unable to copy from (%s) to (%s), "
+ "error is (%s)", temp_dir_path,
+ application_path, err_str);
+ }
+ return -1;
+ }
+ return 0;
+}
+
static int _app2sd_move_app_to_internal(const char *pkgid, GList *dir_list,
uid_t uid, char *mmc_path)
{
int ret;
mode_t mode = DIR_PERMS;
- char temp_dir_path[FILENAME_MAX];
char app_mmc_path[FILENAME_MAX];
char app_archive_path[FILENAME_MAX];
char application_path[FILENAME_MAX];
FILE *fp;
GList *list;
app2ext_dir_details *dir_detail;
- int reqd_size;
int free_internal_mem;
- unsigned long long temp = 0;
- char err_buf[1024];
- const char *err_str;
int mount_type;
ret = _app2sd_get_loopback_device_path(mmc_path, pkgid, uid,
return ret;
_app2sd_set_application_path(pkgid, uid, application_path,
- sizeof(application_path));
+ sizeof(application_path));
/* check whether application is in external memory or not */
fp = fopen(loopback_device, "r+");
if (fp == NULL) {
_E("application (%s) is not installed on SD Card",
- pkgid);
+ pkgid);
return APP2EXT_ERROR_FILE_ABSENT;
}
fclose(fp);
fclose(fp);
/* get installed app size*/
- temp = _app2sd_calculate_file_size(loopback_device);
- reqd_size = (int)((temp) / (1024 * 1024));
- _D("reqd size is (%d)", reqd_size);
-
- if (reqd_size == 0) {
- _E("app entry is not present in SD Card");
- return APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE;
- }
-
- _I("reqd size: (%d)MB, free internal mem: (%d)MB",
- reqd_size, free_internal_mem);
-
- /* if avaialalbe free memory in internal storage is
- * less than required size, return error
- */
- if (reqd_size > free_internal_mem) {
- _E("innsufficient memory in internal storage"
- " for application installation (%d)", ret);
- return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY;
- }
+ ret = __check_storage_availability(loopback_device, free_internal_mem);
+ if (ret)
+ return ret;
device_node =
_app2sd_find_associated_dmcrypt_device_node(pkgid, uid);
dir_detail->type != APP2EXT_DIR_RO)
continue;
/* archiving code */
- ret = snprintf(temp_dir_path, sizeof(temp_dir_path), "%s/%s",
- app_mmc_path, dir_detail->name);
- if (ret < 0 || ret > sizeof(temp_dir_path)) {
- _E("snprintf fail");
- ret = -1;
- goto ERR;
- }
- _D("mmc2archive, temp_dir_path(%s)", temp_dir_path);
- ret = _app2sd_copy_dir(temp_dir_path, app_archive_path);
- if (ret) {
- if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- _E("unable to access (%s)", temp_dir_path);
- } else {
- err_str = strerror_r(errno, err_buf,
- sizeof(err_buf));
- _E("unable to copy from (%s) to (%s),"
- "error is (%s)", temp_dir_path,
- app_archive_path, err_str);
- }
- goto ERR;
- }
- /* delete the symbolic link files [bin, lib, res]*/
- ret = snprintf(temp_dir_path, sizeof(temp_dir_path), "%s/%s",
- application_path, dir_detail->name);
- if (ret < 0 || ret > sizeof(temp_dir_path)) {
- _E("snprintf fail");
- ret = -1;
- goto ERR;
- }
- _D("unlink, temp_dir_path(%s)", temp_dir_path);
- ret = unlink(temp_dir_path);
- if (ret) {
- if (errno == ENOENT) {
- _W("(%s) does not exist", temp_dir_path);
- } else {
- _E("unable to remove the symbolic link file "
- "(%s), it is already unlinked",
- temp_dir_path);
- goto ERR;
- }
- }
- /* Copy content to destination */
- ret = snprintf(temp_dir_path, sizeof(temp_dir_path), "%s/%s",
- app_archive_path, dir_detail->name);
- if (ret < 0 || ret > sizeof(temp_dir_path)) {
- _E("snprintf fail");
+ ret = __copy_directories(app_mmc_path, app_archive_path,
+ application_path, dir_detail);
+ if (ret != 0) {
ret = -1;
goto ERR;
}
- _D("archive2app, temp_dir_path(%s)", temp_dir_path);
- ret = _app2sd_copy_dir(temp_dir_path, application_path);
- if (ret) {
- if (ret == APP2EXT_ERROR_ACCESS_FILE) {
- _E("unable to access (%s)", temp_dir_path);
- } else {
- err_str = strerror_r(errno, err_buf,
- sizeof(err_buf));
- _E("unable to copy from (%s) to (%s), "
- "error is (%s)", temp_dir_path,
- application_path, err_str);
- }
- goto ERR;
- }
}
_D("copying file completed");