Standard Libraries for EDK II.
This set of three packages: AppPkg, StdLib, StdLibPrivateInternalFiles; contains the implementation of libraries based upon non-UEFI standards such as ISO/IEC-9899, the library portion of the C Language Standard, POSIX, etc. AppPkg contains applications that make use of the standard libraries defined in the StdLib Package. StdLib contains header (include) files and the implementations of the standard libraries. StdLibPrivateInternalFiles contains files for the exclusive use of the library implementations in StdLib. These files should never be directly referenced from applications or other code. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11600 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
393
StdLib/LibC/Uefi/Console.c
Normal file
393
StdLib/LibC/Uefi/Console.c
Normal file
@@ -0,0 +1,393 @@
|
||||
/** @file
|
||||
File abstractions of the console.
|
||||
|
||||
Manipulates EFI_FILE_PROTOCOL abstractions for stdin, stdout, stderr.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials are licensed and made available under
|
||||
the terms and conditions of the BSD License that accompanies this distribution.
|
||||
The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
#include <Uefi.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
|
||||
#include <LibConfig.h>
|
||||
#include <sys/EfiCdefs.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <MainData.h>
|
||||
#include <Efi/Console.h>
|
||||
|
||||
static const CHAR16 * stdioNames[NUM_SPECIAL] = {
|
||||
L"stdin:", L"stdout:", L"stderr:"
|
||||
};
|
||||
static const int stdioFlags[NUM_SPECIAL] = {
|
||||
O_RDONLY, // stdin
|
||||
O_WRONLY, // stdout
|
||||
O_WRONLY // stderr
|
||||
};
|
||||
|
||||
static const int stdioMode[NUM_SPECIAL] = {
|
||||
0444, // stdin
|
||||
0222, // stdout
|
||||
0222 // stderr
|
||||
};
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConClose(
|
||||
IN EFI_FILE_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
ConInstance *Stream;
|
||||
|
||||
Stream = BASE_CR(This, ConInstance, Abstraction);
|
||||
// Quick check to see if Stream looks reasonable
|
||||
if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb'
|
||||
return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer
|
||||
}
|
||||
// Nothing to Flush.
|
||||
// Mark the Stream as closed.
|
||||
Stream->Dev = NULL;
|
||||
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConDelete(
|
||||
IN EFI_FILE_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConRead(
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN OUT UINTN *BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto;
|
||||
ConInstance *Stream;
|
||||
CHAR16 *OutPtr;
|
||||
EFI_INPUT_KEY Key;
|
||||
UINTN NumChar;
|
||||
UINTN Edex;
|
||||
EFI_STATUS Status;
|
||||
UINTN i;
|
||||
|
||||
Stream = BASE_CR(This, ConInstance, Abstraction);
|
||||
// Quick check to see if Stream looks reasonable
|
||||
if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb'
|
||||
return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer
|
||||
}
|
||||
if(Stream->Dev == NULL) {
|
||||
// Can't read from an unopened Stream
|
||||
return RETURN_DEVICE_ERROR;
|
||||
}
|
||||
if(Stream != &gMD->StdIo[0]) {
|
||||
// Read only valid for stdin
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
// It looks like things are OK for trying to read
|
||||
// We will accumulate *BufferSize characters or until we encounter
|
||||
// an "activation" character. Currently any control character.
|
||||
Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
|
||||
OutPtr = Buffer;
|
||||
NumChar = (*BufferSize - 1) / sizeof(CHAR16);
|
||||
i = 0;
|
||||
do {
|
||||
Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);
|
||||
if(Status != EFI_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
Status = Proto->ReadKeyStroke(Proto, &Key);
|
||||
if(Status != EFI_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
if(Key.ScanCode == SCAN_NULL) {
|
||||
*OutPtr++ = Key.UnicodeChar;
|
||||
++i;
|
||||
}
|
||||
if(Key.UnicodeChar < 0x0020) { // If a control character, or a scan code
|
||||
break;
|
||||
}
|
||||
} while(i < NumChar);
|
||||
*BufferSize = i * sizeof(CHAR16);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* Write a NULL terminated WCS to the EFI console.
|
||||
|
||||
@param[in,out] BufferSize Number of bytes in Buffer. Set to zero if
|
||||
the string couldn't be displayed.
|
||||
@parem[in] Buffer The WCS string to be displayed
|
||||
|
||||
*/
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConWrite(
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN OUT UINTN *BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
|
||||
ConInstance *Stream;
|
||||
CHAR16 *MyBuf;
|
||||
UINTN NumChar;
|
||||
|
||||
Stream = BASE_CR(This, ConInstance, Abstraction);
|
||||
// Quick check to see if Stream looks reasonable
|
||||
if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb'
|
||||
return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer
|
||||
}
|
||||
if(Stream->Dev == NULL) {
|
||||
// Can't write to an unopened Stream
|
||||
return RETURN_DEVICE_ERROR;
|
||||
}
|
||||
if(Stream == &gMD->StdIo[0]) {
|
||||
// Write is not valid for stdin
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
// Everything is OK to do the write.
|
||||
Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
|
||||
MyBuf = (CHAR16 *)Buffer;
|
||||
NumChar = *BufferSize;
|
||||
|
||||
// Send MyBuf to the console
|
||||
Status = Proto->OutputString( Proto, MyBuf);
|
||||
// Depending on status, update BufferSize and return
|
||||
if(Status != EFI_SUCCESS) {
|
||||
*BufferSize = 0; // We don't really know how many characters made it out
|
||||
}
|
||||
else {
|
||||
*BufferSize = NumChar;
|
||||
Stream->NumWritten += NumChar;
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConGetPosition(
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
OUT UINT64 *Position
|
||||
)
|
||||
{
|
||||
ConInstance *Stream;
|
||||
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
|
||||
XYoffset CursorPos;
|
||||
|
||||
Stream = BASE_CR(This, ConInstance, Abstraction);
|
||||
// Quick check to see if Stream looks reasonable
|
||||
if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb'
|
||||
return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer
|
||||
}
|
||||
if(Stream == &gMD->StdIo[0]) {
|
||||
// This is stdin
|
||||
*Position = Stream->NumRead;
|
||||
}
|
||||
else {
|
||||
Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
|
||||
CursorPos.XYpos.Column = (UINT32)Proto->Mode->CursorColumn;
|
||||
CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow;
|
||||
*Position = CursorPos.Offset;
|
||||
}
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConSetPosition(
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN UINT64 Position
|
||||
)
|
||||
{
|
||||
ConInstance *Stream;
|
||||
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
|
||||
XYoffset CursorPos;
|
||||
|
||||
Stream = BASE_CR(This, ConInstance, Abstraction);
|
||||
// Quick check to see if Stream looks reasonable
|
||||
if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb'
|
||||
return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer
|
||||
}
|
||||
if(Stream->Dev == NULL) {
|
||||
// Can't write to an unopened Stream
|
||||
return RETURN_DEVICE_ERROR;
|
||||
}
|
||||
if(Stream == &gMD->StdIo[0]) {
|
||||
// Seek is not valid for stdin
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
// Everything is OK to do the final verification and "seek".
|
||||
Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
|
||||
CursorPos.Offset = Position;
|
||||
|
||||
return Proto->SetCursorPosition(Proto,
|
||||
(INTN)CursorPos.XYpos.Column,
|
||||
(INTN)CursorPos.XYpos.Row);
|
||||
}
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConGetInfo(
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN EFI_GUID *InformationType,
|
||||
IN OUT UINTN *BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
EFI_FILE_INFO *InfoBuf;
|
||||
ConInstance *Stream;
|
||||
|
||||
Stream = BASE_CR(This, ConInstance, Abstraction);
|
||||
// Quick check to see if Stream looks reasonable
|
||||
if((Stream->Cookie != 0x62416F49) || // Cookie == 'IoAb'
|
||||
(Buffer == NULL))
|
||||
{
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
if(*BufferSize < sizeof(EFI_FILE_INFO)) {
|
||||
*BufferSize = sizeof(EFI_FILE_INFO);
|
||||
return RETURN_BUFFER_TOO_SMALL;
|
||||
}
|
||||
// All of our parameters are correct, so fill in the information.
|
||||
(void) ZeroMem(Buffer, sizeof(EFI_FILE_INFO));
|
||||
InfoBuf = (EFI_FILE_INFO *)Buffer;
|
||||
InfoBuf->Size = sizeof(EFI_FILE_INFO);
|
||||
InfoBuf->FileSize = 1;
|
||||
InfoBuf->PhysicalSize = 1;
|
||||
*BufferSize = sizeof(EFI_FILE_INFO);
|
||||
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConSetInfo(
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN EFI_GUID *InformationType,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConFlush(
|
||||
IN EFI_FILE_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConOpen(
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
OUT EFI_FILE_PROTOCOL **NewHandle,
|
||||
IN CHAR16 *FileName,
|
||||
IN UINT64 OpenMode, // Ignored
|
||||
IN UINT64 Attributes // Ignored
|
||||
)
|
||||
{
|
||||
ConInstance *Stream;
|
||||
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
|
||||
UINTN Columns;
|
||||
UINTN Rows;
|
||||
int i;
|
||||
|
||||
if((NewHandle == NULL) ||
|
||||
(FileName == NULL))
|
||||
{
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
// Process FileName
|
||||
for(i = 0; i < NUM_SPECIAL; ++i) {
|
||||
if(StrCmp( stdioNames[i], FileName) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i >= NUM_SPECIAL) {
|
||||
return RETURN_NO_MAPPING;
|
||||
}
|
||||
// Get pointer to instance.
|
||||
Stream = &gMD->StdIo[i];
|
||||
if(Stream->Dev == NULL) {
|
||||
// If this stream has been closed, then
|
||||
// Initialize instance.
|
||||
Stream->Cookie = 0x62416F49;
|
||||
Stream->NumRead = 0;
|
||||
Stream->NumWritten = 0;
|
||||
switch(i) {
|
||||
case 0:
|
||||
Stream->Dev = gST->ConIn;
|
||||
break;
|
||||
case 1:
|
||||
Stream->Dev = gST->ConOut;
|
||||
break;
|
||||
case 2:
|
||||
if(gST->StdErr == NULL) {
|
||||
Stream->Dev = gST->ConOut;
|
||||
}
|
||||
else {
|
||||
Stream->Dev = gST->StdErr;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return RETURN_VOLUME_CORRUPTED; // This is a "should never happen" case.
|
||||
}
|
||||
Stream->Abstraction.Revision = 0x00010000;
|
||||
Stream->Abstraction.Open = &ConOpen;
|
||||
Stream->Abstraction.Close = &ConClose;
|
||||
Stream->Abstraction.Delete = &ConDelete;
|
||||
Stream->Abstraction.Read = &ConRead;
|
||||
Stream->Abstraction.Write = &ConWrite;
|
||||
Stream->Abstraction.GetPosition = &ConGetPosition;
|
||||
Stream->Abstraction.SetPosition = &ConSetPosition;
|
||||
Stream->Abstraction.GetInfo = &ConGetInfo;
|
||||
Stream->Abstraction.SetInfo = &ConSetInfo;
|
||||
Stream->Abstraction.Flush = &ConFlush;
|
||||
// Get additional information if this is an Output stream
|
||||
if(i != 0) {
|
||||
Proto = Stream->Dev;
|
||||
Stream->ConOutMode = Proto->Mode->Mode;
|
||||
if( Proto->QueryMode(Proto, Stream->ConOutMode, &Columns, &Rows) != RETURN_SUCCESS) {
|
||||
Stream->Dev = NULL; // Mark this stream as closed
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
Stream->MaxConXY.XYpos.Column = (UINT32)Columns;
|
||||
Stream->MaxConXY.XYpos.Row = (UINT32)Rows;
|
||||
}
|
||||
}
|
||||
// Save NewHandle and return.
|
||||
*NewHandle = &Stream->Abstraction;
|
||||
|
||||
return RETURN_SUCCESS;
|
||||
}
|
1198
StdLib/LibC/Uefi/SysCalls.c
Normal file
1198
StdLib/LibC/Uefi/SysCalls.c
Normal file
File diff suppressed because it is too large
Load Diff
37
StdLib/LibC/Uefi/SysEfi.h
Normal file
37
StdLib/LibC/Uefi/SysEfi.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/** @file
|
||||
Declarations local to the Uefi SysCalls module of the Standard C Library.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials are licensed and made available under
|
||||
the terms and conditions of the BSD License that accompanies this distribution.
|
||||
The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
#ifndef _SYSEFI_H
|
||||
#define _SYSEFI_H
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
#define EFI_FILE_MODE_MASK ( EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE )
|
||||
#define OMODE_MASK 0xFFFF00UL
|
||||
#define OMODE_SHIFT 8
|
||||
|
||||
#define S_ACC_READ ( S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH )
|
||||
#define S_ACC_WRITE ( S_IWUSR | S_IWGRP | S_IWOTH )
|
||||
#define S_ACC_MASK ( S_IRWXU | S_IRWXG | S_IRWXO )
|
||||
|
||||
UINT64
|
||||
Oflags2EFI( int oflags);
|
||||
|
||||
UINT64
|
||||
Omode2EFI( int mode);
|
||||
|
||||
/* Converts the first several EFI status values into the appropriate errno value.
|
||||
*/
|
||||
int
|
||||
EFI2errno( RETURN_STATUS Status);
|
||||
|
||||
#endif /* _SYSEFI_H */
|
49
StdLib/LibC/Uefi/Uefi.inf
Normal file
49
StdLib/LibC/Uefi/Uefi.inf
Normal file
@@ -0,0 +1,49 @@
|
||||
## @file
|
||||
# Standard C library: UEFI "system calls".
|
||||
#
|
||||
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php.
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = LibUefi
|
||||
FILE_GUID = 39356e02-26bf-4cfb-9564-378ce25e702f
|
||||
MODULE_TYPE = UEFI_APPLICATION
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = LibUefi
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF
|
||||
#
|
||||
|
||||
[Sources]
|
||||
SysCalls.c
|
||||
Xform.c
|
||||
Console.c
|
||||
|
||||
[Packages]
|
||||
StdLib/StdLib.dec
|
||||
StdLibPrivateInternalFiles/DoNotUse.dec
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
UefiLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
MemoryAllocationLib
|
||||
UefiBootServicesTableLib
|
||||
ShellLib
|
||||
LibC
|
||||
LibLocale
|
||||
LibString
|
||||
LibTime
|
173
StdLib/LibC/Uefi/Xform.c
Normal file
173
StdLib/LibC/Uefi/Xform.c
Normal file
@@ -0,0 +1,173 @@
|
||||
/** @file
|
||||
Value transformations between stdio and the UEFI environment.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials are licensed and made available under
|
||||
the terms and conditions of the BSD License that accompanies this distribution.
|
||||
The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
#include <Uefi.h>
|
||||
|
||||
#include <LibConfig.h>
|
||||
#include <sys/EfiCdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "SysEfi.h"
|
||||
|
||||
/** Translate the Open flags into a Uefi Open Modes value.
|
||||
|
||||
The Open Flags are:
|
||||
O_RDONLY, O_WRONLY, O_RDWR // Pick only one
|
||||
|
||||
O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL // ORed with one of the previous
|
||||
|
||||
The UEFI Open modes are:
|
||||
// ******************************************************
|
||||
// Open Modes
|
||||
// ******************************************************
|
||||
#define EFI_FILE_MODE_READ 0x0000000000000001
|
||||
#define EFI_FILE_MODE_WRITE 0x0000000000000002
|
||||
#define EFI_FILE_MODE_CREATE 0x8000000000000000
|
||||
|
||||
|
||||
*/
|
||||
UINT64
|
||||
Oflags2EFI( int oflags )
|
||||
{
|
||||
UINT64 flags;
|
||||
|
||||
// Build the Open Modes
|
||||
flags = (UINT64)((oflags & O_ACCMODE) + 1); // Handle the Read/Write flags
|
||||
if(oflags & (O_CREAT | O_TRUNC)) { // Now add the Create flag.
|
||||
// Also added if O_TRUNC set since we will need to create a new file.
|
||||
// We just set the flags here since the only valid EFI mode with create
|
||||
// is Read+Write+Create.
|
||||
flags = EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
/* Transform the permissions flags from the open() call into the
|
||||
Attributes bits needed by UEFI.
|
||||
|
||||
The UEFI File attributes are:
|
||||
// ******************************************************
|
||||
// File Attributes
|
||||
// ******************************************************
|
||||
#define EFI_FILE_READ_ONLY 0x0000000000000001
|
||||
#define EFI_FILE_HIDDEN 0x0000000000000002
|
||||
#define EFI_FILE_SYSTEM 0x0000000000000004
|
||||
#define EFI_FILE_RESERVED 0x0000000000000008
|
||||
#define EFI_FILE_DIRECTORY 0x0000000000000010
|
||||
#define EFI_FILE_ARCHIVE 0x0000000000000020
|
||||
#define EFI_FILE_VALID_ATTR 0x0000000000000037
|
||||
|
||||
The input permission flags consist of two groups:
|
||||
( S_IRUSR | S_IRGRP | S_IROTH ) -- S_ACC_READ
|
||||
( S_IWUSR | S_IWGRP | S_IWOTH ) -- S_ACC_WRITE
|
||||
|
||||
The only thing we can set, at this point, is whether or not
|
||||
this is a SYSTEM file. If the group and other bits are
|
||||
zero and the user bits are non-zero then set SYSTEM. Otherwise
|
||||
the attributes are zero.
|
||||
|
||||
The attributes can be set later using fcntl().
|
||||
*/
|
||||
UINT64
|
||||
Omode2EFI( int mode)
|
||||
{
|
||||
UINT64 flags = 0;
|
||||
|
||||
if((mode & (S_IRWXG | S_IRWXO)) == 0) {
|
||||
if((mode & S_IRWXU) != 0) {
|
||||
// Only user permissions so set system
|
||||
flags = EFI_FILE_SYSTEM;
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
/* Converts the first several EFI status values into the appropriate errno value.
|
||||
*/
|
||||
int
|
||||
EFI2errno( RETURN_STATUS Status)
|
||||
{
|
||||
int retval;
|
||||
|
||||
switch(Status) {
|
||||
case RETURN_SUCCESS:
|
||||
retval = 0;
|
||||
break;
|
||||
case RETURN_INVALID_PARAMETER:
|
||||
retval = EINVAL;
|
||||
break;
|
||||
case RETURN_UNSUPPORTED:
|
||||
retval = ENODEV;
|
||||
break;
|
||||
case RETURN_BAD_BUFFER_SIZE:
|
||||
case RETURN_BUFFER_TOO_SMALL:
|
||||
retval = EBUFSIZE;
|
||||
break;
|
||||
case RETURN_NOT_READY:
|
||||
retval = EBUSY;
|
||||
break;
|
||||
case RETURN_WRITE_PROTECTED:
|
||||
retval = EROFS;
|
||||
break;
|
||||
case RETURN_OUT_OF_RESOURCES: // May be overridden by specific functions
|
||||
retval = ENOMEM;
|
||||
break;
|
||||
case RETURN_VOLUME_FULL:
|
||||
retval = ENOSPC;
|
||||
break;
|
||||
case RETURN_NOT_FOUND:
|
||||
case RETURN_NO_MAPPING:
|
||||
retval = ENOENT;
|
||||
break;
|
||||
case RETURN_TIMEOUT:
|
||||
retval = ETIMEDOUT;
|
||||
break;
|
||||
case RETURN_NOT_STARTED:
|
||||
retval = EAGAIN;
|
||||
break;
|
||||
case RETURN_ALREADY_STARTED:
|
||||
retval = EALREADY;
|
||||
break;
|
||||
case RETURN_ABORTED:
|
||||
retval = EINTR;
|
||||
break;
|
||||
case RETURN_ICMP_ERROR:
|
||||
case RETURN_TFTP_ERROR:
|
||||
case RETURN_PROTOCOL_ERROR:
|
||||
retval = EPROTO;
|
||||
break;
|
||||
case RETURN_INCOMPATIBLE_VERSION:
|
||||
retval = EPERM;
|
||||
break;
|
||||
case RETURN_ACCESS_DENIED:
|
||||
case RETURN_SECURITY_VIOLATION:
|
||||
retval = EACCES;
|
||||
break;
|
||||
/* case RETURN_LOAD_ERROR:
|
||||
case RETURN_DEVICE_ERROR:
|
||||
case RETURN_VOLUME_CORRUPTED:
|
||||
case RETURN_NO_MEDIA:
|
||||
case RETURN_MEDIA_CHANGED:
|
||||
case RETURN_NO_RESPONSE:
|
||||
case RETURN_CRC_ERROR:
|
||||
case RETURN_END_OF_MEDIA:
|
||||
case RETURN_END_OF_FILE:
|
||||
case RETURN_INVALID_LANGUAGE:
|
||||
*/
|
||||
default:
|
||||
retval = EIO;
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
Reference in New Issue
Block a user