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.

2998 lines
80 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. regboot.c
  5. Abstract:
  6. Provides a minimal registry implementation designed to be used by the
  7. osloader at boot time. This includes loading the system hive
  8. ( <SystemRoot>\config\SYSTEM ) into memory, and computing the driver
  9. load list from it.
  10. Author:
  11. John Vert (jvert) 10-Mar-1992
  12. Revision History:
  13. Doug Fritz (dFritz) 07-Oct-1997 & KenRay Feb 98
  14. - Filter hardware profiles based on detected hardware
  15. configuration (docking station) information
  16. --*/
  17. #include "bldr.h"
  18. #include "msg.h"
  19. #include "cmp.h"
  20. #include "stdio.h"
  21. #include "string.h"
  22. #include <dockinfo.h>
  23. #include <netboot.h>
  24. #ifdef i386
  25. #include "bldrx86.h"
  26. #endif
  27. #if defined(_IA64_)
  28. #include "bldria64.h"
  29. #endif
  30. #ifdef _WANT_MACHINE_IDENTIFICATION
  31. #include <stdlib.h>
  32. #include <ntverp.h>
  33. #endif
  34. #include "bldrint.h"
  35. #include "vmode.h"
  36. CMHIVE BootHive;
  37. ULONG CmLogLevel=100;
  38. ULONG CmLogSelect=0;
  39. ULONG ScreenWidth=80;
  40. #ifdef EFI
  41. ULONG ScreenHeight=24;
  42. #else
  43. ULONG ScreenHeight=25;
  44. #endif
  45. ULONG LkgStartTime;
  46. //
  47. // used by the advanced boot screen to force a LKG boot
  48. //
  49. BOOLEAN ForceLastKnownGood;
  50. //
  51. // Variable used to check whether to display
  52. // "Return to OS Choices Menu" or not in adv. boot
  53. //
  54. BOOLEAN BlShowReturnToOSChoices = TRUE;
  55. VOID
  56. BlRedrawProgressBar(
  57. VOID
  58. );
  59. VOID
  60. BlOutputStartupMsg(
  61. ULONG uMsgID
  62. );
  63. ULONG
  64. BlGetAdvancedBootID(
  65. LONG BootOption
  66. );
  67. //
  68. // Private function prototypes
  69. //
  70. BOOLEAN
  71. BlInitializeHive(
  72. IN PVOID HiveImage,
  73. IN PCMHIVE Hive,
  74. IN BOOLEAN IsAlternate
  75. );
  76. BOOLEAN
  77. BlpCheckRestartSetup(
  78. VOID
  79. );
  80. PVOID
  81. BlpHiveAllocate(
  82. IN ULONG Length,
  83. IN BOOLEAN UseForIo,
  84. ULONG Tag
  85. );
  86. VOID
  87. BlDockInfoFilterProfileList(
  88. IN OUT PCM_HARDWARE_PROFILE_LIST ProfileList,
  89. IN OUT PCM_HARDWARE_PROFILE_ALIAS_LIST AliasList
  90. );
  91. VOID
  92. BlStartConfigPrompt(
  93. VOID
  94. )
  95. /*++
  96. Routine Description:
  97. This routine displays the LKG prompt, records the current time,
  98. and returns. The prompt is displayed before the kernel and HAL
  99. are loaded, and then removed afterwards.
  100. Arguments:
  101. None.
  102. Return Value:
  103. None.
  104. --*/
  105. {
  106. ULONG Count;
  107. PTCHAR LkgPrompt;
  108. LkgPrompt = BlFindMessage(BL_LKG_MENU_PROMPT);
  109. if (LkgPrompt==NULL) {
  110. return;
  111. }
  112. //
  113. // display LKG prompt
  114. //
  115. #if 0
  116. BlPositionCursor(1,3);
  117. ArcWrite(BlConsoleOutDeviceId,
  118. LkgPrompt,
  119. _tcslen(LkgPrompt)*sizeof(TCHAR),
  120. &Count);
  121. BlPositionCursor(1,2);
  122. #endif
  123. LkgStartTime = ArcGetRelativeTime();
  124. #if defined(REMOTE_BOOT) && defined(i386)
  125. //
  126. // Wait to allow the user to type space or F8. If anything is typed then behave
  127. // conservatively and load the kernel, etc., from the server just in case CSC or
  128. // the local filesystem is broken.
  129. //
  130. if (BlBootingFromNet) {
  131. ULONG EndTime;
  132. ULONG Status;
  133. ULONG CurrentTime;
  134. EndTime = LkgStartTime + 3;
  135. if (EndTime <= ArcGetRelativeTime()) {
  136. EndTime = ArcGetRelativeTime()+1;
  137. }
  138. do {
  139. if (ArcGetReadStatus(ARC_CONSOLE_INPUT) == ESUCCESS) {
  140. //
  141. // There is a key pending, assume it is CSC related. If it isn't
  142. // CSC then it just means we laod a few extra files from the
  143. // server.
  144. //
  145. NetBootCSC = FALSE;
  146. break;
  147. }
  148. CurrentTime = ArcGetRelativeTime();
  149. //
  150. // Terminate the loop if the EndTime has been reached, or
  151. // if the CurrentTime has wrapped at midnight.
  152. //
  153. } while ((CurrentTime < EndTime) &&
  154. (CurrentTime >= LkgStartTime));
  155. }
  156. #endif // defined(REMOTE_BOOT) && defined(i386)
  157. }
  158. BOOLEAN
  159. BlEndConfigPrompt(
  160. VOID
  161. )
  162. /*++
  163. Routine Description:
  164. This routine waits until the LKG timeout has expired or the
  165. user presses a key and then removes the LKG prompt.
  166. Arguments:
  167. None.
  168. Return Value:
  169. TRUE - Space bar pressed.
  170. FALSE - Space bar was not pressed.
  171. --*/
  172. {
  173. ULONG EndTime;
  174. ULONG Count;
  175. ULONG Key;
  176. ULONG Status;
  177. ULONG CurrentTime;
  178. //
  179. // We do not wait for a keypress if there is not already one.
  180. //
  181. EndTime = 0;
  182. if( BlIsTerminalConnected() ) {
  183. //
  184. // If we're booting headless, give the user lots of time
  185. // to press any of the advanced options keys.
  186. //
  187. EndTime = ArcGetRelativeTime() + 5;
  188. }
  189. #if defined(REMOTE_BOOT) && defined(i386)
  190. //
  191. // If a key was detected and CSC turned off then re-enable CSC until
  192. // we find out if it should be disabled for this whole boot.
  193. //
  194. NetBootCSC = TRUE;
  195. #endif // defined(REMOTE_BOOT) && defined(i386)
  196. do {
  197. LONG AdvancedBoot = -1;
  198. BOOLEAN bOldState = BlShowReturnToOSChoices;
  199. BlShowReturnToOSChoices = FALSE;
  200. if ((Key = BlGetKey()) != 0) {
  201. //
  202. // return if the pending key was the spacebar.
  203. //
  204. if (Key == ' ') {
  205. return(TRUE);
  206. }
  207. //
  208. // look to see if the user pressed the F5 or F8 keys,
  209. // these keys trigger the advanced boot menu. the advanced
  210. // boot menu can also be entered from the main boot menu by
  211. // pressing the same keys.
  212. //
  213. if (Key == F5_KEY || Key == F8_KEY) {
  214. //
  215. // present the menu and get the user's request
  216. //
  217. LONG AdvancedBoot = -1;
  218. BOOLEAN bOldState = BlShowReturnToOSChoices;
  219. BlShowReturnToOSChoices = FALSE;
  220. if (DisplayLogoOnBoot) {
  221. if (!DbcsLangId)
  222. HW_CURSOR(0x80000000,0x3);
  223. else
  224. HW_CURSOR(0x80000000,0x12);
  225. }
  226. AdvancedBoot = BlDoAdvancedBoot( BL_ADVANCEDBOOT_TITLE, 0, FALSE, 0 );
  227. if (DisplayLogoOnBoot) {
  228. PSTR BootOption;
  229. if ((AdvancedBoot != -1) &&
  230. ((BootOption = BlGetAdvancedBootLoadOptions(AdvancedBoot)) != NULL ) &&
  231. (!strncmp("SAFEBOOT",BootOption,8))) {
  232. DisplayLogoOnBoot = FALSE; // on safe boot let the "Checking file system" message
  233. // appear as it appears today (in graphics mode)
  234. } else {
  235. #ifndef EFI
  236. HW_CURSOR(0x80000000,0x12);
  237. if (DbcsLangId)
  238. TextClearDisplay();
  239. VgaEnableVideo();
  240. PaletteOn();
  241. DrawBitmap ();
  242. BlUpdateBootStatus();
  243. #endif
  244. }
  245. }
  246. BlShowReturnToOSChoices = bOldState;
  247. if (AdvancedBoot != -1) {
  248. //
  249. // they chose a valid boot option so append
  250. // any os load options and perform any necessary
  251. // option processing.
  252. //
  253. PSTR NewOptions = BlGetAdvancedBootLoadOptions(AdvancedBoot);
  254. if( BlGetAdvancedBootID(AdvancedBoot) == BL_MSG_REBOOT ) {
  255. BlClearScreen();
  256. REBOOT_PROCESSOR();
  257. }
  258. if (NewOptions != NULL && strstr(BlLoaderBlock->LoadOptions,NewOptions) == NULL) {
  259. ULONG len = strlen(NewOptions) + // new options
  260. 1 + // seperated by a space
  261. strlen(BlLoaderBlock->LoadOptions) + // old options
  262. 1; // null terminator
  263. NewOptions = BlAllocateHeap(len * sizeof(PCHAR));
  264. strcpy(NewOptions,BlLoaderBlock->LoadOptions);
  265. strcat(NewOptions," ");
  266. strcat(NewOptions,BlGetAdvancedBootLoadOptions(AdvancedBoot));
  267. BlLoaderBlock->LoadOptions = NewOptions;
  268. DBGTRACE(TEXT("Load Options = %S"), BlLoaderBlock->LoadOptions);
  269. }
  270. BlDoAdvancedBootLoadProcessing(AdvancedBoot);
  271. }
  272. }
  273. }
  274. CurrentTime = ArcGetRelativeTime();
  275. //
  276. // Terminate the loop if the EndTime has been reached, or
  277. // if the CurrentTime has wrapped at midnight.
  278. //
  279. } while ((CurrentTime < EndTime) &&
  280. (CurrentTime >= LkgStartTime));
  281. //
  282. // make LKG prompt go away, so as not to startle the user.
  283. // remote the trailer & update progress bar
  284. //
  285. #if defined(_IA64_)
  286. BlOutputStartupMsg(BL_MSG_STARTING_WINDOWS);
  287. #endif
  288. BlRedrawProgressBar();
  289. return(FALSE);
  290. }
  291. VOID
  292. BlpSwitchControlSet(
  293. OUT PCM_HARDWARE_PROFILE_LIST *ProfileList,
  294. OUT PCM_HARDWARE_PROFILE_ALIAS_LIST *AliasList,
  295. IN BOOLEAN UseLastKnownGood,
  296. OUT PHCELL_INDEX ControlSet
  297. )
  298. /*++
  299. Routine Description:
  300. Switches the current control set to the specified control
  301. set and rebuilds the hardware profile list.
  302. Arguments:
  303. ProfileList - Returns the new hardware profile list
  304. UseLastKnownGood - Supplies whether the LKG control set is to be used.
  305. ControlSet - Returns the HCELL_INDEX of the new control set.
  306. Return Value:
  307. None.
  308. --*/
  309. {
  310. UNICODE_STRING ControlName;
  311. HCELL_INDEX NewControlSet;
  312. BOOLEAN AutoSelect; // ignored
  313. ULONG ProfileTimeout; // ignored
  314. //
  315. // Find the new control set.
  316. //
  317. if (UseLastKnownGood) {
  318. RtlInitUnicodeString(&ControlName, L"LastKnownGood");
  319. } else {
  320. RtlInitUnicodeString(&ControlName, L"Default");
  321. }
  322. NewControlSet = CmpFindControlSet(&BootHive.Hive,
  323. BootHive.Hive.BaseBlock->RootCell,
  324. &ControlName,
  325. &AutoSelect);
  326. if (NewControlSet == HCELL_NIL) {
  327. return;
  328. }
  329. CmpFindProfileOption(&BootHive.Hive,
  330. NewControlSet,
  331. ProfileList,
  332. AliasList,
  333. NULL);
  334. *ControlSet = NewControlSet;
  335. }
  336. ULONG
  337. BlCountLines(
  338. IN PTCHAR Lines
  339. )
  340. /*++
  341. Routine Description:
  342. Counts the number of lines in the given string.
  343. Arguments:
  344. Lines - Supplies a pointer to the start of the string
  345. Return Value:
  346. The number of lines in the string.
  347. --*/
  348. {
  349. PTCHAR p;
  350. ULONG NumLines = 0;
  351. p=Lines;
  352. while (*p != TEXT('\0')) {
  353. if ((*p == TEXT('\r')) && (*(p+1) == TEXT('\n'))) {
  354. ++NumLines;
  355. ++p; // move forward to \n
  356. }
  357. ++p;
  358. }
  359. return(NumLines);
  360. }
  361. BOOLEAN
  362. BlConfigMenuPrompt(
  363. IN ULONG Timeout,
  364. IN OUT PBOOLEAN UseLastKnownGood,
  365. IN OUT PHCELL_INDEX ControlSet,
  366. OUT PCM_HARDWARE_PROFILE_LIST *ProfileList,
  367. OUT PCM_HARDWARE_PROFILE_ALIAS_LIST *AliasList,
  368. OUT PCM_HARDWARE_PROFILE *HardwareProfile
  369. )
  370. /*++
  371. Routine Description:
  372. This routine provides the user-interface for the configuration menu.
  373. The prompt is given if the user hits the break-in key, or if the
  374. LastKnownGood environment variable is TRUE and AutoSelect is FALSE, or
  375. if the timeout value on the hardware profile configuration is non-zero
  376. Arguments:
  377. Timeout - Supplies the timeout value for the menu. -1 or 0 implies the menu
  378. will never timeout.
  379. UseLastKnownGood - Returns the LastKnownGood setting that should be
  380. used for the boot.
  381. ControlSet - Returns the control set (either Default or LKG)
  382. ProfileList - Supplies the default list of profiles.
  383. Returns the current list of profiles.
  384. (may change due to switching to/from the LKG controlset)
  385. HardwareProfile - Returns the hardware profile that should be used.
  386. Return Value:
  387. TRUE - Boot should proceed.
  388. FALSE - The user has chosen to return to the firmware menu/flexboot menu.
  389. --*/
  390. {
  391. ULONG HeaderLines;
  392. ULONG TrailerLines;
  393. ULONG i;
  394. ULONG Count;
  395. ULONG flags;
  396. ULONG Key;
  397. PTCHAR MenuHeader;
  398. PTCHAR MenuTrailer1;
  399. PTCHAR MenuTrailer2;
  400. PTCHAR p;
  401. ULONG OptionLength;
  402. TCHAR MenuOption[80];
  403. PCM_HARDWARE_PROFILE Profile;
  404. ULONG ProfileCount;
  405. _TUCHAR LkgMnemonic;
  406. _TUCHAR DefaultMnemonic;
  407. PTCHAR Temp;
  408. ULONG DisplayLines;
  409. ULONG TopProfileLine=0;
  410. ULONG CurrentSelection = 0;
  411. ULONG CurrentProfile;
  412. ULONG EndTime;
  413. ULONG CurrentTime;
  414. PTCHAR TimeoutPrompt;
  415. if ((Timeout != (ULONG)-1) && (Timeout != 0)) {
  416. CurrentTime = ArcGetRelativeTime();
  417. EndTime = CurrentTime + Timeout;
  418. TimeoutPrompt = BlFindMessage(BL_LKG_TIMEOUT);
  419. if (TimeoutPrompt != NULL) {
  420. p=_tcschr(TimeoutPrompt, TEXT('\n'));
  421. if (p) {
  422. *p = TEXT('\0');
  423. }
  424. p=_tcschr(TimeoutPrompt, TEXT('\r'));
  425. if (p) {
  426. *p = TEXT('\0');
  427. }
  428. }
  429. } else {
  430. TimeoutPrompt = NULL;
  431. }
  432. MenuHeader = BlFindMessage(BL_LKG_MENU_HEADER);
  433. Temp = BlFindMessage(BL_LKG_SELECT_MNEMONIC);
  434. if (Temp == NULL) {
  435. return(TRUE);
  436. }
  437. LkgMnemonic = (_TUCHAR)_totupper(Temp[0]);
  438. Temp = BlFindMessage(BL_DEFAULT_SELECT_MNEMONIC);
  439. if (Temp == NULL) {
  440. return(TRUE);
  441. }
  442. DefaultMnemonic = (_TUCHAR)_totupper(Temp[0]);
  443. if ((*UseLastKnownGood) &&
  444. (*ProfileList) && ((*ProfileList)->CurrentProfileCount == 1)) {
  445. //
  446. // The user selected last known good via boot.ini/nvram/etc. Since this
  447. // was a concious decision, and we don't have more than one profile to
  448. // choose, just skip this UI altogether.
  449. //
  450. ASSERT(CurrentSelection == 0);
  451. goto ProcessSelection;
  452. }
  453. Restart:
  454. if (*ProfileList == NULL) {
  455. ProfileCount = 0;
  456. } else {
  457. ProfileCount = (*ProfileList)->CurrentProfileCount;
  458. }
  459. if (ProfileCount == 0) {
  460. MenuTrailer1 = BlFindMessage(BL_LKG_MENU_TRAILER_NO_PROFILES);
  461. } else {
  462. MenuTrailer1 = BlFindMessage(BL_LKG_MENU_TRAILER);
  463. }
  464. if (*UseLastKnownGood) {
  465. MenuTrailer2 = BlFindMessage(BL_SWITCH_DEFAULT_TRAILER);
  466. } else {
  467. MenuTrailer2 = BlFindMessage(BL_SWITCH_LKG_TRAILER);
  468. }
  469. if ((MenuHeader==NULL) || (MenuTrailer1==NULL) || (MenuTrailer2==NULL)) {
  470. return(TRUE);
  471. }
  472. //
  473. // strip trailing /r/n from MenuTrailer2 to prevent it from scrolling
  474. // the screen when we output it.
  475. //
  476. #if 0
  477. p=MenuTrailer2 + strlen(MenuTrailer2) - 1;
  478. while ((*p == TEXT('\r')) || (*p == TEXT('\n'))) {
  479. *p = TEXT('\0');
  480. --p;
  481. }
  482. #endif
  483. BlClearScreen();
  484. #ifdef EFI
  485. BlEfiSetAttribute( DEFATT );
  486. #else
  487. BlSetInverseMode(FALSE);
  488. #endif
  489. //
  490. // Count the number of lines in the header.
  491. //
  492. HeaderLines=BlCountLines(MenuHeader);
  493. //
  494. // Display the menu header.
  495. //
  496. ArcWrite(BlConsoleOutDeviceId,
  497. MenuHeader,
  498. _tcslen(MenuHeader)*sizeof(TCHAR),
  499. &Count);
  500. //
  501. // Count the number of lines in the trailer.
  502. //
  503. TrailerLines=BlCountLines(MenuTrailer1) + BlCountLines(MenuTrailer2);
  504. //
  505. // Display the trailing prompt.
  506. //
  507. if (TimeoutPrompt) {
  508. TrailerLines += 1;
  509. }
  510. BlPositionCursor(1, ScreenHeight-TrailerLines);
  511. ArcWrite(BlConsoleOutDeviceId,
  512. MenuTrailer1,
  513. _tcslen(MenuTrailer1)*sizeof(TCHAR),
  514. &Count);
  515. ArcWrite(BlConsoleOutDeviceId,
  516. MenuTrailer2,
  517. _tcslen(MenuTrailer2)*sizeof(TCHAR),
  518. &Count);
  519. //
  520. // Compute number of selections that can be displayed
  521. //
  522. DisplayLines = ScreenHeight-HeaderLines-TrailerLines-3;
  523. if (ProfileCount < DisplayLines) {
  524. DisplayLines = ProfileCount;
  525. }
  526. //
  527. // Start menu selection loop.
  528. //
  529. do {
  530. if (ProfileCount > 0) {
  531. //
  532. // Display options with current selection highlighted
  533. //
  534. for (i=0; i < DisplayLines; i++) {
  535. CurrentProfile = i+TopProfileLine;
  536. Profile = &(*ProfileList)->Profile[CurrentProfile];
  537. BlPositionCursor(5, HeaderLines+i+2);
  538. #ifdef EFI
  539. BlEfiSetAttribute( (CurrentProfile == CurrentSelection) ? INVATT : DEFATT );
  540. #else
  541. BlSetInverseMode((BOOLEAN)(CurrentProfile == CurrentSelection));
  542. #endif
  543. #ifdef UNICODE
  544. ArcWrite(BlConsoleOutDeviceId,
  545. Profile->FriendlyName,
  546. Profile->NameLength,
  547. &Count );
  548. #else
  549. RtlUnicodeToMultiByteN(MenuOption,
  550. sizeof(MenuOption),
  551. &OptionLength,
  552. Profile->FriendlyName,
  553. Profile->NameLength);
  554. ArcWrite(BlConsoleOutDeviceId,
  555. MenuOption,
  556. OptionLength,
  557. &Count);
  558. #endif
  559. #ifdef EFI
  560. BlEfiSetAttribute( DEFATT );
  561. #else
  562. BlSetInverseMode(FALSE);
  563. #endif
  564. BlClearToEndOfLine();
  565. }
  566. } else {
  567. //
  568. // No profile options available, just display the default
  569. // highlighted to indicate that ENTER will start the system.
  570. //
  571. Temp = BlFindMessage(BL_BOOT_DEFAULT_PROMPT);
  572. if (Temp != NULL) {
  573. BlPositionCursor(5, HeaderLines+3);
  574. #ifdef EFI
  575. BlEfiSetAttribute( INVATT );
  576. #else
  577. BlSetInverseMode(TRUE);
  578. #endif
  579. ArcWrite(BlConsoleOutDeviceId,
  580. Temp,
  581. _tcslen(Temp)*sizeof(TCHAR),
  582. &Count);
  583. #ifdef EFI
  584. BlEfiSetAttribute( INVATT );
  585. #else
  586. BlSetInverseMode(TRUE);
  587. #endif
  588. }
  589. }
  590. if (TimeoutPrompt) {
  591. CurrentTime = ArcGetRelativeTime();
  592. _stprintf(MenuOption, TimeoutPrompt, EndTime-CurrentTime);
  593. BlPositionCursor(1, ScreenHeight);
  594. ArcWrite(BlConsoleOutDeviceId,
  595. MenuOption,
  596. _tcslen(MenuOption)*sizeof(TCHAR),
  597. &Count);
  598. BlClearToEndOfLine();
  599. }
  600. //
  601. // Loop waiting for keypress or time change.
  602. //
  603. do {
  604. if ((Key = BlGetKey()) != 0) {
  605. TimeoutPrompt = NULL; // turn off timeout prompt
  606. BlPositionCursor(1,ScreenHeight);
  607. BlClearToEndOfLine();
  608. break;
  609. }
  610. if (TimeoutPrompt) {
  611. if (ArcGetRelativeTime() != CurrentTime) {
  612. //
  613. // Time has changed, update the countdown and check for timeout
  614. //
  615. CurrentTime = ArcGetRelativeTime();
  616. _stprintf(MenuOption, TimeoutPrompt, EndTime-CurrentTime);
  617. BlPositionCursor(1, ScreenHeight);
  618. ArcWrite(BlConsoleOutDeviceId,
  619. MenuOption,
  620. _tcslen(MenuOption)*sizeof(TCHAR),
  621. &Count);
  622. BlClearToEndOfLine();
  623. if (EndTime == CurrentTime) {
  624. goto ProcessSelection;
  625. }
  626. }
  627. }
  628. } while ( TRUE );
  629. switch (Key) {
  630. case UP_ARROW:
  631. //
  632. // Cursor up
  633. //
  634. if (ProfileCount > 0) {
  635. if (CurrentSelection==0) {
  636. CurrentSelection = ProfileCount - 1;
  637. if (TopProfileLine + DisplayLines <= CurrentSelection) {
  638. TopProfileLine = CurrentSelection - DisplayLines + 1;
  639. }
  640. } else {
  641. if (--CurrentSelection < TopProfileLine) {
  642. //
  643. // Scroll up
  644. //
  645. TopProfileLine = CurrentSelection;
  646. }
  647. }
  648. }
  649. break;
  650. case DOWN_ARROW:
  651. //
  652. // Cursor down
  653. //
  654. if (ProfileCount > 0) {
  655. CurrentSelection = (CurrentSelection+1) % ProfileCount;
  656. if (CurrentSelection == 0) {
  657. TopProfileLine = 0;
  658. } else if (TopProfileLine + DisplayLines <= CurrentSelection) {
  659. TopProfileLine = CurrentSelection - DisplayLines + 1;
  660. }
  661. }
  662. break;
  663. case F3_KEY:
  664. //
  665. // F3
  666. //
  667. *ControlSet = HCELL_NIL;
  668. return(FALSE);
  669. default:
  670. //
  671. // Check to see if the Key indicates the user selection LKG
  672. // first, we have to make sure we are looking at an alpha char.
  673. //
  674. if ( ((Key >> 8) == 0) && _istalpha((TCHAR)Key) ) {
  675. if ((_totupper((TCHAR)Key) == LkgMnemonic) && (*UseLastKnownGood == FALSE)) {
  676. *UseLastKnownGood = TRUE;
  677. BlpSwitchControlSet(ProfileList,
  678. AliasList,
  679. TRUE,
  680. ControlSet);
  681. if (NULL != *ProfileList) {
  682. if ((*ProfileList)->CurrentProfileCount > 0) {
  683. BlDockInfoFilterProfileList (*ProfileList, *AliasList);
  684. }
  685. }
  686. goto Restart;
  687. //
  688. // regenerate profile list here
  689. //
  690. } else if ((_totupper((TCHAR)Key) == DefaultMnemonic) && (*UseLastKnownGood)) {
  691. *UseLastKnownGood = FALSE;
  692. BlpSwitchControlSet(ProfileList,
  693. AliasList,
  694. FALSE,
  695. ControlSet);
  696. if (NULL != *ProfileList) {
  697. if ((*ProfileList)->CurrentProfileCount > 0) {
  698. BlDockInfoFilterProfileList (*ProfileList, *AliasList);
  699. }
  700. }
  701. goto Restart;
  702. }
  703. }
  704. break;
  705. } // switch
  706. } while ( (Key != ASCII_CR) && (Key != ASCII_LF) );
  707. ProcessSelection:
  708. if (ProfileCount > 0) {
  709. if (HW_PROFILE_STATUS_SUCCESS == BlLoaderBlock->Extension->Profile.Status) {
  710. flags = ((*ProfileList)->Profile[CurrentSelection].Flags);
  711. if (flags & CM_HP_FLAGS_PRISTINE) {
  712. BlLoaderBlock->Extension->Profile.Status =
  713. HW_PROFILE_STATUS_PRISTINE_MATCH;
  714. } else if (flags & CM_HP_FLAGS_TRUE_MATCH) {
  715. BlLoaderBlock->Extension->Profile.Status =
  716. HW_PROFILE_STATUS_TRUE_MATCH;
  717. } else if (flags & CM_HP_FLAGS_ALIASABLE) {
  718. BlLoaderBlock->Extension->Profile.Status =
  719. HW_PROFILE_STATUS_ALIAS_MATCH;
  720. }
  721. }
  722. CmpSetCurrentProfile(&BootHive.Hive,
  723. *ControlSet,
  724. &(*ProfileList)->Profile[CurrentSelection]);
  725. }
  726. return(TRUE);
  727. }
  728. ARC_STATUS
  729. BlLoadBootDrivers(
  730. IN PPATH_SET DefaultPathSet,
  731. IN PLIST_ENTRY BootDriverListHead,
  732. OUT PCHAR BadFileName
  733. )
  734. /*++
  735. Routine Description:
  736. Walks the boot driver list and loads all the drivers
  737. Arguments:
  738. DefaultPathSet - Describes the possible locations drivers could be loaded
  739. from.
  740. BootDriverListHead - Supplies the head of the boot driver list
  741. BadFileName - Returns the filename of the critical driver that
  742. did not load. Not valid if ESUCCESS is returned.
  743. Return Value:
  744. ESUCCESS is returned if all the boot drivers were successfully loaded.
  745. Otherwise, an unsuccessful status is returned.
  746. --*/
  747. {
  748. ULONG DeviceId;
  749. PBOOT_DRIVER_NODE DriverNode;
  750. PBOOT_DRIVER_LIST_ENTRY DriverEntry;
  751. PLIST_ENTRY NextEntry;
  752. CHAR DriverName[64];
  753. PCHAR NameStart;
  754. CHAR DriverDevice[128];
  755. CHAR DriverPath[128];
  756. ARC_STATUS Status;
  757. UNICODE_STRING DeviceName;
  758. UNICODE_STRING FileName;
  759. WCHAR SystemRootBuffer[] = L"\\SystemRoot\\";
  760. ULONG SystemRootLength;
  761. PWSTR p;
  762. ULONG Index;
  763. BOOLEAN AbsolutePath;
  764. FULL_PATH_SET LocalPathSet;
  765. PPATH_SOURCE PathSource;
  766. SystemRootLength = wcslen(SystemRootBuffer);
  767. NextEntry = BootDriverListHead->Flink;
  768. while (NextEntry != BootDriverListHead) {
  769. DriverNode = CONTAINING_RECORD(NextEntry,
  770. BOOT_DRIVER_NODE,
  771. ListEntry.Link);
  772. Status = ESUCCESS;
  773. DriverEntry = &DriverNode->ListEntry;
  774. if (DriverEntry->FilePath.Buffer[0] != L'\\') {
  775. //
  776. // This is a relative pathname, so generate the full pathname
  777. // relative to the boot partition.
  778. //
  779. sprintf(DriverPath, "%wZ", &DriverEntry->FilePath);
  780. AbsolutePath = FALSE;
  781. } else if (memcmp(DriverEntry->FilePath.Buffer,
  782. SystemRootBuffer,
  783. (SystemRootLength * sizeof(WCHAR))) == 0) {
  784. //
  785. // This is a pathname starting with "\SystemRoot\", so just ignore
  786. // that part and treat like the previous case.
  787. //
  788. FileName.Buffer = DriverEntry->FilePath.Buffer + SystemRootLength;
  789. FileName.Length = (USHORT)(DriverEntry->FilePath.Length - (SystemRootLength * sizeof(WCHAR)));
  790. sprintf(DriverPath, "%wZ", &FileName);
  791. AbsolutePath = FALSE;
  792. } else {
  793. //
  794. // This is an absolute pathname, of the form
  795. // "\ArcDeviceName\dir\subdir\filename"
  796. //
  797. // We need to open the specified ARC device and pass that
  798. // to BlLoadDeviceDriver.
  799. //
  800. p = DeviceName.Buffer = DriverEntry->FilePath.Buffer+1;
  801. DeviceName.Length = 0;
  802. DeviceName.MaximumLength = DriverEntry->FilePath.MaximumLength-sizeof(WCHAR);
  803. while ((*p != L'\\') &&
  804. (DeviceName.Length < DeviceName.MaximumLength)) {
  805. ++p;
  806. DeviceName.Length += sizeof(WCHAR);
  807. }
  808. DeviceName.MaximumLength = DeviceName.Length;
  809. sprintf(DriverDevice, "%wZ", &DeviceName);
  810. Status = ArcOpen(DriverDevice,ArcOpenReadOnly,&DeviceId);
  811. FileName.Buffer = p+1;
  812. FileName.Length = DriverEntry->FilePath.Length - DeviceName.Length - 2*sizeof(WCHAR);
  813. FileName.MaximumLength = FileName.Length;
  814. //
  815. // Device successfully opened, parse out the path and filename.
  816. //
  817. sprintf(DriverPath, "%wZ", &FileName);
  818. AbsolutePath = TRUE;
  819. }
  820. //
  821. // Parse out the driver name from the driver path
  822. //
  823. NameStart = strrchr(DriverPath, '\\');
  824. if (NameStart != NULL) {
  825. strcpy(DriverName, NameStart+1);
  826. *NameStart = '\0';
  827. } else if (DriverPath[0]) {
  828. strcpy(DriverName, DriverPath);
  829. *DriverPath = '\0';
  830. } else {
  831. NextEntry = DriverEntry->Link.Flink;
  832. continue;
  833. }
  834. //
  835. // Ensure DriverPath is terminated with a '\\' if it's filled out.
  836. //
  837. if (DriverPath[0]) {
  838. strcat(DriverPath, "\\");
  839. }
  840. if (AbsolutePath) {
  841. //
  842. // There is only one entry if an absolute path is specified (in
  843. // this case we cannot do last known good).
  844. //
  845. PathSource = &LocalPathSet.Source[0];
  846. PathSource->DeviceId = DeviceId;
  847. PathSource->DeviceName = DriverDevice;
  848. PathSource->DirectoryPath = "\\";
  849. LocalPathSet.PathCount = 1;
  850. LocalPathSet.AliasName = NULL;
  851. strcpy(LocalPathSet.PathOffset, DriverPath);
  852. } else {
  853. //
  854. // It's relative. Copy over the DefaultPathSet array so we can
  855. // edit our own local copy.
  856. //
  857. *((PSPARSE_PATH_SET) &LocalPathSet) = *((PSPARSE_PATH_SET) DefaultPathSet);
  858. for(Index=0; Index < DefaultPathSet->PathCount; Index++) {
  859. LocalPathSet.Source[Index] = DefaultPathSet->Source[Index];
  860. }
  861. //
  862. // Now append our relative path to the PathOffset already present
  863. // in our local copy.
  864. //
  865. strcat(LocalPathSet.PathOffset, DriverPath);
  866. }
  867. if (Status == ESUCCESS) {
  868. Status = BlLoadDeviceDriver(&LocalPathSet,
  869. DriverName,
  870. NULL,
  871. LDRP_ENTRY_PROCESSED,
  872. &DriverEntry->LdrEntry);
  873. }
  874. NextEntry = DriverEntry->Link.Flink;
  875. if (Status != ESUCCESS) {
  876. //
  877. // Attempt to load driver failed, remove it from the list.
  878. //
  879. RemoveEntryList(&DriverEntry->Link);
  880. //
  881. // Check the Error Control of the failed driver. If it
  882. // was critical, fail the boot. If the driver
  883. // wasn't critical, keep going.
  884. //
  885. if (DriverNode->ErrorControl == CriticalError) {
  886. strcpy(BadFileName, DriverPath);
  887. strcat(BadFileName, DriverName);
  888. return(Status);
  889. }
  890. }
  891. }
  892. return(ESUCCESS);
  893. }
  894. BOOLEAN
  895. BlRecoverHive(
  896. PVOID RegistryBase,
  897. ULONG_PTR LogBase
  898. )
  899. /*++
  900. Routine Description:
  901. Applies log from LogBase over the RegistryBase
  902. Arguments:
  903. Return Value:
  904. ESUCCESS is returned if the system hive was successfully loaded.
  905. Otherwise, an unsuccessful status is returned.
  906. --*/
  907. {
  908. PHBASE_BLOCK BaseBlockHive;
  909. PHBASE_BLOCK BaseBlockLog;
  910. BOOLEAN RecoverData = FALSE;
  911. ULONG FileOffset = HSECTOR_SIZE;
  912. ULONG DirtyVectorSignature = 0;
  913. PUCHAR FlatLog;
  914. PUCHAR FlatReg;
  915. ULONG VectorSize;
  916. ULONG Length;
  917. ULONG ClusterSize;
  918. ULONG HeaderLength;
  919. RTL_BITMAP BitMap;
  920. PULONG Vector;
  921. ULONG Current;
  922. ULONG Start;
  923. ULONG End;
  924. PUCHAR MemoryBlock;
  925. PUCHAR Dest;
  926. ULONG i;
  927. BaseBlockHive = (PHBASE_BLOCK)RegistryBase;
  928. BaseBlockLog = (PHBASE_BLOCK)LogBase;
  929. FlatLog = (PUCHAR)LogBase;
  930. FlatReg = (PUCHAR)RegistryBase;
  931. ClusterSize = BaseBlockLog->Cluster * HSECTOR_SIZE;
  932. HeaderLength = ROUND_UP(HLOG_HEADER_SIZE, ClusterSize);
  933. FileOffset = ClusterSize;
  934. FileOffset = ROUND_UP(FileOffset, HeaderLength);
  935. if(HvpHeaderCheckSum(BaseBlockHive) != BaseBlockHive->CheckSum ) {
  936. //
  937. // recover header case
  938. //
  939. RtlCopyMemory((PVOID)BaseBlockHive,(PVOID)BaseBlockLog,ClusterSize);
  940. BaseBlockHive->Type = HFILE_TYPE_PRIMARY;
  941. } else {
  942. //
  943. // if not recoverheader (which implies recoverdata)
  944. //
  945. ASSERT( BaseBlockHive->Sequence1 != BaseBlockHive->Sequence2 );
  946. }
  947. DirtyVectorSignature = *((PULONG)(FlatLog + FileOffset));
  948. FileOffset += sizeof(DirtyVectorSignature);
  949. if (DirtyVectorSignature != HLOG_DV_SIGNATURE) {
  950. return FALSE;
  951. }
  952. Length = BaseBlockHive->Length;
  953. VectorSize = Length / HSECTOR_SIZE;
  954. Vector = (PULONG)(FlatLog + FileOffset);
  955. RtlInitializeBitMap(&BitMap, Vector, VectorSize);
  956. FileOffset += VectorSize / 8;
  957. FileOffset = ROUND_UP(FileOffset, ClusterSize);
  958. //
  959. // step through the diry map, and copy from the log to the flat hive
  960. //
  961. Current = 0;
  962. while (Current < VectorSize) {
  963. //
  964. // find next contiguous block of entries to read in
  965. //
  966. for (i = Current; i < VectorSize; i++) {
  967. if (RtlCheckBit(&BitMap, i) == 1) {
  968. break;
  969. }
  970. }
  971. Start = i;
  972. for ( ; i < VectorSize; i++) {
  973. if (RtlCheckBit(&BitMap, i) == 0) {
  974. break;
  975. }
  976. }
  977. End = i;
  978. Current = End;
  979. //
  980. // Start == number of 1st sector, End == number of Last sector + 1
  981. //
  982. Length = (End - Start) * HSECTOR_SIZE;
  983. if( 0 == Length ) {
  984. // no more dirty blocks.
  985. break;
  986. }
  987. MemoryBlock = (PUCHAR)(FlatLog + FileOffset);
  988. FileOffset += Length;
  989. ASSERT((FileOffset % ClusterSize) == 0);
  990. Dest = (PUCHAR)(FlatReg + HBLOCK_SIZE + Start * HSECTOR_SIZE);
  991. //
  992. // copy recovered data in the right locations inside the flat hive image
  993. //
  994. RtlCopyMemory(Dest,MemoryBlock, Length);
  995. }
  996. BaseBlockHive->Sequence2 = BaseBlockHive->Sequence1;
  997. BaseBlockHive->CheckSum = HvpHeaderCheckSum(BaseBlockHive);
  998. return TRUE;
  999. }
  1000. ARC_STATUS
  1001. BlLoadAndInitSystemHive(
  1002. IN ULONG DeviceId,
  1003. IN PCHAR DeviceName,
  1004. IN PCHAR DirectoryPath,
  1005. IN PCHAR HiveName,
  1006. IN BOOLEAN IsAlternate,
  1007. OUT PBOOLEAN RestartSetup,
  1008. OUT PBOOLEAN LogPresent
  1009. )
  1010. /*++
  1011. Routine Description:
  1012. Loads the registry SYSTEM hive, verifies it is a valid hive file,
  1013. and inits the relevant registry structures. (particularly the HHIVE)
  1014. Arguments:
  1015. DeviceId - Supplies the file id of the device the system tree is on.
  1016. DeviceName - Supplies the name of the device the system tree is on.
  1017. DirectoryPath - Supplies a pointer to the zero-terminated directory path
  1018. of the root of the NT tree.
  1019. HiveName - Supplies the name of the system hive (ie, "SYSTEM",
  1020. "SYSTEM.ALT", or "SYSTEM.SAV").
  1021. IsAlternate - Supplies whether or not the hive to be loaded is the
  1022. alternate hive.
  1023. RestartSetup - if the hive to be loaded is not the alternate, then
  1024. this routine will check for a value of RestartSetup in the Setup
  1025. key. If present and non-0, then this variable receives TRUE.
  1026. Otherwise it receives FALSE.
  1027. Return Value:
  1028. ESUCCESS is returned if the system hive was successfully loaded.
  1029. Otherwise, an unsuccessful status is returned.
  1030. --*/
  1031. {
  1032. ARC_STATUS Status;
  1033. ULONG_PTR LogData;
  1034. *RestartSetup = FALSE;
  1035. *LogPresent = FALSE;
  1036. BlClearToEndOfLine();
  1037. Status = BlLoadSystemHive(DeviceId,
  1038. DeviceName,
  1039. DirectoryPath,
  1040. HiveName);
  1041. if (Status!=ESUCCESS) {
  1042. return(Status);
  1043. }
  1044. if (!BlInitializeHive(BlLoaderBlock->RegistryBase,
  1045. &BootHive,
  1046. IsAlternate)) {
  1047. if( !IsAlternate ) {
  1048. //
  1049. // try to recover the hive
  1050. //
  1051. Status = BlLoadSystemHiveLog(DeviceId,
  1052. DeviceName,
  1053. DirectoryPath,
  1054. "system.log",
  1055. &LogData );
  1056. if (Status!=ESUCCESS) {
  1057. return(Status);
  1058. }
  1059. *LogPresent = TRUE;
  1060. if( !BlRecoverHive( BlLoaderBlock->RegistryBase,
  1061. LogData ) ) {
  1062. BlFreeDescriptor( (ULONG)((ULONG_PTR)LogData & (~KSEG0_BASE)) >> PAGE_SHIFT );
  1063. return(EINVAL);
  1064. }
  1065. BlFreeDescriptor( (ULONG)((ULONG_PTR)LogData & (~KSEG0_BASE)) >> PAGE_SHIFT );
  1066. //
  1067. // we successfully recovered. Try setting up the hive again
  1068. //
  1069. if (!BlInitializeHive(BlLoaderBlock->RegistryBase,
  1070. &BootHive,
  1071. IsAlternate)) {
  1072. return(EINVAL);
  1073. }
  1074. //
  1075. // mark the hive as "recovered"
  1076. //
  1077. BootHive.Hive.BaseBlock->BootRecover = 1;
  1078. } else {
  1079. return(EINVAL);
  1080. }
  1081. } else {
  1082. //
  1083. // mark the hive as "no-recovered"
  1084. //
  1085. BootHive.Hive.BaseBlock->BootRecover = 0;
  1086. }
  1087. //
  1088. // See whether we need to switch to the backup setup hive.
  1089. //
  1090. *RestartSetup = BlpCheckRestartSetup();
  1091. return(ESUCCESS);
  1092. }
  1093. HCELL_INDEX
  1094. BlpDetermineControlSet(
  1095. IN OUT BOOLEAN *LastKnownGoodBoot
  1096. )
  1097. /*++
  1098. Routine Description:
  1099. Determines the appropriate control set and static hardware profile.
  1100. This routine ends the configuration prompt. If the user has hit a
  1101. key, the configuration menu is displayed. If the user has not hit
  1102. a key, but the default controlset specifies a non-zero timeout for
  1103. the configuration menu, the configuration menu is displayed.
  1104. If the configuration menu is displayed, further modifications to the
  1105. control set and hardware profile can be made by the user. If not,
  1106. the default hardware profile is selected.
  1107. Arguments:
  1108. LastKnownGoodBoot - On input, LastKnownGood indicates whether LKG has been
  1109. selected. This value is updated to TRUE if the user
  1110. chooses LKG via the profile configuration menu.
  1111. Return Value:
  1112. On success, HCELL_INDEX is control the set to boot from.
  1113. On error, HCELL_NIL is returned and LastKnownGoodBoot is unchanged.
  1114. --*/
  1115. {
  1116. BOOLEAN UseLastKnownGood;
  1117. BOOLEAN ConfigMenu = FALSE;
  1118. HCELL_INDEX ControlSet;
  1119. HCELL_INDEX ProfileControl;
  1120. UNICODE_STRING DefaultControlName;
  1121. UNICODE_STRING LkgControlName;
  1122. PUNICODE_STRING ControlName;
  1123. BOOLEAN AutoSelect;
  1124. ULONG ProfileTimeout = (ULONG)0;
  1125. PCM_HARDWARE_PROFILE_LIST ProfileList;
  1126. PCM_HARDWARE_PROFILE_ALIAS_LIST AliasList;
  1127. PCM_HARDWARE_PROFILE SelectedProfile;
  1128. DOCKING_STATION_INFO dockInfo = { 0, 0, 0, FW_DOCKINFO_DOCK_STATE_UNKNOWN };
  1129. PCONFIGURATION_COMPONENT_DATA dockInfoData;
  1130. ULONG flags;
  1131. #if DOCKINFO_VERBOSE
  1132. _TUCHAR Buffer[1024];
  1133. ULONG count;
  1134. USHORT dkState;
  1135. PTCHAR stateTxt;
  1136. #endif
  1137. //
  1138. // Preinit for failure
  1139. //
  1140. RtlInitUnicodeString(&DefaultControlName, L"Default");
  1141. RtlInitUnicodeString(&LkgControlName, L"LastKnownGood");
  1142. UseLastKnownGood = (*LastKnownGoodBoot);
  1143. if (ForceLastKnownGood) {
  1144. //
  1145. // last known good was selected from the
  1146. // advanced boot menu.
  1147. // this code path is entered when the user
  1148. // enters the advanced boot menu via the
  1149. // main boot menu.
  1150. //
  1151. UseLastKnownGood = TRUE;
  1152. }
  1153. if( !CmpValidateSelect(&BootHive.Hive,
  1154. BootHive.Hive.BaseBlock->RootCell) ) {
  1155. //
  1156. // some of the essential values (Current,Default,Failed,LastKnownGood)
  1157. // does not exist under \SYSTEM\Select key
  1158. //
  1159. return HCELL_NIL;
  1160. }
  1161. do_it_again:
  1162. //
  1163. // Get the appropriate control set
  1164. // and check the hardware profile timeout value.
  1165. //
  1166. if (UseLastKnownGood) {
  1167. ControlName = &LkgControlName;
  1168. } else {
  1169. ControlName = &DefaultControlName;
  1170. }
  1171. ControlSet = CmpFindControlSet(&BootHive.Hive,
  1172. BootHive.Hive.BaseBlock->RootCell,
  1173. ControlName,
  1174. &AutoSelect);
  1175. if (ControlSet == HCELL_NIL) {
  1176. return(HCELL_NIL);
  1177. }
  1178. //
  1179. // Check the hardware profile configuration options to
  1180. // determine the timeout value for the config menu.
  1181. //
  1182. ProfileList = NULL;
  1183. AliasList = NULL;
  1184. ProfileControl = CmpFindProfileOption(&BootHive.Hive,
  1185. ControlSet,
  1186. &ProfileList,
  1187. &AliasList,
  1188. &ProfileTimeout);
  1189. //
  1190. // Pull the Docking information from the hardware tree.
  1191. //
  1192. dockInfoData = KeFindConfigurationEntry(BlLoaderBlock->ConfigurationRoot,
  1193. PeripheralClass,
  1194. DockingInformation,
  1195. NULL);
  1196. if (NULL == dockInfoData) {
  1197. BlLoaderBlock->Extension->Profile.Status = HW_PROFILE_STATUS_SUCCESS;
  1198. BlLoaderBlock->Extension->Profile.DockingState = HW_PROFILE_DOCKSTATE_UNKNOWN;
  1199. BlLoaderBlock->Extension->Profile.Capabilities = 0;
  1200. BlLoaderBlock->Extension->Profile.DockID = 0;
  1201. BlLoaderBlock->Extension->Profile.SerialNumber = 0;
  1202. } else if (sizeof (dockInfo) <=
  1203. dockInfoData->ComponentEntry.ConfigurationDataLength) {
  1204. RtlCopyMemory (
  1205. &dockInfo,
  1206. (PUCHAR) (dockInfoData->ConfigurationData) + sizeof(CM_PARTIAL_RESOURCE_LIST),
  1207. sizeof (dockInfo));
  1208. BlLoaderBlock->Extension->Profile.Status = HW_PROFILE_STATUS_FAILURE;
  1209. switch (dockInfo.ReturnCode) {
  1210. case FW_DOCKINFO_SUCCESS:
  1211. BlLoaderBlock->Extension->Profile.Status = HW_PROFILE_STATUS_SUCCESS;
  1212. BlLoaderBlock->Extension->Profile.DockingState = HW_PROFILE_DOCKSTATE_DOCKED;
  1213. BlLoaderBlock->Extension->Profile.Capabilities = dockInfo.Capabilities;
  1214. BlLoaderBlock->Extension->Profile.DockID = dockInfo.DockID;
  1215. BlLoaderBlock->Extension->Profile.SerialNumber = dockInfo.SerialNumber;
  1216. break;
  1217. case FW_DOCKINFO_SYSTEM_NOT_DOCKED:
  1218. BlLoaderBlock->Extension->Profile.Status = HW_PROFILE_STATUS_SUCCESS;
  1219. BlLoaderBlock->Extension->Profile.DockingState = HW_PROFILE_DOCKSTATE_UNDOCKED;
  1220. BlLoaderBlock->Extension->Profile.Capabilities = dockInfo.Capabilities;
  1221. BlLoaderBlock->Extension->Profile.DockID = dockInfo.DockID;
  1222. BlLoaderBlock->Extension->Profile.SerialNumber = dockInfo.SerialNumber;
  1223. break;
  1224. case FW_DOCKINFO_DOCK_STATE_UNKNOWN:
  1225. BlLoaderBlock->Extension->Profile.Status = HW_PROFILE_STATUS_SUCCESS;
  1226. BlLoaderBlock->Extension->Profile.DockingState = HW_PROFILE_DOCKSTATE_UNKNOWN;
  1227. BlLoaderBlock->Extension->Profile.Capabilities = dockInfo.Capabilities;
  1228. BlLoaderBlock->Extension->Profile.DockID = dockInfo.DockID;
  1229. BlLoaderBlock->Extension->Profile.SerialNumber = dockInfo.SerialNumber;
  1230. break;
  1231. case FW_DOCKINFO_FUNCTION_NOT_SUPPORTED:
  1232. case FW_DOCKINFO_BIOS_NOT_CALLED:
  1233. BlLoaderBlock->Extension->Profile.Status = HW_PROFILE_STATUS_SUCCESS;
  1234. default:
  1235. BlLoaderBlock->Extension->Profile.DockingState = HW_PROFILE_DOCKSTATE_UNSUPPORTED;
  1236. BlLoaderBlock->Extension->Profile.Capabilities = dockInfo.Capabilities;
  1237. BlLoaderBlock->Extension->Profile.DockID = dockInfo.DockID;
  1238. BlLoaderBlock->Extension->Profile.SerialNumber = dockInfo.SerialNumber;
  1239. break;
  1240. }
  1241. } else {
  1242. BlLoaderBlock->Extension->Profile.Status = HW_PROFILE_STATUS_SUCCESS;
  1243. BlLoaderBlock->Extension->Profile.Capabilities = 0;
  1244. BlLoaderBlock->Extension->Profile.DockID = 0;
  1245. BlLoaderBlock->Extension->Profile.SerialNumber = 0;
  1246. }
  1247. #ifdef DOCKINFO_VERBOSE
  1248. dkState = BlLoaderBlock->Extension->Profile.DockingState;
  1249. if ((dkState & HW_PROFILE_DOCKSTATE_UNKNOWN) == HW_PROFILE_DOCKSTATE_UNKNOWN) {
  1250. stateTxt = TEXT("Unknown");
  1251. } else if (dkState & HW_PROFILE_DOCKSTATE_DOCKED) {
  1252. stateTxt = TEXT("Docked");
  1253. } else if (dkState & HW_PROFILE_DOCKSTATE_UNDOCKED) {
  1254. stateTxt = TEXT("Undocked");
  1255. } else {
  1256. stateTxt = TEXT("Truely unknown");
  1257. }
  1258. _stprintf(Buffer,
  1259. TEXT("Profile Docking: <%x, %s> := %x [%x, %x] \r\n\0"),
  1260. BlLoaderBlock->Extension->Profile.Status,
  1261. stateTxt,
  1262. BlLoaderBlock->Extension->Profile.Capabilities,
  1263. BlLoaderBlock->Extension->Profile.DockID,
  1264. BlLoaderBlock->Extension->Profile.SerialNumber);
  1265. ArcWrite(BlConsoleOutDeviceId, Buffer, _tcslen(Buffer)*sizeof(TCHAR), &count);
  1266. _stprintf(Buffer, TEXT("press 'y' (lowercase) to continue...\r\n\0"));
  1267. ArcWrite(BlConsoleOutDeviceId, Buffer, _tcslen(Buffer)*sizeof(TCHAR), &count);
  1268. while(BlGetKey() != 'y') {
  1269. //
  1270. // Nothing
  1271. //
  1272. }
  1273. #endif
  1274. //
  1275. // Filter the list of Hardware Profiles to
  1276. // eliminate profiles that should not be considered
  1277. //
  1278. if (NULL != ProfileList) {
  1279. if (ProfileList->CurrentProfileCount > 0) {
  1280. BlDockInfoFilterProfileList (ProfileList, AliasList);
  1281. }
  1282. }
  1283. //
  1284. // Now check to see whether the config menu should be displayed.
  1285. // Display the menu if:
  1286. // - user has pressed a key OR
  1287. // - we are booting from LKG and AutoSelect is FALSE. OR
  1288. // - ProfileTimeout != 0
  1289. //
  1290. if (!BlEndConfigPrompt()) {
  1291. if (!UseLastKnownGood && ForceLastKnownGood) {
  1292. //
  1293. // last known good was selected from the
  1294. // advanced boot menu.
  1295. // this code path is entered when the user
  1296. // enters the advanced boot menu by pressing
  1297. // F8 while the cinfiguration hives are preparing to load.
  1298. //
  1299. // the currentcontrolset has already been set to the
  1300. // "default" control set, so go back and try this again to
  1301. // load the "lastknowngood" controlset.
  1302. //
  1303. UseLastKnownGood = TRUE;
  1304. goto do_it_again;
  1305. }
  1306. ConfigMenu = FALSE;
  1307. } else {
  1308. ConfigMenu = TRUE;
  1309. }
  1310. if (ConfigMenu || ForceLastKnownGood ||
  1311. (UseLastKnownGood && !AutoSelect) ||
  1312. ((ProfileTimeout != 0) &&
  1313. (ProfileList != NULL) &&
  1314. (ProfileList->CurrentProfileCount > 1))) {
  1315. //
  1316. // Display the configuration menu.
  1317. //
  1318. BlRebootSystem = !BlConfigMenuPrompt(ProfileTimeout,
  1319. &UseLastKnownGood,
  1320. &ControlSet,
  1321. &ProfileList,
  1322. &AliasList,
  1323. &SelectedProfile);
  1324. if (BlRebootSystem) {
  1325. REBOOT_PROCESSOR();
  1326. }
  1327. BlClearScreen();
  1328. } else {
  1329. if ((ProfileControl != HCELL_NIL) &&
  1330. (ProfileList != NULL)) {
  1331. //
  1332. // The system is configured to boot the default
  1333. // profile directly. Since the returned profile
  1334. // list is sorted by priority, the first entry in
  1335. // the list is our default.
  1336. //
  1337. if (HW_PROFILE_STATUS_SUCCESS ==
  1338. BlLoaderBlock->Extension->Profile.Status) {
  1339. flags = (ProfileList->Profile[0].Flags);
  1340. if (flags & CM_HP_FLAGS_PRISTINE) {
  1341. BlLoaderBlock->Extension->Profile.Status =
  1342. HW_PROFILE_STATUS_PRISTINE_MATCH;
  1343. } else if (flags & CM_HP_FLAGS_TRUE_MATCH) {
  1344. BlLoaderBlock->Extension->Profile.Status =
  1345. HW_PROFILE_STATUS_TRUE_MATCH;
  1346. } else if (flags & CM_HP_FLAGS_ALIASABLE) {
  1347. BlLoaderBlock->Extension->Profile.Status =
  1348. HW_PROFILE_STATUS_ALIAS_MATCH;
  1349. }
  1350. }
  1351. CmpSetCurrentProfile(&BootHive.Hive,
  1352. ControlSet,
  1353. &ProfileList->Profile[0]);
  1354. }
  1355. }
  1356. //
  1357. // Update the passed in parameter. We should only be doing this if we have
  1358. // something real to return.
  1359. //
  1360. //ASSERT(ControlSet != HCELL_NIL);
  1361. *LastKnownGoodBoot = UseLastKnownGood;
  1362. return(ControlSet);
  1363. }
  1364. BOOLEAN
  1365. BlpCheckRestartSetup(
  1366. VOID
  1367. )
  1368. /*++
  1369. Routine Description:
  1370. Examine the system hive loaded and described by BootHive, to see
  1371. whether it contains a Setup key, and if so, whether that key has
  1372. a "RestartSetup" value that is non-0.
  1373. Arguments:
  1374. None.
  1375. Return Value:
  1376. Boolean value indicating whether the above condition is satisfied.
  1377. --*/
  1378. {
  1379. HCELL_INDEX KeyCell;
  1380. HCELL_INDEX ValueCell;
  1381. UNICODE_STRING UnicodeString;
  1382. PCM_KEY_VALUE Value;
  1383. PULONG Data;
  1384. ULONG DataSize;
  1385. //
  1386. // Address the Setup key
  1387. //
  1388. RtlInitUnicodeString(&UnicodeString,L"Setup");
  1389. KeyCell = CmpFindSubKeyByName(
  1390. &BootHive.Hive,
  1391. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive,BootHive.Hive.BaseBlock->RootCell),
  1392. &UnicodeString
  1393. );
  1394. if(KeyCell == HCELL_NIL) {
  1395. return(FALSE);
  1396. }
  1397. //
  1398. // Find RestartSetup value in Setup key
  1399. //
  1400. RtlInitUnicodeString(&UnicodeString,L"RestartSetup");
  1401. ValueCell = CmpFindValueByName(
  1402. &BootHive.Hive,
  1403. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive,KeyCell),
  1404. &UnicodeString
  1405. );
  1406. if(ValueCell == HCELL_NIL) {
  1407. return(FALSE);
  1408. }
  1409. //
  1410. // Validate value and check.
  1411. //
  1412. Value = (PCM_KEY_VALUE)HvGetCell(&BootHive.Hive,ValueCell);
  1413. if(Value->Type != REG_DWORD) {
  1414. return(FALSE);
  1415. }
  1416. Data = (PULONG)(CmpIsHKeyValueSmall(DataSize,Value->DataLength)
  1417. ? (struct _CELL_DATA *)&Value->Data
  1418. : HvGetCell(&BootHive.Hive,Value->Data));
  1419. if(DataSize != sizeof(ULONG)) {
  1420. return(FALSE);
  1421. }
  1422. return((BOOLEAN)(*Data != 0));
  1423. }
  1424. #if defined(REMOTE_BOOT)
  1425. BOOLEAN
  1426. BlpQueryRemoteBootParameter(
  1427. IN HCELL_INDEX ControlSet,
  1428. IN PWSTR ValueName,
  1429. IN ULONG ValueType,
  1430. OUT PVOID ValueBuffer,
  1431. IN ULONG ValueBufferLength
  1432. )
  1433. /*++
  1434. Routine Description:
  1435. Query a parameter from under Control\RemoteBoot.
  1436. Arguments:
  1437. ControlSet - The index of the current control set.
  1438. ValueName - The name of the value to query.
  1439. ValueType - The expected type of the value.
  1440. ValueBuffer - The location to return the data.
  1441. ValueBufferLength - The length of the buffer.
  1442. Return Value:
  1443. Boolean value indicating whether the data was read successfully.
  1444. --*/
  1445. {
  1446. UNICODE_STRING Name;
  1447. HCELL_INDEX Control;
  1448. HCELL_INDEX RemoteBoot;
  1449. HCELL_INDEX ValueCell;
  1450. PCM_KEY_VALUE Value;
  1451. ULONG RealSize;
  1452. BOOLEAN ValueSmall;
  1453. //
  1454. // Find Services node
  1455. //
  1456. RtlInitUnicodeString(&Name, L"Control");
  1457. Control = CmpFindSubKeyByName(
  1458. &BootHive.Hive,
  1459. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive,ControlSet),
  1460. &Name);
  1461. if (Control == HCELL_NIL) {
  1462. return(FALSE);
  1463. }
  1464. //
  1465. // Find RemoteBoot node
  1466. //
  1467. RtlInitUnicodeString(&Name, L"RemoteBoot");
  1468. RemoteBoot = CmpFindSubKeyByName(
  1469. &BootHive.Hive,
  1470. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive,Control),
  1471. &Name);
  1472. if (RemoteBoot == HCELL_NIL) {
  1473. return(FALSE);
  1474. }
  1475. //
  1476. // Find value
  1477. //
  1478. RtlInitUnicodeString(&Name, ValueName);
  1479. ValueCell = CmpFindValueByName(
  1480. &BootHive.Hive,
  1481. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive,RemoteBoot),
  1482. &Name);
  1483. if (ValueCell == HCELL_NIL) {
  1484. return(FALSE);
  1485. }
  1486. Value = (PCM_KEY_VALUE)HvGetCell(&BootHive.Hive, ValueCell);
  1487. if (Value->Type != ValueType) {
  1488. return(FALSE);
  1489. }
  1490. //
  1491. // This determines if the value is small (stored right in Value)
  1492. // or not, and also returns the real size of it.
  1493. //
  1494. ValueSmall = CmpIsHKeyValueSmall(RealSize,Value->DataLength);
  1495. if (RealSize > ValueBufferLength) {
  1496. return(FALSE);
  1497. }
  1498. RtlMoveMemory(
  1499. ValueBuffer,
  1500. (ValueSmall ?
  1501. (struct _CELL_DATA *)&Value->Data :
  1502. HvGetCell(&BootHive.Hive,Value->Data)),
  1503. RealSize);
  1504. return(TRUE);
  1505. }
  1506. #endif // defined(REMOTE_BOOT)
  1507. PTCHAR
  1508. BlScanRegistry(
  1509. IN PWSTR BootFileSystemPath,
  1510. IN OUT BOOLEAN *LastKnownGoodBoot,
  1511. OUT PLIST_ENTRY BootDriverListHead,
  1512. OUT PUNICODE_STRING AnsiCodepage,
  1513. OUT PUNICODE_STRING OemCodepage,
  1514. OUT PUNICODE_STRING LanguageTable,
  1515. OUT PUNICODE_STRING OemHalFont,
  1516. #ifdef _WANT_MACHINE_IDENTIFICATION
  1517. OUT PUNICODE_STRING Biosinfo,
  1518. #endif
  1519. OUT PSETUP_LOADER_BLOCK SetupLoaderBlock,
  1520. OUT BOOLEAN *ServerHive
  1521. )
  1522. /*++
  1523. Routine Description:
  1524. Scans the SYSTEM hive, determines the control set and static hardware
  1525. profile (with appropriate input from the user) and finally
  1526. computes the list of boot drivers to be loaded.
  1527. Arguments:
  1528. BootFileSystemPath - Supplies the name of the image the filesystem
  1529. for the boot volume was read from. The last entry in
  1530. BootDriverListHead will refer to this file, and to the registry
  1531. key entry that controls it.
  1532. LastKnownGoodBoot - On input, LastKnownGood indicates whether LKG has been
  1533. selected. This value is updated to TRUE if the user
  1534. chooses LKG via the profile configuration menu.
  1535. BootDriverListHead - Receives a pointer to the first element of the
  1536. list of boot drivers. Each element in this singly linked list will
  1537. provide the loader with two paths. The first is the path of the
  1538. file that contains the driver to load, the second is the path of
  1539. the registry key that controls that driver. Both will be passed
  1540. to the system via the loader heap.
  1541. AnsiCodepage - Receives the name of the ANSI codepage data file
  1542. OemCodepage - Receives the name of the OEM codepage data file
  1543. Language - Receives the name of the language case table data file
  1544. OemHalfont - receives the name of the OEM font to be used by the HAL.
  1545. SetupLoaderBlock - if non-NULL, used to return information about the
  1546. net boot card.
  1547. ServerHive - Returns TRUE if this is a server hive, else FALSE.
  1548. Return Value:
  1549. NULL if all is well.
  1550. NON-NULL if the hive is corrupt or inconsistent. Return value is a
  1551. pointer to a string that describes what is wrong. On error LastKnownGood
  1552. is unchanged.
  1553. --*/
  1554. {
  1555. HCELL_INDEX ControlSet;
  1556. UNICODE_STRING ControlName;
  1557. BOOLEAN AutoSelect;
  1558. BOOLEAN KeepGoing;
  1559. UNICODE_STRING TmpName;
  1560. HCELL_INDEX Control;
  1561. HCELL_INDEX ProductOptions;
  1562. HCELL_INDEX ValueCell;
  1563. PCM_KEY_VALUE Value;
  1564. ULONG RealSize;
  1565. BOOLEAN ValueSmall;
  1566. PWCHAR CellString;
  1567. BOOLEAN UsingLastKnownGood;
  1568. #ifdef _WANT_MACHINE_IDENTIFICATION
  1569. UNICODE_STRING regDate;
  1570. CHAR date[9];
  1571. ANSI_STRING ansiString;
  1572. UNICODE_STRING biosDate;
  1573. WCHAR buffer[9];
  1574. BOOLEAN biosDateChanged;
  1575. #endif
  1576. //
  1577. // Preinit.
  1578. //
  1579. UsingLastKnownGood = *LastKnownGoodBoot;
  1580. //
  1581. // Get the appropriate control set.
  1582. //
  1583. ControlSet = BlpDetermineControlSet(&UsingLastKnownGood);
  1584. if (ControlSet == HCELL_NIL) {
  1585. return(TEXT("CmpFindControlSet"));
  1586. }
  1587. if (!CmpFindNLSData(&BootHive.Hive,
  1588. ControlSet,
  1589. AnsiCodepage,
  1590. OemCodepage,
  1591. LanguageTable,
  1592. OemHalFont)) {
  1593. return(TEXT("CmpFindNLSData"));
  1594. }
  1595. InitializeListHead(BootDriverListHead);
  1596. if (!CmpFindDrivers(&BootHive.Hive,
  1597. ControlSet,
  1598. BootLoad,
  1599. BootFileSystemPath,
  1600. BootDriverListHead)) {
  1601. return(TEXT("CmpFindDriver"));
  1602. }
  1603. if (!CmpSortDriverList(&BootHive.Hive,
  1604. ControlSet,
  1605. BootDriverListHead)) {
  1606. return(TEXT("Missing or invalid Control\\ServiceGroupOrder\\List registry value"));
  1607. }
  1608. if (!CmpResolveDriverDependencies(BootDriverListHead)) {
  1609. return(TEXT("CmpResolveDriverDependencies"));
  1610. }
  1611. if (ServerHive != NULL) {
  1612. *ServerHive = FALSE;
  1613. //
  1614. // Find Control node
  1615. //
  1616. RtlInitUnicodeString(&TmpName, L"Control");
  1617. Control = CmpFindSubKeyByName(&BootHive.Hive,
  1618. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive, ControlSet),
  1619. &TmpName
  1620. );
  1621. if (Control == HCELL_NIL) {
  1622. return(TEXT("Missing Control key"));
  1623. }
  1624. //
  1625. // Find ProductOptions node
  1626. //
  1627. RtlInitUnicodeString(&TmpName, L"ProductOptions");
  1628. ProductOptions = CmpFindSubKeyByName(&BootHive.Hive,
  1629. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive,Control),
  1630. &TmpName
  1631. );
  1632. if (ProductOptions == HCELL_NIL) {
  1633. return(TEXT("Missing ProductOptions key"));
  1634. }
  1635. //
  1636. // Find value
  1637. //
  1638. RtlInitUnicodeString(&TmpName, L"ProductType");
  1639. ValueCell = CmpFindValueByName(&BootHive.Hive,
  1640. (PCM_KEY_NODE)HvGetCell(&BootHive.Hive, ProductOptions),
  1641. &TmpName
  1642. );
  1643. if (ValueCell == HCELL_NIL) {
  1644. return(TEXT("Missing ProductType value"));
  1645. }
  1646. Value = (PCM_KEY_VALUE)HvGetCell(&BootHive.Hive, ValueCell);
  1647. if (Value->Type != REG_SZ) {
  1648. return(TEXT("Bad ProductType value"));
  1649. }
  1650. //
  1651. // This determines if the value is small (stored right in Value)
  1652. // or not, and also returns the real size of it.
  1653. //
  1654. CellString = (PWCHAR)(CmpIsHKeyValueSmall(RealSize, Value->DataLength) ?
  1655. (struct _CELL_DATA *)&Value->Data :
  1656. HvGetCell(&BootHive.Hive, Value->Data)
  1657. );
  1658. //
  1659. // Now compare if this is a server hive or not.
  1660. // The proper way to check this is to check the string against
  1661. // the "professional" type 'WinNT'. If it's not professional,
  1662. // it must be a server. (There are multiple strings for different
  1663. // server flavours.)
  1664. //
  1665. *ServerHive = (_wcsicmp(L"WinNT", CellString) != 0);
  1666. }
  1667. #if defined(REMOTE_BOOT)
  1668. if (SetupLoaderBlock != NULL) {
  1669. ULONG EnableIpSecurity;
  1670. if (BlpQueryRemoteBootParameter(
  1671. ControlSet,
  1672. L"EnableIpSecurity",
  1673. REG_DWORD,
  1674. &EnableIpSecurity,
  1675. sizeof(EnableIpSecurity))) {
  1676. if (EnableIpSecurity != 0) {
  1677. SetupLoaderBlock->Flags |= SETUPBLK_FLAGS_IPSEC_ENABLED;
  1678. }
  1679. }
  1680. if (BlpQueryRemoteBootParameter(
  1681. ControlSet,
  1682. L"NetCardInfo",
  1683. REG_BINARY,
  1684. SetupLoaderBlock->NetbootCardInfo,
  1685. SetupLoaderBlock->NetbootCardInfoLength)) {
  1686. if (!BlpQueryRemoteBootParameter(
  1687. ControlSet,
  1688. L"HardwareId",
  1689. REG_SZ,
  1690. SetupLoaderBlock->NetbootCardHardwareId,
  1691. sizeof(SetupLoaderBlock->NetbootCardHardwareId))) {
  1692. SetupLoaderBlock->NetbootCardHardwareId[0] = L'\0';
  1693. }
  1694. if (!BlpQueryRemoteBootParameter(
  1695. ControlSet,
  1696. L"DriverName",
  1697. REG_SZ,
  1698. SetupLoaderBlock->NetbootCardDriverName,
  1699. sizeof(SetupLoaderBlock->NetbootCardDriverName))) {
  1700. SetupLoaderBlock->NetbootCardDriverName[0] = L'\0';
  1701. }
  1702. if (!BlpQueryRemoteBootParameter(
  1703. ControlSet,
  1704. L"ServiceName",
  1705. REG_SZ,
  1706. SetupLoaderBlock->NetbootCardServiceName,
  1707. sizeof(SetupLoaderBlock->NetbootCardServiceName))) {
  1708. SetupLoaderBlock->NetbootCardServiceName[0] = L'\0';
  1709. }
  1710. }
  1711. }
  1712. #endif // defined(REMOTE_BOOT)
  1713. #ifdef _WANT_MACHINE_IDENTIFICATION
  1714. biosDateChanged = TRUE;
  1715. if (CmpGetBiosDateFromRegistry(&BootHive.Hive, ControlSet, &regDate)) {
  1716. //
  1717. // Read the date from the BIOS ROM.
  1718. //
  1719. memcpy(date, (PVOID)0xffff5, 8);
  1720. date[8] = '\0';
  1721. //
  1722. // Convert the date into unicode string.
  1723. //
  1724. ansiString.Buffer = date;
  1725. ansiString.Length = (USHORT) strlen(date);
  1726. ansiString.MaximumLength = ansiString.Length + 1;
  1727. biosDate.Buffer = buffer;
  1728. biosDate.MaximumLength = (ansiString.Length << 1) + sizeof(UNICODE_NULL);
  1729. RtlAnsiStringToUnicodeString(&biosDate, &ansiString, FALSE);
  1730. //
  1731. // Check if the dates are different.
  1732. //
  1733. if (RtlCompareUnicodeString(&biosDate, &regDate, FALSE) == 0) {
  1734. biosDateChanged = FALSE;
  1735. }
  1736. }
  1737. Biosinfo->Length = 0;
  1738. if (biosDateChanged) {
  1739. CmpGetBiosinfoFileNameFromRegistry(&BootHive.Hive, ControlSet, Biosinfo);
  1740. }
  1741. #endif // defined(_WANT_MACHINE_IDENTIFICATION)
  1742. *LastKnownGoodBoot = UsingLastKnownGood;
  1743. return( NULL );
  1744. }
  1745. ARC_STATUS
  1746. BlAddToBootDriverList(
  1747. IN PLIST_ENTRY BootDriverListHead,
  1748. IN PWSTR DriverName,
  1749. IN PWSTR Name,
  1750. IN PWSTR Group,
  1751. IN ULONG Tag,
  1752. IN ULONG ErrorControl,
  1753. IN BOOLEAN InsertAtHead
  1754. )
  1755. /*++
  1756. Routine Description:
  1757. Adds a single driver to the boot driver list. The list
  1758. is NOT re-sorted.
  1759. Arguments:
  1760. BootDriverListHead - Receives a pointer to the first element of the
  1761. list of boot drivers. Each element in this singly linked list will
  1762. provide the loader with two paths. The first is the path of the
  1763. file that contains the driver to load, the second is the path of
  1764. the registry key that controls that driver. Both will be passed
  1765. to the system via the loader heap.
  1766. DriverName - The name of the driver. This will be stored with
  1767. \system32\drivers on the front.
  1768. Name - The service name of the driver. Typically will be DriverName
  1769. without the ".sys".
  1770. Group - The group this driver is in.
  1771. Tag - The tag value within the group for this driver.
  1772. ErrorControl - The error control value for this driver.
  1773. InsertAtHead - Should this driver be inserted at the head of the list, otw tail.
  1774. Return Value:
  1775. ESUCCESS if the driver is successfully inserted.
  1776. ENOMEM if there is an allocation failure.
  1777. --*/
  1778. {
  1779. PBOOT_DRIVER_NODE DriverNode;
  1780. PBOOT_DRIVER_LIST_ENTRY DriverListEntry;
  1781. USHORT Length;
  1782. DriverNode = BlpHiveAllocate(sizeof(BOOT_DRIVER_NODE),FALSE,0);
  1783. if (DriverNode == FALSE) {
  1784. return ENOMEM;
  1785. }
  1786. DriverListEntry = &DriverNode->ListEntry;
  1787. //
  1788. // FilePath
  1789. //
  1790. Length = sizeof(L"System32\\Drivers\\") + (wcslen(DriverName) * sizeof(WCHAR));
  1791. DriverListEntry->FilePath.Buffer = BlpHiveAllocate(Length,FALSE,0);
  1792. if (DriverListEntry->FilePath.Buffer == NULL) {
  1793. return ENOMEM;
  1794. }
  1795. DriverListEntry->FilePath.Length = 0;
  1796. DriverListEntry->FilePath.MaximumLength = Length;
  1797. RtlAppendUnicodeToString(&DriverListEntry->FilePath, L"System32\\Drivers\\");
  1798. RtlAppendUnicodeToString(&DriverListEntry->FilePath, DriverName);
  1799. //
  1800. // Registry Path
  1801. //
  1802. Length = sizeof(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\") + (wcslen(Name) * sizeof(WCHAR));
  1803. DriverListEntry->RegistryPath.Buffer = BlpHiveAllocate(Length,FALSE,0);
  1804. if (DriverListEntry->RegistryPath.Buffer == NULL) {
  1805. return ENOMEM;
  1806. }
  1807. DriverListEntry->RegistryPath.Length = 0;
  1808. DriverListEntry->RegistryPath.MaximumLength = Length;
  1809. RtlAppendUnicodeToString(&DriverListEntry->RegistryPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
  1810. RtlAppendUnicodeToString(&DriverListEntry->RegistryPath, Name);
  1811. //
  1812. // Group
  1813. //
  1814. Length = (wcslen(Group) + 1) * sizeof(WCHAR);
  1815. DriverNode->Group.Buffer = BlpHiveAllocate(Length,FALSE,0);
  1816. if (DriverNode->Group.Buffer == NULL) {
  1817. return ENOMEM;
  1818. }
  1819. DriverNode->Group.Length = 0;
  1820. DriverNode->Group.MaximumLength = Length;
  1821. RtlAppendUnicodeToString(&DriverNode->Group, Group);
  1822. //
  1823. // Name
  1824. //
  1825. Length = (wcslen(Name) + 1) * sizeof(WCHAR);
  1826. DriverNode->Name.Buffer = BlpHiveAllocate(Length,FALSE,0);
  1827. if (DriverNode->Name.Buffer == NULL) {
  1828. return ENOMEM;
  1829. }
  1830. DriverNode->Name.Length = 0;
  1831. DriverNode->Name.MaximumLength = Length;
  1832. RtlAppendUnicodeToString(&DriverNode->Name, Name);
  1833. //
  1834. // Tag/ErrorControl
  1835. //
  1836. DriverNode->Tag = Tag;
  1837. DriverNode->ErrorControl = ErrorControl;
  1838. if (InsertAtHead) {
  1839. InsertHeadList(BootDriverListHead, &DriverListEntry->Link);
  1840. } else {
  1841. InsertTailList(BootDriverListHead, &DriverListEntry->Link);
  1842. }
  1843. return ESUCCESS;
  1844. }
  1845. #define HFILE_TYPE_ALTERNATE 1 // alternate, in order for boot to be able to boot downlevel OSes
  1846. BOOLEAN
  1847. BlInitializeHive(
  1848. IN PVOID HiveImage,
  1849. IN PCMHIVE Hive,
  1850. IN BOOLEAN IsAlternate
  1851. )
  1852. /*++
  1853. Routine Description:
  1854. Initializes the hive data structure based on the in-memory hive image.
  1855. Arguments:
  1856. HiveImage - Supplies a pointer to the in-memory hive image.
  1857. Hive - Supplies the CMHIVE structure to be filled in.
  1858. IsAlternate - Supplies whether or not the hive is the alternate hive,
  1859. which indicates that the primary hive is corrupt and should be
  1860. rewritten by the system.
  1861. Return Value:
  1862. TRUE - Hive successfully initialized.
  1863. FALSE - Hive is corrupt.
  1864. --*/
  1865. {
  1866. NTSTATUS status;
  1867. ULONG HiveCheckCode;
  1868. status = HvInitializeHive(
  1869. &Hive->Hive,
  1870. HINIT_MEMORY_INPLACE,
  1871. FALSE,
  1872. IsAlternate ? HFILE_TYPE_ALTERNATE : HFILE_TYPE_PRIMARY,
  1873. HiveImage,
  1874. (PALLOCATE_ROUTINE)BlpHiveAllocate, // allocate
  1875. NULL, // free
  1876. NULL, // setsize
  1877. NULL, // write
  1878. NULL, // read
  1879. NULL, // flush
  1880. 1, // cluster
  1881. NULL
  1882. );
  1883. if (!NT_SUCCESS(status)) {
  1884. return FALSE;
  1885. }
  1886. HiveCheckCode = CmCheckRegistry(Hive,CM_CHECK_REGISTRY_LOADER_CLEAN|CM_CHECK_REGISTRY_HIVE_CHECK);
  1887. if (HiveCheckCode != 0) {
  1888. return(FALSE);
  1889. } else {
  1890. return TRUE;
  1891. }
  1892. }
  1893. PVOID
  1894. BlpHiveAllocate(
  1895. IN ULONG Length,
  1896. IN BOOLEAN UseForIo,
  1897. IN ULONG Tag
  1898. )
  1899. /*++
  1900. Routine Description:
  1901. Wrapper for hive allocation calls. It just calls BlAllocateHeap.
  1902. Arguments:
  1903. Length - Supplies the size of block required in bytes.
  1904. UseForIo - Supplies whether or not the memory is to be used for I/O
  1905. (this is currently ignored)
  1906. Return Value:
  1907. address of the block of memory
  1908. or
  1909. NULL if no memory available
  1910. --*/
  1911. {
  1912. return(BlAllocateHeap(Length));
  1913. }
  1914. NTSTATUS
  1915. HvLoadHive(
  1916. PHHIVE Hive
  1917. )
  1918. {
  1919. UNREFERENCED_PARAMETER(Hive);
  1920. return(STATUS_SUCCESS);
  1921. }
  1922. NTSTATUS
  1923. HvMapHive(
  1924. PHHIVE Hive
  1925. )
  1926. {
  1927. UNREFERENCED_PARAMETER(Hive);
  1928. return(STATUS_SUCCESS);
  1929. }
  1930. NTSTATUS
  1931. HvpAdjustHiveFreeDisplay(
  1932. IN PHHIVE Hive,
  1933. IN ULONG HiveLength,
  1934. IN HSTORAGE_TYPE Type
  1935. )
  1936. {
  1937. UNREFERENCED_PARAMETER(Hive);
  1938. UNREFERENCED_PARAMETER(HiveLength);
  1939. UNREFERENCED_PARAMETER(Type);
  1940. return(STATUS_SUCCESS);
  1941. }
  1942. VOID
  1943. HvpAddFreeCellHint(
  1944. PHHIVE Hive,
  1945. HCELL_INDEX Cell,
  1946. ULONG Index,
  1947. HSTORAGE_TYPE Type
  1948. )
  1949. {
  1950. UNREFERENCED_PARAMETER(Hive);
  1951. UNREFERENCED_PARAMETER(Cell);
  1952. UNREFERENCED_PARAMETER(Index);
  1953. UNREFERENCED_PARAMETER(Type);
  1954. }
  1955. VOID
  1956. HvpRemoveFreeCellHint(
  1957. PHHIVE Hive,
  1958. HCELL_INDEX Cell,
  1959. ULONG Index,
  1960. HSTORAGE_TYPE Type
  1961. )
  1962. {
  1963. UNREFERENCED_PARAMETER(Hive);
  1964. UNREFERENCED_PARAMETER(Cell);
  1965. UNREFERENCED_PARAMETER(Index);
  1966. UNREFERENCED_PARAMETER(Type);
  1967. }
  1968. HCELL_INDEX
  1969. HvpFindFreeCell(
  1970. PHHIVE Hive,
  1971. ULONG Index,
  1972. ULONG NewSize,
  1973. HSTORAGE_TYPE Type,
  1974. HCELL_INDEX Vicinity
  1975. )
  1976. {
  1977. UNREFERENCED_PARAMETER(Hive);
  1978. UNREFERENCED_PARAMETER(Index);
  1979. UNREFERENCED_PARAMETER(Type);
  1980. UNREFERENCED_PARAMETER(NewSize);
  1981. UNREFERENCED_PARAMETER(Vicinity);
  1982. return HCELL_NIL;
  1983. }
  1984. VOID
  1985. CmpTouchView(
  1986. IN PCMHIVE CmHive,
  1987. IN PCM_VIEW_OF_FILE CmView,
  1988. IN ULONG Cell
  1989. )
  1990. {
  1991. UNREFERENCED_PARAMETER(CmHive);
  1992. UNREFERENCED_PARAMETER(CmView);
  1993. UNREFERENCED_PARAMETER(Cell);
  1994. }
  1995. NTSTATUS
  1996. CmpMapThisBin(
  1997. PCMHIVE CmHive,
  1998. HCELL_INDEX Cell,
  1999. BOOLEAN Touch
  2000. )
  2001. {
  2002. UNREFERENCED_PARAMETER(CmHive);
  2003. UNREFERENCED_PARAMETER(Cell);
  2004. UNREFERENCED_PARAMETER(Touch);
  2005. return(STATUS_SUCCESS);
  2006. }
  2007. /*
  2008. NTSTATUS
  2009. CmpMapCmView(
  2010. IN PCMHIVE CmHive,
  2011. IN ULONG FileOffset,
  2012. OUT PCM_VIEW_OF_FILE *CmView
  2013. )
  2014. {
  2015. UNREFERENCED_PARAMETER(CmHive);
  2016. UNREFERENCED_PARAMETER(FileOffset);
  2017. UNREFERENCED_PARAMETER(CmView);
  2018. return(STATUS_SUCCESS);
  2019. }
  2020. VOID
  2021. CmpPinCmView (
  2022. IN PCMHIVE CmHive,
  2023. PCM_VIEW_OF_FILE CmView
  2024. )
  2025. {
  2026. UNREFERENCED_PARAMETER(CmHive);
  2027. UNREFERENCED_PARAMETER(CmView);
  2028. }
  2029. VOID
  2030. CmpUnPinCmView (
  2031. IN PCMHIVE CmHive,
  2032. IN PCM_VIEW_OF_FILE CmView,
  2033. IN BOOLEAN SetClean
  2034. )
  2035. {
  2036. UNREFERENCED_PARAMETER(CmHive);
  2037. UNREFERENCED_PARAMETER(CmView);
  2038. UNREFERENCED_PARAMETER(SetClean);
  2039. }
  2040. VOID
  2041. CmpLazyFlush(
  2042. VOID
  2043. )
  2044. {
  2045. }
  2046. */
  2047. /*
  2048. NTSTATUS
  2049. CmpDoFileSetSize(
  2050. PHHIVE Hive,
  2051. ULONG FileType,
  2052. ULONG FileSize
  2053. )
  2054. {
  2055. UNREFERENCED_PARAMETER(Hive);
  2056. UNREFERENCED_PARAMETER(FileType);
  2057. UNREFERENCED_PARAMETER(FileSize);
  2058. return(STATUS_SUCCESS);
  2059. }
  2060. */
  2061. BOOLEAN
  2062. HvMarkCellDirty(
  2063. PHHIVE Hive,
  2064. HCELL_INDEX Cell
  2065. )
  2066. {
  2067. UNREFERENCED_PARAMETER(Hive);
  2068. UNREFERENCED_PARAMETER(Cell);
  2069. return(TRUE);
  2070. }
  2071. BOOLEAN
  2072. HvMarkDirty(
  2073. PHHIVE Hive,
  2074. HCELL_INDEX Start,
  2075. ULONG Length,
  2076. BOOLEAN DirtyAndPin
  2077. )
  2078. {
  2079. UNREFERENCED_PARAMETER(Hive);
  2080. UNREFERENCED_PARAMETER(Start);
  2081. UNREFERENCED_PARAMETER(Length);
  2082. UNREFERENCED_PARAMETER(DirtyAndPin);
  2083. return(TRUE);
  2084. }
  2085. BOOLEAN
  2086. HvpDoWriteHive(
  2087. PHHIVE Hive,
  2088. ULONG FileType
  2089. )
  2090. {
  2091. UNREFERENCED_PARAMETER(Hive);
  2092. UNREFERENCED_PARAMETER(FileType);
  2093. return(TRUE);
  2094. }
  2095. BOOLEAN
  2096. HvpGrowLog1(
  2097. PHHIVE Hive,
  2098. ULONG Count
  2099. )
  2100. {
  2101. UNREFERENCED_PARAMETER(Hive);
  2102. UNREFERENCED_PARAMETER(Count);
  2103. return(TRUE);
  2104. }
  2105. BOOLEAN
  2106. HvpGrowLog2(
  2107. PHHIVE Hive,
  2108. ULONG Size
  2109. )
  2110. {
  2111. UNREFERENCED_PARAMETER(Hive);
  2112. UNREFERENCED_PARAMETER(Size);
  2113. return(TRUE);
  2114. }
  2115. BOOLEAN
  2116. CmpValidateHiveSecurityDescriptors(
  2117. IN PHHIVE Hive,
  2118. OUT PBOOLEAN ResetSD
  2119. )
  2120. {
  2121. UNREFERENCED_PARAMETER(Hive);
  2122. return(TRUE);
  2123. }
  2124. BOOLEAN
  2125. CmpTestRegistryLock()
  2126. {
  2127. return TRUE;
  2128. }
  2129. BOOLEAN
  2130. CmpTestRegistryLockExclusive()
  2131. {
  2132. return TRUE;
  2133. }
  2134. BOOLEAN
  2135. HvIsBinDirty(
  2136. IN PHHIVE Hive,
  2137. IN HCELL_INDEX Cell
  2138. )
  2139. {
  2140. return(FALSE);
  2141. }
  2142. PHBIN
  2143. HvpAddBin(
  2144. IN PHHIVE Hive,
  2145. IN ULONG NewSize,
  2146. IN HSTORAGE_TYPE Type
  2147. )
  2148. {
  2149. return(NULL);
  2150. }
  2151. VOID
  2152. CmpReleaseGlobalQuota(
  2153. IN ULONG Size
  2154. )
  2155. {
  2156. }
  2157. #if DOCKINFO_VERBOSE
  2158. VOID
  2159. BlDiagDisplayProfileList(
  2160. IN PCM_HARDWARE_PROFILE_LIST ProfileList,
  2161. IN PCM_HARDWARE_PROFILE_ALIAS_LIST AliasList,
  2162. IN BOOLEAN WaitForUserInput
  2163. )
  2164. /*++
  2165. Routine Description:
  2166. This is a diagnostic function only!
  2167. Display hardware profile list on console, optionally wait for user
  2168. input before proceeding.
  2169. Arguments:
  2170. ProfileList - Supplies a list of hardware profiles to display
  2171. WaitForUserInput - Prompt user to hit a key ('y') to continue, and wait
  2172. for user's input if TRUE. Don't wait if FALSE.
  2173. Return Value:
  2174. None.
  2175. --*/
  2176. {
  2177. TCHAR Buffer[200];
  2178. TCHAR StrFriendlyName[30];
  2179. PTCHAR AliasType [] = {
  2180. TEXT("NotAliasable"), // 0
  2181. TEXT("Aliasable "), // 1
  2182. TEXT("True Match "), // 2
  2183. TEXT("True & Alias"), // 3
  2184. TEXT("Pristine "), // 4
  2185. TEXT("Pris & Alias"), // 5
  2186. TEXT("Pris & True "), // 6
  2187. TEXT("P & A & T ") // 7
  2188. };
  2189. ULONG Count;
  2190. ULONG i;
  2191. // display header
  2192. _stprintf(Buffer, TEXT("Profiles: <PrefOrd, Id - Aliased FriendlyName>\r\n\0"));
  2193. ArcWrite(BlConsoleOutDeviceId, Buffer, _tcslen(Buffer)*sizeof(TCHAR), &Count);
  2194. // for each hardware profile
  2195. for (i = 0; i < ProfileList->CurrentProfileCount; ++i) {
  2196. #ifdef UNICODE
  2197. wcsncpy(
  2198. StrFriendlyName,
  2199. ProfileList->Profile[i].FriendlyName,
  2200. ProfileList->Profile[i].NameLength,
  2201. );
  2202. StrFriendlyName[29] = L'\0';
  2203. StrFriendlyName[ProfileList->Profile[i].NameLength] = L'\0';
  2204. #else
  2205. // copy and convert unicode fields to ascii for output
  2206. RtlUnicodeToMultiByteN(StrFriendlyName,
  2207. sizeof(StrFriendlyName),
  2208. &Count,
  2209. ProfileList->Profile[i].FriendlyName,
  2210. ProfileList->Profile[i].NameLength);
  2211. StrFriendlyName[Count] = '\0';
  2212. #endif
  2213. // display info for current profile
  2214. _stprintf(Buffer,
  2215. TEXT(" <%2ld> %2ld - %s \"%s\"\r\n\0"),
  2216. ProfileList->Profile[i].PreferenceOrder,
  2217. ProfileList->Profile[i].Id,
  2218. AliasType[ ProfileList->Profile[i].Flags ],
  2219. StrFriendlyName);
  2220. ArcWrite(
  2221. BlConsoleOutDeviceId,
  2222. Buffer,
  2223. _tcslen(Buffer)*sizeof(TCHAR),
  2224. &Count );
  2225. }
  2226. // display header
  2227. _stprintf(Buffer, TEXT("Aliases: <Profile #> DockState [DockID, SerialNumber]\r\n\0"));
  2228. ArcWrite(BlConsoleOutDeviceId, Buffer, _tcslen(Buffer)*sizeof(TCHAR), &Count);
  2229. if (AliasList) {
  2230. for (i = 0; i < AliasList->CurrentAliasCount; i++) {
  2231. _stprintf(Buffer, TEXT(" <%2ld> %x [%x, %x]\r\n\0"),
  2232. AliasList->Alias[i].ProfileNumber,
  2233. AliasList->Alias[i].DockState,
  2234. AliasList->Alias[i].DockID,
  2235. AliasList->Alias[i].SerialNumber);
  2236. ArcWrite(BlConsoleOutDeviceId, Buffer, _tcslen(Buffer)*sizeof(TCHAR), &Count);
  2237. }
  2238. }
  2239. if(WaitForUserInput) {
  2240. // display prompt and wait for user input to continue
  2241. _stprintf(Buffer, TEXT("press 'y' (lowercase) to continue...\r\n\0"));
  2242. ArcWrite(BlConsoleOutDeviceId, Buffer, _tcslen(Buffer)*sizeof(TCHAR), &Count);
  2243. while (BlGetKey() != 'y') {
  2244. //
  2245. // nothing
  2246. //
  2247. }
  2248. }
  2249. }
  2250. #endif
  2251. VOID
  2252. BlDockInfoFilterDockingState(
  2253. IN OUT PCM_HARDWARE_PROFILE_LIST ProfileList,
  2254. IN OUT PCM_HARDWARE_PROFILE_ALIAS_LIST AliasList,
  2255. IN ULONG DockingState,
  2256. IN ULONG DockID,
  2257. IN ULONG SerialNumber
  2258. )
  2259. /*++
  2260. Routine Description:
  2261. Discard all hardware profiles that do not have the
  2262. DOCKINFO_UNDOCKED bit set in the DockState field
  2263. Arguments:
  2264. ProfileList - Supplies a list of hardware profiles.
  2265. Returns a list containing a subset of the supplied
  2266. hardware profiles.
  2267. Return Value:
  2268. None.
  2269. --*/
  2270. {
  2271. ULONG i = 0;
  2272. ULONG j;
  2273. ULONG len;
  2274. ULONG mask = HW_PROFILE_DOCKSTATE_UNDOCKED | HW_PROFILE_DOCKSTATE_DOCKED;
  2275. BOOLEAN trueMatch = FALSE;
  2276. #if DOCKINFO_VERBOSE
  2277. TCHAR buffer[200];
  2278. ULONG count;
  2279. #endif
  2280. if (AliasList) {
  2281. while (i < AliasList->CurrentAliasCount) {
  2282. if (((AliasList->Alias[i].DockState & mask) != 0) &&
  2283. ((AliasList->Alias[i].DockState & mask) != DockingState)) {
  2284. //
  2285. // This alias claims to be docked or undocked, but does not
  2286. // match the current state. Therefore skip it.
  2287. //
  2288. ;
  2289. } else if ((AliasList->Alias[i].DockID == DockID) &&
  2290. (AliasList->Alias[i].SerialNumber == SerialNumber)) {
  2291. //
  2292. // This alias matches so mark the profile.
  2293. //
  2294. for (j = 0; j < ProfileList->CurrentProfileCount; j++) {
  2295. if (ProfileList->Profile[j].Id ==
  2296. AliasList->Alias[i].ProfileNumber) {
  2297. ProfileList->Profile[j].Flags =
  2298. CM_HP_FLAGS_TRUE_MATCH;
  2299. trueMatch = TRUE;
  2300. }
  2301. }
  2302. }
  2303. i++;
  2304. }
  2305. }
  2306. #if DOCKINFO_VERBOSE
  2307. _stprintf(buffer, TEXT("Filtering Profiles ...\r\n\0"));
  2308. ArcWrite(BlConsoleOutDeviceId, buffer, _tcslen(buffer)*sizeof(TCHAR), &count);
  2309. #endif
  2310. i = 0;
  2311. while (i < ProfileList->CurrentProfileCount) {
  2312. if ((ProfileList->Profile[i].Flags & CM_HP_FLAGS_PRISTINE) &&
  2313. !trueMatch &&
  2314. AliasList) {
  2315. //
  2316. // Leave this one in the list
  2317. //
  2318. i++;
  2319. continue;
  2320. } else if (ProfileList->Profile[i].Flags & CM_HP_FLAGS_ALIASABLE) {
  2321. //
  2322. // Leave this one in the list
  2323. //
  2324. i++;
  2325. continue;
  2326. } else if (ProfileList->Profile[i].Flags & CM_HP_FLAGS_TRUE_MATCH) {
  2327. //
  2328. // Leave this one in the list
  2329. //
  2330. i++;
  2331. continue;
  2332. }
  2333. //
  2334. // discard this profile by (1) shifting remaining profiles in
  2335. // array to fill in the space of this discarded profile
  2336. // and (2) decrementing profile count
  2337. //
  2338. len = ProfileList->CurrentProfileCount - i - 1;
  2339. if (0 < len) {
  2340. RtlMoveMemory(&ProfileList->Profile[i],
  2341. &ProfileList->Profile[i+1],
  2342. sizeof(CM_HARDWARE_PROFILE) * len);
  2343. }
  2344. --ProfileList->CurrentProfileCount;
  2345. }
  2346. }
  2347. VOID
  2348. BlDockInfoFilterProfileList(
  2349. IN OUT PCM_HARDWARE_PROFILE_LIST ProfileList,
  2350. IN OUT PCM_HARDWARE_PROFILE_ALIAS_LIST AliasList
  2351. )
  2352. /*++
  2353. Routine Description:
  2354. Filters hardware profile list by discarding hardware profiles that
  2355. do not match the docking station information returned by NTDETECT.
  2356. Arguments:
  2357. ProfileList - Supplies a list of hardware profiles.
  2358. - Returns a list containing a subset of the supplied
  2359. hardware profiles.
  2360. Return Value:
  2361. None.
  2362. --*/
  2363. {
  2364. #if DOCKINFO_VERBOSE
  2365. // display ProfileList prior to filtering
  2366. BlDiagDisplayProfileList(ProfileList, AliasList, TRUE);
  2367. #endif
  2368. if (1 == ProfileList->CurrentProfileCount) {
  2369. if (ProfileList->Profile[0].Flags & CM_HP_FLAGS_PRISTINE) {
  2370. //
  2371. // Nothing to filter.
  2372. //
  2373. return;
  2374. }
  2375. }
  2376. BlDockInfoFilterDockingState (
  2377. ProfileList,
  2378. AliasList,
  2379. BlLoaderBlock->Extension->Profile.DockingState,
  2380. BlLoaderBlock->Extension->Profile.DockID,
  2381. BlLoaderBlock->Extension->Profile.SerialNumber);
  2382. #if DOCKINFO_VERBOSE
  2383. // display ProfileList prior to filtering
  2384. BlDiagDisplayProfileList(ProfileList, AliasList, TRUE);
  2385. #endif
  2386. }
  2387. int
  2388. BlIsReturnToOSChoicesValid(
  2389. VOID
  2390. )
  2391. /*++
  2392. Routine Description:
  2393. Indicates whether the "Return to OS Choices Menu" should
  2394. be shown as advanced boot option or not.
  2395. Arguments:
  2396. None
  2397. Return Value:
  2398. 1 if yes otherwise 0.
  2399. --*/
  2400. {
  2401. return BlShowReturnToOSChoices;
  2402. }