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.

272 lines
6.6 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: DSDATA.C
  4. //
  5. // Contents:
  6. // This module declares the global data used by the Dsfs file system.
  7. //
  8. // Functions:
  9. //
  10. // History: 12 Nov 1991 AlanW Created from CDFS souce.
  11. //-----------------------------------------------------------------------------
  12. #include "dfsprocs.h"
  13. //
  14. // The debug trace level
  15. //
  16. #define Dbg (DEBUG_TRACE_CATCH_EXCEPTIONS)
  17. // DfsBugCheck
  18. // DfsExceptionFilter
  19. // DfsProcessException
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text ( PAGE, DfsBugCheck )
  22. #pragma alloc_text ( PAGE, DfsExceptionFilter )
  23. #pragma alloc_text ( PAGE, DfsProcessException )
  24. //
  25. // The following rountine cannot be paged because it raises the IRQL to
  26. // complete IRPs.
  27. //
  28. //
  29. // DfsCompleteRequest_Real
  30. //
  31. #endif // ALLOC_PRAGMA
  32. //
  33. // The global FSD data record
  34. //
  35. DFS_DATA DfsData;
  36. //
  37. // The global event logging level
  38. //
  39. ULONG DfsEventLog = 0;
  40. #if DBG
  41. //+---------------------------------------------------------------------------
  42. // Function: DfsDebugTracePrint, public
  43. //
  44. // Synopsis: Produce a DFS debug trace printout
  45. //
  46. // Arguments: [x] -- DbgPrint format string
  47. // [y] -- optional argument to DbgPrint
  48. //
  49. // Returns: None
  50. //
  51. //----------------------------------------------------------------------------
  52. LONG DfsDebugTraceLevel = 0x00000001;
  53. LONG DfsDebugTraceIndent = 0;
  54. VOID
  55. DfsDebugTracePrint(PCHAR x, PVOID y)
  56. {
  57. int i;
  58. DbgPrint("%08X:",PsGetCurrentThread());
  59. if (DfsDebugTraceIndent < 0)
  60. DfsDebugTraceIndent = 0;
  61. for (i = 0; i+5 < DfsDebugTraceIndent; i += 5) {
  62. DbgPrint(" ");
  63. }
  64. for ( ; i < DfsDebugTraceIndent; i += 1) {
  65. DbgPrint(" ");
  66. }
  67. DbgPrint(x,y);
  68. }
  69. #endif // DBG
  70. //+---------------------------------------------------------------------------
  71. // Function: DfsBugCheck, public
  72. //
  73. // Synopsis: Call KeBugCheck with DFS' constant
  74. //
  75. // Arguments: [pszmsg] -- message (DBG=1 only)
  76. // [pszfile] -- filename (DBG=1 only)
  77. // [line] -- line number (DBG=1 only)
  78. //
  79. // Returns: None
  80. //
  81. //----------------------------------------------------------------------------
  82. #if DBG
  83. VOID DfsBugCheck(CHAR *pszmsg, CHAR *pszfile, ULONG line)
  84. {
  85. PVOID CallersAddress, CallersCaller;
  86. RtlGetCallersAddress(&CallersAddress, &CallersCaller);
  87. DbgPrint("\nDFS: BugCheck in %s, line %u (%s)\n", pszfile, line, pszmsg);
  88. KeBugCheckEx(DFS_FILE_SYSTEM, (ULONG_PTR)CallersAddress, (ULONG_PTR)pszmsg, (ULONG_PTR)pszfile, line);
  89. }
  90. #else // DBG
  91. VOID DfsBugCheck(VOID)
  92. {
  93. PVOID CallersAddress, CallersCaller;
  94. RtlGetCallersAddress(&CallersAddress, &CallersCaller);
  95. KeBugCheckEx(DFS_FILE_SYSTEM, (ULONG_PTR)CallersAddress, (ULONG_PTR)CallersCaller, 0, 0);
  96. }
  97. #endif // DBG
  98. //+----------------------------------------------------------------------------
  99. //
  100. // Function: FillDebugException
  101. //
  102. // Synopsis: Captures the exception record into variables that we can
  103. // look at.
  104. //
  105. // Arguments: [pep] -- Pointer to exception record.
  106. //
  107. // Returns: Nothing
  108. //
  109. //-----------------------------------------------------------------------------
  110. #define CEXCEPTION_STACK 8
  111. PEXCEPTION_RECORD DfsExceptionRecord;
  112. PCONTEXT DfsExceptionContext;
  113. ULONG DfsExceptionStack[CEXCEPTION_STACK];
  114. VOID
  115. FillDebugException(
  116. PEXCEPTION_POINTERS pep)
  117. {
  118. if(pep != NULL) {
  119. DfsExceptionRecord = pep->ExceptionRecord;
  120. DfsExceptionContext = pep->ContextRecord;
  121. }
  122. }
  123. //+-------------------------------------------------------------------
  124. //
  125. // Function: DfsExceptionFilter
  126. //
  127. // Synopsis: Decide if we should or should not handle an exception status
  128. // that is being raised.
  129. //
  130. // Arguments: [ExceptionCode] -- Supplies the exception code to being checked.
  131. // [ExceptionPointers] -- Supplies the struct to fill with exception pointers
  132. //
  133. // Returns: ULONG - returns EXCEPTION_EXECUTE_HANDLER or BugChecks
  134. //
  135. //--------------------------------------------------------------------
  136. LONG
  137. DfsExceptionFilter (
  138. IN NTSTATUS ExceptionCode,
  139. IN PEXCEPTION_POINTERS ExceptionPointers OPTIONAL
  140. ) {
  141. DebugTrace(
  142. 0, DEBUG_TRACE_UNWIND, "DfsExceptionFilter %lx\n", ULongToPtr( ExceptionCode ));
  143. FillDebugException( ExceptionPointers );
  144. ASSERT(ExceptionCode != STATUS_ACCESS_VIOLATION);
  145. ASSERTMSG(
  146. "DfsExceptionFilter entered\n",
  147. !(DfsDebugTraceLevel & DEBUG_TRACE_UNWIND));
  148. if (!FsRtlIsNtstatusExpected( ExceptionCode )) {
  149. BugCheck( "DfsExceptionFilter: Unexpected exception" );
  150. }
  151. return EXCEPTION_EXECUTE_HANDLER;
  152. }
  153. //+-------------------------------------------------------------------
  154. //
  155. // Function: DfsProcessException, public
  156. //
  157. // Synopsis: This routine processes an exception. It either completes
  158. // the request with the saved exception status or it sends
  159. // the request off to the Fsp.
  160. //
  161. // Arguments: [Irp] -- Supplies the IRP being processed
  162. // [ExceptionCode] -- normalized exception status being handled
  163. //
  164. // Returns: NTSTATUS - Returns the results of either posting the Irp or the
  165. // saved completion status.
  166. //
  167. //--------------------------------------------------------------------
  168. NTSTATUS
  169. DfsProcessException (
  170. IN PIRP Irp,
  171. IN NTSTATUS ExceptionCode
  172. )
  173. {
  174. NTSTATUS Status;
  175. DebugTrace(0, Dbg, "DfsProcessException\n", 0);
  176. //
  177. // We got an error, so zero out the information field before
  178. // completing the request if this was an input operation.
  179. // Otherwise IopCompleteRequest will try to copy to the user's buffer.
  180. //
  181. if (FlagOn(Irp->Flags, IRP_INPUT_OPERATION)) {
  182. Irp->IoStatus.Information = 0;
  183. }
  184. Status = ExceptionCode;
  185. DfsCompleteRequest( Irp, Status );
  186. return Status;
  187. }
  188. //+-------------------------------------------------------------------
  189. //
  190. // Function: DfsCompleteRequest, public
  191. //
  192. // Synopsis: This routine completes a Irp
  193. //
  194. // Arguments: [Irp] - Supplies the Irp being processed
  195. // [Status] - Supplies the status to complete the Irp with
  196. //
  197. // Returns: None.
  198. //
  199. //--------------------------------------------------------------------
  200. VOID
  201. DfsCompleteRequest_Real (
  202. IN PIRP Irp OPTIONAL,
  203. IN NTSTATUS Status
  204. ) {
  205. KIRQL PreviousIrql;
  206. //
  207. // If we have an Irp then complete the irp.
  208. //
  209. if (Irp != NULL) {
  210. Irp->IoStatus.Status = Status;
  211. IoCompleteRequest( Irp, IO_DISK_INCREMENT );
  212. }
  213. return;
  214. }