diff --git a/src/WINNT/afsrdr/common/AFSRedirCommonDefines.h b/src/WINNT/afsrdr/common/AFSRedirCommonDefines.h index 4772fad573..9b506216da 100644 --- a/src/WINNT/afsrdr/common/AFSRedirCommonDefines.h +++ b/src/WINNT/afsrdr/common/AFSRedirCommonDefines.h @@ -77,6 +77,7 @@ #define AFS_VCB_ALLOCATION_TAG 'CVFA' #define AFS_VCB_NP_ALLOCATION_TAG 'NVFA' #define AFS_CCB_ALLOCATION_TAG 'CCFA' +#define AFS_CCB_NP_ALLOCATION_TAG 'NCFA' #define AFS_WORKER_CB_TAG 'CWFA' #define AFS_WORK_ITEM_TAG 'IWFA' #define AFS_POOL_ENTRY_TAG 'EPFA' diff --git a/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp b/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp index 325dd87718..ec415440c5 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp @@ -1050,6 +1050,9 @@ try_exit: if( pCcb != NULL) { + AFSAcquireExcl( &pCcb->NPCcb->CcbLock, + TRUE); + RtlCopyMemory( &pCcb->AuthGroup, &stAuthGroup, sizeof( GUID)); @@ -1111,6 +1114,8 @@ try_exit: pCcb->NameArray = pNameArray; pNameArray = NULL; + + AFSReleaseResource( &pCcb->NPCcb->CcbLock); } // diff --git a/src/WINNT/afsrdr/kernel/lib/AFSDirControl.cpp b/src/WINNT/afsrdr/kernel/lib/AFSDirControl.cpp index d9e3e9668e..e67de20b89 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSDirControl.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSDirControl.cpp @@ -296,10 +296,15 @@ AFSQueryDirectory( IN PIRP Irp) // Perform a new snapshot of the directory // + AFSAcquireExcl( &pCcb->NPCcb->CcbLock, + TRUE); + ntStatus = AFSSnapshotDirectory( pFcb, pCcb, FALSE); + AFSReleaseResource( &pCcb->NPCcb->CcbLock); + if( !NT_SUCCESS( ntStatus)) { @@ -337,6 +342,9 @@ AFSQueryDirectory( IN PIRP Irp) try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES); } + AFSAcquireExcl( &pCcb->NPCcb->CcbLock, + TRUE); + // Check if initial on this map if( bInitialQuery) { @@ -348,6 +356,8 @@ AFSQueryDirectory( IN PIRP Irp) if( !NT_SUCCESS( ntStatus)) { + AFSReleaseResource( &pCcb->NPCcb->CcbLock); + AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING, AFS_TRACE_LEVEL_ERROR, "AFSQueryDirectory Snapshot directory failure for parent %wZ Mask %wZ Status %08lX\n", @@ -462,6 +472,8 @@ AFSQueryDirectory( IN PIRP Irp) if( pFcb->ObjectInformation->Specific.Directory.PIOCtlDirectoryCB == NULL) { + AFSReleaseResource( &pCcb->NPCcb->CcbLock); + AFSReleaseResource( pFcb->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock); bReleaseMain = FALSE; @@ -496,6 +508,9 @@ AFSQueryDirectory( IN PIRP Irp) bReleaseMain = TRUE; AFSReleaseResource( &pFcb->NPFcb->Resource); + + AFSAcquireExcl( &pCcb->NPCcb->CcbLock, + TRUE); } } @@ -538,6 +553,12 @@ AFSQueryDirectory( IN PIRP Irp) } } + AFSReleaseResource( &pCcb->NPCcb->CcbLock); + + AFSReleaseResource( pFcb->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock); + + bReleaseMain = FALSE; + switch( FileInformationClass) { @@ -590,10 +611,6 @@ AFSQueryDirectory( IN PIRP Irp) try_return( ntStatus = STATUS_INVALID_INFO_CLASS); } - AFSReleaseResource( pFcb->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock); - - bReleaseMain = FALSE; - while( TRUE) { @@ -1094,6 +1111,12 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo, __Enter { + AFSAcquireShared( ObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock, + TRUE); + + AFSAcquireExcl( &Ccb->NPCcb->CcbLock, + TRUE); + // // Is this a PIOCtl query // @@ -1203,9 +1226,6 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo, // Get to a valid entry // - AFSAcquireShared( ObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock, - TRUE); - while( ulCount < pSnapshotHdr->EntryCount) { @@ -1276,13 +1296,13 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo, Ccb->CurrentDirIndex++; } - - AFSReleaseResource( ObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock); } try_exit: - NOTHING; + AFSReleaseResource( &Ccb->NPCcb->CcbLock); + + AFSReleaseResource( ObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock); } return pDirEntry; @@ -1303,6 +1323,9 @@ AFSLocateDirEntryByIndex( IN AFSObjectInfoCB *ObjectInfo, __Enter { + AFSAcquireExcl( &Ccb->NPCcb->CcbLock, + TRUE); + Ccb->CurrentDirIndex = DirIndex; if( DirIndex == (ULONG)AFS_DIR_ENTRY_DOT_INDEX) @@ -1374,7 +1397,7 @@ AFSLocateDirEntryByIndex( IN AFSObjectInfoCB *ObjectInfo, try_exit: - NOTHING; + AFSReleaseResource( &Ccb->NPCcb->CcbLock); } return pDirEntry; @@ -1541,6 +1564,9 @@ AFSFsRtlNotifyFullChangeDirectory( IN AFSObjectInfoCB *ObjectInfo, __Enter { + AFSAcquireExcl( &Ccb->NPCcb->CcbLock, + TRUE); + // // Build a dir name based on the FID of the file // @@ -1621,6 +1647,8 @@ try_exit: Ccb->NotifyMask.Buffer = NULL; } } + + AFSReleaseResource( &Ccb->NPCcb->CcbLock); } return ntStatus; diff --git a/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp b/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp index 71f90c41a5..e9add10e90 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp @@ -1140,8 +1140,25 @@ AFSInitCcb( IN OUT AFSCcb **Ccb) sizeof( AFSCcb)); pCcb->Size = sizeof( AFSCcb); + pCcb->Type = AFS_CCB; + pCcb->NPCcb = (AFSNonPagedCcb *)AFSExAllocatePoolWithTag( NonPagedPool, + sizeof( AFSNonPagedCcb), + AFS_CCB_NP_ALLOCATION_TAG); + + if( pCcb->NPCcb == NULL) + { + + AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING, + AFS_TRACE_LEVEL_ERROR, + "AFSInitCcb Failed to allocate NPCcb\n"); + + try_return( Status = STATUS_INSUFFICIENT_RESOURCES); + } + + ExInitializeResourceLite( &pCcb->NPCcb->CcbLock); + // // Return the Ccb // @@ -1156,6 +1173,12 @@ try_exit: if( pCcb != NULL) { + if ( pCcb->NPCcb != NULL) + { + + AFSExFreePool( pCcb->NPCcb); + } + AFSExFreePool( pCcb); } @@ -1185,6 +1208,9 @@ AFSRemoveCcb( IN AFSFcb *Fcb, NTSTATUS ntStatus = STATUS_SUCCESS; + AFSAcquireExcl( &Ccb->NPCcb->CcbLock, + TRUE); + if( Fcb != NULL && BooleanFlagOn( Ccb->Flags, CCB_FLAG_INSERTED_CCB_LIST)) { @@ -1263,10 +1289,16 @@ AFSRemoveCcb( IN AFSFcb *Fcb, AFSExFreePool( Ccb->NotifyMask.Buffer); } + AFSReleaseResource( &Ccb->NPCcb->CcbLock); + // // Free up the Ccb // + ExDeleteResourceLite( &Ccb->NPCcb->CcbLock); + + AFSExFreePool( Ccb->NPCcb); + AFSExFreePool( Ccb); return ntStatus; @@ -1282,6 +1314,9 @@ AFSInsertCcb( IN AFSFcb *Fcb, AFSAcquireExcl( &Fcb->NPFcb->CcbListLock, TRUE); + AFSAcquireExcl( &Ccb->NPCcb->CcbLock, + TRUE); + if( Fcb->CcbListHead == NULL) { Fcb->CcbListHead = Ccb; @@ -1297,6 +1332,8 @@ AFSInsertCcb( IN AFSFcb *Fcb, SetFlag( Ccb->Flags, CCB_FLAG_INSERTED_CCB_LIST); + AFSReleaseResource( &Ccb->NPCcb->CcbLock); + AFSReleaseResource( &Fcb->NPFcb->CcbListLock); return ntStatus; diff --git a/src/WINNT/afsrdr/kernel/lib/Include/AFSStructs.h b/src/WINNT/afsrdr/kernel/lib/Include/AFSStructs.h index f3509423c3..b12c31833b 100644 --- a/src/WINNT/afsrdr/kernel/lib/Include/AFSStructs.h +++ b/src/WINNT/afsrdr/kernel/lib/Include/AFSStructs.h @@ -73,14 +73,25 @@ typedef struct _AFS_WORKER_QUEUE_HDR // These are the context control blocks for the open instance // +typedef struct _AFS_NONPAGED_CCB +{ + + ERESOURCE CcbLock; + +} AFSNonPagedCcb; + + typedef struct _AFS_CCB { USHORT Size; + USHORT Type; ULONG Flags; + AFSNonPagedCcb *NPCcb; + AFSListEntry ListEntry; //