ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r
\r
AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);\r
+ ASSERT (AlignedNode != NULL);\r
\r
// File Path Device Path Nodes 'can optionally add a "\" separator to\r
// the beginning and/or the end of the Path Name string.'\r
return (EFI_NOT_FOUND);\r
}\r
\r
- Status = InternalOpenFileDevicePath(DevicePath, FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, FileAttribs); // 0 = no specific file attributes\r
+ Status = InternalOpenFileDevicePath(DevicePath, FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, FileAttribs);\r
FreePool(DevicePath);\r
\r
return(Status);\r
}\r
\r
+/**\r
+ Register a GUID and a localized human readable name for it.\r
+\r
+ If Guid is not assigned a name, then assign GuidName to Guid. This list of GUID\r
+ names must be used whenever a shell command outputs GUID information.\r
+\r
+ This function is only available when the major and minor versions in the\r
+ EfiShellProtocol are greater than or equal to 2 and 1, respectively.\r
+\r
+ @param[in] Guid A pointer to the GUID being registered.\r
+ @param[in] GuidName A pointer to the localized name for the GUID being registered.\r
+\r
+ @retval EFI_SUCCESS The operation was successful.\r
+ @retval EFI_INVALID_PARAMETER Guid was NULL.\r
+ @retval EFI_INVALID_PARAMETER GuidName was NULL.\r
+ @retval EFI_ACCESS_DENIED Guid already is assigned a name.\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+EfiShellRegisterGuidName(\r
+ IN CONST EFI_GUID *Guid,\r
+ IN CONST CHAR16 *GuidName\r
+ )\r
+{\r
+ return (AddNewGuidNameMapping(Guid, GuidName, NULL));\r
+}\r
+\r
/**\r
Opens a file or a directory by file name.\r
\r
SHELL_FILE_HANDLE FileHandle;\r
EFI_STATUS Status;\r
\r
+ FileHandle = NULL;\r
+\r
//\r
// get a handle to the file\r
//\r
/**\r
internal worker function to load and run an image via device path.\r
\r
- @param ParentImageHandle A handle of the image that is executing the specified\r
- command line.\r
- @param DevicePath device path of the file to execute\r
- @param CommandLine Points to the NULL-terminated UCS-2 encoded string\r
- containing the command line. If NULL then the command-\r
- line will be empty.\r
- @param Environment Points to a NULL-terminated array of environment\r
- variables with the format 'x=y', where x is the\r
- environment variable name and y is the value. If this\r
- is NULL, then the current shell environment is used.\r
-\r
- @param[out] ExitDataSize ExitDataSize as returned from gBS->StartImage\r
- @param[out] ExitData ExitData as returned from gBS->StartImage\r
+ @param ParentImageHandle A handle of the image that is executing the specified\r
+ command line.\r
+ @param DevicePath device path of the file to execute\r
+ @param CommandLine Points to the NULL-terminated UCS-2 encoded string\r
+ containing the command line. If NULL then the command-\r
+ line will be empty.\r
+ @param Environment Points to a NULL-terminated array of environment\r
+ variables with the format 'x=y', where x is the\r
+ environment variable name and y is the value. If this\r
+ is NULL, then the current shell environment is used.\r
+ \r
+ @param[out] StartImageStatus Returned status from gBS->StartImage.\r
+ @param[out] ExitDataSize ExitDataSize as returned from gBS->StartImage\r
+ @param[out] ExitData ExitData as returned from gBS->StartImage\r
\r
@retval EFI_SUCCESS The command executed successfully. The status code\r
returned by the command is pointed to by StatusCode.\r
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
IN CONST CHAR16 *CommandLine OPTIONAL,\r
IN CONST CHAR16 **Environment OPTIONAL,\r
+ OUT EFI_STATUS *StartImageStatus OPTIONAL,\r
OUT UINTN *ExitDataSize OPTIONAL,\r
OUT CHAR16 **ExitData OPTIONAL\r
)\r
{\r
EFI_STATUS Status;\r
+ EFI_STATUS StartStatus;\r
EFI_STATUS CleanupStatus;\r
EFI_HANDLE NewHandle;\r
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
// now start the image, passing up exit data if the caller requested it\r
//\r
if (!EFI_ERROR(Status)) {\r
- Status = gBS->StartImage(\r
+ StartStatus = gBS->StartImage(\r
NewHandle,\r
ExitDataSizePtr,\r
ExitData\r
);\r
+ if (StartImageStatus != NULL) {\r
+ *StartImageStatus = StartStatus;\r
+ }\r
\r
CleanupStatus = gBS->UninstallProtocolInterface(\r
NewHandle,\r
DevPath,\r
Temp,\r
(CONST CHAR16**)Environment,\r
+ StatusCode,\r
&ExitDataSize,\r
&ExitData);\r
\r
}\r
FreePool (ExitData);\r
Status = EFI_SUCCESS;\r
- } else if ((StatusCode != NULL) && !EFI_ERROR(Status)) {\r
- *StatusCode = EFI_SUCCESS;\r
}\r
\r
//\r
}\r
return (EFI_SUCCESS);\r
}\r
+\r
+//\r
+// This is the same structure as the external version, but it has no CONST qualifiers.\r
+//\r
+typedef struct {\r
+ LIST_ENTRY Link; ///< Linked list members.\r
+ EFI_STATUS Status; ///< Status of opening the file. Valid only if Handle != NULL.\r
+ CHAR16 *FullName; ///< Fully qualified filename.\r
+ CHAR16 *FileName; ///< name of this file.\r
+ SHELL_FILE_HANDLE Handle; ///< Handle for interacting with the opened file or NULL if closed.\r
+ EFI_FILE_INFO *Info; ///< Pointer to the FileInfo struct for this file or NULL.\r
+} EFI_SHELL_FILE_INFO_NO_CONST;\r
+\r
/**\r
Allocates and duplicates a EFI_SHELL_FILE_INFO node.\r
\r
IN BOOLEAN Save\r
)\r
{\r
- EFI_SHELL_FILE_INFO *NewNode;\r
+ EFI_SHELL_FILE_INFO_NO_CONST *NewNode;\r
+\r
+ //\r
+ // try to confirm that the objects are in sync\r
+ //\r
+ ASSERT(sizeof(EFI_SHELL_FILE_INFO_NO_CONST) == sizeof(EFI_SHELL_FILE_INFO));\r
\r
NewNode = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
if (NewNode == NULL) {\r
if ( NewNode->FullName == NULL\r
|| NewNode->FileName == NULL\r
|| NewNode->Info == NULL\r
- ){\r
+ ){\r
+ SHELL_FREE_NON_NULL(NewNode->FullName);\r
+ SHELL_FREE_NON_NULL(NewNode->FileName);\r
+ SHELL_FREE_NON_NULL(NewNode->Info);\r
+ SHELL_FREE_NON_NULL(NewNode);\r
return(NULL);\r
}\r
NewNode->Status = Node->Status;\r
StrCpy((CHAR16*)NewNode->FileName, Node->FileName);\r
CopyMem(NewNode->Info, Node->Info, (UINTN)Node->Info->Size);\r
\r
- return(NewNode);\r
+ return((EFI_SHELL_FILE_INFO*)NewNode);\r
}\r
\r
/**\r
TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);\r
if (TempString == NULL) {\r
FreePool((VOID*)ShellFileListItem->FileName);\r
- FreePool(ShellFileListItem->Info);\r
+ SHELL_FREE_NON_NULL(ShellFileListItem->Info);\r
FreePool(ShellFileListItem);\r
return (NULL);\r
}\r
}\r
}\r
\r
+ TempString = PathCleanUpDirectories(TempString);\r
+\r
ShellFileListItem->FullName = TempString;\r
ShellFileListItem->Status = Status;\r
ShellFileListItem->Handle = Handle;\r
UINTN Size;\r
CHAR16 *TempSpot;\r
\r
+ BasePath = NULL;\r
Status = FileHandleGetFileName(FileDirHandle, &BasePath);\r
if (EFI_ERROR(Status)) {\r
return (Status);\r
return(Status);\r
}\r
\r
+/**\r
+ Get the GUID value from a human readable name.\r
+\r
+ If GuidName is a known GUID name, then update Guid to have the correct value for\r
+ that GUID.\r
+\r
+ This function is only available when the major and minor versions in the\r
+ EfiShellProtocol are greater than or equal to 2 and 1, respectively.\r
+\r
+ @param[in] GuidName A pointer to the localized name for the GUID being queried.\r
+ @param[out] Guid A pointer to the GUID structure to be filled in.\r
+\r
+ @retval EFI_SUCCESS The operation was successful.\r
+ @retval EFI_INVALID_PARAMETER Guid was NULL.\r
+ @retval EFI_INVALID_PARAMETER GuidName was NULL.\r
+ @retval EFI_NOT_FOUND GuidName is not a known GUID Name.\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+EfiShellGetGuidFromName(\r
+ IN CONST CHAR16 *GuidName,\r
+ OUT EFI_GUID *Guid\r
+ )\r
+{\r
+ EFI_GUID *NewGuid;\r
+ EFI_STATUS Status;\r
+\r
+ if (Guid == NULL || GuidName == NULL) {\r
+ return (EFI_INVALID_PARAMETER);\r
+ }\r
+ \r
+ Status = GetGuidFromStringName(GuidName, NULL, &NewGuid);\r
+\r
+ if (!EFI_ERROR(Status)) {\r
+ CopyGuid(NewGuid, Guid);\r
+ }\r
+\r
+ return (Status);\r
+}\r
+\r
+/**\r
+ Get the human readable name for a GUID from the value.\r
+\r
+ If Guid is assigned a name, then update *GuidName to point to the name. The callee\r
+ should not modify the value.\r
+\r
+ This function is only available when the major and minor versions in the\r
+ EfiShellProtocol are greater than or equal to 2 and 1, respectively.\r
+\r
+ @param[in] Guid A pointer to the GUID being queried.\r
+ @param[out] GuidName A pointer to a pointer the localized to name for the GUID being requested\r
+\r
+ @retval EFI_SUCCESS The operation was successful.\r
+ @retval EFI_INVALID_PARAMETER Guid was NULL.\r
+ @retval EFI_INVALID_PARAMETER GuidName was NULL.\r
+ @retval EFI_NOT_FOUND Guid is not assigned a name.\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+EfiShellGetGuidName(\r
+ IN CONST EFI_GUID *Guid,\r
+ OUT CONST CHAR16 **GuidName\r
+ )\r
+{\r
+ CHAR16 *Name;\r
+\r
+ if (Guid == NULL || GuidName == NULL) {\r
+ return (EFI_INVALID_PARAMETER);\r
+ }\r
+\r
+ Name = GetStringNameFromGuid(Guid, NULL);\r
+ if (Name == NULL || StrLen(Name) == 0) {\r
+ SHELL_FREE_NON_NULL(Name);\r
+ return (EFI_NOT_FOUND);\r
+ }\r
+\r
+ *GuidName = AddBufferToFreeList(Name);\r
+\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
/**\r
Updates a file name to be preceeded by the mapped drive name\r
\r
EFI_SHELL_FILE_INFO *ShellInfo;\r
EFI_SHELL_FILE_INFO *ShellInfoNode;\r
EFI_SHELL_FILE_INFO *NewShellNode;\r
+ EFI_FILE_INFO *FileInfo;\r
BOOLEAN Directory;\r
CHAR16 *NewFullName;\r
UINTN Size;\r
\r
if (CurrentFilePattern[0] == CHAR_NULL\r
&&NextFilePatternStart[0] == CHAR_NULL\r
- ){\r
+ ){\r
//\r
- // Add the current parameter FileHandle to the list, then end...\r
+ // we want the parent or root node (if no parent)\r
//\r
if (ParentNode == NULL) {\r
- Status = EFI_INVALID_PARAMETER;\r
+ //\r
+ // We want the root node. create the node.\r
+ //\r
+ FileInfo = FileHandleGetInfo(FileHandle);\r
+ NewShellNode = CreateAndPopulateShellFileInfo(\r
+ MapName,\r
+ EFI_SUCCESS,\r
+ L"\\",\r
+ FileHandle,\r
+ FileInfo\r
+ );\r
+ SHELL_FREE_NON_NULL(FileInfo);\r
} else {\r
+ //\r
+ // Add the current parameter FileHandle to the list, then end...\r
+ //\r
NewShellNode = InternalDuplicateShellFileInfo((EFI_SHELL_FILE_INFO*)ParentNode, TRUE);\r
- if (NewShellNode == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- } else {\r
- NewShellNode->Handle = NULL;\r
- if (*FileList == NULL) {\r
- *FileList = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
- InitializeListHead(&((*FileList)->Link));\r
- }\r
+ }\r
+ if (NewShellNode == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ } else {\r
+ NewShellNode->Handle = NULL;\r
+ if (*FileList == NULL) {\r
+ *FileList = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+ InitializeListHead(&((*FileList)->Link));\r
+ }\r
\r
- //\r
- // Add to the returning to use list\r
- //\r
- InsertTailList(&(*FileList)->Link, &NewShellNode->Link);\r
+ //\r
+ // Add to the returning to use list\r
+ //\r
+ InsertTailList(&(*FileList)->Link, &NewShellNode->Link);\r
\r
- Status = EFI_SUCCESS;\r
- }\r
+ Status = EFI_SUCCESS;\r
}\r
} else {\r
Status = EfiShellFindFilesInDir(FileHandle, &ShellInfo);\r
}\r
\r
/**\r
- This function updated with errata.\r
-\r
- Gets either a single or list of environment variables.\r
-\r
- If name is not NULL then this function returns the current value of the specified\r
- environment variable.\r
-\r
- If Name is NULL, then a list of all environment variable names is returned. Each is a\r
- NULL terminated string with a double NULL terminating the list.\r
-\r
- @param Name A pointer to the environment variable name. If\r
- Name is NULL, then the function will return all\r
- of the defined shell environment variables. In\r
- the case where multiple environment variables are\r
- being returned, each variable will be terminated by\r
- a NULL, and the list will be terminated by a double\r
- NULL.\r
-\r
- @return !=NULL A pointer to the returned string.\r
- The returned pointer does not need to be freed by the caller.\r
-\r
- @retval NULL The environment variable doesn't exist or there are\r
- no environment variables.\r
+ Gets the environment variable and Attributes, or list of environment variables. Can be\r
+ used instead of GetEnv().\r
+\r
+ This function returns the current value of the specified environment variable and\r
+ the Attributes. If no variable name was specified, then all of the known\r
+ variables will be returned.\r
+\r
+ @param[in] Name A pointer to the environment variable name. If Name is NULL,\r
+ then the function will return all of the defined shell\r
+ environment variables. In the case where multiple environment\r
+ variables are being returned, each variable will be terminated\r
+ by a NULL, and the list will be terminated by a double NULL.\r
+ @param[out] Attributes If not NULL, a pointer to the returned attributes bitmask for\r
+ the environment variable. In the case where Name is NULL, and\r
+ multiple environment variables are being returned, Attributes\r
+ is undefined.\r
+\r
+ @retval NULL The environment variable doesn't exist.\r
+ @return A non-NULL value points to the variable's value. The returned\r
+ pointer does not need to be freed by the caller.\r
**/\r
CONST CHAR16 *\r
-EFIAPI\r
-EfiShellGetEnv(\r
- IN CONST CHAR16 *Name\r
+EFIAPI \r
+EfiShellGetEnvEx(\r
+ IN CONST CHAR16 *Name,\r
+ OUT UINT32 *Attributes OPTIONAL\r
)\r
{\r
EFI_STATUS Status;\r
//\r
// get the size we need for this EnvVariable\r
//\r
- Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);\r
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name, Attributes, &Size, Buffer);\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
//\r
// Allocate the space and recall the get function\r
//\r
Buffer = AllocateZeroPool(Size);\r
ASSERT(Buffer != NULL);\r
- Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);\r
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name, Attributes, &Size, Buffer);\r
}\r
//\r
// we didnt get it (might not exist)\r
return (AddBufferToFreeList(Buffer));\r
}\r
\r
+/**\r
+ Gets either a single or list of environment variables.\r
+\r
+ If name is not NULL then this function returns the current value of the specified\r
+ environment variable.\r
+\r
+ If Name is NULL, then a list of all environment variable names is returned. Each is a\r
+ NULL terminated string with a double NULL terminating the list.\r
+\r
+ @param Name A pointer to the environment variable name. If\r
+ Name is NULL, then the function will return all\r
+ of the defined shell environment variables. In\r
+ the case where multiple environment variables are\r
+ being returned, each variable will be terminated by\r
+ a NULL, and the list will be terminated by a double\r
+ NULL.\r
+\r
+ @retval !=NULL A pointer to the returned string.\r
+ The returned pointer does not need to be freed by the caller.\r
+\r
+ @retval NULL The environment variable doesn't exist or there are\r
+ no environment variables.\r
+**/\r
+CONST CHAR16 *\r
+EFIAPI\r
+EfiShellGetEnv(\r
+ IN CONST CHAR16 *Name\r
+ )\r
+{\r
+ return (EfiShellGetEnvEx(Name, NULL));\r
+}\r
+\r
/**\r
Internal variable setting function. Allows for setting of the read only variables.\r
\r
/**\r
Convert a null-terminated unicode string, in-place, to all lowercase.\r
Then return it.\r
+ \r
+ @param Str The null-terminated string to be converted to all lowercase.\r
+ \r
+ @return The null-terminated string converted into all lowercase. \r
**/\r
-STATIC\r
-CHAR16 *\r
+STATIC CHAR16 *\r
ToLower (\r
CHAR16 *Str\r
)\r
\r
// Pure FILE_HANDLE operations are passed to FileHandleLib\r
// these functions are indicated by the *\r
-EFI_SHELL_PROTOCOL mShellProtocol = {\r
+EFI_SHELL_PROTOCOL21 mShellProtocol = {\r
EfiShellExecute,\r
EfiShellGetEnv,\r
EfiShellSetEnv,\r
EfiShellOpenRoot,\r
EfiShellOpenRootByHandle,\r
NULL,\r
- SHELL_MAJOR_VERSION,\r
- SHELL_MINOR_VERSION\r
+ 2, // SHELL_MAJOR_VERSION,\r
+ 1, // SHELL_MINOR_VERSION,\r
+\r
+ // New for UEFI Shell 2.1\r
+ EfiShellRegisterGuidName,\r
+ EfiShellGetGuidName,\r
+ EfiShellGetGuidFromName,\r
+ EfiShellGetEnvEx\r
};\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
CreatePopulateInstallShellProtocol (\r
- IN OUT EFI_SHELL_PROTOCOL **NewShell\r
+ IN OUT EFI_SHELL_PROTOCOL21 **NewShell\r
)\r
{\r
EFI_STATUS Status;\r
EFI_STATUS\r
EFIAPI\r
CleanUpShellProtocol (\r
- IN OUT EFI_SHELL_PROTOCOL *NewShell\r
+ IN OUT EFI_SHELL_PROTOCOL21 *NewShell\r
)\r
{\r
EFI_STATUS Status;\r
}\r
return (Status);\r
}\r
+\r