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.

263 lines
7.1 KiB

  1. //--------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1999, Microsoft Corporation
  4. //
  5. // File: flush.cxx
  6. //
  7. //--------------------------------------------------------------------------
  8. #define UNICODE 1
  9. #include <stdio.h>
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <shellapi.h>
  15. #include <winldap.h>
  16. #include <stdlib.h>
  17. #include <dsgetdc.h>
  18. #include <lm.h>
  19. #include <lmdfs.h>
  20. #include "struct.hxx"
  21. #include "dfsfsctl.h"
  22. #include "messages.h"
  23. #include <dfsutil.hxx>
  24. #include "misc.hxx"
  25. WCHAR wszEverything[] = L"*";
  26. DWORD
  27. PktFlush(
  28. LPWSTR EntryPath)
  29. {
  30. DWORD dwErr = STATUS_SUCCESS;
  31. NTSTATUS NtStatus;
  32. HANDLE DriverHandle = NULL;
  33. IO_STATUS_BLOCK IoStatusBlock;
  34. OBJECT_ATTRIBUTES objectAttributes;
  35. UNICODE_STRING DfsDriverName;
  36. ULONG Type = 0;
  37. DebugInformation((L"PktFlush(%ws)\r\n", EntryPath));
  38. if (EntryPath == NULL)
  39. EntryPath = wszEverything;
  40. DebugInformation((L"EntryPath=[%ws]\r\n", EntryPath));
  41. RtlInitUnicodeString(&DfsDriverName, DFS_DRIVER_NAME);
  42. InitializeObjectAttributes(
  43. &objectAttributes,
  44. &DfsDriverName,
  45. OBJ_CASE_INSENSITIVE,
  46. NULL,
  47. NULL);
  48. NtStatus = NtCreateFile(
  49. &DriverHandle,
  50. SYNCHRONIZE | FILE_WRITE_DATA,
  51. &objectAttributes,
  52. &IoStatusBlock,
  53. NULL,
  54. FILE_ATTRIBUTE_NORMAL,
  55. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  56. FILE_OPEN_IF,
  57. FILE_CREATE_TREE_CONNECTION | FILE_SYNCHRONOUS_IO_NONALERT,
  58. NULL,
  59. 0);
  60. if (!NT_SUCCESS(NtStatus)) {
  61. dwErr = RtlNtStatusToDosError(NtStatus);
  62. DebugInformation((L"NtCreateFile returned 0x%x\r\n", NtStatus));
  63. goto Cleanup;
  64. }
  65. NtStatus = NtFsControlFile(
  66. DriverHandle,
  67. NULL, // Event,
  68. NULL, // ApcRoutine,
  69. NULL, // ApcContext,
  70. &IoStatusBlock,
  71. FSCTL_DFS_PKT_FLUSH_CACHE,
  72. EntryPath,
  73. wcslen(EntryPath) * sizeof(WCHAR),
  74. NULL,
  75. 0);
  76. NtClose(DriverHandle);
  77. if (!NT_SUCCESS(NtStatus)) {
  78. DebugInformation((L"NtFsControlFile returned 0x%x\r\n", NtStatus));
  79. ErrorMessage(NtStatus);
  80. } else {
  81. CommandSucceeded = TRUE;
  82. }
  83. dwErr = RtlNtStatusToDosError(NtStatus);
  84. Cleanup:
  85. if (dwErr != ERROR_SUCCESS)
  86. DebugInformation((L"PktFlush exit %d\r\n", dwErr));
  87. return(dwErr);
  88. }
  89. DWORD
  90. SpcFlush(
  91. LPWSTR EntryPath)
  92. {
  93. DWORD dwErr = STATUS_SUCCESS;
  94. NTSTATUS NtStatus;
  95. HANDLE DriverHandle = NULL;
  96. IO_STATUS_BLOCK IoStatusBlock;
  97. OBJECT_ATTRIBUTES objectAttributes;
  98. UNICODE_STRING DfsDriverName;
  99. ULONG Type = 0;
  100. DebugInformation((L"SpcFlush(%ws)\r\n", EntryPath));
  101. if (EntryPath == NULL)
  102. EntryPath = wszEverything;
  103. RtlInitUnicodeString(&DfsDriverName, DFS_DRIVER_NAME);
  104. InitializeObjectAttributes(
  105. &objectAttributes,
  106. &DfsDriverName,
  107. OBJ_CASE_INSENSITIVE,
  108. NULL,
  109. NULL);
  110. NtStatus = NtCreateFile(
  111. &DriverHandle,
  112. SYNCHRONIZE | FILE_WRITE_DATA,
  113. &objectAttributes,
  114. &IoStatusBlock,
  115. NULL,
  116. FILE_ATTRIBUTE_NORMAL,
  117. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  118. FILE_OPEN_IF,
  119. FILE_CREATE_TREE_CONNECTION | FILE_SYNCHRONOUS_IO_NONALERT,
  120. NULL,
  121. 0);
  122. if (!NT_SUCCESS(NtStatus)) {
  123. dwErr = RtlNtStatusToDosError(NtStatus);
  124. DebugInformation((L"NtCreateFile returned 0x%x\r\n", NtStatus));
  125. goto Cleanup;
  126. }
  127. DebugInformation((L"EntryPath=[%ws]\r\n", EntryPath));
  128. NtStatus = NtFsControlFile(
  129. DriverHandle,
  130. NULL, // Event,
  131. NULL, // ApcRoutine,
  132. NULL, // ApcContext,
  133. &IoStatusBlock,
  134. FSCTL_DFS_PKT_FLUSH_SPC_CACHE,
  135. EntryPath,
  136. wcslen(EntryPath) * sizeof(WCHAR),
  137. NULL,
  138. 0);
  139. NtClose(DriverHandle);
  140. if (!NT_SUCCESS(NtStatus)) {
  141. DebugInformation((L"NtFsControlFile returned 0x%x\r\n", NtStatus));
  142. } else {
  143. CommandSucceeded = TRUE;
  144. }
  145. dwErr = RtlNtStatusToDosError(NtStatus);
  146. Cleanup:
  147. if (dwErr != ERROR_SUCCESS)
  148. DebugInformation((L"SpcFlush exit %d\r\n", dwErr));
  149. return(dwErr);
  150. }
  151. DWORD
  152. PurgeMupCache(
  153. LPWSTR ServerName)
  154. {
  155. DWORD dwErr = STATUS_SUCCESS;
  156. NTSTATUS NtStatus;
  157. HANDLE DriverHandle = NULL;
  158. IO_STATUS_BLOCK IoStatusBlock;
  159. OBJECT_ATTRIBUTES objectAttributes;
  160. UNICODE_STRING DfsDriverName;
  161. ULONG Type = 0;
  162. //
  163. // Currently no server name is ever sent.
  164. //
  165. DebugInformation((L"PurgeMupCache(%ws)\r\n", ServerName));
  166. if (ServerName == NULL)
  167. ServerName = L"*";
  168. RtlInitUnicodeString(&DfsDriverName, DFS_DRIVER_NAME);
  169. InitializeObjectAttributes(
  170. &objectAttributes,
  171. &DfsDriverName,
  172. OBJ_CASE_INSENSITIVE,
  173. NULL,
  174. NULL);
  175. NtStatus = NtCreateFile(
  176. &DriverHandle,
  177. SYNCHRONIZE | FILE_WRITE_DATA,
  178. &objectAttributes,
  179. &IoStatusBlock,
  180. NULL,
  181. FILE_ATTRIBUTE_NORMAL,
  182. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  183. FILE_OPEN_IF,
  184. FILE_CREATE_TREE_CONNECTION | FILE_SYNCHRONOUS_IO_NONALERT,
  185. NULL,
  186. 0);
  187. if (!NT_SUCCESS(NtStatus)) {
  188. dwErr = RtlNtStatusToDosError(NtStatus);
  189. DebugInformation((L"NtCreateFile returned 0x%x\r\n", NtStatus));
  190. goto Cleanup;
  191. }
  192. DebugInformation((L"ServerName=[%ws]\r\n", ServerName));
  193. NtStatus = NtFsControlFile(
  194. DriverHandle,
  195. NULL, // Event,
  196. NULL, // ApcRoutine,
  197. NULL, // ApcContext,
  198. &IoStatusBlock,
  199. FSCTL_DFS_CSC_SERVER_ONLINE,
  200. ServerName,
  201. wcslen(ServerName) * sizeof(WCHAR),
  202. NULL,
  203. 0);
  204. NtClose(DriverHandle);
  205. if (!NT_SUCCESS(NtStatus)) {
  206. DebugInformation((L"NtFsControlFile returned 0x%x\r\n", NtStatus));
  207. } else {
  208. CommandSucceeded = TRUE;
  209. }
  210. dwErr = RtlNtStatusToDosError(NtStatus);
  211. Cleanup:
  212. if (dwErr != ERROR_SUCCESS)
  213. DebugInformation((L"PurgeMupCache exit %d\r\n", dwErr));
  214. return(dwErr);
  215. }