2 * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3 * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
14 * this list of conditions and the following disclaimer in the
16 * and/or other materials provided with the distribution.
17 * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18 * nor the names of their contributors may be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission from Kernel Drivers, LLC and Your File System, Inc.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // File: AFSNameSupport.cpp
39 #include "AFSCommon.h"
42 AFSLocateNameEntry( IN GUID *AuthGroup,
43 IN PFILE_OBJECT FileObject,
44 IN UNICODE_STRING *RootPathName,
45 IN UNICODE_STRING *ParsedPathName,
46 IN AFSNameArrayHdr *NameArray,
48 OUT AFSVolumeCB **VolumeCB,
49 IN OUT AFSDirectoryCB **ParentDirectoryCB,
50 OUT AFSDirectoryCB **DirectoryCB,
51 OUT PUNICODE_STRING ComponentName)
54 NTSTATUS ntStatus = STATUS_SUCCESS;
55 UNICODE_STRING uniPathName, uniComponentName, uniRemainingPath, uniSearchName, uniFullPathName;
57 AFSDirectoryCB *pDirEntry = NULL, *pParentDirEntry = NULL;
58 AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
59 UNICODE_STRING uniSysName;
60 ULONG ulSubstituteIndex = 0;
61 BOOLEAN bSubstituteName = FALSE;
62 AFSNameArrayHdr *pNameArray = NameArray;
63 BOOLEAN bAllocatedSymLinkBuffer = FALSE;
64 UNICODE_STRING uniRelativeName, uniNoOpName;
65 AFSObjectInfoCB *pCurrentObject = NULL;
66 AFSObjectInfoCB *pParentObjectInfo = NULL;
67 AFSVolumeCB *pCurrentVolume = *VolumeCB;
68 BOOLEAN bReleaseCurrentVolume = TRUE;
69 BOOLEAN bSubstitutedName = FALSE;
75 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
76 AFS_TRACE_LEVEL_VERBOSE_2,
77 "AFSLocateNameEntry (FO: %08lX) Processing full name %wZ\n",
81 RtlInitUnicodeString( &uniSysName,
84 RtlInitUnicodeString( &uniRelativeName,
87 RtlInitUnicodeString( &uniNoOpName,
91 // Cleanup some parameters
94 if( ComponentName != NULL)
97 ComponentName->Length = 0;
98 ComponentName->MaximumLength = 0;
99 ComponentName->Buffer = NULL;
103 // We will parse through the filename, locating the directory nodes until we encounter a cache miss
104 // Starting at the root node
107 pParentDirEntry = NULL;
109 pDirEntry = *ParentDirectoryCB;
111 uniPathName = *ParsedPathName;
113 uniFullPathName = *RootPathName;
115 uniComponentName.Length = uniComponentName.MaximumLength = 0;
116 uniComponentName.Buffer = NULL;
118 uniRemainingPath.Length = uniRemainingPath.MaximumLength = 0;
119 uniRemainingPath.Buffer = NULL;
121 uniSearchName.Length = uniSearchName.MaximumLength = 0;
122 uniSearchName.Buffer = NULL;
124 ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
130 // Check our total link count for this name array
133 if( pNameArray->LinkCount >= (LONG)pDevExt->Specific.RDR.MaxLinkCount)
136 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
139 pCurrentObject = pDirEntry->ObjectInformation;
141 KeQueryTickCount( &pCurrentObject->LastAccessCount);
144 // Check that the directory entry is not deleted or pending delete
147 if( BooleanFlagOn( pDirEntry->Flags, AFS_DIR_ENTRY_DELETED))
150 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
151 AFS_TRACE_LEVEL_ERROR,
152 "AFSLocateNameEntry (FO: %08lX) Deleted parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
154 &pDirEntry->NameInformation.FileName,
155 pCurrentObject->FileId.Cell,
156 pCurrentObject->FileId.Volume,
157 pCurrentObject->FileId.Vnode,
158 pCurrentObject->FileId.Unique,
159 STATUS_FILE_DELETED);
161 try_return( ntStatus = STATUS_FILE_DELETED);
164 if( BooleanFlagOn( pDirEntry->Flags, AFS_DIR_ENTRY_PENDING_DELETE))
167 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
168 AFS_TRACE_LEVEL_ERROR,
169 "AFSLocateNameEntry (FO: %08lX) Delete pending on %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
171 &pDirEntry->NameInformation.FileName,
172 pCurrentObject->FileId.Cell,
173 pCurrentObject->FileId.Volume,
174 pCurrentObject->FileId.Vnode,
175 pCurrentObject->FileId.Unique,
176 STATUS_DELETE_PENDING);
178 try_return( ntStatus = STATUS_DELETE_PENDING);
182 // Check if the directory requires verification
185 if( BooleanFlagOn( pCurrentObject->Flags, AFS_OBJECT_FLAGS_VERIFY) &&
186 ( pCurrentObject->FileType != AFS_FILE_TYPE_DIRECTORY ||
187 !AFSIsEnumerationInProcess( pCurrentObject)))
190 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
191 AFS_TRACE_LEVEL_VERBOSE,
192 "AFSLocateNameEntry (FO: %08lX) Verifying parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
194 &pDirEntry->NameInformation.FileName,
195 pCurrentObject->FileId.Cell,
196 pCurrentObject->FileId.Volume,
197 pCurrentObject->FileId.Vnode,
198 pCurrentObject->FileId.Unique);
201 // Directory TreeLock should be exclusively held
204 AFSAcquireExcl( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
207 ntStatus = AFSVerifyEntry( AuthGroup,
210 AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
212 if( !NT_SUCCESS( ntStatus))
215 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
216 AFS_TRACE_LEVEL_ERROR,
217 "AFSLocateNameEntry (FO: %08lX) Failed to verify parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
219 &pDirEntry->NameInformation.FileName,
220 pCurrentObject->FileId.Cell,
221 pCurrentObject->FileId.Volume,
222 pCurrentObject->FileId.Vnode,
223 pCurrentObject->FileId.Unique,
226 try_return( ntStatus);
231 // Ensure the parent node has been evaluated, if not then go do it now
234 if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_NOT_EVALUATED) ||
235 pCurrentObject->FileType == AFS_FILE_TYPE_UNKNOWN)
238 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
239 AFS_TRACE_LEVEL_VERBOSE,
240 "AFSLocateNameEntry (FO: %08lX) Evaluating parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
242 &pDirEntry->NameInformation.FileName,
243 pCurrentObject->FileId.Cell,
244 pCurrentObject->FileId.Volume,
245 pCurrentObject->FileId.Vnode,
246 pCurrentObject->FileId.Unique);
248 ntStatus = AFSEvaluateNode( AuthGroup,
251 if( !NT_SUCCESS( ntStatus))
254 if ( ntStatus == STATUS_NOT_A_DIRECTORY)
257 if ( pCurrentObject->ParentObjectInformation == NULL)
260 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
261 AFS_TRACE_LEVEL_ERROR,
262 "AFSLocateNameEntry (FO: %08lX) Failed to evaluate object %wZ FID %08lX-%08lX-%08lX-%08lX PARENT NULL Status %08lX\n",
264 &pDirEntry->NameInformation.FileName,
265 pCurrentObject->FileId.Cell,
266 pCurrentObject->FileId.Volume,
267 pCurrentObject->FileId.Vnode,
268 pCurrentObject->FileId.Unique,
274 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
275 AFS_TRACE_LEVEL_ERROR,
276 "AFSLocateNameEntry (FO: %08lX) Failed to evaluate object %wZ FID %08lX-%08lX-%08lX-%08lX PARENT %08lX-%08lX-%08lX-%08lX Status %08lX\n",
278 &pDirEntry->NameInformation.FileName,
279 pCurrentObject->FileId.Cell,
280 pCurrentObject->FileId.Volume,
281 pCurrentObject->FileId.Vnode,
282 pCurrentObject->FileId.Unique,
283 pCurrentObject->ParentObjectInformation->FileId.Cell,
284 pCurrentObject->ParentObjectInformation->FileId.Volume,
285 pCurrentObject->ParentObjectInformation->FileId.Vnode,
286 pCurrentObject->ParentObjectInformation->FileId.Unique,
292 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
293 AFS_TRACE_LEVEL_ERROR,
294 "AFSLocateNameEntry (FO: %08lX) Failed to evaluate parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
296 &pDirEntry->NameInformation.FileName,
297 pCurrentObject->FileId.Cell,
298 pCurrentObject->FileId.Volume,
299 pCurrentObject->FileId.Vnode,
300 pCurrentObject->FileId.Unique,
304 try_return( ntStatus);
307 ClearFlag( pCurrentObject->Flags, AFS_OBJECT_FLAGS_NOT_EVALUATED);
311 // If this is a mount point or symlink then go get the real directory node
314 switch( pCurrentObject->FileType)
317 case AFS_FILE_TYPE_SYMLINK:
320 UNICODE_STRING uniTempName;
321 WCHAR *pTmpBuffer = NULL;
325 // Check if the flag is set to NOT evaluate a symlink
326 // and we are done with the parsing
329 if( BooleanFlagOn( Flags, AFS_LOCATE_FLAGS_NO_SL_TARGET_EVAL) &&
330 uniRemainingPath.Length == 0)
334 // Pass back the directory entries
337 *ParentDirectoryCB = pParentDirEntry;
339 *DirectoryCB = pDirEntry;
341 *VolumeCB = pCurrentVolume;
343 *RootPathName = uniFullPathName;
345 try_return( ntStatus);
348 AFSAcquireExcl( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
351 AFSAcquireExcl( &pDirEntry->NonPaged->Lock,
354 if( pDirEntry->NameInformation.TargetName.Length == 0)
358 // We'll reset the DV to ensure we validate the metadata content
361 pCurrentObject->DataVersion.QuadPart = (ULONGLONG)-1;
363 SetFlag( pCurrentObject->Flags, AFS_OBJECT_FLAGS_VERIFY);
365 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
366 AFS_TRACE_LEVEL_VERBOSE,
367 "AFSLocateNameEntry (FO: %08lX) Verifying symlink parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
369 &pDirEntry->NameInformation.FileName,
370 pCurrentObject->FileId.Cell,
371 pCurrentObject->FileId.Volume,
372 pCurrentObject->FileId.Vnode,
373 pCurrentObject->FileId.Unique);
376 // Directory TreeLock should be exclusively held
379 ntStatus = AFSVerifyEntry( AuthGroup,
382 AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
384 if( !NT_SUCCESS( ntStatus))
387 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
388 AFS_TRACE_LEVEL_ERROR,
389 "AFSLocateNameEntry (FO: %08lX) Failed to verify symlink parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
391 &pDirEntry->NameInformation.FileName,
392 pCurrentObject->FileId.Cell,
393 pCurrentObject->FileId.Volume,
394 pCurrentObject->FileId.Vnode,
395 pCurrentObject->FileId.Unique,
398 AFSReleaseResource( &pDirEntry->NonPaged->Lock);
400 try_return( ntStatus);
404 // If the type changed then reprocess this entry
407 if( pCurrentObject->FileType != AFS_FILE_TYPE_SYMLINK)
410 AFSReleaseResource( &pDirEntry->NonPaged->Lock);
418 AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
422 // If we were given a zero length target name then deny access to the entry
425 if( pDirEntry->NameInformation.TargetName.Length == 0)
428 ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
430 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
431 AFS_TRACE_LEVEL_ERROR,
432 "AFSLocateNameEntry (FO: %08lX) Failed to retrieve target name for symlink %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
434 &pDirEntry->NameInformation.FileName,
435 pCurrentObject->FileId.Cell,
436 pCurrentObject->FileId.Volume,
437 pCurrentObject->FileId.Vnode,
438 pCurrentObject->FileId.Unique,
441 AFSReleaseResource( &pDirEntry->NonPaged->Lock);
443 try_return( ntStatus);
446 if( AFSIsRelativeName( &pDirEntry->NameInformation.TargetName))
449 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
450 AFS_TRACE_LEVEL_VERBOSE,
451 "AFSLocateNameEntry (FO: %08lX) Processing relative symlink target %wZ for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
453 &pDirEntry->NameInformation.TargetName,
454 &pDirEntry->NameInformation.FileName,
455 pCurrentObject->FileId.Cell,
456 pCurrentObject->FileId.Volume,
457 pCurrentObject->FileId.Vnode,
458 pCurrentObject->FileId.Unique);
461 // We'll substitute this name into the current process name
462 // starting at where we sit in the path
465 uniTempName.Length = 0;
466 uniTempName.MaximumLength = (USHORT)((char *)uniComponentName.Buffer - (char *)uniFullPathName.Buffer) +
467 pDirEntry->NameInformation.TargetName.Length +
469 uniRemainingPath.Length;
471 uniTempName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
472 uniTempName.MaximumLength,
473 AFS_NAME_BUFFER_ONE_TAG);
475 if( uniTempName.Buffer == NULL)
478 AFSReleaseResource( &pDirEntry->NonPaged->Lock);
480 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
484 // We have so first copy in the portion up to the component
488 RtlCopyMemory( uniTempName.Buffer,
489 uniFullPathName.Buffer,
490 (ULONG)((char *)uniComponentName.Buffer - (char *)uniFullPathName.Buffer));
492 uniTempName.Length = (USHORT)((char *)uniComponentName.Buffer - (char *)uniFullPathName.Buffer);
494 if( bAllocatedSymLinkBuffer ||
498 pTmpBuffer = uniFullPathName.Buffer;
501 bAllocatedSymLinkBuffer = TRUE;
504 // Have we parsed this name yet? Better have at least once ...
507 if( uniComponentName.Length == 0)
513 // Copy in the target name ...
516 RtlCopyMemory( &uniTempName.Buffer[ uniTempName.Length/sizeof( WCHAR)],
517 pDirEntry->NameInformation.TargetName.Buffer,
518 pDirEntry->NameInformation.TargetName.Length);
520 uniPathName.Buffer = &uniTempName.Buffer[ uniTempName.Length/sizeof( WCHAR)];
522 uniPathName.Length += pDirEntry->NameInformation.TargetName.Length;
523 uniPathName.MaximumLength = uniTempName.MaximumLength;
525 uniTempName.Length += pDirEntry->NameInformation.TargetName.Length;
528 // And now any remaining portion of the name
531 if( uniRemainingPath.Length > 0)
534 if( uniRemainingPath.Buffer[ 0] != L'\\')
537 uniRemainingPath.Buffer--;
538 uniRemainingPath.Length += sizeof( WCHAR);
540 uniPathName.Length += sizeof( WCHAR);
543 RtlCopyMemory( &uniTempName.Buffer[ uniTempName.Length/sizeof( WCHAR)],
544 uniRemainingPath.Buffer,
545 uniRemainingPath.Length);
547 uniTempName.Length += uniRemainingPath.Length;
550 uniFullPathName = uniTempName;
552 if( pTmpBuffer != NULL)
555 AFSExFreePoolWithTag( pTmpBuffer, 0);
558 AFSReleaseResource( &pDirEntry->NonPaged->Lock);
561 // Dereference the current entry ..
564 lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
566 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
567 AFS_TRACE_LEVEL_VERBOSE,
568 "AFSLocateNameEntry Decrement1 count on %wZ DE %p Ccb %p Cnt %d\n",
569 &pDirEntry->NameInformation.FileName,
575 // OK, need to back up one entry for the correct parent since the current
576 // entry we are on is the symlink itself
579 pDirEntry = AFSBackupEntry( pNameArray);
582 // Increment our reference on this dir entry
585 lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
587 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
588 AFS_TRACE_LEVEL_VERBOSE,
589 "AFSLocateNameEntry Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
590 &pDirEntry->NameInformation.FileName,
595 if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_ROOT_VOLUME))
598 pParentDirEntry = NULL;
603 pParentDirEntry = AFSGetParentEntry( pNameArray);
605 ASSERT( pParentDirEntry != pDirEntry);
611 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
612 AFS_TRACE_LEVEL_VERBOSE,
613 "AFSLocateNameEntry (FO: %08lX) Processing absolute symlink target %wZ for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
615 &pDirEntry->NameInformation.TargetName,
616 &pDirEntry->NameInformation.FileName,
617 pCurrentObject->FileId.Cell,
618 pCurrentObject->FileId.Volume,
619 pCurrentObject->FileId.Vnode,
620 pCurrentObject->FileId.Unique);
623 // We'll substitute this name into the current process name
624 // starting at where we sit in the path
627 uniTempName.Length = 0;
628 uniTempName.MaximumLength = pDirEntry->NameInformation.TargetName.Length +
630 uniRemainingPath.Length;
632 uniTempName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
633 uniTempName.MaximumLength,
634 AFS_NAME_BUFFER_TWO_TAG);
636 if( uniTempName.Buffer == NULL)
639 AFSReleaseResource( &pDirEntry->NonPaged->Lock);
641 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
644 if( bAllocatedSymLinkBuffer ||
648 pTmpBuffer = uniFullPathName.Buffer;
651 bAllocatedSymLinkBuffer = TRUE;
654 // Have we parsed this name yet? Better have at least once ...
657 if( uniComponentName.Length == 0)
663 // Copy in the target name ...
666 RtlCopyMemory( uniTempName.Buffer,
667 pDirEntry->NameInformation.TargetName.Buffer,
668 pDirEntry->NameInformation.TargetName.Length);
670 uniTempName.Length = pDirEntry->NameInformation.TargetName.Length;
673 // And now any remaining portion of the name
676 if( uniRemainingPath.Length > 0)
679 if( uniRemainingPath.Buffer[ 0] != L'\\')
682 uniRemainingPath.Buffer--;
683 uniRemainingPath.Length += sizeof( WCHAR);
686 RtlCopyMemory( &uniTempName.Buffer[ uniTempName.Length/sizeof( WCHAR)],
687 uniRemainingPath.Buffer,
688 uniRemainingPath.Length);
690 uniTempName.Length += uniRemainingPath.Length;
693 uniFullPathName = uniTempName;
695 uniPathName = uniTempName;
697 if( pTmpBuffer != NULL)
700 AFSExFreePoolWithTag( pTmpBuffer, 0);
703 AFSReleaseResource( &pDirEntry->NonPaged->Lock);
706 // If our current volume is not the global root then make it so ...
709 if( pCurrentVolume != AFSGlobalRoot)
712 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
713 AFS_TRACE_LEVEL_VERBOSE,
714 "AFSLocateNameEntry (FO: %08lX) Current volume not global, resetting for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
716 &pDirEntry->NameInformation.FileName,
717 pCurrentObject->FileId.Cell,
718 pCurrentObject->FileId.Volume,
719 pCurrentObject->FileId.Vnode,
720 pCurrentObject->FileId.Unique);
722 lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
724 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
725 AFS_TRACE_LEVEL_VERBOSE,
726 "AFSLocateNameEntry Decrement count on volume %08lX Cnt %d\n",
730 pCurrentVolume = AFSGlobalRoot;
732 lCount = InterlockedIncrement( &pCurrentVolume->VolumeReferenceCount);
734 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
735 AFS_TRACE_LEVEL_VERBOSE,
736 "AFSLocateNameEntry Increment count on volume %08lX Cnt %d\n",
742 // Dereference our current dir entry
745 lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
747 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
748 AFS_TRACE_LEVEL_VERBOSE,
749 "AFSLocateNameEntry Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
750 &pDirEntry->NameInformation.FileName,
755 pDirEntry = pCurrentVolume->DirectoryCB;
758 // Reference the new dir entry
761 lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
763 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
764 AFS_TRACE_LEVEL_VERBOSE,
765 "AFSLocateNameEntry Increment2 count on %wZ DE %p Ccb %p Cnt %d\n",
766 &pDirEntry->NameInformation.FileName,
772 // Reset the name array
773 // Persist the link count in the name array
776 lLinkCount = pNameArray->LinkCount;
778 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
779 AFS_TRACE_LEVEL_VERBOSE,
780 "AFSLocateNameEntry (FO: %08lX) Resetting name array for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
782 &pDirEntry->NameInformation.FileName,
783 pCurrentObject->FileId.Cell,
784 pCurrentObject->FileId.Volume,
785 pCurrentObject->FileId.Vnode,
786 pCurrentObject->FileId.Unique);
788 AFSResetNameArray( pNameArray,
791 pNameArray->LinkCount = lLinkCount;
794 // Process over the \\<Global root> portion of the name
797 FsRtlDissectName( uniPathName,
801 if( RtlCompareUnicodeString( &uniComponentName,
806 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
807 AFS_TRACE_LEVEL_ERROR,
808 "AFSLocateNameEntry Name %wZ contains invalid server name\n",
812 // The correct response would be STATUS_OBJECT_PATH_INVALID
813 // but that prevents cmd.exe from performing a recursive
814 // directory enumeration when opening a directory entry
815 // that represents a symlink to an invalid path is discovered.
817 try_return( ntStatus = STATUS_OBJECT_PATH_NOT_FOUND);
820 uniPathName = uniRemainingPath;
822 pParentDirEntry = NULL;
826 // Increment our link count
829 lCount = InterlockedIncrement( &pNameArray->LinkCount);
834 case AFS_FILE_TYPE_MOUNTPOINT:
838 // Check if the flag is set to NOT evaluate a mount point
839 // and we are done with the parsing
842 if( BooleanFlagOn( Flags, AFS_LOCATE_FLAGS_NO_MP_TARGET_EVAL) &&
843 uniRemainingPath.Length == 0)
847 // Pass back the directory entries
850 *ParentDirectoryCB = pParentDirEntry;
852 *DirectoryCB = pDirEntry;
854 *VolumeCB = pCurrentVolume;
856 *RootPathName = uniFullPathName;
858 try_return( ntStatus);
861 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
862 AFS_TRACE_LEVEL_VERBOSE,
863 "AFSLocateNameEntry (FO: %08lX) Building MP target for parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
865 &pDirEntry->NameInformation.FileName,
866 pCurrentObject->FileId.Cell,
867 pCurrentObject->FileId.Volume,
868 pCurrentObject->FileId.Vnode,
869 pCurrentObject->FileId.Unique);
872 // Go retrieve the target entry for this node
873 // Release the current volume cb entry since we would
874 // have lock inversion in the following call
875 // Also decrement the ref count on the volume
878 ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
880 lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
882 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
883 AFS_TRACE_LEVEL_VERBOSE,
884 "AFSLocateNameEntry Decrement2 count on volume %08lX Cnt %d\n",
886 pCurrentVolume->VolumeReferenceCount);
888 ntStatus = AFSBuildMountPointTarget( AuthGroup,
892 if( !NT_SUCCESS( ntStatus))
895 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
896 AFS_TRACE_LEVEL_ERROR,
897 "AFSLocateNameEntry (FO: %08lX) Failed to build MP target for parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
899 &pDirEntry->NameInformation.FileName,
900 pCurrentObject->FileId.Cell,
901 pCurrentObject->FileId.Volume,
902 pCurrentObject->FileId.Vnode,
903 pCurrentObject->FileId.Unique,
907 // We already decremented the current volume above
910 bReleaseCurrentVolume = FALSE;
912 try_return( ntStatus);
915 ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
918 // The name array stores both the mount point and the target.
919 // Insert the target.
922 AFSInsertNextElement( pNameArray,
923 pCurrentVolume->DirectoryCB);
926 // We want to restart processing here on the new parent ...
927 // Deref and ref count the entries
930 lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
932 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
933 AFS_TRACE_LEVEL_VERBOSE,
934 "AFSLocateNameEntry Decrement3 count on %wZ DE %p Ccb %p Cnt %d\n",
935 &pDirEntry->NameInformation.FileName,
940 pDirEntry = pCurrentVolume->DirectoryCB;
942 lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
944 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
945 AFS_TRACE_LEVEL_VERBOSE,
946 "AFSLocateNameEntry Increment3 count on %wZ DE %p Ccb %p Cnt %d\n",
947 &pDirEntry->NameInformation.FileName,
952 pParentDirEntry = NULL;
955 // Increment our link count
958 lCount = InterlockedIncrement( &pNameArray->LinkCount);
963 case AFS_FILE_TYPE_DFSLINK:
966 if( BooleanFlagOn( Flags, AFS_LOCATE_FLAGS_NO_DFS_LINK_EVAL))
970 // Pass back the directory entries
973 *ParentDirectoryCB = pParentDirEntry;
975 *DirectoryCB = pDirEntry;
977 *VolumeCB = pCurrentVolume;
979 *RootPathName = uniFullPathName;
981 try_return( ntStatus);
985 // This is a DFS link so we need to update the file name and return STATUS_REPARSE to the
986 // system for it to reevaluate it
989 if( FileObject != NULL)
992 ntStatus = AFSProcessDFSLink( pDirEntry,
1001 // This is where we have been re-entered from an NP evaluation call via the BuildBranch()
1005 ntStatus = STATUS_INVALID_PARAMETER;
1008 if( ntStatus != STATUS_SUCCESS &&
1009 ntStatus != STATUS_REPARSE)
1012 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1013 AFS_TRACE_LEVEL_ERROR,
1014 "AFSLocateNameEntry (FO: %08lX) Failed to process DFSLink parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
1016 &pDirEntry->NameInformation.FileName,
1017 pCurrentObject->FileId.Cell,
1018 pCurrentObject->FileId.Volume,
1019 pCurrentObject->FileId.Vnode,
1020 pCurrentObject->FileId.Unique,
1024 try_return( ntStatus);
1027 case AFS_FILE_TYPE_UNKNOWN:
1028 case AFS_FILE_TYPE_INVALID:
1032 // Something was not processed ...
1035 try_return( ntStatus = STATUS_ACCESS_DENIED);
1038 } /* end of switch */
1041 // If the parent is not initialized then do it now
1044 if( pCurrentObject->FileType == AFS_FILE_TYPE_DIRECTORY &&
1045 !BooleanFlagOn( pCurrentObject->Flags, AFS_OBJECT_FLAGS_DIRECTORY_ENUMERATED))
1048 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1049 AFS_TRACE_LEVEL_VERBOSE,
1050 "AFSLocateNameEntry (FO: %08lX) Enumerating parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1052 &pDirEntry->NameInformation.FileName,
1053 pCurrentObject->FileId.Cell,
1054 pCurrentObject->FileId.Volume,
1055 pCurrentObject->FileId.Vnode,
1056 pCurrentObject->FileId.Unique);
1058 AFSAcquireExcl( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
1061 if( !BooleanFlagOn( pCurrentObject->Flags, AFS_OBJECT_FLAGS_DIRECTORY_ENUMERATED))
1064 ntStatus = AFSEnumerateDirectory( AuthGroup,
1068 if( !NT_SUCCESS( ntStatus))
1071 AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
1073 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1074 AFS_TRACE_LEVEL_ERROR,
1075 "AFSLocateNameEntry (FO: %08lX) Failed to enumerate parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
1077 &pDirEntry->NameInformation.FileName,
1078 pCurrentObject->FileId.Cell,
1079 pCurrentObject->FileId.Volume,
1080 pCurrentObject->FileId.Vnode,
1081 pCurrentObject->FileId.Unique,
1084 try_return( ntStatus);
1087 SetFlag( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DIRECTORY_ENUMERATED);
1090 AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
1092 else if( pCurrentObject->FileType == AFS_FILE_TYPE_FILE)
1095 if( uniPathName.Length > 0)
1098 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1099 AFS_TRACE_LEVEL_ERROR,
1100 "AFSLocateNameEntry (FO: %08lX) Encountered file node %wZ FID %08lX-%08lX-%08lX-%08lX in path processing\n",
1102 &pDirEntry->NameInformation.FileName,
1103 pCurrentObject->FileId.Cell,
1104 pCurrentObject->FileId.Volume,
1105 pCurrentObject->FileId.Vnode,
1106 pCurrentObject->FileId.Unique);
1108 // The proper error code to return would be STATUS_OBJECT_PATH_INVALID because
1109 // one of the components of the path is not a directory. However, returning
1110 // that error prevents IIS 7 and 7.5 from being able to serve data out of AFS.
1111 // Instead IIS insists on treating the target file as if it is a directory containing
1112 // a potential web.config file. NTFS and LanMan return STATUS_OBJECT_PATH_NOT_FOUND.
1113 // AFS will follow suit.
1115 ntStatus = STATUS_OBJECT_PATH_NOT_FOUND;
1120 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1121 AFS_TRACE_LEVEL_VERBOSE,
1122 "AFSLocateNameEntry (FO: %08lX) Returning file %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1124 &pDirEntry->NameInformation.FileName,
1125 pCurrentObject->FileId.Cell,
1126 pCurrentObject->FileId.Volume,
1127 pCurrentObject->FileId.Vnode,
1128 pCurrentObject->FileId.Unique);
1131 // Pass back the directory entries
1134 *ParentDirectoryCB = pParentDirEntry;
1136 *DirectoryCB = pDirEntry;
1138 *VolumeCB = pCurrentVolume;
1140 *RootPathName = uniFullPathName;
1143 try_return( ntStatus);
1147 // If we are at the end of the processing, set our returned information and get out
1150 if( uniPathName.Length == 0)
1153 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1154 AFS_TRACE_LEVEL_VERBOSE,
1155 "AFSLocateNameEntry (FO: %08lX) Completed processing returning %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1157 &pDirEntry->NameInformation.FileName,
1158 pCurrentObject->FileId.Cell,
1159 pCurrentObject->FileId.Volume,
1160 pCurrentObject->FileId.Vnode,
1161 pCurrentObject->FileId.Unique);
1164 // Pass back the directory entries
1167 *ParentDirectoryCB = pParentDirEntry;
1169 *DirectoryCB = pDirEntry;
1171 *VolumeCB = pCurrentVolume;
1173 *RootPathName = uniFullPathName;
1175 try_return( ntStatus);
1179 // We may have returned to the top of the while( TRUE)
1181 if( bSubstituteName &&
1182 uniSearchName.Buffer != NULL)
1185 AFSExFreePoolWithTag( uniSearchName.Buffer, 0);
1187 bSubstituteName = FALSE;
1189 uniSearchName.Length = uniSearchName.MaximumLength = 0;
1190 uniSearchName.Buffer = NULL;
1193 ulSubstituteIndex = 1;
1195 ntStatus = STATUS_SUCCESS;
1198 // Get the next component name
1201 FsRtlDissectName( uniPathName,
1206 // Check for the . and .. in the path
1209 if( RtlCompareUnicodeString( &uniComponentName,
1214 uniPathName = uniRemainingPath;
1219 if( RtlCompareUnicodeString( &uniComponentName,
1224 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1225 AFS_TRACE_LEVEL_VERBOSE,
1226 "AFSLocateNameEntry (FO: %08lX) Backing up entry from %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1228 &pDirEntry->NameInformation.FileName,
1229 pCurrentObject->FileId.Cell,
1230 pCurrentObject->FileId.Volume,
1231 pCurrentObject->FileId.Vnode,
1232 pCurrentObject->FileId.Unique);
1235 // Need to back up one entry in the name array
1237 lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
1239 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1240 AFS_TRACE_LEVEL_VERBOSE,
1241 "AFSLocateNameEntry Decrement4 count on %wZ DE %p Ccb %p Cnt %d\n",
1242 &pDirEntry->NameInformation.FileName,
1247 pDirEntry = AFSBackupEntry( NameArray);
1249 if( pDirEntry == NULL)
1252 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1253 AFS_TRACE_LEVEL_ERROR,
1254 "AFSLocateNameEntry AFSBackupEntry failed\n");
1256 try_return(ntStatus = STATUS_OBJECT_PATH_INVALID);
1259 lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
1261 if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_ROOT_VOLUME))
1264 pParentDirEntry = NULL;
1269 pParentDirEntry = AFSGetParentEntry( pNameArray);
1271 ASSERT( pParentDirEntry != pDirEntry);
1274 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1275 AFS_TRACE_LEVEL_VERBOSE,
1276 "AFSLocateNameEntry Increment4 count on %wZ DE %p Ccb %p Cnt %d\n",
1277 &pDirEntry->NameInformation.FileName,
1280 pDirEntry->OpenReferenceCount);
1282 uniPathName = uniRemainingPath;
1288 // Update our pointers
1291 pParentDirEntry = pDirEntry;
1295 uniSearchName = uniComponentName;
1297 while( pDirEntry == NULL)
1301 // If the SearchName contains @SYS then we perform the substitution.
1302 // If there is no substitution we give up.
1305 if( !bSubstituteName &&
1306 FsRtlIsNameInExpression( &uniSysName,
1312 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1313 AFS_TRACE_LEVEL_VERBOSE_2,
1314 "AFSLocateNameEntry (FO: %08lX) Processing @SYS substitution for %wZ Index %08lX\n",
1319 ntStatus = AFSSubstituteSysName( &uniComponentName,
1323 if ( NT_SUCCESS( ntStatus))
1326 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1327 AFS_TRACE_LEVEL_VERBOSE_2,
1328 "AFSLocateNameEntry (FO: %08lX) Located substitution %wZ for %wZ Index %08lX\n",
1335 // Go reparse the name again
1338 bSubstituteName = TRUE;
1340 ulSubstituteIndex++; // For the next entry, if needed
1342 continue; // while( pDirEntry == NULL)
1347 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1348 AFS_TRACE_LEVEL_ERROR,
1349 "AFSLocateNameEntry (FO: %08lX) Failed to locate substitute string for %wZ Index %08lX Status %08lX\n",
1355 if( ntStatus == STATUS_OBJECT_NAME_NOT_FOUND)
1359 // Pass back the directory entries
1362 *ParentDirectoryCB = pParentDirEntry;
1364 *DirectoryCB = NULL;
1366 *VolumeCB = pCurrentVolume;
1368 if( ComponentName != NULL)
1371 *ComponentName = uniComponentName;
1374 *RootPathName = uniFullPathName;
1378 // We can't possibly have a pDirEntry since the lookup failed
1380 try_return( ntStatus);
1385 // Generate the CRC on the node and perform a case sensitive lookup
1388 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1389 AFS_TRACE_LEVEL_VERBOSE_2,
1390 "AFSLocateNameEntry (FO: %08lX) Searching for entry %wZ case sensitive\n",
1394 ulCRC = AFSGenerateCRC( &uniSearchName,
1397 AFSAcquireShared( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
1400 AFSLocateCaseSensitiveDirEntry( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
1404 if( pDirEntry == NULL)
1408 // Missed so perform a case insensitive lookup
1411 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1412 AFS_TRACE_LEVEL_VERBOSE_2,
1413 "AFSLocateNameEntry (FO: %08lX) Searching for entry %wZ case insensitive\n",
1417 ulCRC = AFSGenerateCRC( &uniSearchName,
1420 AFSLocateCaseInsensitiveDirEntry( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
1424 if( pDirEntry == NULL)
1428 // OK, if this component is a valid short name then try
1429 // a lookup in the short name tree
1432 if( !BooleanFlagOn( pDevExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
1433 RtlIsNameLegalDOS8Dot3( &uniSearchName,
1438 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1439 AFS_TRACE_LEVEL_VERBOSE_2,
1440 "AFSLocateNameEntry (FO: %08lX) Searching for entry %wZ short name\n",
1444 AFSLocateShortNameDirEntry( pParentDirEntry->ObjectInformation->Specific.Directory.ShortNameTree,
1449 if( pDirEntry == NULL)
1453 // If we substituted a name then reset our search name and try again
1456 if( bSubstituteName)
1459 AFSExFreePoolWithTag( uniSearchName.Buffer, 0);
1461 uniSearchName = uniComponentName;
1463 bSubstituteName = FALSE;
1465 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1467 continue; // while( pDirEntry == NULL)
1470 if( uniRemainingPath.Length > 0)
1473 ntStatus = STATUS_OBJECT_PATH_NOT_FOUND;
1478 ntStatus = STATUS_OBJECT_NAME_NOT_FOUND;
1480 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1481 AFS_TRACE_LEVEL_VERBOSE,
1482 "AFSLocateNameEntry (FO: %08lX) Returning name not found for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1485 pCurrentObject->FileId.Cell,
1486 pCurrentObject->FileId.Volume,
1487 pCurrentObject->FileId.Vnode,
1488 pCurrentObject->FileId.Unique);
1491 // Pass back the directory entries
1494 *ParentDirectoryCB = pParentDirEntry;
1496 *DirectoryCB = NULL;
1498 *VolumeCB = pCurrentVolume;
1500 if( ComponentName != NULL)
1503 *ComponentName = uniComponentName;
1506 *RootPathName = uniFullPathName;
1509 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1512 // Node name not found so get out
1515 try_return( ntStatus); // while( pDirEntry == NULL)
1522 // Here we have a match on the case insensitive lookup for the name. If there
1523 // Is more than one link entry for this node then fail the lookup request
1526 if( !BooleanFlagOn( pDirEntry->Flags, AFS_DIR_ENTRY_CASE_INSENSTIVE_LIST_HEAD) ||
1527 pDirEntry->CaseInsensitiveList.fLink != NULL)
1530 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1532 try_return(ntStatus = STATUS_OBJECT_NAME_COLLISION);
1537 if( pDirEntry != NULL)
1541 // If the verify flag is set on the parent and the current entry is deleted
1542 // revalidate the parent and search again.
1545 if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED) &&
1546 BooleanFlagOn( pParentDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY))
1549 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1551 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1552 AFS_TRACE_LEVEL_VERBOSE,
1553 "AFSLocateNameEntry (FO: %08lX) Verifying(2) parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1555 &pParentDirEntry->NameInformation.FileName,
1556 pParentDirEntry->ObjectInformation->FileId.Cell,
1557 pParentDirEntry->ObjectInformation->FileId.Volume,
1558 pParentDirEntry->ObjectInformation->FileId.Vnode,
1559 pParentDirEntry->ObjectInformation->FileId.Unique);
1562 // Directory TreeLock should be exclusively held
1565 AFSAcquireExcl( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
1568 ntStatus = AFSVerifyEntry( AuthGroup,
1571 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1573 if( !NT_SUCCESS( ntStatus))
1576 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1577 AFS_TRACE_LEVEL_ERROR,
1578 "AFSLocateNameEntry (FO: %08lX) Failed to verify(2) parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
1580 &pParentDirEntry->NameInformation.FileName,
1581 pParentDirEntry->ObjectInformation->FileId.Cell,
1582 pParentDirEntry->ObjectInformation->FileId.Volume,
1583 pParentDirEntry->ObjectInformation->FileId.Vnode,
1584 pParentDirEntry->ObjectInformation->FileId.Unique,
1587 try_return( ntStatus);
1590 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1591 AFS_TRACE_LEVEL_VERBOSE,
1592 "AFSLocateNameEntry (FO: %08lX) Reprocessing component %wZ in parent %wZ\n",
1595 &pParentDirEntry->NameInformation.FileName);
1604 // Increment our dir entry ref count
1607 lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
1609 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1610 AFS_TRACE_LEVEL_VERBOSE,
1611 "AFSLocateNameEntry Increment5 count on %wZ DE %p Ccb %p Cnt %d\n",
1612 &pDirEntry->NameInformation.FileName,
1618 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1620 } // End while( pDirEntry == NULL)
1623 // If we have a dirEntry for this component, perform some basic validation on it
1626 if( pDirEntry != NULL &&
1627 BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED))
1630 pCurrentObject = pDirEntry->ObjectInformation;
1632 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1633 AFS_TRACE_LEVEL_ERROR,
1634 "AFSLocateNameEntry (FO: %08lX) Deleted entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1636 &pDirEntry->NameInformation.FileName,
1637 pCurrentObject->FileId.Cell,
1638 pCurrentObject->FileId.Volume,
1639 pCurrentObject->FileId.Vnode,
1640 pCurrentObject->FileId.Unique);
1643 // This entry was deleted through the invalidation call back so perform cleanup
1647 pParentObjectInfo = pCurrentObject->ParentObjectInformation;
1649 ASSERT( pParentObjectInfo != NULL);
1651 AFSAcquireExcl( pParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock,
1654 AFSAcquireExcl( pCurrentObject->VolumeCB->ObjectInfoTree.TreeLock,
1657 lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
1662 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING|AFS_SUBSYSTEM_CLEANUP_PROCESSING,
1663 AFS_TRACE_LEVEL_VERBOSE,
1664 "AFSLocateNameEntry Deleting dir entry %08lX (%08lX) for %wZ\n",
1667 &pDirEntry->NameInformation.FileName);
1670 // Remove and delete the directory entry from the parent list
1673 AFSDeleteDirEntry( pParentObjectInfo,
1676 if( pCurrentObject->ObjectReferenceCount <= 0)
1679 if( BooleanFlagOn( pCurrentObject->Flags, AFS_OBJECT_INSERTED_HASH_TREE))
1682 AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
1683 AFS_TRACE_LEVEL_VERBOSE,
1684 "AFSLocateNameEntry Removing object %08lX from volume tree\n",
1687 AFSRemoveHashEntry( &pCurrentObject->VolumeCB->ObjectInfoTree.TreeHead,
1688 &pCurrentObject->TreeEntry);
1690 ClearFlag( pCurrentObject->Flags, AFS_OBJECT_INSERTED_HASH_TREE);
1697 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1698 AFS_TRACE_LEVEL_VERBOSE,
1699 "AFSLocateNameEntry Setting DELETE flag in dir entry %p for %wZ\n",
1701 &pDirEntry->NameInformation.FileName);
1703 SetFlag( pDirEntry->Flags, AFS_DIR_ENTRY_DELETED);
1705 AFSRemoveNameEntry( pParentObjectInfo,
1709 AFSReleaseResource( pParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
1711 AFSReleaseResource( pCurrentObject->VolumeCB->ObjectInfoTree.TreeLock);
1714 // We deleted the dir entry so check if there is any remaining portion
1715 // of the name to process.
1718 if( uniRemainingPath.Length > 0)
1720 ntStatus = STATUS_OBJECT_PATH_NOT_FOUND;
1725 ntStatus = STATUS_OBJECT_NAME_NOT_FOUND;
1727 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1728 AFS_TRACE_LEVEL_VERBOSE,
1729 "AFSLocateNameEntry (FO: %08lX) Returning name not found(2) for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1732 pCurrentObject->FileId.Cell,
1733 pCurrentObject->FileId.Volume,
1734 pCurrentObject->FileId.Vnode,
1735 pCurrentObject->FileId.Unique);
1738 // Pass back the directory entries
1741 *ParentDirectoryCB = pParentDirEntry;
1743 *DirectoryCB = NULL;
1745 *VolumeCB = pCurrentVolume;
1747 if( ComponentName != NULL)
1750 *ComponentName = uniComponentName;
1753 *RootPathName = uniFullPathName;
1757 if( ntStatus != STATUS_SUCCESS)
1760 try_return( ntStatus);
1764 // Decrement the previous parent
1767 lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
1769 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1770 AFS_TRACE_LEVEL_VERBOSE,
1771 "AFSLocateNameEntry Decrement5 count on Parent %wZ DE %p Ccb %p Cnt %d\n",
1772 &pParentDirEntry->NameInformation.FileName,
1778 // If we ended up substituting a name in the component then update
1779 // the full path and update the pointers
1782 if( bSubstituteName)
1785 BOOLEAN bRelativeOpen = FALSE;
1787 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1788 AFS_TRACE_LEVEL_VERBOSE_2,
1789 "AFSLocateNameEntry (FO: %08lX) Substituting %wZ into %wZ Index %08lX\n",
1795 if( FileObject != NULL &&
1796 FileObject->RelatedFileObject != NULL)
1799 bRelativeOpen = TRUE;
1803 // AFSSubstituteNameInPath will replace the uniFullPathName.Buffer
1804 // and free the prior Buffer contents but only if the fourth
1805 // parameter is TRUE.
1808 ntStatus = AFSSubstituteNameInPath( &uniFullPathName,
1813 bAllocatedSymLinkBuffer ||
1816 if( !NT_SUCCESS( ntStatus))
1819 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1820 AFS_TRACE_LEVEL_ERROR,
1821 "AFSLocateNameEntry (FO: %08lX) Failure to substitute %wZ into %wZ Index %08lX Status %08lX\n",
1828 try_return( ntStatus);
1832 // We have substituted a name into the buffer so if we do this again for this
1833 // path, we need to free up the buffer we allocated.
1836 bSubstitutedName = TRUE;
1840 // Update the search parameters
1843 uniPathName = uniRemainingPath;
1846 // Check if the is a SymLink entry but has no Target FileID or Name. In this
1847 // case it might be a DFS Link so let's go and evaluate it to be sure
1850 if( pCurrentObject->FileType == AFS_FILE_TYPE_SYMLINK &&
1851 pCurrentObject->TargetFileId.Vnode == 0 &&
1852 pCurrentObject->TargetFileId.Unique == 0 &&
1853 pDirEntry->NameInformation.TargetName.Length == 0)
1856 ntStatus = AFSValidateSymLink( AuthGroup,
1859 if( !NT_SUCCESS( ntStatus))
1862 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1863 AFS_TRACE_LEVEL_ERROR,
1864 "AFSLocateNameEntry (FO: %08lX) Failed to evaluate possible DFS Link %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
1866 &pDirEntry->NameInformation.FileName,
1867 pCurrentObject->FileId.Cell,
1868 pCurrentObject->FileId.Volume,
1869 pCurrentObject->FileId.Vnode,
1870 pCurrentObject->FileId.Unique,
1873 try_return( ntStatus);
1878 // Update the name array
1881 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1882 AFS_TRACE_LEVEL_VERBOSE,
1883 "AFSLocateNameEntry (FO: %08lX) Inserting name array entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
1885 &pDirEntry->NameInformation.FileName,
1886 pCurrentObject->FileId.Cell,
1887 pCurrentObject->FileId.Volume,
1888 pCurrentObject->FileId.Vnode,
1889 pCurrentObject->FileId.Unique);
1891 ntStatus = AFSInsertNextElement( pNameArray,
1894 if( !NT_SUCCESS( ntStatus))
1897 try_return( ntStatus);
1903 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1904 AFS_TRACE_LEVEL_VERBOSE,
1905 "AFSLocateNameEntry (FO: %08lX) Completed processing %wZ Status %08lX\n",
1910 if( ( !NT_SUCCESS( ntStatus) &&
1911 ntStatus != STATUS_OBJECT_NAME_NOT_FOUND) ||
1912 ntStatus == STATUS_REPARSE)
1915 if( pDirEntry != NULL)
1918 lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
1920 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1921 AFS_TRACE_LEVEL_VERBOSE,
1922 "AFSLocateNameEntry Decrement6 count on %wZ DE %p Ccb %p Cnt %d\n",
1923 &pDirEntry->NameInformation.FileName,
1928 else if( pParentDirEntry != NULL)
1931 lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
1933 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1934 AFS_TRACE_LEVEL_VERBOSE,
1935 "AFSLocateNameEntry Decrement7 count on %wZ DE %p Ccb %p Cnt %d\n",
1936 &pParentDirEntry->NameInformation.FileName,
1942 if( bReleaseCurrentVolume)
1945 ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
1947 lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
1949 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
1950 AFS_TRACE_LEVEL_VERBOSE,
1951 "AFSLocateNameEntry Decrement3 count on volume %08lX Cnt %d\n",
1956 if( RootPathName->Buffer != uniFullPathName.Buffer)
1959 AFSExFreePoolWithTag( uniFullPathName.Buffer, 0);
1965 if( *ParentDirectoryCB != NULL)
1968 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1969 AFS_TRACE_LEVEL_VERBOSE,
1970 "AFSLocateNameEntry Count on Parent %wZ DE %p Ccb %p Cnt %d\n",
1971 &(*ParentDirectoryCB)->NameInformation.FileName,
1974 (*ParentDirectoryCB)->OpenReferenceCount);
1977 if( *DirectoryCB != NULL)
1980 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1981 AFS_TRACE_LEVEL_VERBOSE,
1982 "AFSLocateNameEntry Count on %wZ DE %p Ccb %p Cnt %d\n",
1983 &(*DirectoryCB)->NameInformation.FileName,
1986 (*DirectoryCB)->OpenReferenceCount);
1990 if( bSubstituteName &&
1991 uniSearchName.Buffer != NULL)
1994 AFSExFreePoolWithTag( uniSearchName.Buffer, 0);
2002 AFSCreateDirEntry( IN GUID *AuthGroup,
2003 IN AFSObjectInfoCB *ParentObjectInfo,
2004 IN AFSDirectoryCB *ParentDirCB,
2005 IN PUNICODE_STRING FileName,
2006 IN PUNICODE_STRING ComponentName,
2007 IN ULONG Attributes,
2008 IN OUT AFSDirectoryCB **DirEntry)
2011 NTSTATUS ntStatus = STATUS_SUCCESS;
2012 AFSDirectoryCB *pDirNode = NULL, *pExistingDirNode = NULL;
2013 UNICODE_STRING uniShortName;
2014 LARGE_INTEGER liFileSize = {0,0};
2020 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2021 AFS_TRACE_LEVEL_VERBOSE_2,
2022 "AFSCreateDirEntry Creating dir entry in parent %wZ FID %08lX-%08lX-%08lX-%08lX Component %wZ Attribs %08lX\n",
2023 &ParentDirCB->NameInformation.FileName,
2024 ParentObjectInfo->FileId.Cell,
2025 ParentObjectInfo->FileId.Volume,
2026 ParentObjectInfo->FileId.Vnode,
2027 ParentObjectInfo->FileId.Unique,
2032 // OK, before inserting the node into the parent tree, issue
2033 // the request to the service for node creation
2034 // We will need to drop the lock on the parent node since the create
2035 // could cause a callback into the file system to invalidate it's cache
2038 ntStatus = AFSNotifyFileCreate( AuthGroup,
2046 // If the returned status is STATUS_REPARSE then the entry exists
2047 // and we raced, get out.
2049 if( ntStatus == STATUS_REPARSE)
2052 *DirEntry = pDirNode;
2054 try_return( ntStatus = STATUS_SUCCESS);
2057 if( !NT_SUCCESS( ntStatus))
2060 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2061 AFS_TRACE_LEVEL_ERROR,
2062 "AFSCreateDirEntry Failed to create dir entry in parent %wZ FID %08lX-%08lX-%08lX-%08lX Component %wZ Attribs %08lX Status %08lX\n",
2063 &ParentDirCB->NameInformation.FileName,
2064 ParentObjectInfo->FileId.Cell,
2065 ParentObjectInfo->FileId.Volume,
2066 ParentObjectInfo->FileId.Vnode,
2067 ParentObjectInfo->FileId.Unique,
2072 try_return( ntStatus);
2075 AFSAcquireExcl( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock,
2079 // Before attempting to insert the new entry, check if we need to validate the parent
2082 if( BooleanFlagOn( ParentObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY))
2085 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2086 AFS_TRACE_LEVEL_VERBOSE,
2087 "AFSCreateDirEntry Verifying parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
2088 &ParentDirCB->NameInformation.FileName,
2089 ParentObjectInfo->FileId.Cell,
2090 ParentObjectInfo->FileId.Volume,
2091 ParentObjectInfo->FileId.Vnode,
2092 ParentObjectInfo->FileId.Unique);
2094 ntStatus = AFSVerifyEntry( AuthGroup,
2097 if( !NT_SUCCESS( ntStatus))
2100 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2101 AFS_TRACE_LEVEL_ERROR,
2102 "AFSCreateDirEntry Failed to verify parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
2103 &ParentDirCB->NameInformation.FileName,
2104 ParentObjectInfo->FileId.Cell,
2105 ParentObjectInfo->FileId.Volume,
2106 ParentObjectInfo->FileId.Vnode,
2107 ParentObjectInfo->FileId.Unique,
2110 AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
2112 try_return( ntStatus);
2117 // Check for the entry in the event we raced with some other thread
2120 AFSLocateCaseSensitiveDirEntry( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
2121 (ULONG)pDirNode->CaseSensitiveTreeEntry.HashIndex,
2124 if( pExistingDirNode != NULL)
2126 if (AFSIsEqualFID( &pDirNode->ObjectInformation->FileId,
2127 &pExistingDirNode->ObjectInformation->FileId))
2130 AFSDeleteDirEntry( ParentObjectInfo,
2133 lCount = InterlockedIncrement( &pExistingDirNode->OpenReferenceCount);
2135 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2136 AFS_TRACE_LEVEL_VERBOSE,
2137 "AFSCreateDirEntry Increment count on %wZ DE %p Cnt %d\n",
2138 &pExistingDirNode->NameInformation.FileName,
2142 *DirEntry = pExistingDirNode;
2144 AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
2146 try_return( ntStatus = STATUS_SUCCESS);
2152 // Need to tear down this entry and rebuild it below
2155 if( pExistingDirNode->OpenReferenceCount == 0)
2158 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2159 AFS_TRACE_LEVEL_VERBOSE,
2160 "AFSCreateDirEntry Different FIDs - Deleting DE %p for %wZ Old FID %08lX-%08lX-%08lX-%08lX New FID %08lX-%08lX-%08lX-%08lX\n",
2162 &pExistingDirNode->NameInformation.FileName,
2163 pExistingDirNode->ObjectInformation->FileId.Cell,
2164 pExistingDirNode->ObjectInformation->FileId.Volume,
2165 pExistingDirNode->ObjectInformation->FileId.Vnode,
2166 pExistingDirNode->ObjectInformation->FileId.Unique,
2167 pDirNode->ObjectInformation->FileId.Cell,
2168 pDirNode->ObjectInformation->FileId.Volume,
2169 pDirNode->ObjectInformation->FileId.Vnode,
2170 pDirNode->ObjectInformation->FileId.Unique);
2172 AFSDeleteDirEntry( ParentObjectInfo,
2178 SetFlag( pExistingDirNode->Flags, AFS_DIR_ENTRY_DELETED);
2180 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2181 AFS_TRACE_LEVEL_VERBOSE,
2182 "AFSCreateDirEntry Different FIDs - Removing DE %p for %wZ Old FID %08lX-%08lX-%08lX-%08lX New FID %08lX-%08lX-%08lX-%08lX\n",
2184 &pExistingDirNode->NameInformation.FileName,
2185 pExistingDirNode->ObjectInformation->FileId.Cell,
2186 pExistingDirNode->ObjectInformation->FileId.Volume,
2187 pExistingDirNode->ObjectInformation->FileId.Vnode,
2188 pExistingDirNode->ObjectInformation->FileId.Unique,
2189 pDirNode->ObjectInformation->FileId.Cell,
2190 pDirNode->ObjectInformation->FileId.Volume,
2191 pDirNode->ObjectInformation->FileId.Vnode,
2192 pDirNode->ObjectInformation->FileId.Unique);
2194 AFSRemoveNameEntry( ParentObjectInfo,
2201 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2202 AFS_TRACE_LEVEL_VERBOSE_2,
2203 "AFSCreateDirEntry Inserting dir entry in parent %wZ FID %08lX-%08lX-%08lX-%08lX Component %wZ\n",
2204 &ParentDirCB->NameInformation.FileName,
2205 ParentObjectInfo->FileId.Cell,
2206 ParentObjectInfo->FileId.Volume,
2207 ParentObjectInfo->FileId.Vnode,
2208 ParentObjectInfo->FileId.Unique,
2212 // Insert the directory node
2215 AFSInsertDirectoryNode( ParentObjectInfo,
2219 lCount = InterlockedIncrement( &pDirNode->OpenReferenceCount);
2221 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2222 AFS_TRACE_LEVEL_VERBOSE,
2223 "AFSCreateDirEntry Increment2 count on %wZ DE %p Cnt %d\n",
2224 &pDirNode->NameInformation.FileName,
2229 // Pass back the dir entry
2232 *DirEntry = pDirNode;
2234 AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
2245 AFSInsertDirectoryNode( IN AFSObjectInfoCB *ParentObjectInfo,
2246 IN AFSDirectoryCB *DirEntry,
2247 IN BOOLEAN InsertInEnumList)
2255 ASSERT( ExIsResourceAcquiredExclusiveLite( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock));
2258 // Insert the node into the directory node tree
2261 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2262 AFS_TRACE_LEVEL_VERBOSE,
2263 "AFSInsertDirectoryNode Insert DE %p for %wZ Clearing NOT_IN flag\n",
2265 &DirEntry->NameInformation.FileName);
2267 ClearFlag( DirEntry->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE);
2269 if( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead == NULL)
2272 ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead = DirEntry;
2274 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2275 AFS_TRACE_LEVEL_VERBOSE,
2276 "AFSInsertDirectoryNode Insert DE %p to head of case sensitive tree for %wZ\n",
2278 &DirEntry->NameInformation.FileName);
2283 AFSInsertCaseSensitiveDirEntry( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
2286 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2287 AFS_TRACE_LEVEL_VERBOSE,
2288 "AFSInsertDirectoryNode Insert DE %p to case sensitive tree for %wZ\n",
2290 &DirEntry->NameInformation.FileName);
2293 if( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead == NULL)
2296 ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead = DirEntry;
2298 SetFlag( DirEntry->Flags, AFS_DIR_ENTRY_CASE_INSENSTIVE_LIST_HEAD);
2300 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2301 AFS_TRACE_LEVEL_VERBOSE,
2302 "AFSInsertDirectoryNode Insert DE %p to head of case insensitive tree for %wZ\n",
2304 &DirEntry->NameInformation.FileName);
2309 AFSInsertCaseInsensitiveDirEntry( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
2312 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2313 AFS_TRACE_LEVEL_VERBOSE,
2314 "AFSInsertDirectoryNode Insert DE %p to case insensitive tree for %wZ\n",
2316 &DirEntry->NameInformation.FileName);
2320 // Into the shortname tree
2323 if( DirEntry->Type.Data.ShortNameTreeEntry.HashIndex != 0)
2326 if( ParentObjectInfo->Specific.Directory.ShortNameTree == NULL)
2329 ParentObjectInfo->Specific.Directory.ShortNameTree = DirEntry;
2331 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2332 AFS_TRACE_LEVEL_VERBOSE,
2333 "AFSInsertDirectoryNode Insert DE %p to head of shortname tree for %wZ\n",
2335 &DirEntry->NameInformation.FileName);
2337 SetFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_SHORT_NAME);
2342 if( !NT_SUCCESS( AFSInsertShortNameDirEntry( ParentObjectInfo->Specific.Directory.ShortNameTree,
2345 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2346 AFS_TRACE_LEVEL_VERBOSE,
2347 "AFSInsertDirectoryNode Failed to insert DE %p to shortname tree for %wZ\n",
2349 &DirEntry->NameInformation.FileName);
2353 SetFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_SHORT_NAME);
2355 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2356 AFS_TRACE_LEVEL_VERBOSE,
2357 "AFSInsertDirectoryNode Insert DE %p to shortname tree for %wZ\n",
2359 &DirEntry->NameInformation.FileName);
2364 if( InsertInEnumList)
2368 // And insert the node into the directory list
2371 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2372 AFS_TRACE_LEVEL_VERBOSE,
2373 "AFSInsertDirectoryNode Inserting entry %08lX %wZ FID %08lX-%08lX-%08lX-%08lX\n",
2375 &DirEntry->NameInformation.FileName,
2376 DirEntry->ObjectInformation->FileId.Cell,
2377 DirEntry->ObjectInformation->FileId.Volume,
2378 DirEntry->ObjectInformation->FileId.Vnode,
2379 DirEntry->ObjectInformation->FileId.Unique);
2381 if( ParentObjectInfo->Specific.Directory.DirectoryNodeListHead == NULL)
2384 ParentObjectInfo->Specific.Directory.DirectoryNodeListHead = DirEntry;
2389 ParentObjectInfo->Specific.Directory.DirectoryNodeListTail->ListEntry.fLink = (void *)DirEntry;
2391 DirEntry->ListEntry.bLink = (void *)ParentObjectInfo->Specific.Directory.DirectoryNodeListTail;
2394 ParentObjectInfo->Specific.Directory.DirectoryNodeListTail = DirEntry;
2396 SetFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
2398 lCount = InterlockedIncrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
2400 AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
2401 AFS_TRACE_LEVEL_VERBOSE,
2402 "AFSInsertDirectoryNode Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
2403 &DirEntry->NameInformation.FileName,
2405 ParentObjectInfo->FileId.Cell,
2406 ParentObjectInfo->FileId.Volume,
2407 ParentObjectInfo->FileId.Vnode,
2408 ParentObjectInfo->FileId.Unique);
2416 AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
2417 IN AFSDirectoryCB *DirEntry)
2420 NTSTATUS ntStatus = STATUS_SUCCESS;
2426 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2427 AFS_TRACE_LEVEL_VERBOSE,
2428 "AFSDeleteDirEntry Deleting dir entry in parent %08lX Entry %08lX %wZ FID %08lX-%08lX-%08lX-%08lX\n",
2431 &DirEntry->NameInformation.FileName,
2432 DirEntry->ObjectInformation->FileId.Cell,
2433 DirEntry->ObjectInformation->FileId.Volume,
2434 DirEntry->ObjectInformation->FileId.Vnode,
2435 DirEntry->ObjectInformation->FileId.Unique);
2437 AFSRemoveDirNodeFromParent( ParentObjectInfo,
2442 // Free up the name buffer if it was reallocated
2445 if( BooleanFlagOn( DirEntry->Flags, AFS_DIR_RELEASE_NAME_BUFFER))
2448 AFSExFreePoolWithTag( DirEntry->NameInformation.FileName.Buffer, 0);
2451 if( BooleanFlagOn( DirEntry->Flags, AFS_DIR_RELEASE_TARGET_NAME_BUFFER))
2454 AFSExFreePoolWithTag( DirEntry->NameInformation.TargetName.Buffer, 0);
2458 // Dereference the object for this dir entry
2461 ASSERT( DirEntry->ObjectInformation->ObjectReferenceCount > 0);
2463 lCount = InterlockedDecrement( &DirEntry->ObjectInformation->ObjectReferenceCount);
2467 SetFlag( DirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED);
2470 AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2471 AFS_TRACE_LEVEL_VERBOSE,
2472 "AFSDeleteDirEntry Decrement count on object %08lX Cnt %d\n",
2473 DirEntry->ObjectInformation,
2474 DirEntry->ObjectInformation->ObjectReferenceCount);
2476 ExDeleteResourceLite( &DirEntry->NonPaged->Lock);
2478 AFSExFreePoolWithTag( DirEntry->NonPaged, AFS_DIR_ENTRY_NP_TAG);
2481 // Free up the dir entry
2484 AFSExFreePoolWithTag( DirEntry, AFS_DIR_ENTRY_TAG);
2491 AFSRemoveDirNodeFromParent( IN AFSObjectInfoCB *ParentObjectInfo,
2492 IN AFSDirectoryCB *DirEntry,
2493 IN BOOLEAN RemoveFromEnumList)
2496 NTSTATUS ntStatus = STATUS_SUCCESS;
2503 ASSERT( ExIsResourceAcquiredExclusiveLite( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock));
2505 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2506 AFS_TRACE_LEVEL_VERBOSE,
2507 "AFSRemoveDirNodeFromParent Removing DirEntry %08lX %wZ FID %08lX-%08lX-%08lX-%08lX from Parent %08lX\n",
2509 &DirEntry->NameInformation.FileName,
2510 DirEntry->ObjectInformation->FileId.Cell,
2511 DirEntry->ObjectInformation->FileId.Volume,
2512 DirEntry->ObjectInformation->FileId.Vnode,
2513 DirEntry->ObjectInformation->FileId.Unique,
2516 if( !BooleanFlagOn( DirEntry->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE))
2519 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2520 AFS_TRACE_LEVEL_VERBOSE,
2521 "AFSRemoveDirNodeFromParent Removing DirEntry %08lX name %wZ\n",
2523 &DirEntry->NameInformation.FileName);
2525 AFSRemoveNameEntry( ParentObjectInfo,
2531 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2532 AFS_TRACE_LEVEL_VERBOSE,
2533 "AFSRemoveDirNodeFromParent DE %p for %wZ NOT removing entry due to flag set\n",
2535 &DirEntry->NameInformation.FileName);
2539 if( RemoveFromEnumList &&
2540 BooleanFlagOn( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST))
2544 // And remove the entry from the enumeration list
2547 if( DirEntry->ListEntry.fLink == NULL)
2550 ParentObjectInfo->Specific.Directory.DirectoryNodeListTail = (AFSDirectoryCB *)DirEntry->ListEntry.bLink;
2555 ((AFSDirectoryCB *)DirEntry->ListEntry.fLink)->ListEntry.bLink = DirEntry->ListEntry.bLink;
2558 if( DirEntry->ListEntry.bLink == NULL)
2561 ParentObjectInfo->Specific.Directory.DirectoryNodeListHead = (AFSDirectoryCB *)DirEntry->ListEntry.fLink;
2566 ((AFSDirectoryCB *)DirEntry->ListEntry.bLink)->ListEntry.fLink = DirEntry->ListEntry.fLink;
2569 ASSERT( ParentObjectInfo->Specific.Directory.DirectoryNodeCount > 0);
2571 lCount = InterlockedDecrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
2573 ClearFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
2575 AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
2576 AFS_TRACE_LEVEL_VERBOSE,
2577 "AFSRemoveDirNodeFromParent Removing entry %wZ Dec Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
2578 &DirEntry->NameInformation.FileName,
2580 ParentObjectInfo->FileId.Cell,
2581 ParentObjectInfo->FileId.Volume,
2582 ParentObjectInfo->FileId.Vnode,
2583 ParentObjectInfo->FileId.Unique);
2585 DirEntry->ListEntry.fLink = NULL;
2586 DirEntry->ListEntry.bLink = NULL;
2594 AFSFixupTargetName( IN OUT PUNICODE_STRING FileName,
2595 IN OUT PUNICODE_STRING TargetFileName)
2598 NTSTATUS ntStatus = STATUS_SUCCESS;
2599 UNICODE_STRING uniFileName;
2605 // We will process backwards from the end of the name looking
2606 // for the first \ we encounter
2609 uniFileName.Length = FileName->Length;
2610 uniFileName.MaximumLength = FileName->MaximumLength;
2612 uniFileName.Buffer = FileName->Buffer;
2617 if( uniFileName.Buffer[ (uniFileName.Length/sizeof( WCHAR)) - 1] == L'\\')
2621 // Subtract one more character off of the filename if it is not the root
2624 if( uniFileName.Length > sizeof( WCHAR))
2627 uniFileName.Length -= sizeof( WCHAR);
2631 // Now build up the target name
2634 TargetFileName->Length = FileName->Length - uniFileName.Length;
2637 // If we are not on the root then fixup the name
2640 if( uniFileName.Length > sizeof( WCHAR))
2643 TargetFileName->Length -= sizeof( WCHAR);
2645 TargetFileName->Buffer = &uniFileName.Buffer[ (uniFileName.Length/sizeof( WCHAR)) + 1];
2650 TargetFileName->Buffer = &uniFileName.Buffer[ uniFileName.Length/sizeof( WCHAR)];
2654 // Fixup the passed back filename length
2657 FileName->Length = uniFileName.Length;
2659 TargetFileName->MaximumLength = TargetFileName->Length;
2664 uniFileName.Length -= sizeof( WCHAR);
2672 AFSParseName( IN PIRP Irp,
2674 OUT PUNICODE_STRING FileName,
2675 OUT PUNICODE_STRING ParsedFileName,
2676 OUT PUNICODE_STRING RootFileName,
2677 OUT ULONG *ParseFlags,
2678 OUT AFSVolumeCB **VolumeCB,
2679 OUT AFSDirectoryCB **ParentDirectoryCB,
2680 OUT AFSNameArrayHdr **NameArray)
2683 NTSTATUS ntStatus = STATUS_SUCCESS;
2684 PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
2685 AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
2686 UNICODE_STRING uniFullName, uniComponentName, uniRemainingPath;
2688 AFSDirectoryCB *pDirEntry = NULL, *pShareDirEntry = NULL, *pTargetDirEntry = NULL;
2689 USHORT usIndex = 0, usDriveIndex = 0;
2690 AFSCcb *pRelatedCcb = NULL;
2691 AFSNameArrayHdr *pNameArray = NULL, *pRelatedNameArray = NULL;
2692 USHORT usComponentIndex = 0;
2693 USHORT usComponentLength = 0;
2694 AFSVolumeCB *pVolumeCB = NULL;
2695 AFSFcb *pRelatedFcb = NULL;
2696 BOOLEAN bReleaseTreeLock = FALSE;
2697 BOOLEAN bIsAllShare = FALSE;
2704 // Indicate we are opening a root ...
2707 *ParseFlags = AFS_PARSE_FLAG_ROOT_ACCESS;
2709 if( pIrpSp->FileObject->RelatedFileObject != NULL)
2712 pRelatedFcb = (AFSFcb *)pIrpSp->FileObject->RelatedFileObject->FsContext;
2714 pRelatedCcb = (AFSCcb *)pIrpSp->FileObject->RelatedFileObject->FsContext2;
2716 pRelatedNameArray = pRelatedCcb->NameArray;
2718 uniFullName = pIrpSp->FileObject->FileName;
2720 ASSERT( pRelatedFcb != NULL);
2723 // No wild cards in the name
2726 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2727 AFS_TRACE_LEVEL_VERBOSE_2,
2728 "AFSParseName (%08lX) Relative open for %wZ FID %08lX-%08lX-%08lX-%08lX component %wZ\n",
2730 &pRelatedCcb->DirectoryCB->NameInformation.FileName,
2731 pRelatedCcb->DirectoryCB->ObjectInformation->FileId.Cell,
2732 pRelatedCcb->DirectoryCB->ObjectInformation->FileId.Volume,
2733 pRelatedCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
2734 pRelatedCcb->DirectoryCB->ObjectInformation->FileId.Unique,
2737 if( FsRtlDoesNameContainWildCards( &uniFullName))
2740 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2741 AFS_TRACE_LEVEL_ERROR,
2742 "AFSParseName (%08lX) Component %wZ contains wild cards\n",
2746 try_return( ntStatus = STATUS_OBJECT_NAME_INVALID);
2749 pVolumeCB = pRelatedFcb->ObjectInformation->VolumeCB;
2751 pDirEntry = pRelatedCcb->DirectoryCB;
2753 *FileName = pIrpSp->FileObject->FileName;
2756 // Grab the root node while checking state
2759 AFSAcquireShared( pVolumeCB->VolumeLock,
2762 if( BooleanFlagOn( pVolumeCB->ObjectInformation.Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID) ||
2763 BooleanFlagOn( pVolumeCB->Flags, AFS_VOLUME_FLAGS_OFFLINE))
2767 // The volume has been taken off line so fail the access
2770 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2771 AFS_TRACE_LEVEL_ERROR,
2772 "AFSParseName (%08lX) Volume %08lX:%08lX OFFLINE/INVALID\n",
2774 pVolumeCB->ObjectInformation.FileId.Cell,
2775 pVolumeCB->ObjectInformation.FileId.Volume);
2777 AFSReleaseResource( pVolumeCB->VolumeLock);
2779 try_return( ntStatus = STATUS_DEVICE_NOT_READY);
2782 if( BooleanFlagOn( pVolumeCB->ObjectInformation.Flags, AFS_OBJECT_FLAGS_VERIFY))
2785 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2786 AFS_TRACE_LEVEL_VERBOSE,
2787 "AFSParseName (%08lX) Verifying root of volume %08lX:%08lX\n",
2789 pVolumeCB->ObjectInformation.FileId.Cell,
2790 pVolumeCB->ObjectInformation.FileId.Volume);
2792 ntStatus = AFSVerifyVolume( (ULONGLONG)PsGetCurrentProcessId(),
2795 if( !NT_SUCCESS( ntStatus))
2798 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2799 AFS_TRACE_LEVEL_ERROR,
2800 "AFSParseName (%08lX) Failed verification of root Status %08lX\n",
2804 AFSReleaseResource( pVolumeCB->VolumeLock);
2806 try_return( ntStatus);
2810 AFSReleaseResource( pVolumeCB->VolumeLock);
2812 if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY))
2815 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2816 AFS_TRACE_LEVEL_VERBOSE,
2817 "AFSParseName (%08lX) Verifying parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
2819 &pDirEntry->NameInformation.FileName,
2820 pDirEntry->ObjectInformation->FileId.Cell,
2821 pDirEntry->ObjectInformation->FileId.Volume,
2822 pDirEntry->ObjectInformation->FileId.Vnode,
2823 pDirEntry->ObjectInformation->FileId.Unique);
2826 // Directory TreeLock should be exclusively held
2829 AFSAcquireExcl( pDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
2832 ntStatus = AFSVerifyEntry( AuthGroup,
2835 AFSReleaseResource( pDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
2837 if( !NT_SUCCESS( ntStatus))
2840 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2841 AFS_TRACE_LEVEL_VERBOSE,
2842 "AFSParseName (%08lX) Failed verification of parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
2844 &pDirEntry->NameInformation.FileName,
2845 pDirEntry->ObjectInformation->FileId.Cell,
2846 pDirEntry->ObjectInformation->FileId.Volume,
2847 pDirEntry->ObjectInformation->FileId.Vnode,
2848 pDirEntry->ObjectInformation->FileId.Unique,
2851 try_return( ntStatus);
2856 // Create our full path name buffer
2859 uniFullName.MaximumLength = pRelatedCcb->FullFileName.Length +
2861 pIrpSp->FileObject->FileName.Length +
2864 uniFullName.Length = 0;
2866 uniFullName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
2867 uniFullName.MaximumLength,
2868 AFS_NAME_BUFFER_THREE_TAG);
2870 if( uniFullName.Buffer == NULL)
2873 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2874 AFS_TRACE_LEVEL_ERROR,
2875 "AFSParseName (%08lX) Failed to allocate full name buffer\n",
2878 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
2881 RtlZeroMemory( uniFullName.Buffer,
2882 uniFullName.MaximumLength);
2884 RtlCopyMemory( uniFullName.Buffer,
2885 pRelatedCcb->FullFileName.Buffer,
2886 pRelatedCcb->FullFileName.Length);
2888 uniFullName.Length = pRelatedCcb->FullFileName.Length;
2890 usComponentIndex = (USHORT)(uniFullName.Length/sizeof( WCHAR));
2892 usComponentLength = pIrpSp->FileObject->FileName.Length;
2894 if( uniFullName.Buffer[ (uniFullName.Length/sizeof( WCHAR)) - 1] != L'\\' &&
2895 pIrpSp->FileObject->FileName.Length > 0 &&
2896 pIrpSp->FileObject->FileName.Buffer[ 0] != L'\\' &&
2897 pIrpSp->FileObject->FileName.Buffer[ 0] != L':')
2900 uniFullName.Buffer[ (uniFullName.Length/sizeof( WCHAR))] = L'\\';
2902 uniFullName.Length += sizeof( WCHAR);
2904 usComponentLength += sizeof( WCHAR);
2907 if( pIrpSp->FileObject->FileName.Length > 0)
2910 RtlCopyMemory( &uniFullName.Buffer[ uniFullName.Length/sizeof( WCHAR)],
2911 pIrpSp->FileObject->FileName.Buffer,
2912 pIr
\epSp->FileObject->FileName.Length);
2914 uniFullName.Length += pIrpSp->FileObject->FileName.Length;
2917 *RootFileName = uniFullName;
2920 // We populate up to the current parent
2923 if( pRelatedNameArray == NULL)
2927 // Init and populate our name array
2930 pNameArray = AFSInitNameArray( NULL,
2933 if( pNameArray == NULL)
2936 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2937 AFS_TRACE_LEVEL_VERBOSE,
2938 "AFSParseName (%08lX) Failed to initialize name array\n",
2941 AFSExFreePoolWithTag( uniFullName.Buffer, 0);
2943 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
2946 ntStatus = AFSPopulateNameArray( pNameArray,
2948 pRelatedCcb->DirectoryCB);
2954 // Init and populate our name array
2957 pNameArray = AFSInitNameArray( NULL,
2958 pRelatedNameArray->MaxElementCount);
2960 if( pNameArray == NULL)
2963 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2964 AFS_TRACE_LEVEL_VERBOSE,
2965 "AFSParseName (%08lX) Failed to initialize name array\n",
2968 AFSExFreePoolWithTag( uniFullName.Buffer, 0);
2970 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
2973 ntStatus = AFSPopulateNameArrayFromRelatedArray( pNameArray,
2975 pRelatedCcb->DirectoryCB);
2978 if( !NT_SUCCESS( ntStatus))
2981 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2982 AFS_TRACE_LEVEL_VERBOSE,
2983 "AFSParseName (%08lX) Failed to populate name array\n",
2986 AFSExFreePoolWithTag( uniFullName.Buffer, 0);
2988 try_return( ntStatus);
2991 ParsedFileName->Length = usComponentLength;
2992 ParsedFileName->MaximumLength = uniFullName.MaximumLength;
2994 ParsedFileName->Buffer = &uniFullName.Buffer[ usComponentIndex];
2997 // Indicate to caller that RootFileName must be freed
3000 SetFlag( *ParseFlags, AFS_PARSE_FLAG_FREE_FILE_BUFFER);
3002 *NameArray = pNameArray;
3004 *VolumeCB = pVolumeCB;
3007 // Increment our volume reference count
3010 lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
3012 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
3013 AFS_TRACE_LEVEL_VERBOSE,
3014 "AFSParseName Increment count on volume %08lX Cnt %d\n",
3018 *ParentDirectoryCB = pDirEntry;
3020 lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
3022 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3023 AFS_TRACE_LEVEL_VERBOSE,
3024 "AFSParseName Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
3025 &pDirEntry->NameInformation.FileName,
3030 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3031 AFS_TRACE_LEVEL_VERBOSE_2,
3032 "AFSParseName (%08lX) Returning full name %wZ\n",
3036 try_return( ntStatus);
3040 // No wild cards in the name
3043 uniFullName = pIrpSp->FileObject->FileName;
3045 if( FsRtlDoesNameContainWildCards( &uniFullName) ||
3046 uniFullName.Length < AFSServerName.Length)
3049 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3050 AFS_TRACE_LEVEL_ERROR,
3051 "AFSParseName (%08lX) Name %wZ contains wild cards or too short\n",
3055 try_return( ntStatus = STATUS_OBJECT_NAME_INVALID);
3059 // The name is a fully qualified name. Parse out the server/share names and
3060 // point to the root qualified name
3061 // First thing is to locate the server name
3064 FsRtlDissectName( uniFullName,
3068 uniFullName = uniRemainingPath;
3071 // This component is the server name we are serving
3074 if( RtlCompareUnicodeString( &uniComponentName,
3080 // Drive letter based name?
3083 uniFullName = pIrpSp->FileObject->FileName;
3085 while( usIndex < uniFullName.Length/sizeof( WCHAR))
3088 if( uniFullName.Buffer[ usIndex] == L':')
3091 uniFullName.Buffer = &uniFullName.Buffer[ usIndex + 2];
3093 uniFullName.Length -= (usIndex + 2) * sizeof( WCHAR);
3095 usDriveIndex = usIndex - 1;
3104 // Do we have the right server name now?
3107 FsRtlDissectName( uniFullName,
3111 uniFullName = uniRemainingPath;
3114 // This component is the server name we are serving
3117 if( RtlCompareUnicodeString( &uniComponentName,
3122 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3123 AFS_TRACE_LEVEL_ERROR,
3124 "AFSParseName (%08lX) Name %wZ does not have server name\n",
3126 &pIrpSp->FileObject->FileName);
3128 try_return( ntStatus = STATUS_BAD_NETWORK_NAME);
3132 // Validate this drive letter is actively mapped
3135 if( usDriveIndex > 0 &&
3136 !AFSIsDriveMapped( pIrpSp->FileObject->FileName.Buffer[ usDriveIndex]))
3139 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3140 AFS_TRACE_LEVEL_ERROR,
3141 "AFSParseName (%08lX) Name %wZ contains invalid drive mapping\n",
3143 &pIrpSp->FileObject->FileName);
3145 try_return( ntStatus = STATUS_BAD_NETWORK_NAME);
3149 if( FsRtlDoesNameContainWildCards( &uniFullName))
3152 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3153 AFS_TRACE_LEVEL_ERROR,
3154 "AFSParseName (%08lX) Component %wZ contains wild cards\n",
3158 try_return( ntStatus = STATUS_OBJECT_NAME_INVALID);
3161 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3162 AFS_TRACE_LEVEL_VERBOSE_2,
3163 "AFSParseName (%08lX) Processing full name %wZ\n",
3167 if( uniFullName.Length > 0 &&
3168 uniFullName.Buffer[ (uniFullName.Length/sizeof( WCHAR)) - 1] == L'\\')
3171 uniFullName.Length -= sizeof( WCHAR);
3175 // Be sure we are online and ready to go
3178 AFSAcquireShared( AFSGlobalRoot->VolumeLock,
3181 if( BooleanFlagOn( AFSGlobalRoot->ObjectInformation.Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID) ||
3182 BooleanFlagOn( AFSGlobalRoot->Flags, AFS_VOLUME_FLAGS_OFFLINE))
3186 // The volume has been taken off line so fail the access
3189 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3190 AFS_TRACE_LEVEL_ERROR,
3191 "AFSParseName (%08lX) Volume %08lX:%08lX OFFLINE/INVALID\n",
3193 AFSGlobalRoot->ObjectInformation.FileId.Cell,
3194 AFSGlobalRoot->ObjectInformation.FileId.Volume);
3196 AFSReleaseResource( AFSGlobalRoot->VolumeLock);
3198 try_return( ntStatus = STATUS_DEVICE_NOT_READY);
3201 if( BooleanFlagOn( AFSGlobalRoot->ObjectInformation.Flags, AFS_OBJECT_FLAGS_VERIFY))
3204 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3205 AFS_TRACE_LEVEL_VERBOSE,
3206 "AFSParseName (%08lX) Verifying root of volume %08lX:%08lX\n",
3208 AFSGlobalRoot->ObjectInformation.FileId.Cell,
3209 AFSGlobalRoot->ObjectInformation.FileId.Volume);
3211 ntStatus = AFSVerifyVolume( (ULONGLONG)PsGetCurrentProcessId(),
3214 if( !NT_SUCCESS( ntStatus))
3217 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3218 AFS_TRACE_LEVEL_ERROR,
3219 "AFSParseName (%08lX) Failed verification of root Status %08lX\n",
3223 AFSReleaseResource( AFSGlobalRoot->VolumeLock);
3225 try_return( ntStatus);
3229 AFSReleaseResource( AFSGlobalRoot->VolumeLock);
3231 if( !BooleanFlagOn( AFSGlobalRoot->ObjectInformation.Flags, AFS_OBJECT_FLAGS_DIRECTORY_ENUMERATED))
3234 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3235 AFS_TRACE_LEVEL_VERBOSE,
3236 "AFSParseName (%08lX) Enumerating global root of volume %08lX:%08lX\n",
3238 AFSGlobalRoot->ObjectInformation.FileId.Cell,
3239 AFSGlobalRoot->ObjectInformation.FileId.Volume);
3241 ntStatus = AFSEnumerateGlobalRoot( AuthGroup);
3243 if( !NT_SUCCESS( ntStatus))
3246 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3247 AFS_TRACE_LEVEL_ERROR,
3248 "AFSParseName (%08lX) Failed enumeraiton of root Status %08lX\n",
3252 try_return( ntStatus);
3257 // Check for the \\Server access and return it as though it where \\Server\Globalroot
3260 if( uniRemainingPath.Buffer == NULL ||
3261 ( uniRemainingPath.Length == sizeof( WCHAR) &&
3262 uniRemainingPath.Buffer[ 0] == L'\\'))
3265 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3266 AFS_TRACE_LEVEL_VERBOSE_2,
3267 "AFSParseName (%08lX) Returning global root access\n",
3270 lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
3272 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3273 AFS_TRACE_LEVEL_VERBOSE,
3274 "AFSParseName Increment2 count on %wZ DE %p Ccb %p Cnt %d\n",
3275 &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
3276 AFSGlobalRoot->DirectoryCB,
3282 FileName->Length = 0;
3283 FileName->MaximumLength = 0;
3284 FileName->Buffer = NULL;
3286 try_return( ntStatus = STATUS_SUCCESS);
3289 *RootFileName = uniFullName;
3292 // Include the starting \ in the root name
3295 if( RootFileName->Buffer[ 0] != L'\\')
3297 RootFileName->Buffer--;
3298 RootFileName->Length += sizeof( WCHAR);
3299 RootFileName->MaximumLength += sizeof( WCHAR);
3303 // Get the 'share' name
3306 FsRtlDissectName( uniFullName,
3310 if( FsRtlDoesNameContainWildCards( &uniFullName))
3313 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3314 AFS_TRACE_LEVEL_ERROR,
3315 "AFSParseName (%08lX) Component %wZ contains wild cards\n",
3319 try_return( ntStatus = STATUS_OBJECT_NAME_INVALID);
3323 // If this is the ALL access then perform some additional processing
3326 if( uniComponentName.Length == 0 ||
3327 RtlCompareUnicodeString( &uniComponentName,
3335 // If there is nothing else then get out
3338 if( uniRemainingPath.Buffer == NULL ||
3339 uniRemainingPath.Length == 0 ||
3340 ( uniRemainingPath.Length == sizeof( WCHAR) &&
3341 uniRemainingPath.Buffer[ 0] == L'\\'))
3344 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3345 AFS_TRACE_LEVEL_VERBOSE_2,
3346 "AFSParseName (%08lX) Returning global root access\n",
3349 lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
3351 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3352 AFS_TRACE_LEVEL_VERBOSE,
3353 "AFSParseName Increment3 count on %wZ DE %p Ccb %p Cnt %d\n",
3354 &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
3355 AFSGlobalRoot->DirectoryCB,
3361 FileName->Length = 0;
3362 FileName->MaximumLength = 0;
3363 FileName->Buffer = NULL;
3365 try_return( ntStatus = STATUS_SUCCESS);
3369 // Process the name again to strip off the ALL portion
3372 uniFullName = uniRemainingPath;
3374 FsRtlDissectName( uniFullName,
3379 // Check for the PIOCtl name
3382 if( RtlCompareUnicodeString( &uniComponentName,
3387 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3388 AFS_TRACE_LEVEL_VERBOSE_2,
3389 "AFSParseName (%08lX) Returning root PIOCtl access\n",
3392 lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
3394 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3395 AFS_TRACE_LEVEL_VERBOSE,
3396 "AFSParseName Increment4 count on %wZ DE %p Ccb %p Cnt %d\n",
3397 &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
3398 AFSGlobalRoot->DirectoryCB,
3402 ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
3406 *FileName = AFSPIOCtlName;
3408 try_return( ntStatus = STATUS_SUCCESS);
3411 else if( (pDirEntry = AFSGetSpecialShareNameEntry( &uniComponentName,
3412 &uniRemainingPath)) != NULL)
3415 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3416 AFS_TRACE_LEVEL_VERBOSE_2,
3417 "AFSParseName (%08lX) Returning root share name %wZ access\n",
3422 // Add in the full share name to pass back
3425 if( uniRemainingPath.Buffer != NULL)
3429 // This routine strips off the leading slash so add it back in
3432 uniRemainingPath.Buffer--;
3433 uniRemainingPath.Length += sizeof( WCHAR);
3434 uniRemainingPath.MaximumLength += sizeof( WCHAR);
3437 // And the cell name
3440 uniRemainingPath.Buffer -= (uniComponentName.Length/sizeof( WCHAR));
3441 uniRemainingPath.Length += uniComponentName.Length;
3442 uniRemainingPath.MaximumLength += uniComponentName.Length;
3444 uniComponentName = uniRemainingPath;
3449 *FileName = uniComponentName;
3451 *ParentDirectoryCB = pDirEntry;
3453 ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
3455 lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
3457 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3458 AFS_TRACE_LEVEL_VERBOSE,
3459 "AFSParseName Increment5 count on %wZ DE %p Ccb %p Cnt %d\n",
3460 &pDirEntry->NameInformation.FileName,
3465 try_return( ntStatus = STATUS_SUCCESS);
3469 // Determine the 'share' we are accessing
3472 ulCRC = AFSGenerateCRC( &uniComponentName,
3475 AFSAcquireShared( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
3478 bReleaseTreeLock = TRUE;
3480 AFSLocateCaseSensitiveDirEntry( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
3484 if( pDirEntry == NULL)
3487 ulCRC = AFSGenerateCRC( &uniComponentName,
3490 AFSLocateCaseInsensitiveDirEntry( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
3494 if( pDirEntry == NULL)
3498 // OK, if this component is a valid short name then try
3499 // a lookup in the short name tree
3502 if( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
3503 RtlIsNameLegalDOS8Dot3( &uniComponentName,
3508 AFSLocateShortNameDirEntry( AFSGlobalRoot->ObjectInformation.Specific.Directory.ShortNameTree,
3513 if( pDirEntry == NULL)
3517 // Check with the service whether it is a valid cell name
3520 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
3522 bReleaseTreeLock = FALSE;
3524 ntStatus = AFSCheckCellName( AuthGroup,
3528 if( !NT_SUCCESS( ntStatus))
3532 uniRemainingPath.Length == 0 &&
3533 ntStatus == STATUS_OBJECT_PATH_NOT_FOUND)
3536 ntStatus = STATUS_OBJECT_NAME_NOT_FOUND;
3539 try_return( ntStatus);
3545 if( bReleaseTreeLock)
3547 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
3552 // Be sure we are starting from the correct volume
3555 if( pDirEntry->ObjectInformation->VolumeCB != AFSGlobalRoot)
3559 // We dropped the global root in the CheckCellName routine which is the
3560 // only way we can be here
3563 pVolumeCB = pDirEntry->ObjectInformation->VolumeCB;
3566 // Init our name array
3569 pNameArray = AFSInitNameArray( AFSGlobalRoot->DirectoryCB,
3572 if( pNameArray == NULL)
3575 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3576 AFS_TRACE_LEVEL_VERBOSE,
3577 "AFSParseName (%08lX) Failed to initialize name array\n",
3580 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
3583 ntStatus = AFSInsertNextElement( pNameArray,
3584 pVolumeCB->DirectoryCB);
3589 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3590 AFS_TRACE_LEVEL_VERBOSE,
3591 "AFSParseName (%08lX) Failed to insert name array element\n",
3594 try_return( ntStatus);
3598 // In this case don't add back in the 'share' name since that is where we are
3599 // starting. Just put the leading slash back in
3602 if( uniRemainingPath.Buffer != NULL)
3605 uniRemainingPath.Buffer--;
3606 uniRemainingPath.Length += sizeof( WCHAR);
3607 uniRemainingPath.MaximumLength += sizeof( WCHAR);
3609 if( uniRemainingPath.Length > sizeof( WCHAR))
3612 ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
3616 // Pass back the parent being the root of the volume
3619 *ParentDirectoryCB = pVolumeCB->DirectoryCB;
3625 // Pass back a root slash
3628 uniRemainingPath = uniComponentName;
3630 uniRemainingPath.Buffer--;
3631 uniRemainingPath.Length = sizeof( WCHAR);
3632 uniRemainingPath.MaximumLength = sizeof( WCHAR);
3635 // This is a root open so pass back no parent
3638 *ParentDirectoryCB = NULL;
3644 pVolumeCB = AFSGlobalRoot;
3647 // Init our name array
3650 pNameArray = AFSInitNameArray( AFSGlobalRoot->DirectoryCB,
3652 if( pNameArray == NULL)
3655 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3656 AFS_TRACE_LEVEL_VERBOSE,
3657 "AFSParseName (%08lX) Failed to initialize name array\n",
3660 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
3664 // Add back in the 'share' portion of the name since we will parse it out on return
3667 if( uniRemainingPath.Buffer != NULL)
3671 // This routine strips off the leading slash so add it back in
3674 uniRemainingPath.Buffer--;
3675 uniRemainingPath.Length += sizeof( WCHAR);
3676 uniRemainingPath.MaximumLength += sizeof( WCHAR);
3678 if( uniRemainingPath.Length > sizeof( WCHAR))
3681 ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
3685 // And the cell name
3688 uniRemainingPath.Buffer -= (uniComponentName.Length/sizeof( WCHAR));
3689 uniRemainingPath.Length += uniComponentName.Length;
3690 uniRemainingPath.MaximumLength += uniComponentName.Length;
3695 uniRemainingPath = uniComponentName;
3699 // And the leading slash again ...
3702 uniRemainingPath.Buffer--;
3703 uniRemainingPath.Length += sizeof( WCHAR);
3704 uniRemainingPath.MaximumLength += sizeof( WCHAR);
3706 lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
3708 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3709 AFS_TRACE_LEVEL_VERBOSE,
3710 "AFSParseName Increment6 count on %wZ DE %p Ccb %p Cnt %d\n",
3711 &pVolumeCB->DirectoryCB->NameInformation.FileName,
3712 pVolumeCB->DirectoryCB,
3714 lCount = pVolumeCB->DirectoryCB->OpenReferenceCount);
3717 // Pass back the parent being the volume root
3720 *ParentDirectoryCB = pVolumeCB->DirectoryCB;
3725 // Return the remaining portion as the file name
3728 *FileName = uniRemainingPath;
3730 *ParsedFileName = uniRemainingPath;
3732 *NameArray = pNameArray;
3734 *VolumeCB = pVolumeCB;
3737 // Increment our reference on the volume
3740 lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
3742 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
3743 AFS_TRACE_LEVEL_VERBOSE,
3744 "AFSParseName Increment2 count on global volume %08lX Cnt %d\n",
3750 if( NT_SUCCESS( ntStatus))
3753 if( *ParentDirectoryCB != NULL)
3756 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3757 AFS_TRACE_LEVEL_VERBOSE,
3758 "AFSParseName Count on %wZ DE %p Ccb %p Cnt %d\n",
3759 &(*ParentDirectoryCB)->NameInformation.FileName,
3762 (*ParentDirectoryCB)->OpenReferenceCount);
3766 if( *VolumeCB != NULL)
3768 ASSERT( (*VolumeCB)->VolumeReferenceCount > 1);
3771 if( ntStatus != STATUS_SUCCESS)
3774 if( pNameArray != NULL)
3777 AFSFreeNameArray( pNameArray);
3786 AFSCheckCellName( IN GUID *AuthGroup,
3787 IN UNICODE_STRING *CellName,
3788 OUT AFSDirectoryCB **ShareDirEntry)
3791 NTSTATUS ntStatus = STATUS_SUCCESS;
3792 UNICODE_STRING uniName;
3793 AFSDirEnumEntry *pDirEnumEntry = NULL;
3794 AFSDeviceExt *pDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
3795 AFSDirHdr *pDirHdr = &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr;
3796 AFSDirectoryCB *pDirNode = NULL;
3797 UNICODE_STRING uniDirName, uniTargetName;
3798 AFSVolumeCB *pVolumeCB = NULL;
3805 // Look for some default names we will not handle
3808 RtlInitUnicodeString( &uniName,
3811 if( RtlCompareUnicodeString( &uniName,
3816 try_return( ntStatus = STATUS_NO_SUCH_FILE);
3819 RtlInitUnicodeString( &uniName,
3822 if( RtlCompareUnicodeString( &uniName,
3827 try_return( ntStatus = STATUS_NO_SUCH_FILE);
3830 RtlInitUnicodeString( &uniName,
3833 if( RtlCompareUnicodeString( &uniName,
3838 try_return( ntStatus = STATUS_NO_SUCH_FILE);
3841 RtlInitUnicodeString( &uniName,
3844 if( RtlCompareUnicodeString( &uniName,
3849 try_return( ntStatus = STATUS_NO_SUCH_FILE);
3853 // OK, ask the CM about this component name
3856 ntStatus = AFSEvaluateTargetByName( AuthGroup,
3857 &AFSGlobalRoot->ObjectInformation,
3861 if( !NT_SUCCESS( ntStatus))
3864 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3865 AFS_TRACE_LEVEL_WARNING,
3866 "AFSCheckCellName entry %wZ does not exist parent FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
3868 AFSGlobalRoot->ObjectInformation.FileId.Cell,
3869 AFSGlobalRoot->ObjectInformation.FileId.Volume,
3870 AFSGlobalRoot->ObjectInformation.FileId.Vnode,
3871 AFSGlobalRoot->ObjectInformation.FileId.Unique,
3874 try_return( ntStatus);
3878 // OK, we have a dir enum entry back so add it to the root node
3881 uniDirName = *CellName;
3883 uniTargetName.Length = (USHORT)pDirEnumEntry->TargetNameLength;
3884 uniTargetName.MaximumLength = uniTargetName.Length;
3885 uniTargetName.Buffer = (WCHAR *)((char *)pDirEnumEntry + pDirEnumEntry->TargetNameOffset);
3888 // Is this entry a root volume entry?
3891 if( pDirEnumEntry->FileId.Cell != AFSGlobalRoot->ObjectInformation.FileId.Cell ||
3892 pDirEnumEntry->FileId.Volume != AFSGlobalRoot->ObjectInformation.FileId.Volume)
3896 // Build the root volume entry
3899 ntStatus = AFSBuildRootVolume( AuthGroup,
3900 &pDirEnumEntry->FileId,
3903 if( !NT_SUCCESS( ntStatus))
3905 try_return( ntStatus);
3908 *ShareDirEntry = pVolumeCB->DirectoryCB;
3910 lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
3912 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
3913 AFS_TRACE_LEVEL_VERBOSE,
3914 "AFSCheckCellName Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
3915 &pVolumeCB->DirectoryCB->NameInformation.FileName,
3916 pVolumeCB->DirectoryCB,
3920 lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
3925 lCount = InterlockedIncrement( &pDirHdr->ContentIndex);
3927 pDirNode = AFSInitDirEntry( &AFSGlobalRoot->ObjectInformation,
3933 if( pDirNode == NULL)
3936 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
3940 // Init the short name if we have one
3943 if( pDirEnumEntry->ShortNameLength > 0)
3946 pDirNode->NameInformation.ShortNameLength = pDirEnumEntry->ShortNameLength;
3948 RtlCopyMemory( pDirNode->NameInformation.ShortName,
3949 pDirEnumEntry->ShortName,
3950 pDirNode->NameInformation.ShortNameLength);
3953 AFSAcquireExcl( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
3957 // Insert the node into the name tree
3960 ASSERT( ExIsResourceAcquiredExclusiveLite( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock));
3962 if( pDirHdr->CaseSensitiveTreeHead == NULL)
3965 pDirHdr->CaseSensitiveTreeHead = pDirNode;
3970 if( !NT_SUCCESS( AFSInsertCaseSensitiveDirEntry( pDirHdr->CaseSensitiveTreeHead,
3974 AFSDeleteDirEntry( &AFSGlobalRoot->ObjectInformation,
3977 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
3979 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
3983 ClearFlag( pDirNode->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE);
3985 if( pDirHdr->CaseInsensitiveTreeHead == NULL)
3988 pDirHdr->CaseInsensitiveTreeHead = pDirNode;
3990 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_CASE_INSENSTIVE_LIST_HEAD);
3995 AFSInsertCaseInsensitiveDirEntry( pDirHdr->CaseInsensitiveTreeHead,
3999 if( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeListHead == NULL)
4002 AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeListHead = pDirNode;
4007 AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeListTail->ListEntry.fLink = pDirNode;
4009 pDirNode->ListEntry.bLink = AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeListTail;
4012 AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeListTail = pDirNode;
4014 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
4016 lCount = InterlockedIncrement( &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeCount);
4018 AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
4019 AFS_TRACE_LEVEL_VERBOSE,
4020 "AFSCheckCellName Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
4021 &pDirNode->NameInformation.FileName,
4023 AFSGlobalRoot->ObjectInformation.FileId.Cell,
4024 AFSGlobalRoot->ObjectInformation.FileId.Volume,
4025 AFSGlobalRoot->ObjectInformation.FileId.Vnode,
4026 AFSGlobalRoot->ObjectInformation.FileId.Unique);
4028 lCount = InterlockedIncrement( &pDirNode->OpenReferenceCount);
4030 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
4031 AFS_TRACE_LEVEL_VERBOSE,
4032 "AFSCheckCellName Increment2 count on %wZ DE %p Ccb %p Cnt %d\n",
4033 &pDirNode->NameInformation.FileName,
4038 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
4041 // Pass back the dir node
4044 *ShareDirEntry = pDirNode;
4049 if( pDirEnumEntry != NULL)
4052 AFSExFreePoolWithTag( pDirEnumEntry, AFS_GENERIC_MEMORY_31_TAG);
4060 AFSBuildMountPointTarget( IN GUID *AuthGroup,
4061 IN AFSDirectoryCB *DirectoryCB,
4062 OUT AFSVolumeCB **TargetVolumeCB)
4065 NTSTATUS ntStatus = STATUS_SUCCESS;
4066 AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
4067 AFSDirEnumEntry *pDirEntry = NULL;
4068 AFSDirectoryCB *pDirNode = NULL;
4069 UNICODE_STRING uniDirName, uniTargetName;
4070 ULONGLONG ullIndex = 0;
4071 AFSVolumeCB *pVolumeCB = NULL;
4072 AFSFileID stTargetFileID;
4074 BOOLEAN bReleaseVolumeLock = FALSE;
4080 // Loop on each entry, building the chain until we encounter the final target
4083 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4084 AFS_TRACE_LEVEL_VERBOSE_2,
4085 "AFSBuildMountPointTarget Building target directory for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
4086 &DirectoryCB->NameInformation.FileName,
4087 DirectoryCB->ObjectInformation->FileId.Cell,
4088 DirectoryCB->ObjectInformation->FileId.Volume,
4089 DirectoryCB->ObjectInformation->FileId.Vnode,
4090 DirectoryCB->ObjectInformation->FileId.Unique);
4093 // Do we need to evaluate the node?
4096 //if( DirectoryCB->ObjectInformation->TargetFileId.Vnode == 0 &&
4097 // DirectoryCB->ObjectInformation->TargetFileId.Unique == 0)
4101 // Go evaluate the current target to get the target fid
4104 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4105 AFS_TRACE_LEVEL_VERBOSE_2,
4106 "AFSBuildMountPointTarget Evaluating target %wZ FID %08lX-%08lX-%08lX-%08lX\n",
4107 &DirectoryCB->NameInformation.FileName,
4108 DirectoryCB->ObjectInformation->FileId.Cell,
4109 DirectoryCB->ObjectInformation->FileId.Volume,
4110 DirectoryCB->ObjectInformation->FileId.Vnode,
4111 DirectoryCB->ObjectInformation->FileId.Unique);
4113 ntStatus = AFSEvaluateTargetByID( DirectoryCB->ObjectInformation,
4118 if( !NT_SUCCESS( ntStatus))
4121 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4122 AFS_TRACE_LEVEL_ERROR,
4123 "AFSBuildMountPointTarget Failed to evaluate target %wZ Status %08lX\n",
4124 &DirectoryCB->NameInformation.FileName,
4126 try_return( ntStatus);
4129 if( pDirEntry->TargetFileId.Vnode == 0 &&
4130 pDirEntry->TargetFileId.Unique == 0)
4133 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4134 AFS_TRACE_LEVEL_ERROR,
4135 "AFSBuildMountPointTarget Target %wZ FID %08lX-%08lX-%08lX-%08lX service returned zero FID\n",
4136 &DirectoryCB->NameInformation.FileName,
4137 DirectoryCB->ObjectInformation->FileId.Cell,
4138 DirectoryCB->ObjectInformation->FileId.Volume,
4139 DirectoryCB->ObjectInformation->FileId.Vnode,
4140 DirectoryCB->ObjectInformation->FileId.Unique);
4142 try_return( ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED);
4145 AFSAcquireExcl( &DirectoryCB->NonPaged->Lock,
4148 ntStatus = AFSUpdateTargetName( &DirectoryCB->NameInformation.TargetName,
4149 &DirectoryCB->Flags,
4150 (WCHAR *)((char *)pDirEntry + pDirEntry->TargetNameOffset),
4151 (USHORT)pDirEntry->TargetNameLength);
4153 if( !NT_SUCCESS( ntStatus))
4156 AFSReleaseResource( &DirectoryCB->NonPaged->Lock);
4158 try_return( ntStatus);
4161 AFSReleaseResource( &DirectoryCB->NonPaged->Lock);
4163 DirectoryCB->ObjectInformation->TargetFileId = pDirEntry->TargetFileId;
4166 stTargetFileID = DirectoryCB->ObjectInformation->TargetFileId;
4169 // Try to locate this FID. First the volume then the
4173 ullIndex = AFSCreateHighIndex( &stTargetFileID);
4175 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
4176 AFS_TRACE_LEVEL_VERBOSE,
4177 "AFSBuildMountPointTarget Acquiring RDR VolumeTreeLock lock %08lX EXCL %08lX\n",
4178 &pDevExt->Specific.RDR.VolumeTreeLock,
4179 PsGetCurrentThread());
4181 AFSAcquireShared( &pDevExt->Specific.RDR.VolumeTreeLock,
4184 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4185 AFS_TRACE_LEVEL_VERBOSE_2,
4186 "AFSBuildMountPointTarget Locating volume for target %I64X\n",
4189 ntStatus = AFSLocateHashEntry( pDevExt->Specific.RDR.VolumeTree.TreeHead,
4191 (AFSBTreeEntry **)&pVolumeCB);
4194 // We can be processing a request for a target that is on a volume
4195 // we have never seen before.
4198 if( pVolumeCB == NULL)
4202 // Locking is held correctly in init routine
4205 AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
4208 // Go init the root of the volume
4211 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4212 AFS_TRACE_LEVEL_VERBOSE_2,
4213 "AFSBuildMountPointTarget Initializing root for %wZ FID %08lX-%08lX-%08lX-%08lX\n",
4214 &DirectoryCB->NameInformation.FileName,
4215 DirectoryCB->ObjectInformation->FileId.Cell,
4216 DirectoryCB->ObjectInformation->FileId.Volume,
4217 DirectoryCB->ObjectInformation->FileId.Vnode,
4218 DirectoryCB->ObjectInformation->FileId.Unique);
4220 ntStatus = AFSInitVolume( AuthGroup,
4224 if( !NT_SUCCESS( ntStatus))
4227 try_return( ntStatus);
4231 // pVolumeCB->VolumeLock held exclusive and
4232 // pVolumeCB->VolumeReferenceCount has been incremented
4233 // pVolumeCB->RootFcb == NULL
4236 bReleaseVolumeLock = TRUE;
4242 // AFSInitVolume returns with a VolumeReferenceCount
4243 // obtain one to match
4246 lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
4248 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
4249 AFS_TRACE_LEVEL_VERBOSE,
4250 "AFSBuildMountPointTarget Increment count on volume %08lX Cnt %d\n",
4254 AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
4257 if( pVolumeCB->RootFcb == NULL)
4260 if ( bReleaseVolumeLock == FALSE)
4263 AFSAcquireExcl( pVolumeCB->VolumeLock,
4266 bReleaseVolumeLock = TRUE;
4270 // Initialize the root fcb for this volume
4273 ntStatus = AFSInitRootFcb( (ULONGLONG)PsGetCurrentProcessId(),
4276 if( !NT_SUCCESS( ntStatus))
4279 lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
4281 AFSReleaseResource( pVolumeCB->VolumeLock);
4283 try_return( ntStatus);
4287 // Drop the lock acquired above
4290 AFSReleaseResource( &pVolumeCB->RootFcb->NPFcb->Resource);
4293 if ( bReleaseVolumeLock == TRUE)
4296 AFSReleaseResource( pVolumeCB->VolumeLock);
4299 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4300 AFS_TRACE_LEVEL_VERBOSE_2,
4301 "AFSBuildMountPointTarget Evaluated target of %wZ FID %08lX-%08lX-%08lX-%08lX as root volume\n",
4302 &pVolumeCB->DirectoryCB->NameInformation.FileName,
4303 pVolumeCB->ObjectInformation.FileId.Cell,
4304 pVolumeCB->ObjectInformation.FileId.Volume,
4305 pVolumeCB->ObjectInformation.FileId.Vnode,
4306 pVolumeCB->ObjectInformation.FileId.Unique);
4308 *TargetVolumeCB = pVolumeCB;
4315 AFSExFreePoolWithTag( pDirEntry, AFS_GENERIC_MEMORY_2_TAG);
4323 AFSBuildRootVolume( IN GUID *AuthGroup,
4324 IN AFSFileID *FileId,
4325 OUT AFSVolumeCB **TargetVolumeCB)
4328 NTSTATUS ntStatus = STATUS_SUCCESS;
4329 AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
4330 AFSDirectoryCB *pDirNode = NULL;
4331 UNICODE_STRING uniDirName, uniTargetName;
4332 ULONGLONG ullIndex = 0;
4333 AFSVolumeCB *pVolumeCB = NULL;
4335 BOOLEAN bReleaseVolumeLock = FALSE;
4340 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4341 AFS_TRACE_LEVEL_VERBOSE_2,
4342 "AFSBuildRootVolume Building target volume for FID %08lX-%08lX-%08lX-%08lX\n",
4348 ullIndex = AFSCreateHighIndex( FileId);
4350 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
4351 AFS_TRACE_LEVEL_VERBOSE,
4352 "AFSBuildRootVolume Acquiring RDR VolumeTreeLock lock %08lX EXCL %08lX\n",
4353 &pDevExt->Specific.RDR.VolumeTreeLock,
4354 PsGetCurrentThread());
4356 AFSAcquireShared( &pDevExt->Specific.RDR.VolumeTreeLock,
4359 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4360 AFS_TRACE_LEVEL_VERBOSE_2,
4361 "AFSBuildRootVolume Locating volume for target %I64X\n",
4364 ntStatus = AFSLocateHashEntry( pDevExt->Specific.RDR.VolumeTree.TreeHead,
4366 (AFSBTreeEntry **)&pVolumeCB);
4369 // We can be processing a request for a target that is on a volume
4370 // we have never seen before.
4373 if( pVolumeCB == NULL)
4377 // Locking is held correctly in init routine
4380 AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
4383 // Go init the root of the volume
4386 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4387 AFS_TRACE_LEVEL_VERBOSE_2,
4388 "AFSBuildRootVolume Initializing root for FID %08lX-%08lX-%08lX-%08lX\n",
4394 ntStatus = AFSInitVolume( AuthGroup,
4398 if( !NT_SUCCESS( ntStatus))
4401 try_return( ntStatus);
4405 // pVolumeCB->VolumeLock is held exclusive
4406 // pVolumeCB->VolumeReferenceCount has been incremented
4407 // pVolumeCB->RootFcb == NULL
4410 bReleaseVolumeLock = TRUE;
4416 // AFSInitVolume returns with a VolumeReferenceCount
4417 // obtain one to match
4420 lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
4422 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
4423 AFS_TRACE_LEVEL_VERBOSE,
4424 "AFSBuildRootVolume Increment count on volume %08lX Cnt %d\n",
4428 AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
4432 if( pVolumeCB->RootFcb == NULL)
4435 if ( bReleaseVolumeLock == FALSE)
4438 AFSAcquireExcl( pVolumeCB->VolumeLock,
4441 bReleaseVolumeLock = TRUE;
4445 // Initialize the root fcb for this volume
4448 ntStatus = AFSInitRootFcb( (ULONGLONG)PsGetCurrentProcessId(),
4451 if( !NT_SUCCESS( ntStatus))
4454 lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
4456 AFSReleaseResource( pVolumeCB->VolumeLock);
4458 try_return( ntStatus);
4462 // Drop the lock acquired above
4465 AFSReleaseResource( &pVolumeCB->RootFcb->NPFcb->Resource);
4468 if ( bReleaseVolumeLock == TRUE)
4471 AFSReleaseResource( pVolumeCB->VolumeLock);
4474 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4475 AFS_TRACE_LEVEL_VERBOSE_2,
4476 "AFSBuildRootVolume Evaluated target of %wZ FID %08lX-%08lX-%08lX-%08lX as root volume\n",
4477 &pVolumeCB->DirectoryCB->NameInformation.FileName,
4478 pVolumeCB->ObjectInformation.FileId.Cell,
4479 pVolumeCB->ObjectInformation.FileId.Volume,
4480 pVolumeCB->ObjectInformation.FileId.Vnode,
4481 pVolumeCB->ObjectInformation.FileId.Unique);
4483 *TargetVolumeCB = pVolumeCB;
4494 AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
4495 IN PFILE_OBJECT FileObject,
4496 IN UNICODE_STRING *RemainingPath,
4500 NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
4501 UNICODE_STRING uniReparseName;
4502 UNICODE_STRING uniMUPDeviceName;
4503 AFSDirEnumEntry *pDirEntry = NULL;
4509 // Build up the name to reparse
4512 RtlInitUnicodeString( &uniMUPDeviceName,
4515 uniReparseName.Length = 0;
4516 uniReparseName.Buffer = NULL;
4519 // Be sure we have a target name
4522 if( DirEntry->NameInformation.TargetName.Length == 0)
4525 ntStatus = AFSEvaluateTargetByID( DirEntry->ObjectInformation,
4530 if( !NT_SUCCESS( ntStatus) ||
4531 pDirEntry->TargetNameLength == 0)
4534 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4535 AFS_TRACE_LEVEL_ERROR,
4536 "AFSProcessDFSLink EvaluateTargetByID failed for Fcb %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
4537 &DirEntry->NameInformation.FileName,
4538 DirEntry->ObjectInformation->FileId.Cell,
4539 DirEntry->ObjectInformation->FileId.Volume,
4540 DirEntry->ObjectInformation->FileId.Vnode,
4541 DirEntry->ObjectInformation->FileId.Unique,
4544 if( NT_SUCCESS( ntStatus))
4547 ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
4550 try_return( ntStatus);
4554 // Update the target name
4557 AFSAcquireExcl( &DirEntry->NonPaged->Lock,
4560 ntStatus = AFSUpdateTargetName( &DirEntry->NameInformation.TargetName,
4562 (WCHAR *)((char *)pDirEntry + pDirEntry->TargetNameOffset),
4563 (USHORT)pDirEntry->TargetNameLength);
4565 if( !NT_SUCCESS( ntStatus))
4568 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4569 AFS_TRACE_LEVEL_ERROR,
4570 "AFSProcessDFSLink UpdateTargetName failed for Fcb %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
4571 &DirEntry->NameInformation.FileName,
4572 DirEntry->ObjectInformation->FileId.Cell,
4573 DirEntry->ObjectInformation->FileId.Volume,
4574 DirEntry->ObjectInformation->FileId.Vnode,
4575 DirEntry->ObjectInformation->FileId.Unique,
4578 AFSReleaseResource( &DirEntry->NonPaged->Lock);
4580 try_return( ntStatus);
4583 AFSConvertToShared( &DirEntry->NonPaged->Lock);
4587 AFSAcquireShared( &DirEntry->NonPaged->Lock,
4591 uniReparseName.MaximumLength = uniMUPDeviceName.Length +
4593 DirEntry->NameInformation.TargetName.Length +
4596 if( RemainingPath != NULL &&
4597 RemainingPath->Length > 0)
4600 uniReparseName.MaximumLength += RemainingPath->Length;
4604 // Allocate the reparse buffer
4607 uniReparseName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
4608 uniReparseName.MaximumLength,
4609 AFS_REPARSE_NAME_TAG);
4611 if( uniReparseName.Buffer == NULL)
4614 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4615 AFS_TRACE_LEVEL_ERROR,
4616 "AFSProcessDFSLink uniReparseName.Buffer == NULL Fcb %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
4617 &DirEntry->NameInformation.FileName,
4618 DirEntry->ObjectInformation->FileId.Cell,
4619 DirEntry->ObjectInformation->FileId.Volume,
4620 DirEntry->ObjectInformation->FileId.Vnode,
4621 DirEntry->ObjectInformation->FileId.Unique,
4622 STATUS_INSUFFICIENT_RESOURCES);
4624 AFSReleaseResource( &DirEntry->NonPaged->Lock);
4626 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
4630 // Start building the name
4633 RtlCopyMemory( uniReparseName.Buffer,
4634 uniMUPDeviceName.Buffer,
4635 uniMUPDeviceName.Length);
4637 uniReparseName.Length = uniMUPDeviceName.Length;
4639 if( DirEntry->NameInformation.TargetName.Buffer[ 0] != L'\\')
4642 uniReparseName.Buffer[ uniReparseName.Length/sizeof( WCHAR)] = L'\\';
4644 uniReparseName.Length += sizeof( WCHAR);
4647 RtlCopyMemory( &uniReparseName.Buffer[ uniReparseName.Length/sizeof( WCHAR)],
4648 DirEntry->NameInformation.TargetName.Buffer,
4649 DirEntry->NameInformation.TargetName.Length);
4651 uniReparseName.Length += DirEntry->NameInformation.TargetName.Length;
4653 AFSReleaseResource( &DirEntry->NonPaged->Lock);
4655 if( RemainingPath != NULL &&
4656 RemainingPath->Length > 0)
4659 if( uniReparseName.Buffer[ (uniReparseName.Length/sizeof( WCHAR)) - 1] != L'\\' &&
4660 RemainingPath->Buffer[ 0] != L'\\')
4663 uniReparseName.Buffer[ uniReparseName.Length/sizeof( WCHAR)] = L'\\';
4665 uniReparseName.Length += sizeof( WCHAR);
4668 RtlCopyMemory( &uniReparseName.Buffer[ uniReparseName.Length/sizeof( WCHAR)],
4669 RemainingPath->Buffer,
4670 RemainingPath->Length);
4672 uniReparseName.Length += RemainingPath->Length;
4676 // Update the name in the file object
4679 if( FileObject->FileName.Buffer != NULL)
4682 AFSExFreePoolWithTag( FileObject->FileName.Buffer, 0);
4685 FileObject->FileName = uniReparseName;
4687 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
4688 AFS_TRACE_LEVEL_VERBOSE,
4689 "AFSProcessDFSLink Reparsing access to Fcb %wZ FID %08lX-%08lX-%08lX-%08lX to %wZ\n",
4690 &DirEntry->NameInformation.FileName,
4691 DirEntry->ObjectInformation->FileId.Cell,
4692 DirEntry->ObjectInformation->FileId.Volume,
4693 DirEntry->ObjectInformation->FileId.Vnode,
4694 DirEntry->ObjectInformation->FileId.Unique,
4698 // Return status reparse ...
4701 ntStatus = STATUS_REPARSE;
4708 AFSExFreePoolWithTag( pDirEntry, AFS_GENERIC_MEMORY_2_TAG);