2 * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3 * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
14 * this list of conditions and the following disclaimer in the
16 * and/or other materials provided with the distribution.
17 * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18 * nor the names of their contributors may be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission from Kernel Drivers, LLC and Your File System, Inc.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include "AFSCommon.h"
43 AFSCachedRead( IN PDEVICE_OBJECT DeviceObject,
45 IN LARGE_INTEGER StartingByte,
48 UNREFERENCED_PARAMETER(DeviceObject);
49 NTSTATUS ntStatus = STATUS_SUCCESS;
50 IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
51 PFILE_OBJECT pFileObject = pIrpSp->FileObject;
52 BOOLEAN bSynchronousIo = BooleanFlagOn( pFileObject->Flags, FO_SYNCHRONOUS_IO);
53 VOID *pSystemBuffer = NULL;
54 ULONG ulCurrentIO = 0, ulTotalLen = ByteCount;
55 PMDL pCurrentMdl = Irp->MdlAddress;
56 LARGE_INTEGER liCurrentOffset;
61 Irp->IoStatus.Information = 0;
63 liCurrentOffset.QuadPart = StartingByte.QuadPart;
65 while( ulTotalLen > 0)
68 ntStatus = STATUS_SUCCESS;
70 if( pCurrentMdl != NULL)
73 ASSERT( pCurrentMdl != NULL);
75 pSystemBuffer = MmGetSystemAddressForMdlSafe( pCurrentMdl,
78 ulCurrentIO = MmGetMdlByteCount( pCurrentMdl);
80 if( ulCurrentIO > ulTotalLen)
82 ulCurrentIO = ulTotalLen;
88 pSystemBuffer = AFSLockSystemBuffer( Irp,
91 ulCurrentIO = ulTotalLen;
94 if( pSystemBuffer == NULL)
97 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
98 AFS_TRACE_LEVEL_ERROR,
99 "AFSCachedRead (%p) Failed to lock system buffer\n",
102 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
108 if( !CcCopyRead( pFileObject,
117 // Failed to process request.
120 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
121 AFS_TRACE_LEVEL_ERROR,
122 "AFSCachedRead (%p) Failed CcCopyRead() %wZ @ %0I64X Status %08lX\n",
124 &pFileObject->FileName,
125 liCurrentOffset.QuadPart,
126 Irp->IoStatus.Status);
128 try_return( ntStatus = Irp->IoStatus.Status);
131 __except( EXCEPTION_EXECUTE_HANDLER)
133 ntStatus = GetExceptionCode();
135 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
136 AFS_TRACE_LEVEL_ERROR,
137 "AFSCachedRead (%p) CcCopyRead() Threw exception %wZ @ %0I64X Status %08lX\n",
139 &pFileObject->FileName,
140 liCurrentOffset.QuadPart,
144 if( !NT_SUCCESS( ntStatus))
147 try_return( ntStatus);
150 if( ulTotalLen <= ulCurrentIO)
155 liCurrentOffset.QuadPart += ulCurrentIO;
157 ulTotalLen -= ulCurrentIO;
159 pCurrentMdl = pCurrentMdl->Next;
164 if( NT_SUCCESS( ntStatus))
167 Irp->IoStatus.Information = ByteCount;
170 // Update the CBO if this is a sync read
176 pFileObject->CurrentByteOffset.QuadPart = StartingByte.QuadPart + ByteCount;
180 AFSCompleteRequest( Irp,
189 AFSNonCachedRead( IN PDEVICE_OBJECT DeviceObject,
191 IN LARGE_INTEGER StartingByte)
193 NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
194 IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
195 PFILE_OBJECT pFileObject = pIrpSp->FileObject;
196 AFSFcb *pFcb = (AFSFcb *)pFileObject->FsContext;
197 AFSCcb *pCcb = (AFSCcb *)pFileObject->FsContext2;
198 VOID *pSystemBuffer = NULL;
199 BOOLEAN bPagingIo = BooleanFlagOn( Irp->Flags, IRP_PAGING_IO);
200 BOOLEAN bLocked = FALSE;
201 AFSGatherIo *pGatherIo = NULL;
202 AFSIoRun *pIoRuns = NULL;
203 AFSIoRun stIoRuns[AFS_MAX_STACK_IO_RUNS];
204 ULONG extentsCount = 0, runCount = 0;
205 AFSExtent *pStartExtent = NULL;
206 AFSExtent *pIgnoreExtent = NULL;
207 BOOLEAN bCompleteIrp = TRUE;
208 ULONG ulReadByteCount;
210 AFSDeviceExt *pDevExt = (AFSDeviceExt *)DeviceObject->DeviceExtension;
211 LARGE_INTEGER liCurrentTime, liLastRequestTime;
212 AFSDeviceExt *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
213 PFILE_OBJECT pCacheFileObject = NULL;
218 ulByteCount = pIrpSp->Parameters.Read.Length;
220 if (ulByteCount > pDevExt->Specific.RDR.MaxIo.QuadPart)
223 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
224 AFS_TRACE_LEVEL_ERROR,
225 "AFSNonCachedRead (%p) Request larger than MaxIO %I64X\n",
227 pDevExt->Specific.RDR.MaxIo.QuadPart);
229 try_return( ntStatus = STATUS_UNSUCCESSFUL);
232 pSystemBuffer = AFSLockSystemBuffer( Irp,
235 if( pSystemBuffer == NULL)
238 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
239 AFS_TRACE_LEVEL_ERROR,
240 "AFSNonCachedRead (%p) Failed to map system buffer\n",
243 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
246 if( StartingByte.QuadPart + ulByteCount > pFcb->Header.FileSize.QuadPart)
248 ULONG zeroCount = (ULONG) (StartingByte.QuadPart + ulByteCount - pFcb->Header.FileSize.QuadPart);
249 ulReadByteCount = (ULONG)(pFcb->Header.FileSize.QuadPart - StartingByte.QuadPart);
255 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
256 AFS_TRACE_LEVEL_VERBOSE,
257 "AFSNonCachedRead (%p) Zeroing to EOF zero byte length %08lX\n",
261 RtlZeroMemory( ((PCHAR)pSystemBuffer) + ulReadByteCount, zeroCount);
265 ulReadByteCount = ulByteCount;
269 // Provoke a get of the extents - if we need to.
274 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
275 AFS_TRACE_LEVEL_VERBOSE,
276 "AFSNonCachedRead Requesting extents for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
277 pFcb->ObjectInformation->FileId.Cell,
278 pFcb->ObjectInformation->FileId.Volume,
279 pFcb->ObjectInformation->FileId.Vnode,
280 pFcb->ObjectInformation->FileId.Unique,
281 StartingByte.QuadPart,
284 ntStatus = AFSRequestExtentsAsync( pFcb,
289 if (!NT_SUCCESS(ntStatus))
292 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
293 AFS_TRACE_LEVEL_ERROR,
294 "AFSNonCachedRead (%p) Failed to request extents Status %08lX\n",
298 try_return( ntStatus);
301 KeQueryTickCount( &liLastRequestTime);
306 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
307 AFS_TRACE_LEVEL_VERBOSE,
308 "AFSNonCachedRead Acquiring Fcb extents lock %p SHARED %08lX\n",
309 &pFcb->NPFcb->Specific.File.ExtentsResource,
310 PsGetCurrentThread());
312 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource, TRUE );
316 pIgnoreExtent = NULL;
318 if( AFSDoExtentsMapRegion( pFcb,
327 KeClearEvent( &pFcb->NPFcb->Specific.File.ExtentsRequestComplete);
329 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
330 AFS_TRACE_LEVEL_VERBOSE,
331 "AFSNonCachedRead Releasing Fcb extents lock %p SHARED %08lX\n",
332 &pFcb->NPFcb->Specific.File.ExtentsResource,
333 PsGetCurrentThread());
335 AFSReleaseResource( &pFcb->NPFcb->Specific.File.ExtentsResource );
339 // We will re-request the extents after 10 seconds of waiting for them
342 KeQueryTickCount( &liCurrentTime);
344 if( liCurrentTime.QuadPart - liLastRequestTime.QuadPart >= pControlDevExt->Specific.Control.ExtentRequestTimeCount.QuadPart)
347 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
348 AFS_TRACE_LEVEL_VERBOSE,
349 "AFSNonCachedRead Requesting extents, again, for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
350 pFcb->ObjectInformation->FileId.Cell,
351 pFcb->ObjectInformation->FileId.Volume,
352 pFcb->ObjectInformation->FileId.Vnode,
353 pFcb->ObjectInformation->FileId.Unique,
354 StartingByte.QuadPart,
357 ntStatus = AFSRequestExtentsAsync( pFcb,
362 if (!NT_SUCCESS(ntStatus))
365 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
366 AFS_TRACE_LEVEL_ERROR,
367 "AFSNonCachedRead (%p) Failed to request extents Status %08lX\n",
371 try_return( ntStatus);
374 KeQueryTickCount( &liLastRequestTime);
377 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
378 AFS_TRACE_LEVEL_VERBOSE,
379 "AFSNonCachedRead Waiting for extents for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
380 pFcb->ObjectInformation->FileId.Cell,
381 pFcb->ObjectInformation->FileId.Volume,
382 pFcb->ObjectInformation->FileId.Vnode,
383 pFcb->ObjectInformation->FileId.Unique,
384 StartingByte.QuadPart,
387 ntStatus = AFSWaitForExtentMapping ( pFcb, pCcb);
389 if (!NT_SUCCESS(ntStatus))
392 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
393 AFS_TRACE_LEVEL_ERROR,
394 "AFSNonCachedRead Failed wait for extents for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX Status %08lX\n",
395 pFcb->ObjectInformation->FileId.Cell,
396 pFcb->ObjectInformation->FileId.Volume,
397 pFcb->ObjectInformation->FileId.Vnode,
398 pFcb->ObjectInformation->FileId.Unique,
399 StartingByte.QuadPart,
403 try_return( ntStatus);
408 // At this stage we know that the extents are fully mapped and
409 // that, because we took a reference they won't be unmapped.
410 // Thus the list will not move between the start and end.
413 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
414 AFS_TRACE_LEVEL_VERBOSE,
415 "AFSNonCachedRead Extents mapped for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
416 pFcb->ObjectInformation->FileId.Cell,
417 pFcb->ObjectInformation->FileId.Volume,
418 pFcb->ObjectInformation->FileId.Vnode,
419 pFcb->ObjectInformation->FileId.Unique,
420 StartingByte.QuadPart,
423 ntStatus = AFSGetExtents( pFcb,
430 if (!NT_SUCCESS(ntStatus))
433 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
434 AFS_TRACE_LEVEL_ERROR,
435 "AFSNonCachedRead (%p) Failed to retrieve mapped extents Status %08lX\n",
439 try_return( ntStatus );
442 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
443 AFS_TRACE_LEVEL_VERBOSE,
444 "AFSNonCachedRead (%p) Successfully retrieved map extents count %d run count %d\n",
449 if( BooleanFlagOn( AFSLibControlFlags, AFS_REDIR_LIB_FLAGS_NONPERSISTENT_CACHE))
452 Irp->IoStatus.Information = ulReadByteCount;
454 ntStatus = AFSProcessExtentRun( pSystemBuffer,
460 if (!NT_SUCCESS(ntStatus))
463 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
464 AFS_TRACE_LEVEL_ERROR,
465 "AFSNonCachedRead (%p) Failed to process extent run for non-persistent cache Status %08lX\n",
470 try_return( ntStatus);
474 // Retrieve the cache file object
477 pCacheFileObject = AFSReferenceCacheFileObject();
479 if( pCacheFileObject == NULL)
482 ntStatus = STATUS_DEVICE_NOT_READY;
484 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
485 AFS_TRACE_LEVEL_ERROR,
486 "AFSNonCachedRead Failed to retrieve cache fileobject for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX Status %08lX\n",
487 pFcb->ObjectInformation->FileId.Cell,
488 pFcb->ObjectInformation->FileId.Volume,
489 pFcb->ObjectInformation->FileId.Vnode,
490 pFcb->ObjectInformation->FileId.Unique,
491 StartingByte.QuadPart,
495 try_return( ntStatus);
498 if (runCount > AFS_MAX_STACK_IO_RUNS)
501 pIoRuns = (AFSIoRun*) AFSExAllocatePoolWithTag( PagedPool,
502 runCount * sizeof( AFSIoRun ),
507 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
508 AFS_TRACE_LEVEL_ERROR,
509 "AFSNonCachedRead (%p) Failed to allocate IO run block\n",
512 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES );
521 RtlZeroMemory( pIoRuns, runCount * sizeof( AFSIoRun ));
523 ntStatus = AFSSetupIoRun( IoGetRelatedDeviceObject( pCacheFileObject),
532 if (!NT_SUCCESS(ntStatus))
535 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
536 AFS_TRACE_LEVEL_ERROR,
537 "AFSNonCachedRead (%p) Failed to initialize IO run block Status %08lX\n",
541 try_return( ntStatus );
544 AFSReferenceActiveExtents( pStartExtent,
547 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
548 AFS_TRACE_LEVEL_VERBOSE,
549 "AFSNonCachedRead Releasing Fcb extents lock %p SHARED %08lX\n",
550 &pFcb->NPFcb->Specific.File.ExtentsResource,
551 PsGetCurrentThread());
553 AFSReleaseResource( &pFcb->NPFcb->Specific.File.ExtentsResource );
556 pGatherIo = (AFSGatherIo*) AFSExAllocatePoolWithTag( NonPagedPool,
557 sizeof( AFSGatherIo ),
560 if (NULL == pGatherIo)
563 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
564 AFS_TRACE_LEVEL_ERROR,
565 "AFSNonCachedRead (%p) Failed to allocate IO gather block\n",
568 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
569 AFS_TRACE_LEVEL_VERBOSE,
570 "AFSNonCachedRead Acquiring(2) Fcb extents lock %p SHARED %08lX\n",
571 &pFcb->NPFcb->Specific.File.ExtentsResource,
572 PsGetCurrentThread());
574 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource,
578 AFSDereferenceActiveExtents( pStartExtent,
581 try_return (ntStatus = STATUS_INSUFFICIENT_RESOURCES );
584 RtlZeroMemory( pGatherIo, sizeof( AFSGatherIo ));
587 // Initialize count to 1, that was we won't get an early
588 // completion if the first irp completes before the second is
591 pGatherIo->Count = 1;
592 pGatherIo->Status = STATUS_SUCCESS;
593 pGatherIo->MasterIrp = Irp;
594 pGatherIo->Synchronous = TRUE;
595 pGatherIo->Fcb = pFcb;
596 pGatherIo->CompleteMasterIrp = FALSE;
600 if (pGatherIo->Synchronous)
602 KeInitializeEvent( &pGatherIo->Event, NotificationEvent, FALSE );
606 IoMarkIrpPending( Irp);
610 // Pre-emptively set up the count
613 Irp->IoStatus.Information = ulByteCount;
615 ntStatus = AFSQueueStartIos( pCacheFileObject,
617 IRP_READ_OPERATION | IRP_SYNCHRONOUS_API,
622 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
623 AFS_TRACE_LEVEL_VERBOSE,
624 "AFSNonCachedRead (%p) AFSStartIos completed Status %08lX\n",
628 if( !NT_SUCCESS( ntStatus))
631 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
632 AFS_TRACE_LEVEL_VERBOSE,
633 "AFSNonCachedRead Acquiring(3) Fcb extents lock %p SHARED %08lX\n",
634 &pFcb->NPFcb->Specific.File.ExtentsResource,
635 PsGetCurrentThread());
637 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource,
641 AFSDereferenceActiveExtents( pStartExtent,
644 try_return( ntStatus);
648 // Wait for completion of all IOs we started.
650 (VOID) KeWaitForSingleObject( &pGatherIo->Event,
656 ntStatus = pGatherIo->Status;
658 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
659 AFS_TRACE_LEVEL_VERBOSE,
660 "AFSNonCachedRead (%p) AFSStartIos wait completed Status %08lX\n",
664 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
665 AFS_TRACE_LEVEL_VERBOSE,
666 "AFSNonCachedRead Acquiring(4) Fcb extents lock %p SHARED %08lX\n",
667 &pFcb->NPFcb->Specific.File.ExtentsResource,
668 PsGetCurrentThread());
670 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource,
674 AFSDereferenceActiveExtents( pStartExtent,
677 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
678 AFS_TRACE_LEVEL_VERBOSE,
679 "AFSNonCachedRead Releasing Fcb extents lock %p SHARED %08lX\n",
680 &pFcb->NPFcb->Specific.File.ExtentsResource,
681 PsGetCurrentThread());
683 AFSReleaseResource( &pFcb->NPFcb->Specific.File.ExtentsResource );
687 // The data is there now. Give back the extents now so the service
691 if ( pFcb->Specific.File.ExtentLength > 4096)
694 (VOID) AFSReleaseExtentsWithFlush( pFcb,
701 if( pCacheFileObject != NULL)
703 AFSReleaseCacheFileObject( pCacheFileObject);
706 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
707 AFS_TRACE_LEVEL_VERBOSE,
708 "AFSNonCachedRead (%p) Completed request Status %08lX\n",
712 if (NT_SUCCESS(ntStatus) &&
714 BooleanFlagOn( pFileObject->Flags, FO_SYNCHRONOUS_IO))
717 // Update the CBO if this is a sync, nopaging read
719 pFileObject->CurrentByteOffset.QuadPart = StartingByte.QuadPart + ulByteCount;
725 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
726 AFS_TRACE_LEVEL_VERBOSE,
727 "AFSNonCachedRead Releasing Fcb extents lock %p SHARED %08lX\n",
728 &pFcb->NPFcb->Specific.File.ExtentsResource,
729 PsGetCurrentThread());
731 AFSReleaseResource( &pFcb->NPFcb->Specific.File.ExtentsResource );
736 AFSExFreePoolWithTag(pGatherIo, AFS_GATHER_TAG);
739 if (NULL != pIoRuns && stIoRuns != pIoRuns)
741 AFSExFreePoolWithTag(pIoRuns, AFS_IO_RUN_TAG);
747 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
748 AFS_TRACE_LEVEL_VERBOSE,
749 "AFSNonCachedRead Completing irp %08lX Status %08lX Info %08lX\n",
752 Irp->IoStatus.Information);
754 AFSCompleteRequest( Irp, ntStatus );
762 AFSNonCachedReadDirect( IN PDEVICE_OBJECT DeviceObject,
764 IN LARGE_INTEGER StartingByte)
766 NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
767 IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
768 PFILE_OBJECT pFileObject = pIrpSp->FileObject;
769 AFSFcb *pFcb = (AFSFcb *)pFileObject->FsContext;
770 AFSCcb *pCcb = (AFSCcb *)pFileObject->FsContext2;
771 VOID *pSystemBuffer = NULL;
772 ULONG ulByteCount = 0;
773 ULONG ulReadByteCount = 0;
775 BOOLEAN bNoIntermediateBuffering = BooleanFlagOn( pFileObject->Flags, FO_NO_INTERMEDIATE_BUFFERING);
776 AFSDeviceExt *pDevExt = (AFSDeviceExt *)DeviceObject->DeviceExtension;
777 AFSFileIOCB stFileIORequest;
778 AFSFileIOResultCB stFileIOResult;
779 ULONG ulResultLen = 0;
784 Irp->IoStatus.Information = 0;
786 ulByteCount = pIrpSp->Parameters.Read.Length;
788 if (ulByteCount > pDevExt->Specific.RDR.MaxIo.QuadPart)
791 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
792 AFS_TRACE_LEVEL_ERROR,
793 "AFSNonCachedReadDirect (%p) Request larger than MaxIO %I64X\n",
795 pDevExt->Specific.RDR.MaxIo.QuadPart);
797 try_return( ntStatus = STATUS_UNSUCCESSFUL);
800 pSystemBuffer = AFSLockSystemBuffer( Irp,
803 if( pSystemBuffer == NULL)
806 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
807 AFS_TRACE_LEVEL_ERROR,
808 "AFSNonCachedReadDirect (%p) Failed to map system buffer\n",
811 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
814 if( StartingByte.QuadPart + ulByteCount > pFcb->Header.FileSize.QuadPart)
816 ULONG zeroCount = (ULONG) (StartingByte.QuadPart + ulByteCount - pFcb->Header.FileSize.QuadPart);
817 ulReadByteCount = (ULONG)(pFcb->Header.FileSize.QuadPart - StartingByte.QuadPart);
823 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
824 AFS_TRACE_LEVEL_VERBOSE,
825 "AFSNonCachedReadDirect (%p) Zeroing to EOF zero byte length %08lX\n",
829 RtlZeroMemory( ((PCHAR)pSystemBuffer) + ulReadByteCount, zeroCount);
833 ulReadByteCount = ulByteCount;
837 // Issue the request at the service for processing
840 ulResultLen = sizeof( AFSFileIOResultCB);
842 RtlZeroMemory( &stFileIORequest,
843 sizeof( AFSFileIOCB));
845 RtlZeroMemory( &stFileIOResult,
846 sizeof( AFSFileIOResultCB));
848 stFileIORequest.SystemIOBuffer = pSystemBuffer;
850 stFileIORequest.SystemIOBufferMdl = Irp->MdlAddress;
852 stFileIORequest.IOOffset = StartingByte;
854 stFileIORequest.IOLength = ulReadByteCount;
856 ulFlags = AFS_REQUEST_FLAG_SYNCHRONOUS;
858 if ( bNoIntermediateBuffering)
861 ulFlags |= AFS_REQUEST_FLAG_CACHE_BYPASS;
864 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PROCESS_READ_FILE,
867 &pCcb->DirectoryCB->NameInformation.FileName,
868 &pFcb->ObjectInformation->FileId,
869 pFcb->ObjectInformation->VolumeCB->VolumeInformation.Cell,
870 pFcb->ObjectInformation->VolumeCB->VolumeInformation.CellLength,
872 sizeof( AFSFileIOCB),
876 if( NT_SUCCESS( ntStatus))
879 Irp->IoStatus.Information = (ULONG_PTR)stFileIOResult.Length;
884 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
885 AFS_TRACE_LEVEL_ERROR,
886 "AFSNonCachedReadDirect (%p) Failed to send read to service Status %08lX\n",
893 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
894 AFS_TRACE_LEVEL_VERBOSE,
895 "AFSNonCachedReadDirect (%p) Completed request Status %08lX\n",
899 if (NT_SUCCESS(ntStatus) &&
900 !BooleanFlagOn( Irp->Flags, IRP_PAGING_IO) &&
901 BooleanFlagOn( pFileObject->Flags, FO_SYNCHRONOUS_IO))
904 // Update the CBO if this is a sync, nopaging read
906 pFileObject->CurrentByteOffset.QuadPart = StartingByte.QuadPart + ulByteCount;
909 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
910 AFS_TRACE_LEVEL_VERBOSE,
911 "AFSNonCachedReadDirect Completing irp %08lX Status %08lX Info %08lX\n",
914 Irp->IoStatus.Information);
916 AFSCompleteRequest( Irp, ntStatus );
923 // Function: AFSDispatch
927 // A shim around AFSCommonRead (qv)
930 AFSRead( IN PDEVICE_OBJECT LibDeviceObject,
934 UNREFERENCED_PARAMETER(LibDeviceObject);
935 NTSTATUS ntStatus = STATUS_SUCCESS;
940 ntStatus = AFSCommonRead( AFSRDRDeviceObject, Irp, NULL);
942 __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
945 ntStatus = STATUS_INSUFFICIENT_RESOURCES;
947 AFSDumpTraceFilesFnc();
957 // This function is a slightly widened Dispatch handler for the
958 // AFS Read function. The third parameter is NULL if we were called
959 // at our dispatch point and a process handle if we have been posted.
961 // After doing the obvious (completing MDL writes and so forth)
962 // we then post, or not.
966 // A status is returned for the function
970 AFSCommonRead( IN PDEVICE_OBJECT DeviceObject,
972 IN HANDLE OnBehalfOf)
975 UNREFERENCED_PARAMETER(OnBehalfOf);
976 NTSTATUS ntStatus = STATUS_SUCCESS;
977 AFSDeviceExt *pDeviceExt;
978 IO_STACK_LOCATION *pIrpSp;
981 BOOLEAN bReleaseMain = FALSE;
982 BOOLEAN bReleaseSectionObject = FALSE;
983 BOOLEAN bReleasePaging = FALSE;
984 BOOLEAN bPagingIo = FALSE;
985 BOOLEAN bNonCachedIo = FALSE;
986 BOOLEAN bCompleteIrp = TRUE;
987 PFILE_OBJECT pFileObject = NULL;
988 LARGE_INTEGER liStartingByte;
990 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
992 pIrpSp = IoGetCurrentIrpStackLocation( Irp);
993 pDeviceExt = (AFSDeviceExt *)DeviceObject->DeviceExtension;
998 // Decode the fileobject
1000 pFileObject = pIrpSp->FileObject;
1003 // There is a risk (albeit infinitely small) that the Irp will
1004 // complete before this function exits, then a cleanup and
1005 // close will happen and the FCB will be torn down before we
1006 // get to the try_exit. Pin the file Object which will pin the FCB
1009 ObReferenceObject( pFileObject);
1012 // If we are in shutdown mode then fail the request
1015 if( BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_REDIRECTOR_SHUTDOWN))
1018 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1019 AFS_TRACE_LEVEL_WARNING,
1020 "AFSCommonRead (%p) Open request after shutdown\n",
1023 try_return( ntStatus = STATUS_TOO_LATE);
1026 pFcb = (AFSFcb *)pFileObject->FsContext;
1028 pCcb = (AFSCcb *)pFileObject->FsContext2;
1033 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1034 AFS_TRACE_LEVEL_ERROR,
1035 "AFSCommonRead Attempted read (%p) when pFcb == NULL\n",
1038 try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
1041 bPagingIo = BooleanFlagOn( Irp->Flags, IRP_PAGING_IO);
1042 bNonCachedIo = BooleanFlagOn( Irp->Flags,IRP_NOCACHE);
1044 liStartingByte = pIrpSp->Parameters.Read.ByteOffset;
1045 ulByteCount = pIrpSp->Parameters.Read.Length;
1047 if( pFcb->Header.NodeTypeCode != AFS_IOCTL_FCB &&
1048 pFcb->Header.NodeTypeCode != AFS_FILE_FCB &&
1049 pFcb->Header.NodeTypeCode != AFS_SPECIAL_SHARE_FCB)
1052 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1053 AFS_TRACE_LEVEL_ERROR,
1054 "AFSCommonRead Attempted read (%p) on an invalid node type %08lX\n",
1056 pFcb->Header.NodeTypeCode);
1058 try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
1062 // If this is a read against an IOCtl node then handle it
1063 // in a different pathway
1066 if( pFcb->Header.NodeTypeCode == AFS_IOCTL_FCB)
1069 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1070 AFS_TRACE_LEVEL_VERBOSE,
1071 "AFSCommonRead (%p) Processing file (PIOCTL) Offset %I64X Length %08lX Irp Flags %08lX\n",
1073 liStartingByte.QuadPart,
1077 ntStatus = AFSIOCtlRead( DeviceObject,
1080 try_return( ntStatus);
1082 else if( pFcb->Header.NodeTypeCode == AFS_SPECIAL_SHARE_FCB)
1085 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1086 AFS_TRACE_LEVEL_VERBOSE,
1087 "AFSCommonRead (%p) Processing file (SHARE) Offset %I64X Length %08lX Irp Flags %08lX\n",
1089 liStartingByte.QuadPart,
1093 ntStatus = AFSShareRead( DeviceObject,
1096 try_return( ntStatus);
1100 // No fileobject yet? Bail.
1102 if( !BooleanFlagOn( AFSLibControlFlags, AFS_REDIR_LIB_FLAGS_NONPERSISTENT_CACHE) &&
1103 !BooleanFlagOn( pRDRDevExt->DeviceFlags, AFS_REDIR_INIT_PERFORM_SERVICE_IO) &&
1104 NULL == pDeviceExt->Specific.RDR.CacheFileObject)
1107 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1108 AFS_TRACE_LEVEL_ERROR,
1109 "AFSCommonRead (%p) Request failed due to AFS cache closed\n",
1112 try_return( ntStatus = STATUS_TOO_LATE );
1115 if( pIrpSp->Parameters.Read.Length == 0)
1118 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1119 AFS_TRACE_LEVEL_VERBOSE,
1120 "AFSCommonRead (%p) Request completed due to zero length\n",
1123 try_return( ntStatus);
1126 if ( FlagOn(pIrpSp->MinorFunction, IRP_MN_COMPLETE) )
1129 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1130 AFS_TRACE_LEVEL_VERBOSE,
1131 "AFSCommonRead Acquiring Fcb SectionObject lock %p SHARED %08lX\n",
1132 &pFcb->NPFcb->SectionObjectResource,
1133 PsGetCurrentThread());
1135 AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
1138 bReleaseSectionObject = TRUE;
1140 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1141 AFS_TRACE_LEVEL_VERBOSE,
1142 "AFSCommonRead (%p) IRP_MN_COMPLETE being processed\n",
1145 CcMdlReadComplete(pIrpSp->FileObject, Irp->MdlAddress);
1148 // Mdl is now Deallocated
1151 Irp->MdlAddress = NULL;
1153 try_return( ntStatus = STATUS_SUCCESS );
1157 // If we get a non cached IO for a cached file we should do a purge.
1158 // For now we will just promote to cached
1160 if (NULL != pFileObject->SectionObjectPointer->DataSectionObject && !bPagingIo)
1163 bNonCachedIo = FALSE;
1167 // We acquire the main/paging resource first to synchronize
1168 // against size checks.
1174 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1175 AFS_TRACE_LEVEL_VERBOSE,
1176 "AFSCommonRead Acquiring Fcb PagingIo lock %p SHARED %08lX\n",
1177 &pFcb->NPFcb->PagingResource,
1178 PsGetCurrentThread());
1180 AFSAcquireShared( &pFcb->NPFcb->PagingResource,
1183 bReleasePaging = TRUE;
1185 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1186 AFS_TRACE_LEVEL_VERBOSE,
1187 "AFSCommonRead Acquiring Fcb SectionObject lock %p SHARED %08lX\n",
1188 &pFcb->NPFcb->SectionObjectResource,
1189 PsGetCurrentThread());
1191 AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
1194 bReleaseSectionObject = TRUE;
1200 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1201 AFS_TRACE_LEVEL_VERBOSE,
1202 "AFSCommonRead Acquiring Fcb SectionObject lock %p SHARED %08lX\n",
1203 &pFcb->NPFcb->SectionObjectResource,
1204 PsGetCurrentThread());
1206 AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
1209 bReleaseSectionObject = TRUE;
1212 // Check the BR locks
1215 if( !FsRtlCheckLockForReadAccess( &pFcb->Specific.File.FileLock,
1219 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1220 AFS_TRACE_LEVEL_ERROR,
1221 "AFSCommonRead (%p) Request failed due to lock conflict\n",
1224 try_return( ntStatus = STATUS_FILE_LOCK_CONFLICT);
1228 if( BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_DELETED) ||
1229 BooleanFlagOn( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED))
1232 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1233 AFS_TRACE_LEVEL_ERROR,
1234 "AFSCommonRead (%p) Request failed due to file deleted\n",
1237 try_return( ntStatus = STATUS_FILE_DELETED);
1241 // If the read starts beyond End of File, return EOF.
1244 if( liStartingByte.QuadPart >= pFcb->Header.FileSize.QuadPart)
1247 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1248 AFS_TRACE_LEVEL_VERBOSE,
1249 "AFSCommonRead (%p) Request beyond EOF %I64X\n",
1251 pFcb->Header.FileSize.QuadPart);
1253 try_return( ntStatus = STATUS_END_OF_FILE);
1259 if( liStartingByte.QuadPart + ulByteCount > pFcb->Header.FileSize.QuadPart)
1262 ulByteCount = (ULONG)(pFcb->Header.FileSize.QuadPart - liStartingByte.QuadPart);
1264 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1265 AFS_TRACE_LEVEL_VERBOSE,
1266 "AFSCommonRead (%p) Truncated read request to %08lX\n",
1272 // Is this Fcb valid???
1275 if( BooleanFlagOn( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID))
1278 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1279 AFS_TRACE_LEVEL_ERROR,
1280 "AFSCommonRead (%p) Failing request due to INVALID fcb\n",
1283 Irp->IoStatus.Information = 0;
1285 try_return( ntStatus = STATUS_FILE_DELETED);
1289 // If this is an cached IO
1291 if( (!bPagingIo && !bNonCachedIo))
1294 // This is a top level irp. Init the caching if it has not yet
1295 // been initialzed for this FO
1298 if( pFileObject->PrivateCacheMap == NULL)
1304 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1305 AFS_TRACE_LEVEL_VERBOSE,
1306 "AFSCommonRead Initialize caching on Fcb %p FO %p\n",
1310 CcInitializeCacheMap( pFileObject,
1311 (PCC_FILE_SIZES)&pFcb->Header.AllocationSize,
1313 AFSLibCacheManagerCallbacks,
1316 CcSetReadAheadGranularity( pFileObject,
1317 pDeviceExt->Specific.RDR.MaximumRPCLength);
1319 CcSetDirtyPageThreshold( pFileObject,
1320 AFS_DIRTY_CHUNK_THRESHOLD * pDeviceExt->Specific.RDR.MaximumRPCLength / 4096);
1322 __except( EXCEPTION_EXECUTE_HANDLER)
1325 ntStatus = GetExceptionCode();
1327 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1328 AFS_TRACE_LEVEL_ERROR,
1329 "AFSCommonRead (%p) Exception thrown while initializing cache map Status %08lX\n",
1334 if( !NT_SUCCESS( ntStatus))
1337 try_return( ntStatus);
1342 // And if this is MDL operation, deal with it now (yes we
1343 // could post, but we are almost certainly posted
1344 // already and we don't want to grow and SVA for it..)
1347 if( BooleanFlagOn( pIrpSp->MinorFunction, IRP_MN_MDL))
1352 CcMdlRead( pFileObject,
1357 ntStatus = Irp->IoStatus.Status;
1359 __except( EXCEPTION_EXECUTE_HANDLER)
1361 ntStatus = GetExceptionCode();
1363 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1364 AFS_TRACE_LEVEL_ERROR,
1365 "AFSCommonRead (%p) Exception thrown during mdl read Status %08lX\n",
1370 if( !NT_SUCCESS( ntStatus))
1373 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1374 AFS_TRACE_LEVEL_ERROR,
1375 "AFSCommonRead (%p) Failed to process MDL read Status %08lX\n",
1379 try_return( ntStatus);
1383 // Update the CBO if this is a sync read
1386 if( BooleanFlagOn( pFileObject->Flags, FO_SYNCHRONOUS_IO))
1389 pFileObject->CurrentByteOffset.QuadPart = liStartingByte.QuadPart + ulByteCount;
1392 try_return( ntStatus);
1397 // The called request completes the IRP for us.
1400 bCompleteIrp = FALSE;
1406 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1407 AFS_TRACE_LEVEL_VERBOSE,
1408 "AFSCommonRead (%p) Processing CACHED request Offset %I64X Len %08lX\n",
1410 liStartingByte.QuadPart,
1413 ntStatus = AFSCachedRead( DeviceObject, Irp, liStartingByte, ulByteCount);
1421 AFSReleaseResource( &pFcb->NPFcb->PagingResource);
1423 bReleasePaging = FALSE;
1426 if( bReleaseSectionObject)
1429 AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
1431 bReleaseSectionObject = FALSE;
1437 AFSReleaseResource( &pFcb->NPFcb->Resource);
1439 bReleaseMain = FALSE;
1442 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1443 AFS_TRACE_LEVEL_VERBOSE,
1444 "AFSCommonRead (%p) Processing NON-CACHED request Offset %I64X Len %08lX\n",
1446 liStartingByte.QuadPart,
1449 if( BooleanFlagOn( pRDRDevExt->DeviceFlags, AFS_DEVICE_FLAG_DIRECT_SERVICE_IO))
1452 ntStatus = AFSNonCachedReadDirect( DeviceObject, Irp, liStartingByte);
1456 ntStatus = AFSNonCachedRead( DeviceObject, Irp, liStartingByte);
1462 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1463 AFS_TRACE_LEVEL_VERBOSE,
1464 "AFSCommonRead (%p) Process complete Status %08lX\n",
1471 AFSReleaseResource( &pFcb->NPFcb->PagingResource);
1474 if( bReleaseSectionObject)
1477 AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
1483 AFSReleaseResource( &pFcb->NPFcb->Resource);
1489 AFSCompleteRequest( Irp, ntStatus);
1492 ObDereferenceObject( pFileObject);
1499 AFSIOCtlRead( IN PDEVICE_OBJECT DeviceObject,
1503 UNREFERENCED_PARAMETER(DeviceObject);
1504 NTSTATUS ntStatus = STATUS_SUCCESS;
1505 AFSPIOCtlIORequestCB stIORequestCB;
1506 PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1507 AFSFcb *pFcb = NULL;
1508 AFSCcb *pCcb = NULL;
1509 AFSPIOCtlIOResultCB stIOResultCB;
1510 ULONG ulBytesReturned = 0;
1511 AFSFileID stParentFID;
1516 RtlZeroMemory( &stIORequestCB,
1517 sizeof( AFSPIOCtlIORequestCB));
1519 if( pIrpSp->Parameters.Read.Length == 0)
1523 // Nothing to do in this case
1526 try_return( ntStatus);
1529 pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
1531 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1533 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1534 AFS_TRACE_LEVEL_VERBOSE,
1535 "AFSIOCtlRead Acquiring Fcb lock %p SHARED %08lX\n",
1536 &pFcb->NPFcb->Resource,
1537 PsGetCurrentThread());
1539 AFSAcquireShared( &pFcb->NPFcb->Resource,
1543 // Get the parent fid to pass to the cm
1546 RtlZeroMemory( &stParentFID,
1547 sizeof( AFSFileID));
1549 if( BooleanFlagOn( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
1553 // The parent directory FID of the node
1556 stParentFID = pFcb->ObjectInformation->ParentFileId;
1560 // Set the control block up
1563 stIORequestCB.RequestId = pCcb->RequestID;
1565 if( pFcb->ObjectInformation->VolumeCB != NULL)
1567 stIORequestCB.RootId = pFcb->ObjectInformation->VolumeCB->ObjectInformation.FileId;
1571 // Lock down the buffer
1574 stIORequestCB.MappedBuffer = AFSMapToService( Irp,
1575 pIrpSp->Parameters.Read.Length);
1577 if( stIORequestCB.MappedBuffer == NULL)
1580 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1583 stIORequestCB.BufferLength = pIrpSp->Parameters.Read.Length;
1585 stIOResultCB.BytesProcessed = 0;
1587 ulBytesReturned = sizeof( AFSPIOCtlIOResultCB);
1590 // Issue the request to the service
1593 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PIOCTL_READ,
1594 AFS_REQUEST_FLAG_SYNCHRONOUS,
1600 (void *)&stIORequestCB,
1601 sizeof( AFSPIOCtlIORequestCB),
1605 if( !NT_SUCCESS( ntStatus))
1608 try_return( ntStatus);
1612 // Update the length read
1615 Irp->IoStatus.Information = stIOResultCB.BytesProcessed;
1619 if( stIORequestCB.MappedBuffer != NULL)
1622 AFSUnmapServiceMappedBuffer( stIORequestCB.MappedBuffer,
1629 AFSReleaseResource( &pFcb->NPFcb->Resource);
1637 AFSShareRead( IN PDEVICE_OBJECT DeviceObject,
1641 UNREFERENCED_PARAMETER(DeviceObject);
1642 NTSTATUS ntStatus = STATUS_SUCCESS;
1643 PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1644 AFSFcb *pFcb = NULL;
1645 AFSCcb *pCcb = NULL;
1646 ULONG ulBytesReturned = 0;
1647 void *pBuffer = NULL;
1648 AFSPipeIORequestCB stIoRequest;
1653 pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
1655 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1657 AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
1658 AFS_TRACE_LEVEL_VERBOSE,
1659 "AFSShareRead On pipe %wZ Length %08lX\n",
1660 &pCcb->DirectoryCB->NameInformation.FileName,
1661 pIrpSp->Parameters.Read.Length);
1663 if( pIrpSp->Parameters.Read.Length == 0)
1667 // Nothing to do in this case
1670 try_return( ntStatus);
1673 AFSAcquireShared( &pFcb->NPFcb->Resource,
1677 // Retrieve the buffer for the read request
1680 pBuffer = AFSLockSystemBuffer( Irp,
1681 pIrpSp->Parameters.Read.Length);
1683 if( pBuffer == NULL)
1686 AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
1687 AFS_TRACE_LEVEL_ERROR,
1688 "AFSShareRead Failed to map buffer on pipe %wZ\n",
1689 &pCcb->DirectoryCB->NameInformation.FileName);
1691 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1694 RtlZeroMemory( &stIoRequest,
1695 sizeof( AFSPipeIORequestCB));
1697 stIoRequest.RequestId = pCcb->RequestID;
1699 stIoRequest.RootId = pFcb->ObjectInformation->VolumeCB->ObjectInformation.FileId;
1701 stIoRequest.BufferLength = pIrpSp->Parameters.Read.Length;
1703 ulBytesReturned = pIrpSp->Parameters.Read.Length;
1706 // Issue the open request to the service
1709 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PIPE_READ,
1710 AFS_REQUEST_FLAG_SYNCHRONOUS,
1712 &pCcb->DirectoryCB->NameInformation.FileName,
1716 (void *)&stIoRequest,
1717 sizeof( AFSPipeIORequestCB),
1721 if( !NT_SUCCESS( ntStatus) &&
1722 ntStatus != STATUS_BUFFER_OVERFLOW)
1725 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1726 AFS_TRACE_LEVEL_ERROR,
1727 "AFSShareRead (%p) Failed service read Status %08lX\n",
1731 try_return( ntStatus);
1734 AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
1735 AFS_TRACE_LEVEL_VERBOSE,
1736 "AFSShareRead Completed on pipe %wZ Length read %08lX Status %08lX\n",
1737 &pCcb->DirectoryCB->NameInformation.FileName,
1741 Irp->IoStatus.Information = ulBytesReturned;
1748 AFSReleaseResource( &pFcb->NPFcb->Resource);