void TWFunc::Update_Log_File(void) { // Copy logs to cache so the system can find out what happened. Copy_Log(TMP_LOG_FILE, "/cache/recovery/log"); copy_file("/cache/recovery/log", "/cache/recovery/last_log", 600); chown("/cache/recovery/log", 1000, 1000); chmod("/cache/recovery/log", 0600); chmod("/cache/recovery/last_log", 0640); // Reset bootloader message TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc"); if (Part != NULL) { struct bootloader_message boot; memset(&boot, 0, sizeof(boot)); if (Part->Current_File_System == "mtd") { if (set_bootloader_message_mtd_name(&boot, Part->MTD_Name.c_str()) != 0) LOGERR("Unable to set MTD bootloader message.\n"); } else if (Part->Current_File_System == "emmc") { if (set_bootloader_message_block_name(&boot, Part->Actual_Block_Device.c_str()) != 0) LOGERR("Unable to set emmc bootloader message.\n"); } else { LOGERR("Unknown file system for /misc: '%s'\n", Part->Current_File_System.c_str()); } } if (!PartitionManager.Mount_By_Path("/cache", true) || (unlink("/cache/recovery/command") && errno != ENOENT)) { LOGINFO("Can't unlink %s\n", "/cache/recovery/command"); } PartitionManager.UnMount_By_Path("/cache", true); sync(); }
int set_bootloader_message(const struct bootloader_message *in) { //volume_for_path("/misc"); if (device_name[0] == 0) { LOGE("Cannot load volume /misc!\n"); return -1; } if (device_type == 'm') { return set_bootloader_message_mtd_name(in, device_name); } else if (device_type == 'e') { return set_bootloader_message_block_name(in, device_name); } LOGE("unknown misc partition type \"%c\"\n", device_type); return -1; }
void TWFunc::Update_Log_File(void) { // Copy logs to cache so the system can find out what happened. if (PartitionManager.Mount_By_Path("/cache", false)) { if (!TWFunc::Path_Exists("/cache/recovery/.")) { LOGINFO("Recreating /cache/recovery folder.\n"); if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) LOGINFO("Unable to create /cache/recovery folder.\n"); } Copy_Log(TMP_LOG_FILE, "/cache/recovery/log"); copy_file("/cache/recovery/log", "/cache/recovery/last_log", 600); chown("/cache/recovery/log", 1000, 1000); chmod("/cache/recovery/log", 0600); chmod("/cache/recovery/last_log", 0640); } else { LOGINFO("Failed to mount /cache for TWFunc::Update_Log_File\n"); } // Reset bootloader message TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc"); if (Part != NULL) { struct bootloader_message boot; memset(&boot, 0, sizeof(boot)); if (Part->Current_File_System == "mtd") { if (set_bootloader_message_mtd_name(&boot, Part->MTD_Name.c_str()) != 0) LOGERR("Unable to set MTD bootloader message.\n"); } else if (Part->Current_File_System == "emmc") { if (set_bootloader_message_block_name(&boot, Part->Actual_Block_Device.c_str()) != 0) LOGERR("Unable to set emmc bootloader message.\n"); } else { LOGERR("Unknown file system for /misc: '%s'\n", Part->Current_File_System.c_str()); } } if (PartitionManager.Mount_By_Path("/cache", true)) { if (unlink("/cache/recovery/command") && errno != ENOENT) { LOGINFO("Can't unlink %s\n", "/cache/recovery/command"); } } sync(); }