void update_system_details() { ui_print(" * Verifying filesystems...\n"); createFstab(); ui_print(" * Verifying partition sizes...\n"); updateUsedSized(); }
int nandroid_back_exe() { SetDataState("Starting", "backup", 0, 0); if (ensure_path_mounted(SDCARD_ROOT) != 0) { ui_print("-- Could not mount: %s.\n-- Aborting.\n",SDCARD_ROOT); SetDataState("Unable to mount", "/sdcard", 1, 1); return 1; } // Create backup folder struct tm *t; char timestamp[64]; char image_dir[255]; char exe[255]; time_t start, stop; time_t seconds; seconds = time(0); t = localtime(&seconds); sprintf(timestamp,"%04d-%02d-%02d--%02d-%02d-%02d",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); // make time stamp sprintf(image_dir,"%s/%s/%s/", backup_folder, device_id, timestamp); // for backup folder if (recursive_mkdir(image_dir)) { LOGE("Unable to create folder: '%s'\n", backup_folder); SetDataState("Backup failed", image_dir, 1, 1); return -1; } // Record the start time time(&start); // Prepare operation ui_print("\n[BACKUP STARTED]\n"); ui_print(" * Backup Folder: %s\n", backup_folder); ui_print(" * Verifying filesystems...\n"); verifyFst(); createFstab(); ui_print(" * Verifying partition sizes...\n"); updateUsedSized(); unsigned long long sdc_free = sdcext.sze - sdcext.used; // Compute totals int total = 0; unsigned long long total_img_bytes = 0, total_file_bytes = 0; CalculateBackupDetails(&total, &total_img_bytes, &total_file_bytes); unsigned long long total_bytes = total_img_bytes + total_file_bytes; if (total == 0 || total_bytes == 0) { LOGE("Unable to compute target usage (%d partitions, %llu bytes)\n", total, total_bytes); SetDataState("Backup failed", image_dir, 1, 1); return -1; } ui_print(" * Total number of partition to back up: %d\n", total); ui_print(" * Total size of all data, in KB: %llu\n", total_bytes / 1024); ui_print(" * Available space on the SD card, in KB: %llu\n", sdc_free / 1024); // We can't verify sufficient space on devices where sdcard is a portion of the data partition #ifndef RECOVERY_SDCARD_ON_DATA // Verify space if (sdc_free < (total_bytes + 0x2000000)) // We require at least 32MB of additional space { LOGE("Insufficient space on SDCARD. Required space is %lluKB, available %lluKB\n", (total_bytes + 0x2000000) / 1024, sdc_free / 1024); SetDataState("Backup failed", image_dir, 1, 1); return -1; } #else ui_print(" * This device does not support verifying available free space.\n"); #endif // Prepare progress bar... unsigned long long img_bytes_remaining = total_img_bytes; unsigned long long file_bytes_remaining = total_file_bytes; unsigned long img_byte_time = 0, file_byte_time = 0; struct stat st; ui_set_progress(0.0); // SYSTEM if (phx_do_backup(VAR_BACKUP_SYSTEM_VAR, &sys, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // DATA if (phx_do_backup(VAR_BACKUP_DATA_VAR, &dat, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // BOOT if (phx_do_backup(VAR_BACKUP_BOOT_VAR, &boo, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // RECOVERY if (phx_do_backup(VAR_BACKUP_RECOVERY_VAR, &rec, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // CACHE if (phx_do_backup(VAR_BACKUP_CACHE_VAR, &cac, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // SP1 if (phx_do_backup(VAR_BACKUP_SP1_VAR, &sp1, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // SP2 if (phx_do_backup(VAR_BACKUP_SP2_VAR, &sp2, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // SP3 if (phx_do_backup(VAR_BACKUP_SP3_VAR, &sp3, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // ANDROID-SECURE if (stat(ase.dev, &st) ==0) if (phx_do_backup(VAR_BACKUP_ANDSEC_VAR, &ase, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; // SD-EXT if (stat(sde.dev, &st) ==0) if (phx_do_backup(VAR_BACKUP_SDEXT_VAR, &sde, image_dir, total_img_bytes, total_file_bytes, &img_bytes_remaining, &file_bytes_remaining, &img_byte_time, &file_byte_time)) return 1; ui_print(" * Verifying filesystems...\n"); verifyFst(); createFstab(); ui_print(" * Verifying partition sizes...\n"); updateUsedSized(); time(&stop); // Average BPS unsigned long int img_bps = total_img_bytes / img_byte_time; unsigned long int file_bps = total_file_bytes / file_byte_time; LOGI("img_bps = %lu total_img_bytes = %llu img_byte_time = %lu\n", img_bps, total_img_bytes, img_byte_time); ui_print("Average backup rate for file systems: %lu MB/sec\n", (file_bps / (1024 * 1024))); ui_print("Average backup rate for imaged drives: %lu MB/sec\n", (img_bps / (1024 * 1024))); if (DataManager_GetIntValue(VAR_SKIP_MD5_GENERATE_VAR) == 1) { // If we're skipping MD5 generation, our BPS is faster by about 1.65 file_bps = (unsigned long) (file_bps / 1.65); img_bps = (unsigned long) (img_bps / 1.65); } img_bps += (DataManager_GetIntValue(VAR_BACKUP_AVG_IMG_RATE) * 4); img_bps /= 5; if (DataManager_GetIntValue(VAR_USE_COMPRESSION_VAR)) file_bps += (DataManager_GetIntValue(VAR_BACKUP_AVG_FILE_COMP_RATE) * 4); else file_bps += (DataManager_GetIntValue(VAR_BACKUP_AVG_FILE_RATE) * 4); file_bps /= 5; DataManager_SetIntValue(VAR_BACKUP_AVG_IMG_RATE, img_bps); if (DataManager_GetIntValue(VAR_USE_COMPRESSION_VAR)) DataManager_SetIntValue(VAR_BACKUP_AVG_FILE_COMP_RATE, file_bps); else DataManager_SetIntValue(VAR_BACKUP_AVG_FILE_RATE, file_bps); int total_time = (int) difftime(stop, start); unsigned long long new_sdc_free = (sdcext.sze - sdcext.used) / (1024 * 1024); sdc_free /= (1024 * 1024); ui_print("[%lu MB TOTAL BACKED UP TO SDCARD]\n",(unsigned long) (sdc_free - new_sdc_free)); ui_print("[BACKUP COMPLETED IN %d SECONDS]\n\n", total_time); // the end SetDataState("Backup Succeeded", "", 0, 1); return 0; }