Nandroid restore of sd-ext.

This commit is contained in:
Koushik K. Dutta 2010-04-01 12:20:39 -07:00
parent 3f99539c4d
commit 68b0190858
6 changed files with 60 additions and 24 deletions

View File

@ -76,6 +76,14 @@ $(SYMLINKS): $(LOCAL_INSTALLED_MODULE)
ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
include $(CLEAR_VARS)
LOCAL_MODULE := nandroid-md5.sh
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := nandroid-md5.sh
include $(BUILD_PREBUILT)
include $(commands_recovery_local_path)/amend/Android.mk
include $(commands_recovery_local_path)/minui/Android.mk
include $(commands_recovery_local_path)/minzip/Android.mk

View File

@ -811,6 +811,7 @@ cmd_restore_rom(const char *name, void *cookie, int argc, const char *argv[],
int restoresystem = 1;
int restoredata = 1;
int restorecache = 1;
int restoresdext = 1;
int i;
for (i = 0; i < argc; i++)
{
@ -822,9 +823,11 @@ cmd_restore_rom(const char *name, void *cookie, int argc, const char *argv[],
restoredata = 0;
else if (strcmp(argv[i], "nocache") == 0)
restorecache = 0;
else if (strcmp(argv[i], "nosd-ext") == 0)
restorecache = 0;
}
return nandroid_restore(argv[0], restoreboot, restoresystem, restoredata, restorecache);
return nandroid_restore(argv[0], restoreboot, restoresystem, restoredata, restorecache, restoresdext);
}
static int

View File

@ -347,7 +347,7 @@ void show_nandroid_restore_menu()
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers);
if (file == NULL)
return;
nandroid_restore(file, 1, 1, 1, 1);
nandroid_restore(file, 1, 1, 1, 1, 1);
}
void show_mount_usb_storage_menu()
@ -641,6 +641,7 @@ void show_nandroid_advanced_restore_menu()
"Restore system",
"Restore data",
"Restore cache",
"Restore sd-ext",
NULL
};
@ -648,16 +649,16 @@ void show_nandroid_advanced_restore_menu()
switch (chosen_item)
{
case 0:
nandroid_restore(file, 1, 0, 0, 0);
nandroid_restore(file, 1, 0, 0, 0, 0);
break;
case 1:
nandroid_restore(file, 0, 1, 0, 0);
nandroid_restore(file, 0, 1, 0, 0, 0);
break;
case 2:
nandroid_restore(file, 0, 0, 1, 0);
nandroid_restore(file, 0, 0, 1, 0, 0);
break;
case 3:
nandroid_restore(file, 0, 0, 0, 1);
nandroid_restore(file, 0, 0, 0, 1, 0);
break;
}
}

View File

@ -36,3 +36,6 @@ __system(const char *command);
void
show_advanced_menu();
int
format_mmc_device(char* root);

View File

@ -75,10 +75,11 @@ void compute_directory_stats(char* directory)
ui_show_progress(1, 0);
}
int nandroid_backup_partition(char* backup_path, char* root, char* name) {
int nandroid_backup_partition(char* backup_path, char* root) {
int ret = 0;
char mount_point[PATH_MAX];
sprintf(mount_point, "/%s", name);
translate_root_path(root, mount_point, PATH_MAX);
char* name = basename(mount_point);
ui_print("Backing up %s...\n", name);
if (0 != (ret = ensure_root_path_mounted(root) != 0)) {
@ -108,10 +109,13 @@ int nandroid_backup(char* backup_path)
struct statfs s;
if (0 != (ret = statfs("/sdcard", &s)))
return print_and_error("Unable to stat /sdcard\n");
long sdcard_free = s.f_bavail * s.f_bsize;
if (sdcard_free < 150000000L)
uint64_t bavail = s.f_bavail;
uint64_t bsize = s.f_bsize;
uint64_t sdcard_free = bavail * bsize;
uint64_t sdcard_free_mb = sdcard_free / (uint64_t)(1024 * 1024);
ui_print("SD Card space free: %lluMB\n", sdcard_free_mb);
if (sdcard_free_mb < 150)
ui_print("There may not be enough free space to complete backup... continuing...\n");
// return print_and_error("There is not enough free space on the SD Card! At least 150MB is required to create a backup.\n");
char tmp[PATH_MAX];
sprintf(tmp, "mkdir -p %s", backup_path);
@ -129,22 +133,22 @@ int nandroid_backup(char* backup_path)
if (0 != ret)
return print_and_error("Error while dumping boot image!\n");
if (0 != (ret = nandroid_backup_partition(backup_path, "SYSTEM:", "system")))
if (0 != (ret = nandroid_backup_partition(backup_path, "SYSTEM:")))
return ret;
if (0 != (ret = nandroid_backup_partition(backup_path, "DATA:", "data")))
if (0 != (ret = nandroid_backup_partition(backup_path, "DATA:")))
return ret;
if (0 != (ret = nandroid_backup_partition(backup_path, "CACHE:", "cache")))
if (0 != (ret = nandroid_backup_partition(backup_path, "CACHE:")))
return ret;
if (0 != ensure_root_path_mounted("SDEXT:"))
ui_print("No sd-ext found. Skipping backup.\n");
else if (0 != (ret = nandroid_backup_partition(backup_path, "SDEXT:", "sd-ext")))
else if (0 != (ret = nandroid_backup_partition(backup_path, "SDEXT:")))
return ret;
ui_print("Generating md5 sum...\n");
sprintf(tmp, "cd %s && (md5sum *img > nandroid.md5)", backup_path);
sprintf(tmp, "nandroid-md5.sh %s", backup_path);
if (0 != (ret = __system(tmp))) {
ui_print("Error while generating md5 sum!\n");
return ret;
@ -157,17 +161,20 @@ int nandroid_backup(char* backup_path)
return 0;
}
int nandroid_restore_partition(char* backup_path, char* root, char* name) {
typedef int (*format_function)(char* root);
int nandroid_restore_partition_internal(char* backup_path, char* root, format_function formatter) {
int ret = 0;
char mount_point[PATH_MAX];
sprintf(mount_point, "/%s", name);
translate_root_path(root, mount_point, PATH_MAX);
char* name = basename(mount_point);
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 (0 != (ret = format_root_device(root))) {
if (0 != (ret = formatter(root))) {
ui_print("Error while formatting %s!\n", root);
return ret;
}
@ -186,7 +193,11 @@ int nandroid_restore_partition(char* backup_path, char* root, char* name) {
return 0;
}
int nandroid_restore(char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache)
int nandroid_restore_partition(char* backup_path, char* root) {
return nandroid_restore_partition_internal(backup_path, root, format_root_device);
}
int nandroid_restore(char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache, int restore_sdext)
{
ui_set_background(BACKGROUND_ICON_INSTALLING);
ui_show_indeterminate_progress();
@ -213,15 +224,25 @@ int nandroid_restore(char* backup_path, int restore_boot, int restore_system, in
}
}
if (restore_system && 0 != (ret = nandroid_restore_partition(backup_path, "SYSTEM:", "system")))
if (restore_system && 0 != (ret = nandroid_restore_partition(backup_path, "SYSTEM:")))
return ret;
if (restore_data && 0 != (ret = nandroid_restore_partition(backup_path, "DATA:", "data")))
if (restore_data && 0 != (ret = nandroid_restore_partition(backup_path, "DATA:")))
return ret;
if (restore_cache && 0 != (ret = nandroid_restore_partition(backup_path, "CACHE:", "cache")))
if (restore_cache && 0 != (ret = nandroid_restore_partition(backup_path, "CACHE:")))
return ret;
if (restore_sdext)
{
struct statfs s;
sprintf(tmp, "%s/sd-ext.img", backup_path);
if (0 != (ret = statfs(tmp, &s)))
ui_print("sd-ext.img not found. Skipping restore of /sd-ext.");
else if (0 != (ret = nandroid_restore_partition_internal(backup_path, "SDEXT:", format_mmc_device)))
return ret;
}
sync();
ui_set_background(BACKGROUND_ICON_NONE);
ui_reset_progress();

View File

@ -3,6 +3,6 @@
int nandroid_main(int argc, char** argv);
int nandroid_backup(char* backup_path);
int nandroid_restore(char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache);
int nandroid_restore(char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache, int restore_sdext);
#endif