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.

90 lines
2.7 KiB

  1. //
  2. // REGFKEY.C
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // Implementation of RegFlushKey and supporting functions.
  7. //
  8. #include "pch.h"
  9. // Magic HKEY used by Setup to disable disk I/O for the duration of this
  10. // Windows session (you must restart to re-enable disk I/O). This is done
  11. // just before the new SYSTEM.DAT and USER.DAT are copied to their final
  12. // destination.
  13. #define HKEY_DISABLE_REG (HKEY) 0x484A574D
  14. // Magic HKEY used by CONFIGMG to force a flush of the registry before we've
  15. // received our normal post-critical init call.
  16. #define HKEY_CRITICAL_FLUSH (HKEY) 0x5350574D
  17. // Magic HKEY used by ScanregW to clear the failed boot bit FHF_BOOTFAILED in the file header
  18. // of HKEY_LOCAL_MACHINE. Indicating that we successfully booted and verified the integrity
  19. // of the registry files, and that scanreg.exe does not need to be ran by win.com on next boot.
  20. #define HKEY_BOOT_SUCCESS (HKEY) 0x5342574D
  21. //
  22. // VMMRegFlushKey
  23. //
  24. LONG
  25. REGAPI
  26. VMMRegFlushKey(
  27. HKEY hKey
  28. )
  29. {
  30. int ErrorCode;
  31. BOOL fBootSuccess = FALSE;
  32. if (!RgLockRegistry())
  33. return ERROR_LOCK_FAILED;
  34. #ifdef VXD
  35. // Set the g_RgFileAccessDisabled flag so that all create or open file
  36. // calls will be failed. The backing stores for our files are about to
  37. // be changed, so there's no file for us to go to.
  38. if (hKey == HKEY_DISABLE_REG) {
  39. g_RgFileAccessDisabled = TRUE;
  40. ErrorCode = ERROR_SUCCESS;
  41. goto ReturnErrorCode;
  42. }
  43. // Set the g_RgPostCriticalInit flag so that all I/O calls will go to disk
  44. // instead of the XMS cache. The XMS cache will be freed when/if the
  45. // normal post critical init routine is called, but we should only be
  46. // getting this call when we're about to die, so it doesn't really matter.
  47. if (hKey == HKEY_CRITICAL_FLUSH) {
  48. g_RgPostCriticalInit = TRUE;
  49. hKey = HKEY_LOCAL_MACHINE;
  50. }
  51. // Clears the failed boot bit FHF_BOOTFAILED in the file header of HKEY_LOCAL_MACHINE.
  52. // Indicating that we successfully booted and verified the integrity of the registry files.
  53. if (hKey == HKEY_BOOT_SUCCESS)
  54. {
  55. fBootSuccess = TRUE;
  56. hKey = HKEY_LOCAL_MACHINE;
  57. }
  58. #endif
  59. if ((ErrorCode = RgValidateAndConvertKeyHandle(&hKey)) == ERROR_SUCCESS)
  60. {
  61. #ifdef VXD
  62. if (fBootSuccess)
  63. {
  64. hKey-> lpFileInfo-> FileHeader.Flags |= FHF_DIRTY;
  65. hKey-> lpFileInfo-> FileHeader.Flags &= ~FHF_BOOTFAILED;
  66. }
  67. #endif
  68. ErrorCode = RgFlushFileInfo(hKey-> lpFileInfo);
  69. }
  70. #ifdef VXD
  71. ReturnErrorCode:
  72. #endif
  73. RgUnlockRegistry();
  74. return ErrorCode;
  75. }