);\r
}\r
\r
+/**\r
+ Enumerate all boot option descriptions and append " 2"/" 3"/... to make\r
+ unique description.\r
+\r
+ @param BootOptions Array of boot options.\r
+ @param BootOptionCount Count of boot options.\r
+**/\r
+VOID\r
+BmMakeBootOptionDescriptionUnique (\r
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r
+ UINTN BootOptionCount\r
+ )\r
+{\r
+ UINTN Base;\r
+ UINTN Index;\r
+ UINTN DescriptionSize;\r
+ UINTN MaxSuffixSize;\r
+ BOOLEAN *Visited;\r
+ UINTN MatchCount;\r
+\r
+ if (BootOptionCount == 0) {\r
+ return;\r
+ }\r
+\r
+ //\r
+ // Calculate the maximum buffer size for the number suffix.\r
+ // The initial sizeof (CHAR16) is for the blank space before the number.\r
+ //\r
+ MaxSuffixSize = sizeof (CHAR16);\r
+ for (Index = BootOptionCount; Index != 0; Index = Index / 10) {\r
+ MaxSuffixSize += sizeof (CHAR16);\r
+ }\r
+\r
+ Visited = AllocateZeroPool (sizeof (BOOLEAN) * BootOptionCount);\r
+ ASSERT (Visited != NULL);\r
+\r
+ for (Base = 0; Base < BootOptionCount; Base++) {\r
+ if (!Visited[Base]) {\r
+ MatchCount = 1;\r
+ Visited[Base] = TRUE;\r
+ DescriptionSize = StrSize (BootOptions[Base].Description);\r
+ for (Index = Base + 1; Index < BootOptionCount; Index++) {\r
+ if (!Visited[Index] && StrCmp (BootOptions[Base].Description, BootOptions[Index].Description) == 0) {\r
+ Visited[Index] = TRUE;\r
+ MatchCount++;\r
+ FreePool (BootOptions[Index].Description);\r
+ BootOptions[Index].Description = AllocatePool (DescriptionSize + MaxSuffixSize);\r
+ UnicodeSPrint (\r
+ BootOptions[Index].Description, DescriptionSize + MaxSuffixSize,\r
+ L"%s %d",\r
+ BootOptions[Base].Description, MatchCount\r
+ );\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ FreePool (Visited);\r
+}\r
+\r
/**\r
Emuerate all possible bootable medias in the following order:\r
1. Removable BlockIo - The boot option only points to the removable media\r
FreePool (Handles);\r
}\r
\r
+ BmMakeBootOptionDescriptionUnique (BootOptions, *BootOptionCount);\r
return BootOptions;\r
}\r
\r