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.

450 lines
12 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. FsRtlP.h
  5. Abstract:
  6. This module defines private part of the File System Rtl component
  7. Author:
  8. Gary Kimura [GaryKi] 30-Jul-1990
  9. Revision History:
  10. --*/
  11. #ifndef _FSRTLP_
  12. #define _FSRTLP_
  13. #pragma warning(disable:4214) // bit field types other than int
  14. #pragma warning(disable:4201) // nameless struct/union
  15. #pragma warning(disable:4127) // condition expression is constant
  16. #pragma warning(disable:4115) // named type definition in parentheses
  17. #pragma warning(disable:4706) // assignment within conditional expression
  18. #include <ntos.h>
  19. #include <FsRtl.h>
  20. #include <NtDdFt.h>
  21. #include <zwapi.h>
  22. #define FsRtlAllocatePool(PoolType, NumberOfBytes ) \
  23. ExAllocatePoolWithTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  24. NumberOfBytes, \
  25. 'trSF')
  26. #define FsRtlAllocatePoolWithQuota(PoolType, NumberOfBytes ) \
  27. ExAllocatePoolWithQuotaTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  28. NumberOfBytes, \
  29. 'trSF')
  30. #define FsRtlpAllocatePool(a,b) FsRtlAllocatePoolWithTag((a),(b),MODULE_POOL_TAG)
  31. //
  32. // The global FsRtl debug level variable, its values are:
  33. //
  34. // 0x00000000 Always gets printed (used when about to bug check)
  35. //
  36. // 0x00000001 Error conditions
  37. // 0x00000002 Debug hooks
  38. // 0x00000004
  39. // 0x00000008
  40. //
  41. // 0x00000010
  42. // 0x00000020
  43. // 0x00000040
  44. // 0x00000080
  45. //
  46. // 0x00000100
  47. // 0x00000200
  48. // 0x00000400
  49. // 0x00000800
  50. //
  51. // 0x00001000
  52. // 0x00002000
  53. // 0x00004000
  54. // 0x00008000
  55. //
  56. // 0x00010000
  57. // 0x00020000
  58. // 0x00040000
  59. // 0x00080000
  60. //
  61. // 0x00100000
  62. // 0x00200000
  63. // 0x00400000
  64. // 0x00800000
  65. //
  66. // 0x01000000
  67. // 0x02000000
  68. // 0x04000000 NotifyChange routines
  69. // 0x08000000 Oplock routines
  70. //
  71. // 0x10000000 Name routines
  72. // 0x20000000 FileLock routines
  73. // 0x40000000 Vmcb routines
  74. // 0x80000000 Mcb routines
  75. //
  76. //
  77. // Debug trace support
  78. //
  79. #ifdef FSRTLDBG
  80. extern LONG FsRtlDebugTraceLevel;
  81. extern LONG FsRtlDebugTraceIndent;
  82. #define DebugTrace(INDENT,LEVEL,X,Y) { \
  83. LONG _i; \
  84. if (((LEVEL) == 0) || (FsRtlDebugTraceLevel & (LEVEL))) { \
  85. _i = (ULONG)PsGetCurrentThread(); \
  86. DbgPrint("%08lx:",_i); \
  87. if ((INDENT) < 0) { \
  88. FsRtlDebugTraceIndent += (INDENT); \
  89. } \
  90. if (FsRtlDebugTraceIndent < 0) { \
  91. FsRtlDebugTraceIndent = 0; \
  92. } \
  93. for (_i=0; _i<FsRtlDebugTraceIndent; _i+=1) { \
  94. DbgPrint(" "); \
  95. } \
  96. DbgPrint(X,Y); \
  97. if ((INDENT) > 0) { \
  98. FsRtlDebugTraceIndent += (INDENT); \
  99. } \
  100. } \
  101. }
  102. #define DebugDump(STR,LEVEL,PTR) { \
  103. ULONG _i; \
  104. VOID FsRtlDump(); \
  105. if (((LEVEL) == 0) || (FsRtlDebugTraceLevel & (LEVEL))) { \
  106. _i = (ULONG)PsGetCurrentThread(); \
  107. DbgPrint("%08lx:",_i); \
  108. DbgPrint(STR); \
  109. if (PTR != NULL) {FsRtlDump(PTR);} \
  110. DbgBreakPoint(); \
  111. } \
  112. }
  113. #else
  114. #define DebugTrace(INDENT,LEVEL,X,Y) {NOTHING;}
  115. #define DebugDump(STR,LEVEL,PTR) {NOTHING;}
  116. #endif // FSRTLDBG
  117. //
  118. // Miscellaneous support routines
  119. //
  120. VOID
  121. FsRtlInitializeFileLocks (
  122. VOID
  123. );
  124. VOID
  125. FsRtlInitializeLargeMcbs (
  126. VOID
  127. );
  128. VOID
  129. FsRtlInitializeTunnels(
  130. VOID
  131. );
  132. NTSTATUS
  133. FsRtlInitializeWorkerThread (
  134. VOID
  135. );
  136. //
  137. // This macro returns TRUE if a flag in a set of flags is on and FALSE
  138. // otherwise
  139. //
  140. #define FlagOn(Flags,SingleFlag) ((Flags) & (SingleFlag))
  141. #define BooleanFlagOn(Flags,SingleFlag) ((BOOLEAN)(((Flags) & (SingleFlag)) != 0))
  142. #define SetFlag(F,SF) { \
  143. (F) |= (SF); \
  144. }
  145. #define ClearFlag(F,SF) { \
  146. (F) &= ~(SF); \
  147. }
  148. //
  149. // This macro takes a pointer (or ulong) and returns its rounded up word
  150. // value
  151. //
  152. #define WordAlign(Ptr) ( \
  153. ((((ULONG_PTR)(Ptr)) + 1) & -2) \
  154. )
  155. //
  156. // This macro takes a pointer (or ulong) and returns its rounded up longword
  157. // value
  158. //
  159. #define LongAlign(Ptr) ( \
  160. ((((ULONG_PTR)(Ptr)) + 3) & -4) \
  161. )
  162. //
  163. // This macro takes a pointer (or ulong) and returns its rounded up quadword
  164. // value
  165. //
  166. #define QuadAlign(Ptr) ( \
  167. ((((ULONG_PTR)(Ptr)) + 7) & -8) \
  168. )
  169. //
  170. // This macro takes a ulong and returns its value rounded up to a sector
  171. // boundary
  172. //
  173. #define SectorAlign(Ptr) ( \
  174. ((((ULONG_PTR)(Ptr)) + 511) & -512) \
  175. )
  176. //
  177. // This macro takes a number of bytes and returns the number of sectors
  178. // required to contain that many bytes, i.e., it sector aligns and divides
  179. // by the size of a sector.
  180. //
  181. #define SectorsFromBytes(bytes) ( \
  182. ((bytes) + 511) / 512 \
  183. )
  184. //
  185. // This macro takes a number of sectors and returns the number of bytes
  186. // contained in that many sectors.
  187. //
  188. #define BytesFromSectors(sectors) ( \
  189. (sectors) * 512 \
  190. )
  191. //
  192. // The following types and macros are used to help unpack the packed and
  193. // misaligned fields found in the Bios parameter block
  194. //
  195. typedef union _UCHAR1 {
  196. UCHAR Uchar[1];
  197. UCHAR ForceAlignment;
  198. } UCHAR1, *PUCHAR1;
  199. typedef union _UCHAR2 {
  200. UCHAR Uchar[2];
  201. USHORT ForceAlignment;
  202. } UCHAR2, *PUCHAR2;
  203. typedef union _UCHAR4 {
  204. UCHAR Uchar[4];
  205. ULONG ForceAlignment;
  206. } UCHAR4, *PUCHAR4;
  207. //
  208. // This macro copies an unaligned src byte to an aligned dst byte
  209. //
  210. #define CopyUchar1(Dst,Src) { \
  211. *((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
  212. }
  213. //
  214. // This macro copies an unaligned src word to an aligned dst word
  215. //
  216. #define CopyUchar2(Dst,Src) { \
  217. *((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
  218. }
  219. //
  220. // This macro copies an unaligned src longword to an aligned dsr longword
  221. //
  222. #define CopyUchar4(Dst,Src) { \
  223. *((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
  224. }
  225. //
  226. // The following macros are used to establish the semantics needed
  227. // to do a return from within a try-finally clause. As a rule every
  228. // try clause must end with a label call try_exit. For example,
  229. //
  230. // try {
  231. // :
  232. // :
  233. //
  234. // try_exit: NOTHING;
  235. // } finally {
  236. //
  237. // :
  238. // :
  239. // }
  240. //
  241. // Every return statement executed inside of a try clause should use the
  242. // try_return macro. If the compiler fully supports the try-finally construct
  243. // then the macro should be
  244. //
  245. // #define try_return(S) { return(S); }
  246. //
  247. // If the compiler does not support the try-finally construct then the macro
  248. // should be
  249. //
  250. // #define try_return(S) { S; goto try_exit; }
  251. //
  252. #define try_return(S) { S; goto try_exit; }
  253. #define GET_FAST_IO_DISPATCH(DevObj) \
  254. ((DevObj)->DriverObject->FastIoDispatch)
  255. #define GET_FS_FILTER_CALLBACKS(DevObj) \
  256. ((DevObj)->DriverObject->DriverExtension->FsFilterCallbacks)
  257. //
  258. // Macro for validating the FastIo dispatch routines before calling
  259. // them in the FastIo pass through functions.
  260. //
  261. #define VALID_FAST_IO_DISPATCH_HANDLER(FastIoDispatchPtr, FieldName) \
  262. (((FastIoDispatchPtr) != NULL) && \
  263. (((FastIoDispatchPtr)->SizeOfFastIoDispatch) >= \
  264. (FIELD_OFFSET(FAST_IO_DISPATCH, FieldName) + sizeof(VOID *))) && \
  265. ((FastIoDispatchPtr)->FieldName != NULL))
  266. #define VALID_FS_FILTER_CALLBACK_HANDLER(FsFilterCallbackPtr, FieldName) \
  267. (((FsFilterCallbackPtr) != NULL) && \
  268. (((FsFilterCallbackPtr)->SizeOfFsFilterCallbacks) >= \
  269. (FIELD_OFFSET(FS_FILTER_CALLBACKS, FieldName) + sizeof(VOID *))) && \
  270. ((FsFilterCallbackPtr)->FieldName != NULL))
  271. #define FSRTL_FILTER_MEMORY_TAG 'gmSF'
  272. typedef struct _FS_FILTER_COMPLETION_NODE {
  273. PDEVICE_OBJECT DeviceObject;
  274. PFILE_OBJECT FileObject;
  275. PVOID CompletionContext;
  276. PFS_FILTER_COMPLETION_CALLBACK CompletionCallback;
  277. } FS_FILTER_COMPLETION_NODE, *PFS_FILTER_COMPLETION_NODE;
  278. #define FS_FILTER_DEFAULT_STACK_SIZE 15
  279. typedef struct _FS_FILTER_COMPLETION_STACK {
  280. USHORT StackLength;
  281. USHORT NextStackPosition;
  282. PFS_FILTER_COMPLETION_NODE Stack;
  283. FS_FILTER_COMPLETION_NODE DefaultStack[FS_FILTER_DEFAULT_STACK_SIZE];
  284. } FS_FILTER_COMPLETION_STACK, *PFS_FILTER_COMPLETION_STACK;
  285. typedef struct _FS_FILTER_CTRL {
  286. FS_FILTER_CALLBACK_DATA Data;
  287. ULONG Flags;
  288. ULONG Reserved;
  289. FS_FILTER_COMPLETION_STACK CompletionStack;
  290. } FS_FILTER_CTRL, *PFS_FILTER_CTRL;
  291. //
  292. // Flag values for FS_FILTER_CTRL
  293. //
  294. #define FS_FILTER_ALLOCATED_COMPLETION_STACK 0x00000001
  295. #define FS_FILTER_USED_RESERVE_POOL 0x00000002
  296. #define FS_FILTER_CHANGED_DEVICE_STACKS 0x00000004
  297. NTSTATUS
  298. FsFilterInit(
  299. );
  300. NTSTATUS
  301. FsFilterAllocateCompletionStack (
  302. IN PFS_FILTER_CTRL FsFilterCtrl,
  303. IN BOOLEAN CanFail,
  304. OUT PULONG AllocationSize
  305. );
  306. VOID
  307. FsFilterFreeCompletionStack (
  308. IN PFS_FILTER_CTRL FsFilterCtrl
  309. );
  310. NTSTATUS
  311. FsFilterCtrlInit (
  312. IN OUT PFS_FILTER_CTRL FsFilterCtrl,
  313. IN UCHAR Operation,
  314. IN PDEVICE_OBJECT DeviceObject,
  315. IN PDEVICE_OBJECT BaseFsDeviceObject,
  316. IN PFILE_OBJECT FileObject,
  317. IN BOOLEAN CanFail
  318. );
  319. VOID
  320. FsFilterCtrlFree (
  321. IN PFS_FILTER_CTRL FsFilterCtrl
  322. );
  323. #define PUSH_COMPLETION_NODE( completionStack ) \
  324. (((completionStack)->NextStackPosition < (completionStack)->StackLength ) ? \
  325. &(completionStack)->Stack[(completionStack)->NextStackPosition++] : \
  326. (ASSERT( FALSE ), NULL) )
  327. #define POP_COMPLETION_NODE( completionStack ) \
  328. (ASSERT((completionStack)->NextStackPosition > 0), \
  329. ((completionStack)->NextStackPosition--))
  330. #define GET_COMPLETION_NODE( completionStack ) \
  331. (ASSERT((completionStack)->NextStackPosition > 0),\
  332. (&(completionStack)->Stack[(completionStack)->NextStackPosition-1]))
  333. #define FS_FILTER_HAVE_COMPLETIONS( fsFilterCtrl ) \
  334. ((fsFilterCtrl)->CompletionStack.NextStackPosition > 0)
  335. VOID
  336. FsFilterGetCallbacks (
  337. IN UCHAR Operation,
  338. IN PDEVICE_OBJECT DeviceObject,
  339. OUT PFS_FILTER_CALLBACK *PreOperationCallback,
  340. OUT PFS_FILTER_COMPLETION_CALLBACK *PostOperationCallback
  341. );
  342. NTSTATUS
  343. FsFilterPerformCallbacks (
  344. IN PFS_FILTER_CTRL FsFilterCtrl,
  345. IN BOOLEAN AllowFilterToFail,
  346. IN BOOLEAN AllowBaseFsToFail,
  347. OUT BOOLEAN *BaseFsFailedOp
  348. );
  349. VOID
  350. FsFilterPerformCompletionCallbacks(
  351. IN PFS_FILTER_CTRL FsFilterCtrl,
  352. IN NTSTATUS OperationStatus
  353. );
  354. #endif // _FSRTLP_