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.

152 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. io.c
  5. Abstract:
  6. Author:
  7. Thomas J. Dimitri (TommyD) 08-May-1992
  8. Environment:
  9. Kernel Mode - Or whatever is the equivalent on OS/2 and DOS.
  10. Revision History:
  11. --*/
  12. #include "asyncall.h"
  13. // asyncmac.c will define the global parameters.
  14. #include "globals.h"
  15. NTSTATUS
  16. AsyncSetupIrp(
  17. IN PASYNC_FRAME Frame,
  18. IN PIRP irp
  19. )
  20. /*++
  21. This is the routine which intializes the Irp
  22. --*/
  23. {
  24. // PMDL mdl;
  25. PDEVICE_OBJECT deviceObject=Frame->Info->DeviceObject;
  26. PFILE_OBJECT fileObject=Frame->Info->FileObject;
  27. irp->Tail.Overlay.OriginalFileObject = fileObject;
  28. irp->RequestorMode = KernelMode;
  29. irp->PendingReturned = FALSE;
  30. //
  31. // Fill in the service independent parameters in the IRP.
  32. //
  33. irp->UserEvent = NULL;
  34. irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
  35. irp->Overlay.AsynchronousParameters.UserApcContext = NULL;
  36. //
  37. // Now determine whether this device expects to have data buffered to it
  38. // or whether it performs direct I/O. This is based on the DO_BUFFERED_IO
  39. // flag in the device object. If the flag is set, then a system buffer is
  40. // allocated and the caller's data is copied into it. Otherwise, a Memory
  41. // Descriptor List (MDL) is allocated and the caller's buffer is locked
  42. // down using it.
  43. //
  44. if (deviceObject->Flags & DO_BUFFERED_IO) {
  45. //
  46. // The device does not support direct I/O. Allocate a system buffer,
  47. // and copy the caller's data into it. This is done using an
  48. // exception handler that will perform cleanup if the operation
  49. // fails. Note that this is only done if the operation has a non-zero
  50. // length.
  51. //
  52. irp->AssociatedIrp.SystemBuffer = Frame->Frame;
  53. //
  54. // Set the IRP_BUFFERED_IO flag in the IRP so that I/O completion
  55. // will know that this is not a direct I/O operation.
  56. //
  57. irp->Flags = IRP_BUFFERED_IO;
  58. } else if (deviceObject->Flags & DO_DIRECT_IO) {
  59. //
  60. // This is a direct I/O operation. Allocate an MDL and invoke the
  61. // memory management routine to lock the buffer into memory. This
  62. // is done using an exception handler that will perform cleanup if
  63. // the operation fails. Note that no MDL is allocated, nor is any
  64. // memory probed or locked if the length of the request was zero.
  65. //
  66. #if DBG
  67. DbgPrintf(("The DeviceObject is NOT BUFFERED_IO!! IRP FAILURE!!\n"));
  68. DbgBreakPoint();
  69. #endif
  70. } else {
  71. //
  72. // Pass the address of the caller's buffer to the device driver. It
  73. // is now up to the driver to do everything.
  74. //
  75. irp->UserBuffer = Frame->Frame;
  76. }
  77. // For now, if we get this far, it means success!
  78. return(STATUS_SUCCESS);
  79. }
  80. PASYNC_IO_CTX
  81. AsyncAllocateIoCtx(
  82. BOOLEAN AllocateSync,
  83. PVOID Context
  84. )
  85. {
  86. PASYNC_IO_CTX AsyncIoCtx;
  87. AsyncIoCtx = ExAllocateFromNPagedLookasideList(&AsyncIoCtxList);
  88. if (AsyncIoCtx == NULL) {
  89. return (NULL);
  90. }
  91. RtlZeroMemory(AsyncIoCtx, sizeof(ASYNC_IO_CTX));
  92. AsyncIoCtx->Context = Context;
  93. AsyncIoCtx->Sync = AllocateSync;
  94. if (AllocateSync) {
  95. ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
  96. KeInitializeEvent(&AsyncIoCtx->Event,
  97. SynchronizationEvent,
  98. (BOOLEAN)FALSE);
  99. }
  100. return (AsyncIoCtx);
  101. }
  102. VOID
  103. AsyncFreeIoCtx(
  104. PASYNC_IO_CTX AsyncIoCtx
  105. )
  106. {
  107. ExFreeToNPagedLookasideList(&AsyncIoCtxList,
  108. AsyncIoCtx);
  109. }