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.

293 lines
12 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:
  15. //
  16. // Functions:
  17. //
  18. //--------------------------------------------------------------------------
  19. #ifndef _DFS_FSCTRL_
  20. #define _DFS_FSCTRL_
  21. #ifndef IOCTL_DFS_BASE
  22. # include <dfsfsctl.h>
  23. #endif //IOCTL_DFS_BASE
  24. //+----------------------------------------------------------------------------
  25. //
  26. // Macro: IS_DFS_CTL_CODE
  27. //
  28. // Synopsis: Determines whether a fsctrl code is a Dfs fsctrl code.
  29. //
  30. // Arguments: [c] -- The control code to test
  31. //
  32. // Returns: TRUE if c is a Dfs fsctrl code, FALSE if its not.
  33. //
  34. //-----------------------------------------------------------------------------
  35. #define IS_DFS_CTL_CODE(c) \
  36. (((c) & CTL_CODE(0xFF, 0,0,0)) == CTL_CODE(FSCTL_DFS_BASE, 0,0,0))
  37. //+----------------------------------------------------------------------------
  38. //
  39. // Macro: UNICODESTRING_IS_VALID
  40. //
  41. // Synopsis: Determines whether a passed-in UNICODE_STRING is good
  42. //
  43. // Returns: TRUE if is good, FALSE if not
  44. //
  45. //-----------------------------------------------------------------------------
  46. #define UNICODESTRING_IS_VALID(ustr,start,len) \
  47. ( \
  48. ((ustr).Length <= (len)) && \
  49. ((PCHAR)(ustr).Buffer >= (PCHAR)(start)) && \
  50. ((PCHAR)(ustr).Buffer <= (PCHAR)(start) + ((len) - (ustr).Length)) \
  51. )
  52. //+----------------------------------------------------------------------------
  53. //
  54. // Macro: POINTER_IN_BUFFER
  55. //
  56. // Synopsis: Determines whether a pointer lies within a buffer
  57. //
  58. // Returns: TRUE if is good, FALSE if not
  59. //
  60. //-----------------------------------------------------------------------------
  61. #define POINTER_IN_BUFFER(ptr,size,buf,len) \
  62. (((PCHAR)(ptr) >= (PCHAR)(buf)) && (((PCHAR)(ptr) + (size)) <= ((PCHAR)(buf) + len)))
  63. //+----------------------------------------------------------------------------
  64. //
  65. // Macro: OFFSET_TO_POINTER
  66. //
  67. // Synopsis: Certain fsctls (mainly those issued by the srvsvc) communicate
  68. // via buffers that contain "pointers" which are really offsets
  69. // from the beginning of the buffer. This macro fixes up the
  70. // offsets to real pointers
  71. //
  72. // Arguments: [field] -- The field to fix up.
  73. // [buffer] -- The beginning of the buffer.
  74. //
  75. // Returns: Nothing
  76. //
  77. //-----------------------------------------------------------------------------
  78. #define OFFSET_TO_POINTER(field, buffer) \
  79. ( ((PCHAR)field) += ((ULONG_PTR)buffer) )
  80. //+----------------------------------------------------------------------------
  81. //
  82. // Macro: POINTER_IS_VALID
  83. //
  84. // Synopsis: Determine whether a pointer is within a certain range.
  85. //
  86. // Arguments: [val] -- The pointer to check
  87. // [start] -- The start of the buffer
  88. // [len] -- The length of the buffer
  89. //
  90. // Returns: TRUE if is good, FALSE if not
  91. //
  92. //-----------------------------------------------------------------------------
  93. #define POINTER_IS_VALID(val,start,len) \
  94. ( (PCHAR)(val) > (PCHAR)(start) && \
  95. (PCHAR)(val) < ((PCHAR)(start) + (len)) )
  96. //+----------------------------------------------------------------------------
  97. //
  98. // Macro: ALIGNMENT_IS_VALID
  99. //
  100. // Synopsis: Determine whether a pointer is aligned correctly
  101. //
  102. // Arguments: [val] -- The pointer to check
  103. // [type] -- The type of object to pointer can point to
  104. //
  105. // Returns: TRUE if is good, FALSE if not
  106. //
  107. //-----------------------------------------------------------------------------
  108. #define ALIGNMENT_IS_VALID(val, type) \
  109. ( ((ULONG_PTR)(val) & (sizeof(type)-1)) == 0 )
  110. //+----------------------------------------------------------------------------
  111. //
  112. // Function: DFS_DUPLICATE_STRING
  113. //
  114. // Synopsis: Macro to create a UNICODE_STRING from an LPWSTR. The buffer
  115. // for the UNICODE_STRING is allocated using ExAllocatePoolWithTag.
  116. //
  117. // Useful for duplicating strings received in fsctls from the
  118. // server.
  119. //
  120. // Arguments: [ustr] -- Destination UNICODE_STRING
  121. // [pwsz] -- Source LPWSTR
  122. // [status] -- If pool allocation fails, or the string would be too
  123. // large, this will be set to STATUS_INSUFFICIENT_RESOURCES
  124. //
  125. // Returns: Nothing. Check the status parameter to see if the operation
  126. // succeeded.
  127. //
  128. //-----------------------------------------------------------------------------
  129. #define DFS_DUPLICATE_STRING(ustr,pwsz,status) \
  130. { \
  131. ULONG Len = wcslen(pwsz) * sizeof(WCHAR); \
  132. \
  133. if ((Len + sizeof(WCHAR)) <= MAXUSHORT) { \
  134. ustr.Length = (USHORT)Len; \
  135. ustr.MaximumLength = ustr.Length + sizeof(WCHAR); \
  136. ustr.Buffer = ExAllocatePoolWithTag(PagedPool, ustr.MaximumLength,' sfD'); \
  137. if (ustr.Buffer != NULL) { \
  138. RtlCopyMemory( ustr.Buffer, pwsz, ustr.MaximumLength ); \
  139. status = STATUS_SUCCESS; \
  140. } else { \
  141. status = STATUS_INSUFFICIENT_RESOURCES; \
  142. } \
  143. } else { \
  144. status = STATUS_INSUFFICIENT_RESOURCES; \
  145. } \
  146. }
  147. //+---------------------------------------------------------------------------
  148. //
  149. // Macro: STD_FSCTRL_PROLOGUE, public
  150. //
  151. // Synopsis: Do the standard stuff associated with any fsctrl implementation
  152. // which needs to run in the FSP. This assumes a standard set
  153. // of parameters for the calling function, as below:
  154. //
  155. // DfsMyownFsctrl(
  156. // IN PIRP Irp,
  157. // [maybe] IN PVOID InputBuffer,
  158. // IN ULONG InputBufferLength,
  159. // [maybe] IN PVOID OutputBuffer,
  160. // IN ULONG OutputBufferLength
  161. // );
  162. //
  163. // Arguments: [szName] -- Name of the function for debug trace messages
  164. // [fExpInp] -- TRUE if it takes an input buffer
  165. // [fExpOutp] -- TRUE if it takes an output buffer
  166. //
  167. // Returns: None
  168. //
  169. // Notes: The macros CHECK_BUFFER_TRUE and CHECK_BUFFER_FALSE are
  170. // necessary for the generation of STD_FSCTRL_PROLOGUE and
  171. // are not intended to be used directly.
  172. //
  173. //
  174. //----------------------------------------------------------------------------
  175. #define CHK_BUFFER_FALSE(szName, inout) ;
  176. #define CHK_BUFFER_TRUE(szName, inout) \
  177. if (!ARGUMENT_PRESENT(inout##Buffer) || (inout##BufferLength == 0)) {\
  178. DebugTrace(0, Dbg, #szName ": Bad buffer\n", 0); \
  179. DfsCompleteRequest( Irp, STATUS_INVALID_PARAMETER ); \
  180. return STATUS_INVALID_PARAMETER; \
  181. }
  182. #define STD_FSCTRL_PROLOGUE(szName, fExpInp, fExpOutp) { \
  183. ASSERT((ARGUMENT_PRESENT(Irp))); \
  184. CHK_BUFFER_##fExpInp(szName, Input) \
  185. CHK_BUFFER_##fExpOutp(szName, Output) \
  186. DebugTrace(+1, Dbg, #szName ": Entered\n", 0); \
  187. }
  188. //+---------------------------------------------------------------------------
  189. //
  190. // Macro: RETURN_BUFFER_SIZE, public
  191. //
  192. // Synopsis: Return conventional errors when the output of an fsctrl
  193. // function is larger than the user buffer. This assumes a
  194. // standard set of parameters for the calling function, as
  195. // below:
  196. //
  197. // DfsMyownFsctrl(
  198. // IN PIRP Irp,
  199. // [maybe] IN PVOID InputBuffer,
  200. // [maybe] IN ULONG InputBufferLength,
  201. // IN PVOID OutputBuffer,
  202. // IN ULONG OutputBufferLength
  203. // );
  204. //
  205. // Arguments: [x] -- The required size of the output buffer
  206. // [Status] -- The status to be returned from the fsctrl.
  207. //
  208. // Returns: Sets Status to STATUS_BUFFER_TOO_SMALL or
  209. // STATUS_BUFFER_OVERFLOW. The convention we use is that if
  210. // the OutputBuffer is at least sizeof(ULONG) big, then we stuff
  211. // the needed size in OutputBuffer and return
  212. // STATUS_BUFFER_OVERFLOW, which is a warning code. If the
  213. // OutputBuffer isn't big enough for that, we return
  214. // STATUS_BUFFER_TOO_SMALL.
  215. //
  216. // Notes: Requires that the function declare "OutputBufferLength",
  217. // "OutputBuffer", and "Irp". Irp->IoStatus.Information will
  218. // be set to the return size.
  219. //
  220. //----------------------------------------------------------------------------
  221. #define RETURN_BUFFER_SIZE(x, Status) \
  222. if ((OutputBufferLength) < sizeof(ULONG)) { \
  223. Status = STATUS_BUFFER_TOO_SMALL; \
  224. } else { \
  225. Status = STATUS_BUFFER_OVERFLOW; \
  226. *((PULONG) OutputBuffer) = x; \
  227. Irp->IoStatus.Information = sizeof(ULONG); \
  228. }
  229. //
  230. // Internal Distributed file system control operations.
  231. //
  232. #define FSCTL_DFS_DBG_BREAK CTL_CODE(FSCTL_DFS_BASE, 2045, METHOD_BUFFERED, FILE_WRITE_DATA)
  233. #define FSCTL_DFS_DBG_FLAGS CTL_CODE(FSCTL_DFS_BASE, 2046, METHOD_BUFFERED, FILE_WRITE_DATA)
  234. #define FSCTL_DFS_INTERNAL_READ_MEM CTL_CODE(FSCTL_DFS_BASE, 2047, METHOD_BUFFERED, FILE_READ_DATA)
  235. #define FSCTL_DFS_SET_PKT_ENTRY_TIMEOUT CTL_CODE(FSCTL_DFS_BASE, 2048, METHOD_BUFFERED, FILE_READ_DATA)
  236. #define FSCTL_DFS_INTERNAL_READSTRUCT CTL_CODE(FSCTL_DFS_BASE, 2049, METHOD_BUFFERED, FILE_READ_DATA)
  237. //
  238. // Control structure for FSCTL_DFS_INTERNAL_READSTRUCT (input)
  239. //
  240. typedef struct _FILE_DFS_READ_STRUCT_PARAM {
  241. ULONG_PTR StructKey; // key (ptr) to desired structure
  242. CSHORT TypeCode; // expected type code (or 0)
  243. CSHORT ByteCount; // expected size
  244. } FILE_DFS_READ_STRUCT_PARAM, *PFILE_DFS_READ_STRUCT_PARAM;
  245. //
  246. // Control structure for FSCTL_DFS_INTERNAL_READ_MEM (input)
  247. //
  248. typedef struct _FILE_DFS_READ_MEM {
  249. ULONG_PTR Address;
  250. ULONG Length;
  251. } FILE_DFS_READ_MEM, *PFILE_DFS_READ_MEM;
  252. BOOLEAN
  253. DfspStringInBuffer(LPWSTR pwszString, PVOID Buffer, ULONG BufferLen);
  254. #endif // _DFS_FSCTRL_