-/*++\r
-Copyright (c) 2004 - 2008, Intel Corporation\r
+/** @file\r
+ Provide boot option support for Application "BootMaint"\r
+\r
+ Include file system navigation, system handle selection\r
+\r
+ Boot option manipulation\r
+\r
+Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
-Module Name:\r
-\r
- bootoption.c\r
-\r
-Abstract:\r
-\r
- Provide boot option support for Application "BootMaint"\r
-\r
- Include file system navigation, system handle selection\r
+**/\r
\r
- Boot option manipulation\r
+#include "BootMaint.h"\r
+#include "BBSsupport.h"\r
\r
-Revision History\r
+/**\r
+ Create a menu entry give a Menu type.\r
\r
---*/\r
+ @param MenuType The Menu type to be created.\r
\r
-#include "BootMaint.h"\r
-#include "BBSsupport.h"\r
+ @retval NULL If failed to create the menu.\r
+ @return The menu.\r
\r
+**/\r
BM_MENU_ENTRY *\r
BOpt_CreateMenuEntry (\r
UINTN MenuType\r
)\r
-/*++\r
-\r
-Routine Description\r
- Create Menu Entry for future use, make all types together\r
- in order to reduce code size\r
-\r
-Arguments:\r
- MenuType Use this parameter to identify current\r
- Menu type\r
-\r
-Returns:\r
- NULL Cannot allocate memory for current menu\r
- entry\r
- Others A valid pointer pointing to the allocated\r
- memory pool for current menu entry\r
-\r
---*/\r
{\r
BM_MENU_ENTRY *MenuEntry;\r
UINTN ContextSize;\r
\r
+ //\r
+ // Get context size according to menu type\r
+ //\r
switch (MenuType) {\r
case BM_LOAD_CONTEXT_SELECT:\r
ContextSize = sizeof (BM_LOAD_CONTEXT);\r
default:\r
ContextSize = 0;\r
break;\r
-\r
}\r
\r
- if (0 == ContextSize) {\r
+ if (ContextSize == 0) {\r
return NULL;\r
}\r
\r
- MenuEntry = EfiAllocateZeroPool (sizeof (BM_MENU_ENTRY));\r
+ //\r
+ // Create new menu entry\r
+ //\r
+ MenuEntry = AllocateZeroPool (sizeof (BM_MENU_ENTRY));\r
if (NULL == MenuEntry) {\r
return MenuEntry;\r
}\r
\r
- MenuEntry->VariableContext = EfiAllocateZeroPool (ContextSize);\r
+ MenuEntry->VariableContext = AllocateZeroPool (ContextSize);\r
if (NULL == MenuEntry->VariableContext) {\r
- SafeFreePool (MenuEntry);\r
- MenuEntry = NULL;\r
- return MenuEntry;\r
+ FreePool (MenuEntry);\r
+ return NULL;\r
}\r
\r
MenuEntry->Signature = BM_MENU_ENTRY_SIGNATURE;\r
return MenuEntry;\r
}\r
\r
+/**\r
+ Free up all resource allocated for a BM_MENU_ENTRY.\r
+\r
+ @param MenuEntry A pointer to BM_MENU_ENTRY.\r
+\r
+**/\r
VOID\r
BOpt_DestroyMenuEntry (\r
BM_MENU_ENTRY *MenuEntry\r
)\r
-/*++\r
- Routine Description :\r
- Destroy the menu entry passed in\r
-\r
- Arguments :\r
- The menu entry need to be destroyed\r
-\r
- Returns :\r
- None\r
-\r
---*/\r
{\r
BM_LOAD_CONTEXT *LoadContext;\r
BM_FILE_CONTEXT *FileContext;\r
switch (MenuEntry->ContextSelection) {\r
case BM_LOAD_CONTEXT_SELECT:\r
LoadContext = (BM_LOAD_CONTEXT *) MenuEntry->VariableContext;\r
- SafeFreePool (LoadContext->FilePathList);\r
- SafeFreePool (LoadContext->LoadOption);\r
- SafeFreePool (LoadContext->OptionalData);\r
- SafeFreePool (LoadContext);\r
+ FreePool (LoadContext->FilePathList);\r
+ FreePool (LoadContext->LoadOption);\r
+ if (LoadContext->OptionalData != NULL) {\r
+ FreePool (LoadContext->OptionalData);\r
+ }\r
+ FreePool (LoadContext);\r
break;\r
\r
case BM_FILE_CONTEXT_SELECT:\r
FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext;\r
\r
if (!FileContext->IsRoot) {\r
- SafeFreePool (FileContext->DevicePath);\r
+ FreePool (FileContext->DevicePath);\r
} else {\r
if (FileContext->FHandle != NULL) {\r
FileContext->FHandle->Close (FileContext->FHandle);\r
}\r
}\r
\r
- SafeFreePool (FileContext->FileName);\r
- SafeFreePool (FileContext->Info);\r
- SafeFreePool (FileContext);\r
+ if (FileContext->FileName != NULL) {\r
+ FreePool (FileContext->FileName);\r
+ }\r
+ if (FileContext->Info != NULL) {\r
+ FreePool (FileContext->Info);\r
+ }\r
+ FreePool (FileContext);\r
break;\r
\r
case BM_CONSOLE_CONTEXT_SELECT:\r
ConsoleContext = (BM_CONSOLE_CONTEXT *) MenuEntry->VariableContext;\r
- SafeFreePool (ConsoleContext->DevicePath);\r
- SafeFreePool (ConsoleContext);\r
+ FreePool (ConsoleContext->DevicePath);\r
+ FreePool (ConsoleContext);\r
break;\r
\r
case BM_TERMINAL_CONTEXT_SELECT:\r
TerminalContext = (BM_TERMINAL_CONTEXT *) MenuEntry->VariableContext;\r
- SafeFreePool (TerminalContext->DevicePath);\r
- SafeFreePool (TerminalContext);\r
+ FreePool (TerminalContext->DevicePath);\r
+ FreePool (TerminalContext);\r
break;\r
\r
case BM_HANDLE_CONTEXT_SELECT:\r
HandleContext = (BM_HANDLE_CONTEXT *) MenuEntry->VariableContext;\r
- SafeFreePool (HandleContext);\r
+ FreePool (HandleContext);\r
break;\r
\r
case BM_LEGACY_DEV_CONTEXT_SELECT:\r
LegacyDevContext = (BM_LEGACY_DEVICE_CONTEXT *) MenuEntry->VariableContext;\r
- SafeFreePool (LegacyDevContext);\r
+ FreePool (LegacyDevContext);\r
\r
default:\r
break;\r
}\r
\r
- SafeFreePool (MenuEntry->DisplayString);\r
+ FreePool (MenuEntry->DisplayString);\r
if (NULL != MenuEntry->HelpString) {\r
- SafeFreePool (MenuEntry->HelpString);\r
+ FreePool (MenuEntry->HelpString);\r
}\r
\r
- SafeFreePool (MenuEntry);\r
+ FreePool (MenuEntry);\r
}\r
\r
+/**\r
+ Get the Menu Entry from the list in Menu Entry List.\r
+\r
+ If MenuNumber is great or equal to the number of Menu\r
+ Entry in the list, then ASSERT.\r
+\r
+ @param MenuOption The Menu Entry List to read the menu entry.\r
+ @param MenuNumber The index of Menu Entry.\r
+\r
+ @return The Menu Entry.\r
+\r
+**/\r
BM_MENU_ENTRY *\r
BOpt_GetMenuEntry (\r
BM_MENU_OPTION *MenuOption,\r
UINTN MenuNumber\r
)\r
-/*++\r
- Rountine Description :\r
- Use this routine to get one particular menu entry in specified\r
- menu\r
-\r
- Arguments :\r
- MenuOption The menu that we will search\r
-\r
- MenuNumber The menunubmer that we want\r
-\r
- Returns :\r
- The desired menu entry\r
-\r
---*/\r
{\r
BM_MENU_ENTRY *NewMenuEntry;\r
UINTN Index;\r
LIST_ENTRY *List;\r
\r
- if (MenuNumber >= MenuOption->MenuNumber) {\r
- return NULL;\r
- }\r
+ ASSERT (MenuNumber < MenuOption->MenuNumber);\r
\r
List = MenuOption->Head.ForwardLink;\r
for (Index = 0; Index < MenuNumber; Index++) {\r
return NewMenuEntry;\r
}\r
\r
+/**\r
+ This function build the FsOptionMenu list which records all\r
+ available file system in the system. They includes all instances\r
+ of EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, all instances of EFI_LOAD_FILE_SYSTEM\r
+ and all type of legacy boot device.\r
+\r
+ @param CallbackData BMM context data\r
+\r
+ @retval EFI_SUCCESS Success find the file system\r
+ @retval EFI_OUT_OF_RESOURCES Can not create menu entry\r
+\r
+**/\r
EFI_STATUS\r
BOpt_FindFileSystem (\r
IN BMM_CALLBACK_DATA *CallbackData\r
)\r
-/*++\r
-\r
-Routine Description\r
- Find file systems for current Extensible Firmware\r
- Including Handles that support Simple File System\r
- protocol, Load File protocol.\r
-\r
- Building up the FileSystem Menu for user selection\r
- All file system will be stored in FsOptionMenu\r
- for future use.\r
-\r
-Arguments:\r
- CallbackData - BMM context data\r
-\r
-Returns:\r
- EFI_SUCCESS - Success find the file system\r
- EFI_OUT_OF_RESOURCES - Can not create menu entry\r
-\r
---*/\r
{\r
UINTN NoBlkIoHandles;\r
UINTN NoSimpleFsHandles;\r
// Issue a dummy read to trigger reinstall of BlockIo protocol for removable media\r
//\r
if (BlkIo->Media->RemovableMedia) {\r
- Buffer = EfiAllocateZeroPool (BlkIo->Media->BlockSize);\r
+ Buffer = AllocateZeroPool (BlkIo->Media->BlockSize);\r
if (NULL == Buffer) {\r
- SafeFreePool (BlkIoHandle);\r
+ FreePool (BlkIoHandle);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
BlkIo->Media->BlockSize,\r
Buffer\r
);\r
- SafeFreePool (Buffer);\r
+ FreePool (Buffer);\r
}\r
}\r
- SafeFreePool (BlkIoHandle);\r
+ FreePool (BlkIoHandle);\r
}\r
\r
//\r
//\r
MenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT);\r
if (NULL == MenuEntry) {\r
- SafeFreePool (SimpleFsHandle);\r
+ FreePool (SimpleFsHandle);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
FileContext->Handle = SimpleFsHandle[Index];\r
MenuEntry->OptionNumber = Index;\r
FileContext->FHandle = EfiLibOpenRoot (FileContext->Handle);\r
- if (!FileContext->FHandle) {\r
+ if (FileContext->FHandle == NULL) {\r
BOpt_DestroyMenuEntry (MenuEntry);\r
continue;\r
}\r
}\r
\r
TempStr = MenuEntry->HelpString;\r
- MenuEntry->DisplayString = EfiAllocateZeroPool (MAX_CHAR);\r
+ MenuEntry->DisplayString = AllocateZeroPool (MAX_CHAR);\r
ASSERT (MenuEntry->DisplayString != NULL);\r
UnicodeSPrint (\r
MenuEntry->DisplayString,\r
}\r
\r
if (NoSimpleFsHandles != 0) {\r
- SafeFreePool (SimpleFsHandle);\r
+ FreePool (SimpleFsHandle);\r
}\r
//\r
// Searching for handles that support Load File protocol\r
for (Index = 0; Index < NoLoadFileHandles; Index++) {\r
MenuEntry = BOpt_CreateMenuEntry (BM_FILE_CONTEXT_SELECT);\r
if (NULL == MenuEntry) {\r
- SafeFreePool (LoadFileHandle);\r
+ FreePool (LoadFileHandle);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
MenuEntry->HelpString = DevicePathToStr (FileContext->DevicePath);\r
\r
TempStr = MenuEntry->HelpString;\r
- MenuEntry->DisplayString = EfiAllocateZeroPool (MAX_CHAR);\r
+ MenuEntry->DisplayString = AllocateZeroPool (MAX_CHAR);\r
ASSERT (MenuEntry->DisplayString != NULL);\r
UnicodeSPrint (\r
MenuEntry->DisplayString,\r
}\r
\r
if (NoLoadFileHandles != 0) {\r
- SafeFreePool (LoadFileHandle);\r
+ FreePool (LoadFileHandle);\r
}\r
\r
//\r
MenuEntry->HelpString = DevicePathToStr (FileContext->DevicePath);\r
\r
TempStr = MenuEntry->HelpString;\r
- MenuEntry->DisplayString = EfiAllocateZeroPool (MAX_CHAR);\r
+ MenuEntry->DisplayString = AllocateZeroPool (MAX_CHAR);\r
ASSERT (MenuEntry->DisplayString != NULL);\r
UnicodeSPrint (\r
MenuEntry->DisplayString,\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Free resources allocated in Allocate Rountine.\r
+\r
+ @param FreeMenu Menu to be freed\r
+**/\r
VOID\r
BOpt_FreeMenu (\r
BM_MENU_OPTION *FreeMenu\r
)\r
-/*++\r
-\r
-Routine Description\r
- Free resources allocated in Allocate Rountine\r
-\r
-Arguments:\r
- FreeMenu Menu to be freed\r
-\r
-Returns:\r
- VOID\r
-\r
---*/\r
{\r
BM_MENU_ENTRY *MenuEntry;\r
while (!IsListEmpty (&FreeMenu->Head)) {\r
}\r
}\r
\r
-EFI_STATUS\r
-BOpt_FindFiles (\r
- IN BMM_CALLBACK_DATA *CallbackData,\r
- IN BM_MENU_ENTRY *MenuEntry\r
- )\r
-/*++\r
-\r
-Routine Description\r
+/**\r
Find files under current directory\r
All files and sub-directories in current directory\r
will be stored in DirectoryMenu for future use.\r
\r
-Arguments:\r
- FileOption -- Pointer for Dir to explore\r
+ @param CallbackData The BMM context data.\r
+ @param MenuEntry The Menu Entry.\r
\r
-Returns:\r
- TRUE -- Get files from current dir successfully\r
- FALSE -- Can't get files from current dir\r
+ @retval EFI_SUCCESS Get files from current dir successfully.\r
+ @return Other value if can't get files from current dir.\r
\r
---*/\r
+**/\r
+EFI_STATUS\r
+BOpt_FindFiles (\r
+ IN BMM_CALLBACK_DATA *CallbackData,\r
+ IN BM_MENU_ENTRY *MenuEntry\r
+ )\r
{\r
EFI_FILE_HANDLE NewDir;\r
EFI_FILE_HANDLE Dir;\r
}\r
\r
DirInfo = EfiLibFileInfo (NewDir);\r
- if (!DirInfo) {\r
+ if (DirInfo == NULL) {\r
return EFI_NOT_FOUND;\r
}\r
\r
);\r
\r
DirBufferSize = sizeof (EFI_FILE_INFO) + 1024;\r
- DirInfo = EfiAllocateZeroPool (DirBufferSize);\r
- if (!DirInfo) {\r
+ DirInfo = AllocateZeroPool (DirBufferSize);\r
+ if (DirInfo == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
//\r
\r
if (NewFileContext->IsDir) {\r
BufferSize = StrLen (DirInfo->FileName) * 2 + 6;\r
- NewMenuEntry->DisplayString = EfiAllocateZeroPool (BufferSize);\r
+ NewMenuEntry->DisplayString = AllocateZeroPool (BufferSize);\r
\r
UnicodeSPrint (\r
NewMenuEntry->DisplayString,\r
}\r
\r
DirectoryMenu.MenuNumber = OptionNumber;\r
- SafeFreePool (DirInfo);\r
+ FreePool (DirInfo);\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Build the LegacyFDMenu LegacyHDMenu LegacyCDMenu according to LegacyBios.GetBbsInfo().\r
+\r
+ @retval EFI_SUCCESS The function complete successfully.\r
+ @retval EFI_OUT_OF_RESOURCES No enough memory to complete this function.\r
+\r
+**/\r
EFI_STATUS\r
BOpt_GetLegacyOptions (\r
VOID\r
)\r
-/*++\r
-Routine Description:\r
-\r
- Build the LegacyFDMenu LegacyHDMenu LegacyCDMenu according to LegacyBios.GetBbsInfo().\r
-\r
-Arguments:\r
- None\r
-\r
-Returns:\r
- The device info of legacy device.\r
-\r
---*/\r
{\r
BM_MENU_ENTRY *NewMenuEntry;\r
BM_LEGACY_DEVICE_CONTEXT *NewLegacyDevContext;\r
sizeof (DescString),\r
DescString\r
);\r
- NewLegacyDevContext->Description = EfiAllocateZeroPool (StrSize (DescString));\r
+ NewLegacyDevContext->Description = AllocateZeroPool (StrSize (DescString));\r
if (NULL == NewLegacyDevContext->Description) {\r
break;\r
}\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Free out resouce allocated from Legacy Boot Options.\r
+\r
+**/\r
VOID\r
BOpt_FreeLegacyOptions (\r
VOID\r
BOpt_FreeMenu (&LegacyBEVMenu);\r
}\r
\r
-EFI_STATUS\r
-BOpt_GetBootOptions (\r
- IN BMM_CALLBACK_DATA *CallbackData\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
Build the BootOptionMenu according to BootOrder Variable.\r
- This Routine will access the Boot#### to get EFI_LOAD_OPTION\r
+ This Routine will access the Boot#### to get EFI_LOAD_OPTION.\r
\r
-Arguments:\r
- None\r
+ @param CallbackData The BMM context data.\r
\r
-Returns:\r
- The number of the Var Boot####\r
+ @return The number of the Var Boot####.\r
\r
---*/\r
+**/\r
+EFI_STATUS\r
+BOpt_GetBootOptions (\r
+ IN BMM_CALLBACK_DATA *CallbackData\r
+ )\r
{\r
UINTN Index;\r
UINT16 BootString[10];\r
&BootNextSize\r
);\r
\r
- if (BootNext) {\r
+ if (BootNext != NULL) {\r
if (BootNextSize != sizeof (UINT16)) {\r
- SafeFreePool (BootNext);\r
+ FreePool (BootNext);\r
BootNext = NULL;\r
}\r
}\r
&gEfiGlobalVariableGuid,\r
&BootOptionSize\r
);\r
- if (!LoadOptionFromVar) {\r
+ if (LoadOptionFromVar == NULL) {\r
continue;\r
}\r
\r
- LoadOption = EfiAllocateZeroPool (BootOptionSize);\r
- if (!LoadOption) {\r
+ LoadOption = AllocateZeroPool (BootOptionSize);\r
+ if (LoadOption == NULL) {\r
continue;\r
}\r
\r
CopyMem (LoadOption, LoadOptionFromVar, BootOptionSize);\r
- SafeFreePool (LoadOptionFromVar);\r
+ FreePool (LoadOptionFromVar);\r
\r
- if (BootNext) {\r
+ if (BootNext != NULL) {\r
BootNextFlag = (BOOLEAN) (*BootNext == BootOrderList[Index]);\r
} else {\r
BootNextFlag = FALSE;\r
}\r
\r
if (0 == (*((UINT32 *) LoadOption) & LOAD_OPTION_ACTIVE)) {\r
- SafeFreePool (LoadOption);\r
+ FreePool (LoadOption);\r
continue;\r
}\r
//\r
LoadOptionPtr += sizeof (UINT16);\r
\r
StringSize = StrSize ((UINT16 *) LoadOptionPtr);\r
- NewLoadContext->Description = EfiAllocateZeroPool (StringSize);\r
+ NewLoadContext->Description = AllocateZeroPool (StringSize);\r
ASSERT (NewLoadContext->Description != NULL);\r
CopyMem (\r
NewLoadContext->Description,\r
\r
LoadOptionPtr += StringSize;\r
\r
- NewLoadContext->FilePathList = EfiAllocateZeroPool (NewLoadContext->FilePathListLength);\r
+ NewLoadContext->FilePathList = AllocateZeroPool (NewLoadContext->FilePathListLength);\r
ASSERT (NewLoadContext->FilePathList != NULL);\r
CopyMem (\r
NewLoadContext->FilePathList,\r
StringSize -\r
NewLoadContext->FilePathListLength;\r
\r
- NewLoadContext->OptionalData = EfiAllocateZeroPool (OptionalDataSize);\r
+ NewLoadContext->OptionalData = AllocateZeroPool (OptionalDataSize);\r
ASSERT (NewLoadContext->OptionalData != NULL);\r
CopyMem (\r
NewLoadContext->OptionalData,\r
MenuCount++;\r
}\r
\r
- SafeFreePool (BootNext);\r
- SafeFreePool (BootOrderList);\r
+ if (BootNext != NULL) {\r
+ FreePool (BootNext);\r
+ }\r
+ if (BootOrderList != NULL) {\r
+ FreePool (BootOrderList);\r
+ }\r
BootOptionMenu.MenuNumber = MenuCount;\r
return MenuCount;\r
}\r
\r
-CHAR16 *\r
-BdsStrCpy (\r
- OUT CHAR16 *Destination,\r
- IN CONST CHAR16 *Source\r
- )\r
-{\r
- CHAR16 *ReturnValue;\r
+/**\r
\r
- //\r
- // Destination cannot be NULL\r
- //\r
- ASSERT (Destination != NULL);\r
+ Append file name to existing file name.\r
\r
- ReturnValue = Destination;\r
- while (*Source) {\r
- *(Destination++) = *(Source++);\r
- }\r
- *Destination = 0;\r
- return ReturnValue;\r
-}\r
+ @param Str1 The existing file name\r
+ @param Str2 The file name to be appended\r
+\r
+ @return Allocate a new string to hold the appended result.\r
+ Caller is responsible to free the returned string.\r
\r
+**/\r
CHAR16 *\r
BOpt_AppendFileName (\r
IN CHAR16 *Str1,\r
IN CHAR16 *Str2\r
)\r
-/*++\r
-\r
-Routine Description\r
- Append file name to existing file name.\r
-\r
-Arguments:\r
- Str1 - existing file name\r
- Str2 - file name to be appended\r
-\r
-Returns:\r
- Allocate a new string to hold the appended result.\r
- Caller is responsible to free the returned string.\r
-\r
---*/\r
{\r
UINTN Size1;\r
UINTN Size2;\r
CHAR16 *Str;\r
+ CHAR16 *TmpStr;\r
CHAR16 *Ptr;\r
CHAR16 *LastSlash;\r
\r
Size1 = StrSize (Str1);\r
Size2 = StrSize (Str2);\r
- Str = EfiAllocateZeroPool (Size1 + Size2 + sizeof (CHAR16));\r
+ Str = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16));\r
ASSERT (Str != NULL);\r
\r
+ TmpStr = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16)); \r
+ ASSERT (TmpStr != NULL);\r
+\r
StrCat (Str, Str1);\r
if (!((*Str == '\\') && (*(Str + 1) == 0))) {\r
StrCat (Str, L"\\");\r
Ptr = Str;\r
LastSlash = Str;\r
while (*Ptr != 0) {\r
- if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '.' && *(Ptr + 3) != 0) {\r
+ if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '.' && *(Ptr + 3) == L'\\') {\r
//\r
- // Convert \Name\..\ to \\r
+ // Convert "\Name\..\" to "\"\r
// DO NOT convert the .. if it is at the end of the string. This will\r
// break the .. behavior in changing directories.\r
//\r
- BdsStrCpy (LastSlash, Ptr + 3);\r
+\r
+ //\r
+ // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings \r
+ // that overlap.\r
+ //\r
+ StrCpy (TmpStr, Ptr + 3);\r
+ StrCpy (LastSlash, TmpStr);\r
Ptr = LastSlash;\r
} else if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '\\') {\r
//\r
- // Convert a \.\ to a \\r
+ // Convert a "\.\" to a "\"\r
+ //\r
+\r
+ //\r
+ // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings \r
+ // that overlap.\r
//\r
- BdsStrCpy (Ptr, Ptr + 2);\r
+ StrCpy (TmpStr, Ptr + 2);\r
+ StrCpy (Ptr, TmpStr);\r
Ptr = LastSlash;\r
} else if (*Ptr == '\\') {\r
LastSlash = Ptr;\r
Ptr++;\r
}\r
\r
+ FreePool (TmpStr);\r
+ \r
return Str;\r
}\r
\r
-BOOLEAN\r
-BOpt_IsEfiImageName (\r
- IN UINT16 *FileName\r
- )\r
-/*++\r
+/**\r
\r
-Routine Description\r
Check whether current FileName point to a valid\r
Efi Image File.\r
\r
-Arguments:\r
- FileName - File need to be checked.\r
+ @param FileName File need to be checked.\r
\r
-Returns:\r
- TRUE - Is Efi Image\r
- FALSE - Not a valid Efi Image\r
+ @retval TRUE Is Efi Image\r
+ @retval FALSE Not a valid Efi Image\r
\r
---*/\r
+**/\r
+BOOLEAN\r
+BOpt_IsEfiImageName (\r
+ IN UINT16 *FileName\r
+ )\r
{\r
//\r
// Search for ".efi" extension\r
//\r
- while (*FileName) {\r
+ while (*FileName != L'\0') {\r
if (FileName[0] == '.') {\r
if (FileName[1] == 'e' || FileName[1] == 'E') {\r
if (FileName[2] == 'f' || FileName[2] == 'F') {\r
return FALSE;\r
}\r
\r
-BOOLEAN\r
-BOpt_IsEfiApp (\r
- IN EFI_FILE_HANDLE Dir,\r
- IN UINT16 *FileName\r
- )\r
-/*++\r
+/**\r
\r
-Routine Description:\r
Check whether current FileName point to a valid Efi Application\r
\r
-Arguments:\r
- Dir - Pointer to current Directory\r
- FileName - Pointer to current File name.\r
+ @param Dir Pointer to current Directory\r
+ @param FileName Pointer to current File name.\r
\r
-Returns:\r
- TRUE - Is a valid Efi Application\r
- FALSE - not a valid Efi Application\r
+ @retval TRUE Is a valid Efi Application\r
+ @retval FALSE not a valid Efi Application\r
\r
---*/\r
+**/\r
+BOOLEAN\r
+BOpt_IsEfiApp (\r
+ IN EFI_FILE_HANDLE Dir,\r
+ IN UINT16 *FileName\r
+ )\r
{\r
UINTN BufferSize;\r
EFI_IMAGE_DOS_HEADER DosHdr;\r
}\r
}\r
\r
-EFI_STATUS\r
-BOpt_FindDrivers (\r
- VOID\r
- )\r
-/*++\r
+/**\r
\r
-Routine Description\r
Find drivers that will be added as Driver#### variables from handles\r
in current system environment\r
All valid handles in the system except those consume SimpleFs, LoadFile\r
are stored in DriverMenu for future use.\r
\r
-Arguments:\r
- None\r
-\r
-Returns:\r
- EFI_SUCCESS\r
- Others\r
+ @retval EFI_SUCCESS The function complets successfully.\r
+ @return Other value if failed to build the DriverMenu.\r
\r
---*/\r
+**/\r
+EFI_STATUS\r
+BOpt_FindDrivers (\r
+ VOID\r
+ )\r
{\r
UINTN NoDevicePathHandles;\r
EFI_HANDLE *DevicePathHandle;\r
for (Index = 0; Index < NoDevicePathHandles; Index++) {\r
CurHandle = DevicePathHandle[Index];\r
\r
- //\r
- // Check whether this handle support\r
- // driver binding\r
- //\r
Status = gBS->HandleProtocol (\r
CurHandle,\r
&gEfiSimpleFileSystemProtocolGuid,\r
\r
NewMenuEntry = BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT);\r
if (NULL == NewMenuEntry) {\r
- SafeFreePool (DevicePathHandle);\r
+ FreePool (DevicePathHandle);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
InsertTailList (&DriverMenu.Head, &NewMenuEntry->Link);\r
\r
}\r
- SafeFreePool (DevicePathHandle);\r
+\r
+ if (DevicePathHandle != NULL) {\r
+ FreePool (DevicePathHandle);\r
+ }\r
\r
DriverMenu.MenuNumber = OptionNumber;\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+\r
+ Get the Option Number that has not been allocated for use.\r
+\r
+ @return The available Option Number.\r
+\r
+**/\r
UINT16\r
BOpt_GetBootOptionNumber (\r
VOID\r
)\r
-/*++\r
-\r
-Routine Description:\r
- Get the Option Number that does not used\r
-\r
-Arguments:\r
-\r
-Returns:\r
- The Option Number\r
-\r
---*/\r
{\r
BM_MENU_ENTRY *NewMenuEntry;\r
UINT16 *BootOrderList;\r
&gEfiGlobalVariableGuid,\r
&BootOrderListSize\r
);\r
- if (BootOrderList) {\r
+ if (BootOrderList != NULL) {\r
//\r
// already have Boot####\r
//\r
}\r
\r
if (Found) {\r
- UnicodeSPrint (StrTemp, 100, L"Boot%04x", Index);\r
- DEBUG((DEBUG_ERROR,"INdex= %s\n", StrTemp));\r
- OptionBuffer = BdsLibGetVariableAndSize (\r
- StrTemp,\r
- &gEfiGlobalVariableGuid,\r
- &OptionSize\r
- );\r
- if (NULL == OptionBuffer)\r
- break;\r
+ UnicodeSPrint (StrTemp, 100, L"Boot%04x", Index);\r
+ DEBUG((DEBUG_ERROR,"INdex= %s\n", StrTemp));\r
+ OptionBuffer = BdsLibGetVariableAndSize (\r
+ StrTemp,\r
+ &gEfiGlobalVariableGuid,\r
+ &OptionSize\r
+ );\r
+ if (NULL == OptionBuffer) {\r
+ break;\r
+ }\r
}\r
}\r
//\r
return Number;\r
}\r
\r
+/**\r
+\r
+ Get the Option Number that is not in use.\r
+\r
+ @return The unused Option Number.\r
+\r
+**/\r
UINT16\r
BOpt_GetDriverOptionNumber (\r
VOID\r
)\r
-/*++\r
-\r
-Routine Description:\r
- Get the Option Number that does not used\r
-\r
-Arguments:\r
-\r
-Returns:\r
- The Option Number\r
-\r
---*/\r
{\r
BM_MENU_ENTRY *NewMenuEntry;\r
UINT16 *DriverOrderList;\r
&gEfiGlobalVariableGuid,\r
&DriverOrderListSize\r
);\r
- if (DriverOrderList) {\r
+ if (DriverOrderList != NULL) {\r
//\r
// already have Driver####\r
//\r
return Number;\r
}\r
\r
-EFI_STATUS\r
-BOpt_GetDriverOptions (\r
- IN BMM_CALLBACK_DATA *CallbackData\r
- )\r
-/*++\r
+/**\r
\r
-Routine Description:\r
Build up all DriverOptionMenu\r
\r
-Arguments:\r
+ @param CallbackData The BMM context data.\r
\r
-Returns:\r
- The Option Number\r
+ @return EFI_SUCESS The functin completes successfully.\r
+ @retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.\r
+ \r
\r
---*/\r
+**/\r
+EFI_STATUS\r
+BOpt_GetDriverOptions (\r
+ IN BMM_CALLBACK_DATA *CallbackData\r
+ )\r
{\r
UINTN Index;\r
UINT16 DriverString[12];\r
&gEfiGlobalVariableGuid,\r
&DriverOptionSize\r
);\r
- if (!LoadOptionFromVar) {\r
+ if (LoadOptionFromVar == NULL) {\r
continue;\r
}\r
\r
- LoadOption = EfiAllocateZeroPool (DriverOptionSize);\r
- if (!LoadOption) {\r
+ LoadOption = AllocateZeroPool (DriverOptionSize);\r
+ if (LoadOption == NULL) {\r
continue;\r
}\r
\r
CopyMem (LoadOption, LoadOptionFromVar, DriverOptionSize);\r
- SafeFreePool (LoadOptionFromVar);\r
+ FreePool (LoadOptionFromVar);\r
\r
NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);\r
if (NULL == NewMenuEntry) {\r
LoadOptionPtr += sizeof (UINT16);\r
\r
StringSize = StrSize ((UINT16 *) LoadOptionPtr);\r
- NewLoadContext->Description = EfiAllocateZeroPool (StringSize);\r
+ NewLoadContext->Description = AllocateZeroPool (StringSize);\r
ASSERT (NewLoadContext->Description != NULL);\r
CopyMem (\r
NewLoadContext->Description,\r
\r
LoadOptionPtr += StringSize;\r
\r
- NewLoadContext->FilePathList = EfiAllocateZeroPool (NewLoadContext->FilePathListLength);\r
+ NewLoadContext->FilePathList = AllocateZeroPool (NewLoadContext->FilePathListLength);\r
ASSERT (NewLoadContext->FilePathList != NULL);\r
CopyMem (\r
NewLoadContext->FilePathList,\r
StringSize -\r
NewLoadContext->FilePathListLength;\r
\r
- NewLoadContext->OptionalData = EfiAllocateZeroPool (OptionalDataSize);\r
+ NewLoadContext->OptionalData = AllocateZeroPool (OptionalDataSize);\r
ASSERT (NewLoadContext->OptionalData != NULL);\r
CopyMem (\r
NewLoadContext->OptionalData,\r
\r
}\r
\r
- SafeFreePool (DriverOrderList);\r
+ if (DriverOrderList != NULL) {\r
+ FreePool (DriverOrderList);\r
+ }\r
DriverOptionMenu.MenuNumber = Index;\r
return EFI_SUCCESS;\r
\r