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.

233 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. volume.c
  5. Abstract:
  6. This file contains code for commands that affect
  7. the the dirty bit of ntfs volumes.
  8. Author:
  9. Wesley Witt [wesw] 1-March-2000
  10. Revision History:
  11. --*/
  12. #include <precomp.h>
  13. INT
  14. DirtyHelp(
  15. IN INT argc,
  16. IN PWSTR argv[]
  17. )
  18. {
  19. DisplayMsg( MSG_USAGE_DIRTY );
  20. return EXIT_CODE_SUCCESS;
  21. }
  22. INT
  23. IsVolumeDirty(
  24. IN INT argc,
  25. IN PWSTR argv[]
  26. )
  27. /*++
  28. Routine Description:
  29. This routine checks if the Volume specified is dirty.
  30. Arguments:
  31. argc - The argument count.
  32. argv - Array of Strings of the form :
  33. ' fscutl isdirtyv <volume pathname>'.
  34. Return Value:
  35. None
  36. --*/
  37. {
  38. HANDLE FileHandle = INVALID_HANDLE_VALUE;
  39. WCHAR FileName[MAX_PATH];
  40. BOOL Status;
  41. DWORD BytesReturned;
  42. DWORD VolumeStatus;
  43. INT ExitCode = EXIT_CODE_SUCCESS;
  44. try {
  45. if (argc != 1) {
  46. DisplayMsg( MSG_USAGE_ISVDIRTY );
  47. if (argc != 0) {
  48. ExitCode = EXIT_CODE_FAILURE;
  49. }
  50. leave;
  51. }
  52. if (!IsVolumeLocal( argv[0][0] )) {
  53. DisplayMsg( MSG_NEED_LOCAL_VOLUME );
  54. ExitCode = EXIT_CODE_FAILURE;
  55. leave;
  56. }
  57. if (wcslen( DotPrefix ) + wcslen( argv[0] ) + 1 > MAX_PATH) {
  58. DisplayMsg( MSG_FILENAME_TOO_LONG );
  59. ExitCode = EXIT_CODE_FAILURE;
  60. leave;
  61. }
  62. wcscpy( FileName, DotPrefix );
  63. wcscat( FileName, argv[0] );
  64. FileHandle = CreateFile(
  65. FileName,
  66. GENERIC_READ,
  67. FILE_SHARE_READ | FILE_SHARE_WRITE,
  68. NULL,
  69. OPEN_EXISTING,
  70. FILE_ATTRIBUTE_NORMAL,
  71. NULL
  72. );
  73. if (FileHandle == INVALID_HANDLE_VALUE) {
  74. DisplayError();
  75. ExitCode = EXIT_CODE_FAILURE;
  76. leave;
  77. }
  78. Status = DeviceIoControl(
  79. FileHandle,
  80. FSCTL_IS_VOLUME_DIRTY,
  81. NULL,
  82. 0,
  83. (LPVOID)&VolumeStatus,
  84. sizeof(VolumeStatus),
  85. &BytesReturned,
  86. (LPOVERLAPPED)NULL
  87. );
  88. if (!Status) {
  89. DisplayError();
  90. ExitCode = EXIT_CODE_FAILURE;
  91. leave;
  92. }
  93. if (VolumeStatus & VOLUME_IS_DIRTY) {
  94. DisplayMsg( MSG_ISVDIRTY_YES, argv[0] );
  95. } else {
  96. DisplayMsg( MSG_ISVDIRTY_NO, argv[0] );
  97. }
  98. } finally {
  99. if (FileHandle != INVALID_HANDLE_VALUE) {
  100. CloseHandle( FileHandle );
  101. }
  102. }
  103. return ExitCode;
  104. }
  105. INT
  106. MarkVolumeDirty(
  107. IN INT argc,
  108. IN PWSTR argv[]
  109. )
  110. /*++
  111. Routine Description:
  112. This routine marks the volume as dirty.
  113. Arguments:
  114. argc - The argument count.
  115. argv - Array of Strings of the form :
  116. ' fscutl markv <volume pathname>'.
  117. Return Value:
  118. None
  119. --*/
  120. {
  121. BOOL Status;
  122. HANDLE FileHandle = INVALID_HANDLE_VALUE;
  123. DWORD BytesReturned;
  124. WCHAR FileName[MAX_PATH];
  125. INT ExitCode = EXIT_CODE_SUCCESS;
  126. try {
  127. if (argc != 1) {
  128. DisplayMsg( MSG_USAGE_MARKV );
  129. if (argc != 0) {
  130. ExitCode = EXIT_CODE_FAILURE;
  131. }
  132. leave;
  133. }
  134. if (!IsVolumeLocalNTFS( argv[0][0] )) {
  135. DisplayMsg( MSG_NTFS_REQUIRED );
  136. ExitCode = EXIT_CODE_FAILURE;
  137. leave;
  138. }
  139. if (wcslen( DotPrefix ) + wcslen( argv[0] ) + 1 > MAX_PATH) {
  140. DisplayMsg( MSG_FILENAME_TOO_LONG );
  141. ExitCode = EXIT_CODE_FAILURE;
  142. leave;
  143. }
  144. wcscpy( FileName, DotPrefix );
  145. wcscat( FileName, argv[0] );
  146. FileHandle = CreateFile(
  147. FileName,
  148. GENERIC_WRITE,
  149. FILE_SHARE_READ | FILE_SHARE_WRITE,
  150. NULL,
  151. OPEN_EXISTING,
  152. FILE_ATTRIBUTE_NORMAL,
  153. NULL
  154. );
  155. if (FileHandle == INVALID_HANDLE_VALUE) {
  156. DisplayError();
  157. ExitCode = EXIT_CODE_FAILURE;
  158. leave;
  159. }
  160. Status = DeviceIoControl(
  161. FileHandle,
  162. FSCTL_MARK_VOLUME_DIRTY,
  163. NULL,
  164. 0,
  165. NULL,
  166. 0,
  167. &BytesReturned,
  168. (LPOVERLAPPED)NULL
  169. );
  170. if (!Status) {
  171. DisplayError();
  172. ExitCode = EXIT_CODE_FAILURE;
  173. } else {
  174. DisplayMsg( MSG_DIRTY_SET, argv[0] );
  175. }
  176. } finally {
  177. if (FileHandle != INVALID_HANDLE_VALUE) {
  178. CloseHandle( FileHandle );
  179. }
  180. }
  181. return ExitCode;
  182. }