Leaked source code of windows server 2003
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.

111 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. pagefile.c
  5. Abstract:
  6. This module contains code to create a pagefile in the WinPE environment.
  7. [WinPE]
  8. PageFileSize = size - Creates a pagefile of the specified size named c:\pagefile.sys.
  9. Author:
  10. Adrian Cosma (acosma) 06/2001
  11. Revision History:
  12. --*/
  13. //
  14. // Include File(s):
  15. //
  16. #include "factoryp.h"
  17. //
  18. // Defined Value(s):
  19. //
  20. #define PAGEFILENAME _T("\\??\\C:\\pagefile.sys")
  21. #define PAGEFILESIZE 64
  22. //
  23. // External Function(s):
  24. //
  25. BOOL DisplayCreatePageFile(LPSTATEDATA lpStateData)
  26. {
  27. MEMORYSTATUSEX mStatus;
  28. static INT iRet = 0;
  29. if ( 0 == iRet )
  30. {
  31. // Fill in required values
  32. //
  33. ZeroMemory(&mStatus, sizeof(mStatus));
  34. mStatus.dwLength = sizeof(mStatus);
  35. // If we are running on less than or 64MB machine OR if there is a PageFileSize=x entry in the
  36. // winbom, set the static variable so we know whether this check has been done and if we need to
  37. // create the pagefile.
  38. //
  39. // iRet = 0 - we haven't initialized this yet
  40. // iRet = 1 - we don't need to create a pagefile
  41. // iRet = 0 - we need to create a pagefile
  42. //
  43. if ( ( ( GlobalMemoryStatusEx(&mStatus) ) &&
  44. ( (mStatus.ullTotalPhys / (1024 * 1024)) <= 64) ) ||
  45. ( IniSettingExists(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_WINPE, INI_KEY_WBOM_WINPE_PAGEFILE, NULL) ) )
  46. {
  47. iRet = 2;
  48. }
  49. else
  50. {
  51. iRet = 1;
  52. }
  53. }
  54. return (iRet - 1);
  55. }
  56. BOOL CreatePageFile(LPSTATEDATA lpStateData)
  57. {
  58. NTSTATUS Status;
  59. UNICODE_STRING UnicodeString;
  60. LARGE_INTEGER liPageFileSize;
  61. BOOL bRet = TRUE;
  62. UINT uiPageFileSizeMB;
  63. if ( DisplayCreatePageFile(lpStateData) )
  64. {
  65. uiPageFileSizeMB = GetPrivateProfileInt(INI_SEC_WBOM_WINPE, INI_KEY_WBOM_WINPE_PAGEFILE, PAGEFILESIZE, lpStateData->lpszWinBOMPath);
  66. // If the user specified 0 means we don't want to create the file.
  67. //
  68. if ( uiPageFileSizeMB )
  69. {
  70. liPageFileSize.QuadPart = uiPageFileSizeMB * 1024 * 1024;
  71. // Request the privilege to create a pagefile.
  72. //
  73. EnablePrivilege(SE_CREATE_PAGEFILE_NAME, TRUE);
  74. RtlInitUnicodeString(&UnicodeString, PAGEFILENAME);
  75. Status = NtCreatePagingFile(&UnicodeString, &liPageFileSize, &liPageFileSize, 0);
  76. if ( !NT_SUCCESS(Status) )
  77. {
  78. bRet = FALSE;
  79. FacLogFile(0 | LOG_ERR, IDS_ERR_PAGEFILE, Status);
  80. }
  81. }
  82. }
  83. return bRet;
  84. }