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.

282 lines
5.6 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. };
  35. #define NUM_OPTIONS (sizeof(Options)/sizeof(BEHAVIOR_OPTION))
  36. INT
  37. RegistryQueryValueKey(
  38. IN INT argc,
  39. IN PWSTR argv[]
  40. )
  41. /*++
  42. Routine Description:
  43. This is the routine for querying the Registry Key Value.
  44. This routine display the value associated with the corresponding
  45. Key Value.
  46. Arguments:
  47. argc - The argument count and must be 1
  48. argv - Array with one string element that is the registry key to display.
  49. Return Value:
  50. None
  51. --*/
  52. {
  53. ULONG i,Value,Size;
  54. HKEY hKey = NULL;
  55. LONG Status;
  56. INT ExitCode = EXIT_CODE_SUCCESS;
  57. try {
  58. if (argc != 1) {
  59. DisplayMsg( MSG_USAGE_RQUERYVK );
  60. if (argc != 0) {
  61. ExitCode = EXIT_CODE_FAILURE;
  62. }
  63. leave;
  64. }
  65. //
  66. // Verify that the option is correct
  67. //
  68. for (i = 0; i < NUM_OPTIONS; i++) {
  69. if (_wcsicmp( argv[0], Options[i].Name ) == 0) {
  70. break;
  71. }
  72. }
  73. if (i >= NUM_OPTIONS) {
  74. DisplayMsg( MSG_USAGE_RSETVK );
  75. ExitCode = EXIT_CODE_FAILURE;
  76. leave;
  77. }
  78. //
  79. // Open the registry key
  80. //
  81. Status = RegOpenKeyEx(
  82. HKEY_LOCAL_MACHINE,
  83. NTFS_KEY,
  84. 0,
  85. KEY_ALL_ACCESS,
  86. &hKey
  87. );
  88. if (Status != ERROR_SUCCESS ) {
  89. DisplayErrorMsg( Status, NTFS_KEY );
  90. ExitCode = EXIT_CODE_FAILURE;
  91. leave;
  92. }
  93. //
  94. // Query the value
  95. //
  96. Size = sizeof(ULONG);
  97. Status = RegQueryValueEx(
  98. hKey,
  99. Options[i].RegVal,
  100. 0,
  101. NULL,
  102. (PBYTE)&Value,
  103. &Size
  104. );
  105. if (Status != ERROR_SUCCESS ) {
  106. DisplayMsg( MSG_BEHAVIOR_OUTPUT_NOT_SET, Options[i].Name );
  107. } else {
  108. DisplayMsg( MSG_BEHAVIOR_OUTPUT, Options[i].Name, Value );
  109. }
  110. } finally {
  111. if (hKey) {
  112. RegCloseKey( hKey );
  113. }
  114. }
  115. return ExitCode;
  116. }
  117. INT
  118. RegistrySetValueKey (
  119. IN INT argc,
  120. IN PWSTR argv[]
  121. )
  122. /*++
  123. Routine Description:
  124. This is the routine for setting the Registry Key Value.
  125. This routine sets the value for the Key Value Name given.
  126. Arguments:
  127. argc - The argument count.
  128. argv - Array of strings which contain the DataType, DataLength,
  129. Data and KeyValue Name.
  130. Return Value:
  131. None
  132. --*/
  133. {
  134. ULONG i,j;
  135. HKEY hKey = NULL;
  136. LONG Status;
  137. INT ExitCode = EXIT_CODE_SUCCESS;
  138. PWSTR EndPtr;
  139. try {
  140. if (argc != 2) {
  141. DisplayMsg( MSG_USAGE_RSETVK );
  142. if (argc != 0) {
  143. ExitCode = EXIT_CODE_FAILURE;
  144. }
  145. leave;
  146. }
  147. //
  148. // Verify that the option is correct
  149. //
  150. for (i = 0; i < NUM_OPTIONS; i++) {
  151. if (_wcsicmp( argv[0], Options[i].Name ) == 0) {
  152. break;
  153. }
  154. }
  155. if (i == NUM_OPTIONS) {
  156. DisplayMsg( MSG_USAGE_RSETVK );
  157. ExitCode = EXIT_CODE_FAILURE;
  158. leave;
  159. }
  160. //
  161. // Verify that the value is correct
  162. //
  163. j = My_wcstoul( argv[1], &EndPtr, 0 );
  164. //
  165. // If we did not parse the entire string or
  166. // if we overflowed ULONG or
  167. // if we're out of range
  168. //
  169. if (UnsignedNumberCheck( j, EndPtr )
  170. || j > Options[i].MaxVal
  171. || j < Options[i].MinVal) {
  172. DisplayMsg( MSG_USAGE_RSETVK );
  173. ExitCode = EXIT_CODE_FAILURE;
  174. leave;
  175. }
  176. //
  177. // Open the registry key
  178. //
  179. Status = RegOpenKeyEx(
  180. HKEY_LOCAL_MACHINE,
  181. NTFS_KEY,
  182. 0,
  183. KEY_ALL_ACCESS,
  184. &hKey
  185. );
  186. if (Status != ERROR_SUCCESS ) {
  187. DisplayErrorMsg( Status, NTFS_KEY );
  188. ExitCode = EXIT_CODE_FAILURE;
  189. leave;
  190. }
  191. //
  192. // Set the value
  193. //
  194. Status = RegSetValueEx(
  195. hKey,
  196. Options[i].RegVal,
  197. 0,
  198. REG_DWORD,
  199. (PBYTE)&j,
  200. sizeof(DWORD)
  201. );
  202. if (Status != ERROR_SUCCESS ) {
  203. DisplayErrorMsg( Status, Options[i].RegVal );
  204. ExitCode = EXIT_CODE_FAILURE;
  205. leave;
  206. }
  207. } finally {
  208. if (hKey) {
  209. RegCloseKey( hKey );
  210. }
  211. }
  212. return ExitCode;
  213. }