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.

283 lines
6.6 KiB

  1. /*
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. forkio.h
  5. Abstract:
  6. This file defines the fork I/O prototypes which are callable at DISPATCH
  7. level.
  8. Author:
  9. Jameel Hyder (microsoft!jameelh)
  10. Revision History:
  11. 15 Jan 1993 Initial Version
  12. Notes: Tab stop: 4
  13. --*/
  14. #ifndef _FORKIO_
  15. #define _FORKIO_
  16. #define AFP_DELALLOC_SIGNATURE 0x15263748
  17. typedef struct _DelayedAlloc
  18. {
  19. #if DBG
  20. LIST_ENTRY Linkage;
  21. DWORD Signature;
  22. PIRP pIrp;
  23. DWORD State;
  24. #endif
  25. WORK_ITEM WorkItem;
  26. PSDA pSda;
  27. PREQUEST pRequest;
  28. LARGE_INTEGER Offset;
  29. DWORD BufSize;
  30. POPENFORKENTRY pOpenForkEntry;
  31. PMDL pMdl;
  32. DWORD Flags;
  33. } DELAYEDALLOC, *PDELAYEDALLOC;
  34. #define AFP_CACHEMDL_DEADSESSION 0x1
  35. #define AFP_CACHEMDL_ALLOC_ERROR 0x2
  36. #define AFP_DBG_MDL_INIT 0x00000001
  37. #define AFP_DBG_MDL_REQUESTED 0x00000002
  38. #define AFP_DBG_MDL_IN_USE 0x00000004
  39. #define AFP_DBG_MDL_RETURN_IN_PROGRESS 0x00000008
  40. #define AFP_DBG_MDL_RETURN_COMPLETED 0x00000010
  41. #define AFP_DBG_MDL_PROC_QUEUED 0x00000020
  42. #define AFP_DBG_MDL_PROC_IN_PROGRESS 0x00000040
  43. #define AFP_DBG_WRITE_MDL 0x10000000
  44. #define AFP_DBG_READ_MDL 0x40000000
  45. #define AFP_DBG_MDL_END 0x80000000
  46. #if DBG
  47. #define AFP_DBG_SET_DELALLOC_STATE(_pDelA, _flag) (_pDelA->State |= _flag)
  48. #define AFP_DBG_SET_DELALLOC_IRP(_pDelA, _pIrp) (_pDelA->pIrp = (PIRP)_pIrp)
  49. #define AFP_DBG_INC_DELALLOC_BYTECOUNT(_Counter, _ByteCount) \
  50. { \
  51. KIRQL _OldIrql; \
  52. ACQUIRE_SPIN_LOCK(&AfpDebugSpinLock, &_OldIrql); \
  53. _Counter += _ByteCount; \
  54. RELEASE_SPIN_LOCK(&AfpDebugSpinLock, _OldIrql); \
  55. }
  56. #define AFP_DBG_DEC_DELALLOC_BYTECOUNT(_Counter, _ByteCount) \
  57. { \
  58. KIRQL _OldIrql; \
  59. ACQUIRE_SPIN_LOCK(&AfpDebugSpinLock, &_OldIrql); \
  60. _Counter -= _ByteCount; \
  61. RELEASE_SPIN_LOCK(&AfpDebugSpinLock, _OldIrql); \
  62. }
  63. #else
  64. #define AFP_DBG_SET_DELALLOC_STATE(_pDelA, _flag)
  65. #define AFP_DBG_SET_DELALLOC_IRP(_pDelA, _pIrp)
  66. #define AFP_DBG_INC_DELALLOC_BYTECOUNT(_Counter, _ByteCount)
  67. #define AFP_DBG_DEC_DELALLOC_BYTECOUNT(_Counter, _ByteCount)
  68. #endif
  69. extern
  70. AFPSTATUS
  71. AfpIoForkRead(
  72. IN PSDA pSda, // The session requesting read
  73. IN POPENFORKENTRY pOpenForkEntry, // The open fork in question
  74. IN PFORKOFFST pOffset, // Pointer to fork offset
  75. IN LONG ReqCount, // Size of read request
  76. IN BYTE NlMask,
  77. IN BYTE NlChar
  78. );
  79. extern
  80. AFPSTATUS
  81. AfpIoForkWrite(
  82. IN PSDA pSda, // The session requesting read
  83. IN POPENFORKENTRY pOpenForkEntry, // The open fork in question
  84. IN PFORKOFFST pOffset, // Pointer to fork offset
  85. IN LONG ReqCount // Size of read request
  86. );
  87. extern
  88. AFPSTATUS
  89. AfpIoForkLockUnlock(
  90. IN PSDA pSda,
  91. IN PFORKLOCK pForkLock,
  92. IN PFORKOFFST pForkOffset,
  93. IN PFORKSIZE pLockSize,
  94. IN BYTE Func
  95. );
  96. extern
  97. VOID FASTCALL
  98. AfpAllocWriteMdl(
  99. IN PDELAYEDALLOC pDelAlloc
  100. );
  101. extern
  102. NTSTATUS
  103. AfpAllocWriteMdlCompletion(
  104. IN PDEVICE_OBJECT DeviceObject,
  105. IN PIRP pIrp,
  106. IN PVOID Context
  107. );
  108. extern
  109. NTSTATUS FASTCALL
  110. AfpBorrowWriteMdlFromCM(
  111. IN PDELAYEDALLOC pDelAlloc,
  112. OUT PMDL *ppReturnMdl
  113. );
  114. extern
  115. VOID FASTCALL
  116. AfpReturnWriteMdlToCM(
  117. IN PDELAYEDALLOC pDelAlloc
  118. );
  119. extern
  120. NTSTATUS
  121. AfpReturnWriteMdlToCMCompletion(
  122. IN PDEVICE_OBJECT DeviceObject,
  123. IN PIRP pIrp,
  124. IN PVOID Context
  125. );
  126. extern
  127. NTSTATUS FASTCALL
  128. AfpBorrowReadMdlFromCM(
  129. IN PSDA pSda
  130. );
  131. extern
  132. NTSTATUS
  133. AfpBorrowReadMdlFromCMCompletion(
  134. IN PDEVICE_OBJECT DeviceObject,
  135. IN PIRP pIrp,
  136. IN PVOID Context
  137. );
  138. extern
  139. VOID FASTCALL
  140. AfpReturnReadMdlToCM(
  141. IN PDELAYEDALLOC pDelAlloc
  142. );
  143. extern
  144. NTSTATUS
  145. AfpReturnReadMdlToCMCompletion(
  146. IN PDEVICE_OBJECT DeviceObject,
  147. IN PIRP pIrp,
  148. IN PVOID Context
  149. );
  150. extern
  151. PDELAYEDALLOC FASTCALL
  152. AfpAllocDelAlloc(
  153. IN VOID
  154. );
  155. extern
  156. VOID FASTCALL
  157. AfpFreeDelAlloc(
  158. IN PDELAYEDALLOC pDelAlloc
  159. );
  160. // defined in fsp_fork.c, but we will put the prototype here
  161. extern
  162. AFPSTATUS FASTCALL
  163. AfpFspDispReadContinue(
  164. IN PSDA pSda
  165. );
  166. #define FUNC_READ 0x01
  167. #define FUNC_WRITE 0x02
  168. #define FUNC_LOCK 0x03
  169. #define FUNC_UNLOCK 0x04
  170. #define FUNC_NOTIFY 0x05
  171. // if the Write size is below this, it's probably more efficient to avoid going to cache mgr
  172. #define CACHEMGR_WRITE_THRESHOLD 8192
  173. // if the Read size is below this, it's probably more efficient to avoid going to cache mgr
  174. #define CACHEMGR_READ_THRESHOLD 8192
  175. #ifdef FORKIO_LOCALS
  176. // The following structure is used as a context in the Irp. The completion
  177. // routines uses this to handle responding to the original request.
  178. #if DBG
  179. #define CTX_SIGNATURE *(DWORD *)"FCTX"
  180. #define VALID_CTX(pCmplCtxt) (((pCmplCtxt) != NULL) && \
  181. ((pCmplCtxt)->Signature == CTX_SIGNATURE))
  182. #else
  183. #define VALID_CTX(pCmplCtxt) ((pCmplCtxt) != NULL)
  184. #endif
  185. typedef struct _CompletionContext
  186. {
  187. #if DBG
  188. DWORD Signature;
  189. #endif
  190. PSDA cc_pSda; // The session context (valid except unlock)
  191. PFORKLOCK cc_pForkLock; // Valid only during a LOCK
  192. AFPSTATUS cc_SavedStatus; // Used by READ
  193. LONG cc_Offst; // Offset of Write request
  194. LONG cc_ReqCount; // The request count for read/write
  195. BYTE cc_Func; // READ/WRITE/LOCK/UNLOCK/NOTIFY
  196. BYTE cc_NlMask; // For read only
  197. BYTE cc_NlChar; // For read only
  198. } CMPLCTXT, *PCMPLCTXT;
  199. #if DBG
  200. #define afpInitializeCmplCtxt(pCtxt, Func, SavedStatus, pSda, pForkLock, ReqCount, Offst) \
  201. (pCtxt)->Signature = CTX_SIGNATURE; \
  202. (pCtxt)->cc_Func = Func; \
  203. (pCtxt)->cc_pSda = pSda; \
  204. (pCtxt)->cc_pForkLock = pForkLock; \
  205. (pCtxt)->cc_SavedStatus = SavedStatus; \
  206. (pCtxt)->cc_ReqCount= ReqCount; \
  207. (pCtxt)->cc_Offst = Offst;
  208. #else
  209. #define afpInitializeCmplCtxt(pCtxt, Func, SavedStatus, pSda, pForkLock, ReqCount, Offst) \
  210. (pCtxt)->cc_Func = Func; \
  211. (pCtxt)->cc_pSda = pSda; \
  212. (pCtxt)->cc_pForkLock = pForkLock; \
  213. (pCtxt)->cc_SavedStatus = SavedStatus; \
  214. (pCtxt)->cc_ReqCount= ReqCount; \
  215. (pCtxt)->cc_Offst = Offst;
  216. #endif
  217. extern
  218. PCMPLCTXT
  219. AfpAllocCmplCtxtBuf(
  220. IN PSDA pSda
  221. );
  222. VOID
  223. AfpFreeCmplCtxtBuf(
  224. IN PCMPLCTXT pCmplCtxt
  225. );
  226. #endif // FORKIO_LOCALS
  227. #endif // _FORKIO_
  228.