summaryrefslogtreecommitdiff
path: root/StdLib/LibC/Uefi
diff options
context:
space:
mode:
Diffstat (limited to 'StdLib/LibC/Uefi')
-rw-r--r--StdLib/LibC/Uefi/Devices/Console/daConsole.c765
-rw-r--r--StdLib/LibC/Uefi/Devices/UefiShell/daShell.c856
-rw-r--r--StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c158
-rw-r--r--StdLib/LibC/Uefi/Devices/Utility/DevSearch.c112
-rw-r--r--StdLib/LibC/Uefi/Devices/Utility/Path.c431
-rw-r--r--StdLib/LibC/Uefi/Devices/daConsole.inf52
-rw-r--r--StdLib/LibC/Uefi/Devices/daShell.inf52
-rw-r--r--StdLib/LibC/Uefi/Devices/daUtility.inf44
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/CanonRead.c167
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/IIO.c373
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/IIO.inf51
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/IIOecho.c141
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h33
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c290
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/IIOutilities.h129
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/IIOwrite.c207
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c88
-rw-r--r--StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c285
-rw-r--r--StdLib/LibC/Uefi/StubFunctions.c92
-rw-r--r--StdLib/LibC/Uefi/SysCalls.c1437
-rw-r--r--StdLib/LibC/Uefi/Uefi.inf53
-rw-r--r--StdLib/LibC/Uefi/Xform.c191
-rw-r--r--StdLib/LibC/Uefi/compat.c843
-rw-r--r--StdLib/LibC/Uefi/select.c256
-rw-r--r--StdLib/LibC/Uefi/writev.c144
25 files changed, 0 insertions, 7250 deletions
diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
deleted file mode 100644
index d926a0c56e..0000000000
--- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c
+++ /dev/null
@@ -1,765 +0,0 @@
-/** @file
- Abstract device driver for the UEFI Console.
-
- Manipulates abstractions for stdin, stdout, stderr.
-
- This device is a WIDE device and this driver returns WIDE
- characters. It this the responsibility of the caller to convert between
- narrow and wide characters in order to perform the desired operations.
-
- The devices status as a wide device is indicatd by _S_IWTTY being set in
- f_iflags.
-
- Copyright (c) 2010 - 2014, 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/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/DebugLib.h>
-#include <Protocol/SimpleTextIn.h>
-#include <Protocol/SimpleTextOut.h>
-
-#include <LibConfig.h>
-
-#include <errno.h>
-#include <wctype.h>
-#include <wchar.h>
-#include <stdarg.h>
-#include <sys/fcntl.h>
-#include <unistd.h>
-#include <sys/termios.h>
-#include <kfile.h>
-#include <Device/Device.h>
-#include <Device/IIO.h>
-#include <MainData.h>
-
-static const CHAR16* const
-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 DeviceNode *ConNode[NUM_SPECIAL];
-static ConInstance *ConInstanceList;
-
-static cIIO *IIO;
-
-/* Flags settable by Ioctl */
-static BOOLEAN TtyCooked;
-static BOOLEAN TtyEcho;
-
-/** Convert string from MBCS to WCS and translate \n to \r\n.
-
- It is the caller's responsibility to ensure that dest is
- large enough to hold the converted results. It is guaranteed
- that there will be fewer than n characters placed in dest.
-
- @param[out] dest WCS buffer to receive the converted string.
- @param[in] buf MBCS string to convert to WCS.
- @param[in] n Number of BYTES contained in buf.
- @param[in,out] Cs Pointer to the character state object for this stream
-
- @return The number of BYTES consumed from buf.
-**/
-ssize_t
-WideTtyCvt( CHAR16 *dest, const char *buf, ssize_t n, mbstate_t *Cs)
-{
- ssize_t i = 0;
- int numB = 0;
- wchar_t wc[2];
-
- while(n > 0) {
- numB = (int)mbrtowc(wc, buf, MIN(MB_LEN_MAX,n), Cs);
- if( numB == 0) {
- break;
- };
- if(numB < 0) { // If an unconvertable character, replace it.
- wc[0] = BLOCKELEMENT_LIGHT_SHADE;
- numB = 1;
- }
- if(wc[0] == L'\n') {
- *dest++ = L'\r';
- ++i;
- }
- *dest++ = (CHAR16)wc[0];
- i += numB;
- n -= numB;
- buf += numB;
- }
- *dest = 0;
- return i;
-}
-
-/** Close an open file.
-
- @param[in] filp Pointer to the file descriptor structure for this file.
-
- @retval 0 The file has been successfully closed.
- @retval -1 filp does not point to a valid console descriptor.
-**/
-static
-int
-EFIAPI
-da_ConClose(
- IN struct __filedes *filp
-)
-{
- ConInstance *Stream;
-
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- // Quick check to see if Stream looks reasonable
- if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
- errno = EINVAL;
- EFIerrno = RETURN_INVALID_PARAMETER;
- return -1; // Looks like a bad File Descriptor pointer
- }
- gMD->StdIo[Stream->InstanceNum] = NULL; // Mark the stream as closed
- return 0;
-}
-
-/** Position the console cursor to the coordinates specified by Position.
-
- @param[in] filp Pointer to the file descriptor structure for this file.
- @param[in] Position A value containing the target X and Y coordinates.
- @param[in] whence Ignored by the Console device.
-
- @retval Position Success. Returns a copy of the Position argument.
- @retval -1 filp is not associated with a valid console stream.
- @retval -1 This console stream is attached to stdin.
- @retval -1 The SetCursorPosition operation failed.
-**/
-static
-off_t
-EFIAPI
-da_ConSeek(
- struct __filedes *filp,
- off_t Position,
- int whence ///< Ignored by Console
-)
-{
- ConInstance *Stream;
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
- XY_OFFSET CursorPos;
-
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- // Quick check to see if Stream looks reasonable
- if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
- EFIerrno = RETURN_INVALID_PARAMETER;
- return -1; // Looks like a bad This pointer
- }
- if(Stream->InstanceNum == STDIN_FILENO) {
- // Seek is not valid for stdin
- EFIerrno = RETURN_UNSUPPORTED;
- return -1;
- }
- // Everything is OK to do the final verification and "seek".
- Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
- CursorPos.Offset = Position;
-
- EFIerrno = Proto->SetCursorPosition(Proto,
- (INTN)CursorPos.XYpos.Column,
- (INTN)CursorPos.XYpos.Row);
-
- if(RETURN_ERROR(EFIerrno)) {
- return -1;
- }
- else {
- return Position;
- }
-}
-
-/* Write a NULL terminated WCS to the EFI console.
-
- NOTE: The UEFI Console is a wide device, _S_IWTTY, so characters received
- by da_ConWrite are WIDE characters. It is the responsibility of the
- higher-level function(s) to perform any necessary conversions.
-
- @param[in,out] BufferSize Number of characters in Buffer.
- @param[in] Buffer The WCS string to be displayed
-
- @return The number of Characters written.
-*/
-static
-ssize_t
-EFIAPI
-da_ConWrite(
- IN struct __filedes *filp,
- IN off_t *Position,
- IN size_t BufferSize,
- IN const void *Buffer
- )
-{
- EFI_STATUS Status;
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
- ConInstance *Stream;
- ssize_t NumChar;
- XY_OFFSET CursorPos;
-
- NumChar = -1;
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- // Quick check to see if Stream looks reasonable
- if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
- EFIerrno = RETURN_INVALID_PARAMETER;
- return -1; // Looks like a bad This pointer
- }
- if(Stream->InstanceNum == STDIN_FILENO) {
- // Write is not valid for stdin
- EFIerrno = RETURN_UNSUPPORTED;
- return -1;
- }
- // Everything is OK to do the write.
- Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
-
- Status = EFI_SUCCESS;
- if(Position != NULL) {
- CursorPos.Offset = *Position;
-
- Status = Proto->SetCursorPosition(Proto,
- (INTN)CursorPos.XYpos.Column,
- (INTN)CursorPos.XYpos.Row);
-
- }
- if(!RETURN_ERROR(Status)) {
- // Send the Unicode buffer to the console
- Status = Proto->OutputString( Proto, (CHAR16 *)Buffer);
- }
-
- // Depending on status, update BufferSize and return
- if(!RETURN_ERROR(Status)) {
- NumChar = BufferSize;
- Stream->NumWritten += NumChar;
- }
- EFIerrno = Status; // Make error reason available to caller
- return NumChar;
-}
-
-/** Read a wide character from the console input device.
-
- Returns NUL or a translated input character.
-
- @param[in] filp Pointer to file descriptor for this file.
- @param[out] Buffer Buffer in which to place the read character.
-
- @retval EFI_DEVICE_ERROR A hardware error has occurred.
- @retval EFI_NOT_READY No data is available. Try again later.
- @retval EFI_SUCCESS One wide character has been placed in Character
- - 0x0000 NUL, ignore this
- - Otherwise, should be a good wide character in Character
-**/
-static
-EFI_STATUS
-da_ConRawRead (
- IN OUT struct __filedes *filp,
- OUT wchar_t *Character
-)
-{
- EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto;
- ConInstance *Stream;
- cIIO *Self;
- EFI_STATUS Status;
- EFI_INPUT_KEY Key = {0,0};
- wchar_t RetChar;
-
- Self = (cIIO *)filp->devdata;
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
-
- if(Stream->UnGetKey == CHAR_NULL) {
- Status = Proto->ReadKeyStroke(Proto, &Key);
- }
- else {
- Status = EFI_SUCCESS;
- // Use the data in the Un-get buffer
- // Guaranteed that ScanCode and UnicodeChar are not both NUL
- Key.ScanCode = SCAN_NULL;
- Key.UnicodeChar = Stream->UnGetKey;
- Stream->UnGetKey = CHAR_NULL;
- }
- if(Status == EFI_SUCCESS) {
- // Translate the Escape Scan Code to an ESC character
- if (Key.ScanCode != 0) {
- if (Key.ScanCode == SCAN_ESC) {
- RetChar = CHAR_ESC;
- }
- else if((Self->Termio.c_iflag & IGNSPEC) != 0) {
- // If we are ignoring special characters, return a NUL
- RetChar = 0;
- }
- else {
- // Must be a control, function, or other non-printable key.
- // Map it into the Platform portion of the Unicode private use area
- RetChar = TtyFunKeyMax - Key.ScanCode;
- }
- }
- else {
- RetChar = Key.UnicodeChar;
- }
- *Character = RetChar;
- }
- else {
- *Character = 0;
- }
- return Status;
-}
-
-/** Read a wide character from the console input device.
-
- NOTE: The UEFI Console is a wide device, _S_IWTTY, so characters returned
- by da_ConRead are WIDE characters. It is the responsibility of the
- higher-level function(s) to perform any necessary conversions.
-
- A NUL character, 0x0000, is never returned. In the event that such a character
- is encountered, the read is either retried or -1 is returned with errno set
- to EAGAIN.
-
- @param[in] filp Pointer to file descriptor for this file.
- @param[in] offset Ignored.
- @param[in] BufferSize Buffer size, in bytes.
- @param[out] Buffer Buffer in which to place the read characters.
-
- @retval -1 An error has occurred. Reason in errno and EFIerrno.
- @retval -1 No data is available. errno is set to EAGAIN
- @retval 1 One wide character has been placed in Buffer
-**/
-static
-ssize_t
-EFIAPI
-da_ConRead(
- IN OUT struct __filedes *filp,
- IN OUT off_t *offset, // Console ignores this
- IN size_t BufferSize,
- OUT VOID *Buffer
-)
-{
- EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto;
- ConInstance *Stream;
- //cIIO *Self;
- EFI_STATUS Status;
- UINTN Edex;
- ssize_t NumRead;
- BOOLEAN BlockingMode;
- wchar_t RetChar;
-
- NumRead = -1;
- if(BufferSize < sizeof(wchar_t)) {
- errno = EINVAL; // Buffer is too small to hold one character
- }
- else {
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
- BlockingMode = (BOOLEAN)((filp->Oflags & O_NONBLOCK) == 0);
-
- do {
- Status = EFI_SUCCESS;
- if(BlockingMode) {
- // Read a byte in Blocking mode
- Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);
- }
-
- /* WaitForEvent should not be able to fail since
- NumberOfEvents is set to constant 1 so is never 0
- Event is set by the Simple Text Input protocol so should never be EVT_NOTIFY_SIGNAL
- Current TPL should be TPL_APPLICATION.
- ASSERT so that we catch any problems during development.
- */
- ASSERT(Status == EFI_SUCCESS);
-
- Status = da_ConRawRead (filp, &RetChar);
- } while ( BlockingMode &&
- (RetChar == 0) &&
- (Status != EFI_DEVICE_ERROR));
-
- EFIerrno = Status;
- if(Status == EFI_SUCCESS) {
- // Got a keystroke.
- NumRead = 1; // Indicate that Key holds the data
- }
- else if(Status == EFI_NOT_READY) {
- // Keystroke data is not available
- errno = EAGAIN;
- }
- else {
- // Hardware error
- errno = EIO;
- }
- if (RetChar == 0) {
- NumRead = -1;
- errno = EAGAIN;
- }
- else {
- *((wchar_t *)Buffer) = RetChar;
- }
- }
- return NumRead;
-}
-
-/** Console-specific helper function for the fstat() function.
-
- st_size Set to number of characters read for stdin and number written for stdout and stderr.
- st_physsize 1 for stdin, 0 if QueryMode error, else max X and Y coordinates for the current mode.
- st_curpos 0 for stdin, current X & Y coordinates for stdout and stderr
- st_blksize Set to 1 since this is a character device
-
- All other members of the stat structure are left unchanged.
-
- @param[in] filp Pointer to file descriptor for this file.
- @param[out] Buffer Pointer to a stat structure to receive the information.
- @param[in,out] Something Ignored.
-
- @retval 0 Successful completion.
- @retval -1 Either filp is not associated with a console stream, or
- Buffer is NULL. errno is set to EINVAL.
-**/
-static
-int
-EFIAPI
-da_ConStat(
- struct __filedes *filp,
- struct stat *Buffer,
- void *Something
- )
-{
- ConInstance *Stream;
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
- XY_OFFSET CursorPos;
- INT32 OutMode;
- UINTN ModeCol;
- UINTN ModeRow;
-
-// ConGetInfo
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- // Quick check to see if Stream looks reasonable
- if ((Stream->Cookie != CON_COOKIE) || // Cookie == 'IoAb'
- (Buffer == NULL))
- {
- errno = EINVAL;
- EFIerrno = RETURN_INVALID_PARAMETER;
- return -1;
- }
- // All of our parameters are correct, so fill in the information.
- Buffer->st_blksize = 0; // Character device, not a block device
- Buffer->st_mode = filp->f_iflags;
-
-// ConGetPosition
- if(Stream->InstanceNum == STDIN_FILENO) {
- // This is stdin
- Buffer->st_curpos = 0;
- Buffer->st_size = (off_t)Stream->NumRead;
- Buffer->st_physsize = 1;
- }
- else {
- Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;
- CursorPos.XYpos.Column = (UINT32)Proto->Mode->CursorColumn;
- CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow;
- Buffer->st_curpos = (off_t)CursorPos.Offset;
- Buffer->st_size = (off_t)Stream->NumWritten;
-
- OutMode = Proto->Mode->Mode;
- EFIerrno = Proto->QueryMode(Proto, (UINTN)OutMode, &ModeCol, &ModeRow);
- if(RETURN_ERROR(EFIerrno)) {
- Buffer->st_physsize = 0;
- }
- else {
- CursorPos.XYpos.Column = (UINT32)ModeCol;
- CursorPos.XYpos.Row = (UINT32)ModeRow;
- Buffer->st_physsize = (off_t)CursorPos.Offset;
- }
- }
- return 0;
-}
-
-/** Console-specific helper for the ioctl system call.
-
- The console device does not directly participate in ioctl operations.
- This function completes the device abstraction and returns an error value
- to indicate that the function is not supported for this device.
-
- @retval -1 Function is not supported for this device.
-**/
-static
-int
-EFIAPI
-da_ConIoctl(
- struct __filedes *filp,
- ULONGN cmd,
- va_list argp
- )
-{
- errno = ENODEV;
- return -1;
-}
-
-/** Open an abstract Console Device.
-
- @param[in] DevNode Pointer to the Device control structure for this stream.
- @param[in] filp Pointer to the new file control structure for this stream.
- @param[in] DevInstance Not used for the console device.
- @param[in] Path Not used for the console device.
- @param[in] MPath Not used for the console device.
-
- @retval 0 This console stream has been successfully opened.
- @retval -1 The DevNode or filp pointer is NULL.
- @retval -1 DevNode does not point to a valid console stream device.
-**/
-int
-EFIAPI
-da_ConOpen(
- DeviceNode *DevNode,
- struct __filedes *filp,
- int DevInstance, // Not used for console devices
- wchar_t *Path, // Not used for console devices
- wchar_t *MPath // Not used for console devices
- )
-{
- ConInstance *Stream;
- UINT32 Instance;
- int RetVal = -1;
-
- if((filp != NULL) &&
- (DevNode != NULL))
- {
- Stream = (ConInstance *)DevNode->InstanceList;
- // Quick check to see if Stream looks reasonable
- if(Stream->Cookie == CON_COOKIE)
- {
- Instance = Stream->InstanceNum;
- if(Instance < NUM_SPECIAL) {
- gMD->StdIo[Instance] = Stream;
- filp->f_iflags |= (_S_IFCHR | _S_ITTY | _S_IWTTY | _S_ICONSOLE);
- filp->f_offset = 0;
- filp->f_ops = &Stream->Abstraction;
- filp->devdata = (void *)IIO;
- RetVal = 0;
- }
- }
- }
- if (RetVal < 0) {
- EFIerrno = RETURN_INVALID_PARAMETER;
- errno = EINVAL;
- }
- return RetVal;
-
-}
-
-#include <sys/poll.h>
-/* Returns a bit mask describing which operations could be completed immediately.
-
- Testable Events for this device are:
- (POLLIN | POLLRDNORM) A Unicode character is available to read
- (POLLIN) A ScanCode is ready.
- (POLLOUT) The device is ready for output - always set on stdout and stderr.
-
- Non-testable Events which are only valid in return values are:
- POLLERR The specified device is not one of stdin, stdout, or stderr.
- POLLHUP The specified stream has been disconnected
- POLLNVAL da_ConPoll was called with an invalid parameter.
-
- NOTE: The "Events" handled by this function are not UEFI events.
-
- @param[in] filp Pointer to the file control structure for this stream.
- @param[in] events A bit mask identifying the events to be examined
- for this device.
-
- @return Returns a bit mask comprised of both testable and non-testable
- event codes indicating both the state of the operation and the
- status of the device.
-*/
-static
-short
-EFIAPI
-da_ConPoll(
- struct __filedes *filp,
- short events
- )
-{
- ConInstance *Stream;
- EFI_STATUS Status = RETURN_SUCCESS;
- short RdyMask = 0;
-
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- // Quick check to see if Stream looks reasonable
- if(Stream->Cookie != CON_COOKIE) { // Cookie == 'IoAb'
- errno = EINVAL;
- EFIerrno = RETURN_INVALID_PARAMETER;
- return POLLNVAL; // Looks like a bad filp pointer
- }
- if(Stream->InstanceNum == 0) {
- // STDIN: Only input is supported for this device
- Status = da_ConRawRead (filp, &Stream->UnGetKey);
- if(Status == RETURN_SUCCESS) {
- RdyMask = POLLIN;
- if ((Stream->UnGetKey < TtyFunKeyMin) ||
- (Stream->UnGetKey >= TtyFunKeyMax))
- {
- RdyMask |= POLLRDNORM;
- }
- }
- else {
- Stream->UnGetKey = CHAR_NULL;
- }
- }
- else if(Stream->InstanceNum < NUM_SPECIAL) { // Not 0, is it 1 or 2?
- // (STDOUT || STDERR): Only output is supported for this device
- RdyMask = POLLOUT;
- }
- else {
- RdyMask = POLLERR; // Not one of the standard streams
- }
- EFIerrno = Status;
-
- return (RdyMask & (events | POLL_RETONLY));
-}
-
-/** Construct the Console stream devices: stdin, stdout, stderr.
-
- Allocate the instance structure and populate it with the information for
- each stream device.
-**/
-RETURN_STATUS
-EFIAPI
-__Cons_construct(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
-)
-{
- ConInstance *Stream;
- RETURN_STATUS Status;
- int i;
-
- Status = RETURN_OUT_OF_RESOURCES;
- ConInstanceList = (ConInstance *)AllocateZeroPool(NUM_SPECIAL * sizeof(ConInstance));
- if(ConInstanceList != NULL) {
- IIO = New_cIIO();
- if(IIO == NULL) {
- FreePool(ConInstanceList);
- }
- else {
- Status = RETURN_SUCCESS;
- for( i = 0; i < NUM_SPECIAL; ++i) {
- // Get pointer to instance.
- Stream = &ConInstanceList[i];
-
- Stream->Cookie = CON_COOKIE;
- Stream->InstanceNum = i;
- Stream->CharState.A = 0; // Start in the initial state
-
- switch(i) {
- case STDIN_FILENO:
- Stream->Dev = SystemTable->ConIn;
- break;
- case STDOUT_FILENO:
- Stream->Dev = SystemTable->ConOut;
- break;
- case STDERR_FILENO:
- if(SystemTable->StdErr == NULL) {
- Stream->Dev = SystemTable->ConOut;
- }
- else {
- Stream->Dev = SystemTable->StdErr;
- }
- break;
- default:
- return RETURN_VOLUME_CORRUPTED; // This is a "should never happen" case.
- }
-
- Stream->Abstraction.fo_close = &da_ConClose;
- Stream->Abstraction.fo_read = &da_ConRead;
- Stream->Abstraction.fo_write = &da_ConWrite;
- Stream->Abstraction.fo_stat = &da_ConStat;
- Stream->Abstraction.fo_lseek = &da_ConSeek;
- Stream->Abstraction.fo_fcntl = &fnullop_fcntl;
- Stream->Abstraction.fo_ioctl = &da_ConIoctl;
- Stream->Abstraction.fo_poll = &da_ConPoll;
- Stream->Abstraction.fo_flush = &fnullop_flush;
- Stream->Abstraction.fo_delete = &fbadop_delete;
- Stream->Abstraction.fo_mkdir = &fbadop_mkdir;
- Stream->Abstraction.fo_rmdir = &fbadop_rmdir;
- Stream->Abstraction.fo_rename = &fbadop_rename;
-
- Stream->NumRead = 0;
- Stream->NumWritten = 0;
- Stream->UnGetKey = CHAR_NULL;
-
- if(Stream->Dev == NULL) {
- continue; // No device for this stream.
- }
- ConNode[i] = __DevRegister(stdioNames[i], NULL, &da_ConOpen, Stream,
- 1, sizeof(ConInstance), stdioFlags[i]);
- if(ConNode[i] == NULL) {
- Status = EFIerrno; // Grab error code that DevRegister produced.
- break;
- }
- Stream->Parent = ConNode[i];
- }
- /* Initialize Ioctl flags until Ioctl is really implemented. */
- TtyCooked = TRUE;
- TtyEcho = TRUE;
- }
- }
- return Status;
-}
-
-RETURN_STATUS
-EFIAPI
-__Cons_deconstruct(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
-)
-{
- int i;
-
- for(i = 0; i < NUM_SPECIAL; ++i) {
- if(ConNode[i] != NULL) {
- FreePool(ConNode[i]);
- }
- }
- if(ConInstanceList != NULL) {
- FreePool(ConInstanceList);
- }
- if(IIO != NULL) {
- IIO->Delete(IIO);
- IIO = NULL;
- }
-
- return RETURN_SUCCESS;
-}
-
-/* ######################################################################### */
-#if 0 /* Not implemented (yet?) for Console */
-
-static
-int
-EFIAPI
-da_ConCntl(
- struct __filedes *filp,
- UINT32,
- void *,
- void *
- )
-{
-}
-
-static
-int
-EFIAPI
-da_ConFlush(
- struct __filedes *filp
- )
-{
- return 0;
-}
-#endif /* Not implemented for Console */
diff --git a/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c b/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c
deleted file mode 100644
index 861765e6bc..0000000000
--- a/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c
+++ /dev/null
@@ -1,856 +0,0 @@
-/** @file
- Abstract device driver for the UEFI Shell-hosted environment.
-
- In a Shell-hosted environment, this is the driver that is called
- when no other driver matches.
-
- Copyright (c) 2011, 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.
-
- 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/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/ShellLib.h>
-
-#include <LibConfig.h>
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <wctype.h>
-#include <wchar.h>
-#include <sys/fcntl.h>
-#include <sys/filio.h>
-#include <sys/syslimits.h>
-#include <unistd.h>
-#include <kfile.h>
-#include <Device/Device.h>
-#include <MainData.h>
-#include <Efi/SysEfi.h>
-
-/** EFI Shell specific operations for close().
-
- @param[in] Fp Pointer to a file descriptor structure.
-
- @retval 0 Successful completion.
- @retval -1 Operation failed. Further information is specified by errno.
-**/
-static
-int
-EFIAPI
-da_ShellClose(
- IN struct __filedes *Fp
-)
-{
- EFIerrno = ShellCloseFile( (SHELL_FILE_HANDLE *)&Fp->devdata);
- if(RETURN_ERROR(EFIerrno)) {
- return -1;
- }
- return 0;
-}
-
-/** EFI Shell specific operations for deleting a file or directory.
-
- @param[in] filp Pointer to a file descriptor structure.
-
- @retval 0 Successful completion.
- @retval -1 Operation failed. Further information is specified by errno.
-**/
-static
-int
-EFIAPI
-da_ShellDelete(
- struct __filedes *filp
- )
-{
- RETURN_STATUS Status;
-
- Status = ShellDeleteFile( (SHELL_FILE_HANDLE *)&filp->devdata);
- if(Status != RETURN_SUCCESS) {
- errno = EFI2errno(Status);
- EFIerrno = Status;
- return -1;
- }
- return 0;
-}
-
-/** EFI Shell specific operations for setting the position within a file.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] offset Relative position to move to.
- @param[in] whence Specifies the location offset is relative to: Beginning, Current, End.
-
- @return Returns the new file position or EOF if the seek failed.
-**/
-static
-off_t
-EFIAPI
-da_ShellSeek(
- struct __filedes *filp,
- off_t offset,
- int whence
-)
-{
- __off_t CurPos = -1;
- RETURN_STATUS Status = RETURN_SUCCESS;
- SHELL_FILE_HANDLE FileHandle;
-
- FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
-
- if(whence != SEEK_SET) {
- // We are doing a relative seek
- if(whence == SEEK_END) {
- // seeking relative to EOF, so position there first.
- Status = ShellSetFilePosition( FileHandle, 0xFFFFFFFFFFFFFFFFULL);
- }
- if(Status == RETURN_SUCCESS) {
- // Now, determine our current position.
- Status = ShellGetFilePosition( FileHandle, (UINT64 *)&CurPos);
- }
- }
- else {
- CurPos = 0; // offset is an absolute position for SEEK_SET
- if(offset < 0) {
- Status = RETURN_INVALID_PARAMETER;
- }
- }
- if(Status == RETURN_SUCCESS) {
- /* CurPos now indicates the point we are seeking from, so seek... */
- Status = ShellSetFilePosition( FileHandle, (UINT64)(CurPos + offset));
- if(Status == RETURN_SUCCESS) {
- // Now, determine our final position.
- Status = ShellGetFilePosition( FileHandle, (UINT64 *)&CurPos);
- }
- }
- if(Status != RETURN_SUCCESS) {
- if(Status == EFI_UNSUPPORTED) {
- errno = EISDIR;
- }
- else {
- errno = EFI2errno(Status);
- }
- EFIerrno = Status;
- CurPos = EOF;
- }
- return CurPos;
-}
-
-/** The directory path is created with the access permissions specified by
- perms.
-
- The directory is closed after it is created.
-
- @param[in] path The directory to be created.
- @param[in] perms Access permissions for the new directory.
-
- @retval 0 The directory was created successfully.
- @retval -1 An error occurred and an error code is stored in errno.
-**/
-static
-int
-EFIAPI
-da_ShellMkdir(
- const char *path,
- __mode_t perms
- )
-{
- UINT64 TempAttr;
- SHELL_FILE_HANDLE FileHandle;
- RETURN_STATUS Status;
- EFI_FILE_INFO *FileInfo;
- wchar_t *NewPath;
- int retval = -1;
-
- // Convert name from MBCS to WCS and change '/' to '\\'
- NewPath = NormalizePath( path);
-
- if(NewPath != NULL) {
- Status = ShellCreateDirectory( NewPath, &FileHandle);
- if(Status == RETURN_SUCCESS) {
- FileInfo = ShellGetFileInfo( FileHandle);
- Status = RETURN_ABORTED; // In case ShellGetFileInfo() failed
- if(FileInfo != NULL) {
- TempAttr = FileInfo->Attribute & (EFI_FILE_RESERVED | EFI_FILE_DIRECTORY);
- FileInfo->Attribute = TempAttr | Omode2EFI(perms);
- Status = ShellSetFileInfo( FileHandle, FileInfo);
- FreePool(FileInfo);
- if(Status == RETURN_SUCCESS) {
- (void)ShellCloseFile(&FileHandle);
- retval = 0;
- }
- }
- }
- errno = EFI2errno(Status);
- EFIerrno = Status;
- free(NewPath);
- }
- return retval;
-}
-
-/** EFI Shell specific operations for reading from a file.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] offset Offset into the file to begin reading at, or NULL.
- @param[in] BufferSize Number of bytes in Buffer. Max number of bytes to read.
- @param[in] Buffer Pointer to a buffer to receive the read data.
-
- @return Returns the number of bytes successfully read,
- or -1 if the operation failed. Further information is specified by errno.
-**/
-static
-ssize_t
-EFIAPI
-da_ShellRead(
- IN OUT struct __filedes *filp,
- IN OUT off_t *offset,
- IN size_t BufferSize,
- OUT VOID *Buffer
-)
-{
- ssize_t BufSize;
- SHELL_FILE_HANDLE FileHandle;
- RETURN_STATUS Status;
-
- if(offset != NULL) {
- BufSize = (ssize_t)da_ShellSeek(filp, *offset, SEEK_SET);
- if(BufSize >= 0) {
- filp->f_offset = BufSize;
- }
- }
-
- BufSize = (ssize_t)BufferSize;
- FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
-
- Status = ShellReadFile( FileHandle, (UINTN *)&BufSize, Buffer);
- if(Status != RETURN_SUCCESS) {
- EFIerrno = Status;
- errno = EFI2errno(Status);
- if(Status == RETURN_BUFFER_TOO_SMALL) {
- BufSize = -BufSize;
- }
- else {
- BufSize = -1;
- }
- }
- else {
- filp->f_offset += BufSize; // Advance to where we want to read next.
- }
- return BufSize;
-}
-
-/** EFI Shell specific operations for writing to a file.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] offset Offset into the file to begin writing at, or NULL.
- @param[in] BufferSize Number of bytes in Buffer. Max number of bytes to write.
- @param[in] Buffer Pointer to a buffer containing the data to be written.
-
- @return Returns the number of bytes successfully written,
- or -1 if the operation failed. Further information is specified by errno.
-**/
-static
-ssize_t
-EFIAPI
-da_ShellWrite(
- IN struct __filedes *filp,
- IN off_t *offset,
- IN size_t BufferSize,
- IN const void *Buffer
- )
-{
- ssize_t BufSize;
- SHELL_FILE_HANDLE FileHandle;
- RETURN_STATUS Status;
- off_t Position = 0;
- int How = SEEK_SET;
-
-
- if((offset != NULL) || (filp->Oflags & O_APPEND)) {
- if(filp->Oflags & O_APPEND) {
- Position = 0;
- How = SEEK_END;
- }
- else {
- Position = *offset;
- How = SEEK_SET;
- }
- BufSize = (ssize_t)da_ShellSeek(filp, Position, How);
- if(BufSize >= 0) {
- filp->f_offset = BufSize;
- }
- }
-
- BufSize = (ssize_t)BufferSize;
- FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
-
- Status = ShellWriteFile( FileHandle, (UINTN *)&BufSize, (void *)Buffer);
-
- if(Status != RETURN_SUCCESS) {
- EFIerrno = Status;
- errno = EFI2errno(Status);
- if(Status == EFI_UNSUPPORTED) {
- errno = EISDIR;
- }
- BufSize = -1;
- }
- else {
- filp->f_offset += BufSize; // Advance to where we want to write next.
- }
-
- return BufSize;
-}
-
-/** EFI Shell specific operations for getting information about an open file.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[out] statbuf Buffer in which to store the file status.
- @param[in] Something This parameter is not used by this device.
-
- @retval 0 Successful completion.
- @retval -1 Operation failed. Further information is specified by errno.
-**/
-static
-int
-EFIAPI
-da_ShellStat(
- struct __filedes *filp,
- struct stat *statbuf,
- void *Something
- )
-{
- SHELL_FILE_HANDLE FileHandle;
- EFI_FILE_INFO *FileInfo = NULL;
- UINT64 Attributes;
- RETURN_STATUS Status;
- mode_t newmode;
-
- FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
-
- FileInfo = ShellGetFileInfo( FileHandle);
-
- if(FileInfo != NULL) {
- // Got the info, now populate statbuf with it
- statbuf->st_blksize = S_BLKSIZE;
- statbuf->st_size = FileInfo->FileSize;
- statbuf->st_physsize = FileInfo->PhysicalSize;
- statbuf->st_birthtime = Efi2Time( &FileInfo->CreateTime);
- statbuf->st_atime = Efi2Time( &FileInfo->LastAccessTime);
- statbuf->st_mtime = Efi2Time( &FileInfo->ModificationTime);
- Attributes = FileInfo->Attribute;
- newmode = (mode_t)(Attributes << S_EFISHIFT) | S_ACC_READ;
- if((Attributes & EFI_FILE_DIRECTORY) == 0) {
- newmode |= _S_IFREG;
- if((Attributes & EFI_FILE_READ_ONLY) == 0) {
- newmode |= S_ACC_WRITE;
- }
- }
- else {
- newmode |= _S_IFDIR;
- }
- statbuf->st_mode = newmode;
- Status = RETURN_SUCCESS;
- }
- else {
- Status = RETURN_DEVICE_ERROR;
- errno = EIO;
- }
- EFIerrno = Status;
-
- if(FileInfo != NULL) {
- FreePool(FileInfo); // Release the buffer allocated by the GetInfo function
- }
- return (Status == RETURN_SUCCESS)? 0 : -1;
-}
-
-/** EFI Shell specific operations for low-level control of a file or device.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] cmd The command this ioctl is to perform.
- @param[in,out] argp Zero or more arguments as needed by the command.
-
- @retval 0 Successful completion.
- @retval -1 Operation failed. Further information is specified by errno.
-**/
-static
-int
-EFIAPI
-da_ShellIoctl(
- struct __filedes *filp,
- ULONGN cmd,
- va_list argp
- )
-{
- EFI_FILE_INFO *FileInfo = NULL;
- SHELL_FILE_HANDLE FileHandle;
- RETURN_STATUS Status = RETURN_SUCCESS;
- int retval = 0;
-
- FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
-
- FileInfo = ShellGetFileInfo( FileHandle);
-
- if(FileInfo != NULL) {
- if( cmd == (ULONGN)FIOSETIME) {
- struct timeval *TV;
- EFI_TIME *ET;
- int mod = 0;
-
- TV = va_arg(argp, struct timeval*);
- if(TV[0].tv_sec != 0) {
- ET = Time2Efi(TV[0].tv_sec);
- if(ET != NULL) {
- (void) memcpy(&FileInfo->LastAccessTime, ET, sizeof(EFI_TIME));
- FileInfo->LastAccessTime.Nanosecond = TV[0].tv_usec * 1000;
- free(ET);
- ++mod;
- }
- }
- if(TV[1].tv_sec != 0) {
- ET = Time2Efi(TV[1].tv_sec);
- if(ET != NULL) {
- (void) memcpy(&FileInfo->ModificationTime, ET, sizeof(EFI_TIME));
- FileInfo->ModificationTime.Nanosecond = TV[1].tv_usec * 1000;
- free(ET);
- ++mod;
- }
- }
- /* Set access and modification times */
- Status = ShellSetFileInfo(FileHandle, FileInfo);
- errno = EFI2errno(Status);
- }
- }
- else {
- Status = RETURN_DEVICE_ERROR;
- errno = EIO;
- }
- if(RETURN_ERROR(Status)) {
- retval = -1;
- }
- EFIerrno = Status;
-
- if(FileInfo != NULL) {
- FreePool(FileInfo); // Release the buffer allocated by the GetInfo function
- }
- return retval;
-}
-
-/** EFI Shell specific operations for opening a file or directory.
-
- @param[in] DevNode Pointer to a device descriptor
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] DevInstance Not used by this device.
- @param[in] Path File-system path to the file or directory.
- @param[in] MPath Device or Map name on which Path resides.
-
- @return Returns a file descriptor for the newly opened file,
- or -1 if the Operation failed. Further information is specified by errno.
-**/
-int
-EFIAPI
-da_ShellOpen(
- DeviceNode *DevNode,
- struct __filedes *filp,
- int DevInstance, /* Not used by Shell */
- wchar_t *Path,
- wchar_t *MPath
- )
-{
- UINT64 OpenMode;
- UINT64 Attributes;
- SHELL_FILE_HANDLE FileHandle;
- GenericInstance *Gip;
- char *NPath;
- wchar_t *WPath;
- RETURN_STATUS Status;
- int oflags;
- int retval;
-
- EFIerrno = RETURN_SUCCESS;
-
- //Attributes = Omode2EFI(mode);
- Attributes = 0;
-
- // Convert oflags to Attributes
- oflags = filp->Oflags;
- OpenMode = Oflags2EFI(oflags);
- if(OpenMode == 0) {
- errno = EINVAL;
- return -1;
- }
-
- /* Re-create the full mapped path for the shell. */
- if(MPath != NULL) {
- WPath = AllocateZeroPool(PATH_MAX * sizeof(wchar_t) + 1);
- if(WPath == NULL) {
- errno = ENOMEM;
- EFIerrno = RETURN_OUT_OF_RESOURCES;
- return -1;
- }
- wcsncpy(WPath, MPath, NAME_MAX); /* Get the Map Name */
- wcsncat(WPath, Path, (PATH_MAX - NAME_MAX)); /* Append the path */
- }
- else {
- WPath = Path;
- }
-
- retval = -1; /* Initially assume failure. */
-
- /* Do we care if the file already exists?
- If O_TRUNC, then delete the file. It will be created anew subsequently.
- If O_EXCL, then error if the file exists and O_CREAT is set.
-
- !!!!!!!!! Change this to use ShellSetFileInfo() to actually truncate the file
- !!!!!!!!! instead of deleting and re-creating it.
- */
- do { /* Do fake exception handling */
- if((oflags & O_TRUNC) || ((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {
- Status = ShellIsFile( WPath );
- if(Status == RETURN_SUCCESS) {
- // The file exists
- if(oflags & O_TRUNC) {
- NPath = AllocateZeroPool(PATH_MAX);
- if(NPath == NULL) {
- errno = ENOMEM;
- EFIerrno = RETURN_OUT_OF_RESOURCES;
- break;
- }
- wcstombs(NPath, WPath, PATH_MAX);
- // We do a truncate by deleting the existing file and creating a new one.
- if(unlink(NPath) != 0) {
- filp->f_iflags = 0; // Release our reservation on this FD
- FreePool(NPath);
- break;
- }
- FreePool(NPath);
- }
- else if((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) {
- errno = EEXIST;
- EFIerrno = RETURN_ACCESS_DENIED;
- filp->f_iflags = 0; // Release our reservation on this FD
- break;
- }
- }
- }
-
- // Call the EFI Shell's Open function
- Status = ShellOpenFileByName( WPath, &FileHandle, OpenMode, Attributes);
- if(RETURN_ERROR(Status)) {
- filp->f_iflags = 0; // Release our reservation on this FD
- // Set errno based upon Status
- errno = EFI2errno(Status);
- EFIerrno = Status;
- break;
- }
- retval = 0;
- // Successfully got a regular File
- filp->f_iflags |= S_IFREG;
-
- // Update the info in the fd
- filp->devdata = (void *)FileHandle;
-
- Gip = (GenericInstance *)DevNode->InstanceList;
- filp->f_offset = 0;
- filp->f_ops = &Gip->Abstraction;
- // filp->devdata = FileHandle;
- } while(FALSE);
-
- /* If we get this far, WPath is not NULL.
- If MPath is not NULL, then WPath was allocated so we need to free it.
- */
- if(MPath != NULL) {
- FreePool(WPath);
- }
- return retval;
-}
-
-#include <sys/poll.h>
-/** Returns a bit mask describing which operations could be completed immediately.
-
- For now, assume the file system, via the shell, is always ready.
-
- (POLLIN | POLLRDNORM) The file system is ready to be read.
- (POLLOUT) The file system is ready for output.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] events Bit mask describing which operations to check.
-
- @return The returned value is a bit mask describing which operations
- could be completed immediately, without blocking.
-**/
-static
-short
-EFIAPI
-da_ShellPoll(
- struct __filedes *filp,
- short events
- )
-{
- UINT32 RdyMask;
- short retval = 0;
-
- RdyMask = (UINT32)filp->Oflags;
-
- switch(RdyMask & O_ACCMODE) {
- case O_RDONLY:
- retval = (POLLIN | POLLRDNORM);
- break;
-
- case O_WRONLY:
- retval = POLLOUT;
- break;
-
- case O_RDWR:
- retval = (POLLIN | POLLRDNORM | POLLOUT);
- break;
-
- default:
- retval = POLLERR;
- break;
- }
- return (retval & (events | POLL_RETONLY));
-}
-
-/** EFI Shell specific operations for renaming a file.
-
- @param[in] from Name of the file to be renamed.
- @param[in] to New name for the file.
-
- @retval 0 Successful completion.
- @retval -1 Operation failed. Further information is specified by errno.
-**/
-static
-int
-EFIAPI
-da_ShellRename(
- const char *from,
- const char *to
- )
-{
- RETURN_STATUS Status;
- EFI_FILE_INFO *NewFileInfo;
- EFI_FILE_INFO *OldFileInfo;
- wchar_t *NewFn;
- int OldFd;
- SHELL_FILE_HANDLE FileHandle;
- wchar_t *NormalizedPath;
-
- // Open old file
- OldFd = open(from, O_RDWR, 0);
- if(OldFd >= 0) {
- FileHandle = (SHELL_FILE_HANDLE)gMD->fdarray[OldFd].devdata;
-
- NewFileInfo = malloc(sizeof(EFI_FILE_INFO) + PATH_MAX);
- if(NewFileInfo != NULL) {
- OldFileInfo = ShellGetFileInfo( FileHandle);
- if(OldFileInfo != NULL) {
- // Copy the Old file info into our new buffer, and free the old.
- memcpy(NewFileInfo, OldFileInfo, sizeof(EFI_FILE_INFO));
- FreePool(OldFileInfo);
- // Normalize path and convert to WCS.
- NormalizedPath = NormalizePath(to);
- if (NormalizedPath != NULL) {
- // Strip off all but the file name portion of new
- NewFn = GetFileNameFromPath(NormalizedPath);
- // Copy the new file name into our new file info buffer
- wcsncpy(NewFileInfo->FileName, NewFn, wcslen(NewFn) + 1);
- // Update the size of the structure.
- NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFn);
- // Apply the new file name
- Status = ShellSetFileInfo(FileHandle, NewFileInfo);
- free(NormalizedPath);
- free(NewFileInfo);
- if(Status == EFI_SUCCESS) {
- // File has been successfully renamed. We are DONE!
- return 0;
- }
- errno = EFI2errno( Status );
- EFIerrno = Status;
- }
- else {
- free(NewFileInfo);
- errno = ENOMEM;
- }
- }
- else {
- free(NewFileInfo);
- errno = EIO;
- }
- }
- else {
- errno = ENOMEM;
- }
- }
- return -1;
-}
-
-/** EFI Shell specific operations for deleting directories.
-
- @param[in] filp Pointer to a file descriptor structure.
-
- @retval 0 Successful completion.
- @retval -1 Operation failed. Further information is specified by errno.
-**/
-static
-int
-EFIAPI
-da_ShellRmdir(
- struct __filedes *filp
- )
-{
- SHELL_FILE_HANDLE FileHandle;
- RETURN_STATUS Status = RETURN_SUCCESS;
- EFI_FILE_INFO *FileInfo;
- int OldErrno;
- int Count = 0;
- BOOLEAN NoFile = FALSE;
-
- OldErrno = errno; // Save the original value
- errno = 0; // Make it easier to see if we have an error later
-
- FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
-
- FileInfo = ShellGetFileInfo(FileHandle);
- if(FileInfo != NULL) {
- if((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
- errno = ENOTDIR;
- }
- else {
- FreePool(FileInfo); // Free up the buffer from ShellGetFileInfo()
- // See if the directory has any entries other than ".." and ".".
- Status = ShellFindFirstFile( FileHandle, &FileInfo);
- if(Status == RETURN_SUCCESS) {
- ++Count;
- while(Count < 3) {
- Status = ShellFindNextFile( FileHandle, FileInfo, &NoFile);
- if(Status == RETURN_SUCCESS) {
- if(NoFile) {
- break;
- }
- ++Count;
- }
- else {
- Count = 99;
- }
- }
- /* Count == 99 and FileInfo is allocated if ShellFindNextFile failed.
- ShellFindNextFile has freed FileInfo itself if it sets NoFile TRUE.
- */
- if((! NoFile) || (Count == 99)) {
- free(FileInfo); // Free buffer from ShellFindFirstFile()
- }
- if(Count < 3) {
- // Directory is empty
- Status = ShellDeleteFile( &FileHandle);
- if(Status == RETURN_SUCCESS) {
- EFIerrno = RETURN_SUCCESS;
- errno = OldErrno; // Restore the original value
- return 0;
- /* ######## SUCCESSFUL RETURN ######## */
- }
- /* FileInfo is freed and FileHandle closed. */
- }
- else {
- if(Count == 99) {
- errno = EIO;
- }
- else {
- errno = ENOTEMPTY;
- }
- }
- }
- }
- }
- else {
- errno = EIO;
- }
- ShellCloseFile( &FileHandle);
- EFIerrno = Status;
- if(errno == 0) {
- errno = EFI2errno( Status );
- }
- return -1;
-}
-
-/** Construct an instance of the abstract Shell device.
-
- Allocate the instance structure and populate it with the information for
- the device.
-
- @param[in] ImageHandle This application's image handle.
- @param[in] SystemTable Pointer to the UEFI System Table.
-
- @retval RETURN_SUCCESS Successful completion.
- @retval RETURN_OUT_OF_RESOURCES Failed to allocate memory for new device.
- @retval RETURN_INVALID_PARAMETER A default device has already been created.
-**/
-RETURN_STATUS
-EFIAPI
-__ctor_DevShell(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
-)
-{
- GenericInstance *Stream;
- DeviceNode *Node;
- RETURN_STATUS Status;
-
- Stream = (GenericInstance *)AllocateZeroPool(sizeof(GenericInstance));
- if(Stream == NULL) {
- return RETURN_OUT_OF_RESOURCES;
- }
-
- Stream->Cookie = CON_COOKIE;
- Stream->InstanceNum = 1;
- Stream->Dev = NULL;
- Stream->Abstraction.fo_close = &da_ShellClose;
- Stream->Abstraction.fo_read = &da_ShellRead;
- Stream->Abstraction.fo_write = &da_ShellWrite;
- Stream->Abstraction.fo_fcntl = &fnullop_fcntl;
- Stream->Abstraction.fo_poll = &da_ShellPoll;
- Stream->Abstraction.fo_flush = &fnullop_flush;
- Stream->Abstraction.fo_stat = &da_ShellStat;
- Stream->Abstraction.fo_ioctl = &da_ShellIoctl;
- Stream->Abstraction.fo_delete = &da_ShellDelete;
- Stream->Abstraction.fo_rmdir = &da_ShellRmdir;
- Stream->Abstraction.fo_mkdir = &da_ShellMkdir;
- Stream->Abstraction.fo_rename = &da_ShellRename;
- Stream->Abstraction.fo_lseek = &da_ShellSeek;
-
- Node = __DevRegister(NULL, NULL, &da_ShellOpen, Stream, 1, sizeof(GenericInstance), O_RDWR);
- Status = EFIerrno;
- Stream->Parent = Node;
-
- return Status;
-}
-
-/** Destructor for previously constructed EFI Shell device instances.
-
- @param[in] ImageHandle This application's image handle.
- @param[in] SystemTable Pointer to the UEFI System Table.
-
- @retval 0 Successful completion is always returned.
-**/
-RETURN_STATUS
-EFIAPI
-__dtor_DevShell(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
-)
-{
- if(daDefaultDevice != NULL) {
- if(daDefaultDevice->InstanceList != NULL) {
- FreePool(daDefaultDevice->InstanceList);
- }
- FreePool(daDefaultDevice);
- }
- return RETURN_SUCCESS;
-}
diff --git a/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c b/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c
deleted file mode 100644
index 8d95fbad5e..0000000000
--- a/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/** @file
- Device Abstraction: device creation utility functions.
-
- Copyright (c) 2011 - 2012, 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/MemoryAllocationLib.h>
-
-#include <LibConfig.h>
-
-#include <errno.h>
-#include <stdarg.h>
-#include <sys/poll.h>
-#include <kfile.h>
-#include <Device/Device.h>
-#include <MainData.h>
-
-LIST_ENTRY daDeviceList = INITIALIZE_LIST_HEAD_VARIABLE(daDeviceList);
-DeviceNode *daDefaultDevice = NULL; ///< Device to use if nothing else found
-DeviceNode *daRootDevice = NULL; ///< Device containing the root file system
-DeviceNode *daCurrentDevice = NULL; ///< Device currently being accessed
-
-/* Commonly used fileops
- fnullop_* Does nothing and returns success.
- fbadop_* Does nothing and returns EPERM
-*/
-int EFIAPI fnullop_fcntl (struct __filedes *filp, UINT32 Cmd, void *p3, void *p4)
-{ return 0; }
-
-short EFIAPI fnullop_poll (struct __filedes *filp, short Events)
-{
- return ((POLLIN | POLLRDNORM | POLLOUT) & Events);
-}
-
-int EFIAPI fnullop_flush (struct __filedes *filp)
-{ return 0; }
-
-int EFIAPI fbadop_stat (struct __filedes *filp, struct stat *StatBuf, void *Buf)
-{
- errno = EPERM;
- return -1;
-}
-
-int EFIAPI fbadop_ioctl (struct __filedes *filp, ULONGN Cmd, va_list argp)
-{
- errno = EPERM;
- return -1;
-}
-
-int EFIAPI fbadop_delete (struct __filedes *filp)
-{
- errno = EPERM;
- return -1;
-}
-
-int EFIAPI fbadop_mkdir (const char *path, __mode_t perms)
-{
- errno = EPERM;
- return -1;
-}
-
-int EFIAPI fbadop_rename (const char *from, const char *to)
-{
- errno = EPERM;
- return -1;
-}
-
-int EFIAPI fbadop_rmdir (struct __filedes *filp)
-{
- errno = EPERM;
- return -1;
-}
-
-/** Add a new device to the device list.
- If both DevName and DevProto are NULL, register this as the Default device.
-
- @param DevName Name of the device to add.
- @param DevProto Pointer to the GUID identifying the protocol associated with this device.
- If DevProto is NULL, startup code will not try to find instances
- of this device.
- @param OpenFunc Pointer to the device's Open function.
- @param InstanceList Optional pointer to the device's initialized instance list.
- If InstanceList is NULL, the application startup code will
- scan for instances of the protocol identified by DevProto and
- populate the InstanceList in the order those protocols are found.
- @param NumInstance Number of instances in InstanceList.
- @param Modes Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.
-
-**/
-DeviceNode *
-EFIAPI
-__DevRegister(
- IN const CHAR16 *DevName,
- IN GUID *DevProto,
- IN FO_OPEN OpenFunc,
- IN void *InstanceList,
- IN int NumInstance,
- IN UINT32 InstanceSize,
- IN UINT32 Modes
- )
-{
- DeviceNode *Node;
- GenericInstance *GIp;
- char *GenPtr;
- int i;
-
- /* Validate parameters */
- if(((DevName == NULL) && (DevProto != NULL)) ||
- (OpenFunc == NULL)) {
- EFIerrno = RETURN_INVALID_PARAMETER;
- return NULL;
- }
- Node = (DeviceNode *)AllocateZeroPool(sizeof(DeviceNode));
- if(Node == NULL) {
- EFIerrno = RETURN_OUT_OF_RESOURCES;
- return NULL;
- }
-
- Node->DevName = DevName;
- Node->DevProto = DevProto;
- Node->InstanceList = InstanceList;
- Node->OpenFunc = OpenFunc;
- Node->InstanceSize = InstanceSize;
- Node->NumInstances = NumInstance;
- Node->OpModes = Modes;
-
- /* Update the Parent member of each element of the InstanceList */
- if(InstanceList != NULL) {
- GenPtr = InstanceList;
-
- for(i = 0; i < NumInstance; ++i) { // Iterate through each element of InstanceList
- GIp = (GenericInstance *)GenPtr;
- GIp->Parent = Node; // Initializing the Parent member & InstanceNum
- //GIp->InstanceNum = i;
- GenPtr += InstanceSize;
- }
- }
- if(DevName == NULL) {
- if(daDefaultDevice != NULL) {
- EFIerrno = RETURN_INVALID_PARAMETER;
- return NULL;
- }
- daDefaultDevice = Node;
- }
- else {
- (void) InsertTailList(&daDeviceList, &Node->DevList);
- }
- EFIerrno = RETURN_SUCCESS;
- return Node;
-}
diff --git a/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c b/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c
deleted file mode 100644
index b0fc7bacd1..0000000000
--- a/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/** @file
- Device Abstraction: Search device list for a matching device.
-
- Copyright (c) 2011, 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 <LibConfig.h>
-
-#include <errno.h>
-#include <kfile.h>
-#include <Device/Device.h>
-#include <MainData.h>
-
-/** Find a DeviceNode matching DevName or DevProto, or both.
-
- If DevName is NULL, then the device name is not used in the search.
- If DevProto is NULL, then the protocol GUID is not used in the search.
- If both are NULL, then INVALID_PARAMETER is returned.
- If both DevName and DevProto are specified, then both must match.
- If both are specified but only one matches, then DEVICE_ERROR is returned.
-
- @param DevName Name of the Device Abstraction to find.
- @param DevProto GUID of the Protocol associated with the Device Abstraction.
- @param Node Pointer to the pointer to receive the found Device Node's address.
-
- @retval RETURN_SUCCESS The desired Device Node was found.
- @retval RETURN_INVALID_PARAMETER Both DevName and DevProto are NULL or Node is NULL.
- @retval RETURN_DEVICE_ERROR DevName matched but DevProto did not.
- @retval RETURN_NOT_FOUND The desired device was not found.
-**/
-EFI_STATUS
-EFIAPI
-__DevSearch(
- IN CHAR16 *DevName,
- IN GUID *DevProto,
- OUT DeviceNode **Node
- )
-{
- RETURN_STATUS Status = RETURN_NOT_FOUND;
- DeviceNode *WorkNode;
- INT32 DevMatched;
-
- if(((DevName == NULL) && (DevProto == NULL)) || (Node == NULL)) {
- Status = RETURN_INVALID_PARAMETER;
- }
- else {
- if(IsListEmpty((LIST_ENTRY *)&daDeviceList)) {
- Status = RETURN_NOT_FOUND;
- }
- else {
- /* Traverse the list of Device Nodes hunting for a match */
- WorkNode = (DeviceNode *)GetFirstNode((LIST_ENTRY *)&daDeviceList);
- do {
- /* Use DevMatched to keep track of the three match conditions. */
- DevMatched = 0;
- if(DevName != NULL) {
- ++DevMatched;
- if(wcsncmp(DevName, WorkNode->DevName, wcslen(WorkNode->DevName)) == 0) {
- ++DevMatched;
- }
- }
- /* At this point, DevMatched has one of the following values:
- 0 DevName == NULL, no name comparison
- 1 DevName did not match WorkNode's name
- 2 DevName MATCHED
- */
- if((DevMatched != 1) && (DevProto != NULL) && (WorkNode->DevProto != NULL)) {
- /* Only bother with the GUID comparison if:
- * There was NOT a name mismatch
- * DevProto is NOT NULL -- there is a GUID to compare
- * WorkNode->DevProto is NOT NULL
- */
- if(CompareGuid(DevProto, WorkNode->DevProto)) {
- // GUIDs matched, we found it
- Status = RETURN_SUCCESS;
- *Node = WorkNode;
- break;
- }
- else {
- // GUIDs did not match
- if(DevMatched == 2) {
- // Name matched, GUID did not!
- Status = RETURN_DEVICE_ERROR;
- break; // Don't try any more, we have an internal problem
- }
- }
- }
- else {
- if(DevMatched == 2) {
- // Device Name matched, GUIDs skipped
- Status = RETURN_SUCCESS;
- *Node = WorkNode;
- break;
- }
- }
- // Check the next device in the list
- WorkNode = (DeviceNode *)GetNextNode(&daDeviceList, (LIST_ENTRY *)WorkNode);
- } while(&daDeviceList != (LIST_ENTRY *)WorkNode);
- }
- }
- return Status;
-}
diff --git a/StdLib/LibC/Uefi/Devices/Utility/Path.c b/StdLib/LibC/Uefi/Devices/Utility/Path.c
deleted file mode 100644
index 96392e018d..0000000000
--- a/StdLib/LibC/Uefi/Devices/Utility/Path.c
+++ /dev/null
@@ -1,431 +0,0 @@
-/** @file
- Device Abstraction: Path manipulation utilities.
-
- Copyright (c) 2011, 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 <Library/BaseLib.h>
-
-#include <LibConfig.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <wchar.h>
-#include <wctype.h>
-#include <kfile.h>
-#include <Device/Device.h>
-#include <MainData.h>
-
-/** Identify the type of path pointed to by Path.
-
- Paths are classified based upon their initial character sequences.
- ^\\ Absolute Path
- ^\. Relative Path
- ^[^:\\]: Mapping Path
- .* Relative Path
-
- Mapping paths are broken into two parts at the ':'. The part to the left of the ':'
- is the Map Name, pointed to by Path, and the part to the right of the ':' is pointed
- to by NewPath.
-
- If Path was not a Mapping Path, then NewPath is set to Path.
-
- @param[in] Path Pointer to the path to be classified.
- @param[out] NewPath Pointer to the path portion of a mapping path.
- @param[out] Length Length of the Map Name portion of the path.
-
- @retval PathAbsolute Path is an absolute path. NewPath points to the first '\'.
- @retval PathRelative Path is a relative path. NewPath = Path.
- @retval PathMapping Path is a mapping path. NewPath points to the character following ':'.
- @retval PathError Path is NULL.
-**/
-PATH_CLASS
-EFIAPI
-ClassifyPath(
- IN wchar_t * Path,
- OUT wchar_t ** NewPath,
- OUT int * const Length
- )
-{
- size_t MapLen;
-
- if(Path == NULL) {
- return PathError; // Bad parameter
- }
- if(NewPath != NULL) {
- *NewPath = Path; // Setup default condition
- }
- if((*Path == L'\\') || (*Path == L'\0')) {
- return PathAbsolute;
- }
- if(*Path == L'.') {
- return PathRelative;
- }
- /* The easy stuff has been done, now see if this is a mapping path.
- See if there is a ':' in Path that isn't the first character and is before
- any '\\' characters.
- */
- MapLen = wcscspn(Path, L"\\:");
- if(Length != NULL) {
- *Length = (int)MapLen;
- }
- /* MapLen == 0 means that the first character is a ':'
- == PathLen means that there are no '\\' or ':'
- Otherwise, Path[MapLen] == ':' for a mapping path
- or '\\' for a relative path.
- */
- if(MapLen == 0) {
- return PathError;
- }
- if(Path[MapLen] == L':') {
- if(NewPath != NULL) {
- *NewPath = &Path[MapLen + 1]; // Point to character after then ':'. Might be '\0'.
- }
- return PathMapping;
- }
- return PathRelative;
-}
-
-/* Normalize a narrow-character path and produce a wide-character path
- that has forward slashes replaced with backslashes.
- Backslashes are directory separators in UEFI File Paths.
-
- It is the caller's responsibility to eventually free() the returned buffer.
-
- @param[in] path A pointer to the narrow-character path to be normalized.
-
- @return A pointer to a buffer containing the normalized, wide-character, path.
-*/
-wchar_t *
-NormalizePath( const char *path)
-{
- wchar_t *temp;
- wchar_t *OldPath;
- wchar_t *NewPath;
- size_t Length;
-
- OldPath = AsciiStrToUnicodeStr(path, gMD->UString);
- Length = wcslen(OldPath) + 1;
-
- NewPath = calloc(Length, sizeof(wchar_t));
- if(NewPath != NULL) {
- temp = NewPath;
- for( ; *OldPath; ++OldPath) {
- if(*OldPath == L'/') {
- *temp = L'\\';
- }
- else {
- *temp = *OldPath;
- }
- ++temp;
- }
- }
- else {
- errno = ENOMEM;
- EFIerrno = RETURN_OUT_OF_RESOURCES;
- }
- return NewPath;
-}
-
-/** Process a wide character string representing a Mapping Path and extract the instance number.
-
- The instance number is the sequence of decimal digits immediately to the left
- of the ":" in the Map Name portion of a Mapping Path.
-
- This function is called with a pointer to beginning of the Map Name.
- Thus Path[Length] must be a ':' and Path[Length - 1] must be a decimal digit.
- If either of these are not true, an instance value of 0 is returned.
-
- If Path is NULL, an instance value of 0 is returned.
-
- @param[in] Path Points to the beginning of a Mapping Path
- @param[in] Length Number of valid characters to the left of the ':'
-
- @return Returns either 0 or the value of the contiguous digits to the left of the ':'.
-**/
-int
-EFIAPI
-PathInstance(
- const wchar_t *Path,
- int Length
- )
-{
- wchar_t *temp;
- int instance = 0;
-
- if((Path != NULL) && (Path[Length] == L':') && (Length > 0)) {
- for(temp = __UNCONST(&Path[Length - 1]); Length > 0; --Length) {
- if(!iswdigit(*temp)) {
- break;
- }
- --temp;
- }
- instance = (int)wcstol(temp+1, NULL, 10);
- }
- return instance;
-}
-
-/** Transform a relative path into an absolute path.
-
- If Path is NULL, return NULL.
- Otherwise, pre-pend the CWD to Path then process the resulting path to:
- - Replace "/./" with "/"
- - Replace "/<dirname>/../" with "/"
- - Do not allow one to back up past the root, "/"
-
- Also sets the Current Working Device to the Root Device.
-
- Path must be a previously allocated buffer. PathAdjust will
- allocate a new buffer to hold the results of the transformation
- and free Path. A pointer to the newly allocated buffer is returned.
-
- @param[in] Path A pointer to the path to be transformed. This buffer
- will always be freed.
-
- @return A pointer to a buffer containing the transformed path.
-**/
-wchar_t *
-EFIAPI
-PathAdjust(
- wchar_t *Path
- )
-{
- wchar_t *NewPath;
-
- NewPath = calloc(PATH_MAX, sizeof(wchar_t));
- if(NewPath != NULL) {
- wmemcpy(NewPath, Path, PATH_MAX);
- }
- else {
- errno = ENOMEM;
- }
- free(Path);
- return NewPath;
-}
-
-/** Replace the leading portion of Path with any aliases.
-
- Aliases are read from /etc/fstab. If there is an associated device, the
- Current Working Device is set to that device.
-
- Path must be a previously allocated buffer. PathAlias will
- allocate a new buffer to hold the results of the transformation
- then free Path. A pointer to the newly allocated buffer is returned.
-
- @param[in] Path A pointer to the original, unaliased, path. This
- buffer is always freed.
- @param[out] Node Filled in with a pointer to the Device Node describing
- the device abstraction associated with this path.
-
- @return A pointer to a buffer containing the aliased path.
-**/
-wchar_t *
-EFIAPI
-PathAlias(
- wchar_t *Path,
- DeviceNode **Node
- )
-{
- wchar_t *NewPath;
-
- NewPath = calloc(PATH_MAX, sizeof(wchar_t));
- if(NewPath != NULL) {
- wmemcpy(NewPath, Path, PATH_MAX);
- }
- else {
- errno = ENOMEM;
- }
- free(Path);
- *Node = NULL;
- return NewPath;
-}
-
-/** Parse a path producing the target device, device instance, and file path.
-
- It is the caller's responsibility to free() FullPath and MapPath when they
- are no longer needed.
-
- @param[in] path
- @param[out] FullPath
- @param[out] DevNode
- @param[out] Which
- @param[out] MapPath OPTIONAL. If not NULL, it points to the place to save a pointer
- to the extracted map name. If the path didn't have a map name,
- then *MapPath is set to NULL.
-
- @retval RETURN_SUCCESS The path was parsed successfully.
- @retval RETURN_NOT_FOUND The path does not map to a valid device.
- @retval RETURN_OUT_OF_RESOURCES Insufficient memory to calloc a MapName buffer.
- The errno variable is set to ENOMEM.
- @retval RETURN_INVALID_PARAMETER The path parameter is not valid.
- The errno variable is set to EINVAL.
-**/
-RETURN_STATUS
-EFIAPI
-ParsePath(
- IN const char *path,
- OUT wchar_t **FullPath,
- OUT DeviceNode **DevNode,
- OUT int *Which,
- OUT wchar_t **MapPath
- )
-{
- int MapLen;
- PATH_CLASS PathClass;
- wchar_t *NewPath;
- wchar_t *WPath = NULL;
- wchar_t *MPath = NULL;
- DeviceNode *Node = NULL;
- RETURN_STATUS Status = RETURN_NOT_FOUND;
- int Instance = 0;
- BOOLEAN ReMapped;
-
- ReMapped = FALSE;
-
- // Convert name from MBCS to WCS and change '/' to '\\'
- WPath = NormalizePath( path);
- PathClass = ClassifyPath(WPath, &NewPath, &MapLen);
-
-reclassify:
- switch(PathClass) {
- case PathMapping:
- if(!ReMapped) {
- if((NewPath == NULL) || (*NewPath == L'\0')) { /* Nothing after the ':' */
- PathClass = PathAbsolute;
- }
- else {
- Instance = PathInstance(WPath, MapLen);
- PathClass = ClassifyPath(NewPath, NULL, NULL);
- }
- ReMapped = TRUE;
- if(WPath[MapLen] == L':') {
- // Get the Map Name, including the trailing ':'. */
- MPath = calloc(MapLen+2, sizeof(wchar_t));
- if(MPath != NULL) {
- wmemcpy(MPath, WPath, MapLen+1);
- }
- else {
- errno = ENOMEM;
- Status = RETURN_OUT_OF_RESOURCES;
- break; // Exit the switch(PathClass) statement.
- }
- }
- if(WPath != NewPath) {
- /* Shift the RHS of the path down to the start of the buffer. */
- wmemmove(WPath, NewPath, wcslen(NewPath)+1);
- NewPath = WPath;
- }
- goto reclassify;
- }
- /* Fall through to PathError if Remapped.
- This means that the path looked like "foo:bar:something".
- */
-
- case PathError:
- errno = EINVAL;
- Status = RETURN_INVALID_PARAMETER;
- break;
-
- case PathRelative:
- /* Transform a relative path into an Absolute path.
- Prepends CWD and handles ./ and ../ entries.
- It is the caller's responsibility to free the space
- allocated to WPath.
- */
- WPath = PathAdjust(NewPath); // WPath was malloc()ed by PathAdjust
-
- case PathAbsolute:
- /* Perform any path aliasing. For example: /dev/foo -> { node.foo, "" }
- The current volume and directory are updated in the path as needed.
- It is the caller's responsibility to free the space
- allocated to WPath.
- */
- Status = RETURN_SUCCESS;
- WPath = PathAlias(WPath, &Node); // PathAlias frees its argument and malloc()s a new one.
- break;
- }
- if(!RETURN_ERROR(Status)) {
- *FullPath = WPath;
- *Which = Instance;
- if(MapPath != NULL) {
- *MapPath = MPath;
- }
- else if(MPath != NULL) {
- free(MPath); /* Caller doesn't want it so let MPath go free */
- }
-
- /* At this point, WPath is an absolute path,
- MPath is either NULL or points to the Map Name,
- and Instance is the instance number.
- */
- if(MPath == NULL) {
- /* This is NOT a mapped path. */
- if(Node == NULL) {
- Node = daDefaultDevice;
- }
- if(Node != NULL) {
- Status = RETURN_SUCCESS;
- }
- else {
- Status = RETURN_NOT_FOUND;
- }
- }
- else {
- /* This is a mapped path. */
- Status = __DevSearch( MPath, NULL, &Node);
- if(Status == RETURN_NOT_FOUND) {
- Node = daDefaultDevice;
-
- if(Node != NULL) {
- Status = RETURN_SUCCESS;
- }
- }
- }
- if(DevNode != NULL) {
- *DevNode = Node;
- }
- }
- return Status;
-}
-
-/**
- Parses a normalized wide character path and returns a pointer to the entry
- following the last \. If a \ is not found in the path the return value will
- be the same as the input value. All error conditions return NULL.
-
- The behavior when passing in a path that has not been normalized is undefined.
-
- @param Path - A pointer to a wide character string containing a path to a
- directory or a file.
-
- @return Pointer to the file name or terminal directory. NULL if an error is
- detected.
-**/
-wchar_t *
-EFIAPI
-GetFileNameFromPath (
- const wchar_t *Path
- )
-{
- wchar_t *Tail;
-
- if (Path == NULL) {
- return NULL;
- }
-
- Tail = wcsrchr(Path, L'\\');
- if(Tail == NULL) {
- Tail = (wchar_t *) Path;
- } else {
- // Move to the next character after the '\\' to get the file name.
- Tail++;
- }
-
- return Tail;
-}
diff --git a/StdLib/LibC/Uefi/Devices/daConsole.inf b/StdLib/LibC/Uefi/Devices/daConsole.inf
deleted file mode 100644
index e23193f4e2..0000000000
--- a/StdLib/LibC/Uefi/Devices/daConsole.inf
+++ /dev/null
@@ -1,52 +0,0 @@
-## @file
-# Standard C library: Console Device Abstraction.
-#
-# Copyright (c) 2011 - 2012, 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 = DevConsole
- FILE_GUID = f6937495-1f44-4a8a-8a1b-5a669f9396f6
- MODULE_TYPE = UEFI_APPLICATION
- VERSION_STRING = 1.0
- LIBRARY_CLASS = DevConsole
- CONSTRUCTOR = __Cons_construct
- DESTRUCTOR = __Cons_deconstruct
-
-#
-# VALID_ARCHITECTURES = IA32 X64 IPF
-#
-
-[Sources]
- Console/daConsole.c
-
-[Packages]
- StdLib/StdLib.dec
- StdLibPrivateInternalFiles/DoNotUse.dec
- MdePkg/MdePkg.dec
- ShellPkg/ShellPkg.dec
-
-[LibraryClasses]
- BaseLib
- BaseMemoryLib
- MemoryAllocationLib
- UefiBootServicesTableLib
- LibC
- LibWchar
- LibUefi
- LibIIO
- DevUtility
-
-[Protocols]
- gEfiSimpleTextInProtocolGuid ## CONSUMED
- gEfiSimpleTextOutProtocolGuid ## CONSUMED
diff --git a/StdLib/LibC/Uefi/Devices/daShell.inf b/StdLib/LibC/Uefi/Devices/daShell.inf
deleted file mode 100644
index 7c456cb652..0000000000
--- a/StdLib/LibC/Uefi/Devices/daShell.inf
+++ /dev/null
@@ -1,52 +0,0 @@
-## @file
-# Standard C library: Shell-Hosted Device Abstraction.
-#
-# When this library is included in an application, it creates the default device.
-# This allows every device type not recognized to be passed to the shell for processing.
-#
-# Copyright (c) 2011, 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 = DevShell
- FILE_GUID = 0a1d4fd8-4704-4501-85eb-93399492cbed
- MODULE_TYPE = UEFI_APPLICATION
- VERSION_STRING = 1.0
- LIBRARY_CLASS = DevShell
- LIBRARY_CLASS = DevMedia
- CONSTRUCTOR = __ctor_DevShell
- DESTRUCTOR = __dtor_DevShell
-
-#
-# VALID_ARCHITECTURES = IA32 X64 IPF
-#
-
-[Sources]
- UefiShell/daShell.c
-
-[Packages]
- StdLib/StdLib.dec
- StdLibPrivateInternalFiles/DoNotUse.dec
- MdePkg/MdePkg.dec
- ShellPkg/ShellPkg.dec
-
-[LibraryClasses]
- BaseLib
- MemoryAllocationLib
- UefiBootServicesTableLib
- LibC
- LibString
- LibStdLib
- LibWchar
- LibUefi
- DevUtility
diff --git a/StdLib/LibC/Uefi/Devices/daUtility.inf b/StdLib/LibC/Uefi/Devices/daUtility.inf
deleted file mode 100644
index 6bdc1eead9..0000000000
--- a/StdLib/LibC/Uefi/Devices/daUtility.inf
+++ /dev/null
@@ -1,44 +0,0 @@
-## @file
-# Standard C library: Console Device Abstraction.
-#
-# Copyright (c) 2011, 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 = DevUtility
- FILE_GUID = d6a9928c-3397-4dd1-818f-c664ba6dcaaf
- MODULE_TYPE = UEFI_APPLICATION
- VERSION_STRING = 1.0
- LIBRARY_CLASS = DevUtility
-
-#
-# VALID_ARCHITECTURES = IA32 X64 IPF
-#
-
-[Sources]
- Utility/DevGenisis.c
- Utility/DevSearch.c
- Utility/Path.c
-
-[Packages]
- StdLib/StdLib.dec
- StdLibPrivateInternalFiles/DoNotUse.dec
- MdePkg/MdePkg.dec
- ShellPkg/ShellPkg.dec
-
-[LibraryClasses]
- BaseLib
- BaseMemoryLib
- MemoryAllocationLib
- LibC
- LibWchar
- LibUefi
diff --git a/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c b/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c
deleted file mode 100644
index 8c8e076d80..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/** @file
- Canonical Interactive Input Function.
-
- The functions assume that isatty() is TRUE at the time they are called.
-
- Copyright (c) 2012 - 2014, 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.
-**/
-#include <Uefi.h>
-
-#include <LibConfig.h>
-
-#include <errno.h>
-#include <sys/syslimits.h>
-#include <sys/termios.h>
-#include <Device/IIO.h>
-#include <MainData.h>
-#include "IIOutilities.h"
-#include "IIOechoCtrl.h"
-
-/** Read a line from the input file in canonical mode.
- Perform echoing and input processing as directed by the termios flags.
-
- @param[in] filp A pointer to a file descriptor structure.
-
- @return The number of characters in the input buffer, or -1 if there
- was an error.
-**/
-ssize_t
-IIO_CanonRead (
- struct __filedes *filp
- )
-{
- cIIO *This;
- cFIFO *InBuf;
- struct termios *Termio;
- struct __filedes *fpOut;
- size_t NumRead;
- wint_t InChar;
- tcflag_t IFlag;
- tcflag_t LFlag;
- BOOLEAN EchoIsOK;
- BOOLEAN Activate;
- BOOLEAN FirstRead;
- int OutMode;
- UINTN MaxColumn;
- UINTN MaxRow;
-
- NumRead = MAX_INPUT; // Workaround "potentially uninitialized" warning
- EchoIsOK = FALSE;
- FirstRead = TRUE;
- This = filp->devdata;
- Termio = &This->Termio;
- InBuf = This->InBuf;
-
- // Get a copy of the flags we are going to use
- IFlag = Termio->c_iflag;
- LFlag = Termio->c_lflag;
-
- /* Determine what the current screen size is. Also validates the output device. */
- OutMode = IIO_GetOutputSize(STDOUT_FILENO, &MaxColumn, &MaxRow);
- if(OutMode >= 0) {
- /* Set the maximum screen dimensions. */
- This->MaxColumn = MaxColumn;
- This->MaxRow = MaxRow;
-
- /* Record where the cursor is at the beginning of this Input operation.
- The currently set stdout device is used to determine this. If there is
- no stdout, or stdout is not an interactive device, nothing is recorded.
- */
- if (IIO_GetCursorPosition(STDOUT_FILENO, &This->InitialXY.Column, &This->InitialXY.Row) >= 0) {
- This->CurrentXY.Column = This->InitialXY.Column;
- This->CurrentXY.Row = This->InitialXY.Row;
- EchoIsOK = TRUE; // Can only echo to stdout
- }
- }
-
- // For now, we only echo to stdout.
- fpOut = &gMD->fdarray[STDOUT_FILENO];
-
- // Input and process characters until BufferSize is exhausted.
- do {
- InChar = IIO_GetInChar(filp, FirstRead);
- if (InChar == WEOF) {
- NumRead = 0;
- break;
- }
- FirstRead = FALSE;
- Activate = TRUE;
- if(InChar == CHAR_CARRIAGE_RETURN) {
- if((IFlag & IGNCR) != 0) {
- continue; // Restart the do loop, discarding the CR
- }
- else if((IFlag & ICRNL) != 0) {
- InChar = L'\n';
- }
- }
- else if(InChar == CHAR_LINEFEED) {
- if((IFlag & INLCR) != 0) {
- InChar = L'\r';
- }
- }
- else if(CCEQ(Termio->c_cc[VINTR], InChar)) {
- if((LFlag & ISIG) != 0) {
- // Raise Signal
- // Flush Input Buffer
- // Return to caller
- InChar = IIO_ECHO_DISCARD;
- errno = EINTR;
- }
- else {
- Activate = FALSE;
- }
- }
- else if(CCEQ(Termio->c_cc[VQUIT], InChar)) {
- if((LFlag & ISIG) != 0) {
- // Raise Signal
- // Flush Input Buffer
- // Return to caller
- InChar = IIO_ECHO_DISCARD;
- errno = EINTR;
- }
- else {
- Activate = FALSE;
- }
- }
- else if(CCEQ(Termio->c_cc[VEOF], InChar)) {
- InChar = WEOF;
- NumRead = 0;
- EchoIsOK = FALSE; // Buffer, but don't echo this character
- }
- else if(CCEQ(Termio->c_cc[VEOL], InChar)) {
- EchoIsOK = FALSE; // Buffer, but don't echo this character
- }
- else if(CCEQ(Termio->c_cc[VERASE], InChar)) {
- InChar = IIO_ECHO_ERASE;
- Activate = FALSE;
- }
- else if(CCEQ(Termio->c_cc[VKILL], InChar)) {
- InChar = IIO_ECHO_KILL;
- Activate = FALSE;
- }
- else {
- if((InChar < TtySpecKeyMin) || (InChar >= TtyFunKeyMax)) {
- Activate = FALSE;
- }
- }
- /** The Echo function is responsible for:
- * Adding the character to the input buffer, if appropriate.
- * Removing characters from the input buffer for ERASE and KILL processing.
- * Visually removing characters from the screen if ECHOE is set.
- * Ensuring one can not backspace beyond the beginning of the input text.
- * Sending final echo strings to output.
- **/
- (void)This->Echo(fpOut, (wchar_t)InChar, EchoIsOK);
- NumRead = InBuf->Count(InBuf, AsElements);
- } while((NumRead < MAX_INPUT) &&
- (Activate == FALSE));
-
- return (ssize_t)NumRead;
-}
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIO.c b/StdLib/LibC/Uefi/InteractiveIO/IIO.c
deleted file mode 100644
index 65b61d9bcc..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/IIO.c
+++ /dev/null
@@ -1,373 +0,0 @@
-/** @file
- Definitions for the Interactive IO library.
-
- The functions assume that isatty() is TRUE at the time they are called.
-
- Copyright (c) 2012, 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.
-**/
-#include <Uefi.h>
-#include <Library/MemoryAllocationLib.h>
-
-#include <LibConfig.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <sys/syslimits.h>
-#include <sys/termios.h>
-#include <Device/IIO.h>
-#include <MainData.h>
-#include "IIOutilities.h"
-#include "IIOechoCtrl.h"
-
-/** Read from an Interactive IO device.
-
- NOTE: If _S_IWTTY is set, the internal buffer contains WIDE characters.
- They will need to be converted to MBCS when returned.
-
- Input is line buffered if ICANON is set,
- otherwise MIN determines how many characters to input.
- Currently MIN is always zero, meaning 0 or 1 character is input in
- noncanonical mode.
-
- @param[in] filp Pointer to the descriptor of the device (file) to be read.
- @param[in] BufferSize Maximum number of bytes to be returned to the caller.
- @param[out] Buffer Pointer to the buffer where the input is to be stored.
-
- @retval -1 An error occurred. No data is available.
- @retval 0 No data was available. Try again later.
- @retval >0 The number of bytes consumed by the returned data.
-**/
-static
-ssize_t
-EFIAPI
-IIO_Read(
- struct __filedes *filp,
- size_t BufferSize,
- VOID *Buffer
- )
-{
- cIIO *This;
- ssize_t NumRead;
- tcflag_t Flags;
- size_t XlateSz;
- size_t Needed;
-
- NumRead = -1;
- This = filp->devdata;
- if(This != NULL) {
- Flags = This->Termio.c_lflag;
- if(Flags & ICANON) {
- NumRead = IIO_CanonRead(filp);
- }
- else {
- NumRead = IIO_NonCanonRead(filp);
- }
- // At this point, the input has been accumulated in the input buffer.
- if(filp->f_iflags & _S_IWTTY) {
- // Data in InBuf is wide characters. Convert to MBCS
- // First, convert into a linear buffer
- NumRead = This->InBuf->Copy(This->InBuf, gMD->UString2, (INT32)UNICODE_STRING_MAX-1);
- gMD->UString2[NumRead] = 0; // Ensure that the buffer is terminated
- // Determine the needed space
- XlateSz = EstimateWtoM((const wchar_t *)gMD->UString2, BufferSize, &Needed);
-
- // Now translate this into MBCS in Buffer
- NumRead = wcstombs((char *)Buffer, (const wchar_t *)gMD->UString2, XlateSz);
-
- // Consume the translated characters
- (void)This->InBuf->Flush(This->InBuf, Needed);
- }
- else {
- // Data in InBuf is narrow characters. Use verbatim.
- NumRead = This->InBuf->Read(This->InBuf, Buffer, (INT32)BufferSize);
- }
- }
- return NumRead;
-}
-
-/** Process characters from buffer buf and write them to the output device
- specified by filp.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] buf Pointer to the MBCS string to be output.
- @param[in] N Number of bytes in buf.
-
- @retval >=0 Number of bytes sent to the output device.
-**/
-static
-ssize_t
-EFIAPI
-IIO_Write(
- struct __filedes *filp,
- const char *buf,
- ssize_t N
- )
-{
- cIIO *This;
- cFIFO *OutBuf;
- mbstate_t *OutState;
- char *MbcsPtr;
- ssize_t NumWritten;
- ssize_t NumProc;
- size_t CharLen;
- UINTN MaxColumn;
- UINTN MaxRow;
- wchar_t OutChar[2]; // Just in case we run into 4-byte MBCS character
- int OutMode;
-
- errno = 0; // indicate no error as default
- NumWritten = -1;
-
- /* Determine what the current screen size is. Also validates the output device. */
- OutMode = IIO_GetOutputSize(filp->MyFD, &MaxColumn, &MaxRow);
-
- This = filp->devdata;
- if((This != NULL) && (OutMode >= 0)) {
- if(filp->MyFD == STDERR_FILENO) {
- OutBuf = This->ErrBuf;
- OutState = &This->ErrState;
- }
- else {
- OutBuf = This->OutBuf;
- OutState = &This->OutState;
- }
-
- /* Set the maximum screen dimensions. */
- This->MaxColumn = MaxColumn;
- This->MaxRow = MaxRow;
-
- /* Record where the cursor is at the beginning of the Output operation. */
- (void)IIO_GetCursorPosition(filp->MyFD, &This->InitialXY.Column, &This->InitialXY.Row);
- This->CurrentXY.Column = This->InitialXY.Column;
- This->CurrentXY.Row = This->InitialXY.Row;
-
-
- NumWritten = 0;
- OutChar[0] = (wchar_t)buf[0];
- while((OutChar[0] != 0) && (NumWritten < N)) {
- CharLen = mbrtowc(OutChar, (const char *)&buf[NumWritten], MB_CUR_MAX, OutState);
- NumProc = IIO_WriteOne(filp, OutBuf, OutChar[0]);
- if(NumProc > 0) {
- // Successfully processed and buffered one character
- NumWritten += CharLen; // Index of start of next character
- }
- else if(NumProc == -1) {
- // Encoding Error
- (void)mbrtowc(NULL, NULL, 1, OutState); // Re-Initialize the conversion state
- errno = EILSEQ;
- break;
- }
- else {
- // Last character was incomplete
- break;
- }
- }
- // At this point, the characters to write are in OutBuf
- // First, linearize the buffer
- NumWritten = OutBuf->Copy(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);
- gMD->UString[NumWritten] = 0; // Ensure that the buffer is terminated
-
- if(filp->f_iflags & _S_IWTTY) {
- // Output device expects wide characters, Output what we have
- NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, gMD->UString);
- }
- else {
- // Output device expects narrow characters, convert to MBCS
- MbcsPtr = (char *)gMD->UString2;
- // Determine the needed space
- NumProc = (ssize_t)EstimateWtoM((const wchar_t *)gMD->UString, UNICODE_STRING_MAX * sizeof(wchar_t), &CharLen);
-
- // Now translate this into MBCS in Buffer
- NumWritten = wcstombs(MbcsPtr, (const wchar_t *)gMD->UString, NumProc);
- MbcsPtr[NumWritten] = 0; // Ensure the buffer is terminated
-
- // Send the MBCS buffer to Output
- NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, MbcsPtr);
- }
- // Consume the translated characters
- (void)OutBuf->Flush(OutBuf, NumWritten);
- }
- else {
- if(This == NULL) {
- errno = EINVAL;
- }
- // Otherwise, errno is already set.
- }
- return NumWritten;
-}
-
-/** Echo a character to an output device.
- Performs translation and edit processing depending upon termios flags.
-
- @param[in] filp A pointer to a file descriptor structure.
- @param[in] EChar The character to echo.
- @param[in] EchoIsOK TRUE if the caller has determined that characters
- should be echoed. Otherwise, just buffer.
-
- @return Returns the number of characters actually output.
-**/
-static
-ssize_t
-EFIAPI
-IIO_Echo(
- struct __filedes *filp,
- wchar_t EChar,
- BOOLEAN EchoIsOK
- )
-{
- cIIO *This;
- ssize_t NumWritten;
- cFIFO *OutBuf;
- char *MbcsPtr;
- ssize_t NumProc;
- tcflag_t LFlags;
-
- NumWritten = -1;
- This = filp->devdata;
- if(This != NULL) {
- OutBuf = This->OutBuf;
- LFlags = This->Termio.c_lflag & (ECHOK | ECHOE);
-
- if((EChar >= TtyFunKeyMin) && (EChar < TtyFunKeyMax)) {
- // A special function key was pressed, buffer it, don't echo, and activate.
- // Process and buffer the character. May produce multiple characters.
- NumProc = IIO_EchoOne(filp, EChar, FALSE); // Don't echo this character
- EChar = CHAR_LINEFEED; // Every line must end with '\n' (legacy)
- }
- // Process and buffer the character. May produce multiple characters.
- NumProc = IIO_EchoOne(filp, EChar, EchoIsOK);
-
- // At this point, the character(s) to write are in OutBuf
- // First, linearize the buffer
- NumWritten = OutBuf->Copy(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);
- gMD->UString[NumWritten] = 0; // Ensure that the buffer is terminated
-
- if((EChar == IIO_ECHO_KILL) && (LFlags & ECHOE) && EchoIsOK) {
- // Position the cursor to the start of input.
- (void)IIO_SetCursorPosition(filp, &This->InitialXY);
- }
- // Output the buffer
- if(filp->f_iflags & _S_IWTTY) {
- // Output device expects wide characters, Output what we have
- NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, gMD->UString);
- }
- else {
- // Output device expects narrow characters, convert to MBCS
- MbcsPtr = (char *)gMD->UString2;
- // Determine the needed space
- NumProc = (ssize_t)EstimateWtoM((const wchar_t *)gMD->UString, UNICODE_STRING_MAX * sizeof(wchar_t), NULL);
-
- // Now translate this into MBCS in Buffer
- NumWritten = wcstombs(MbcsPtr, (const wchar_t *)gMD->UString, NumProc);
- MbcsPtr[NumWritten] = 0; // Ensure the buffer is terminated
-
- // Send the MBCS buffer to Output
- NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, MbcsPtr);
- }
- // Consume the echoed characters
- (void)OutBuf->Flush(OutBuf, NumWritten);
-
- if(EChar == IIO_ECHO_KILL) {
- if(LFlags == ECHOK) {
- NumWritten = IIO_WriteOne(filp, OutBuf, CHAR_LINEFEED);
- }
- else if((LFlags & ECHOE) && EchoIsOK) {
- // Position the cursor to the start of input.
- (void)IIO_SetCursorPosition(filp, &This->InitialXY);
- }
- NumWritten = 0;
- }
- }
- else {
- errno = EINVAL;
- }
-
- return NumWritten;
-}
-
-static
-void
-FifoDelete(cFIFO *Member)
-{
- if(Member != NULL) {
- Member->Delete(Member);
- }
-}
-
-/** Destructor for an IIO instance.
-
- Releases all resources used by a particular IIO instance.
-**/
-static
-void
-EFIAPI
-IIO_Delete(
- cIIO *Self
- )
-{
- if(Self != NULL) {
- FifoDelete(Self->ErrBuf);
- FifoDelete(Self->OutBuf);
- FifoDelete(Self->InBuf);
- if(Self->AttrBuf != NULL) {
- FreePool(Self->AttrBuf);
- }
- FreePool(Self);
- }
-}
-
-/** Constructor for new IIO instances.
-
- @return Returns NULL or a pointer to a new IIO instance.
-**/
-cIIO *
-EFIAPI
-New_cIIO(void)
-{
- cIIO *IIO;
- cc_t *TempBuf;
- int i;
-
- IIO = (cIIO *)AllocateZeroPool(sizeof(cIIO));
- if(IIO != NULL) {
- IIO->InBuf = New_cFIFO(MAX_INPUT, sizeof(wchar_t));
- IIO->OutBuf = New_cFIFO(MAX_OUTPUT, sizeof(wchar_t));
- IIO->ErrBuf = New_cFIFO(MAX_OUTPUT, sizeof(wchar_t));
- IIO->AttrBuf = (UINT8 *)AllocateZeroPool(MAX_OUTPUT);
-
- if((IIO->InBuf == NULL) || (IIO->OutBuf == NULL) ||
- (IIO->ErrBuf == NULL) || (IIO->AttrBuf == NULL))
- {
- IIO_Delete(IIO);
- IIO = NULL;
- }
- else {
- IIO->Delete = IIO_Delete;
- IIO->Read = IIO_Read;
- IIO->Write = IIO_Write;
- IIO->Echo = IIO_Echo;
- }
- // Initialize Termio member
- TempBuf = &IIO->Termio.c_cc[0];
- TempBuf[0] = 8; // Default length for TABs
- for(i=1; i < NCCS; ++i) {
- TempBuf[i] = _POSIX_VDISABLE;
- }
- TempBuf[VMIN] = 0;
- TempBuf[VTIME] = 0;
- IIO->Termio.c_ispeed = B115200;
- IIO->Termio.c_ospeed = B115200;
- IIO->Termio.c_iflag = ICRNL;
- IIO->Termio.c_oflag = OPOST | ONLCR | ONOCR | ONLRET;
- IIO->Termio.c_cflag = 0;
- IIO->Termio.c_lflag = ECHO | ECHONL;
- }
- return IIO;
-}
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIO.inf b/StdLib/LibC/Uefi/InteractiveIO/IIO.inf
deleted file mode 100644
index dd21e85b13..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/IIO.inf
+++ /dev/null
@@ -1,51 +0,0 @@
-## @file
-# Interactive I/O Library.
-#
-# Copyright (c) 2012, 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 = LibIIO
- FILE_GUID = c1e9fffb-5557-4cb5-a5f5-1fbd902a74ed
- MODULE_TYPE = UEFI_APPLICATION
- VERSION_STRING = 1.0
- LIBRARY_CLASS = LibIIO
-
-#
-# VALID_ARCHITECTURES = IA32 X64
-#
-
-[Sources]
- IIO.c
- NonCanonRead.c
- CanonRead.c
- TerminalFunctions.c
- IIOutilities.c
- IIOwrite.c
- IIOecho.c
-
-[Packages]
- MdePkg/MdePkg.dec
- StdLib/StdLib.dec
- StdLibPrivateInternalFiles/DoNotUse.dec
-
-[LibraryClasses]
- BaseLib
- BaseMemoryLib
- MemoryAllocationLib
- LibC
- LibWchar
- LibContainer
-
-[Protocols]
- gEfiSimpleTextInProtocolGuid ## CONSUMES
- gEfiSimpleTextOutProtocolGuid ## CONSUMES
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIOecho.c b/StdLib/LibC/Uefi/InteractiveIO/IIOecho.c
deleted file mode 100644
index 14369de95b..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/IIOecho.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/** @file
- Echo characters to an Interactive I/O Output device.
-
- The functions assume that isatty() is TRUE at the time they are called.
- Since the UEFI console is a WIDE character device, these functions do all
- processing using wide characters.
-
- It is the responsibility of the caller, or higher level function, to perform
- any necessary translation between wide and narrow characters.
-
- Copyright (c) 2012, 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.
-**/
-#include <Uefi.h>
-
-#include <LibConfig.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <sys/termios.h>
-#include <Device/IIO.h>
-#include "IIOutilities.h"
-#include "IIOechoCtrl.h"
-
-/** Echo one character to an IIO file.
-
- If character InCh is a special "echo control" character, process it and output
- the resultant character(s), if any. Otherwise pass the character on to the
- IIO_WriteOne() function which performs generic output processing, if needed.
-
- @param[in] filp Pointer to an open IIO file's file descriptor structure.
- @param[in] InCh The wide character to be echoed.
- @param[in] EchoIsOK A flag indicating whether echoing is appropriate for this
- device or not.
-
- @retval -1 The filp argument does not refer to an IIO device.
- Global value errno is set to EINVAL.
- @retval >=0 The number of characters actually output.
-
- @sa IIO_WriteOne
-**/
-ssize_t
-IIO_EchoOne (
- struct __filedes *filp,
- wchar_t InCh,
- BOOLEAN EchoIsOK
- )
-{
- cIIO *This;
- cFIFO *OutBuf;
- cFIFO *InBuf;
- UINT8 *AttrBuf;
- ssize_t NumEcho;
- tcflag_t LFlags;
- UINT32 AttrDex;
- int i;
-
- NumEcho = -1;
- This = filp->devdata;
-
- if(This != NULL) {
- LFlags = This->Termio.c_lflag;
- OutBuf = This->OutBuf;
- InBuf = This->InBuf;
- AttrBuf = This->AttrBuf;
- AttrDex = InBuf->GetWDex(InBuf);
-
- switch(InCh) {
- case IIO_ECHO_DISCARD:
- // Do not buffer or otherwise process
- NumEcho = 0;
- break;
-
- case IIO_ECHO_ERASE:
- // Delete last character from InBuf
- if(!InBuf->IsEmpty(InBuf)) {
- (void)InBuf->Truncate(InBuf);
-
- // Erase screen character(s) based on Attrib value
- if(LFlags & ECHO) {
- AttrDex = (UINT32)ModuloDecrement(AttrDex, InBuf->NumElements);
- NumEcho = AttrBuf[AttrDex];
- for(i = 0; i < NumEcho; ++i) {
- (void)IIO_WriteOne(filp, OutBuf, CHAR_BACKSPACE);
- }
- if(LFlags & ECHOE) {
- for(i = 0; i < NumEcho; ++i) {
- (void)IIO_WriteOne(filp, OutBuf, L' ');
- }
- for(i = 0; i < NumEcho; ++i) {
- (void)IIO_WriteOne(filp, OutBuf, CHAR_BACKSPACE);
- }
- }
- }
- else {
- NumEcho = 0;
- }
- }
- break;
-
- case IIO_ECHO_KILL:
- // Flush contents of InBuf and OutBuf
- InBuf->Flush(InBuf, (size_t)-1);
- OutBuf->Flush(OutBuf, (size_t)-1);
-
- // Erase characters from screen.
- if(LFlags & ECHOE) {
- NumEcho = IIO_CursorDelta(This, &This->InitialXY, &This->CurrentXY);
- for(i = 0; i < NumEcho; ++i) {
- (void)IIO_WriteOne(filp, OutBuf, L' ');
- }
- }
- break;
-
- default:
- // Add character to input buffer
- (void)InBuf->Write(InBuf, &InCh, 1);
-
- NumEcho = 0; // In case echoing is not enabled or OK
- // If echoing is OK and enabled, "echo" character using IIO_WriteOne
- if( EchoIsOK &&
- ( (LFlags & ECHO) ||
- ((LFlags & ECHONL) && (InCh == CHAR_LINEFEED))))
- {
- NumEcho = IIO_WriteOne(filp, OutBuf, InCh);
- }
- AttrBuf[AttrDex] = (UINT8)NumEcho;
- break;
- }
- }
- else {
- errno = EINVAL;
- }
- return NumEcho;
-}
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h b/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h
deleted file mode 100644
index 068a7203ef..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/** @file
- Constants and declarations for the Echo function.
-
- Copyright (c) 2012 - 2014, 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.
-**/
-#ifndef _IIO_ECHO_CTRL_H
-#define _IIO_ECHO_CTRL_H
-#include <sys/termios.h>
-
-__BEGIN_DECLS
-
-/* These constants are assigned values within the Unicode Private Use range.
- The value of IIO_ECHO_MIN must be adjusted to ensure that IIO_ECHO_MAX
- never exceeds the value of (TtyFunKeyMin - 1).
-*/
-typedef enum {
- IIO_ECHO_MIN = (TtySpecKeyMin),
- IIO_ECHO_DISCARD = IIO_ECHO_MIN, // Ignore this character completely
- IIO_ECHO_ERASE, // Erase previous character
- IIO_ECHO_KILL, // Kill the entire line
- IIO_ECHO_MAX
-} IioEchoCtrl;
-
-__END_DECLS
-
-#endif /* _IIO_ECHO_CTRL_H */
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c b/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c
deleted file mode 100644
index 2e61cd1e80..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c
+++ /dev/null
@@ -1,290 +0,0 @@
-/** @file
- Utilities for Interactive I/O Functions.
-
- The functions assume that isatty() is TRUE at the time they are called.
-
- Copyright (c) 2012 - 2014, 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.
-**/
-#include <Uefi.h>
-#include <Protocol/SimpleTextOut.h>
-
-#include <LibConfig.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <sys/syslimits.h>
-#include <sys/termios.h>
-#include <Device/IIO.h>
-#include <MainData.h>
-#include "IIOutilities.h"
-
-/** Get the low-level UEFI protocol associated with an open file.
-
- @param[in] fd File descriptor for an open file.
- @param[out] filp NULL, or a pointer to where a pointer to the file's
- file descriptor structure is to be stored.
-
- @return Returns NULL if fd is not a valid file descriptor, otherwise
- a pointer to the file's associated UEFI protocol is returned.
-**/
-void *
-EFIAPI
-IIO_GetDeviceProto (
- int fd,
- struct __filedes **filp
- )
-{
- void *Proto;
- ConInstance *Stream;
- struct __filedes *pfil;
-
- Proto = NULL;
- if(ValidateFD( fd, VALID_OPEN)) {
- pfil = &gMD->fdarray[fd];
- Stream = BASE_CR(pfil->f_ops, ConInstance, Abstraction);
- Proto = (void *)Stream->Dev;
- if(filp != NULL) {
- *filp = pfil;
- }
- }
- return Proto;
-}
-
-/** Get a character either from the input buffer or from hardware.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] First Set to TRUE to identify the initial read.
-
- @return Returns a character read from either the input buffer
- or from the open file (device) identified by filp.
- A return value of WEOF indicates an error has occurred.
-**/
-wint_t
-EFIAPI
-IIO_GetInChar (
- struct __filedes *filp,
- BOOLEAN First
-)
-{
- cIIO *This;
- cFIFO *InBuf;
- size_t Status;
- ssize_t NumRead;
- wint_t RetVal;
- wchar_t InChar;
-
- static size_t BufCnt;
-
- This = filp->devdata;
- InBuf = This->InBuf;
-
- NumRead = -1;
- InChar = 0;
- if(First) {
- BufCnt = InBuf->Count(InBuf, AsElements);
- }
- if(BufCnt > 0) {
- Status = InBuf->Read(InBuf, &InChar, 1);
- if (Status > 0) {
- --BufCnt;
- NumRead = 1;
- }
- }
- else {
- NumRead = filp->f_ops->fo_read(filp, &filp->f_offset, sizeof(wchar_t), &InChar);
- }
- if(NumRead <= 0) {
- RetVal = WEOF;
- }
- else {
- RetVal = (wint_t)InChar;
- }
- return RetVal;
-}
-
-/** Get the current cursor position.
-
- @param[in] fd File descriptor for an open file.
- @param[out] Column Pointer to where the current cursor column is to be stored.
- @param[out] Row Pointer to where the current cursor row is to be stored.
-
- @retval -1 fd is not an IIO output device.
- @retval 0 Cursor position retrieved, Cursor is Not Visible.
- @retval 1 Cursor position retrieved, Cursor is Visible.
-**/
-int
-EFIAPI
-IIO_GetCursorPosition (
- int fd,
- UINT32 *Column,
- UINT32 *Row
- )
-{
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
- struct __filedes *pStdOut;
- int RetVal;
-
- RetVal = -1;
-
- Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)IIO_GetDeviceProto(fd, &pStdOut);
- if(Proto != NULL) {
- if(((pStdOut->f_iflags & _S_ITTY) != 0) && // file is a TTY
- ((pStdOut->Oflags & O_ACCMODE) != 0)) // and it is open for output
- {
- // fd is for a TTY or "Interactive IO" device
- *Column = Proto->Mode->CursorColumn;
- *Row = Proto->Mode->CursorRow;
- if(Proto->Mode->CursorVisible) {
- RetVal = 1;
- }
- else {
- RetVal = 0;
- }
- }
- }
- return RetVal;
-}
-
-/** Set the cursor position.
-
- @param[in] filp Pointer to the output device's file descriptor structure.
- @param[in] StartXY Pointer to a cursor coordinate (XY) structure indicating
- the desired coordinate to move the cursor to.
-
- @retval -1 fd is not an IIO output device
- @retval 0 Cursor position set successfully.
-**/
-int
-EFIAPI
-IIO_SetCursorPosition (
- struct __filedes *filp,
- CURSOR_XY *CursorXY
- )
-{
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
- cIIO *This;
- EFI_STATUS Status;
- int RetVal;
-
- RetVal = -1;
-
- This = filp->devdata;
- Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)IIO_GetDeviceProto(filp->MyFD, NULL);
- if(Proto != NULL) {
- if(((filp->f_iflags & _S_ITTY) != 0) && // file is a TTY
- ((filp->Oflags & O_ACCMODE) != 0)) // and it is open for output
- {
- // fd is for a TTY or "Interactive IO" device
- Status = Proto->SetCursorPosition(Proto, CursorXY->Column, CursorXY->Row);
- if(Status == EFI_SUCCESS) {
- This->CurrentXY.Column = CursorXY->Column;
- This->CurrentXY.Row = CursorXY->Row;
- RetVal = 0;
- }
- }
- }
- return RetVal;
-}
-
-/** Get Output screen size and mode.
-
- @param[in] fd File descriptor of the output device.
- @param[out] Col Pointer to where to store the MAX Column, or NULL.
- @param[out] Row Pointer to where to store the MAX Row, or NULL.
-
- @retval <0 An error occurred. The reason is in errno and EFIerrno.
- * EIO UEFI QueryMode failed
- * ENOTTY fd does not refer to an interactive output device
- @retval >=0 Current output mode
-**/
-int
-EFIAPI
-IIO_GetOutputSize (
- int fd,
- UINTN *Col,
- UINTN *Row
-)
-{
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto;
- struct __filedes *pStdOut;
- EFI_STATUS Status;
- UINTN TempCol;
- UINTN TempRow;
- UINTN TempMode;
- int RetVal;
-
- RetVal = -1;
-
- Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)IIO_GetDeviceProto(fd, &pStdOut);
- if(Proto != NULL) {
- if(((pStdOut->f_iflags & _S_ITTY) != 0) && // file is a TTY
- ((pStdOut->Oflags & O_ACCMODE) != 0)) // and it is open for output
- {
- // fd is for a TTY or "Interactive IO" device
- TempMode = Proto->Mode->Mode;
- Status = Proto->QueryMode(Proto, TempMode, &TempCol, &TempRow);
- if(EFI_ERROR(Status)) {
- EFIerrno = Status;
- errno = EIO;
- }
- else {
- *Col = TempCol;
- *Row = TempRow;
- RetVal = (int)TempMode;
- }
- }
- else {
- errno = ENOTTY;
- }
- }
- return RetVal;
-}
-
-/** Calculate the number of character positions between two X/Y coordinate pairs.
-
- Using the current output device characteristics, calculate the number of
- characters between two coordinates. It is assumed that EndXY points to
- an output location that occurs after StartXY.
-
- RowDelta is the computed difference between the ending and starting rows.
- If RowDelta < 0, then EndXY is NOT after StartXY, so assert.
-
- ColumnDelta is the computed number of character positions (columns) between
- the starting position and the ending position. If ColumnDelta is < 0,
- then EndXY is NOT after StartXY, so assert.
-
- @param[in] This Pointer to the IIO instance to be examined.
- @param[in] StartXY Pointer to the starting coordinate pair.
- @param[in] EndXY Pointer to the ending coordinate pair.
-
- @return Returns the difference between the starting and ending coordinates.
- The return value is positive if the coordinates contained in EndXY
- are larger than StartXY, otherwise the return value is negative.
-**/
-int
-EFIAPI
-IIO_CursorDelta (
- cIIO *This,
- CURSOR_XY *StartXY,
- CURSOR_XY *EndXY
-)
-{
- int ColumnDelta;
- int RowDelta;
-
- RowDelta = (int)EndXY->Row - (int)StartXY->Row;
-
- assert(RowDelta >= 0); // assert if EndXY is NOT after StartXY
-
- ColumnDelta = (int)((This->MaxColumn * RowDelta) + EndXY->Column);
- ColumnDelta -= (int)StartXY->Column;
-
- return ColumnDelta;
-}
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.h b/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.h
deleted file mode 100644
index 778b612ea5..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/** @file
- Utilities for Interactive I/O Functions.
-
- The functions assume that isatty() is TRUE at the time they are called.
-
- Copyright (c) 2012, 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.
-**/
-#ifndef _IIO_UTILITIES_H
-#define _IIO_UTILITIES_H
-
-#include <sys/EfiSysCall.h>
-
-__BEGIN_DECLS
-
-/** Get the low-level UEFI protocol associated with an open file.
-
- @param[in] fd File descriptor for an open file.
- @param[out] filp NULL, or a pointer to where a pointer to the file's
- file descriptor structure is to be stored.
-
- @return Returns NULL if fd is not a valid file descriptor, otherwise
- a pointer to the file's associated UEFI protocol is returned.
-**/
-void *
-EFIAPI
-IIO_GetDeviceProto (
- int fd,
- struct __filedes **filp // Optional - filp == NULL if unused
- );
-
-/** Get a character either from the input buffer or from hardware.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] First Set to TRUE to identify the initial read.
-
- @return Returns a character read from either the input buffer
- or from the open file (device) identified by filp.
- A return value of WEOF indicates an error has occurred.
-**/
-wint_t
-EFIAPI
-IIO_GetInChar (
- struct __filedes *filp,
- BOOLEAN First
- );
-
-/** Get the current cursor position.
-
- @param[in] fd File descriptor for an open file.
- @param[out] Column Pointer to where the current cursor column is to be stored.
- @param[out] Row Pointer to where the current cursor row is to be stored.
-
- @retval -1 fd is not an IIO output device.
- @retval 0 Cursor position retrieved, Cursor is Not Visible.
- @retval 1 Cursor position retrieved, Cursor is Visible.
-**/
-int
-EFIAPI
-IIO_GetCursorPosition (
- int fd,
- UINT32 *Column,
- UINT32 *Row
- );
-
-/** Set the cursor position.
-
- @param[in] filp Pointer to the output device's file descriptor structure.
- @param[in] StartXY Pointer to a cursor coordinate (XY) structure indicating
- the desired coordinate to move the cursor to.
-
- @retval -1 fd is not an IIO output device
- @retval 0 Cursor position set successfully.
-**/
-int
-EFIAPI
-IIO_SetCursorPosition (
- struct __filedes *filp,
- CURSOR_XY *StartXY
- );
-
-/** Get Output screen size and mode.
-
- @param[in] fd File descriptor of the output device.
- @param[out] Col Pointer to where to store the MAX Column, or NULL.
- @param[out] Row Pointer to where to store the MAX Row, or NULL.
-
- @retval <0 An error occurred. The reason is in errno and EFIerrno.
- * EIO UEFI QueryMode failed
- * ENOTTY fd does not refer to an interactive output device
- @retval >=0 Current output mode
-**/
-int
-EFIAPI
-IIO_GetOutputSize (
- int fd,
- UINTN *Col,
- UINTN *Row
-);
-
-/** Calculate the number of character positions between two X/Y coordinate pairs.
-
- Using the current output device characteristics, calculate the number of
- characters between two coordinates.
-
- @param[in] This Pointer to the IIO instance to be examined.
- @param[in] StartXY Pointer to the starting coordinate pair.
- @param[in] EndXY Pointer to the ending coordinate pair.
-
- @return Returns the difference between the starting and ending coordinates.
- The return value is positive if the coordinates contained in EndXY
- are larger than StartXY, otherwise the return value is negative.
-**/
-int
-EFIAPI
-IIO_CursorDelta (
- cIIO *This,
- CURSOR_XY *StartXY,
- CURSOR_XY *EndXY
- );
-
-__END_DECLS
-#endif /* _IIO_UTILITIES_H */
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIOwrite.c b/StdLib/LibC/Uefi/InteractiveIO/IIOwrite.c
deleted file mode 100644
index ef52cc890e..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/IIOwrite.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/** @file
- Write to an Interactive I/O Output device.
-
- The functions assume that isatty() is TRUE at the time they are called.
- Since the UEFI console is a WIDE character device, these functions do all
- processing using wide characters.
-
- It is the responsibility of the caller, or higher level function, to perform
- any necessary translation between wide and narrow characters.
-
- Copyright (c) 2012 - 2014, 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.
-**/
-#include <Uefi.h>
-
-#include <LibConfig.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <sys/termios.h>
-#include <Device/IIO.h>
-
-static wchar_t Spaces[] = L" "; // Spaces for expanding TABs
-
-#define MAX_TAB_WIDTH ((int)(sizeof(Spaces) / sizeof(wchar_t)) - 1)
-
-#define MAX_EXPANSION 3
-
-/** Process and buffer one character for output.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[out] OBuf Pointer to the Output Buffer FIFO.
- @param[in] InCh The wide character to process.
-
- @retval <0 An error occurred. Reason is in errno.
- * EINVAL The pointer to the IIO object is NULL.
- * ENOSPC The OBuf FIFO is full.
-
- @retval 0 A character was input but not placed in the output buffer.
-
- @retval >0 The number of characters buffered. Normally 1, or 2.
- If a character is discarded because of flag settings, a
- 1 will be returned.
-**/
-ssize_t
-IIO_WriteOne(struct __filedes *filp, cFIFO *OBuf, wchar_t InCh)
-{
- cIIO *This;
- struct termios *Termio;
- tcflag_t OFlag;
- ssize_t RetVal;
- wchar_t wc[MAX_EXPANSION]; // Sub-buffer for conversions
- wchar_t *wcb; // Pointer to either wc or spaces
- int numW = 0; // Wide characters placed in OBuf
- INT32 TabWidth; // Each TAB expands into this number of spaces
- UINT32 CurColumn; // Current cursor column on the screen
- UINT32 CurRow; // Current cursor row on the screen
- UINT32 PrevColumn; // Previous column. Used to detect wrapping.
- UINT32 AdjColumn; // Current cursor column on the screen
-
- RetVal = -1;
- wcb = wc;
- This = filp->devdata;
- if((This != NULL) && (OBuf->FreeSpace(OBuf, AsElements) >= MAX_EXPANSION)) {
- Termio = &This->Termio;
- OFlag = Termio->c_oflag;
- TabWidth = (INT32)This->Termio.c_cc[VTABLEN];
- if(TabWidth > MAX_TAB_WIDTH) {
- TabWidth = MAX_TAB_WIDTH;
- }
- CurColumn = This->CurrentXY.Column;
- CurRow = This->CurrentXY.Row;
-
- numW = 1; // The majority of characters buffer one character
- AdjColumn = 0;
- if(OFlag & OPOST) {
- /* Perform output processing */
- switch(InCh) {
- case CHAR_TAB: //{{
- if(OFlag & OXTABS) {
- if(TabWidth > 0) {
- int SpaceIndex;
-
- SpaceIndex = CurColumn % TabWidth; // Number of spaces after a Tab Stop
- numW = TabWidth - SpaceIndex; // Number of spaces to the next Tab Stop
- SpaceIndex = MAX_TAB_WIDTH - numW; // Index into the Spaces array
- wcb = &Spaces[SpaceIndex]; // Point to the appropriate number of spaces
- }
- else {
- wc[0] = L' ';
- }
- AdjColumn = numW;
- }
- else {
- wc[0] = InCh; // Send the TAB itself - assumes that it does not move cursor.
- }
- break; //}}
-
- case CHAR_CARRIAGE_RETURN: //{{
- if((OFlag & OCRNL) == 0) {
- if((OFlag & ONLRET) == 0) {
- numW = 0; /* Discard the CR */
- // Cursor doesn't move
- }
- else {
- wc[0] = CHAR_CARRIAGE_RETURN;
- CurColumn = 0;
- }
- break;
- }
- else {
- InCh = CHAR_LINEFEED;
- } //}}
- // Fall through to the NL case
- case CHAR_LINEFEED: //{{
- if(OFlag & ONLCR) {
- wc[0] = CHAR_CARRIAGE_RETURN;
- wc[1] = CHAR_LINEFEED;
- numW = 2;
- CurColumn = 0;
- }
- break; //}}
-
- case CHAR_BACKSPACE: //{{
- if(CurColumn > 0) {
- wc[0] = CHAR_BACKSPACE;
- CurColumn = (UINT32)ModuloDecrement(CurColumn, (UINT32)This->MaxColumn);
- }
- else {
- numW = 0; // Discard the backspace if in column 0
- }
- break; //}}
-
- case CHAR_EOT: //{{
- if(OFlag & ONOEOT) {
- numW = 0; // Discard the EOT character
- // Cursor doesn't move
- break;
- } //}}
- // Fall through to default in order to potentially output "^D"
- default: //{{
- if((InCh >= 0) && (InCh < L' ')) {
- // InCh contains a control character
- if(OFlag & OCTRL) {
- wc[1] = InCh + L'@';
- wc[0] = L'^';
- numW = 2;
- AdjColumn = 2;
- }
- else {
- numW = 0; // Discard. Not a UEFI supported control character.
- }
- }
- else {
- // Regular printing character
- wc[0] = InCh;
- AdjColumn = 1;
- }
- break; //}}
- }
- if(numW < MAX_EXPANSION) {
- wc[numW] = 0; // Terminate the sub-buffer
- }
- if(AdjColumn != 0) {
- // Adjust the cursor position
- PrevColumn = CurColumn;
- CurColumn = ModuloAdd(PrevColumn, AdjColumn, (UINT32)This->MaxColumn);
- if(CurColumn < PrevColumn) {
- // We must have wrapped, so we are on the next Row
- ++CurRow;
- if(CurRow >= This->MaxRow) {
- // The screen has scrolled so need to adjust Initial location.
- --This->InitialXY.Row; // Initial row has moved up one
- CurRow = (UINT32)(This->MaxRow - 1); // We stay on the bottom row
- }
- }
- }
- This->CurrentXY.Column = CurColumn;
- This->CurrentXY.Row = CurRow;
- }
- else {
- // Output processing disabled -- RAW output mode
- wc[0] = InCh;
- wc[1] = 0;
- }
- // Put the character(s) into the output buffer
- if(numW > 0) {
- (void)OBuf->Write(OBuf, (const void *)wcb, (size_t)numW);
- }
- RetVal = numW;
- }
- else {
- if(This == NULL) {
- errno = EINVAL;
- }
- else {
- errno = ENOSPC;
- }
- }
- return RetVal;
-}
diff --git a/StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c b/StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c
deleted file mode 100644
index aab81cdaa8..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/** @file
- NonCanonical Interactive Input Function.
-
- The functions assume that isatty() is TRUE at the time they are called.
- If _S_IWTTY is set, the device returns WIDE characters.
-
- Copyright (c) 2012 - 2014, 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.
-**/
-#include <LibConfig.h>
-
-#include <sys/syslimits.h>
-#include <sys/termios.h>
-#include <Containers/Fifo.h>
-#include <Device/IIO.h>
-
-/** Perform a noncanonical read of input.
-
- @param[in] filp Pointer to a file descriptor structure.
- @param[in] BufferSize Maximum number of bytes to return.
-
- @retval -1 An error has occurred. Reason in errno.
- @retval -1 No data returned. None was ready.
- @retval >0 The number of elements returned
-**/
-ssize_t
-IIO_NonCanonRead (
- struct __filedes *filp
- )
-{
- cIIO *This;
- cFIFO *InBuf;
- struct termios *Termio;
- ssize_t NumRead;
- cc_t tioMin;
- cc_t tioTime;
- UINT32 InputType;
- wchar_t InChar; // Intermediate character buffer
-
- NumRead = -1;
- InChar = 0; // Initialize so compilers don't complain.
- This = filp->devdata;
- Termio = &This->Termio;
- InBuf = This->InBuf;
- tioMin = Termio->c_cc[VMIN];
- tioTime = Termio->c_cc[VTIME];
-
- if(tioMin >= MAX_INPUT) {
- tioMin = MAX_INPUT;
- }
- /* There are four types of processing that may be done, based on
- the values of tioMin and tioTime.
- Min Time Type
- --- ---- ----
- 0 0 0 Return buffer contents or 1 new char
- 0 >0 1 Return 0 or 1 character depending on timeout
- >0 0 2 Buffer Min chars. Return BufferSize chars.
- >0 >0 3 Return up to Min chars. Unless the inter-byte timer expires.
-
- Currently, only type 0 is implemented.
- */
- InputType = 0;
- if(tioMin != 0) InputType = 2;
- if(tioTime != 0) ++InputType;
- //switch(InputType) {
- // case 0:
- if(InBuf->IsEmpty(InBuf)) {
- NumRead = filp->f_ops->fo_read(filp, &filp->f_offset, sizeof(wchar_t), &InChar);
- if(NumRead > 0) {
- (void) InBuf->Write(InBuf, &InChar, 1); // Buffer the character
- }
- }
- // break;
- // case 1:
- // break;
- // case 2:
- // break;
- // case 3:
- // break;
- //}
- return NumRead;
-}
diff --git a/StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c b/StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c
deleted file mode 100644
index 807ab1fd4c..0000000000
--- a/StdLib/LibC/Uefi/InteractiveIO/TerminalFunctions.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/** @file
- "Terminal" Control functions for Interactive IO.
-
- Copyright (c) 2012, 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.
-
- 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/BaseMemoryLib.h>
-
-#include <LibConfig.h>
-
-#include <errno.h>
-#include <sys/termios.h>
-#include <Device/IIO.h>
-#include <MainData.h>
-
-/** Get input baud rate.
-
- Extracts the input baud rate from the termios structure pointed to by the
- pTermios argument.
-
- @param[in] pTermios A pointer to the termios structure from which to extract
- the input baud rate.
-
- @return The value of the input speed is returned exactly as it is contained
- in the termios structure, without interpretation.
-**/
-speed_t
-cfgetispeed (
- const struct termios *pTermios
- )
-{
- return pTermios->c_ispeed;
-}
-
-/** Get output baud rate.
-
- Extracts the output baud rate from the termios structure pointed to by the
- pTermios argument.
-
- @param[in] pTermios A pointer to the termios structure from which to extract
- the output baud rate.
-
- @return The value of the output speed is returned exactly as it is contained
- in the termios structure, without interpretation.
-**/
-speed_t
-cfgetospeed (
- const struct termios *pTermios
- )
-{
- return pTermios->c_ospeed;
-}
-
-/** Set input baud rate.
-
- Replaces the input baud rate, in the termios structure pointed to by the
- pTermios argument, with the value of NewSpeed.
-
- @param[out] pTermios A pointer to the termios structure into which to set
- the input baud rate.
- @param[in] NewSpeed The new input baud rate.
-
- @retval 0 The operation completed successfully.
- @retval -1 An error occured and errno is set to indicate the error.
- * EINVAL - The value of NewSpeed is outside the range of
- possible speed values as specified in <sys/termios.h>.
-**/
-int
-cfsetispeed (
- struct termios *pTermios,
- speed_t NewSpeed
- )
-{
- int RetVal;
-
- if(NewSpeed < B921600) {
- pTermios->c_ispeed = NewSpeed;
- RetVal = 0;
- }
- else {
- RetVal = -1;
- errno = EINVAL;
- }
- return RetVal;
-}
-
-/** Set output baud rate.
-
- Replaces the output baud rate, in the termios structure pointed to by the
- pTermios argument, with the value of NewSpeed.
-
- @param[out] pTermios A pointer to the termios structure into which to set
- the output baud rate.
- @param[in] NewSpeed The new output baud rate.
-
- @retval 0 The operation completed successfully.
- @retval -1 An error occured and errno is set to indicate the error.
- * EINVAL - The value of NewSpeed is outside the range of
- possible speed values as specified in <sys/termios.h>.
-**/
-int
-cfsetospeed (
- struct termios *pTermios,
- speed_t NewSpeed
- )
-{
- int RetVal;
-
- if(NewSpeed < B921600) {
- pTermios->c_ospeed = NewSpeed;
- RetVal = 0;
- }
- else {
- RetVal = -1;
- errno = EINVAL;
- }
- return RetVal;
-}
-
-/** Get the parameters associated with an interactive IO device.
-
- Get the parameters associated with the device referred to by
- fd and store them into the termios structure referenced by pTermios.
-
- @param[in] fd The file descriptor for an open interactive IO device.
- @param[out] pTermios A pointer to a termios structure into which to store
- attributes of the interactive IO device.
-
- @retval 0 The operation completed successfully.
- @retval -1 An error occured and errno is set to indicate the error.
- * EBADF - The fd argument is not a valid file descriptor.
- * ENOTTY - The file associated with fd is not an interactive IO device.
-**/
-int
-tcgetattr (
- int fd,
- struct termios *pTermios
- )
-{
- cIIO *IIO;
- int RetVal;
- struct __filedes *filp;
- struct termios *Termio;
-
- RetVal = 0;
- if(ValidateFD( fd, VALID_OPEN)) {
- filp = &gMD->fdarray[fd];
-
- if((filp->f_iflags & _S_ITTY) != 0) {
- // fd is for a TTY or "Interactive IO" device
- IIO = (cIIO *)filp->devdata;
- Termio = &IIO->Termio;
- (void)CopyMem((void *)pTermios, (const void *)Termio, sizeof(struct termios));
- }
- else {
- errno = ENOTTY;
- RetVal = -1;
- }
- }
- else {
- errno = EBADF;
- RetVal = -1;
- }
- return RetVal;
-}
-
-/** Set the parameters associated with an interactive IO device.
-
- Set the parameters associated with the device referred to by
- fd to the values in the termios structure referenced by pTermios.
-
- Behavior is modified by the value of the OptAct parameter:
- * TCSANOW: The change shall occur immediately.
- * TCSADRAIN: The change shall occur after all output written to fd is
- transmitted. This action should be used when changing parameters which
- affect output.
- * TCSAFLUSH: The change shall occur after all output written to fd is
- transmitted, and all input so far received but not read shall be
- discarded before the change is made.
-
- @param[in] fd The file descriptor for an open interactive IO device.
- @param[in] OptAct Currently has no effect.
- @param[in] pTermios A pointer to a termios structure into which to retrieve
- attributes to set in the interactive IO device.
-
- @retval 0 The operation completed successfully.
- @retval -1 An error occured and errno is set to indicate the error.
- * EBADF - The fd argument is not a valid file descriptor.
- * ENOTTY - The file associated with fd is not an interactive IO device.
-**/
-int
-tcsetattr (
- int fd,
- int OptAct, // Currently ignored
- const struct termios *pTermios
- )
-{
- cIIO *IIO;
- int RetVal;
- struct __filedes *filp;
- struct termios *Termio;
-
- RetVal = 0;
- if(ValidateFD( fd, VALID_OPEN)) {
- filp = &gMD->fdarray[fd];
-
- if((filp->f_iflags & _S_ITTY) != 0) {
- // fd is for a TTY or "Interactive IO" device
- IIO = (cIIO *)filp->devdata;
- Termio = &IIO->Termio;
- (void)CopyMem((void *)Termio, (const void *)pTermios, sizeof(struct termios));
- }
- else {
- errno = ENOTTY;
- RetVal = -1;
- }
- }
- else {
- errno = EBADF;
- RetVal = -1;
- }
- return RetVal;
-}
-
-/** Transmit pending output.
-
- Function is not yet implemented for UEFI.
-
- @param[in] fd Ignored
-
- @retval -1 This function is not yet supported. errno is set to ENOTSUP.
-**/
-int
-tcdrain (int fd)
-{
- errno = ENOTSUP;
- return -1;
-}
-
-/** Suspend or restart the transmission or reception of data.
-
- This function will suspend or resume transmission or reception of data on
- the file referred to by fd, depending on the value of Action.
-
- Function is not yet implemented for UEFI.
-
- @param[in] fd Ignored
- @param[in] Action Ignored
-
- @retval -1 This function is not yet supported. errno is set to ENOTSUP.
-**/
-int
-tcflow (
- int fd,
- int Action)
-{
- errno = ENOTSUP;
- return -1;
-}
-
-/** Discard non-transmitted output data, non-read input data, or both.
-
- Function is not yet implemented for UEFI.
-
- @param[in] fd Ignored
- @param[in] QueueSelector Ignored
-
- @retval -1 This function is not yet supported. errno is set to ENOTSUP.
-**/
-int
-tcflush (
- int fd,
- int QueueSelector)
-{
- errno = ENOTSUP;
- return -1;
-}
-
diff --git a/StdLib/LibC/Uefi/StubFunctions.c b/StdLib/LibC/Uefi/StubFunctions.c
deleted file mode 100644
index 806cf4ac2b..0000000000
--- a/StdLib/LibC/Uefi/StubFunctions.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/** @file
- Implement the invalid functions to return failures.
-
- Copyright (c) 2011, Intel Corporation
- All rights reserved. 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
-
- 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 <LibConfig.h>
-#include <sys/EfiCdefs.h>
-#include <sys/featuretest.h>
-#include <namespace.h>
-#include <stdio.h>
-#include <pwd.h>
-#include <errno.h>
-
-struct passwd *
-getpwuid (uid_t uid)
-{
- errno = EPERM;
- return NULL;
-}
-
-char *
-getlogin (void)
-{
- errno = EPERM;
- return NULL;
-}
-
-struct passwd *
-getpwnam (const char *name)
-{
- errno = EPERM;
- return NULL;
-}
-
-uid_t
-getuid (void)
-{
- return 0;
-}
-
-pid_t
-getpid(void)
-{
- return 0;
-}
-
-pid_t
-fork (void)
-{
- errno = EPERM;
- return (-1);
-}
-
-int
-chmod (const char *c, mode_t m)
-{
- errno = EPERM;
- return (-1);
-}
-
-pid_t
-wait(int *stat_loc) {
- return 0;
-}
-
-FILE *
-popen (const char *cmd, const char *type)
-{
- errno = EPERM;
- return NULL;
-}
-
-int
-pclose (FILE *stream)
-{
- errno = EPERM;
- return -1;
-}
-
-mode_t
-umask(mode_t cmask)
-{
- return (mode_t)0;
-}
diff --git a/StdLib/LibC/Uefi/SysCalls.c b/StdLib/LibC/Uefi/SysCalls.c
deleted file mode 100644
index a2b627bd12..0000000000
--- a/StdLib/LibC/Uefi/SysCalls.c
+++ /dev/null
@@ -1,1437 +0,0 @@
-/** @file
- EFI versions of NetBSD system calls.
-
- Copyright (c) 2010 - 2012, 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.
-
- 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/UefiLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/BaseLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/ShellLib.h>
-
-#include <LibConfig.h>
-#include <sys/EfiCdefs.h>
-
-#include <sys/ansi.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <wchar.h>
-#include <sys/poll.h>
-#include <sys/fcntl.h>
-#include <sys/stat.h>
-#include <sys/syslimits.h>
-#include <sys/filio.h>
-#include <Efi/SysEfi.h>
-#include <unistd.h>
-#include <kfile.h>
-#include <Device/Device.h>
-#include <Device/IIO.h>
-#include <MainData.h>
-#include <extern.h>
-
-/* EFI versions of BSD system calls used in stdio */
-
-/* Validate that fd refers to a valid file descriptor.
- IsOpen is interpreted as follows:
- - Positive fd must be OPEN
- - Zero fd must be CLOSED
- - Negative fd may be OPEN or CLOSED
-
- @retval TRUE fd is VALID
- @retval FALSE fd is INVALID
-*/
-BOOLEAN
-ValidateFD( int fd, int IsOpen)
-{
- struct __filedes *filp;
- BOOLEAN retval = FALSE;
-
- if((fd >= 0) && (fd < OPEN_MAX)) {
- filp = &gMD->fdarray[fd];
- retval = TRUE;
- if(IsOpen >= 0) {
- retval = (BOOLEAN)((filp->f_iflags != 0) && // TRUE if OPEN
- FILE_IS_USABLE(filp)); // and Usable (not Larval or Closing)
- if(IsOpen == VALID_CLOSED) {
- retval = (BOOLEAN)!retval; // We want TRUE if CLOSED
- }
- }
- }
- return retval;
-}
-
-/* Find and reserve a free File Descriptor.
-
- Returns the first free File Descriptor greater than or equal to the,
- already validated, fd specified by Minfd.
-
- @return Returns -1 if there are no free FDs. Otherwise returns the
- found fd.
-*/
-int
-FindFreeFD( int MinFd )
-{
- struct __filedes *Mfd;
- int i;
- int fd = -1;
-
- Mfd = gMD->fdarray;
-
- // Get an available fd
- for(i=MinFd; i < OPEN_MAX; ++i) {
- if(Mfd[i].f_iflags == 0) {
- Mfd[i].f_iflags = FIF_LARVAL; // Temporarily mark this fd as reserved
- fd = i;
- break;
- }
- }
- return fd;
-}
-
-/* Mark that an open file is to be deleted when closed. */
-int
-DeleteOnClose(int fd)
-{
- int retval = 0;
-
- if(ValidateFD( fd, VALID_OPEN)) {
- gMD->fdarray[fd].f_iflags |= FIF_DELCLOSE;
- }
- else {
- errno = EBADF;
- retval = -1;
- }
- return retval;
-}
-
-/** The isatty() function tests whether fd, an open file descriptor,
- is associated with a terminal device.
-
- @param[in] fd File Descriptor for the file to be examined.
-
- @retval 1 fd is associated with a terminal.
- @retval 0 fd is not associated with a terminal. errno is set to
- EBADF if fd is not a valid open FD.
-**/
-int
-isatty (int fd)
-{
- int retval = 0;
- struct __filedes *Fp;
-
- if(ValidateFD( fd, VALID_OPEN)) {
- Fp = &gMD->fdarray[fd];
- retval = (Fp->f_iflags & _S_ITTY) ? 1 : 0;
- }
- else {
- errno = EBADF;
- }
- return retval;
-}
-
-/** Determine if file descriptor fd is a duplicate of some other fd.
-
- @param[in] fd The file descriptor to check.
-
- @retval TRUE fd is a duplicate of another fd.
- @retval FALSE fd is unique.
-**/
-static BOOLEAN
-IsDupFd( int fd)
-{
- void * DevData;
- const struct fileops *FileOps;
- int i;
- BOOLEAN Ret = FALSE;
-
- if(ValidateFD( fd, VALID_OPEN )) {
- FileOps = gMD->fdarray[fd].f_ops;
- DevData = gMD->fdarray[fd].devdata;
- for(i=0; i < OPEN_MAX; ++i) {
- if(i == fd) continue;
- if(ValidateFD( i, VALID_OPEN )) { // TRUE if fd is valid and OPEN
- if((gMD->fdarray[i].f_ops == FileOps)
- &&(gMD->fdarray[i].devdata == DevData )) {
- Ret = TRUE;
- break;
- }
- }
- }
- }
- return Ret;
-}
-
-/** Worker function to Close a file and set its fd to the specified state.
-
- @param[in] fd The file descriptor to close.
- @param[in] NewState State to set the fd to after the file is closed.
-
- @retval 0 The operation completed successfully.
- @retval -1 The operation failed. Further information is in errno.
- * EBADF fd is not a valid or open file descriptor.
-**/
-static int
-_closeX (int fd, int NewState)
-{
- struct __filedes *Fp;
- int retval = 0;
-
- // Verify my pointers and get my FD.
- if(ValidateFD( fd, VALID_OPEN )) {
- Fp = &gMD->fdarray[fd];
- // Check if there are other users of this FileHandle
- if(Fp->RefCount == 1) { // There should be no other users
- if(! IsDupFd(fd)) {
- // Only do the close if no one else is using the FileHandle
- if(Fp->f_iflags & FIF_DELCLOSE) {
- /* Handle files marked "Delete on Close". */
- if(Fp->f_ops->fo_delete != NULL) {
- retval = Fp->f_ops->fo_delete(Fp);
- }
- }
- else {
- retval = Fp->f_ops->fo_close( Fp);
- }
- }
- Fp->f_iflags = NewState; // Close this FD or reserve it
- Fp->RefCount = 0; // No one using this FD
- }
- else {
- --Fp->RefCount; /* One less user of this FD */
- }
- }
- else {
- // Bad FD
- retval = -1;
- errno = EBADF;
- }
- return retval;
-}
-
-/** The close() function deallocates the file descriptor indicated by fd.
- To deallocate means to make the file descriptor available for return by
- subsequent calls to open() or other functions that allocate file
- descriptors. All outstanding record locks owned by the process on the file
- associated with the file descriptor are removed (that is, unlocked).
-
- @param[in] fd Descriptor for the File to close.
-
- @retval 0 Successful completion.
- @retval -1 An error occurred and errno is set to identify the error.
-**/
-int
-close (int fd)
-{
- return _closeX(fd, 0);
-}
-
-/** Delete the file specified by path.
-
- @param[in] path The MBCS path of the file to delete.
-
- @retval -1 Unable to open the file specified by path.
- @retval -1 If (errno == EPERM), unlink is not permited for this file.
- @retval -1 Low-level delete filed. Reason is in errno.
- @retval 0 The file was successfully deleted.
-**/
-int
-unlink (const char *path)
-{
- struct __filedes *Fp;
- int fd;
- int retval = -1;
-
- EFIerrno = RETURN_SUCCESS;
-
- fd = open(path, O_WRONLY, 0);
- if(fd >= 0) {
- Fp = &gMD->fdarray[fd];
-
- if(Fp->f_ops->fo_delete != NULL) {
- retval = Fp->f_ops->fo_delete(Fp);
- }
- Fp->f_iflags = 0; // Close this FD
- Fp->RefCount = 0; // No one using this FD
- }
- return retval;
-}
-
-/** The fcntl() function shall perform the operations described below on open
- files. The fildes argument is a file descriptor.
-
- The available values for cmd are defined in <fcntl.h> and are as follows:
- - F_DUPFD - Return a new file descriptor which shall be the lowest
- numbered available (that is, not already open) file
- descriptor greater than or equal to the third argument, arg,
- taken as an integer of type int. The new file descriptor
- shall refer to the same open file description as the original
- file descriptor, and shall share any locks. The FD_CLOEXEC
- flag associated with the new file descriptor shall be cleared
- to keep the file open across calls to one of the exec functions.
- - F_GETFD - Get the file descriptor flags defined in <fcntl.h> that are
- associated with the file descriptor fildes. File descriptor
- flags are associated with a single file descriptor and do not
- affect other file descriptors that refer to the same file.
- - F_SETFD - Set the file descriptor flags defined in <fcntl.h>, that are
- associated with fildes, to the third argument, arg, taken
- as type int. If the FD_CLOEXEC flag in the third argument
- is 0, the file shall remain open across the exec
- functions; otherwise, the file shall be closed upon
- successful execution of one of the exec functions.
- - F_GETFL - Get the file status flags and file access modes, defined in
- <fcntl.h>, for the file description associated with fildes.
- The file access modes can be extracted from the return
- value using the mask O_ACCMODE, which is defined in
- <fcntl.h>. File status flags and file access modes are
- associated with the file description and do not affect
- other file descriptors that refer to the same file with
- different open file descriptions.
- - F_SETFL - Set the file status flags, defined in <fcntl.h>, for the file
- description associated with fildes from the corresponding
- bits in the third argument, arg, taken as type int. Bits
- corresponding to the file access mode and the file creation
- flags, as defined in <fcntl.h>, that are set in arg shall
- be ignored. If any bits in arg other than those mentioned
- here are changed by the application, the result is unspecified.
- - F_GETOWN - If fildes refers to a socket, get the process or process group
- ID specified to receive SIGURG signals when out-of-band
- data is available. Positive values indicate a process ID;
- negative values, other than -1, indicate a process group
- ID. If fildes does not refer to a socket, the results are
- unspecified.
- - F_SETOWN - If fildes refers to a socket, set the process or process
- group ID specified to receive SIGURG signals when
- out-of-band data is available, using the value of the third
- argument, arg, taken as type int. Positive values indicate
- a process ID; negative values, other than -1, indicate a
- process group ID. If fildes does not refer to a socket, the
- results are unspecified.
-
- The fcntl() function shall fail if:
-
- [EBADF] The fildes argument is not a valid open file descriptor.
- [EINVAL] The cmd argument is invalid, or the cmd argument is F_DUPFD
- and arg is negative or greater than or equal to {OPEN_MAX}.
- [EMFILE] The argument cmd is F_DUPFD and {OPEN_MAX} file descriptors
- are currently open in the calling process, or no file
- descriptors greater than or equal to arg are available.
- [EOVERFLOW] One of the values to be returned cannot be represented correctly.
-
- @param[in] fildes Descriptor for the file to be controlled.
- @param[in] cmd Command to be acted upon.
- @param[in,out] ... Optional additional parameters as required by cmd.
-
- @return Upon successful completion, the value returned shall depend on
- cmd as follows:
- - F_DUPFD - A new file descriptor.
- - F_GETFD - Value of flags defined in <fcntl.h>. The return value
- shall not be negative.
- - F_SETFD - Value other than -1.
- - F_GETFL - Value of file status flags and access modes. The return
- value is not negative.
- - F_SETFL - Value other than -1.
- - F_GETOWN - Value of the socket owner process or process group;
- this will not be -1.
- - F_SETOWN - Value other than -1.
- Otherwise, -1 shall be returned and errno set to indicate the error.
-
-**/
-int
-fcntl (int fildes, int cmd, ...)
-{
- va_list p3;
- struct __filedes *MyFd;
- int retval = -1;
- int temp;
-
-//Print(L"%a( %d, %d, ...)\n", __func__, fildes, cmd);
- va_start(p3, cmd);
-
- if(ValidateFD( fildes, VALID_OPEN )) {
- MyFd = &gMD->fdarray[fildes];
-
- switch(cmd) {
- case F_DUPFD:
- temp = va_arg(p3, int);
- if(ValidateFD( temp, VALID_DONT_CARE )) {
- temp = FindFreeFD( temp );
- if(temp < 0) {
- errno = EMFILE;
- break;
- }
- /* temp is now a valid fd reserved for further use
- so copy fd into temp.
- */
- (void)memcpy(&gMD->fdarray[temp], MyFd, sizeof(struct __filedes));
- retval = temp;
- }
- else {
- errno = EINVAL;
- }
- break;
-
- case F_SETFL:
- retval = MyFd->Oflags; // Get original value
- temp = va_arg(p3, int);
- temp &= O_SETMASK; // Only certain bits can be set
- temp |= retval & O_SETMASK;
- MyFd->Oflags = temp; // Set new value
- break;
-
- case F_SETFD:
- retval = MyFd->f_iflags;
- break;
- //case F_SETOWN:
- // retval = MyFd->SocProc;
- // MyFd->SocProc = va_arg(p3, int);
- // break;
- case F_GETFD:
- retval = MyFd->f_iflags;
- break;
- case F_GETFL:
- retval = MyFd->Oflags;
- break;
- //case F_GETOWN:
- // retval = MyFd->SocProc;
- // break;
- default:
- errno = EINVAL;
- break;
- }
- }
- else {
- // Bad FD
- errno = EBADF;
- }
- va_end(p3);
- return retval;;
-}
-
-/** The dup() function provides an alternative interface to the
- service provided by fcntl() using the F_DUPFD command. The call:
- - fid = dup(fildes);
- shall be equivalent to:
- - fid = fcntl(fildes, F_DUPFD, 0);
-
- @param[in] fildes Descriptor for the file to be examined.
-
- @return Upon successful completion a non-negative integer, namely the
- file descriptor, shall be returned; otherwise, -1 shall be
- returned and errno set to indicate the error.
-**/
-int
-dup (int fildes)
-{
- return fcntl(fildes, F_DUPFD, 0);
-}
-
-/** Make fildes2 refer to a duplicate of fildes.
-
- The dup2() function provides an alternative interface to the
- service provided by fcntl() using the F_DUPFD command. The call:
- - fid = dup2(fildes, fildes2);
- shall be equivalent to:
- - close(fildes2);
- - fid = fcntl(fildes, F_DUPFD, fildes2);
- except for the following:
- - If fildes2 is less than 0 or greater than or equal to {OPEN_MAX},
- dup2() shall return -1 with errno set to [EBADF].
- - If fildes is a valid file descriptor and is equal to fildes2, dup2()
- shall return fildes2 without closing it.
- - If fildes is not a valid file descriptor, dup2() shall return -1 and
- shall not close fildes2.
- - The value returned shall be equal to the value of fildes2 upon
- successful completion, or -1 upon failure.
-
- @param[in] fildes File Descriptor to be duplicated.
- @param[in] fildes2 File Descriptor to be made a duplicate of fildes.
-
- @return Upon successful completion a non-negative integer, namely
- fildes2, shall be returned; otherwise, -1 shall be
- returned and errno set to EBADF indicate the error.
-**/
-int
-dup2 (int fildes, int fildes2)
-{
- int retval = -1;
-
- if(ValidateFD( fildes, VALID_OPEN)) {
- retval = fildes2;
- if( fildes != fildes2) {
- if(ValidateFD( fildes2, VALID_DONT_CARE)) {
- gMD->fdarray[fildes2].f_iflags = FIF_LARVAL; // Mark the file closed, but reserved
- (void)memcpy(&gMD->fdarray[fildes2], // Duplicate fildes into fildes2
- &gMD->fdarray[fildes], sizeof(struct __filedes));
- gMD->fdarray[fildes2].MyFD = (UINT16)fildes2;
- }
- else {
- errno = EBADF;
- retval = -1;
- }
- }
- }
- else {
- errno = EBADF;
- }
- return retval;
-}
-
-/** Reposition a file's read/write offset.
-
- The lseek() function repositions the offset of the file descriptor fildes
- to the argument offset according to the directive how. The argument
- fildes must be an open file descriptor. lseek() repositions the file
- pointer fildes as follows:
-
- - If how is SEEK_SET, the offset is set to offset bytes.
-
- - If how is SEEK_CUR, the offset is set to its current location
- plus offset bytes.
-
- - If how is SEEK_END, the offset is set to the size of the file
- plus offset bytes.
-
- The lseek() function allows the file offset to be set beyond the end of
- the existing end-of-file of the file. If data is later written at this
- point, subsequent reads of the data in the gap return bytes of zeros
- (until data is actually written into the gap).
-
- Some devices are incapable of seeking. The value of the pointer associ-
- ated with such a device is undefined.
-
- @param[in] fd Descriptor for the File to be affected.
- @param[in] offset Value to adjust the file position by.
- @param[in] how How the file position is to be adjusted.
-
- @return Upon successful completion, lseek() returns the resulting offset
- location as measured in bytes from the beginning of the file.
- Otherwise, a value of -1 is returned and errno is set to
- indicate the error.
-**/
-__off_t
-lseek (int fd, __off_t offset, int how)
-{
- __off_t CurPos = -1;
-// RETURN_STATUS Status = RETURN_SUCCESS;
- struct __filedes *filp;
-
- EFIerrno = RETURN_SUCCESS; // In case of error without an EFI call
-
- if( how == SEEK_SET || how == SEEK_CUR || how == SEEK_END) {
- if(ValidateFD( fd, VALID_OPEN)) {
- filp = &gMD->fdarray[fd];
- // Both of our parameters have been verified as valid
- CurPos = filp->f_ops->fo_lseek( filp, offset, how);
- if(CurPos >= 0) {
- filp->f_offset = CurPos;
- }
- }
- else {
- errno = EBADF; // Bad File Descriptor
- }
- }
- else {
- errno = EINVAL; // Invalid how argument
- }
- return CurPos;
-}
-
-/** The directory path is created with the access permissions specified by
- perms.
-
- The directory is closed after it is created.
-
- @param[in] path The path to a directory to create.
- @param[in] perms Permissions as defined in <sys/stat.h>
-
- @retval 0 The directory was created successfully.
- @retval -1 An error occurred and error codes are stored in errno and EFIerrno.
-**/
-int
-mkdir (const char *path, __mode_t perms)
-{
- wchar_t *NewPath;
- DeviceNode *Node;
- char *GenI;
- RETURN_STATUS Status;
- int Instance = 0;
- int retval = 0;
-
- Status = ParsePath(path, &NewPath, &Node, &Instance, NULL);
- if(Status == RETURN_SUCCESS) {
- GenI = Node->InstanceList;
- if(GenI == NULL) {
- errno = EPERM;
- retval = -1;
- }
- else {
- //GenI += (Instance * Node->InstanceSize);
- retval = ((GenericInstance *)GenI)->Abstraction.fo_mkdir( path, perms);
- }
- free(NewPath);
- }
- else {
- retval = -1;
- }
- return retval;
-}
-
-/** Open a file.
- The open() function establishes the connection between a file and a file
- descriptor. It creates an open file description that refers to a file
- and a file descriptor that refers to that open file description. The file
- descriptor is used by other I/O functions to refer to that file.
-
- The open() function returns a file descriptor for the named file that is
- the lowest file descriptor not currently open for that process. The open
- file description is new, and therefore the file descriptor shall not
- share it with any other process in the system.
-
- The file offset used to mark the current position within the file is set
- to the beginning of the file.
-
- The EFI ShellOpenFileByName() function is used to perform the low-level
- file open operation. The primary task of open() is to translate from the
- flags used in the <stdio.h> environment to those used by the EFI function.
-
- The file status flags and file access modes of the open file description
- are set according to the value of oflags.
-
- Values for oflags are constructed by a bitwise-inclusive OR of flags from
- the following list, defined in <fcntl.h>. Applications shall specify
- exactly one of { O_RDONLY, O_RDWR, O_WRONLY } in the value of oflags.
- Any combination of { O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL } may
- also be specified in oflags.
-
- The only valid flag combinations for ShellOpenFileByName() are:
- - Read
- - Read/Write
- - Create/Read/Write
-
- Values for mode specify the access permissions for newly created files.
- The mode value is saved in the FD to indicate permissions for further operations.
-
- O_RDONLY -- flags = EFI_FILE_MODE_READ -- this is always done
- O_WRONLY -- flags |= EFI_FILE_MODE_WRITE
- O_RDWR -- flags |= EFI_FILE_MODE_WRITE -- READ is already set
-
- O_NONBLOCK -- ignored
- O_APPEND -- Seek to EOF before every write
- O_CREAT -- flags |= EFI_FILE_MODE_CREATE
- O_TRUNC -- delete first then create new
- O_EXCL -- if O_CREAT is also set, open will fail if the file already exists.
-
- @param[in] Path The path argument points to a pathname naming the
- object to be opened.
- @param[in] oflags File status flags and file access modes of the
- open file description.
- @param[in] mode File access permission bits as defined in
- <sys/stat.h>. Only used if a file is created
- as a result of the open.
-
- @return Upon successful completion, open() opens the file and returns
- a non-negative integer representing the lowest numbered
- unused file descriptor. Otherwise, open returns -1 and sets
- errno to indicate the error. If a negative value is
- returned, no files are created or modified.
- - EMFILE - No file descriptors available -- Max number already open.
- - EINVAL - Bad value specified for oflags or mode.
- - ENOMEM - Failure allocating memory for internal buffers.
- - EEXIST - File exists and open attempted with (O_EXCL | O_CREAT) set.
- - EIO - UEFI failure. Check value in EFIerrno.
-**/
-int
-open(
- const char *path,
- int oflags,
- int mode
- )
-{
- wchar_t *NewPath;
- wchar_t *MPath;
- DeviceNode *Node;
- struct __filedes *filp;
- struct termios *Termio;
- int Instance = 0;
- RETURN_STATUS Status;
- UINT32 OpenMode;
- int fd = -1;
- int doresult;
-
- Status = ParsePath(path, &NewPath, &Node, &Instance, &MPath);
- if(Status == RETURN_SUCCESS) {
- if((Node == NULL) ||
- (Node->InstanceList == NULL))
- {
- errno = EPERM;
- }
- else {
- // Could add a test to see if the file name begins with a period.
- // If it does, then add the HIDDEN flag to Attributes.
-
- // Get an available fd
- fd = FindFreeFD( VALID_CLOSED );
-
- if( fd < 0 ) {
- // All available FDs are in use
- errno = EMFILE;
- }
- else {
- filp = &gMD->fdarray[fd];
- // Save the flags and mode in the File Descriptor
- filp->Oflags = oflags;
- filp->Omode = mode;
-
- doresult = Node->OpenFunc(Node, filp, Instance, NewPath, MPath);
- if(doresult < 0) {
- filp->f_iflags = 0; // Release this FD
- fd = -1; // Indicate an error
- }
- else {
- // Build our final f_iflags value
- OpenMode = ( mode & S_ACC_READ ) ? S_ACC_READ : 0;
- OpenMode |= ( mode & S_ACC_WRITE ) ? S_ACC_WRITE : 0;
-
- filp->f_iflags |= OpenMode;
-
- if((oflags & O_TTY_INIT) && (filp->f_iflags & _S_ITTY) && (filp->devdata != NULL)) {
- // Initialize the device's termios flags to a "sane" value
- Termio = &((cIIO *)filp->devdata)->Termio;
- Termio->c_iflag = ICRNL | IGNSPEC;
- Termio->c_oflag = OPOST | ONLCR | OXTABS | ONOEOT | ONOCR | ONLRET | OCTRL;
- Termio->c_lflag = ECHO | ECHOE | ECHONL | ICANON;
- Termio->c_cc[VERASE] = 0x08; // ^H Backspace
- Termio->c_cc[VKILL] = 0x15; // ^U
- Termio->c_cc[VINTR] = 0x03; // ^C Interrupt character
- }
- ++filp->RefCount;
- FILE_SET_MATURE(filp);
- }
- }
- }
- free(NewPath);
- }
- free(MPath); // We don't need this any more.
-
- // return the fd of our now open file
- return fd;
-}
-
-
-/**
- Poll a list of file descriptors.
-
- The ::poll routine waits for up to timeout milliseconds for an event
- to occur on one or more of the file descriptors listed. The event
- types of interested are specified for each file descriptor in the events
- field. The actual event detected is returned in the revents field of
- the array. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html">POSIX</a>
- documentation is available online.
-
- @param[in] pfd Address of an array of pollfd structures.
-
- @param[in] nfds Number of elements in the array of pollfd structures.
-
- @param[in] timeout Length of time in milliseconds to wait for the event
-
- @return The number of file descriptors with detected events. Zero
- indicates that the call timed out and -1 indicates an error.
-
- **/
-int
-poll (
- struct pollfd * pfd,
- nfds_t nfds,
- int timeout
- )
-{
- struct __filedes * pDescriptor;
- struct pollfd * pEnd;
- struct pollfd * pPollFD;
- int SelectedFDs;
- EFI_STATUS Status;
- EFI_EVENT Timer;
- UINT64 TimerTicks;
-
- //
- // Create the timer for the timeout
- //
- Timer = NULL;
- Status = EFI_SUCCESS;
- if ( INFTIM != timeout ) {
- Status = gBS->CreateEvent ( EVT_TIMER,
- TPL_NOTIFY,
- NULL,
- NULL,
- &Timer );
- if ( !EFI_ERROR ( Status )) {
- //
- // Start the timeout timer
- //
- TimerTicks = timeout;
- TimerTicks *= 1000 * 10;
- Status = gBS->SetTimer ( Timer,
- TimerRelative,
- TimerTicks );
- }
- else {
- SelectedFDs = -1;
- errno = ENOMEM;
- }
- }
- if ( !EFI_ERROR ( Status )) {
- //
- // Poll until an event is detected or the timer fires
- //
- SelectedFDs = 0;
- errno = 0;
- do {
- //
- // Poll the list of file descriptors
- //
- pPollFD = pfd;
- pEnd = &pPollFD [ nfds ];
- while ( pEnd > pPollFD ) {
- //
- // Validate the file descriptor
- //
- if ( !ValidateFD ( pPollFD->fd, VALID_OPEN )) {
- errno = EINVAL;
- return -1;
- }
-
- //
- // Poll the device or file
- //
- pDescriptor = &gMD->fdarray [ pPollFD->fd ];
- pPollFD->revents = pDescriptor->f_ops->fo_poll ( pDescriptor,
- pPollFD->events );
-
- //
- // Determine if this file descriptor detected an event
- //
- if ( 0 != pPollFD->revents ) {
- //
- // Select this descriptor
- //
- SelectedFDs += 1;
- }
-
- //
- // Set the next file descriptor
- //
- pPollFD += 1;
- }
-
- //
- // Check for timeout
- //
- if ( NULL != Timer ) {
- Status = gBS->CheckEvent ( Timer );
- if ( EFI_SUCCESS == Status ) {
- //
- // Timeout
- //
- break;
- }
- else if ( EFI_NOT_READY == Status ) {
- Status = EFI_SUCCESS;
- }
- }
- } while (( 0 == SelectedFDs )
- && ( EFI_SUCCESS == Status ));
-
- //
- // Stop the timer
- //
- if ( NULL != Timer ) {
- gBS->SetTimer ( Timer,
- TimerCancel,
- 0 );
- }
- }
- else {
- SelectedFDs = -1;
- errno = EAGAIN;
- }
-
- //
- // Release the timer
- //
- if ( NULL != Timer ) {
- gBS->CloseEvent ( Timer );
- }
-
- //
- // Return the number of selected file system descriptors
- //
- return SelectedFDs;
-}
-
-
-/** The rename() function changes the name of a file.
- The From argument points to the pathname of the file to be renamed. The To
- argument points to the new pathname of the file.
-
- If the From argument points to the pathname of a file that is not a
- directory, the To argument shall not point to the pathname of a
- directory. If the file named by the To argument exists, it shall be
- removed and From renamed to To. Write access permission is required for
- both the directory containing old and the directory containing To.
-
- If the From argument points to the pathname of a directory, the To
- argument shall not point to the pathname of a file that is not a
- directory. If the directory named by the To argument exists, it shall be
- removed and From renamed to To.
-
- The To pathname shall not contain a path prefix that names From. Write
- access permission is required for the directory containing From and the
- directory containing To. If the From argument points to the pathname of a
- directory, write access permission may be required for the directory named
- by From, and, if it exists, the directory named by To.
-
- If the rename() function fails for any reason other than [EIO], any file
- named by To shall be unaffected.
-
- @param[in] From Path to the file to be renamed.
- @param[in] To The new name of From.
-
- @retval 0 Successful completion.
- @retval -1 An error has occured and errno has been set to further specify the error.
- Neither the file named by From nor the file named by To are
- changed or created.
- - ENXIO: Path specified is not supported by any loaded driver.
- - ENOMEM: Insufficient memory to calloc a MapName buffer.
- - EINVAL: The path parameter is not valid.
-**/
-int
-rename(
- const char *From,
- const char *To
- )
-{
- wchar_t *FromPath;
- DeviceNode *FromNode;
- char *GenI;
- int Instance = 0;
- RETURN_STATUS Status;
- int retval = -1;
-
- Status = ParsePath(From, &FromPath, &FromNode, &Instance, NULL);
- if(Status == RETURN_SUCCESS) {
- GenI = FromNode->InstanceList;
- if(GenI == NULL) {
- errno = EPERM;
- retval = -1;
- }
- else {
- //GenI += (Instance * FromNode->InstanceSize);
- retval = ((GenericInstance *)GenI)->Abstraction.fo_rename( From, To);
- }
- free(FromPath);
- }
- return retval;
-}
-
-/** Delete a specified directory.
-
- @param[in] path Path to the directory to delete.
-
- @retval -1 The directory couldn't be opened (doesn't exist).
- @retval -1 The directory wasn't empty or an IO error occured.
-**/
-int
-rmdir(
- const char *path
- )
-{
- struct __filedes *filp;
- int fd;
- int retval = -1;
-
- fd = open(path, O_RDWR, 0);
- if(fd >= 0) {
- filp = &gMD->fdarray[fd];
-
- retval = filp->f_ops->fo_rmdir(filp);
- filp->f_iflags = 0; // Close this FD
- filp->RefCount = 0; // No one using this FD
- }
- return retval;
-}
-
-/** The fstat() function obtains information about an open file associated
- with the file descriptor fd, and writes it to the area pointed to
- by statbuf.
-
- The statbuf argument is a pointer to a stat structure, as defined
- in <sys/stat.h>, into which information is placed concerning the file.
-
- The structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atime,
- st_ctime, and st_mtime shall have meaningful values. The value of the
- member st_nlink shall be set to the number of links to the file.
-
- The fstat() function shall update any time-related fields before writing
- into the stat structure.
-
- The fstat() function is implemented using the ShellGetFileInfo()
- function.
-
- The stat structure members which don't have direct analogs to EFI file
- information are filled in as follows:
- - st_mode Populated with information from fd
- - st_ino Set to zero. (inode)
- - st_dev Set to zero.
- - st_uid Set to zero.
- - st_gid Set to zero.
- - st_nlink Set to one.
-
- @param[in] fd File descriptor as returned from open().
- @param[out] statbuf Buffer in which the file status is put.
-
- @retval 0 Successful Completion.
- @retval -1 An error has occurred and errno has been set to
- identify the error.
-**/
-int
-fstat (int fd, struct stat *statbuf)
-{
- int retval = -1;
- struct __filedes *filp;
-
- if(ValidateFD( fd, VALID_OPEN)) {
- filp = &gMD->fdarray[fd];
- retval = filp->f_ops->fo_stat(filp, statbuf, NULL);
- }
- else {
- errno = EBADF;
- }
- return retval;
-}
-
-/** Obtains information about the file pointed to by path.
-
- Opens the file pointed to by path, calls _EFI_FileInfo with the file's handle,
- then closes the file.
-
- @param[in] path Path to the file to obtain information about.
- @param[out] statbuf Buffer in which the file status is put.
-
- @retval 0 Successful Completion.
- @retval -1 An error has occurred and errno has been set to
- identify the error.
-**/
-int
-stat (const char *path, struct stat *statbuf)
-{
- int fd;
- int retval = -1;
- struct __filedes *filp;
-
- fd = open(path, O_RDONLY, 0);
- if(fd >= 0) {
- filp = &gMD->fdarray[fd];
- retval = filp->f_ops->fo_stat( filp, statbuf, NULL);
- close(fd);
- }
- return retval;
-}
-
-/** Same as stat since EFI doesn't have symbolic links.
-
- @param[in] path Path to the file to obtain information about.
- @param[out] statbuf Buffer in which the file status is put.
-
- @retval 0 Successful Completion.
- @retval -1 An error has occurred and errno has been set to
- identify the error.
-**/
-int
-lstat (const char *path, struct stat *statbuf)
-{
- return stat(path, statbuf);
-}
-
-/** Control a device.
-
- @param[in] fd Descriptor for the file to be acted upon.
- @param[in] request Specifies the operation to perform.
- @param[in,out] ... Zero or more parameters as required for request.
-
- @retval >=0 The operation completed successfully.
- @retval -1 An error occured. More information is in errno.
-**/
-int
-ioctl(
- int fd,
- unsigned long request,
- ...
- )
-{
- int retval = -1;
- struct __filedes *filp;
- va_list argp;
-
- va_start(argp, request);
-
- if(ValidateFD( fd, VALID_OPEN)) {
- filp = &gMD->fdarray[fd];
-
- if(request == FIODLEX) {
- /* set Delete-on-Close */
- filp->f_iflags |= FIF_DELCLOSE;
- retval = 0;
- }
- else if(request == FIONDLEX) {
- /* clear Delete-on-Close */
- filp->f_iflags &= ~FIF_DELCLOSE;
- retval = 0;
- }
- else {
- /* All other requests. */
- retval = filp->f_ops->fo_ioctl(filp, request, argp);
- }
- }
- else {
- errno = EBADF;
- }
- va_end(argp);
-
- return retval;
-}
-
-/** Read from a file.
-
- The read() function shall attempt to read nbyte bytes from the file
- associated with the open file descriptor, fildes, into the buffer pointed
- to by buf.
-
- Before any action described below is taken, and if nbyte is zero, the
- read() function may detect and return errors as described below. In the
- absence of errors, or if error detection is not performed, the read()
- function shall return zero and have no other results.
-
- On files that support seeking (for example, a regular file), the read()
- shall start at a position in the file given by the file offset associated
- with fildes. The file offset shall be incremented by the number of bytes
- actually read.
-
- Files that do not support seeking - for example, terminals - always read
- from the current position. The value of a file offset associated with
- such a file is undefined.
-
- No data transfer shall occur past the current end-of-file. If the
- starting position is at or after the end-of-file, 0 shall be returned.
-
- The read() function reads data previously written to a file. If any
- portion of a regular file prior to the end-of-file has not been written,
- read() shall return bytes with value 0. For example, lseek() allows the
- file offset to be set beyond the end of existing data in the file. If data
- is later written at this point, subsequent reads in the gap between the
- previous end of data and the newly written data shall return bytes with
- value 0 until data is written into the gap.
-
- Upon successful completion, where nbyte is greater than 0, read() shall
- mark for update the st_atime field of the file, and shall return the
- number of bytes read. This number shall never be greater than nbyte. The
- value returned may be less than nbyte if the number of bytes left in the
- file is less than nbyte, if the read() request was interrupted by a
- signal, or if the file is a pipe or FIFO or special file and has fewer
- than nbyte bytes immediately available for reading. For example, a read()
- from a file associated with a terminal may return one typed line of data.
-
- If fildes does not refer to a directory, the function reads the requested
- number of bytes from the file at the file's current position and returns
- them in buf. If the read goes beyond the end of the file, the read
- length is truncated to the end of the file. The file's current position is
- increased by the number of bytes returned.
-
- If fildes refers to a directory, the function reads the directory entry at
- the file's current position and returns the entry in buf. If buf
- is not large enough to hold the current directory entry, then
- errno is set to EBUFSIZE, EFIerrno is set to EFI_BUFFER_TOO_SMALL, and the
- current file position is not updated. The size of the buffer needed to read
- the entry will be returned as a negative number. On success, the current
- position is updated to the next directory entry. If there are no more
- directory entries, the read returns a zero-length buffer.
- EFI_FILE_INFO is the structure returned as the directory entry.
-
- @param[in] fildes Descriptor of the file to be read.
- @param[out] buf Pointer to location in which to store the read data.
- @param[in] nbyte Maximum number of bytes to be read.
-
- @return Upon successful completion, read() returns a non-negative integer
- indicating the number of bytes actually read. Otherwise, the
- functions return a negative value and sets errno to indicate the
- error. If errno is EBUFSIZE, the absolute value of the
- return value indicates the size of the buffer needed to read
- the directory entry.
-**/
-ssize_t
-read (int fildes, void *buf, size_t nbyte)
-{
- struct __filedes *filp;
- cIIO *IIO;
- ssize_t BufSize;
-
- BufSize = (ssize_t)nbyte;
- if(BufSize > 0) {
- if(ValidateFD( fildes, VALID_OPEN)) {
- filp = &gMD->fdarray[fildes];
-
- IIO = filp->devdata;
- if(isatty(fildes) && (IIO != NULL)) {
- BufSize = IIO->Read(filp, nbyte, buf);
- }
- else {
- BufSize = filp->f_ops->fo_read(filp, &filp->f_offset, nbyte, buf);
- }
- }
- else {
- errno = EBADF;
- BufSize = -1;
- }
- }
- return BufSize;
-}
-
-/** Write data to a file.
-
- This function writes the specified number of bytes to the file at the current
- file position. The current file position is advanced the actual number of bytes
- written, which is returned in BufferSize. Partial writes only occur when there
- has been a data error during the write attempt (such as "volume space full").
- The file is automatically grown to hold the data if required. Direct writes to
- opened directories are not supported.
-
- If fildes refers to a terminal device, isatty() returns TRUE, a partial write
- will occur if a NULL or EOF character is encountered before n characters have
- been written. Characters inserted due to line-end translations will not be
- counted. Unconvertable characters are translated into the UEFI character
- BLOCKELEMENT_LIGHT_SHADE.
-
- Since the UEFI console device works on wide characters, the buffer is assumed
- to contain a single-byte character stream which is then translated to wide
- characters using the mbtowc() functions. The resulting wide character stream
- is what is actually sent to the UEFI console.
-
- @param[in] fd Descriptor of file to be written to.
- @param[in] buf Pointer to data to write to the file.
- @param[in] nbyte Number of bytes to be written to the file.
-
- @retval >=0 Number of bytes actually written to the file.
- @retval <0 An error occurred. More data is provided by errno.
-**/
-ssize_t
-write (int fd, const void *buf, size_t nbyte)
-{
- struct __filedes *filp;
- cIIO *IIO;
- ssize_t BufSize;
-
- BufSize = (ssize_t)nbyte;
-
- if(ValidateFD( fd, VALID_OPEN)) {
- filp = &gMD->fdarray[fd];
- if ((filp->Oflags & O_ACCMODE) != 0) {
- // File is open for writing
- IIO = filp->devdata;
- if(isatty(fd) && (IIO != NULL)) {
- // Output to an Interactive I/O device
- BufSize = IIO->Write(filp, buf, nbyte);
- }
- else {
- // Output to a file, socket, pipe, etc.
- BufSize = filp->f_ops->fo_write(filp, &filp->f_offset, nbyte, buf);
- }
- }
- else {
- // File is NOT open for writing
- errno = EINVAL;
- BufSize = -1;
- }
- }
- else {
- // fd is not for a valid open file
- errno = EBADF;
- BufSize = -1;
- }
- return BufSize;
-}
-
-/** Gets the current working directory.
-
- The getcwd() function shall place an absolute pathname of the current
- working directory in the array pointed to by buf, and return buf.The
- size argument is the size in bytes of the character array pointed to
- by the buf argument.
-
- @param[in,out] buf The buffer to fill.
- @param[in] size The number of bytes in buffer.
-
- @retval NULL The function failed. The value in errno provides
- further information about the cause of the failure.
- Values for errno are:
- - EINVAL: buf is NULL or size is zero.
- - ENOENT: directory does not exist.
- - ERANGE: buf size is too small to hold CWD
-
- @retval buf The function completed successfully.
-**/
-char
-*getcwd (char *buf, size_t size)
-{
- CONST CHAR16 *Cwd;
-
- if (size == 0 || buf == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- Cwd = ShellGetCurrentDir(NULL);
- if (Cwd == NULL) {
- errno = ENOENT;
- return NULL;
- }
- if (size < ((StrLen (Cwd) + 1) * sizeof (CHAR8))) {
- errno = ERANGE;
- return (NULL);
- }
- return (UnicodeStrToAsciiStr(Cwd, buf));
-}
-
-/** Change the current working directory.
-
- The chdir() function shall cause the directory named by the pathname
- pointed to by the path argument to become the current working directory;
- that is, the starting point for path searches for pathnames not beginning
- with '/'.
-
- @param[in] path The new path to set.
-
- @retval 0 Operation completed successfully.
- @retval -1 Function failed. The value in errno provides more
- information on the cause of failure:
- - EPERM: Operation not supported with this Shell version.
- - ENOMEM: Unable to allocate memory.
- - ENOENT: Target directory does not exist.
-
- @todo Add non-NEW-shell CWD changing.
-**/
-int
-chdir (const char *path)
-{
- CONST CHAR16 *Cwd;
- EFI_STATUS Status;
- CHAR16 *UnicodePath;
-
- /* Old Shell does not support Set Current Dir. */
- if(gEfiShellProtocol != NULL) {
- Cwd = ShellGetCurrentDir(NULL);
- if (Cwd != NULL) {
- /* We have shell support */
- UnicodePath = AllocatePool(((AsciiStrLen (path) + 1) * sizeof (CHAR16)));
- if (UnicodePath == NULL) {
- errno = ENOMEM;
- return -1;
- }
- AsciiStrToUnicodeStr(path, UnicodePath);
- Status = gEfiShellProtocol->SetCurDir(NULL, UnicodePath);
- FreePool(UnicodePath);
- if (EFI_ERROR(Status)) {
- errno = ENOENT;
- return -1;
- } else {
- return 0;
- }
- }
- }
- /* Add here for non-shell */
- errno = EPERM;
- return -1;
-}
-
-/** Get the foreground process group ID associated with a terminal.
-
- Just returns the Image Handle for the requestor since UEFI does not have
- a concept of processes or groups.
-
- @param[in] x Ignored.
-
- @return Returns the Image Handle of the application or driver which
- called this function.
-**/
-pid_t tcgetpgrp (int x)
-{
- return ((pid_t)(UINTN)(gImageHandle));
-}
-
-/** Get the process group ID of the calling process.
-
- Just returns the Image Handle for the requestor since UEFI does not have
- a concept of processes or groups.
-
- @return Returns the Image Handle of the application or driver which
- called this function.
-**/
-pid_t getpgrp(void)
-{
- return ((pid_t)(UINTN)(gImageHandle));
-}
-
-/* Internal worker function for utimes.
- This works around an error produced by GCC when the va_* macros
- are used within a function with a fixed number of arguments.
-*/
-static
-int
-EFIAPI
-va_Utimes(
- const char *path,
- ...
- )
-{
- struct __filedes *filp;
- va_list ap;
- int fd;
- int retval = -1;
-
- va_start(ap, path);
- fd = open(path, O_RDWR, 0);
- if(fd >= 0) {
- filp = &gMD->fdarray[fd];
- retval = filp->f_ops->fo_ioctl( filp, FIOSETIME, ap);
- close(fd);
- }
- va_end(ap);
- return retval;
-}
-
-/** Set file access and modification times.
-
- @param[in] path Path to the file to be modified.
- @param[in] times Pointer to an array of two timeval structures
-
- @retval 0 File times successfully set.
- @retval -1 An error occured. Error type in errno.
-**/
-int
-utimes(
- const char *path,
- const struct timeval *times
- )
-{
- return va_Utimes(path, times);
-}
diff --git a/StdLib/LibC/Uefi/Uefi.inf b/StdLib/LibC/Uefi/Uefi.inf
deleted file mode 100644
index 1982dd9761..0000000000
--- a/StdLib/LibC/Uefi/Uefi.inf
+++ /dev/null
@@ -1,53 +0,0 @@
-## @file
-# Standard C library: UEFI "system calls".
-#
-# Copyright (c) 2010 - 2014, 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 = 1dcff17c-aa53-4b78-b234-864027555035
- MODULE_TYPE = UEFI_APPLICATION
- VERSION_STRING = 1.05
- LIBRARY_CLASS = LibUefi
- LIBRARY_DESTRUCTOR = DestructMePlease
-
-#
-# VALID_ARCHITECTURES = IA32 X64
-#
-
-[Sources]
- select.c
- SysCalls.c
- writev.c
- Xform.c
- compat.c
- StubFunctions.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
- LibGen
- DevUtility
diff --git a/StdLib/LibC/Uefi/Xform.c b/StdLib/LibC/Uefi/Xform.c
deleted file mode 100644
index ecf51d6b0f..0000000000
--- a/StdLib/LibC/Uefi/Xform.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/** @file
- Value transformations between stdio and the UEFI environment.
-
- Copyright (c) 2010 - 2011, 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 <Efi/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(flags & EFI_FILE_MODE_WRITE) { // Asking for write only?
- // EFI says the only two RW modes are read-only and read+write.
- flags = EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE;
- }
- 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 into their equivalent UEFI File Attribute bits.
- This transformation is most frequently used when translating attributes for use
- by the UEFI EFI_FILE_PROTOCOL.SetInfo() function.
-
- 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 the following flags:
- O_RDONLY -- open for reading only
- O_WRONLY -- open for writing only
- O_RDWR -- open for reading and writing
- O_ACCMODE -- mask for above modes
- O_NONBLOCK -- no delay
- O_APPEND -- set append mode
- O_CREAT -- create if nonexistent
- O_TRUNC -- truncate to zero length
- O_EXCL -- error if already exists
- O_HIDDEN -- Hidden file attribute
- O_SYSTEM -- System file attribute
- O_ARCHIVE -- Archive file attribute
-*/
-UINT64
-Omode2EFI( int mode)
-{
- UINT64 flags = 0;
-
- /* File is Read-Only. */
- if((mode & O_ACCMODE) == 0) {
- flags = EFI_FILE_READ_ONLY;
- }
- /* Set the Hidden attribute. */
- if((mode & O_HIDDEN) != 0) {
- flags |= EFI_FILE_HIDDEN;
- }
- /* Set the System attribute. */
- if((mode & O_SYSTEM) != 0) {
- flags |= EFI_FILE_SYSTEM;
- }
- /* Set the Archive attribute. */
- if((mode & O_ARCHIVE) != 0) {
- flags |= EFI_FILE_ARCHIVE;
- }
- 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;
-}
diff --git a/StdLib/LibC/Uefi/compat.c b/StdLib/LibC/Uefi/compat.c
deleted file mode 100644
index 251863fb14..0000000000
--- a/StdLib/LibC/Uefi/compat.c
+++ /dev/null
@@ -1,843 +0,0 @@
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id: compat.c,v 1.1.1.1 2008/08/24 05:33:08 gmcgarry Exp $
-
- * Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Klaus Klein and Jason R. Thorpe.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * $NetBSD: compat.c,v 1.1.1.1 2008/08/24 05:33:08 gmcgarry Exp $
-
- * Copyright (c) 1987, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $NetBSD: compat.c,v 1.1.1.1 2008/08/24 05:33:08 gmcgarry Exp $
- */
-#include <LibConfig.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/syslimits.h>
-
-#ifndef HAVE_GETOPT
-char *optarg;
-int optind = 1;
-int
-getopt(int argc, char **argv, char *args)
-{
- size_t n;
- size_t nlen = strlen(args);
- char cmd;
- char rv;
-
- if (argv[optind] && *argv[optind] == '-') {
- cmd = *(argv[optind] + 1);
-
- for (n = 0; n < nlen; n++) {
- if (args[n] == ':')
- continue;
- if (args[n] == cmd) {
- rv = *(argv[optind] + 1);
- if (args[n+1] == ':') {
- if (*(argv[optind] + 2) != '\0') {
- optarg = argv[optind] + 2;
- optind += 1;
- } else {
- optarg = argv[optind + 1];
- optind += 2;
- }
- if (!optarg)
- optarg="";
- return rv;
- } else {
- optarg = NULL;
- optind += 1;
- return rv;
- }
- }
- }
- }
- return -1;
-}
-#endif
-
-#define ISPATHSEPARATOR(x) ((x == '/') || (x == '\\'))
-
-#ifdef HAVE_BASENAME
-#ifndef PATH_MAX
- #define PATH_MAX 5000
-#endif
-
-char *
-basename(char *path)
-{
- static char singledot[] = ".";
- static char result[PATH_MAX];
- char *p, *lastp;
- size_t len;
-
- /*
- * If `path' is a null pointer or points to an empty string,
- * return a pointer to the string ".".
- */
- if ((path == NULL) || (*path == '\0'))
- return (singledot);
-
- /* Strip trailing slashes, if any. */
- lastp = path + strlen(path) - 1;
- while (lastp != path && ISPATHSEPARATOR(*lastp))
- lastp--;
-
- /* Now find the beginning of this (final) component. */
- p = lastp;
- while (p != path && !ISPATHSEPARATOR(*(p - 1)))
- p--;
-
- /* ...and copy the result into the result buffer. */
- len = (lastp - p) + 1 /* last char */;
- if (len > (PATH_MAX - 1))
- len = PATH_MAX - 1;
-
- memcpy(result, p, len);
- result[len] = '\0';
-
- return (result);
-}
-#endif
-
-#if !defined(HAVE_MKSTEMP) && !defined(WIN32)
-int
-mkstemp(char *path)
-{
- char *start, *trv;
- unsigned int pid;
-
- /* To guarantee multiple calls generate unique names even if
- the file is not created. 676 different possibilities with 7
- or more X's, 26 with 6 or less. */
- static char xtra[2] = "aa";
- int xcnt = 0;
-
- pid = getpid();
-
- /* Move to end of path and count trailing X's. */
- for (trv = path; *trv; ++trv)
- if (*trv == 'X')
- xcnt++;
- else
- xcnt = 0;
-
- /* Use at least one from xtra. Use 2 if more than 6 X's. */
- if (*(trv - 1) == 'X')
- *--trv = xtra[0];
- if (xcnt > 6 && *(trv - 1) == 'X')
- *--trv = xtra[1];
-
- /* Set remaining X's to pid digits with 0's to the left. */
- while (*--trv == 'X') {
- *trv = (pid % 10) + '0';
- pid /= 10;
- }
-
- /* update xtra for next call. */
- if (xtra[0] != 'z')
- xtra[0]++;
- else {
- xtra[0] = 'a';
- if (xtra[1] != 'z')
- xtra[1]++;
- else
- xtra[1] = 'a';
- }
-
- return open(path, O_CREAT | O_EXCL | O_RDWR, 0600);
-}
-#endif
-
-#ifdef HAVE_FFS
-int
-ffs(int x)
-{
- int r = 1;
- if (!x) return 0;
- if (!(x & 0xffff)) { x >>= 16; r += 16; }
- if (!(x & 0xff)) { x >>= 8; r += 8; }
- if (!(x & 0xf)) { x >>= 4; r += 4; }
- if (!(x & 3)) { x >>= 2; r += 2; }
- if (!(x & 1)) { x >>= 1; r += 1; }
-
- return r;
-}
-#endif
-
-/*
- * Copyright Patrick Powell 1995
- * This code is based on code written by Patrick Powell (papowell@astart.com)
- * It may be used for any purpose as long as this notice remains intact
- * on all source code distributions
- */
-
-#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
-
-static void
-dopr(char *buffer, size_t maxlen, const char *format, va_list args);
-
-static void
-fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags,
- int min, int max);
-
-static void
-fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base,
- int min, int max, int flags);
-
-static void
-fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
- int min, int max, int flags);
-
-static void
-dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
-
-/*
- * dopr(): poor man's version of doprintf
- */
-
-/* format read states */
-#define DP_S_DEFAULT 0
-#define DP_S_FLAGS 1
-#define DP_S_MIN 2
-#define DP_S_DOT 3
-#define DP_S_MAX 4
-#define DP_S_MOD 5
-#define DP_S_CONV 6
-#define DP_S_DONE 7
-
-/* format flags - Bits */
-#define DP_F_MINUS (1 << 0)
-#define DP_F_PLUS (1 << 1)
-#define DP_F_SPACE (1 << 2)
-#define DP_F_NUM (1 << 3)
-#define DP_F_ZERO (1 << 4)
-#define DP_F_UP (1 << 5)
-#define DP_F_UNSIGNED (1 << 6)
-
-/* Conversion Flags */
-#define DP_C_SHORT 1
-#define DP_C_LONG 2
-#define DP_C_LDOUBLE 3
-#define DP_C_LONG_LONG 4
-
-#define char_to_int(p) (p - '0')
-#define abs_val(p) (p < 0 ? -p : p)
-
-
-static void
-dopr(char *buffer, size_t maxlen, const char *format, va_list args)
-{
- char *strvalue, ch;
- long value;
- long double fvalue;
- int min = 0, max = -1, state = DP_S_DEFAULT, flags = 0, cflags = 0;
- size_t currlen = 0;
-
- ch = *format++;
-
- while (state != DP_S_DONE) {
- if ((ch == '\0') || (currlen >= maxlen))
- state = DP_S_DONE;
-
- switch(state) {
- case DP_S_DEFAULT:
- if (ch == '%')
- state = DP_S_FLAGS;
- else
- dopr_outch(buffer, &currlen, maxlen, ch);
- ch = *format++;
- break;
- case DP_S_FLAGS:
- switch (ch) {
- case '-':
- flags |= DP_F_MINUS;
- ch = *format++;
- break;
- case '+':
- flags |= DP_F_PLUS;
- ch = *format++;
- break;
- case ' ':
- flags |= DP_F_SPACE;
- ch = *format++;
- break;
- case '#':
- flags |= DP_F_NUM;
- ch = *format++;
- break;
- case '0':
- flags |= DP_F_ZERO;
- ch = *format++;
- break;
- default:
- state = DP_S_MIN;
- break;
- }
- break;
- case DP_S_MIN:
- if (isdigit((unsigned char)ch)) {
- min = 10 * min + char_to_int (ch);
- ch = *format++;
- } else if (ch == '*') {
- min = va_arg (args, int);
- ch = *format++;
- state = DP_S_DOT;
- } else
- state = DP_S_DOT;
- break;
- case DP_S_DOT:
- if (ch == '.') {
- state = DP_S_MAX;
- ch = *format++;
- } else
- state = DP_S_MOD;
- break;
- case DP_S_MAX:
- if (isdigit((unsigned char)ch)) {
- if (max < 0)
- max = 0;
- max = 10 * max + char_to_int(ch);
- ch = *format++;
- } else if (ch == '*') {
- max = va_arg (args, int);
- ch = *format++;
- state = DP_S_MOD;
- } else
- state = DP_S_MOD;
- break;
- case DP_S_MOD:
- switch (ch) {
- case 'h':
- cflags = DP_C_SHORT;
- ch = *format++;
- break;
- case 'l':
- cflags = DP_C_LONG;
- ch = *format++;
- if (ch == 'l') {
- cflags = DP_C_LONG_LONG;
- ch = *format++;
- }
- break;
- case 'q':
- cflags = DP_C_LONG_LONG;
- ch = *format++;
- break;
- case 'L':
- cflags = DP_C_LDOUBLE;
- ch = *format++;
- break;
- default:
- break;
- }
- state = DP_S_CONV;
- break;
- case DP_S_CONV:
- switch (ch) {
- case 'd':
- case 'i':
- if (cflags == DP_C_SHORT)
- value = va_arg(args, int);
- else if (cflags == DP_C_LONG)
- value = va_arg(args, long int);
- else if (cflags == DP_C_LONG_LONG)
- value = va_arg (args, long long);
- else
- value = va_arg (args, int);
- fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
- break;
- case 'o':
- flags |= DP_F_UNSIGNED;
- if (cflags == DP_C_SHORT)
- value = va_arg(args, unsigned int);
- else if (cflags == DP_C_LONG)
- value = va_arg(args, unsigned long int);
- else if (cflags == DP_C_LONG_LONG)
- value = va_arg(args, unsigned long long);
- else
- value = va_arg(args, unsigned int);
- fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags);
- break;
- case 'u':
- flags |= DP_F_UNSIGNED;
- if (cflags == DP_C_SHORT)
- value = va_arg(args, unsigned int);
- else if (cflags == DP_C_LONG)
- value = va_arg(args, unsigned long int);
- else if (cflags == DP_C_LONG_LONG)
- value = va_arg(args, unsigned long long);
- else
- value = va_arg(args, unsigned int);
- fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
- break;
- case 'X':
- flags |= DP_F_UP;
- case 'x':
- flags |= DP_F_UNSIGNED;
- if (cflags == DP_C_SHORT)
- value = va_arg(args, unsigned int);
- else if (cflags == DP_C_LONG)
- value = va_arg(args, unsigned long int);
- else if (cflags == DP_C_LONG_LONG)
- value = va_arg(args, unsigned long long);
- else
- value = va_arg(args, unsigned int);
- fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags);
- break;
- case 'f':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, long double);
- else
- fvalue = va_arg(args, double);
- /* um, floating point? */
- fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
- break;
- case 'E':
- flags |= DP_F_UP;
- case 'e':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, long double);
- else
- fvalue = va_arg(args, double);
- break;
- case 'G':
- flags |= DP_F_UP;
- case 'g':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, long double);
- else
- fvalue = va_arg(args, double);
- break;
- case 'c':
- dopr_outch(buffer, &currlen, maxlen, va_arg(args, int));
- break;
- case 's':
- strvalue = va_arg(args, char *);
- if (max < 0)
- max = maxlen; /* ie, no max */
- fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max);
- break;
- case 'p':
- strvalue = va_arg(args, void *);
- fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
- break;
- case 'n':
- if (cflags == DP_C_SHORT) {
- short int *num;
- num = va_arg(args, short int *);
- *num = currlen;
- } else if (cflags == DP_C_LONG) {
- long int *num;
- num = va_arg(args, long int *);
- *num = currlen;
- } else if (cflags == DP_C_LONG_LONG) {
- long long *num;
- num = va_arg(args, long long *);
- *num = currlen;
- } else {
- int *num;
- num = va_arg(args, int *);
- *num = currlen;
- }
- break;
- case '%':
- dopr_outch(buffer, &currlen, maxlen, ch);
- break;
- case 'w': /* not supported yet, treat as next char */
- ch = *format++;
- break;
- default: /* Unknown, skip */
- break;
- }
- ch = *format++;
- state = DP_S_DEFAULT;
- flags = cflags = min = 0;
- max = -1;
- break;
- case DP_S_DONE:
- break;
- default: /* hmm? */
- break; /* some picky compilers need this */
- }
- }
- if (currlen < maxlen - 1)
- buffer[currlen] = '\0';
- else
- buffer[maxlen - 1] = '\0';
-}
-
-static void
-fmtstr(char *buffer, size_t *currlen, size_t maxlen,
- char *value, int flags, int min, int max)
-{
- int cnt = 0, padlen, strln; /* amount to pad */
-
- if (value == 0)
- value = "<NULL>";
-
- for (strln = 0; value[strln]; ++strln); /* strlen */
- padlen = min - strln;
- if (padlen < 0)
- padlen = 0;
- if (flags & DP_F_MINUS)
- padlen = -padlen; /* Left Justify */
-
- while ((padlen > 0) && (cnt < max)) {
- dopr_outch(buffer, currlen, maxlen, ' ');
- --padlen;
- ++cnt;
- }
- while (*value && (cnt < max)) {
- dopr_outch(buffer, currlen, maxlen, *value++);
- ++cnt;
- }
- while ((padlen < 0) && (cnt < max)) {
- dopr_outch(buffer, currlen, maxlen, ' ');
- ++padlen;
- ++cnt;
- }
-}
-
-/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
-
-static void
-fmtint(char *buffer, size_t *currlen, size_t maxlen,
- long value, int base, int min, int max, int flags)
-{
- unsigned long uvalue;
- char convert[20];
- int signvalue = 0, place = 0, caps = 0;
- int spadlen = 0; /* amount to space pad */
- int zpadlen = 0; /* amount to zero pad */
-
-#define PADMAX(x,y) ((x) > (y) ? (x) : (y))
-
- if (max < 0)
- max = 0;
-
- uvalue = value;
-
- if (!(flags & DP_F_UNSIGNED)) {
- if (value < 0) {
- signvalue = '-';
- uvalue = -value;
- } else if (flags & DP_F_PLUS) /* Do a sign (+/i) */
- signvalue = '+';
- else if (flags & DP_F_SPACE)
- signvalue = ' ';
- }
-
- if (flags & DP_F_UP)
- caps = 1; /* Should characters be upper case? */
- do {
- convert[place++] =
- (caps ? "0123456789ABCDEF" : "0123456789abcdef")
- [uvalue % (unsigned)base];
- uvalue = (uvalue / (unsigned)base );
- } while (uvalue && (place < 20));
- if (place == 20)
- place--;
- convert[place] = 0;
-
- zpadlen = max - place;
- spadlen = min - PADMAX(max, place) - (signvalue ? 1 : 0);
- if (zpadlen < 0)
- zpadlen = 0;
- if (spadlen < 0)
- spadlen = 0;
- if (flags & DP_F_ZERO) {
- zpadlen = PADMAX(zpadlen, spadlen);
- spadlen = 0;
- }
- if (flags & DP_F_MINUS)
- spadlen = -spadlen; /* Left Justifty */
-
- /* Spaces */
- while (spadlen > 0) {
- dopr_outch(buffer, currlen, maxlen, ' ');
- --spadlen;
- }
-
- /* Sign */
- if (signvalue)
- dopr_outch(buffer, currlen, maxlen, signvalue);
-
- /* Zeros */
- if (zpadlen > 0) {
- while (zpadlen > 0) {
- dopr_outch(buffer, currlen, maxlen, '0');
- --zpadlen;
- }
- }
-
- /* Digits */
- while (place > 0)
- dopr_outch(buffer, currlen, maxlen, convert[--place]);
-
- /* Left Justified spaces */
- while (spadlen < 0) {
- dopr_outch (buffer, currlen, maxlen, ' ');
- ++spadlen;
- }
-}
-
-static long double
-pow10(int exp)
-{
- long double result = 1;
-
- while (exp) {
- result *= 10;
- exp--;
- }
-
- return result;
-}
-
-static long
-round(long double value)
-{
- long intpart = value;
-
- value -= intpart;
- if (value >= 0.5)
- intpart++;
-
- return intpart;
-}
-
-static void
-fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
- int min, int max, int flags)
-{
- char iconvert[20], fconvert[20];
- int signvalue = 0, iplace = 0, fplace = 0;
- int padlen = 0; /* amount to pad */
- int zpadlen = 0, caps = 0;
- long intpart, fracpart;
- long double ufvalue;
-
- /*
- * AIX manpage says the default is 0, but Solaris says the default
- * is 6, and sprintf on AIX defaults to 6
- */
- if (max < 0)
- max = 6;
-
- ufvalue = abs_val(fvalue);
-
- if (fvalue < 0)
- signvalue = '-';
- else if (flags & DP_F_PLUS) /* Do a sign (+/i) */
- signvalue = '+';
- else if (flags & DP_F_SPACE)
- signvalue = ' ';
-
- intpart = ufvalue;
-
- /*
- * Sorry, we only support 9 digits past the decimal because of our
- * conversion method
- */
- if (max > 9)
- max = 9;
-
- /* We "cheat" by converting the fractional part to integer by
- * multiplying by a factor of 10
- */
- fracpart = round((pow10 (max)) * (ufvalue - intpart));
-
- if (fracpart >= pow10 (max)) {
- intpart++;
- fracpart -= pow10 (max);
- }
-
- /* Convert integer part */
- do {
- iconvert[iplace++] =
- (caps ? "0123456789ABCDEF" : "0123456789abcdef")
- [intpart % 10];
- intpart = (intpart / 10);
- } while(intpart && (iplace < 20));
- if (iplace == 20)
- iplace--;
- iconvert[iplace] = 0;
-
- /* Convert fractional part */
- do {
- fconvert[fplace++] =
- (caps ? "0123456789ABCDEF" : "0123456789abcdef")
- [fracpart % 10];
- fracpart = (fracpart / 10);
- } while(fracpart && (fplace < 20));
- if (fplace == 20)
- fplace--;
- fconvert[fplace] = 0;
-
- /* -1 for decimal point, another -1 if we are printing a sign */
- padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
- zpadlen = max - fplace;
- if (zpadlen < 0)
- zpadlen = 0;
- if (padlen < 0)
- padlen = 0;
- if (flags & DP_F_MINUS)
- padlen = -padlen; /* Left Justifty */
-
- if ((flags & DP_F_ZERO) && (padlen > 0)) {
- if (signvalue) {
- dopr_outch(buffer, currlen, maxlen, signvalue);
- --padlen;
- signvalue = 0;
- }
- while (padlen > 0) {
- dopr_outch(buffer, currlen, maxlen, '0');
- --padlen;
- }
- }
- while (padlen > 0) {
- dopr_outch(buffer, currlen, maxlen, ' ');
- --padlen;
- }
- if (signvalue)
- dopr_outch(buffer, currlen, maxlen, signvalue);
-
- while (iplace > 0)
- dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
-
- /*
- * Decimal point. This should probably use locale to find the
- * correct char to print out.
- */
- dopr_outch(buffer, currlen, maxlen, '.');
-
- while (fplace > 0)
- dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
-
- while (zpadlen > 0) {
- dopr_outch(buffer, currlen, maxlen, '0');
- --zpadlen;
- }
-
- while (padlen < 0) {
- dopr_outch(buffer, currlen, maxlen, ' ');
- ++padlen;
- }
-}
-
-static void
-dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
-{
- if (*currlen < maxlen)
- buffer[(*currlen)++] = c;
-}
-#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
-
-#ifndef HAVE_VSNPRINTF
-int
-vsnprintf(char *str, size_t count, const char *fmt, va_list args)
-{
- str[0] = 0;
- dopr(str, count, fmt, args);
-
- return(strlen(str));
-}
-#endif /* !HAVE_VSNPRINTF */
-
-#ifndef HAVE_SNPRINTF
-int
-snprintf(char *str,size_t count,const char *fmt,...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- (void) vsnprintf(str, count, fmt, ap);
- va_end(ap);
-
- return(strlen(str));
-}
-
-#endif /* !HAVE_SNPRINTF */
diff --git a/StdLib/LibC/Uefi/select.c b/StdLib/LibC/Uefi/select.c
deleted file mode 100644
index 28951856d1..0000000000
--- a/StdLib/LibC/Uefi/select.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright (c) 1982, 1986, 1989, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- *
- * Portions copyright (c) 1999, 2000
- * Intel Corporation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- *
- * This product includes software developed by the University of
- * California, Berkeley, Intel Corporation, and its contributors.
- *
- * 4. Neither the name of University, Intel Corporation, or their respective
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
- * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
- * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
- * $Id: select.c,v 1.1.1.1 2003/11/19 01:50:30 kyu3 Exp $
- */
-#include <Library/UefiBootServicesTableLib.h>
-
-#include <LibConfig.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <strings.h>
-#include <sys/poll.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#ifndef KERNEL
-#define KERNEL
-#include <errno.h>
-#undef KERNEL
-#else
-#include <errno.h>
-#endif
-
-#ifdef EFI_NT_EMULATOR
-#define _SELECT_DELAY_ 10000
-#else
-#define _SELECT_DELAY_ 1000
-#endif
-
-#define MAX_SLEEP_DELAY 0xfffffffe
-
-/** Sleep for the specified number of Microseconds.
-
- Implements the usleep(3) function.
-
- @param[in] Microseconds Number of microseconds to sleep.
-
- @retval 0 Always returns zero.
-**/
-int
-usleep( useconds_t Microseconds )
-{
- while ( MAX_SLEEP_DELAY < Microseconds ) {
- gBS->Stall ( MAX_SLEEP_DELAY );
- Microseconds -= MAX_SLEEP_DELAY;
- }
- gBS->Stall((UINTN)Microseconds );
- return (0);
-}
-
-unsigned int
-sleep( unsigned int Seconds )
-{
- return (usleep( (useconds_t)(Seconds * 1000000) ));
-}
-
-static int
-selscan(
- fd_mask **ibits,
- fd_mask **obits,
- int nfd,
- int *nselected
- )
-{
- int msk;
- int i;
- int j;
- int fd;
- int n;
- struct pollfd pfd;
- int FdCount;
- fd_mask bits;
- /* Note: backend also returns POLLHUP/POLLERR if appropriate. */
- static int16_t flag[3] = { POLLRDNORM, POLLWRNORM, POLLRDBAND };
-
- for (msk = 0, n = 0; msk < 3; msk++) {
- if (ibits[msk] == NULL)
- continue;
- for (i = 0; i < nfd; i += NFDBITS) {
- bits = ibits[ msk ][ i / NFDBITS ];
- while (( 0 != (j = ffs(bits))) && ((fd = i + --j) < nfd)) {
- bits &= ~(1 << j);
-
- pfd.fd = fd;
- pfd.events = flag[msk];
- pfd.revents = 0;
- FdCount = poll ( &pfd, 1, 0 );
- if ( -1 == FdCount ) {
- return errno;
- }
- if ( 0 != FdCount ) {
- obits[msk][(fd)/NFDBITS] |=
- (1 << ((fd) % NFDBITS));
- n++;
- break;
- }
- }
- }
- }
- *nselected = n;
- return (0);
-}
-
-int
-select(
- int nd,
- fd_set *in,
- fd_set *ou,
- fd_set *ex,
- struct timeval *tv
- )
-{
- fd_mask *ibits[3], *obits[3], *selbits, *sbp;
- int error, forever, nselected;
- u_int nbufbytes, ncpbytes, nfdbits;
- int64_t timo;
-
- if (nd < 0)
- return (EINVAL);
-
- /*
- * Allocate just enough bits for the non-null fd_sets. Use the
- * preallocated auto buffer if possible.
- */
- nfdbits = roundup(nd, NFDBITS);
- ncpbytes = nfdbits / NBBY;
- nbufbytes = 0;
- if (in != NULL)
- nbufbytes += 2 * ncpbytes;
- if (ou != NULL)
- nbufbytes += 2 * ncpbytes;
- if (ex != NULL)
- nbufbytes += 2 * ncpbytes;
- selbits = malloc(nbufbytes);
-
- /*
- * Assign pointers into the bit buffers and fetch the input bits.
- * Put the output buffers together so that they can be bzeroed
- * together.
- */
- sbp = selbits;
-#define getbits(name, x) \
- do { \
- if (name == NULL) \
- ibits[x] = NULL; \
- else { \
- ibits[x] = sbp + nbufbytes / 2 / sizeof *sbp; \
- obits[x] = sbp; \
- sbp += ncpbytes / sizeof *sbp; \
- bcopy(name, ibits[x], ncpbytes); \
- } \
- } while (0)
- getbits(in, 0);
- getbits(ou, 1);
- getbits(ex, 2);
-#undef getbits
- if (nbufbytes != 0)
- memset(selbits, 0, nbufbytes / 2);
-
- if (tv) {
- timo = tv->tv_usec + (tv->tv_sec * 1000000);
- forever = 0;
- } else {
- timo = 0;
- forever = 1;
- }
-
- /*
- * Poll for I/O events
- */
- nselected = 0;
- do {
- /*
- * Scan for pending I/O
- */
- error = selscan(ibits, obits, nd, &nselected);
- if (error || nselected)
- break;
-
- /*
- * Adjust timeout is needed
- */
- if (timo) {
- /*
- * Give it a rest
- */
- usleep( _SELECT_DELAY_ );
- timo -= _SELECT_DELAY_;
- }
-
- } while (timo > 0 || forever);
-
- /* select is not restarted after signals... */
- if (error == ERESTART)
- error = EINTR;
- else if (error == EWOULDBLOCK)
- error = 0;
-
-#define putbits(name, x) if (name) bcopy(obits[x], name, ncpbytes)
- if (error == 0) {
- putbits(in, 0);
- putbits(ou, 1);
- putbits(ex, 2);
-#undef putbits
- } else {
- errno = error;
- nselected = -1;
- }
-
- free( selbits );
- return ( nselected );
-}
diff --git a/StdLib/LibC/Uefi/writev.c b/StdLib/LibC/Uefi/writev.c
deleted file mode 100644
index 31d2acd629..0000000000
--- a/StdLib/LibC/Uefi/writev.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/** @file
- *
- * Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. All advertising materials mentioning features or use of this software must
- * display the following acknowledgement:
- *
- * This product includes software developed by Intel Corporation and its
- * contributors.
- *
- * 4. Neither the name of Intel Corporation or its contributors may be used to
- * endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/*++
-
-Module Name:
-
- writev.c
-
-Abstract:
-
- Functions implementing the standard "writev" system call interface
-
-
-Revision History
-
---*/
-#include <LibConfig.h>
-
-#ifdef foo
-#include <efi_interface.h>
-#include <unistd.h>
-#include <fcntl.h>
-#define KERNEL
-#include <errno.h>
-#undef KERNEL
-#include "./filedesc.h"
-
-#include <libc_debug.h>
-#include <assert.h>
-#endif
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/uio.h>
-#include <string.h>
-#ifndef KERNEL
-#define KERNEL
-#include <errno.h>
-#undef KERNEL
-#else
-#include <errno.h>
-#endif
-
-//
-// Name:
-// writev
-//
-// Description:
-// BSD writev interface for libc
-//
-// Arguments:
-// File Descriptor (index into file descriptor table)
-// iovec pointer
-// size of iovec array
-//
-// Returns:
-// number of bytes written
-//
-
-ssize_t
-writev(
- int fd,
- const struct iovec *iov,
- int iovcnt
- )
-{
- const struct iovec *pVecTmp;
- char *pBuf;
- size_t TotalBytes;
- size_t i;
- size_t ret;
-
- //
- // See how much memory we'll need
- //
-
- for (i = 0, TotalBytes = 0, pVecTmp = iov; i < (size_t)iovcnt; i++, pVecTmp++) {
- TotalBytes += pVecTmp->iov_len;
- }
-
- //
- // Allocate a contiguous buffer
- //
-
- pBuf = (char*)malloc (TotalBytes);
- if (pBuf == NULL) {
- errno = ENOMEM;
- return -1;
- }
-
- //
- // Copy vectors to the buffer
- //
-
- for (; iovcnt; iovcnt--) {
- bcopy(iov->iov_base, pBuf, iov->iov_len);
- pBuf += iov->iov_len;
- iov++;
- }
-
- //
- // Use standard write(2) then free buffer
- //
-
- ret = write (fd, pBuf, TotalBytes);
- free (pBuf);
-
- return (ret);
-}