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.

283 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. behavior.c
  5. Abstract:
  6. This file contains routines that control file system behavior
  7. Author:
  8. Wesley Witt [wesw] 1-March-2000
  9. Revision History:
  10. --*/
  11. #include <precomp.h>
  12. INT
  13. BehaviorHelp(
  14. IN INT argc,
  15. IN PWSTR argv[]
  16. )
  17. {
  18. DisplayMsg( MSG_USAGE_BEHAVIOR );
  19. return EXIT_CODE_SUCCESS;
  20. }
  21. #define NTFS_KEY L"System\\CurrentControlSet\\Control\\FileSystem"
  22. typedef struct _BEHAVIOR_OPTION {
  23. PWSTR Name;
  24. PWSTR RegVal;
  25. ULONG MinVal;
  26. ULONG MaxVal;
  27. } BEHAVIOR_OPTION, *PBEHAVIOR_OPTION;
  28. BEHAVIOR_OPTION Options[] = {
  29. { L"disable8dot3", L"NtfsDisable8dot3NameCreation", 0, 1 },
  30. { L"allowextchar", L"NtfsAllowExtendedCharacterIn8dot3Name", 0, 1 },
  31. { L"disablelastaccess", L"NtfsDisableLastAccessUpdate", 0, 1 },
  32. { L"quotanotify", L"NtfsQuotaNotifyRate", 1, -1 },
  33. { L"mftzone", L"NtfsMftZoneReservation", 1, 4 },
  34. { L"memoryusage", L"NtfsMemoryUsage", 1, 2 },
  35. };
  36. #define NUM_OPTIONS (sizeof(Options)/sizeof(BEHAVIOR_OPTION))
  37. INT
  38. RegistryQueryValueKey(
  39. IN INT argc,
  40. IN PWSTR argv[]
  41. )
  42. /*++
  43. Routine Description:
  44. This is the routine for querying the Registry Key Value.
  45. This routine display the value associated with the corresponding
  46. Key Value.
  47. Arguments:
  48. argc - The argument count and must be 1
  49. argv - Array with one string element that is the registry key to display.
  50. Return Value:
  51. None
  52. --*/
  53. {
  54. ULONG i,Value,Size;
  55. HKEY hKey = NULL;
  56. LONG Status;
  57. INT ExitCode = EXIT_CODE_SUCCESS;
  58. try {
  59. if (argc != 1) {
  60. DisplayMsg( MSG_USAGE_RQUERYVK );
  61. if (argc != 0) {
  62. ExitCode = EXIT_CODE_FAILURE;
  63. }
  64. leave;
  65. }
  66. //
  67. // Verify that the option is correct
  68. //
  69. for (i = 0; i < NUM_OPTIONS; i++) {
  70. if (_wcsicmp( argv[0], Options[i].Name ) == 0) {
  71. break;
  72. }
  73. }
  74. if (i >= NUM_OPTIONS) {
  75. DisplayMsg( MSG_USAGE_RSETVK );
  76. ExitCode = EXIT_CODE_FAILURE;
  77. leave;
  78. }
  79. //
  80. // Open the registry key
  81. //
  82. Status = RegOpenKeyEx(
  83. HKEY_LOCAL_MACHINE,
  84. NTFS_KEY,
  85. 0,
  86. KEY_ALL_ACCESS,
  87. &hKey
  88. );
  89. if (Status != ERROR_SUCCESS ) {
  90. DisplayErrorMsg( Status, NTFS_KEY );
  91. ExitCode = EXIT_CODE_FAILURE;
  92. leave;
  93. }
  94. //
  95. // Query the value
  96. //
  97. Size = sizeof(ULONG);
  98. Status = RegQueryValueEx(
  99. hKey,
  100. Options[i].RegVal,
  101. 0,
  102. NULL,
  103. (PBYTE)&Value,
  104. &Size
  105. );
  106. if (Status != ERROR_SUCCESS ) {
  107. DisplayMsg( MSG_BEHAVIOR_OUTPUT_NOT_SET, Options[i].Name );
  108. } else {
  109. DisplayMsg( MSG_BEHAVIOR_OUTPUT, Options[i].Name, Value );
  110. }
  111. } finally {
  112. if (hKey) {
  113. RegCloseKey( hKey );
  114. }
  115. }
  116. return ExitCode;
  117. }
  118. INT
  119. RegistrySetValueKey (
  120. IN INT argc,
  121. IN PWSTR argv[]
  122. )
  123. /*++
  124. Routine Description:
  125. This is the routine for setting the Registry Key Value.
  126. This routine sets the value for the Key Value Name given.
  127. Arguments:
  128. argc - The argument count.
  129. argv - Array of strings which contain the DataType, DataLength,
  130. Data and KeyValue Name.
  131. Return Value:
  132. None
  133. --*/
  134. {
  135. ULONG i,j;
  136. HKEY hKey = NULL;
  137. LONG Status;
  138. INT ExitCode = EXIT_CODE_SUCCESS;
  139. PWSTR EndPtr;
  140. try {
  141. if (argc != 2) {
  142. DisplayMsg( MSG_USAGE_RSETVK );
  143. if (argc != 0) {
  144. ExitCode = EXIT_CODE_FAILURE;
  145. }
  146. leave;
  147. }
  148. //
  149. // Verify that the option is correct
  150. //
  151. for (i = 0; i < NUM_OPTIONS; i++) {
  152. if (_wcsicmp( argv[0], Options[i].Name ) == 0) {
  153. break;
  154. }
  155. }
  156. if (i == NUM_OPTIONS) {
  157. DisplayMsg( MSG_USAGE_RSETVK );
  158. ExitCode = EXIT_CODE_FAILURE;
  159. leave;
  160. }
  161. //
  162. // Verify that the value is correct
  163. //
  164. j = My_wcstoul( argv[1], &EndPtr, 0 );
  165. //
  166. // If we did not parse the entire string or
  167. // if we overflowed ULONG or
  168. // if we're out of range
  169. //
  170. if (UnsignedNumberCheck( j, EndPtr )
  171. || j > Options[i].MaxVal
  172. || j < Options[i].MinVal) {
  173. DisplayMsg( MSG_USAGE_RSETVK );
  174. ExitCode = EXIT_CODE_FAILURE;
  175. leave;
  176. }
  177. //
  178. // Open the registry key
  179. //
  180. Status = RegOpenKeyEx(
  181. HKEY_LOCAL_MACHINE,
  182. NTFS_KEY,
  183. 0,
  184. KEY_ALL_ACCESS,
  185. &hKey
  186. );
  187. if (Status != ERROR_SUCCESS ) {
  188. DisplayErrorMsg( Status, NTFS_KEY );
  189. ExitCode = EXIT_CODE_FAILURE;
  190. leave;
  191. }
  192. //
  193. // Set the value
  194. //
  195. Status = RegSetValueEx(
  196. hKey,
  197. Options[i].RegVal,
  198. 0,
  199. REG_DWORD,
  200. (PBYTE)&j,
  201. sizeof(DWORD)
  202. );
  203. if (Status != ERROR_SUCCESS ) {
  204. DisplayErrorMsg( Status, Options[i].RegVal );
  205. ExitCode = EXIT_CODE_FAILURE;
  206. leave;
  207. }
  208. } finally {
  209. if (hKey) {
  210. RegCloseKey( hKey );
  211. }
  212. }
  213. return ExitCode;
  214. }