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.

301 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. FspDisp.c
  5. Abstract:
  6. This module implements the main dispatch procedure/thread for the Udfs
  7. Fsp
  8. // @@BEGIN_DDKSPLIT
  9. Author:
  10. Dan Lovinger [DanLo] 23-Sep-1996
  11. Revision History:
  12. // @@END_DDKSPLIT
  13. --*/
  14. #include "UdfProcs.h"
  15. //
  16. // The Bug check file id for this module
  17. //
  18. #define BugCheckFileId (UDFS_BUG_CHECK_FSPDISP)
  19. //
  20. // The local debug trace level
  21. //
  22. #define Dbg (UDFS_DEBUG_LEVEL_FSPDISP)
  23. VOID
  24. UdfFspDispatch (
  25. IN PIRP_CONTEXT IrpContext
  26. )
  27. /*++
  28. Routine Description:
  29. This is the main FSP thread routine that is executed to receive
  30. and dispatch IRP requests. Each FSP thread begins its execution here.
  31. There is one thread created at system initialization time and subsequent
  32. threads created as needed.
  33. Arguments:
  34. IrpContext - IrpContext for a request to process.
  35. Return Value:
  36. None
  37. --*/
  38. {
  39. THREAD_CONTEXT ThreadContext;
  40. NTSTATUS Status;
  41. PIRP Irp = IrpContext->Irp;
  42. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
  43. PVOLUME_DEVICE_OBJECT VolDo = NULL;
  44. //
  45. // If this request has an associated volume device object, remember it.
  46. //
  47. if (IrpSp->FileObject != NULL) {
  48. VolDo = CONTAINING_RECORD( IrpSp->DeviceObject,
  49. VOLUME_DEVICE_OBJECT,
  50. DeviceObject );
  51. }
  52. //
  53. // Now case on the function code. For each major function code,
  54. // either call the appropriate worker routine. This routine that
  55. // we call is responsible for completing the IRP, and not us.
  56. // That way the routine can complete the IRP and then continue
  57. // post processing as required. For example, a read can be
  58. // satisfied right away and then read can be done.
  59. //
  60. // We'll do all of the work within an exception handler that
  61. // will be invoked if ever some underlying operation gets into
  62. // trouble.
  63. //
  64. while (TRUE) {
  65. //
  66. // Set all the flags indicating we are in the Fsp.
  67. //
  68. SetFlag( IrpContext->Flags, IRP_CONTEXT_FSP_FLAGS );
  69. FsRtlEnterFileSystem();
  70. UdfSetThreadContext( IrpContext, &ThreadContext );
  71. while (TRUE) {
  72. try {
  73. //
  74. // Reinitialize for the next try at completing this
  75. // request.
  76. //
  77. Status =
  78. IrpContext->ExceptionStatus = STATUS_SUCCESS;
  79. //
  80. // Initialize the Io status field in the Irp.
  81. //
  82. Irp->IoStatus.Status = STATUS_SUCCESS;
  83. Irp->IoStatus.Information = 0;
  84. //
  85. // Case on the major irp code.
  86. //
  87. switch (IrpContext->MajorFunction) {
  88. case IRP_MJ_CLEANUP :
  89. Status = UdfCommonCleanup( IrpContext, Irp );
  90. break;
  91. case IRP_MJ_CLOSE :
  92. //
  93. // Closes should never be posted.
  94. //
  95. ASSERT( FALSE );
  96. break;
  97. case IRP_MJ_CREATE :
  98. Status = UdfCommonCreate( IrpContext, Irp );
  99. break;
  100. case IRP_MJ_DEVICE_CONTROL :
  101. Status = UdfCommonDevControl( IrpContext, Irp );
  102. break;
  103. case IRP_MJ_DIRECTORY_CONTROL :
  104. Status = UdfCommonDirControl( IrpContext, Irp );
  105. break;
  106. case IRP_MJ_FILE_SYSTEM_CONTROL :
  107. Status = UdfCommonFsControl( IrpContext, Irp );
  108. break;
  109. case IRP_MJ_LOCK_CONTROL :
  110. Status = UdfCommonLockControl( IrpContext, Irp );
  111. break;
  112. case IRP_MJ_PNP :
  113. ASSERT( FALSE );
  114. Status = UdfCommonPnp( IrpContext, Irp );
  115. break;
  116. case IRP_MJ_QUERY_INFORMATION :
  117. Status = UdfCommonQueryInfo( IrpContext, Irp );
  118. break;
  119. case IRP_MJ_QUERY_VOLUME_INFORMATION :
  120. Status = UdfCommonQueryVolInfo( IrpContext, Irp );
  121. break;
  122. case IRP_MJ_READ :
  123. Status = UdfCommonRead( IrpContext, Irp );
  124. break;
  125. case IRP_MJ_WRITE :
  126. Status = UdfCommonWrite( IrpContext, Irp );
  127. break;
  128. case IRP_MJ_SET_INFORMATION :
  129. Status = UdfCommonSetInfo( IrpContext, Irp );
  130. break;
  131. default :
  132. Status = STATUS_INVALID_DEVICE_REQUEST;
  133. UdfCompleteRequest( IrpContext, Irp, Status );
  134. }
  135. } except( UdfExceptionFilter( IrpContext, GetExceptionInformation() )) {
  136. Status = UdfProcessException( IrpContext, Irp, GetExceptionCode() );
  137. }
  138. //
  139. // Break out of the loop if we didn't get CANT_WAIT.
  140. //
  141. if (Status != STATUS_CANT_WAIT) { break; }
  142. //
  143. // We are retrying this request. Cleanup the IrpContext for the retry.
  144. //
  145. SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING );
  146. UdfCleanupIrpContext( IrpContext, FALSE );
  147. }
  148. FsRtlExitFileSystem();
  149. //
  150. // If there are any entries on this volume's overflow queue, service
  151. // them.
  152. //
  153. if (VolDo != NULL) {
  154. KIRQL SavedIrql;
  155. PVOID Entry = NULL;
  156. //
  157. // We have a volume device object so see if there is any work
  158. // left to do in its overflow queue.
  159. //
  160. KeAcquireSpinLock( &VolDo->OverflowQueueSpinLock, &SavedIrql );
  161. if (VolDo->OverflowQueueCount > 0) {
  162. //
  163. // There is overflow work to do in this volume so we'll
  164. // decrement the Overflow count, dequeue the IRP, and release
  165. // the Event
  166. //
  167. VolDo->OverflowQueueCount -= 1;
  168. Entry = RemoveHeadList( &VolDo->OverflowQueue );
  169. }
  170. KeReleaseSpinLock( &VolDo->OverflowQueueSpinLock, SavedIrql );
  171. //
  172. // There wasn't an entry, break out of the loop and return to
  173. // the Ex Worker thread.
  174. //
  175. if (Entry == NULL) { break; }
  176. //
  177. // Extract the IrpContext , Irp, set wait to TRUE, and loop.
  178. //
  179. IrpContext = CONTAINING_RECORD( Entry,
  180. IRP_CONTEXT,
  181. WorkQueueItem.List );
  182. Irp = IrpContext->Irp;
  183. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  184. continue;
  185. }
  186. break;
  187. }
  188. //
  189. // Decrement the PostedRequestCount if there was a volume device object.
  190. //
  191. if (VolDo) {
  192. InterlockedDecrement( &VolDo->PostedRequestCount );
  193. }
  194. return;
  195. }