From 89ed0b7355e93c145bb40483db5f79766a00e7df Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 26 Oct 2011 21:25:34 -0700 Subject: [PATCH] support backup and restore on internal sdcard Change-Id: I6295b5bb7ada967ca223758be58d555c1a2ff462 --- Android.mk | 2 +- extendedcommands.c | 57 +++++++++++++++++++++++++++++++++++----------- extendedcommands.h | 5 +++- nandroid.c | 16 ++++++++----- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/Android.mk b/Android.mk index e01f71d..843d660 100644 --- a/Android.mk +++ b/Android.mk @@ -37,7 +37,7 @@ else RECOVERY_NAME := CWM-based Recovery endif -RECOVERY_VERSION := $(RECOVERY_NAME) v5.0.2.6 +RECOVERY_VERSION := $(RECOVERY_NAME) v5.0.2.7 LOCAL_CFLAGS += -DRECOVERY_VERSION="$(RECOVERY_VERSION)" RECOVERY_API_VERSION := 2 diff --git a/extendedcommands.c b/extendedcommands.c index 2b6d5c3..9e63782 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -333,10 +333,10 @@ void show_choose_zip_menu(const char *mount_point) install_zip(file); } -void show_nandroid_restore_menu() +void show_nandroid_restore_menu(const char* path) { - if (ensure_path_mounted("/sdcard") != 0) { - LOGE ("Can't mount /sdcard\n"); + if (ensure_path_mounted(path) != 0) { + LOGE("Can't mount %s\n", path); return; } @@ -345,7 +345,9 @@ void show_nandroid_restore_menu() NULL }; - char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers); + char tmp[PATH_MAX]; + sprintf(tmp, "%s/clockworkmod/backup/", path); + char* file = choose_file_menu(tmp, NULL, headers); if (file == NULL) return; @@ -713,7 +715,7 @@ void show_partition_menu() } -void show_nandroid_advanced_restore_menu() +void show_nandroid_advanced_restore_menu(const char* path) { if (ensure_path_mounted("/sdcard") != 0) { LOGE ("Can't mount /sdcard\n"); @@ -792,12 +794,18 @@ void show_nandroid_menu() NULL }; - static char* list[] = { "Backup", - "Restore", - "Advanced Restore", + static char* list[] = { "backup", + "restore", + "advanced restore", + "backup to internal sdcard", + "restore from internal sdcard", + "advanced restore from internal sdcard", NULL }; + if (volume_for_path("/emmc") == NULL) + INSTALL_MENU_ITEMS[3] = NULL; + int chosen_item = get_menu_selection(headers, list, 0, 0); switch (chosen_item) { @@ -820,10 +828,34 @@ void show_nandroid_menu() } break; case 1: - show_nandroid_restore_menu(); + show_nandroid_restore_menu("/sdcard"); break; case 2: - show_nandroid_advanced_restore_menu(); + show_nandroid_advanced_restore_menu("/sdcard"); + break; + case 3: + { + char backup_path[PATH_MAX]; + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + if (tmp == NULL) + { + struct timeval tp; + gettimeofday(&tp, NULL); + sprintf(backup_path, "/emmc/clockworkmod/backup/%d", tp.tv_sec); + } + else + { + strftime(backup_path, sizeof(backup_path), "/emmc/clockworkmod/backup/%F.%H.%M.%S", tmp); + } + nandroid_backup(backup_path); + } + break; + case 4: + show_nandroid_restore_menu("/emmc"); + break; + case 5: + show_nandroid_advanced_restore_menu("/emmc"); break; } } @@ -1048,9 +1080,8 @@ void create_fstab() write_fstab_root("/boot", file); write_fstab_root("/cache", file); write_fstab_root("/data", file); - if (has_datadata()) { - write_fstab_root("/datadata", file); - } + write_fstab_root("/datadata", file); + write_fstab_root("/emmc", file); write_fstab_root("/system", file); write_fstab_root("/sdcard", file); write_fstab_root("/sd-ext", file); diff --git a/extendedcommands.h b/extendedcommands.h index 101552f..53a0201 100644 --- a/extendedcommands.h +++ b/extendedcommands.h @@ -17,7 +17,10 @@ int do_nandroid_restore(); void -show_nandroid_restore_menu(); +show_nandroid_restore_menu(const char* path); + +void +show_nandroid_advanced_restore_menu(const char* path); void show_nandroid_menu(); diff --git a/nandroid.c b/nandroid.c index ffc5ac0..315660c 100644 --- a/nandroid.c +++ b/nandroid.c @@ -228,13 +228,17 @@ int nandroid_backup(const char* backup_path) { ui_set_background(BACKGROUND_ICON_INSTALLING); - if (ensure_path_mounted("/sdcard") != 0) - return print_and_error("Can't mount /sdcard\n"); + if (ensure_path_mounted(backup_path) != 0) { + return print_and_error("Can't mount backup path.\n"); + } + Volume* volume = volume_for_path(backup_path); + if (NULL == volume) + return print_and_error("Unable to find volume for backup path.\n"); int ret; struct statfs s; - if (0 != (ret = statfs("/sdcard", &s))) - return print_and_error("Unable to stat /sdcard\n"); + if (0 != (ret = statfs(volume->mount_point, &s))) + return print_and_error("Unable to stat backup path.\n"); uint64_t bavail = s.f_bavail; uint64_t bsize = s.f_bsize; uint64_t sdcard_free = bavail * bsize; @@ -513,8 +517,8 @@ int nandroid_restore(const char* backup_path, int restore_boot, int restore_syst ui_show_indeterminate_progress(); yaffs_files_total = 0; - if (ensure_path_mounted("/sdcard") != 0) - return print_and_error("Can't mount /sdcard\n"); + if (ensure_path_mounted(backup_path) != 0) + return print_and_error("Can't mount backup path\n"); char tmp[PATH_MAX];