diff options
Diffstat (limited to 'StdLib/LibC/Uefi/Devices')
-rw-r--r-- | StdLib/LibC/Uefi/Devices/Console/daConsole.c | 765 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/UefiShell/daShell.c | 856 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c | 158 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/Utility/DevSearch.c | 112 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/Utility/Path.c | 431 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/daConsole.inf | 52 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/daShell.inf | 52 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/daUtility.inf | 44 |
8 files changed, 0 insertions, 2470 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
|