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.

245 lines
5.0 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. LaDate.cpp
  5. Abstract:
  6. Implementation of CLaDate, a class representing the enabled or
  7. disabled state of last access date updating of NTFS files. Last
  8. access date updating on NTFS files can be disabled through the
  9. registry for performance reasons. This class implements updating
  10. and reporting of the state of the registry value that contols last
  11. access date. The following states are used to represent the registry
  12. value:
  13. LAD_DISABLED: last access date is disabled, registry value is 1
  14. LAD_ENABLED: last access date is enabled, registry value is not 1
  15. LAD_UNSET: last access date is enabled, no registry value
  16. Author:
  17. Carl Hagerstrom [carlh] 01-Sep-1998
  18. --*/
  19. #include <StdAfx.h>
  20. #include <LaDate.h>
  21. /*++
  22. Implements:
  23. CLaDate Constructor
  24. Routine Description:
  25. Initialize object state and open registry key. If the registry key cannot
  26. be opened, we will assume that the last access state is LAD_UNSET.
  27. --*/
  28. CLaDate::CLaDate( )
  29. {
  30. TRACEFN( "CLaDate::CLaDate" );
  31. HKEY regKey = 0;
  32. m_regPath = L"System\\CurrentControlSet\\Control\\FileSystem";
  33. m_regEntry = L"NtfsDisableLastAccessUpdate";
  34. m_regKey = (HKEY)0;
  35. if( ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  36. m_regPath,
  37. (DWORD)0,
  38. KEY_ALL_ACCESS,
  39. &regKey ) ) {
  40. m_regKey = regKey;
  41. }
  42. }
  43. /*++
  44. Implements:
  45. CLaDate Destructor
  46. Routine Description:
  47. Close registry key.
  48. --*/
  49. CLaDate::~CLaDate( )
  50. {
  51. TRACEFN( "CLaDate::~CLaDate" );
  52. if ( m_regKey ) {
  53. RegCloseKey( m_regKey );
  54. }
  55. }
  56. /*++
  57. Implements:
  58. CLaDate::UnsetLadState
  59. Routine Description:
  60. Removes the registry value.
  61. Arguments:
  62. None
  63. Return Value:
  64. S_OK - Success
  65. E_* - Any unexpected exceptions from lower level routines
  66. --*/
  67. HRESULT
  68. CLaDate::UnsetLadState( )
  69. {
  70. TRACEFNHR( "CLaDate::UnsetLadState" );
  71. try {
  72. if( m_regKey ) {
  73. RsOptAffirmWin32( RegDeleteValue( m_regKey, m_regEntry ) );
  74. }
  75. } RsOptCatch( hrRet );
  76. return( hrRet );
  77. }
  78. /*++
  79. Implements:
  80. CLaDate::SetLadState
  81. Routine Description:
  82. Sets the registry value according to the input parameter.
  83. Arguments:
  84. ladState - LAD_ENABLED or LAD_DISABLED
  85. Return Value:
  86. S_OK - Success
  87. E_NOTIMPL - Operation not supported
  88. E_* - Any unexpected exceptions from lower level routines
  89. --*/
  90. HRESULT
  91. CLaDate::SetLadState(
  92. IN LAD_STATE ladState
  93. )
  94. {
  95. TRACEFNHR( "CLaDate::SetLadState" );
  96. DWORD newVal = (DWORD)0;
  97. try {
  98. if ( !m_regKey ) {
  99. RsOptThrow( E_NOTIMPL );
  100. }
  101. if ( ladState == LAD_DISABLED ) {
  102. newVal = (DWORD)1;
  103. }
  104. RsOptAffirmWin32( RegSetValueEx( m_regKey,
  105. m_regEntry,
  106. (DWORD)0,
  107. REG_DWORD,
  108. (BYTE*)&newVal,
  109. (DWORD)sizeof( DWORD ) ) );
  110. } RsOptCatch( hrRet );
  111. return( hrRet );
  112. }
  113. /*++
  114. Implements:
  115. CLaDate::GetLadState
  116. Routine Description:
  117. Returns the current state of registry value.
  118. Arguments:
  119. ladState - LAD_ENABLED, LAD_DISABLED or LAD_UNSET
  120. Return Value:
  121. S_OK - Success
  122. E_FAIL - Registry value is of bad type or size
  123. E_* - Any unexpected exceptions from lower level routines
  124. --*/
  125. HRESULT
  126. CLaDate::GetLadState(
  127. OUT LAD_STATE* ladState
  128. )
  129. {
  130. TRACEFNHR( "CLaDate::GetLadState" );
  131. DWORD regType;
  132. BYTE regData[sizeof( DWORD )];
  133. DWORD dataSize = sizeof( DWORD );
  134. try {
  135. if( !m_regKey ) {
  136. *ladState = LAD_UNSET;
  137. } else {
  138. RsOptAffirmWin32( RegQueryValueEx( m_regKey,
  139. m_regEntry,
  140. (LPDWORD)0,
  141. &regType,
  142. regData,
  143. &dataSize ) );
  144. if( regType != REG_DWORD || dataSize != sizeof( DWORD ) ) {
  145. *ladState = LAD_ENABLED;
  146. } else {
  147. if ( (DWORD)1 == *( (DWORD*)regData ) ) {
  148. *ladState = LAD_DISABLED;
  149. } else {
  150. *ladState = LAD_ENABLED;
  151. }
  152. }
  153. }
  154. } RsOptCatch( hrRet );
  155. return( hrRet );
  156. }