Ejemplo n.º 1
0
//custom raw restore handler
int custom_restore_raw_handler(const char* backup_path, const char* root) {
    Volume *vol = volume_for_path(root);
    // make sure the volume exists...
    if (vol == NULL || vol->fs_type == NULL) {
        ui_print("Volume not found! Skipping raw restore of %s...\n", root);
        return 0;
    }

    // make sure we  have a valid image file name
    const char *raw_image_format[] = { ".img", ".bin", NULL };
    char* image_file = basename(backup_path);
    int i = 0;
    while (raw_image_format[i] != NULL) {
        if (strlen(image_file) > strlen(raw_image_format[i]) &&
                    strcmp(image_file + strlen(image_file) - strlen(raw_image_format[i]), raw_image_format[i]) == 0 &&
                    strncmp(image_file, root + 1, strlen(root)-1) == 0) {
            break;
        }
        i++;
    }
    if (raw_image_format[i] == NULL) {
        ui_print("Invalid image file! Failed to restore %s to %s\n", image_file, root);
        return -1;
    }
    
    //make sure file exists
    struct stat file_check;
    if (0 != stat(backup_path, &file_check)) {
        ui_print("%s not found. Skipping restore of %s\n", backup_path, root);
        return -1;
    }

    //restore raw image
    ui_print("Restoring %s to %s\n", image_file, root);
    int ret = 0;
    char tmp[PATH_MAX];
    sprintf(tmp, "raw-backup.sh -r %s %s %s", backup_path, vol->device, root);
    if (0 != (ret = __system(tmp))) {
        ui_print("Failed raw restore of %s to %s\n", image_file, root);
    }
    //log
    char logfile[PATH_MAX];
    sprintf(logfile, "%s/log.txt", dirname(backup_path));
    ui_print_custom_logtail(logfile, 3);
    //this can be called outside nandroid_restore()
    sync();
    return ret;
}
Ejemplo n.º 2
0
//custom backup: raw backup through shell (ext4 raw backup not supported in backup_raw_partition())
//ret = 0 if success, else ret = 1
int custom_backup_raw_handler(const char* backup_path, const char* root) {
    Volume *vol = volume_for_path(root);
    // make sure the volume exists...
    if (vol == NULL || vol->fs_type == NULL) {
        ui_print("Volume not found! Skipping raw backup of %s...\n", root);
        return 0;
    }

    ui_print("Backing up %s in raw image...\n", root);
    int ret = 0;
    char tmp[PATH_MAX];
    sprintf(tmp, "raw-backup.sh -b %s %s %s", backup_path, vol->device, root);
    if (0 != (ret = __system(tmp))) {
        ui_print("Failed raw backup of %s...\n", root);
    }
    //log
    char logfile[PATH_MAX];
    sprintf(logfile, "%s/log.txt", backup_path);
    ui_print_custom_logtail(logfile, 3);
    //this can be called outside nandroid_restore()
    sync();
    return ret;
}
Ejemplo n.º 3
0
// custom backup: raw backup through shell (ext4 raw backup not supported in backup_raw_partition())
// for efs partition
// for now called only from nandroid_backup()
// ret = 0 if success, else ret = 1
int dd_raw_backup_handler(const char* backup_path, const char* root) {
    Volume *vol = volume_for_path(root);
    ui_print("\n>> Backing up %s...\nUsing raw mode...\n", root);
    if (vol == NULL || vol->fs_type == NULL) {
        LOGE("volume not found! Skipping raw backup of %s\n", root);
        return 0;
    }

    int ret = 0;
    char tmp[PATH_MAX];
    char* device_mmcblk;
    if (strstr(vol->blk_device, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device, "/dev/block/mtdblock") != NULL) {
        sprintf(tmp, "raw-backup.sh -b %s %s %s", backup_path, vol->blk_device, vol->mount_point);
    }
    else if (vol->blk_device2 != NULL &&
            (strstr(vol->blk_device2, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device2, "/dev/block/mtdblock") != NULL)) {
        sprintf(tmp, "raw-backup.sh -b %s %s %s", backup_path, vol->blk_device2, vol->mount_point);
    }
    else if ((device_mmcblk = readlink_device_blk(root)) != NULL) {
        sprintf(tmp, "raw-backup.sh -b %s %s %s", backup_path, device_mmcblk, vol->mount_point);
        free(device_mmcblk);
    }
    else {
        LOGE("invalid device! Skipping raw backup of %s\n", root);
        return 0;
    }

    if (0 != (ret = __system(tmp)))
        LOGE("failed raw backup of %s...\n", root);

    //log
    //finish_nandroid_job();
    char logfile[PATH_MAX];
    sprintf(logfile, "%s/log.txt", backup_path);
    ui_print_custom_logtail(logfile, 3);
    return ret;
}
Ejemplo n.º 4
0
// custom raw restore handler
// used to restore efs in raw mode or modem.bin files
// for now, only called directly from outside functions (not from nandroid_restore())
// user selects an image file to restore, so backup_file_image path is already mounted
int dd_raw_restore_handler(const char* backup_file_image, const char* root) {
    ui_print("\n>> Restoring %s...\n", root);
    Volume *vol = volume_for_path(root);
    if (vol == NULL || vol->fs_type == NULL) {
        ui_print("volume not found! Skipping raw restore of %s...\n", root);
        return 0;
    }

    ui_set_background(BACKGROUND_ICON_INSTALLING);
    ui_show_indeterminate_progress();

    // make sure we  have a valid image file name
    int i = 0;
    char errmsg[PATH_MAX];
    char tmp[PATH_MAX];
    char filename[PATH_MAX];
    const char *raw_image_format[] = { ".img", ".bin", NULL };

    sprintf(filename, "%s", BaseName(backup_file_image));
    while (raw_image_format[i] != NULL) {
        if (strlen(filename) > strlen(raw_image_format[i]) &&
                    strcmp(filename + strlen(filename) - strlen(raw_image_format[i]), raw_image_format[i]) == 0 &&
                    strncmp(filename, vol->mount_point + 1, strlen(vol->mount_point)-1) == 0) {
            break;
        }
        i++;
    }

    if (raw_image_format[i] == NULL) {
        sprintf(errmsg, "invalid image file! Failed to restore %s to %s\n", filename, root);
        return print_and_error(errmsg, NANDROID_ERROR_GENERAL);
    }

    //make sure file exists
    if (!file_found(backup_file_image)) {
        sprintf(errmsg, "%s not found. Skipping restore of %s\n", backup_file_image, root);
        return print_and_error(errmsg, NANDROID_ERROR_GENERAL);
    }

    //restore raw image
    int ret = 0;
    char* device_mmcblk;

    ui_print("Restoring %s to %s\n", filename, vol->mount_point);
    if (strstr(vol->blk_device, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device, "/dev/block/mtdblock") != NULL) {
        sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, vol->blk_device, vol->mount_point);
    } else if (vol->blk_device2 != NULL &&
            (strstr(vol->blk_device2, "/dev/block/mmcblk") != NULL || strstr(vol->blk_device2, "/dev/block/mtdblock") != NULL)) {
        sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, vol->blk_device2, vol->mount_point);
    } else if ((device_mmcblk = readlink_device_blk(root)) != NULL) {
        sprintf(tmp, "raw-backup.sh -r '%s' %s %s", backup_file_image, device_mmcblk, vol->mount_point);
        free(device_mmcblk);
    } else {
        sprintf(errmsg, "raw restore: no device found (%s)\n", root);
        return print_and_error(errmsg, NANDROID_ERROR_GENERAL);
    }

    ret = __system(tmp);
    if (0 != ret) {
        sprintf(errmsg, "failed raw restore of %s to %s\n", filename, root);
        print_and_error(errmsg, ret);
    } else {
        finish_nandroid_job();
    }

    sprintf(tmp, "%s/log.txt", DirName(backup_file_image));
    ui_print_custom_logtail(tmp, 3);
    return ret;
}