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.

3712 lines
100 KiB

  1. /******************************************************************************
  2. Copyright(c) Microsoft Corporation
  3. Module Name:
  4. BootCfg64.cpp
  5. Abstract:
  6. This file is intended to have the functionality for
  7. configuring, displaying, changing and deleting boot.ini
  8. settings for the local host for a 64 bit system.
  9. Author:
  10. J.S.Vasu 17/1/2001 .
  11. Revision History:
  12. J.S.Vasu 17/1/2001 Created it.
  13. SanthoshM.B 10/2/2001 Modified it.
  14. J.S.Vasu 15/2/2001 Modified it.
  15. ******************************************************************************/
  16. #include "pch.h"
  17. #include "resource.h"
  18. #include "BootCfg.h"
  19. #include "BootCfg64.h"
  20. //Global Linked lists for storing the boot entries
  21. LIST_ENTRY BootEntries;
  22. LIST_ENTRY ActiveUnorderedBootEntries;
  23. LIST_ENTRY InactiveUnorderedBootEntries;
  24. // ***************************************************************************
  25. //
  26. // Name : InitializeEfi
  27. //
  28. // Synopsis : This routine initializes the EFI environment required
  29. // Initializes the function pointers for the
  30. // NT Boot Entry Management API's
  31. //
  32. // Parameters : None
  33. //
  34. // Return Type : DWORD
  35. //
  36. // Global Variables: Global Linked lists for storing the boot entries
  37. // LIST_ENTRY BootEntries;
  38. // LIST_ENTRY ActiveUnorderedBootEntries;
  39. // LIST_ENTRY InactiveUnorderedBootEntries;
  40. //
  41. // ***************************************************************************
  42. DWORD InitializeEFI(void)
  43. {
  44. DWORD error;
  45. NTSTATUS status;
  46. BOOLEAN wasEnabled;
  47. HMODULE hModule;
  48. PBOOT_ENTRY_LIST ntBootEntries = NULL;
  49. PMY_BOOT_ENTRY bootEntry;
  50. PLIST_ENTRY listEntry;
  51. PULONG BootEntryOrder;
  52. ULONG BootEntryOrderCount;
  53. PULONG OriginalBootEntryOrder;
  54. ULONG OriginalBootEntryOrderCount;
  55. ULONG length, i, myId;
  56. TCHAR dllName[MAX_PATH];
  57. // Enable the privilege that is necessary to query/set NVRAM.
  58. status = RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE,
  59. TRUE,
  60. FALSE,
  61. &wasEnabled
  62. );
  63. if (!NT_SUCCESS(status))
  64. {
  65. error = RtlNtStatusToDosError( status );
  66. DISPLAY_MESSAGE( stderr, GetResString(IDS_INSUFF_PRIV));
  67. }
  68. // Load ntdll.dll from the system directory. This is used to get the
  69. // function addresses for the various NT Boot Entry Management API's used by
  70. // this tool.
  71. if(!GetSystemDirectory( dllName, MAX_PATH ))
  72. {
  73. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  74. ShowLastError(stderr);
  75. return FALSE;
  76. }
  77. lstrcat(dllName, _T("\\ntdll.dll"));
  78. hModule = LoadLibrary( dllName );
  79. if ( hModule == NULL )
  80. {
  81. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  82. ShowLastError(stderr);
  83. return FALSE;
  84. }
  85. // Get the system boot order list.
  86. length = 0;
  87. status = NtQueryBootEntryOrder( NULL, &length );
  88. if ( status != STATUS_BUFFER_TOO_SMALL )
  89. {
  90. if ( status == STATUS_SUCCESS )
  91. {
  92. length = 0;
  93. }
  94. else
  95. {
  96. error = RtlNtStatusToDosError( status );
  97. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_QUERY_BOOTENTRY) );
  98. return FALSE;
  99. }
  100. }
  101. if ( length != 0 )
  102. {
  103. BootEntryOrder = (PULONG)malloc( length * sizeof(ULONG) );
  104. if(BootEntryOrder == NULL)
  105. {
  106. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  107. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  108. ShowLastError(stderr);
  109. return FALSE;
  110. }
  111. status = NtQueryBootEntryOrder( BootEntryOrder, &length );
  112. if ( status != STATUS_SUCCESS )
  113. {
  114. error = RtlNtStatusToDosError( status );
  115. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_QUERY_BOOTENTRY) );
  116. if(BootEntryOrder)
  117. free(BootEntryOrder);
  118. return FALSE;
  119. }
  120. }
  121. BootEntryOrderCount = length;
  122. //Enumerate all the boot entries
  123. status = BootCfg_EnumerateBootEntries(&ntBootEntries);
  124. if ( status != STATUS_SUCCESS )
  125. {
  126. error = RtlNtStatusToDosError( status );
  127. //free the ntBootEntries list
  128. if(ntBootEntries)
  129. free(ntBootEntries);
  130. if(BootEntryOrder)
  131. free(BootEntryOrder);
  132. return FALSE;
  133. }
  134. //Initialize the various head pointers
  135. InitializeListHead( &BootEntries );
  136. InitializeListHead( &ActiveUnorderedBootEntries );
  137. InitializeListHead( &InactiveUnorderedBootEntries );
  138. //Convert the bootentries into our know format -- MY_BOOT_ENTRIES.
  139. if(ConvertBootEntries( ntBootEntries ) == EXIT_FAILURE)
  140. {
  141. if(ntBootEntries)
  142. free(ntBootEntries);
  143. if(BootEntryOrder)
  144. free(BootEntryOrder);
  145. return FALSE;
  146. }
  147. //free the memory allocated for the enumeration
  148. if(ntBootEntries)
  149. free(ntBootEntries);
  150. // Build the ordered boot entry list.
  151. myId = 1;
  152. for ( i = 0; i < BootEntryOrderCount; i++ )
  153. {
  154. ULONG id = BootEntryOrder[i];
  155. for ( listEntry = ActiveUnorderedBootEntries.Flink;
  156. listEntry != &ActiveUnorderedBootEntries;
  157. listEntry = listEntry->Flink )
  158. {
  159. bootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  160. if ( bootEntry->Id == id )
  161. {
  162. //Mark this entry as "Ordered" as the ordered id is found
  163. bootEntry->Ordered = 1;
  164. //Assign the internal ID
  165. bootEntry->myId = myId++;
  166. listEntry = listEntry->Blink;
  167. RemoveEntryList( &bootEntry->ListEntry );
  168. InsertTailList( &BootEntries, &bootEntry->ListEntry );
  169. bootEntry->ListHead = &BootEntries;
  170. }
  171. }
  172. for ( listEntry = InactiveUnorderedBootEntries.Flink;
  173. listEntry != &InactiveUnorderedBootEntries;
  174. listEntry = listEntry->Flink )
  175. {
  176. bootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  177. if ( bootEntry->Id == id )
  178. {
  179. //Mark this entry as ordered as the ordered id is found
  180. bootEntry->Ordered = 1;
  181. //Assign the internal ID
  182. bootEntry->myId = myId++;
  183. listEntry = listEntry->Blink;
  184. RemoveEntryList( &bootEntry->ListEntry );
  185. InsertTailList( &BootEntries, &bootEntry->ListEntry );
  186. bootEntry->ListHead = &BootEntries;
  187. }
  188. }
  189. }
  190. //Now add the boot entries that are not a part of the ordered list
  191. for (listEntry = ActiveUnorderedBootEntries.Flink;
  192. listEntry != &ActiveUnorderedBootEntries;
  193. listEntry = listEntry->Flink )
  194. {
  195. bootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  196. if ( bootEntry->Ordered != 1 )
  197. {
  198. //Assign the internal ID
  199. bootEntry->myId = myId++;
  200. listEntry = listEntry->Blink;
  201. RemoveEntryList( &bootEntry->ListEntry );
  202. InsertTailList( &BootEntries, &bootEntry->ListEntry );
  203. bootEntry->ListHead = &BootEntries;
  204. }
  205. }
  206. for (listEntry = InactiveUnorderedBootEntries.Flink;
  207. listEntry != &InactiveUnorderedBootEntries;
  208. listEntry = listEntry->Flink)
  209. {
  210. bootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  211. if ( bootEntry->Id != 1 )
  212. {
  213. //Assign the internal ID
  214. bootEntry->myId = myId++;
  215. listEntry = listEntry->Blink;
  216. RemoveEntryList( &bootEntry->ListEntry );
  217. InsertTailList( &BootEntries, &bootEntry->ListEntry );
  218. bootEntry->ListHead = &BootEntries;
  219. }
  220. }
  221. if(BootEntryOrder)
  222. free(BootEntryOrder);
  223. return TRUE;
  224. }
  225. // ***************************************************************************
  226. //
  227. // Name : QueryBootIniSettings_IA64
  228. //
  229. // Synopsis : This routine is displays the boot entries and their settings
  230. // for an EFI based machine
  231. //
  232. // Parameters : None
  233. //
  234. // Return Type : VOID
  235. //
  236. // Global Variables: Global Linked lists for storing the boot entries
  237. // LIST_ENTRY BootEntries;
  238. //
  239. // ***************************************************************************
  240. BOOL QueryBootIniSettings_IA64(void)
  241. {
  242. if(DisplayBootOptions() == EXIT_FAILURE)
  243. return EXIT_FAILURE;
  244. DisplayBootEntry();
  245. //Remember to free the memory for the linked lists here
  246. return EXIT_SUCCESS;
  247. }
  248. // ***************************************************************************
  249. //
  250. // Name : BootCfg_EnumerateBootEntries
  251. //
  252. // Synopsis : This routine enumerates the boot entries and fills the
  253. // BootEntryList
  254. // This routine will fill in the Boot entry list. The caller
  255. // of this function needs to free the memory for ntBootEntries.
  256. //
  257. // Parameters : Pointer to the BOOT_ENTRY_LIST structure
  258. //
  259. // Return Type : NTSTATUS
  260. //
  261. // Global Variables: None
  262. //
  263. // ***************************************************************************
  264. NTSTATUS BootCfg_EnumerateBootEntries(PBOOT_ENTRY_LIST *ntBootEntries)
  265. {
  266. DWORD error;
  267. NTSTATUS status;
  268. ULONG length = 0;
  269. // Query all existing boot entries.
  270. status = NtEnumerateBootEntries( NULL, &length );
  271. if ( status != STATUS_BUFFER_TOO_SMALL )
  272. {
  273. if ( status == STATUS_SUCCESS )
  274. {
  275. length = 0;
  276. }
  277. else
  278. {
  279. error = RtlNtStatusToDosError( status );
  280. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_ENUM_BOOTENTRY) );
  281. }
  282. }
  283. if ( length != 0 )
  284. {
  285. *ntBootEntries = (PBOOT_ENTRY_LIST)malloc( length );
  286. if(*ntBootEntries == NULL)
  287. {
  288. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  289. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  290. ShowLastError(stderr);
  291. return STATUS_UNSUCCESSFUL;
  292. }
  293. status = NtEnumerateBootEntries( *ntBootEntries, &length );
  294. if ( status != STATUS_SUCCESS )
  295. {
  296. error = RtlNtStatusToDosError( status );
  297. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_ENUM_BOOTENTRY) );
  298. }
  299. }
  300. return status;
  301. }
  302. // ***************************************************************************
  303. //
  304. // Name : BootCfg_QueryBootOptions
  305. //
  306. // Synopsis : This routine enumerates the boot options and fills the
  307. // BOOT_OPTIONS
  308. // The caller of this function needs to free the memory for
  309. // BOOT_OPTIONS.
  310. //
  311. // Parameters : Pointer to the BOOT_ENTRY_LIST structure
  312. //
  313. // Return Type : NTSTATUS
  314. //
  315. // Global Variables: NONE
  316. //
  317. // ***************************************************************************
  318. NTSTATUS BootCfg_QueryBootOptions(PBOOT_OPTIONS *ppBootOptions)
  319. {
  320. DWORD error;
  321. NTSTATUS status;
  322. ULONG length = 0;
  323. //Querying the Boot options
  324. status = NtQueryBootOptions( NULL, &length );
  325. if ( status == STATUS_NOT_IMPLEMENTED )
  326. {
  327. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_EFINVRAM) );
  328. }
  329. if ( status != STATUS_BUFFER_TOO_SMALL )
  330. {
  331. error = RtlNtStatusToDosError( status );
  332. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_QUERY_BOOTOPTIONS) );
  333. }
  334. *ppBootOptions = (PBOOT_OPTIONS)malloc(length);
  335. if(*ppBootOptions == NULL)
  336. {
  337. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  338. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  339. ShowLastError(stderr);
  340. return STATUS_UNSUCCESSFUL;
  341. }
  342. status = NtQueryBootOptions( *ppBootOptions, &length );
  343. if ( status != STATUS_SUCCESS )
  344. {
  345. error = RtlNtStatusToDosError( status );
  346. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_QUERY_BOOTOPTIONS) );
  347. }
  348. return status;
  349. }
  350. // ***************************************************************************
  351. //
  352. // Name : RawStringOsOptions_IA64
  353. //
  354. // Synopsis : Allows the user to add the OS load options specifed
  355. // as a raw string at the cmdline to the boot
  356. //
  357. // Parameters : DWORD argc (in) - Number of command line arguments
  358. // LPCTSTR argv (in) - Array containing command line arguments
  359. //
  360. // Return Type : DWORD
  361. //
  362. // Global Variables: Global Linked lists for storing the boot entries
  363. // LIST_ENTRY BootEntries;
  364. //
  365. // ***************************************************************************
  366. DWORD RawStringOsOptions_IA64( DWORD argc, LPCTSTR argv[] )
  367. {
  368. BOOL bUsage = FALSE ;
  369. BOOL bRaw = FALSE ;
  370. DWORD dwBootID = 0;
  371. BOOL bBootIdFound = FALSE;
  372. DWORD dwExitCode = ERROR_SUCCESS;
  373. PMY_BOOT_ENTRY mybootEntry;
  374. PLIST_ENTRY listEntry;
  375. PBOOT_ENTRY bootEntry;
  376. STRING256 szRawString = NULL_STRING ;
  377. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  378. BOOL bAppendFlag = FALSE ;
  379. STRING256 szAppendString = NULL_STRING ;
  380. PWINDOWS_OS_OPTIONS pWindowsOptions;
  381. // Building the TCMDPARSER structure
  382. TCMDPARSER cmdOptions[] =
  383. {
  384. { CMDOPTION_RAW, CP_MAIN_OPTION, 1, 0,&bRaw, NULL_STRING, NULL, NULL },
  385. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  386. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwBootID, NULL_STRING, NULL, NULL },
  387. { CMDOPTION_DEFAULT, CP_DEFAULT | CP_TYPE_TEXT | CP_MANDATORY, 1, 0, &szRawString,NULL_STRING, NULL, NULL },
  388. { CMDOPTION_APPEND , 0, 1, 0, &bAppendFlag,NULL_STRING, NULL, NULL }
  389. };
  390. // Parsing the copy option switches
  391. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  392. {
  393. dwExitCode = EXIT_FAILURE;
  394. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  395. ShowMessage(stderr,GetReason());
  396. return (dwExitCode);
  397. }
  398. // Displaying query usage if user specified -? with -query option
  399. if( bUsage )
  400. {
  401. displayRawUsage_IA64();
  402. return (EXIT_SUCCESS);
  403. }
  404. // error checking in case the
  405. // raw string does not start with a "/" .
  406. if(*szRawString != _T('/'))
  407. {
  408. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_FWDSLASH));
  409. return (EXIT_FAILURE);
  410. }
  411. //Trim any leading or trailing spaces
  412. if(szRawString)
  413. StrTrim(szRawString, _T(" "));
  414. //Query the boot entries till u get the BootID specified by the user
  415. for (listEntry = BootEntries.Flink;
  416. listEntry != &BootEntries;
  417. listEntry = listEntry->Flink)
  418. {
  419. //Get the boot entry
  420. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  421. if(mybootEntry->myId == dwBootID)
  422. {
  423. bBootIdFound = TRUE;
  424. bootEntry = &mybootEntry->NtBootEntry;
  425. //Check whether the bootEntry is a Windows one or not.
  426. //The OS load options can be added only to a Windows boot entry.
  427. if(!IsBootEntryWindows(bootEntry))
  428. {
  429. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  430. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  431. DISPLAY_MESSAGE(stderr, GetResString(IDS_INFO_NOTWINDOWS));
  432. dwExitCode = EXIT_FAILURE;
  433. break;
  434. }
  435. pWindowsOptions = (PWINDOWS_OS_OPTIONS)bootEntry->OsOptions;
  436. if(bAppendFlag == TRUE )
  437. {
  438. lstrcpy(szAppendString,pWindowsOptions->OsLoadOptions);
  439. lstrcat(szAppendString,TOKEN_EMPTYSPACE);
  440. lstrcat(szAppendString,szRawString);
  441. }
  442. else
  443. {
  444. lstrcpy(szAppendString,szRawString);
  445. }
  446. //display error message if Os Load options is more than 254
  447. // characters.
  448. if(lstrlen(szAppendString) >= MAX_RES_STRING)
  449. {
  450. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_STRING_LENGTH1),MAX_RES_STRING);
  451. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  452. break ;
  453. }
  454. //
  455. //Change the OS load options.
  456. //Pass NULL to friendly name as we are not changing the same
  457. //szAppendString is the Os load options specified by the user
  458. //to be appended or to be overwritten over the existing options
  459. //
  460. dwExitCode = ChangeBootEntry(bootEntry, NULL, szAppendString);
  461. if(dwExitCode == ERROR_SUCCESS)
  462. {
  463. _stprintf(szMsgBuffer, GetResString(IDS_SUCCESS_OSOPTIONS),dwBootID);
  464. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  465. }
  466. else
  467. {
  468. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  469. DISPLAY_MESSAGE(stderr, szMsgBuffer);
  470. }
  471. break;
  472. }
  473. }
  474. if(bBootIdFound == FALSE)
  475. {
  476. //Could not find the BootID specified by the user so output the message and return failure
  477. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  478. dwExitCode = EXIT_FAILURE;
  479. }
  480. //Remember to free memory allocated for the linked lists
  481. return (dwExitCode);
  482. }
  483. // ***************************************************************************
  484. //
  485. // Name : ChangeBootEntry
  486. //
  487. // Synopsis : This routine is used to change the FriendlyName and the
  488. // OS Options for a boot entry.
  489. //
  490. // Parameters : PBOOT_ENTRY bootEntry (in) - Pointer to a BootEntry structure
  491. // for which the changes needs to be made
  492. // LPTSTR lpNewFriendlyName (in) - String specifying the new friendly name.
  493. // LPTSTR lpOSLoadOptions (in) - String specifying the OS load options.
  494. //
  495. // Return Type : DWORD -- ERROR_SUCCESS on success
  496. // -- ERROR_FAILURE on failure
  497. //
  498. // Global Variables : None
  499. //
  500. // ***************************************************************************
  501. DWORD ChangeBootEntry(PBOOT_ENTRY bootEntry, LPTSTR lpNewFriendlyName, LPTSTR lpOSLoadOptions)
  502. {
  503. PBOOT_ENTRY_LIST bootEntryList;
  504. PBOOT_ENTRY bootEntryCopy;
  505. PMY_BOOT_ENTRY myBootEntry;
  506. PWINDOWS_OS_OPTIONS osOptions;
  507. ULONG length;
  508. PMY_BOOT_ENTRY myChBootEntry;
  509. NTSTATUS status;
  510. DWORD error, dwErrorCode = ERROR_SUCCESS;
  511. // Calculate the length of our internal structure. This includes
  512. // the base part of MY_BOOT_ENTRY plus the NT BOOT_ENTRY.
  513. //
  514. length = FIELD_OFFSET(MY_BOOT_ENTRY, NtBootEntry) + bootEntry->Length;
  515. myBootEntry = (PMY_BOOT_ENTRY)malloc(length);
  516. if(myBootEntry == NULL)
  517. {
  518. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  519. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  520. ShowLastError(stderr);
  521. dwErrorCode = EXIT_FAILURE;
  522. return dwErrorCode;
  523. }
  524. RtlZeroMemory(myBootEntry, length);
  525. //
  526. // Copy the NT BOOT_ENTRY into the allocated buffer.
  527. //
  528. bootEntryCopy = &myBootEntry->NtBootEntry;
  529. memcpy(bootEntryCopy, bootEntry, bootEntry->Length);
  530. myBootEntry->Id = bootEntry->Id;
  531. myBootEntry->Attributes = bootEntry->Attributes;
  532. //Change the friendly name if lpNewFriendlyName is not NULL
  533. if(lpNewFriendlyName)
  534. {
  535. myBootEntry->FriendlyName = lpNewFriendlyName;
  536. myBootEntry->FriendlyNameLength = ((ULONG)wcslen(lpNewFriendlyName) + 1) * sizeof(WCHAR);
  537. }
  538. else
  539. {
  540. myBootEntry->FriendlyName = (PWSTR)ADD_OFFSET(bootEntryCopy, FriendlyNameOffset);
  541. myBootEntry->FriendlyNameLength =
  542. ((ULONG)wcslen(myBootEntry->FriendlyName) + 1) * sizeof(WCHAR);
  543. }
  544. myBootEntry->BootFilePath = (PFILE_PATH)ADD_OFFSET(bootEntryCopy, BootFilePathOffset);
  545. // If this is an NT boot entry, capture the NT-specific information in
  546. // the OsOptions.
  547. osOptions = (PWINDOWS_OS_OPTIONS)bootEntryCopy->OsOptions;
  548. if ((bootEntryCopy->OsOptionsLength >= FIELD_OFFSET(WINDOWS_OS_OPTIONS, OsLoadOptions)) &&
  549. (strcmp((char *)osOptions->Signature, WINDOWS_OS_OPTIONS_SIGNATURE) == 0))
  550. {
  551. MBE_SET_IS_NT( myBootEntry );
  552. //To change the OS Load options
  553. if(lpOSLoadOptions)
  554. {
  555. myBootEntry->OsLoadOptions = lpOSLoadOptions;
  556. myBootEntry->OsLoadOptionsLength =
  557. ((ULONG)wcslen(lpOSLoadOptions) + 1) * sizeof(WCHAR);
  558. }
  559. else
  560. {
  561. myBootEntry->OsLoadOptions = osOptions->OsLoadOptions;
  562. myBootEntry->OsLoadOptionsLength =
  563. ((ULONG)wcslen(myBootEntry->OsLoadOptions) + 1) * sizeof(WCHAR);
  564. }
  565. myBootEntry->OsFilePath = (PFILE_PATH)ADD_OFFSET(osOptions, OsLoadPathOffset);
  566. }
  567. else
  568. {
  569. // Foreign boot entry. Just capture whatever OS options exist.
  570. //
  571. myBootEntry->ForeignOsOptions = bootEntryCopy->OsOptions;
  572. myBootEntry->ForeignOsOptionsLength = bootEntryCopy->OsOptionsLength;
  573. }
  574. myChBootEntry = CreateBootEntryFromBootEntry(myBootEntry);
  575. if(myChBootEntry == NULL)
  576. {
  577. dwErrorCode = EXIT_FAILURE;
  578. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  579. DISPLAY_MESSAGE(stderr, ERROR_TAG);
  580. ShowLastError(stderr);
  581. //free the memory
  582. if(myBootEntry)
  583. free(myBootEntry);
  584. return dwErrorCode;
  585. }
  586. //Call the modify API
  587. status = NtModifyBootEntry(&myChBootEntry->NtBootEntry);
  588. if ( status != STATUS_SUCCESS )
  589. {
  590. error = RtlNtStatusToDosError( status );
  591. dwErrorCode = error;
  592. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_MODIFY_BOOTENTRY) );
  593. }
  594. //free the memory
  595. if(myChBootEntry)
  596. free(myChBootEntry);
  597. if(myBootEntry)
  598. free(myBootEntry);
  599. return dwErrorCode;
  600. }
  601. // ***************************************************************************
  602. //
  603. // Name : CreateBootEntryFromBootEntry
  604. //
  605. // Synopsis : This routine is used to create a new MY_BOOT_ENTRY struct.
  606. // The caller of this function needs to free the memory allocated
  607. // for the MY_BOOT_ENTRY struct.
  608. //
  609. // Parameters : PBOOT_ENTRY bootEntry (in) - Pointer to a BootEntry structure
  610. // for which the changes needs to be made
  611. // LPTSTR lpNewFriendlyName (in) - String specifying the new friendly name.
  612. // LPTSTR lpOSLoadOptions (in) - String specifying the OS load options.
  613. //
  614. // Return Type : PMY_BOOT_ENTRY - Pointer to the new MY_BOOT_ENTRY strucure.
  615. // NULL on failure
  616. //
  617. //
  618. // Global Variables : None
  619. //
  620. // ***************************************************************************
  621. PMY_BOOT_ENTRY
  622. CreateBootEntryFromBootEntry (IN PMY_BOOT_ENTRY OldBootEntry)
  623. {
  624. ULONG requiredLength;
  625. ULONG osOptionsOffset;
  626. ULONG osLoadOptionsLength;
  627. ULONG osLoadPathOffset;
  628. ULONG osLoadPathLength;
  629. ULONG osOptionsLength;
  630. ULONG friendlyNameOffset;
  631. ULONG friendlyNameLength;
  632. ULONG bootPathOffset;
  633. ULONG bootPathLength;
  634. PMY_BOOT_ENTRY newBootEntry;
  635. PBOOT_ENTRY ntBootEntry;
  636. PWINDOWS_OS_OPTIONS osOptions;
  637. PFILE_PATH osLoadPath;
  638. PWSTR friendlyName;
  639. PFILE_PATH bootPath;
  640. // Calculate how long the internal boot entry needs to be. This includes
  641. // our internal structure, plus the BOOT_ENTRY structure that the NT APIs
  642. // use.
  643. //
  644. // Our structure:
  645. //
  646. requiredLength = FIELD_OFFSET(MY_BOOT_ENTRY, NtBootEntry);
  647. // Base part of NT structure:
  648. //
  649. requiredLength += FIELD_OFFSET(BOOT_ENTRY, OsOptions);
  650. // Save offset to BOOT_ENTRY.OsOptions. Add in base part of
  651. // WINDOWS_OS_OPTIONS. Calculate length in bytes of OsLoadOptions
  652. // and add that in.
  653. //
  654. osOptionsOffset = requiredLength;
  655. if ( MBE_IS_NT( OldBootEntry ) )
  656. {
  657. // Add in base part of WINDOWS_OS_OPTIONS. Calculate length in
  658. // bytes of OsLoadOptions and add that in.
  659. //
  660. requiredLength += FIELD_OFFSET(WINDOWS_OS_OPTIONS, OsLoadOptions);
  661. osLoadOptionsLength = OldBootEntry->OsLoadOptionsLength;
  662. requiredLength += osLoadOptionsLength;
  663. // Round up to a ULONG boundary for the OS FILE_PATH in the
  664. // WINDOWS_OS_OPTIONS. Save offset to OS FILE_PATH. Calculate length
  665. // in bytes of FILE_PATH and add that in. Calculate total length of
  666. // WINDOWS_OS_OPTIONS.
  667. //
  668. requiredLength = ALIGN_UP(requiredLength, ULONG);
  669. osLoadPathOffset = requiredLength;
  670. requiredLength += OldBootEntry->OsFilePath->Length;
  671. osLoadPathLength = requiredLength - osLoadPathOffset;
  672. }
  673. else
  674. {
  675. // Add in length of foreign OS options.
  676. //
  677. requiredLength += OldBootEntry->ForeignOsOptionsLength;
  678. osLoadOptionsLength = 0;
  679. osLoadPathOffset = 0;
  680. osLoadPathLength = 0;
  681. }
  682. osOptionsLength = requiredLength - osOptionsOffset;
  683. // Round up to a ULONG boundary for the friendly name in the BOOT_ENTRY.
  684. // Save offset to friendly name. Calculate length in bytes of friendly name
  685. // and add that in.
  686. //
  687. requiredLength = ALIGN_UP(requiredLength, ULONG);
  688. friendlyNameOffset = requiredLength;
  689. friendlyNameLength = OldBootEntry->FriendlyNameLength;
  690. requiredLength += friendlyNameLength;
  691. // Round up to a ULONG boundary for the boot FILE_PATH in the BOOT_ENTRY.
  692. // Save offset to boot FILE_PATH. Calculate length in bytes of FILE_PATH
  693. // and add that in.
  694. //
  695. requiredLength = ALIGN_UP(requiredLength, ULONG);
  696. bootPathOffset = requiredLength;
  697. requiredLength += OldBootEntry->BootFilePath->Length;
  698. bootPathLength = requiredLength - bootPathOffset;
  699. // Allocate memory for the boot entry.
  700. //
  701. newBootEntry = (PMY_BOOT_ENTRY)malloc(requiredLength);
  702. if(newBootEntry == NULL)
  703. return NULL;
  704. RtlZeroMemory(newBootEntry, requiredLength);
  705. // Calculate addresses of various substructures using the saved offsets.
  706. //
  707. ntBootEntry = &newBootEntry->NtBootEntry;
  708. osOptions = (PWINDOWS_OS_OPTIONS)ntBootEntry->OsOptions;
  709. osLoadPath = (PFILE_PATH)((PUCHAR)newBootEntry + osLoadPathOffset);
  710. friendlyName = (PWSTR)((PUCHAR)newBootEntry + friendlyNameOffset);
  711. bootPath = (PFILE_PATH)((PUCHAR)newBootEntry + bootPathOffset);
  712. // Fill in the internal-format structure.
  713. //
  714. // newBootEntry->AllocationEnd = (PUCHAR)newBootEntry + requiredLength;
  715. newBootEntry->Status = OldBootEntry->Status & MBE_STATUS_IS_NT;
  716. newBootEntry->Attributes = OldBootEntry->Attributes;
  717. newBootEntry->Id = OldBootEntry->Id;
  718. newBootEntry->FriendlyName = friendlyName;
  719. newBootEntry->FriendlyNameLength = friendlyNameLength;
  720. newBootEntry->BootFilePath = bootPath;
  721. if ( MBE_IS_NT( OldBootEntry ) )
  722. {
  723. newBootEntry->OsLoadOptions = osOptions->OsLoadOptions;
  724. newBootEntry->OsLoadOptionsLength = osLoadOptionsLength;
  725. newBootEntry->OsFilePath = osLoadPath;
  726. }
  727. // Fill in the base part of the NT boot entry.
  728. //
  729. ntBootEntry->Version = BOOT_ENTRY_VERSION;
  730. ntBootEntry->Length = requiredLength - FIELD_OFFSET(MY_BOOT_ENTRY, NtBootEntry);
  731. ntBootEntry->Attributes = OldBootEntry->Attributes;
  732. ntBootEntry->Id = OldBootEntry->Id;
  733. ntBootEntry->FriendlyNameOffset = (ULONG)((PUCHAR)friendlyName - (PUCHAR)ntBootEntry);
  734. ntBootEntry->BootFilePathOffset = (ULONG)((PUCHAR)bootPath - (PUCHAR)ntBootEntry);
  735. ntBootEntry->OsOptionsLength = osOptionsLength;
  736. if ( MBE_IS_NT( OldBootEntry ) )
  737. {
  738. // Fill in the base part of the WINDOWS_OS_OPTIONS, including the
  739. // OsLoadOptions.
  740. //
  741. strcpy((char *)osOptions->Signature, WINDOWS_OS_OPTIONS_SIGNATURE);
  742. osOptions->Version = WINDOWS_OS_OPTIONS_VERSION;
  743. osOptions->Length = osOptionsLength;
  744. osOptions->OsLoadPathOffset = (ULONG)((PUCHAR)osLoadPath - (PUCHAR)osOptions);
  745. wcscpy(osOptions->OsLoadOptions, OldBootEntry->OsLoadOptions);
  746. // Copy the OS FILE_PATH.
  747. //
  748. memcpy( osLoadPath, OldBootEntry->OsFilePath, osLoadPathLength );
  749. }
  750. else
  751. {
  752. // Copy the foreign OS options.
  753. memcpy( osOptions, OldBootEntry->ForeignOsOptions, osOptionsLength );
  754. }
  755. // Copy the friendly name.
  756. wcscpy(friendlyName, OldBootEntry->FriendlyName);
  757. // Copy the boot FILE_PATH.
  758. memcpy( bootPath, OldBootEntry->BootFilePath, bootPathLength );
  759. return newBootEntry;
  760. } // CreateBootEntryFromBootEntry
  761. // ***************************************************************************
  762. //
  763. // Name : DeleteBootIniSettings_IA64
  764. //
  765. // Synopsis : This routine deletes an existing boot entry from an EFI
  766. // based machine
  767. //
  768. // Parameters : DWORD argc (in) - Number of command line arguments
  769. // LPCTSTR argv (in) - Array containing command line arguments
  770. //
  771. // Return Type : DWORD
  772. //
  773. // Global Variables: Global Linked lists for storing the boot entries
  774. // LIST_ENTRY BootEntries;
  775. //
  776. // ***************************************************************************
  777. DWORD DeleteBootIniSettings_IA64( DWORD argc, LPCTSTR argv[] )
  778. {
  779. BOOL bDelete = FALSE ;
  780. BOOL bUsage = FALSE;
  781. DWORD dwBootID = 0;
  782. BOOL bBootIdFound = FALSE;
  783. DWORD dwExitCode = ERROR_SUCCESS;
  784. NTSTATUS status;
  785. PMY_BOOT_ENTRY mybootEntry;
  786. PLIST_ENTRY listEntry;
  787. PBOOT_ENTRY bootEntry;
  788. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  789. // Building the TCMDPARSER structure
  790. TCMDPARSER cmdOptions[] =
  791. {
  792. { CMDOPTION_DELETE, CP_MAIN_OPTION, 1, 0, &bDelete, NULL_STRING, NULL, NULL },
  793. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  794. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwBootID, NULL_STRING, NULL, NULL }
  795. };
  796. // Parsing the delete option switches
  797. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  798. {
  799. dwExitCode = EXIT_FAILURE;
  800. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  801. ShowMessage(stderr,GetReason());
  802. return dwExitCode;
  803. }
  804. // Displaying delete usage if user specified -? with -delete option
  805. if( bUsage )
  806. {
  807. displayDeleteUsage_IA64();
  808. return EXIT_SUCCESS;
  809. }
  810. //Query the boot entries till u get the BootID specified by the user
  811. for (listEntry = BootEntries.Flink;
  812. listEntry != &BootEntries;
  813. listEntry = listEntry->Flink)
  814. {
  815. //
  816. //display an error message if there is only 1 boot entry saying
  817. //that it cannot be deleted.
  818. //
  819. if (listEntry->Flink == NULL)
  820. {
  821. DISPLAY_MESSAGE(stderr,GetResString(IDS_ONLY_ONE_OS));
  822. dwExitCode = EXIT_FAILURE;
  823. break ;
  824. }
  825. //Get the boot entry
  826. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  827. if(mybootEntry->myId == dwBootID)
  828. {
  829. bBootIdFound = TRUE;
  830. //Delete the boot entry specified by the user.
  831. status = NtDeleteBootEntry(mybootEntry->Id);
  832. if(status == STATUS_SUCCESS)
  833. {
  834. _stprintf(szMsgBuffer, GetResString(IDS_DELETE_SUCCESS),dwBootID);
  835. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  836. }
  837. else
  838. {
  839. _stprintf(szMsgBuffer, GetResString(IDS_DELETE_FAILURE),dwBootID);
  840. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  841. }
  842. break;
  843. }
  844. }
  845. if(bBootIdFound == FALSE)
  846. {
  847. //Could not find the BootID specified by the user so output the message and return failure
  848. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  849. dwExitCode = EXIT_FAILURE;
  850. }
  851. //Remember to free the memory allocated to the linked lists
  852. return (dwExitCode);
  853. }
  854. // ***************************************************************************
  855. //
  856. // Name : IsBootEntryWindows
  857. //
  858. // Synopsis : Checks whether the boot entry is a Windows or a foreign one
  859. //
  860. // Parameters : PBOOT_ENTRY bootEntry: Boot entry structure describing the
  861. // boot entry.
  862. //
  863. // Return Type : BOOL
  864. //
  865. // Global Variables: None
  866. //
  867. // ***************************************************************************
  868. BOOL IsBootEntryWindows(PBOOT_ENTRY bootEntry)
  869. {
  870. PWINDOWS_OS_OPTIONS osOptions;
  871. osOptions = (PWINDOWS_OS_OPTIONS)bootEntry->OsOptions;
  872. if ((bootEntry->OsOptionsLength >= FIELD_OFFSET(WINDOWS_OS_OPTIONS, OsLoadOptions)) &&
  873. (strcmp((char *)osOptions->Signature, WINDOWS_OS_OPTIONS_SIGNATURE) == 0))
  874. {
  875. return TRUE;
  876. }
  877. return FALSE;
  878. }
  879. // ***************************************************************************
  880. //
  881. // Name : GetNtNameForFilePath
  882. //
  883. // Synopsis : Converts the FilePath into a NT file path.
  884. //
  885. // Parameters : PFILE_PATH FilePath: The File path.
  886. //
  887. // Return Type : PWSTR: The NT file path.
  888. //
  889. // Global Variables: None
  890. //
  891. // ***************************************************************************
  892. PWSTR GetNtNameForFilePath(IN PFILE_PATH FilePath)
  893. {
  894. NTSTATUS status;
  895. ULONG length;
  896. PFILE_PATH ntPath;
  897. PWSTR osDeviceNtName;
  898. PWSTR osDirectoryNtName;
  899. PWSTR fullNtName;
  900. DWORD dwDeviceLength = 0;
  901. length = 0;
  902. status = NtTranslateFilePath(
  903. FilePath,
  904. FILE_PATH_TYPE_NT,
  905. NULL,
  906. &length
  907. );
  908. if ( status != STATUS_BUFFER_TOO_SMALL )
  909. {
  910. return NULL;
  911. }
  912. ntPath = (PFILE_PATH)malloc( length );
  913. if(ntPath == NULL)
  914. return NULL;
  915. status = NtTranslateFilePath(
  916. FilePath,
  917. FILE_PATH_TYPE_NT,
  918. ntPath,
  919. &length
  920. );
  921. if ( !NT_SUCCESS(status) )
  922. {
  923. if(ntPath)
  924. free(ntPath);
  925. return NULL;
  926. }
  927. osDeviceNtName = (PWSTR)ntPath->FilePath;
  928. osDirectoryNtName = osDeviceNtName + wcslen(osDeviceNtName) + 1;
  929. length = (ULONG)(wcslen(osDeviceNtName) + wcslen(osDirectoryNtName) + 1) * sizeof(WCHAR);
  930. fullNtName = (PWSTR)malloc( length );
  931. if(fullNtName == NULL)
  932. {
  933. if(ntPath)
  934. free(ntPath);
  935. return NULL;
  936. }
  937. wcscpy( fullNtName, osDeviceNtName );
  938. wcscat( fullNtName, osDirectoryNtName );
  939. if(ntPath)
  940. free( ntPath );
  941. return fullNtName;
  942. } // GetNtNameForFilePath
  943. // ***************************************************************************
  944. //
  945. // Name : CopyBootIniSettings_IA64
  946. //
  947. // Synopsis : This routine copies and existing boot entry for an EFI
  948. // based machine. The user can then add the various OS load
  949. // options.
  950. //
  951. // Parameters : DWORD argc (in) - Number of command line arguments
  952. // LPCTSTR argv (in) - Array containing command line arguments
  953. //
  954. // Return Type : DWORD
  955. //
  956. // Global Variables: Global Linked lists for storing the boot entries
  957. // LIST_ENTRY BootEntries;
  958. //
  959. // ***************************************************************************
  960. DWORD CopyBootIniSettings_IA64( DWORD argc, LPCTSTR argv[] )
  961. {
  962. BOOL bCopy = FALSE ;
  963. BOOL bUsage = FALSE;
  964. DWORD dwExitCode = EXIT_SUCCESS;
  965. DWORD dwBootID = 0;
  966. BOOL bBootIdFound = FALSE;
  967. PMY_BOOT_ENTRY mybootEntry;
  968. PLIST_ENTRY listEntry;
  969. PBOOT_ENTRY bootEntry;
  970. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  971. STRING256 szDescription = NULL_STRING;
  972. // Builiding the TCMDPARSER structure
  973. TCMDPARSER cmdOptions[] = {
  974. { CMDOPTION_COPY, CP_MAIN_OPTION, 1, 0, &bCopy, NULL_STRING, NULL, NULL },
  975. { SWITCH_DESCRIPTION, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szDescription, NULL_STRING, NULL, NULL },
  976. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, 0, 0 },
  977. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY,1, 0, &dwBootID, NULL_STRING, NULL, NULL }
  978. };
  979. // Parsing the copy option switches
  980. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  981. {
  982. dwExitCode = EXIT_FAILURE;
  983. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  984. ShowMessage(stderr,GetReason());
  985. return dwExitCode;
  986. }
  987. // Displaying copy usage if user specified -? with -copy option
  988. if( bUsage )
  989. {
  990. displayCopyUsage_IA64();
  991. dwExitCode = EXIT_SUCCESS;
  992. return dwExitCode;
  993. }
  994. //Query the boot entries till u get the BootID specified by the user
  995. for (listEntry = BootEntries.Flink;
  996. listEntry != &BootEntries;
  997. listEntry = listEntry->Flink)
  998. {
  999. //Get the boot entry
  1000. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  1001. if(mybootEntry->myId == dwBootID)
  1002. {
  1003. bBootIdFound = TRUE;
  1004. bootEntry = &mybootEntry->NtBootEntry;
  1005. //Copy the boot entry specified by the user.
  1006. dwExitCode = CopyBootEntry(bootEntry, szDescription);
  1007. if(dwExitCode == EXIT_SUCCESS)
  1008. {
  1009. _stprintf(szMsgBuffer, GetResString(IDS_COPY_SUCCESS),dwBootID);
  1010. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  1011. }
  1012. else
  1013. {
  1014. _stprintf(szMsgBuffer, GetResString(IDS_COPY_ERROR),dwBootID);
  1015. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  1016. }
  1017. break;
  1018. }
  1019. }
  1020. if(bBootIdFound == FALSE)
  1021. {
  1022. //Could not find the BootID specified by the user so output the message and return failure
  1023. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  1024. dwExitCode = EXIT_FAILURE;
  1025. return EXIT_FAILURE ;
  1026. }
  1027. //Remember to free the memory allocated for the linked lists
  1028. return EXIT_SUCCESS;
  1029. }
  1030. // ***************************************************************************
  1031. //
  1032. // Name : CopyBootEntry
  1033. //
  1034. // Synopsis : This routine is used to add / copy a boot entry.
  1035. //
  1036. // Parameters : PBOOT_ENTRY bootEntry (in) - Pointer to a BootEntry structure
  1037. // for which the changes needs to be made
  1038. // LPTSTR lpNewFriendlyName (in) - String specifying the new friendly name.
  1039. //
  1040. // Return Type : DWORD -- ERROR_SUCCESS on success
  1041. // -- EXIT_FAILURE on failure
  1042. //
  1043. // Global Variables : None
  1044. //
  1045. // ***************************************************************************
  1046. DWORD CopyBootEntry(PBOOT_ENTRY bootEntry, LPTSTR lpNewFriendlyName)
  1047. {
  1048. PBOOT_ENTRY bootEntryCopy;
  1049. PMY_BOOT_ENTRY myBootEntry;
  1050. PWINDOWS_OS_OPTIONS osOptions;
  1051. ULONG length, Id;
  1052. PMY_BOOT_ENTRY myChBootEntry;
  1053. NTSTATUS status;
  1054. DWORD error, dwErrorCode = ERROR_SUCCESS;
  1055. PULONG BootEntryOrder, NewBootEntryOrder, NewTempBootEntryOrder;
  1056. // Calculate the length of our internal structure. This includes
  1057. // the base part of MY_BOOT_ENTRY plus the NT BOOT_ENTRY.
  1058. //
  1059. length = FIELD_OFFSET(MY_BOOT_ENTRY, NtBootEntry) + bootEntry->Length;
  1060. myBootEntry = (PMY_BOOT_ENTRY)malloc(length);
  1061. if(myBootEntry == NULL)
  1062. {
  1063. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1064. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1065. ShowLastError(stderr);
  1066. dwErrorCode = EXIT_FAILURE;
  1067. return dwErrorCode;
  1068. }
  1069. RtlZeroMemory(myBootEntry, length);
  1070. //
  1071. // Copy the NT BOOT_ENTRY into the allocated buffer.
  1072. //
  1073. bootEntryCopy = &myBootEntry->NtBootEntry;
  1074. memcpy(bootEntryCopy, bootEntry, bootEntry->Length);
  1075. myBootEntry->Id = bootEntry->Id;
  1076. myBootEntry->Attributes = bootEntry->Attributes;
  1077. //Change the friendly name if lpNewFriendlyName is not NULL
  1078. if(lpNewFriendlyName && (lstrlen(lpNewFriendlyName) != 0))
  1079. {
  1080. myBootEntry->FriendlyName = lpNewFriendlyName;
  1081. myBootEntry->FriendlyNameLength = ((ULONG)wcslen(lpNewFriendlyName) + 1) * sizeof(WCHAR);
  1082. }
  1083. else
  1084. {
  1085. myBootEntry->FriendlyName = NULL_STRING;
  1086. myBootEntry->FriendlyNameLength = 0;
  1087. }
  1088. myBootEntry->BootFilePath = (PFILE_PATH)ADD_OFFSET(bootEntryCopy, BootFilePathOffset);
  1089. // If this is an NT boot entry, capture the NT-specific information in
  1090. // the OsOptions.
  1091. osOptions = (PWINDOWS_OS_OPTIONS)bootEntryCopy->OsOptions;
  1092. if ((bootEntryCopy->OsOptionsLength >= FIELD_OFFSET(WINDOWS_OS_OPTIONS, OsLoadOptions)) &&
  1093. (strcmp((char *)osOptions->Signature, WINDOWS_OS_OPTIONS_SIGNATURE) == 0))
  1094. {
  1095. MBE_SET_IS_NT( myBootEntry );
  1096. //To change the OS Load options
  1097. myBootEntry->OsLoadOptions = osOptions->OsLoadOptions;
  1098. myBootEntry->OsLoadOptionsLength =
  1099. ((ULONG)wcslen(myBootEntry->OsLoadOptions) + 1) * sizeof(WCHAR);
  1100. myBootEntry->OsFilePath = (PFILE_PATH)ADD_OFFSET(osOptions, OsLoadPathOffset);
  1101. }
  1102. else
  1103. {
  1104. // Foreign boot entry. Just capture whatever OS options exist.
  1105. //
  1106. myBootEntry->ForeignOsOptions = bootEntryCopy->OsOptions;
  1107. myBootEntry->ForeignOsOptionsLength = bootEntryCopy->OsOptionsLength;
  1108. }
  1109. myChBootEntry = CreateBootEntryFromBootEntry(myBootEntry);
  1110. if(myChBootEntry == NULL)
  1111. {
  1112. dwErrorCode = EXIT_FAILURE;
  1113. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1114. DISPLAY_MESSAGE(stderr, ERROR_TAG);
  1115. if(myBootEntry)
  1116. free(myBootEntry);
  1117. ShowLastError(stderr);
  1118. return dwErrorCode;
  1119. }
  1120. //Call the NtAddBootEntry API
  1121. status = NtAddBootEntry(&myChBootEntry->NtBootEntry, &Id);
  1122. if ( status != STATUS_SUCCESS )
  1123. {
  1124. error = RtlNtStatusToDosError( status );
  1125. dwErrorCode = error;
  1126. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_UNEXPECTED) );
  1127. }
  1128. // Get the system boot order list.
  1129. length = 0;
  1130. status = NtQueryBootEntryOrder( NULL, &length );
  1131. if ( status != STATUS_BUFFER_TOO_SMALL )
  1132. {
  1133. if ( status == STATUS_SUCCESS )
  1134. {
  1135. length = 0;
  1136. }
  1137. else
  1138. {
  1139. error = RtlNtStatusToDosError( status );
  1140. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_QUERY_BOOTENTRY) );
  1141. if(myBootEntry)
  1142. free(myBootEntry);
  1143. if(myChBootEntry)
  1144. free(myChBootEntry);
  1145. return FALSE;
  1146. }
  1147. }
  1148. if ( length != 0 )
  1149. {
  1150. BootEntryOrder = (PULONG)malloc( length * sizeof(ULONG) );
  1151. if(BootEntryOrder == NULL)
  1152. {
  1153. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1154. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1155. ShowLastError(stderr);
  1156. dwErrorCode = EXIT_FAILURE;
  1157. if(myBootEntry)
  1158. free(myBootEntry);
  1159. if(myChBootEntry)
  1160. free(myChBootEntry);
  1161. return dwErrorCode;
  1162. }
  1163. status = NtQueryBootEntryOrder( BootEntryOrder, &length );
  1164. if ( status != STATUS_SUCCESS )
  1165. {
  1166. error = RtlNtStatusToDosError( status );
  1167. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_QUERY_BOOTENTRY));
  1168. dwErrorCode = error;
  1169. if(myBootEntry)
  1170. free(myBootEntry);
  1171. if(BootEntryOrder)
  1172. free(BootEntryOrder);
  1173. if(myChBootEntry)
  1174. free(myChBootEntry);
  1175. return dwErrorCode;
  1176. }
  1177. }
  1178. //Allocate memory for the new boot entry order.
  1179. NewBootEntryOrder = (PULONG)malloc((length+1) * sizeof(ULONG));
  1180. if(NewBootEntryOrder == NULL)
  1181. {
  1182. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1183. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1184. ShowLastError(stderr);
  1185. dwErrorCode = EXIT_FAILURE;
  1186. if(myBootEntry)
  1187. free(myBootEntry);
  1188. if(BootEntryOrder)
  1189. free(BootEntryOrder);
  1190. if(myChBootEntry)
  1191. free(myChBootEntry);
  1192. return dwErrorCode;
  1193. }
  1194. NewTempBootEntryOrder = NewBootEntryOrder;
  1195. memcpy(NewTempBootEntryOrder,BootEntryOrder,length*sizeof(ULONG));
  1196. NewTempBootEntryOrder = NewTempBootEntryOrder + length;
  1197. *NewTempBootEntryOrder = Id;
  1198. status = NtSetBootEntryOrder(NewBootEntryOrder, length+1);
  1199. if ( status != STATUS_SUCCESS )
  1200. {
  1201. error = RtlNtStatusToDosError( status );
  1202. dwErrorCode = error;
  1203. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_SET_BOOTENTRY));
  1204. }
  1205. //free the memory
  1206. if(NewBootEntryOrder)
  1207. free(NewBootEntryOrder);
  1208. if(BootEntryOrder)
  1209. free(BootEntryOrder);
  1210. if(myBootEntry)
  1211. free(myBootEntry);
  1212. if(myChBootEntry)
  1213. free(myChBootEntry);
  1214. return dwErrorCode;
  1215. }
  1216. // ***************************************************************************
  1217. //
  1218. // Name : ChangeTimeOut_IA64
  1219. //
  1220. // Synopsis : This routine chnages the Timeout value in the system
  1221. // global boot options.
  1222. //
  1223. // Parameters : DWORD argc (in) - Number of command line arguments
  1224. // LPCTSTR argv (in) - Array containing command line arguments
  1225. //
  1226. // Return Type : DOWRD
  1227. //
  1228. // Global Variables: None
  1229. //
  1230. // ***************************************************************************
  1231. DWORD ChangeTimeOut_IA64( DWORD argc, LPCTSTR argv[])
  1232. {
  1233. BOOL bTimeOut = FALSE ;
  1234. DWORD dwTimeOut = 0;
  1235. DWORD dwExitCode = EXIT_SUCCESS;
  1236. ULONG Flag = 0;
  1237. TCMDPARSER cmdOptions[] =
  1238. {
  1239. { CMDOPTION_TIMEOUT, CP_MAIN_OPTION | CP_TYPE_UNUMERIC | CP_VALUE_MANDATORY, 1, 0,&dwTimeOut,NULL_STRING, NULL, NULL}
  1240. };
  1241. if( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  1242. {
  1243. dwExitCode = EXIT_FAILURE;
  1244. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  1245. ShowMessage(stderr,GetReason());
  1246. return dwExitCode ;
  1247. }
  1248. //Check for the limit of Timeout value entered by the user.
  1249. if(dwTimeOut > TIMEOUT_MAX)
  1250. {
  1251. dwExitCode = EXIT_FAILURE;
  1252. DISPLAY_MESSAGE(stderr,GetResString(IDS_TIMEOUT_RANGE));
  1253. return dwExitCode;
  1254. }
  1255. //Call the ModifyBootOptions function with the BOOT_OPTIONS_FIELD_COUNTDOWN
  1256. Flag |= BOOT_OPTIONS_FIELD_COUNTDOWN;
  1257. dwExitCode = ModifyBootOptions(dwTimeOut, NULL, 0, Flag);
  1258. return dwExitCode;
  1259. }
  1260. // ***************************************************************************
  1261. //
  1262. // Name : ModifyBootOptions
  1263. //
  1264. // Synopsis : This routine Modifies the Boot options
  1265. // - Timeout
  1266. // - NextBootEntryID
  1267. // - HeadlessRedirection
  1268. //
  1269. // Parameters : ULONG Timeout (in) - The new Timeout value
  1270. // LPTSTR pHeadlessRedirection (in) - The Headless redirection string
  1271. // ULONG NextBootEntryID (in) - The NextBootEntryID
  1272. // ULONG Flag - The Flags indicating what fields that needs to be changed
  1273. // BOOT_OPTIONS_FIELD_COUNTDOWN
  1274. // BOOT_OPTIONS_FIELD_NEXT_BOOT_ENTRY_ID
  1275. // BOOT_OPTIONS_FIELD_HEADLESS_REDIRECTION
  1276. // Return Type : DOWRD
  1277. //
  1278. // Global Variables: None
  1279. //
  1280. // ***************************************************************************
  1281. DWORD ModifyBootOptions(ULONG Timeout, LPTSTR pHeadlessRedirection, ULONG NextBootEntryID, ULONG Flag)
  1282. {
  1283. DWORD dwExitCode = EXIT_SUCCESS;
  1284. DWORD error;
  1285. NTSTATUS status;
  1286. ULONG length, i;
  1287. ULONG newlength=0;
  1288. PBOOT_OPTIONS pBootOptions, pModifiedBootOptions;
  1289. //Query the existing Boot options and modify based on the Flag value
  1290. status = BootCfg_QueryBootOptions(&pBootOptions);
  1291. if(status != STATUS_SUCCESS)
  1292. {
  1293. error = RtlNtStatusToDosError( status );
  1294. //free the ntBootEntries list
  1295. if(pBootOptions)
  1296. free(pBootOptions);
  1297. dwExitCode = EXIT_FAILURE;
  1298. return dwExitCode;
  1299. }
  1300. //Calculate the new length of the BOOT_OPTIONS struct based on the fields that needs to be changed.
  1301. newlength = FIELD_OFFSET(BOOT_OPTIONS, HeadlessRedirection);
  1302. if((Flag & BOOT_OPTIONS_FIELD_HEADLESS_REDIRECTION))
  1303. {
  1304. newlength = FIELD_OFFSET(BOOT_OPTIONS, HeadlessRedirection);
  1305. newlength += lstrlen(pHeadlessRedirection);
  1306. newlength = ALIGN_UP(newlength, ULONG);
  1307. }
  1308. else
  1309. newlength = pBootOptions->Length;
  1310. //Also allocate the memory for a new Boot option struct
  1311. pModifiedBootOptions = (PBOOT_OPTIONS)malloc(newlength);
  1312. if(pModifiedBootOptions == NULL)
  1313. {
  1314. dwExitCode = EXIT_FAILURE;
  1315. //free the memory for the pBootOptions allocated by the
  1316. //BootCfg_QueryBootOptions function
  1317. if(pBootOptions)
  1318. free(pBootOptions);
  1319. return dwExitCode;
  1320. }
  1321. //Fill in the new boot options struct
  1322. pModifiedBootOptions->Version = BOOT_OPTIONS_VERSION;
  1323. pModifiedBootOptions->Length = newlength;
  1324. if((Flag & BOOT_OPTIONS_FIELD_COUNTDOWN))
  1325. pModifiedBootOptions->Timeout = Timeout;
  1326. else
  1327. pModifiedBootOptions->Timeout = pBootOptions->Timeout;
  1328. //Cannot change the CurrentBootEntryId.So just pass what u got.
  1329. pModifiedBootOptions->CurrentBootEntryId = pBootOptions->CurrentBootEntryId;
  1330. if((Flag & BOOT_OPTIONS_FIELD_NEXT_BOOT_ENTRY_ID))
  1331. pModifiedBootOptions->NextBootEntryId = pBootOptions->NextBootEntryId;
  1332. else
  1333. pModifiedBootOptions->NextBootEntryId = pBootOptions->NextBootEntryId;
  1334. if((Flag & BOOT_OPTIONS_FIELD_HEADLESS_REDIRECTION))
  1335. {
  1336. wcscpy(pModifiedBootOptions->HeadlessRedirection, pBootOptions->HeadlessRedirection);
  1337. }
  1338. else
  1339. wcscpy(pModifiedBootOptions->HeadlessRedirection, pBootOptions->HeadlessRedirection);
  1340. //Set the boot options in the NVRAM
  1341. status = NtSetBootOptions(pModifiedBootOptions, Flag);
  1342. if(status != STATUS_SUCCESS)
  1343. {
  1344. dwExitCode = EXIT_SUCCESS;
  1345. if((Flag & BOOT_OPTIONS_FIELD_COUNTDOWN))
  1346. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_MODIFY_TIMEOUT));
  1347. if((Flag & BOOT_OPTIONS_FIELD_NEXT_BOOT_ENTRY_ID))
  1348. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_MODIFY_NEXTBOOTID));
  1349. if((Flag & BOOT_OPTIONS_FIELD_HEADLESS_REDIRECTION))
  1350. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_MODIFY_HEADLESS));
  1351. }
  1352. else
  1353. {
  1354. dwExitCode = EXIT_SUCCESS;
  1355. if((Flag & BOOT_OPTIONS_FIELD_COUNTDOWN))
  1356. DISPLAY_MESSAGE(stdout,GetResString(IDS_SUCCESS_MODIFY_TIMEOUT));
  1357. if((Flag & BOOT_OPTIONS_FIELD_NEXT_BOOT_ENTRY_ID))
  1358. DISPLAY_MESSAGE(stdout,GetResString(IDS_SUCCESS_MODIFY_NEXTBOOTID));
  1359. if((Flag & BOOT_OPTIONS_FIELD_HEADLESS_REDIRECTION))
  1360. DISPLAY_MESSAGE(stdout,GetResString(IDS_SUCCESS_MODIFY_HEADLESS));
  1361. }
  1362. //free the memory
  1363. if(pModifiedBootOptions)
  1364. free(pModifiedBootOptions);
  1365. if(pBootOptions)
  1366. free(pBootOptions);
  1367. return dwExitCode;
  1368. }
  1369. // ***************************************************************************
  1370. //
  1371. // Name : ConvertBootEntries
  1372. //
  1373. // Synopsis : Convert boot entries read from EFI NVRAM into our internal format.
  1374. //
  1375. // Parameters : PBOOT_ENTRY_LIST NtBootEntries - The boot entry list given by the enumeration
  1376. //
  1377. // Return Type : DWORD
  1378. //
  1379. // Global Variables: Global Linked lists for storing the boot entries
  1380. // LIST_ENTRY BootEntries;
  1381. // LIST_ENTRY ActiveUnorderedBootEntries;
  1382. // LIST_ENTRY InactiveUnorderedBootEntries;
  1383. //
  1384. // ***************************************************************************
  1385. DWORD ConvertBootEntries (PBOOT_ENTRY_LIST NtBootEntries)
  1386. {
  1387. PBOOT_ENTRY_LIST bootEntryList;
  1388. PBOOT_ENTRY bootEntry;
  1389. PBOOT_ENTRY bootEntryCopy;
  1390. PMY_BOOT_ENTRY myBootEntry;
  1391. PWINDOWS_OS_OPTIONS osOptions;
  1392. ULONG length;
  1393. DWORD dwErrorCode = EXIT_SUCCESS;
  1394. bootEntryList = NtBootEntries;
  1395. while (TRUE) {
  1396. bootEntry = &bootEntryList->BootEntry;
  1397. //
  1398. // Calculate the length of our internal structure. This includes
  1399. // the base part of MY_BOOT_ENTRY plus the NT BOOT_ENTRY.
  1400. //
  1401. length = FIELD_OFFSET(MY_BOOT_ENTRY, NtBootEntry) + bootEntry->Length;
  1402. //Remember to check for the NULL pointer
  1403. myBootEntry = (PMY_BOOT_ENTRY)malloc(length);
  1404. if(myBootEntry == NULL)
  1405. {
  1406. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1407. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1408. ShowLastError(stderr);
  1409. dwErrorCode = EXIT_FAILURE;
  1410. return dwErrorCode;
  1411. }
  1412. RtlZeroMemory(myBootEntry, length);
  1413. //
  1414. // Link the new entry into the list.
  1415. //
  1416. if ( (bootEntry->Attributes & BOOT_ENTRY_ATTRIBUTE_ACTIVE) != 0 ) {
  1417. InsertTailList( &ActiveUnorderedBootEntries, &myBootEntry->ListEntry );
  1418. myBootEntry->ListHead = &ActiveUnorderedBootEntries;
  1419. } else {
  1420. InsertTailList( &InactiveUnorderedBootEntries, &myBootEntry->ListEntry );
  1421. myBootEntry->ListHead = &InactiveUnorderedBootEntries;
  1422. }
  1423. //
  1424. // Copy the NT BOOT_ENTRY into the allocated buffer.
  1425. //
  1426. bootEntryCopy = &myBootEntry->NtBootEntry;
  1427. memcpy(bootEntryCopy, bootEntry, bootEntry->Length);
  1428. //
  1429. // Fill in the base part of the structure.
  1430. //
  1431. myBootEntry->AllocationEnd = (PUCHAR)myBootEntry + length - 1;
  1432. myBootEntry->Id = bootEntry->Id;
  1433. //Assign 0 to the Ordered field currently so that
  1434. //once the boot order is known, we can assign 1 if this entry is a part of the ordered list.
  1435. myBootEntry->Ordered = 0;
  1436. myBootEntry->Attributes = bootEntry->Attributes;
  1437. myBootEntry->FriendlyName = (PWSTR)ADD_OFFSET(bootEntryCopy, FriendlyNameOffset);
  1438. myBootEntry->FriendlyNameLength =
  1439. ((ULONG)wcslen(myBootEntry->FriendlyName) + 1) * sizeof(WCHAR);
  1440. myBootEntry->BootFilePath = (PFILE_PATH)ADD_OFFSET(bootEntryCopy, BootFilePathOffset);
  1441. //
  1442. // If this is an NT boot entry, capture the NT-specific information in
  1443. // the OsOptions.
  1444. //
  1445. osOptions = (PWINDOWS_OS_OPTIONS)bootEntryCopy->OsOptions;
  1446. if ((bootEntryCopy->OsOptionsLength >= FIELD_OFFSET(WINDOWS_OS_OPTIONS, OsLoadOptions)) &&
  1447. (strcmp((char *)osOptions->Signature, WINDOWS_OS_OPTIONS_SIGNATURE) == 0)) {
  1448. MBE_SET_IS_NT( myBootEntry );
  1449. myBootEntry->OsLoadOptions = osOptions->OsLoadOptions;
  1450. myBootEntry->OsLoadOptionsLength =
  1451. ((ULONG)wcslen(myBootEntry->OsLoadOptions) + 1) * sizeof(WCHAR);
  1452. myBootEntry->OsFilePath = (PFILE_PATH)ADD_OFFSET(osOptions, OsLoadPathOffset);
  1453. } else {
  1454. //
  1455. // Foreign boot entry. Just capture whatever OS options exist.
  1456. //
  1457. myBootEntry->ForeignOsOptions = bootEntryCopy->OsOptions;
  1458. myBootEntry->ForeignOsOptionsLength = bootEntryCopy->OsOptionsLength;
  1459. }
  1460. //
  1461. // Move to the next entry in the enumeration list, if any.
  1462. //
  1463. if (bootEntryList->NextEntryOffset == 0) {
  1464. break;
  1465. }
  1466. bootEntryList = (PBOOT_ENTRY_LIST)ADD_OFFSET(bootEntryList, NextEntryOffset);
  1467. }
  1468. return dwErrorCode;
  1469. } // ConvertBootEntries
  1470. // ***************************************************************************
  1471. //
  1472. // Name : DisplayBootOptions
  1473. //
  1474. // Synopsis : Display the boot options
  1475. //
  1476. // Parameters : NONE
  1477. //
  1478. // Return Type : DWORD
  1479. //
  1480. // Global Variables: Global Linked lists for storing the boot entries
  1481. // LIST_ENTRY BootEntries;
  1482. //
  1483. // ***************************************************************************
  1484. DWORD DisplayBootOptions()
  1485. {
  1486. DWORD error;
  1487. NTSTATUS status;
  1488. PBOOT_OPTIONS pBootOptions;
  1489. TCHAR szDisplay[MAX_RES_STRING] = NULL_STRING;
  1490. //Query the boot options
  1491. status = BootCfg_QueryBootOptions(&pBootOptions);
  1492. if(status != STATUS_SUCCESS)
  1493. {
  1494. error = RtlNtStatusToDosError( status );
  1495. //free the ntBootEntries list
  1496. if(pBootOptions)
  1497. free(pBootOptions);
  1498. return FALSE;
  1499. }
  1500. //Printout the boot options
  1501. _tprintf(_T("\n"));
  1502. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64A));
  1503. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64B));
  1504. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64C), pBootOptions->Timeout);
  1505. DISPLAY_MESSAGE(stdout,szDisplay);
  1506. //Get the CurrentBootEntryId from the actual Id present in the boot options
  1507. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64D), GetCurrentBootEntryID(pBootOptions->CurrentBootEntryId));
  1508. DISPLAY_MESSAGE(stdout,szDisplay);
  1509. #if 0
  1510. if(lstrlen(pBootOptions->HeadlessRedirection) == 0)
  1511. {
  1512. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64E));
  1513. }
  1514. else
  1515. {
  1516. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64F), pBootOptions->HeadlessRedirection);
  1517. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64F));
  1518. }
  1519. #endif //Commenting out the display of the Headless redirection
  1520. //as we cannot query the same through API (its Firmware controlled)
  1521. if(pBootOptions)
  1522. free(pBootOptions);
  1523. return EXIT_SUCCESS;
  1524. }
  1525. // ***************************************************************************
  1526. //
  1527. // Name : DisplayBootEntry
  1528. //
  1529. // Synopsis : Display the boot entries (in an order)
  1530. //
  1531. // Parameters : NONE
  1532. //
  1533. // Return Type : DWORD
  1534. //
  1535. // Global Variables: Global Linked lists for storing the boot entries
  1536. // LIST_ENTRY BootEntries;
  1537. //
  1538. // ***************************************************************************
  1539. VOID DisplayBootEntry()
  1540. {
  1541. PLIST_ENTRY listEntry;
  1542. PMY_BOOT_ENTRY bootEntry;
  1543. PFILE_PATH OsLoadPath, BootFilePath;
  1544. PWSTR NtFilePath;
  1545. TCHAR szDisplay[MAX_RES_STRING] = NULL_STRING ;
  1546. //Printout the boot entires
  1547. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64G));
  1548. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64H));
  1549. for (listEntry = BootEntries.Flink;
  1550. listEntry != &BootEntries;
  1551. listEntry = listEntry->Flink)
  1552. {
  1553. //Get the boot entry
  1554. bootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  1555. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64I), bootEntry->myId);
  1556. DISPLAY_MESSAGE(stdout,szDisplay);
  1557. //friendly name
  1558. if(lstrlen(bootEntry->FriendlyName)!=0)
  1559. {
  1560. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64J), bootEntry->FriendlyName);
  1561. DISPLAY_MESSAGE(stdout,szDisplay);
  1562. }
  1563. else
  1564. {
  1565. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64K));
  1566. }
  1567. if(MBE_IS_NT(bootEntry))
  1568. {
  1569. //the OS load options
  1570. if(lstrlen(bootEntry->OsLoadOptions)!=0)
  1571. {
  1572. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64L), bootEntry->OsLoadOptions);
  1573. DISPLAY_MESSAGE(stdout,szDisplay);
  1574. }
  1575. else
  1576. {
  1577. DISPLAY_MESSAGE(stdout,GetResString(IDS_OUTPUT_IA64M));
  1578. }
  1579. //Get the BootFilePath
  1580. NtFilePath = GetNtNameForFilePath(bootEntry->BootFilePath);
  1581. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64N), NtFilePath);
  1582. DISPLAY_MESSAGE(stdout,szDisplay);
  1583. //free the memory
  1584. if(NtFilePath)
  1585. free(NtFilePath);
  1586. //Get the OS load path
  1587. NtFilePath = GetNtNameForFilePath(bootEntry->OsFilePath);
  1588. _stprintf(szDisplay,GetResString(IDS_OUTPUT_IA64O), NtFilePath);
  1589. DISPLAY_MESSAGE(stdout,szDisplay);
  1590. //free the memory
  1591. if(NtFilePath)
  1592. free(NtFilePath);
  1593. }
  1594. else
  1595. {
  1596. _tprintf(_T("\n"));
  1597. }
  1598. }
  1599. }
  1600. // ***************************************************************************
  1601. //
  1602. // Name : GetCurrentBootEntryID
  1603. //
  1604. // Synopsis : Gets the Boot entry ID generated by us from the BootId given by the NVRAM
  1605. //
  1606. // Parameters : DWORD Id -- The current boot id (BootId given by the NVRAM)
  1607. //
  1608. // Return Type : DWORD
  1609. //
  1610. // Global Variables: Global Linked lists for storing the boot entries
  1611. // LIST_ENTRY BootEntries;
  1612. //
  1613. // ***************************************************************************
  1614. DWORD GetCurrentBootEntryID(DWORD Id)
  1615. {
  1616. PLIST_ENTRY listEntry;
  1617. PMY_BOOT_ENTRY bootEntry;
  1618. for (listEntry = BootEntries.Flink;
  1619. listEntry != &BootEntries;
  1620. listEntry = listEntry->Flink)
  1621. {
  1622. //Get the boot entry
  1623. bootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  1624. if(bootEntry->Id == Id)
  1625. {
  1626. return bootEntry->myId;
  1627. }
  1628. }
  1629. return 0;
  1630. }
  1631. // ***************************************************************************
  1632. //
  1633. // Name : ChangeDefaultBootEntry_IA64
  1634. //
  1635. // Synopsis : This routine is to change the Default boot entry in the NVRAM
  1636. //
  1637. // Parameters : DWORD argc (in) - Number of command line arguments
  1638. // LPCTSTR argv (in) - Array containing command line arguments
  1639. //
  1640. // Return Type : DWORD
  1641. //
  1642. // Global Variables : None
  1643. //
  1644. // ***************************************************************************
  1645. DWORD ChangeDefaultBootEntry_IA64(DWORD argc,LPCTSTR argv[])
  1646. {
  1647. DWORD dwBootID = 0;
  1648. BOOL bDefaultOs = FALSE ;
  1649. DWORD dwExitCode = ERROR_SUCCESS;
  1650. BOOL bBootIdFound = FALSE, bIdFoundInBootOrderList = FALSE;
  1651. PMY_BOOT_ENTRY mybootEntry;
  1652. PLIST_ENTRY listEntry;
  1653. ULONG length, i, j, defaultId=0;
  1654. NTSTATUS status;
  1655. DWORD error;
  1656. PULONG BootEntryOrder, NewBootEntryOrder, NewTempBootEntryOrder;
  1657. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  1658. TCMDPARSER cmdOptions[] =
  1659. {
  1660. { CMDOPTION_DEFAULTOS, CP_MAIN_OPTION, 1, 0,&bDefaultOs, NULL_STRING, NULL, NULL },
  1661. { SWITCH_ID,CP_TYPE_NUMERIC | CP_VALUE_MANDATORY| CP_MANDATORY, 1, 0, &dwBootID, NULL_STRING, NULL, NULL }
  1662. };
  1663. if( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  1664. {
  1665. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  1666. ShowMessage(stderr,GetReason());
  1667. dwExitCode = EXIT_FAILURE;
  1668. return dwExitCode ;
  1669. }
  1670. //Check whether the boot entry entered bu the user is a valid boot entry id or not.
  1671. for (listEntry = BootEntries.Flink;
  1672. listEntry != &BootEntries;
  1673. listEntry = listEntry->Flink)
  1674. {
  1675. //Get the boot entry
  1676. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  1677. if(mybootEntry->myId == dwBootID)
  1678. {
  1679. bBootIdFound = TRUE;
  1680. //store the default ID
  1681. defaultId = mybootEntry->Id;
  1682. break;
  1683. }
  1684. }
  1685. if(bBootIdFound == FALSE)
  1686. {
  1687. //Could not find the BootID specified by the user so output the message and return failure
  1688. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  1689. dwExitCode = EXIT_FAILURE;
  1690. return dwExitCode;
  1691. }
  1692. // Get the system boot order list.
  1693. length = 0;
  1694. status = NtQueryBootEntryOrder( NULL, &length );
  1695. if ( status != STATUS_BUFFER_TOO_SMALL )
  1696. {
  1697. if ( status == STATUS_SUCCESS )
  1698. {
  1699. length = 0;
  1700. }
  1701. else
  1702. {
  1703. error = RtlNtStatusToDosError( status );
  1704. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_DEFAULT_ENTRY),dwBootID);
  1705. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  1706. dwExitCode = EXIT_FAILURE;
  1707. return dwExitCode;
  1708. }
  1709. }
  1710. if ( length != 0 )
  1711. {
  1712. BootEntryOrder = (PULONG)malloc( length * sizeof(ULONG) );
  1713. if(BootEntryOrder == NULL)
  1714. {
  1715. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1716. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1717. ShowLastError(stderr);
  1718. dwExitCode = EXIT_FAILURE;
  1719. return dwExitCode;
  1720. }
  1721. status = NtQueryBootEntryOrder( BootEntryOrder, &length );
  1722. if ( status != STATUS_SUCCESS )
  1723. {
  1724. error = RtlNtStatusToDosError( status );
  1725. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_DEFAULT_ENTRY),dwBootID);
  1726. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  1727. dwExitCode = error;
  1728. if(BootEntryOrder)
  1729. free(BootEntryOrder);
  1730. return dwExitCode;
  1731. }
  1732. }
  1733. //Check if the boot id entered by the user is a part of the Boot entry order.
  1734. //If not for the time being do not make it the default.
  1735. for(i=0;i<length;i++)
  1736. {
  1737. if(*(BootEntryOrder+i) == defaultId)
  1738. {
  1739. bIdFoundInBootOrderList = TRUE;
  1740. break;
  1741. }
  1742. }
  1743. if(bIdFoundInBootOrderList == FALSE)
  1744. {
  1745. dwExitCode = EXIT_FAILURE;
  1746. if(BootEntryOrder)
  1747. free(BootEntryOrder);
  1748. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_DEFAULT_ENTRY),dwBootID);
  1749. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  1750. return dwExitCode;
  1751. }
  1752. //Allocate memory for storing the new boot entry order.
  1753. NewBootEntryOrder = (PULONG)malloc((length) * sizeof(ULONG));
  1754. if(NewBootEntryOrder == NULL)
  1755. {
  1756. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1757. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1758. ShowLastError(stderr);
  1759. dwExitCode = EXIT_FAILURE;
  1760. if(BootEntryOrder)
  1761. free(BootEntryOrder);
  1762. return dwExitCode;
  1763. }
  1764. *NewBootEntryOrder = defaultId;
  1765. j=0;
  1766. for(i=0;i<length;i++)
  1767. {
  1768. if(*(BootEntryOrder+i) == defaultId)
  1769. continue;
  1770. *(NewBootEntryOrder+(j+1)) = *(BootEntryOrder+i);
  1771. j++;
  1772. }
  1773. status = NtSetBootEntryOrder(NewBootEntryOrder, length);
  1774. if ( status != STATUS_SUCCESS )
  1775. {
  1776. error = RtlNtStatusToDosError( status );
  1777. dwExitCode = error;
  1778. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_DEFAULT_ENTRY),dwBootID);
  1779. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  1780. }
  1781. else
  1782. {
  1783. _stprintf(szMsgBuffer, GetResString(IDS_SUCCESS_DEFAULT_ENTRY),dwBootID);
  1784. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  1785. }
  1786. //free the memory
  1787. if(NewBootEntryOrder)
  1788. free(NewBootEntryOrder);
  1789. if(BootEntryOrder)
  1790. free(BootEntryOrder);
  1791. return dwExitCode;
  1792. }
  1793. // ***************************************************************************
  1794. //
  1795. // Name : ProcessDebugSwitch_IA64
  1796. //
  1797. // Synopsis : Allows the user to add the OS load options specifed
  1798. // as a debug string at the cmdline to the boot
  1799. //
  1800. // Parameters : DWORD argc (in) - Number of command line arguments
  1801. // LPCTSTR argv (in) - Array containing command line arguments
  1802. //
  1803. // Return Type : DWORD
  1804. //
  1805. // Global Variables: Global Linked lists for storing the boot entries
  1806. // LIST_ENTRY BootEntries;
  1807. //
  1808. // ***************************************************************************
  1809. DWORD ProcessDebugSwitch_IA64( DWORD argc, LPCTSTR argv[] )
  1810. {
  1811. BOOL bUsage = FALSE ;
  1812. DWORD dwBootID = 0;
  1813. BOOL bBootIdFound = FALSE;
  1814. DWORD dwExitCode = ERROR_SUCCESS;
  1815. PMY_BOOT_ENTRY mybootEntry;
  1816. PLIST_ENTRY listEntry;
  1817. PBOOT_ENTRY bootEntry;
  1818. STRING100 szRawString = NULL_STRING ;
  1819. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING ;
  1820. TCHAR szPort[MAX_RES_STRING] = NULL_STRING ;
  1821. TCHAR szBaudRate[MAX_RES_STRING] = NULL_STRING ;
  1822. TCHAR szDebug[MAX_RES_STRING] = NULL_STRING ;
  1823. BOOL bDebug = FALSE ;
  1824. DWORD dwId = 0;
  1825. PWINDOWS_OS_OPTIONS pWindowsOptions = NULL ;
  1826. TCHAR szOsLoadOptions[MAX_RES_STRING] = NULL_STRING ;
  1827. TCHAR szTemp[MAX_RES_STRING] = NULL_STRING ;
  1828. TCHAR szTmpBuffer[MAX_RES_STRING] = NULL_STRING ;
  1829. // Building the TCMDPARSER structure
  1830. TCMDPARSER cmdOptions[] =
  1831. {
  1832. { CMDOPTION_DEBUG, CP_MAIN_OPTION | CP_TYPE_TEXT | CP_MODE_VALUES | CP_VALUE_OPTIONAL, 1, 0,&szDebug, CMDOPTION_DEBUG_VALUES, NULL, NULL },
  1833. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  1834. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwBootID, NULL_STRING, NULL, NULL },
  1835. { SWITCH_PORT, CP_TYPE_TEXT | CP_VALUE_MANDATORY|CP_MODE_VALUES,1,0,&szPort,COM_PORT_RANGE,NULL,NULL},
  1836. { SWITCH_BAUD, CP_TYPE_TEXT | CP_VALUE_MANDATORY |CP_MODE_VALUES,1,0,&szBaudRate,BAUD_RATE_VALUES_DEBUG,NULL,NULL},
  1837. };
  1838. // Parsing the copy option switches
  1839. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  1840. {
  1841. dwExitCode = EXIT_FAILURE;
  1842. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  1843. ShowMessage(stderr,GetReason());
  1844. return (dwExitCode);
  1845. }
  1846. // Displaying query usage if user specified -? with -query option
  1847. if( bUsage )
  1848. {
  1849. displayDebugUsage_IA64();
  1850. return (ERROR_SUCCESS);
  1851. }
  1852. //Trim any leading or trailing spaces
  1853. if(szDebug)
  1854. StrTrim(szDebug, _T(" "));
  1855. if( !( ( lstrcmpi(szDebug,VALUE_ON)== 0) || (lstrcmpi(szDebug,VALUE_OFF)== 0 ) ||(lstrcmpi(szDebug,EDIT_STRING)== 0) ) )
  1856. {
  1857. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  1858. return EXIT_FAILURE;
  1859. }
  1860. //Query the boot entries till u get the BootID specified by the user
  1861. for (listEntry = BootEntries.Flink;
  1862. listEntry != &BootEntries;
  1863. listEntry = listEntry->Flink)
  1864. {
  1865. //Get the boot entry
  1866. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  1867. if(mybootEntry->myId == dwBootID)
  1868. {
  1869. bBootIdFound = TRUE;
  1870. bootEntry = &mybootEntry->NtBootEntry;
  1871. //Check whether the bootEntry is a Windows one or not.
  1872. //The OS load options can be added only to a Windows boot entry.
  1873. if(!IsBootEntryWindows(bootEntry))
  1874. {
  1875. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  1876. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  1877. DISPLAY_MESSAGE(stderr, GetResString(IDS_INFO_NOTWINDOWS));
  1878. dwExitCode = EXIT_FAILURE;
  1879. break;
  1880. }
  1881. //Change the OS load options. Pass NULL to friendly name as we are not changing the same
  1882. //szRawString is the Os load options specified by the user
  1883. pWindowsOptions = (PWINDOWS_OS_OPTIONS)bootEntry->OsOptions;
  1884. // copy the existing OS Loadoptions into a string.
  1885. lstrcpy(szOsLoadOptions,pWindowsOptions->OsLoadOptions);
  1886. //check if the user has entered On option
  1887. if( lstrcmpi(szDebug,VALUE_ON)== 0)
  1888. {
  1889. //display an error message
  1890. if ( (_tcsstr(szOsLoadOptions,DEBUG_SWITCH) != 0 )&& (lstrlen(szPort)==0) &&(lstrlen(szBaudRate)==0) )
  1891. {
  1892. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_DEBUG));
  1893. dwExitCode = EXIT_FAILURE;
  1894. break;
  1895. }
  1896. //display a error message and exit if the 1394 port is already present.
  1897. if(_tcsstr(szOsLoadOptions,DEBUGPORT_1394) != 0 )
  1898. {
  1899. DISPLAY_MESSAGE(stderr,GetResString(IDS_1394_ALREADY_PRESENT));
  1900. dwExitCode = EXIT_FAILURE;
  1901. break;
  1902. }
  1903. if( (lstrlen(szPort)==0) &&(lstrlen(szBaudRate)!=0) )
  1904. {
  1905. if( (_tcsstr(szOsLoadOptions,TOKEN_DEBUGPORT) == 0 ) )
  1906. {
  1907. DISPLAY_MESSAGE(stderr,GetResString(IDS_CANNOT_ADD_BAUDRATE));
  1908. dwExitCode = EXIT_FAILURE;
  1909. break;
  1910. }
  1911. }
  1912. //
  1913. //display an duplicate entry error message if substring is already present.
  1914. //
  1915. if ( GetSubString(szOsLoadOptions,TOKEN_DEBUGPORT,szTemp) == EXIT_SUCCESS )
  1916. {
  1917. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPLICATE_ENTRY));
  1918. return EXIT_FAILURE ;
  1919. }
  1920. if(lstrlen(szTemp)!=0)
  1921. {
  1922. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPLICATE_ENTRY));
  1923. dwExitCode = EXIT_FAILURE;
  1924. break;
  1925. }
  1926. //check if the Os load options already contains
  1927. // debug switch
  1928. if(_tcsstr(szOsLoadOptions,DEBUG_SWITCH) == 0 )
  1929. {
  1930. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  1931. lstrcat(szOsLoadOptions,DEBUG_SWITCH);
  1932. }
  1933. if(lstrlen(szPort)!= 0)
  1934. {
  1935. lstrcat(szTmpBuffer,TOKEN_EMPTYSPACE);
  1936. lstrcat(szTmpBuffer,TOKEN_DEBUGPORT) ;
  1937. lstrcat(szTmpBuffer,TOKEN_EQUAL) ;
  1938. CharUpper(szPort);
  1939. lstrcat(szTmpBuffer,szPort);
  1940. lstrcat(szOsLoadOptions,szTmpBuffer);
  1941. }
  1942. //Check if the OS Load Options contains the baud rate already specified.
  1943. if(lstrlen(szBaudRate)!=0)
  1944. {
  1945. GetBaudRateVal(szOsLoadOptions,szTemp) ;
  1946. if(lstrlen(szTemp)!=0)
  1947. {
  1948. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPLICATE_BAUD_RATE));
  1949. dwExitCode = EXIT_FAILURE;
  1950. break;
  1951. }
  1952. else
  1953. {
  1954. lstrcpy(szTemp,BAUD_RATE);
  1955. lstrcat(szTemp,TOKEN_EQUAL);
  1956. lstrcat(szTemp,szBaudRate);
  1957. }
  1958. }
  1959. //append the string containing the modified port value to the string
  1960. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  1961. lstrcat(szOsLoadOptions,szTemp);
  1962. }
  1963. //check if the user has entered OFF option
  1964. if( lstrcmpi(szDebug,VALUE_OFF)== 0)
  1965. {
  1966. // If the user enters either com port or baud rate then display error message and exit.
  1967. if ((lstrlen(szPort)!=0) ||(lstrlen(szBaudRate)!=0))
  1968. {
  1969. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  1970. dwExitCode = EXIT_FAILURE;
  1971. break;
  1972. }
  1973. // If the user enters either com port or baud rate then display error message and exit.
  1974. if (_tcsstr(szOsLoadOptions,DEBUG_SWITCH) == 0 )
  1975. {
  1976. DISPLAY_MESSAGE(stderr,GetResString(IDS_DEBUG_ABSENT));
  1977. dwExitCode = EXIT_FAILURE;
  1978. break;
  1979. }
  1980. //remove the debug switch from the OSLoad Options
  1981. removeSubString(szOsLoadOptions,DEBUG_SWITCH);
  1982. if(_tcsstr(szOsLoadOptions,DEBUGPORT_1394) != 0 )
  1983. {
  1984. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_1394_REMOVE));
  1985. dwExitCode = EXIT_FAILURE;
  1986. break;
  1987. }
  1988. //display an error message if debug port doee not exist.
  1989. if ( GetSubString(szOsLoadOptions,TOKEN_DEBUGPORT,szTemp) == EXIT_FAILURE)
  1990. {
  1991. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_DEBUGPORT));
  1992. return EXIT_FAILURE ;
  1993. }
  1994. if(lstrlen(szTemp)!=0)
  1995. {
  1996. // remove the /debugport=comport switch if it is present from the Boot Entry
  1997. removeSubString(szOsLoadOptions,szTemp);
  1998. }
  1999. lstrcpy(szTemp , NULL_STRING );
  2000. //remove the baud rate switch if it is present.
  2001. GetBaudRateVal(szOsLoadOptions,szTemp) ;
  2002. // if the OSLoadOptions contains baudrate then delete it.
  2003. if (lstrlen(szTemp )!= 0)
  2004. {
  2005. removeSubString(szOsLoadOptions,szTemp);
  2006. }
  2007. }
  2008. //if the user selected the edit option .
  2009. if( lstrcmpi(szDebug,EDIT_STRING)== 0)
  2010. {
  2011. //check if the debug switch is present in the Osload options else display error message.
  2012. if (_tcsstr(szOsLoadOptions,DEBUG_SWITCH) == 0 )
  2013. {
  2014. DISPLAY_MESSAGE(stderr,GetResString(IDS_DEBUG_ABSENT));
  2015. dwExitCode = EXIT_FAILURE;
  2016. break;
  2017. }
  2018. if( _tcsstr(szOsLoadOptions,DEBUGPORT_1394) != 0 )
  2019. {
  2020. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_EDIT_1394_SWITCH));
  2021. dwExitCode = EXIT_FAILURE;
  2022. break;
  2023. }
  2024. //check if the user enters COM port or baud rate else display error message.
  2025. if((lstrlen(szPort)==0)&&(lstrlen(szBaudRate)==0))
  2026. {
  2027. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  2028. dwExitCode = EXIT_FAILURE;
  2029. break;
  2030. }
  2031. if( lstrlen(szPort)!=0 )
  2032. {
  2033. if ( GetSubString(szOsLoadOptions,TOKEN_DEBUGPORT,szTemp) == EXIT_FAILURE)
  2034. {
  2035. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_DEBUGPORT));
  2036. return EXIT_FAILURE ;
  2037. }
  2038. if(lstrlen(szTemp)!=0)
  2039. {
  2040. //remove the existing entry from the OsLoadOptions String.
  2041. removeSubString(szOsLoadOptions,szTemp);
  2042. }
  2043. //Add the port entry specified by user into the OsLoadOptions String.
  2044. lstrcat(szTmpBuffer,TOKEN_EMPTYSPACE);
  2045. lstrcat(szTmpBuffer,TOKEN_DEBUGPORT) ;
  2046. lstrcat(szTmpBuffer,TOKEN_EQUAL) ;
  2047. CharUpper(szPort);
  2048. lstrcat(szTmpBuffer,szPort);
  2049. lstrcat(szOsLoadOptions,szTmpBuffer);
  2050. }
  2051. //Check if the OS Load Options contains the baud rate already specified.
  2052. if(lstrlen(szBaudRate)!=0)
  2053. {
  2054. if ( GetSubString(szOsLoadOptions,TOKEN_DEBUGPORT,szTemp) == EXIT_FAILURE)
  2055. {
  2056. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_DEBUGPORT));
  2057. return EXIT_FAILURE ;
  2058. }
  2059. if(lstrlen(szTemp)==0)
  2060. {
  2061. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_DEBUGPORT));
  2062. return EXIT_FAILURE ;
  2063. }
  2064. lstrcpy(szTemp,NULL_STRING);
  2065. GetBaudRateVal(szOsLoadOptions,szTemp) ;
  2066. if(lstrlen(szTemp)!=0)
  2067. {
  2068. removeSubString(szOsLoadOptions,szTemp);
  2069. }
  2070. lstrcpy(szTemp,BAUD_RATE);
  2071. lstrcat(szTemp,TOKEN_EQUAL);
  2072. lstrcat(szTemp,szBaudRate);
  2073. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2074. lstrcat(szOsLoadOptions,szTemp);
  2075. }
  2076. }
  2077. //display error message if Os Load options is more than 254
  2078. // characters.
  2079. if(lstrlen(szOsLoadOptions) >= MAX_RES_STRING)
  2080. {
  2081. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_STRING_LENGTH1),MAX_RES_STRING);
  2082. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2083. break ;
  2084. }
  2085. // modify the Boot Entry with the modified OsLoad Options.
  2086. dwExitCode = ChangeBootEntry(bootEntry, NULL, szOsLoadOptions);
  2087. if(dwExitCode == ERROR_SUCCESS)
  2088. {
  2089. _stprintf(szMsgBuffer, GetResString(IDS_SUCCESS_CHANGE_OSOPTIONS),dwBootID);
  2090. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  2091. }
  2092. else
  2093. {
  2094. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_CHANGE_OSOPTIONS),dwBootID);
  2095. DISPLAY_MESSAGE(stderr, szMsgBuffer);
  2096. }
  2097. break;
  2098. }
  2099. }
  2100. if(bBootIdFound == FALSE)
  2101. {
  2102. //Could not find the BootID specified by the user so output the message and return failure
  2103. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  2104. dwExitCode = EXIT_FAILURE;
  2105. }
  2106. //Remember to free memory allocated for the linked lists
  2107. return (dwExitCode);
  2108. }
  2109. // ***************************************************************************
  2110. //
  2111. // Name : GetComPortType_IA64
  2112. //
  2113. // Synopsis : Get the Type of Com Port present in Boot Entry
  2114. //
  2115. // Parameters : szString : The String which is to be searched.
  2116. // szTemp : String which will get the com port type
  2117. // Return Type : VOID
  2118. //
  2119. // Global Variables : None
  2120. //
  2121. // ***************************************************************************
  2122. VOID GetComPortType_IA64( LPTSTR szString,LPTSTR szTemp )
  2123. {
  2124. if(_tcsstr(szString,PORT_COM1A)!=0)
  2125. {
  2126. lstrcpy(szTemp,PORT_COM1A);
  2127. }
  2128. else if(_tcsstr(szString,PORT_COM2A)!=0)
  2129. {
  2130. lstrcpy(szTemp,PORT_COM2A);
  2131. }
  2132. else if(_tcsstr(szString,PORT_COM3A)!=0)
  2133. {
  2134. lstrcpy(szTemp,PORT_COM3A);
  2135. }
  2136. else if(_tcsstr(szString,PORT_COM4A)!=0)
  2137. {
  2138. lstrcpy(szTemp,PORT_COM4A);
  2139. }
  2140. else if(_tcsstr(szString,PORT_1394A)!=0)
  2141. {
  2142. lstrcpy(szTemp,PORT_1394A);
  2143. }
  2144. }
  2145. // ***************************************************************************
  2146. //
  2147. // Name : ProcessEmsSwitch_IA64
  2148. //
  2149. // Synopsis : Allows the user to add the OS load options specifed
  2150. // as a debug string at the cmdline to the boot
  2151. //
  2152. // Parameters : DWORD argc (in) - Number of command line arguments
  2153. // LPCTSTR argv (in) - Array containing command line arguments
  2154. //
  2155. // Return Type : DWORD
  2156. //
  2157. // Global Variables: Global Linked lists for storing the boot entries
  2158. // LIST_ENTRY BootEntries;
  2159. //
  2160. // ***************************************************************************
  2161. DWORD ProcessEmsSwitch_IA64( DWORD argc, LPCTSTR argv[] )
  2162. {
  2163. BOOL bUsage = FALSE ;
  2164. DWORD dwBootID = 0;
  2165. BOOL bBootIdFound = FALSE;
  2166. DWORD dwExitCode = ERROR_SUCCESS;
  2167. PMY_BOOT_ENTRY mybootEntry;
  2168. PLIST_ENTRY listEntry;
  2169. PBOOT_ENTRY bootEntry;
  2170. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING ;
  2171. TCHAR szEms[MAX_RES_STRING] = NULL_STRING ;
  2172. BOOL bEms = FALSE ;
  2173. PWINDOWS_OS_OPTIONS pWindowsOptions = NULL ;
  2174. TCHAR szOsLoadOptions[MAX_RES_STRING] = NULL_STRING ;
  2175. // Building the TCMDPARSER structure
  2176. TCMDPARSER cmdOptions[] =
  2177. {
  2178. { CMDOPTION_EMS, CP_MAIN_OPTION | CP_TYPE_TEXT | CP_MODE_VALUES | CP_VALUE_OPTIONAL, 1, 0,&szEms,CMDOPTION_EMS_VALUES_IA64, NULL, NULL },
  2179. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  2180. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwBootID, NULL_STRING, NULL, NULL },
  2181. };
  2182. // Parsing the copy option switches
  2183. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  2184. {
  2185. dwExitCode = EXIT_FAILURE;
  2186. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  2187. ShowMessage(stderr,GetReason());
  2188. return (dwExitCode);
  2189. }
  2190. // Displaying query usage if user specified -? with -query option
  2191. if( bUsage )
  2192. {
  2193. displayEmsUsage_IA64();
  2194. return (EXIT_SUCCESS);
  2195. }
  2196. //display error message if the user enters any other string other that on/off.
  2197. if( !((lstrcmpi(szEms,VALUE_ON)== 0) || (lstrcmpi(szEms,VALUE_OFF)== 0)))
  2198. {
  2199. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  2200. return EXIT_FAILURE ;
  2201. }
  2202. //Query the boot entries till u get the BootID specified by the user
  2203. for (listEntry = BootEntries.Flink;
  2204. listEntry != &BootEntries;
  2205. listEntry = listEntry->Flink)
  2206. {
  2207. //Get the boot entry
  2208. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  2209. if(mybootEntry->myId == dwBootID)
  2210. {
  2211. bBootIdFound = TRUE;
  2212. bootEntry = &mybootEntry->NtBootEntry;
  2213. //Check whether the bootEntry is a Windows one or not.
  2214. //The OS load options can be added only to a Windows boot entry.
  2215. if(!IsBootEntryWindows(bootEntry))
  2216. {
  2217. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  2218. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2219. DISPLAY_MESSAGE(stderr, GetResString(IDS_INFO_NOTWINDOWS));
  2220. dwExitCode = EXIT_FAILURE;
  2221. break;
  2222. }
  2223. pWindowsOptions = (PWINDOWS_OS_OPTIONS)bootEntry->OsOptions;
  2224. // copy the existing OS Loadoptions into a string.
  2225. lstrcpy(szOsLoadOptions,pWindowsOptions->OsLoadOptions);
  2226. //check if the user has entered On option
  2227. if( lstrcmpi(szEms,VALUE_ON)== 0)
  2228. {
  2229. if (_tcsstr(szOsLoadOptions,REDIRECT_SWITCH) != 0 )
  2230. {
  2231. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_REDIRECT));
  2232. dwExitCode = EXIT_FAILURE;
  2233. break;
  2234. }
  2235. // add the redirect switch to the OS Load Options string.
  2236. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2237. lstrcat(szOsLoadOptions,REDIRECT_SWITCH);
  2238. }
  2239. //check if the user has entered OFF option
  2240. if( lstrcmpi(szEms,VALUE_OFF)== 0)
  2241. {
  2242. // If the user enters either com port or baud rate then display error message and exit.
  2243. if (_tcsstr(szOsLoadOptions,REDIRECT_SWITCH) == 0 )
  2244. {
  2245. DISPLAY_MESSAGE(stderr,GetResString(IDS_REDIRECT_ABSENT));
  2246. dwExitCode = EXIT_FAILURE;
  2247. break;
  2248. }
  2249. //remove the debug switch from the OSLoad Options
  2250. removeSubString(szOsLoadOptions,REDIRECT_SWITCH);
  2251. }
  2252. //display error message if Os Load options is more than 254
  2253. // characters.
  2254. if(lstrlen(szOsLoadOptions) >= MAX_RES_STRING)
  2255. {
  2256. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_STRING_LENGTH1),MAX_RES_STRING);
  2257. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2258. break ;
  2259. }
  2260. // modify the Boot Entry with the modified OsLoad Options.
  2261. dwExitCode = ChangeBootEntry(bootEntry, NULL, szOsLoadOptions);
  2262. if(dwExitCode == ERROR_SUCCESS)
  2263. {
  2264. _stprintf(szMsgBuffer, GetResString(IDS_SUCCESS_CHANGE_OSOPTIONS),dwBootID);
  2265. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  2266. }
  2267. else
  2268. {
  2269. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_CHANGE_OSOPTIONS),dwBootID);
  2270. DISPLAY_MESSAGE(stderr, szMsgBuffer);
  2271. }
  2272. break;
  2273. }
  2274. }
  2275. if(bBootIdFound == FALSE)
  2276. {
  2277. //Could not find the BootID specified by the user so output the message and return failure
  2278. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  2279. dwExitCode = EXIT_FAILURE;
  2280. }
  2281. return (dwExitCode);
  2282. }
  2283. // ***************************************************************************
  2284. //
  2285. // Name : ProcessAddSwSwitch_IA64
  2286. //
  2287. // Synopsis : Allows the user to add the OS load options specifed
  2288. // at the cmdline to the boot
  2289. //
  2290. // Parameters : DWORD argc (in) - Number of command line arguments
  2291. // LPCTSTR argv (in) - Array containing command line arguments
  2292. //
  2293. // Return Type : DWORD
  2294. //
  2295. // Global Variables: Global Linked lists for storing the boot entries
  2296. // LIST_ENTRY BootEntries;
  2297. //
  2298. // ***************************************************************************
  2299. DWORD ProcessAddSwSwitch_IA64( DWORD argc, LPCTSTR argv[] )
  2300. {
  2301. BOOL bUsage = FALSE ;
  2302. BOOL bAddSw = FALSE ;
  2303. DWORD dwBootID = 0;
  2304. BOOL bBootIdFound = FALSE;
  2305. DWORD dwExitCode = ERROR_SUCCESS;
  2306. PMY_BOOT_ENTRY mybootEntry;
  2307. PLIST_ENTRY listEntry;
  2308. PBOOT_ENTRY bootEntry;
  2309. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  2310. BOOL bBaseVideo = FALSE ;
  2311. BOOL bNoGui = FALSE ;
  2312. BOOL bSos = FALSE ;
  2313. DWORD dwMaxmem = 0 ;
  2314. PWINDOWS_OS_OPTIONS pWindowsOptions = NULL ;
  2315. TCHAR szOsLoadOptions[MAX_RES_STRING] = NULL_STRING ;
  2316. TCHAR szMaxmem[MAX_RES_STRING] = NULL_STRING ;
  2317. // Building the TCMDPARSER structure
  2318. TCMDPARSER cmdOptions[] =
  2319. {
  2320. { CMDOPTION_ADDSW, CP_MAIN_OPTION, 1, 0,&bAddSw, NULL_STRING, NULL, NULL },
  2321. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  2322. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY|CP_MANDATORY , 1, 0, &dwBootID, NULL_STRING, NULL, NULL },
  2323. { SWITCH_MAXMEM, CP_TYPE_UNUMERIC | CP_VALUE_MANDATORY,1,0,&dwMaxmem,NULL_STRING,NULL,NULL},
  2324. { SWITCH_BASEVIDEO, 0,1,0,&bBaseVideo,NULL_STRING,NULL,NULL},
  2325. { SWITCH_NOGUIBOOT, 0,1,0,&bNoGui,NULL_STRING,NULL,NULL},
  2326. { SWITCH_SOS, 0,1,0,&bSos,NULL_STRING,NULL,NULL},
  2327. };
  2328. // Parsing the copy option switches
  2329. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  2330. {
  2331. dwExitCode = EXIT_FAILURE;
  2332. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  2333. ShowMessage(stderr,GetReason());
  2334. return (dwExitCode);
  2335. }
  2336. // Displaying query usage if user specified -? with -query option
  2337. if( bUsage )
  2338. {
  2339. displayAddSwUsage_IA64();
  2340. return (EXIT_SUCCESS);
  2341. }
  2342. if((dwMaxmem==0)&&(cmdOptions[3].dwActuals!=0))
  2343. {
  2344. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_MAXMEM_VALUES));
  2345. return EXIT_FAILURE ;
  2346. }
  2347. //display an error mesage if none of the options are specified.
  2348. if((!bSos)&&(!bBaseVideo)&&(!bNoGui)&&(dwMaxmem==0))
  2349. {
  2350. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_ADDSW));
  2351. return EXIT_FAILURE ;
  2352. }
  2353. //Query the boot entries till u get the BootID specified by the user
  2354. for (listEntry = BootEntries.Flink;
  2355. listEntry != &BootEntries;
  2356. listEntry = listEntry->Flink)
  2357. {
  2358. //Get the boot entry
  2359. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  2360. if(mybootEntry->myId == dwBootID)
  2361. {
  2362. bBootIdFound = TRUE;
  2363. bootEntry = &mybootEntry->NtBootEntry;
  2364. //Check whether the bootEntry is a Windows one or not.
  2365. //The OS load options can be added only to a Windows boot entry.
  2366. if(!IsBootEntryWindows(bootEntry))
  2367. {
  2368. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  2369. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2370. DISPLAY_MESSAGE(stderr, GetResString(IDS_INFO_NOTWINDOWS));
  2371. dwExitCode = EXIT_FAILURE;
  2372. break;
  2373. }
  2374. pWindowsOptions = (PWINDOWS_OS_OPTIONS)bootEntry->OsOptions;
  2375. // copy the existing OS Loadoptions into a string.
  2376. lstrcpy(szOsLoadOptions,pWindowsOptions->OsLoadOptions);
  2377. //check if the user has entered -basevideo option
  2378. if(bBaseVideo)
  2379. {
  2380. if (_tcsstr(szOsLoadOptions,BASEVIDEO_VALUE) != 0 )
  2381. {
  2382. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_BASEVIDEO_SWITCH));
  2383. dwExitCode = EXIT_FAILURE;
  2384. break;
  2385. }
  2386. else
  2387. {
  2388. // add the redirect switch to the OS Load Options string.
  2389. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2390. lstrcat(szOsLoadOptions,BASEVIDEO_VALUE);
  2391. }
  2392. }
  2393. if(bSos)
  2394. {
  2395. if (_tcsstr(szOsLoadOptions,SOS_VALUE) != 0 )
  2396. {
  2397. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_SOS_SWITCH));
  2398. dwExitCode = EXIT_FAILURE;
  2399. break;
  2400. }
  2401. else
  2402. {
  2403. // add the redirect switch to the OS Load Options string.
  2404. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2405. lstrcat(szOsLoadOptions,SOS_VALUE);
  2406. }
  2407. }
  2408. if(bNoGui)
  2409. {
  2410. if (_tcsstr(szOsLoadOptions,NOGUI_VALUE) != 0 )
  2411. {
  2412. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_NOGUI_SWITCH));
  2413. dwExitCode = EXIT_FAILURE;
  2414. break;
  2415. }
  2416. else
  2417. {
  2418. // add the redirect switch to the OS Load Options string.
  2419. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2420. lstrcat(szOsLoadOptions,NOGUI_VALUE);
  2421. }
  2422. }
  2423. if(dwMaxmem!=0)
  2424. {
  2425. // check if the maxmem value is in the valid range.
  2426. if( (dwMaxmem < 32) )
  2427. {
  2428. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_MAXMEM_VALUES));
  2429. dwExitCode = EXIT_FAILURE;
  2430. break;
  2431. }
  2432. if (_tcsstr(szOsLoadOptions,MAXMEM_VALUE1) != 0 )
  2433. {
  2434. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_MAXMEM_SWITCH));
  2435. dwExitCode = EXIT_FAILURE;
  2436. break;
  2437. }
  2438. else
  2439. {
  2440. // add the redirect switch to the OS Load Options string.
  2441. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2442. lstrcat(szOsLoadOptions,MAXMEM_VALUE1);
  2443. lstrcat(szOsLoadOptions,TOKEN_EQUAL);
  2444. _ltow(dwMaxmem,szMaxmem,10);
  2445. lstrcat(szOsLoadOptions,szMaxmem);
  2446. }
  2447. }
  2448. //display error message if Os Load options is more than 254
  2449. // characters.
  2450. if(lstrlen(szOsLoadOptions) >= MAX_RES_STRING)
  2451. {
  2452. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_STRING_LENGTH1),MAX_RES_STRING);
  2453. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2454. break ;
  2455. }
  2456. //Change the OS load options. Pass NULL to friendly name as we are not changing the same
  2457. //szRawString is the Os load options specified by the user
  2458. dwExitCode = ChangeBootEntry(bootEntry, NULL, szOsLoadOptions);
  2459. if(dwExitCode == ERROR_SUCCESS)
  2460. {
  2461. _stprintf(szMsgBuffer, GetResString(IDS_SUCCESS_OSOPTIONS),dwBootID);
  2462. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  2463. }
  2464. else
  2465. {
  2466. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  2467. DISPLAY_MESSAGE(stderr, szMsgBuffer);
  2468. }
  2469. break;
  2470. }
  2471. }
  2472. if(bBootIdFound == FALSE)
  2473. {
  2474. //Could not find the BootID specified by the user so output the message and return failure
  2475. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  2476. dwExitCode = EXIT_FAILURE;
  2477. }
  2478. //Remember to free memory allocated for the linked lists
  2479. return (dwExitCode);
  2480. }
  2481. // ***************************************************************************
  2482. //
  2483. // Name : ProcessRmSwSwitch_IA64
  2484. //
  2485. // Synopsis : Allows the user to add the OS load options specifed
  2486. // at the cmdline to the boot
  2487. //
  2488. // Parameters : DWORD argc (in) - Number of command line arguments
  2489. // LPCTSTR argv (in) - Array containing command line arguments
  2490. //
  2491. // Return Type : DWORD
  2492. //
  2493. // Global Variables: Global Linked lists for storing the boot entries
  2494. // LIST_ENTRY BootEntries;
  2495. //
  2496. // ***************************************************************************
  2497. DWORD ProcessRmSwSwitch_IA64( DWORD argc, LPCTSTR argv[] )
  2498. {
  2499. BOOL bUsage = FALSE ;
  2500. BOOL bRmSw = FALSE ;
  2501. DWORD dwBootID = 0;
  2502. BOOL bBootIdFound = FALSE;
  2503. DWORD dwExitCode = ERROR_SUCCESS;
  2504. PMY_BOOT_ENTRY mybootEntry;
  2505. PLIST_ENTRY listEntry;
  2506. PBOOT_ENTRY bootEntry;
  2507. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  2508. BOOL bBaseVideo = FALSE ;
  2509. BOOL bNoGui = FALSE ;
  2510. BOOL bSos = FALSE ;
  2511. BOOL bMaxmem = FALSE ;
  2512. PWINDOWS_OS_OPTIONS pWindowsOptions = NULL ;
  2513. TCHAR szOsLoadOptions[MAX_RES_STRING] = NULL_STRING ;
  2514. TCHAR szMaxmem[MAX_RES_STRING] = NULL_STRING ;
  2515. TCHAR szTemp[MAX_RES_STRING] = NULL_STRING ;
  2516. // Building the TCMDPARSER structure
  2517. TCMDPARSER cmdOptions[] =
  2518. {
  2519. { CMDOPTION_RMSW, CP_MAIN_OPTION, 1, 0,&bRmSw, NULL_STRING, NULL, NULL },
  2520. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  2521. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY|CP_MANDATORY, 1, 0, &dwBootID, NULL_STRING, NULL, NULL },
  2522. { SWITCH_MAXMEM, 0,1,0,&bMaxmem,NULL_STRING,NULL,NULL},
  2523. { SWITCH_BASEVIDEO, 0,1,0,&bBaseVideo,NULL_STRING,NULL,NULL},
  2524. { SWITCH_NOGUIBOOT, 0,1,0,&bNoGui,NULL_STRING,NULL,NULL},
  2525. { SWITCH_SOS, 0,1,0,&bSos,NULL_STRING,NULL,NULL},
  2526. };
  2527. // Parsing the copy option switches
  2528. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  2529. {
  2530. dwExitCode = EXIT_FAILURE;
  2531. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  2532. ShowMessage(stderr,GetReason());
  2533. return (dwExitCode);
  2534. }
  2535. // Displaying query usage if user specified -? with -query option
  2536. if( bUsage )
  2537. {
  2538. displayRmSwUsage_IA64();
  2539. return (EXIT_SUCCESS);
  2540. }
  2541. //display an error mesage if none of the options are specified.
  2542. if((!bSos)&&(!bBaseVideo)&&(!bNoGui)&&(!bMaxmem))
  2543. {
  2544. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_RMSW));
  2545. return EXIT_FAILURE;
  2546. }
  2547. //Query the boot entries till u get the BootID specified by the user
  2548. for (listEntry = BootEntries.Flink;
  2549. listEntry != &BootEntries;
  2550. listEntry = listEntry->Flink)
  2551. {
  2552. //Get the boot entry
  2553. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  2554. if(mybootEntry->myId == dwBootID)
  2555. {
  2556. bBootIdFound = TRUE;
  2557. bootEntry = &mybootEntry->NtBootEntry;
  2558. //Check whether the bootEntry is a Windows one or not.
  2559. //The OS load options can be added only to a Windows boot entry.
  2560. if(!IsBootEntryWindows(bootEntry))
  2561. {
  2562. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  2563. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2564. DISPLAY_MESSAGE(stderr, GetResString(IDS_INFO_NOTWINDOWS));
  2565. dwExitCode = EXIT_FAILURE;
  2566. break;
  2567. }
  2568. pWindowsOptions = (PWINDOWS_OS_OPTIONS)bootEntry->OsOptions;
  2569. // copy the existing OS Loadoptions into a string.
  2570. lstrcpy(szOsLoadOptions,pWindowsOptions->OsLoadOptions);
  2571. //check if the user has entered -basevideo option
  2572. if(bBaseVideo)
  2573. {
  2574. if (_tcsstr(szOsLoadOptions,BASEVIDEO_VALUE) == 0 )
  2575. {
  2576. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_BV_SWITCH));
  2577. dwExitCode = EXIT_FAILURE;
  2578. break;
  2579. }
  2580. else
  2581. {
  2582. // remove the basevideo switch from the OS Load Options string.
  2583. removeSubString(szOsLoadOptions,BASEVIDEO_VALUE);
  2584. }
  2585. }
  2586. if(bSos)
  2587. {
  2588. if (_tcsstr(szOsLoadOptions,SOS_VALUE) == 0 )
  2589. {
  2590. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_SOS_SWITCH));
  2591. dwExitCode = EXIT_FAILURE;
  2592. break;
  2593. }
  2594. else
  2595. {
  2596. // remove the /sos switch from the Load Options string.
  2597. removeSubString(szOsLoadOptions,SOS_VALUE);
  2598. }
  2599. }
  2600. if(bNoGui)
  2601. {
  2602. if (_tcsstr(szOsLoadOptions,NOGUI_VALUE) == 0 )
  2603. {
  2604. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_NOGUI_SWITCH));
  2605. dwExitCode = EXIT_FAILURE;
  2606. break;
  2607. }
  2608. else
  2609. {
  2610. // remove the noguiboot switch to the OS Load Options string.
  2611. removeSubString(szOsLoadOptions,NOGUI_VALUE);
  2612. }
  2613. }
  2614. if(bMaxmem)
  2615. {
  2616. if (_tcsstr(szOsLoadOptions,MAXMEM_VALUE1) == 0 )
  2617. {
  2618. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_MAXMEM_SWITCH));
  2619. dwExitCode = EXIT_FAILURE;
  2620. break;
  2621. }
  2622. else
  2623. {
  2624. // add the redirect switch to the OS Load Options string.
  2625. //for, a temporary string of form /maxmem=xx so that it
  2626. //can be checked in the Os load options,
  2627. if ( GetSubString(szOsLoadOptions,MAXMEM_VALUE1,szTemp) == EXIT_FAILURE)
  2628. {
  2629. return EXIT_FAILURE ;
  2630. }
  2631. removeSubString(szOsLoadOptions,szTemp);
  2632. if(_tcsstr(szOsLoadOptions,MAXMEM_VALUE1)!=0)
  2633. {
  2634. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_MAXMEM) );
  2635. return EXIT_FAILURE ;
  2636. }
  2637. }
  2638. }
  2639. //display error message if Os Load options is more than 254
  2640. // characters.
  2641. if(lstrlen(szOsLoadOptions) >= MAX_RES_STRING)
  2642. {
  2643. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_STRING_LENGTH1),MAX_RES_STRING);
  2644. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2645. break ;
  2646. }
  2647. //Change the OS load options. Pass NULL to friendly name as we are not changing the same
  2648. //szRawString is the Os load options specified by the user
  2649. dwExitCode = ChangeBootEntry(bootEntry, NULL, szOsLoadOptions);
  2650. if(dwExitCode == ERROR_SUCCESS)
  2651. {
  2652. _stprintf(szMsgBuffer, GetResString(IDS_SUCCESS_CHANGE_OSOPTIONS),dwBootID);
  2653. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  2654. }
  2655. else
  2656. {
  2657. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  2658. DISPLAY_MESSAGE(stderr, szMsgBuffer);
  2659. }
  2660. break;
  2661. }
  2662. }
  2663. if(bBootIdFound == FALSE)
  2664. {
  2665. //Could not find the BootID specified by the user so output the message and return failure
  2666. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  2667. dwExitCode = EXIT_FAILURE;
  2668. }
  2669. return (dwExitCode);
  2670. }
  2671. // ***************************************************************************
  2672. //
  2673. // Name : ProcessDbg1394Switch_IA64
  2674. //
  2675. // Synopsis : Allows the user to add the OS load options specifed
  2676. // at the cmdline to the boot
  2677. //
  2678. // Parameters : DWORD argc (in) - Number of command line arguments
  2679. // LPCTSTR argv (in) - Array containing command line arguments
  2680. //
  2681. // Return Type : DWORD
  2682. //
  2683. // Global Variables: Global Linked lists for storing the boot entries
  2684. // LIST_ENTRY BootEntries;
  2685. //
  2686. // ***************************************************************************
  2687. DWORD ProcessDbg1394Switch_IA64( DWORD argc, LPCTSTR argv[] )
  2688. {
  2689. BOOL bUsage = FALSE ;
  2690. BOOL bDbg1394 = FALSE ;
  2691. DWORD dwBootID = 0;
  2692. BOOL bBootIdFound = FALSE;
  2693. DWORD dwExitCode = ERROR_SUCCESS;
  2694. PMY_BOOT_ENTRY mybootEntry;
  2695. PLIST_ENTRY listEntry;
  2696. PBOOT_ENTRY bootEntry;
  2697. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  2698. BOOL bBaseVideo = FALSE ;
  2699. BOOL bNoGui = FALSE ;
  2700. BOOL bSos = FALSE ;
  2701. BOOL bMaxmem = FALSE ;
  2702. PWINDOWS_OS_OPTIONS pWindowsOptions = NULL ;
  2703. TCHAR szOsLoadOptions[MAX_RES_STRING] = NULL_STRING ;
  2704. TCHAR szMaxmem[MAX_RES_STRING] = NULL_STRING ;
  2705. TCHAR szTemp[MAX_RES_STRING] = NULL_STRING ;
  2706. TCHAR szChannel[MAX_RES_STRING] = NULL_STRING ;
  2707. TCHAR szDefault[MAX_RES_STRING] = NULL_STRING ;
  2708. DWORD dwChannel = 0 ;
  2709. DWORD dwCode = 0 ;
  2710. // Building the TCMDPARSER structure
  2711. TCMDPARSER cmdOptions[] =
  2712. {
  2713. { CMDOPTION_DBG1394, CP_MAIN_OPTION, 1, 0,&bDbg1394,NULL_STRING , NULL, NULL },
  2714. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  2715. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY , 1, 0, &dwBootID, NULL_STRING, NULL, NULL },
  2716. { CMDOPTION_CHANNEL, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY,1,0,&dwChannel,NULL_STRING,NULL,NULL},
  2717. { CMDOPTION_DEFAULT, CP_DEFAULT|CP_TYPE_TEXT , 1, 0, &szDefault,NULL_STRING, NULL, NULL }
  2718. };
  2719. // Parsing the copy option switches
  2720. if ( !(DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) ) )
  2721. {
  2722. DISPLAY_MESSAGE(stderr,ERROR_TAG) ;
  2723. ShowMessage(stderr,GetReason()) ;
  2724. return (EXIT_FAILURE);
  2725. }
  2726. // Displaying query usage if user specified -? with -query option
  2727. if( bUsage )
  2728. {
  2729. displayDbg1394Usage_IA64() ;
  2730. return (EXIT_SUCCESS);
  2731. }
  2732. if((cmdOptions[2].dwActuals == 0) &&(dwBootID == 0 ))
  2733. {
  2734. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_ID_MISSING));
  2735. DISPLAY_MESSAGE(stderr,GetResString(IDS_1394_HELP));
  2736. return (EXIT_FAILURE);
  2737. }
  2738. //
  2739. //display error message if user enters a value
  2740. // other than on or off
  2741. //
  2742. if( ( lstrcmpi(szDefault,OFF_STRING)!=0 ) && (lstrcmpi(szDefault,ON_STRING)!=0 ) )
  2743. {
  2744. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_DEFAULT_MISSING));
  2745. DISPLAY_MESSAGE(stderr,GetResString(IDS_1394_HELP));
  2746. return (EXIT_FAILURE);
  2747. }
  2748. if(( lstrcmpi(szDefault,OFF_STRING)==0 ) &&(dwChannel != 0) )
  2749. {
  2750. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DBG1394));
  2751. return (EXIT_FAILURE);
  2752. }
  2753. if(( lstrcmpi(szDefault,ON_STRING)==0 ) && (cmdOptions[3].dwActuals != 0) &&( (dwChannel < 1) || (dwChannel > 64 ) ) )
  2754. {
  2755. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_CH_RANGE));
  2756. return (EXIT_FAILURE);
  2757. }
  2758. //Query the boot entries till u get the BootID specified by the user
  2759. for (listEntry = BootEntries.Flink;
  2760. listEntry != &BootEntries;
  2761. listEntry = listEntry->Flink)
  2762. {
  2763. //Get the boot entry
  2764. mybootEntry = CONTAINING_RECORD( listEntry, MY_BOOT_ENTRY, ListEntry );
  2765. if(mybootEntry->myId == dwBootID)
  2766. {
  2767. bBootIdFound = TRUE;
  2768. bootEntry = &mybootEntry->NtBootEntry;
  2769. //Check whether the bootEntry is a Windows one or not.
  2770. //The OS load options can be added only to a Windows boot entry.
  2771. if(!IsBootEntryWindows(bootEntry))
  2772. {
  2773. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  2774. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2775. DISPLAY_MESSAGE(stderr, GetResString(IDS_INFO_NOTWINDOWS));
  2776. dwExitCode = EXIT_FAILURE;
  2777. break;
  2778. }
  2779. pWindowsOptions = (PWINDOWS_OS_OPTIONS)bootEntry->OsOptions;
  2780. // copy the existing OS Loadoptions into a string.
  2781. lstrcpy(szOsLoadOptions,pWindowsOptions->OsLoadOptions);
  2782. //check if the user has entered on option
  2783. if(lstrcmpi(szDefault,ON_STRING)==0 )
  2784. {
  2785. if(_tcsstr(szOsLoadOptions,DEBUGPORT) != 0)
  2786. {
  2787. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPLICATE_ENTRY));
  2788. dwExitCode = EXIT_FAILURE;
  2789. break;
  2790. }
  2791. if( _tcsstr(szOsLoadOptions,DEBUG_SWITCH)== 0)
  2792. {
  2793. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2794. lstrcat(szOsLoadOptions,DEBUG_SWITCH);
  2795. }
  2796. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2797. lstrcat(szOsLoadOptions,DEBUGPORT_1394) ;
  2798. if(dwChannel!=0)
  2799. {
  2800. //frame the string and concatenate to the Os Load options.
  2801. lstrcat(szOsLoadOptions,TOKEN_EMPTYSPACE);
  2802. lstrcat(szOsLoadOptions,TOKEN_CHANNEL);
  2803. lstrcat(szOsLoadOptions,TOKEN_EQUAL);
  2804. _ltow(dwChannel,szChannel,10);
  2805. lstrcat(szOsLoadOptions,szChannel);
  2806. }
  2807. }
  2808. if(lstrcmpi(szDefault,OFF_STRING)==0 )
  2809. {
  2810. if(_tcsstr(szOsLoadOptions,DEBUGPORT_1394) == 0)
  2811. {
  2812. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_1394_SWITCH));
  2813. dwExitCode = EXIT_FAILURE;
  2814. break;
  2815. }
  2816. //
  2817. //remove the port from the Os Load options string.
  2818. //
  2819. removeSubString(szOsLoadOptions,DEBUGPORT_1394);
  2820. // check if the string contains the channel token
  2821. // and if present remove that also.
  2822. //
  2823. if(_tcsstr(szOsLoadOptions,TOKEN_CHANNEL)!=0)
  2824. {
  2825. lstrcpy(szTemp,NULL_STRING);
  2826. dwCode = GetSubString(szOsLoadOptions,TOKEN_CHANNEL,szTemp);
  2827. if(dwCode == EXIT_SUCCESS)
  2828. {
  2829. //
  2830. //Remove the channel token if present.
  2831. //
  2832. if(lstrlen(szTemp)!= 0)
  2833. {
  2834. removeSubString(szOsLoadOptions,szTemp);
  2835. removeSubString(szOsLoadOptions,DEBUG_SWITCH);
  2836. }
  2837. }
  2838. }
  2839. removeSubString(szOsLoadOptions,DEBUG_SWITCH);
  2840. }
  2841. //display error message if Os Load options is more than 254
  2842. // characters.
  2843. if(lstrlen(szOsLoadOptions) >= MAX_RES_STRING)
  2844. {
  2845. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_STRING_LENGTH1),MAX_RES_STRING);
  2846. DISPLAY_MESSAGE(stderr,szMsgBuffer);
  2847. break ;
  2848. }
  2849. //Change the OS load options. Pass NULL to friendly name as we are not changing the same
  2850. //szRawString is the Os load options specified by the user
  2851. dwExitCode = ChangeBootEntry(bootEntry, NULL, szOsLoadOptions);
  2852. if(dwExitCode == ERROR_SUCCESS)
  2853. {
  2854. _stprintf(szMsgBuffer, GetResString(IDS_SUCCESS_CHANGE_OSOPTIONS),dwBootID);
  2855. DISPLAY_MESSAGE(stdout,szMsgBuffer);
  2856. }
  2857. else
  2858. {
  2859. _stprintf(szMsgBuffer, GetResString(IDS_ERROR_OSOPTIONS),dwBootID);
  2860. DISPLAY_MESSAGE(stderr, szMsgBuffer);
  2861. }
  2862. break;
  2863. }
  2864. }
  2865. if(bBootIdFound == FALSE)
  2866. {
  2867. //Could not find the BootID specified by the user so output the message and return failure
  2868. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  2869. dwExitCode = EXIT_FAILURE;
  2870. }
  2871. return (dwExitCode);
  2872. }
  2873. // ***************************************************************************
  2874. //
  2875. // Synopsis : Allows the user to add the OS load options specifed
  2876. // based on the mirror plex
  2877. //
  2878. // Parameters : DWORD argc (in) - Number of command line arguments
  2879. // LPCTSTR argv (in) - Array containing command line arguments
  2880. //
  2881. // Return Type : DWORD
  2882. //
  2883. // Global Variables: Global Linked lists for storing the boot entries
  2884. // LIST_ENTRY BootEntries;
  2885. //
  2886. // ***************************************************************************
  2887. DWORD ProcessMirrorSwitch_IA64( DWORD argc, LPCTSTR argv[] )
  2888. {
  2889. BOOL bUsage = FALSE ;
  2890. BOOL bDbg1394 = FALSE ;
  2891. DWORD dwBootID = 1;
  2892. BOOL bBootIdFound = FALSE;
  2893. DWORD dwExitCode = ERROR_SUCCESS;
  2894. PMY_BOOT_ENTRY mybootEntry;
  2895. PLIST_ENTRY listEntry;
  2896. PBOOT_ENTRY bootEntry;
  2897. PBOOT_ENTRY ModbootEntry;
  2898. TCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  2899. BOOL bBaseVideo = FALSE ;
  2900. BOOL bNoGui = FALSE ;
  2901. BOOL bSos = FALSE ;
  2902. BOOL bMaxmem = FALSE ;
  2903. PWINDOWS_OS_OPTIONS pWindowsOptions = NULL ;
  2904. TCHAR szOsLoadOptions[MAX_RES_STRING] = NULL_STRING ;
  2905. TCHAR szMaxmem[MAX_RES_STRING] = NULL_STRING ;
  2906. TCHAR szTemp[MAX_RES_STRING] = NULL_STRING ;
  2907. TCHAR szChannel[MAX_RES_STRING] = NULL_STRING ;
  2908. TCHAR szAdd[MAX_RES_STRING] = NULL_STRING ;
  2909. TCHAR szDefault[MAX_RES_STRING] = NULL_STRING ;
  2910. TCHAR szUpdate[MAX_RES_STRING] = NULL_STRING ;
  2911. DWORD dwChannel = 0 ;
  2912. DWORD dwCode = 0 ;
  2913. BOOL bMirror = FALSE ;
  2914. DWORD dwList = 0 ;
  2915. DWORD dwCnt = 0 ;
  2916. TCHAR szArcPath[MAX_RES_STRING] = NULL_STRING ;
  2917. TCHAR szBootPath[MAX_RES_STRING] = NULL_STRING ;
  2918. TCHAR szLdrString[MAX_RES_STRING] = NULL_STRING ;
  2919. ULONG length = 0 ;
  2920. DWORD Id = 0 ;
  2921. NTSTATUS status ;
  2922. DWORD error = 0 ;
  2923. LONG lRetVal = 0 ;
  2924. WCHAR pwszLoaderPath[] = L"signature({09de56a0-a122-01c0-507b-9e5f8078f531})\\EFI\\Microsoft\\WINNT50.1\\ia64ldr.efi" ;
  2925. WCHAR pwszArcString[] = L"signature(fd0611c0a12101c0a1f404622fd5ec6d)\\WINDOWS=";
  2926. WCHAR pwszArcString1[] = L"\"Boot Mirror x: - secondary plex\"";
  2927. WCHAR pwszFinalArcString[1024] ;
  2928. // Building the TCMDPARSER structure
  2929. TCMDPARSER cmdOptions[] =
  2930. {
  2931. { CMDOPTION_MIRROR, CP_MAIN_OPTION, 1, 0,&bMirror,NULL_STRING , NULL, NULL },
  2932. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  2933. { CMDOPTION_LIST, CP_VALUE_OPTIONAL|CP_TYPE_UNUMERIC,1,0,&dwList,NULL_STRING,NULL,NULL},
  2934. { CMDOPTION_ADD, CP_TYPE_TEXT|CP_VALUE_MANDATORY , 1, 0, &szAdd,NULL_STRING, NULL, NULL } ,
  2935. { CMDOPTION_UPDATE, CP_TYPE_TEXT|CP_VALUE_MANDATORY, 1, 0, &szUpdate,NULL_STRING, NULL, NULL },
  2936. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY , 1, 0, &dwBootID, NULL_STRING, NULL, NULL }
  2937. };
  2938. // Parsing the copy option switches
  2939. if ( !(DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) ) )
  2940. {
  2941. DISPLAY_MESSAGE(stderr,ERROR_TAG) ;
  2942. ShowMessage(stderr,GetReason()) ;
  2943. return (EXIT_FAILURE);
  2944. }
  2945. // Displaying query usage if user specified -? with -query option
  2946. if( bUsage )
  2947. {
  2948. displayMirrorUsage_IA64() ;
  2949. return (EXIT_SUCCESS);
  2950. }
  2951. if((cmdOptions[2].dwActuals ==0)&&(cmdOptions[3].dwActuals ==0)&&(cmdOptions[4].dwActuals ==0) )
  2952. {
  2953. DISPLAY_MESSAGE(stdout,GetResString(IDS_MIRROR_SYNTAX));
  2954. return (EXIT_FAILURE);
  2955. }
  2956. if((cmdOptions[2].dwActuals !=0))
  2957. {
  2958. if(dwList > 0)
  2959. {
  2960. //ScanGPT(dwList) ;
  2961. _tprintf(_T("To be implemented.\n"));
  2962. return (EXIT_SUCCESS);
  2963. }
  2964. else
  2965. {
  2966. dwList = 0 ;
  2967. //ScanGPT(dwList) ;
  2968. _tprintf(_T("To be implemented.\n"));
  2969. return (EXIT_SUCCESS);
  2970. }
  2971. }
  2972. if(lstrlen(szAdd) !=0)
  2973. {
  2974. _tprintf(_T("To be implemented.\n"));
  2975. }
  2976. if(lstrlen(szUpdate) !=0)
  2977. {
  2978. _tprintf(_T("To be implemented.\n"));
  2979. }
  2980. return EXIT_SUCCESS ;
  2981. }