From 38a921435a4050acb0d1db1c3299a131039ea1c6 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 10 Jun 2011 09:45:52 -0700 Subject: [PATCH] make tar backups opt in. Change-Id: Ib01131f3a65ce4114e73abe2c7ba42263d281844 --- extendedcommands.c | 6 +++--- nandroid.c | 22 ++++++++++++++++++++++ roots.c | 18 ++++++++++++++---- roots.h | 3 +++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/extendedcommands.c b/extendedcommands.c index b32ca0b..4395377 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -1105,9 +1105,9 @@ int bml_check_volume(const char *path) { void process_volumes() { create_fstab(); - if (volume_for_path("/sdcard") == NULL) { - rmdir("/sdcard"); - symlink("/data/media", "/sdcard"); + + if (is_data_media()) { + setup_data_media(); } return; diff --git a/nandroid.c b/nandroid.c index 8cee3be..5a32a76 100644 --- a/nandroid.c +++ b/nandroid.c @@ -139,6 +139,17 @@ static nandroid_backup_handler get_backup_handler(const char *backup_path) { return NULL; } + if (strcmp(backup_path, "/data") == 0 && is_data_media()) { + return tar_compress_wrapper; + } + + char str[255]; + char* partition; + property_get("ro.cwm.prefer_tar", str, "false"); + if (strcmp("true", str) != 0) { + return mkyaffs2image_wrapper; + } + if (strcmp("yaffs2", mv->filesystem) == 0) { return mkyaffs2image_wrapper; } @@ -345,6 +356,17 @@ static nandroid_restore_handler get_restore_handler(const char *backup_path) { return NULL; } + if (strcmp(backup_path, "/data") == 0 && is_data_media()) { + return tar_extract_wrapper; + } + + char str[255]; + char* partition; + property_get("ro.cwm.prefer_tar", str, "false"); + if (strcmp("true", str) != 0) { + return unyaffs_wrapper; + } + if (strcmp("yaffs2", mv->filesystem) == 0) { return unyaffs_wrapper; } diff --git a/roots.c b/roots.c index 49b7729..fa7a5df 100644 --- a/roots.c +++ b/roots.c @@ -164,17 +164,27 @@ int try_mount(const char* device, const char* mount_point, const char* fs_type, return ret; } +int is_data_media() { + Volume *data = volume_for_path("/data"); + return data != NULL && strcmp(data->fs_type, "auto") == 0 && volume_for_path("/sdcard") == NULL; +} + +void setup_data_media() { + rmdir("/sdcard"); + mkdir("/data/media", 0755); + symlink("/data/media", "/sdcard"); +} + int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { // no /sdcard? let's assume /data/media - if (strstr(path, "/sdcard") == path) { + if (strstr(path, "/sdcard") == path && is_data_media()) { LOGW("using /data/media, no /sdcard found.\n"); int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; - rmdir("/sdcard"); - symlink("/data/media", "/sdcard"); + setup_data_media(); return 0; } LOGE("unknown volume for path [%s]\n", path); @@ -245,7 +255,7 @@ int ensure_path_unmounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { // no /sdcard? let's assume /data/media - if (strstr(path, "/sdcard") == path) { + if (strstr(path, "/sdcard") == path && is_data_media()) { return ensure_path_unmounted("/data"); } LOGE("unknown volume for path [%s]\n", path); diff --git a/roots.h b/roots.h index 7132fed..7914307 100644 --- a/roots.h +++ b/roots.h @@ -42,4 +42,7 @@ int get_num_volumes(); Volume* get_device_volumes(); +int is_data_media(); +void setup_data_media(); + #endif // RECOVERY_ROOTS_H_