udk2010.up2.shell initial release.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10874 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Provides interface to EFI_FILE_HANDLE functionality.
|
||||
|
||||
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
@@ -30,13 +30,13 @@
|
||||
#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
|
||||
|
||||
/**
|
||||
This function will retrieve the information about the file for the handle
|
||||
This function will retrieve the information about the file for the handle
|
||||
specified and store it in allocated pool memory.
|
||||
|
||||
This function allocates a buffer to store the file's information. It is the
|
||||
This function allocates a buffer to store the file's information. It is the
|
||||
caller's responsibility to free the buffer
|
||||
|
||||
@param FileHandle The file handle of the file for which information is
|
||||
@param FileHandle The file handle of the file for which information is
|
||||
being requested.
|
||||
|
||||
@retval NULL information could not be retrieved.
|
||||
@@ -49,7 +49,7 @@ FileHandleGetInfo (
|
||||
IN EFI_FILE_HANDLE FileHandle
|
||||
)
|
||||
{
|
||||
EFI_FILE_INFO *pFileInfo;
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
UINTN FileInfoSize;
|
||||
EFI_STATUS Status;
|
||||
|
||||
@@ -62,51 +62,52 @@ FileHandleGetInfo (
|
||||
// Get the required size to allocate
|
||||
//
|
||||
FileInfoSize = 0;
|
||||
pFileInfo = NULL;
|
||||
Status = FileHandle->GetInfo(FileHandle,
|
||||
&gEfiFileInfoGuid,
|
||||
&FileInfoSize,
|
||||
pFileInfo);
|
||||
FileInfo = NULL;
|
||||
Status = FileHandle->GetInfo(FileHandle,
|
||||
&gEfiFileInfoGuid,
|
||||
&FileInfoSize,
|
||||
FileInfo);
|
||||
//
|
||||
// error is expected. getting size to allocate
|
||||
//
|
||||
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
|
||||
pFileInfo = AllocateZeroPool(FileInfoSize);
|
||||
ASSERT (pFileInfo != NULL);
|
||||
FileInfo = AllocateZeroPool(FileInfoSize);
|
||||
ASSERT (FileInfo != NULL);
|
||||
//
|
||||
// now get the information
|
||||
//
|
||||
Status = FileHandle->GetInfo(FileHandle,
|
||||
&gEfiFileInfoGuid,
|
||||
&FileInfoSize,
|
||||
pFileInfo);
|
||||
Status = FileHandle->GetInfo(FileHandle,
|
||||
&gEfiFileInfoGuid,
|
||||
&FileInfoSize,
|
||||
FileInfo);
|
||||
//
|
||||
// if we got an error free the memory and return NULL
|
||||
//
|
||||
if (EFI_ERROR(Status)) {
|
||||
FreePool(pFileInfo);
|
||||
FreePool(FileInfo);
|
||||
return NULL;
|
||||
}
|
||||
return (pFileInfo);
|
||||
return (FileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
This function will set the information about the file for the opened handle
|
||||
This function sets the information about the file for the opened handle
|
||||
specified.
|
||||
|
||||
@param FileHandle The file handle of the file for which information
|
||||
is being set
|
||||
@param[in] FileHandle The file handle of the file for which information
|
||||
is being set.
|
||||
|
||||
@param FileInfo The infotmation to set.
|
||||
@param[in] FileInfo The information to set.
|
||||
|
||||
@retval EFI_SUCCESS The information was set.
|
||||
@retval EFI_UNSUPPORTED The InformationType is not known.
|
||||
@retval EFI_NO_MEDIA The device has no medium.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error.
|
||||
@retval EFI_SUCCESS The information was set.
|
||||
@retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
|
||||
@retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
|
||||
@retval EFI_NO_MEDIA The device has no medium.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error.
|
||||
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
||||
@retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
||||
@retval EFI_ACCESS_DENIED The file was opened read only.
|
||||
@retval EFI_VOLUME_FULL The volume is full.
|
||||
@retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
||||
@retval EFI_ACCESS_DENIED The file was opened read only.
|
||||
@retval EFI_VOLUME_FULL The volume is full.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@@ -115,7 +116,7 @@ FileHandleSetInfo (
|
||||
IN CONST EFI_FILE_INFO *FileInfo
|
||||
)
|
||||
{
|
||||
|
||||
|
||||
//
|
||||
// ASSERT if the FileHandle or FileInfo is NULL
|
||||
//
|
||||
@@ -125,38 +126,38 @@ FileHandleSetInfo (
|
||||
//
|
||||
// Set the info
|
||||
//
|
||||
return (FileHandle->SetInfo(FileHandle,
|
||||
return (FileHandle->SetInfo(FileHandle,
|
||||
&gEfiFileInfoGuid,
|
||||
(UINTN)FileInfo->Size,
|
||||
(EFI_FILE_INFO*)FileInfo));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
This function reads information from an opened file.
|
||||
|
||||
If FileHandle is not a directory, the function reads the requested number of
|
||||
bytes from the file at the file's current position and returns them in Buffer.
|
||||
If FileHandle is not a directory, the function reads the requested number of
|
||||
bytes from the file at the file's current position and returns them in Buffer.
|
||||
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 FileHandle is a directory, the function reads the directory entry
|
||||
at the file's current position and returns the entry in Buffer. If the Buffer
|
||||
is not large enough to hold the current directory entry, then
|
||||
EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
|
||||
BufferSize is set to be the size of the buffer needed to read the entry. 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.
|
||||
end of the file. The file's current position is increased by the number of bytes
|
||||
returned. If FileHandle is a directory, the function reads the directory entry
|
||||
at the file's current position and returns the entry in Buffer. If the Buffer
|
||||
is not large enough to hold the current directory entry, then
|
||||
EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
|
||||
BufferSize is set to be the size of the buffer needed to read the entry. 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 FileHandle the opened file handle
|
||||
@param BufferSize on input the size of buffer in bytes. on return
|
||||
@param BufferSize on input the size of buffer in bytes. on return
|
||||
the number of bytes written.
|
||||
@param Buffer the buffer to put read data into.
|
||||
|
||||
@retval EFI_SUCCESS Data was read.
|
||||
@retval EFI_NO_MEDIA The device has no media.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error.
|
||||
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
||||
@retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
|
||||
@retval EFI_SUCCESS Data was read.
|
||||
@retval EFI_NO_MEDIA The device has no media.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error.
|
||||
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
||||
@retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
|
||||
size.
|
||||
|
||||
**/
|
||||
@@ -183,11 +184,11 @@ FileHandleRead(
|
||||
/**
|
||||
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
|
||||
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.
|
||||
|
||||
@param FileHandle The opened file for writing
|
||||
@@ -222,11 +223,11 @@ FileHandleWrite(
|
||||
return (FileHandle->Write(FileHandle, BufferSize, Buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
Close an open file handle.
|
||||
|
||||
This function closes a specified file handle. All "dirty" cached file data is
|
||||
flushed to the device, and the file is closed. In all cases the handle is
|
||||
This function closes a specified file handle. All "dirty" cached file data is
|
||||
flushed to the device, and the file is closed. In all cases the handle is
|
||||
closed.
|
||||
|
||||
@param FileHandle the file handle to close.
|
||||
@@ -255,13 +256,13 @@ FileHandleClose (
|
||||
Delete a file and close the handle
|
||||
|
||||
This function closes and deletes a file. In all cases the file handle is closed.
|
||||
If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
|
||||
If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
|
||||
returned, but the handle is still closed.
|
||||
|
||||
@param FileHandle the file handle to delete
|
||||
|
||||
@retval EFI_SUCCESS the file was closed sucessfully
|
||||
@retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
|
||||
@retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
|
||||
deleted
|
||||
@retval INVALID_PARAMETER One of the parameters has an invalid value.
|
||||
**/
|
||||
@@ -286,19 +287,19 @@ FileHandleDelete (
|
||||
/**
|
||||
Set the current position in a file.
|
||||
|
||||
This function sets the current file position for the handle to the position
|
||||
This function sets the current file position for the handle to the position
|
||||
supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
|
||||
absolute positioning is supported, and seeking past the end of the file is
|
||||
allowed (a subsequent write would grow the file). Seeking to position
|
||||
absolute positioning is supported, and seeking past the end of the file is
|
||||
allowed (a subsequent write would grow the file). Seeking to position
|
||||
0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
|
||||
If FileHandle is a directory, the only position that may be set is zero. This
|
||||
If FileHandle is a directory, the only position that may be set is zero. This
|
||||
has the effect of starting the read process of the directory entries over.
|
||||
|
||||
@param FileHandle The file handle on which the position is being set
|
||||
@param Position Byte position from begining of file
|
||||
|
||||
@retval EFI_SUCCESS Operation completed sucessfully.
|
||||
@retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
|
||||
@retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
|
||||
directories.
|
||||
@retval INVALID_PARAMETER One of the parameters has an invalid value.
|
||||
**/
|
||||
@@ -319,11 +320,11 @@ FileHandleSetPosition (
|
||||
return (FileHandle->SetPosition(FileHandle, Position));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
Gets a file's current position
|
||||
|
||||
This function retrieves the current file position for the file handle. For
|
||||
directories, the current file position has no meaning outside of the file
|
||||
This function retrieves the current file position for the file handle. For
|
||||
directories, the current file position has no meaning outside of the file
|
||||
system driver and as such the operation is not supported. An error is returned
|
||||
if FileHandle is a directory.
|
||||
|
||||
@@ -341,6 +342,9 @@ FileHandleGetPosition (
|
||||
OUT UINT64 *Position
|
||||
)
|
||||
{
|
||||
if (Position == NULL) {
|
||||
return (EFI_INVALID_PARAMETER);
|
||||
}
|
||||
//
|
||||
// ASSERT if FileHandle is NULL
|
||||
//
|
||||
@@ -352,7 +356,7 @@ FileHandleGetPosition (
|
||||
}
|
||||
/**
|
||||
Flushes data on a file
|
||||
|
||||
|
||||
This function flushes all modified data associated with a file to a device.
|
||||
|
||||
@param FileHandle The file handle on which to flush data
|
||||
@@ -406,12 +410,12 @@ FileHandleIsDirectory (
|
||||
// ASSERT if DirHandle is NULL
|
||||
//
|
||||
ASSERT(DirHandle != NULL);
|
||||
|
||||
|
||||
//
|
||||
// get the file information for DirHandle
|
||||
//
|
||||
DirInfo = FileHandleGetInfo (DirHandle);
|
||||
|
||||
|
||||
//
|
||||
// Parse DirInfo
|
||||
//
|
||||
@@ -420,7 +424,7 @@ FileHandleIsDirectory (
|
||||
// We got nothing...
|
||||
//
|
||||
return (EFI_INVALID_PARAMETER);
|
||||
}
|
||||
}
|
||||
if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
|
||||
//
|
||||
// Attributes say this is not a directory
|
||||
@@ -438,8 +442,8 @@ FileHandleIsDirectory (
|
||||
/**
|
||||
Retrieves the first file from a directory
|
||||
|
||||
This function opens a directory and gets the first file's info in the
|
||||
directory. Caller can use FileHandleFindNextFile() to get other files. When
|
||||
This function opens a directory and gets the first file's info in the
|
||||
directory. Caller can use FileHandleFindNextFile() to get other files. When
|
||||
complete the caller is responsible for calling FreePool() on Buffer.
|
||||
|
||||
@param DirHandle The file handle of the directory to search
|
||||
@@ -475,15 +479,15 @@ FileHandleFindFirstFile (
|
||||
Status = FileHandleIsDirectory(DirHandle);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return (Status);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// reset to the begining of the directory
|
||||
// reset to the begining of the directory
|
||||
//
|
||||
Status = FileHandleSetPosition(DirHandle, 0);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return (Status);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Allocate a buffer sized to struct size + enough for the string at the end
|
||||
@@ -507,12 +511,12 @@ FileHandleFindFirstFile (
|
||||
/**
|
||||
Retrieves the next file in a directory.
|
||||
|
||||
To use this function, caller must call the FileHandleFindFirstFile() to get the
|
||||
first file, and then use this function get other files. This function can be
|
||||
called for several times to get each file's information in the directory. If
|
||||
the call of FileHandleFindNextFile() got the last file in the directory, the next
|
||||
call of this function has no file to get. *NoFile will be set to TRUE and the
|
||||
Buffer memory will be automatically freed.
|
||||
To use this function, caller must call the FileHandleFindFirstFile() to get the
|
||||
first file, and then use this function get other files. This function can be
|
||||
called for several times to get each file's information in the directory. If
|
||||
the call of FileHandleFindNextFile() got the last file in the directory, the next
|
||||
call of this function has no file to get. *NoFile will be set to TRUE and the
|
||||
Buffer memory will be automatically freed.
|
||||
|
||||
@param DirHandle the file handle of the directory
|
||||
@param Buffer pointer to buffer for file's information
|
||||
@@ -565,13 +569,14 @@ FileHandleFindNextFile(
|
||||
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieve the size of a file.
|
||||
|
||||
if FileHandle is NULL then ASSERT()
|
||||
if Size is NULL then ASSERT()
|
||||
|
||||
This function extracts the file size info from the FileHandle's EFI_FILE_INFO
|
||||
This function extracts the file size info from the FileHandle's EFI_FILE_INFO
|
||||
data.
|
||||
|
||||
@param FileHandle file handle from which size is retrieved
|
||||
@@ -594,7 +599,7 @@ FileHandleGetSize (
|
||||
//
|
||||
ASSERT (FileHandle != NULL);
|
||||
ASSERT (Size != NULL);
|
||||
|
||||
|
||||
//
|
||||
// get the FileInfo structure
|
||||
//
|
||||
@@ -607,7 +612,7 @@ FileHandleGetSize (
|
||||
// Assign the Size pointer to the correct value
|
||||
//
|
||||
*Size = FileInfo->FileSize;
|
||||
|
||||
|
||||
//
|
||||
// free the FileInfo memory
|
||||
//
|
||||
@@ -616,47 +621,98 @@ FileHandleGetSize (
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Set the size of a file.
|
||||
|
||||
If FileHandle is NULL then ASSERT().
|
||||
|
||||
This function changes the file size info from the FileHandle's EFI_FILE_INFO
|
||||
data.
|
||||
|
||||
@param FileHandle File handle whose size is to be changed.
|
||||
@param Size New size.
|
||||
|
||||
@retval EFI_SUCCESS operation was completed sucessfully.
|
||||
@retval EFI_DEVICE_ERROR cannot access the file.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FileHandleSetSize (
|
||||
IN EFI_FILE_HANDLE FileHandle,
|
||||
IN UINT64 Size
|
||||
)
|
||||
{
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// ASSERT for FileHandle or Size being NULL
|
||||
//
|
||||
ASSERT (FileHandle != NULL);
|
||||
|
||||
//
|
||||
// get the FileInfo structure
|
||||
//
|
||||
FileInfo = FileHandleGetInfo(FileHandle);
|
||||
if (FileInfo == NULL) {
|
||||
return (EFI_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
//
|
||||
// Assign the FileSize pointer to the new value
|
||||
//
|
||||
FileInfo->FileSize = Size;
|
||||
|
||||
Status = FileHandleSetInfo(FileHandle, FileInfo);
|
||||
//
|
||||
// free the FileInfo memory
|
||||
//
|
||||
FreePool(FileInfo);
|
||||
|
||||
return (Status);
|
||||
}
|
||||
|
||||
/**
|
||||
Safely append (on the left) with automatic string resizing given length of Destination and
|
||||
Safely append (on the left) with automatic string resizing given length of Destination and
|
||||
desired length of copy from Source.
|
||||
|
||||
append the first D characters of Source to the end of Destination, where D is
|
||||
the lesser of Count and the StrLen() of Source. If appending those D characters
|
||||
will fit within Destination (whose Size is given as CurrentSize) and
|
||||
still leave room for a NULL terminator, then those characters are appended,
|
||||
starting at the original terminating NULL of Destination, and a new terminating
|
||||
append the first D characters of Source to the end of Destination, where D is
|
||||
the lesser of Count and the StrLen() of Source. If appending those D characters
|
||||
will fit within Destination (whose Size is given as CurrentSize) and
|
||||
still leave room for a NULL terminator, then those characters are appended,
|
||||
starting at the original terminating NULL of Destination, and a new terminating
|
||||
NULL is appended.
|
||||
|
||||
If appending D characters onto Destination will result in a overflow of the size
|
||||
given in CurrentSize the string will be grown such that the copy can be performed
|
||||
and CurrentSize will be updated to the new size.
|
||||
|
||||
If Source is NULL, there is nothing to append, just return the current buffer in
|
||||
If Source is NULL, there is nothing to append, just return the current buffer in
|
||||
Destination.
|
||||
|
||||
if Destination is NULL, then ASSERT()
|
||||
if Destination's current length (including NULL terminator) is already more then
|
||||
if Destination's current length (including NULL terminator) is already more then
|
||||
CurrentSize, then ASSERT()
|
||||
|
||||
@param[in,out] Destination The String to append onto
|
||||
@param[in,out] CurrentSize on call the number of bytes in Destination. On
|
||||
@param[in,out] CurrentSize on call the number of bytes in Destination. On
|
||||
return possibly the new size (still in bytes). if NULL
|
||||
then allocate whatever is needed.
|
||||
@param[in] Source The String to append from
|
||||
@param[in] Count Maximum number of characters to append. if 0 then
|
||||
@param[in] Count Maximum number of characters to append. if 0 then
|
||||
all are appended.
|
||||
|
||||
@return Destination return the resultant string.
|
||||
**/
|
||||
CHAR16*
|
||||
CHAR16*
|
||||
EFIAPI
|
||||
StrnCatGrowLeft (
|
||||
IN OUT CHAR16 **Destination,
|
||||
IN OUT UINTN *CurrentSize,
|
||||
IN CONST CHAR16 *Source,
|
||||
IN UINTN Count
|
||||
){
|
||||
)
|
||||
{
|
||||
UINTN DestinationStartSize;
|
||||
UINTN NewSize;
|
||||
UINTN CopySize;
|
||||
@@ -713,13 +769,13 @@ StrnCatGrowLeft (
|
||||
}
|
||||
|
||||
/**
|
||||
Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
|
||||
Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
|
||||
directory 'stack'.
|
||||
|
||||
if Handle is NULL, return EFI_INVALID_PARAMETER
|
||||
|
||||
@param[in] Handle Handle to the Directory or File to create path to.
|
||||
@param[out] FullFileName pointer to pointer to generated full file name. It
|
||||
@param[out] FullFileName pointer to pointer to generated full file name. It
|
||||
is the responsibility of the caller to free this memory
|
||||
with a call to FreePool().
|
||||
@retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.
|
||||
@@ -732,7 +788,8 @@ EFIAPI
|
||||
FileHandleGetFileName (
|
||||
IN CONST EFI_FILE_HANDLE Handle,
|
||||
OUT CHAR16 **FullFileName
|
||||
){
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Size;
|
||||
EFI_FILE_HANDLE CurrentHandle;
|
||||
@@ -749,6 +806,7 @@ FileHandleGetFileName (
|
||||
}
|
||||
|
||||
*FullFileName = NULL;
|
||||
CurrentHandle = NULL;
|
||||
|
||||
Status = Handle->Open(Handle, &CurrentHandle, L".", EFI_FILE_MODE_READ, 0);
|
||||
if (!EFI_ERROR(Status)) {
|
||||
@@ -766,14 +824,17 @@ FileHandleGetFileName (
|
||||
//
|
||||
if (StrLen (FileInfo->FileName) == 0) {
|
||||
if (*FullFileName == NULL) {
|
||||
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
||||
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
||||
}
|
||||
FreePool(FileInfo);
|
||||
break;
|
||||
} else {
|
||||
if (*FullFileName == NULL) {
|
||||
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
||||
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
||||
}
|
||||
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
||||
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, FileInfo->FileName, 0);
|
||||
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
||||
FreePool(FileInfo);
|
||||
@@ -790,6 +851,10 @@ FileHandleGetFileName (
|
||||
FileHandleClose(CurrentHandle);
|
||||
CurrentHandle = NextHigherHandle;
|
||||
}
|
||||
} else if (Status == EFI_NOT_FOUND) {
|
||||
Status = EFI_SUCCESS;
|
||||
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
||||
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
||||
}
|
||||
|
||||
if (CurrentHandle != NULL) {
|
||||
@@ -804,10 +869,10 @@ FileHandleGetFileName (
|
||||
}
|
||||
|
||||
/**
|
||||
Function to read a single line from a file. The \n is not included in the returned
|
||||
Function to read a single line from a file. The \n is not included in the returned
|
||||
buffer. The returned buffer must be callee freed.
|
||||
|
||||
If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
||||
If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
||||
maintained and not changed for all operations with the same file.
|
||||
|
||||
@param[in] Handle FileHandle to read from.
|
||||
@@ -845,24 +910,24 @@ FileHandleReturnLine(
|
||||
}
|
||||
|
||||
/**
|
||||
Function to read a single line (up to but not including the \n) from a file.
|
||||
Function to read a single line (up to but not including the \n) from a EFI_FILE_HANDLE.
|
||||
|
||||
If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
||||
If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
||||
maintained and not changed for all operations with the same file.
|
||||
|
||||
@param[in] Handle FileHandle to read from
|
||||
@param[in,out] Buffer pointer to buffer to read into
|
||||
@param[in,out] Size pointer to number of bytes in buffer
|
||||
@param[in] Truncate if TRUE then allows for truncation of the line to fit.
|
||||
if FALSE will reset the position to the begining of the
|
||||
if FALSE will reset the position to the begining of the
|
||||
line if the buffer is not large enough.
|
||||
@param[in,out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
|
||||
|
||||
@retval EFI_SUCCESS the operation was sucessful. the line is stored in
|
||||
@retval EFI_SUCCESS the operation was sucessful. the line is stored in
|
||||
Buffer.
|
||||
@retval EFI_INVALID_PARAMETER Handle was NULL.
|
||||
@retval EFI_INVALID_PARAMETER Size was NULL.
|
||||
@retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
|
||||
@retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
|
||||
Size was updated to minimum space required.
|
||||
@sa FileHandleRead
|
||||
**/
|
||||
@@ -874,7 +939,8 @@ FileHandleReadLine(
|
||||
IN OUT UINTN *Size,
|
||||
IN BOOLEAN Truncate,
|
||||
IN OUT BOOLEAN *Ascii
|
||||
){
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
CHAR16 CharBuffer;
|
||||
UINTN CharSize;
|
||||
@@ -884,8 +950,13 @@ FileHandleReadLine(
|
||||
|
||||
if (Handle == NULL
|
||||
||Size == NULL
|
||||
){
|
||||
return (EFI_INVALID_PARAMETER);
|
||||
){
|
||||
return (EFI_INVALID_PARAMETER);
|
||||
}
|
||||
if (Buffer == NULL) {
|
||||
ASSERT(*Size == 0);
|
||||
} else {
|
||||
*Buffer = CHAR_NULL;
|
||||
}
|
||||
FileHandleGetPosition(Handle, &OriginalFilePosition);
|
||||
if (OriginalFilePosition == 0) {
|
||||
@@ -908,17 +979,11 @@ FileHandleReadLine(
|
||||
CharSize = sizeof(CHAR16);
|
||||
}
|
||||
Status = FileHandleRead(Handle, &CharSize, &CharBuffer);
|
||||
if (OriginalFilePosition == 0 && *Ascii == FALSE && CountSoFar == 0) {
|
||||
//
|
||||
// we need to skip the unicode tag
|
||||
//
|
||||
continue;
|
||||
}
|
||||
if ( EFI_ERROR(Status)
|
||||
|| CharSize == 0
|
||||
|| (CharBuffer == L'\n' && *Ascii == FALSE)
|
||||
|| (CharBuffer == '\n' && *Ascii != FALSE )
|
||||
){
|
||||
if ( EFI_ERROR(Status)
|
||||
|| CharSize == 0
|
||||
|| (CharBuffer == L'\n' && !(*Ascii))
|
||||
|| (CharBuffer == '\n' && *Ascii)
|
||||
){
|
||||
break;
|
||||
}
|
||||
//
|
||||
@@ -936,7 +1001,7 @@ FileHandleReadLine(
|
||||
//
|
||||
if ((CountSoFar+1)*sizeof(CHAR16) > *Size){
|
||||
*Size = (CountSoFar+1)*sizeof(CHAR16);
|
||||
if (Truncate == FALSE) {
|
||||
if (!Truncate) {
|
||||
FileHandleSetPosition(Handle, OriginalFilePosition);
|
||||
} else {
|
||||
DEBUG((DEBUG_WARN, "The line was truncated in FileHandleReadLine"));
|
||||
@@ -969,7 +1034,8 @@ EFIAPI
|
||||
FileHandleWriteLine(
|
||||
IN EFI_FILE_HANDLE Handle,
|
||||
IN CHAR16 *Buffer
|
||||
){
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Size;
|
||||
|
||||
@@ -1031,7 +1097,7 @@ FileHandlePrintLine(
|
||||
Status = FileHandleWriteLine(Handle, Buffer);
|
||||
|
||||
//
|
||||
// Cleanup and return
|
||||
// Cleanup and return
|
||||
//
|
||||
FreePool(Buffer);
|
||||
return (Status);
|
||||
@@ -1063,15 +1129,15 @@ FileHandleEof(
|
||||
// ASSERT if Handle is NULL
|
||||
//
|
||||
ASSERT(Handle != NULL);
|
||||
|
||||
|
||||
FileHandleGetPosition(Handle, &Pos);
|
||||
Info = FileHandleGetInfo (Handle);
|
||||
ASSERT(Info != NULL);
|
||||
FileHandleSetPosition(Handle, Pos);
|
||||
|
||||
|
||||
if (Info == NULL) {
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (Pos == Info->FileSize) {
|
||||
RetVal = TRUE;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## @file
|
||||
## @file
|
||||
# Provides interface to shell functionality for shell commands and applications.
|
||||
#
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
@@ -25,7 +25,7 @@
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
[Sources.common]
|
||||
BaseFileHandleLib.c
|
||||
|
||||
[Packages]
|
||||
@@ -46,5 +46,5 @@
|
||||
[Guids]
|
||||
gEfiFileInfoGuid # ALWAYS_CONSUMED
|
||||
|
||||
[Pcd]
|
||||
[Pcd.common]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Library used for sorting routines.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
@@ -62,7 +62,7 @@ QuickSortWorker (
|
||||
|
||||
if ( Count < 2
|
||||
|| ElementSize < 1
|
||||
){
|
||||
){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ QuickSortWorker (
|
||||
for ( LoopCount = 0
|
||||
; LoopCount < Count -1
|
||||
; LoopCount++
|
||||
){
|
||||
){
|
||||
//
|
||||
// if the element is less than the pivot
|
||||
//
|
||||
@@ -174,6 +174,9 @@ PerformQuickSort (
|
||||
/**
|
||||
Not supported in Base version.
|
||||
|
||||
@param[in] Buffer1 Ignored.
|
||||
@param[in] Buffer2 Ignored.
|
||||
|
||||
ASSERT and return 0.
|
||||
**/
|
||||
INTN
|
||||
@@ -209,3 +212,25 @@ StringNoCaseCompare (
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Function to compare 2 strings.
|
||||
|
||||
@param[in] Buffer1 Pointer to String to compare (CHAR16**).
|
||||
@param[in] Buffer2 Pointer to second String to compare (CHAR16**).
|
||||
|
||||
@retval 0 Buffer1 equal to Buffer2.
|
||||
@return < 0 Buffer1 is less than Buffer2.
|
||||
@return > 0 Buffer1 is greater than Buffer2.
|
||||
**/
|
||||
INTN
|
||||
EFIAPI
|
||||
StringCompare (
|
||||
IN CONST VOID *Buffer1,
|
||||
IN CONST VOID *Buffer2
|
||||
)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## @file
|
||||
## @file
|
||||
# Library used for sorting routines.
|
||||
#
|
||||
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2009-2010, Intel Corporation.All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
@@ -19,13 +19,13 @@
|
||||
FILE_GUID = 03F3331B-F12D-494f-BF37-E55A657F2497
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = SORTLib|UEFI_APPLICATION UEFI_DRIVER
|
||||
LIBRARY_CLASS = SortLib|UEFI_APPLICATION UEFI_DRIVER
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
[Sources.common]
|
||||
BaseSortLib.c
|
||||
|
||||
[Packages]
|
||||
@@ -42,4 +42,4 @@
|
||||
|
||||
[Guids]
|
||||
|
||||
[Pcd]
|
||||
[Pcd.common]
|
||||
|
1420
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
Normal file
1420
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
Normal file
File diff suppressed because it is too large
Load Diff
142
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.h
Normal file
142
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/** @file
|
||||
Provides interface to advanced shell functionality for parsing both handle and protocol database.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
#include <Guid/FileInfo.h>
|
||||
#include <Guid/ConsoleInDevice.h>
|
||||
#include <Guid/ConsoleOutDevice.h>
|
||||
#include <Guid/StandardErrorDevice.h>
|
||||
#include <Guid/GlobalVariable.h>
|
||||
#include <Guid/Gpt.h>
|
||||
#include <Guid/FileSystemInfo.h>
|
||||
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Protocol/EfiShellInterface.h>
|
||||
#include <Protocol/EfiShellEnvironment2.h>
|
||||
#include <Protocol/EfiShell.h>
|
||||
#include <Protocol/EfiShellParameters.h>
|
||||
#include <Protocol/DevicePathToText.h>
|
||||
#include <Protocol/DriverBinding.h>
|
||||
#include <Protocol/DriverConfiguration2.h>
|
||||
#include <Protocol/DriverConfiguration.h>
|
||||
#include <Protocol/DriverDiagnostics2.h>
|
||||
#include <Protocol/DriverDiagnostics.h>
|
||||
#include <Protocol/ComponentName2.h>
|
||||
#include <Protocol/ComponentName.h>
|
||||
#include <Protocol/PlatformDriverOverride.h>
|
||||
#include <Protocol/DevicePathUtilities.h>
|
||||
#include <Protocol/DevicePathFromText.h>
|
||||
#include <Protocol/BusSpecificDriverOverride.h>
|
||||
#include <Protocol/PlatformToDriverConfiguration.h>
|
||||
#include <Protocol/DriverSupportedEfiVersion.h>
|
||||
#include <Protocol/SimpleTextInEx.h>
|
||||
#include <Protocol/SimplePointer.h>
|
||||
#include <Protocol/SerialIo.h>
|
||||
#include <Protocol/AbsolutePointer.h>
|
||||
#include <Protocol/GraphicsOutput.h>
|
||||
#include <Protocol/EdidDiscovered.h>
|
||||
#include <Protocol/EdidActive.h>
|
||||
#include <Protocol/EdidOverride.h>
|
||||
#include <Protocol/LoadFile.h>
|
||||
#include <Protocol/LoadFile2.h>
|
||||
#include <Protocol/SimpleFilesystem.h>
|
||||
#include <Protocol/TapeIo.h>
|
||||
#include <Protocol/DiskIo.h>
|
||||
#include <Protocol/BlockIo.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
#include <Protocol/PciRootBridgeIo.h>
|
||||
#include <Protocol/PciIo.h>
|
||||
#include <Protocol/ScsiPassThru.h>
|
||||
#include <Protocol/ScsiPassThruExt.h>
|
||||
#include <Protocol/ScsiIo.h>
|
||||
#include <Protocol/IScsiInitiatorName.h>
|
||||
#include <Protocol/UsbIo.h>
|
||||
#include <Protocol/UsbHostController.h>
|
||||
#include <Protocol/Usb2HostController.h>
|
||||
#include <Protocol/DebugSupport.h>
|
||||
#include <Protocol/DebugPort.h>
|
||||
#include <Protocol/Decompress.h>
|
||||
#include <Protocol/AcpiTable.h>
|
||||
#include <Protocol/Ebc.h>
|
||||
#include <Protocol/SimpleNetwork.h>
|
||||
#include <Protocol/NetworkInterfaceIdentifier.h>
|
||||
#include <Protocol/PxeBaseCode.h>
|
||||
#include <Protocol/PxeBaseCodeCallBack.h>
|
||||
#include <Protocol/Bis.h>
|
||||
#include <Protocol/ManagedNetwork.h>
|
||||
#include <Protocol/Arp.h>
|
||||
#include <Protocol/Dhcp4.h>
|
||||
#include <Protocol/Tcp4.h>
|
||||
#include <Protocol/Ip4.h>
|
||||
#include <Protocol/Ip4Config.h>
|
||||
#include <Protocol/Udp4.h>
|
||||
#include <Protocol/Mtftp4.h>
|
||||
#include <Protocol/AuthenticationInfo.h>
|
||||
#include <Protocol/Hash.h>
|
||||
#include <Protocol/HiiFont.h>
|
||||
#include <Protocol/HiiString.h>
|
||||
#include <Protocol/HiiImage.h>
|
||||
#include <Protocol/HiiDatabase.h>
|
||||
#include <Protocol/HiiConfigRouting.h>
|
||||
#include <Protocol/HiiConfigAccess.h>
|
||||
#include <Protocol/FormBrowser2.h>
|
||||
#include <Protocol/DeviceIo.h>
|
||||
#include <Protocol/UgaDraw.h>
|
||||
#include <Protocol/UgaIo.h>
|
||||
#include <Protocol/DriverConfiguration.h>
|
||||
#include <Protocol/DriverConfiguration2.h>
|
||||
#include <Protocol/DevicePathUtilities.h>
|
||||
//#include <Protocol/FirmwareVolume.h>
|
||||
//#include <Protocol/FirmwareVolume2.h>
|
||||
|
||||
#include <Library/HandleParsingLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/HiiLib.h>
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY Link;
|
||||
EFI_HANDLE TheHandle;
|
||||
UINTN TheIndex;
|
||||
}HANDLE_LIST;
|
||||
|
||||
typedef struct {
|
||||
HANDLE_LIST List;
|
||||
UINTN NextIndex;
|
||||
} HANDLE_INDEX_LIST;
|
||||
|
||||
typedef
|
||||
CHAR16 *
|
||||
(EFIAPI *DUMP_PROTOCOL_INFO)(
|
||||
IN CONST EFI_HANDLE TheHandle,
|
||||
IN CONST BOOLEAN Verbose
|
||||
);
|
||||
|
||||
|
||||
typedef struct {
|
||||
EFI_STRING_ID StringId;
|
||||
EFI_GUID *GuidId;
|
||||
DUMP_PROTOCOL_INFO DumpInfo;
|
||||
} PROTOCOL_INFO_BLOCK;
|
||||
|
158
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
Normal file
158
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
Normal file
@@ -0,0 +1,158 @@
|
||||
## @file
|
||||
# Provides interface to advanced shell functionality for parsing both handle and protocol database.
|
||||
# Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = UefiHandleParsingLib
|
||||
FILE_GUID = 3CDC7177-CC2A-4678-BA8F-1A936A093FA4
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = HandleParsingLib|UEFI_APPLICATION UEFI_DRIVER
|
||||
CONSTRUCTOR = HandleParsingLibConstructor
|
||||
DESTRUCTOR = HandleParsingLibDestructor
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources.common]
|
||||
UefiHandleParsingLib.c
|
||||
UefiHandleParsingLib.h
|
||||
UefiHandleParsingLib.uni
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
IntelFrameworkPkg/IntelFrameworkPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
UefiBootServicesTableLib
|
||||
MemoryAllocationLib
|
||||
DevicePathLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
FileHandleLib
|
||||
PrintLib
|
||||
UefiLib
|
||||
HiiLib
|
||||
|
||||
[Protocols]
|
||||
gEfiSimpleFileSystemProtocolGuid # ALWAYS_CONSUMED
|
||||
|
||||
# shell 2.0
|
||||
gEfiShellProtocolGuid # SOMETIMES_CONSUMED
|
||||
gEfiShellParametersProtocolGuid # SOMETIMES_CONSUMED
|
||||
|
||||
# 'old' shell
|
||||
gEfiShellEnvironment2Guid # SOMETIMES_CONSUMED
|
||||
gEfiShellInterfaceGuid # SOMETIMES_CONSUMED
|
||||
|
||||
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDevicePathToTextProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiBusSpecificDriverOverrideProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDevicePathUtilitiesProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDevicePathFromTextProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiPlatformDriverOverrideProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiSimpleTextInProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiPlatformToDriverConfigurationProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDriverSupportedEfiVersionProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiLoadedImageProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDevicePathProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiLoadedImageDevicePathProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiSimpleTextOutProtocolGuid
|
||||
gEfiSimplePointerProtocolGuid
|
||||
gEfiAbsolutePointerProtocolGuid
|
||||
gEfiSerialIoProtocolGuid
|
||||
gEfiEdidDiscoveredProtocolGuid
|
||||
gEfiEdidActiveProtocolGuid
|
||||
gEfiEdidOverrideProtocolGuid
|
||||
gEfiLoadFileProtocolGuid
|
||||
gEfiLoadFile2ProtocolGuid
|
||||
gEfiTapeIoProtocolGuid
|
||||
gEfiDiskIoProtocolGuid
|
||||
gEfiBlockIoProtocolGuid
|
||||
gEfiUnicodeCollationProtocolGuid
|
||||
gEfiUnicodeCollation2ProtocolGuid
|
||||
gEfiPciRootBridgeIoProtocolGuid
|
||||
gEfiPciIoProtocolGuid
|
||||
gEfiScsiPassThruProtocolGuid
|
||||
gEfiScsiIoProtocolGuid
|
||||
gEfiExtScsiPassThruProtocolGuid
|
||||
gEfiIScsiInitiatorNameProtocolGuid
|
||||
gEfiUsbIoProtocolGuid
|
||||
gEfiUsbHcProtocolGuid
|
||||
gEfiUsb2HcProtocolGuid
|
||||
gEfiDebugSupportProtocolGuid
|
||||
gEfiDebugPortProtocolGuid
|
||||
gEfiDecompressProtocolGuid
|
||||
gEfiAcpiTableProtocolGuid
|
||||
gEfiEbcProtocolGuid
|
||||
gEfiSimpleNetworkProtocolGuid
|
||||
gEfiNetworkInterfaceIdentifierProtocolGuid
|
||||
gEfiNetworkInterfaceIdentifierProtocolGuid_31
|
||||
gEfiPxeBaseCodeProtocolGuid
|
||||
gEfiPxeBaseCodeCallbackProtocolGuid
|
||||
gEfiBisProtocolGuid
|
||||
gEfiManagedNetworkServiceBindingProtocolGuid
|
||||
gEfiManagedNetworkProtocolGuid
|
||||
gEfiArpServiceBindingProtocolGuid
|
||||
gEfiArpProtocolGuid
|
||||
gEfiDhcp4ServiceBindingProtocolGuid
|
||||
gEfiDhcp4ProtocolGuid
|
||||
gEfiTcp4ServiceBindingProtocolGuid
|
||||
gEfiTcp4ProtocolGuid
|
||||
gEfiIp4ServiceBindingProtocolGuid
|
||||
gEfiIp4ProtocolGuid
|
||||
gEfiIp4ConfigProtocolGuid
|
||||
gEfiUdp4ServiceBindingProtocolGuid
|
||||
gEfiUdp4ProtocolGuid
|
||||
gEfiMtftp4ServiceBindingProtocolGuid
|
||||
gEfiMtftp4ProtocolGuid
|
||||
gEfiAuthenticationInfoProtocolGuid
|
||||
gEfiHashServiceBindingProtocolGuid
|
||||
gEfiHashProtocolGuid
|
||||
gEfiHiiFontProtocolGuid
|
||||
gEfiHiiStringProtocolGuid
|
||||
gEfiHiiImageProtocolGuid
|
||||
gEfiHiiConfigRoutingProtocolGuid
|
||||
gEfiHiiConfigAccessProtocolGuid
|
||||
gEfiFormBrowser2ProtocolGuid
|
||||
gEfiDeviceIoProtocolGuid
|
||||
gEfiUgaDrawProtocolGuid
|
||||
gEfiUgaIoProtocolGuid
|
||||
gEfiDriverConfigurationProtocolGuid
|
||||
gEfiDriverConfiguration2ProtocolGuid
|
||||
gEfiSimpleTextInputExProtocolGuid
|
||||
|
||||
[Guids]
|
||||
gEfiFileInfoGuid # ALWAYS_CONSUMED
|
||||
gEfiShellEnvironment2ExtGuid # ALWAYS_CONSUMED
|
||||
gEfiPcAnsiGuid
|
||||
gEfiVT100Guid
|
||||
gEfiVT100PlusGuid
|
||||
gEfiVTUTF8Guid
|
||||
gEfiStandardErrorDeviceGuid
|
||||
gEfiConsoleInDeviceGuid
|
||||
gEfiConsoleOutDeviceGuid
|
||||
gEfiFileSystemInfoGuid
|
||||
gEfiGlobalVariableGuid
|
||||
gEfiPartTypeSystemPartGuid
|
||||
gEfiPartTypeLegacyMbrGuid
|
||||
|
||||
[Pcd.common]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize # ALWAYS_CONSUMED
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellIncludeNtGuids # ALWAYS_CONSUMED
|
BIN
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.uni
Normal file
BIN
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.uni
Normal file
Binary file not shown.
@@ -59,7 +59,7 @@ ShellCEntryLib (
|
||||
ImageHandle,
|
||||
NULL,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
);
|
||||
if (!EFI_ERROR(Status)) {
|
||||
//
|
||||
// use shell 2.0 interface
|
||||
@@ -67,7 +67,7 @@ ShellCEntryLib (
|
||||
ReturnFromMain = ShellAppMain (
|
||||
EfiShellParametersProtocol->Argc,
|
||||
EfiShellParametersProtocol->Argv
|
||||
);
|
||||
);
|
||||
} else {
|
||||
//
|
||||
// try to get shell 1.0 interface instead.
|
||||
@@ -78,7 +78,7 @@ ShellCEntryLib (
|
||||
ImageHandle,
|
||||
NULL,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
);
|
||||
if (!EFI_ERROR(Status)) {
|
||||
//
|
||||
// use shell 1.0 interface
|
||||
@@ -86,7 +86,7 @@ ShellCEntryLib (
|
||||
ReturnFromMain = ShellAppMain (
|
||||
EfiShellInterface->Argc,
|
||||
EfiShellInterface->Argv
|
||||
);
|
||||
);
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## @file
|
||||
## @file
|
||||
# Provides interface to shell functionality for shell commands and applications.
|
||||
#
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
@@ -19,13 +19,13 @@
|
||||
FILE_GUID = 0e205c8a-8586-4dec-9f5c-4f9e394aefe8
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = ShellCEntryLib|UEFI_APPLICATION
|
||||
LIBRARY_CLASS = ShellCEntryLib|UEFI_APPLICATION UEFI_DRIVER
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
[Sources.common]
|
||||
UefiShellCEntryLib.c
|
||||
|
||||
[Packages]
|
||||
@@ -43,5 +43,5 @@
|
||||
|
||||
[Guids]
|
||||
|
||||
[Pcd]
|
||||
[Pcd.common]
|
||||
|
||||
|
1310
ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
Normal file
1310
ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
Normal file
File diff suppressed because it is too large
Load Diff
1511
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
Normal file
1511
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
Normal file
File diff suppressed because it is too large
Load Diff
79
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
Normal file
79
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/** @file
|
||||
Provides interface to shell internal functions for shell commands.
|
||||
|
||||
Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _UEFI_COMMAND_LIB_INTERNAL_HEADER_
|
||||
#define _UEFI_COMMAND_LIB_INTERNAL_HEADER_
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <ShellBase.h>
|
||||
|
||||
#include <Guid/FileInfo.h>
|
||||
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Protocol/EfiShellInterface.h>
|
||||
#include <Protocol/EfiShellEnvironment2.h>
|
||||
#include <Protocol/EfiShell.h>
|
||||
#include <Protocol/EfiShellParameters.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
#include <Protocol/BlockIo.h>
|
||||
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/SortLib.h>
|
||||
#include <Library/HandleParsingLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <library/ShellCommandLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/ShellLib.h>
|
||||
#include <Library/HiiLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
|
||||
typedef struct{
|
||||
LIST_ENTRY Link;
|
||||
CHAR16 *CommandString;
|
||||
SHELL_GET_MAN_FILENAME GetManFileName;
|
||||
SHELL_RUN_COMMAND CommandHandler;
|
||||
BOOLEAN LastError;
|
||||
EFI_HANDLE HiiHandle;
|
||||
EFI_STRING_ID ManFormatHelp;
|
||||
} SHELL_COMMAND_INTERNAL_LIST_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY Link;
|
||||
SCRIPT_FILE *Data;
|
||||
} SCRIPT_FILE_LIST;
|
||||
|
||||
/**
|
||||
Function to cleanup all memory from a SCRIPT_FILE structure.
|
||||
|
||||
@param[in] Script The pointer to the structure to cleanup.
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
DeleteScriptFileStruct (
|
||||
IN SCRIPT_FILE *Script
|
||||
);
|
||||
|
||||
typedef struct {
|
||||
EFI_FILE_PROTOCOL *FileHandle;
|
||||
CHAR16 *Path;
|
||||
} SHELL_COMMAND_FILE_HANDLE;
|
||||
|
||||
|
||||
#endif //_UEFI_COMMAND_LIB_INTERNAL_HEADER_
|
||||
|
61
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
Normal file
61
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
Normal file
@@ -0,0 +1,61 @@
|
||||
## @file
|
||||
# Provides interface to shell internal functions for shell commands.
|
||||
#
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = UefiShellCommandLib
|
||||
FILE_GUID = 5C12F31F-EBAC-466e-A400-FCA8C9EA3A05
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = ShellCommandLib|UEFI_APPLICATION UEFI_DRIVER
|
||||
CONSTRUCTOR = ShellCommandLibConstructor
|
||||
DESTRUCTOR = ShellCommandLibDestructor
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources.common]
|
||||
UefiShellCommandLib.c
|
||||
UefiShellCommandLib.h
|
||||
ConsistMapping.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
MemoryAllocationLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
PrintLib
|
||||
UefiBootServicesTableLib
|
||||
ShellLib
|
||||
HiiLib
|
||||
|
||||
[Protocols]
|
||||
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiShellProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiShellParametersProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDevicePathToTextProtocolGuid # ALWAYS_CONSUMED
|
||||
|
||||
[Guids]
|
||||
|
||||
|
||||
[Pcd.common]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## ALWAYS_CONSUMED
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength ## ALWAYS_CONSUMED
|
BIN
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.uni
Normal file
BIN
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.uni
Normal file
Binary file not shown.
273
ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c
Normal file
273
ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c
Normal file
@@ -0,0 +1,273 @@
|
||||
/** @file
|
||||
Main file for connect shell Driver1 function.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellDriver1CommandsLib.h"
|
||||
#include <Guid/GlobalVariable.h>
|
||||
#include <Guid/ConsoleInDevice.h>
|
||||
#include <Guid/ConsoleOutDevice.h>
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConnectControllers (
|
||||
IN CONST EFI_HANDLE ControllerHandle,
|
||||
IN CONST EFI_HANDLE DriverHandle,
|
||||
IN CONST BOOLEAN Recursive,
|
||||
IN CONST BOOLEAN Output
|
||||
){
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE *ControllerHandleList;
|
||||
EFI_HANDLE *DriverHandleList;
|
||||
EFI_HANDLE *HandleWalker;
|
||||
|
||||
ControllerHandleList = NULL;
|
||||
Status = EFI_NOT_FOUND;
|
||||
|
||||
//
|
||||
// If we have a single handle to connect make that a 'list'
|
||||
//
|
||||
if (DriverHandle == NULL) {
|
||||
DriverHandleList = NULL;
|
||||
} else {
|
||||
DriverHandleList = AllocatePool(2*sizeof(EFI_HANDLE));
|
||||
DriverHandleList[0] = DriverHandle;
|
||||
DriverHandleList[1] = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// do we connect all controllers (with a loop) or a single one...
|
||||
// This is where we call the gBS->ConnectController function.
|
||||
//
|
||||
if (ControllerHandle == NULL) {
|
||||
ControllerHandleList = GetHandleListByPotocol(&gEfiDevicePathProtocolGuid);
|
||||
for (HandleWalker = ControllerHandleList
|
||||
; HandleWalker != NULL && *HandleWalker != NULL
|
||||
; HandleWalker++
|
||||
){
|
||||
Status = gBS->ConnectController(*HandleWalker, DriverHandleList, NULL, Recursive);
|
||||
if (Output) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_CON_RESULT), gShellDriver1HiiHandle, *HandleWalker, Status);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Status = gBS->ConnectController(ControllerHandle, DriverHandleList, NULL, Recursive);
|
||||
ASSERT(Output == FALSE);
|
||||
}
|
||||
|
||||
//
|
||||
// Free any memory we allocated.
|
||||
//
|
||||
if (ControllerHandleList != NULL) {
|
||||
FreePool(ControllerHandleList);
|
||||
}
|
||||
if (DriverHandleList != NULL) {
|
||||
FreePool(DriverHandleList);
|
||||
}
|
||||
return (Status);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConnectFromDevPaths (
|
||||
IN CONST CHAR16 *Key
|
||||
){
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevPath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevPathWalker;
|
||||
UINTN Length;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_STATUS Status;
|
||||
|
||||
DevPath = NULL;
|
||||
Length = 0;
|
||||
|
||||
//
|
||||
// Get the DevicePath buffer from the variable...
|
||||
//
|
||||
Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath);
|
||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||
DevPath = AllocatePool(Length);
|
||||
Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath);
|
||||
}
|
||||
|
||||
//
|
||||
// walk the list of devices and connect them
|
||||
//
|
||||
for (DevPathWalker = DevPath
|
||||
; DevPathWalker < (DevPath + Length) && !EFI_ERROR(Status) && DevPath != NULL
|
||||
; DevPathWalker += GetDevicePathSize(DevPathWalker)
|
||||
){
|
||||
//
|
||||
// get the correct handle from a given device path
|
||||
//
|
||||
if (StrCmp(Key, L"ConInDev") == 0) {
|
||||
Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleInDeviceGuid, &DevPathWalker, &Handle);
|
||||
} else if (StrCmp(Key, L"ConOutDev") == 0) {
|
||||
Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleOutDeviceGuid, &DevPathWalker, &Handle);
|
||||
} else {
|
||||
Handle = NULL;
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
if (!EFI_ERROR(Status)) {
|
||||
Status = ConnectControllers(Handle, NULL, FALSE, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (DevPath != NULL) {
|
||||
FreePool(DevPath);
|
||||
}
|
||||
return (Status);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConvertAndConnectControllers (
|
||||
IN CONST CHAR16 *StringHandle1,
|
||||
IN CONST CHAR16 *StringHandle2 OPTIONAL,
|
||||
IN CONST BOOLEAN Recursive,
|
||||
IN CONST BOOLEAN Output
|
||||
){
|
||||
EFI_HANDLE Handle1;
|
||||
EFI_HANDLE Handle2;
|
||||
|
||||
//
|
||||
// Convert the command line parameters to HANDLES. They must be in HEX according to spec.
|
||||
//
|
||||
if (StringHandle1 != NULL) {
|
||||
Handle1 = (EFI_HANDLE)StrHexToUintn(StringHandle1);
|
||||
} else {
|
||||
Handle1 = NULL;
|
||||
}
|
||||
if (StringHandle2 != NULL) {
|
||||
Handle2 = (EFI_HANDLE)StrHexToUintn(StringHandle2);
|
||||
} else {
|
||||
Handle2 = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// if only one is NULL verify it's the proper one...
|
||||
//
|
||||
if ( (Handle1 == NULL && Handle2 != NULL)
|
||||
|| (Handle1 != NULL && Handle2 == NULL)
|
||||
){
|
||||
//
|
||||
// Figure out which one should be NULL and move the handle to the right place.
|
||||
// If Handle1 is NULL then test Handle2 and vise versa.
|
||||
// The one that DOES has driver binding must be Handle2
|
||||
//
|
||||
if (Handle1 == NULL) {
|
||||
if (EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
|
||||
// swap
|
||||
Handle1 = Handle2;
|
||||
Handle2 = NULL;
|
||||
} else {
|
||||
// We're all good...
|
||||
}
|
||||
} else {
|
||||
if (EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
|
||||
// We're all good...
|
||||
} else {
|
||||
// swap
|
||||
Handle2 = Handle1;
|
||||
Handle1 = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (ConnectControllers(Handle1, Handle2, Recursive, Output));
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-c", TypeFlag},
|
||||
{L"-r", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunConnect (
|
||||
VOID *RESERVED
|
||||
) {
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if EFI_ERROR(Status) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// if more than 2 'value' parameters (plus the name one) or either -r or -c with any value parameters we have too many parameters
|
||||
//
|
||||
if ((ShellCommandLineGetCount() > 3)
|
||||
||((ShellCommandLineGetFlag(Package, L"-r") != FALSE || ShellCommandLineGetFlag(Package, L"-c") != FALSE) && ShellCommandLineGetCount()!=0)
|
||||
){
|
||||
//
|
||||
// error for too many parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-c") != FALSE) {
|
||||
//
|
||||
// do the conin and conout from EFI variables
|
||||
// if the first fails dont 'loose' the error
|
||||
//
|
||||
Status = ConnectFromDevPaths(L"ConInDev");
|
||||
if (EFI_ERROR(Status)) {
|
||||
ConnectFromDevPaths(L"ConOutDev");
|
||||
} else {
|
||||
Status = ConnectFromDevPaths(L"ConOutDev");
|
||||
}
|
||||
ShellStatus = Status & (~MAX_BIT);
|
||||
} else {
|
||||
//
|
||||
// 0, 1, or 2 specific handles and possibly recursive
|
||||
//
|
||||
if (ShellCommandLineGetRawValue(Package, 1) != NULL && CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 1))) == NULL){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL && CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 2))) == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 2));
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
Status = ConvertAndConnectControllers(ShellCommandLineGetRawValue(Package, 1), ShellCommandLineGetRawValue(Package, 2), ShellCommandLineGetFlag(Package, L"-r"), (BOOLEAN)(ShellCommandLineGetCount()!=0));
|
||||
ShellStatus = Status & (~MAX_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
164
ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c
Normal file
164
ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c
Normal file
@@ -0,0 +1,164 @@
|
||||
/** @file
|
||||
Main file for devices shell Driver1 function.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellDriver1CommandsLib.h"
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GetDeviceHandleInfo (
|
||||
IN EFI_HANDLE TheHandle,
|
||||
IN CHAR16 *Type,
|
||||
IN BOOLEAN *Cfg,
|
||||
IN BOOLEAN *Diag,
|
||||
IN UINT8 *Parents,
|
||||
IN UINT8 *Devices,
|
||||
IN UINT8 *Children,
|
||||
OUT CHAR16 **Name,
|
||||
IN CONST CHAR8 *Language
|
||||
){
|
||||
*Name = NULL;
|
||||
|
||||
gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-l", TypeValue},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunDevices (
|
||||
VOID *RESERVED
|
||||
) {
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CHAR8 *Language;
|
||||
EFI_HANDLE *HandleList;
|
||||
EFI_HANDLE *HandleListWalker;
|
||||
CHAR16 Type;
|
||||
BOOLEAN Cfg;
|
||||
BOOLEAN Diag;
|
||||
UINT8 Parents;
|
||||
UINT8 Devices;
|
||||
UINT8 Children;
|
||||
CHAR16 *Name;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
Language = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if EFI_ERROR(Status) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// if more than 0 'value' parameters we have too many parameters
|
||||
//
|
||||
if (ShellCommandLineGetRawValue(Package, 1) != NULL){
|
||||
//
|
||||
// error for too many parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// get the language if necessary
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-l") != FALSE) {
|
||||
Language = AllocateZeroPool(StrSize(ShellCommandLineGetValue(Package, L"-l")));
|
||||
AsciiSPrint(Language, StrSize(ShellCommandLineGetValue(Package, L"-l")), "%S", ShellCommandLineGetValue(Package, L"-l"));
|
||||
}
|
||||
|
||||
//
|
||||
// Print Header
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);
|
||||
|
||||
//
|
||||
// loop through each handle
|
||||
//
|
||||
HandleList = GetHandleListByPotocol(NULL);
|
||||
ASSERT(HandleList != NULL);
|
||||
for (HandleListWalker = HandleList
|
||||
; HandleListWalker != NULL && *HandleListWalker != NULL && !EFI_ERROR(Status)
|
||||
; HandleListWalker++
|
||||
){
|
||||
//
|
||||
// get all the info on each handle
|
||||
//
|
||||
Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);
|
||||
if (Parents != 0 || Devices != 0 || Children != 0) {
|
||||
ShellPrintHiiEx(
|
||||
-1,
|
||||
-1,
|
||||
Language,
|
||||
STRING_TOKEN (STR_DEVICES_ITEM_LINE),
|
||||
gShellDriver1HiiHandle,
|
||||
*HandleListWalker,
|
||||
Type,
|
||||
Cfg!=FALSE?L'X':L'-',
|
||||
Diag!=FALSE?L'X':L'-',
|
||||
Parents,
|
||||
Devices,
|
||||
Children,
|
||||
Name);
|
||||
}
|
||||
if (Name != NULL) {
|
||||
FreePool(Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (HandleList != NULL) {
|
||||
FreePool(HandleList);
|
||||
}
|
||||
}
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
243
ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c
Normal file
243
ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c
Normal file
@@ -0,0 +1,243 @@
|
||||
/** @file
|
||||
Main file for OpenInfo shell Driver1 function.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellDriver1CommandsLib.h"
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
TraverseHandleDatabase (
|
||||
IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
|
||||
IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
|
||||
IN UINTN *HandleCount,
|
||||
OUT EFI_HANDLE **HandleBuffer,
|
||||
OUT UINTN **HandleType
|
||||
){
|
||||
EFI_STATUS Status;
|
||||
UINTN HandleIndex;
|
||||
EFI_GUID **ProtocolGuidArray;
|
||||
UINTN ArrayCount;
|
||||
UINTN ProtocolIndex;
|
||||
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
|
||||
UINTN OpenInfoCount;
|
||||
UINTN OpenInfoIndex;
|
||||
UINTN ChildIndex;
|
||||
|
||||
ASSERT(HandleCount != NULL);
|
||||
ASSERT(HandleBuffer != NULL);
|
||||
ASSERT(HandleType != NULL);
|
||||
ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
|
||||
|
||||
*HandleCount = 0;
|
||||
*HandleBuffer = NULL;
|
||||
*HandleType = NULL;
|
||||
|
||||
//
|
||||
// Retrieve the list of all handles from the handle database
|
||||
//
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
AllHandles,
|
||||
NULL,
|
||||
NULL,
|
||||
HandleCount,
|
||||
HandleBuffer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return (Status);
|
||||
}
|
||||
|
||||
*HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));
|
||||
ASSERT(*HandleType != NULL);
|
||||
|
||||
for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
|
||||
//
|
||||
// Retrieve the list of all the protocols on each handle
|
||||
//
|
||||
Status = gBS->ProtocolsPerHandle (
|
||||
(*HandleBuffer)[HandleIndex],
|
||||
&ProtocolGuidArray,
|
||||
&ArrayCount
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
|
||||
for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
|
||||
|
||||
//
|
||||
// Set the bit describing what this handle has
|
||||
//
|
||||
if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_IMAGE_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_BINDING_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_CONFIGURATION_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_CONFIGURATION_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_DIAGNOSTICS_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_DIAGNOSTICS_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_COMPONENT_NAME_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_COMPONENT_NAME_HANDLE;
|
||||
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) != FALSE) {
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DEVICE_HANDLE;
|
||||
} else {
|
||||
DEBUG_CODE_BEGIN();
|
||||
ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);
|
||||
DEBUG_CODE_END();
|
||||
}
|
||||
//
|
||||
// Retrieve the list of agents that have opened each protocol
|
||||
//
|
||||
Status = gBS->OpenProtocolInformation (
|
||||
(*HandleBuffer)[HandleIndex],
|
||||
ProtocolGuidArray[ProtocolIndex],
|
||||
&OpenInfo,
|
||||
&OpenInfoCount
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
|
||||
if (DriverBindingHandle != NULL && OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
|
||||
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
|
||||
//
|
||||
// Mark the device handle as being managed by the driver specified by DriverBindingHandle
|
||||
//
|
||||
(*HandleType)[HandleIndex] |= (HANDLE_RELATIONSHIP_DEVICE_HANDLE | HANDLE_RELATIONSHIP_CONTROLLER_HANDLE);
|
||||
}
|
||||
if (ControllerHandle != NULL && (*HandleBuffer)[HandleIndex] == ControllerHandle) {
|
||||
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
|
||||
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
|
||||
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].ControllerHandle) {
|
||||
(*HandleType)[ChildIndex] |= (HANDLE_RELATIONSHIP_DEVICE_HANDLE | HANDLE_RELATIONSHIP_CHILD_HANDLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (DriverBindingHandle == NULL && OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
|
||||
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
|
||||
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
|
||||
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
|
||||
//
|
||||
// mark the handle who opened this as a device driver
|
||||
//
|
||||
(*HandleType)[ChildIndex] |= HANDLE_RELATIONSHIP_DEVICE_DRIVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
|
||||
//
|
||||
// this handle has people opening by child so it must be a parent
|
||||
//
|
||||
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_PARENT_HANDLE;
|
||||
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
|
||||
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
|
||||
(*HandleType)[ChildIndex] |= HANDLE_RELATIONSHIP_BUS_DRIVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FreePool (OpenInfo);
|
||||
}
|
||||
}
|
||||
|
||||
FreePool (ProtocolGuidArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (*HandleType != NULL) {
|
||||
FreePool (*HandleType);
|
||||
}
|
||||
if (*HandleBuffer != NULL) {
|
||||
FreePool (*HandleBuffer);
|
||||
}
|
||||
|
||||
*HandleCount = 0;
|
||||
*HandleBuffer = NULL;
|
||||
*HandleType = NULL;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunOpenInfo (
|
||||
VOID *RESERVED
|
||||
) {
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
EFI_HANDLE theHandle;
|
||||
EFI_HANDLE *HandleList;
|
||||
UINTN Count;
|
||||
UINTN *Type;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if EFI_ERROR(Status) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
if (ShellCommandLineGetCount() > 2){
|
||||
//
|
||||
// error for too many parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetCount() == 0) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
if (ShellCommandLineGetRawValue(Package, 1) != NULL && CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 1))) == NULL){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
theHandle = CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 1)));
|
||||
ASSERT(theHandle != NULL);
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, StrHexToUintn(ShellCommandLineGetRawValue(Package, 1)), theHandle);
|
||||
Status = TraverseHandleDatabase (NULL, theHandle, &Count, &HandleList, &Type);
|
||||
if (EFI_ERROR(Status) == FALSE && Count > 0) {
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
@@ -0,0 +1,137 @@
|
||||
/** @file
|
||||
Main file for NULL named library for level 1 shell command functions.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellDriver1CommandsLib.h"
|
||||
|
||||
STATIC CONST CHAR16 mFileName[] = L"Driver1Commands";
|
||||
EFI_HANDLE gShellDriver1HiiHandle = NULL;
|
||||
CONST EFI_GUID gShellDriver1HiiGuid = \
|
||||
{ \
|
||||
0xaf0b742, 0x63ec, 0x45bd, {0x8d, 0xb6, 0x71, 0xad, 0x7f, 0x2f, 0xe8, 0xe8} \
|
||||
};
|
||||
|
||||
|
||||
CONST CHAR16*
|
||||
EFIAPI
|
||||
ShellCommandGetManFileNameDriver1 (
|
||||
VOID
|
||||
){
|
||||
return (mFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructor for the Shell Driver1 Commands library.
|
||||
|
||||
@param ImageHandle the image handle of the process
|
||||
@param SystemTable the EFI System Table pointer
|
||||
|
||||
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
|
||||
@retval EFI_UNSUPPORTED the shell level required was not found.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiShellDriver1CommandsLibConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
) {
|
||||
//
|
||||
// check or bit of the profiles mask
|
||||
//
|
||||
if (PcdGet8(PcdShellProfileMask) && BIT0 == 0) {
|
||||
return (EFI_UNSUPPORTED);
|
||||
}
|
||||
|
||||
//
|
||||
// install our shell command handlers that are always installed
|
||||
//
|
||||
ShellCommandRegisterCommandName(L"connect", ShellCommandRunConnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"devices", ShellCommandRunDevices , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"openinfo", ShellCommandRunOpenInfo , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
/*
|
||||
ShellCommandRegisterCommandName(L"devtree", ShellCommandRunDevTree , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"dh", ShellCommandRunDH , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"disconnect", ShellCommandRunDisconnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"drivers", ShellCommandRunDrivers , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"drvcfg", ShellCommandRunDrvCfg , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"drvdiag", ShellCommandRunDrvDiag , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"reconnect", ShellCommandRunReconnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
ShellCommandRegisterCommandName(L"unload", ShellCommandRunUnload , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
|
||||
*/
|
||||
|
||||
//
|
||||
// install the HII stuff.
|
||||
//
|
||||
gShellDriver1HiiHandle = HiiAddPackages (&gShellDriver1HiiGuid, gImageHandle, UefiShellDriver1CommandsLibStrings, NULL);
|
||||
if (gShellDriver1HiiHandle == NULL) {
|
||||
return (EFI_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Destructory for the library. free any resources.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UefiShellDriver1CommandsLibDestructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
if (gShellDriver1HiiHandle != NULL) {
|
||||
HiiRemovePackages(gShellDriver1HiiHandle);
|
||||
}
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
EFI_HANDLE*
|
||||
EFIAPI
|
||||
GetHandleListByPotocol (
|
||||
IN CONST EFI_GUID *ProtocolGuid
|
||||
){
|
||||
EFI_HANDLE *HandleList;
|
||||
UINTN Size;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Size = 0;
|
||||
HandleList = NULL;
|
||||
|
||||
//
|
||||
// We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
|
||||
//
|
||||
if (ProtocolGuid == NULL) {
|
||||
Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
|
||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||
HandleList = AllocatePool(Size + sizeof(EFI_HANDLE));
|
||||
Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
|
||||
HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
|
||||
}
|
||||
} else {
|
||||
Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
|
||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||
HandleList = AllocatePool(Size + sizeof(EFI_HANDLE));
|
||||
Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
|
||||
HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
|
||||
}
|
||||
}
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (HandleList != NULL) {
|
||||
FreePool(HandleList);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
return (HandleList);
|
||||
}
|
||||
|
@@ -0,0 +1,71 @@
|
||||
/** @file
|
||||
Main file for NULL named library for Profile1 shell command functions.
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <ShellBase.h>
|
||||
|
||||
#include <Protocol/EfiShell.h>
|
||||
#include <Protocol/EfiShellParameters.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
#include <Protocol/DevicePathToText.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/ShellCommandLib.h>
|
||||
#include <Library/ShellLib.h>
|
||||
#include <Library/SortLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/HiiLib.h>
|
||||
#include <Library/FileHandleLib.h>
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
|
||||
|
||||
extern EFI_HANDLE gShellDriver1HiiHandle;
|
||||
extern CONST EFI_GUID gShellDriver1HiiGuid;
|
||||
|
||||
EFI_HANDLE*
|
||||
EFIAPI
|
||||
GetHandleListByPotocol (
|
||||
IN CONST EFI_GUID *ProtocolGuid
|
||||
);
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunConnect (
|
||||
VOID *RESERVED
|
||||
);
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunDevices (
|
||||
VOID *RESERVED
|
||||
);
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunOpenInfo (
|
||||
VOID *RESERVED
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,57 @@
|
||||
#/** @file
|
||||
# Provides shell driver1 profile functions
|
||||
#
|
||||
# Copyright (c) 2010, Intel Corporation.All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
#**/
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = UefiShellDriver1CommandsLib
|
||||
FILE_GUID = 313D3674-3ED4-48fd-BF97-7DB35D4190D1
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
|
||||
CONSTRUCTOR = UefiShellDriver1CommandsLibConstructor
|
||||
DESTRUCTOR = UefiShellDriver1CommandsLibDestructor
|
||||
|
||||
[Sources]
|
||||
Connect.c
|
||||
Devices.c
|
||||
OpenInfo.c
|
||||
UefiShellDriver1CommandsLib.c
|
||||
UefiShellDriver1CommandsLib.h
|
||||
UefiShellDriver1CommandsLib.uni
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
MemoryAllocationLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
ShellCommandLib
|
||||
ShellLib
|
||||
UefiLib
|
||||
UefiRuntimeServicesTableLib
|
||||
UefiBootServicesTableLib
|
||||
SortLib
|
||||
PrintLib
|
||||
|
||||
[Pcd]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask # ALWAYS_CONSUMED
|
||||
|
||||
[Guids]
|
||||
gEfiGlobalVariableGuid
|
||||
gEfiConsoleInDeviceGuid
|
||||
gEfiConsoleOutDeviceGuid
|
Binary file not shown.
81
ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
Normal file
81
ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/** @file
|
||||
Main file for exit shell level 1 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel1CommandsLib.h"
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"/b", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'exit' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunExit (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
|
||||
//
|
||||
// If we are in a batch file and /b then pass TRUE otherwise false...
|
||||
//
|
||||
ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")));
|
||||
|
||||
//
|
||||
// return the specified error code
|
||||
//
|
||||
if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
|
||||
ShellStatus = (SHELL_STATUS)(ShellStrToUintn(ShellCommandLineGetRawValue(Package, 1)));
|
||||
}
|
||||
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
581
ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
Normal file
581
ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
Normal file
@@ -0,0 +1,581 @@
|
||||
/** @file
|
||||
Main file for endfor and for shell level 1 functions.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel1CommandsLib.h"
|
||||
#include <Library/PrintLib.h>
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
ShellIsValidForNumber (
|
||||
IN CONST CHAR16 *Number
|
||||
)
|
||||
{
|
||||
if (Number == NULL || *Number == CHAR_NULL) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
if (*Number == L'-') {
|
||||
Number++;
|
||||
}
|
||||
|
||||
if (StrLen(Number) == 0) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
if (StrLen(Number) >= 7) {
|
||||
if (StrStr(Number, L" ") != NULL && (StrStr(Number, L" ") - Number) >= 7) {
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ShellIsDecimalDigitCharacter(*Number)) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'endfor' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunEndFor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
BOOLEAN Found;
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"EndFor");
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
if (gEfiShellParametersProtocol->Argc > 1) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
Found = MoveToTag(GetPreviousNode, L"for", L"endfor", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE);
|
||||
|
||||
if (!Found) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"For", L"EndFor", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
return (SHELL_NOT_FOUND);
|
||||
}
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
INTN Current;
|
||||
INTN End;
|
||||
INTN Step;
|
||||
CHAR16 *ReplacementName;
|
||||
CHAR16 *CurrentValue;
|
||||
BOOLEAN RemoveSubstAlias;
|
||||
CHAR16 Set[1];
|
||||
} SHELL_FOR_INFO;
|
||||
#define SIZE_OF_SHELL_FOR_INFO OFFSET_OF (SHELL_FOR_INFO, Set)
|
||||
#define SHELL_FOR_INFO_SIGNATURE SIGNATURE_32 ('S', 'F', 'I', 's')
|
||||
|
||||
/**
|
||||
Update the value of a given alias on the list. If the alias is not there then add it.
|
||||
|
||||
@param[in] Alias The alias to test for.
|
||||
@param[in] CommandString The updated command string.
|
||||
@param[in,out] List The list to search.
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
InternalUpdateAliasOnList(
|
||||
IN CONST CHAR16 *Alias,
|
||||
IN CONST CHAR16 *CommandString,
|
||||
IN OUT LIST_ENTRY *List
|
||||
)
|
||||
{
|
||||
ALIAS_LIST *Node;
|
||||
BOOLEAN Found;
|
||||
|
||||
//
|
||||
// assert for NULL parameter
|
||||
//
|
||||
ASSERT(Alias != NULL);
|
||||
|
||||
//
|
||||
// check for the Alias
|
||||
//
|
||||
for ( Node = (ALIAS_LIST *)GetFirstNode(List), Found = FALSE
|
||||
; !IsNull(List, &Node->Link)
|
||||
; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
|
||||
){
|
||||
ASSERT(Node->CommandString != NULL);
|
||||
ASSERT(Node->Alias != NULL);
|
||||
if (StrCmp(Node->Alias, Alias)==0) {
|
||||
FreePool(Node->CommandString);
|
||||
Node->CommandString = NULL;
|
||||
Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
|
||||
Found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!Found) {
|
||||
Node = AllocateZeroPool(sizeof(ALIAS_LIST));
|
||||
ASSERT(Node->Alias == NULL);
|
||||
Node->Alias = StrnCatGrow(&Node->Alias, NULL, Alias, 0);
|
||||
ASSERT(Node->CommandString == NULL);
|
||||
Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
|
||||
InsertTailList(List, &Node->Link);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Find out if an alias is on the given list.
|
||||
|
||||
@param[in] Alias The alias to test for.
|
||||
@param[in] List The list to search.
|
||||
|
||||
@retval TRUE The alias is on the list.
|
||||
@retval FALSE The alias is not on the list.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
InternalIsAliasOnList(
|
||||
IN CONST CHAR16 *Alias,
|
||||
IN CONST LIST_ENTRY *List
|
||||
)
|
||||
{
|
||||
ALIAS_LIST *Node;
|
||||
|
||||
//
|
||||
// assert for NULL parameter
|
||||
//
|
||||
ASSERT(Alias != NULL);
|
||||
|
||||
//
|
||||
// check for the Alias
|
||||
//
|
||||
for ( Node = (ALIAS_LIST *)GetFirstNode(List)
|
||||
; !IsNull(List, &Node->Link)
|
||||
; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
|
||||
){
|
||||
ASSERT(Node->CommandString != NULL);
|
||||
ASSERT(Node->Alias != NULL);
|
||||
if (StrCmp(Node->Alias, Alias)==0) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Remove an alias from the given list.
|
||||
|
||||
@param[in] Alias The alias to remove.
|
||||
@param[in,out] List The list to search.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
InternalRemoveAliasFromList(
|
||||
IN CONST CHAR16 *Alias,
|
||||
IN OUT LIST_ENTRY *List
|
||||
)
|
||||
{
|
||||
ALIAS_LIST *Node;
|
||||
|
||||
//
|
||||
// assert for NULL parameter
|
||||
//
|
||||
ASSERT(Alias != NULL);
|
||||
|
||||
//
|
||||
// check for the Alias
|
||||
//
|
||||
for ( Node = (ALIAS_LIST *)GetFirstNode(List)
|
||||
; !IsNull(List, &Node->Link)
|
||||
; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
|
||||
){
|
||||
ASSERT(Node->CommandString != NULL);
|
||||
ASSERT(Node->Alias != NULL);
|
||||
if (StrCmp(Node->Alias, Alias)==0) {
|
||||
RemoveEntryList(&Node->Link);
|
||||
FreePool(Node->Alias);
|
||||
FreePool(Node->CommandString);
|
||||
FreePool(Node);
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'for' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunFor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
SHELL_STATUS ShellStatus;
|
||||
SCRIPT_FILE *CurrentScriptFile;
|
||||
CHAR16 *ArgSet;
|
||||
CHAR16 *ArgSetWalker;
|
||||
UINTN ArgSize;
|
||||
UINTN LoopVar;
|
||||
SHELL_FOR_INFO *Info;
|
||||
CHAR16 *TempString;
|
||||
CHAR16 *TempSpot;
|
||||
BOOLEAN FirstPass;
|
||||
EFI_SHELL_FILE_INFO *Node;
|
||||
EFI_SHELL_FILE_INFO *FileList;
|
||||
UINTN NewSize;
|
||||
|
||||
ArgSet = NULL;
|
||||
ArgSize = 0;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ArgSetWalker = NULL;
|
||||
TempString = NULL;
|
||||
FirstPass = FALSE;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"For");
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
if (gEfiShellParametersProtocol->Argc < 4) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
CurrentScriptFile = ShellCommandGetCurrentScriptFile();
|
||||
ASSERT(CurrentScriptFile != NULL);
|
||||
|
||||
if (CurrentScriptFile->CurrentCommand->Data == NULL) {
|
||||
FirstPass = TRUE;
|
||||
|
||||
//
|
||||
// Make sure that an End exists.
|
||||
//
|
||||
if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
//
|
||||
// Process the line.
|
||||
//
|
||||
if (gEfiShellParametersProtocol->Argv[1][0] != L'%' || gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL
|
||||
||!((gEfiShellParametersProtocol->Argv[1][1] >= L'a' && gEfiShellParametersProtocol->Argv[1][1] <= L'z')
|
||||
||(gEfiShellParametersProtocol->Argv[1][1] >= L'A' && gEfiShellParametersProtocol->Argv[1][1] <= L'Z'))
|
||||
) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[2]);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
L"in",
|
||||
gEfiShellParametersProtocol->Argv[2]) == 0) {
|
||||
for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
|
||||
ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
|
||||
if (ArgSet == NULL) {
|
||||
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
|
||||
} else {
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
|
||||
}
|
||||
if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL
|
||||
||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL
|
||||
||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL
|
||||
||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL) {
|
||||
FileList = NULL;
|
||||
Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);
|
||||
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
|
||||
} else {
|
||||
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
|
||||
; !IsNull(&FileList->Link, &Node->Link)
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
|
||||
){
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Node->FullName, 0);
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
|
||||
}
|
||||
ShellCloseFileMetaArg(&FileList);
|
||||
}
|
||||
} else {
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
|
||||
}
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
|
||||
}
|
||||
//
|
||||
// set up for an 'in' for loop
|
||||
//
|
||||
NewSize = StrSize(ArgSet);
|
||||
NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);
|
||||
Info = AllocateZeroPool(NewSize);
|
||||
ASSERT(Info != NULL);
|
||||
Info->Signature = SHELL_FOR_INFO_SIGNATURE;
|
||||
CopyMem(Info->Set, ArgSet, StrSize(ArgSet));
|
||||
NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);
|
||||
CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);
|
||||
Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);
|
||||
Info->CurrentValue = (CHAR16*)Info->Set;
|
||||
Info->Step = 0;
|
||||
Info->Current = 0;
|
||||
Info->End = 0;
|
||||
|
||||
if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
|
||||
Info->RemoveSubstAlias = FALSE;
|
||||
} else {
|
||||
Info->RemoveSubstAlias = TRUE;
|
||||
}
|
||||
CurrentScriptFile->CurrentCommand->Data = Info;
|
||||
} else if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
L"run",
|
||||
gEfiShellParametersProtocol->Argv[2]) == 0) {
|
||||
for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
|
||||
ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
|
||||
if (ArgSet == NULL) {
|
||||
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
|
||||
} else {
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
|
||||
}
|
||||
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
|
||||
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
|
||||
}
|
||||
//
|
||||
// set up for a 'run' for loop
|
||||
//
|
||||
Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
|
||||
ASSERT(Info != NULL);
|
||||
CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
|
||||
Info->ReplacementName = Info->Set;
|
||||
Info->CurrentValue = NULL;
|
||||
ArgSetWalker = ArgSet;
|
||||
if (ArgSetWalker[0] != L'(') {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ArgSetWalker++;
|
||||
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
|
||||
ArgSetWalker++;
|
||||
}
|
||||
if (!ShellIsValidForNumber(ArgSetWalker)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
if (ArgSetWalker[0] == L'-') {
|
||||
Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
|
||||
} else {
|
||||
Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);
|
||||
}
|
||||
ArgSetWalker = StrStr(ArgSetWalker, L" ");
|
||||
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
|
||||
ArgSetWalker++;
|
||||
}
|
||||
if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
if (ArgSetWalker[0] == L'-') {
|
||||
Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
|
||||
} else {
|
||||
Info->End = (INTN)ShellStrToUintn(ArgSetWalker);
|
||||
}
|
||||
if (Info->Current < Info->End) {
|
||||
Info->Step = 1;
|
||||
} else {
|
||||
Info->Step = -1;
|
||||
}
|
||||
|
||||
ArgSetWalker = StrStr(ArgSetWalker, L" ");
|
||||
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
|
||||
ArgSetWalker++;
|
||||
}
|
||||
if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {
|
||||
TempSpot = StrStr(ArgSetWalker, L")");
|
||||
if (TempSpot == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
*TempSpot = CHAR_NULL;
|
||||
if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
if (*ArgSetWalker == L')') {
|
||||
ASSERT(Info->Step == 1 || Info->Step == -1);
|
||||
} else {
|
||||
if (ArgSetWalker[0] == L'-') {
|
||||
Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
|
||||
} else {
|
||||
Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
|
||||
Info->RemoveSubstAlias = FALSE;
|
||||
} else {
|
||||
Info->RemoveSubstAlias = TRUE;
|
||||
}
|
||||
}
|
||||
CurrentScriptFile->CurrentCommand->Data = Info;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// These need to be NULL since they are used to determine if this is the first pass later on...
|
||||
//
|
||||
ASSERT(ArgSetWalker == NULL);
|
||||
ASSERT(ArgSet == NULL);
|
||||
}
|
||||
|
||||
Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;
|
||||
if (CurrentScriptFile->CurrentCommand->Reset) {
|
||||
Info->CurrentValue = (CHAR16*)Info->Set;
|
||||
FirstPass = TRUE;
|
||||
CurrentScriptFile->CurrentCommand->Reset = FALSE;
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
ASSERT(Info != NULL);
|
||||
if (Info->Step != 0) {
|
||||
//
|
||||
// only advance if not the first pass
|
||||
//
|
||||
if (!FirstPass) {
|
||||
//
|
||||
// sequence version of for loop...
|
||||
//
|
||||
Info->Current += Info->Step;
|
||||
}
|
||||
|
||||
TempString = AllocateZeroPool(50*sizeof(CHAR16));
|
||||
UnicodeSPrint(TempString, 50*sizeof(CHAR16), L"%d", Info->Current);
|
||||
InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
|
||||
FreePool(TempString);
|
||||
|
||||
if ((Info->Step > 0 && Info->Current > Info->End) || (Info->Step < 0 && Info->Current < Info->End)) {
|
||||
CurrentScriptFile->CurrentCommand->Data = NULL;
|
||||
//
|
||||
// find the matching endfor (we're done with the loop)
|
||||
//
|
||||
if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
}
|
||||
if (Info->RemoveSubstAlias) {
|
||||
//
|
||||
// remove item from list
|
||||
//
|
||||
InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
|
||||
}
|
||||
FreePool(Info);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// Must be in 'in' version of for loop...
|
||||
//
|
||||
ASSERT(Info->Set != NULL);
|
||||
if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {
|
||||
if (Info->CurrentValue[0] == L'\"') {
|
||||
Info->CurrentValue++;
|
||||
}
|
||||
while (Info->CurrentValue[0] == L' ') {
|
||||
Info->CurrentValue++;
|
||||
}
|
||||
if (Info->CurrentValue[0] == L'\"') {
|
||||
Info->CurrentValue++;
|
||||
}
|
||||
//
|
||||
// do the next one of the set
|
||||
//
|
||||
ASSERT(TempString == NULL);
|
||||
TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);
|
||||
TempSpot = StrStr(TempString, L"\" \"");
|
||||
if (TempSpot != NULL) {
|
||||
*TempSpot = CHAR_NULL;
|
||||
}
|
||||
while (TempString[StrLen(TempString)-1] == L'\"') {
|
||||
TempString[StrLen(TempString)-1] = CHAR_NULL;
|
||||
}
|
||||
InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
|
||||
Info->CurrentValue += StrLen(TempString);
|
||||
|
||||
if (Info->CurrentValue[0] == L'\"') {
|
||||
Info->CurrentValue++;
|
||||
}
|
||||
while (Info->CurrentValue[0] == L' ') {
|
||||
Info->CurrentValue++;
|
||||
}
|
||||
if (Info->CurrentValue[0] == L'\"') {
|
||||
Info->CurrentValue++;
|
||||
}
|
||||
FreePool(TempString);
|
||||
|
||||
} else {
|
||||
CurrentScriptFile->CurrentCommand->Data = NULL;
|
||||
//
|
||||
// find the matching endfor (we're done with the loop)
|
||||
//
|
||||
if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
}
|
||||
if (Info->RemoveSubstAlias) {
|
||||
//
|
||||
// remove item from list
|
||||
//
|
||||
InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
|
||||
}
|
||||
FreePool(Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ArgSet != NULL) {
|
||||
FreePool(ArgSet);
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
92
ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
Normal file
92
ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/** @file
|
||||
Main file for goto shell level 1 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel1CommandsLib.h"
|
||||
|
||||
/**
|
||||
Function for 'goto' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunGoto (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CHAR16 *CompareString;
|
||||
UINTN Size;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
CompareString = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
Size = 0;
|
||||
ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));
|
||||
CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);
|
||||
CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);
|
||||
//
|
||||
// Check forwards and then backwards for a label...
|
||||
//
|
||||
if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, CompareString, L"Goto", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
FreePool(CompareString);
|
||||
}
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
962
ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
Normal file
962
ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
Normal file
@@ -0,0 +1,962 @@
|
||||
/** @file
|
||||
Main file for If and else shell level 1 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel1CommandsLib.h"
|
||||
#include <Library/PrintLib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
END_TAG_OR,
|
||||
END_TAG_AND,
|
||||
END_TAG_THEN,
|
||||
END_TAG_MAX
|
||||
} END_TAG_TYPE;
|
||||
|
||||
typedef enum {
|
||||
OPERATOR_GT,
|
||||
OPERATOR_LT,
|
||||
OPERATOR_EQ,
|
||||
OPERATOR_NE,
|
||||
OPERATOR_GE,
|
||||
OPERATOR_LE,
|
||||
OPERATOR_UGT,
|
||||
OPERATOR_ULT,
|
||||
OPERATOR_UGE,
|
||||
OPERATOR_ULE,
|
||||
OPERATOR_MAX
|
||||
} BIN_OPERATOR_TYPE;
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsNextFragment (
|
||||
IN CONST CHAR16 **Statement,
|
||||
IN CONST CHAR16 *Fragment
|
||||
)
|
||||
{
|
||||
CHAR16 *Tester;
|
||||
|
||||
Tester = NULL;
|
||||
|
||||
Tester = StrnCatGrow(&Tester, NULL, *Statement, StrLen(Fragment));
|
||||
ASSERT(Tester != NULL);
|
||||
Tester[StrLen(Fragment)] = CHAR_NULL;
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
(CHAR16*)Fragment,
|
||||
Tester) == 0) {
|
||||
//
|
||||
// increment the string pointer to the end of what we found and then chop off spaces...
|
||||
//
|
||||
*Statement+=StrLen(Fragment);
|
||||
while (*Statement[0] == L' ') {
|
||||
*Statement++;
|
||||
}
|
||||
FreePool(Tester);
|
||||
return (TRUE);
|
||||
}
|
||||
FreePool(Tester);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsValidProfile (
|
||||
IN CONST CHAR16 *String
|
||||
)
|
||||
{
|
||||
CONST CHAR16 *ProfilesString;
|
||||
CONST CHAR16 *TempLocation;
|
||||
|
||||
ProfilesString = ShellGetEnvironmentVariable(L"profiles");
|
||||
TempLocation = StrStr(ProfilesString, String);
|
||||
if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) {
|
||||
return (TRUE);
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
TestOperation (
|
||||
IN CONST CHAR16 *Compare1,
|
||||
IN CONST CHAR16 *Compare2,
|
||||
IN CONST BIN_OPERATOR_TYPE BinOp,
|
||||
IN CONST BOOLEAN CaseInsensitive,
|
||||
IN CONST BOOLEAN ForceStringCompare
|
||||
)
|
||||
{
|
||||
INTN Cmp1;
|
||||
INTN Cmp2;
|
||||
|
||||
//
|
||||
// "Compare1 BinOp Compare2"
|
||||
//
|
||||
switch (BinOp) {
|
||||
case OPERATOR_UGT:
|
||||
case OPERATOR_GT:
|
||||
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
|
||||
//
|
||||
// string compare
|
||||
//
|
||||
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) > 0) || (StringCompare(&Compare1, &Compare2) > 0)) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// numeric compare
|
||||
//
|
||||
if (Compare1[0] == L'-') {
|
||||
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
|
||||
} else {
|
||||
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
|
||||
}
|
||||
if (Compare2[0] == L'-') {
|
||||
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
|
||||
} else {
|
||||
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
|
||||
}
|
||||
if (BinOp == OPERATOR_GT) {
|
||||
if (Cmp1 > Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
if ((UINTN)Cmp1 > (UINTN)Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
break;
|
||||
case OPERATOR_ULT:
|
||||
case OPERATOR_LT:
|
||||
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
|
||||
//
|
||||
// string compare
|
||||
//
|
||||
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) < 0) || (StringCompare(&Compare1, &Compare2) < 0)) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// numeric compare
|
||||
//
|
||||
if (Compare1[0] == L'-') {
|
||||
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
|
||||
} else {
|
||||
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
|
||||
}
|
||||
if (Compare2[0] == L'-') {
|
||||
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
|
||||
} else {
|
||||
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
|
||||
}
|
||||
if (BinOp == OPERATOR_LT) {
|
||||
if (Cmp1 < Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
if ((UINTN)Cmp1 < (UINTN)Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return (FALSE);
|
||||
break;
|
||||
case OPERATOR_EQ:
|
||||
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
|
||||
//
|
||||
// string compare
|
||||
//
|
||||
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) == 0) || (StringCompare(&Compare1, &Compare2) == 0)) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// numeric compare
|
||||
//
|
||||
if (Compare1[0] == L'-') {
|
||||
Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
|
||||
} else {
|
||||
Cmp1 = (INTN)ShellStrToUintn(Compare1);
|
||||
}
|
||||
if (Compare2[0] == L'-') {
|
||||
Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
|
||||
} else {
|
||||
Cmp2 = (INTN)ShellStrToUintn(Compare2);
|
||||
}
|
||||
if (Cmp1 == Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
break;
|
||||
case OPERATOR_NE:
|
||||
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
|
||||
//
|
||||
// string compare
|
||||
//
|
||||
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) != 0) || (StringCompare(&Compare1, &Compare2) != 0)) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// numeric compare
|
||||
//
|
||||
if (Compare1[0] == L'-') {
|
||||
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
|
||||
} else {
|
||||
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
|
||||
}
|
||||
if (Compare2[0] == L'-') {
|
||||
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
|
||||
} else {
|
||||
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
|
||||
}
|
||||
if (Cmp1 != Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
break;
|
||||
case OPERATOR_UGE:
|
||||
case OPERATOR_GE:
|
||||
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
|
||||
//
|
||||
// string compare
|
||||
//
|
||||
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) >= 0) || (StringCompare(&Compare1, &Compare2) >= 0)) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// numeric compare
|
||||
//
|
||||
if (Compare1[0] == L'-') {
|
||||
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
|
||||
} else {
|
||||
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
|
||||
}
|
||||
if (Compare2[0] == L'-') {
|
||||
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
|
||||
} else {
|
||||
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
|
||||
}
|
||||
if (BinOp == OPERATOR_GE) {
|
||||
if (Cmp1 >= Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
if ((UINTN)Cmp1 >= (UINTN)Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
break;
|
||||
case OPERATOR_LE:
|
||||
case OPERATOR_ULE:
|
||||
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
|
||||
//
|
||||
// string compare
|
||||
//
|
||||
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) <= 0) || (StringCompare(&Compare1, &Compare2) <= 0)) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// numeric compare
|
||||
//
|
||||
if (Compare1[0] == L'-') {
|
||||
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
|
||||
} else {
|
||||
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
|
||||
}
|
||||
if (Compare2[0] == L'-') {
|
||||
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
|
||||
} else {
|
||||
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
|
||||
}
|
||||
if (BinOp == OPERATOR_LE) {
|
||||
if (Cmp1 <= Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
} else {
|
||||
if ((UINTN)Cmp1 <= (UINTN)Cmp2) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
break;
|
||||
}
|
||||
ASSERT(FALSE);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ProcessStatement (
|
||||
IN OUT BOOLEAN *PassingState,
|
||||
IN UINTN StartParameterNumber,
|
||||
IN UINTN EndParameterNumber,
|
||||
IN CONST END_TAG_TYPE OperatorToUse,
|
||||
IN CONST BOOLEAN CaseInsensitive,
|
||||
IN CONST BOOLEAN ForceStringCompare
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
BOOLEAN OperationResult;
|
||||
BOOLEAN NotPresent;
|
||||
CHAR16 *StatementWalker;
|
||||
BIN_OPERATOR_TYPE BinOp;
|
||||
CHAR16 *Compare1;
|
||||
CHAR16 *Compare2;
|
||||
CHAR16 HexString[20];
|
||||
CHAR16 *TempSpot;
|
||||
|
||||
ASSERT((END_TAG_TYPE)OperatorToUse != END_TAG_THEN);
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
BinOp = OPERATOR_MAX;
|
||||
OperationResult = FALSE;
|
||||
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber];
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"not")) {
|
||||
NotPresent = TRUE;
|
||||
StatementWalker = gEfiShellParametersProtocol->Argv[++StartParameterNumber];
|
||||
} else {
|
||||
NotPresent = FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// now check for 'boolfunc' operators
|
||||
//
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"isint")) {
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
|
||||
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
|
||||
OperationResult = ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE);
|
||||
} else {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"isint");
|
||||
}
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exists") || IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exist")) {
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
|
||||
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
|
||||
//
|
||||
// is what remains a file in CWD???
|
||||
//
|
||||
OperationResult = (BOOLEAN)(ShellFileExists(StatementWalker)==EFI_SUCCESS);
|
||||
} else if (StatementWalker[0] == CHAR_NULL && StartParameterNumber+1 == EndParameterNumber) {
|
||||
OperationResult = (BOOLEAN)(ShellFileExists(gEfiShellParametersProtocol->Argv[++StartParameterNumber])==EFI_SUCCESS);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"exist(s)");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"available")) {
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
|
||||
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
|
||||
//
|
||||
// is what remains a file in the CWD or path???
|
||||
//
|
||||
OperationResult = (BOOLEAN)(ShellIsFileInPath(StatementWalker)==EFI_SUCCESS);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"available");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"profile")) {
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
|
||||
//
|
||||
// Chop off that ')'
|
||||
//
|
||||
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
|
||||
OperationResult = IsValidProfile(StatementWalker);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"profile");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else if (StartParameterNumber+1 >= EndParameterNumber) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[StartParameterNumber]);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// must be 'item binop item' style
|
||||
//
|
||||
Compare1 = NULL;
|
||||
Compare2 = NULL;
|
||||
BinOp = OPERATOR_MAX;
|
||||
|
||||
//
|
||||
// get the first item
|
||||
//
|
||||
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber];
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror")) {
|
||||
TempSpot = StrStr(StatementWalker, L")");
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
|
||||
*TempSpot = CHAR_NULL;
|
||||
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
|
||||
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT);
|
||||
ASSERT(Compare1 == NULL);
|
||||
Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
|
||||
StatementWalker += StrLen(StatementWalker) + 1;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror")) {
|
||||
TempSpot = StrStr(StatementWalker, L")");
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
|
||||
*TempSpot = CHAR_NULL;
|
||||
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
|
||||
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>2));
|
||||
ASSERT(Compare1 == NULL);
|
||||
Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
|
||||
StatementWalker += StrLen(StatementWalker) + 1;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"oemerror")) {
|
||||
TempSpot = StrStr(StatementWalker, L")");
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
|
||||
TempSpot = CHAR_NULL;
|
||||
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
|
||||
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>1));
|
||||
ASSERT(Compare1 == NULL);
|
||||
Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
|
||||
StatementWalker += StrLen(StatementWalker) + 1;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
ASSERT(Compare1 == NULL);
|
||||
if (EndParameterNumber - StartParameterNumber > 2) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_STARTING), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[StartParameterNumber+2]);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// must be a raw string
|
||||
//
|
||||
Compare1 = StrnCatGrow(&Compare1, NULL, StatementWalker, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// get the operator
|
||||
//
|
||||
ASSERT(StartParameterNumber+1<EndParameterNumber);
|
||||
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber+1];
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"gt")) {
|
||||
BinOp = OPERATOR_GT;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"lt")) {
|
||||
BinOp = OPERATOR_LT;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"eq")) {
|
||||
BinOp = OPERATOR_EQ;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ne")) {
|
||||
BinOp = OPERATOR_NE;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ge")) {
|
||||
BinOp = OPERATOR_GE;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"le")) {
|
||||
BinOp = OPERATOR_LE;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"==")) {
|
||||
BinOp = OPERATOR_EQ;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ugt")) {
|
||||
BinOp = OPERATOR_UGT;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ult")) {
|
||||
BinOp = OPERATOR_ULT;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"uge")) {
|
||||
BinOp = OPERATOR_UGE;
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ule")) {
|
||||
BinOp = OPERATOR_ULE;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_INVALID_BINOP), gShellLevel1HiiHandle, StatementWalker);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// get the second item
|
||||
//
|
||||
ASSERT(StartParameterNumber+2<=EndParameterNumber);
|
||||
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber+2];
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror")) {
|
||||
TempSpot = StrStr(StatementWalker, L")");
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
|
||||
TempSpot = CHAR_NULL;
|
||||
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
|
||||
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT);
|
||||
ASSERT(Compare2 == NULL);
|
||||
Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
|
||||
StatementWalker += StrLen(StatementWalker) + 1;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
//
|
||||
// can this be collapsed into the above?
|
||||
//
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror")) {
|
||||
TempSpot = StrStr(StatementWalker, L")");
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
|
||||
TempSpot = CHAR_NULL;
|
||||
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
|
||||
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>2));
|
||||
ASSERT(Compare2 == NULL);
|
||||
Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
|
||||
StatementWalker += StrLen(StatementWalker) + 1;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"oemerror")) {
|
||||
TempSpot = StrStr(StatementWalker, L")");
|
||||
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
|
||||
TempSpot = CHAR_NULL;
|
||||
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
|
||||
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>1));
|
||||
ASSERT(Compare2 == NULL);
|
||||
Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
|
||||
StatementWalker += StrLen(StatementWalker) + 1;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// must be a raw string
|
||||
//
|
||||
ASSERT(Compare2 == NULL);
|
||||
Compare2 = StrnCatGrow(&Compare2, NULL, StatementWalker, 0);
|
||||
}
|
||||
|
||||
if (Compare1 != NULL && Compare2 != NULL && BinOp != OPERATOR_MAX) {
|
||||
OperationResult = TestOperation(Compare1, Compare2, BinOp, CaseInsensitive, ForceStringCompare);
|
||||
}
|
||||
|
||||
SHELL_FREE_NON_NULL(Compare1);
|
||||
SHELL_FREE_NON_NULL(Compare2);
|
||||
}
|
||||
|
||||
//
|
||||
// done processing do result...
|
||||
//
|
||||
|
||||
if (!EFI_ERROR(Status)) {
|
||||
if (NotPresent) {
|
||||
OperationResult = (BOOLEAN)(!OperationResult);
|
||||
}
|
||||
switch(OperatorToUse) {
|
||||
case END_TAG_OR:
|
||||
*PassingState = (BOOLEAN)(*PassingState || OperationResult);
|
||||
break;
|
||||
case END_TAG_AND:
|
||||
*PassingState = (BOOLEAN)(*PassingState && OperationResult);
|
||||
break;
|
||||
case END_TAG_MAX:
|
||||
*PassingState = (BOOLEAN)(OperationResult);
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
}
|
||||
return (Status);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
BuildNextStatement (
|
||||
IN UINTN ParameterNumber,
|
||||
OUT UINTN *EndParameter,
|
||||
OUT END_TAG_TYPE *EndTag
|
||||
)
|
||||
{
|
||||
CHAR16 *Buffer;
|
||||
UINTN BufferSize;
|
||||
|
||||
*EndTag = END_TAG_MAX;
|
||||
|
||||
for(Buffer = NULL, BufferSize = 0
|
||||
; ParameterNumber < gEfiShellParametersProtocol->Argc
|
||||
; ParameterNumber++
|
||||
) {
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[ParameterNumber],
|
||||
L"or") == 0) {
|
||||
*EndParameter = ParameterNumber - 1;
|
||||
*EndTag = END_TAG_OR;
|
||||
break;
|
||||
} else if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[ParameterNumber],
|
||||
L"and") == 0) {
|
||||
*EndParameter = ParameterNumber - 1;
|
||||
*EndTag = END_TAG_AND;
|
||||
break;
|
||||
} else if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[ParameterNumber],
|
||||
L"then") == 0) {
|
||||
*EndParameter = ParameterNumber - 1;
|
||||
*EndTag = END_TAG_THEN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*EndTag == END_TAG_MAX) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
MoveToTagSpecial (
|
||||
IN SCRIPT_FILE *ScriptFile
|
||||
)
|
||||
{
|
||||
SCRIPT_COMMAND_LIST *CommandNode;
|
||||
BOOLEAN Found;
|
||||
UINTN TargetCount;
|
||||
CHAR16 *CommandName;
|
||||
CHAR16 *CommandWalker;
|
||||
CHAR16 *TempLocation;
|
||||
|
||||
TargetCount = 1;
|
||||
Found = FALSE;
|
||||
|
||||
if (ScriptFile == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (CommandNode = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &ScriptFile->CurrentCommand->Link), Found = FALSE
|
||||
; !IsNull(&ScriptFile->CommandList, &CommandNode->Link) && !Found
|
||||
; CommandNode = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &CommandNode->Link)
|
||||
){
|
||||
|
||||
//
|
||||
// get just the first part of the command line...
|
||||
//
|
||||
CommandName = NULL;
|
||||
CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
|
||||
CommandWalker = CommandName;
|
||||
while (CommandWalker[0] == L' ') {
|
||||
CommandWalker++;
|
||||
}
|
||||
TempLocation = StrStr(CommandWalker, L" ");
|
||||
|
||||
if (TempLocation != NULL) {
|
||||
*TempLocation = CHAR_NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// did we find a nested item ?
|
||||
//
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
(CHAR16*)CommandWalker,
|
||||
L"If") == 0) {
|
||||
TargetCount++;
|
||||
} else if (TargetCount == 1 && gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
(CHAR16*)CommandWalker,
|
||||
(CHAR16*)L"else") == 0) {
|
||||
//
|
||||
// else can only decrement the last part... not an nested if
|
||||
// hence the TargetCount compare added
|
||||
//
|
||||
TargetCount--;
|
||||
} else if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
(CHAR16*)CommandWalker,
|
||||
(CHAR16*)L"endif") == 0) {
|
||||
TargetCount--;
|
||||
}
|
||||
if (TargetCount == 0) {
|
||||
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &CommandNode->Link);
|
||||
Found = TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Free the memory for this loop...
|
||||
//
|
||||
SHELL_FREE_NON_NULL(CommandName);
|
||||
}
|
||||
return (Found);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
PerformResultOperation (
|
||||
IN CONST BOOLEAN Result
|
||||
)
|
||||
{
|
||||
if (Result || MoveToTagSpecial(ShellCommandGetCurrentScriptFile())) {
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
return (EFI_NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'if' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunIf (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
SHELL_STATUS ShellStatus;
|
||||
BOOLEAN CaseInsensitive;
|
||||
BOOLEAN ForceString;
|
||||
UINTN CurrentParameter;
|
||||
UINTN EndParameter;
|
||||
BOOLEAN CurrentValue;
|
||||
END_TAG_TYPE Ending;
|
||||
END_TAG_TYPE PreviousEnding;
|
||||
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"If");
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
if (gEfiShellParametersProtocol->Argc < 3) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
//
|
||||
// Make sure that an End exists.
|
||||
//
|
||||
if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), TRUE, TRUE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EnfIf", L"If", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
CurrentParameter = 1;
|
||||
EndParameter = 0;
|
||||
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[1],
|
||||
L"/i") == 0 ||
|
||||
gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[2],
|
||||
L"/i") == 0 ||
|
||||
(gEfiShellParametersProtocol->Argc > 3 && gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[3],
|
||||
L"/i") == 0)) {
|
||||
CaseInsensitive = TRUE;
|
||||
CurrentParameter++;
|
||||
} else {
|
||||
CaseInsensitive = FALSE;
|
||||
}
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[1],
|
||||
L"/s") == 0 ||
|
||||
gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[2],
|
||||
L"/s") == 0 ||
|
||||
(gEfiShellParametersProtocol->Argc > 3 && gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[3],
|
||||
L"/s") == 0)) {
|
||||
ForceString = TRUE;
|
||||
CurrentParameter++;
|
||||
} else {
|
||||
ForceString = FALSE;
|
||||
}
|
||||
|
||||
for ( ShellStatus = SHELL_SUCCESS, CurrentValue = FALSE, Ending = END_TAG_MAX
|
||||
; CurrentParameter < gEfiShellParametersProtocol->Argc && ShellStatus == SHELL_SUCCESS
|
||||
; CurrentParameter++) {
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
gEfiShellParametersProtocol->Argv[CurrentParameter],
|
||||
L"then") == 0) {
|
||||
//
|
||||
// we are at the then
|
||||
//
|
||||
if (CurrentParameter+1 != gEfiShellParametersProtocol->Argc) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TEXT_AFTER_THEN), gShellLevel1HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
Status = PerformResultOperation(CurrentValue);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PreviousEnding = Ending;
|
||||
//
|
||||
// build up the next statement for analysis
|
||||
//
|
||||
if (!BuildNextStatement(CurrentParameter, &EndParameter, &Ending)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"Then", L"If", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// Analyze the statement
|
||||
//
|
||||
Status = ProcessStatement(&CurrentValue, CurrentParameter, EndParameter, PreviousEnding, CaseInsensitive, ForceString);
|
||||
if (EFI_ERROR(Status)) {
|
||||
// ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_STARTING), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// Optomize to get out of the loop early...
|
||||
//
|
||||
if ((Ending == END_TAG_OR && CurrentValue) || (Ending == END_TAG_AND && !CurrentValue)) {
|
||||
Status = PerformResultOperation(CurrentValue);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS){
|
||||
CurrentParameter = EndParameter;
|
||||
//
|
||||
// Skip over the or or and parameter.
|
||||
//
|
||||
if (Ending == END_TAG_OR || Ending == END_TAG_AND) {
|
||||
CurrentParameter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'else' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunElse (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
ASSERT_EFI_ERROR(CommandInit());
|
||||
|
||||
if (gEfiShellParametersProtocol->Argc > 1) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Else");
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
|
||||
if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
if (!MoveToTag(GetPreviousNode, L"if", L"else", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndIf", "Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'endif' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunEndIf (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
ASSERT_EFI_ERROR(CommandInit());
|
||||
|
||||
if (gEfiShellParametersProtocol->Argc > 1) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Endif");
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"EndIf", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
/** @file
|
||||
Main file for else and endif shell level 1 functions. Does nothing really...
|
||||
|
||||
Copyright (c) 2009-2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel1CommandsLib.h"
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunNoOpScriptCommand (
|
||||
VOID *RESERVED
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
//
|
||||
// ASSERT that we can init...
|
||||
//
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// We best be in a script...
|
||||
//
|
||||
ASSERT(gEfiShellProtocol->BatchIsActive());
|
||||
|
||||
//
|
||||
// Do nothing...
|
||||
//
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
63
ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c
Normal file
63
ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/** @file
|
||||
Main file for Shift shell level 1 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel1CommandsLib.h"
|
||||
|
||||
/**
|
||||
Function for 'shift' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunShift (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
SCRIPT_FILE *CurrentScriptFile;
|
||||
UINTN LoopVar;
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Shift");
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
CurrentScriptFile = ShellCommandGetCurrentScriptFile();
|
||||
ASSERT(CurrentScriptFile != NULL);
|
||||
|
||||
if (CurrentScriptFile->Argc < 2) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
for (LoopVar = 0 ; LoopVar < CurrentScriptFile->Argc ; LoopVar++) {
|
||||
if (LoopVar == 0) {
|
||||
SHELL_FREE_NON_NULL(CurrentScriptFile->Argv[LoopVar]);
|
||||
}
|
||||
if (LoopVar < CurrentScriptFile->Argc -1) {
|
||||
CurrentScriptFile->Argv[LoopVar] = CurrentScriptFile->Argv[LoopVar+1];
|
||||
} else {
|
||||
CurrentScriptFile->Argv[LoopVar] = NULL;
|
||||
}
|
||||
}
|
||||
CurrentScriptFile->Argc--;
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
@@ -0,0 +1,251 @@
|
||||
/** @file
|
||||
Main file for NULL named library for level 1 shell command functions.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel1CommandsLib.h"
|
||||
|
||||
STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
|
||||
EFI_HANDLE gShellLevel1HiiHandle = NULL;
|
||||
CONST EFI_GUID gShellLevel1HiiGuid = \
|
||||
{ \
|
||||
0xdec5daa4, 0x6781, 0x4820, { 0x9c, 0x63, 0xa7, 0xb0, 0xe4, 0xf1, 0xdb, 0x31 }
|
||||
};
|
||||
|
||||
|
||||
CONST CHAR16*
|
||||
EFIAPI
|
||||
ShellCommandGetManFileNameLevel1 (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (mFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructor for the Shell Level 1 Commands library.
|
||||
|
||||
Install the handlers for level 1 UEFI Shell 2.0 commands.
|
||||
|
||||
@param ImageHandle the image handle of the process
|
||||
@param SystemTable the EFI System Table pointer
|
||||
|
||||
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
|
||||
@retval EFI_UNSUPPORTED the shell level required was not found.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ShellLevel1CommandsLibConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
//
|
||||
// if shell level is less than 2 do nothing
|
||||
//
|
||||
if (PcdGet8(PcdShellSupportLevel) < 1) {
|
||||
return (EFI_UNSUPPORTED);
|
||||
}
|
||||
|
||||
gShellLevel1HiiHandle = HiiAddPackages (&gShellLevel1HiiGuid, gImageHandle, UefiShellLevel1CommandsLibStrings, NULL);
|
||||
if (gShellLevel1HiiHandle == NULL) {
|
||||
return (EFI_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
//
|
||||
// install our shell command handlers that are always installed
|
||||
//
|
||||
ShellCommandRegisterCommandName(L"for", ShellCommandRunFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR) ));
|
||||
ShellCommandRegisterCommandName(L"goto", ShellCommandRunGoto , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO) ));
|
||||
ShellCommandRegisterCommandName(L"if", ShellCommandRunIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF) ));
|
||||
ShellCommandRegisterCommandName(L"shift", ShellCommandRunShift , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT) ));
|
||||
ShellCommandRegisterCommandName(L"exit", ShellCommandRunExit , ShellCommandGetManFileNameLevel1, 1, L"", TRUE , gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT) ));
|
||||
ShellCommandRegisterCommandName(L"else", ShellCommandRunElse , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE) ));
|
||||
ShellCommandRegisterCommandName(L"endif", ShellCommandRunEndIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF) ));
|
||||
ShellCommandRegisterCommandName(L"endfor", ShellCommandRunEndFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR)));
|
||||
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Destructor for the library. free any resources.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ShellLevel1CommandsLibDestructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
if (gShellLevel1HiiHandle != NULL) {
|
||||
HiiRemovePackages(gShellLevel1HiiHandle);
|
||||
}
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
TestNodeForMove (
|
||||
IN CONST LIST_MANIP_FUNC Function,
|
||||
IN CONST CHAR16 *DecrementerTag,
|
||||
IN CONST CHAR16 *IncrementerTag,
|
||||
IN CONST CHAR16 *Label OPTIONAL,
|
||||
IN SCRIPT_FILE *ScriptFile,
|
||||
IN CONST BOOLEAN MovePast,
|
||||
IN CONST BOOLEAN FindOnly,
|
||||
IN CONST SCRIPT_COMMAND_LIST *CommandNode,
|
||||
IN UINTN *TargetCount
|
||||
)
|
||||
{
|
||||
BOOLEAN Found;
|
||||
CHAR16 *CommandName;
|
||||
CHAR16 *CommandNameWalker;
|
||||
CHAR16 *TempLocation;
|
||||
|
||||
Found = FALSE;
|
||||
|
||||
//
|
||||
// get just the first part of the command line...
|
||||
//
|
||||
CommandName = NULL;
|
||||
CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
|
||||
CommandNameWalker = CommandName;
|
||||
while(CommandNameWalker[0] == L' ') {
|
||||
CommandNameWalker++;
|
||||
}
|
||||
TempLocation = StrStr(CommandNameWalker, L" ");
|
||||
|
||||
if (TempLocation != NULL) {
|
||||
*TempLocation = CHAR_NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// did we find a nested item ?
|
||||
//
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
(CHAR16*)CommandNameWalker,
|
||||
(CHAR16*)IncrementerTag) == 0) {
|
||||
(*TargetCount)++;
|
||||
} else if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
(CHAR16*)CommandNameWalker,
|
||||
(CHAR16*)DecrementerTag) == 0) {
|
||||
if (*TargetCount > 0) {
|
||||
(*TargetCount)--;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// did we find the matching one...
|
||||
//
|
||||
if (Label == NULL) {
|
||||
if (*TargetCount == 0) {
|
||||
Found = TRUE;
|
||||
if (!FindOnly) {
|
||||
if (MovePast) {
|
||||
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
|
||||
} else {
|
||||
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (gUnicodeCollation->StriColl(
|
||||
gUnicodeCollation,
|
||||
(CHAR16*)CommandNameWalker,
|
||||
(CHAR16*)Label) == 0
|
||||
&& (*TargetCount) == 0) {
|
||||
Found = TRUE;
|
||||
if (!FindOnly) {
|
||||
//
|
||||
// we found the target label without loops
|
||||
//
|
||||
if (MovePast) {
|
||||
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
|
||||
} else {
|
||||
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Free the memory for this loop...
|
||||
//
|
||||
FreePool(CommandName);
|
||||
return (Found);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
MoveToTag (
|
||||
IN CONST LIST_MANIP_FUNC Function,
|
||||
IN CONST CHAR16 *DecrementerTag,
|
||||
IN CONST CHAR16 *IncrementerTag,
|
||||
IN CONST CHAR16 *Label OPTIONAL,
|
||||
IN SCRIPT_FILE *ScriptFile,
|
||||
IN CONST BOOLEAN MovePast,
|
||||
IN CONST BOOLEAN FindOnly,
|
||||
IN CONST BOOLEAN WrapAroundScript
|
||||
)
|
||||
{
|
||||
SCRIPT_COMMAND_LIST *CommandNode;
|
||||
BOOLEAN Found;
|
||||
UINTN TargetCount;
|
||||
|
||||
if (Label == NULL) {
|
||||
TargetCount = 1;
|
||||
} else {
|
||||
TargetCount = 0;
|
||||
}
|
||||
|
||||
if (ScriptFile == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &ScriptFile->CurrentCommand->Link), Found = FALSE
|
||||
; !IsNull(&ScriptFile->CommandList, &CommandNode->Link)&& !Found
|
||||
; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
|
||||
){
|
||||
Found = TestNodeForMove(
|
||||
Function,
|
||||
DecrementerTag,
|
||||
IncrementerTag,
|
||||
Label,
|
||||
ScriptFile,
|
||||
MovePast,
|
||||
FindOnly,
|
||||
CommandNode,
|
||||
&TargetCount);
|
||||
}
|
||||
|
||||
if (WrapAroundScript && !Found) {
|
||||
for (CommandNode = (SCRIPT_COMMAND_LIST *)GetFirstNode(&ScriptFile->CommandList), Found = FALSE
|
||||
; CommandNode != ScriptFile->CurrentCommand && !Found
|
||||
; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
|
||||
){
|
||||
Found = TestNodeForMove(
|
||||
Function,
|
||||
DecrementerTag,
|
||||
IncrementerTag,
|
||||
Label,
|
||||
ScriptFile,
|
||||
MovePast,
|
||||
FindOnly,
|
||||
CommandNode,
|
||||
&TargetCount);
|
||||
}
|
||||
}
|
||||
return (Found);
|
||||
}
|
||||
|
@@ -0,0 +1,182 @@
|
||||
/** @file
|
||||
Main file for NULL named library for level 1 shell command functions.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <ShellBase.h>
|
||||
|
||||
#include <Protocol/EfiShell.h>
|
||||
#include <Protocol/EfiShellParameters.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
#include <Protocol/DevicePathToText.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/ShellCommandLib.h>
|
||||
#include <Library/ShellLib.h>
|
||||
#include <Library/SortLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/HiiLib.h>
|
||||
#include <Library/FileHandleLib.h>
|
||||
|
||||
extern EFI_HANDLE gShellLevel1HiiHandle;
|
||||
extern CONST EFI_GUID gShellLevel1HiiGuid;
|
||||
|
||||
/**
|
||||
Function for 'exit' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunExit (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'endif' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunEndIf (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'for' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunFor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'endfor' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunEndFor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'if' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunIf (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'goto' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunGoto (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'shift' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunShift (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
Function for 'else' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunElse (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
///
|
||||
/// Function prototype for BOTH GetNextNode and GetPreviousNode...
|
||||
/// This is used to control the MoveToTag function direction...
|
||||
///
|
||||
typedef
|
||||
LIST_ENTRY *
|
||||
(EFIAPI *LIST_MANIP_FUNC)(
|
||||
IN CONST LIST_ENTRY *List,
|
||||
IN CONST LIST_ENTRY *Node
|
||||
);
|
||||
|
||||
/**
|
||||
Function to move to a spacified tag in a script file structure.
|
||||
|
||||
@param[in] Function The pointer to the function to move with.
|
||||
@param[in] DecrementerTag The pointer to a string to decrement upon finding.
|
||||
@param[in] IncrementerTag The pointer to a string to increment upon finding.
|
||||
@param[in] Label A Label to look for.
|
||||
@param[in] ScriptFile The script file structure to look in.
|
||||
@param[in] MovePast TRUE to go to the element just after the found one. FALSE otherwise.
|
||||
@param[in] FindOnly FALSE to change the execution point in the script file structure. TRUE otherwise.
|
||||
@param[in] WrapAroundScript TRUE to go to begining when end is hit, or vise versa. FALSE otherwise.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
MoveToTag (
|
||||
IN CONST LIST_MANIP_FUNC Function,
|
||||
IN CONST CHAR16 *DecrementerTag,
|
||||
IN CONST CHAR16 *IncrementerTag,
|
||||
IN CONST CHAR16 *Label OPTIONAL,
|
||||
IN SCRIPT_FILE *ScriptFile,
|
||||
IN CONST BOOLEAN MovePast,
|
||||
IN CONST BOOLEAN FindOnly,
|
||||
IN CONST BOOLEAN WrapAroundScript
|
||||
);
|
||||
|
@@ -0,0 +1,54 @@
|
||||
## @file
|
||||
# Provides shell level 1 functions
|
||||
#
|
||||
# Copyright (c) 2009-2010, Intel Corporation. All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = UefiShellLevel1CommandsLib
|
||||
FILE_GUID = 50cb6037-1102-47af-b2dd-9944b6eb1abe
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
|
||||
CONSTRUCTOR = ShellLevel1CommandsLibConstructor
|
||||
DESTRUCTOR = ShellLevel1CommandsLibDestructor
|
||||
|
||||
[Sources.common]
|
||||
UefiShellLevel1CommandsLib.c
|
||||
UefiShellLevel1CommandsLib.h
|
||||
UefiShellLevel1CommandsLib.uni
|
||||
Exit.c
|
||||
Goto.c
|
||||
If.c
|
||||
For.c
|
||||
Shift.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
MemoryAllocationLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
ShellCommandLib
|
||||
ShellLib
|
||||
UefiLib
|
||||
UefiRuntimeServicesTableLib
|
||||
UefiBootServicesTableLib
|
||||
SortLib
|
||||
PrintLib
|
||||
|
||||
[Pcd.common]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED
|
Binary file not shown.
271
ShellPkg/Library/UefiShellLevel2CommandsLib/Attrib.c
Normal file
271
ShellPkg/Library/UefiShellLevel2CommandsLib/Attrib.c
Normal file
@@ -0,0 +1,271 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
STATIC CONST CHAR16 AllFiles[] = L"*";
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM AttribParamList[] = {
|
||||
{L"-a", TypeFlag},
|
||||
{L"+a", TypeFlag},
|
||||
{L"-s", TypeFlag},
|
||||
{L"+s", TypeFlag},
|
||||
{L"-h", TypeFlag},
|
||||
{L"+h", TypeFlag},
|
||||
{L"-r", TypeFlag},
|
||||
{L"+r", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'attrib' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunAttrib (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
UINT64 FileAttributesToAdd;
|
||||
UINT64 FileAttributesToRemove;
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamNumberCount;
|
||||
CONST CHAR16 *FileName;
|
||||
EFI_SHELL_FILE_INFO *ListOfFiles;
|
||||
EFI_SHELL_FILE_INFO *FileNode;
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
|
||||
ListOfFiles = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ProblemParam = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (AttribParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else {
|
||||
FileAttributesToAdd = 0;
|
||||
FileAttributesToRemove = 0;
|
||||
|
||||
//
|
||||
// apply or remove each flag
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"+a")) {
|
||||
FileAttributesToAdd |= EFI_FILE_ARCHIVE;
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"-a")) {
|
||||
FileAttributesToRemove |= EFI_FILE_ARCHIVE;
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"+s")) {
|
||||
FileAttributesToAdd |= EFI_FILE_SYSTEM;
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"-s")) {
|
||||
FileAttributesToRemove |= EFI_FILE_SYSTEM;
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"+h")) {
|
||||
FileAttributesToAdd |= EFI_FILE_HIDDEN;
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"-h")) {
|
||||
FileAttributesToRemove |= EFI_FILE_HIDDEN;
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"+r")) {
|
||||
FileAttributesToAdd |= EFI_FILE_READ_ONLY;
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"-r")) {
|
||||
FileAttributesToRemove |= EFI_FILE_READ_ONLY;
|
||||
}
|
||||
|
||||
if (FileAttributesToRemove == 0 && FileAttributesToAdd == 0) {
|
||||
//
|
||||
// Do display as we have no attributes to change
|
||||
//
|
||||
for ( ParamNumberCount = 1
|
||||
;
|
||||
; ParamNumberCount++
|
||||
){
|
||||
FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
|
||||
// if we dont have anything left, move on...
|
||||
if (FileName == NULL && ParamNumberCount == 1) {
|
||||
FileName = (CHAR16*)AllFiles;
|
||||
} else if (FileName == NULL) {
|
||||
break;
|
||||
}
|
||||
ASSERT(ListOfFiles == NULL);
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
|
||||
; !IsNull(&ListOfFiles->Link, &FileNode->Link)
|
||||
; FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
|
||||
){
|
||||
ShellPrintHiiEx(
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_ATTRIB_OUTPUT_LINE),
|
||||
gShellLevel2HiiHandle,
|
||||
FileNode->Info->Attribute&EFI_FILE_DIRECTORY? L'D':L' ',
|
||||
FileNode->Info->Attribute&EFI_FILE_ARCHIVE? L'A':L' ',
|
||||
FileNode->Info->Attribute&EFI_FILE_SYSTEM? L'S':L' ',
|
||||
FileNode->Info->Attribute&EFI_FILE_HIDDEN? L'H':L' ',
|
||||
FileNode->Info->Attribute&EFI_FILE_READ_ONLY? L'R':L' ',
|
||||
FileNode->FileName
|
||||
);
|
||||
}
|
||||
Status = ShellCloseFileMetaArg(&ListOfFiles);
|
||||
ListOfFiles = NULL;
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
} // for loop for handling wildcard filenames
|
||||
} // for loop for printing out the info
|
||||
} else if ((FileAttributesToRemove & FileAttributesToAdd) != 0) {
|
||||
//
|
||||
// fail as we have conflcting params.
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// enumerate through all the files/directories and apply the attributes
|
||||
//
|
||||
for ( ParamNumberCount = 1
|
||||
;
|
||||
; ParamNumberCount++
|
||||
){
|
||||
FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
|
||||
// if we dont have anything left, move on...
|
||||
if (FileName == NULL) {
|
||||
//
|
||||
// make sure we are not failing on the first one we do... if yes that's an error...
|
||||
//
|
||||
if (ParamNumberCount == 1) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// OpenFileByName / GetFileInfo / Change attributes / SetFileInfo / CloseFile / free memory
|
||||
// for each file or directory on the line.
|
||||
//
|
||||
|
||||
//
|
||||
// Open the file(s)
|
||||
//
|
||||
ASSERT(ListOfFiles == NULL);
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
|
||||
; !IsNull(&ListOfFiles->Link, &FileNode->Link)
|
||||
; FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
|
||||
){
|
||||
//
|
||||
// skip the directory traversing stuff...
|
||||
//
|
||||
if (StrCmp(FileNode->FileName, L".") == 0 || StrCmp(FileNode->FileName, L"..") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FileInfo = gEfiShellProtocol->GetFileInfo(FileNode->Handle);
|
||||
|
||||
//
|
||||
// if we are removing Read-Only we need to do that alone
|
||||
//
|
||||
if ((FileAttributesToRemove & EFI_FILE_READ_ONLY) == EFI_FILE_READ_ONLY) {
|
||||
FileInfo->Attribute &= ~EFI_FILE_READ_ONLY;
|
||||
//
|
||||
// SetFileInfo
|
||||
//
|
||||
Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
|
||||
if (EFI_ERROR(Status)) {;
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// change the attribute
|
||||
//
|
||||
FileInfo->Attribute &= ~FileAttributesToRemove;
|
||||
FileInfo->Attribute |= FileAttributesToAdd;
|
||||
|
||||
//
|
||||
// SetFileInfo
|
||||
//
|
||||
Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
|
||||
if (EFI_ERROR(Status)) {;
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
SHELL_FREE_NON_NULL(FileInfo);
|
||||
}
|
||||
Status = ShellCloseFileMetaArg(&ListOfFiles);
|
||||
ListOfFiles = NULL;
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
} // for loop for handling wildcard filenames
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
//
|
||||
// return the status
|
||||
//
|
||||
return (ShellStatus);
|
||||
}
|
218
ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
Normal file
218
ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
Normal file
@@ -0,0 +1,218 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
/**
|
||||
Function for 'cd' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunCd (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CONST CHAR16 *Directory;
|
||||
CHAR16 *Path;
|
||||
CHAR16 *Drive;
|
||||
UINTN DriveSize;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
SHELL_FILE_HANDLE Handle;
|
||||
CONST CHAR16 *Param1;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
Drive = NULL;
|
||||
DriveSize = 0;
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// remember that param 0 is the command name
|
||||
// If there are 0 value parameters, then print the current directory
|
||||
// else If there are 2 value parameters, then print the error message
|
||||
// else If there is 1 value paramerer , then change the directory
|
||||
//
|
||||
Param1 = ShellCommandLineGetRawValue(Package, 1);
|
||||
if (Param1 == NULL) {
|
||||
//
|
||||
// display the current directory
|
||||
//
|
||||
Directory = ShellGetCurrentDir(NULL);
|
||||
if (Directory != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, Directory);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
} else {
|
||||
if (StrCmp(Param1, L".") == 0) {
|
||||
//
|
||||
// nothing to do... change to current directory
|
||||
//
|
||||
} else if (StrCmp(Param1, L"..") == 0) {
|
||||
//
|
||||
// Change up one directory...
|
||||
//
|
||||
Directory = ShellGetCurrentDir(NULL);
|
||||
if (Directory == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
Drive = GetFullyQualifiedPath(Directory);
|
||||
ChopLastSlash(Drive);
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
|
||||
//
|
||||
// change directory on current drive letter
|
||||
//
|
||||
Status = gEfiShellProtocol->SetCurDir(NULL, Drive);
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
} else if (StrCmp(Param1, L"\\") == 0) {
|
||||
//
|
||||
// Move to root of current drive
|
||||
//
|
||||
Directory = ShellGetCurrentDir(NULL);
|
||||
if (Directory == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
Drive = GetFullyQualifiedPath(Directory);
|
||||
while (ChopLastSlash(Drive)) ;
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
|
||||
//
|
||||
// change directory on current drive letter
|
||||
//
|
||||
Status = gEfiShellProtocol->SetCurDir(NULL, Drive);
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
} else if (StrStr(Param1, L":") == NULL) {
|
||||
if (ShellGetCurrentDir(NULL) == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));
|
||||
Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);
|
||||
if (*Param1 == L'\\') {
|
||||
while (ChopLastSlash(Drive)) ;
|
||||
Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);
|
||||
} else {
|
||||
Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);
|
||||
}
|
||||
//
|
||||
// Verify that this is a valid directory
|
||||
//
|
||||
Status = gEfiShellProtocol->OpenFileByName(Drive, &Handle, EFI_FILE_MODE_READ);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Drive);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else if (EFI_ERROR(FileHandleIsDirectory(Handle))) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Drive);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
|
||||
//
|
||||
// change directory on current drive letter
|
||||
//
|
||||
Status = gEfiShellProtocol->SetCurDir(NULL, Drive);
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
if (Handle != NULL) {
|
||||
gEfiShellProtocol->CloseFile(Handle);
|
||||
DEBUG_CODE(Handle = NULL;);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// change directory on other drive letter
|
||||
//
|
||||
Drive = AllocateZeroPool(StrSize(Param1));
|
||||
Drive = StrCpy(Drive, Param1);
|
||||
Path = StrStr(Drive, L":");
|
||||
*(++Path) = CHAR_NULL;
|
||||
Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);
|
||||
|
||||
if (Status == EFI_NOT_FOUND) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
|
||||
Status = SHELL_NOT_FOUND;
|
||||
} else if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);
|
||||
Status = SHELL_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Drive != NULL) {
|
||||
FreePool(Drive);
|
||||
}
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
//
|
||||
// return the status
|
||||
//
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
599
ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
Normal file
599
ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
Normal file
@@ -0,0 +1,599 @@
|
||||
/** @file
|
||||
Main file for cp shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
// this is later in the file.
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ValidateAndCopyFiles(
|
||||
IN CONST EFI_SHELL_FILE_INFO *FileList,
|
||||
IN CONST CHAR16 *DestDir,
|
||||
IN BOOLEAN SilentMode,
|
||||
IN BOOLEAN RecursiveMode,
|
||||
IN VOID **Resp
|
||||
);
|
||||
|
||||
/**
|
||||
Function to Copy one file to another location
|
||||
|
||||
If the destination exists the user will be prompted and the result put into *resp
|
||||
|
||||
@param[in] Source pointer to source file name
|
||||
@param[in] Dest pointer to destination file name
|
||||
@param[out] Resp pointer to response from question. Pass back on looped calling
|
||||
@param[in] SilentMode whether to run in quiet mode or not
|
||||
|
||||
@retval SHELL_SUCCESS The source file was copied to the destination
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
CopySingleFile(
|
||||
IN CONST CHAR16 *Source,
|
||||
IN CONST CHAR16 *Dest,
|
||||
OUT VOID **Resp,
|
||||
IN BOOLEAN SilentMode
|
||||
)
|
||||
{
|
||||
VOID *Response;
|
||||
UINTN ReadSize;
|
||||
SHELL_FILE_HANDLE SourceHandle;
|
||||
SHELL_FILE_HANDLE DestHandle;
|
||||
EFI_STATUS Status;
|
||||
VOID *Buffer;
|
||||
CHAR16 *TempName;
|
||||
UINTN Size;
|
||||
EFI_SHELL_FILE_INFO *List;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
|
||||
ASSERT(Resp != NULL);
|
||||
|
||||
SourceHandle = NULL;
|
||||
DestHandle = NULL;
|
||||
Response = *Resp;
|
||||
List = NULL;
|
||||
|
||||
ReadSize = PcdGet16(PcdShellFileOperationSize);
|
||||
// Why bother copying a file to itself
|
||||
if (StrCmp(Source, Dest) == 0) {
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
//
|
||||
// Open destination file without create
|
||||
//
|
||||
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
|
||||
|
||||
//
|
||||
// close file
|
||||
//
|
||||
if (DestHandle != NULL) {
|
||||
ShellCloseFile(&DestHandle);
|
||||
DestHandle = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// if the destination file existed check response and possibly prompt user
|
||||
//
|
||||
if (!EFI_ERROR(Status)) {
|
||||
if (Response == NULL && !SilentMode) {
|
||||
Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_CP_PROMPT), gShellLevel2HiiHandle, &Response);
|
||||
}
|
||||
//
|
||||
// possibly return based on response
|
||||
//
|
||||
if (!SilentMode) {
|
||||
switch (*(SHELL_PROMPT_RESPONSE*)Response) {
|
||||
case ShellPromptResponseNo:
|
||||
//
|
||||
// return success here so we dont stop the process
|
||||
//
|
||||
return (SHELL_SUCCESS);
|
||||
case ShellPromptResponseCancel:
|
||||
*Resp = Response;
|
||||
//
|
||||
// indicate to stop everything
|
||||
//
|
||||
return (SHELL_ABORTED);
|
||||
case ShellPromptResponseAll:
|
||||
*Resp = Response;
|
||||
case ShellPromptResponseYes:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ShellIsDirectory(Source) == EFI_SUCCESS) {
|
||||
Status = ShellCreateDirectory(Dest, &DestHandle);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return (SHELL_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
//
|
||||
// Now copy all the files under the directory...
|
||||
//
|
||||
TempName = NULL;
|
||||
Size = 0;
|
||||
StrnCatGrow(&TempName, &Size, Source, 0);
|
||||
StrnCatGrow(&TempName, &Size, L"\\*", 0);
|
||||
ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
|
||||
TempName = NULL;
|
||||
StrnCatGrow(&TempName, &Size, Dest, 0);
|
||||
StrnCatGrow(&TempName, &Size, L"\\", 0);
|
||||
ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
|
||||
ShellCloseFileMetaArg(&List);
|
||||
FreePool(TempName);
|
||||
Size = 0;
|
||||
} else {
|
||||
//
|
||||
// open file with create enabled
|
||||
//
|
||||
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return (SHELL_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
//
|
||||
// open source file
|
||||
//
|
||||
Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// copy data between files
|
||||
//
|
||||
Buffer = AllocateZeroPool(ReadSize);
|
||||
ASSERT(Buffer != NULL);
|
||||
while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
|
||||
Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// close files
|
||||
//
|
||||
if (DestHandle != NULL) {
|
||||
ShellCloseFile(&DestHandle);
|
||||
DestHandle = NULL;
|
||||
}
|
||||
if (SourceHandle != NULL) {
|
||||
ShellCloseFile(&SourceHandle);
|
||||
SourceHandle = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// return
|
||||
//
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
function to take a list of files to copy and a destination location and do
|
||||
the verification and copying of those files to that location. This function
|
||||
will report any errors to the user and halt.
|
||||
|
||||
The key is to have this function called ONLY once. this allows for the parameter
|
||||
verification to happen correctly.
|
||||
|
||||
@param[in] FileList A LIST_ENTRY* based list of files to move
|
||||
@param[in] DestDir the destination location
|
||||
|
||||
@retval SHELL_SUCCESS the files were all moved.
|
||||
@retval SHELL_INVALID_PARAMETER a parameter was invalid
|
||||
@retval SHELL_SECURITY_VIOLATION a security violation ocurred
|
||||
@retval SHELL_WRITE_PROTECTED the destination was write protected
|
||||
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ValidateAndCopyFiles(
|
||||
IN CONST EFI_SHELL_FILE_INFO *FileList,
|
||||
IN CONST CHAR16 *DestDir,
|
||||
IN BOOLEAN SilentMode,
|
||||
IN BOOLEAN RecursiveMode,
|
||||
IN VOID **Resp
|
||||
)
|
||||
{
|
||||
CHAR16 *HiiOutput;
|
||||
CHAR16 *HiiResultOk;
|
||||
CONST EFI_SHELL_FILE_INFO *Node;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CHAR16 *DestPath;
|
||||
VOID *Response;
|
||||
UINTN PathLen;
|
||||
CONST CHAR16 *Cwd;
|
||||
CONST CHAR16 *TempLocation;
|
||||
UINTN NewSize;
|
||||
|
||||
if (Resp == NULL) {
|
||||
Response = NULL;
|
||||
} else {
|
||||
Response = *Resp;
|
||||
}
|
||||
|
||||
DestPath = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
PathLen = 0;
|
||||
Cwd = ShellGetCurrentDir(NULL);
|
||||
|
||||
ASSERT(FileList != NULL);
|
||||
ASSERT(DestDir != NULL);
|
||||
|
||||
//
|
||||
// If we are trying to copy multiple files... make sure we got a directory for the target...
|
||||
//
|
||||
if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
|
||||
//
|
||||
// Error for destination not a directory
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
|
||||
; !IsNull(&FileList->Link, &Node->Link)
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
|
||||
){
|
||||
//
|
||||
// skip the directory traversing stuff...
|
||||
//
|
||||
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NewSize = StrSize(DestDir);
|
||||
NewSize += StrSize(Node->FileName);
|
||||
NewSize += StrSize(Cwd);
|
||||
if (NewSize > PathLen) {
|
||||
PathLen = NewSize;
|
||||
}
|
||||
|
||||
//
|
||||
// Make sure got -r if required
|
||||
//
|
||||
if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
//
|
||||
// make sure got dest as dir if needed
|
||||
//
|
||||
if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(DestDir))) {
|
||||
//
|
||||
// Error for destination not a directory
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
}
|
||||
|
||||
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);
|
||||
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
|
||||
DestPath = AllocatePool(PathLen);
|
||||
|
||||
//
|
||||
// Go through the list of files to copy...
|
||||
//
|
||||
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
|
||||
; !IsNull(&FileList->Link, &Node->Link)
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
|
||||
){
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
break;
|
||||
}
|
||||
ASSERT(Node->FileName != NULL);
|
||||
ASSERT(Node->FullName != NULL);
|
||||
|
||||
//
|
||||
// skip the directory traversing stuff...
|
||||
//
|
||||
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item
|
||||
&& EFI_ERROR(ShellIsDirectory(DestDir)) // not an existing directory
|
||||
) {
|
||||
ASSERT(StrStr(DestDir, L":") == NULL);
|
||||
//
|
||||
// simple copy of a single file
|
||||
//
|
||||
StrCpy(DestPath, Cwd);
|
||||
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
|
||||
StrCat(DestPath, L"\\");
|
||||
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
|
||||
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
|
||||
}
|
||||
StrCat(DestPath, DestDir);
|
||||
} else {
|
||||
//
|
||||
// we have multiple files or a directory in the DestDir
|
||||
//
|
||||
if (StrStr(DestDir, L":") == NULL) {
|
||||
StrCpy(DestPath, Cwd);
|
||||
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
|
||||
StrCat(DestPath, L"\\");
|
||||
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
|
||||
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
|
||||
}
|
||||
StrCat(DestPath, DestDir);
|
||||
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
|
||||
StrCat(DestPath, L"\\");
|
||||
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
|
||||
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
|
||||
}
|
||||
StrCat(DestPath, Node->FileName);
|
||||
|
||||
} else {
|
||||
StrCpy(DestPath, DestDir);
|
||||
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
|
||||
StrCat(DestPath, L"\\");
|
||||
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
|
||||
((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;
|
||||
}
|
||||
StrCat(DestPath, Node->FileName);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Make sure the path exists
|
||||
//
|
||||
if (EFI_ERROR(VerifyIntermediateDirectories(DestPath))) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !EFI_ERROR(ShellIsDirectory(Node->FullName))
|
||||
&& !EFI_ERROR(ShellIsDirectory(DestPath))
|
||||
&& StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == NULL
|
||||
){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
if (StringNoCaseCompare(&Node->FullName, &DestPath) == 0) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((TempLocation = StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName))) == 0
|
||||
&& (DestPath[StrLen(Node->FullName)] == CHAR_NULL || DestPath[StrLen(Node->FullName)] == L'\\')
|
||||
) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
CleanPath(DestPath);
|
||||
|
||||
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
|
||||
|
||||
//
|
||||
// copy single file...
|
||||
//
|
||||
ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode);
|
||||
if (ShellStatus != SHELL_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS && Resp == NULL) {
|
||||
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
|
||||
}
|
||||
|
||||
SHELL_FREE_NON_NULL(DestPath);
|
||||
SHELL_FREE_NON_NULL(HiiOutput);
|
||||
SHELL_FREE_NON_NULL(HiiResultOk);
|
||||
if (Resp != NULL) {
|
||||
SHELL_FREE_NON_NULL(Response);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ProcessValidateAndCopyFiles(
|
||||
IN EFI_SHELL_FILE_INFO *FileList,
|
||||
IN CONST CHAR16 *DestDir,
|
||||
IN BOOLEAN SilentMode,
|
||||
IN BOOLEAN RecursiveMode
|
||||
)
|
||||
{
|
||||
SHELL_STATUS ShellStatus;
|
||||
EFI_SHELL_FILE_INFO *List;
|
||||
EFI_STATUS Status;
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
|
||||
List = NULL;
|
||||
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
|
||||
if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
ShellCloseFileMetaArg(&List);
|
||||
} else if (List != NULL) {
|
||||
ASSERT(List != NULL);
|
||||
ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
|
||||
ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
|
||||
FileInfo = NULL;
|
||||
FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
|
||||
ASSERT(FileInfo != NULL);
|
||||
if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
|
||||
ShellStatus = ValidateAndCopyFiles(FileList, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, SilentMode, RecursiveMode, NULL);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
}
|
||||
SHELL_FREE_NON_NULL(FileInfo);
|
||||
ShellCloseFileMetaArg(&List);
|
||||
} else {
|
||||
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-r", TypeFlag},
|
||||
{L"-q", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'cp' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunCp (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamCount;
|
||||
UINTN LoopCounter;
|
||||
EFI_SHELL_FILE_INFO *FileList;
|
||||
BOOLEAN SilentMode;
|
||||
BOOLEAN RecursiveMode;
|
||||
CONST CHAR16 *Cwd;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ParamCount = 0;
|
||||
FileList = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize SilentMode and RecursiveMode
|
||||
//
|
||||
if (gEfiShellProtocol->BatchIsActive()) {
|
||||
SilentMode = TRUE;
|
||||
} else {
|
||||
SilentMode = ShellCommandLineGetFlag(Package, L"-q");
|
||||
}
|
||||
RecursiveMode = ShellCommandLineGetFlag(Package, L"-r");
|
||||
|
||||
switch (ParamCount = ShellCommandLineGetCount(Package)) {
|
||||
case 0:
|
||||
case 1:
|
||||
//
|
||||
// we have insufficient parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
case 2:
|
||||
//
|
||||
// must have valid CWD for single parameter...
|
||||
//
|
||||
Cwd = ShellGetCurrentDir(NULL);
|
||||
if (Cwd == NULL){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
|
||||
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
ShellStatus = ProcessValidateAndCopyFiles(FileList, Cwd, SilentMode, RecursiveMode);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
//
|
||||
// Make a big list of all the files...
|
||||
//
|
||||
for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
break;
|
||||
}
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
|
||||
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
//
|
||||
// now copy them all...
|
||||
//
|
||||
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
|
||||
ShellStatus = ProcessValidateAndCopyFiles(FileList, ShellCommandCleanPath((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
|
||||
Status = ShellCloseFileMetaArg(&FileList);
|
||||
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
} // switch on parameter count
|
||||
|
||||
if (FileList != NULL) {
|
||||
ShellCloseFileMetaArg(&FileList);
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
return (SHELL_ABORTED);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
282
ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c
Normal file
282
ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c
Normal file
@@ -0,0 +1,282 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
// This function was from from the BdsLib implementation in
|
||||
// IntelFrameworkModulePkg\Library\GenericBdsLib\BdsConnect.c
|
||||
// function name: BdsLibConnectAllEfi
|
||||
/**
|
||||
This function will connect all current system handles recursively. The
|
||||
connection will finish until every handle's child handle created if it have.
|
||||
|
||||
@retval EFI_SUCCESS All handles and it's child handle have been
|
||||
connected
|
||||
@retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ConnectAllEfi (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN HandleCount;
|
||||
EFI_HANDLE *HandleBuffer;
|
||||
UINTN Index;
|
||||
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
AllHandles,
|
||||
NULL,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&HandleBuffer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < HandleCount; Index++) {
|
||||
Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
|
||||
}
|
||||
|
||||
if (HandleBuffer != NULL) {
|
||||
FreePool (HandleBuffer);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
function to load a .EFI driver into memory and possible connect the driver.
|
||||
|
||||
if FileName is NULL then ASSERT.
|
||||
|
||||
@param[in] FileName FileName of the driver to load
|
||||
@param[in] Connect Whether to connect or not
|
||||
|
||||
@retval EFI_SUCCESS the driver was loaded and if Connect was
|
||||
true then connect was attempted. Connection may
|
||||
have failed.
|
||||
@retval EFI_OUT_OF_RESOURCES there was insufficient memory
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
LoadDriver(
|
||||
IN CONST CHAR16 *FileName,
|
||||
IN CONST BOOLEAN Connect
|
||||
)
|
||||
{
|
||||
EFI_HANDLE LoadedDriverHandle;
|
||||
EFI_STATUS Status;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Node;
|
||||
EFI_DEVICE_PATH_PROTOCOL *FilePath;
|
||||
EFI_LOADED_IMAGE_PROTOCOL *LoadedDriverImage;
|
||||
|
||||
LoadedDriverImage = NULL;
|
||||
FilePath = NULL;
|
||||
Node = NULL;
|
||||
LoadedDriverHandle = NULL;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
ASSERT (FileName != NULL);
|
||||
|
||||
//
|
||||
// Fix local copies of the protocol pointers
|
||||
//
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// Convert to DEVICE_PATH
|
||||
//
|
||||
FilePath = gEfiShellProtocol->GetDevicePathFromFilePath(FileName);
|
||||
|
||||
if (FilePath == NULL) {
|
||||
ASSERT(FALSE);
|
||||
return (EFI_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
//
|
||||
// Use LoadImage to get it into memory
|
||||
//
|
||||
Status = gBS->LoadImage(
|
||||
FALSE,
|
||||
gImageHandle,
|
||||
FilePath,
|
||||
NULL,
|
||||
0,
|
||||
&LoadedDriverHandle);
|
||||
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_IMAGE), gShellLevel2HiiHandle, FileName, Status);
|
||||
} else {
|
||||
//
|
||||
// Make sure it is a driver image
|
||||
//
|
||||
Status = gBS->HandleProtocol (LoadedDriverHandle, &gEfiLoadedImageProtocolGuid, (VOID *) &LoadedDriverImage);
|
||||
|
||||
ASSERT (LoadedDriverImage != NULL);
|
||||
|
||||
if ( EFI_ERROR(Status)
|
||||
|| ( LoadedDriverImage->ImageCodeType != EfiBootServicesCode
|
||||
&& LoadedDriverImage->ImageCodeType != EfiRuntimeServicesCode)
|
||||
){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_DRIVER), gShellLevel2HiiHandle, FileName);
|
||||
|
||||
//
|
||||
// Exit and unload the non-driver image
|
||||
//
|
||||
gBS->Exit(LoadedDriverHandle, EFI_INVALID_PARAMETER, 0, NULL);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EFI_ERROR(Status)) {
|
||||
//
|
||||
// Start the image
|
||||
//
|
||||
Status = gBS->StartImage(LoadedDriverHandle, NULL, NULL);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_ERROR), gShellLevel2HiiHandle, FileName, Status);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_LOADED), gShellLevel2HiiHandle, FileName, LoadedDriverImage->ImageBase, Status);
|
||||
}
|
||||
}
|
||||
|
||||
if (!EFI_ERROR(Status) && Connect) {
|
||||
//
|
||||
// Connect it...
|
||||
//
|
||||
Status = ConnectAllEfi();
|
||||
}
|
||||
|
||||
//
|
||||
// clean up memory...
|
||||
//
|
||||
if (FilePath != NULL) {
|
||||
FreePool(FilePath);
|
||||
}
|
||||
|
||||
return (Status);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM LoadParamList[] = {
|
||||
{L"-nc", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'load' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunLoad (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamCount;
|
||||
EFI_SHELL_FILE_INFO *ListHead;
|
||||
EFI_SHELL_FILE_INFO *Node;
|
||||
|
||||
ListHead = NULL;
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (LoadParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// we didnt get a single file to load parameter
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
for ( ParamCount = 1
|
||||
; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
|
||||
; ParamCount++
|
||||
){
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount), EFI_FILE_MODE_READ, &ListHead);
|
||||
if (!EFI_ERROR(Status)) {
|
||||
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
|
||||
; !IsNull(&ListHead->Link, &Node->Link)
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
|
||||
){
|
||||
//
|
||||
// once we have an error preserve that value, but finish the loop.
|
||||
//
|
||||
if (EFI_ERROR(Status)) {
|
||||
LoadDriver(Node->FullName, ShellCommandLineGetFlag(Package, L"-nc"));
|
||||
} else {
|
||||
Status = LoadDriver(Node->FullName, ShellCommandLineGetFlag(Package, L"-nc"));
|
||||
}
|
||||
} // for loop for multi-open
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellCloseFileMetaArg(&ListHead);
|
||||
} else {
|
||||
Status = ShellCloseFileMetaArg(&ListHead);;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// no files found.
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, (CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
} // for loop for params
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
564
ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
Normal file
564
ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
Normal file
@@ -0,0 +1,564 @@
|
||||
/** @file
|
||||
Main file for ls shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
#include <Guid/FileSystemInfo.h>
|
||||
|
||||
/**
|
||||
print out the list of files and directories from the LS command
|
||||
|
||||
@param[in] Rec TRUE to automatically recurse into each found directory
|
||||
FALSE to only list the specified directory.
|
||||
@param[in] Attribs List of required Attribute for display.
|
||||
If 0 then all non-system and non-hidden files will be printed.
|
||||
@param[in] Sfo TRUE to use Standard Format Output, FALSE otherwise
|
||||
@param[in] Path String with starting path.
|
||||
@param[in] First TRUE for the original and FALSE for any recursion spawned instances.
|
||||
@param[in] Count The count of bits enabled in Attribs.
|
||||
@param[in] TimeZone The current time zone offset.
|
||||
|
||||
@retval SHELL_SUCCESS the printing was sucessful.
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
PrintLsOutput(
|
||||
IN CONST BOOLEAN Rec,
|
||||
IN CONST UINT64 Attribs,
|
||||
IN CONST BOOLEAN Sfo,
|
||||
IN CONST CHAR16 *Path,
|
||||
IN CONST BOOLEAN First,
|
||||
IN CONST UINTN Count,
|
||||
IN CONST INT16 TimeZone
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_SHELL_FILE_INFO *ListHead;
|
||||
EFI_SHELL_FILE_INFO *Node;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINT64 FileCount;
|
||||
UINT64 DirCount;
|
||||
UINT64 FileSize;
|
||||
CHAR16 *DirectoryName;
|
||||
UINTN LongestPath;
|
||||
EFI_FILE_SYSTEM_INFO *SysInfo;
|
||||
UINTN SysInfoSize;
|
||||
SHELL_FILE_HANDLE ShellFileHandle;
|
||||
CHAR16 *CorrectedPath;
|
||||
EFI_FILE_PROTOCOL *EfiFpHandle;
|
||||
|
||||
FileCount = 0;
|
||||
DirCount = 0;
|
||||
FileSize = 0;
|
||||
ListHead = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
LongestPath = 0;
|
||||
CorrectedPath = NULL;
|
||||
|
||||
CorrectedPath = StrnCatGrow(&CorrectedPath, NULL, Path, 0);
|
||||
ASSERT(CorrectedPath != NULL);
|
||||
ShellCommandCleanPath(CorrectedPath);
|
||||
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
if (ListHead == NULL || IsListEmpty(&ListHead->Link)) {
|
||||
//
|
||||
// On the first one only we expect to find something...
|
||||
// do we find the . and .. directories otherwise?
|
||||
//
|
||||
if (First) {
|
||||
return (SHELL_NOT_FOUND);
|
||||
}
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
if (Sfo && First) {
|
||||
//
|
||||
// Get the first valid handle (directories)
|
||||
//
|
||||
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
|
||||
; !IsNull(&ListHead->Link, &Node->Link) && Node->Handle == NULL
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
|
||||
);
|
||||
|
||||
if (Node->Handle == NULL) {
|
||||
DirectoryName = GetFullyQualifiedPath(((EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link))->FullName);
|
||||
|
||||
//
|
||||
// We need to open something up to get system information
|
||||
//
|
||||
Status = gEfiShellProtocol->OpenFileByName(
|
||||
DirectoryName,
|
||||
&ShellFileHandle,
|
||||
EFI_FILE_MODE_READ);
|
||||
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
FreePool(DirectoryName);
|
||||
|
||||
//
|
||||
// Get the Volume Info from ShellFileHandle
|
||||
//
|
||||
SysInfo = NULL;
|
||||
SysInfoSize = 0;
|
||||
EfiFpHandle = ConvertShellHandleToEfiFileProtocol(ShellFileHandle);
|
||||
Status = EfiFpHandle->GetInfo(
|
||||
EfiFpHandle,
|
||||
&gEfiFileSystemInfoGuid,
|
||||
&SysInfoSize,
|
||||
SysInfo);
|
||||
|
||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||
SysInfo = AllocateZeroPool(SysInfoSize);
|
||||
Status = EfiFpHandle->GetInfo(
|
||||
EfiFpHandle,
|
||||
&gEfiFileSystemInfoGuid,
|
||||
&SysInfoSize,
|
||||
SysInfo);
|
||||
}
|
||||
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
gEfiShellProtocol->CloseFile(ShellFileHandle);
|
||||
} else {
|
||||
//
|
||||
// Get the Volume Info from Node->Handle
|
||||
//
|
||||
SysInfo = NULL;
|
||||
SysInfoSize = 0;
|
||||
EfiFpHandle = ConvertShellHandleToEfiFileProtocol(Node->Handle);
|
||||
Status = EfiFpHandle->GetInfo(
|
||||
EfiFpHandle,
|
||||
&gEfiFileSystemInfoGuid,
|
||||
&SysInfoSize,
|
||||
SysInfo);
|
||||
|
||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||
SysInfo = AllocateZeroPool(SysInfoSize);
|
||||
Status = EfiFpHandle->GetInfo(
|
||||
EfiFpHandle,
|
||||
&gEfiFileSystemInfoGuid,
|
||||
&SysInfoSize,
|
||||
SysInfo);
|
||||
}
|
||||
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
}
|
||||
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_GEN_SFO_HEADER),
|
||||
gShellLevel2HiiHandle,
|
||||
L"ls");
|
||||
//
|
||||
// print VolumeInfo table
|
||||
//
|
||||
ASSERT(SysInfo != NULL);
|
||||
ShellPrintHiiEx (
|
||||
0,
|
||||
gST->ConOut->Mode->CursorRow,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_SFO_VOLINFO),
|
||||
gShellLevel2HiiHandle,
|
||||
SysInfo->VolumeLabel,
|
||||
SysInfo->VolumeSize,
|
||||
SysInfo->ReadOnly?L"TRUE":L"FALSE",
|
||||
SysInfo->FreeSpace,
|
||||
SysInfo->BlockSize
|
||||
);
|
||||
if (SysInfo != NULL) {
|
||||
FreePool(SysInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Sfo) {
|
||||
//
|
||||
// get directory name from path...
|
||||
//
|
||||
DirectoryName = GetFullyQualifiedPath(CorrectedPath);
|
||||
|
||||
//
|
||||
// print header
|
||||
//
|
||||
ShellPrintHiiEx (
|
||||
0,
|
||||
gST->ConOut->Mode->CursorRow,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_HEADER_LINE1),
|
||||
gShellLevel2HiiHandle,
|
||||
DirectoryName
|
||||
);
|
||||
FreePool(DirectoryName);
|
||||
}
|
||||
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
|
||||
; !IsNull(&ListHead->Link, &Node->Link)
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
|
||||
){
|
||||
ASSERT(Node != NULL);
|
||||
if (LongestPath < StrSize(Node->FullName)) {
|
||||
LongestPath = StrSize(Node->FullName);
|
||||
}
|
||||
ASSERT(Node->Info != NULL);
|
||||
ASSERT((Node->Info->Attribute & EFI_FILE_VALID_ATTR) == Node->Info->Attribute);
|
||||
if (Attribs == 0) {
|
||||
//
|
||||
// NOT system & NOT hidden
|
||||
//
|
||||
if ( (Node->Info->Attribute & EFI_FILE_SYSTEM)
|
||||
|| (Node->Info->Attribute & EFI_FILE_HIDDEN)
|
||||
){
|
||||
continue;
|
||||
}
|
||||
} else if (Attribs != EFI_FILE_VALID_ATTR) {
|
||||
if (Count == 1) {
|
||||
//
|
||||
// the bit must match
|
||||
//
|
||||
if ( (Node->Info->Attribute & Attribs) != Attribs) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// exact match on all bits
|
||||
//
|
||||
if ( Node->Info->Attribute != Attribs) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Sfo) {
|
||||
//
|
||||
// Print the FileInfo Table
|
||||
//
|
||||
ShellPrintHiiEx (
|
||||
0,
|
||||
gST->ConOut->Mode->CursorRow,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_SFO_FILEINFO),
|
||||
gShellLevel2HiiHandle,
|
||||
Node->FullName,
|
||||
Node->Info->FileSize,
|
||||
Node->Info->PhysicalSize,
|
||||
(Node->Info->Attribute & EFI_FILE_ARCHIVE) != 0?L"a":L"",
|
||||
(Node->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"d":L"",
|
||||
(Node->Info->Attribute & EFI_FILE_HIDDEN) != 0?L"h":L"",
|
||||
(Node->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L"r":L"",
|
||||
(Node->Info->Attribute & EFI_FILE_SYSTEM) != 0?L"s":L"",
|
||||
Node->Info->CreateTime.Hour,
|
||||
Node->Info->CreateTime.Minute,
|
||||
Node->Info->CreateTime.Second,
|
||||
Node->Info->CreateTime.Day,
|
||||
Node->Info->CreateTime.Month,
|
||||
Node->Info->CreateTime.Year,
|
||||
Node->Info->LastAccessTime.Hour,
|
||||
Node->Info->LastAccessTime.Minute,
|
||||
Node->Info->LastAccessTime.Second,
|
||||
Node->Info->LastAccessTime.Day,
|
||||
Node->Info->LastAccessTime.Month,
|
||||
Node->Info->LastAccessTime.Year,
|
||||
Node->Info->ModificationTime.Hour,
|
||||
Node->Info->ModificationTime.Minute,
|
||||
Node->Info->ModificationTime.Second,
|
||||
Node->Info->ModificationTime.Day,
|
||||
Node->Info->ModificationTime.Month,
|
||||
Node->Info->ModificationTime.Year
|
||||
);
|
||||
} else {
|
||||
//
|
||||
// print this one out...
|
||||
// first print the universal start, next print the type specific name format, last print the CRLF
|
||||
//
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_LINE_START_ALL),
|
||||
gShellLevel2HiiHandle,
|
||||
&Node->Info->ModificationTime,
|
||||
(Node->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"<DIR>":L"",
|
||||
(Node->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L'r':L' ',
|
||||
Node->Info->FileSize
|
||||
);
|
||||
if (Node->Info->Attribute & EFI_FILE_DIRECTORY) {
|
||||
DirCount++;
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_LINE_END_DIR),
|
||||
gShellLevel2HiiHandle,
|
||||
Node->FileName
|
||||
);
|
||||
} else {
|
||||
FileCount++;
|
||||
FileSize += Node->Info->FileSize;
|
||||
if ( (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".nsh", (CHAR16*)&(Node->FileName[StrLen (Node->FileName) - 4])) == 0)
|
||||
|| (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".efi", (CHAR16*)&(Node->FileName[StrLen (Node->FileName) - 4])) == 0)
|
||||
){
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_LINE_END_EXE),
|
||||
gShellLevel2HiiHandle,
|
||||
Node->FileName
|
||||
);
|
||||
} else {
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_LINE_END_FILE),
|
||||
gShellLevel2HiiHandle,
|
||||
Node->FileName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Sfo) {
|
||||
//
|
||||
// print footer
|
||||
//
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_LS_FOOTER_LINE),
|
||||
gShellLevel2HiiHandle,
|
||||
FileCount,
|
||||
FileSize,
|
||||
DirCount
|
||||
);
|
||||
}
|
||||
|
||||
if (Rec){
|
||||
DirectoryName = AllocatePool(LongestPath + 2*sizeof(CHAR16));
|
||||
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
|
||||
; !IsNull(&ListHead->Link, &Node->Link)
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
|
||||
){
|
||||
//
|
||||
// recurse on any directory except the traversing ones...
|
||||
//
|
||||
if (((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
|
||||
&& StrCmp(Node->FileName, L".") != 0
|
||||
&& StrCmp(Node->FileName, L"..") != 0
|
||||
){
|
||||
StrCpy(DirectoryName, Node->FullName);
|
||||
StrCat(DirectoryName, L"\\*");
|
||||
PrintLsOutput(
|
||||
Rec,
|
||||
Attribs,
|
||||
Sfo,
|
||||
DirectoryName,
|
||||
FALSE,
|
||||
Count,
|
||||
TimeZone);
|
||||
}
|
||||
}
|
||||
FreePool(DirectoryName);
|
||||
}
|
||||
|
||||
FreePool(CorrectedPath);
|
||||
ShellCloseFileMetaArg(&ListHead);
|
||||
FreePool(ListHead);
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM LsParamList[] = {
|
||||
{L"-r", TypeFlag},
|
||||
{L"-a", TypeStart},
|
||||
{L"-sfo", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'ls' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunLs (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
CONST CHAR16 *Attribs;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINT64 RequiredAttributes;
|
||||
CONST CHAR16 *PathName;
|
||||
CONST CHAR16 *CurDir;
|
||||
UINTN Count;
|
||||
CHAR16 *FullPath;
|
||||
UINTN Size;
|
||||
EFI_TIME theTime;
|
||||
BOOLEAN SfoMode;
|
||||
|
||||
Size = 0;
|
||||
FullPath = NULL;
|
||||
ProblemParam = NULL;
|
||||
Attribs = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
RequiredAttributes = 0;
|
||||
PathName = NULL;
|
||||
CurDir = NULL;
|
||||
Count = 0;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// Fix local copies of the protocol pointers
|
||||
//
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (LsParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if (ShellCommandLineGetCount(Package) > 2) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// check for -a
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-a")) {
|
||||
for ( Attribs = ShellCommandLineGetValue(Package, L"-a")
|
||||
; Attribs != NULL && *Attribs != CHAR_NULL && ShellStatus == SHELL_SUCCESS
|
||||
; Attribs++
|
||||
){
|
||||
switch (*Attribs) {
|
||||
case L'a':
|
||||
case L'A':
|
||||
RequiredAttributes |= EFI_FILE_ARCHIVE;
|
||||
Count++;
|
||||
continue;
|
||||
case L's':
|
||||
case L'S':
|
||||
RequiredAttributes |= EFI_FILE_SYSTEM;
|
||||
Count++;
|
||||
continue;
|
||||
case L'h':
|
||||
case L'H':
|
||||
RequiredAttributes |= EFI_FILE_HIDDEN;
|
||||
Count++;
|
||||
continue;
|
||||
case L'r':
|
||||
case L'R':
|
||||
RequiredAttributes |= EFI_FILE_READ_ONLY;
|
||||
Count++;
|
||||
continue;
|
||||
case L'd':
|
||||
case L'D':
|
||||
RequiredAttributes |= EFI_FILE_DIRECTORY;
|
||||
Count++;
|
||||
continue;
|
||||
default:
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ATTRIBUTE), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-a"));
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
} // switch
|
||||
} // for loop
|
||||
//
|
||||
// if nothing is specified all are specified
|
||||
//
|
||||
if (RequiredAttributes == 0) {
|
||||
RequiredAttributes = EFI_FILE_VALID_ATTR;
|
||||
}
|
||||
} // if -a present
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
PathName = ShellCommandLineGetRawValue(Package, 1);
|
||||
if (PathName == NULL) {
|
||||
CurDir = gEfiShellProtocol->GetCurDir(NULL);
|
||||
if (CurDir == NULL) {
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
|
||||
}
|
||||
}
|
||||
if (PathName != NULL) {
|
||||
ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL));
|
||||
StrnCatGrow(&FullPath, &Size, PathName, 0);
|
||||
if (ShellIsDirectory(PathName) == EFI_SUCCESS) {
|
||||
StrnCatGrow(&FullPath, &Size, L"\\*", 0);
|
||||
}
|
||||
} else {
|
||||
ASSERT(FullPath == NULL);
|
||||
StrnCatGrow(&FullPath, NULL, L"*", 0);
|
||||
}
|
||||
Status = gRT->GetTime(&theTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
ShellStatus = PrintLsOutput(
|
||||
ShellCommandLineGetFlag(Package, L"-r"),
|
||||
RequiredAttributes,
|
||||
SfoMode,
|
||||
FullPath,
|
||||
TRUE,
|
||||
Count,
|
||||
(INT16)(theTime.TimeZone==2047?0:theTime.TimeZone)
|
||||
);
|
||||
if (ShellStatus == SHELL_NOT_FOUND) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_FILES), gShellLevel2HiiHandle);
|
||||
} else if (ShellStatus == SHELL_INVALID_PARAMETER) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
|
||||
} else if (ShellStatus != SHELL_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FullPath != NULL) {
|
||||
FreePool(FullPath);
|
||||
}
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
1116
ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
Normal file
1116
ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
Normal file
File diff suppressed because it is too large
Load Diff
128
ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c
Normal file
128
ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
/**
|
||||
Function for 'mkdir' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunMkDir (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
CONST CHAR16 *NewDirName;
|
||||
UINTN DirCreateCount;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_FILE_HANDLE FileHandle;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
//
|
||||
// create a set of directories
|
||||
//
|
||||
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// we didnt get a single parameter
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
for ( DirCreateCount = 1
|
||||
;
|
||||
; DirCreateCount++
|
||||
){
|
||||
//
|
||||
// loop through each directory specified
|
||||
//
|
||||
|
||||
NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount);
|
||||
if (NewDirName == NULL) {
|
||||
break;
|
||||
}
|
||||
//
|
||||
// check if that already exists... if yes fail
|
||||
//
|
||||
FileHandle = NULL;
|
||||
Status = ShellOpenFileByName(NewDirName,
|
||||
&FileHandle,
|
||||
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,
|
||||
EFI_FILE_DIRECTORY
|
||||
);
|
||||
if (!EFI_ERROR(Status)) {
|
||||
ShellCloseFile(&FileHandle);
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
} else {
|
||||
ASSERT(FileHandle == NULL);
|
||||
//
|
||||
// create the directory named NewDirName
|
||||
//
|
||||
Status = ShellCreateDirectory(NewDirName, &FileHandle);
|
||||
if (FileHandle != NULL) {
|
||||
gEfiShellProtocol->CloseFile(FileHandle);
|
||||
}
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
478
ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
Normal file
478
ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
Normal file
@@ -0,0 +1,478 @@
|
||||
/** @file
|
||||
Main file for mv shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
/**
|
||||
Function to validate that moving a specific file (FileName) to a specific
|
||||
location (DestPath) is valid.
|
||||
|
||||
This function will verify that the destination is not a subdirectory of
|
||||
FullName, that the Current working Directory is not being moved, and that
|
||||
the directory is not read only.
|
||||
|
||||
if the move is invalid this function will report the error to StdOut.
|
||||
|
||||
@param FullName [in] The name of the file to move.
|
||||
@param Cwd [in] The current working directory
|
||||
@param DestPath [in] The target location to move to
|
||||
@param Attribute[in] The Attribute of the file
|
||||
|
||||
@retval TRUE The move is valid
|
||||
@retval FALSE The move is not
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsValidMove(
|
||||
IN CONST CHAR16 *FullName,
|
||||
IN CONST CHAR16 *Cwd,
|
||||
IN CONST CHAR16 *DestPath,
|
||||
IN CONST UINT64 Attribute
|
||||
)
|
||||
{
|
||||
CHAR16 *Test;
|
||||
CHAR16 *Test1;
|
||||
CHAR16 *TestWalker;
|
||||
UINTN Result;
|
||||
UINTN TempLen;
|
||||
if (Cwd != NULL && StrCmp(FullName, Cwd) == 0) {
|
||||
//
|
||||
// Invalid move
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);
|
||||
return (FALSE);
|
||||
}
|
||||
Test = NULL;
|
||||
Test = StrnCatGrow(&Test, NULL, DestPath, 0);
|
||||
TestWalker = Test;
|
||||
ASSERT(TestWalker != NULL);
|
||||
while(*TestWalker == L'\\') {
|
||||
TestWalker++;
|
||||
}
|
||||
while(TestWalker != NULL && TestWalker[StrLen(TestWalker)-1] == L'\\') {
|
||||
TestWalker[StrLen(TestWalker)-1] = CHAR_NULL;
|
||||
}
|
||||
ASSERT(TestWalker != NULL);
|
||||
ASSERT(FullName != NULL);
|
||||
if (StrStr(FullName, TestWalker) != 0) {
|
||||
TempLen = StrLen(FullName);
|
||||
if (StrStr(FullName, TestWalker) != FullName // not the first items... (could below it)
|
||||
&& TempLen <= (StrLen(TestWalker) + 1)
|
||||
&& StrStr(FullName+StrLen(TestWalker) + 1, L"\\") == NULL) {
|
||||
//
|
||||
// Invalid move
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
|
||||
FreePool(Test);
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
FreePool(Test);
|
||||
if (StrStr(DestPath, FullName) != 0 && StrStr(DestPath, FullName) != DestPath) {
|
||||
//
|
||||
// Invalid move
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
|
||||
return (FALSE);
|
||||
}
|
||||
if ((Attribute & EFI_FILE_READ_ONLY) != 0) {
|
||||
//
|
||||
// invalid to move read only
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle);
|
||||
return (FALSE);
|
||||
}
|
||||
Test = StrStr(FullName, L":");
|
||||
Test1 = StrStr(DestPath, L":");
|
||||
if (Test1 != NULL && Test != NULL) {
|
||||
*Test = CHAR_NULL;
|
||||
*Test1 = CHAR_NULL;
|
||||
Result = StringNoCaseCompare(&FullName, &DestPath);
|
||||
*Test = L':';
|
||||
*Test1 = L':';
|
||||
if (Result != 0) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_FS), gShellLevel2HiiHandle);
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
Function to take a destination path that might contain wildcards and verify
|
||||
that there is only a single possible target (IE we cant have wildcards that
|
||||
have 2 possible destination).
|
||||
|
||||
if the result is sucessful the caller must free *DestPathPointer.
|
||||
|
||||
@param[in] DestDir The original path to the destination
|
||||
@param[in,out] DestPathPointer a pointer to the callee allocated final path.
|
||||
|
||||
@retval EFI_INVALID_PARAMETR the DestDir could not be resolved to a location
|
||||
@retval EFI_INVALID_PARAMETR the DestDir could be resolved to more than 1 location
|
||||
@retval EFI_SUCCESS the operation was sucessful
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
GetDestinationLocation(
|
||||
IN CONST CHAR16 *DestDir,
|
||||
IN OUT CHAR16 **DestPathPointer,
|
||||
IN CONST CHAR16 *Cwd
|
||||
)
|
||||
{
|
||||
EFI_SHELL_FILE_INFO *DestList;
|
||||
EFI_SHELL_FILE_INFO *Node;
|
||||
EFI_STATUS Status;
|
||||
CHAR16 *DestPath;
|
||||
CHAR16 *TempLocation;
|
||||
UINTN NewSize;
|
||||
|
||||
DestList = NULL;
|
||||
DestPath = NULL;
|
||||
//
|
||||
// get the destination path
|
||||
//
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
|
||||
if (DestList == NULL || IsListEmpty(&DestList->Link)) {
|
||||
//
|
||||
// Not existing... must be renaming
|
||||
//
|
||||
if ((TempLocation = StrStr(DestDir, L":")) == NULL) {
|
||||
NewSize = StrSize(Cwd);
|
||||
NewSize += StrSize(DestDir);
|
||||
DestPath = AllocateZeroPool(NewSize);
|
||||
StrCpy(DestPath, Cwd);
|
||||
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
|
||||
StrCat(DestPath, L"\\");
|
||||
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
|
||||
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
|
||||
}
|
||||
StrCat(DestPath, DestDir);
|
||||
} else {
|
||||
ASSERT(DestPath == NULL);
|
||||
DestPath = StrnCatGrow(&DestPath, NULL, DestDir, 0);
|
||||
}
|
||||
} else {
|
||||
Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);
|
||||
//
|
||||
// Make sure there is only 1 node in the list.
|
||||
//
|
||||
if (!IsNodeAtEnd(&DestList->Link, &Node->Link)) {
|
||||
ShellCloseFileMetaArg(&DestList);
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS) {
|
||||
DestPath = AllocateZeroPool(StrSize(Node->FullName)+sizeof(CHAR16));
|
||||
StrCpy(DestPath, Node->FullName);
|
||||
StrCat(DestPath, L"\\");
|
||||
} else {
|
||||
//
|
||||
// cant move onto another file.
|
||||
//
|
||||
ShellCloseFileMetaArg(&DestList);
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, DestDir);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
}
|
||||
|
||||
*DestPathPointer = DestPath;
|
||||
ShellCloseFileMetaArg(&DestList);
|
||||
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
function to take a list of files to move and a destination location and do
|
||||
the verification and moving of those files to that location. This function
|
||||
will report any errors to the user and continue to move the rest of the files.
|
||||
|
||||
@param[in] FileList A LIST_ENTRY* based list of files to move
|
||||
@param[in] DestDir the destination location
|
||||
|
||||
@retval SHELL_SUCCESS the files were all moved.
|
||||
@retval SHELL_INVALID_PARAMETER a parameter was invalid
|
||||
@retval SHELL_SECURITY_VIOLATION a security violation ocurred
|
||||
@retval SHELL_WRITE_PROTECTED the destination was write protected
|
||||
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ValidateAndMoveFiles(
|
||||
IN CONST EFI_SHELL_FILE_INFO *FileList,
|
||||
IN CONST CHAR16 *DestDir
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
CHAR16 *HiiOutput;
|
||||
CHAR16 *HiiResultOk;
|
||||
CHAR16 *DestPath;
|
||||
CONST CHAR16 *Cwd;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CONST EFI_SHELL_FILE_INFO *Node;
|
||||
EFI_FILE_INFO *NewFileInfo;
|
||||
CHAR16 *TempLocation;
|
||||
UINTN NewSize;
|
||||
|
||||
ASSERT(FileList != NULL);
|
||||
ASSERT(DestDir != NULL);
|
||||
|
||||
DestPath = NULL;
|
||||
Cwd = ShellGetCurrentDir(NULL);
|
||||
|
||||
//
|
||||
// Get and validate the destination location
|
||||
//
|
||||
ShellStatus = GetDestinationLocation(DestDir, &DestPath, Cwd);
|
||||
if (ShellStatus != SHELL_SUCCESS) {
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);
|
||||
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
|
||||
ASSERT (DestPath != NULL);
|
||||
ASSERT (HiiResultOk != NULL);
|
||||
ASSERT (HiiOutput != NULL);
|
||||
// ASSERT (Cwd != NULL);
|
||||
|
||||
//
|
||||
// Go through the list of files and directories to move...
|
||||
//
|
||||
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
|
||||
; !IsNull(&FileList->Link, &Node->Link)
|
||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
|
||||
){
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
break;
|
||||
}
|
||||
ASSERT(Node->FileName != NULL);
|
||||
ASSERT(Node->FullName != NULL);
|
||||
|
||||
//
|
||||
// skip the directory traversing stuff...
|
||||
//
|
||||
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate that the move is valid
|
||||
//
|
||||
if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute)) {
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Chop off map info from "DestPath"
|
||||
//
|
||||
if ((TempLocation = StrStr(DestPath, L":")) != NULL) {
|
||||
CopyMem(DestPath, TempLocation+1, StrSize(TempLocation+1));
|
||||
}
|
||||
|
||||
//
|
||||
// construct the new file info block
|
||||
//
|
||||
NewSize = StrSize(DestPath);
|
||||
NewSize += StrSize(Node->FileName) + sizeof(EFI_FILE_INFO) + sizeof(CHAR16);
|
||||
NewFileInfo = AllocateZeroPool(NewSize);
|
||||
ASSERT(NewFileInfo != NULL);
|
||||
CopyMem(NewFileInfo, Node->Info, sizeof(EFI_FILE_INFO));
|
||||
if (DestPath[0] != L'\\') {
|
||||
StrCpy(NewFileInfo->FileName, L"\\");
|
||||
StrCat(NewFileInfo->FileName, DestPath);
|
||||
} else {
|
||||
StrCpy(NewFileInfo->FileName, DestPath);
|
||||
}
|
||||
if (NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] == L'\\') {
|
||||
if (Node->FileName[0] == L'\\') {
|
||||
//
|
||||
// Don't allow for double slashes. Eliminate one of them.
|
||||
//
|
||||
NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] = CHAR_NULL;
|
||||
}
|
||||
StrCat(NewFileInfo->FileName, Node->FileName);
|
||||
}
|
||||
NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFileInfo->FileName);
|
||||
|
||||
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);
|
||||
|
||||
//
|
||||
// Perform the move operation
|
||||
//
|
||||
Status = ShellSetFileInfo(Node->Handle, NewFileInfo);
|
||||
|
||||
//
|
||||
// Free the info object we used...
|
||||
//
|
||||
ASSERT (NewFileInfo != NULL);
|
||||
FreePool(NewFileInfo);
|
||||
|
||||
//
|
||||
// Check our result
|
||||
//
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
|
||||
//
|
||||
// move failed
|
||||
//
|
||||
switch(Status){
|
||||
default:
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
case EFI_SECURITY_VIOLATION:
|
||||
ShellStatus = SHELL_SECURITY_VIOLATION;
|
||||
case EFI_WRITE_PROTECTED:
|
||||
ShellStatus = SHELL_WRITE_PROTECTED;
|
||||
case EFI_OUT_OF_RESOURCES:
|
||||
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||
case EFI_DEVICE_ERROR:
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
case EFI_ACCESS_DENIED:
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
} // switch
|
||||
} else {
|
||||
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
|
||||
}
|
||||
} // for loop
|
||||
|
||||
FreePool(DestPath);
|
||||
FreePool(HiiOutput);
|
||||
FreePool(HiiResultOk);
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunMv (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamCount;
|
||||
UINTN LoopCounter;
|
||||
EFI_SHELL_FILE_INFO *FileList;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ParamCount = 0;
|
||||
FileList = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
switch (ParamCount = ShellCommandLineGetCount(Package)) {
|
||||
case 0:
|
||||
case 1:
|
||||
//
|
||||
// we have insufficient parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
case 2:
|
||||
//
|
||||
// must have valid CWD for single parameter...
|
||||
//
|
||||
if (ShellGetCurrentDir(NULL) == NULL){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
|
||||
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
//
|
||||
// ValidateAndMoveFiles will report errors to the screen itself
|
||||
//
|
||||
ShellStatus = ValidateAndMoveFiles(FileList, ShellGetCurrentDir(NULL));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
///@todo make sure this works with error half way through and continues...
|
||||
for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
break;
|
||||
}
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
|
||||
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
//
|
||||
// ValidateAndMoveFiles will report errors to the screen itself
|
||||
// Only change ShellStatus if it's sucessful
|
||||
//
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
ShellStatus = ValidateAndMoveFiles(FileList, ShellCommandLineGetRawValue(Package, ParamCount));
|
||||
} else {
|
||||
ValidateAndMoveFiles(FileList, ShellCommandLineGetRawValue(Package, ParamCount));
|
||||
}
|
||||
}
|
||||
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
|
||||
Status = ShellCloseFileMetaArg(&FileList);
|
||||
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} // switch on parameter count
|
||||
|
||||
if (FileList != NULL) {
|
||||
ShellCloseFileMetaArg(&FileList);
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
return (SHELL_ABORTED);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
190
ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c
Normal file
190
ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c
Normal file
@@ -0,0 +1,190 @@
|
||||
/** @file
|
||||
Main file for Parse shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
PerformParsing(
|
||||
IN CONST CHAR16 *FileName,
|
||||
IN CONST CHAR16 *TableName,
|
||||
IN CONST UINTN ColumnIndex,
|
||||
IN CONST UINTN TableNameInstance,
|
||||
IN CONST UINTN ShellCommandInstance
|
||||
)
|
||||
{
|
||||
SHELL_FILE_HANDLE FileHandle;
|
||||
EFI_STATUS Status;
|
||||
BOOLEAN Ascii;
|
||||
UINTN LoopVariable;
|
||||
UINTN ColumnLoop;
|
||||
CHAR16 *TempLine;
|
||||
CHAR16 *ColumnPointer;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CHAR16 *TempSpot;
|
||||
|
||||
ASSERT(FileName != NULL);
|
||||
ASSERT(TableName != NULL);
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, FileName);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
for (LoopVariable = 0 ; LoopVariable < ShellCommandInstance && !ShellFileHandleEof(FileHandle);) {
|
||||
TempLine = ShellFileHandleReturnLine(FileHandle, &Ascii);
|
||||
if (TempLine == NULL) {
|
||||
break;
|
||||
}
|
||||
if (StrStr(TempLine, L"ShellCommand, \"") == TempLine) {
|
||||
LoopVariable++;
|
||||
}
|
||||
SHELL_FREE_NON_NULL(TempLine);
|
||||
}
|
||||
if (LoopVariable == ShellCommandInstance) {
|
||||
LoopVariable = 0;
|
||||
while(1) {
|
||||
TempLine = ShellFileHandleReturnLine(FileHandle, &Ascii);
|
||||
if ( TempLine == NULL
|
||||
|| *TempLine == CHAR_NULL
|
||||
|| StrStr(TempLine, L"ShellCommand, \"") == TempLine
|
||||
){
|
||||
SHELL_FREE_NON_NULL(TempLine);
|
||||
break;
|
||||
}
|
||||
if (StrStr(TempLine, TableName) == TempLine) {
|
||||
LoopVariable++;
|
||||
}
|
||||
if ( LoopVariable == TableNameInstance
|
||||
|| (TableNameInstance == (UINTN)-1 && StrStr(TempLine, TableName) == TempLine)
|
||||
){
|
||||
for (ColumnLoop = 1, ColumnPointer = TempLine; ColumnLoop < ColumnIndex && ColumnPointer != NULL && *ColumnPointer != CHAR_NULL; ColumnLoop++) {
|
||||
ColumnPointer = StrStr(ColumnPointer, L",");
|
||||
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL){
|
||||
ColumnPointer++;
|
||||
}
|
||||
}
|
||||
if (ColumnLoop == ColumnIndex) {
|
||||
ASSERT(ColumnPointer != NULL);
|
||||
TempSpot = StrStr(ColumnPointer, L",");
|
||||
if (TempSpot != NULL) {
|
||||
*TempSpot = CHAR_NULL;
|
||||
}
|
||||
while (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L' '){
|
||||
ColumnPointer++;
|
||||
}
|
||||
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L'\"'){
|
||||
ColumnPointer++;
|
||||
}
|
||||
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen(ColumnPointer)-1] == L'\"'){
|
||||
ColumnPointer[StrLen(ColumnPointer)-1] = CHAR_NULL;
|
||||
}
|
||||
|
||||
ShellPrintEx(-1, -1, L"%s\r\n", ColumnPointer);
|
||||
}
|
||||
}
|
||||
SHELL_FREE_NON_NULL(TempLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-i", TypeValue},
|
||||
{L"-s", TypeValue},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'parse' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunParse (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
CONST CHAR16 *FileName;
|
||||
CONST CHAR16 *TableName;
|
||||
CONST CHAR16 *ColumnString;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ShellCommandInstance;
|
||||
UINTN TableNameInstance;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ProblemParam = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
if (ShellCommandLineGetCount(Package) < 4) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetCount(Package) > 4) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
FileName = ShellCommandLineGetRawValue(Package, 1);
|
||||
TableName = ShellCommandLineGetRawValue(Package, 2);
|
||||
ColumnString = ShellCommandLineGetRawValue(Package, 3);
|
||||
|
||||
if (ShellCommandLineGetValue(Package, L"-i") == NULL) {
|
||||
TableNameInstance = (UINTN)-1;
|
||||
} else {
|
||||
TableNameInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-i"));
|
||||
}
|
||||
if (ShellCommandLineGetValue(Package, L"-s") == NULL) {
|
||||
ShellCommandInstance = 1;
|
||||
} else {
|
||||
ShellCommandInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-s"));
|
||||
}
|
||||
|
||||
ShellStatus = PerformParsing(FileName, TableName, ShellStrToUintn(ColumnString), TableNameInstance, ShellCommandInstance);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
131
ShellPkg/Library/UefiShellLevel2CommandsLib/Reset.c
Normal file
131
ShellPkg/Library/UefiShellLevel2CommandsLib/Reset.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ResetParamList[] = {
|
||||
{L"-w", TypeValue},
|
||||
{L"-s", TypeValue},
|
||||
{L"-c", TypeValue},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'reset' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunReset (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CONST CHAR16 *String;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ProblemParam = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ResetParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// check for cold reset flag, then shutdown reset flag, then warm (default) reset flag
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-c")) {
|
||||
if (ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-w")) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
String = ShellCommandLineGetValue(Package, L"-c");
|
||||
if (String != NULL) {
|
||||
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
|
||||
} else {
|
||||
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
|
||||
}
|
||||
}
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-s")) {
|
||||
if (ShellCommandLineGetFlag(Package, L"-w")) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
String = ShellCommandLineGetValue(Package, L"-s");
|
||||
DEBUG_CODE(ShellPrintEx(-1,-1,L"Reset with %s (%d bytes)", String, String!=NULL?StrSize(String):0););
|
||||
if (String != NULL) {
|
||||
gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, StrSize(String), (VOID*)String);
|
||||
} else {
|
||||
gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// this is default so dont worry about flag...
|
||||
//
|
||||
String = ShellCommandLineGetValue(Package, L"-w");
|
||||
if (String != NULL) {
|
||||
gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
|
||||
} else {
|
||||
gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// we should never get here... so the free and return are for formality more than use
|
||||
// as the ResetSystem function should not return...
|
||||
//
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
//
|
||||
// return the status
|
||||
//
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
296
ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c
Normal file
296
ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c
Normal file
@@ -0,0 +1,296 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-q", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsDirectoryEmpty (
|
||||
IN EFI_HANDLE FileHandle
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
BOOLEAN NoFile;
|
||||
BOOLEAN RetVal;
|
||||
|
||||
RetVal = TRUE;
|
||||
NoFile = FALSE;
|
||||
|
||||
for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo)
|
||||
; !NoFile
|
||||
; Status = FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)
|
||||
){
|
||||
if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName
|
||||
&&StrStr(FileInfo->FileName, L"..") != FileInfo->FileName) {
|
||||
RetVal = FALSE;
|
||||
}
|
||||
}
|
||||
return (RetVal);
|
||||
}
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
CascadeDelete(
|
||||
IN EFI_SHELL_FILE_INFO *Node,
|
||||
IN CONST BOOLEAN Quiet
|
||||
)
|
||||
{
|
||||
SHELL_STATUS ShellStatus;
|
||||
EFI_SHELL_FILE_INFO *List;
|
||||
EFI_SHELL_FILE_INFO *Node2;
|
||||
EFI_STATUS Status;
|
||||
SHELL_PROMPT_RESPONSE *Resp;
|
||||
|
||||
Resp = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
List = NULL;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
if ((Node->Info->Attribute & EFI_FILE_READ_ONLY) == EFI_FILE_READ_ONLY) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DETELE_RO), gShellLevel2HiiHandle, Node->FullName);
|
||||
return (SHELL_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
if ((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
|
||||
if (!IsDirectoryEmpty(Node->Handle)) {
|
||||
if (!Quiet) {
|
||||
Status = ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_RM_LOG_DELETE_CONF), gShellLevel2HiiHandle, Node->FullName);
|
||||
Status = ShellPromptForResponse(ShellPromptResponseTypeYesNo, NULL, (VOID**)&Resp);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
ASSERT(Resp != NULL);
|
||||
if (EFI_ERROR(Status) || *Resp != ShellPromptResponseYes) {
|
||||
SHELL_FREE_NON_NULL(Resp);
|
||||
return (SHELL_ABORTED);
|
||||
}
|
||||
SHELL_FREE_NON_NULL(Resp);
|
||||
}
|
||||
//
|
||||
// empty out the directory
|
||||
//
|
||||
Status = gEfiShellProtocol->FindFilesInDir(Node->Handle, &List);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (List!=NULL) {
|
||||
gEfiShellProtocol->FreeFileList(&List);
|
||||
}
|
||||
return (SHELL_DEVICE_ERROR);
|
||||
}
|
||||
for (Node2 = (EFI_SHELL_FILE_INFO *)GetFirstNode(&List->Link)
|
||||
; !IsNull(&List->Link, &Node2->Link)
|
||||
; Node2 = (EFI_SHELL_FILE_INFO *)GetNextNode(&List->Link, &Node2->Link)
|
||||
){
|
||||
//
|
||||
// skip the directory traversing stuff...
|
||||
//
|
||||
if (StrCmp(Node2->FileName, L".") == 0 || StrCmp(Node2->FileName, L"..") == 0) {
|
||||
continue;
|
||||
}
|
||||
Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
|
||||
ShellStatus = CascadeDelete(Node2, Quiet);
|
||||
if (ShellStatus != SHELL_SUCCESS) {
|
||||
if (List!=NULL) {
|
||||
gEfiShellProtocol->FreeFileList(&List);
|
||||
}
|
||||
return (ShellStatus);
|
||||
}
|
||||
}
|
||||
if (List!=NULL) {
|
||||
gEfiShellProtocol->FreeFileList(&List);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0)) {
|
||||
//
|
||||
// now delete the current node...
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName);
|
||||
Status = gEfiShellProtocol->DeleteFile(Node->Handle);
|
||||
Node->Handle = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// We cant allow for the warning here!
|
||||
//
|
||||
if (Status != EFI_SUCCESS){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR), gShellLevel2HiiHandle, Status);
|
||||
return (SHELL_ACCESS_DENIED);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle);
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
IsValidDeleteTarget(
|
||||
IN CONST EFI_SHELL_FILE_INFO *List,
|
||||
IN CONST EFI_SHELL_FILE_INFO *Node,
|
||||
IN CONST LIST_ENTRY *Package
|
||||
)
|
||||
{
|
||||
CONST CHAR16 *TempLocation;
|
||||
CHAR16 *Temp2;
|
||||
UINTN Size;
|
||||
|
||||
TempLocation = StrStr(Node->FullName, L":");
|
||||
if (StrLen(TempLocation) == 2) {
|
||||
//
|
||||
// Deleting the root directory is invalid.
|
||||
//
|
||||
return (FALSE);
|
||||
}
|
||||
TempLocation = ShellGetCurrentDir(NULL);
|
||||
Size = 0;
|
||||
Temp2 = NULL;
|
||||
StrnCatGrow(&Temp2, &Size, TempLocation, 0);
|
||||
if (StrStr(Temp2, Node->FullName) != NULL) {
|
||||
FreePool(Temp2);
|
||||
return (FALSE);
|
||||
}
|
||||
FreePool(Temp2);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'rm' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunRm (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
CONST CHAR16 *Param;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamCount;
|
||||
EFI_SHELL_FILE_INFO *FileList;
|
||||
EFI_SHELL_FILE_INFO *Node;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ParamCount = 0;
|
||||
FileList = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// we insufficient parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// get a list with each file specified by parameters
|
||||
// if parameter is a directory then add all the files below it to the list
|
||||
//
|
||||
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
|
||||
; Param != NULL
|
||||
; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
|
||||
){
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
|
||||
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, (CHAR16*)Param);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ShellStatus == SHELL_SUCCESS){
|
||||
//
|
||||
// loop through the list and make sure we are not aborting...
|
||||
//
|
||||
for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
|
||||
; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
|
||||
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
|
||||
){
|
||||
//
|
||||
// skip the directory traversing stuff...
|
||||
//
|
||||
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// do the deleting of nodes
|
||||
//
|
||||
if (EFI_ERROR(Node->Status)){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR2), gShellLevel2HiiHandle, Node->Status);
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
break;
|
||||
}
|
||||
if (!IsValidDeleteTarget(FileList, Node, Package)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR3), gShellLevel2HiiHandle, Node->FullName);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
ShellStatus = CascadeDelete(Node, ShellCommandLineGetFlag(Package, L"-q"));
|
||||
}
|
||||
}
|
||||
//
|
||||
// Free the fileList
|
||||
//
|
||||
if (FileList != NULL) {
|
||||
Status = ShellCloseFileMetaArg(&FileList);
|
||||
}
|
||||
FileList = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
169
ShellPkg/Library/UefiShellLevel2CommandsLib/Set.c
Normal file
169
ShellPkg/Library/UefiShellLevel2CommandsLib/Set.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
/**
|
||||
Print out each environment variable registered with the Shell 2.0 GUID.
|
||||
|
||||
If you spawn a pre 2.0 shell from the Shell 2.0 the environment variable may not carry through.
|
||||
|
||||
@retval STATUS_SUCCESS the printout was sucessful
|
||||
@return any return code from GetNextVariableName except EFI_NOT_FOUND
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
PrintAllShellEnvVars(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
CONST CHAR16 *Value;
|
||||
CONST CHAR16 *ConstEnvNameList;
|
||||
|
||||
ConstEnvNameList = gEfiShellProtocol->GetEnv(NULL);
|
||||
if (ConstEnvNameList == NULL) {
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
while (*ConstEnvNameList != CHAR_NULL){
|
||||
Value = gEfiShellProtocol->GetEnv(ConstEnvNameList);
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, ConstEnvNameList, Value);
|
||||
ConstEnvNameList += StrLen(ConstEnvNameList)+1;
|
||||
}
|
||||
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM SetParamList[] = {
|
||||
{L"-d", TypeValue},
|
||||
{L"-v", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'set' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSet (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CONST CHAR16 *KeyName;
|
||||
CONST CHAR16 *Value;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// Make sure globals are good...
|
||||
//
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (SetParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL && ShellCommandLineGetFlag(Package, L"-d")) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-d")) {
|
||||
//
|
||||
// delete a environment variable
|
||||
//
|
||||
KeyName = ShellCommandLineGetValue(Package, L"-d");
|
||||
if (KeyName == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-d");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
Status = ShellSetEnvironmentVariable(KeyName, L"", ShellCommandLineGetFlag(Package, L"-v"));
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, KeyName, Status);
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// print out all current environment variables
|
||||
//
|
||||
return(PrintAllShellEnvVars());
|
||||
} else {
|
||||
//
|
||||
// we are either printing one or assigning one
|
||||
//
|
||||
KeyName = ShellCommandLineGetRawValue(Package, 1);
|
||||
Value = ShellCommandLineGetRawValue(Package, 2);
|
||||
if (KeyName != NULL && Value != NULL) {
|
||||
//
|
||||
// assigning one
|
||||
//
|
||||
Status = ShellSetEnvironmentVariable(KeyName, Value, ShellCommandLineGetFlag(Package, L"-v"));
|
||||
} else {
|
||||
if (KeyName != NULL) {
|
||||
//
|
||||
// print out value for this one only.
|
||||
//
|
||||
Value = ShellGetEnvironmentVariable(KeyName);
|
||||
if (Value == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, KeyName);
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
772
ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
Normal file
772
ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
Normal file
@@ -0,0 +1,772 @@
|
||||
/** @file
|
||||
Main file for time, timezone, and date shell level 2 and shell level 3 functions.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
INT16
|
||||
EFIAPI
|
||||
AbsVal(
|
||||
INT16 v
|
||||
)
|
||||
{
|
||||
if (v>0) {
|
||||
return (v);
|
||||
}
|
||||
return ((INT16)(-v));
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
InternalIsTimeLikeString (
|
||||
IN CONST CHAR16 *String,
|
||||
IN CONST CHAR16 Char,
|
||||
IN CONST UINTN Min,
|
||||
IN CONST UINTN Max,
|
||||
IN CONST BOOLEAN MinusOk
|
||||
)
|
||||
{
|
||||
UINTN Count;
|
||||
Count = 0;
|
||||
|
||||
if (MinusOk) {
|
||||
//
|
||||
// A single minus is ok.
|
||||
//
|
||||
if (*String == L'-') {
|
||||
String++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// the first char must be numeric.
|
||||
//
|
||||
if (!ShellIsDecimalDigitCharacter(*String)) {
|
||||
return (FALSE);
|
||||
}
|
||||
//
|
||||
// loop through the characters and use the lib function
|
||||
//
|
||||
for ( ; String != NULL && *String != CHAR_NULL ; String++){
|
||||
if (*String == Char) {
|
||||
Count++;
|
||||
if (Count > Max) {
|
||||
return (FALSE);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!ShellIsDecimalDigitCharacter(*String)) {
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
if (Count < Min) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
CheckAndSetDate (
|
||||
IN CONST CHAR16 *DateString
|
||||
)
|
||||
{
|
||||
EFI_TIME TheTime;
|
||||
EFI_STATUS Status;
|
||||
CONST CHAR16 *Walker;
|
||||
|
||||
if (!InternalIsTimeLikeString(DateString, L'/', 2, 2, FALSE)) {
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
Status = gRT->GetTime(&TheTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Walker = DateString;
|
||||
|
||||
TheTime.Month = 0xFF;
|
||||
TheTime.Day = 0xFF;
|
||||
TheTime.Year = 0xFFFF;
|
||||
|
||||
TheTime.Month = (UINT8)StrDecimalToUintn (Walker);
|
||||
Walker = StrStr(Walker, L"/");
|
||||
if (Walker != NULL && *Walker == L'/') {
|
||||
Walker = Walker + 1;
|
||||
}
|
||||
if (Walker != NULL && Walker[0] != CHAR_NULL) {
|
||||
TheTime.Day = (UINT8)StrDecimalToUintn (Walker);
|
||||
Walker = StrStr(Walker, L"/");
|
||||
if (Walker != NULL && *Walker == L'/') {
|
||||
Walker = Walker + 1;
|
||||
}
|
||||
if (Walker != NULL && Walker[0] != CHAR_NULL) {
|
||||
TheTime.Year = (UINT16)StrDecimalToUintn (Walker);
|
||||
}
|
||||
}
|
||||
|
||||
if (TheTime.Year < 100) {
|
||||
if (TheTime.Year >= 98) {
|
||||
TheTime.Year = (UINT16)(1900 + TheTime.Year);
|
||||
} else {
|
||||
TheTime.Year = (UINT16)(2000 + TheTime.Year);
|
||||
}
|
||||
}
|
||||
|
||||
Status = gRT->SetTime(&TheTime);
|
||||
|
||||
if (!EFI_ERROR(Status)){
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'date' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunDate (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
EFI_TIME TheTime;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ProblemParam = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (SfoParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// If there are 0 value parameters, then print the current date
|
||||
// else If there are any value paramerers, then print error
|
||||
//
|
||||
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// get the current date
|
||||
//
|
||||
Status = gRT->GetTime(&TheTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// ShellPrintEx the date in SFO or regular format
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-sfo")) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
|
||||
}
|
||||
} else {
|
||||
if (PcdGet8(PcdShellSupportLevel) == 2) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// perform level 3 operation here.
|
||||
//
|
||||
ShellStatus = CheckAndSetDate(ShellCommandLineGetRawValue(Package, 1));
|
||||
if (ShellStatus != SHELL_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
//
|
||||
// return the status
|
||||
//
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
//
|
||||
// Note "-tz" is invalid for this (non-interactive) version of 'time'.
|
||||
//
|
||||
STATIC CONST SHELL_PARAM_ITEM TimeParamList2[] = {
|
||||
{L"-d", TypeValue},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM TimeParamList3[] = {
|
||||
{L"-d", TypeValue},
|
||||
{L"-tz", TypeValue},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
CheckAndSetTime (
|
||||
IN CONST CHAR16 *TimeString,
|
||||
IN CONST INT16 Tz,
|
||||
IN CONST UINT8 Daylight
|
||||
)
|
||||
{
|
||||
EFI_TIME TheTime;
|
||||
EFI_STATUS Status;
|
||||
CONST CHAR16 *Walker;
|
||||
|
||||
if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) {
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
Status = gRT->GetTime(&TheTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (TimeString != NULL) {
|
||||
Walker = TimeString;
|
||||
TheTime.Hour = 0xFF;
|
||||
TheTime.Minute = 0xFF;
|
||||
|
||||
TheTime.Hour = (UINT8)StrDecimalToUintn (Walker);
|
||||
Walker = StrStr(Walker, L":");
|
||||
if (Walker != NULL && *Walker == L':') {
|
||||
Walker = Walker + 1;
|
||||
}
|
||||
if (Walker != NULL && Walker[0] != CHAR_NULL) {
|
||||
TheTime.Minute = (UINT8)StrDecimalToUintn (Walker);
|
||||
Walker = StrStr(Walker, L":");
|
||||
if (Walker != NULL && *Walker == L':') {
|
||||
Walker = Walker + 1;
|
||||
}
|
||||
if (Walker != NULL && Walker[0] != CHAR_NULL) {
|
||||
TheTime.Second = (UINT8)StrDecimalToUintn (Walker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((Tz >= -1440 && Tz <= 1440)||(Tz == 2047)) {
|
||||
TheTime.TimeZone = Tz;
|
||||
}
|
||||
if (Daylight <= 3 && Daylight != 2) {
|
||||
TheTime.Daylight = Daylight;
|
||||
}
|
||||
Status = gRT->SetTime(&TheTime);
|
||||
|
||||
if (!EFI_ERROR(Status)){
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
/**
|
||||
Function for 'time' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunTime (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *Message;
|
||||
EFI_TIME TheTime;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
INT16 Tz;
|
||||
UINT8 Daylight;
|
||||
CONST CHAR16 *TempLocation;
|
||||
UINTN TzMinutes;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ProblemParam = NULL;
|
||||
|
||||
//
|
||||
// Initialize variables
|
||||
//
|
||||
Message = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
if (PcdGet8(PcdShellSupportLevel) == 2) {
|
||||
Status = ShellCommandLineParseEx (TimeParamList2, &Package, &ProblemParam, TRUE, TRUE);
|
||||
} else {
|
||||
ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
|
||||
Status = ShellCommandLineParseEx (TimeParamList3, &Package, &ProblemParam, TRUE, TRUE);
|
||||
}
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
Status = gRT->GetTime(&TheTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// If there are no parameters, then print the current time
|
||||
//
|
||||
if (ShellCommandLineGetRawValue(Package, 1) == NULL
|
||||
&& !ShellCommandLineGetFlag(Package, L"-d")
|
||||
&& !ShellCommandLineGetFlag(Package, L"-tz")) {
|
||||
//
|
||||
// ShellPrintEx the current time
|
||||
//
|
||||
if (TheTime.TimeZone == 2047) {
|
||||
TzMinutes = 0;
|
||||
} else {
|
||||
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
|
||||
}
|
||||
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_TIME_FORMAT),
|
||||
gShellLevel2HiiHandle,
|
||||
TheTime.Hour,
|
||||
TheTime.Minute,
|
||||
TheTime.Second,
|
||||
TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
|
||||
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
|
||||
TzMinutes
|
||||
);
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) {
|
||||
if (TheTime.TimeZone == 2047) {
|
||||
TzMinutes = 0;
|
||||
} else {
|
||||
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
|
||||
}
|
||||
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_TIME_FORMAT),
|
||||
gShellLevel2HiiHandle,
|
||||
TheTime.Hour,
|
||||
TheTime.Minute,
|
||||
TheTime.Second,
|
||||
TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
|
||||
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
|
||||
TzMinutes
|
||||
);
|
||||
switch (TheTime.Daylight) {
|
||||
case 0:
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTNA), gShellLevel2HiiHandle);
|
||||
break;
|
||||
case EFI_TIME_ADJUST_DAYLIGHT:
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTST), gShellLevel2HiiHandle);
|
||||
break;
|
||||
case EFI_TIME_IN_DAYLIGHT:
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTDT), gShellLevel2HiiHandle);
|
||||
break;
|
||||
default:
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight);
|
||||
}
|
||||
} else {
|
||||
if (PcdGet8(PcdShellSupportLevel) == 2) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// perform level 3 operation here.
|
||||
//
|
||||
if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {
|
||||
if (TempLocation[0] == L'-') {
|
||||
Tz = (INT16)(0 - StrDecimalToUintn(++TempLocation));
|
||||
} else {
|
||||
Tz = (INT16)StrDecimalToUintn(TempLocation);
|
||||
}
|
||||
if (!(Tz >= -1440 && Tz <= 1440) && Tz != 2047) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// intentionally out of bounds value will prevent changing it...
|
||||
//
|
||||
Tz = 1441;
|
||||
}
|
||||
TempLocation = ShellCommandLineGetValue(Package, L"-d");
|
||||
if (TempLocation != NULL) {
|
||||
Daylight = (UINT8)StrDecimalToUintn(TempLocation);
|
||||
if (Daylight != 0 && Daylight != 1 && Daylight != 3) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// invalid = will not use
|
||||
//
|
||||
Daylight = 0xFF;
|
||||
}
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
ShellStatus = CheckAndSetTime(ShellCommandLineGetRawValue(Package, 1), Tz, Daylight);
|
||||
if (ShellStatus != SHELL_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
//
|
||||
// return the status
|
||||
//
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
INT16 TimeZone;
|
||||
EFI_STRING_ID StringId;
|
||||
} TIME_ZONE_ITEM;
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2[] = {
|
||||
{L"-l", TypeFlag},
|
||||
{L"-f", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3[] = {
|
||||
{L"-l", TypeFlag},
|
||||
{L"-f", TypeFlag},
|
||||
{L"-s", TypeValue},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
STATIC CONST TIME_ZONE_ITEM TimeZoneList[] = {
|
||||
{720, STRING_TOKEN (STR_TIMEZONE_M12)},
|
||||
{660, STRING_TOKEN (STR_TIMEZONE_M11)},
|
||||
{600, STRING_TOKEN (STR_TIMEZONE_M10)},
|
||||
{540, STRING_TOKEN (STR_TIMEZONE_M9)},
|
||||
{480, STRING_TOKEN (STR_TIMEZONE_M8)},
|
||||
{420, STRING_TOKEN (STR_TIMEZONE_M7)},
|
||||
{360, STRING_TOKEN (STR_TIMEZONE_M6)},
|
||||
{300, STRING_TOKEN (STR_TIMEZONE_M5)},
|
||||
{270, STRING_TOKEN (STR_TIMEZONE_M430)},
|
||||
{240, STRING_TOKEN (STR_TIMEZONE_M4)},
|
||||
{210, STRING_TOKEN (STR_TIMEZONE_M330)},
|
||||
{180, STRING_TOKEN (STR_TIMEZONE_M3)},
|
||||
{120, STRING_TOKEN (STR_TIMEZONE_M2)},
|
||||
{60 , STRING_TOKEN (STR_TIMEZONE_M1)},
|
||||
{0 , STRING_TOKEN (STR_TIMEZONE_0)},
|
||||
{-60 , STRING_TOKEN (STR_TIMEZONE_P1)},
|
||||
{-120 , STRING_TOKEN (STR_TIMEZONE_P2)},
|
||||
{-180 , STRING_TOKEN (STR_TIMEZONE_P3)},
|
||||
{-210 , STRING_TOKEN (STR_TIMEZONE_P330)},
|
||||
{-240 , STRING_TOKEN (STR_TIMEZONE_P4)},
|
||||
{-270 , STRING_TOKEN (STR_TIMEZONE_P430)},
|
||||
{-300 , STRING_TOKEN (STR_TIMEZONE_P5)},
|
||||
{-330 , STRING_TOKEN (STR_TIMEZONE_P530)},
|
||||
{-345 , STRING_TOKEN (STR_TIMEZONE_P545)},
|
||||
{-360 , STRING_TOKEN (STR_TIMEZONE_P6)},
|
||||
{-390 , STRING_TOKEN (STR_TIMEZONE_P630)},
|
||||
{-420 , STRING_TOKEN (STR_TIMEZONE_P7)},
|
||||
{-480 , STRING_TOKEN (STR_TIMEZONE_P8)},
|
||||
{-540 , STRING_TOKEN (STR_TIMEZONE_P9)},
|
||||
{-570 , STRING_TOKEN (STR_TIMEZONE_P930)},
|
||||
{-600 , STRING_TOKEN (STR_TIMEZONE_P10)},
|
||||
{-660 , STRING_TOKEN (STR_TIMEZONE_P11)},
|
||||
{-720 , STRING_TOKEN (STR_TIMEZONE_P12)},
|
||||
{-780 , STRING_TOKEN (STR_TIMEZONE_P13)},
|
||||
{-840 , STRING_TOKEN (STR_TIMEZONE_P14)}
|
||||
};
|
||||
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
CheckAndSetTimeZone (
|
||||
IN CONST CHAR16 *TimeZoneString
|
||||
)
|
||||
{
|
||||
EFI_TIME TheTime;
|
||||
EFI_STATUS Status;
|
||||
CONST CHAR16 *Walker;
|
||||
UINTN LoopVar;
|
||||
|
||||
if (TimeZoneString == NULL) {
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) {
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
Status = gRT->GetTime(&TheTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Walker = TimeZoneString;
|
||||
if (*Walker == L'-') {
|
||||
TheTime.TimeZone = (INT16)((StrDecimalToUintn (++Walker)) * 60);
|
||||
} else {
|
||||
TheTime.TimeZone = (INT16)((StrDecimalToUintn (Walker)) * -60);
|
||||
}
|
||||
Walker = StrStr(Walker, L":");
|
||||
if (Walker != NULL && *Walker == L':') {
|
||||
Walker = Walker + 1;
|
||||
}
|
||||
if (Walker != NULL && Walker[0] != CHAR_NULL) {
|
||||
if (TheTime.TimeZone < 0) {
|
||||
TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)StrDecimalToUintn (Walker));
|
||||
} else {
|
||||
TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)StrDecimalToUintn (Walker));
|
||||
}
|
||||
}
|
||||
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
|
||||
for ( LoopVar = 0
|
||||
; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
|
||||
; LoopVar++
|
||||
){
|
||||
if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
|
||||
Status = gRT->SetTime(&TheTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EFI_ERROR(Status)){
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
return (SHELL_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Function for 'timezone' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunTimeZone (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
//
|
||||
// non interactive
|
||||
//
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINT8 LoopVar;
|
||||
EFI_TIME TheTime;
|
||||
BOOLEAN Found;
|
||||
UINTN TzMinutes;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ProblemParam = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
if (PcdGet8(PcdShellSupportLevel) == 2) {
|
||||
Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, FALSE);
|
||||
} else {
|
||||
ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
|
||||
Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, FALSE, TRUE);
|
||||
}
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetCount(Package) > 1) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-s")) {
|
||||
if ((ShellCommandLineGetFlag(Package, L"-l")) || (ShellCommandLineGetFlag(Package, L"-f"))) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-l or -f");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
|
||||
if (ShellCommandLineGetValue(Package, L"-s") == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-s");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// Set the time zone
|
||||
//
|
||||
ShellStatus = CheckAndSetTimeZone(ShellCommandLineGetValue(Package, L"-s"));
|
||||
if (ShellStatus != SHELL_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-s"));
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-l")) {
|
||||
//
|
||||
// Print a list of all time zones
|
||||
//
|
||||
for ( LoopVar = 0
|
||||
; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
|
||||
; LoopVar++
|
||||
){
|
||||
ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// Get Current Time Zone Info
|
||||
//
|
||||
Status = gRT->GetTime(&TheTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (TheTime.TimeZone != 2047) {
|
||||
Found = FALSE;
|
||||
for ( LoopVar = 0
|
||||
; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
|
||||
; LoopVar++
|
||||
){
|
||||
if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
|
||||
if (ShellCommandLineGetFlag(Package, L"-f")) {
|
||||
//
|
||||
// Print all info about current time zone
|
||||
//
|
||||
ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
|
||||
} else {
|
||||
//
|
||||
// Print basic info only
|
||||
//
|
||||
if (TheTime.TimeZone == 2047) {
|
||||
TzMinutes = 0;
|
||||
} else {
|
||||
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
|
||||
}
|
||||
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN(STR_TIMEZONE_SIMPLE),
|
||||
gShellLevel2HiiHandle,
|
||||
TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),
|
||||
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
|
||||
TzMinutes);
|
||||
}
|
||||
Found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!Found) {
|
||||
//
|
||||
// Print basic info only
|
||||
//
|
||||
if (TheTime.TimeZone == 2047) {
|
||||
TzMinutes = 0;
|
||||
} else {
|
||||
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
|
||||
}
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN(STR_TIMEZONE_SIMPLE),
|
||||
gShellLevel2HiiHandle,
|
||||
TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),
|
||||
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
|
||||
TzMinutes);
|
||||
if (ShellCommandLineGetFlag(Package, L"-f")) {
|
||||
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// TimeZone was 2047 (unknown) from GetTime()
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
@@ -0,0 +1,329 @@
|
||||
/** @file
|
||||
Main file for NULL named library for level 2 shell command functions.
|
||||
|
||||
these functions are:
|
||||
attrib,
|
||||
cd,
|
||||
cp,
|
||||
date*,
|
||||
time*,
|
||||
load,
|
||||
ls,
|
||||
map,
|
||||
mkdir,
|
||||
mv,
|
||||
parse,
|
||||
rm,
|
||||
reset,
|
||||
set,
|
||||
timezone*
|
||||
|
||||
* functions are non-interactive only
|
||||
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
#include "UefiShellLevel2CommandsLib.h"
|
||||
|
||||
CONST CHAR16 mFileName[] = L"ShellCommands";
|
||||
EFI_HANDLE gShellLevel2HiiHandle = NULL;
|
||||
CONST EFI_GUID gShellLevel2HiiGuid = \
|
||||
{ \
|
||||
0xf95a7ccc, 0x4c55, 0x4426, { 0xa7, 0xb4, 0xdc, 0x89, 0x61, 0x95, 0xb, 0xae } \
|
||||
};
|
||||
|
||||
CONST CHAR16*
|
||||
EFIAPI
|
||||
ShellCommandGetManFileNameLevel2 (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (mFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructor for the Shell Level 2 Commands library.
|
||||
|
||||
Install the handlers for level 2 UEFI Shell 2.0 commands.
|
||||
|
||||
@param ImageHandle the image handle of the process
|
||||
@param SystemTable the EFI System Table pointer
|
||||
|
||||
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
|
||||
@retval EFI_UNSUPPORTED the shell level required was not found.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ShellLevel2CommandsLibConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
//
|
||||
// if shell level is less than 2 do nothing
|
||||
//
|
||||
if (PcdGet8(PcdShellSupportLevel) < 2) {
|
||||
return (EFI_UNSUPPORTED);
|
||||
}
|
||||
|
||||
gShellLevel2HiiHandle = HiiAddPackages (&gShellLevel2HiiGuid, gImageHandle, UefiShellLevel2CommandsLibStrings, NULL);
|
||||
if (gShellLevel2HiiHandle == NULL) {
|
||||
return (EFI_DEVICE_ERROR);
|
||||
}
|
||||
|
||||
//
|
||||
// install our shell command handlers that are always installed
|
||||
//
|
||||
ShellCommandRegisterCommandName(L"attrib", ShellCommandRunAttrib , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_ATTRIB) );
|
||||
ShellCommandRegisterCommandName(L"cd", ShellCommandRunCd , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_CD) );
|
||||
ShellCommandRegisterCommandName(L"cp", ShellCommandRunCp , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_CP) );
|
||||
ShellCommandRegisterCommandName(L"load", ShellCommandRunLoad , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD) );
|
||||
ShellCommandRegisterCommandName(L"map", ShellCommandRunMap , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MAP) );
|
||||
ShellCommandRegisterCommandName(L"mkdir", ShellCommandRunMkDir , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MKDIR) );
|
||||
ShellCommandRegisterCommandName(L"mv", ShellCommandRunMv , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MV) );
|
||||
ShellCommandRegisterCommandName(L"parse", ShellCommandRunParse , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_PARSE) );
|
||||
ShellCommandRegisterCommandName(L"reset", ShellCommandRunReset , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RESET) );
|
||||
ShellCommandRegisterCommandName(L"set", ShellCommandRunSet , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET) );
|
||||
ShellCommandRegisterCommandName(L"ls", ShellCommandRunLs , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LS) );
|
||||
ShellCommandRegisterCommandName(L"rm", ShellCommandRunRm , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RM) );
|
||||
|
||||
//
|
||||
// support for permenant (built in) aliases
|
||||
//
|
||||
ShellCommandRegisterAlias(L"rm", L"del");
|
||||
ShellCommandRegisterAlias(L"ls", L"dir");
|
||||
ShellCommandRegisterAlias(L"cp", L"copy");
|
||||
ShellCommandRegisterAlias(L"mkdir", L"md");
|
||||
ShellCommandRegisterAlias(L"cd ..", L"cd..");
|
||||
ShellCommandRegisterAlias(L"cd \\", L"cd\\");
|
||||
//
|
||||
// These are installed in level 2 or 3...
|
||||
//
|
||||
if (PcdGet8(PcdShellSupportLevel) == 2 || PcdGet8(PcdShellSupportLevel) == 3) {
|
||||
ShellCommandRegisterCommandName(L"date", ShellCommandRunDate , ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_DATE) );
|
||||
ShellCommandRegisterCommandName(L"time", ShellCommandRunTime , ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIME) );
|
||||
ShellCommandRegisterCommandName(L"timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIMEZONE));
|
||||
} else {
|
||||
DEBUG_CODE_BEGIN();
|
||||
//
|
||||
// we want to be able to test these so install them under a different name in debug mode...
|
||||
//
|
||||
ShellCommandRegisterCommandName(L"l2date", ShellCommandRunDate , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_DATE) );
|
||||
ShellCommandRegisterCommandName(L"l2time", ShellCommandRunTime , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIME) );
|
||||
ShellCommandRegisterCommandName(L"l2timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIMEZONE));
|
||||
DEBUG_CODE_END();
|
||||
}
|
||||
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Destructor for the library. free any resources.
|
||||
|
||||
@param ImageHandle The image handle of the process.
|
||||
@param SystemTable The EFI System Table pointer.
|
||||
|
||||
@retval EFI_SUCCESS Always returned.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ShellLevel2CommandsLibDestructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
if (gShellLevel2HiiHandle != NULL) {
|
||||
HiiRemovePackages(gShellLevel2HiiHandle);
|
||||
}
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Function to clean up paths. Removes the following items:
|
||||
single periods in the path (no need for the current directory tag)
|
||||
double periods in the path and removes a single parent directory.
|
||||
|
||||
This will be done inline and the resultant string may be be 'too big'.
|
||||
|
||||
@param[in] PathToReturn The pointer to the string containing the path.
|
||||
|
||||
@return PathToReturn is always returned.
|
||||
**/
|
||||
CHAR16*
|
||||
EFIAPI
|
||||
CleanPath(
|
||||
IN CHAR16 *PathToReturn
|
||||
)
|
||||
{
|
||||
CHAR16 *TempString;
|
||||
UINTN TempSize;
|
||||
if (PathToReturn==NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
//
|
||||
// Fix up the directory name
|
||||
//
|
||||
while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) {
|
||||
*TempString = CHAR_NULL;
|
||||
TempString += 4;
|
||||
ChopLastSlash(PathToReturn);
|
||||
TempSize = StrSize(TempString);
|
||||
CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
|
||||
}
|
||||
if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {
|
||||
*TempString = CHAR_NULL;
|
||||
ChopLastSlash(PathToReturn);
|
||||
}
|
||||
while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) {
|
||||
*TempString = CHAR_NULL;
|
||||
TempString += 2;
|
||||
TempSize = StrSize(TempString);
|
||||
CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
|
||||
}
|
||||
if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
|
||||
*TempString = CHAR_NULL;
|
||||
}
|
||||
return (PathToReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
returns a fully qualified directory (contains a map drive at the begining)
|
||||
path from a unknown directory path.
|
||||
|
||||
If Path is already fully qualified this will return a duplicat otherwise this
|
||||
will use get the current directory and use that to build the fully qualified
|
||||
version.
|
||||
|
||||
if the return value is not NULL it must be caller freed.
|
||||
|
||||
@param[in] Path The unknown Path Value
|
||||
|
||||
@retval NULL A memory allocation failed
|
||||
@retval NULL a fully qualified path could not be discovered.
|
||||
@retval other pointer to a fuly qualified path.
|
||||
**/
|
||||
CHAR16*
|
||||
EFIAPI
|
||||
GetFullyQualifiedPath(
|
||||
IN CONST CHAR16* Path
|
||||
)
|
||||
{
|
||||
CHAR16 *PathToReturn;
|
||||
UINTN Size;
|
||||
CONST CHAR16 *CurDir;
|
||||
|
||||
PathToReturn = NULL;
|
||||
Size = 0;
|
||||
|
||||
ASSERT((PathToReturn == NULL && Size == 0) || (PathToReturn != NULL));
|
||||
//
|
||||
// convert a local path to an absolute path
|
||||
//
|
||||
if (StrStr(Path, L":") == NULL) {
|
||||
CurDir = gEfiShellProtocol->GetCurDir(NULL);
|
||||
StrnCatGrow(&PathToReturn, &Size, CurDir, 0);
|
||||
if (*Path == L'\\') {
|
||||
Path++;
|
||||
}
|
||||
}
|
||||
StrnCatGrow(&PathToReturn, &Size, Path, 0);
|
||||
|
||||
CleanPath(PathToReturn);
|
||||
|
||||
while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {
|
||||
PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;
|
||||
}
|
||||
|
||||
return (PathToReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
Function to verify all intermediate directories in the path.
|
||||
|
||||
@param[in] Path The pointer to the path to fix.
|
||||
|
||||
@retval EFI_SUCCESS The operation was successful.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VerifyIntermediateDirectories (
|
||||
IN CONST CHAR16 *Path
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
CHAR16 *PathCopy;
|
||||
CHAR16 *TempSpot;
|
||||
SHELL_FILE_HANDLE FileHandle;
|
||||
|
||||
ASSERT(Path != NULL);
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
PathCopy = NULL;
|
||||
PathCopy = StrnCatGrow(&PathCopy, NULL, Path, 0);
|
||||
FileHandle = NULL;
|
||||
|
||||
for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){
|
||||
*TempSpot = CHAR_NULL;
|
||||
}
|
||||
if (*TempSpot == L'\\') {
|
||||
*TempSpot = CHAR_NULL;
|
||||
}
|
||||
|
||||
if (PathCopy != NULL && *PathCopy != CHAR_NULL) {
|
||||
Status = VerifyIntermediateDirectories(PathCopy);
|
||||
|
||||
if (PathCopy[StrLen(PathCopy)-1] != L':') {
|
||||
if (!EFI_ERROR(Status)) {
|
||||
Status = ShellOpenFileByName(PathCopy, &FileHandle, EFI_FILE_MODE_READ, 0);
|
||||
if (FileHandle != NULL) {
|
||||
ShellCloseFile(&FileHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SHELL_FREE_NON_NULL(PathCopy);
|
||||
|
||||
return (Status);
|
||||
}
|
||||
|
||||
// be lazy and borrow from baselib.
|
||||
CHAR16
|
||||
EFIAPI
|
||||
InternalCharToUpper (
|
||||
IN CONST CHAR16 Char
|
||||
);
|
||||
|
||||
CONST CHAR16*
|
||||
EFIAPI
|
||||
StrniCmp(
|
||||
IN CONST CHAR16 *Source,
|
||||
IN CONST CHAR16 *Target,
|
||||
IN CONST UINTN Count
|
||||
)
|
||||
{
|
||||
UINTN LoopCount;
|
||||
CHAR16 Char1;
|
||||
CHAR16 Char2;
|
||||
|
||||
ASSERT(Source != NULL);
|
||||
ASSERT(Target != NULL);
|
||||
|
||||
for (LoopCount = 0 ; LoopCount < Count ; LoopCount++) {
|
||||
Char1 = InternalCharToUpper(Source[LoopCount]);
|
||||
Char2 = InternalCharToUpper(Target[LoopCount]);
|
||||
if (Char1 != Char2) {
|
||||
return (&Source[LoopCount]);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
@@ -0,0 +1,297 @@
|
||||
/** @file
|
||||
Main file for NULL named library for level 2 shell command functions.
|
||||
|
||||
these functions are:
|
||||
attrib, cd, cp, date*, time*, rm, reset,
|
||||
load, ls, map, mkdir, mv, parse, set, timezone*
|
||||
|
||||
|
||||
* functions are non-interactive only
|
||||
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <ShellBase.h>
|
||||
|
||||
#include <Protocol/EfiShell.h>
|
||||
#include <Protocol/EfiShellParameters.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
#include <Protocol/DevicePathToText.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/ShellCommandLib.h>
|
||||
#include <Library/ShellLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/HiiLib.h>
|
||||
#include <Library/SortLib.h>
|
||||
#include <Library/FileHandleLib.h>
|
||||
|
||||
extern CONST CHAR16 mFileName[];
|
||||
extern EFI_HANDLE gShellLevel2HiiHandle;
|
||||
extern CONST EFI_GUID gShellLevel2HiiGuid;
|
||||
|
||||
/**
|
||||
Function for 'attrib' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunAttrib (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'date' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunDate (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'time' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunTime (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'load' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunLoad (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'ls' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunLs (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'map' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunMap (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'reset' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunReset (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'timezone' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunTimeZone (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'set' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunSet (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'mkdir' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunMkDir (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'cd' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunCd (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'cp' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunCp (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'parse' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunParse (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'rm' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunRm (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'mv' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunMv (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
returns a fully qualified directory (contains a map drive at the begining)
|
||||
path from a unknown directory path.
|
||||
|
||||
If Path is already fully qualified this will return a duplicat otherwise this
|
||||
will use get the current directory and use that to build the fully qualified
|
||||
version.
|
||||
|
||||
if the return value is not NULL it must be caller freed.
|
||||
|
||||
@param[in] Path The unknown Path Value
|
||||
|
||||
@retval NULL A memory allocation failed
|
||||
@retval NULL a fully qualified path could not be discovered.
|
||||
@retval other pointer to a fuly qualified path.
|
||||
**/
|
||||
CHAR16*
|
||||
EFIAPI
|
||||
GetFullyQualifiedPath(
|
||||
IN CONST CHAR16* Path
|
||||
);
|
||||
|
||||
/**
|
||||
Function to verify all intermediate directories in the path.
|
||||
|
||||
@param[in] Path The pointer to the path to fix.
|
||||
|
||||
@retval EFI_SUCCESS The operation was successful.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
VerifyIntermediateDirectories (
|
||||
IN CONST CHAR16 *Path
|
||||
);
|
||||
|
||||
/**
|
||||
CaseInsensitive length limited string comparison.
|
||||
|
||||
@param[in] Source Pointer to first string.
|
||||
@param[in] Target Pointer to second string.
|
||||
@param[in] Count Number of characters to compare.
|
||||
|
||||
@retval 0 The strings are the same.
|
||||
@return non-zero if the strings are different.
|
||||
**/
|
||||
CONST CHAR16*
|
||||
EFIAPI
|
||||
StrniCmp(
|
||||
IN CONST CHAR16 *Source,
|
||||
IN CONST CHAR16 *Target,
|
||||
IN CONST UINTN Count
|
||||
);
|
@@ -0,0 +1,82 @@
|
||||
## @file
|
||||
# Provides shell level 2 functions
|
||||
#
|
||||
# Copyright (c) 2009, 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 = 0x00010006
|
||||
BASE_NAME = UefiShellLevel2CommandsLib
|
||||
FILE_GUID = CBF3931C-A2DF-40e5-B77E-CCA9555E9755
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
|
||||
CONSTRUCTOR = ShellLevel2CommandsLibConstructor
|
||||
DESTRUCTOR = ShellLevel2CommandsLibDestructor
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources.common]
|
||||
UefiShellLevel2CommandsLib.c
|
||||
UefiShellLevel2CommandsLib.h
|
||||
UefiShellLevel2CommandsLib.uni
|
||||
TimeDate.c
|
||||
Load.c
|
||||
Ls.c
|
||||
Map.c
|
||||
Reset.c
|
||||
Set.c
|
||||
MkDir.c
|
||||
Cd.c
|
||||
Cp.c
|
||||
Parse.c
|
||||
Rm.c
|
||||
Mv.c
|
||||
Attrib.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
MemoryAllocationLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
ShellCommandLib
|
||||
ShellLib
|
||||
UefiLib
|
||||
UefiRuntimeServicesTableLib
|
||||
UefiBootServicesTableLib
|
||||
PcdLib
|
||||
HiiLib
|
||||
HandleParsingLib
|
||||
|
||||
[Protocols]
|
||||
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiShellProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiShellParametersProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDevicePathProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiLoadedImageProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiSimpleFileSystemProtocolGuid # ALWAYS_CONSUMED
|
||||
gEfiDevicePathToTextProtocolGuid # ALWAYS_CONSUMED
|
||||
|
||||
[Pcd.common]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize # ALWAYS_CONSUMED
|
||||
|
||||
[Guids]
|
||||
gEfiFileSystemInfoGuid
|
||||
gEfiFileInfoGuid
|
Binary file not shown.
162
ShellPkg/Library/UefiShellLevel3CommandsLib/Alias.c
Normal file
162
ShellPkg/Library/UefiShellLevel3CommandsLib/Alias.c
Normal file
@@ -0,0 +1,162 @@
|
||||
/** @file
|
||||
Main file for Alias shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
/**
|
||||
Print out each alias registered with the Shell.
|
||||
|
||||
@retval STATUS_SUCCESS the printout was sucessful
|
||||
@return any return code from GetNextVariableName except EFI_NOT_FOUND
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
PrintAllShellAlias(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
CONST CHAR16 *ConstAllAliasList;
|
||||
CHAR16 *Alias;
|
||||
CONST CHAR16 *Command;
|
||||
CHAR16 *Walker;
|
||||
BOOLEAN Volatile;
|
||||
|
||||
Volatile = FALSE;
|
||||
|
||||
ConstAllAliasList = gEfiShellProtocol->GetAlias(NULL, NULL);
|
||||
if (ConstAllAliasList == NULL) {
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
Alias = AllocateZeroPool(StrSize(ConstAllAliasList));
|
||||
Walker = (CHAR16*)ConstAllAliasList;
|
||||
|
||||
do {
|
||||
CopyMem(Alias, Walker, StrSize(Walker));
|
||||
Walker = StrStr(Alias, L";");
|
||||
if (Walker != NULL) {
|
||||
Walker[0] = CHAR_NULL;
|
||||
Walker = Walker + 1;
|
||||
}
|
||||
Command = gEfiShellProtocol->GetAlias(Alias, &Volatile);
|
||||
if (ShellCommandIsOnAliasList(Alias)) {
|
||||
Volatile = FALSE;
|
||||
}
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ALIAS_OUTPUT), gShellLevel3HiiHandle, !Volatile?L' ':L'*', Alias, Command);
|
||||
} while (Walker != NULL && Walker[0] != CHAR_NULL);
|
||||
|
||||
FreePool(Alias);
|
||||
|
||||
return (SHELL_SUCCESS);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-v", TypeFlag},
|
||||
{L"-d", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'alias' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunAlias (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CONST CHAR16 *Param1;
|
||||
CONST CHAR16 *Param2;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
Param1 = ShellCommandLineGetRawValue(Package, 1);
|
||||
Param2 = ShellCommandLineGetRawValue(Package, 2);
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
if (ShellCommandLineGetCount(Package) == 1) {
|
||||
//
|
||||
// print out alias'
|
||||
//
|
||||
Status = PrintAllShellAlias();
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-d")) {
|
||||
//
|
||||
// delete an alias
|
||||
//
|
||||
Status = gEfiShellProtocol->SetAlias(Param1, NULL, TRUE, FALSE);
|
||||
} else if (ShellCommandLineGetCount(Package) == 3) {
|
||||
//
|
||||
// must be adding an alias
|
||||
//
|
||||
Status = gEfiShellProtocol->SetAlias(Param2, Param1, FALSE, ShellCommandLineGetFlag(Package, L"-v"));
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_ACCESS_DENIED) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel3HiiHandle, Status);
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
} else if (ShellCommandLineGetCount(Package) == 2) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
135
ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c
Normal file
135
ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/** @file
|
||||
Main file for attrib shell level 2 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
/**
|
||||
Function for 'cls' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunCls (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *Message;
|
||||
UINTN Background;
|
||||
UINTN ForeColor;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CONST CHAR16 *Param1;
|
||||
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ProblemParam = NULL;
|
||||
Background = 0;
|
||||
|
||||
//
|
||||
// Initialize variables
|
||||
//
|
||||
Message = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else {
|
||||
//
|
||||
// If there are 0 value parameters, clear sceen
|
||||
//
|
||||
Param1 = ShellCommandLineGetRawValue(Package, 1);
|
||||
if (Param1 == NULL) {
|
||||
//
|
||||
// clear screen
|
||||
//
|
||||
gST->ConOut->ClearScreen (gST->ConOut);
|
||||
} else if (ShellCommandLineGetCount(Package) > 2) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
if (StrDecimalToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, Param1);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
switch (StrDecimalToUintn(Param1)) {
|
||||
case 0:
|
||||
Background = EFI_BACKGROUND_BLACK;
|
||||
break;
|
||||
case 1:
|
||||
Background = EFI_BACKGROUND_BLUE;
|
||||
break;
|
||||
case 2:
|
||||
Background = EFI_BACKGROUND_GREEN;
|
||||
break;
|
||||
case 3:
|
||||
Background = EFI_BACKGROUND_CYAN;
|
||||
break;
|
||||
case 4:
|
||||
Background = EFI_BACKGROUND_RED;
|
||||
break;
|
||||
case 5:
|
||||
Background = EFI_BACKGROUND_MAGENTA;
|
||||
break;
|
||||
case 6:
|
||||
Background = EFI_BACKGROUND_BROWN;
|
||||
break;
|
||||
case 7:
|
||||
Background = EFI_BACKGROUND_LIGHTGRAY;
|
||||
break;
|
||||
}
|
||||
ForeColor = (~StrDecimalToUintn(Param1)) & 0xF;
|
||||
Status = gST->ConOut->SetAttribute (gST->ConOut, ForeColor | Background);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
Status = gST->ConOut->ClearScreen (gST->ConOut);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
|
||||
//
|
||||
// return the status
|
||||
//
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
116
ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
Normal file
116
ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/** @file
|
||||
Main file for Echo shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-on", TypeFlag},
|
||||
{L"-off", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'echo' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunEcho (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
// CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamCount;
|
||||
|
||||
// ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParseEx (ParamList, &Package, NULL, TRUE, TRUE);
|
||||
// if (EFI_ERROR(Status)) {
|
||||
// if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
// ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
// FreePool(ProblemParam);
|
||||
// ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
// } else {
|
||||
// ASSERT(FALSE);
|
||||
// }
|
||||
// } else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
if (ShellCommandLineGetFlag(Package, L"-on")) {
|
||||
//
|
||||
// Turn it on
|
||||
//
|
||||
ShellCommandSetEchoState(TRUE);
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-off")) {
|
||||
//
|
||||
// turn it off
|
||||
//
|
||||
ShellCommandSetEchoState(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// output its current state
|
||||
//
|
||||
if (ShellCommandGetEchoState()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);
|
||||
} else {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// print the line
|
||||
//
|
||||
for ( ParamCount = 1
|
||||
; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
|
||||
; ParamCount++
|
||||
) {
|
||||
if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {
|
||||
ShellPrintEx(-1, -1, L"%s ", ShellCommandLineGetRawValue(Package, ParamCount));
|
||||
} else {
|
||||
ShellPrintEx(-1, -1, L"%s", ShellCommandLineGetRawValue(Package, ParamCount));
|
||||
}
|
||||
}
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel3HiiHandle);
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
// }
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
101
ShellPkg/Library/UefiShellLevel3CommandsLib/GetMtc.c
Normal file
101
ShellPkg/Library/UefiShellLevel3CommandsLib/GetMtc.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/** @file
|
||||
Main file for GetMtc shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
/**
|
||||
Function for 'getmtc' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunGetMtc (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINT64 Mtc;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// Get the monotonic counter count
|
||||
//
|
||||
Status = gBS->GetNextMonotonicCount(&Mtc);
|
||||
switch(Status) {
|
||||
case EFI_DEVICE_ERROR:
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
break;
|
||||
case EFI_SECURITY_VIOLATION:
|
||||
ShellStatus = SHELL_SECURITY_VIOLATION;
|
||||
break;
|
||||
default:
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellStatus = SHELL_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// print it...
|
||||
//
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GET_MTC_OUTPUT), gShellLevel3HiiHandle, Mtc);
|
||||
}
|
||||
}
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
183
ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
Normal file
183
ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
Normal file
@@ -0,0 +1,183 @@
|
||||
/** @file
|
||||
Main file for Help shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-usage", TypeFlag},
|
||||
{L"-section", TypeValue},
|
||||
{L"-verbose", TypeFlag},
|
||||
{L"-v", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'help' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunHelp (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
CHAR16 *OutText;
|
||||
CONST COMMAND_LIST *CommandList;
|
||||
CONST COMMAND_LIST *Node;
|
||||
CHAR16 *CommandToGetHelpOn;
|
||||
CHAR16 *SectionToGetHelpOn;
|
||||
CHAR16 *HiiString;
|
||||
BOOLEAN Found;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
OutText = NULL;
|
||||
CommandToGetHelpOn = NULL;
|
||||
SectionToGetHelpOn = NULL;
|
||||
Found = FALSE;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// Check for conflicting parameters.
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-usage")
|
||||
&&ShellCommandLineGetFlag(Package, L"-section")
|
||||
&&(ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v"))
|
||||
){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// Get the command name we are getting help on
|
||||
//
|
||||
ASSERT(CommandToGetHelpOn == NULL);
|
||||
StrnCatGrow(&CommandToGetHelpOn, NULL, ShellCommandLineGetRawValue(Package, 1), 0);
|
||||
if (CommandToGetHelpOn == NULL && ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
//
|
||||
// If we dont have a command and we got a simple -?
|
||||
// we are looking for help on help command.
|
||||
//
|
||||
StrnCatGrow(&CommandToGetHelpOn, NULL, L"help", 0);
|
||||
}
|
||||
|
||||
if (CommandToGetHelpOn == NULL) {
|
||||
StrnCatGrow(&CommandToGetHelpOn, NULL, L"*", 0);
|
||||
ASSERT(SectionToGetHelpOn == NULL);
|
||||
StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
|
||||
} else {
|
||||
ASSERT(SectionToGetHelpOn == NULL);
|
||||
//
|
||||
// Get the section name for the given command name
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-section")) {
|
||||
StrnCatGrow(&SectionToGetHelpOn, NULL, ShellCommandLineGetValue(Package, L"-section"), 0);
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-usage")) {
|
||||
StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS", 0);
|
||||
} else if (ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v")) {
|
||||
} else {
|
||||
StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {
|
||||
//
|
||||
// we need info on the special characters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_HEADER), gShellLevel3HiiHandle);
|
||||
HiiString = HiiGetString(gShellLevel3HiiHandle, STRING_TOKEN(STR_HELP_SC_DATA), NULL);
|
||||
ShellPrintEx(-1, -1, L"%s", HiiString);
|
||||
FreePool(HiiString);
|
||||
Found = TRUE;
|
||||
} else {
|
||||
CommandList = ShellCommandGetCommandList();
|
||||
ASSERT(CommandList != NULL);
|
||||
for ( Node = (COMMAND_LIST*)GetFirstNode(&CommandList->Link)
|
||||
; CommandList != NULL && !IsListEmpty(&CommandList->Link) && !IsNull(&CommandList->Link, &Node->Link)
|
||||
; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link)
|
||||
){
|
||||
if (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) {
|
||||
//
|
||||
// We have a command to look for help on.
|
||||
//
|
||||
Status = gEfiShellProtocol->GetHelpText(Node->CommandString, SectionToGetHelpOn, &OutText);
|
||||
if (EFI_ERROR(Status) || OutText == NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
} else {
|
||||
while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {
|
||||
OutText[StrLen(OutText)-1] = CHAR_NULL;
|
||||
}
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_COMMAND), gShellLevel3HiiHandle, Node->CommandString, OutText);
|
||||
FreePool(OutText);
|
||||
OutText = NULL;
|
||||
Found = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Found && ShellStatus == SHELL_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
}
|
||||
if (CommandToGetHelpOn != NULL) {
|
||||
FreePool(CommandToGetHelpOn);
|
||||
}
|
||||
if (SectionToGetHelpOn != NULL) {
|
||||
FreePool(SectionToGetHelpOn);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
106
ShellPkg/Library/UefiShellLevel3CommandsLib/Pause.c
Normal file
106
ShellPkg/Library/UefiShellLevel3CommandsLib/Pause.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/** @file
|
||||
Main file for Pause shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-q", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'pause' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunPause (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
SHELL_PROMPT_RESPONSE *Resp;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (!gEfiShellProtocol->BatchIsActive()) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_SCRIPT_ONLY), gShellLevel3HiiHandle);
|
||||
return (SHELL_UNSUPPORTED);
|
||||
}
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
if (!ShellCommandLineGetFlag(Package, L"-q")) {
|
||||
Status = ShellPromptForResponseHii(ShellPromptResponseTypeQuitContinue, STRING_TOKEN (STR_PAUSE_PROMPT), gShellLevel3HiiHandle, (VOID**)&Resp);
|
||||
} else {
|
||||
Status = ShellPromptForResponse(ShellPromptResponseTypeQuitContinue, NULL, (VOID**)&Resp);
|
||||
}
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
if (Resp == NULL || *Resp == ShellPromptResponseQuit) {
|
||||
ShellCommandRegisterExit(TRUE);
|
||||
ShellStatus = SHELL_ABORTED;
|
||||
}
|
||||
|
||||
if (Resp != NULL) {
|
||||
FreePool(Resp);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
265
ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
Normal file
265
ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
Normal file
@@ -0,0 +1,265 @@
|
||||
/** @file
|
||||
Main file for Touch shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
TouchFileByHandle (
|
||||
IN EFI_HANDLE Handle
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_FILE_INFO *FileInfo;
|
||||
|
||||
FileInfo = gEfiShellProtocol->GetFileInfo(Handle);
|
||||
if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) != 0){
|
||||
return (EFI_ACCESS_DENIED);
|
||||
}
|
||||
Status = gRT->GetTime(&FileInfo->ModificationTime, NULL);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
CopyMem(&FileInfo->LastAccessTime, &FileInfo->ModificationTime, sizeof(EFI_TIME));
|
||||
|
||||
Status = gEfiShellProtocol->SetFileInfo(Handle, FileInfo);
|
||||
|
||||
FreePool(FileInfo);
|
||||
|
||||
return (Status);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DoTouchByHandle (
|
||||
IN CONST CHAR16 *Name,
|
||||
IN CHAR16 *FS,
|
||||
IN SHELL_FILE_HANDLE Handle,
|
||||
IN BOOLEAN Rec
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_SHELL_FILE_INFO *FileList;
|
||||
EFI_SHELL_FILE_INFO *Walker;
|
||||
CHAR16 *TempSpot;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
FileList = NULL;
|
||||
Walker = NULL;
|
||||
|
||||
if (FS == NULL) {
|
||||
FS = StrnCatGrow(&FS, NULL, Name, 0);
|
||||
TempSpot = StrStr(FS, L"\\");
|
||||
if (TempSpot != NULL) {
|
||||
*TempSpot = CHAR_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// do it
|
||||
//
|
||||
Status = TouchFileByHandle(Handle);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Name, Status);
|
||||
return (Status);
|
||||
}
|
||||
|
||||
//
|
||||
// if it's a directory recurse...
|
||||
//
|
||||
if (FileHandleIsDirectory(Handle) == EFI_SUCCESS && Rec) {
|
||||
//
|
||||
// get each file under this directory
|
||||
//
|
||||
if (EFI_ERROR(gEfiShellProtocol->FindFilesInDir(Handle, &FileList))) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// recurse on each
|
||||
//
|
||||
for (Walker = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
|
||||
; FileList != NULL && !IsNull(&FileList->Link, &Walker->Link) && !EFI_ERROR(Status)
|
||||
; Walker = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Walker->Link)
|
||||
){
|
||||
if ( (StrCmp(Walker->FileName, L".") != 0)
|
||||
&& (StrCmp(Walker->FileName, L"..") != 0)
|
||||
){
|
||||
//
|
||||
// Open the file since we need that handle.
|
||||
//
|
||||
Status = gEfiShellProtocol->OpenFileByName (Walker->FullName, &Walker->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Walker->FullName, Status);
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
} else {
|
||||
Status = DoTouchByHandle(Walker->FullName, FS, Walker->Handle, TRUE);
|
||||
gEfiShellProtocol->CloseFile(Walker->Handle);
|
||||
Walker->Handle = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free stuff
|
||||
//
|
||||
if (FileList != NULL && EFI_ERROR(gEfiShellProtocol->FreeFileList(&FileList))) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
return (Status);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-r", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'touch' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunTouch (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
CONST CHAR16 *Param;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamCount;
|
||||
EFI_SHELL_FILE_INFO *FileList;
|
||||
EFI_SHELL_FILE_INFO *Node;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ParamCount = 0;
|
||||
FileList = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// we insufficient parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// get a list with each file specified by parameters
|
||||
// if parameter is a directory then add all the files below it to the list
|
||||
//
|
||||
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
|
||||
; Param != NULL
|
||||
; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
|
||||
){
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, (CHAR16*)Param);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
//
|
||||
// make sure we completed the param parsing sucessfully...
|
||||
// Also make sure that any previous action was sucessful
|
||||
//
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
//
|
||||
// check that we have at least 1 file
|
||||
//
|
||||
if (FileList == NULL || IsListEmpty(&FileList->Link)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, Param);
|
||||
continue;
|
||||
} else {
|
||||
//
|
||||
// loop through the list and make sure we are not aborting...
|
||||
//
|
||||
for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
|
||||
; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
|
||||
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
|
||||
){
|
||||
//
|
||||
// make sure the file opened ok
|
||||
//
|
||||
if (EFI_ERROR(Node->Status)){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Node->Status);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
continue;
|
||||
}
|
||||
|
||||
Status = DoTouchByHandle(Node->FullName, NULL, Node->Handle, ShellCommandLineGetFlag(Package, L"-r"));
|
||||
if (EFI_ERROR(Status) && Status != EFI_ACCESS_DENIED) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Status);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// Free the fileList
|
||||
//
|
||||
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
|
||||
Status = ShellCloseFileMetaArg(&FileList);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
}
|
||||
FileList = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
return (SHELL_ABORTED);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
239
ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c
Normal file
239
ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c
Normal file
@@ -0,0 +1,239 @@
|
||||
/** @file
|
||||
Main file for Type shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
TypeFileByHandle (
|
||||
IN EFI_HANDLE Handle,
|
||||
BOOLEAN Ascii,
|
||||
BOOLEAN UCS2
|
||||
)
|
||||
{
|
||||
UINTN ReadSize;
|
||||
VOID *Buffer;
|
||||
EFI_STATUS Status;
|
||||
UINTN LoopVar;
|
||||
CHAR16 AsciiChar;
|
||||
|
||||
ReadSize = PcdGet16(PcdShellFileOperationSize);
|
||||
Buffer = AllocatePool(ReadSize);
|
||||
if (Buffer == NULL) {
|
||||
return (EFI_OUT_OF_RESOURCES);
|
||||
}
|
||||
|
||||
Status = ShellSetFilePosition(Handle, 0);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
while (ReadSize == ((UINTN)PcdGet16(PcdShellFileOperationSize))){
|
||||
ZeroMem(Buffer, ReadSize);
|
||||
Status = ShellReadFile(Handle, &ReadSize, Buffer);
|
||||
if (EFI_ERROR(Status)){
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(Ascii|UCS2)){
|
||||
if (*(UINT16*)Buffer == UnicodeFileTag) {
|
||||
UCS2 = TRUE;
|
||||
Buffer = ((UINT16*)Buffer) + 1;
|
||||
} else {
|
||||
Ascii = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// We want to use plain Print function here! (no color support for files)
|
||||
//
|
||||
if (Ascii){
|
||||
for (LoopVar = 0 ; LoopVar < ReadSize ; LoopVar++) {
|
||||
AsciiChar = CHAR_NULL;
|
||||
AsciiChar = ((CHAR8*)Buffer)[LoopVar];
|
||||
if (AsciiChar == CHAR_NULL) {
|
||||
AsciiChar = '.';
|
||||
}
|
||||
Print(L"%c", AsciiChar);
|
||||
}
|
||||
} else {
|
||||
Print(L"%s", Buffer);
|
||||
}
|
||||
}
|
||||
Status = Print(L"\r\n", Buffer);
|
||||
return (Status);
|
||||
}
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-a", TypeFlag},
|
||||
{L"-u", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'type' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunType (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
CONST CHAR16 *Param;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINTN ParamCount;
|
||||
EFI_SHELL_FILE_INFO *FileList;
|
||||
EFI_SHELL_FILE_INFO *Node;
|
||||
BOOLEAN AsciiMode;
|
||||
BOOLEAN UnicodeMode;
|
||||
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
ParamCount = 0;
|
||||
FileList = NULL;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
AsciiMode = ShellCommandLineGetFlag(Package, L"-a");
|
||||
UnicodeMode = ShellCommandLineGetFlag(Package, L"-u");
|
||||
|
||||
if (AsciiMode && UnicodeMode) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"-a & -u");
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
||||
//
|
||||
// we insufficient parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
//
|
||||
// get a list with each file specified by parameters
|
||||
// if parameter is a directory then add all the files below it to the list
|
||||
//
|
||||
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
|
||||
; Param != NULL
|
||||
; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
|
||||
){
|
||||
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ, &FileList);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
//
|
||||
// make sure we completed the param parsing sucessfully...
|
||||
// Also make sure that any previous action was sucessful
|
||||
//
|
||||
if (ShellStatus == SHELL_SUCCESS) {
|
||||
//
|
||||
// check that we have at least 1 file
|
||||
//
|
||||
if (FileList == NULL || IsListEmpty(&FileList->Link)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, Param);
|
||||
continue;
|
||||
} else {
|
||||
//
|
||||
// loop through the list and make sure we are not aborting...
|
||||
//
|
||||
for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
|
||||
; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
|
||||
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
|
||||
){
|
||||
//
|
||||
// make sure the file opened ok
|
||||
//
|
||||
if (EFI_ERROR(Node->Status)){
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Node->Status);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// make sure its not a directory
|
||||
//
|
||||
if (FileHandleIsDirectory(Node->Handle) == EFI_SUCCESS) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_IS_DIR), gShellLevel3HiiHandle, Node->FileName);
|
||||
ShellStatus = SHELL_NOT_FOUND;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// do it
|
||||
//
|
||||
Status = TypeFileByHandle(Node->Handle, AsciiMode, UnicodeMode);
|
||||
if (EFI_ERROR(Status)) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TYP_ERROR), gShellLevel3HiiHandle, Node->FileName, Status);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
}
|
||||
ASSERT(ShellStatus == SHELL_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// Free the fileList
|
||||
//
|
||||
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
|
||||
Status = ShellCloseFileMetaArg(&FileList);
|
||||
}
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
FileList = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
if (ShellGetExecutionBreakFlag()) {
|
||||
return (SHELL_ABORTED);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
@@ -0,0 +1,94 @@
|
||||
/** @file
|
||||
Main file for NULL named library for level 3 shell command functions.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
CONST CHAR16 gShellLevel3FileName[] = L"ShellCommands";
|
||||
EFI_HANDLE gShellLevel3HiiHandle = NULL;
|
||||
STATIC CONST EFI_GUID gShellLevel3HiiGuid = \
|
||||
{ \
|
||||
0x4344558d, 0x4ef9, 0x4725, { 0xb1, 0xe4, 0x33, 0x76, 0xe8, 0xd6, 0x97, 0x4f } \
|
||||
};
|
||||
|
||||
CONST CHAR16*
|
||||
EFIAPI
|
||||
ShellCommandGetManFileNameLevel3 (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (gShellLevel3FileName);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructor for the Shell Level 3 Commands library.
|
||||
|
||||
Install the handlers for level 3 UEFI Shell 2.0 commands.
|
||||
|
||||
@param ImageHandle the image handle of the process
|
||||
@param SystemTable the EFI System Table pointer
|
||||
|
||||
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
|
||||
@retval EFI_UNSUPPORTED the shell level required was not found.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ShellLevel3CommandsLibConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
gShellLevel3HiiHandle = NULL;
|
||||
//
|
||||
// if shell level is less than 3 do nothing
|
||||
//
|
||||
if (PcdGet8(PcdShellSupportLevel) < 3) {
|
||||
return (EFI_UNSUPPORTED);
|
||||
}
|
||||
|
||||
gShellLevel3HiiHandle = HiiAddPackages (&gShellLevel3HiiGuid, gImageHandle, UefiShellLevel3CommandsLibStrings, NULL);
|
||||
if (gShellLevel3HiiHandle == NULL) {
|
||||
return (EFI_DEVICE_ERROR);
|
||||
}
|
||||
//
|
||||
// install our shell command handlers that are always installed
|
||||
//
|
||||
// Note: that Time, Timezone, and Date are part of level 2 library
|
||||
//
|
||||
ShellCommandRegisterCommandName(L"type", ShellCommandRunType , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_TYPE));
|
||||
ShellCommandRegisterCommandName(L"touch", ShellCommandRunTouch , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_TOUCH));
|
||||
ShellCommandRegisterCommandName(L"ver", ShellCommandRunVer , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_VER));
|
||||
ShellCommandRegisterCommandName(L"alias", ShellCommandRunAlias , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_ALIAS));
|
||||
ShellCommandRegisterCommandName(L"cls", ShellCommandRunCls , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_CLS));
|
||||
ShellCommandRegisterCommandName(L"echo", ShellCommandRunEcho , ShellCommandGetManFileNameLevel3, 3, L"", FALSE, gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_ECHO));
|
||||
ShellCommandRegisterCommandName(L"pause", ShellCommandRunPause , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_PAUSE));
|
||||
ShellCommandRegisterCommandName(L"getmtc", ShellCommandRunGetMtc , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_GETMTC));
|
||||
ShellCommandRegisterCommandName(L"help", ShellCommandRunHelp , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_HELP));
|
||||
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Destructor for the library. free any resources.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ShellLevel3CommandsLibDestructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
if (gShellLevel3HiiHandle != NULL) {
|
||||
HiiRemovePackages(gShellLevel3HiiHandle);
|
||||
}
|
||||
return (EFI_SUCCESS);
|
||||
}
|
@@ -0,0 +1,156 @@
|
||||
/** @file
|
||||
header file for NULL named library for level 3 shell command functions.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <ShellBase.h>
|
||||
|
||||
#include <Protocol/EfiShell.h>
|
||||
#include <Protocol/EfiShellParameters.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Protocol/UnicodeCollation.h>
|
||||
#include <Protocol/DevicePathToText.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/ShellCommandLib.h>
|
||||
#include <Library/ShellLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/HiiLib.h>
|
||||
#include <Library/FileHandleLib.h>
|
||||
|
||||
extern EFI_HANDLE gShellLevel3HiiHandle;
|
||||
|
||||
/**
|
||||
Function for 'type' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunType (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'touch' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunTouch (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'ver' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunVer (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'alias' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunAlias (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'cls' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunCls (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'echo' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunEcho (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'pause' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunPause (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'getmtc' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunGetMtc (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
/**
|
||||
Function for 'help' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunHelp (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
@@ -0,0 +1,68 @@
|
||||
## @file
|
||||
# Provides shell level 3 functions
|
||||
# Note that the interactive versions of the time, date, and timezone functions are handled in the level 2 library.
|
||||
#
|
||||
# Copyright (c) 2009-2010, Intel Corporation. All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = UefiShellLevel3CommandsLib
|
||||
FILE_GUID = 71374B42-85D7-4753-AD17-AA84C3A0EB93
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
|
||||
CONSTRUCTOR = ShellLevel3CommandsLibConstructor
|
||||
DESTRUCTOR = ShellLevel3CommandsLibDestructor
|
||||
|
||||
[Sources.common]
|
||||
# note that time, timezone, and date are part of the level 2 library
|
||||
Type.c
|
||||
Touch.c
|
||||
Ver.c
|
||||
UefiShellLevel3CommandsLib.uni
|
||||
UefiShellLevel3CommandsLib.c
|
||||
UefiShellLevel3CommandsLib.h
|
||||
Cls.c
|
||||
Alias.c
|
||||
Echo.c
|
||||
Pause.c
|
||||
GetMtc.c
|
||||
Help.c
|
||||
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
MemoryAllocationLib
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
ShellCommandLib
|
||||
ShellLib
|
||||
UefiLib
|
||||
UefiRuntimeServicesTableLib
|
||||
UefiBootServicesTableLib
|
||||
PcdLib
|
||||
HiiLib
|
||||
FileHandleLib
|
||||
|
||||
[Guids]
|
||||
gEfiFileInfoGuid
|
||||
|
||||
[Pcd.common]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize
|
||||
|
Binary file not shown.
145
ShellPkg/Library/UefiShellLevel3CommandsLib/Ver.c
Normal file
145
ShellPkg/Library/UefiShellLevel3CommandsLib/Ver.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/** @file
|
||||
Main file for Ver shell level 3 function.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiShellLevel3CommandsLib.h"
|
||||
|
||||
#include <Library/ShellLib.h>
|
||||
|
||||
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||
{L"-s", TypeFlag},
|
||||
{L"-terse", TypeFlag},
|
||||
{L"-t", TypeFlag},
|
||||
{L"-_pa", TypeFlag},
|
||||
{NULL, TypeMax}
|
||||
};
|
||||
|
||||
/**
|
||||
Function for 'ver' command.
|
||||
|
||||
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
||||
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
||||
**/
|
||||
SHELL_STATUS
|
||||
EFIAPI
|
||||
ShellCommandRunVer (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
SHELL_STATUS ShellStatus;
|
||||
UINT8 Level;
|
||||
|
||||
Level = PcdGet8(PcdShellSupportLevel);
|
||||
ProblemParam = NULL;
|
||||
ShellStatus = SHELL_SUCCESS;
|
||||
|
||||
//
|
||||
// initialize the shell lib (we must be in non-auto-init...)
|
||||
//
|
||||
Status = ShellInitialize();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
Status = CommandInit();
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
|
||||
//
|
||||
// parse the command line
|
||||
//
|
||||
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
||||
FreePool(ProblemParam);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// check for "-?"
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-?")) {
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
|
||||
//
|
||||
// we have too many parameters
|
||||
//
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
|
||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||
} else {
|
||||
if (ShellCommandLineGetFlag(Package, L"-s")) {
|
||||
ShellPrintHiiEx (
|
||||
0,
|
||||
gST->ConOut->Mode->CursorRow,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_VER_OUTPUT_SIMPLE),
|
||||
gShellLevel3HiiHandle,
|
||||
gEfiShellProtocol->MajorVersion,
|
||||
gEfiShellProtocol->MinorVersion
|
||||
);
|
||||
} else {
|
||||
ShellPrintHiiEx (
|
||||
0,
|
||||
gST->ConOut->Mode->CursorRow,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_VER_OUTPUT_SHELL),
|
||||
gShellLevel3HiiHandle,
|
||||
SupportLevel[Level],
|
||||
gEfiShellProtocol->MajorVersion,
|
||||
gEfiShellProtocol->MinorVersion
|
||||
);
|
||||
if (!ShellCommandLineGetFlag(Package, L"-terse") && !ShellCommandLineGetFlag(Package, L"-t")){
|
||||
ShellPrintHiiEx(
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_VER_EXTRA_STRING),
|
||||
gShellLevel3HiiHandle
|
||||
);
|
||||
|
||||
|
||||
ShellPrintHiiEx (
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
STRING_TOKEN (STR_VER_OUTPUT_UEFI),
|
||||
gShellLevel3HiiHandle,
|
||||
(gST->Hdr.Revision&0xffff0000)>>16,
|
||||
(gST->Hdr.Revision&0x0000ffff),
|
||||
gST->FirmwareVendor,
|
||||
gST->FirmwareRevision
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
// implementation specific support for displaying processor architecture
|
||||
//
|
||||
if (ShellCommandLineGetFlag(Package, L"-_pa")) {
|
||||
ShellPrintEx(-1, -1, L"%d\r\n", sizeof(UINTN)==sizeof(UINT64)?64:32);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// free the command line package
|
||||
//
|
||||
ShellCommandLineFreeVarList (Package);
|
||||
}
|
||||
|
||||
return (ShellStatus);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
## @file
|
||||
## @file
|
||||
# Provides interface to shell functionality for shell commands and applications.
|
||||
#
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
@@ -27,7 +27,7 @@
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
[Sources.common]
|
||||
UefiShellLib.c
|
||||
UefiShellLib.h
|
||||
|
||||
@@ -63,6 +63,6 @@
|
||||
gEfiFileInfoGuid # ALWAYS_CONSUMED
|
||||
gEfiShellEnvironment2ExtGuid # ALWAYS_CONSUMED
|
||||
|
||||
[Pcd]
|
||||
[Pcd.common]
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize # ALWAYS_CONSUMED
|
||||
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Library used for sorting routines.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
@@ -71,7 +71,7 @@ QuickSortWorker (
|
||||
|
||||
if ( Count < 2
|
||||
|| ElementSize < 1
|
||||
){
|
||||
){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ QuickSortWorker (
|
||||
for ( LoopCount = 0
|
||||
; LoopCount < Count -1
|
||||
; LoopCount++
|
||||
){
|
||||
){
|
||||
//
|
||||
// if the element is less than the pivot
|
||||
//
|
||||
@@ -291,3 +291,24 @@ StringNoCaseCompare (
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Function to compare 2 strings.
|
||||
|
||||
@param[in] Buffer1 Pointer to String to compare (CHAR16**).
|
||||
@param[in] Buffer2 Pointer to second String to compare (CHAR16**).
|
||||
|
||||
@retval 0 Buffer1 equal to Buffer2.
|
||||
@return < 0 Buffer1 is less than Buffer2.
|
||||
@return > 0 Buffer1 is greater than Buffer2.
|
||||
**/
|
||||
INTN
|
||||
EFIAPI
|
||||
StringCompare (
|
||||
IN CONST VOID *Buffer1,
|
||||
IN CONST VOID *Buffer2
|
||||
)
|
||||
{
|
||||
return (StrCmp(
|
||||
*(CHAR16**)Buffer1,
|
||||
*(CHAR16**)Buffer2));
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## @file
|
||||
## @file
|
||||
# Library used for sorting routines.
|
||||
#
|
||||
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2009, 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
|
||||
@@ -19,13 +19,13 @@
|
||||
FILE_GUID = 4264A823-45A3-42db-B92C-AA078555CBD3
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = SORTLib|UEFI_APPLICATION UEFI_DRIVER
|
||||
LIBRARY_CLASS = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
[Sources.common]
|
||||
UefiSortLib.c
|
||||
|
||||
[Packages]
|
||||
@@ -46,4 +46,4 @@
|
||||
|
||||
[Guids]
|
||||
|
||||
[Pcd]
|
||||
[Pcd.common]
|
||||
|
Reference in New Issue
Block a user