From 062d6b0bb38801393a94111b392640e16f73c69b Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 3 Jul 2010 13:54:21 -0700 Subject: [PATCH] Backup of Froyo apps on external storage. --- extendedcommands.c | 1 - nandroid.c | 53 +++++++++++++++++++++++++++++++++++++++------- recovery.c | 1 + roots.c | 2 ++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/extendedcommands.c b/extendedcommands.c index c79836e..9310d21 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -448,7 +448,6 @@ int format_non_mtd_device(const char* root) ui_print("Error mounting %s!\n", path); ui_print("Skipping format...\n"); return 0; - } static char tmp[PATH_MAX]; diff --git a/nandroid.c b/nandroid.c index 763ce5b..00afbd9 100644 --- a/nandroid.c +++ b/nandroid.c @@ -75,7 +75,7 @@ void compute_directory_stats(char* directory) ui_show_progress(1, 0); } -int nandroid_backup_partition(const char* backup_path, char* root) { +int nandroid_backup_partition_extended(const char* backup_path, char* root, int umount_when_finished) { int ret = 0; char mount_point[PATH_MAX]; translate_root_path(root, mount_point, PATH_MAX); @@ -96,7 +96,9 @@ int nandroid_backup_partition(const char* backup_path, char* root) { char tmp[PATH_MAX]; sprintf(tmp, "%s/%s.img", backup_path, name); ret = mkyaffs2image(mount_point, tmp, 0, callback); - ensure_root_path_unmounted(root); + if (umount_when_finished) { + ensure_root_path_unmounted(root); + } if (0 != ret) { ui_print("Error while making a yaffs2 image of %s!\n", mount_point); return ret; @@ -104,6 +106,10 @@ int nandroid_backup_partition(const char* backup_path, char* root) { return 0; } +int nandroid_backup_partition(const char* backup_path, char* root) { + return nandroid_backup_partition_extended(backup_path, root, 1); +} + int nandroid_backup(const char* backup_path) { ui_set_background(BACKGROUND_ICON_INSTALLING); @@ -150,10 +156,20 @@ int nandroid_backup(const char* backup_path) return ret; #endif - if (0 != (ret = nandroid_backup_partition(backup_path, "CACHE:"))) + struct stat st; + if (0 != stat("/sdcard/.android_secure", &st)) + { + ui_print("No /sdcard/.android_secure found. Skipping backup of applications on external storage.\n"); + } + else + { + if (0 != (ret = nandroid_backup_partition_extended(backup_path, "SDCARD:/.android_secure", 0))) + return ret; + } + + if (0 != (ret = nandroid_backup_partition_extended(backup_path, "CACHE:", 0))) return ret; - struct stat st; if (0 != stat(SDEXT_DEVICE, &st)) { ui_print("No sd-ext found. Skipping backup of sd-ext.\n"); @@ -165,7 +181,7 @@ int nandroid_backup(const char* backup_path) else if (0 != (ret = nandroid_backup_partition(backup_path, "SDEXT:"))) return ret; } - + ui_print("Generating md5 sum...\n"); sprintf(tmp, "nandroid-md5.sh %s", backup_path); if (0 != (ret = __system(tmp))) { @@ -182,7 +198,7 @@ int nandroid_backup(const char* backup_path) typedef int (*format_function)(char* root); -int nandroid_restore_partition(const char* backup_path, const char* root) { +int nandroid_restore_partition_extended(const char* backup_path, const char* root, int umount_when_finished) { int ret = 0; char mount_point[PATH_MAX]; translate_root_path(root, mount_point, PATH_MAX); @@ -216,12 +232,17 @@ int nandroid_restore_partition(const char* backup_path, const char* root) { return ret; } - if (0 != strcmp(root, "CACHE")) { + if (umount_when_finished) { ensure_root_path_unmounted(root); } + return 0; } +int nandroid_restore_partition(const char* backup_path, const char* root) { + return nandroid_restore_partition_extended(backup_path, root, 1); +} + int nandroid_restore(const char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache, int restore_sdext) { ui_set_background(BACKGROUND_ICON_INSTALLING); @@ -263,7 +284,23 @@ int nandroid_restore(const char* backup_path, int restore_boot, int restore_syst return ret; #endif - if (restore_cache && 0 != (ret = nandroid_restore_partition(backup_path, "CACHE:"))) + if (restore_data) + { + struct statfs s; + sprintf(tmp, "%s/.android_secure.img", backup_path); + if (0 != (ret = statfs(tmp, &s))) + { + ui_print(".android_secure.img not found. Skipping restore of applications on external storage."); + } + else + { + __system("mkdir -p /sdcard/.android_secure"); + if (0 != (ret = nandroid_restore_partition_extended(backup_path, "SDCARD:/.android_secure", 0))) + return ret; + } + } + + if (restore_cache && 0 != (ret = nandroid_restore_partition_extended(backup_path, "CACHE:", 0))) return ret; if (restore_sdext) diff --git a/recovery.c b/recovery.c index d169cdb..344ed46 100644 --- a/recovery.c +++ b/recovery.c @@ -397,6 +397,7 @@ wipe_data(int confirm) { #endif erase_root("CACHE:"); erase_root("SDEXT:"); + erase_root("SDCARD:/.android_secure"); ui_print("Data wipe complete.\n"); } diff --git a/roots.c b/roots.c index 535a1a7..d54de2d 100644 --- a/roots.c +++ b/roots.c @@ -314,10 +314,12 @@ format_root_device(const char *root) while (*c != '\0' && *c != ':') { c++; } + /* if (c[0] != ':' || c[1] != '\0') { LOGW("format_root_device: bad root name \"%s\"\n", root); return -1; } + */ const RootInfo *info = get_root_info_for_path(root); if (info == NULL || info->device == NULL) {