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.

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