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.

273 lines
11 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992, Microsoft Corporation.
  4. //
  5. // File: dsfsctl.h
  6. //
  7. // Contents: This module contains the definitions of internally used file
  8. // system controls for the Dfs file system. It also contains
  9. // definitions of macros used in the implementation of Fsctrls.
  10. //
  11. // Public control code and structure declarations are in the
  12. // private header file dfsfsctl.h.
  13. //
  14. // Classes: -none-
  15. //
  16. // Functions: -none-
  17. //
  18. // History: 02 Jan 1992 Alan Whitney (alanw) Created
  19. //
  20. //--------------------------------------------------------------------------
  21. #ifndef _DSFSCTL_
  22. #define _DSFSCTL_
  23. #ifndef IOCTL_DFS_BASE
  24. # include <dfsfsctl.h>
  25. #endif //IOCTL_DFS_BASE
  26. //+----------------------------------------------------------------------------
  27. //
  28. // Macro: IS_DFS_CTL_CODE
  29. //
  30. // Synopsis: Determines whether a fsctrl code is a Dfs fsctrl code.
  31. //
  32. // Arguments: [c] -- The control code to test
  33. //
  34. // Returns: TRUE if c is a Dfs fsctrl code, FALSE if its not.
  35. //
  36. //-----------------------------------------------------------------------------
  37. #define IS_DFS_CTL_CODE(c) \
  38. (((c) & CTL_CODE(0xFF, 0,0,0)) == CTL_CODE(FSCTL_DFS_BASE, 0,0,0))
  39. //+----------------------------------------------------------------------------
  40. //
  41. // Macro: OFFSET_TO_POINTER
  42. //
  43. // Synopsis: Certain fsctls (mainly those issued by the srvsvc) communicate
  44. // via buffers that contain "pointers" which are really offsets
  45. // from the beginning of the buffer. This macro fixes up the
  46. // offsets to real pointers
  47. //
  48. // Arguments: [field] -- The field to fix up.
  49. // [buffer] -- The beginning of the buffer.
  50. //
  51. // Returns: Nothing
  52. //
  53. //-----------------------------------------------------------------------------
  54. #define OFFSET_TO_POINTER(field, buffer) \
  55. ( ((PCHAR)field) += ((ULONG_PTR)buffer) )
  56. //+----------------------------------------------------------------------------
  57. //
  58. // Macro: POINTER_TO_OFFSET
  59. //
  60. // Synopsis: Reverse of OFFSET_TO_POINTER. Turns a pointer into a
  61. // buffer-relative address
  62. //
  63. // Arguments: [field] -- The field to fix up.
  64. // [buffer] -- The beginning of the buffer.
  65. //
  66. // Returns: Nothing
  67. //
  68. //-----------------------------------------------------------------------------
  69. #define POINTER_TO_OFFSET(field, buffer) \
  70. ( ((PCHAR)field) -= ((ULONG_PTR)buffer) )
  71. //+----------------------------------------------------------------------------
  72. //
  73. // Macro: UNICODESTRING_IS_VALID
  74. //
  75. // Synopsis: Determines whether a passed-in UNICODE_STRING is good
  76. //
  77. // Returns: TRUE if is good, FALSE if not
  78. //
  79. //-----------------------------------------------------------------------------
  80. #define UNICODESTRING_IS_VALID(ustr,start,len) \
  81. ( \
  82. ((ustr).Length <= (len)) && \
  83. ((PCHAR)(ustr).Buffer >= (PCHAR)(start)) && \
  84. ((PCHAR)(ustr).Buffer <= (PCHAR)(start) + ((len) - (ustr).Length)) \
  85. )
  86. //+----------------------------------------------------------------------------
  87. //
  88. // Macro: POINTER_IN_BUFFER
  89. //
  90. // Synopsis: Determines whether a pointer lies within a buffer
  91. //
  92. // Returns: TRUE if is good, FALSE if not
  93. //
  94. //-----------------------------------------------------------------------------
  95. #define POINTER_IN_BUFFER(ptr,size,buf,len) \
  96. (((PCHAR)(ptr) >= (PCHAR)(buf)) && (((PCHAR)(ptr) + (size)) <= ((PCHAR)(buf) + len)))
  97. //+----------------------------------------------------------------------------
  98. //
  99. // Function: DFS_DUPLICATE_STRING
  100. //
  101. // Synopsis: Macro to create a UNICODE_STRING from an LPWSTR. The buffer
  102. // for the UNICODE_STRING is allocated using ExAllocatePoolWithTag.
  103. //
  104. // Useful for duplicating strings received in fsctls from the
  105. // server.
  106. //
  107. // Arguments: [ustr] -- Destination UNICODE_STRING
  108. // [pwsz] -- Source LPWSTR
  109. // [status] -- If pool allocation fails, this will be set to
  110. // STATUS_INSUFFICIENT_RESOURCES
  111. //
  112. // Returns: Nothing. Check the status parameter to see if the operation
  113. // succeeded.
  114. //
  115. //-----------------------------------------------------------------------------
  116. #define DFS_DUPLICATE_STRING(ustr,pwsz,status) \
  117. ustr.Length = wcslen(pwsz) * sizeof(WCHAR); \
  118. ustr.MaximumLength = ustr.Length + sizeof(WCHAR); \
  119. ustr.Buffer = ExAllocatePoolWithTag(PagedPool,ustr.MaximumLength,' puM'); \
  120. if (ustr.Buffer != NULL) { \
  121. RtlCopyMemory( ustr.Buffer, pwsz, ustr.MaximumLength ); \
  122. status = STATUS_SUCCESS; \
  123. } else { \
  124. status = STATUS_INSUFFICIENT_RESOURCES; \
  125. }
  126. //+---------------------------------------------------------------------------
  127. //
  128. // Macro: STD_FSCTRL_PROLOGUE, public
  129. //
  130. // Synopsis: Do the standard stuff associated with any fsctrl implementation
  131. // which needs to run in the FSP. This assumes a standard set
  132. // of parameters for the calling function, as below:
  133. //
  134. // DfsMyownFsctrl(
  135. // IN PIRP_CONTEXT IrpContext,
  136. // IN PIRP Irp,
  137. // [maybe] IN PVOID InputBuffer,
  138. // IN ULONG InputBufferLength,
  139. // [maybe] IN PVOID OutputBuffer,
  140. // IN ULONG OutputBufferLength
  141. // );
  142. //
  143. // Arguments: [szName] -- Name of the function for debug trace messages
  144. // [fExpInp] -- TRUE if it takes an input buffer
  145. // [fExpOutp] -- TRUE if it takes an output buffer
  146. // [fInFsp] -- TRUE if the request must be processed from the
  147. // FSP.
  148. //
  149. // Returns: None
  150. //
  151. // Notes: The macros CHECK_BUFFER_TRUE and CHECK_BUFFER_FALSE are
  152. // necessary for the generation of STD_FSCTRL_PROLOGUE and
  153. // are not intended to be used directly.
  154. //
  155. //
  156. //----------------------------------------------------------------------------
  157. #define CHK_BUFFER_FALSE(szName, inout) ;
  158. #define CHK_BUFFER_TRUE(szName, inout) \
  159. if (!ARGUMENT_PRESENT(inout##Buffer) || (inout##BufferLength == 0)) {\
  160. DfsDbgTrace(0, Dbg, #szName ": Bad buffer\n", 0); \
  161. DfsCompleteRequest( IrpContext, Irp, STATUS_INVALID_PARAMETER );\
  162. return STATUS_INVALID_PARAMETER; \
  163. }
  164. #define CHK_INFSP_FALSE(szName)
  165. #define CHK_INFSP_TRUE(szName) \
  166. if ((IrpContext->Flags & IRP_CONTEXT_FLAG_IN_FSD) != 0) { \
  167. DfsDbgTrace(0, Dbg, #szName ": Posting to FSP\n",0); \
  168. status = DfsFsdPostRequest( IrpContext, Irp ); \
  169. return status; \
  170. }
  171. #define STD_FSCTRL_PROLOGUE(szName, fExpInp, fExpOutp, fInFsp) { \
  172. ASSERT(ARGUMENT_PRESENT(IrpContext) && (ARGUMENT_PRESENT(Irp))); \
  173. CHK_BUFFER_##fExpInp(szName, Input) \
  174. CHK_BUFFER_##fExpOutp(szName, Output) \
  175. CHK_INFSP_##fInFsp(szName) \
  176. DfsDbgTrace(+1, Dbg, #szName ": Entered\n", 0); \
  177. }
  178. //+---------------------------------------------------------------------------
  179. //
  180. // Macro: RETURN_BUFFER_SIZE, public
  181. //
  182. // Synopsis: Return conventional errors when the output of an fsctrl
  183. // function is larger than the user buffer. This assumes a
  184. // standard set of parameters for the calling function, as
  185. // below:
  186. //
  187. // DfsMyownFsctrl(
  188. // IN PIRP_CONTEXT IrpContext,
  189. // IN PIRP Irp,
  190. // [maybe] IN PVOID InputBuffer,
  191. // [maybe] IN ULONG InputBufferLength,
  192. // IN PVOID OutputBuffer,
  193. // IN ULONG OutputBufferLength
  194. // );
  195. //
  196. // Arguments: [x] -- The required size of the output buffer
  197. // [Status] -- The status to be returned from the fsctrl.
  198. //
  199. // Returns: Sets Status to STATUS_BUFFER_TOO_SMALL or
  200. // STATUS_BUFFER_OVERFLOW. The convention we use is that if
  201. // the OutputBuffer is at least sizeof(ULONG) big, then we stuff
  202. // the needed size in OutputBuffer and return
  203. // STATUS_BUFFER_OVERFLOW, which is a warning code. If the
  204. // OutputBuffer isn't big enough for that, we return
  205. // STATUS_BUFFER_TOO_SMALL.
  206. //
  207. // Notes: Requires that the function declare "OutputBufferLength",
  208. // "OutputBuffer", and "Irp". Irp->IoStatus.Information will
  209. // be set to the return size.
  210. //
  211. //----------------------------------------------------------------------------
  212. #define RETURN_BUFFER_SIZE(x, Status) \
  213. if ((OutputBufferLength) < sizeof(ULONG)) { \
  214. Status = STATUS_BUFFER_TOO_SMALL; \
  215. } else { \
  216. Status = STATUS_BUFFER_OVERFLOW; \
  217. *((PULONG) OutputBuffer) = x; \
  218. Irp->IoStatus.Information = sizeof(ULONG); \
  219. }
  220. //
  221. // Internal Distributed file system control operations (private, checked versions only)
  222. //
  223. #define FSCTL_DFS_DBG_BREAK CTL_CODE(FSCTL_DFS_BASE, 2045, METHOD_BUFFERED, FILE_WRITE_DATA)
  224. #define FSCTL_DFS_DBG_FLAGS CTL_CODE(FSCTL_DFS_BASE, 2046, METHOD_BUFFERED, FILE_WRITE_DATA)
  225. #define FSCTL_DFS_INTERNAL_READ_MEM CTL_CODE(FSCTL_DFS_BASE, 2047, METHOD_BUFFERED, FILE_READ_DATA)
  226. #define FSCTL_DFS_SET_PKT_ENTRY_TIMEOUT CTL_CODE(FSCTL_DFS_BASE, 2048, METHOD_BUFFERED, FILE_WRITE_DATA)
  227. #define FSCTL_DFS_VERBOSE_FLAGS CTL_CODE(FSCTL_DFS_BASE, 2049, METHOD_BUFFERED, FILE_WRITE_DATA)
  228. #define FSCTL_DFS_EVENTLOG_FLAGS CTL_CODE(FSCTL_DFS_BASE, 2050, METHOD_BUFFERED, FILE_WRITE_DATA)
  229. //
  230. // Control structure for FSCTL_DFS_INTERNAL_READ_MEM (input)
  231. //
  232. typedef struct _FILE_DFS_READ_MEM {
  233. DWORD_PTR Address;
  234. ULONG Length;
  235. } FILE_DFS_READ_MEM, *PFILE_DFS_READ_MEM;
  236. #endif // _DSFSCTL_