📄 dbfileio.c
字号:
fseek (fp, 0, SEEK_END); FileSize = (UINT32) ftell (fp); fseek (fp, 0, SEEK_SET); if (FileSize < 4) { return (AE_BAD_HEADER); } /* Read the signature */ if (fread (&TableHeader, 1, 4, fp) != 4) { AcpiOsPrintf ("Could not read the table signature\n"); return (AE_BAD_HEADER); } fseek (fp, 0, SEEK_SET); /* The RSDT and FACS tables do not have standard ACPI headers */ if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") || ACPI_COMPARE_NAME (TableHeader.Signature, "FACS")) { *TableLength = FileSize; StandardHeader = FALSE; } else { /* Read the table header */ if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != sizeof (ACPI_TABLE_HEADER)) { AcpiOsPrintf ("Could not read the table header\n"); return (AE_BAD_HEADER); }#if 0 /* Validate the table header/length */ Status = AcpiTbValidateTableHeader (&TableHeader); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Table header is invalid!\n"); return (Status); }#endif /* File size must be at least as long as the Header-specified length */ if (TableHeader.Length > FileSize) { AcpiOsPrintf ( "TableHeader length [0x%X] greater than the input file size [0x%X]\n", TableHeader.Length, FileSize); return (AE_BAD_HEADER); }#ifdef ACPI_OBSOLETE_CODE /* We only support a limited number of table types */ if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) && ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) && ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4)) { AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n", (char *) TableHeader.Signature); ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); return (AE_ERROR); }#endif *TableLength = TableHeader.Length; } /* Allocate a buffer for the table */ *Table = AcpiOsAllocate ((size_t) FileSize); if (!*Table) { AcpiOsPrintf ( "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n", TableHeader.Signature, *TableLength); return (AE_NO_MEMORY); } /* Get the rest of the table */ fseek (fp, 0, SEEK_SET); Actual = fread (*Table, 1, (size_t) FileSize, fp); if (Actual == FileSize) { if (StandardHeader) { /* Now validate the checksum */ Status = AcpiTbChecksum ((void *) *Table, ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length); if (Status == AE_BAD_CHECKSUM) { Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table, FileSize, (*Table)->Length); return (Status); } } return (AE_OK); } if (Actual > 0) { AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", FileSize, Actual); return (AE_OK); } AcpiOsPrintf ("Error - could not read the table file\n"); AcpiOsFree (*Table); *Table = NULL; *TableLength = 0; return (AE_ERROR);}/******************************************************************************* * * FUNCTION: AeLocalLoadTable * * PARAMETERS: Table - pointer to a buffer containing the entire * table to be loaded * * RETURN: Status * * DESCRIPTION: This function is called to load a table from the caller's * buffer. The buffer must contain an entire ACPI Table including * a valid header. The header fields will be verified, and if it * is determined that the table is invalid, the call will fail. * ******************************************************************************/static ACPI_STATUSAeLocalLoadTable ( ACPI_TABLE_HEADER *Table){ ACPI_STATUS Status = AE_OK;/* ACPI_TABLE_DESC TableInfo; */ ACPI_FUNCTION_TRACE (AeLocalLoadTable);#if 0 if (!Table) { return_ACPI_STATUS (AE_BAD_PARAMETER); } TableInfo.Pointer = Table; Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Install the new table into the local data structures */ Status = AcpiTbInstallTable (&TableInfo); if (ACPI_FAILURE (Status)) { if (Status == AE_ALREADY_EXISTS) { /* Table already exists, no error */ Status = AE_OK; } /* Free table allocated by AcpiTbGetTable */ AcpiTbDeleteSingleTable (&TableInfo); return_ACPI_STATUS (Status); }#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); if (ACPI_FAILURE (Status)) { /* Uninstall table and free the buffer */ AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT); return_ACPI_STATUS (Status); }#endif#endif return_ACPI_STATUS (Status);}/******************************************************************************* * * FUNCTION: AcpiDbReadTableFromFile * * PARAMETERS: Filename - File where table is located * Table - Where a pointer to the table is returned * * RETURN: Status * * DESCRIPTION: Get an ACPI table from a file * ******************************************************************************/ACPI_STATUSAcpiDbReadTableFromFile ( char *Filename, ACPI_TABLE_HEADER **Table){ FILE *fp; UINT32 TableLength; ACPI_STATUS Status; /* Open the file */ fp = fopen (Filename, "rb"); if (!fp) { AcpiOsPrintf ("Could not open input file %s\n", Filename); return (AE_ERROR); } /* Get the entire file */ fprintf (stderr, "Loading Acpi table from file %s\n", Filename); Status = AcpiDbReadTable (fp, Table, &TableLength); fclose(fp); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not get table from the file\n"); return (Status); } return (AE_OK); }#endif/******************************************************************************* * * FUNCTION: AcpiDbGetTableFromFile * * PARAMETERS: Filename - File where table is located * ReturnTable - Where a pointer to the table is returned * * RETURN: Status * * DESCRIPTION: Load an ACPI table from a file * ******************************************************************************/ACPI_STATUSAcpiDbGetTableFromFile ( char *Filename, ACPI_TABLE_HEADER **ReturnTable){#ifdef ACPI_APPLICATION ACPI_STATUS Status; ACPI_TABLE_HEADER *Table; BOOLEAN IsAmlTable = TRUE; Status = AcpiDbReadTableFromFile (Filename, &Table); if (ACPI_FAILURE (Status)) { return (Status); }#ifdef ACPI_DATA_TABLE_DISASSEMBLY IsAmlTable = AcpiUtIsAmlTable (Table);#endif if (IsAmlTable) { /* Attempt to recognize and install the table */ Status = AeLocalLoadTable (Table); if (ACPI_FAILURE (Status)) { if (Status == AE_ALREADY_EXISTS) { AcpiOsPrintf ("Table %4.4s is already installed\n", Table->Signature); } else { AcpiOsPrintf ("Could not install table, %s\n", AcpiFormatException (Status)); } return (Status); } fprintf (stderr, "Acpi table [%4.4s] successfully installed and loaded\n", Table->Signature); } AcpiGbl_AcpiHardwarePresent = FALSE; if (ReturnTable) { *ReturnTable = Table; }#endif /* ACPI_APPLICATION */ return (AE_OK);}#endif /* ACPI_DEBUGGER */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -