void sysfs_init(void) { do_mkdir("/dev_vfs/infiniband", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/class", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/class/infiniband_verbs", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/class/infiniband", S_IRWXU | S_IRWXG | S_IRWXO); make_device("/sys/class/infiniband_verbs/abi_version", S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&ib_api_ver); do_mkdir("/sys/module", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/module/mlx4_core", S_IRWXU | S_IRWXG | S_IRWXO); do_mkdir("/sys/module/mlx4_core/parameters", S_IRWXU | S_IRWXG | S_IRWXO); make_device("/sys/module/mlx4_core/parameters/log_num_mgm_entry_size", S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&mlx4_mgm); #if 0 /* Do this thru init scripts */ do_mkdir("/proc", S_IRWXU | S_IRWXG | S_IRWXO); make_device("/proc/cpuinfo", S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&cpuinfo); #endif }
int main() { time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); Device* device = make_device(); ui = device->GetUI(); ui->Init(); ui->SetLocale(locale); ui->SetBackground(RecoveryUI::NONE); device->StartRecovery(); int i = 0; for(;i < 3; i++) { ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); ui->ShowProgress(0.3,3); sleep(3); } return 0; }
static void find_dev(char *path) { DIR *dir; int len=strlen(path); if (!(dir = opendir(path))) bb_perror_msg_and_die("No %s",path); for (;;) { struct dirent *entry = readdir(dir); if (!entry) break; /* Skip "." and ".." (also skips hidden files, which is ok) */ if (entry->d_name[0]=='.') continue; if (entry->d_type == DT_DIR) { snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name); find_dev(path); path[len] = 0; } /* If there's a dev entry, mknod it */ if (strcmp(entry->d_name, "dev")) make_device(path); } closedir(dir); }
void mdev_main(void) { // Handle -s if (toys.optflags) { dirtree_read("/sys/class", callback); dirtree_read("/sys/block", callback); } else { // hotplug support make_device(NULL); } }
void devfs_init(void) { int mode; /* Make sure there is a dev directory */ struct dentry *dentry = lookup_dentry("/dev/", 0); if (!dentry) { assert(!do_mkdir("/dev/", S_IRWXU | S_IRWXG | S_IRWXO)); } else { kref_put(&dentry->d_kref); } /* Notice we don't kref_put(). We're storing the refs globally */ dev_stdin = make_device("/dev/stdin", S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, &dev_f_op_stdin); dev_stdout = make_device("/dev/stdout", S_IWUSR | S_IWGRP | S_IWOTH, __S_IFCHR, &dev_f_op_stdout); /* Note stderr uses the same f_op as stdout */ dev_stderr = make_device("/dev/stderr", S_IWUSR | S_IWGRP | S_IWOTH, __S_IFCHR, &dev_f_op_stdout); dev_null = make_device("/dev/null", S_IWUSR | S_IWGRP | S_IWOTH, __S_IFCHR, &dev_f_op_null); }
static int callback(struct dirtree *node) { // Entries in /sys/class/block aren't char devices, so skip 'em. (We'll // get block devices out of /sys/block.) if(!strcmp(node->name, "block")) return 0; // Does this directory have a "dev" entry in it? // This is path based because the hotplug callbacks are if (S_ISDIR(node->st.st_mode) || S_ISLNK(node->st.st_mode)) { int len=4; char *dev = dirtree_path(node, &len); strcpy(dev+len, "/dev"); if (!access(dev, R_OK)) make_device(dev); free(dev); } // Circa 2.6.25 the entries more than 2 deep are all either redundant // (mouse#, event#) or unnamed (every usb_* entry is called "device"). return (node->parent && node->parent->parent) ? 0 : DIRTREE_RECURSE; }
int main(int argc, char **argv) { time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); // If this binary is started with the single argument "--adbd", // instead of being the normal recovery binary, it turns into kind // of a stripped-down version of adbd that only supports the // 'sideload' command. Note this must be a real argument, not // anything in the command file or bootloader control block; the // only way recovery should be run with this argument is when it // starts a copy of itself from the apply_from_adb() function. if (argc == 2 && strcmp(argv[1], "--adbd") == 0) { adb_main(); return 0; } printf("Starting recovery on %s", ctime(&start)); load_volume_table(); ensure_path_mounted(LAST_LOG_FILE); rotate_last_logs(10); get_args(&argc, &argv); const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0, show_text = 0; bool just_exit = false; bool shutdown_after = false; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case 't': show_text = 1; break; case 'x': just_exit = true; break; case 'l': locale = optarg; break; case 'g': { if (stage == NULL || *stage == '\0') { char buffer[20] = "1/"; strncat(buffer, optarg, sizeof(buffer)-3); stage = strdup(buffer); } break; } case 'p': shutdown_after = true; break; case '?': LOGE("Invalid command argument\n"); continue; } } if (locale == NULL) { load_locale_from_cache(); } printf("locale is [%s]\n", locale); printf("stage is [%s]\n", stage, stage); Device* device = make_device(); ui = device->GetUI(); gCurrentUI = ui; ui->SetLocale(locale); ui->Init(); int st_cur, st_max; if (stage != NULL && sscanf(stage, "%d/%d", &st_cur, &st_max) == 2) { ui->SetStage(st_cur, st_max); } ui->SetBackground(RecoveryUI::NONE); if (show_text) ui->ShowText(true); struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } }; sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); if (!sehandle) { ui->Print("Warning: No file_contexts\n"); } device->StartRecovery(); printf("Command:"); for (arg = 0; arg < argc; arg++) { printf(" \"%s\"", argv[arg]); } printf("\n"); if (update_package) { // For backwards compatibility on the cache partition only, if // we're given an old 'root' path "CACHE:foo", change it to // "/cache/foo". if (strncmp(update_package, "CACHE:", 6) == 0) { int len = strlen(update_package) + 10; char* modified_path = (char*)malloc(len); strlcpy(modified_path, "/cache/", len); strlcat(modified_path, update_package+6, len); printf("(replacing path \"%s\" with \"%s\")\n", update_package, modified_path); update_package = modified_path; } } printf("\n"); property_list(print_property, NULL); property_get("ro.build.display.id", recovery_version, ""); printf("\n"); int status = INSTALL_SUCCESS; if (update_package != NULL) { status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status == INSTALL_SUCCESS && wipe_cache) { if (erase_volume("/cache")) { LOGE("Cache wipe (requested by package) failed."); } } if (status != INSTALL_SUCCESS) { ui->Print("Installation aborted.\n"); // If this is an eng or userdebug build, then automatically // turn the text display on if the script fails so the error // message is visible. char buffer[PROPERTY_VALUE_MAX+1]; property_get("ro.build.fingerprint", buffer, ""); if (strstr(buffer, ":userdebug/") || strstr(buffer, ":eng/")) { ui->ShowText(true); } } } else if (wipe_data) { if (device->WipeData()) status = INSTALL_ERROR; if (erase_volume("/data")) status = INSTALL_ERROR; if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n"); } else if (wipe_cache) { if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n"); } else if (!just_exit) { status = INSTALL_NONE; // No command specified ui->SetBackground(RecoveryUI::NO_COMMAND); } if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) { copy_logs(); ui->SetBackground(RecoveryUI::ERROR); } if (status != INSTALL_SUCCESS || ui->IsTextVisible()) { prompt_and_wait(device, status); } // Otherwise, get ready to boot the main system... finish_recovery(send_intent); if (shutdown_after) { ui->Print("Shutting down...\n"); property_set(ANDROID_RB_PROPERTY, "shutdown,"); } else { ui->Print("Rebooting...\n"); property_set(ANDROID_RB_PROPERTY, "reboot,"); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { // Recovery needs to install world-readable files, so clear umask // set by init umask(0); time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); // If this binary is started with the single argument "--adbd", // instead of being the normal recovery binary, it turns into kind // of a stripped-down version of adbd that only supports the // 'sideload' command. Note this must be a real argument, not // anything in the command file or bootloader control block; the // only way recovery should be run with this argument is when it // starts a copy of itself from the apply_from_adb() function. if (argc == 3 && strcmp(argv[1], "--adbd") == 0) { adb_main(argv[2]); return 0; } printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&start)); Device* device = make_device(); ui = device->GetUI(); //ui->Init(); //ui->SetBackground(RecoveryUI::NONE); //load_volume_table(); // Load default values to set DataManager constants and handle ifdefs DataManager_LoadDefaults(); printf("Starting the UI..."); gui_init(); printf("=> Linking mtab\n"); system("ln -s /proc/mounts /etc/mtab"); // Link mtab for mke2fs printf("=> Processing recovery.fstab\n"); if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) { LOGE("Failing out of recovery due to problem with recovery.fstab.\n"); //return -1; } PartitionManager.Output_Partition_Logging(); // Load up all the resources gui_loadResources(); get_args(&argc, &argv); int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; bool just_exit = false; bool perform_backup = false; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case 't': ui->ShowText(true); break; case 'x': just_exit = true; break; case 'n': perform_backup = true; LOGI("nandroid\n"); break; case '?': LOGE("Invalid command argument\n"); continue; } } #ifdef HAVE_SELINUX struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } }; sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); if (!sehandle) { fprintf(stderr, "Warning: No file_contexts\n"); ui->Print("Warning: No file_contexts\n"); } #endif //device->StartRecovery(); printf("Command:"); for (arg = 0; arg < argc; arg++) { printf(" \"%s\"", argv[arg]); } printf("\n"); if (update_package) { // For backwards compatibility on the cache partition only, if // we're given an old 'root' path "CACHE:foo", change it to // "/cache/foo". if (strncmp(update_package, "CACHE:", 6) == 0) { int len = strlen(update_package) + 10; char* modified_path = (char*)malloc(len); strlcpy(modified_path, "/cache/", len); strlcat(modified_path, update_package+6, len); printf("(replacing path \"%s\" with \"%s\")\n", update_package, modified_path); update_package = modified_path; } } printf("\n"); property_list(print_property, NULL); printf("\n"); // Check for and run startup script if script exists TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot"); TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot"); #ifdef TW_INCLUDE_INJECTTWRP // Back up TWRP Ramdisk if needed: LOGI("Backing up TWRP ramdisk...\n"); system("injecttwrp --backup /tmp/backup_recovery_ramdisk.img"); LOGI("Backup of TWRP ramdisk done.\n"); #endif int status = INSTALL_SUCCESS; if (perform_backup) { char empt[50]; gui_console_only(); strcpy(empt, "(Current Date)"); DataManager_SetStrValue(TW_BACKUP_NAME, empt); if (OpenRecoveryScript::Backup_Command("BSDCAE") != 0) status = INSTALL_ERROR; } if (status == INSTALL_SUCCESS) { // Prevent other actions if backup failed if (update_package != NULL) { gui_console_only(); if (OpenRecoveryScript::Install_Command(update_package) == 0) status = INSTALL_SUCCESS; else status = INSTALL_ERROR; /* status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status == INSTALL_SUCCESS && wipe_cache) { if (erase_volume("/cache")) { LOGE("Cache wipe (requested by package) failed."); } } if (status != INSTALL_SUCCESS) ui->Print("Installation aborted.\n"); */ } else if (wipe_data) { gui_console_only(); if (!PartitionManager.Factory_Reset()) status = INSTALL_ERROR; /* if (device->WipeData()) status = INSTALL_ERROR; if (erase_volume("/data")) status = INSTALL_ERROR; if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; */ if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n"); } else if (wipe_cache) { gui_console_only(); if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n"); } else if (!just_exit) { status = INSTALL_ERROR; // No command specified } } //if (status != INSTALL_SUCCESS) ui->SetBackground(RecoveryUI::ERROR); if (status != INSTALL_SUCCESS /*|| ui->IsTextVisible()*/) { finish_recovery(NULL); DataManager_ReadSettingsFile(); if (PartitionManager.Mount_By_Path("/system", false) && TWFunc::Path_Exists("/system/recovery-from-boot.p")) { system("mv /system/recovery-from-boot.p /system/recovery-from-boot.bak"); ui_print("Renamed stock recovery file in /system to prevent\nthe stock ROM from replacing TWRP.\n"); } PartitionManager.UnMount_By_Path("/system", false); if (DataManager_GetIntValue(TW_IS_ENCRYPTED) == 0 && OpenRecoveryScript::check_for_script_file()) { gui_console_only(); if (OpenRecoveryScript::run_script_file() != 0) { // There was an error, boot the recovery gui_start(); } else { usleep(2000000); // Sleep for 2 seconds before rebooting } } else gui_start(); //prompt_and_wait(device); } // Otherwise, get ready to boot the main system... finish_recovery(send_intent); ui->Print("Rebooting...\n"); #ifdef ANDROID_RB_RESTART android_reboot(ANDROID_RB_RESTART, 0, 0); #else reboot(RB_AUTOBOOT); #endif return EXIT_SUCCESS; }
int main(int argc, char **argv) { // Recovery needs to install world-readable files, so clear umask // set by init umask(0); time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); // If this binary is started with the single argument "--adbd", // instead of being the normal recovery binary, it turns into kind // of a stripped-down version of adbd that only supports the // 'sideload' command. Note this must be a real argument, not // anything in the command file or bootloader control block; the // only way recovery should be run with this argument is when it // starts a copy of itself from the apply_from_adb() function. if (argc == 3 && strcmp(argv[1], "--adbd") == 0) { adb_main(argv[2]); return 0; } printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&start)); Device* device = make_device(); ui = device->GetUI(); //ui->Init(); //ui->SetBackground(RecoveryUI::NONE); //load_volume_table(); // Load default values to set DataManager constants and handle ifdefs DataManager_LoadDefaults(); printf("Starting the UI..."); gui_init(); printf("=> Linking mtab\n"); symlink("/proc/mounts", "/etc/mtab"); printf("=> Processing recovery.fstab\n"); if (!PartitionManager.Process_Fstab("/etc/recovery.fstab", 1)) { LOGE("Failing out of recovery due to problem with recovery.fstab.\n"); //return -1; } PartitionManager.Output_Partition_Logging(); // Load up all the resources gui_loadResources(); PartitionManager.Mount_By_Path("/cache", true); get_args(&argc, &argv); int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; bool just_exit = false; bool perform_backup = false; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case 't': ui->ShowText(true); break; case 'x': just_exit = true; break; case 'n': perform_backup = true; LOGI("nandroid\n"); break; case '?': LOGE("Invalid command argument\n"); continue; } } #ifdef HAVE_SELINUX struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } }; sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); if (!sehandle) { fprintf(stderr, "Warning: No file_contexts\n"); ui->Print("Warning: No file_contexts\n"); } #endif //device->StartRecovery(); printf("Command:"); for (arg = 0; arg < argc; arg++) { printf(" \"%s\"", argv[arg]); } printf("\n"); if (update_package) { // For backwards compatibility on the cache partition only, if // we're given an old 'root' path "CACHE:foo", change it to // "/cache/foo". if (strncmp(update_package, "CACHE:", 6) == 0) { int len = strlen(update_package) + 10; char* modified_path = (char*)malloc(len); strlcpy(modified_path, "/cache/", len); strlcat(modified_path, update_package+6, len); printf("(replacing path \"%s\" with \"%s\")\n", update_package, modified_path); update_package = modified_path; } } printf("\n"); property_list(print_property, NULL); printf("\n"); // Check for and run startup script if script exists TWFunc::check_and_run_script("/sbin/runatboot.sh", "boot"); TWFunc::check_and_run_script("/sbin/postrecoveryboot.sh", "boot"); #ifdef TW_INCLUDE_INJECTTWRP // Back up TWRP Ramdisk if needed: TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); string result; LOGI("Backing up TWRP ramdisk...\n"); if (Boot == NULL || Boot->Current_File_System != "emmc") TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img", result); else { string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device; TWFunc::Exec_Cmd(injectcmd, result); } LOGI("Backup of TWRP ramdisk done.\n"); #endif int status = INSTALL_SUCCESS; string ORSCommand; if (perform_backup) { char empt[50]; gui_console_only(); strcpy(empt, "(Current Date)"); DataManager_SetStrValue(TW_BACKUP_NAME, empt); if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n")) status = INSTALL_ERROR; } if (status == INSTALL_SUCCESS) { // Prevent other actions if backup failed if (update_package != NULL) { ORSCommand = "install "; ORSCommand += update_package; ORSCommand += "\n"; if (OpenRecoveryScript::Insert_ORS_Command(ORSCommand)) status = INSTALL_SUCCESS; else status = INSTALL_ERROR; /* status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status == INSTALL_SUCCESS && wipe_cache) { if (erase_volume("/cache")) { LOGE("Cache wipe (requested by package) failed."); } } if (status != INSTALL_SUCCESS) ui->Print("Installation aborted.\n"); */ } else if (wipe_data) { if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n")) status = INSTALL_ERROR; /* if (device->WipeData()) status = INSTALL_ERROR; if (erase_volume("/data")) status = INSTALL_ERROR; if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; */ if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n"); } else if (wipe_cache) { if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n"); } else if (!just_exit) { status = INSTALL_ERROR; // No command specified } } finish_recovery(NULL); // Offer to decrypt if the device is encrypted if (DataManager_GetIntValue(TW_IS_ENCRYPTED) != 0) { LOGI("Is encrypted, do decrypt page first\n"); if (gui_startPage("decrypt") != 0) { LOGE("Failed to start decrypt GUI page.\n"); } } // Read the settings file DataManager_ReadSettingsFile(); // Run any outstanding OpenRecoveryScript if (DataManager_GetIntValue(TW_IS_ENCRYPTED) == 0 && (TWFunc::Path_Exists(SCRIPT_FILE_TMP) || TWFunc::Path_Exists(SCRIPT_FILE_CACHE))) { OpenRecoveryScript::Run_OpenRecoveryScript(); } // Launch the main GUI gui_start(); // Check for su to see if the device is rooted or not if (PartitionManager.Mount_By_Path("/system", false)) { // Disable flashing of stock recovery if (TWFunc::Path_Exists("/system/recovery-from-boot.p")) { rename("/system/recovery-from-boot.p", "/system/recovery-from-boot.bak"); ui_print("Renamed stock recovery file in /system to prevent\nthe stock ROM from replacing TWRP.\n"); } if (TWFunc::Path_Exists("/supersu/su") && !TWFunc::Path_Exists("/system/bin/su") && !TWFunc::Path_Exists("/system/xbin/su") && !TWFunc::Path_Exists("/system/bin/.ext/.su")) { // Device doesn't have su installed DataManager_SetIntValue("tw_busy", 1); if (gui_startPage("installsu") != 0) { LOGE("Failed to start decrypt GUI page.\n"); } } else if (TWFunc::Check_su_Perms() > 0) { // su perms are set incorrectly DataManager_SetIntValue("tw_busy", 1); if (gui_startPage("fixsu") != 0) { LOGE("Failed to start decrypt GUI page.\n"); } } sync(); PartitionManager.UnMount_By_Path("/system", false); } // Otherwise, get ready to boot the main system... finish_recovery(send_intent); ui->Print("Rebooting...\n"); char backup_arg_char[50]; strcpy(backup_arg_char, DataManager_GetStrValue("tw_reboot_arg")); string backup_arg = backup_arg_char; if (backup_arg == "recovery") TWFunc::tw_reboot(rb_recovery); else if (backup_arg == "poweroff") TWFunc::tw_reboot(rb_poweroff); else if (backup_arg == "bootloader") TWFunc::tw_reboot(rb_bootloader); else if (backup_arg == "download") TWFunc::tw_reboot(rb_download); else TWFunc::tw_reboot(rb_system); #ifdef ANDROID_RB_RESTART android_reboot(ANDROID_RB_RESTART, 0, 0); #else reboot(RB_AUTOBOOT); #endif return EXIT_SUCCESS; }
void sysfs_create(int devnum, const struct file_operations *verb_fops, void *ptr) { char sysname[256] = "/sys/class/infiniband_verbs/uverbs0"; char devname[] = "/dev_vfs/infiniband/uverbs0"; char drvname[64] = "/sys/class/infiniband/"; int sysnameidx = strlen(sysname), drvidx; struct file *fp; struct ib_uverbs_device *uvp = (struct ib_uverbs_device *)ptr; /* Create correct name */ if (devnum > 9) panic("Too many devs"); devname[strlen(devname) - 1] = '0' + devnum; sysname[sysnameidx - 1] = '0' + devnum; /* Foll fops need to come from caller */ fp = make_device(devname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)verb_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband/mlx4_0 */ strncpy((drvname + strlen(drvname)), uvp->ib_dev->name, 12); do_mkdir(drvname, S_IRWXU | S_IRWXG | S_IRWXO); drvidx = strlen(drvname); /* /sys/class/infiniband/mlx4_0/node_type */ strncpy(drvname + drvidx, "/node_type", 11); make_device(drvname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&ntype_fops); /* /sys/class/infiniband/mlx4_0/vsd */ strncpy(drvname + drvidx, "/vsd", 5); fp = make_device(drvname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&vsd_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0 */ do_mkdir(sysname, S_IRWXU | S_IRWXG | S_IRWXO); /* /sys/class/infiniband_verbs/uverbs0/device */ strncpy(sysname + sysnameidx, "/device", 16); do_mkdir(sysname, S_IRWXU | S_IRWXG | S_IRWXO); /* /sys/class/infiniband_verbs/uverbs0/device/device */ strncpy(sysname + sysnameidx, "/device/device", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&ddev_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0/device/vendor */ strncpy(sysname + sysnameidx, "/device/vendor", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&dven_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0/ibdev */ strncpy(sysname + sysnameidx, "/ibdev", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&dname_fops); set_fs_info(fp, ptr); /* /sys/class/infiniband_verbs/uverbs0/abi_version */ strncpy(sysname + sysnameidx, "/abi_version", 16); fp = make_device(sysname, S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH, __S_IFCHR, (struct file_operations *)&dver_fops); set_fs_info(fp, ptr); }
int main(int argc __unused, char **argv) { int fd; struct usbmon_packet_1 hdrb; struct usbmon_packet_1 *hdr; struct usbmon_get_arg getb; enum { MFETCH_NM = 3 }; unsigned int offs[MFETCH_NM]; unsigned int off; struct usbmon_mfetch_arg mfb; unsigned char *data_buff; unsigned int toflush; int i; int rc; if (sizeof(struct usbmon_packet) != 48) { extern void usbmon_packet_size_is_bolixed(void); usbmon_packet_size_is_bolixed(); /* link-time error */ } if (sizeof(struct usbmon_packet_1) != 64) { extern void usbmon_packet_1_size_is_bolixed(void); usbmon_packet_1_size_is_bolixed(); /* link-time error */ } parse_params(&par, argv+1); /* * Two reasons to do this: * 1. Reduce weird error messages. * 2. If we create device nodes, we want them owned by root. */ if (geteuid() != 0) { fprintf(stderr, TAG ": Must run as root\n"); exit(1); } if ((fd = open(par.devname, O_RDWR)) == -1) { if (errno == ENOENT) { make_device(&par); fd = open(par.devname, O_RDWR); } if (fd == -1) { if (errno == ENODEV && par.ifnum == 0) { fprintf(stderr, TAG ": Can't open pseudo-bus zero at %s" " (probably not supported by kernel)\n", par.devname); } else { fprintf(stderr, TAG ": Can't open %s: %s\n", par.devname, strerror(errno)); } exit(1); } } if (par.api == API_B1M) { rc = ioctl(fd, MON_IOCQ_RING_SIZE, 0); if (rc == -1) { fprintf(stderr, TAG ": Cannot get ring size: %s\n", strerror(errno)); exit(1); } printf("Ring size: %d\n", rc); /* P3 */ par.map_size = rc; data_buff = mmap(0, par.map_size, PROT_READ, MAP_SHARED, fd, 0); if (data_buff == MAP_FAILED) { fprintf(stderr, TAG ": Cannot mmap: %s\n", strerror(errno)); exit(1); } } else { if ((data_buff = malloc(par.data_size)) == NULL) { fprintf(stderr, TAG ": No core\n"); exit(1); } } if (par.format == TFMT_HUMAN && par.api == API_B0) { /* * Zero fields which are not present in old (zero) API */ memset(&hdrb, 0, sizeof(struct usbmon_packet_1)); } else { /* * Make uninitialized fields visible. */ memset(&hdrb, 0xdb, sizeof(struct usbmon_packet_1)); } toflush = 0; for (;;) { if (par.api == API_B0) { getb.hdr = &hdrb; getb.data = data_buff; getb.alloc = par.data_size; if ((rc = ioctl(fd, MON_IOCX_GET, &getb)) != 0) { fprintf(stderr, TAG ": MON_IOCX_GET: %s\n", strerror(errno)); exit(1); } print(&par, &hdrb, data_buff); } else if (par.api == API_B1) { getb.hdr = &hdrb; getb.data = data_buff; getb.alloc = par.data_size; if ((rc = ioctl(fd, MON_IOCX_GETX, &getb)) != 0) { fprintf(stderr, TAG ": MON_IOCX_GETX: %s\n", strerror(errno)); exit(1); } print(&par, &hdrb, data_buff); } else if (par.api == API_B1M) { mfb.offvec = offs; mfb.nfetch = MFETCH_NM; mfb.nflush = toflush; if ((rc = ioctl(fd, MON_IOCX_MFETCH, &mfb)) != 0) { fprintf(stderr, TAG ": MON_IOCX_MFETCH: %s\n", strerror(errno)); exit(1); } for (i = 0; i < mfb.nfetch; i++) { off = offs[i]; if (off >= par.map_size) { fprintf(stderr, TAG ": offset\n"); continue; } hdr = (struct usbmon_packet_1 *)(data_buff + off); if (hdr->type == '@') continue; print(&par, hdr, (const unsigned char *)(hdr + 1)); } toflush = mfb.nfetch; } else { getb.hdr = &hdrb; getb.data = data_buff; getb.alloc = par.data_size; if ((rc = ioctl(fd, MON_IOCX_GETX, &getb)) != 0) { if (errno == ENOTTY) { par.api = API_B0; rc = ioctl(fd, MON_IOCX_GET, &getb); if (rc != 0) { fprintf(stderr, TAG ": MON_IOCX_GET: %s\n", strerror(errno)); exit(1); } } else { fprintf(stderr, TAG ": MON_IOCX_GETX: %s\n", strerror(errno)); exit(1); } } print(&par, &hdrb, data_buff); } } // return 0; }
#ifdef CONFIG_EXT2FS /* Now probe for and init the block device for the ext2 ram disk */ extern uint8_t _binary_mnt_ext2fs_img_size[]; extern uint8_t _binary_mnt_ext2fs_img_start[]; /* Build and init the block device */ struct block_device *ram_bd = kmalloc(sizeof(struct block_device), 0); memset(ram_bd, 0, sizeof(struct block_device)); ram_bd->b_id = 31337; ram_bd->b_sector_sz = 512; ram_bd->b_nr_sector = (unsigned long)_binary_mnt_ext2fs_img_size / 512; kref_init(&ram_bd->b_kref, fake_release, 1); pm_init(&ram_bd->b_pm, &block_pm_op, ram_bd); ram_bd->b_data = _binary_mnt_ext2fs_img_start; strlcpy(ram_bd->b_name, "RAMDISK", BDEV_INLINE_NAME); /* Connect it to the file system */ struct file *ram_bf = make_device("/dev/ramdisk", S_IRUSR | S_IWUSR, __S_IFBLK, &block_f_op); /* make sure the inode tracks the right pm (not it's internal one) */ ram_bf->f_dentry->d_inode->i_mapping = &ram_bd->b_pm; ram_bf->f_dentry->d_inode->i_bdev = ram_bd; /* this holds the bd kref */ kref_put(&ram_bf->f_kref); #endif /* CONFIG_EXT2FS */ } /* Generic helper, returns a kref'd reference out of principle. */ struct block_device *get_bdev(char *path) { struct block_device *bdev; struct file *block_f; block_f = do_file_open(path, O_RDWR, 0); assert(block_f); bdev = block_f->f_dentry->d_inode->i_bdev;
int main(int argc, char **argv) { time_t start = time(NULL); char firmware[50] = {0}; property_get("ro.reversion.aw_sdk_tag", firmware, "unknow"); strcat(reversion,firmware); char storage_type[50] = {0}; property_get("ro.sys.storage_type",storage_type,""); if(!strcmp(storage_type,"emulated")){ internal_storage_type = 1; } // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); // If this binary is started with the single argument "--adbd", // instead of being the normal recovery binary, it turns into kind // of a stripped-down version of adbd that only supports the // 'sideload' command. Note this must be a real argument, not // anything in the command file or bootloader control block; the // only way recovery should be run with this argument is when it // starts a copy of itself from the apply_from_adb() function. if (argc == 2 && strcmp(argv[1], "--adbd") == 0) { adb_main(); return 0; } printf("Starting recovery on %s", ctime(&start)); load_volume_table(); get_args(&argc, &argv); int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0, show_text = 0; bool just_exit = false; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; case 't': show_text = 1; break; case 'x': just_exit = true; break; case 'l': locale = optarg; break; case '?': LOGE("Invalid command argument\n"); continue; } } if (locale == NULL) { load_locale_from_cache(); } printf("locale is [%s]\n", locale); Device* device = make_device(); ui = device->GetUI(); ui->Init(); ui->SetLocale(locale); ui->SetBackground(RecoveryUI::NONE); if (show_text) ui->ShowText(true); #ifdef HAVE_SELINUX struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } }; sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); if (!sehandle) { fprintf(stderr, "Warning: No file_contexts\n"); ui->Print("Warning: No file_contexts\n"); } #endif device->StartRecovery(); printf("Command:"); for (arg = 0; arg < argc; arg++) { printf(" \"%s\"", argv[arg]); } printf("\n"); if (update_package) { // For backwards compatibility on the cache partition only, if // we're given an old 'root' path "CACHE:foo", change it to // "/cache/foo". if (strncmp(update_package, "CACHE:", 6) == 0) { int len = strlen(update_package) + 10; char* modified_path = (char*)malloc(len); strlcpy(modified_path, "/cache/", len); strlcat(modified_path, update_package+6, len); printf("(replacing path \"%s\" with \"%s\")\n", update_package, modified_path); update_package = modified_path; } } printf("\n"); property_list(print_property, NULL); printf("\n"); int status = INSTALL_SUCCESS; if (update_package != NULL) { status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status == INSTALL_SUCCESS && wipe_cache) { if (erase_volume("/cache")) { LOGE("Cache wipe (requested by package) failed."); } } if (status != INSTALL_SUCCESS) ui->Print("Installation aborted.\n"); } else if (wipe_data) { if (device->WipeData()) status = INSTALL_ERROR; if (erase_volume("/data")) status = INSTALL_ERROR; if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; copy_databk_to_data(); if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n"); } else if (wipe_cache) { if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n"); } else if (!just_exit) { status = INSTALL_NONE; // No command specified // ui->SetBackground(RecoveryUI::NO_COMMAND); // modify by cjcheng } if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) { ui->SetBackground(RecoveryUI::ERROR); } if (status != INSTALL_SUCCESS || ui->IsTextVisible()) { ui->ShowText(false); // modify by cjcheng ui->SetTipTitle(RecoveryUI::TIP_TITLE_READY); // add by cjcheng prompt_and_wait(device, status); /* add by cjcheng start... */ if (install_flag == INSTALL_SUCCESS){ ui->SetTipTitle(RecoveryUI::TIP_TITLE_SUCCESS); status = INSTALL_SUCCESS; } /* add by cjcheng end... */ } /* add by cjcheng start... */ if (status != INSTALL_SUCCESS){ ui->SetBackground(RecoveryUI::ERROR); ui->SetTipTitle(RecoveryUI::TIP_TITLE_ERROR); } /* add by cjcheng end... */ sleep(2); // Otherwise, get ready to boot the main system... finish_recovery(send_intent); ui->Print("Rebooting...\n"); sync(); android_reboot(ANDROID_RB_RESTART, 0, 0); return EXIT_SUCCESS; }