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.

221 lines
4.3 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. wcscpy( FileName, L"\\\\.\\" );
  58. wcscat( FileName, argv[0] );
  59. FileHandle = CreateFile(
  60. FileName,
  61. GENERIC_READ,
  62. FILE_SHARE_READ | FILE_SHARE_WRITE,
  63. NULL,
  64. OPEN_EXISTING,
  65. FILE_ATTRIBUTE_NORMAL,
  66. NULL
  67. );
  68. if (FileHandle == INVALID_HANDLE_VALUE) {
  69. DisplayError();
  70. ExitCode = EXIT_CODE_FAILURE;
  71. leave;
  72. }
  73. Status = DeviceIoControl(
  74. FileHandle,
  75. FSCTL_IS_VOLUME_DIRTY,
  76. NULL,
  77. 0,
  78. (LPVOID)&VolumeStatus,
  79. sizeof(VolumeStatus),
  80. &BytesReturned,
  81. (LPOVERLAPPED)NULL
  82. );
  83. if (!Status) {
  84. DisplayError();
  85. ExitCode = EXIT_CODE_FAILURE;
  86. leave;
  87. }
  88. if (VolumeStatus & VOLUME_IS_DIRTY) {
  89. DisplayMsg( MSG_ISVDIRTY_YES, argv[0] );
  90. } else {
  91. DisplayMsg( MSG_ISVDIRTY_NO, argv[0] );
  92. }
  93. } finally {
  94. if (FileHandle != INVALID_HANDLE_VALUE) {
  95. CloseHandle( FileHandle );
  96. }
  97. }
  98. return ExitCode;
  99. }
  100. INT
  101. MarkVolumeDirty(
  102. IN INT argc,
  103. IN PWSTR argv[]
  104. )
  105. /*++
  106. Routine Description:
  107. This routine marks the volume as dirty.
  108. Arguments:
  109. argc - The argument count.
  110. argv - Array of Strings of the form :
  111. ' fscutl markv <volume pathname>'.
  112. Return Value:
  113. None
  114. --*/
  115. {
  116. BOOL Status;
  117. HANDLE FileHandle = INVALID_HANDLE_VALUE;
  118. DWORD BytesReturned;
  119. WCHAR FileName[MAX_PATH];
  120. INT ExitCode = EXIT_CODE_SUCCESS;
  121. try {
  122. if (argc != 1) {
  123. DisplayMsg( MSG_USAGE_MARKV );
  124. if (argc != 0) {
  125. ExitCode = EXIT_CODE_FAILURE;
  126. }
  127. leave;
  128. }
  129. if (!IsVolumeLocalNTFS( argv[0][0] )) {
  130. DisplayMsg( MSG_NTFS_REQUIRED );
  131. ExitCode = EXIT_CODE_FAILURE;
  132. leave;
  133. }
  134. wcscpy( FileName, L"\\\\.\\" );
  135. wcsncat( FileName, argv[0], (sizeof(FileName)/sizeof(WCHAR))-wcslen(FileName) );
  136. FileHandle = CreateFile(
  137. FileName,
  138. GENERIC_WRITE,
  139. FILE_SHARE_READ | FILE_SHARE_WRITE,
  140. NULL,
  141. OPEN_EXISTING,
  142. FILE_ATTRIBUTE_NORMAL,
  143. NULL
  144. );
  145. if (FileHandle == INVALID_HANDLE_VALUE) {
  146. DisplayError();
  147. ExitCode = EXIT_CODE_FAILURE;
  148. leave;
  149. }
  150. Status = DeviceIoControl(
  151. FileHandle,
  152. FSCTL_MARK_VOLUME_DIRTY,
  153. NULL,
  154. 0,
  155. NULL,
  156. 0,
  157. &BytesReturned,
  158. (LPOVERLAPPED)NULL
  159. );
  160. if (!Status) {
  161. DisplayError();
  162. ExitCode = EXIT_CODE_FAILURE;
  163. } else {
  164. DisplayMsg( MSG_DIRTY_SET, argv[0] );
  165. }
  166. } finally {
  167. if (FileHandle != INVALID_HANDLE_VALUE) {
  168. CloseHandle( FileHandle );
  169. }
  170. }
  171. return ExitCode;
  172. }