struct acpi_table_header *ap_get_table_from_file(char *pathname, u32 *out_file_size) { struct acpi_table_header *buffer = NULL; ACPI_FILE file; u32 file_size; size_t actual; /* Must use binary mode */ file = acpi_os_open_file(pathname, ACPI_FILE_READING | ACPI_FILE_BINARY); if (!file) { acpi_log_error("Could not open input file: %s\n", pathname); return (NULL); } /* Need file size to allocate a buffer */ file_size = cm_get_file_size(file); if (file_size == ACPI_UINT32_MAX) { acpi_log_error("Could not get input file size: %s\n", pathname); goto cleanup; } /* Allocate a buffer for the entire file */ buffer = ACPI_ALLOCATE_ZEROED(file_size); if (!buffer) { acpi_log_error("Could not allocate file buffer of size: %u\n", file_size); goto cleanup; } /* Read the entire file */ actual = acpi_os_read_file(file, buffer, 1, file_size); if (actual != file_size) { acpi_log_error("Could not read input file: %s\n", pathname); ACPI_FREE(buffer); buffer = NULL; goto cleanup; } *out_file_size = file_size; cleanup: acpi_os_close_file(file); return (buffer); }
int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance) { char filename[ACPI_NAME_SIZE + 16]; char instance_str[16]; ACPI_FILE file; size_t actual; u32 table_length; /* Obtain table length */ table_length = ap_get_table_length(table); /* Construct lower-case filename from the table local signature */ if (ACPI_VALIDATE_RSDP_SIG(table->signature)) { ACPI_MOVE_NAME(filename, ACPI_RSDP_NAME); } else { ACPI_MOVE_NAME(filename, table->signature); } filename[0] = (char)ACPI_TOLOWER(filename[0]); filename[1] = (char)ACPI_TOLOWER(filename[1]); filename[2] = (char)ACPI_TOLOWER(filename[2]); filename[3] = (char)ACPI_TOLOWER(filename[3]); filename[ACPI_NAME_SIZE] = 0; /* Handle multiple SSDts - create different filenames for each */ if (instance > 0) { acpi_ut_snprintf(instance_str, sizeof(instance_str), "%u", instance); ACPI_STRCAT(filename, instance_str); } ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX); if (gbl_verbose_mode) { acpi_log_error ("Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", table->signature, filename, table->length, table->length); } /* Open the file and dump the entire table in binary mode */ file = acpi_os_open_file(filename, ACPI_FILE_WRITING | ACPI_FILE_BINARY); if (!file) { acpi_log_error("Could not open output file: %s\n", filename); return (-1); } actual = acpi_os_write_file(file, table, 1, table_length); if (actual != table_length) { acpi_log_error("Error writing binary output file: %s\n", filename); acpi_os_close_file(file); return (-1); } acpi_os_close_file(file); return (0); }
int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[]) #endif { int status = 0; struct ap_dump_action *action; u32 file_size; u32 i; ACPI_DEBUG_INITIALIZE(); /* For debug version only */ acpi_os_initialize(); gbl_output_file = ACPI_FILE_OUT; /* Process command line options */ status = ap_do_options(argc, argv); if (status > 0) { return (0); } if (status < 0) { return (status); } /* Get/dump ACPI table(s) as requested */ for (i = 0; i < current_action; i++) { action = &action_table[i]; switch (action->to_be_done) { case AP_DUMP_ALL_TABLES: status = ap_dump_all_tables(); break; case AP_DUMP_TABLE_BY_ADDRESS: status = ap_dump_table_by_address(action->argument); break; case AP_DUMP_TABLE_BY_NAME: status = ap_dump_table_by_name(action->argument); break; case AP_DUMP_TABLE_BY_FILE: status = ap_dump_table_from_file(action->argument); break; default: acpi_log_error("Internal error, invalid action: 0x%X\n", action->to_be_done); return (-1); } if (status) { return (status); } } if (gbl_output_filename) { if (gbl_verbose_mode) { /* Summary for the output file */ file_size = cm_get_file_size(gbl_output_file); acpi_log_error ("Output file %s contains 0x%X (%u) bytes\n\n", gbl_output_filename, file_size, file_size); } acpi_os_close_file(gbl_output_file); } return (status); }