diff options
author | Lv Zheng <lv.zheng@intel.com> | 2016-07-22 23:48:21 +0800 |
---|---|---|
committer | Lv Zheng <lv.zheng@intel.com> | 2016-07-22 23:48:21 +0800 |
commit | 189429fb7d06cdb89043ae32d615faf553467f1d (patch) | |
tree | 84308ac4ccb05d2162dc0fe879aa1f51e2c5985c | |
parent | d261d40ea168f8e4c4e3986de720b8651c4aba1c (diff) | |
download | acpica-189429fb7d06cdb89043ae32d615faf553467f1d.tar.gz |
Clib: Eliminate AcpiOsXXXFile()/AcpiLogError and link clibrary fxxx()/errno/perror() instead
This patch follows new ACPICA design, eliminates old portable OSLs, and
implements fopen/fread/fwrite/fclose/fseek/ftell for GNU EFI
environment. This patch also eliminates AcpiLogError(), convering them
into fprintf(stderr)/perror(). Lv Zheng.
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
27 files changed, 1004 insertions, 1190 deletions
diff --git a/generate/efi/acpidump/Makefile b/generate/efi/acpidump/Makefile index 672421d6e..39fa364d0 100644 --- a/generate/efi/acpidump/Makefile +++ b/generate/efi/acpidump/Makefile @@ -32,6 +32,7 @@ OBJECTS = \ $(OBJDIR)/apmain.o\ $(OBJDIR)/cmfsize.o\ $(OBJDIR)/getopt.o\ + $(OBJDIR)/oseficlib.o\ $(OBJDIR)/osefitbl.o\ $(OBJDIR)/osefixf.o\ $(OBJDIR)/tbprint.o\ diff --git a/generate/unix/acpibin/Makefile b/generate/unix/acpibin/Makefile index 70a480fe2..72094bd29 100644 --- a/generate/unix/acpibin/Makefile +++ b/generate/unix/acpibin/Makefile @@ -46,7 +46,6 @@ OBJECTS = \ $(OBJDIR)/utstate.o\ $(OBJDIR)/utstring.o\ $(OBJDIR)/utxferror.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o # diff --git a/generate/unix/acpidump/Makefile b/generate/unix/acpidump/Makefile index 841417768..4aa98a345 100644 --- a/generate/unix/acpidump/Makefile +++ b/generate/unix/acpidump/Makefile @@ -33,7 +33,6 @@ OBJECTS = \ $(OBJDIR)/apmain.o\ $(OBJDIR)/cmfsize.o\ $(OBJDIR)/getopt.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixdir.o\ $(OBJDIR)/osunixmap.o\ $(OBJDIR)/osunixxf.o\ diff --git a/generate/unix/acpiexamples/Makefile b/generate/unix/acpiexamples/Makefile index 371bbb51f..d1e5ac213 100644 --- a/generate/unix/acpiexamples/Makefile +++ b/generate/unix/acpiexamples/Makefile @@ -107,7 +107,6 @@ OBJECTS = \ $(OBJDIR)/nsxfeval.o\ $(OBJDIR)/nsxfname.o\ $(OBJDIR)/nsxfobj.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/psargs.o\ $(OBJDIR)/psloop.o\ diff --git a/generate/unix/acpiexec/Makefile b/generate/unix/acpiexec/Makefile index 7393a69fc..ad53dbe7b 100644 --- a/generate/unix/acpiexec/Makefile +++ b/generate/unix/acpiexec/Makefile @@ -163,7 +163,6 @@ OBJECTS = \ $(OBJDIR)/nsxfeval.o\ $(OBJDIR)/nsxfname.o\ $(OBJDIR)/nsxfobj.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/psargs.o\ $(OBJDIR)/psloop.o\ diff --git a/generate/unix/acpihelp/Makefile b/generate/unix/acpihelp/Makefile index e75fa301f..fc38071c3 100644 --- a/generate/unix/acpihelp/Makefile +++ b/generate/unix/acpihelp/Makefile @@ -38,7 +38,6 @@ OBJECTS = \ $(OBJDIR)/ahtable.o\ $(OBJDIR)/ahuuids.o\ $(OBJDIR)/getopt.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/utdebug.o\ $(OBJDIR)/utexcep.o\ diff --git a/generate/unix/acpinames/Makefile b/generate/unix/acpinames/Makefile index 469bdd8c7..fd263a01a 100644 --- a/generate/unix/acpinames/Makefile +++ b/generate/unix/acpinames/Makefile @@ -72,7 +72,6 @@ OBJECTS = \ $(OBJDIR)/nsxfeval.o\ $(OBJDIR)/nsxfname.o\ $(OBJDIR)/nsxfobj.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/psargs.o\ $(OBJDIR)/psloop.o\ diff --git a/generate/unix/acpisrc/Makefile b/generate/unix/acpisrc/Makefile index 42f8f0cfd..2a3282c8b 100644 --- a/generate/unix/acpisrc/Makefile +++ b/generate/unix/acpisrc/Makefile @@ -36,7 +36,6 @@ OBJECTS = \ $(OBJDIR)/asutils.o\ $(OBJDIR)/cmfsize.o\ $(OBJDIR)/getopt.o \ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixdir.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/utascii.o\ diff --git a/generate/unix/acpixtract/Makefile b/generate/unix/acpixtract/Makefile index bd21eef45..609451fd1 100644 --- a/generate/unix/acpixtract/Makefile +++ b/generate/unix/acpixtract/Makefile @@ -31,7 +31,6 @@ OBJECTS = \ $(OBJDIR)/axmain.o\ $(OBJDIR)/axutils.o\ $(OBJDIR)/getopt.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/utascii.o\ $(OBJDIR)/utdebug.o\ diff --git a/generate/unix/iasl/Makefile b/generate/unix/iasl/Makefile index 751765ca3..805568cdf 100644 --- a/generate/unix/iasl/Makefile +++ b/generate/unix/iasl/Makefile @@ -177,7 +177,6 @@ OBJECTS = \ $(OBJDIR)/nswalk.o\ $(OBJDIR)/nsxfobj.o\ $(OBJDIR)/osunixxf.o\ - $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/prexpress.o\ $(OBJDIR)/prmacros.o\ $(OBJDIR)/prscan.o\ diff --git a/source/common/acfileio.c b/source/common/acfileio.c index be5b9be4c..b7d50391f 100644 --- a/source/common/acfileio.c +++ b/source/common/acfileio.c @@ -169,7 +169,7 @@ AcGetAllTablesFromFile ( File = fopen (Filename, "rb"); if (!File) { - perror ("Could not open input file"); + fprintf (stderr, "Could not open input file: %s\n", Filename); if (errno == ENOENT) { return (AE_NOT_EXIST); diff --git a/source/common/cmfsize.c b/source/common/cmfsize.c index 4d35105cb..2139e4b26 100644 --- a/source/common/cmfsize.c +++ b/source/common/cmfsize.c @@ -145,19 +145,19 @@ CmGetFileSize ( /* Save the current file pointer, seek to EOF to obtain file size */ - CurrentOffset = AcpiOsGetFileOffset (File); + CurrentOffset = ftell (File); if (CurrentOffset < 0) { goto OffsetError; } - Status = AcpiOsSetFileOffset (File, 0, ACPI_FILE_END); + Status = fseek (File, 0, SEEK_END); if (ACPI_FAILURE (Status)) { goto SeekError; } - FileSize = AcpiOsGetFileOffset (File); + FileSize = ftell (File); if (FileSize < 0) { goto OffsetError; @@ -165,7 +165,7 @@ CmGetFileSize ( /* Restore original file pointer */ - Status = AcpiOsSetFileOffset (File, CurrentOffset, ACPI_FILE_BEGIN); + Status = fseek (File, CurrentOffset, SEEK_SET); if (ACPI_FAILURE (Status)) { goto SeekError; @@ -175,10 +175,10 @@ CmGetFileSize ( OffsetError: - AcpiLogError ("Could not get file offset"); + fprintf (stderr, "Could not get file offset\n"); return (ACPI_UINT32_MAX); SeekError: - AcpiLogError ("Could not set file offset"); + fprintf (stderr, "Could not set file offset\n"); return (ACPI_UINT32_MAX); } diff --git a/source/common/getopt.c b/source/common/getopt.c index 15eadc259..cf4375dd8 100644 --- a/source/common/getopt.c +++ b/source/common/getopt.c @@ -129,7 +129,7 @@ #include "acapps.h" #define ACPI_OPTION_ERROR(msg, badchar) \ - if (AcpiGbl_Opterr) {AcpiLogError ("%s%c\n", msg, badchar);} + if (AcpiGbl_Opterr) {fprintf (stderr, "%s%c\n", msg, badchar);} int AcpiGbl_Opterr = 1; diff --git a/source/components/utilities/utdebug.c b/source/components/utilities/utdebug.c index d13c0974e..995d45cc3 100644 --- a/source/components/utilities/utdebug.c +++ b/source/components/utilities/utdebug.c @@ -780,33 +780,3 @@ AcpiTracePoint ( ACPI_EXPORT_SYMBOL (AcpiTracePoint) #endif - - -#ifdef ACPI_APPLICATION -/******************************************************************************* - * - * FUNCTION: AcpiLogError - * - * PARAMETERS: Format - Printf format field - * ... - Optional printf arguments - * - * RETURN: None - * - * DESCRIPTION: Print error message to the console, used by applications. - * - ******************************************************************************/ - -void ACPI_INTERNAL_VAR_XFACE -AcpiLogError ( - const char *Format, - ...) -{ - va_list Args; - - va_start (Args, Format); - (void) vfprintf (ACPI_FILE_ERR, Format, Args); - va_end (Args); -} - -ACPI_EXPORT_SYMBOL (AcpiLogError) -#endif diff --git a/source/components/utilities/utprint.c b/source/components/utilities/utprint.c index a43a3ea6b..552656f79 100644 --- a/source/components/utilities/utprint.c +++ b/source/components/utilities/utprint.c @@ -874,7 +874,7 @@ vprintf ( Length = vsnprintf (AcpiGbl_PrintBuffer, sizeof (AcpiGbl_PrintBuffer), Format, Args); - (void) AcpiOsWriteFile (ACPI_FILE_OUT, AcpiGbl_PrintBuffer, Length, 1); + (void) fwrite (AcpiGbl_PrintBuffer, Length, 1, ACPI_FILE_OUT); AcpiOsReleaseLock (AcpiGbl_PrintLock, Flags); return (Length); @@ -938,7 +938,7 @@ vfprintf ( Length = vsnprintf (AcpiGbl_PrintBuffer, sizeof (AcpiGbl_PrintBuffer), Format, Args); - (void) AcpiOsWriteFile (File, AcpiGbl_PrintBuffer, Length, 1); + (void) fwrite (AcpiGbl_PrintBuffer, Length, 1, File); AcpiOsReleaseLock (AcpiGbl_PrintLock, Flags); return (Length); diff --git a/source/include/acclib.h b/source/include/acclib.h index 46919656b..f18f2b8b7 100644 --- a/source/include/acclib.h +++ b/source/include/acclib.h @@ -145,6 +145,23 @@ extern const UINT8 AcpiGbl_Ctypes[]; #define isprint(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU)) #define isalpha(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP)) +/* Error code */ + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define EBADF 9 /* Bad file number */ +#define EAGAIN 11 /* Try again */ +#define ENOMEM 12 /* Out of memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define EBUSY 16 /* Device or resource busy */ +#define EEXIST 17 /* File exists */ +#define ENODEV 19 /* No such device */ +#define EINVAL 22 /* Invalid argument */ +#define EPIPE 32 /* Broken pipe */ +#define ERANGE 34 /* Math result not representable */ /* Strings */ @@ -270,6 +287,17 @@ sprintf ( ...); #ifdef ACPI_APPLICATION +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +/* + * NOTE: Currently we only need to update errno for file IOs. Other + * Clibrary invocations in ACPICA do not make descisions according to + * the errno. + */ +extern int errno; + int vprintf ( const char *Format, @@ -291,6 +319,39 @@ fprintf ( FILE *File, const char *Format, ...); + +FILE * +fopen ( + const char *Path, + const char *Modes); + +void +fclose ( + FILE *File); + +int +fread ( + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count, + FILE *File); + +int +fwrite ( + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count, + FILE *File); + +int +fseek ( + FILE *File, + long Offset, + int From); + +long +ftell ( + FILE *File); #endif #endif /* _ACCLIB_H */ diff --git a/source/include/acpiosxf.h b/source/include/acpiosxf.h index 550e264bd..60d61f119 100644 --- a/source/include/acpiosxf.h +++ b/source/include/acpiosxf.h @@ -564,6 +564,15 @@ AcpiOsGetLine ( UINT32 *BytesRead); #endif +#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTracePoint +void +AcpiOsTracePoint ( + ACPI_TRACE_EVENT_TYPE Type, + BOOLEAN Begin, + UINT8 *Aml, + char *Pathname); +#endif + /* * Obtain ACPI table(s) @@ -624,62 +633,4 @@ AcpiOsCloseDirectory ( #endif -/* - * File I/O and related support - */ -#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsOpenFile -ACPI_FILE -AcpiOsOpenFile ( - const char *Path, - UINT8 Modes); -#endif - -#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCloseFile -void -AcpiOsCloseFile ( - ACPI_FILE File); -#endif - -#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadFile -int -AcpiOsReadFile ( - ACPI_FILE File, - void *Buffer, - ACPI_SIZE Size, - ACPI_SIZE Count); -#endif - -#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWriteFile -int -AcpiOsWriteFile ( - ACPI_FILE File, - void *Buffer, - ACPI_SIZE Size, - ACPI_SIZE Count); -#endif - -#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetFileOffset -long -AcpiOsGetFileOffset ( - ACPI_FILE File); -#endif - -#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsSetFileOffset -ACPI_STATUS -AcpiOsSetFileOffset ( - ACPI_FILE File, - long Offset, - UINT8 From); -#endif - -#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTracePoint -void -AcpiOsTracePoint ( - ACPI_TRACE_EVENT_TYPE Type, - BOOLEAN Begin, - UINT8 *Aml, - char *Pathname); -#endif - - #endif /* __ACPIOSXF_H__ */ diff --git a/source/include/acpixf.h b/source/include/acpixf.h index 2f939b1f5..ba6b62d7e 100644 --- a/source/include/acpixf.h +++ b/source/include/acpixf.h @@ -1304,13 +1304,6 @@ AcpiTracePoint ( UINT8 *Aml, char *Pathname)) -ACPI_APP_DEPENDENT_RETURN_VOID ( -ACPI_PRINTF_LIKE(1) -void ACPI_INTERNAL_VAR_XFACE -AcpiLogError ( - const char *Format, - ...)) - ACPI_STATUS AcpiInitializeDebugger ( void); diff --git a/source/include/actypes.h b/source/include/actypes.h index 039d71a5a..abc4f7b4c 100644 --- a/source/include/actypes.h +++ b/source/include/actypes.h @@ -1459,16 +1459,6 @@ typedef enum #define ACPI_OSI_WIN_10 0x0D -/* Definitions of file IO */ - -#define ACPI_FILE_READING 0x01 -#define ACPI_FILE_WRITING 0x02 -#define ACPI_FILE_BINARY 0x04 - -#define ACPI_FILE_BEGIN 0x01 -#define ACPI_FILE_END 0x02 - - /* Definitions of getopt */ #define ACPI_OPT_END -1 diff --git a/source/os_specific/service_layers/oseficlib.c b/source/os_specific/service_layers/oseficlib.c new file mode 100644 index 000000000..629e99d00 --- /dev/null +++ b/source/os_specific/service_layers/oseficlib.c @@ -0,0 +1,880 @@ +/****************************************************************************** + * + * Module Name: oseficlib - EFI specific CLibrary interfaces + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#include "acpi.h" +#include "accommon.h" +#include "acapps.h" + +#define _COMPONENT ACPI_OS_SERVICES + ACPI_MODULE_NAME ("oseficlib") + + +/* Local definitions */ + +#define ACPI_EFI_PRINT_LENGTH 256 + + +/* Local prototypes */ + +static int +AcpiEfiArgify ( + char *String, + int *ArgcPtr, + char ***ArgvPtr); + +static int +AcpiEfiConvertArgcv ( + CHAR16 *LoadOpt, + UINT32 LoadOptSize, + int *ArgcPtr, + char ***ArgvPtr, + char **BufferPtr); + +static CHAR16 * +AcpiEfiFlushFile ( + FILE *File, + CHAR16 *Begin, + CHAR16 *End, + CHAR16 *Pos, + BOOLEAN FlushAll); + + +/* Local variables */ + +static EFI_FILE_HANDLE AcpiGbl_EfiCurrentVolume = NULL; +EFI_GUID AcpiGbl_LoadedImageProtocol = LOADED_IMAGE_PROTOCOL; +EFI_GUID AcpiGbl_TextInProtocol = SIMPLE_TEXT_INPUT_PROTOCOL; +EFI_GUID AcpiGbl_TextOutProtocol = SIMPLE_TEXT_OUTPUT_PROTOCOL; +EFI_GUID AcpiGbl_FileSystemProtocol = SIMPLE_FILE_SYSTEM_PROTOCOL; + +int errno = 0; + + +/******************************************************************************* + * + * FUNCTION: fopen + * + * PARAMETERS: Path - File path + * Modes - File operation type + * + * RETURN: File descriptor + * + * DESCRIPTION: Open a file for reading or/and writing. + * + ******************************************************************************/ + +FILE * +fopen ( + const char *Path, + const char *Modes) +{ + EFI_STATUS EfiStatus = EFI_SUCCESS; + UINT64 OpenModes; + EFI_FILE_HANDLE EfiFile = NULL; + CHAR16 *Path16 = NULL; + CHAR16 *Pos16; + const char *Pos; + INTN Count, i; + BOOLEAN IsAppend = FALSE; + FILE *File = NULL; + + + if (!Path) + { + errno = EINVAL; + return (NULL); + } + + /* + * Convert modes, EFI says the only 2 read/write modes are read-only, + * read+write. Thus set default mode as read-only. + */ + OpenModes = EFI_FILE_MODE_READ; + switch (*Modes++) + { + case 'r': + + break; + + case 'w': + + OpenModes |= (EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE); + break; + + case 'a': + + OpenModes |= (EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE); + IsAppend = TRUE; + break; + + default: + + errno = EINVAL; + return (NULL); + } + + for (; *Modes; Modes++) + { + switch (*Modes) + { + case '+': + + OpenModes |= (EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE); + break; + + case 'b': + case 't': + + break; + + case 'f': + default: + + break; + } + } + + /* Allocate path buffer */ + + Count = strlen (Path); + Path16 = ACPI_ALLOCATE_ZEROED ((Count + 1) * sizeof (CHAR16)); + if (!Path16) + { + EfiStatus = EFI_BAD_BUFFER_SIZE; + errno = ENOMEM; + goto ErrorExit; + } + Pos = Path; + Pos16 = Path16; + while (*Pos == '/' || *Pos == '\\') + { + Pos++; + Count--; + } + for (i = 0; i < Count; i++) + { + if (*Pos == '/') + { + *Pos16++ = '\\'; + Pos++; + } + else + { + *Pos16++ = *Pos++; + } + } + *Pos16 = '\0'; + + EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Open, 5, + AcpiGbl_EfiCurrentVolume, &EfiFile, Path16, OpenModes, 0); + if (EFI_ERROR (EfiStatus)) + { + fprintf (stderr, "EFI_FILE_HANDLE->Open() failure.\n"); + errno = ENOENT; + goto ErrorExit; + } + + File = (FILE *) EfiFile; + if (IsAppend) + { + fseek (File, 0, SEEK_END); + } + +ErrorExit: + + if (Path16) + { + ACPI_FREE (Path16); + } + + return (File); +} + + +/******************************************************************************* + * + * FUNCTION: fclose + * + * PARAMETERS: File - File descriptor + * + * RETURN: None. + * + * DESCRIPTION: Close a file. + * + ******************************************************************************/ + +void +fclose ( + FILE *File) +{ + EFI_FILE_HANDLE EfiFile; + + + if (File == stdout || File == stderr) + { + return; + } + EfiFile = (EFI_FILE_HANDLE) File; + (void) uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Close, 1, EfiFile); + + return; +} + + +/******************************************************************************* + * + * FUNCTION: fread + * + * PARAMETERS: Buffer - Data buffer + * Size - Data block size + * Count - Number of data blocks + * File - File descriptor + * + * RETURN: Size of successfully read buffer + * + * DESCRIPTION: Read from a file. + * + ******************************************************************************/ + +int +fread ( + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count, + FILE *File) +{ + int Length = -1; + EFI_FILE_HANDLE EfiFile; + UINTN ReadSize; + EFI_STATUS EfiStatus; + + + if (File == stdout || File == stderr) + { + } + else + { + EfiFile = (EFI_FILE_HANDLE) File; + if (!EfiFile) + { + errno = EINVAL; + goto ErrorExit; + } + ReadSize = Size * Count; + + EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Read, 3, + EfiFile, &ReadSize, Buffer); + if (EFI_ERROR (EfiStatus)) + { + fprintf (stderr, "EFI_FILE_HANDLE->Read() failure.\n"); + errno = EIO; + goto ErrorExit; + } + Length = ReadSize; + } + +ErrorExit: + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiEfiFlushFile + * + * PARAMETERS: File - File descriptor + * Begin - String with boundary + * End - Boundary of the string + * Pos - Current position + * FlushAll - Whether checking boundary before flushing + * + * RETURN: Updated position + * + * DESCRIPTION: Flush cached buffer to the file. + * + ******************************************************************************/ + +static CHAR16 * +AcpiEfiFlushFile ( + FILE *File, + CHAR16 *Begin, + CHAR16 *End, + CHAR16 *Pos, + BOOLEAN FlushAll) +{ + + if (FlushAll || Pos >= (End - 1)) + { + *Pos = 0; + uefi_call_wrapper (File->OutputString, 2, File, Begin); + Pos = Begin; + } + + return (Pos); +} + + +/******************************************************************************* + * + * FUNCTION: fwrite + * + * PARAMETERS: Buffer - Data buffer + * Size - Data block size + * Count - Number of data blocks + * File - File descriptor + * + * RETURN: Size of successfully written buffer + * + * DESCRIPTION: Write to a file. + * + ******************************************************************************/ + +int +fwrite ( + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count, + FILE *File) +{ + int Length = -1; + CHAR16 String[ACPI_EFI_PRINT_LENGTH]; + const char *Ascii; + CHAR16 *End; + CHAR16 *Pos; + int i, j; + EFI_FILE_HANDLE EfiFile; + UINTN WriteSize; + EFI_STATUS EfiStatus; + + + if (File == stdout || File == stderr) + { + Pos = String; + End = String + ACPI_EFI_PRINT_LENGTH - 1; + Ascii = ACPI_CAST_PTR (const char, Buffer); + Length = 0; + + for (j = 0; j < Count; j++) + { + for (i = 0; i < Size; i++) + { + if (*Ascii == '\n') + { + *Pos++ = '\r'; + Pos = AcpiEfiFlushFile (File, String, + End, Pos, FALSE); + } + *Pos++ = *Ascii++; + Length++; + Pos = AcpiEfiFlushFile (File, String, + End, Pos, FALSE); + } + } + Pos = AcpiEfiFlushFile (File, String, End, Pos, TRUE); + } + else + { + EfiFile = (EFI_FILE_HANDLE) File; + if (!EfiFile) + { + errno = EINVAL; + goto ErrorExit; + } + WriteSize = Size * Count; + + EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Write, 3, + EfiFile, &WriteSize, Buffer); + if (EFI_ERROR (EfiStatus)) + { + fprintf (stderr, "EFI_FILE_HANDLE->Write() failure.\n"); + errno = EIO; + goto ErrorExit; + } + Length = WriteSize; + } + +ErrorExit: + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: ftell + * + * PARAMETERS: File - File descriptor + * + * RETURN: Size of current position + * + * DESCRIPTION: Get current file offset. + * + ******************************************************************************/ + +long +ftell ( + FILE *File) +{ + long Offset = -1; + + + return (Offset); +} + + +/******************************************************************************* + * + * FUNCTION: fseek + * + * PARAMETERS: File - File descriptor + * Offset - File offset + * From - From begin/end of file + * + * RETURN: Status + * + * DESCRIPTION: Set current file offset. + * + ******************************************************************************/ + +int +fseek ( + FILE *File, + long Offset, + int From) +{ + + return (-1); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiArgify + * + * PARAMETERS: String - Pointer to command line argument strings + * which are seperated with spaces + * ArgcPtr - Return number of the arguments + * ArgvPtr - Return vector of the arguments + * + * RETURN: Clibraray error code + * -EINVAL: invalid parameter + * EAGAIN: try again + * + * DESCRIPTION: Convert EFI arguments into C arguments. + * + *****************************************************************************/ + +static int +AcpiEfiArgify ( + char *String, + int *ArgcPtr, + char ***ArgvPtr) +{ + char *CopyBuffer; + int MaxArgc = *ArgcPtr; + int Argc = 0; + char **Argv = *ArgvPtr; + char *Arg; + BOOLEAN IsSingleQuote = FALSE; + BOOLEAN IsDoubleQuote = FALSE; + BOOLEAN IsEscape = FALSE; + + + if (String == NULL) + { + errno = EINVAL; + return (-EINVAL); + } + + CopyBuffer = String; + + while (*String != '\0') + { + while (isspace (*String)) + { + *String++ = '\0'; + } + Arg = CopyBuffer; + while (*String != '\0') + { + if (isspace (*String) && + !IsSingleQuote && !IsDoubleQuote && !IsEscape) + { + *Arg++ = '\0'; + String++; + break; + } + if (IsEscape) + { + IsEscape = FALSE; + *Arg++ = *String; + } + else if (*String == '\\') + { + IsEscape = TRUE; + } + else if (IsSingleQuote) + { + if (*String == '\'') + { + IsSingleQuote = FALSE; + *Arg++ = '\0'; + } + else + { + *Arg++ = *String; + } + } + else if (IsDoubleQuote) + { + if (*String == '"') + { + IsDoubleQuote = FALSE; + *Arg = '\0'; + } + else + { + *Arg++ = *String; + } + } + else + { + if (*String == '\'') + { + IsSingleQuote = TRUE; + } + else if (*String == '"') + { + IsDoubleQuote = TRUE; + } + else + { + *Arg++ = *String; + } + } + String++; + } + if (Argv && Argc < MaxArgc) + { + Argv[Argc] = CopyBuffer; + } + Argc++; + CopyBuffer = Arg; + } + if (Argv && Argc < MaxArgc) + { + Argv[Argc] = NULL; + } + + *ArgcPtr = Argc; + *ArgvPtr = Argv; + + if (MaxArgc < Argc) + { + errno = EAGAIN; + return (-ENOMEM); + } + return (0); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiConvertArgcv + * + * PARAMETERS: LoadOptions - Pointer to the EFI options buffer, which + * is NULL terminated + * LoadOptionsSize - Size of the EFI options buffer + * ArgcPtr - Return number of the arguments + * ArgvPtr - Return vector of the arguments + * BufferPtr - Buffer to contain the argument strings + * + * RETURN: Clibrary error code + * + * DESCRIPTION: Convert EFI arguments into C arguments. + * + *****************************************************************************/ + +static int +AcpiEfiConvertArgcv ( + CHAR16 *LoadOptions, + UINT32 LoadOptionsSize, + int *ArgcPtr, + char ***ArgvPtr, + char **BufferPtr) +{ + int Error = 0; + UINT32 Count = LoadOptionsSize / sizeof (CHAR16); + UINT32 i; + CHAR16 *From; + char *To; + int Argc = 0; + char **Argv = NULL; + char *Buffer; + + + /* Prepare a buffer to contain the argument strings */ + + Buffer = ACPI_ALLOCATE_ZEROED (Count); + if (!Buffer) + { + errno = ENOMEM; + Error = -ENOMEM; + goto ErrorExit; + } + +TryAgain: + + /* Extend the argument vector */ + + if (Argv) + { + ACPI_FREE (Argv); + Argv = NULL; + } + if (Argc > 0) + { + Argv = ACPI_ALLOCATE_ZEROED (sizeof (char *) * (Argc + 1)); + if (!Argv) + { + errno = ENOMEM; + Error = -ENOMEM; + goto ErrorExit; + } + } + + /* + * Note: As AcpiEfiArgify() will modify the content of the buffer, so + * we need to restore it each time before invoking + * AcpiEfiArgify(). + */ + From = LoadOptions; + To = ACPI_CAST_PTR (char, Buffer); + for (i = 0; i < Count; i++) + { + *To++ = (char) *From++; + } + + /* + * The "Buffer" will contain NULL terminated strings after invoking + * AcpiEfiArgify(). The number of the strings are saved in Argc and the + * pointers of the strings are saved in Argv. + */ + Error = AcpiEfiArgify (Buffer, &Argc, &Argv); + if (Error && errno == EAGAIN) + { + goto TryAgain; + } + +ErrorExit: + + if (Error) + { + ACPI_FREE (Buffer); + ACPI_FREE (Argv); + } + else + { + *ArgcPtr = Argc; + *ArgvPtr = Argv; + *BufferPtr = Buffer; + } + return (Error); +} + + +/****************************************************************************** + * + * FUNCTION: efi_main + * + * PARAMETERS: Image - EFI image handle + * SystemTab - EFI system table + * + * RETURN: EFI Status + * + * DESCRIPTION: Entry point of EFI executable + * + *****************************************************************************/ + +EFI_STATUS +efi_main ( + EFI_HANDLE Image, + EFI_SYSTEM_TABLE *SystemTab) +{ + EFI_LOADED_IMAGE *Info; + EFI_STATUS EfiStatus = EFI_SUCCESS; + int Error; + int argc; + char **argv = NULL; + char *OptBuffer = NULL; + EFI_FILE_IO_INTERFACE *Volume = NULL; + + + /* Initialize global variables */ + + ST = SystemTab; + BS = SystemTab->BootServices; + + /* Retrieve image information */ + + EfiStatus = uefi_call_wrapper (BS->HandleProtocol, 3, + Image, &AcpiGbl_LoadedImageProtocol, ACPI_CAST_PTR (VOID, &Info)); + if (EFI_ERROR (EfiStatus)) + { + fprintf (stderr, + "EFI_BOOT_SERVICES->HandleProtocol(LoadedImageProtocol) failure.\n"); + return (EfiStatus); + } + + EfiStatus = uefi_call_wrapper (BS->HandleProtocol, 3, + Info->DeviceHandle, &AcpiGbl_FileSystemProtocol, (void **) &Volume); + if (EFI_ERROR (EfiStatus)) + { + fprintf (stderr, + "EFI_BOOT_SERVICES->HandleProtocol(FileSystemProtocol) failure.\n"); + return (EfiStatus); + } + EfiStatus = uefi_call_wrapper (Volume->OpenVolume, 2, + Volume, &AcpiGbl_EfiCurrentVolume); + if (EFI_ERROR (EfiStatus)) + { + fprintf (stderr, "EFI_FILE_IO_INTERFACE->OpenVolume() failure.\n"); + return (EfiStatus); + } + + Error = AcpiEfiConvertArgcv (Info->LoadOptions, + Info->LoadOptionsSize, &argc, &argv, &OptBuffer); + if (Error) + { + EfiStatus = EFI_DEVICE_ERROR; + goto ErrorAlloc; + } + + acpi_main (argc, argv); + +ErrorAlloc: + + if (argv) + { + ACPI_FREE (argv); + } + if (OptBuffer) + { + ACPI_FREE (OptBuffer); + } + + return (EfiStatus); +} diff --git a/source/os_specific/service_layers/osefitbl.c b/source/os_specific/service_layers/osefitbl.c index 42924053d..81bbdc76b 100644 --- a/source/os_specific/service_layers/osefitbl.c +++ b/source/os_specific/service_layers/osefitbl.c @@ -378,7 +378,7 @@ OslAddTableToList ( { if (Instance) { - AcpiLogError ( + fprintf (stderr, "%4.4s: Warning unmatched table instance %d, expected %d\n", Signature, Instance, NextInstance); } @@ -1014,7 +1014,7 @@ OslMapTable ( MappedTable = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); if (!MappedTable) { - AcpiLogError ("Could not map table header at 0x%8.8X%8.8X\n", + fprintf (stderr, "Could not map table header at 0x%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Address)); return (AE_BAD_ADDRESS); } @@ -1050,7 +1050,7 @@ OslMapTable ( MappedTable = AcpiOsMapMemory (Address, Length); if (!MappedTable) { - AcpiLogError ("Could not map table at 0x%8.8X%8.8X length %8.8X\n", + fprintf (stderr, "Could not map table at 0x%8.8X%8.8X length %8.8X\n", ACPI_FORMAT_UINT64 (Address), Length); return (AE_INVALID_TABLE_LENGTH); } diff --git a/source/os_specific/service_layers/osefixf.c b/source/os_specific/service_layers/osefixf.c index 1947197e1..b3da80b8f 100644 --- a/source/os_specific/service_layers/osefixf.c +++ b/source/os_specific/service_layers/osefixf.c @@ -121,53 +121,17 @@ ACPI_MODULE_NAME ("osefixf") -/* Local definitions */ - -#define ACPI_EFI_PRINT_LENGTH 256 - - /* Local prototypes */ -static ACPI_STATUS -AcpiEfiArgify ( - char *String, - int *ArgcPtr, - char ***ArgvPtr); - static BOOLEAN AcpiEfiCompareGuid ( EFI_GUID *Guid1, EFI_GUID *Guid2); -static ACPI_STATUS -AcpiEfiConvertArgcv ( - CHAR16 *LoadOpt, - UINT32 LoadOptSize, - int *ArgcPtr, - char ***ArgvPtr, - char **BufferPtr); - static ACPI_PHYSICAL_ADDRESS AcpiEfiGetRsdpViaGuid ( EFI_GUID *Guid); -static CHAR16 * -AcpiEfiFlushFile ( - ACPI_FILE File, - CHAR16 *Begin, - CHAR16 *End, - CHAR16 *Pos, - BOOLEAN FlushAll); - - -/* Local variables */ - -static EFI_FILE_HANDLE AcpiGbl_EfiCurrentVolume = NULL; -EFI_GUID AcpiGbl_LoadedImageProtocol = LOADED_IMAGE_PROTOCOL; -EFI_GUID AcpiGbl_TextInProtocol = SIMPLE_TEXT_INPUT_PROTOCOL; -EFI_GUID AcpiGbl_TextOutProtocol = SIMPLE_TEXT_OUTPUT_PROTOCOL; -EFI_GUID AcpiGbl_FileSystemProtocol = SIMPLE_FILE_SYSTEM_PROTOCOL; - /****************************************************************************** * @@ -376,7 +340,8 @@ AcpiOsAllocate ( EfiLoaderData, Size, &Mem); if (EFI_ERROR (EfiStatus)) { - AcpiLogError ("EFI_BOOT_SERVICES->AllocatePool(EfiLoaderData) failure.\n"); + fprintf (stderr, + "EFI_BOOT_SERVICES->AllocatePool(EfiLoaderData) failure.\n"); return (NULL); } @@ -436,352 +401,6 @@ AcpiOsFree ( } -/******************************************************************************* - * - * FUNCTION: AcpiOsOpenFile - * - * PARAMETERS: Path - File path - * Modes - File operation type - * - * RETURN: File descriptor - * - * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing - * (ACPI_FILE_WRITING). - * - ******************************************************************************/ - -ACPI_FILE -AcpiOsOpenFile ( - const char *Path, - UINT8 Modes) -{ - EFI_STATUS EfiStatus = EFI_SUCCESS; - UINT64 OpenModes; - EFI_FILE_HANDLE EfiFile = NULL; - CHAR16 *Path16 = NULL; - CHAR16 *Pos16; - const char *Pos; - INTN Count, i; - - - if (!Path) - { - return (NULL); - } - - /* Convert modes */ - - OpenModes = EFI_FILE_MODE_READ; - if (Modes & ACPI_FILE_WRITING) - { - OpenModes |= (EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE); - } - - /* Allocate path buffer */ - - Count = strlen (Path); - Path16 = ACPI_ALLOCATE_ZEROED ((Count + 1) * sizeof (CHAR16)); - if (!Path16) - { - EfiStatus = EFI_BAD_BUFFER_SIZE; - goto ErrorExit; - } - Pos = Path; - Pos16 = Path16; - while (*Pos == '/' || *Pos == '\\') - { - Pos++; - Count--; - } - for (i = 0; i < Count; i++) - { - if (*Pos == '/') - { - *Pos16++ = '\\'; - Pos++; - } - else - { - *Pos16++ = *Pos++; - } - } - *Pos16 = '\0'; - - EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Open, 5, - AcpiGbl_EfiCurrentVolume, &EfiFile, Path16, OpenModes, 0); - if (EFI_ERROR (EfiStatus)) - { - AcpiLogError ("EFI_FILE_HANDLE->Open() failure.\n"); - goto ErrorExit; - } - -ErrorExit: - - if (Path16) - { - ACPI_FREE (Path16); - } - - return ((ACPI_FILE) EfiFile); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsCloseFile - * - * PARAMETERS: File - File descriptor - * - * RETURN: None. - * - * DESCRIPTION: Close a file. - * - ******************************************************************************/ - -void -AcpiOsCloseFile ( - ACPI_FILE File) -{ - EFI_FILE_HANDLE EfiFile; - - - if (File == ACPI_FILE_OUT || - File == ACPI_FILE_ERR) - { - return; - } - EfiFile = (EFI_FILE_HANDLE) File; - (void) uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Close, 1, EfiFile); - - return; -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsReadFile - * - * PARAMETERS: File - File descriptor - * Buffer - Data buffer - * Size - Data block size - * Count - Number of data blocks - * - * RETURN: Size of successfully read buffer - * - * DESCRIPTION: Read from a file. - * - ******************************************************************************/ - -int -AcpiOsReadFile ( - ACPI_FILE File, - void *Buffer, - ACPI_SIZE Size, - ACPI_SIZE Count) -{ - int Length = -1; - EFI_FILE_HANDLE EfiFile; - UINTN ReadSize; - EFI_STATUS EfiStatus; - - - if (File == ACPI_FILE_OUT || - File == ACPI_FILE_ERR) - { - } - else - { - EfiFile = (EFI_FILE_HANDLE) File; - if (!EfiFile) - { - goto ErrorExit; - } - ReadSize = Size * Count; - - EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Read, 3, - EfiFile, &ReadSize, Buffer); - if (EFI_ERROR (EfiStatus)) - { - AcpiLogError ("EFI_FILE_HANDLE->Read() failure.\n"); - goto ErrorExit; - } - Length = ReadSize; - } - -ErrorExit: - - return (Length); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiEfiFlushFile - * - * PARAMETERS: File - File descriptor - * Begin - String with boundary - * End - Boundary of the string - * Pos - Current position - * FlushAll - Whether checking boundary before flushing - * - * RETURN: Updated position - * - * DESCRIPTION: Flush cached buffer to the file. - * - ******************************************************************************/ - -static CHAR16 * -AcpiEfiFlushFile ( - ACPI_FILE File, - CHAR16 *Begin, - CHAR16 *End, - CHAR16 *Pos, - BOOLEAN FlushAll) -{ - - if (FlushAll || Pos >= (End - 1)) - { - *Pos = 0; - uefi_call_wrapper (File->OutputString, 2, File, Begin); - Pos = Begin; - } - - return (Pos); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsWriteFile - * - * PARAMETERS: File - File descriptor - * Buffer - Data buffer - * Size - Data block size - * Count - Number of data blocks - * - * RETURN: Size of successfully written buffer - * - * DESCRIPTION: Write to a file. - * - ******************************************************************************/ - -int -AcpiOsWriteFile ( - ACPI_FILE File, - void *Buffer, - ACPI_SIZE Size, - ACPI_SIZE Count) -{ - int Length = -1; - CHAR16 String[ACPI_EFI_PRINT_LENGTH]; - const char *Ascii; - CHAR16 *End; - CHAR16 *Pos; - int i, j; - EFI_FILE_HANDLE EfiFile; - UINTN WriteSize; - EFI_STATUS EfiStatus; - - - if (File == ACPI_FILE_OUT || - File == ACPI_FILE_ERR) - { - Pos = String; - End = String + ACPI_EFI_PRINT_LENGTH - 1; - Ascii = ACPI_CAST_PTR (const char, Buffer); - Length = 0; - - for (j = 0; j < Count; j++) - { - for (i = 0; i < Size; i++) - { - if (*Ascii == '\n') - { - *Pos++ = '\r'; - Pos = AcpiEfiFlushFile (File, String, - End, Pos, FALSE); - } - *Pos++ = *Ascii++; - Length++; - Pos = AcpiEfiFlushFile (File, String, - End, Pos, FALSE); - } - } - Pos = AcpiEfiFlushFile (File, String, End, Pos, TRUE); - } - else - { - EfiFile = (EFI_FILE_HANDLE) File; - if (!EfiFile) - { - goto ErrorExit; - } - WriteSize = Size * Count; - - EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Write, 3, - EfiFile, &WriteSize, Buffer); - if (EFI_ERROR (EfiStatus)) - { - AcpiLogError ("EFI_FILE_HANDLE->Write() failure.\n"); - goto ErrorExit; - } - Length = WriteSize; - } - -ErrorExit: - - return (Length); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsGetFileOffset - * - * PARAMETERS: File - File descriptor - * - * RETURN: Size of current position - * - * DESCRIPTION: Get current file offset. - * - ******************************************************************************/ - -long -AcpiOsGetFileOffset ( - ACPI_FILE File) -{ - long Offset = -1; - - - return (Offset); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsSetFileOffset - * - * PARAMETERS: File - File descriptor - * Offset - File offset - * From - From begin/end of file - * - * RETURN: Status - * - * DESCRIPTION: Set current file offset. - * - ******************************************************************************/ - -ACPI_STATUS -AcpiOsSetFileOffset ( - ACPI_FILE File, - long Offset, - UINT8 From) -{ - - return (AE_SUPPORT); -} - - /****************************************************************************** * * FUNCTION: AcpiOsPrintf @@ -850,314 +469,3 @@ AcpiOsInitialize ( return (AE_OK); } - - -/****************************************************************************** - * - * FUNCTION: AcpiEfiArgify - * - * PARAMETERS: String - Pointer to command line argument strings - * which are seperated with spaces - * ArgcPtr - Return number of the arguments - * ArgvPtr - Return vector of the arguments - * - * RETURN: Status - * - * DESCRIPTION: Convert EFI arguments into C arguments. - * - *****************************************************************************/ - -static ACPI_STATUS -AcpiEfiArgify ( - char *String, - int *ArgcPtr, - char ***ArgvPtr) -{ - char *CopyBuffer; - int MaxArgc = *ArgcPtr; - int Argc = 0; - char **Argv = *ArgvPtr; - char *Arg; - BOOLEAN IsSingleQuote = FALSE; - BOOLEAN IsDoubleQuote = FALSE; - BOOLEAN IsEscape = FALSE; - - - if (String == NULL) - { - return (AE_BAD_PARAMETER); - } - - CopyBuffer = String; - - while (*String != '\0') - { - while (isspace (*String)) - { - *String++ = '\0'; - } - Arg = CopyBuffer; - while (*String != '\0') - { - if (isspace (*String) && - !IsSingleQuote && !IsDoubleQuote && !IsEscape) - { - *Arg++ = '\0'; - String++; - break; - } - if (IsEscape) - { - IsEscape = FALSE; - *Arg++ = *String; - } - else if (*String == '\\') - { - IsEscape = TRUE; - } - else if (IsSingleQuote) - { - if (*String == '\'') - { - IsSingleQuote = FALSE; - *Arg++ = '\0'; - } - else - { - *Arg++ = *String; - } - } - else if (IsDoubleQuote) - { - if (*String == '"') - { - IsDoubleQuote = FALSE; - *Arg = '\0'; - } - else - { - *Arg++ = *String; - } - } - else - { - if (*String == '\'') - { - IsSingleQuote = TRUE; - } - else if (*String == '"') - { - IsDoubleQuote = TRUE; - } - else - { - *Arg++ = *String; - } - } - String++; - } - if (Argv && Argc < MaxArgc) - { - Argv[Argc] = CopyBuffer; - } - Argc++; - CopyBuffer = Arg; - } - if (Argv && Argc < MaxArgc) - { - Argv[Argc] = NULL; - } - - *ArgcPtr = Argc; - *ArgvPtr = Argv; - - return ((MaxArgc < Argc) ? AE_NO_MEMORY : AE_OK); -} - - -/****************************************************************************** - * - * FUNCTION: AcpiEfiConvertArgcv - * - * PARAMETERS: LoadOptions - Pointer to the EFI options buffer, which - * is NULL terminated - * LoadOptionsSize - Size of the EFI options buffer - * ArgcPtr - Return number of the arguments - * ArgvPtr - Return vector of the arguments - * BufferPtr - Buffer to contain the argument strings - * - * RETURN: Status - * - * DESCRIPTION: Convert EFI arguments into C arguments. - * - *****************************************************************************/ - -static ACPI_STATUS -AcpiEfiConvertArgcv ( - CHAR16 *LoadOptions, - UINT32 LoadOptionsSize, - int *ArgcPtr, - char ***ArgvPtr, - char **BufferPtr) -{ - ACPI_STATUS Status = AE_OK; - UINT32 Count = LoadOptionsSize / sizeof (CHAR16); - UINT32 i; - CHAR16 *From; - char *To; - int Argc = 0; - char **Argv = NULL; - char *Buffer; - - - /* Prepare a buffer to contain the argument strings */ - - Buffer = ACPI_ALLOCATE_ZEROED (Count); - if (!Buffer) - { - Status = AE_NO_MEMORY; - goto ErrorExit; - } - -TryAgain: - - /* Extend the argument vector */ - - if (Argv) - { - ACPI_FREE (Argv); - Argv = NULL; - } - if (Argc > 0) - { - Argv = ACPI_ALLOCATE_ZEROED (sizeof (char *) * (Argc + 1)); - if (!Argv) - { - Status = AE_NO_MEMORY; - goto ErrorExit; - } - } - - /* - * Note: As AcpiEfiArgify() will modify the content of the buffer, so - * we need to restore it each time before invoking - * AcpiEfiArgify(). - */ - From = LoadOptions; - To = ACPI_CAST_PTR (char, Buffer); - for (i = 0; i < Count; i++) - { - *To++ = (char) *From++; - } - - /* - * The "Buffer" will contain NULL terminated strings after invoking - * AcpiEfiArgify(). The number of the strings are saved in Argc and the - * pointers of the strings are saved in Argv. - */ - Status = AcpiEfiArgify (Buffer, &Argc, &Argv); - if (ACPI_FAILURE (Status)) - { - if (Status == AE_NO_MEMORY) - { - goto TryAgain; - } - } - -ErrorExit: - - if (ACPI_FAILURE (Status)) - { - ACPI_FREE (Buffer); - ACPI_FREE (Argv); - } - else - { - *ArgcPtr = Argc; - *ArgvPtr = Argv; - *BufferPtr = Buffer; - } - return (Status); -} - - -/****************************************************************************** - * - * FUNCTION: efi_main - * - * PARAMETERS: Image - EFI image handle - * SystemTab - EFI system table - * - * RETURN: EFI Status - * - * DESCRIPTION: Entry point of EFI executable - * - *****************************************************************************/ - -EFI_STATUS -efi_main ( - EFI_HANDLE Image, - EFI_SYSTEM_TABLE *SystemTab) -{ - EFI_LOADED_IMAGE *Info; - EFI_STATUS EfiStatus = EFI_SUCCESS; - ACPI_STATUS Status; - int argc; - char **argv = NULL; - char *OptBuffer = NULL; - EFI_FILE_IO_INTERFACE *Volume = NULL; - - - /* Initialize global variables */ - - ST = SystemTab; - BS = SystemTab->BootServices; - - /* Retrieve image information */ - - EfiStatus = uefi_call_wrapper (BS->HandleProtocol, 3, - Image, &AcpiGbl_LoadedImageProtocol, ACPI_CAST_PTR (VOID, &Info)); - if (EFI_ERROR (EfiStatus)) - { - AcpiLogError ("EFI_BOOT_SERVICES->HandleProtocol(LoadedImageProtocol) failure.\n"); - return (EfiStatus); - } - - EfiStatus = uefi_call_wrapper (BS->HandleProtocol, 3, - Info->DeviceHandle, &AcpiGbl_FileSystemProtocol, (void **) &Volume); - if (EFI_ERROR (EfiStatus)) - { - AcpiLogError ("EFI_BOOT_SERVICES->HandleProtocol(FileSystemProtocol) failure.\n"); - return (EfiStatus); - } - EfiStatus = uefi_call_wrapper (Volume->OpenVolume, 2, - Volume, &AcpiGbl_EfiCurrentVolume); - if (EFI_ERROR (EfiStatus)) - { - AcpiLogError ("EFI_FILE_IO_INTERFACE->OpenVolume() failure.\n"); - return (EfiStatus); - } - - Status = AcpiEfiConvertArgcv (Info->LoadOptions, - Info->LoadOptionsSize, &argc, &argv, &OptBuffer); - if (ACPI_FAILURE (Status)) - { - EfiStatus = EFI_DEVICE_ERROR; - goto ErrorAlloc; - } - - acpi_main (argc, argv); - -ErrorAlloc: - - if (argv) - { - ACPI_FREE (argv); - } - if (OptBuffer) - { - ACPI_FREE (OptBuffer); - } - - return (EfiStatus); -} diff --git a/source/os_specific/service_layers/oslibcfs.c b/source/os_specific/service_layers/oslibcfs.c deleted file mode 100644 index 26c1a8fed..000000000 --- a/source/os_specific/service_layers/oslibcfs.c +++ /dev/null @@ -1,330 +0,0 @@ -/****************************************************************************** - * - * Module Name: oslibcfs - C library OSL for file I/O - * - *****************************************************************************/ - -/****************************************************************************** - * - * 1. Copyright Notice - * - * Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp. - * All rights reserved. - * - * 2. License - * - * 2.1. This is your license from Intel Corp. under its intellectual property - * rights. You may have additional license terms from the party that provided - * you this software, covering your right to use that party's intellectual - * property rights. - * - * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a - * copy of the source code appearing in this file ("Covered Code") an - * irrevocable, perpetual, worldwide license under Intel's copyrights in the - * base code distributed originally by Intel ("Original Intel Code") to copy, - * make derivatives, distribute, use and display any portion of the Covered - * Code in any form, with the right to sublicense such rights; and - * - * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent - * license (with the right to sublicense), under only those claims of Intel - * patents that are infringed by the Original Intel Code, to make, use, sell, - * offer to sell, and import the Covered Code and derivative works thereof - * solely to the minimum extent necessary to exercise the above copyright - * license, and in no event shall the patent license extend to any additions - * to or modifications of the Original Intel Code. No other license or right - * is granted directly or by implication, estoppel or otherwise; - * - * The above copyright and patent license is granted only if the following - * conditions are met: - * - * 3. Conditions - * - * 3.1. Redistribution of Source with Rights to Further Distribute Source. - * Redistribution of source code of any substantial portion of the Covered - * Code or modification with rights to further distribute source must include - * the above Copyright Notice, the above License, this list of Conditions, - * and the following Disclaimer and Export Compliance provision. In addition, - * Licensee must cause all Covered Code to which Licensee contributes to - * contain a file documenting the changes Licensee made to create that Covered - * Code and the date of any change. Licensee must include in that file the - * documentation of any changes made by any predecessor Licensee. Licensee - * must include a prominent statement that the modification is derived, - * directly or indirectly, from Original Intel Code. - * - * 3.2. Redistribution of Source with no Rights to Further Distribute Source. - * Redistribution of source code of any substantial portion of the Covered - * Code or modification without rights to further distribute source must - * include the following Disclaimer and Export Compliance provision in the - * documentation and/or other materials provided with distribution. In - * addition, Licensee may not authorize further sublicense of source of any - * portion of the Covered Code, and must include terms to the effect that the - * license from Licensee to its licensee is limited to the intellectual - * property embodied in the software Licensee provides to its licensee, and - * not to intellectual property embodied in modifications its licensee may - * make. - * - * 3.3. Redistribution of Executable. Redistribution in executable form of any - * substantial portion of the Covered Code or modification must reproduce the - * above Copyright Notice, and the following Disclaimer and Export Compliance - * provision in the documentation and/or other materials provided with the - * distribution. - * - * 3.4. Intel retains all right, title, and interest in and to the Original - * Intel Code. - * - * 3.5. Neither the name Intel nor any other trademark owned or controlled by - * Intel shall be used in advertising or otherwise to promote the sale, use or - * other dealings in products derived from or relating to the Covered Code - * without prior written authorization from Intel. - * - * 4. Disclaimer and Export Compliance - * - * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED - * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE - * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, - * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY - * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY - * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A - * PARTICULAR PURPOSE. - * - * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES - * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR - * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, - * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY - * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL - * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS - * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY - * LIMITED REMEDY. - * - * 4.3. Licensee shall not export, either directly or indirectly, any of this - * software or system incorporating such software without first obtaining any - * required license or other approval from the U. S. Department of Commerce or - * any other agency or department of the United States Government. In the - * event Licensee exports any such software from the United States or - * re-exports any such software from a foreign destination, Licensee shall - * ensure that the distribution and export/re-export of the software is in - * compliance with all laws, regulations, orders, or other restrictions of the - * U.S. Export Administration Regulations. Licensee agrees that neither it nor - * any of its subsidiaries will export/re-export any technical data, process, - * software, or service, directly or indirectly, to any country for which the - * United States government or any agency thereof requires an export license, - * other governmental approval, or letter of assurance, without first obtaining - * such license, approval or letter. - * - *****************************************************************************/ - -#include "acpi.h" -#include <stdio.h> -#include <stdarg.h> - -#define _COMPONENT ACPI_OS_SERVICES - ACPI_MODULE_NAME ("oslibcfs") - - -/******************************************************************************* - * - * FUNCTION: AcpiOsOpenFile - * - * PARAMETERS: Path - File path - * Modes - File operation type - * - * RETURN: File descriptor. - * - * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing - * (ACPI_FILE_WRITING). - * - ******************************************************************************/ - -ACPI_FILE -AcpiOsOpenFile ( - const char *Path, - UINT8 Modes) -{ - ACPI_FILE File; - UINT32 i = 0; - char ModesStr[4]; - - - if (Modes & ACPI_FILE_READING) - { - ModesStr[i++] = 'r'; - } - if (Modes & ACPI_FILE_WRITING) - { - ModesStr[i++] = 'w'; - } - - if (Modes & ACPI_FILE_BINARY) - { - ModesStr[i++] = 'b'; - } - - ModesStr[i++] = '\0'; - - File = fopen (Path, ModesStr); - if (!File) - { - perror ("Could not open file"); - } - - return (File); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsCloseFile - * - * PARAMETERS: File - An open file descriptor - * - * RETURN: None. - * - * DESCRIPTION: Close a file opened via AcpiOsOpenFile. - * - ******************************************************************************/ - -void -AcpiOsCloseFile ( - ACPI_FILE File) -{ - - fclose (File); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsReadFile - * - * PARAMETERS: File - An open file descriptor - * Buffer - Data buffer - * Size - Data block size - * Count - Number of data blocks - * - * RETURN: Number of bytes actually read. - * - * DESCRIPTION: Read from a file. - * - ******************************************************************************/ - -int -AcpiOsReadFile ( - ACPI_FILE File, - void *Buffer, - ACPI_SIZE Size, - ACPI_SIZE Count) -{ - int Length; - - - Length = fread (Buffer, Size, Count, File); - if (Length < 0) - { - perror ("Error reading file"); - } - - return (Length); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsWriteFile - * - * PARAMETERS: File - An open file descriptor - * Buffer - Data buffer - * Size - Data block size - * Count - Number of data blocks - * - * RETURN: Number of bytes actually written. - * - * DESCRIPTION: Write to a file. - * - ******************************************************************************/ - -int -AcpiOsWriteFile ( - ACPI_FILE File, - void *Buffer, - ACPI_SIZE Size, - ACPI_SIZE Count) -{ - int Length; - - - Length = fwrite (Buffer, Size, Count, File); - if (Length < 0) - { - perror ("Error writing file"); - } - - return (Length); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsGetFileOffset - * - * PARAMETERS: File - An open file descriptor - * - * RETURN: Current file pointer position. - * - * DESCRIPTION: Get current file offset. - * - ******************************************************************************/ - -long -AcpiOsGetFileOffset ( - ACPI_FILE File) -{ - long Offset; - - - Offset = ftell (File); - return (Offset); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiOsSetFileOffset - * - * PARAMETERS: File - An open file descriptor - * Offset - New file offset - * From - From begin/end of file - * - * RETURN: Status - * - * DESCRIPTION: Set current file offset. - * - ******************************************************************************/ - -ACPI_STATUS -AcpiOsSetFileOffset ( - ACPI_FILE File, - long Offset, - UINT8 From) -{ - int Ret = 0; - - - if (From == ACPI_FILE_BEGIN) - { - Ret = fseek (File, Offset, SEEK_SET); - } - - if (From == ACPI_FILE_END) - { - Ret = fseek (File, Offset, SEEK_END); - } - - if (Ret < 0) - { - return (AE_ERROR); - } - else - { - return (AE_OK); - } -} diff --git a/source/tools/acpidump/apdump.c b/source/tools/acpidump/apdump.c index bb5bd545b..68065d733 100644 --- a/source/tools/acpidump/apdump.c +++ b/source/tools/acpidump/apdump.c @@ -148,7 +148,7 @@ ApIsValidHeader ( if (!AcpiUtValidNameseg (Table->Signature)) { - AcpiLogError ("Table signature (0x%8.8X) is invalid\n", + fprintf (stderr, "Table signature (0x%8.8X) is invalid\n", *(UINT32 *) Table->Signature); return (FALSE); } @@ -157,7 +157,7 @@ ApIsValidHeader ( if (Table->Length < sizeof (ACPI_TABLE_HEADER)) { - AcpiLogError ("Table length (0x%8.8X) is invalid\n", + fprintf (stderr, "Table length (0x%8.8X) is invalid\n", Table->Length); return (FALSE); } @@ -203,7 +203,7 @@ ApIsValidChecksum ( if (ACPI_FAILURE (Status)) { - AcpiLogError ("%4.4s: Warning: wrong checksum in table\n", + fprintf (stderr, "%4.4s: Warning: wrong checksum in table\n", Table->Signature); } @@ -346,13 +346,13 @@ ApDumpAllTables ( } else if (i == 0) { - AcpiLogError ("Could not get ACPI tables, %s\n", + fprintf (stderr, "Could not get ACPI tables, %s\n", AcpiFormatException (Status)); return (-1); } else { - AcpiLogError ("Could not get ACPI table at index %u, %s\n", + fprintf (stderr, "Could not get ACPI table at index %u, %s\n", i, AcpiFormatException (Status)); continue; } @@ -402,7 +402,7 @@ ApDumpTableByAddress ( ACPI_MAX64_BYTE_WIDTH, &LongAddress); if (ACPI_FAILURE (Status)) { - AcpiLogError ("%s: Could not convert to a physical address\n", + fprintf (stderr, "%s: Could not convert to a physical address\n", AsciiAddress); return (-1); } @@ -411,7 +411,7 @@ ApDumpTableByAddress ( Status = AcpiOsGetTableByAddress (Address, &Table); if (ACPI_FAILURE (Status)) { - AcpiLogError ("Could not get table at 0x%8.8X%8.8X, %s\n", + fprintf (stderr, "Could not get table at 0x%8.8X%8.8X, %s\n", ACPI_FORMAT_UINT64 (Address), AcpiFormatException (Status)); return (-1); @@ -450,7 +450,7 @@ ApDumpTableByName ( if (strlen (Signature) != ACPI_NAME_SIZE) { - AcpiLogError ( + fprintf (stderr, "Invalid table signature [%s]: must be exactly 4 characters\n", Signature); return (-1); @@ -487,7 +487,7 @@ ApDumpTableByName ( return (0); } - AcpiLogError ( + fprintf (stderr, "Could not get ACPI table with signature [%s], %s\n", LocalSignature, AcpiFormatException (Status)); return (-1); @@ -539,7 +539,7 @@ ApDumpTableFromFile ( if (!AcpiUtValidNameseg (Table->Signature)) { - AcpiLogError ( + fprintf (stderr, "No valid ACPI signature was found in input file %s\n", Pathname); } @@ -548,7 +548,7 @@ ApDumpTableFromFile ( if (Table->Length > FileSize) { - AcpiLogError ( + fprintf (stderr, "Table length (0x%X) is too large for input file (0x%X) %s\n", Table->Length, FileSize, Pathname); goto Exit; @@ -556,7 +556,7 @@ ApDumpTableFromFile ( if (Gbl_VerboseMode) { - AcpiLogError ( + fprintf (stderr, "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", Pathname, Table->Signature, FileSize, FileSize); } diff --git a/source/tools/acpidump/apfiles.c b/source/tools/acpidump/apfiles.c index c01fc6988..b7583ea50 100644 --- a/source/tools/acpidump/apfiles.c +++ b/source/tools/acpidump/apfiles.c @@ -145,7 +145,7 @@ ApIsExistingFile ( if (!stat (Pathname, &StatInfo)) { - AcpiLogError ("Target path already exists, overwrite? [y|n] "); + fprintf (stderr, "Target path already exists, overwrite? [y|n] "); if (getchar () != 'y') { @@ -187,10 +187,10 @@ ApOpenOutputFile ( /* Point stdout to the file */ - File = AcpiOsOpenFile (Pathname, ACPI_FILE_WRITING); + File = fopen (Pathname, "w"); if (!File) { - AcpiLogError ("Could not open output file: %s\n", Pathname); + fprintf (stderr, "Could not open output file: %s\n", Pathname); return (-1); } @@ -261,30 +261,29 @@ ApWriteToBinaryFile ( if (Gbl_VerboseMode) { - AcpiLogError ( + fprintf (stderr, "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 = AcpiOsOpenFile (Filename, - ACPI_FILE_WRITING | ACPI_FILE_BINARY); + File = fopen (Filename, "wb"); if (!File) { - AcpiLogError ("Could not open output file: %s\n", Filename); + fprintf (stderr, "Could not open output file: %s\n", Filename); return (-1); } - Actual = AcpiOsWriteFile (File, Table, 1, TableLength); + Actual = fwrite (Table, 1, TableLength, File); if (Actual != TableLength) { - AcpiLogError ("Error writing binary output file: %s\n", Filename); - AcpiOsCloseFile (File); + fprintf (stderr, "Error writing binary output file: %s\n", Filename); + fclose (File); return (-1); } - AcpiOsCloseFile (File); + fclose (File); return (0); } @@ -315,10 +314,10 @@ ApGetTableFromFile ( /* Must use binary mode */ - File = AcpiOsOpenFile (Pathname, ACPI_FILE_READING | ACPI_FILE_BINARY); + File = fopen (Pathname, "rb"); if (!File) { - AcpiLogError ("Could not open input file: %s\n", Pathname); + fprintf (stderr, "Could not open input file: %s\n", Pathname); return (NULL); } @@ -327,7 +326,7 @@ ApGetTableFromFile ( FileSize = CmGetFileSize (File); if (FileSize == ACPI_UINT32_MAX) { - AcpiLogError ( + fprintf (stderr, "Could not get input file size: %s\n", Pathname); goto Cleanup; } @@ -337,18 +336,17 @@ ApGetTableFromFile ( Buffer = ACPI_ALLOCATE_ZEROED (FileSize); if (!Buffer) { - AcpiLogError ( + fprintf (stderr, "Could not allocate file buffer of size: %u\n", FileSize); goto Cleanup; } /* Read the entire file */ - Actual = AcpiOsReadFile (File, Buffer, 1, FileSize); + Actual = fread (Buffer, 1, FileSize, File); if (Actual != FileSize) { - AcpiLogError ( - "Could not read input file: %s\n", Pathname); + fprintf (stderr, "Could not read input file: %s\n", Pathname); ACPI_FREE (Buffer); Buffer = NULL; goto Cleanup; @@ -357,6 +355,6 @@ ApGetTableFromFile ( *OutFileSize = FileSize; Cleanup: - AcpiOsCloseFile (File); + fclose (File); return (Buffer); } diff --git a/source/tools/acpidump/apmain.c b/source/tools/acpidump/apmain.c index a897aedde..88630c94e 100644 --- a/source/tools/acpidump/apmain.c +++ b/source/tools/acpidump/apmain.c @@ -232,7 +232,7 @@ ApInsertAction ( CurrentAction++; if (CurrentAction > AP_MAX_ACTIONS) { - AcpiLogError ("Too many table options (max %u)\n", AP_MAX_ACTIONS); + fprintf (stderr, "Too many table options (max %u)\n", AP_MAX_ACTIONS); return (-1); } @@ -286,7 +286,7 @@ ApDoOptions ( } else { - AcpiLogError ("%s: Cannot handle this switch, please use on|off\n", + fprintf (stderr, "%s: Cannot handle this switch, please use on|off\n", AcpiGbl_Optarg); return (-1); } @@ -312,7 +312,7 @@ ApDoOptions ( ACPI_MAX64_BYTE_WIDTH, &Gbl_RsdpBase); if (ACPI_FAILURE (Status)) { - AcpiLogError ("%s: Could not convert to a physical address\n", + fprintf (stderr, "%s: Could not convert to a physical address\n", AcpiGbl_Optarg); return (-1); } @@ -343,7 +343,7 @@ ApDoOptions ( case 'z': /* Verbose mode */ Gbl_VerboseMode = TRUE; - AcpiLogError (ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); + fprintf (stderr, ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); continue; /* @@ -469,7 +469,7 @@ acpi_main ( default: - AcpiLogError ("Internal error, invalid action: 0x%X\n", + fprintf (stderr, "Internal error, invalid action: 0x%X\n", Action->ToBeDone); return (-1); } @@ -487,11 +487,11 @@ acpi_main ( /* Summary for the output file */ FileSize = CmGetFileSize (Gbl_OutputFile); - AcpiLogError ("Output file %s contains 0x%X (%u) bytes\n\n", + fprintf (stderr, "Output file %s contains 0x%X (%u) bytes\n\n", Gbl_OutputFilename, FileSize, FileSize); } - AcpiOsCloseFile (Gbl_OutputFile); + fclose (Gbl_OutputFile); } return (Status); diff --git a/source/tools/acpiexec/aeinitfile.c b/source/tools/acpiexec/aeinitfile.c index 57c20dce0..b1b60cd0c 100644 --- a/source/tools/acpiexec/aeinitfile.c +++ b/source/tools/acpiexec/aeinitfile.c @@ -158,7 +158,8 @@ AeOpenInitializationFile ( InitFile = fopen (Filename, "r"); if (!InitFile) { - perror ("Could not open initialization file"); + fprintf (stderr, + "Could not open initialization file: %s\n", Filename); return (-1); } |