AFSNameArrayHdr *pNameArray = NULL;
AFSVolumeCB *pVolumeCB = NULL;
AFSDirectoryCB *pParentDirectoryCB = NULL, *pDirectoryCB = NULL;
+ BOOLEAN bReleaseParentDir = FALSE, bReleaseDir = FALSE;
ULONG ulParseFlags = 0;
GUID stAuthGroup = {0};
ULONG ulNameProcessingFlags = 0;
try_return( ntStatus);
}
+ if ( pParentDirectoryCB != NULL)
+ {
+
+ bReleaseParentDir = TRUE;
+ }
+
//
// If the returned volume cb is NULL then we are dealing with the \\Server\GlobalRoot
// name
TRUE) == 0)
{
+ //
+ // AFSOpenIOCtlFcb does not free a DirOpenReferenceCount for
+ // AFSGlobalRoot->DirectoryCB.
+ //
+
ntStatus = AFSOpenIOCtlFcb( Irp,
&stAuthGroup,
AFSGlobalRoot->DirectoryCB,
ntStatus);
}
}
- else if( pParentDirectoryCB != NULL &&
- pParentDirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SPECIAL_SHARE_NAME)
+ else if( pParentDirectoryCB != NULL)
{
- ntStatus = AFSOpenSpecialShareFcb( Irp,
- &stAuthGroup,
- pParentDirectoryCB,
- &pFcb,
- &pCcb);
-
- if( !NT_SUCCESS( ntStatus))
+ if( pParentDirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SPECIAL_SHARE_NAME)
{
- AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
- AFS_TRACE_LEVEL_ERROR,
- "AFSCommonCreate Failed to open special share Fcb Status %08lX\n",
- ntStatus);
+ ntStatus = AFSOpenSpecialShareFcb( Irp,
+ &stAuthGroup,
+ pParentDirectoryCB,
+ &pFcb,
+ &pCcb);
+
+ if( !NT_SUCCESS( ntStatus))
+ {
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+ AFS_TRACE_LEVEL_ERROR,
+ "AFSCommonCreate Failed to open special share Fcb Status %08lX\n",
+ ntStatus);
+ }
}
}
AFS_TRACE_LEVEL_ERROR,
"AFSCommonCreate Failed to open root Status %08lX\n",
ntStatus);
-
- lCount = InterlockedDecrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement1 count on &wZ DE %p Ccb %p Cnt %d\n",
- &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
- AFSGlobalRoot->DirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
}
try_return( ntStatus);
}
//
- // The routine above released the root while walking the
+ // AFSLocateNameEntry released the Parent while walking the
// branch
//
bReleaseVolume = FALSE;
+ bReleaseParentDir = FALSE;
+
try_return( ntStatus);
}
bReleaseVolume = FALSE;
+ bReleaseParentDir = FALSE;
+
try_return( ntStatus);
}
pParentDirectoryCB != NULL)
{
+ //
+ // pParentDirectoryCB DirOpenReferenceCount is still held
+ //
+
UNICODE_STRING uniFinalComponent;
uniFinalComponent.Length = 0;
try_return( ntStatus);
}
}
+ else
+ {
+
+ //
+ // AFSLocateNameEntry succeeded. The parent directory reference
+ // has been released and if there is a directory returned, it is
+ // referenced.
+ //
+
+ bReleaseParentDir = FALSE;
+
+ if ( pDirectoryCB)
+ {
+
+ bReleaseDir = TRUE;
+ }
+ }
}
//
{
pDirectoryCB = pVolumeCB->DirectoryCB;
+
+ lCount = InterlockedIncrement( &pDirectoryCB->DirOpenReferenceCount);
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonCreate Increment0 count on %wZ DE %p Ccb %p Cnt %d\n",
+ &pDirectoryCB->NameInformation.FileName,
+ pDirectoryCB,
+ pCcb,
+ lCount);
+
+ bReleaseDir = TRUE;
}
if( bOpenTargetDirectory)
if( pDirectoryCB != NULL)
{
- //
- // Perform in this order to prevent thrashing
- //
+ if ( !bReleaseParentDir)
+ {
- lCount = InterlockedIncrement( &pParentDirectoryCB->DirOpenReferenceCount);
+ //
+ // Perform in this order to prevent thrashing
+ //
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pParentDirectoryCB->NameInformation.FileName,
- pParentDirectoryCB,
- NULL,
- lCount);
+ lCount = InterlockedIncrement( &pParentDirectoryCB->DirOpenReferenceCount);
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonCreate Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
+ &pParentDirectoryCB->NameInformation.FileName,
+ pParentDirectoryCB,
+ pCcb,
+ lCount);
+
+ bReleaseParentDir = TRUE;
+ }
//
// Do NOT decrement the reference count on the pDirectoryCB yet.
&uniComponentName,
&pFcb,
&pCcb);
- if( pDirectoryCB != NULL)
- {
- //
- // It is now safe to drop the Reference Count
- //
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
- }
if( !NT_SUCCESS( ntStatus))
{
"AFSCommonCreate Failed to open target directory %wZ Status %08lX\n",
&pParentDirectoryCB->NameInformation.FileName,
ntStatus);
-
- //
- // Decrement the reference on the parent
- //
-
- lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement3 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pParentDirectoryCB->NameInformation.FileName,
- pParentDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
}
try_return( ntStatus);
"AFSCommonCreate Object name collision on create of %wZ Status %08lX\n",
&pDirectoryCB->NameInformation.FileName,
ntStatus);
-
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement4 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
}
else
{
AFS_TRACE_LEVEL_VERBOSE,
"AFSCommonCreate Object name collision on create Status %08lX\n",
ntStatus);
-
- lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement5 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pParentDirectoryCB->NameInformation.FileName,
- pParentDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
}
try_return( ntStatus = STATUS_OBJECT_NAME_COLLISION);
ntStatus);
}
- //
- // Dereference the parent entry
- //
-
- lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCreate Decrement6 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pParentDirectoryCB->NameInformation.FileName,
- pParentDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
-
try_return( ntStatus);
}
TRUE) == 0)
{
+ //
+ // AFSOpenIOCtlFcb does not free a DirOpenReferenceCount for
+ // pParentDirectoryCB.
+ //
+
ntStatus = AFSOpenIOCtlFcb( Irp,
&stAuthGroup,
pParentDirectoryCB,
ntStatus = STATUS_OBJECT_NAME_NOT_FOUND;
}
- if( !NT_SUCCESS( ntStatus))
- {
-
- //
- // Dereference the parent entry
- //
-
- if( pDirectoryCB != NULL)
- {
-
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement7a count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
- }
- else
- {
-
- lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement7b count on %wZ DE %p Ccb %p Cnt %d\n",
- &pParentDirectoryCB->NameInformation.FileName,
- pParentDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
- }
- }
-
try_return( ntStatus);
}
"AFSCommonCreate (%p) Attempt to open root as delete on close\n",
Irp);
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement8 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
-
try_return( ntStatus = STATUS_CANNOT_DELETE);
}
"AFSCommonCreate (%p) Attempt to open root as target directory\n",
Irp);
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement9 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
-
try_return( ntStatus = STATUS_INVALID_PARAMETER);
}
pVolumeCB->ObjectInformation.FileId.Cell,
pVolumeCB->ObjectInformation.FileId.Volume,
ntStatus);
-
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement10 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
}
try_return( ntStatus);
"AFSCommonCreate Failed overwrite/supersede on %wZ Status %08lX\n",
&pDirectoryCB->NameInformation.FileName,
ntStatus);
-
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement11 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
}
try_return( ntStatus);
"AFSCommonCreate Failed open on %wZ Status %08lX\n",
&pDirectoryCB->NameInformation.FileName,
ntStatus);
-
- lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonCreate Decrement12 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirectoryCB->NameInformation.FileName,
- pDirectoryCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
}
try_exit:
lCount);
}
+ if ( bReleaseDir)
+ {
+
+ //
+ // Release the reference from AFSLocateNameEntry
+ //
+
+ lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonCreate Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+ &pDirectoryCB->NameInformation.FileName,
+ pDirectoryCB,
+ pCcb,
+ lCount);
+
+ ASSERT( lCount >= 0);
+ }
+
+ if ( bReleaseParentDir)
+ {
+
+ //
+ // Release the reference from AFSLocateNameEntry
+ //
+
+ lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonCreate Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+ &pParentDirectoryCB->NameInformation.FileName,
+ pParentDirectoryCB,
+ pCcb,
+ lCount);
+
+ ASSERT( lCount >= 0);
+ }
+
//
// Setup the Irp for completion, the Information has been set previously
//
return ntStatus;
}
+//
+// AFSOpenIOCtlFcb does not release a DirOpenReferenceCount on
+// the ParentDirCB.
+//
+
NTSTATUS
AFSOpenIOCtlFcb( IN PIRP Irp,
IN GUID *AuthGroup,
}
//
- // Reference the directory entry
- //
-
- lCount = InterlockedIncrement( &((*Ccb)->DirectoryCB->DirOpenReferenceCount));
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSOpenIOCtlFcb Increment count on %wZ DE %p Ccb %p Cnt %d\n",
- &(*Ccb)->DirectoryCB->NameInformation.FileName,
- (*Ccb)->DirectoryCB,
- (*Ccb),
- lCount);
-
- //
// Increment the handle on the node
//
try_exit:
//
- //Dereference the passed in parent since the returned dir entry
- // is already referenced
- //
-
- lCount = InterlockedDecrement( &ParentDirCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSOpenIOCtlFcb Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
- &ParentDirCB->NameInformation.FileName,
- ParentDirCB,
- NULL,
- lCount);
-
- ASSERT( lCount >= 0);
-
- //
// If we created the Fcb we need to release the resources
//
ULONG ulBytesRemainingInBuffer;
+ //
+ // Drop the DirOpenReferenceCount held during a prior
+ // execution of the loop
+ //
+
+ if ( pDirEntry != NULL)
+ {
+
+ lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSQueryDirectory Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+ &pDirEntry->NameInformation.FileName,
+ pDirEntry,
+ pCcb,
+ lCount);
+
+ ASSERT( lCount >= 0);
+
+ pDirEntry = NULL;
+ }
+
ulAdditionalAttributes = 0;
//
try_return( ntStatus);
}
+ //
+ // On Success, pDirEntry has a held DirOpenReferenceCount
+ //
+
pDirEntry = AFSLocateNextDirEntry( pFcb->ObjectInformation,
pCcb);
BooleanFlagOn( pDirEntry->Flags, AFS_DIR_ENTRY_DELETED))
{
- lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSQueryDirectory Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- pCcb,
- lCount);
-
- ASSERT( lCount >= 0);
-
continue;
}
if( !FlagOn( pObjectInfo->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
{
- lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSQueryDirectory Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- pCcb,
- lCount);
-
- ASSERT( lCount >= 0);
-
continue;
}
}
NULL))
{
- lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSQueryDirectory Decrement3 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- pCcb,
- lCount);
-
- ASSERT( lCount >= 0);
-
continue;
}
}
TRUE))
{
- lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSQueryDirectory Decrement4 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- pCcb,
- lCount);
-
- ASSERT( lCount >= 0);
-
continue;
}
}
pCcb->CurrentDirIndex--;
- lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSQueryDirectory Decrement5 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- pCcb,
- lCount);
-
- ASSERT( lCount >= 0);
-
try_return( ntStatus = STATUS_SUCCESS);
}
break;
}
+
default:
{
AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
Irp,
FileInformationClass);
- lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSQueryDirectory Decrement6 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- pCcb,
- lCount);
-
- ASSERT( lCount >= 0);
-
try_return( ntStatus = STATUS_INVALID_INFO_CLASS);
-
- break;
}
}
if( ulBytesConverted < pDirEntry->NameInformation.FileName.Length)
{
- lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+ try_return( ntStatus = STATUS_BUFFER_OVERFLOW);
+ }
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSQueryDirectory Decrement7 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- pCcb,
- lCount);
+ dStatus = STATUS_SUCCESS;
- ASSERT( lCount >= 0);
+ // Set ourselves up for the next iteration
+ ulLastEntry = ulNextEntry;
+ ulNextEntry += (ULONG)QuadAlign( ulBaseLength + ulBytesConverted);
+ }
- try_return( ntStatus = STATUS_BUFFER_OVERFLOW);
- }
+try_exit:
+
+ if ( pDirEntry != NULL)
+ {
lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
lCount);
ASSERT( lCount >= 0);
-
- dStatus = STATUS_SUCCESS;
-
- // Set ourselves up for the next iteration
- ulLastEntry = ulNextEntry;
- ulNextEntry += (ULONG)QuadAlign( ulBaseLength + ulBytesConverted);
}
-try_exit:
-
if( bReleaseMain)
{
pDirEntry = ObjectInfo->Specific.Directory.PIOCtlDirectoryCB;
- if( pDirEntry != NULL)
- {
-
- lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSLocateNextDirEntry Increment count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- Ccb,
- lCount);
-
- ASSERT( lCount >= 0);
- }
-
AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
"AFSLocateNextDirEntry Returning PIOctl entry %wZ in parent FID %08lX-%08lX-%08lX-%08lX\n",
pDirEntry = AFSGlobalDotDirEntry;
- if( pDirEntry != NULL)
- {
-
- lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSLocateNextDirEntry Increment2 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- Ccb,
- lCount);
-
- ASSERT( lCount >= 0);
- }
-
AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
"AFSLocateNextDirEntry Returning1 snapshot entry %wZ in parent FID %08lX-%08lX-%08lX-%08lX\n",
pDirEntry = AFSGlobalDotDotDirEntry;
- if( pDirEntry != NULL)
- {
-
- lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSLocateNextDirEntry Increment3 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- Ccb,
- lCount);
-
- ASSERT( lCount >= 0);
- }
-
AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
"AFSLocateNextDirEntry Returning2 snapshot entry %wZ in parent FID %08lX-%08lX-%08lX-%08lX\n",
ObjectInfo->FileId.Volume,
ObjectInfo->FileId.Vnode,
ObjectInfo->FileId.Unique);
-
- lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSLocateNextDirEntry Increment4 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- Ccb,
- lCount);
-
- ASSERT( lCount >= 0);
}
else
{
try_exit:
+ if( pDirEntry != NULL)
+ {
+
+ lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSLocateNextDirEntry Increment count on %wZ DE %p Ccb %p Cnt %d\n",
+ &pDirEntry->NameInformation.FileName,
+ pDirEntry,
+ Ccb,
+ lCount);
+
+ ASSERT( lCount >= 0);
+ }
+
AFSReleaseResource( &Ccb->NPCcb->CcbLock);
AFSReleaseResource( ObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
//
// Pass back the target dir entry for this request
+ // The caller must release the DirOpenReferenceCount
//
*TargetDirEntry = pDirectoryEntry;
&uniParsedName,
pNameArray,
AFS_LOCATE_FLAGS_NO_MP_TARGET_EVAL |
- AFS_LOCATE_FLAGS_NO_SL_TARGET_EVAL,
+ AFS_LOCATE_FLAGS_NO_SL_TARGET_EVAL,
&pVolumeCB,
&pParentDirEntry,
&pDirectoryEntry,
}
//
- // Remove the reference made above
+ // Remove the reference obtained from AFSLocateNameEntry
//
lCount = InterlockedDecrement( &pDirectoryEntry->DirOpenReferenceCount);
#include "AFSCommon.h"
+//
+// AFSLocateNameEntry
+//
+// On entry, *VolumeCB must have a held ReferenceCount provided by
+// the caller which will be released. On successful exit, *VolumeCB
+// will be assigned the new current volume with a held ReferenceCount.
+//
+// On entry, *ParentDirectoryCB must have a held DirOpenReferenceCount
+// provided by the caller.
+//
+
NTSTATUS
AFSLocateNameEntry( IN GUID *AuthGroup,
IN PFILE_OBJECT FileObject,
try_return( ntStatus);
}
+ //
+ // If AFSNotifyFileCreate returns pDirNode != NULL, then its
+ // DirOpenReferenceCount is held.
+ //
+
AFSAcquireExcl( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock,
TRUE);
&pExistingDirNode->ObjectInformation->FileId))
{
- AFSDeleteDirEntry( ParentObjectInfo,
- pDirNode);
+ if ( pExistingDirNode != pDirNode)
+ {
- lCount = InterlockedIncrement( &pExistingDirNode->DirOpenReferenceCount);
+ lCount = InterlockedDecrement( &pDirNode->DirOpenReferenceCount);
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCreateDirEntry Increment count on %wZ DE %p Cnt %d\n",
- &pExistingDirNode->NameInformation.FileName,
- pExistingDirNode,
- lCount);
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCreateDirEntry Decrement count on %wZ DE %p Cnt %d\n",
+ &pDirNode->NameInformation.FileName,
+ pDirNode,
+ lCount);
+
+ AFSDeleteDirEntry( ParentObjectInfo,
+ pDirNode);
+
+ lCount = InterlockedIncrement( &pExistingDirNode->DirOpenReferenceCount);
- *DirEntry = pExistingDirNode;
+ AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCreateDirEntry Increment count on %wZ DE %p Cnt %d\n",
+ &pExistingDirNode->NameInformation.FileName,
+ pExistingDirNode,
+ lCount);
+
+ *DirEntry = pExistingDirNode;
+ }
AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
AFSRemoveNameEntry( ParentObjectInfo,
pExistingDirNode);
}
-
}
}
pDirNode,
TRUE);
- lCount = InterlockedIncrement( &pDirNode->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCreateDirEntry Increment2 count on %wZ DE %p Cnt %d\n",
- &pDirNode->NameInformation.FileName,
- pDirNode,
- lCount);
-
//
// Pass back the dir entry
//
*ParseFlags = AFS_PARSE_FLAG_ROOT_ACCESS;
+ *ParentDirectoryCB = NULL;
+
if( pIrpSp->FileObject->RelatedFileObject != NULL)
{
RtlCopyMemory( &uniFullName.Buffer[ uniFullName.Length/sizeof( WCHAR)],
pIrpSp->FileObject->FileName.Buffer,
- pIr\epSp->FileObject->FileName.Length);
+ pIrpSp->FileObject->FileName.Length);
uniFullName.Length += pIrpSp->FileObject->FileName.Length;
}
*NameArray = pNameArray;
- *VolumeCB = pVolumeCB;
-
//
// Increment our volume reference count
//
pVolumeCB,
lCount);
- *ParentDirectoryCB = pDirEntry;
-
- lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+ *VolumeCB = pVolumeCB;
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSParseName Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- NULL,
- lCount);
+ *ParentDirectoryCB = pDirEntry;
AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE_2,
}
//
- // Check for the \\Server access and return it as though it where \\Server\Globalroot
+ // Check for the \\Server access and return it as though it were \\Server\Globalroot
//
if( uniRemainingPath.Buffer == NULL ||
*FileName = uniComponentName;
- *ParentDirectoryCB = pDirEntry;
-
ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
- lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSParseName Increment5 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pDirEntry->NameInformation.FileName,
- pDirEntry,
- NULL,
- lCount);
+ *ParentDirectoryCB = pDirEntry;
try_return( ntStatus = STATUS_SUCCESS);
}
//
// This is a root open so pass back no parent
//
-
- *ParentDirectoryCB = NULL;
}
}
else
uniRemainingPath.Length += sizeof( WCHAR);
uniRemainingPath.MaximumLength += sizeof( WCHAR);
- lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->DirOpenReferenceCount);
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSParseName Increment6 count on %wZ DE %p Ccb %p Cnt %d\n",
- &pVolumeCB->DirectoryCB->NameInformation.FileName,
- pVolumeCB->DirectoryCB,
- NULL,
- lCount);
-
//
// Pass back the parent being the volume root
//
*ParentDirectoryCB = pVolumeCB->DirectoryCB;
-
}
//
if( *ParentDirectoryCB != NULL)
{
+ lCount = InterlockedIncrement( &(*ParentDirectoryCB)->DirOpenReferenceCount);
+
AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSParseName Count on %wZ DE %p Ccb %p Cnt %d\n",
+ "AFSParseName Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
&(*ParentDirectoryCB)->NameInformation.FileName,
- *ParentDirectoryCB,
+ (*ParentDirectoryCB),
NULL,
- (*ParentDirectoryCB)->DirOpenReferenceCount);
+ lCount);
}
}
//
// Setup the request to evaluate the entry
+ // On success, pTargetDirEntry has the DirOpenReferenceCount held
//
ntStatus = AFSEvaluateRootEntry( pShareDirEntry,
pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
}
+ //
+ // Release the DirOpenReferenceCount obtained from AFSEvaluateRootEntry
+ //
+
lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,