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 AFSCachedWrite( IN PDEVICE_OBJECT DeviceObject,
45 IN LARGE_INTEGER StartingByte,
47 IN BOOLEAN ForceFlush);
50 AFSNonCachedWrite( IN PDEVICE_OBJECT DeviceObject,
52 IN LARGE_INTEGER StartingByte,
57 AFSExtendingWrite( IN AFSFcb *Fcb,
58 IN PFILE_OBJECT FileObject,
59 IN LONGLONG NewLength);
66 // This is the dispatch handler for the IRP_MJ_WRITE request
70 // A status is returned for the function
73 AFSWrite( IN PDEVICE_OBJECT LibDeviceObject,
77 NTSTATUS ntStatus = STATUS_SUCCESS;
82 ntStatus = AFSCommonWrite( AFSRDRDeviceObject, Irp, NULL);
84 __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
87 ntStatus = STATUS_INSUFFICIENT_RESOURCES;
94 AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
99 NTSTATUS ntStatus = STATUS_SUCCESS;
100 AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)DeviceObject->DeviceExtension;
101 IO_STACK_LOCATION *pIrpSp;
104 AFSNonPagedFcb *pNPFcb = NULL;
105 ULONG ulByteCount = 0;
106 LARGE_INTEGER liStartingByte;
107 PFILE_OBJECT pFileObject;
108 BOOLEAN bPagingIo = FALSE;
109 BOOLEAN bNonCachedIo = FALSE;
110 BOOLEAN bReleaseMain = FALSE;
111 BOOLEAN bReleasePaging = FALSE;
112 BOOLEAN bExtendingWrite = FALSE;
113 BOOLEAN bCompleteIrp = TRUE;
114 BOOLEAN bForceFlush = FALSE;
116 BOOLEAN bMapped = TRUE;
117 HANDLE hCallingUser = OnBehalfOf;
118 ULONG ulExtensionLength = 0;
119 BOOLEAN bRetry = FALSE;
120 ULONGLONG ullProcessId = (ULONGLONG)PsGetCurrentProcessId();
122 pIrpSp = IoGetCurrentIrpStackLocation( Irp);
127 pFileObject = pIrpSp->FileObject;
130 // Extract the fileobject references
133 pFcb = (AFSFcb *)pFileObject->FsContext;
134 pCcb = (AFSCcb *)pFileObject->FsContext2;
136 ObReferenceObject( pFileObject);
141 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
142 AFS_TRACE_LEVEL_ERROR,
143 "AFSCommonWrite Attempted write (%08lX) when pFcb == NULL\n",
146 try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
149 pNPFcb = pFcb->NPFcb;
152 // If we are in shutdown mode then fail the request
155 if( BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_REDIRECTOR_SHUTDOWN))
158 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
159 AFS_TRACE_LEVEL_WARNING,
160 "AFSCommonWrite (%08lX) Open request after shutdown\n",
163 try_return( ntStatus = STATUS_TOO_LATE);
166 liStartingByte = pIrpSp->Parameters.Write.ByteOffset;
167 bPagingIo = BooleanFlagOn( Irp->Flags, IRP_PAGING_IO);
168 bNonCachedIo = BooleanFlagOn( Irp->Flags, IRP_NOCACHE);
169 ulByteCount = pIrpSp->Parameters.Write.Length;
171 if( pFcb->Header.NodeTypeCode != AFS_IOCTL_FCB &&
172 pFcb->Header.NodeTypeCode != AFS_FILE_FCB &&
173 pFcb->Header.NodeTypeCode != AFS_SPECIAL_SHARE_FCB)
176 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
177 AFS_TRACE_LEVEL_ERROR,
178 "AFSCommonWrite Attempted write (%08lX) on an invalid node type %08lX\n",
180 pFcb->Header.NodeTypeCode);
182 try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
186 // If this is a write against an IOCtl node then handle it
187 // in a different pathway
190 if( pFcb->Header.NodeTypeCode == AFS_IOCTL_FCB)
193 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
194 AFS_TRACE_LEVEL_VERBOSE,
195 "AFSCommonWrite (%08lX) Processing file (PIOCTL) Offset %I64X Length %08lX Irp Flags %08lX\n",
197 liStartingByte.QuadPart,
201 ntStatus = AFSIOCtlWrite( DeviceObject,
204 try_return( ntStatus);
206 else if( pFcb->Header.NodeTypeCode == AFS_SPECIAL_SHARE_FCB)
209 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
210 AFS_TRACE_LEVEL_VERBOSE,
211 "AFSCommonWrite (%08lX) Processing file (SHARE) Offset %I64X Length %08lX Irp Flags %08lX\n",
213 liStartingByte.QuadPart,
217 ntStatus = AFSShareWrite( DeviceObject,
220 try_return( ntStatus);
224 // Is the Cache not there yet? Exit.
226 if( !BooleanFlagOn( AFSLibControlFlags, AFS_REDIR_LIB_FLAGS_NONPERSISTENT_CACHE) &&
227 NULL == pDeviceExt->Specific.RDR.CacheFileObject)
230 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
231 AFS_TRACE_LEVEL_ERROR,
232 "AFSCommonWrite (%08lX) Request failed due to AFS cache closed\n",
235 try_return( ntStatus = STATUS_TOO_LATE );
238 if( pFcb->ObjectInformation->VolumeCB != NULL &&
239 BooleanFlagOn( pFcb->ObjectInformation->VolumeCB->VolumeInformation.Characteristics, FILE_READ_ONLY_DEVICE))
242 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
243 AFS_TRACE_LEVEL_ERROR,
244 "AFSCommonWrite (%08lX) Request failed due to read only volume\n",
247 try_return( ntStatus = STATUS_ACCESS_DENIED);
251 // We need to know on whose behalf we have been called (which
252 // we will eventually tell to the server - for non paging
253 // writes). If we were posted then we were told. If this is
254 // the first time we saw the irp then we grab it now.
256 if( NULL == OnBehalfOf )
259 hCallingUser = PsGetCurrentProcessId();
264 hCallingUser = OnBehalfOf;
268 // Check for zero length write
271 if( ulByteCount == 0)
274 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
275 AFS_TRACE_LEVEL_VERBOSE,
276 "AFSCommonWrite (%08lX) Request completed due to zero length\n",
279 try_return( ntStatus);
283 // Is this Fcb valid???
286 if( BooleanFlagOn( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID))
289 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
290 AFS_TRACE_LEVEL_ERROR,
291 "AFSCommonWrite (%08lX) Failing request due to INVALID fcb\n",
294 Irp->IoStatus.Information = 0;
296 try_return( ntStatus = STATUS_FILE_DELETED);
299 if( BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_DELETED) ||
300 BooleanFlagOn( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED))
303 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
304 AFS_TRACE_LEVEL_ERROR,
305 "AFSCommonWrite (%08lX) Request failed due to file deleted\n",
308 try_return( ntStatus = STATUS_FILE_DELETED);
311 if( FlagOn( pIrpSp->MinorFunction, IRP_MN_COMPLETE))
314 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
315 AFS_TRACE_LEVEL_VERBOSE,
316 "AFSCommonWrite (%08lX) IRP_MN_COMPLETE being processed\n",
319 CcMdlWriteComplete(pFileObject, &pIrpSp->Parameters.Write.ByteOffset, Irp->MdlAddress);
322 // Mdl is now Deallocated
325 Irp->MdlAddress = NULL;
327 try_return( ntStatus = STATUS_SUCCESS );
331 // If we get a non cached IO for a cached file we should do a purge.
332 // For now we will just promote to cached
334 if( NULL != pFileObject->SectionObjectPointer->DataSectionObject && !bPagingIo && bNonCachedIo)
336 bNonCachedIo = FALSE;
340 if( (!bPagingIo && !bNonCachedIo))
343 if( pFileObject->PrivateCacheMap == NULL)
349 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
350 AFS_TRACE_LEVEL_VERBOSE,
351 "AFSCommonWrite Initialize caching on Fcb %08lX FileObject %08lX\n",
355 CcInitializeCacheMap( pFileObject,
356 (PCC_FILE_SIZES)&pFcb->Header.AllocationSize,
358 AFSLibCacheManagerCallbacks,
361 CcSetReadAheadGranularity( pFileObject,
362 READ_AHEAD_GRANULARITY);
365 __except( EXCEPTION_EXECUTE_HANDLER)
368 ntStatus = GetExceptionCode();
370 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
371 AFS_TRACE_LEVEL_ERROR,
372 "AFSCommonWrite (%08lX) Exception thrown while initializing cache map Status %08lX\n",
377 if( !NT_SUCCESS( ntStatus))
380 try_return( ntStatus);
385 while (!bNonCachedIo && !CcCanIWrite( pFileObject,
390 static const LONGLONG llWriteDelay = (LONGLONG)-100000;
392 KeDelayExecutionThread(KernelMode, FALSE, (PLARGE_INTEGER)&llWriteDelay);
396 // Save off the PID if this is not a paging IO
400 ( pFcb->Specific.File.ExtentRequestProcessId == 0 ||
401 ( ullProcessId != (ULONGLONG)AFSSysProcess &&
402 pFcb->Specific.File.ExtentRequestProcessId != ullProcessId)))
405 pFcb->Specific.File.ExtentRequestProcessId = ullProcessId;
407 if( ullProcessId == (ULONGLONG)AFSSysProcess)
409 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
410 AFS_TRACE_LEVEL_WARNING,
411 "%s Setting LastWriterExtentProcessId to system process for Fcb %p\n",
418 // We should be ready to go. So first of all ask for the extents
419 // Provoke a get of the extents - if we need to.
423 if( !bPagingIo && !bNonCachedIo)
426 ntStatus = AFSRequestExtentsAsync( pFcb, pCcb, &liStartingByte, ulByteCount);
428 if (!NT_SUCCESS(ntStatus))
431 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
432 AFS_TRACE_LEVEL_ERROR,
433 "AFSCommonWrite (%08lX) Failed to request extents Status %08lX\n",
437 try_return( ntStatus );
443 // If they are not mapped and we are the Lazy Writer then just
446 if (!bMapped && pFcb->Specific.File.LazyWriterThread == PsGetCurrentThread())
449 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
450 AFS_TRACE_LEVEL_VERBOSE,
451 "AFSCommonWrite (%08lX) Failing lazy writer for unmapped request\n",
454 try_return ( ntStatus = STATUS_FILE_LOCK_CONFLICT);
460 // - if Paging then we need to nothing (the precalls will
461 // have acquired the paging resource), for clarity we will collect
462 // the paging resource
463 // - If extending Write then take the fileresource EX (EOF will change, Allocation will only move out)
464 // - Otherwise we collect the file shared, check against extending and
475 bExtendingWrite = (((liStartingByte.QuadPart + ulByteCount) >=
476 pFcb->Header.FileSize.QuadPart) ||
477 (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
478 liStartingByte.HighPart == -1)) ;
484 //ASSERT( NULL != OnBehalfOf || ExIsResourceAcquiredLite( &pNPFcb->Resource ));
486 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
487 AFS_TRACE_LEVEL_VERBOSE,
488 "AFSCommonWrite Acquiring Fcb PagingIo lock %08lX SHARED %08lX\n",
489 &pNPFcb->PagingResource,
490 PsGetCurrentThread());
492 AFSAcquireShared( &pNPFcb->PagingResource,
495 bReleasePaging = TRUE;
498 // We have the correct lock - we cannot have the wrong one
502 else if( bExtendingWrite)
505 // Check for lock inversion
508 ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
510 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
511 AFS_TRACE_LEVEL_VERBOSE,
512 "AFSCommonWrite Acquiring Fcb lock %08lX EXCL %08lX\n",
514 PsGetCurrentThread());
516 AFSAcquireExcl( &pNPFcb->Resource,
519 if (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
520 liStartingByte.HighPart == -1)
522 if (pFcb->Header.ValidDataLength.QuadPart > pFcb->Header.FileSize.QuadPart)
524 liStartingByte = pFcb->Header.ValidDataLength;
528 liStartingByte = pFcb->Header.FileSize;
534 // We have the correct lock - even if we don't end up truncating
540 ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
542 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
543 AFS_TRACE_LEVEL_VERBOSE,
544 "AFSCommonWrite Acquiring Fcb lock %08lX SHARED %08lX\n",
546 PsGetCurrentThread());
548 AFSAcquireShared( &pNPFcb->Resource,
554 // Have things moved? Are we extending? If so, the the lock isn't OK
556 bLockOK = (liStartingByte.QuadPart + ulByteCount) < pFcb->Header.FileSize.QuadPart;
560 AFSReleaseResource( &pNPFcb->Resource);
561 bReleaseMain = FALSE;
568 // Check the BR locks on the file.
572 !FsRtlCheckLockForWriteAccess( &pFcb->Specific.File.FileLock,
576 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
577 AFS_TRACE_LEVEL_ERROR,
578 "AFSCommonWrite (%08lX) Request failed due to lock conflict\n",
581 try_return( ntStatus = STATUS_FILE_LOCK_CONFLICT);
587 ntStatus = AFSExtendingWrite( pFcb, pFileObject, (liStartingByte.QuadPart + ulByteCount));
589 if( !NT_SUCCESS(ntStatus))
592 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
593 AFS_TRACE_LEVEL_ERROR,
594 "AFSCommonWrite (%08lX) Failed extending write request Status %08lX\n",
598 try_return( ntStatus );
603 // Fire off the request as appropriate
605 bCompleteIrp = FALSE;
611 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
612 AFS_TRACE_LEVEL_VERBOSE,
613 "AFSCommonWrite (%08lX) Processing CACHED request Offset %I64X Len %08lX\n",
615 liStartingByte.QuadPart,
618 ntStatus = AFSCachedWrite( DeviceObject, Irp, liStartingByte, ulByteCount, bForceFlush);
624 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
625 AFS_TRACE_LEVEL_VERBOSE,
626 "AFSCommonWrite (%08lX) Processing NON-CACHED request Offset %I64X Len %08lX\n",
628 liStartingByte.QuadPart,
631 ntStatus = AFSNonCachedWrite( DeviceObject, Irp, liStartingByte, ulByteCount);
636 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
637 AFS_TRACE_LEVEL_VERBOSE,
638 "AFSCommonWrite (%08lX) Process complete Status %08lX\n",
642 ObDereferenceObject(pFileObject);
647 AFSReleaseResource( &pNPFcb->Resource);
653 AFSReleaseResource( &pNPFcb->PagingResource);
659 AFSCompleteRequest( Irp,
668 AFSIOCtlWrite( IN PDEVICE_OBJECT DeviceObject,
672 NTSTATUS ntStatus = STATUS_SUCCESS;
673 AFSPIOCtlIORequestCB stIORequestCB;
674 PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
677 AFSPIOCtlIOResultCB stIOResultCB;
678 ULONG ulBytesReturned = 0;
679 AFSFileID stParentFID;
684 RtlZeroMemory( &stIORequestCB,
685 sizeof( AFSPIOCtlIORequestCB));
687 if( pIrpSp->Parameters.Write.Length == 0)
691 // Nothing to do in this case
694 try_return( ntStatus);
697 pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
699 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
701 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
702 AFS_TRACE_LEVEL_VERBOSE,
703 "AFSIOCtlWrite Acquiring Fcb lock %08lX SHARED %08lX\n",
704 &pFcb->NPFcb->Resource,
705 PsGetCurrentThread());
707 AFSAcquireShared( &pFcb->NPFcb->Resource,
711 // Get the parent fid to pass to the cm
714 RtlZeroMemory( &stParentFID,
717 if( pFcb->ObjectInformation->ParentObjectInformation != NULL)
721 // The parent directory FID of the node
724 stParentFID = pFcb->ObjectInformation->ParentObjectInformation->FileId;
728 // Set the control block up
731 stIORequestCB.RequestId = pCcb->RequestID;
733 if( pFcb->ObjectInformation->VolumeCB != NULL)
735 stIORequestCB.RootId = pFcb->ObjectInformation->VolumeCB->ObjectInformation.FileId;
739 // Lock down the buffer
742 stIORequestCB.MappedBuffer = AFSMapToService( Irp,
743 pIrpSp->Parameters.Write.Length);
745 if( stIORequestCB.MappedBuffer == NULL)
748 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
751 stIORequestCB.BufferLength = pIrpSp->Parameters.Write.Length;
753 stIOResultCB.BytesProcessed = 0;
755 ulBytesReturned = sizeof( AFSPIOCtlIOResultCB);
758 // Issue the request to the service
761 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PIOCTL_WRITE,
762 AFS_REQUEST_FLAG_SYNCHRONOUS,
766 (void *)&stIORequestCB,
767 sizeof( AFSPIOCtlIORequestCB),
771 if( !NT_SUCCESS( ntStatus))
774 try_return( ntStatus);
778 // Update the length written
781 Irp->IoStatus.Information = stIOResultCB.BytesProcessed;
785 if( stIORequestCB.MappedBuffer != NULL)
788 AFSUnmapServiceMappedBuffer( stIORequestCB.MappedBuffer,
795 AFSReleaseResource( &pFcb->NPFcb->Resource);
803 // This function is called when we know we have to read from the AFS Cache.
805 // It ensures that we have exents for the entirety of the write and
806 // then pins the extents into memory (meaning that although we may
807 // add we will not remove). Then it creates a scatter gather write
808 // and fires off the IRPs
812 AFSNonCachedWrite( IN PDEVICE_OBJECT DeviceObject,
814 IN LARGE_INTEGER StartingByte,
817 NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
818 VOID *pSystemBuffer = NULL;
819 BOOLEAN bPagingIo = BooleanFlagOn( Irp->Flags, IRP_PAGING_IO);
820 BOOLEAN bLocked = FALSE;
821 BOOLEAN bCompleteIrp = TRUE;
822 BOOLEAN bExtentsMapped = FALSE;
823 AFSGatherIo *pGatherIo = NULL;
824 AFSIoRun *pIoRuns = NULL;
825 AFSIoRun stIoRuns[AFS_MAX_STACK_IO_RUNS];
826 ULONG extentsCount = 0, runCount = 0;
827 AFSExtent *pStartExtent = NULL;
828 AFSExtent *pIgnoreExtent = NULL;
829 IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
830 PFILE_OBJECT pFileObject = pIrpSp->FileObject;
831 AFSFcb *pFcb = (AFSFcb *)pFileObject->FsContext;
832 AFSCcb *pCcb = (AFSCcb *)pFileObject->FsContext2;
833 BOOLEAN bSynchronousFo = BooleanFlagOn( pFileObject->Flags, FO_SYNCHRONOUS_IO);
834 AFSDeviceExt *pDevExt = (AFSDeviceExt *)DeviceObject->DeviceExtension;
835 ULONG ulRequestCount = 0;
836 LARGE_INTEGER liCurrentTime, liLastRequestTime;
837 AFSDeviceExt *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
838 PFILE_OBJECT pCacheFileObject = NULL;
842 Irp->IoStatus.Information = 0;
844 if (ByteCount > pDevExt->Specific.RDR.MaxIo.QuadPart)
847 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
848 AFS_TRACE_LEVEL_ERROR,
849 "AFSNonCachedWrite (%08lX) Request %08lX Actual %08lX larger than MaxIO %I64X\n",
852 pIrpSp->Parameters.Write.Length,
853 pDevExt->Specific.RDR.MaxIo.QuadPart);
855 try_return( ntStatus = STATUS_UNSUCCESSFUL);
859 // Get the mapping for the buffer
861 pSystemBuffer = AFSLockSystemBuffer( Irp,
864 if( pSystemBuffer == NULL)
867 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
868 AFS_TRACE_LEVEL_ERROR,
869 "AFSNonCachedWrite (%08lX) Failed to map system buffer\n",
872 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
877 // Provoke a get of the extents - if we need to.
880 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
881 AFS_TRACE_LEVEL_VERBOSE,
882 "AFSNonCachedWrite Requesting extents for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
883 pFcb->ObjectInformation->FileId.Cell,
884 pFcb->ObjectInformation->FileId.Volume,
885 pFcb->ObjectInformation->FileId.Vnode,
886 pFcb->ObjectInformation->FileId.Unique,
887 StartingByte.QuadPart,
890 ntStatus = AFSRequestExtentsAsync( pFcb,
895 if (!NT_SUCCESS(ntStatus))
898 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
899 AFS_TRACE_LEVEL_ERROR,
900 "AFSNonCachedWrite (%08lX) Failed to request extents Status %08lX\n",
904 try_return( ntStatus);
907 KeQueryTickCount( &liLastRequestTime);
912 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
913 AFS_TRACE_LEVEL_VERBOSE,
914 "AFSNonCachedWrite Acquiring Fcb extents lock %08lX SHARED %08lX\n",
915 &pFcb->NPFcb->Specific.File.ExtentsResource,
916 PsGetCurrentThread());
918 ASSERT( !ExIsResourceAcquiredLite( &pFcb->NPFcb->Specific.File.ExtentsResource ));
920 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource, TRUE );
924 pIgnoreExtent = NULL;
926 if ( AFSDoExtentsMapRegion( pFcb, &StartingByte, ByteCount, &pStartExtent, &pIgnoreExtent ))
931 KeClearEvent( &pFcb->NPFcb->Specific.File.ExtentsRequestComplete );
933 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
934 AFS_TRACE_LEVEL_VERBOSE,
935 "AFSNonCachedWrite Releasing(1) Fcb extents lock %08lX SHARED %08lX\n",
936 &pFcb->NPFcb->Specific.File.ExtentsResource,
937 PsGetCurrentThread());
939 AFSReleaseResource( &pFcb->NPFcb->Specific.File.ExtentsResource );
943 // We will re-request the extents after waiting for them
946 KeQueryTickCount( &liCurrentTime);
948 if( liCurrentTime.QuadPart - liLastRequestTime.QuadPart >= pControlDevExt->Specific.Control.ExtentRequestTimeCount.QuadPart)
951 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
952 AFS_TRACE_LEVEL_VERBOSE,
953 "AFSNonCachedWrite Requesting extents, again, for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
954 pFcb->ObjectInformation->FileId.Cell,
955 pFcb->ObjectInformation->FileId.Volume,
956 pFcb->ObjectInformation->FileId.Vnode,
957 pFcb->ObjectInformation->FileId.Unique,
958 StartingByte.QuadPart,
961 ntStatus = AFSRequestExtentsAsync( pFcb,
966 if (!NT_SUCCESS(ntStatus))
969 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
970 AFS_TRACE_LEVEL_ERROR,
971 "AFSNonCachedWrite (%08lX) Failed to request extents Status %08lX\n",
975 try_return( ntStatus);
978 KeQueryTickCount( &liLastRequestTime);
982 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
983 AFS_TRACE_LEVEL_VERBOSE,
984 "AFSNonCachedWrite Waiting for extents for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
985 pFcb->ObjectInformation->FileId.Cell,
986 pFcb->ObjectInformation->FileId.Volume,
987 pFcb->ObjectInformation->FileId.Vnode,
988 pFcb->ObjectInformation->FileId.Unique,
989 StartingByte.QuadPart,
996 ntStatus = AFSWaitForExtentMapping ( pFcb, pCcb);
998 if (!NT_SUCCESS(ntStatus))
1001 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
1002 AFS_TRACE_LEVEL_ERROR,
1003 "AFSNonCachedWrite Failed wait for extents for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX Status %08lX\n",
1004 pFcb->ObjectInformation->FileId.Cell,
1005 pFcb->ObjectInformation->FileId.Volume,
1006 pFcb->ObjectInformation->FileId.Vnode,
1007 pFcb->ObjectInformation->FileId.Unique,
1008 StartingByte.QuadPart,
1012 try_return( ntStatus);
1017 // As per the read path -
1020 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
1021 AFS_TRACE_LEVEL_VERBOSE,
1022 "AFSNonCachedWrite Extents located for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX\n",
1023 pFcb->ObjectInformation->FileId.Cell,
1024 pFcb->ObjectInformation->FileId.Volume,
1025 pFcb->ObjectInformation->FileId.Vnode,
1026 pFcb->ObjectInformation->FileId.Unique,
1027 StartingByte.QuadPart,
1030 ntStatus = AFSGetExtents( pFcb,
1037 if (!NT_SUCCESS(ntStatus))
1040 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1041 AFS_TRACE_LEVEL_ERROR,
1042 "AFSNonCachedWrite (%08lX) Failed to retrieve mapped extents Status %08lX\n",
1046 try_return( ntStatus );
1049 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1050 AFS_TRACE_LEVEL_VERBOSE,
1051 "AFSNonCachedWrite (%08lX) Successfully retrieved map extents count %08lX run count %08lX\n",
1056 if( BooleanFlagOn( AFSLibControlFlags, AFS_REDIR_LIB_FLAGS_NONPERSISTENT_CACHE))
1059 Irp->IoStatus.Information = ByteCount;
1063 // Setup the MD5 for each extent
1066 AFSSetupMD5Hash( pFcb,
1074 ntStatus = AFSProcessExtentRun( pSystemBuffer,
1080 if (!NT_SUCCESS(ntStatus))
1083 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1084 AFS_TRACE_LEVEL_ERROR,
1085 "AFSNonCachedWrite (%08lX) Failed to process extent run for non-persistent cache Status %08lX\n",
1090 try_return( ntStatus);
1094 // Retrieve the cache file object
1097 pCacheFileObject = AFSReferenceCacheFileObject();
1099 if( pCacheFileObject == NULL)
1102 ntStatus = STATUS_DEVICE_NOT_READY;
1104 AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
1105 AFS_TRACE_LEVEL_ERROR,
1106 "AFSNonCachedWrite Failed to retrieve cache fileobject for fid %08lX-%08lX-%08lX-%08lX Offset %I64X Length %08lX Status %08lX\n",
1107 pFcb->ObjectInformation->FileId.Cell,
1108 pFcb->ObjectInformation->FileId.Volume,
1109 pFcb->ObjectInformation->FileId.Vnode,
1110 pFcb->ObjectInformation->FileId.Unique,
1111 StartingByte.QuadPart,
1115 try_return( ntStatus);
1118 if (runCount > AFS_MAX_STACK_IO_RUNS)
1121 pIoRuns = (AFSIoRun*) AFSExAllocatePoolWithTag( PagedPool,
1122 runCount * sizeof( AFSIoRun ),
1124 if (NULL == pIoRuns)
1127 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1128 AFS_TRACE_LEVEL_ERROR,
1129 "AFSNonCachedWrite (%08lX) Failed to allocate IO run block\n",
1132 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES );
1141 RtlZeroMemory( pIoRuns, runCount * sizeof( AFSIoRun ));
1143 ntStatus = AFSSetupIoRun( IoGetRelatedDeviceObject( pCacheFileObject),
1152 if (!NT_SUCCESS(ntStatus))
1155 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1156 AFS_TRACE_LEVEL_ERROR,
1157 "AFSNonCachedWrite (%08lX) Failed to initialize IO run block Status %08lX\n",
1161 try_return( ntStatus );
1164 AFSReferenceActiveExtents( pStartExtent,
1167 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1168 AFS_TRACE_LEVEL_VERBOSE,
1169 "AFSNonCachedWrite Releasing(2) Fcb extents lock %08lX SHARED %08lX\n",
1170 &pFcb->NPFcb->Specific.File.ExtentsResource,
1171 PsGetCurrentThread());
1173 AFSReleaseResource( &pFcb->NPFcb->Specific.File.ExtentsResource );
1176 pGatherIo = (AFSGatherIo*) AFSExAllocatePoolWithTag( NonPagedPool,
1177 sizeof( AFSGatherIo),
1180 if (NULL == pGatherIo)
1183 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1184 AFS_TRACE_LEVEL_ERROR,
1185 "AFSNonCachedWrite (%08lX) Failed to allocate IO gather block\n",
1188 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1189 AFS_TRACE_LEVEL_VERBOSE,
1190 "AFSNonCachedWrite Acquiring(1) Fcb extents lock %08lX SHARED %08lX\n",
1191 &pFcb->NPFcb->Specific.File.ExtentsResource,
1192 PsGetCurrentThread());
1194 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource,
1198 AFSDereferenceActiveExtents( pStartExtent,
1201 try_return (ntStatus = STATUS_INSUFFICIENT_RESOURCES );
1204 RtlZeroMemory( pGatherIo, sizeof( AFSGatherIo ));
1207 // Initialize count to 1, that was we won't get an early
1208 // completion if the first irp completes before the second is
1211 pGatherIo->Count = 1;
1212 pGatherIo->Status = STATUS_SUCCESS;
1213 pGatherIo->MasterIrp = Irp;
1214 pGatherIo->Synchronous = TRUE;
1215 pGatherIo->CompleteMasterIrp = FALSE;
1217 bCompleteIrp = TRUE;
1219 if( pGatherIo->Synchronous)
1221 KeInitializeEvent( &pGatherIo->Event, NotificationEvent, FALSE );
1226 // Setup the MD5 for each extent
1229 AFSSetupMD5Hash( pFcb,
1238 // Pre-emptively set up the count
1241 Irp->IoStatus.Information = ByteCount;
1243 ntStatus = AFSQueueStartIos( pCacheFileObject,
1245 IRP_WRITE_OPERATION | IRP_SYNCHRONOUS_API,
1250 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1251 AFS_TRACE_LEVEL_VERBOSE,
1252 "AFSNonCachedWrite (%08lX) AFSStartIos completed Status %08lX\n",
1256 if( !NT_SUCCESS( ntStatus))
1259 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1260 AFS_TRACE_LEVEL_VERBOSE,
1261 "AFSNonCachedWrite Acquiring(2) Fcb extents lock %08lX SHARED %08lX\n",
1262 &pFcb->NPFcb->Specific.File.ExtentsResource,
1263 PsGetCurrentThread());
1265 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource,
1269 AFSDereferenceActiveExtents( pStartExtent,
1272 try_return( ntStatus);
1276 // Wait for completion of All IOs we started.
1279 ntStatus = KeWaitForSingleObject( &pGatherIo->Event,
1285 if( NT_SUCCESS( ntStatus))
1288 ntStatus = pGatherIo->Status;
1291 if( !NT_SUCCESS( ntStatus))
1294 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1295 AFS_TRACE_LEVEL_VERBOSE,
1296 "AFSNonCachedWrite Acquiring(3) Fcb extents lock %08lX SHARED %08lX\n",
1297 &pFcb->NPFcb->Specific.File.ExtentsResource,
1298 PsGetCurrentThread());
1300 AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource,
1304 AFSDereferenceActiveExtents( pStartExtent,
1307 try_return( ntStatus);
1311 // Since this is dirty we can mark the extents dirty now.
1312 // AFSMarkDirty will dereference the extents. Do not call
1313 // AFSDereferenceActiveExtents() in this code path.
1324 // This was an uncached user write - tell the server to do
1325 // the flush when the worker thread next wakes up
1327 pFcb->Specific.File.LastServerFlush.QuadPart = 0;
1336 if( pCacheFileObject != NULL)
1338 AFSReleaseCacheFileObject( pCacheFileObject);
1341 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1342 AFS_TRACE_LEVEL_VERBOSE,
1343 "AFSNonCachedWrite (%08lX) Completed request Status %08lX\n",
1347 if (NT_SUCCESS(ntStatus) &&
1352 pFileObject->CurrentByteOffset.QuadPart = StartingByte.QuadPart + ByteCount;
1358 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1359 AFS_TRACE_LEVEL_VERBOSE,
1360 "AFSNonCachedWrite Releasing Fcb extents lock %08lX SHARED %08lX\n",
1361 &pFcb->NPFcb->Specific.File.ExtentsResource,
1362 PsGetCurrentThread());
1364 AFSReleaseResource( &pFcb->NPFcb->Specific.File.ExtentsResource );
1369 AFSExFreePool(pGatherIo);
1372 if( NULL != pIoRuns &&
1373 stIoRuns != pIoRuns)
1375 AFSExFreePool(pIoRuns);
1381 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1382 AFS_TRACE_LEVEL_VERBOSE,
1383 "AFSNonCachedWrite Completing Irp %08lX Status %08lX Info %08lX\n",
1386 Irp->IoStatus.Information);
1388 AFSCompleteRequest( Irp, ntStatus);
1397 AFSCachedWrite( IN PDEVICE_OBJECT DeviceObject,
1399 IN LARGE_INTEGER StartingByte,
1401 IN BOOLEAN ForceFlush)
1403 PVOID pSystemBuffer = NULL;
1404 NTSTATUS ntStatus = STATUS_SUCCESS;
1405 IO_STATUS_BLOCK iosbFlush;
1406 IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1407 PFILE_OBJECT pFileObject = pIrpSp->FileObject;
1408 AFSFcb *pFcb = (AFSFcb *)pFileObject->FsContext;
1409 AFSCcb *pCcb = (AFSCcb *)pFileObject->FsContext2;
1410 BOOLEAN bSynchronousFo = BooleanFlagOn( pFileObject->Flags, FO_SYNCHRONOUS_IO);
1411 BOOLEAN bMapped = FALSE;
1412 ULONG ulCurrentIO = 0, ulTotalLen = ByteCount;
1413 PMDL pCurrentMdl = Irp->MdlAddress;
1414 LARGE_INTEGER liCurrentOffset;
1419 Irp->IoStatus.Information = 0;
1421 if( BooleanFlagOn( pIrpSp->MinorFunction, IRP_MN_MDL))
1427 CcPrepareMdlWrite( pFileObject,
1433 ntStatus = Irp->IoStatus.Status;
1435 __except( EXCEPTION_EXECUTE_HANDLER)
1437 ntStatus = GetExceptionCode();
1439 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1440 AFS_TRACE_LEVEL_ERROR,
1441 "AFSCachedWrite (%08lX) Exception thrown while preparing mdl write Status %08lX\n",
1446 if( !NT_SUCCESS( ntStatus))
1450 // Free up any potentially allocated mdl's
1453 CcMdlWriteComplete( pFileObject,
1457 Irp->MdlAddress = NULL;
1459 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1460 AFS_TRACE_LEVEL_ERROR,
1461 "AFSCachedWrite (%08lX) Failed to process MDL write Status %08lX\n",
1466 try_return( ntStatus);
1469 liCurrentOffset.QuadPart = StartingByte.QuadPart;
1471 while( ulTotalLen > 0)
1474 ntStatus = STATUS_SUCCESS;
1476 if( pCurrentMdl != NULL)
1479 pSystemBuffer = MmGetSystemAddressForMdlSafe( pCurrentMdl,
1480 NormalPagePriority);
1482 ulCurrentIO = MmGetMdlByteCount( pCurrentMdl);
1484 if( ulCurrentIO > ulTotalLen)
1486 ulCurrentIO = ulTotalLen;
1492 pSystemBuffer = AFSLockSystemBuffer( Irp,
1495 ulCurrentIO = ulTotalLen;
1498 if( pSystemBuffer == NULL)
1501 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1502 AFS_TRACE_LEVEL_ERROR,
1503 "AFSCachedWrite (%08lX) Failed to lock system buffer\n",
1506 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1512 if( !CcCopyWrite( pFileObject,
1519 // Failed to process request.
1522 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1523 AFS_TRACE_LEVEL_ERROR,
1524 "AFSCachedWrite (%08lX) Failed to issue CcCopyWrite %wZ @ %0I64X Status %08lX\n",
1526 &pFileObject->FileName,
1527 liCurrentOffset.QuadPart,
1528 Irp->IoStatus.Status);
1530 try_return( ntStatus = STATUS_UNSUCCESSFUL);
1533 __except( EXCEPTION_EXECUTE_HANDLER)
1536 ntStatus = GetExceptionCode();
1538 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1539 AFS_TRACE_LEVEL_ERROR,
1540 "AFSCachedWrite (%08lX) CcCopyWrite Threw exception %wZ @ %0I64X Status %08lX\n",
1542 &pFileObject->FileName,
1543 liCurrentOffset.QuadPart,
1547 if( !NT_SUCCESS( ntStatus))
1549 try_return( ntStatus);
1556 // We have detected a file we do a write through with.
1559 CcFlushCache(&pFcb->NPFcb->SectionObjectPointers,
1564 if( !NT_SUCCESS( iosbFlush.Status))
1567 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
1568 AFS_TRACE_LEVEL_ERROR,
1569 "AFSCachedWrite (%08lX) CcFlushCache failure %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
1571 &pFileObject->FileName,
1572 pFcb->ObjectInformation->FileId.Cell,
1573 pFcb->ObjectInformation->FileId.Volume,
1574 pFcb->ObjectInformation->FileId.Vnode,
1575 pFcb->ObjectInformation->FileId.Unique,
1577 iosbFlush.Information);
1579 try_return( ntStatus = iosbFlush.Status);
1583 if( ulTotalLen <= ulCurrentIO)
1588 liCurrentOffset.QuadPart += ulCurrentIO;
1590 ulTotalLen -= ulCurrentIO;
1592 pCurrentMdl = pCurrentMdl->Next;
1597 if( NT_SUCCESS( ntStatus))
1600 Irp->IoStatus.Information = ByteCount;
1605 pFileObject->CurrentByteOffset.QuadPart = StartingByte.QuadPart + ByteCount;
1609 // If this extended the Vdl, then update it accordingly
1612 if( StartingByte.QuadPart + ByteCount > pFcb->Header.ValidDataLength.QuadPart)
1615 pFcb->Header.ValidDataLength.QuadPart = StartingByte.QuadPart + ByteCount;
1618 if (BooleanFlagOn(pFileObject->Flags, (FO_NO_INTERMEDIATE_BUFFERING + FO_WRITE_THROUGH)))
1621 // Write through asked for... Set things so that we get
1622 // flush when the worker thread next wakes up
1624 pFcb->Specific.File.LastServerFlush.QuadPart = 0;
1627 if( !BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_LAST_WRITE_TIME))
1630 SetFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_WRITE_TIME);
1632 KeQuerySystemTime( &pFcb->ObjectInformation->LastWriteTime);
1636 AFSCompleteRequest( Irp,
1645 AFSExtendingWrite( IN AFSFcb *Fcb,
1646 IN PFILE_OBJECT FileObject,
1647 IN LONGLONG NewLength)
1649 LARGE_INTEGER liSaveFileSize = Fcb->Header.FileSize;
1650 LARGE_INTEGER liSaveAllocation = Fcb->Header.AllocationSize;
1651 NTSTATUS ntStatus = STATUS_SUCCESS;
1652 AFSCcb *pCcb = (AFSCcb *)FileObject->FsContext2;
1654 if( NewLength > Fcb->Header.AllocationSize.QuadPart)
1657 Fcb->Header.AllocationSize.QuadPart = NewLength;
1659 Fcb->ObjectInformation->AllocationSize = Fcb->Header.AllocationSize;
1662 if( NewLength > Fcb->Header.FileSize.QuadPart)
1665 Fcb->Header.FileSize.QuadPart = NewLength;
1667 Fcb->ObjectInformation->EndOfFile = Fcb->Header.FileSize;
1674 ntStatus = AFSUpdateFileInformation( &Fcb->ObjectInformation->ParentObjectInformation->FileId,
1675 Fcb->ObjectInformation,
1678 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1679 AFS_TRACE_LEVEL_VERBOSE,
1680 "AFSExtendingWrite Acquiring Fcb lock %08lX EXCL %08lX\n",
1681 &Fcb->NPFcb->Resource,
1682 PsGetCurrentThread());
1684 if (NT_SUCCESS(ntStatus))
1687 KeQuerySystemTime( &Fcb->ObjectInformation->ChangeTime);
1689 SetFlag( Fcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED | AFS_FCB_FLAG_UPDATE_CHANGE_TIME);
1692 // If the file is currently cached, then let the MM know about the extension
1695 if( CcIsFileCached( FileObject))
1697 CcSetFileSizes( FileObject,
1698 (PCC_FILE_SIZES)&Fcb->Header.AllocationSize);
1703 Fcb->Header.FileSize = liSaveFileSize;
1704 Fcb->Header.AllocationSize = liSaveAllocation;
1708 // DownConvert file resource to shared
1710 ExConvertExclusiveToSharedLite( &Fcb->NPFcb->Resource);
1716 AFSShareWrite( IN PDEVICE_OBJECT DeviceObject,
1720 NTSTATUS ntStatus = STATUS_SUCCESS;
1721 AFSPIOCtlIORequestCB stIORequestCB;
1722 PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1723 AFSFcb *pFcb = NULL;
1724 AFSCcb *pCcb = NULL;
1725 AFSPipeIORequestCB *pIoRequest = NULL;
1726 void *pBuffer = NULL;
1727 AFSPipeIOResultCB stIoResult;
1728 ULONG ulBytesReturned = 0;
1733 pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
1735 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1737 AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
1738 AFS_TRACE_LEVEL_VERBOSE,
1739 "AFSShareWrite On pipe %wZ Length %08lX\n",
1740 &pCcb->DirectoryCB->NameInformation.FileName,
1741 pIrpSp->Parameters.Write.Length);
1743 if( pIrpSp->Parameters.Write.Length == 0)
1747 // Nothing to do in this case
1750 try_return( ntStatus);
1754 // Retrieve the buffer for the read request
1757 pBuffer = AFSLockSystemBuffer( Irp,
1758 pIrpSp->Parameters.Write.Length);
1760 if( pBuffer == NULL)
1763 AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
1764 AFS_TRACE_LEVEL_ERROR,
1765 "AFSShareWrite Failed to map buffer on pipe %wZ\n",
1766 &pCcb->DirectoryCB->NameInformation.FileName);
1768 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1771 AFSAcquireShared( &pFcb->NPFcb->Resource,
1774 pIoRequest = (AFSPipeIORequestCB *)AFSExAllocatePoolWithTag( PagedPool,
1775 sizeof( AFSPipeIORequestCB) +
1776 pIrpSp->Parameters.Write.Length,
1777 AFS_GENERIC_MEMORY_14_TAG);
1779 if( pIoRequest == NULL)
1782 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1785 RtlZeroMemory( pIoRequest,
1786 sizeof( AFSPipeIORequestCB) + pIrpSp->Parameters.Write.Length);
1788 pIoRequest->RequestId = pCcb->RequestID;
1790 pIoRequest->RootId = pFcb->ObjectInformation->VolumeCB->ObjectInformation.FileId;
1792 pIoRequest->BufferLength = pIrpSp->Parameters.Write.Length;
1794 RtlCopyMemory( (void *)((char *)pIoRequest + sizeof( AFSPipeIORequestCB)),
1796 pIrpSp->Parameters.Write.Length);
1798 stIoResult.BytesProcessed = 0;
1800 ulBytesReturned = sizeof( AFSPipeIOResultCB);
1803 // Issue the open request to the service
1806 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PIPE_WRITE,
1807 AFS_REQUEST_FLAG_SYNCHRONOUS,
1809 &pCcb->DirectoryCB->NameInformation.FileName,
1812 sizeof( AFSPipeIORequestCB) +
1813 pIrpSp->Parameters.Write.Length,
1817 if( !NT_SUCCESS( ntStatus))
1820 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1821 AFS_TRACE_LEVEL_ERROR,
1822 "AFSShareWrite (%08lX) Failed service write Status %08lX\n",
1826 try_return( ntStatus);
1829 AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
1830 AFS_TRACE_LEVEL_VERBOSE,
1831 "AFSShareWrite Completed on pipe %wZ Length read %08lX\n",
1832 &pCcb->DirectoryCB->NameInformation.FileName,
1833 stIoResult.BytesProcessed);
1835 Irp->IoStatus.Information = stIoResult.BytesProcessed;
1842 AFSReleaseResource( &pFcb->NPFcb->Resource);
1845 if( pIoRequest != NULL)
1848 AFSExFreePool( pIoRequest);