static ACPI_STATUS AcGetOneTableFromFile ( char *Filename, FILE *File, UINT8 GetOnlyAmlTables, ACPI_TABLE_HEADER **ReturnTable) { ACPI_STATUS Status = AE_OK; ACPI_TABLE_HEADER TableHeader; ACPI_TABLE_HEADER *Table; INT32 Count; long TableOffset; *ReturnTable = NULL; /* Get the table header to examine signature and length */ TableOffset = ftell (File); Count = fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), File); if (Count != sizeof (ACPI_TABLE_HEADER)) { return (AE_CTRL_TERMINATE); } /* Validate the table signature/header (limited ASCII chars) */ Status = AcValidateTableHeader (File, TableOffset); if (ACPI_FAILURE (Status)) { return (Status); } if (GetOnlyAmlTables) { /* * Table must be an AML table (DSDT/SSDT). * Used for iASL -e option only. */ if (!AcpiUtIsAmlTable (&TableHeader)) { fprintf (stderr, " %s: Table [%4.4s] is not an AML table - ignoring\n", Filename, TableHeader.Signature); return (AE_TYPE); } } /* Allocate a buffer for the entire table */ Table = AcpiOsAllocate ((ACPI_SIZE) TableHeader.Length); if (!Table) { return (AE_NO_MEMORY); } /* Read the entire ACPI table, including header */ fseek (File, TableOffset, SEEK_SET); Count = fread (Table, 1, TableHeader.Length, File); if (Count != (INT32) TableHeader.Length) { Status = AE_ERROR; goto ErrorExit; } /* Validate the checksum (just issue a warning) */ Status = AcpiTbVerifyChecksum (Table, TableHeader.Length); if (ACPI_FAILURE (Status)) { Status = AcCheckTextModeCorruption (Table); if (ACPI_FAILURE (Status)) { goto ErrorExit; } } *ReturnTable = Table; return (AE_OK); ErrorExit: AcpiOsFree (Table); return (Status); }
static UINT8 AslDetectSourceFileType ( ASL_FILE_INFO *Info) { char *FileChar; UINT8 Type = ASL_INPUT_TYPE_ASCII_DATA; /* default */ ACPI_STATUS Status; /* Check for 100% ASCII source file (comments are ignored) */ Status = FlIsFileAsciiSource (Info->Filename, FALSE); if (ACPI_SUCCESS (Status)) { /* * File contains ASCII source code. Determine if this is an ASL * file or an ACPI data table file. */ while (fgets (AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, Info->Handle)) { /* Uppercase the buffer for caseless compare */ FileChar = AslGbl_CurrentLineBuffer; while (*FileChar) { *FileChar = (char) toupper ((int) *FileChar); FileChar++; } /* Presence of "DefinitionBlock" indicates actual ASL code */ if (strstr (AslGbl_CurrentLineBuffer, "DEFINITIONBLOCK")) { /* Appears to be an ASL file */ Type = ASL_INPUT_TYPE_ASCII_ASL; goto Cleanup; } } /* Appears to be an ASCII data table source file */ Type = ASL_INPUT_TYPE_ASCII_DATA; goto Cleanup; } /* We have some sort of binary table, check for valid ACPI table */ fseek (Info->Handle, 0, SEEK_SET); Status = AcValidateTableHeader (Info->Handle, 0); if (ACPI_SUCCESS (Status)) { fprintf (stderr, "Binary file appears to be a valid ACPI table, disassembling\n"); Type = ASL_INPUT_TYPE_BINARY_ACPI_TABLE; goto Cleanup; } else { fprintf (stderr, "Binary file does not contain a valid ACPI table\n"); } Type = ASL_INPUT_TYPE_BINARY; Cleanup: /* Must seek back to the start of the file */ fseek (Info->Handle, 0, SEEK_SET); return (Type); }