Windows: Skip Extent operations if Direct IO
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSGeneric.cpp
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3  * Copyright (c) 2009, 2010, 2011, 2012, 2013 Your File System, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
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
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
16  *   nor the names of their contributors may be used to endorse or promote
17  *   products derived from this software without specific prior written
18  *   permission from Kernel Drivers, LLC and Your File System, Inc.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
24  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 //
34 // File: AFSGeneric.cpp
35 //
36
37 #include "AFSCommon.h"
38
39 //
40 // Function: AFSExceptionFilter
41 //
42 // Description:
43 //
44 //      This function is the exception handler
45 //
46 // Return:
47 //
48 //      A status is returned for the function
49 //
50
51 ULONG
52 AFSExceptionFilter( IN CHAR *FunctionString,
53                     IN ULONG Code,
54                     IN PEXCEPTION_POINTERS ExceptPtrs)
55 {
56
57     UNREFERENCED_PARAMETER(Code);
58     PEXCEPTION_RECORD ExceptRec;
59     PCONTEXT Context;
60
61     __try
62     {
63
64         ExceptRec = ExceptPtrs->ExceptionRecord;
65
66         Context = ExceptPtrs->ContextRecord;
67
68         AFSDbgTrace(( 0,
69                       0,
70                       "AFSExceptionFilter (Library) - EXR %p CXR %p Function %s Code %08lX Address %p Routine %p\n",
71                       ExceptRec,
72                       Context,
73                       FunctionString,
74                       ExceptRec->ExceptionCode,
75                       ExceptRec->ExceptionAddress,
76                       (void *)AFSExceptionFilter));
77
78         DbgPrint("**** Exception Caught in AFS Redirector Library ****\n");
79
80         DbgPrint("\n\nPerform the following WnDbg Cmds:\n");
81         DbgPrint("\n\t.exr %p ;  .cxr %p\n\n", ExceptRec, Context);
82
83         DbgPrint("**** Exception Complete from AFS Redirector Library ****\n");
84
85         if( BooleanFlagOn( AFSDebugFlags, AFS_DBG_BUGCHECK_EXCEPTION))
86         {
87
88             KeBugCheck( (ULONG)-2);
89         }
90         else
91         {
92
93             AFSBreakPoint();
94         }
95     }
96     __except( EXCEPTION_EXECUTE_HANDLER)
97     {
98
99         NOTHING;
100     }
101
102     return EXCEPTION_EXECUTE_HANDLER;
103 }
104
105 //
106 // Function: AFSLibExAllocatePoolWithTag()
107 //
108 // Purpose: Allocate Pool Memory.  If BugCheck Exception flag
109 //          is configured on, then bugcheck the system if
110 //          a memory allocation fails.  The routine should be
111 //          used for all memory allocations that are to be freed
112 //          when the library is unloaded.  Memory allocations that
113 //          are to survive library unload and reload should be
114 //          performed using AFSExAllocatePoolWithTag() which is
115 //          provided by the AFS Framework.
116 //
117 // Parameters:
118 //                POOL_TYPE PoolType - Paged or NonPaged
119 //                SIZE_T NumberOfBytes - requested allocation size
120 //                ULONG  Tag - Pool Allocation Tag to be applied for tracking
121 //
122 // Return:
123 //                void * - the memory allocation
124 //
125
126 void *
127 AFSLibExAllocatePoolWithTag( IN POOL_TYPE  PoolType,
128                              IN SIZE_T  NumberOfBytes,
129                              IN ULONG  Tag)
130 {
131
132     void *pBuffer = NULL;
133
134     pBuffer = ExAllocatePoolWithTag( PoolType,
135                                      NumberOfBytes,
136                                      Tag);
137
138     if( pBuffer == NULL)
139     {
140
141         if( BooleanFlagOn( AFSDebugFlags, AFS_DBG_BUGCHECK_EXCEPTION))
142         {
143
144             KeBugCheck( (ULONG)-2);
145         }
146         else
147         {
148
149             AFSDbgTrace(( 0,
150                           0,
151                           "AFSLibExAllocatePoolWithTag failure Type %08lX Size %08lX Tag %08lX %08lX\n",
152                           PoolType,
153                           NumberOfBytes,
154                           Tag,
155                           PsGetCurrentThread()));
156
157             AFSBreakPoint();
158         }
159     }
160
161     return pBuffer;
162 }
163
164 //
165 // Function: AFSAcquireExcl()
166 //
167 // Purpose: Called to acquire a resource exclusive with optional wait
168 //
169 // Parameters:
170 //                PERESOURCE Resource - Resource to acquire
171 //                BOOLEAN Wait - Whether to block
172 //
173 // Return:
174 //                BOOLEAN - Whether the mask was acquired
175 //
176
177 BOOLEAN
178 AFSAcquireExcl( IN PERESOURCE Resource,
179                 IN BOOLEAN wait)
180 {
181
182     BOOLEAN bStatus = FALSE;
183
184     //
185     // Normal kernel APCs must be disabled before calling
186     // ExAcquireResourceExclusiveLite. Otherwise a bugcheck occurs.
187     //
188
189     KeEnterCriticalRegion();
190
191     bStatus = ExAcquireResourceExclusiveLite( Resource,
192                                               wait);
193
194     if( !bStatus)
195     {
196
197         KeLeaveCriticalRegion();
198     }
199
200     return bStatus;
201 }
202
203 BOOLEAN
204 AFSAcquireSharedStarveExclusive( IN PERESOURCE Resource,
205                                  IN BOOLEAN Wait)
206 {
207
208     BOOLEAN bStatus = FALSE;
209
210     KeEnterCriticalRegion();
211
212     bStatus = ExAcquireSharedStarveExclusive( Resource,
213                                               Wait);
214
215     if( !bStatus)
216     {
217
218         KeLeaveCriticalRegion();
219     }
220
221     return bStatus;
222 }
223
224 //
225 // Function: AFSAcquireShared()
226 //
227 // Purpose: Called to acquire a resource shared with optional wait
228 //
229 // Parameters:
230 //                PERESOURCE Resource - Resource to acquire
231 //                BOOLEAN Wait - Whether to block
232 //
233 // Return:
234 //                BOOLEAN - Whether the mask was acquired
235 //
236
237 BOOLEAN
238 AFSAcquireShared( IN PERESOURCE Resource,
239                   IN BOOLEAN wait)
240 {
241
242     BOOLEAN bStatus = FALSE;
243
244     KeEnterCriticalRegion();
245
246     bStatus = ExAcquireResourceSharedLite( Resource,
247                                            wait);
248
249     if( !bStatus)
250     {
251
252         KeLeaveCriticalRegion();
253     }
254
255     return bStatus;
256 }
257
258 //
259 // Function: AFSReleaseResource()
260 //
261 // Purpose: Called to release a resource
262 //
263 // Parameters:
264 //                PERESOURCE Resource - Resource to release
265 //
266 // Return:
267 //                None
268 //
269
270 void
271 AFSReleaseResource( IN PERESOURCE Resource)
272 {
273
274     AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
275                   AFS_TRACE_LEVEL_VERBOSE,
276                   "AFSReleaseResource Releasing lock %p Thread %08lX\n",
277                   Resource,
278                   PsGetCurrentThread()));
279
280     ExReleaseResourceLite( Resource);
281
282     KeLeaveCriticalRegion();
283
284     return;
285 }
286
287 void
288 AFSConvertToShared( IN PERESOURCE Resource)
289 {
290
291     AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
292                   AFS_TRACE_LEVEL_VERBOSE,
293                   "AFSConvertToShared Converting lock %p Thread %08lX\n",
294                   Resource,
295                   PsGetCurrentThread()));
296
297     ExConvertExclusiveToSharedLite( Resource);
298
299     return;
300 }
301
302 //
303 // Function: AFSCompleteRequest
304 //
305 // Description:
306 //
307 //      This function completes irps
308 //
309 // Return:
310 //
311 //      A status is returned for the function
312 //
313
314 void
315 AFSCompleteRequest( IN PIRP Irp,
316                     IN ULONG Status)
317 {
318
319     Irp->IoStatus.Status = Status;
320
321     IoCompleteRequest( Irp,
322                        IO_NO_INCREMENT);
323
324     return;
325 }
326
327 //
328 // Function: AFSGenerateCRC
329 //
330 // Description:
331 //
332 //      Given a device and filename this function generates a CRC
333 //
334 // Return:
335 //
336 //      A status is returned for the function
337 //
338
339 ULONG
340 AFSGenerateCRC( IN PUNICODE_STRING FileName,
341                 IN BOOLEAN UpperCaseName)
342 {
343
344     ULONG ulCRC = 0;
345     NTSTATUS ntStatus = STATUS_SUCCESS;
346
347     ntStatus = RtlHashUnicodeString( FileName,
348                                      UpperCaseName,
349                                      HASH_STRING_ALGORITHM_DEFAULT,
350                                      &ulCRC);
351
352     if( !NT_SUCCESS( ntStatus))
353     {
354         ulCRC = 0;
355     }
356
357     return ulCRC;
358 }
359
360 void *
361 AFSLockSystemBuffer( IN PIRP Irp,
362                      IN ULONG Length)
363 {
364
365     void *pAddress = NULL;
366
367     if( Irp->MdlAddress != NULL)
368     {
369
370         pAddress = MmGetSystemAddressForMdlSafe( Irp->MdlAddress,
371                                                  NormalPagePriority);
372     }
373     else if( Irp->AssociatedIrp.SystemBuffer != NULL)
374     {
375
376         pAddress = Irp->AssociatedIrp.SystemBuffer;
377     }
378     else if( Irp->UserBuffer != NULL)
379     {
380
381         Irp->MdlAddress = IoAllocateMdl( Irp->UserBuffer,
382                                          Length,
383                                          FALSE,
384                                          FALSE,
385                                          Irp);
386
387         if( Irp->MdlAddress != NULL)
388         {
389
390             //
391             //  Lock the new Mdl in memory.
392             //
393
394             __try
395             {
396                 PIO_STACK_LOCATION pIoStack;
397                 pIoStack = IoGetCurrentIrpStackLocation( Irp);
398
399
400                 MmProbeAndLockPages( Irp->MdlAddress, KernelMode,
401                                      (pIoStack->MajorFunction == IRP_MJ_READ) ? IoWriteAccess : IoReadAccess);
402
403                 pAddress = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority );
404
405             }
406             __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
407             {
408
409                 AFSDumpTraceFilesFnc();
410
411                 IoFreeMdl( Irp->MdlAddress );
412                 Irp->MdlAddress = NULL;
413                 pAddress = NULL;
414             }
415         }
416     }
417
418     return pAddress;
419 }
420
421 void *
422 AFSLockUserBuffer( IN void *UserBuffer,
423                    IN ULONG BufferLength,
424                    OUT MDL ** Mdl)
425 {
426
427     NTSTATUS ntStatus = STATUS_SUCCESS;
428     void *pAddress = NULL;
429     MDL *pMdl = NULL;
430
431     __Enter
432     {
433
434         pMdl = IoAllocateMdl( UserBuffer,
435                               BufferLength,
436                               FALSE,
437                               FALSE,
438                               NULL);
439
440             if( pMdl == NULL)
441             {
442
443                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
444             }
445
446         //
447         //  Lock the new Mdl in memory.
448         //
449
450         __try
451         {
452
453             MmProbeAndLockPages( pMdl,
454                                  KernelMode,
455                                  IoWriteAccess);
456
457             pAddress = MmGetSystemAddressForMdlSafe( pMdl,
458                                                      NormalPagePriority);
459         }
460         __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
461         {
462
463             AFSDumpTraceFilesFnc();
464
465             IoFreeMdl( pMdl);
466             pMdl = NULL;
467             pAddress = NULL;
468         }
469
470         if( pMdl != NULL)
471         {
472
473             *Mdl = pMdl;
474         }
475
476 try_exit:
477
478         NOTHING;
479     }
480
481     return pAddress;
482 }
483
484 void *
485 AFSMapToService( IN PIRP Irp,
486                  IN ULONG ByteCount)
487 {
488
489     NTSTATUS ntStatus = STATUS_SUCCESS;
490     void *pMappedBuffer = NULL;
491     AFSDeviceExt *pDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
492     KAPC stApcState;
493
494     __Enter
495     {
496
497         if( pDevExt->Specific.Control.ServiceProcess == NULL)
498         {
499
500             try_return( ntStatus = STATUS_DEVICE_NOT_READY);
501         }
502
503         if( Irp->MdlAddress == NULL)
504         {
505
506             if( AFSLockSystemBuffer( Irp,
507                                      ByteCount) == NULL)
508             {
509
510                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
511             }
512         }
513
514         //
515         // Attach to the service process for mapping
516         //
517
518         KeStackAttachProcess( pDevExt->Specific.Control.ServiceProcess,
519                               (PRKAPC_STATE)&stApcState);
520
521         pMappedBuffer = MmMapLockedPagesSpecifyCache( Irp->MdlAddress,
522                                                       UserMode,
523                                                       MmCached,
524                                                       NULL,
525                                                       FALSE,
526                                                       NormalPagePriority);
527
528         KeUnstackDetachProcess( (PRKAPC_STATE)&stApcState);
529
530 try_exit:
531
532         NOTHING;
533     }
534
535     return pMappedBuffer;
536 }
537
538 NTSTATUS
539 AFSUnmapServiceMappedBuffer( IN void *MappedBuffer,
540                              IN PMDL Mdl)
541 {
542
543     NTSTATUS ntStatus = STATUS_SUCCESS;
544     AFSDeviceExt *pDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
545     KAPC stApcState;
546
547     __Enter
548     {
549
550         if( pDevExt->Specific.Control.ServiceProcess == NULL)
551         {
552
553             try_return( ntStatus = STATUS_DEVICE_NOT_READY);
554         }
555
556         if( Mdl != NULL)
557         {
558
559             //
560             // Attach to the service process for mapping
561             //
562
563             KeStackAttachProcess( pDevExt->Specific.Control.ServiceProcess,
564                                   (PRKAPC_STATE)&stApcState);
565
566             MmUnmapLockedPages( MappedBuffer,
567                                 Mdl);
568
569             KeUnstackDetachProcess( (PRKAPC_STATE)&stApcState);
570         }
571
572 try_exit:
573
574         NOTHING;
575     }
576
577     return ntStatus;
578 }
579
580 NTSTATUS
581 AFSInitializeLibraryDevice()
582 {
583
584     NTSTATUS ntStatus = STATUS_SUCCESS;
585     AFSDeviceExt *pDeviceExt = NULL;
586
587     __Enter
588     {
589
590         pDeviceExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
591
592         //
593         // The PIOCtl file name
594         //
595
596         RtlInitUnicodeString( &AFSPIOCtlName,
597                               AFS_PIOCTL_FILE_INTERFACE_NAME);
598
599         //
600         // And the global root share name
601         //
602
603         RtlInitUnicodeString( &AFSGlobalRootName,
604                               AFS_GLOBAL_ROOT_SHARE_NAME);
605
606     }
607
608     return ntStatus;
609 }
610
611 NTSTATUS
612 AFSRemoveLibraryDevice()
613 {
614
615     NTSTATUS ntStatus = STATUS_SUCCESS;
616
617     __Enter
618     {
619
620     }
621
622     return ntStatus;
623 }
624
625 NTSTATUS
626 AFSDefaultDispatch( IN PDEVICE_OBJECT DeviceObject,
627                     IN PIRP Irp)
628 {
629
630     UNREFERENCED_PARAMETER(DeviceObject);
631     NTSTATUS            ntStatus = STATUS_INVALID_DEVICE_REQUEST;
632
633     AFSCompleteRequest( Irp,
634                         ntStatus);
635
636     return ntStatus;
637 }
638
639 NTSTATUS
640 AFSInitializeGlobalDirectoryEntries()
641 {
642
643     NTSTATUS ntStatus = STATUS_SUCCESS;
644     AFSDirectoryCB *pDirNode = NULL;
645     ULONG ulEntryLength = 0;
646     AFSObjectInfoCB *pObjectInfoCB = NULL;
647     AFSNonPagedDirectoryCB *pNonPagedDirEntry = NULL;
648     LONG lCount;
649
650     __Enter
651     {
652
653         //
654         // Initialize the global . entry
655         //
656
657         pObjectInfoCB = AFSAllocateObjectInfo( &AFSGlobalRoot->ObjectInformation,
658                                                0);
659
660         if( pObjectInfoCB == NULL)
661         {
662
663             AFSDbgTrace(( AFS_SUBSYSTEM_LOAD_LIBRARY | AFS_SUBSYSTEM_INIT_PROCESSING,
664                           AFS_TRACE_LEVEL_ERROR,
665                           "AFSInitializeGlobalDirectory AFSAllocateObjectInfo failure %08lX\n",
666                           ntStatus));
667
668             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
669         }
670
671         lCount = AFSObjectInfoIncrement( pObjectInfoCB,
672                                          AFS_OBJECT_REFERENCE_GLOBAL);
673
674         AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
675                       AFS_TRACE_LEVEL_VERBOSE,
676                       "AFSInitializeGlobalDirectoryEntries Increment count on object %p Cnt %d\n",
677                       pObjectInfoCB,
678                       lCount));
679
680         ntStatus = STATUS_SUCCESS;
681
682         ulEntryLength = sizeof( AFSDirectoryCB) +
683                                      sizeof( WCHAR);
684
685         pDirNode = (AFSDirectoryCB *)AFSLibExAllocatePoolWithTag( PagedPool,
686                                                                   ulEntryLength,
687                                                                   AFS_DIR_ENTRY_TAG);
688
689         if( pDirNode == NULL)
690         {
691
692             lCount = AFSObjectInfoDecrement( pObjectInfoCB,
693                                              AFS_OBJECT_REFERENCE_GLOBAL);
694
695             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
696                           AFS_TRACE_LEVEL_VERBOSE,
697                           "AFSInitializeGlobalDirectoryEntries Decrement count on object %p Cnt %d\n",
698                           pObjectInfoCB,
699                           lCount));
700
701             if ( lCount == 0)
702             {
703
704                 AFSDeleteObjectInfo( &pObjectInfoCB);
705             }
706
707             AFSDbgTrace(( AFS_SUBSYSTEM_LOAD_LIBRARY | AFS_SUBSYSTEM_INIT_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_ALLOCATION,
708                           AFS_TRACE_LEVEL_ERROR,
709                           "AFSInitializeGlobalDirectory AFS_DIR_ENTRY_TAG allocation failure\n"));
710
711             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
712         }
713
714         AFSDbgTrace(( AFS_SUBSYSTEM_DIRENTRY_ALLOCATION,
715                       AFS_TRACE_LEVEL_VERBOSE,
716                       "AFSInitializeGlobalDirectory AFS_DIR_ENTRY_TAG allocated %p\n",
717                       pDirNode));
718
719         pNonPagedDirEntry = (AFSNonPagedDirectoryCB *)AFSLibExAllocatePoolWithTag( NonPagedPool,
720                                                                                    sizeof( AFSNonPagedDirectoryCB),
721                                                                                    AFS_DIR_ENTRY_NP_TAG);
722
723         if( pNonPagedDirEntry == NULL)
724         {
725
726             AFSLibExFreePoolWithTag( pDirNode,
727                                      AFS_DIR_ENTRY_TAG);
728
729             lCount = AFSObjectInfoDecrement( pObjectInfoCB,
730                                              AFS_OBJECT_REFERENCE_GLOBAL);
731
732             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
733                           AFS_TRACE_LEVEL_VERBOSE,
734                           "AFSInitializeGlobalDirectoryEntries Decrement count on object %p Cnt %d\n",
735                           pObjectInfoCB,
736                           lCount));
737
738             if ( lCount == 0)
739             {
740
741                 AFSDeleteObjectInfo( &pObjectInfoCB);
742             }
743
744             AFSDbgTrace(( AFS_SUBSYSTEM_LOAD_LIBRARY | AFS_SUBSYSTEM_INIT_PROCESSING,
745                           AFS_TRACE_LEVEL_ERROR,
746                           "AFSInitializeGlobalDirectory AFS_DIR_ENTRY_NP_TAG allocation failure\n"));
747
748             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
749         }
750
751         RtlZeroMemory( pDirNode,
752                        ulEntryLength);
753
754         RtlZeroMemory( pNonPagedDirEntry,
755                        sizeof( AFSNonPagedDirectoryCB));
756
757         ExInitializeResourceLite( &pNonPagedDirEntry->Lock);
758
759         pDirNode->NonPaged = pNonPagedDirEntry;
760
761         pDirNode->ObjectInformation = pObjectInfoCB;
762
763         //
764         // Set valid entry
765         //
766
767         SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE | AFS_DIR_ENTRY_FAKE | AFS_DIR_ENTRY_VALID);
768
769         pDirNode->FileIndex = (ULONG)AFS_DIR_ENTRY_DOT_INDEX;
770
771         //
772         // Setup the names in the entry
773         //
774
775         pDirNode->NameInformation.FileName.Length = sizeof( WCHAR);
776
777         pDirNode->NameInformation.FileName.MaximumLength = sizeof( WCHAR);
778
779         pDirNode->NameInformation.FileName.Buffer = (WCHAR *)((char *)pDirNode + sizeof( AFSDirectoryCB));
780
781         pDirNode->NameInformation.FileName.Buffer[ 0] = L'.';
782
783         //
784         // Populate the rest of the data
785         //
786
787         pObjectInfoCB->FileType = AFS_FILE_TYPE_DIRECTORY;
788
789         pObjectInfoCB->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
790
791         AFSGlobalDotDirEntry = pDirNode;
792
793         //
794         // Now the .. entry
795         //
796
797         pObjectInfoCB = AFSAllocateObjectInfo( &AFSGlobalRoot->ObjectInformation,
798                                                0);
799
800         if( pObjectInfoCB == NULL)
801         {
802
803             AFSDbgTrace(( AFS_SUBSYSTEM_LOAD_LIBRARY | AFS_SUBSYSTEM_INIT_PROCESSING,
804                           AFS_TRACE_LEVEL_ERROR,
805                           "AFSInitializeGlobalDirectory AFSAllocateObjectInfo (2) failure %08lX\n",
806                           ntStatus));
807
808             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
809         }
810
811         lCount = AFSObjectInfoIncrement( pObjectInfoCB,
812                                          AFS_OBJECT_REFERENCE_GLOBAL);
813
814         AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
815                       AFS_TRACE_LEVEL_VERBOSE,
816                       "AFSInitializeGlobalDirectoryEntries Increment count on object %p Cnt %d\n",
817                       pObjectInfoCB,
818                       lCount));
819
820         ntStatus = STATUS_SUCCESS;
821
822         ulEntryLength = sizeof( AFSDirectoryCB) +
823                                      ( 2 * sizeof( WCHAR));
824
825         pDirNode = (AFSDirectoryCB *)AFSLibExAllocatePoolWithTag( PagedPool,
826                                                                   ulEntryLength,
827                                                                   AFS_DIR_ENTRY_TAG);
828
829         if( pDirNode == NULL)
830         {
831
832             AFSDbgTrace(( AFS_SUBSYSTEM_LOAD_LIBRARY | AFS_SUBSYSTEM_INIT_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_ALLOCATION,
833                           AFS_TRACE_LEVEL_ERROR,
834                           "AFSInitializeGlobalDirectoryEntries AFS_DIR_ENTRY_TAG allocation failure\n"));
835
836             lCount = AFSObjectInfoDecrement( pObjectInfoCB,
837                                              AFS_OBJECT_REFERENCE_GLOBAL);
838
839             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
840                           AFS_TRACE_LEVEL_VERBOSE,
841                           "AFSInitializeGlobalDirectoryEntries Decrement count on object %p Cnt %d\n",
842                           pObjectInfoCB,
843                           lCount));
844
845             if ( lCount == 0)
846             {
847
848                 AFSDeleteObjectInfo( &pObjectInfoCB);
849             }
850
851             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
852         }
853
854         AFSDbgTrace(( AFS_SUBSYSTEM_DIRENTRY_ALLOCATION,
855                       AFS_TRACE_LEVEL_VERBOSE,
856                       "AFSInitializeGlobalDirectoryEntries AFS_DIR_ENTRY_TAG allocated %p\n",
857                       pDirNode));
858
859         pNonPagedDirEntry = (AFSNonPagedDirectoryCB *)AFSLibExAllocatePoolWithTag( NonPagedPool,
860                                                                                    sizeof( AFSNonPagedDirectoryCB),
861                                                                                    AFS_DIR_ENTRY_NP_TAG);
862
863         if( pNonPagedDirEntry == NULL)
864         {
865
866             AFSLibExFreePoolWithTag( pDirNode,
867                                      AFS_DIR_ENTRY_TAG);
868
869             lCount = AFSObjectInfoDecrement( pObjectInfoCB,
870                                              AFS_OBJECT_REFERENCE_GLOBAL);
871
872             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
873                           AFS_TRACE_LEVEL_VERBOSE,
874                           "AFSInitializeGlobalDirectoryEntries Decrement count on object %p Cnt %d\n",
875                           pObjectInfoCB,
876                           lCount));
877
878             if ( lCount == 0)
879             {
880
881                 AFSDeleteObjectInfo( &pObjectInfoCB);
882             }
883
884             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
885         }
886
887         RtlZeroMemory( pDirNode,
888                        ulEntryLength);
889
890         RtlZeroMemory( pNonPagedDirEntry,
891                        sizeof( AFSNonPagedDirectoryCB));
892
893         ExInitializeResourceLite( &pNonPagedDirEntry->Lock);
894
895         pDirNode->NonPaged = pNonPagedDirEntry;
896
897         pDirNode->ObjectInformation = pObjectInfoCB;
898
899         //
900         // Set valid entry
901         //
902
903         SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE | AFS_DIR_ENTRY_FAKE | AFS_DIR_ENTRY_VALID);
904
905         pDirNode->FileIndex = (ULONG)AFS_DIR_ENTRY_DOT_DOT_INDEX;
906
907         //
908         // Setup the names in the entry
909         //
910
911         pDirNode->NameInformation.FileName.Length = 2 * sizeof( WCHAR);
912
913         pDirNode->NameInformation.FileName.MaximumLength = 2 * sizeof( WCHAR);
914
915         pDirNode->NameInformation.FileName.Buffer = (WCHAR *)((char *)pDirNode + sizeof( AFSDirectoryCB));
916
917         pDirNode->NameInformation.FileName.Buffer[ 0] = L'.';
918
919         pDirNode->NameInformation.FileName.Buffer[ 1] = L'.';
920
921         //
922         // Populate the rest of the data
923         //
924
925         pObjectInfoCB->FileType = AFS_FILE_TYPE_DIRECTORY;
926
927         pObjectInfoCB->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
928
929         AFSGlobalDotDotDirEntry = pDirNode;
930
931 try_exit:
932
933         if( !NT_SUCCESS( ntStatus))
934         {
935
936             if( AFSGlobalDotDirEntry != NULL)
937             {
938
939                 lCount = AFSObjectInfoDecrement( AFSGlobalDotDirEntry->ObjectInformation,
940                                                  AFS_OBJECT_REFERENCE_GLOBAL);
941
942                 AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
943                               AFS_TRACE_LEVEL_VERBOSE,
944                               "AFSInitializeGlobalDirectoryEntries Decrement count on object %p Cnt %d\n",
945                               AFSGlobalDotDirEntry->ObjectInformation,
946                               lCount));
947
948                 if ( lCount == 0)
949                 {
950
951                     AFSDeleteObjectInfo( &AFSGlobalDotDirEntry->ObjectInformation);
952                 }
953
954                 ExDeleteResourceLite( &AFSGlobalDotDirEntry->NonPaged->Lock);
955
956                 AFSLibExFreePoolWithTag( AFSGlobalDotDirEntry->NonPaged,
957                                          AFS_DIR_ENTRY_NP_TAG);
958
959                 AFSLibExFreePoolWithTag( AFSGlobalDotDirEntry,
960                                          AFS_DIR_ENTRY_TAG);
961
962                 AFSGlobalDotDirEntry = NULL;
963             }
964
965             if( AFSGlobalDotDotDirEntry != NULL)
966             {
967
968                 lCount = AFSObjectInfoDecrement( AFSGlobalDotDotDirEntry->ObjectInformation,
969                                                  AFS_OBJECT_REFERENCE_GLOBAL);
970
971                 AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
972                               AFS_TRACE_LEVEL_VERBOSE,
973                               "AFSInitializeGlobalDirectoryEntries Decrement count on object %p Cnt %d\n",
974                               AFSGlobalDotDotDirEntry->ObjectInformation,
975                               lCount));
976
977                 if ( lCount == 0)
978                 {
979
980                     AFSDeleteObjectInfo( &AFSGlobalDotDotDirEntry->ObjectInformation);
981                 }
982
983                 ExDeleteResourceLite( &AFSGlobalDotDotDirEntry->NonPaged->Lock);
984
985                 AFSLibExFreePoolWithTag( AFSGlobalDotDotDirEntry->NonPaged,
986                                          AFS_DIR_ENTRY_NP_TAG);
987
988                 AFSLibExFreePoolWithTag( AFSGlobalDotDotDirEntry,
989                                          AFS_DIR_ENTRY_TAG);
990
991                 AFSGlobalDotDotDirEntry = NULL;
992             }
993         }
994     }
995
996     return ntStatus;
997 }
998
999 AFSDirectoryCB *
1000 AFSInitDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
1001                  IN PUNICODE_STRING FileName,
1002                  IN PUNICODE_STRING TargetName,
1003                  IN AFSDirEnumEntry *DirEnumEntry,
1004                  IN ULONG FileIndex)
1005 {
1006
1007     AFSDirectoryCB *pDirNode = NULL;
1008     NTSTATUS ntStatus = STATUS_SUCCESS;
1009     ULONG ulEntryLength = 0;
1010     AFSObjectInfoCB *pObjectInfoCB = NULL;
1011     ULONGLONG ullIndex = 0;
1012     AFSNonPagedDirectoryCB *pNonPagedDirEntry = NULL;
1013     LONG lCount;
1014
1015     __Enter
1016     {
1017
1018         AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1019                       AFS_TRACE_LEVEL_VERBOSE,
1020                       "AFSInitDirEntry Initializing entry %wZ parent FID %08lX-%08lX-%08lX-%08lX\n",
1021                       FileName,
1022                       ParentObjectInfo->FileId.Cell,
1023                       ParentObjectInfo->FileId.Volume,
1024                       ParentObjectInfo->FileId.Vnode,
1025                       ParentObjectInfo->FileId.Unique));
1026
1027         //
1028         // First thing is to locate/create our object information block
1029         // for this entry
1030         //
1031
1032         AFSAcquireExcl( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock,
1033                         TRUE);
1034
1035         ullIndex = AFSCreateLowIndex( &DirEnumEntry->FileId);
1036
1037         ntStatus = AFSLocateHashEntry( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeHead,
1038                                        ullIndex,
1039                                        (AFSBTreeEntry **)&pObjectInfoCB);
1040
1041         if( !NT_SUCCESS( ntStatus))
1042         {
1043
1044             //
1045             // Allocate our object info cb
1046             //
1047
1048             pObjectInfoCB = AFSAllocateObjectInfo( ParentObjectInfo,
1049                                                    ullIndex);
1050
1051             if( pObjectInfoCB == NULL)
1052             {
1053
1054                 AFSReleaseResource( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
1055
1056                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1057             }
1058
1059             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1060                           AFS_TRACE_LEVEL_VERBOSE,
1061                           "AFSInitDirEntry initialized object %p Parent Object %p for %wZ\n",
1062                           pObjectInfoCB,
1063                           ParentObjectInfo,
1064                           FileName));
1065
1066             //
1067             // If we allocated the object information cb then set the information
1068             //
1069
1070             pObjectInfoCB->FileId = DirEnumEntry->FileId;
1071
1072             pObjectInfoCB->TargetFileId = DirEnumEntry->TargetFileId;
1073
1074             pObjectInfoCB->FileType = DirEnumEntry->FileType;
1075
1076             pObjectInfoCB->FileAttributes = DirEnumEntry->FileAttributes;
1077
1078             if( pObjectInfoCB->FileType == AFS_FILE_TYPE_MOUNTPOINT ||
1079                 pObjectInfoCB->FileType == AFS_FILE_TYPE_DFSLINK)
1080             {
1081
1082                 pObjectInfoCB->FileAttributes |= (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT);
1083             }
1084
1085             if (pObjectInfoCB->FileType == AFS_FILE_TYPE_SYMLINK)
1086             {
1087
1088                 if ( pObjectInfoCB->FileAttributes == FILE_ATTRIBUTE_NORMAL)
1089                 {
1090
1091                     pObjectInfoCB->FileAttributes = FILE_ATTRIBUTE_REPARSE_POINT;
1092                 }
1093                 else
1094                 {
1095
1096                     pObjectInfoCB->FileAttributes |= FILE_ATTRIBUTE_REPARSE_POINT;
1097                 }
1098             }
1099
1100             //
1101             // Check for the case where we have a filetype of SymLink but both the TargetFid and the
1102             // TargetName are empty. In this case set the filetype to zero so we evaluate it later in
1103             // the code
1104             //
1105
1106             if( pObjectInfoCB->FileType == AFS_FILE_TYPE_SYMLINK &&
1107                 pObjectInfoCB->TargetFileId.Vnode == 0 &&
1108                 pObjectInfoCB->TargetFileId.Unique == 0 &&
1109                 (TargetName == NULL || TargetName->Length == 0))
1110             {
1111
1112                 //
1113                 // This will ensure we perform a validation on the node
1114                 //
1115
1116                 pObjectInfoCB->FileType = AFS_FILE_TYPE_UNKNOWN;
1117             }
1118
1119             if( pObjectInfoCB->FileType == AFS_FILE_TYPE_UNKNOWN)
1120             {
1121
1122                 SetFlag( pObjectInfoCB->Flags, AFS_OBJECT_FLAGS_NOT_EVALUATED);
1123             }
1124
1125             SetFlag( pObjectInfoCB->Flags, AFS_OBJECT_FLAGS_VERIFY);
1126         }
1127
1128         if ( BooleanFlagOn( pObjectInfoCB->Flags, AFS_OBJECT_FLAGS_VERIFY))
1129         {
1130
1131             pObjectInfoCB->CreationTime = DirEnumEntry->CreationTime;
1132
1133             pObjectInfoCB->LastAccessTime = DirEnumEntry->LastAccessTime;
1134
1135             pObjectInfoCB->LastWriteTime = DirEnumEntry->LastWriteTime;
1136
1137             pObjectInfoCB->ChangeTime = DirEnumEntry->ChangeTime;
1138
1139             pObjectInfoCB->EndOfFile = DirEnumEntry->EndOfFile;
1140
1141             pObjectInfoCB->AllocationSize = DirEnumEntry->AllocationSize;
1142
1143             pObjectInfoCB->EaSize = DirEnumEntry->EaSize;
1144
1145             pObjectInfoCB->Links = DirEnumEntry->Links;
1146
1147             pObjectInfoCB->Expiration = DirEnumEntry->Expiration;
1148
1149             pObjectInfoCB->DataVersion = DirEnumEntry->DataVersion;
1150
1151             ClearFlag( pObjectInfoCB->Flags, AFS_OBJECT_FLAGS_VERIFY);
1152         }
1153
1154         //
1155         // This reference count is either stored into the return DirectoryCB
1156         // or released before function exit.
1157         //
1158
1159         lCount = AFSObjectInfoIncrement( pObjectInfoCB,
1160                                          AFS_OBJECT_REFERENCE_DIRENTRY);
1161
1162         AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
1163                       AFS_TRACE_LEVEL_VERBOSE,
1164                       "AFSInitDirEntry Increment count on object %p Cnt %d\n",
1165                       pObjectInfoCB,
1166                       lCount));
1167
1168         KeQueryTickCount( &pObjectInfoCB->LastAccessCount);
1169
1170         AFSReleaseResource( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
1171
1172         ntStatus = STATUS_SUCCESS;
1173
1174         ulEntryLength = sizeof( AFSDirectoryCB) +
1175                                      FileName->Length;
1176
1177         if( TargetName != NULL)
1178         {
1179
1180             ulEntryLength += TargetName->Length;
1181         }
1182
1183         pDirNode = (AFSDirectoryCB *)AFSExAllocatePoolWithTag( PagedPool,
1184                                                                ulEntryLength,
1185                                                                AFS_DIR_ENTRY_TAG);
1186
1187         if( pDirNode == NULL)
1188         {
1189
1190             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1191         }
1192
1193         AFSDbgTrace(( AFS_SUBSYSTEM_DIRENTRY_ALLOCATION,
1194                       AFS_TRACE_LEVEL_VERBOSE,
1195                       "AFSInitDirEntry AFS_DIR_ENTRY_TAG allocated %p\n",
1196                       pDirNode));
1197
1198         pNonPagedDirEntry = (AFSNonPagedDirectoryCB *)AFSExAllocatePoolWithTag( NonPagedPool,
1199                                                                                 sizeof( AFSNonPagedDirectoryCB),
1200                                                                                 AFS_DIR_ENTRY_NP_TAG);
1201
1202         if( pNonPagedDirEntry == NULL)
1203         {
1204
1205             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1206         }
1207
1208         RtlZeroMemory( pDirNode,
1209                        ulEntryLength);
1210
1211         RtlZeroMemory( pNonPagedDirEntry,
1212                        sizeof( AFSNonPagedDirectoryCB));
1213
1214         ExInitializeResourceLite( &pNonPagedDirEntry->Lock);
1215
1216         pDirNode->NonPaged = pNonPagedDirEntry;
1217
1218         pDirNode->ObjectInformation = pObjectInfoCB;
1219
1220         //
1221         // Set valid entry and NOT_IN_PARENT flag
1222         //
1223
1224         SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_VALID | AFS_DIR_ENTRY_NOT_IN_PARENT_TREE);
1225
1226         pDirNode->FileIndex = FileIndex;
1227
1228         //
1229         // Setup the names in the entry
1230         //
1231
1232         if( FileName->Length > 0)
1233         {
1234
1235             pDirNode->NameInformation.FileName.Length = FileName->Length;
1236
1237             pDirNode->NameInformation.FileName.MaximumLength = FileName->Length;
1238
1239             pDirNode->NameInformation.FileName.Buffer = (WCHAR *)((char *)pDirNode + sizeof( AFSDirectoryCB));
1240
1241             RtlCopyMemory( pDirNode->NameInformation.FileName.Buffer,
1242                            FileName->Buffer,
1243                            pDirNode->NameInformation.FileName.Length);
1244
1245             //
1246             // Create a CRC for the file
1247             //
1248
1249             pDirNode->CaseSensitiveTreeEntry.HashIndex = AFSGenerateCRC( &pDirNode->NameInformation.FileName,
1250                                                                          FALSE);
1251
1252             pDirNode->CaseInsensitiveTreeEntry.HashIndex = AFSGenerateCRC( &pDirNode->NameInformation.FileName,
1253                                                                            TRUE);
1254         }
1255
1256         AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1257                       AFS_TRACE_LEVEL_VERBOSE,
1258                       "AFSInitDirEntry Initialized DE %p for %wZ in parent FID %08lX-%08lX-%08lX-%08lX\n",
1259                       pDirNode,
1260                       FileName,
1261                       ParentObjectInfo->FileId.Cell,
1262                       ParentObjectInfo->FileId.Volume,
1263                       ParentObjectInfo->FileId.Vnode,
1264                       ParentObjectInfo->FileId.Unique));
1265
1266         if( TargetName != NULL &&
1267             TargetName->Length > 0)
1268         {
1269
1270             pDirNode->NameInformation.TargetName.Length = TargetName->Length;
1271
1272             pDirNode->NameInformation.TargetName.MaximumLength = pDirNode->NameInformation.TargetName.Length;
1273
1274             pDirNode->NameInformation.TargetName.Buffer = (WCHAR *)((char *)pDirNode +
1275                                                                             sizeof( AFSDirectoryCB) +
1276                                                                             pDirNode->NameInformation.FileName.Length);
1277
1278             RtlCopyMemory( pDirNode->NameInformation.TargetName.Buffer,
1279                            TargetName->Buffer,
1280                            pDirNode->NameInformation.TargetName.Length);
1281         }
1282
1283
1284 try_exit:
1285
1286         if( !NT_SUCCESS( ntStatus))
1287         {
1288
1289             if( pNonPagedDirEntry != NULL)
1290             {
1291
1292                 ExDeleteResourceLite( &pNonPagedDirEntry->Lock);
1293
1294                 AFSExFreePoolWithTag( pNonPagedDirEntry, AFS_DIR_ENTRY_NP_TAG);
1295             }
1296
1297             if( pDirNode != NULL)
1298             {
1299
1300                 AFSDbgTrace(( AFS_SUBSYSTEM_DIRENTRY_ALLOCATION,
1301                               AFS_TRACE_LEVEL_VERBOSE,
1302                               "AFSInitDirEntry AFS_DIR_ENTRY_TAG deallocating %p\n",
1303                               pDirNode));
1304
1305                 AFSExFreePoolWithTag( pDirNode, AFS_DIR_ENTRY_TAG);
1306
1307                 pDirNode = NULL;
1308             }
1309
1310             //
1311             // Dereference our object info block if we have one
1312             //
1313
1314             if( pObjectInfoCB != NULL)
1315             {
1316
1317                 AFSAcquireShared( pObjectInfoCB->VolumeCB->ObjectInfoTree.TreeLock,
1318                                   TRUE);
1319
1320                 lCount = AFSObjectInfoDecrement( pObjectInfoCB,
1321                                                  AFS_OBJECT_REFERENCE_DIRENTRY);
1322
1323                 AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
1324                               AFS_TRACE_LEVEL_VERBOSE,
1325                               "AFSInitDirEntry Decrement count on object %p Cnt %d\n",
1326                               pObjectInfoCB,
1327                               lCount));
1328
1329                 AFSReleaseResource( pObjectInfoCB->VolumeCB->ObjectInfoTree.TreeLock);
1330             }
1331         }
1332     }
1333
1334     return pDirNode;
1335 }
1336
1337 BOOLEAN
1338 AFSCheckForReadOnlyAccess( IN ACCESS_MASK DesiredAccess,
1339                            IN BOOLEAN DirectoryEntry)
1340 {
1341
1342     BOOLEAN bReturn = TRUE;
1343     ACCESS_MASK stAccessMask = 0;
1344
1345     //
1346     // Get rid of anything we don't know about
1347     //
1348
1349     DesiredAccess = (DesiredAccess   &
1350                           ( DELETE |
1351                             READ_CONTROL |
1352                             WRITE_OWNER |
1353                             WRITE_DAC |
1354                             SYNCHRONIZE |
1355                             ACCESS_SYSTEM_SECURITY |
1356                             FILE_WRITE_DATA |
1357                             FILE_READ_EA |
1358                             FILE_WRITE_EA |
1359                             FILE_READ_ATTRIBUTES |
1360                             FILE_WRITE_ATTRIBUTES |
1361                             FILE_LIST_DIRECTORY |
1362                             FILE_TRAVERSE |
1363                             FILE_DELETE_CHILD |
1364                             FILE_APPEND_DATA));
1365
1366     //
1367     // Our 'read only' access mask. These are the accesses we will
1368     // allow for a read only file
1369     //
1370
1371     stAccessMask = DELETE |
1372                         READ_CONTROL |
1373                         WRITE_OWNER |
1374                         WRITE_DAC |
1375                         SYNCHRONIZE |
1376                         ACCESS_SYSTEM_SECURITY |
1377                         FILE_READ_DATA |
1378                         FILE_READ_EA |
1379                         FILE_WRITE_EA |
1380                         FILE_READ_ATTRIBUTES |
1381                         FILE_WRITE_ATTRIBUTES |
1382                         FILE_EXECUTE |
1383                         FILE_LIST_DIRECTORY |
1384                         FILE_TRAVERSE;
1385
1386     //
1387     // For a directory, add in the directory specific accesses
1388     //
1389
1390     if( DirectoryEntry)
1391     {
1392
1393         stAccessMask |= FILE_ADD_SUBDIRECTORY |
1394                                 FILE_ADD_FILE |
1395                                 FILE_DELETE_CHILD;
1396     }
1397
1398     if( FlagOn( DesiredAccess, ~stAccessMask))
1399     {
1400
1401         //
1402         // A write access is set ...
1403         //
1404
1405         bReturn = FALSE;
1406     }
1407
1408     return bReturn;
1409 }
1410
1411 NTSTATUS
1412 AFSEvaluateNode( IN GUID *AuthGroup,
1413                  IN AFSDirectoryCB *DirEntry)
1414 {
1415
1416     NTSTATUS ntStatus = STATUS_SUCCESS;
1417     AFSDirEnumEntry *pDirEntry = NULL;
1418     UNICODE_STRING uniTargetName;
1419
1420     __Enter
1421     {
1422
1423         ntStatus = AFSEvaluateTargetByID( DirEntry->ObjectInformation,
1424                                           AuthGroup,
1425                                           FALSE,
1426                                           &pDirEntry);
1427
1428         if( !NT_SUCCESS( ntStatus))
1429         {
1430
1431             try_return( ntStatus);
1432         }
1433
1434         DirEntry->ObjectInformation->TargetFileId = pDirEntry->TargetFileId;
1435
1436         DirEntry->ObjectInformation->Expiration = pDirEntry->Expiration;
1437
1438         DirEntry->ObjectInformation->DataVersion = pDirEntry->DataVersion;
1439
1440         DirEntry->ObjectInformation->FileType = pDirEntry->FileType;
1441
1442         DirEntry->ObjectInformation->CreationTime = pDirEntry->CreationTime;
1443
1444         DirEntry->ObjectInformation->LastAccessTime = pDirEntry->LastAccessTime;
1445
1446         DirEntry->ObjectInformation->LastWriteTime = pDirEntry->LastWriteTime;
1447
1448         DirEntry->ObjectInformation->ChangeTime = pDirEntry->ChangeTime;
1449
1450         DirEntry->ObjectInformation->EndOfFile = pDirEntry->EndOfFile;
1451
1452         DirEntry->ObjectInformation->AllocationSize = pDirEntry->AllocationSize;
1453
1454         DirEntry->ObjectInformation->FileAttributes = pDirEntry->FileAttributes;
1455
1456         if( pDirEntry->FileType == AFS_FILE_TYPE_MOUNTPOINT ||
1457             pDirEntry->FileType == AFS_FILE_TYPE_DFSLINK)
1458         {
1459
1460             DirEntry->ObjectInformation->FileAttributes |= (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT);
1461         }
1462
1463         if( pDirEntry->FileType == AFS_FILE_TYPE_SYMLINK)
1464         {
1465
1466             if ( DirEntry->ObjectInformation->FileAttributes == FILE_ATTRIBUTE_NORMAL)
1467             {
1468
1469                 DirEntry->ObjectInformation->FileAttributes = FILE_ATTRIBUTE_REPARSE_POINT;
1470             }
1471             else
1472             {
1473
1474                 DirEntry->ObjectInformation->FileAttributes |= FILE_ATTRIBUTE_REPARSE_POINT;
1475             }
1476         }
1477
1478         DirEntry->ObjectInformation->EaSize = pDirEntry->EaSize;
1479
1480         DirEntry->ObjectInformation->Links = pDirEntry->Links;
1481
1482         //
1483         // If we have a target name then see if it needs updating ...
1484         //
1485
1486         if( pDirEntry->TargetNameLength > 0)
1487         {
1488
1489             //
1490             // Update the target name information if needed
1491             //
1492
1493             uniTargetName.Length = (USHORT)pDirEntry->TargetNameLength;
1494
1495             uniTargetName.MaximumLength = uniTargetName.Length;
1496
1497             uniTargetName.Buffer = (WCHAR *)((char *)pDirEntry + pDirEntry->TargetNameOffset);
1498
1499             AFSAcquireExcl( &DirEntry->NonPaged->Lock,
1500                             TRUE);
1501
1502             if( DirEntry->NameInformation.TargetName.Length == 0 ||
1503                 RtlCompareUnicodeString( &uniTargetName,
1504                                          &DirEntry->NameInformation.TargetName,
1505                                          TRUE) != 0)
1506             {
1507
1508                 //
1509                 // Update the target name
1510                 //
1511
1512                 ntStatus = AFSUpdateTargetName( &DirEntry->NameInformation.TargetName,
1513                                                 &DirEntry->Flags,
1514                                                 uniTargetName.Buffer,
1515                                                 uniTargetName.Length);
1516
1517                 if( !NT_SUCCESS( ntStatus))
1518                 {
1519
1520                     AFSReleaseResource( &DirEntry->NonPaged->Lock);
1521
1522                     try_return( ntStatus);
1523                 }
1524             }
1525
1526             AFSReleaseResource( &DirEntry->NonPaged->Lock);
1527         }
1528
1529 try_exit:
1530
1531         if( pDirEntry != NULL)
1532         {
1533
1534             AFSExFreePoolWithTag( pDirEntry, AFS_GENERIC_MEMORY_2_TAG);
1535         }
1536     }
1537
1538     return ntStatus;
1539 }
1540
1541 NTSTATUS
1542 AFSValidateSymLink( IN GUID *AuthGroup,
1543                     IN AFSDirectoryCB *DirEntry)
1544 {
1545
1546     NTSTATUS ntStatus = STATUS_SUCCESS;
1547     AFSDirEnumEntry *pDirEntry = NULL;
1548     UNICODE_STRING uniTargetName;
1549
1550     __Enter
1551     {
1552
1553         ntStatus = AFSEvaluateTargetByID( DirEntry->ObjectInformation,
1554                                           AuthGroup,
1555                                           FALSE,
1556                                           &pDirEntry);
1557
1558         if( !NT_SUCCESS( ntStatus))
1559         {
1560
1561             try_return( ntStatus);
1562         }
1563
1564         if( pDirEntry->FileType == AFS_FILE_TYPE_UNKNOWN ||
1565             pDirEntry->FileType == AFS_FILE_TYPE_INVALID)
1566         {
1567
1568             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1569                           AFS_TRACE_LEVEL_VERBOSE_2,
1570                           "AFSValidateSymLink Invalid type Status %08lX\n",
1571                           STATUS_OBJECT_NAME_NOT_FOUND));
1572
1573             try_return( ntStatus = STATUS_OBJECT_NAME_NOT_FOUND);
1574         }
1575
1576         DirEntry->ObjectInformation->TargetFileId = pDirEntry->TargetFileId;
1577
1578         DirEntry->ObjectInformation->Expiration = pDirEntry->Expiration;
1579
1580         DirEntry->ObjectInformation->DataVersion = pDirEntry->DataVersion;
1581
1582         //
1583         // Update the target name information if needed
1584         //
1585
1586         uniTargetName.Length = (USHORT)pDirEntry->TargetNameLength;
1587
1588         uniTargetName.MaximumLength = uniTargetName.Length;
1589
1590         uniTargetName.Buffer = (WCHAR *)((char *)pDirEntry + pDirEntry->TargetNameOffset);
1591
1592         if( uniTargetName.Length > 0)
1593         {
1594
1595             AFSAcquireExcl( &DirEntry->NonPaged->Lock,
1596                             TRUE);
1597
1598             if( DirEntry->NameInformation.TargetName.Length == 0 ||
1599                 RtlCompareUnicodeString( &uniTargetName,
1600                                          &DirEntry->NameInformation.TargetName,
1601                                          TRUE) != 0)
1602             {
1603
1604                 //
1605                 // Update the target name
1606                 //
1607
1608                 ntStatus = AFSUpdateTargetName( &DirEntry->NameInformation.TargetName,
1609                                                 &DirEntry->Flags,
1610                                                 uniTargetName.Buffer,
1611                                                 uniTargetName.Length);
1612
1613                 if( !NT_SUCCESS( ntStatus))
1614                 {
1615
1616                     AFSReleaseResource( &DirEntry->NonPaged->Lock);
1617
1618                     try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1619                 }
1620             }
1621
1622             AFSReleaseResource( &DirEntry->NonPaged->Lock);
1623         }
1624
1625         //
1626         // If the FileType is the same then nothing to do since it IS
1627         // a SymLink
1628         //
1629
1630         if( pDirEntry->FileType == DirEntry->ObjectInformation->FileType)
1631         {
1632
1633             ASSERT( pDirEntry->FileType == AFS_FILE_TYPE_SYMLINK);
1634
1635             try_return( ntStatus = STATUS_SUCCESS);
1636         }
1637
1638         DirEntry->ObjectInformation->FileType = pDirEntry->FileType;
1639
1640         DirEntry->ObjectInformation->CreationTime = pDirEntry->CreationTime;
1641
1642         DirEntry->ObjectInformation->LastAccessTime = pDirEntry->LastAccessTime;
1643
1644         DirEntry->ObjectInformation->LastWriteTime = pDirEntry->LastWriteTime;
1645
1646         DirEntry->ObjectInformation->ChangeTime = pDirEntry->ChangeTime;
1647
1648         DirEntry->ObjectInformation->EndOfFile = pDirEntry->EndOfFile;
1649
1650         DirEntry->ObjectInformation->AllocationSize = pDirEntry->AllocationSize;
1651
1652         DirEntry->ObjectInformation->FileAttributes = pDirEntry->FileAttributes;
1653
1654         if( pDirEntry->FileType == AFS_FILE_TYPE_MOUNTPOINT ||
1655             pDirEntry->FileType == AFS_FILE_TYPE_DFSLINK)
1656         {
1657
1658             DirEntry->ObjectInformation->FileAttributes |= (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT);
1659         }
1660
1661         if( pDirEntry->FileType == AFS_FILE_TYPE_SYMLINK)
1662         {
1663
1664             if ( DirEntry->ObjectInformation->FileAttributes == FILE_ATTRIBUTE_NORMAL)
1665             {
1666
1667                 DirEntry->ObjectInformation->FileAttributes = FILE_ATTRIBUTE_REPARSE_POINT;
1668             }
1669             else
1670             {
1671
1672                 DirEntry->ObjectInformation->FileAttributes |= FILE_ATTRIBUTE_REPARSE_POINT;
1673             }
1674         }
1675
1676         DirEntry->ObjectInformation->EaSize = pDirEntry->EaSize;
1677
1678         DirEntry->ObjectInformation->Links = pDirEntry->Links;
1679
1680 try_exit:
1681
1682         if( pDirEntry != NULL)
1683         {
1684
1685             AFSExFreePoolWithTag( pDirEntry, AFS_GENERIC_MEMORY_2_TAG);
1686         }
1687     }
1688
1689     return ntStatus;
1690 }
1691
1692 NTSTATUS
1693 AFSInvalidateObject( IN OUT AFSObjectInfoCB **ppObjectInfo,
1694                      IN     ULONG Reason)
1695 {
1696
1697     NTSTATUS ntStatus = STATUS_SUCCESS;
1698     AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
1699     IO_STATUS_BLOCK stIoStatus;
1700     ULONG ulFilter = 0;
1701     AFSObjectInfoCB * pParentObjectInfo = NULL;
1702
1703     AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1704                   AFS_TRACE_LEVEL_VERBOSE,
1705                   "AFSInvalidateObject Invalidation on node type %d for fid %08lX-%08lX-%08lX-%08lX Reason %d\n",
1706                   (*ppObjectInfo)->FileType,
1707                   (*ppObjectInfo)->FileId.Cell,
1708                   (*ppObjectInfo)->FileId.Volume,
1709                   (*ppObjectInfo)->FileId.Vnode,
1710                   (*ppObjectInfo)->FileId.Unique,
1711                   Reason));
1712
1713     if ( BooleanFlagOn( (*ppObjectInfo)->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
1714     {
1715
1716         pParentObjectInfo = AFSFindObjectInfo( (*ppObjectInfo)->VolumeCB,
1717                                                &(*ppObjectInfo)->ParentFileId,
1718                                                FALSE);
1719     }
1720
1721     if( (*ppObjectInfo)->FileType == AFS_FILE_TYPE_SYMLINK ||
1722         (*ppObjectInfo)->FileType == AFS_FILE_TYPE_DFSLINK ||
1723         (*ppObjectInfo)->FileType == AFS_FILE_TYPE_MOUNTPOINT)
1724     {
1725         //
1726         // We only act on the mount point itself, not the target. If the
1727         // node has been deleted then mark it as such otherwise indicate
1728         // it requires verification
1729         //
1730
1731         if( Reason == AFS_INVALIDATE_DELETED)
1732         {
1733             SetFlag( (*ppObjectInfo)->Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID);
1734         }
1735         else
1736         {
1737
1738             if( Reason == AFS_INVALIDATE_FLUSHED)
1739             {
1740
1741                 (*ppObjectInfo)->DataVersion.QuadPart = (ULONGLONG)-1;
1742
1743                 SetFlag( (*ppObjectInfo)->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
1744             }
1745
1746             (*ppObjectInfo)->Expiration.QuadPart = 0;
1747
1748             (*ppObjectInfo)->TargetFileId.Vnode = 0;
1749
1750             (*ppObjectInfo)->TargetFileId.Unique = 0;
1751
1752             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1753                           AFS_TRACE_LEVEL_VERBOSE,
1754                           "AFSInvalidateObject Setting VERIFY flag on fid %08lX-%08lX-%08lX-%08lX\n",
1755                           (*ppObjectInfo)->FileId.Cell,
1756                           (*ppObjectInfo)->FileId.Volume,
1757                           (*ppObjectInfo)->FileId.Vnode,
1758                           (*ppObjectInfo)->FileId.Unique));
1759
1760             SetFlag( (*ppObjectInfo)->Flags, AFS_OBJECT_FLAGS_VERIFY);
1761         }
1762
1763         if ( pParentObjectInfo != NULL)
1764         {
1765
1766             ulFilter = FILE_NOTIFY_CHANGE_FILE_NAME;
1767
1768             if( Reason == AFS_INVALIDATE_CREDS)
1769             {
1770                 ulFilter |= FILE_NOTIFY_CHANGE_SECURITY;
1771             }
1772
1773             if( Reason == AFS_INVALIDATE_DATA_VERSION ||
1774                 Reason == AFS_INVALIDATE_FLUSHED)
1775             {
1776                 ulFilter |= FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE;
1777             }
1778             else
1779             {
1780                 ulFilter |= FILE_NOTIFY_CHANGE_ATTRIBUTES;
1781             }
1782
1783             AFSFsRtlNotifyFullReportChange( pParentObjectInfo,
1784                                             NULL,
1785                                             ulFilter,
1786                                             FILE_ACTION_MODIFIED);
1787         }
1788
1789         try_return( ntStatus);
1790     }
1791
1792     //
1793     // Depending on the reason for invalidation then perform work on the node
1794     //
1795
1796     switch( Reason)
1797     {
1798
1799     case AFS_INVALIDATE_DELETED:
1800         {
1801
1802             //
1803             // Mark this node as invalid
1804             //
1805
1806             (*ppObjectInfo)->Links = 0;
1807
1808             SetFlag( (*ppObjectInfo)->Flags, AFS_OBJECT_FLAGS_DELETED);
1809
1810             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1811                           AFS_TRACE_LEVEL_VERBOSE,
1812                           "AFSInvalidateObject Set DELETE flag on fid %08lX-%08lX-%08lX-%08lX\n",
1813                           (*ppObjectInfo)->FileId.Cell,
1814                           (*ppObjectInfo)->FileId.Volume,
1815                           (*ppObjectInfo)->FileId.Vnode,
1816                           (*ppObjectInfo)->FileId.Unique));
1817
1818             if( pParentObjectInfo != NULL)
1819             {
1820
1821                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1822                               AFS_TRACE_LEVEL_VERBOSE,
1823                               "AFSInvalidateObject Set VERIFY flag on parent fid %08lX-%08lX-%08lX-%08lX\n",
1824                               pParentObjectInfo->FileId.Cell,
1825                               pParentObjectInfo->FileId.Volume,
1826                               pParentObjectInfo->FileId.Vnode,
1827                               pParentObjectInfo->FileId.Unique));
1828
1829                 SetFlag( pParentObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
1830
1831                 pParentObjectInfo->DataVersion.QuadPart = (ULONGLONG)-1;
1832
1833                 pParentObjectInfo->Expiration.QuadPart = 0;
1834
1835                 if( (*ppObjectInfo)->FileType == AFS_FILE_TYPE_DIRECTORY)
1836                 {
1837                     ulFilter = FILE_NOTIFY_CHANGE_DIR_NAME;
1838                 }
1839                 else
1840                 {
1841                     ulFilter = FILE_NOTIFY_CHANGE_FILE_NAME;
1842                 }
1843
1844                 AFSFsRtlNotifyFullReportChange( pParentObjectInfo,
1845                                                 NULL,
1846                                                 ulFilter,
1847                                                 FILE_ACTION_REMOVED);
1848             }
1849
1850             if( NT_SUCCESS( AFSQueueInvalidateObject( (*ppObjectInfo),
1851                                                       Reason)))
1852             {
1853                 (*ppObjectInfo) = NULL; // We'll dec the count in the worker item
1854             }
1855
1856             break;
1857         }
1858
1859     case AFS_INVALIDATE_FLUSHED:
1860         {
1861
1862             if( (*ppObjectInfo)->FileType == AFS_FILE_TYPE_FILE &&
1863                 (*ppObjectInfo)->Fcb != NULL)
1864             {
1865
1866                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1867                               AFS_TRACE_LEVEL_VERBOSE,
1868                               "AFSInvalidateObject Flush/purge file fid %08lX-%08lX-%08lX-%08lX\n",
1869                               (*ppObjectInfo)->FileId.Cell,
1870                               (*ppObjectInfo)->FileId.Volume,
1871                               (*ppObjectInfo)->FileId.Vnode,
1872                               (*ppObjectInfo)->FileId.Unique));
1873
1874                 AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
1875                               AFS_TRACE_LEVEL_VERBOSE,
1876                               "AFSInvalidateObject Flush/purge Acquiring Fcb lock %p EXCL %08lX\n",
1877                               &(*ppObjectInfo)->Fcb->NPFcb->Resource,
1878                               PsGetCurrentThread()));
1879
1880                 AFSAcquireExcl( &(*ppObjectInfo)->Fcb->NPFcb->Resource,
1881                                 TRUE);
1882
1883                 AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
1884                               AFS_TRACE_LEVEL_VERBOSE,
1885                               "AFSInvalidateObject Flush/purge Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
1886                               &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectResource,
1887                               PsGetCurrentThread()));
1888
1889                 AFSAcquireExcl( &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectResource,
1890                                 TRUE);
1891
1892                 __try
1893                 {
1894
1895                     CcFlushCache( &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectPointers,
1896                                   NULL,
1897                                   0,
1898                                   &stIoStatus);
1899
1900                     if( !NT_SUCCESS( stIoStatus.Status))
1901                     {
1902
1903                         AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
1904                                       AFS_TRACE_LEVEL_ERROR,
1905                                       "AFSInvalidateObject CcFlushCache failure FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
1906                                       (*ppObjectInfo)->FileId.Cell,
1907                                       (*ppObjectInfo)->FileId.Volume,
1908                                       (*ppObjectInfo)->FileId.Vnode,
1909                                       (*ppObjectInfo)->FileId.Unique,
1910                                       stIoStatus.Status,
1911                                       stIoStatus.Information));
1912
1913                         ntStatus = stIoStatus.Status;
1914                     }
1915
1916
1917                     if ( (*ppObjectInfo)->Fcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL)
1918                     {
1919
1920                         if ( !CcPurgeCacheSection( &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectPointers,
1921                                                    NULL,
1922                                                    0,
1923                                                    FALSE))
1924                         {
1925
1926                             AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
1927                                           AFS_TRACE_LEVEL_WARNING,
1928                                           "AFSInvalidateObject CcPurgeCacheSection failure FID %08lX-%08lX-%08lX-%08lX\n",
1929                                           (*ppObjectInfo)->FileId.Cell,
1930                                           (*ppObjectInfo)->FileId.Volume,
1931                                           (*ppObjectInfo)->FileId.Vnode,
1932                                           (*ppObjectInfo)->FileId.Unique));
1933
1934                             SetFlag( (*ppObjectInfo)->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
1935                         }
1936                     }
1937                 }
1938                 __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()))
1939                 {
1940
1941                     ntStatus = GetExceptionCode();
1942
1943                     AFSDbgTrace(( 0,
1944                                   0,
1945                                   "EXCEPTION - AFSInvalidateObject Cc FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
1946                                   (*ppObjectInfo)->FileId.Cell,
1947                                   (*ppObjectInfo)->FileId.Volume,
1948                                   (*ppObjectInfo)->FileId.Vnode,
1949                                   (*ppObjectInfo)->FileId.Unique,
1950                                   ntStatus));
1951
1952                     SetFlag( (*ppObjectInfo)->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
1953                 }
1954
1955                 AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
1956                               AFS_TRACE_LEVEL_VERBOSE,
1957                               "AFSInvalidateObject Flush/purge Releasing Fcb SectionObject lock %p EXCL %08lX\n",
1958                               &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectResource,
1959                               PsGetCurrentThread()));
1960
1961                 AFSReleaseResource( &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectResource);
1962
1963                 AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
1964                               AFS_TRACE_LEVEL_VERBOSE,
1965                               "AFSInvalidateObject Flush/purge Releasing Fcb lock %p EXCL %08lX\n",
1966                               &(*ppObjectInfo)->Fcb->NPFcb->Resource,
1967                               PsGetCurrentThread()));
1968
1969                 AFSReleaseResource( &(*ppObjectInfo)->Fcb->NPFcb->Resource);
1970
1971                 if( !BooleanFlagOn( pRDRDevExt->DeviceFlags, AFS_DEVICE_FLAG_DIRECT_SERVICE_IO))
1972                 {
1973
1974                     //
1975                     // Clear out the extents
1976                     // Get rid of them (note this involves waiting
1977                     // for any writes or reads to the cache to complete)
1978                     //
1979
1980                     AFSTearDownFcbExtents( (*ppObjectInfo)->Fcb,
1981                                            NULL);
1982                 }
1983             }
1984
1985             (*ppObjectInfo)->DataVersion.QuadPart = (ULONGLONG)-1;
1986
1987
1988             if( (*ppObjectInfo)->FileType == AFS_FILE_TYPE_FILE)
1989             {
1990
1991                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1992                               AFS_TRACE_LEVEL_VERBOSE,
1993                               "AFSInvalidateObject Setting VERIFY_DATA flag on fid %08lX-%08lX-%08lX-%08lX\n",
1994                               (*ppObjectInfo)->FileId.Cell,
1995                               (*ppObjectInfo)->FileId.Volume,
1996                               (*ppObjectInfo)->FileId.Vnode,
1997                               (*ppObjectInfo)->FileId.Unique));
1998
1999                 SetFlag( (*ppObjectInfo)->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
2000             }
2001
2002             // Fall through to the default processing
2003         }
2004
2005     default:
2006         {
2007
2008             if( (*ppObjectInfo)->FileType == AFS_FILE_TYPE_DIRECTORY)
2009             {
2010                 ulFilter = FILE_NOTIFY_CHANGE_DIR_NAME;
2011             }
2012             else
2013             {
2014                 ulFilter = FILE_NOTIFY_CHANGE_FILE_NAME;
2015             }
2016
2017             if( Reason == AFS_INVALIDATE_CREDS)
2018             {
2019                 ulFilter |= FILE_NOTIFY_CHANGE_SECURITY;
2020             }
2021
2022             if( Reason == AFS_INVALIDATE_DATA_VERSION)
2023             {
2024                 ulFilter |= FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE;
2025             }
2026             else
2027             {
2028                 ulFilter |= FILE_NOTIFY_CHANGE_ATTRIBUTES;
2029             }
2030
2031             if( (*ppObjectInfo)->FileType == AFS_FILE_TYPE_DIRECTORY)
2032             {
2033
2034                 AFSFsRtlNotifyFullReportChange( (*ppObjectInfo),
2035                                                 NULL,
2036                                                 ulFilter,
2037                                                 FILE_ACTION_MODIFIED);
2038             }
2039             else if ( pParentObjectInfo != NULL)
2040             {
2041
2042                 AFSFsRtlNotifyFullReportChange( pParentObjectInfo,
2043                                                 NULL,
2044                                                 ulFilter,
2045                                                 FILE_ACTION_MODIFIED);
2046             }
2047
2048             //
2049             // Indicate this node requires re-evaluation for the remaining reasons
2050             //
2051
2052             (*ppObjectInfo)->Expiration.QuadPart = 0;
2053
2054             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2055                           AFS_TRACE_LEVEL_VERBOSE,
2056                           "AFSInvalidateObject Setting VERIFY flag on fid %08lX-%08lX-%08lX-%08lX\n",
2057                           (*ppObjectInfo)->FileId.Cell,
2058                           (*ppObjectInfo)->FileId.Volume,
2059                           (*ppObjectInfo)->FileId.Vnode,
2060                           (*ppObjectInfo)->FileId.Unique));
2061
2062             SetFlag( (*ppObjectInfo)->Flags, AFS_OBJECT_FLAGS_VERIFY);
2063
2064             if( Reason == AFS_INVALIDATE_DATA_VERSION ||
2065                 (*ppObjectInfo)->FileType == AFS_FILE_TYPE_FILE &&
2066                 ( Reason == AFS_INVALIDATE_CALLBACK ||
2067                   Reason == AFS_INVALIDATE_EXPIRED))
2068             {
2069                 if ( NT_SUCCESS( AFSQueueInvalidateObject( (*ppObjectInfo),
2070                                                            AFS_INVALIDATE_DATA_VERSION)))
2071                 {
2072
2073                     (*ppObjectInfo) = NULL; // We'll dec the count in the worker item
2074                 }
2075             }
2076
2077             break;
2078         }
2079     }
2080
2081   try_exit:
2082
2083     if ( pParentObjectInfo != NULL)
2084     {
2085
2086         AFSReleaseObjectInfo( &pParentObjectInfo);
2087     }
2088
2089     return ntStatus;
2090 }
2091
2092 NTSTATUS
2093 AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
2094 {
2095
2096     NTSTATUS ntStatus = STATUS_SUCCESS;
2097     AFSVolumeCB *pVolumeCB = NULL;
2098     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
2099     ULONGLONG   ullIndex = 0;
2100     AFSObjectInfoCB *pObjectInfo = NULL;
2101     LONG lCount;
2102
2103     __Enter
2104     {
2105
2106         AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2107                       AFS_TRACE_LEVEL_VERBOSE,
2108                       "AFSInvalidateCache Invalidation FID %08lX-%08lX-%08lX-%08lX Type %d WholeVolume %d Reason %d\n",
2109                       InvalidateCB->FileID.Cell,
2110                       InvalidateCB->FileID.Volume,
2111                       InvalidateCB->FileID.Vnode,
2112                       InvalidateCB->FileID.Unique,
2113                       InvalidateCB->FileType,
2114                       InvalidateCB->WholeVolume,
2115                       InvalidateCB->Reason));
2116
2117         //
2118         // Need to locate the Fcb for the directory to purge
2119         //
2120
2121         AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
2122                       AFS_TRACE_LEVEL_VERBOSE,
2123                       "AFSInvalidateCache Acquiring RDR VolumeTreeLock lock %p SHARED %08lX\n",
2124                       &pDevExt->Specific.RDR.VolumeTreeLock,
2125                       PsGetCurrentThread()));
2126
2127         //
2128         // Starve any exclusive waiters on this paticular call
2129         //
2130
2131         AFSAcquireSharedStarveExclusive( &pDevExt->Specific.RDR.VolumeTreeLock, TRUE);
2132
2133         //
2134         // Locate the volume node
2135         //
2136
2137         ullIndex = AFSCreateHighIndex( &InvalidateCB->FileID);
2138
2139         ntStatus = AFSLocateHashEntry( pDevExt->Specific.RDR.VolumeTree.TreeHead,
2140                                        ullIndex,
2141                                        (AFSBTreeEntry **)&pVolumeCB);
2142
2143         if( pVolumeCB != NULL)
2144         {
2145
2146             lCount = AFSVolumeIncrement( pVolumeCB,
2147                                          AFS_VOLUME_REFERENCE_INVALIDATE);
2148
2149             AFSDbgTrace(( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
2150                           AFS_TRACE_LEVEL_VERBOSE,
2151                           "AFSInvalidateCache Increment count on volume %p Cnt %d\n",
2152                           pVolumeCB,
2153                           lCount));
2154         }
2155
2156         AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
2157
2158         if( !NT_SUCCESS( ntStatus) ||
2159             pVolumeCB == NULL)
2160         {
2161
2162             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2163                           AFS_TRACE_LEVEL_WARNING,
2164                           "AFSInvalidateCache Invalidation FAILURE Unable to locate volume node FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
2165                           InvalidateCB->FileID.Cell,
2166                           InvalidateCB->FileID.Volume,
2167                           InvalidateCB->FileID.Vnode,
2168                           InvalidateCB->FileID.Unique,
2169                           ntStatus));
2170
2171             try_return( ntStatus = STATUS_SUCCESS);
2172         }
2173
2174         //
2175         // If this is a whole volume invalidation then go do it now
2176         //
2177
2178         if( InvalidateCB->WholeVolume)
2179         {
2180
2181             ntStatus = AFSInvalidateVolume( pVolumeCB,
2182                                             InvalidateCB->Reason);
2183
2184             try_return( ntStatus);
2185         }
2186
2187         AFSAcquireExcl( pVolumeCB->ObjectInfoTree.TreeLock,
2188                           TRUE);
2189
2190         if ( AFSIsVolumeFID( &InvalidateCB->FileID))
2191         {
2192
2193             pObjectInfo = &pVolumeCB->ObjectInformation;
2194         }
2195         else
2196         {
2197
2198             ullIndex = AFSCreateLowIndex( &InvalidateCB->FileID);
2199
2200             ntStatus = AFSLocateHashEntry( pVolumeCB->ObjectInfoTree.TreeHead,
2201                                            ullIndex,
2202                                            (AFSBTreeEntry **)&pObjectInfo);
2203         }
2204
2205         if( pObjectInfo != NULL)
2206         {
2207
2208             //
2209             // Reference the node so it won't be torn down
2210             //
2211
2212             lCount = AFSObjectInfoIncrement( pObjectInfo,
2213                                              AFS_OBJECT_REFERENCE_INVALIDATION);
2214
2215             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2216                           AFS_TRACE_LEVEL_VERBOSE,
2217                           "AFSInvalidateCache Increment count on object %p Cnt %d\n",
2218                           pObjectInfo,
2219                           lCount));
2220         }
2221
2222         AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
2223
2224         if( !NT_SUCCESS( ntStatus) ||
2225             pObjectInfo == NULL)
2226         {
2227
2228             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2229                           AFS_TRACE_LEVEL_VERBOSE,
2230                           "AFSInvalidateCache Invalidation FAILURE Unable to locate object FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
2231                           InvalidateCB->FileID.Cell,
2232                           InvalidateCB->FileID.Volume,
2233                           InvalidateCB->FileID.Vnode,
2234                           InvalidateCB->FileID.Unique,
2235                           ntStatus));
2236
2237             try_return( ntStatus = STATUS_SUCCESS);
2238         }
2239
2240         AFSInvalidateObject( &pObjectInfo,
2241                              InvalidateCB->Reason);
2242
2243 try_exit:
2244
2245         if( pObjectInfo != NULL)
2246         {
2247
2248             lCount = AFSObjectInfoDecrement( pObjectInfo,
2249                                              AFS_OBJECT_REFERENCE_INVALIDATION);
2250
2251             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2252                           AFS_TRACE_LEVEL_VERBOSE,
2253                           "AFSInvalidateCache Decrement count on object %p Cnt %d\n",
2254                           pObjectInfo,
2255                           lCount));
2256         }
2257
2258         if ( pVolumeCB != NULL)
2259         {
2260
2261             lCount = AFSVolumeDecrement( pVolumeCB,
2262                                          AFS_VOLUME_REFERENCE_INVALIDATE);
2263
2264             AFSDbgTrace(( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
2265                           AFS_TRACE_LEVEL_VERBOSE,
2266                           "AFSInvalidateCache Decrement count on volume %p Cnt %d\n",
2267                           pVolumeCB,
2268                           lCount));
2269         }
2270     }
2271
2272     return ntStatus;
2273 }
2274
2275 BOOLEAN
2276 AFSIsChildOfParent( IN AFSFcb *Dcb,
2277                     IN AFSFcb *Fcb)
2278 {
2279
2280     BOOLEAN bIsChild = FALSE;
2281     AFSFcb *pCurrentFcb = Fcb;
2282     AFSObjectInfoCB * pParentObjectInfo = NULL;
2283
2284     while( pCurrentFcb != NULL)
2285     {
2286
2287         if( BooleanFlagOn( pCurrentFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID) &&
2288             AFSIsEqualFID( &pCurrentFcb->ObjectInformation->ParentFileId, &Dcb->ObjectInformation->FileId))
2289         {
2290
2291             bIsChild = TRUE;
2292
2293             break;
2294         }
2295
2296         pParentObjectInfo = AFSFindObjectInfo( pCurrentFcb->ObjectInformation->VolumeCB,
2297                                                &pCurrentFcb->ObjectInformation->ParentFileId,
2298                                                FALSE);
2299
2300         if ( pParentObjectInfo != NULL)
2301         {
2302
2303             pCurrentFcb = pParentObjectInfo->Fcb;
2304
2305             AFSReleaseObjectInfo( &pParentObjectInfo);
2306         }
2307         else
2308         {
2309
2310             pCurrentFcb = NULL;
2311         }
2312     }
2313
2314     return bIsChild;
2315 }
2316
2317 inline
2318 ULONGLONG
2319 AFSCreateHighIndex( IN AFSFileID *FileID)
2320 {
2321
2322     ULONGLONG ullIndex = 0;
2323
2324     ullIndex = (((ULONGLONG)FileID->Cell << 32) | FileID->Volume);
2325
2326     return ullIndex;
2327 }
2328
2329 inline
2330 ULONGLONG
2331 AFSCreateLowIndex( IN AFSFileID *FileID)
2332 {
2333
2334     ULONGLONG ullIndex = 0;
2335
2336     ullIndex = (((ULONGLONG)FileID->Vnode << 32) | FileID->Unique);
2337
2338     return ullIndex;
2339 }
2340
2341 BOOLEAN
2342 AFSCheckAccess( IN ACCESS_MASK DesiredAccess,
2343                 IN ACCESS_MASK GrantedAccess,
2344                 IN BOOLEAN DirectoryEntry)
2345 {
2346
2347     BOOLEAN bAccessGranted = TRUE;
2348
2349     //
2350     // Check if we are asking for read/write and granted only read only
2351     // NOTE: There will be more checks here
2352     //
2353
2354     if( !AFSCheckForReadOnlyAccess( DesiredAccess,
2355                                     DirectoryEntry) &&
2356         AFSCheckForReadOnlyAccess( GrantedAccess,
2357                                    DirectoryEntry))
2358     {
2359
2360         bAccessGranted = FALSE;
2361     }
2362
2363     return bAccessGranted;
2364 }
2365
2366 NTSTATUS
2367 AFSGetDriverStatus( IN AFSDriverStatusRespCB *DriverStatus)
2368 {
2369
2370     NTSTATUS         ntStatus = STATUS_SUCCESS;
2371     AFSDeviceExt    *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
2372
2373     //
2374     // Start with read
2375     //
2376
2377     DriverStatus->Status = AFS_DRIVER_STATUS_READY;
2378
2379     if( AFSGlobalRoot == NULL)
2380     {
2381
2382         //
2383         // We are not ready
2384         //
2385
2386         DriverStatus->Status = AFS_DRIVER_STATUS_NOT_READY;
2387     }
2388
2389     if( pControlDevExt->Specific.Control.CommServiceCB.IrpPoolControlFlag != POOL_ACTIVE)
2390     {
2391
2392         //
2393         // No service yet
2394         //
2395
2396         DriverStatus->Status = AFS_DRIVER_STATUS_NO_SERVICE;
2397     }
2398
2399     return ntStatus;
2400 }
2401
2402 NTSTATUS
2403 AFSSubstituteSysName( IN UNICODE_STRING *ComponentName,
2404                       IN UNICODE_STRING *SubstituteName,
2405                       IN ULONG StringIndex)
2406 {
2407
2408     NTSTATUS ntStatus = STATUS_SUCCESS;
2409     AFSDeviceExt    *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
2410     AFSSysNameCB    *pSysName = NULL;
2411     ERESOURCE       *pSysNameLock = NULL;
2412     ULONG            ulIndex = 1;
2413     USHORT           usIndex = 0;
2414     UNICODE_STRING   uniSysName;
2415
2416     __Enter
2417     {
2418
2419 #if defined(_WIN64)
2420
2421         if( IoIs32bitProcess( NULL))
2422         {
2423
2424             pSysNameLock = &pControlDevExt->Specific.Control.SysName32ListLock;
2425
2426             pSysName = pControlDevExt->Specific.Control.SysName32ListHead;
2427         }
2428         else
2429         {
2430
2431             pSysNameLock = &pControlDevExt->Specific.Control.SysName64ListLock;
2432
2433             pSysName = pControlDevExt->Specific.Control.SysName64ListHead;
2434         }
2435 #else
2436
2437         pSysNameLock = &pControlDevExt->Specific.Control.SysName32ListLock;
2438
2439         pSysName = pControlDevExt->Specific.Control.SysName32ListHead;
2440
2441 #endif
2442
2443         AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
2444                       AFS_TRACE_LEVEL_VERBOSE,
2445                       "AFSSubstituteSysName Acquiring SysName lock %p SHARED %08lX\n",
2446                       pSysNameLock,
2447                       PsGetCurrentThread()));
2448
2449         AFSAcquireShared( pSysNameLock,
2450                           TRUE);
2451
2452         //
2453         // Find where we are in the list
2454         //
2455
2456         while( pSysName != NULL &&
2457             ulIndex < StringIndex)
2458         {
2459
2460             pSysName = pSysName->fLink;
2461
2462             ulIndex++;
2463         }
2464
2465         if( pSysName == NULL)
2466         {
2467
2468             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2469                           AFS_TRACE_LEVEL_VERBOSE_2,
2470                           "AFSSubstituteSysName No sysname %wZ Status %08lX\n",
2471                           &ComponentName,
2472                           STATUS_OBJECT_NAME_NOT_FOUND));
2473
2474             try_return( ntStatus = STATUS_OBJECT_NAME_NOT_FOUND);
2475         }
2476
2477         RtlInitUnicodeString( &uniSysName,
2478                               L"@SYS");
2479         //
2480         // If it is a full component of @SYS then just substitue the
2481         // name in
2482         //
2483
2484         if( RtlCompareUnicodeString( &uniSysName,
2485                                      ComponentName,
2486                                      TRUE) == 0)
2487         {
2488
2489             SubstituteName->Length = pSysName->SysName.Length;
2490             SubstituteName->MaximumLength = SubstituteName->Length;
2491
2492             SubstituteName->Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
2493                                                                         SubstituteName->Length,
2494                                                                         AFS_SUBST_BUFFER_TAG);
2495
2496             if( SubstituteName->Buffer == NULL)
2497             {
2498
2499                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
2500             }
2501
2502             RtlCopyMemory( SubstituteName->Buffer,
2503                            pSysName->SysName.Buffer,
2504                            pSysName->SysName.Length);
2505         }
2506         else
2507         {
2508
2509             usIndex = 0;
2510
2511             while( ComponentName->Buffer[ usIndex] != L'@')
2512             {
2513
2514                 usIndex++;
2515             }
2516
2517             SubstituteName->Length = (usIndex * sizeof( WCHAR)) + pSysName->SysName.Length;
2518             SubstituteName->MaximumLength = SubstituteName->Length;
2519
2520             SubstituteName->Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
2521                                                                         SubstituteName->Length,
2522                                                                         AFS_SUBST_BUFFER_TAG);
2523
2524             if( SubstituteName->Buffer == NULL)
2525             {
2526
2527                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
2528             }
2529
2530             RtlCopyMemory( SubstituteName->Buffer,
2531                            ComponentName->Buffer,
2532                            usIndex * sizeof( WCHAR));
2533
2534             RtlCopyMemory( &SubstituteName->Buffer[ usIndex],
2535                            pSysName->SysName.Buffer,
2536                            pSysName->SysName.Length);
2537         }
2538
2539 try_exit:
2540
2541         AFSReleaseResource( pSysNameLock);
2542     }
2543
2544     return ntStatus;
2545 }
2546
2547 NTSTATUS
2548 AFSSubstituteNameInPath( IN OUT UNICODE_STRING *FullPathName,
2549                          IN OUT UNICODE_STRING *ComponentName,
2550                          IN UNICODE_STRING *SubstituteName,
2551                          IN OUT UNICODE_STRING *RemainingPath,
2552                          IN BOOLEAN FreePathName)
2553 {
2554
2555     NTSTATUS ntStatus = STATUS_SUCCESS;
2556     UNICODE_STRING uniPathName;
2557     USHORT usPrefixNameLen = 0;
2558     SHORT  sNameLenDelta = 0;
2559
2560     __Enter
2561     {
2562
2563         //
2564         // If the passed in name can handle the additional length
2565         // then just moves things around
2566         //
2567
2568         sNameLenDelta = SubstituteName->Length - ComponentName->Length;
2569
2570         usPrefixNameLen = (USHORT)(ComponentName->Buffer - FullPathName->Buffer);
2571
2572         if( FullPathName->MaximumLength > FullPathName->Length + sNameLenDelta)
2573         {
2574
2575             if( FullPathName->Length > usPrefixNameLen + ComponentName->Length)
2576             {
2577
2578                 RtlMoveMemory( &FullPathName->Buffer[ ((usPrefixNameLen*sizeof( WCHAR) + SubstituteName->Length)/sizeof( WCHAR))],
2579                                &FullPathName->Buffer[ ((usPrefixNameLen*sizeof( WCHAR) + ComponentName->Length)/sizeof( WCHAR))],
2580                                FullPathName->Length - usPrefixNameLen*sizeof( WCHAR) - ComponentName->Length);
2581             }
2582
2583             RtlCopyMemory( &FullPathName->Buffer[ usPrefixNameLen],
2584                            SubstituteName->Buffer,
2585                            SubstituteName->Length);
2586
2587             FullPathName->Length += sNameLenDelta;
2588
2589             ComponentName->Length += sNameLenDelta;
2590
2591             ComponentName->MaximumLength = ComponentName->Length;
2592
2593             if ( RemainingPath->Buffer)
2594             {
2595
2596                 RemainingPath->Buffer += sNameLenDelta/sizeof( WCHAR);
2597             }
2598
2599             try_return( ntStatus);
2600         }
2601
2602         //
2603         // Need to re-allocate the buffer
2604         //
2605
2606         uniPathName.Length = FullPathName->Length -
2607                                          ComponentName->Length +
2608                                          SubstituteName->Length;
2609
2610         uniPathName.MaximumLength = FullPathName->MaximumLength + PAGE_SIZE;
2611
2612         uniPathName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
2613                                                                 uniPathName.MaximumLength,
2614                                                                 AFS_NAME_BUFFER_FOUR_TAG);
2615
2616         if( uniPathName.Buffer == NULL)
2617         {
2618
2619             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
2620         }
2621
2622         usPrefixNameLen = (USHORT)(ComponentName->Buffer - FullPathName->Buffer);
2623
2624         usPrefixNameLen *= sizeof( WCHAR);
2625
2626         RtlZeroMemory( uniPathName.Buffer,
2627                        uniPathName.MaximumLength);
2628
2629         RtlCopyMemory( uniPathName.Buffer,
2630                        FullPathName->Buffer,
2631                        usPrefixNameLen);
2632
2633         RtlCopyMemory( &uniPathName.Buffer[ (usPrefixNameLen/sizeof( WCHAR))],
2634                        SubstituteName->Buffer,
2635                        SubstituteName->Length);
2636
2637         if( FullPathName->Length > usPrefixNameLen + ComponentName->Length)
2638         {
2639
2640             RtlCopyMemory( &uniPathName.Buffer[ (usPrefixNameLen + SubstituteName->Length)/sizeof( WCHAR)],
2641                            &FullPathName->Buffer[ (usPrefixNameLen + ComponentName->Length)/sizeof( WCHAR)],
2642                            FullPathName->Length - usPrefixNameLen - ComponentName->Length);
2643         }
2644
2645         ComponentName->Buffer = uniPathName.Buffer + (ComponentName->Buffer - FullPathName->Buffer);
2646
2647         ComponentName->Length += sNameLenDelta;
2648
2649         ComponentName->MaximumLength = ComponentName->Length;
2650
2651         if ( RemainingPath->Buffer)
2652         {
2653
2654             RemainingPath->Buffer = uniPathName.Buffer
2655                 + (RemainingPath->Buffer - FullPathName->Buffer)
2656                 + sNameLenDelta/sizeof( WCHAR);
2657         }
2658
2659         if( FreePathName)
2660         {
2661             AFSExFreePoolWithTag( FullPathName->Buffer, 0);
2662         }
2663
2664         *FullPathName = uniPathName;
2665
2666 try_exit:
2667
2668         NOTHING;
2669     }
2670
2671     return ntStatus;
2672 }
2673
2674 NTSTATUS
2675 AFSInvalidateVolume( IN AFSVolumeCB *VolumeCB,
2676                      IN ULONG Reason)
2677 {
2678
2679     NTSTATUS ntStatus = STATUS_SUCCESS;
2680     AFSObjectInfoCB *pCurrentObject = NULL;
2681     AFSObjectInfoCB *pNextObject = NULL;
2682     LONG lCount;
2683
2684     __Enter
2685     {
2686
2687         AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2688                       AFS_TRACE_LEVEL_VERBOSE,
2689                       "AFSInvalidateVolume Invalidate volume fid %08lX-%08lX-%08lX-%08lX Reason %08lX\n",
2690                       VolumeCB->ObjectInformation.FileId.Cell,
2691                       VolumeCB->ObjectInformation.FileId.Volume,
2692                       VolumeCB->ObjectInformation.FileId.Vnode,
2693                       VolumeCB->ObjectInformation.FileId.Unique,
2694                       Reason));
2695
2696         //
2697         // Depending on the reason for invalidation then perform work on the node
2698         //
2699
2700         switch( Reason)
2701         {
2702
2703             case AFS_INVALIDATE_DELETED:
2704             {
2705
2706                 //
2707                 // Mark this volume as invalid
2708                 //
2709
2710                 SetFlag( VolumeCB->ObjectInformation.Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID);
2711
2712                 SetFlag( VolumeCB->Flags, AFS_VOLUME_FLAGS_OFFLINE);
2713
2714                 break;
2715             }
2716         }
2717
2718         AFSAcquireShared( VolumeCB->ObjectInfoTree.TreeLock,
2719                           TRUE);
2720
2721         //
2722         // Invalidate the volume root directory
2723         //
2724
2725         pCurrentObject = &VolumeCB->ObjectInformation;
2726
2727         if ( pCurrentObject )
2728         {
2729
2730             lCount = AFSObjectInfoIncrement( pCurrentObject,
2731                                              AFS_OBJECT_REFERENCE_INVALIDATION);
2732
2733             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2734                           AFS_TRACE_LEVEL_VERBOSE,
2735                           "AFSInvalidateVolumeObjects Increment count on object %p Cnt %d\n",
2736                           pCurrentObject,
2737                           lCount));
2738
2739             AFSReleaseResource( VolumeCB->ObjectInfoTree.TreeLock);
2740
2741             AFSInvalidateObject( &pCurrentObject,
2742                                  Reason);
2743
2744             AFSAcquireShared( VolumeCB->ObjectInfoTree.TreeLock,
2745                               TRUE);
2746
2747             if ( pCurrentObject)
2748             {
2749
2750                 lCount = AFSObjectInfoDecrement( pCurrentObject,
2751                                                  AFS_OBJECT_REFERENCE_INVALIDATION);
2752
2753                 AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2754                               AFS_TRACE_LEVEL_VERBOSE,
2755                               "AFSInvalidateVolumeObjects Decrement count on object %p Cnt %d\n",
2756                               pCurrentObject,
2757                               lCount));
2758             }
2759         }
2760
2761         //
2762         // Apply invalidation to all other volume objects
2763         //
2764
2765         pCurrentObject = VolumeCB->ObjectInfoListHead;
2766
2767         if ( pCurrentObject)
2768         {
2769
2770             //
2771             // Reference the node so it won't be torn down
2772             //
2773
2774             lCount = AFSObjectInfoIncrement( pCurrentObject,
2775                                              AFS_OBJECT_REFERENCE_INVALIDATION);
2776
2777             AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2778                           AFS_TRACE_LEVEL_VERBOSE,
2779                           "AFSInvalidateVolumeObjects Increment count on object %p Cnt %d\n",
2780                           pCurrentObject,
2781                           lCount));
2782         }
2783
2784         while( pCurrentObject != NULL)
2785         {
2786
2787             pNextObject = (AFSObjectInfoCB *)pCurrentObject->ListEntry.fLink;
2788
2789             if ( pNextObject)
2790             {
2791
2792                 //
2793                 // Reference the node so it won't be torn down
2794                 //
2795
2796                 lCount = AFSObjectInfoIncrement( pNextObject,
2797                                                  AFS_OBJECT_REFERENCE_INVALIDATION);
2798
2799                 AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2800                               AFS_TRACE_LEVEL_VERBOSE,
2801                               "AFSInvalidateVolumeObjects Increment count on object %p Cnt %d\n",
2802                               pNextObject,
2803                               lCount));
2804             }
2805
2806             AFSReleaseResource( VolumeCB->ObjectInfoTree.TreeLock);
2807
2808             AFSInvalidateObject( &pCurrentObject,
2809                                  Reason);
2810
2811             AFSAcquireShared( VolumeCB->ObjectInfoTree.TreeLock,
2812                               TRUE);
2813
2814             if ( pCurrentObject )
2815             {
2816
2817                 lCount = AFSObjectInfoDecrement( pCurrentObject,
2818                                                  AFS_OBJECT_REFERENCE_INVALIDATION);
2819
2820                 AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
2821                               AFS_TRACE_LEVEL_VERBOSE,
2822                               "AFSInvalidateVolumeObjects Decrement count on object %p Cnt %d\n",
2823                               pCurrentObject,
2824                               lCount));
2825             }
2826
2827             pCurrentObject = pNextObject;
2828         }
2829
2830         AFSReleaseResource( VolumeCB->ObjectInfoTree.TreeLock);
2831     }
2832
2833     return ntStatus;
2834 }
2835
2836 VOID
2837 AFSInvalidateAllVolumes( VOID)
2838 {
2839     AFSVolumeCB *pVolumeCB = NULL;
2840     AFSVolumeCB *pNextVolumeCB = NULL;
2841     AFSDeviceExt *pRDRDeviceExt = NULL;
2842     LONG lCount;
2843
2844     pRDRDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
2845
2846     AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
2847                   AFS_TRACE_LEVEL_VERBOSE,
2848                   "AFSInvalidateAllVolumes Acquiring RDR VolumeListLock lock %p SHARED %08lX\n",
2849                   &pRDRDeviceExt->Specific.RDR.VolumeListLock,
2850                   PsGetCurrentThread()));
2851
2852     AFSAcquireShared( &pRDRDeviceExt->Specific.RDR.VolumeListLock,
2853                       TRUE);
2854
2855     pVolumeCB = pRDRDeviceExt->Specific.RDR.VolumeListHead;
2856
2857     if ( pVolumeCB)
2858     {
2859
2860         AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
2861                       AFS_TRACE_LEVEL_VERBOSE,
2862                       "AFSInvalidateAllVolumes Acquiring VolumeRoot ObjectInfoTree lock %p SHARED %08lX\n",
2863                       pVolumeCB->ObjectInfoTree.TreeLock,
2864                       PsGetCurrentThread()));
2865
2866         lCount = AFSVolumeIncrement( pVolumeCB,
2867                                      AFS_VOLUME_REFERENCE_INVALIDATE);
2868
2869         AFSDbgTrace(( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
2870                       AFS_TRACE_LEVEL_VERBOSE,
2871                       "AFSInvalidateAllVolumes Increment count on volume %p Cnt %d\n",
2872                       pVolumeCB,
2873                       lCount));
2874     }
2875
2876     while( pVolumeCB != NULL)
2877     {
2878
2879         pNextVolumeCB = (AFSVolumeCB *)pVolumeCB->ListEntry.fLink;
2880
2881         if ( pNextVolumeCB)
2882         {
2883
2884             lCount = AFSVolumeIncrement( pNextVolumeCB,
2885                                          AFS_VOLUME_REFERENCE_INVALIDATE);
2886
2887             AFSDbgTrace(( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
2888                           AFS_TRACE_LEVEL_VERBOSE,
2889                           "AFSInvalidateAllVolumes Increment count on volume %p Cnt %d\n",
2890                           pVolumeCB,
2891                           lCount));
2892         }
2893
2894         AFSReleaseResource( &pRDRDeviceExt->Specific.RDR.VolumeListLock);
2895
2896         // do I need to hold the volume lock here?
2897
2898         AFSInvalidateVolume( pVolumeCB, AFS_INVALIDATE_EXPIRED);
2899
2900         AFSAcquireShared( &pRDRDeviceExt->Specific.RDR.VolumeListLock,
2901                           TRUE);
2902
2903         lCount = AFSVolumeDecrement( pVolumeCB,
2904                                      AFS_VOLUME_REFERENCE_INVALIDATE);
2905
2906         AFSDbgTrace(( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
2907                       AFS_TRACE_LEVEL_VERBOSE,
2908                       "AFSInvalidateAllVolumes Decrement count on volume %p Cnt %d\n",
2909                       pVolumeCB,
2910                       lCount));
2911
2912         pVolumeCB = pNextVolumeCB;
2913     }
2914
2915     AFSReleaseResource( &pRDRDeviceExt->Specific.RDR.VolumeListLock);
2916 }
2917
2918 NTSTATUS
2919 AFSVerifyEntry( IN GUID *AuthGroup,
2920                 IN AFSDirectoryCB *DirEntry,
2921                 IN BOOLEAN bFollowMountPoint)
2922 {
2923
2924     NTSTATUS ntStatus = STATUS_SUCCESS;
2925     AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
2926     AFSDirEnumEntry *pDirEnumEntry = NULL;
2927     AFSObjectInfoCB *pObjectInfo = DirEntry->ObjectInformation;
2928     IO_STATUS_BLOCK stIoStatus;
2929
2930     __Enter
2931     {
2932
2933         AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2934                       AFS_TRACE_LEVEL_VERBOSE_2,
2935                       "AFSVerifyEntry Verifying entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
2936                       &DirEntry->NameInformation.FileName,
2937                       pObjectInfo->FileId.Cell,
2938                       pObjectInfo->FileId.Volume,
2939                       pObjectInfo->FileId.Vnode,
2940                       pObjectInfo->FileId.Unique));
2941
2942         ntStatus = AFSEvaluateTargetByID( pObjectInfo,
2943                                           AuthGroup,
2944                                           bFollowMountPoint ? FALSE : TRUE,
2945                                           &pDirEnumEntry);
2946
2947         if( !NT_SUCCESS( ntStatus))
2948         {
2949
2950             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2951                           AFS_TRACE_LEVEL_ERROR,
2952                           "AFSVerifyEntry Evaluate Target failed %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
2953                           &DirEntry->NameInformation.FileName,
2954                           pObjectInfo->FileId.Cell,
2955                           pObjectInfo->FileId.Volume,
2956                           pObjectInfo->FileId.Vnode,
2957                           pObjectInfo->FileId.Unique,
2958                           ntStatus));
2959
2960             try_return( ntStatus);
2961         }
2962
2963         //
2964         // Check the data version of the file
2965         //
2966
2967         if( pObjectInfo->DataVersion.QuadPart == pDirEnumEntry->DataVersion.QuadPart &&
2968             !BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA))
2969         {
2970
2971             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
2972                           AFS_TRACE_LEVEL_VERBOSE,
2973                           "AFSVerifyEntry No DV change %I64X for Fcb %wZ FID %08lX-%08lX-%08lX-%08lX\n",
2974                           pObjectInfo->DataVersion.QuadPart,
2975                           &DirEntry->NameInformation.FileName,
2976                           pObjectInfo->FileId.Cell,
2977                           pObjectInfo->FileId.Volume,
2978                           pObjectInfo->FileId.Vnode,
2979                           pObjectInfo->FileId.Unique));
2980
2981             //
2982             // We are ok, just get out
2983             //
2984
2985             ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
2986
2987             try_return( ntStatus = STATUS_SUCCESS);
2988         }
2989
2990         //
2991         // New data version so we will need to process the node based on the type
2992         //
2993
2994         switch( pDirEnumEntry->FileType)
2995         {
2996
2997             case AFS_FILE_TYPE_MOUNTPOINT:
2998             {
2999
3000                 //
3001                 // For a mount point we need to ensure the target is the same
3002                 //
3003
3004                 if( !AFSIsEqualFID( &pObjectInfo->TargetFileId,
3005                                     &pDirEnumEntry->TargetFileId))
3006                 {
3007
3008                 }
3009
3010                 //
3011                 // Update the metadata for the entry
3012                 //
3013
3014                 ntStatus = AFSUpdateMetaData( DirEntry,
3015                                               pDirEnumEntry);
3016
3017                 if( NT_SUCCESS( ntStatus))
3018                 {
3019
3020                     ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
3021                 }
3022
3023                 break;
3024             }
3025
3026             case AFS_FILE_TYPE_SYMLINK:
3027             {
3028
3029                 //
3030                 // Update the metadata for the entry
3031                 //
3032
3033                 ntStatus = AFSUpdateMetaData( DirEntry,
3034                                               pDirEnumEntry);
3035
3036                 if( NT_SUCCESS( ntStatus))
3037                 {
3038
3039                     ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
3040                 }
3041
3042                 break;
3043             }
3044
3045             case AFS_FILE_TYPE_FILE:
3046             {
3047                 FILE_OBJECT * pCCFileObject = NULL;
3048
3049                 if ( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA))
3050                 {
3051
3052                     AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
3053                                   AFS_TRACE_LEVEL_VERBOSE,
3054                                   "AFSVerifyEntry Clearing VERIFY_DATA flag %wZ FID %08lX-%08lX-%08lX-%08lX\n",
3055                                   &DirEntry->NameInformation.FileName,
3056                                   pObjectInfo->FileId.Cell,
3057                                   pObjectInfo->FileId.Volume,
3058                                   pObjectInfo->FileId.Vnode,
3059                                   pObjectInfo->FileId.Unique));
3060
3061                     ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
3062                 }
3063
3064                 if( pObjectInfo->Fcb != NULL)
3065                 {
3066
3067                     AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
3068                                   AFS_TRACE_LEVEL_VERBOSE,
3069                                   "AFSVerifyEntry Flush/purge entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
3070                                   &DirEntry->NameInformation.FileName,
3071                                   pObjectInfo->FileId.Cell,
3072                                   pObjectInfo->FileId.Volume,
3073                                   pObjectInfo->FileId.Vnode,
3074                                   pObjectInfo->FileId.Unique));
3075
3076                     AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
3077                                   AFS_TRACE_LEVEL_VERBOSE,
3078                                   "AFSVerifyEntry Acquiring Fcb lock %p EXCL %08lX\n",
3079                                   &pObjectInfo->Fcb->NPFcb->Resource,
3080                                   PsGetCurrentThread()));
3081
3082                     AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->Resource,
3083                                     TRUE);
3084
3085                     AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
3086                                   AFS_TRACE_LEVEL_VERBOSE,
3087                                   "AFSVerifyEntry Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
3088                                   &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
3089                                   PsGetCurrentThread()));
3090
3091                     AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
3092                                     TRUE);
3093
3094                     __try
3095                     {
3096
3097                         CcFlushCache( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers,
3098                                       NULL,
3099                                       0,
3100                                       &stIoStatus);
3101
3102                         if( !NT_SUCCESS( stIoStatus.Status))
3103                         {
3104
3105                             AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
3106                                           AFS_TRACE_LEVEL_ERROR,
3107                                           "AFSVerifyEntry CcFlushCache failure %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
3108                                           &DirEntry->NameInformation.FileName,
3109                                           pObjectInfo->FileId.Cell,
3110                                           pObjectInfo->FileId.Volume,
3111                                           pObjectInfo->FileId.Vnode,
3112                                           pObjectInfo->FileId.Unique,
3113                                           stIoStatus.Status,
3114                                           stIoStatus.Information));
3115
3116                             ntStatus = stIoStatus.Status;
3117                         }
3118
3119                         if ( pObjectInfo->Fcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL)
3120                         {
3121
3122                             if ( !CcPurgeCacheSection( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers,
3123                                                        NULL,
3124                                                        0,
3125                                                        FALSE))
3126                             {
3127
3128                                 AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
3129                                               AFS_TRACE_LEVEL_WARNING,
3130                                               "AFSVerifyEntry CcPurgeCacheSection failure %wZ FID %08lX-%08lX-%08lX-%08lX\n",
3131                                               &DirEntry->NameInformation.FileName,
3132                                               pObjectInfo->FileId.Cell,
3133                                               pObjectInfo->FileId.Volume,
3134                                               pObjectInfo->FileId.Vnode,
3135                                               pObjectInfo->FileId.Unique));
3136
3137                                 SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
3138                             }
3139                         }
3140                     }
3141                     __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()))
3142                     {
3143                         ntStatus = GetExceptionCode();
3144
3145                         AFSDbgTrace(( 0,
3146                                       0,
3147                                       "EXCEPTION - AFSVerifyEntry CcFlushCache or CcPurgeCacheSection %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
3148                                       &DirEntry->NameInformation.FileName,
3149                                       pObjectInfo->FileId.Cell,
3150                                       pObjectInfo->FileId.Volume,
3151                                       pObjectInfo->FileId.Vnode,
3152                                       pObjectInfo->FileId.Unique,
3153                                       ntStatus));
3154
3155                         SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
3156                     }
3157
3158                     AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
3159                                   AFS_TRACE_LEVEL_VERBOSE,
3160                                   "AFSVerifyEntry Releasing Fcb SectionObject lock %p EXCL %08lX\n",
3161                                   &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
3162                                   PsGetCurrentThread()));
3163
3164                     AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
3165
3166                     if( !BooleanFlagOn( pRDRDevExt->DeviceFlags, AFS_DEVICE_FLAG_DIRECT_SERVICE_IO))
3167                     {
3168
3169                         AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
3170                                       AFS_TRACE_LEVEL_VERBOSE,
3171                                       "AFSVerifyEntry Releasing Fcb lock %p EXCL %08lX\n",
3172                                       &pObjectInfo->Fcb->NPFcb->Resource,
3173                                       PsGetCurrentThread()));
3174
3175                         AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Resource);
3176
3177                         AFSFlushExtents( pObjectInfo->Fcb,
3178                                          AuthGroup);
3179
3180                         //
3181                         // Acquire the Fcb to purge the cache
3182                         //
3183
3184                         AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
3185                                       AFS_TRACE_LEVEL_VERBOSE,
3186                                       "AFSVerifyEntry Acquiring Fcb lock %p EXCL %08lX\n",
3187                                       &pObjectInfo->Fcb->NPFcb->Resource,
3188                                       PsGetCurrentThread()));
3189
3190                         AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->Resource,
3191                                         TRUE);
3192                     }
3193
3194                     //
3195                     // Update the metadata for the entry
3196                     //
3197
3198                     ntStatus = AFSUpdateMetaData( DirEntry,
3199                                                   pDirEnumEntry);
3200
3201                     if( !NT_SUCCESS( ntStatus))
3202                     {
3203
3204                         AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
3205                                       AFS_TRACE_LEVEL_ERROR,
3206                                       "AFSVerifyEntry Meta Data Update failed %wZ FID %08lX-%08lX-%08lX-%08lX ntStatus %08lX\n",
3207                                       &DirEntry->NameInformation.FileName,
3208                                       pObjectInfo->FileId.Cell,
3209                                       pObjectInfo->FileId.Volume,
3210                                       pObjectInfo->FileId.Vnode,
3211                                       pObjectInfo->FileId.Unique,
3212                                       ntStatus));
3213                     }
3214                     else
3215                     {
3216
3217                         //
3218                         // Update file sizes
3219                         //
3220
3221                         pObjectInfo->Fcb->Header.AllocationSize.QuadPart  = pObjectInfo->AllocationSize.QuadPart;
3222                         pObjectInfo->Fcb->Header.FileSize.QuadPart        = pObjectInfo->EndOfFile.QuadPart;
3223                         pObjectInfo->Fcb->Header.ValidDataLength.QuadPart = pObjectInfo->EndOfFile.QuadPart;
3224
3225                         AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
3226                                       AFS_TRACE_LEVEL_VERBOSE,
3227                                       "AFSVerifyEntry Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
3228                                       &pObjectInfo->Fcb->NPFcb->SectionObjectResource,