From 9b3c7b41926758ed9060664a3da93820054db550 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 29 Dec 2012 00:17:59 -0500 Subject: [PATCH] Windows: AFSInitCcb redefinition The new AFSInitCcb() allocates its own DirOpenReferenceCount to associate with the AFSCcb.DirectoryCB. It also accepts the GrantedAccess mask and the FileAccess values which are stored in the AFSCcb. These changes simplify the callers and remove responsibility of tracking whether or not the DirOpenReferenceCount was successfully associated with the AFSCcb. The allocated DirOpenReferenceCount is always released by AFSRemoveCcb(). Change-Id: Ib475310d934830974c553e0eeff96b114a56541b Reviewed-on: http://gerrit.openafs.org/8852 Reviewed-by: Derrick Brashear Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp | 96 +++++++------------ src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp | 40 +++++++- .../afsrdr/kernel/lib/Include/AFSCommon.h | 5 +- 3 files changed, 75 insertions(+), 66 deletions(-) diff --git a/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp b/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp index 61eaa22cc..ba1e642c7 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp @@ -1314,7 +1314,10 @@ AFSOpenAFSRoot( IN PIRP Irp, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + AFSGlobalRoot->DirectoryCB, + 0, + 0); if( !NT_SUCCESS( ntStatus)) { @@ -1327,12 +1330,6 @@ AFSOpenAFSRoot( IN PIRP Irp, try_return( ntStatus); } - // - // Setup the Ccb - // - - (*Ccb)->DirectoryCB = AFSGlobalRoot->DirectoryCB; - // // Increment the open count on this Fcb // @@ -1584,7 +1581,10 @@ AFSOpenRoot( IN PIRP Irp, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + VolumeCB->DirectoryCB, + *pDesiredAccess, + 0); if( !NT_SUCCESS( ntStatus)) { @@ -1600,14 +1600,6 @@ AFSOpenRoot( IN PIRP Irp, bAllocatedCcb = TRUE; - // - // Setup the ccb - // - - (*Ccb)->DirectoryCB = VolumeCB->DirectoryCB; - - (*Ccb)->GrantedAccess = *pDesiredAccess; - // // OK, update the share access on the fileobject // @@ -1944,7 +1936,10 @@ AFSProcessCreate( IN PIRP Irp, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + pDirEntry, + *pDesiredAccess, + 0); if( !NT_SUCCESS( ntStatus)) { @@ -1961,14 +1956,6 @@ AFSProcessCreate( IN PIRP Irp, bAllocatedCcb = TRUE; - // - // Initialize the Ccb - // - - (*Ccb)->DirectoryCB = pDirEntry; - - (*Ccb)->GrantedAccess = *pDesiredAccess; - // // If this is a file, update the headers filesizes. // @@ -2328,7 +2315,10 @@ AFSOpenTargetDirectory( IN PIRP Irp, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + ParentDirectoryCB, + *pDesiredAccess, + 0); if( !NT_SUCCESS( ntStatus)) { @@ -2345,14 +2335,6 @@ AFSOpenTargetDirectory( IN PIRP Irp, bAllocatedCcb = TRUE; - // - // Initialize the Ccb - // - - (*Ccb)->DirectoryCB = ParentDirectoryCB; - - (*Ccb)->GrantedAccess = *pDesiredAccess; - if( TargetDirectoryCB != NULL && FsRtlAreNamesEqual( &TargetDirectoryCB->NameInformation.FileName, TargetName, @@ -2838,7 +2820,10 @@ AFSProcessOpen( IN PIRP Irp, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + DirectoryCB, + *pDesiredAccess, + ulFileAccess); if( !NT_SUCCESS( ntStatus)) { @@ -2855,12 +2840,6 @@ AFSProcessOpen( IN PIRP Irp, bAllocatedCcb = TRUE; - (*Ccb)->DirectoryCB = DirectoryCB; - - (*Ccb)->FileAccess = ulFileAccess; - - (*Ccb)->GrantedAccess = *pDesiredAccess; - // // Perform the access check on the target if this is a mount point or symlink // @@ -3197,7 +3176,10 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + DirectoryCB, + *pDesiredAccess, + 0); if( !NT_SUCCESS( ntStatus)) { @@ -3214,14 +3196,6 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject, bAllocatedCcb = TRUE; - // - // Initialize the Ccb - // - - (*Ccb)->DirectoryCB = DirectoryCB; - - (*Ccb)->GrantedAccess = *pDesiredAccess; - // // Set the file length to zero // @@ -3552,7 +3526,10 @@ AFSOpenIOCtlFcb( IN PIRP Irp, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + pParentObjectInfo->Specific.Directory.PIOCtlDirectoryCB, + 0, + 0); if( !NT_SUCCESS( ntStatus)) { @@ -3568,12 +3545,6 @@ AFSOpenIOCtlFcb( IN PIRP Irp, bAllocatedCcb = TRUE; - // - // Setup the Ccb - // - - (*Ccb)->DirectoryCB = pParentObjectInfo->Specific.Directory.PIOCtlDirectoryCB; - // // Set the PIOCtl index // @@ -3828,7 +3799,10 @@ AFSOpenSpecialShareFcb( IN PIRP Irp, // Initialize the Ccb for the file. // - ntStatus = AFSInitCcb( Ccb); + ntStatus = AFSInitCcb( Ccb, + DirectoryCB, + 0, + 0); if( !NT_SUCCESS( ntStatus)) { @@ -3844,12 +3818,6 @@ AFSOpenSpecialShareFcb( IN PIRP Irp, bAllocatedCcb = TRUE; - // - // Setup the Ccb - // - - (*Ccb)->DirectoryCB = DirectoryCB; - // // Call the service to open the share // diff --git a/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp b/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp index 25dc99332..0546781fa 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp @@ -1141,11 +1141,15 @@ AFSRemoveFcb( IN AFSFcb **ppFcb) } NTSTATUS -AFSInitCcb( IN OUT AFSCcb **Ccb) +AFSInitCcb( IN OUT AFSCcb **Ccb, + IN AFSDirectoryCB *DirectoryCB, + IN ACCESS_MASK GrantedAccess, + IN ULONG FileAccess) { NTSTATUS Status = STATUS_SUCCESS; AFSCcb *pCcb = NULL; + LONG lCount; __Enter { @@ -1191,6 +1195,22 @@ AFSInitCcb( IN OUT AFSCcb **Ccb) ExInitializeResourceLite( &pCcb->NPCcb->CcbLock); + pCcb->DirectoryCB = DirectoryCB; + + lCount = InterlockedIncrement( &pCcb->DirectoryCB->DirOpenReferenceCount); + + AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING, + AFS_TRACE_LEVEL_VERBOSE, + "AFSInitCcb Increment count on %wZ DE %p Ccb %p Cnt %d\n", + &pCcb->DirectoryCB->NameInformation.FileName, + pCcb->DirectoryCB, + pCcb, + lCount); + + pCcb->GrantedAccess = GrantedAccess; + + pCcb->FileAccess = FileAccess; + // // Return the Ccb // @@ -1238,6 +1258,8 @@ AFSRemoveCcb( IN AFSFcb *Fcb, IN AFSCcb *Ccb) { + LONG lCount; + AFSAcquireExcl( &Ccb->NPCcb->CcbLock, TRUE); @@ -1319,6 +1341,22 @@ AFSRemoveCcb( IN AFSFcb *Fcb, AFSExFreePoolWithTag( Ccb->NotifyMask.Buffer, AFS_GENERIC_MEMORY_7_TAG); } + if ( Ccb->DirectoryCB != NULL) + { + + lCount = InterlockedDecrement( &Ccb->DirectoryCB->DirOpenReferenceCount); + + AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING, + AFS_TRACE_LEVEL_VERBOSE, + "AFSRemoveCcb Decrement count on %wZ DE %p Ccb %p Cnt %d\n", + &Ccb->DirectoryCB->NameInformation.FileName, + Ccb->DirectoryCB, + Ccb, + lCount); + + ASSERT( lCount >= 0); + } + AFSReleaseResource( &Ccb->NPCcb->CcbLock); // diff --git a/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h b/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h index ee25a3c66..c44585d20 100644 --- a/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h +++ b/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h @@ -540,7 +540,10 @@ void AFSRemoveRootFcb( IN AFSFcb *RootFcb); NTSTATUS -AFSInitCcb( IN OUT AFSCcb **Ccb); +AFSInitCcb( IN OUT AFSCcb **Ccb, + IN AFSDirectoryCB *DirectoryCB, + IN ACCESS_MASK GrantedAccess, + IN ULONG FileAccess); void AFSRemoveFcb( IN AFSFcb **Fcb); -- 2.39.5