Author: tkreuzer Date: Wed Jan 13 02:10:36 2010 New Revision: 45056
URL: http://svn.reactos.org/svn/reactos?rev=45056&view=rev Log: Update file from trunk
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/fsrtl/fastio.c
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/fsrtl/fastio.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/fsrtl/fastio.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/fsrtl/fastio.c [iso-8859-1] Wed Jan 13 02:10:36 2010 @@ -74,9 +74,9 @@ PFAST_IO_DISPATCH FastIoDispatch; PDEVICE_OBJECT Device; BOOLEAN Result = TRUE; - ULONG PageCount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(FileOffset,Length); - - PAGED_CODE(); + ULONG PageCount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(FileOffset, Length); + + PAGED_CODE(); ASSERT(FileObject); ASSERT(FileObject->FsContext);
@@ -91,9 +91,9 @@
if (Length > MAXLONGLONG - FileOffset->QuadPart) { - IoStatus->Status = STATUS_INVALID_PARAMETER; - IoStatus->Information = 0; - return FALSE; + IoStatus->Status = STATUS_INVALID_PARAMETER; + IoStatus->Information = 0; + return FALSE; }
/* Get the offset and FCB header */ @@ -104,7 +104,7 @@ { /* Use a Resource Acquire */ FsRtlEnterFileSystem(); - CcFastReadWait++; + CcFastReadWait++; ExAcquireResourceSharedLite(FcbHeader->Resource, TRUE); } else @@ -115,9 +115,9 @@ FsRtlEnterFileSystem(); if (!ExAcquireResourceSharedLite(FcbHeader->Resource, FALSE)) { - FsRtlExitFileSystem(); - FsRtlIncrementCcFastReadResourceMiss(); - return FALSE; + FsRtlExitFileSystem(); + FsRtlIncrementCcFastReadResourceMiss(); + return FALSE; } }
@@ -126,8 +126,8 @@ (FcbHeader->IsFastIoPossible == FastIoIsNotPossible)) { /* It's not, so fail */ - Result = FALSE; - goto Cleanup; + Result = FALSE; + goto Cleanup; }
/* Check if we need to find out if fast I/O is available */ @@ -138,7 +138,7 @@
/* Get the Fast I/O table */ Device = IoGetRelatedDeviceObject(FileObject); - FastIoDispatch = Device->DriverObject->FastIoDispatch; + FastIoDispatch = Device->DriverObject->FastIoDispatch;
/* Sanity check */ ASSERT(FastIoDispatch != NULL); @@ -158,7 +158,7 @@ Result = FALSE; goto Cleanup; } - } + }
/* Check if we read too much */ if (Offset.QuadPart > FcbHeader->FileSize.QuadPart) @@ -177,15 +177,15 @@ }
/* Set this as top-level IRP */ - PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; - - _SEH2_TRY - { - /* Make sure the IO and file size is below 4GB */ + PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; + + _SEH2_TRY + { + /* Make sure the IO and file size is below 4GB */ if (Wait && !(Offset.HighPart | FcbHeader->FileSize.HighPart)) {
- /* Call the cache controller */ + /* Call the cache controller */ CcFastCopyRead(FileObject, FileOffset->LowPart, Length, @@ -193,14 +193,14 @@ Buffer, IoStatus);
- /* File was accessed */ - FileObject->Flags |= FO_FILE_FAST_IO_READ; + /* File was accessed */ + FileObject->Flags |= FO_FILE_FAST_IO_READ;
if (IoStatus->Status != STATUS_END_OF_FILE) { ASSERT(FcbHeader->FileSize.QuadPart >= FileOffset->QuadPart + IoStatus->Information); - } + } } else { @@ -214,30 +214,30 @@ IoStatus);
/* File was accessed */ - FileObject->Flags |= FO_FILE_FAST_IO_READ; + FileObject->Flags |= FO_FILE_FAST_IO_READ;
if (Result == TRUE) { - ASSERT( (IoStatus->Status == STATUS_END_OF_FILE) || + ASSERT((IoStatus->Status == STATUS_END_OF_FILE) || ((LONGLONG)(FileOffset->QuadPart + IoStatus->Information) <= FcbHeader->FileSize.QuadPart)); - } - } + } + }
/* Update the current file offset */ if (Result == TRUE) { - FileObject->CurrentByteOffset.QuadPart += IoStatus->Information; - } - } + FileObject->CurrentByteOffset.QuadPart += IoStatus->Information; + } + } _SEH2_EXCEPT(FsRtlIsNtstatusExpected(_SEH2_GetExceptionCode()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) - { - Result = FALSE; + { + Result = FALSE; } _SEH2_END;
- PsGetCurrentThread()->TopLevelIrp = 0; + PsGetCurrentThread()->TopLevelIrp = 0;
/* Return to caller */ Cleanup: @@ -248,7 +248,7 @@ if (Result == FALSE) { CcFastReadNotPossible += 1; - } + }
return Result; } @@ -306,11 +306,11 @@ /* Nagar p.544. * Check with Cc if we can write and check if the IO > 64kB (WDK macro). */ - if ( (CcCanIWrite(FileObject, Length,Wait, FALSE) == FALSE) || - (CcCopyWriteWontFlush(FileObject,FileOffset,Length) == FALSE) || + if ((CcCanIWrite(FileObject, Length, Wait, FALSE) == FALSE) || + (CcCopyWriteWontFlush(FileObject, FileOffset, Length) == FALSE) || ((FileObject->Flags & FO_WRITE_THROUGH) == TRUE)) { - return FALSE; + return FALSE; }
/* No actual read */ @@ -334,12 +334,12 @@ if ((FileOffsetAppend == FALSE) && (Offset.LowPart <= FcbHeader->ValidDataLength.LowPart)) { - ExAcquireResourceSharedLite(FcbHeader->Resource,TRUE); - ResourceAquiredShared = TRUE; + ExAcquireResourceSharedLite(FcbHeader->Resource, TRUE); + ResourceAquiredShared = TRUE; } else { - ExAcquireResourceExclusiveLite(FcbHeader->Resource,TRUE); + ExAcquireResourceExclusiveLite(FcbHeader->Resource, TRUE); }
/* Nagar p.544/545. @@ -348,15 +348,15 @@ */ if (FileOffsetAppend == TRUE) { - Offset.LowPart = FcbHeader->FileSize.LowPart; - NewSize.LowPart = FcbHeader->FileSize.LowPart + Length; - b_4GB = (NewSize.LowPart < FcbHeader->FileSize.LowPart); + Offset.LowPart = FcbHeader->FileSize.LowPart; + NewSize.LowPart = FcbHeader->FileSize.LowPart + Length; + b_4GB = (NewSize.LowPart < FcbHeader->FileSize.LowPart);
} else { - Offset.LowPart = FileOffset->LowPart; - NewSize.LowPart = FileOffset->LowPart + Length; + Offset.LowPart = FileOffset->LowPart; + NewSize.LowPart = FileOffset->LowPart + Length; b_4GB = (NewSize.LowPart < FileOffset->LowPart) || (FileOffset->HighPart != 0); } @@ -367,10 +367,10 @@ * That we are not extending past the allocated size. * That we are not creating a hole bigger than 8k. * That we are not crossing the 4GB boundary. - */ - if ( (FileObject->PrivateCacheMap != NULL) && - (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && - (FcbHeader->AllocationSize.LowPart >= NewSize.LowPart) && + */ + if ((FileObject->PrivateCacheMap != NULL) && + (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && + (FcbHeader->AllocationSize.LowPart >= NewSize.LowPart) && (Offset.LowPart < FcbHeader->ValidDataLength.LowPart + 0x2000) && !b_4GB) { @@ -381,133 +381,133 @@ if (ResourceAquiredShared && (NewSize.LowPart > FcbHeader->ValidDataLength.LowPart + 0x2000)) { - /* Then we need to acquire the resource exclusive */ - ExReleaseResourceLite(FcbHeader->Resource); - ExAcquireResourceExclusiveLite(FcbHeader->Resource,TRUE); + /* Then we need to acquire the resource exclusive */ + ExReleaseResourceLite(FcbHeader->Resource); + ExAcquireResourceExclusiveLite(FcbHeader->Resource, TRUE); if (FileOffsetAppend == TRUE) { - Offset.LowPart = FcbHeader->FileSize.LowPart; // ?? - NewSize.LowPart = FcbHeader->FileSize.LowPart + Length; - - /* Make sure we don't cross the 4GB boundary */ - b_4GB = (NewSize.LowPart < Offset.LowPart); - } + Offset.LowPart = FcbHeader->FileSize.LowPart; // ?? + NewSize.LowPart = FcbHeader->FileSize.LowPart + Length; + + /* Make sure we don't cross the 4GB boundary */ + b_4GB = (NewSize.LowPart < Offset.LowPart); + }
/* Recheck some of the conditions since we let the lock go */ - if ( (FileObject->PrivateCacheMap != NULL) && - (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && - (FcbHeader->AllocationSize.LowPart >= NewSize.LowPart) && - (FcbHeader->AllocationSize.HighPart == 0) && + if ((FileObject->PrivateCacheMap != NULL) && + (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && + (FcbHeader->AllocationSize.LowPart >= NewSize.LowPart) && + (FcbHeader->AllocationSize.HighPart == 0) && !b_4GB) - { + { /* Do nothing? */ } else - { - goto FailAndCleanup; - } - } + { + goto FailAndCleanup; + } + }
} else { - goto FailAndCleanup; - } - - /* Check if we need to find out if fast I/O is available */ - if (FcbHeader->IsFastIoPossible == FastIoIsQuestionable) - { - IO_STATUS_BLOCK FastIoCheckIfPossibleStatus; - - /* Sanity check */ - ASSERT(!KeIsExecutingDpc()); - - /* Get the Fast I/O table */ - Device = IoGetRelatedDeviceObject(FileObject); - FastIoDispatch = Device->DriverObject->FastIoDispatch; - - /* Sanity check */ - ASSERT(FastIoDispatch != NULL); - ASSERT(FastIoDispatch->FastIoCheckIfPossible != NULL); - - /* Ask the driver if we can do it */ - if (!FastIoDispatch->FastIoCheckIfPossible(FileObject, + goto FailAndCleanup; + } + + /* Check if we need to find out if fast I/O is available */ + if (FcbHeader->IsFastIoPossible == FastIoIsQuestionable) + { + IO_STATUS_BLOCK FastIoCheckIfPossibleStatus; + + /* Sanity check */ + ASSERT(!KeIsExecutingDpc()); + + /* Get the Fast I/O table */ + Device = IoGetRelatedDeviceObject(FileObject); + FastIoDispatch = Device->DriverObject->FastIoDispatch; + + /* Sanity check */ + ASSERT(FastIoDispatch != NULL); + ASSERT(FastIoDispatch->FastIoCheckIfPossible != NULL); + + /* Ask the driver if we can do it */ + if (!FastIoDispatch->FastIoCheckIfPossible(FileObject, FileOffsetAppend ? &FcbHeader->FileSize : FileOffset, - Length, - TRUE, - LockKey, - FALSE, - &FastIoCheckIfPossibleStatus, - Device)) - { - /* It's not, fail */ - goto FailAndCleanup; - } - } + Length, + TRUE, + LockKey, + FALSE, + &FastIoCheckIfPossibleStatus, + Device)) + { + /* It's not, fail */ + goto FailAndCleanup; + } + }
/* If we are going to extend the file then save * the old file size in case the operation fails. - */ + */ if (NewSize.LowPart > FcbHeader->FileSize.LowPart) { - FileSizeModified = TRUE; - OldFileSize.LowPart = FcbHeader->FileSize.LowPart; - OldValidDataLength.LowPart = FcbHeader->ValidDataLength.LowPart; - FcbHeader->FileSize.LowPart = NewSize.LowPart; - } - - /* Set this as top-level IRP */ - PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; - - _SEH2_TRY - { + FileSizeModified = TRUE; + OldFileSize.LowPart = FcbHeader->FileSize.LowPart; + OldValidDataLength.LowPart = FcbHeader->ValidDataLength.LowPart; + FcbHeader->FileSize.LowPart = NewSize.LowPart; + } + + /* Set this as top-level IRP */ + PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; + + _SEH2_TRY + { if (Offset.LowPart > FcbHeader->ValidDataLength.LowPart) { - LARGE_INTEGER OffsetVar; - OffsetVar.LowPart = Offset.LowPart; - OffsetVar.HighPart = 0; - CcZeroData(FileObject,&FcbHeader->ValidDataLength,&OffsetVar,TRUE); - } - - /* Call the cache manager */ - CcFastCopyWrite(FileObject,Offset.LowPart,Length,Buffer); - } + LARGE_INTEGER OffsetVar; + OffsetVar.LowPart = Offset.LowPart; + OffsetVar.HighPart = 0; + CcZeroData(FileObject, &FcbHeader->ValidDataLength, &OffsetVar, TRUE); + } + + /* Call the cache manager */ + CcFastCopyWrite(FileObject, Offset.LowPart, Length, Buffer); + } _SEH2_EXCEPT(FsRtlIsNtstatusExpected(_SEH2_GetExceptionCode()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) - { - Result = FALSE; + { + Result = FALSE; } _SEH2_END;
/* Remove ourselves at the top level component after the IO is done */ - PsGetCurrentThread()->TopLevelIrp = 0; - - /* Did the operation succeed ? */ + PsGetCurrentThread()->TopLevelIrp = 0; + + /* Did the operation succeed? */ if (Result == TRUE) { - /* Update the valid file size if necessary */ + /* Update the valid file size if necessary */ if (NewSize.LowPart > FcbHeader->ValidDataLength.LowPart) { - FcbHeader->ValidDataLength.LowPart = NewSize.LowPart ; - } + FcbHeader->ValidDataLength.LowPart = NewSize.LowPart; + }
/* Flag the file as modified */ - FileObject->Flags |= FO_FILE_MODIFIED; - - /* Update the strucutres if the file size changed */ + FileObject->Flags |= FO_FILE_MODIFIED; + + /* Update the strucutres if the file size changed */ if (FileSizeModified) { SharedCacheMap = (PSHARED_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap; SharedCacheMap->FileSize.LowPart = NewSize.LowPart; - FileObject->Flags |= FO_FILE_SIZE_CHANGED; - } + FileObject->Flags |= FO_FILE_SIZE_CHANGED; + }
/* Update the file object current file offset */ - FileObject->CurrentByteOffset.QuadPart = NewSize.LowPart; + FileObject->CurrentByteOffset.QuadPart = NewSize.LowPart;
} else @@ -515,31 +515,31 @@ /* Result == FALSE if we get here */ if (FileSizeModified) { - /* If the file size was modified then restore the old file size */ + /* If the file size was modified then restore the old file size */ if (FcbHeader->PagingIoResource != NULL) { /* Nagar P.544. * Restore the old file size if operation didn't succeed. */ - ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource,TRUE); - FcbHeader->FileSize.LowPart = OldFileSize.LowPart; - FcbHeader->ValidDataLength.LowPart = OldValidDataLength.LowPart; - ExReleaseResourceLite(FcbHeader->PagingIoResource); + ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); + FcbHeader->FileSize.LowPart = OldFileSize.LowPart; + FcbHeader->ValidDataLength.LowPart = OldValidDataLength.LowPart; + ExReleaseResourceLite(FcbHeader->PagingIoResource); } else { - /* If there is no lock and do it without */ - FcbHeader->FileSize.LowPart = OldFileSize.LowPart; - FcbHeader->ValidDataLength.LowPart = OldValidDataLength.LowPart; - } - } + /* If there is no lock and do it without */ + FcbHeader->FileSize.LowPart = OldFileSize.LowPart; + FcbHeader->ValidDataLength.LowPart = OldValidDataLength.LowPart; + } + } else { /* Do nothing? */ - } - } - - goto Cleanup; + } + } + + goto Cleanup; } else { @@ -550,126 +550,126 @@ OldFileSize.QuadPart = 0; #endif
- /* Sanity check */ - ASSERT(!KeIsExecutingDpc()); + /* Sanity check */ + ASSERT(!KeIsExecutingDpc());
/* Nagar P.544. * Check if we need to acquire the resource exclusive. */ - if ( (FileOffsetAppend == FALSE) && + if ((FileOffsetAppend == FALSE) && (FileOffset->QuadPart + Length <= FcbHeader->ValidDataLength.QuadPart)) - { - /* Acquire the resource shared */ + { + /* Acquire the resource shared */ if (!ExAcquireResourceSharedLite(FcbHeader->Resource, Wait)) { - goto LeaveCriticalAndFail; - } - ResourceAquiredShared =TRUE; + goto LeaveCriticalAndFail; + } + ResourceAquiredShared = TRUE; } else { - /* Acquire the resource exclusive */ + /* Acquire the resource exclusive */ if (!ExAcquireResourceExclusiveLite(FcbHeader->Resource, Wait)) { - goto LeaveCriticalAndFail; - } - } - - /* Check if we are appending */ + goto LeaveCriticalAndFail; + } + } + + /* Check if we are appending */ if (FileOffsetAppend == TRUE) { - Offset.QuadPart = FcbHeader->FileSize.QuadPart; - NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; + Offset.QuadPart = FcbHeader->FileSize.QuadPart; + NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; } else { - Offset.QuadPart = FileOffset->QuadPart; - NewSize.QuadPart += FileOffset->QuadPart + Length; - } + Offset.QuadPart = FileOffset->QuadPart; + NewSize.QuadPart += FileOffset->QuadPart + Length; + }
/* Nagar p.544/545. * Make sure that caching is initated. * That fast are allowed for this file stream. * That we are not extending past the allocated size. * That we are not creating a hole bigger than 8k. - */ - if ( (FileObject->PrivateCacheMap != NULL) && - (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && + */ + if ((FileObject->PrivateCacheMap != NULL) && + (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && (FcbHeader->ValidDataLength.QuadPart + 0x2000 > Offset.QuadPart) && (Length <= MAXLONGLONG - Offset.QuadPart) && (FcbHeader->AllocationSize.QuadPart >= NewSize.QuadPart)) - { - /* Check if we can keep the lock shared */ + { + /* Check if we can keep the lock shared */ if (ResourceAquiredShared && (NewSize.QuadPart > FcbHeader->ValidDataLength.QuadPart)) { - ExReleaseResourceLite(FcbHeader->Resource); - if(!ExAcquireResourceExclusiveLite(FcbHeader->Resource,Wait)) - { - goto LeaveCriticalAndFail; - } + ExReleaseResourceLite(FcbHeader->Resource); + if (!ExAcquireResourceExclusiveLite(FcbHeader->Resource, Wait)) + { + goto LeaveCriticalAndFail; + }
/* Compute the offset and the new filesize */ if (FileOffsetAppend) { - Offset.QuadPart = FcbHeader->FileSize.QuadPart; - NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; - } - - /* Recheck the above points since we released and reacquire the lock */ - if ( (FileObject->PrivateCacheMap != NULL) && - (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && + Offset.QuadPart = FcbHeader->FileSize.QuadPart; + NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; + } + + /* Recheck the above points since we released and reacquire the lock */ + if ((FileObject->PrivateCacheMap != NULL) && + (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && (FcbHeader->AllocationSize.QuadPart > NewSize.QuadPart)) - { - /* Do nothing */ + { + /* Do nothing */ } else { - goto FailAndCleanup; - } - } - - /* Check if we need to find out if fast I/O is available */ - if (FcbHeader->IsFastIoPossible == FastIoIsQuestionable) - { - IO_STATUS_BLOCK FastIoCheckIfPossibleStatus; - - /* Sanity check */ - ASSERT(!KeIsExecutingDpc()); - - /* Get the Fast I/O table */ - Device = IoGetRelatedDeviceObject(FileObject); - FastIoDispatch = Device->DriverObject->FastIoDispatch; - - /* Sanity check */ - ASSERT(FastIoDispatch != NULL); - ASSERT(FastIoDispatch->FastIoCheckIfPossible != NULL); - - /* Ask the driver if we can do it */ - if (!FastIoDispatch->FastIoCheckIfPossible(FileObject, + goto FailAndCleanup; + } + } + + /* Check if we need to find out if fast I/O is available */ + if (FcbHeader->IsFastIoPossible == FastIoIsQuestionable) + { + IO_STATUS_BLOCK FastIoCheckIfPossibleStatus; + + /* Sanity check */ + ASSERT(!KeIsExecutingDpc()); + + /* Get the Fast I/O table */ + Device = IoGetRelatedDeviceObject(FileObject); + FastIoDispatch = Device->DriverObject->FastIoDispatch; + + /* Sanity check */ + ASSERT(FastIoDispatch != NULL); + ASSERT(FastIoDispatch->FastIoCheckIfPossible != NULL); + + /* Ask the driver if we can do it */ + if (!FastIoDispatch->FastIoCheckIfPossible(FileObject, FileOffsetAppend ? &FcbHeader->FileSize : FileOffset, - Length, - TRUE, - LockKey, - FALSE, - &FastIoCheckIfPossibleStatus, - Device)) - { - /* It's not, fail */ - goto FailAndCleanup; - } - } + Length, + TRUE, + LockKey, + FALSE, + &FastIoCheckIfPossibleStatus, + Device)) + { + /* It's not, fail */ + goto FailAndCleanup; + } + }
/* If we are going to modify the filesize, * save the old fs in case the operation fails. */ if (NewSize.QuadPart > FcbHeader->FileSize.QuadPart) { - FileSizeModified = TRUE; - OldFileSize.QuadPart = FcbHeader->FileSize.QuadPart; - OldValidDataLength.QuadPart = FcbHeader->ValidDataLength.QuadPart; + FileSizeModified = TRUE; + OldFileSize.QuadPart = FcbHeader->FileSize.QuadPart; + OldValidDataLength.QuadPart = FcbHeader->ValidDataLength.QuadPart;
/* If the high part of the filesize is going * to change, grab the Paging IoResouce. @@ -677,28 +677,28 @@ if (NewSize.HighPart != FcbHeader->FileSize.HighPart && FcbHeader->PagingIoResource) { - ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); - FcbHeader->FileSize.QuadPart = NewSize.QuadPart; - ExReleaseResourceLite(FcbHeader->PagingIoResource); + ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); + FcbHeader->FileSize.QuadPart = NewSize.QuadPart; + ExReleaseResourceLite(FcbHeader->PagingIoResource); } else { - FcbHeader->FileSize.QuadPart = NewSize.QuadPart; - } - } + FcbHeader->FileSize.QuadPart = NewSize.QuadPart; + } + }
/* Nagar p.544. * Set ourselves as top component. */ - PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; - - _SEH2_TRY - { - BOOLEAN CallCc = TRUE; + PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; + + _SEH2_TRY + { + BOOLEAN CallCc = TRUE;
/* Check if there is a gap between the end of the file * and the offset. If yes, then we have to zero the data. - */ + */ if (Offset.QuadPart > FcbHeader->ValidDataLength.QuadPart) { if (!(Result = CcZeroData(FileObject, @@ -708,92 +708,92 @@ { /* If this operation fails, then we have to exit. We can jump * outside the SEH, so I a using a variable to exit normally. - */ - CallCc = FALSE; - } - } + */ + CallCc = FALSE; + } + }
/* Unless the CcZeroData failed, call the cache manager */ if (CallCc) { - Result = CcCopyWrite(FileObject,&Offset,Length, Wait, Buffer); - } + Result = CcCopyWrite(FileObject, &Offset, Length, Wait, Buffer); + } } _SEH2_EXCEPT(FsRtlIsNtstatusExpected(_SEH2_GetExceptionCode()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) - { - Result = FALSE; + { + Result = FALSE; } _SEH2_END;
/* Reset the top component */ - PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; + PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP;
/* Did the operation suceeded */ if (Result) { - /* Check if we need to update the filesize */ + /* Check if we need to update the filesize */ if (NewSize.QuadPart > FcbHeader->ValidDataLength.QuadPart) { if (NewSize.HighPart != FcbHeader->ValidDataLength.HighPart && FcbHeader->PagingIoResource) { - ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); - FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; - ExReleaseResourceLite(FcbHeader->PagingIoResource); + ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); + FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; + ExReleaseResourceLite(FcbHeader->PagingIoResource); } else { - FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; - } - } + FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; + } + }
/* Flag the file as modified */ - FileObject->Flags |= FO_FILE_MODIFIED; - - /* Check if the filesize has changed */ + FileObject->Flags |= FO_FILE_MODIFIED; + + /* Check if the filesize has changed */ if (FileSizeModified) { - /* Update the file sizes */ + /* Update the file sizes */ SharedCacheMap = (PSHARED_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap; SharedCacheMap->FileSize.QuadPart = NewSize.QuadPart; - FileObject->Flags |= FO_FILE_SIZE_CHANGED; - } - - /* Update the current FO byte offset */ - FileObject->CurrentByteOffset.QuadPart = NewSize.QuadPart; - } - else - { + FileObject->Flags |= FO_FILE_SIZE_CHANGED; + } + + /* Update the current FO byte offset */ + FileObject->CurrentByteOffset.QuadPart = NewSize.QuadPart; + } + else + { /* The operation did not succeed. * Reset the file size to what it should be. - */ + */ if (FileSizeModified) { if (FcbHeader->PagingIoResource) { - ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); - FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; - FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; - ExReleaseResourceLite(FcbHeader->PagingIoResource); + ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); + FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; + FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; + ExReleaseResourceLite(FcbHeader->PagingIoResource); } else { - FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; - FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; - } - } - } - - goto Cleanup; + FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; + FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; + } + } + } + + goto Cleanup; } else { - goto FailAndCleanup; - } - } + goto FailAndCleanup; + } + }
LeaveCriticalAndFail:
@@ -818,7 +818,7 @@ */ NTSTATUS NTAPI -FsRtlGetFileSize(IN PFILE_OBJECT FileObject, +FsRtlGetFileSize(IN PFILE_OBJECT FileObject, IN OUT PLARGE_INTEGER FileSize) { FILE_STANDARD_INFORMATION Info; @@ -840,8 +840,8 @@ /* Check if we support Fast Calls, and check FastIoQueryStandardInfo. * Call the function and see if it succeeds. */ - if ( !FastDispatch || - !FastDispatch->FastIoQueryStandardInfo || + if (!FastDispatch || + !FastDispatch->FastIoQueryStandardInfo || !FastDispatch->FastIoQueryStandardInfo(FileObject, TRUE, &Info, @@ -851,10 +851,10 @@ /* If any of the above failed, then we are going to send an * IRP to the device object. Initialize the event for the IO. */ - KeInitializeEvent(&Event,NotificationEvent,FALSE); + KeInitializeEvent(&Event, NotificationEvent, FALSE);
/* Allocate the IRP */ - Irp = IoAllocateIrp(DeviceObject->StackSize,FALSE); + Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (Irp == NULL) { @@ -885,12 +885,12 @@ FileStandardInformation;
/* Send the IRP to the related device object */ - Status = IoCallDriver(DeviceObject,Irp); + Status = IoCallDriver(DeviceObject, Irp);
/* Standard DDK IRP result processing */ if (Status == STATUS_PENDING) { - KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL); + KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); }
/* If there was a synchronous error, signal it */ @@ -905,7 +905,7 @@ /* Check the sync/async IO result */ if (NT_SUCCESS(IoStatus.Status)) { - /* Was the request for a directory ? */ + /* Was the request for a directory? */ if (Info.Directory) { IoStatus.Status = STATUS_FILE_IS_A_DIRECTORY; @@ -1012,8 +1012,8 @@ /* * @implemented */ - BOOLEAN - NTAPI +BOOLEAN +NTAPI FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject, IN PMDL MemoryDescriptorList, IN PDEVICE_OBJECT DeviceObject) @@ -1133,8 +1133,8 @@ _SEH2_EXCEPT(FsRtlIsNtstatusExpected(_SEH2_GetExceptionCode()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) - { - Result = FALSE; + { + Result = FALSE; } _SEH2_END;
@@ -1208,11 +1208,11 @@ { if (FileObject->Flags & FO_WRITE_THROUGH) { - return FALSE; + return FALSE; }
/* Call the Cache Manager */ - CcMdlWriteComplete2(FileObject,FileOffset,MdlChain); + CcMdlWriteComplete2(FileObject, FileOffset, MdlChain); return TRUE; }
@@ -1315,9 +1315,9 @@ * Check with Cc if we can write. */ if (!CcCanIWrite(FileObject, Length, TRUE, FALSE) || - (FileObject->Flags & FO_WRITE_THROUGH)) - { - return FALSE; + (FileObject->Flags & FO_WRITE_THROUGH)) + { + return FALSE; }
IoStatus->Status = STATUS_SUCCESS; @@ -1332,213 +1332,213 @@ FsRtlEnterFileSystem();
/* Check we are going to extend the file */ - if ( (FileOffsetAppend == FALSE) && + if ((FileOffsetAppend == FALSE) && (FileOffset->QuadPart + Length <= FcbHeader->ValidDataLength.QuadPart)) - { - /* Acquire the resource shared */ - ExAcquireResourceSharedLite(FcbHeader->Resource,TRUE); - ResourceAquiredShared =TRUE; + { + /* Acquire the resource shared */ + ExAcquireResourceSharedLite(FcbHeader->Resource, TRUE); + ResourceAquiredShared = TRUE; } else - { - /* Acquire the resource exclusive */ - ExAcquireResourceExclusiveLite(FcbHeader->Resource,TRUE); - } - - /* Check if we are appending */ + { + /* Acquire the resource exclusive */ + ExAcquireResourceExclusiveLite(FcbHeader->Resource, TRUE); + } + + /* Check if we are appending */ if (FileOffsetAppend == TRUE) { - Offset.QuadPart = FcbHeader->FileSize.QuadPart; - NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; + Offset.QuadPart = FcbHeader->FileSize.QuadPart; + NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; } else - { - Offset.QuadPart = FileOffset->QuadPart; - NewSize.QuadPart = FileOffset->QuadPart + Length; - } - - if ( (FileObject->PrivateCacheMap) && - (FcbHeader->IsFastIoPossible) && + { + Offset.QuadPart = FileOffset->QuadPart; + NewSize.QuadPart = FileOffset->QuadPart + Length; + } + + if ((FileObject->PrivateCacheMap) && + (FcbHeader->IsFastIoPossible) && (Length <= MAXLONGLONG - FileOffset->QuadPart) && - (NewSize.QuadPart <= FcbHeader->AllocationSize.QuadPart) ) + (NewSize.QuadPart <= FcbHeader->AllocationSize.QuadPart)) { /* Check if we can keep the lock shared */ if (ResourceAquiredShared && (NewSize.QuadPart > FcbHeader->ValidDataLength.QuadPart)) { - ExReleaseResourceLite(FcbHeader->Resource); - ExAcquireResourceExclusiveLite(FcbHeader->Resource,TRUE); + ExReleaseResourceLite(FcbHeader->Resource); + ExAcquireResourceExclusiveLite(FcbHeader->Resource, TRUE);
/* Compute the offset and the new filesize */ if (FileOffsetAppend) { - Offset.QuadPart = FcbHeader->FileSize.QuadPart; - NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; - } - - /* Recheck the above points since we released and reacquire the lock */ - if ( (FileObject->PrivateCacheMap != NULL) && - (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && + Offset.QuadPart = FcbHeader->FileSize.QuadPart; + NewSize.QuadPart = FcbHeader->FileSize.QuadPart + Length; + } + + /* Recheck the above points since we released and reacquire the lock */ + if ((FileObject->PrivateCacheMap != NULL) && + (FcbHeader->IsFastIoPossible != FastIoIsNotPossible) && (FcbHeader->AllocationSize.QuadPart > NewSize.QuadPart)) - { - /* Do nothing */ + { + /* Do nothing */ } else { - goto FailAndCleanup; - } - } - - /* Check if we need to find out if fast I/O is available */ - if (FcbHeader->IsFastIoPossible == FastIoIsQuestionable) - { - /* Sanity check */ - /* ASSERT(!KeIsExecutingDpc()); */ - - /* Get the Fast I/O table */ - Device = IoGetRelatedDeviceObject(FileObject); - FastIoDispatch = Device->DriverObject->FastIoDispatch; - - /* Sanity check */ - ASSERT(FastIoDispatch != NULL); - ASSERT(FastIoDispatch->FastIoCheckIfPossible != NULL); - - /* Ask the driver if we can do it */ - if (!FastIoDispatch->FastIoCheckIfPossible(FileObject, - FileOffset, - Length, - TRUE, - LockKey, - FALSE, - IoStatus, - Device)) - { - /* It's not, fail */ - goto FailAndCleanup; - } - } + goto FailAndCleanup; + } + } + + /* Check if we need to find out if fast I/O is available */ + if (FcbHeader->IsFastIoPossible == FastIoIsQuestionable) + { + /* Sanity check */ + /* ASSERT(!KeIsExecutingDpc()); */ + + /* Get the Fast I/O table */ + Device = IoGetRelatedDeviceObject(FileObject); + FastIoDispatch = Device->DriverObject->FastIoDispatch; + + /* Sanity check */ + ASSERT(FastIoDispatch != NULL); + ASSERT(FastIoDispatch->FastIoCheckIfPossible != NULL); + + /* Ask the driver if we can do it */ + if (!FastIoDispatch->FastIoCheckIfPossible(FileObject, + FileOffset, + Length, + TRUE, + LockKey, + FALSE, + IoStatus, + Device)) + { + /* It's not, fail */ + goto FailAndCleanup; + } + }
/* If we are going to modify the filesize, * save the old fs in case the operation fails. */ - if (NewSize.QuadPart > FcbHeader->FileSize.QuadPart) - { - FileSizeModified = TRUE; - OldFileSize.QuadPart = FcbHeader->FileSize.QuadPart; - OldValidDataLength.QuadPart = FcbHeader->ValidDataLength.QuadPart; + if (NewSize.QuadPart > FcbHeader->FileSize.QuadPart) + { + FileSizeModified = TRUE; + OldFileSize.QuadPart = FcbHeader->FileSize.QuadPart; + OldValidDataLength.QuadPart = FcbHeader->ValidDataLength.QuadPart;
/* If the high part of the filesize is going * to change, grab the Paging IoResouce. */ if (NewSize.HighPart != FcbHeader->FileSize.HighPart && FcbHeader->PagingIoResource) - { - ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); - FcbHeader->FileSize.QuadPart = NewSize.QuadPart; - ExReleaseResourceLite(FcbHeader->PagingIoResource); + { + ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); + FcbHeader->FileSize.QuadPart = NewSize.QuadPart; + ExReleaseResourceLite(FcbHeader->PagingIoResource); } else { - FcbHeader->FileSize.QuadPart = NewSize.QuadPart; - } - } + FcbHeader->FileSize.QuadPart = NewSize.QuadPart; + } + }
/* Nagar p.544. * Set ourselves as top component. */ - PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; - _SEH2_TRY - { + PsGetCurrentThread()->TopLevelIrp = FSRTL_FAST_IO_TOP_LEVEL_IRP; + _SEH2_TRY + { /* Check if there is a gap between the end of the file and the offset. * If yes, then we have to zero the data. - */ + */ if (Offset.QuadPart > FcbHeader->ValidDataLength.QuadPart) { Result = CcZeroData(FileObject, &FcbHeader->ValidDataLength, &Offset, TRUE); - if (Result) - { + if (Result) + { CcPrepareMdlWrite(FileObject, &Offset, Length, MdlChain, IoStatus); - } + } } else { - CcPrepareMdlWrite(FileObject,&Offset,Length,MdlChain,IoStatus); - } + CcPrepareMdlWrite(FileObject, &Offset, Length, MdlChain, IoStatus); + }
} _SEH2_EXCEPT(FsRtlIsNtstatusExpected(_SEH2_GetExceptionCode()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) - { - Result = FALSE; + { + Result = FALSE; } _SEH2_END;
/* Reset the top component */ - PsGetCurrentThread()->TopLevelIrp = 0; + PsGetCurrentThread()->TopLevelIrp = 0;
/* Did the operation suceeded */ if (Result) { - /* Check if we need to update the filesize */ + /* Check if we need to update the filesize */ if (NewSize.QuadPart > FcbHeader->ValidDataLength.QuadPart) { if (NewSize.HighPart != FcbHeader->ValidDataLength.HighPart && FcbHeader->PagingIoResource) { - ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); - FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; - ExReleaseResourceLite(FcbHeader->PagingIoResource); + ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); + FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; + ExReleaseResourceLite(FcbHeader->PagingIoResource); } else { - FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; - } - } + FcbHeader->ValidDataLength.QuadPart = NewSize.QuadPart; + } + }
/* Flag the file as modified */ - FileObject->Flags |= FO_FILE_MODIFIED; - - /* Check if the filesize has changed */ + FileObject->Flags |= FO_FILE_MODIFIED; + + /* Check if the filesize has changed */ if (FileSizeModified) { SharedCacheMap = (PSHARED_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap; SharedCacheMap->FileSize.QuadPart = NewSize.QuadPart; - FileObject->Flags |= FO_FILE_SIZE_CHANGED; - } - } - else - { + FileObject->Flags |= FO_FILE_SIZE_CHANGED; + } + } + else + { /* The operation did not succeed. * Reset the file size to what it should be. - */ + */ if (FileSizeModified) { if (FcbHeader->PagingIoResource) { - ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); - FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; - FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; - ExReleaseResourceLite(FcbHeader->PagingIoResource); + ExAcquireResourceExclusiveLite(FcbHeader->PagingIoResource, TRUE); + FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; + FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; + ExReleaseResourceLite(FcbHeader->PagingIoResource); } else { - FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; - FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; - } - } - } - - goto Cleanup; + FcbHeader->FileSize.QuadPart = OldFileSize.QuadPart; + FcbHeader->ValidDataLength.QuadPart = OldValidDataLength.QuadPart; + } + } + } + + goto Cleanup; } else {