aboutsummaryrefslogtreecommitdiffstats
path: root/nandroid.c
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2011-09-05 21:14:06 -0700
committerKoushik Dutta <koushd@gmail.com>2011-09-05 21:14:06 -0700
commit30a937a954e78ac600cae97ae86f0a9bc6481ab8 (patch)
tree46480d66823a6e1c512a88167cd744e188d2fbc7 /nandroid.c
parentbf5a60a0343aa1b885539c608566d1d92616ecea (diff)
downloadbootable_recovery-30a937a954e78ac600cae97ae86f0a9bc6481ab8.zip
bootable_recovery-30a937a954e78ac600cae97ae86f0a9bc6481ab8.tar.gz
bootable_recovery-30a937a954e78ac600cae97ae86f0a9bc6481ab8.tar.bz2
cwr 5
Change-Id: I70cbb4df78b0bbc9d227d19aa6d9434eba2b540d
Diffstat (limited to 'nandroid.c')
-rw-r--r--nandroid.c105
1 files changed, 81 insertions, 24 deletions
diff --git a/nandroid.c b/nandroid.c
index f4b2a74..30190fa 100644
--- a/nandroid.c
+++ b/nandroid.c
@@ -101,15 +101,17 @@ typedef void (*file_event_callback)(const char* filename);
typedef int (*nandroid_backup_handler)(const char* backup_path, const char* backup_file_image, int callback);
static int mkyaffs2image_wrapper(const char* backup_path, const char* backup_file_image, int callback) {
- return mkyaffs2image(backup_path, backup_file_image, 0, callback ? yaffs_callback : NULL);
+ char backup_file_image_with_extension[PATH_MAX];
+ sprintf(backup_file_image_with_extension, "%s.img", backup_file_image);
+ return mkyaffs2image(backup_path, backup_file_image_with_extension, 0, callback ? yaffs_callback : NULL);
}
static int tar_compress_wrapper(const char* backup_path, const char* backup_file_image, int callback) {
char tmp[PATH_MAX];
if (strcmp(backup_path, "/data") == 0 && volume_for_path("/sdcard") == NULL)
- sprintf(tmp, "cd $(dirname %s) ; tar cvf %s --exclude 'media' $(basename %s) ; exit $?", backup_path, backup_file_image, backup_path);
+ sprintf(tmp, "cd $(dirname %s) ; tar cvf %s.tar --exclude 'media' $(basename %s) ; exit $?", backup_path, backup_file_image, backup_path);
else
- sprintf(tmp, "cd $(dirname %s) ; tar cvf %s $(basename %s) ; exit $?", backup_path, backup_file_image, backup_path);
+ sprintf(tmp, "cd $(dirname %s) ; tar cvf %s.tar $(basename %s) ; exit $?", backup_path, backup_file_image, backup_path);
FILE *fp = __popen(tmp, "r");
if (fp == NULL) {
@@ -132,7 +134,6 @@ static nandroid_backup_handler get_backup_handler(const char *backup_path) {
ui_print("Unable to find volume.\n");
return NULL;
}
- scan_mounted_volumes();
MountedVolume *mv = find_mounted_volume_by_mount_point(v->mount_point);
if (mv == NULL) {
ui_print("Unable to find mounted volume: %s\n", v->mount_point);
@@ -143,14 +144,15 @@ static nandroid_backup_handler get_backup_handler(const char *backup_path) {
return tar_compress_wrapper;
}
- char str[255];
- char* partition;
- property_get("ro.cwm.prefer_tar", str, "false");
- if (strcmp("true", str) != 0) {
+ // cwr5, we prefer tar for everything except yaffs2
+ if (strcmp("yaffs2", mv->filesystem) == 0) {
return mkyaffs2image_wrapper;
}
- if (strcmp("yaffs2", mv->filesystem) == 0) {
+ char str[255];
+ char* partition;
+ property_get("ro.cwm.prefer_tar", str, "true");
+ if (strcmp("true", str) != 0) {
return mkyaffs2image_wrapper;
}
@@ -163,7 +165,7 @@ int nandroid_backup_partition_extended(const char* backup_path, const char* moun
char* name = basename(mount_point);
struct stat file_info;
- int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) == 0;
+ int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0;
ui_print("Backing up %s...\n", name);
if (0 != (ret = ensure_path_mounted(mount_point) != 0)) {
@@ -172,7 +174,15 @@ int nandroid_backup_partition_extended(const char* backup_path, const char* moun
}
compute_directory_stats(mount_point);
char tmp[PATH_MAX];
- sprintf(tmp, "%s/%s.img", backup_path, name);
+ scan_mounted_volumes();
+ Volume *v = volume_for_path(mount_point);
+ MountedVolume *mv = NULL;
+ if (v != NULL)
+ mv = find_mounted_volume_by_mount_point(v->mount_point);
+ if (mv == NULL || mv->filesystem == NULL)
+ sprintf(tmp, "%s/%s.auto", backup_path, name);
+ else
+ sprintf(tmp, "%s/%s.%s", backup_path, name, mv->filesystem);
nandroid_backup_handler backup_handler = get_backup_handler(mount_point);
if (backup_handler == NULL) {
ui_print("Error finding an appropriate backup handler.\n");
@@ -357,6 +367,7 @@ static nandroid_restore_handler get_restore_handler(const char *backup_path) {
return tar_extract_wrapper;
}
+ // cwr 5, we prefer tar for everything unless it is yaffs2
char str[255];
char* partition;
property_get("ro.cwm.prefer_tar", str, "false");
@@ -374,37 +385,83 @@ static nandroid_restore_handler get_restore_handler(const char *backup_path) {
int nandroid_restore_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) {
int ret = 0;
char* name = basename(mount_point);
-
+
+ nandroid_restore_handler restore_handler = NULL;
+ const char *filesystems[] = { "yaffs2", "ext2", "ext3", "ext4", "vfat", NULL };
+ const char* backup_filesystem = NULL;
+ Volume *vol = volume_for_path(mount_point);
+ const char *device = NULL;
+ if (vol != NULL)
+ device = vol->device;
+
char tmp[PATH_MAX];
sprintf(tmp, "%s/%s.img", backup_path, name);
struct stat file_info;
if (0 != (ret = statfs(tmp, &file_info))) {
- ui_print("%s.img not found. Skipping restore of %s.\n", name, mount_point);
- return 0;
+ // can't find the backup, it may be the new backup format?
+ // iterate through the backup types
+ printf("couldn't find default\n");
+ char *filesystem;
+ int i = 0;
+ while ((filesystem = filesystems[i]) != NULL) {
+ sprintf(tmp, "%s/%s.%s.img", backup_path, name, filesystem);
+ if (0 == (ret = statfs(tmp, &file_info))) {
+ backup_filesystem = filesystem;
+ restore_handler = unyaffs_wrapper;
+ break;
+ }
+ sprintf(tmp, "%s/%s.%s.tar", backup_path, name, filesystem);
+ if (0 == (ret = statfs(tmp, &file_info))) {
+ backup_filesystem = filesystem;
+ restore_handler = tar_extract_wrapper;
+ break;
+ }
+ i++;
+ }
+
+ if (backup_filesystem == NULL || restore_handler == NULL) {
+ ui_print("%s.img not found. Skipping restore of %s.\n", name, mount_point);
+ return 0;
+ }
+ else {
+ printf("Found new backup image: %s\n", tmp);
+ }
+
+ // If the fs_type of this volume is "auto", let's revert to using a
+ // rm -rf, rather than trying to do a ext3/ext4/whatever format.
+ // This is because some phones (like DroidX) will freak out if you
+ // reformat the /system or /data partitions, and not boot due to
+ // a locked bootloader.
+ // The "auto" fs type preserves the file system, and does not
+ // trigger that lock.
+ // Or of volume does not exist (.android_secure), just rm -rf.
+ if (vol == NULL || 0 == strcmp(vol->fs_type, "auto"))
+ backup_filesystem = NULL;
}
ensure_directory(mount_point);
- int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) == 0;
+ int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0;
ui_print("Restoring %s...\n", name);
- /*
- if (0 != (ret = ensure_root_path_unmounted(root))) {
- ui_print("Can't unmount %s!\n", mount_point);
- return ret;
+ if (backup_filesystem == NULL) {
+ if (0 != (ret = format_volume(mount_point))) {
+ ui_print("Error while formatting %s!\n", mount_point);
+ return ret;
+ }
}
- */
- if (0 != (ret = format_volume(mount_point))) {
+ else if (0 != (ret = format_device(device, mount_point, backup_filesystem))) {
ui_print("Error while formatting %s!\n", mount_point);
return ret;
}
-
+
if (0 != (ret = ensure_path_mounted(mount_point))) {
ui_print("Can't mount %s!\n", mount_point);
return ret;
}
-
- nandroid_restore_handler restore_handler = get_restore_handler(mount_point);
+
+ if (restore_handler == NULL)
+ restore_handler = get_restore_handler(mount_point);
if (restore_handler == NULL) {
ui_print("Error finding an appropriate restore handler.\n");
return -2;