//
ULONG
-AFSExceptionFilter( IN ULONG Code,
+AFSExceptionFilter( IN CHAR *FunctionString,
+ IN ULONG Code,
IN PEXCEPTION_POINTERS ExceptPtrs)
{
AFSDbgLogMsg( 0,
0,
- "AFSExceptionFilter (Framework) - EXR %p CXR %p Code %08lX Address %p\n",
+ "AFSExceptionFilter (Framework) - EXR %p CXR %p Function %s Code %08lX Address %p Routine %p\n",
ExceptRec,
Context,
+ FunctionString,
ExceptRec->ExceptionCode,
- ExceptRec->ExceptionAddress);
+ ExceptRec->ExceptionAddress,
+ (void *)AFSExceptionFilter);
DbgPrint("**** Exception Caught in AFS Redirector ****\n");
NotificationEvent,
TRUE);
+ pDeviceExt->Specific.Control.WaitingForMemoryCount = 0;
+
+ KeInitializeEvent( &pDeviceExt->Specific.Control.MemoryAvailableEvent,
+ NotificationEvent,
+ TRUE);
+
ExInitializeResourceLite( &pDeviceExt->Specific.Control.LibraryQueueLock);
pDeviceExt->Specific.Control.LibraryQueueHead = NULL;
AFSServerName.Buffer = NULL;
paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
- paramTable[0].Name = AFS_NETBIOS_NAME;
+ paramTable[0].Name = AFS_REG_NETBIOS_NAME;
paramTable[0].EntryContext = &AFSServerName;
paramTable[0].DefaultType = REG_NONE;
}
NTSTATUS
+AFSReadMountRootName()
+{
+
+ NTSTATUS ntStatus = STATUS_SUCCESS;
+ ULONG Default = 0;
+ UNICODE_STRING paramPath;
+ RTL_QUERY_REGISTRY_TABLE paramTable[2];
+
+ __Enter
+ {
+
+ //
+ // Setup the paramPath buffer.
+ //
+
+ paramPath.MaximumLength = PAGE_SIZE;
+ paramPath.Buffer = (PWSTR)AFSExAllocatePoolWithTag( PagedPool,
+ paramPath.MaximumLength,
+ AFS_GENERIC_MEMORY_17_TAG);
+
+ //
+ // If it exists, setup the path.
+ //
+
+ if( paramPath.Buffer == NULL)
+ {
+
+ try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
+ }
+
+ //
+ // Move in the paths
+ //
+
+ RtlZeroMemory( paramPath.Buffer,
+ paramPath.MaximumLength);
+
+ RtlCopyMemory( ¶mPath.Buffer[ 0],
+ L"\\TransarcAFSDaemon\\Parameters",
+ 58);
+
+ paramPath.Length = 58;
+
+ RtlZeroMemory( paramTable,
+ sizeof( paramTable));
+
+ //
+ // Setup the table to query the registry for the needed value
+ //
+
+ AFSMountRootName.Length = 0;
+ AFSMountRootName.MaximumLength = 0;
+ AFSMountRootName.Buffer = NULL;
+
+ paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
+ paramTable[0].Name = AFS_REG_MOUNT_ROOT;
+ paramTable[0].EntryContext = &AFSMountRootName;
+
+ paramTable[0].DefaultType = REG_NONE;
+ paramTable[0].DefaultData = NULL;
+ paramTable[0].DefaultLength = 0;
+
+ //
+ // Query the registry
+ //
+
+ ntStatus = RtlQueryRegistryValues( RTL_REGISTRY_SERVICES,
+ paramPath.Buffer,
+ paramTable,
+ NULL,
+ NULL);
+
+ if ( NT_SUCCESS( ntStatus))
+ {
+ if ( AFSMountRootName.Buffer[0] == L'/')
+ {
+
+ AFSMountRootName.Buffer[0] = L'\\';
+ }
+ }
+
+ //
+ // Free up the buffer
+ //
+
+ ExFreePool( paramPath.Buffer);
+
+try_exit:
+
+ if( !NT_SUCCESS( ntStatus))
+ {
+
+ RtlInitUnicodeString( &AFSMountRootName,
+ L"\\afs");
+ }
+ }
+
+ return ntStatus;
+}
+
+NTSTATUS
AFSSetSysNameInformation( IN AFSSysNameNotificationCB *SysNameInfo,
IN ULONG SysNameInfoBufferLength)
{
IN ULONG Tag)
{
+ AFSDeviceExt *pControlDevExt = NULL;
void *pBuffer = NULL;
+ BOOLEAN bTimeout = FALSE;
+ LARGE_INTEGER liTimeout;
+ NTSTATUS ntStatus;
- pBuffer = ExAllocatePoolWithTag( PoolType,
- NumberOfBytes,
- Tag);
+ //
+ // Attempt to allocation memory from the system. If the allocation fails
+ // wait up to 30 seconds for the AFS redirector to free some memory. As
+ // long as the wait does not timeout, continue to retry the allocation.
+ // If the wait does timeout, attempt to allocate one more time in case
+ // memory was freed by another driver. Otherwise, fail the request.
+ //
- if( pBuffer == NULL)
+ if ( AFSDeviceObject)
{
- AFSDbgLogMsg( 0,
- 0,
- "AFSExAllocatePoolWithTag failure Type %08lX Size %08lX Tag %08lX %08lX\n",
- PoolType,
- NumberOfBytes,
- Tag,
- PsGetCurrentThread());
+ pControlDevExt = (AFSDeviceExt *)AFSDeviceObject->DeviceExtension;
+ }
- switch ( Tag ) {
+ while( pBuffer == NULL)
+ {
- case AFS_GENERIC_MEMORY_21_TAG:
- case AFS_GENERIC_MEMORY_22_TAG:
- // AFSDumpTraceFiles -- do nothing;
- break;
+ pBuffer = ExAllocatePoolWithTag( PoolType,
+ NumberOfBytes,
+ Tag);
- default:
- AFSBreakPoint();
+ if( pBuffer == NULL)
+ {
+
+ if ( bTimeout || pControlDevExt == NULL)
+ {
+
+ AFSDbgLogMsg( 0,
+ 0,
+ "AFSExAllocatePoolWithTag failure Type %08lX Size %08lX Tag %08lX %08lX\n",
+ PoolType,
+ NumberOfBytes,
+ Tag,
+ PsGetCurrentThread());
+
+ switch ( Tag ) {
+
+ case AFS_GENERIC_MEMORY_21_TAG:
+ case AFS_GENERIC_MEMORY_22_TAG:
+ // AFSDumpTraceFiles -- do nothing;
+ break;
+
+ default:
+ AFSBreakPoint();
+ }
+
+ break;
+ }
+
+
+ //
+ // Wait up to 30 seconds for a memory deallocation
+ //
+
+ liTimeout.QuadPart = -(30 *AFS_ONE_SECOND);
+
+ if( InterlockedIncrement( &pControlDevExt->Specific.Control.WaitingForMemoryCount) == 1)
+ {
+ KeClearEvent( &pControlDevExt->Specific.Control.MemoryAvailableEvent);
+ }
+
+ ntStatus = KeWaitForSingleObject( &pControlDevExt->Specific.Control.MemoryAvailableEvent,
+ Executive,
+ KernelMode,
+ FALSE,
+ &liTimeout);
+
+ if( ntStatus == STATUS_TIMEOUT)
+ {
+
+ bTimeout = TRUE;
+ }
+
+ InterlockedDecrement( &pControlDevExt->Specific.Control.WaitingForMemoryCount);
}
}
}
void
-AFSExFreePool( IN void *Buffer)
+AFSExFreePoolWithTag( IN void *Buffer, IN ULONG Tag)
{
- ExFreePool( Buffer);
+ AFSDeviceExt *pControlDevExt = NULL;
+
+ if ( AFSDeviceObject)
+ {
+
+ pControlDevExt = (AFSDeviceExt *)AFSDeviceObject->DeviceExtension;
+ }
+ if ( Tag)
+ {
+
+ ExFreePoolWithTag( Buffer, Tag);
+ }
+ else
+ {
+
+ ExFreePool( Buffer);
+ }
+
+ if ( pControlDevExt)
+ {
+
+ KeSetEvent( &pControlDevExt->Specific.Control.MemoryAvailableEvent,
+ 0,
+ FALSE);
+ }
return;
}
BOOLEAN bStatus = FALSE;
AFSFcb *pFcb = (AFSFcb *)Fcb;
- BOOLEAN bReleaseMain = FALSE, bReleasePaging = FALSE;
+ BOOLEAN bReleaseSectionObject = FALSE, bReleasePaging = FALSE;
//
// Try and acquire the Fcb resource
"AFSAcquireFcbForLazyWrite Acquiring Fcb %08lX\n",
Fcb);
- ASSERT( NULL == pFcb->Specific.File.LazyWriterThread);
-
- pFcb->Specific.File.LazyWriterThread = PsGetCurrentThread();
+ //
+ // Try and grab the paging
+ //
AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb lock %08lX SHARED %08lX\n",
- &pFcb->NPFcb->Resource,
+ "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb PagingIo lock %08lX SHARED %08lX\n",
+ &pFcb->NPFcb->PagingResource,
PsGetCurrentThread());
- if( AFSAcquireShared( &pFcb->NPFcb->Resource,
+ if( AFSAcquireShared( &pFcb->NPFcb->PagingResource,
Wait))
{
AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSAcquireFcbForLazyWrite Acquired Fcb lock %08lX SHARED %08lX\n",
- &pFcb->NPFcb->Resource,
+ "AFSAcquireFcbForLazyWrite Acquired Fcb PagingIo lock %08lX SHARED %08lX\n",
+ &pFcb->NPFcb->PagingResource,
PsGetCurrentThread());
- bReleaseMain = TRUE;
-
- //
- // Try and grab the paging
- //
+ bReleasePaging = TRUE;
AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb PagingIo lock %08lX SHARED %08lX\n",
- &pFcb->NPFcb->PagingResource,
+ "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb SectionObject lock %08lX SHARED %08lX\n",
+ &pFcb->NPFcb->SectionObjectResource,
PsGetCurrentThread());
- if( AFSAcquireShared( &pFcb->NPFcb->PagingResource,
+ if( AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
Wait))
{
AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSAcquireFcbForLazyWrite Acquired Fcb PagingIo lock %08lX SHARED %08lX\n",
- &pFcb->NPFcb->PagingResource,
+ "AFSAcquireFcbForLazyWrite Acquired Fcb SectionObject lock %08lX SHARED %08lX\n",
+ &pFcb->NPFcb->SectionObjectResource,
PsGetCurrentThread());
- bReleasePaging = TRUE;
+ bReleaseSectionObject = TRUE;
//
// All is well ...
if( !bStatus)
{
- if( bReleaseMain)
+ if( bReleaseSectionObject)
{
- AFSReleaseResource( &pFcb->NPFcb->Resource);
+ AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
}
if( bReleasePaging)
IoSetTopLevelIrp( NULL);
- ASSERT( PsGetCurrentThread() == pFcb->Specific.File.LazyWriterThread);
-
- pFcb->Specific.File.LazyWriterThread = NULL;
-
+ AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
AFSReleaseResource( &pFcb->NPFcb->PagingResource);
- AFSReleaseResource( &pFcb->NPFcb->Resource);
-
return;
}
AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSAcquireFcbForReadAhead Attempt to acquire Fcb lock %08lX SHARED %08lX\n",
- &pFcb->NPFcb->Resource,
+ "AFSAcquireFcbForReadAhead Attempt to acquire Fcb SectionObject lock %08lX SHARED %08lX\n",
+ &pFcb->NPFcb->SectionObjectResource,
PsGetCurrentThread());
- if( AFSAcquireShared( &pFcb->NPFcb->Resource,
+ if( AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
Wait))
{
AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSAcquireFcbForReadAhead Acquired Fcb lock %08lX SHARED %08lX\n",
- &pFcb->NPFcb->Resource,
+ "AFSAcquireFcbForReadAhead Acquired Fcb SectionObject lock %08lX SHARED %08lX\n",
+ &pFcb->NPFcb->SectionObjectResource,
PsGetCurrentThread());
bStatus = TRUE;
IoSetTopLevelIrp( NULL);
- AFSReleaseResource( &pFcb->NPFcb->Resource);
+ AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
return;
}
if( pTokenInfo != NULL)
{
- AFSExFreePool( pTokenInfo);
+ ExFreePool( pTokenInfo); // Allocated by SeQueryInformationToken
}
}