Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.3 KiB

  1. #include <efisbent.h>
  2. #include <tchar.h>
  3. #include <stdlib.h>
  4. VOID
  5. TraceResult(
  6. IN PWSTR Feature,
  7. IN BOOLEAN Result
  8. )
  9. {
  10. wprintf(L"%ws : %ws\n", Feature, Result ? L"Passed" : L"Failed");
  11. if (!Result) {
  12. exit(0);
  13. }
  14. }
  15. VOID
  16. DumpFilePath(
  17. IN PFILE_PATH FilePath
  18. )
  19. {
  20. if (FilePath) {
  21. wprintf(L"%d:%ws\n",
  22. FilePath->Type,
  23. FilePath->FilePath);
  24. }
  25. }
  26. VOID
  27. DumpOsBootEntry(
  28. IN POS_BOOT_ENTRY Entry
  29. )
  30. {
  31. if (Entry) {
  32. wprintf(L"%0d=>%ws,(%ws,%ws),(%ws,%ws),%ws\n",
  33. OSBEGetId(Entry),
  34. OSBEGetFriendlyName(Entry),
  35. OSBEGetOsLoaderVolumeName(Entry),
  36. OSBEGetOsLoaderPath(Entry),
  37. OSBEGetBootVolumeName(Entry),
  38. OSBEGetBootPath(Entry),
  39. OSBEGetOsLoadOptions(Entry)
  40. );
  41. }
  42. }
  43. VOID
  44. DumpOsBootOptions(
  45. IN POS_BOOT_OPTIONS Options
  46. )
  47. {
  48. if (Options) {
  49. ULONG Index;
  50. POS_BOOT_ENTRY Entry = OSBOGetFirstBootEntry(Options, &Index);
  51. wprintf(L"\n");
  52. while (Entry) {
  53. DumpOsBootEntry(Entry);
  54. Entry = OSBOGetNextBootEntry(Options, &Index);
  55. }
  56. for (Index=0;
  57. Index < OSBOGetOrderedBootEntryCount(Options);
  58. Index++) {
  59. wprintf(L"%04d,", OSBOGetBootEntryIdByOrder(Options, Index));
  60. }
  61. wprintf(L"\n\n");
  62. }
  63. }
  64. INT
  65. __cdecl
  66. main(
  67. IN INT Argc,
  68. IN CHAR *Argv[]
  69. )
  70. {
  71. POS_BOOT_OPTIONS OsBootOptions = NULL;
  72. POS_BOOT_ENTRY NewEntry;
  73. POS_BOOT_ENTRY ActiveBootEntry;
  74. POS_BOOT_ENTRY ConvertedEntry;
  75. OsBootOptions = EFIOSBOCreate();
  76. TraceResult(L"Creating EFI OS BootOptions", (OsBootOptions != NULL));
  77. DumpOsBootOptions(OsBootOptions);
  78. //
  79. // Add test
  80. //
  81. NewEntry = OSBOAddNewBootEntry(OsBootOptions,
  82. L"Add Testing",
  83. L"\\Device\\HarddiskVolume1",
  84. L"\\setupldr.efi",
  85. L"\\Device\\HarddiskVolume3",
  86. L"\\WINDOWS",
  87. L"/dummy1 /dummy2");
  88. TraceResult(L"Add test : ", (NewEntry != NULL));
  89. DumpOsBootEntry(NewEntry);
  90. //
  91. // Search test
  92. //
  93. ActiveBootEntry = OSBOFindBootEntry(OsBootOptions, 10);
  94. TraceResult(L"Getting boot entry 0", (ActiveBootEntry != NULL));
  95. DumpOsBootEntry(ActiveBootEntry);
  96. //
  97. // Get active test
  98. //
  99. ActiveBootEntry = OSBOGetActiveBootEntry(OsBootOptions);
  100. TraceResult(L"Getting active boot entry", (ActiveBootEntry != NULL));
  101. DumpOsBootEntry(ActiveBootEntry);
  102. //
  103. // Set active test
  104. //
  105. ActiveBootEntry = OSBOSetActiveBootEntry(OsBootOptions, NewEntry);
  106. TraceResult(L"Setting active boot entry", (ActiveBootEntry != NULL));
  107. ActiveBootEntry = OSBOGetActiveBootEntry(OsBootOptions);
  108. TraceResult(L"Getting active boot entry again", (ActiveBootEntry != NULL));
  109. DumpOsBootEntry(ActiveBootEntry);
  110. DumpOsBootOptions(OsBootOptions);
  111. //
  112. // Delete boot entry test
  113. //
  114. TraceResult(L"Deleting new boot entry",
  115. OSBODeleteBootEntry(OsBootOptions, NewEntry));
  116. DumpOsBootOptions(OsBootOptions);
  117. OSBODelete(OsBootOptions);
  118. }