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.

191 lines
4.8 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 <dfsstr.h>
  20. #include <dfsmrshl.h>
  21. #include <marshal.hxx>
  22. #include <lmdfs.h>
  23. #include <dfspriv.h>
  24. #include <dfsm.hxx>
  25. #include <recon.hxx>
  26. #include <rpc.h>
  27. #include "struct.hxx"
  28. #include "ftsup.hxx"
  29. #include "stdsup.hxx"
  30. #include "rootsup.hxx"
  31. WCHAR wszEverything[] = L"*";
  32. DWORD
  33. PktFlush(
  34. LPWSTR EntryPath)
  35. {
  36. DWORD dwErr = STATUS_SUCCESS;
  37. NTSTATUS NtStatus;
  38. HANDLE DriverHandle = NULL;
  39. IO_STATUS_BLOCK IoStatusBlock;
  40. OBJECT_ATTRIBUTES objectAttributes;
  41. UNICODE_STRING DfsDriverName;
  42. ULONG Type = 0;
  43. if (fSwDebug)
  44. MyPrintf(L"PktFlush(%ws)\r\n", EntryPath);
  45. if (EntryPath == NULL)
  46. EntryPath = wszEverything;
  47. MyPrintf(L"EntryPath=[%ws]\r\n", EntryPath);
  48. RtlInitUnicodeString(&DfsDriverName, DFS_DRIVER_NAME);
  49. InitializeObjectAttributes(
  50. &objectAttributes,
  51. &DfsDriverName,
  52. OBJ_CASE_INSENSITIVE,
  53. NULL,
  54. NULL);
  55. NtStatus = NtCreateFile(
  56. &DriverHandle,
  57. SYNCHRONIZE | FILE_WRITE_DATA,
  58. &objectAttributes,
  59. &IoStatusBlock,
  60. NULL,
  61. FILE_ATTRIBUTE_NORMAL,
  62. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  63. FILE_OPEN_IF,
  64. FILE_CREATE_TREE_CONNECTION | FILE_SYNCHRONOUS_IO_NONALERT,
  65. NULL,
  66. 0);
  67. if (!NT_SUCCESS(NtStatus)) {
  68. dwErr = RtlNtStatusToDosError(NtStatus);
  69. if (fSwDebug)
  70. MyPrintf(L"NtCreateFile returned 0x%x\r\n", NtStatus);
  71. goto Cleanup;
  72. }
  73. NtStatus = NtFsControlFile(
  74. DriverHandle,
  75. NULL, // Event,
  76. NULL, // ApcRoutine,
  77. NULL, // ApcContext,
  78. &IoStatusBlock,
  79. FSCTL_DFS_PKT_FLUSH_CACHE,
  80. EntryPath,
  81. wcslen(EntryPath) * sizeof(WCHAR),
  82. NULL,
  83. 0);
  84. NtClose(DriverHandle);
  85. if (!NT_SUCCESS(NtStatus)) {
  86. if (fSwDebug)
  87. MyPrintf(L"NtFsControlFile returned 0x%x\r\n", NtStatus);
  88. }
  89. dwErr = RtlNtStatusToDosError(NtStatus);
  90. Cleanup:
  91. if (fSwDebug && dwErr != ERROR_SUCCESS)
  92. MyPrintf(L"PktFlush exit %d\r\n", dwErr);
  93. return(dwErr);
  94. }
  95. DWORD
  96. SpcFlush(
  97. LPWSTR EntryPath)
  98. {
  99. DWORD dwErr = STATUS_SUCCESS;
  100. NTSTATUS NtStatus;
  101. HANDLE DriverHandle = NULL;
  102. IO_STATUS_BLOCK IoStatusBlock;
  103. OBJECT_ATTRIBUTES objectAttributes;
  104. UNICODE_STRING DfsDriverName;
  105. ULONG Type = 0;
  106. if (fSwDebug)
  107. MyPrintf(L"SpcFlush(%ws)\r\n", EntryPath);
  108. if (EntryPath == NULL)
  109. EntryPath = wszEverything;
  110. RtlInitUnicodeString(&DfsDriverName, DFS_DRIVER_NAME);
  111. InitializeObjectAttributes(
  112. &objectAttributes,
  113. &DfsDriverName,
  114. OBJ_CASE_INSENSITIVE,
  115. NULL,
  116. NULL);
  117. NtStatus = NtCreateFile(
  118. &DriverHandle,
  119. SYNCHRONIZE | FILE_WRITE_DATA,
  120. &objectAttributes,
  121. &IoStatusBlock,
  122. NULL,
  123. FILE_ATTRIBUTE_NORMAL,
  124. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  125. FILE_OPEN_IF,
  126. FILE_CREATE_TREE_CONNECTION | FILE_SYNCHRONOUS_IO_NONALERT,
  127. NULL,
  128. 0);
  129. if (!NT_SUCCESS(NtStatus)) {
  130. dwErr = RtlNtStatusToDosError(NtStatus);
  131. if (fSwDebug)
  132. MyPrintf(L"NtCreateFile returned 0x%x\r\n", NtStatus);
  133. goto Cleanup;
  134. }
  135. MyPrintf(L"EntryPath=[%ws]\r\n", EntryPath);
  136. NtStatus = NtFsControlFile(
  137. DriverHandle,
  138. NULL, // Event,
  139. NULL, // ApcRoutine,
  140. NULL, // ApcContext,
  141. &IoStatusBlock,
  142. FSCTL_DFS_PKT_FLUSH_SPC_CACHE,
  143. EntryPath,
  144. wcslen(EntryPath) * sizeof(WCHAR),
  145. NULL,
  146. 0);
  147. NtClose(DriverHandle);
  148. if (!NT_SUCCESS(NtStatus)) {
  149. if (fSwDebug)
  150. MyPrintf(L"NtFsControlFile returned 0x%x\r\n", NtStatus);
  151. }
  152. dwErr = RtlNtStatusToDosError(NtStatus);
  153. Cleanup:
  154. if (fSwDebug && dwErr != ERROR_SUCCESS)
  155. MyPrintf(L"PktFlush exit %d\r\n", dwErr);
  156. return(dwErr);
  157. }