af4576ba16d70b33a1bf6419c273ad349ad039a9
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSCleanup.cpp
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3  * Copyright (c) 2009, 2010, 2011 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,
14  *   this list of conditions and the following disclaimer in the
15  *   documentation
16  *   and/or other materials provided with the distribution.
17  * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18  *   nor the names of their contributors may be used to endorse or promote
19  *   products derived from this software without specific prior written
20  *   permission from Kernel Drivers, LLC and Your File System, Inc.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 //
36 // File: AFSCleanup.cpp
37 //
38
39 #include "AFSCommon.h"
40
41 //
42 // Function: AFSCleanup
43 //
44 // Description:
45 //
46 //      This function is the IRP_MJ_CLEANUP dispatch handler
47 //
48 // Return:
49 //
50 //       A status is returned for the handling of this request
51 //
52
53 NTSTATUS
54 AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
55             IN PIRP Irp)
56 {
57
58     NTSTATUS ntStatus = STATUS_SUCCESS;
59     AFSDeviceExt *pDeviceExt = NULL;
60     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
61     AFSFcb *pFcb = NULL;
62     AFSCcb *pCcb = NULL;
63     PFILE_OBJECT pFileObject = NULL;
64     AFSFcb *pRootFcb = NULL;
65     AFSDeviceExt *pControlDeviceExt = NULL;
66     IO_STATUS_BLOCK stIoSB;
67     AFSObjectInfoCB *pObjectInfo = NULL;
68     AFSFileCleanupCB stFileCleanup;
69     AFSFileCleanupResultCB *pResultCB = NULL;
70     ULONG ulResultLen = 0;
71     ULONG   ulNotificationFlags = 0;
72     LONG    lCount;
73
74     __try
75     {
76
77         if( AFSRDRDeviceObject == NULL)
78         {
79
80             //
81             // Let this through, it's a cleanup on the library control device
82             //
83
84             try_return( ntStatus);
85         }
86
87         pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
88         pControlDeviceExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
89
90         //
91         // Set some initial variables to make processing easier
92         //
93
94         pFileObject = pIrpSp->FileObject;
95
96         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
97
98         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
99
100         if( pFcb == NULL)
101         {
102             try_return( ntStatus);
103         }
104
105         pObjectInfo = pFcb->ObjectInformation;
106
107         pRootFcb = pObjectInfo->VolumeCB->RootFcb;
108
109         RtlZeroMemory( &stFileCleanup,
110                        sizeof( AFSFileCleanupCB));
111
112         stFileCleanup.ProcessId = (ULONGLONG)PsGetCurrentProcessId();
113
114         stFileCleanup.Identifier = (ULONGLONG)pFileObject;
115
116         //
117         // Allocate our return buffer
118         //
119
120         pResultCB = (AFSFileCleanupResultCB *)AFSExAllocatePoolWithTag( PagedPool,
121                                                                         PAGE_SIZE,
122                                                                         AFS_GENERIC_MEMORY_32_TAG);
123
124         if( pResultCB == NULL)
125         {
126
127             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
128         }
129
130         RtlZeroMemory( pResultCB,
131                        PAGE_SIZE);
132
133         ulResultLen = PAGE_SIZE;
134
135
136         //
137         // Perform the cleanup functionality depending on the type of node it is
138         //
139
140         switch( pFcb->Header.NodeTypeCode)
141         {
142
143             case AFS_ROOT_ALL:
144             {
145
146                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
147                               AFS_TRACE_LEVEL_VERBOSE,
148                               "AFSCleanup Acquiring GlobalRoot lock %08lX EXCL %08lX\n",
149                               &pFcb->NPFcb->Resource,
150                               PsGetCurrentThread());
151
152                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
153                                   TRUE);
154
155                 ASSERT( pFcb->OpenHandleCount != 0);
156
157                 AFSReleaseResource( &pFcb->NPFcb->Resource);
158
159                 lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
160
161                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
162                               AFS_TRACE_LEVEL_VERBOSE,
163                               "AFSCleanup (RootAll) Decrement handle count on Fcb %08lX Cnt %d\n",
164                               pFcb,
165                               lCount);
166
167                 FsRtlNotifyCleanup( pControlDeviceExt->Specific.Control.NotifySync,
168                                     &pControlDeviceExt->Specific.Control.DirNotifyList,
169                                     pCcb);
170
171                 break;
172             }
173
174             case AFS_IOCTL_FCB:
175             {
176
177                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
178                               AFS_TRACE_LEVEL_VERBOSE,
179                               "AFSCleanup Acquiring PIOCtl lock %08lX EXCL %08lX\n",
180                               &pFcb->NPFcb->Resource,
181                               PsGetCurrentThread());
182
183                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
184                                   TRUE);
185
186                 ASSERT( pFcb->OpenHandleCount != 0);
187
188                 //
189                 // Decrement the open child handle count
190                 //
191
192                 if( pObjectInfo->ParentObjectInformation != NULL &&
193                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0)
194                 {
195
196                     lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
197
198                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
199                                   AFS_TRACE_LEVEL_VERBOSE,
200                                   "AFSCleanup (IOCtl) Decrement child open handle count on Parent object %08lX Cnt %d\n",
201                                   pObjectInfo->ParentObjectInformation,
202                                   lCount);
203                 }
204
205                 AFSReleaseResource( &pFcb->NPFcb->Resource);
206
207                 lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
208
209                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
210                               AFS_TRACE_LEVEL_VERBOSE,
211                               "AFSCleanup (IOCtl) Decrement handle count on Fcb %08lX Cnt %d\n",
212                               pFcb,
213                               lCount);
214
215                 break;
216             }
217
218             //
219             // This Fcb represents a file
220             //
221
222             case AFS_FILE_FCB:
223             {
224
225                 //
226                 // We may be performing some cleanup on the Fcb so grab it exclusive to ensure no collisions
227                 //
228
229                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
230                               AFS_TRACE_LEVEL_VERBOSE,
231                               "AFSCleanup Acquiring Fcb lock %08lX EXCL %08lX\n",
232                               &pFcb->NPFcb->Resource,
233                               PsGetCurrentThread());
234
235                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
236                                 TRUE);
237
238                 //
239                 // If the handle has write permission ...
240                 //
241
242                 if( (pCcb->GrantedAccess & FILE_WRITE_DATA) &&
243                     CcIsFileCached( pIrpSp->FileObject))
244                 {
245
246                     __try
247                     {
248
249                         CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
250                                       NULL,
251                                       0,
252                                       &stIoSB);
253
254                         if( !NT_SUCCESS( stIoSB.Status))
255                         {
256
257                             AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
258                                           AFS_TRACE_LEVEL_ERROR,
259                                           "AFSCleanup CcFlushCache failure %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
260                                           &pCcb->FullFileName,
261                                           pObjectInfo->FileId.Cell,
262                                           pObjectInfo->FileId.Volume,
263                                           pObjectInfo->FileId.Vnode,
264                                           pObjectInfo->FileId.Unique,
265                                           stIoSB.Status,
266                                           stIoSB.Information);
267
268                             ntStatus = stIoSB.Status;
269                         }
270                     }
271                     __except( EXCEPTION_EXECUTE_HANDLER)
272                     {
273
274                         ntStatus = GetExceptionCode();
275                     }
276                 }
277
278                 //
279                 // Uninitialize the cache map. This call is unconditional.
280                 //
281
282                 AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
283                               AFS_TRACE_LEVEL_VERBOSE,
284                               "AFSCleanup Tearing down cache map for Fcb %08lX FileObject %08lX\n",
285                               pFcb,
286                               pFileObject);
287
288                 CcUninitializeCacheMap( pFileObject,
289                                         NULL,
290                                         NULL);
291
292                 //
293                 // Unlock all outstanding locks on the file, again, unconditionally
294                 //
295
296                 (VOID) FsRtlFastUnlockAll( &pFcb->Specific.File.FileLock,
297                                            pFileObject,
298                                            IoGetRequestorProcess( Irp),
299                                            NULL);
300
301                 //
302                 // Tell the service to unlock all on the file
303                 //
304
305                 ulNotificationFlags |= AFS_REQUEST_FLAG_BYTE_RANGE_UNLOCK_ALL;
306
307                 //
308                 // Perform some final common processing
309                 //
310
311                 ASSERT( pFcb->OpenHandleCount != 0);
312
313                 if( pFcb->ObjectInformation->ParentObjectInformation != NULL)
314                 {
315
316                     stFileCleanup.ParentId = pFcb->ObjectInformation->ParentObjectInformation->FileId;
317                 }
318
319                 stFileCleanup.LastAccessTime = pObjectInfo->LastAccessTime;
320
321                 if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED))
322                 {
323
324                     stFileCleanup.AllocationSize = pObjectInfo->EndOfFile;
325
326                     stFileCleanup.FileAttributes = pObjectInfo->FileAttributes;
327
328                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CREATE_TIME))
329                     {
330
331                         stFileCleanup.CreateTime = pObjectInfo->CreationTime;
332
333                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CREATE_TIME);
334                     }
335
336                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CHANGE_TIME))
337                     {
338
339                         stFileCleanup.ChangeTime = pObjectInfo->ChangeTime;
340
341                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CHANGE_TIME);
342                     }
343
344                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_ACCESS_TIME))
345                     {
346
347                         stFileCleanup.LastAccessTime = pObjectInfo->LastAccessTime;
348
349                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_ACCESS_TIME);
350                     }
351
352                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_LAST_WRITE_TIME))
353                     {
354
355                         stFileCleanup.LastWriteTime = pObjectInfo->LastWriteTime;
356
357                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_LAST_WRITE_TIME | AFS_FCB_FLAG_UPDATE_WRITE_TIME);
358                     }
359                 }
360
361                 if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_WRITE_TIME))
362                 {
363
364                     stFileCleanup.LastWriteTime = pObjectInfo->LastWriteTime;
365                 }
366
367                 //
368                 // If the count has dropped to one and there is a pending delete
369                 // then delete the node.  The final count will be decremented just
370                 // before the Fcb->NPFcb->Resource is released.
371                 //
372
373                 if( pFcb->OpenHandleCount == 1 &&
374                     BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE))
375                 {
376
377                     //
378                     // Stop anything possibly in process
379                     //
380
381                     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
382                                   AFS_TRACE_LEVEL_VERBOSE,
383                                   "AFSCleanup Acquiring Fcb extents lock %08lX EXCL %08lX\n",
384                                   &pFcb->NPFcb->Specific.File.ExtentsResource,
385                                   PsGetCurrentThread());
386
387                     AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource,
388                                     TRUE);
389
390                     pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsRequestStatus = STATUS_FILE_DELETED;
391
392                     KeSetEvent( &pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsRequestComplete,
393                                 0,
394                                 FALSE);
395
396                     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
397                                   AFS_TRACE_LEVEL_VERBOSE,
398                                   "AFSCleanup Releasing Fcb extents lock %08lX EXCL %08lX\n",
399                                   &pFcb->NPFcb->Specific.File.ExtentsResource,
400                                   PsGetCurrentThread());
401
402                     AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource);
403
404                     //
405                     // Before telling the server about the deleted file, tear down all extents for
406                     // the file
407                     //
408
409                     AFSTearDownFcbExtents( pFcb,
410                                            &pCcb->AuthGroup);
411
412                     ntStatus = STATUS_SUCCESS;
413
414                     ulNotificationFlags |= AFS_REQUEST_FLAG_FILE_DELETED;
415
416                     //
417                     // Indicate the file access mode that is being released
418                     //
419
420                     stFileCleanup.FileAccess = pCcb->FileAccess;
421
422                     //
423                     // Push the request to the service
424                     //
425
426                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
427                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
428                                                   &pCcb->AuthGroup,
429                                                   &pCcb->DirectoryCB->NameInformation.FileName,
430                                                   &pObjectInfo->FileId,
431                                                   &stFileCleanup,
432                                                   sizeof( AFSFileCleanupCB),
433                                                   pResultCB,
434                                                   &ulResultLen);
435
436                     if( !NT_SUCCESS( ntStatus) &&
437                         ntStatus != STATUS_OBJECT_NAME_NOT_FOUND)
438                     {
439
440                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
441                                       AFS_TRACE_LEVEL_ERROR,
442                                       "AFSCleanup Failed to notify service of deleted file %wZ Status %08lX\n",
443                                       &pCcb->FullFileName,
444                                       ntStatus);
445
446                         ntStatus = STATUS_SUCCESS;
447
448                         ClearFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
449                     }
450                     else
451                     {
452
453                         ntStatus = STATUS_SUCCESS;
454
455                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
456                                       AFS_TRACE_LEVEL_VERBOSE,
457                                       "AFSCleanup Setting DELETE flag in file %wZ Dir Entry %p\n",
458                                       &pCcb->FullFileName,
459                                       pCcb->DirectoryCB);
460
461                         SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_DELETED);
462
463                         ASSERT( pObjectInfo->ParentObjectInformation != NULL);
464
465                         AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
466                                         TRUE);
467
468                         if ( pObjectInfo->ParentObjectInformation->DataVersion.QuadPart != pResultCB->ParentDataVersion.QuadPart - 1)
469                         {
470
471                             SetFlag( pObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
472
473                             pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
474                         }
475                         else
476                         {
477
478                             pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = pResultCB->ParentDataVersion.QuadPart;
479                         }
480
481                         //
482                         // Now that the service has the entry has deleted we need to remove it from the parent
483                         // tree so another lookup on the node will fail
484                         //
485
486                         if( !BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE))
487                         {
488
489                             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
490                                           AFS_TRACE_LEVEL_VERBOSE,
491                                           "AFSCleanup DE %p for %wZ removing entry\n",
492                                           pCcb->DirectoryCB,
493                                           &pCcb->DirectoryCB->NameInformation.FileName);
494
495                             AFSRemoveNameEntry( pObjectInfo->ParentObjectInformation,
496                                                 pCcb->DirectoryCB);
497                         }
498                         else
499                         {
500
501                             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
502                                           AFS_TRACE_LEVEL_VERBOSE,
503                                           "AFSCleanup DE %p for %wZ NOT removing entry due to flag set\n",
504                                           pCcb->DirectoryCB,
505                                           &pCcb->DirectoryCB->NameInformation.FileName);
506                         }
507
508                         AFSReleaseResource( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
509
510                         AFSFsRtlNotifyFullReportChange( pObjectInfo->ParentObjectInformation,
511                                                         pCcb,
512                                                         (ULONG)FILE_NOTIFY_CHANGE_FILE_NAME,
513                                                         (ULONG)FILE_ACTION_REMOVED);
514
515                     }
516                 }
517                 else
518                 {
519
520                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED))
521                     {
522
523                         ULONG ulNotifyFilter = 0;
524
525                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED);
526
527                         ulNotifyFilter |= (FILE_NOTIFY_CHANGE_ATTRIBUTES);
528
529                         AFSFsRtlNotifyFullReportChange( pObjectInfo->ParentObjectInformation,
530                                                         pCcb,
531                                                         (ULONG)ulNotifyFilter,
532                                                         (ULONG)FILE_ACTION_MODIFIED);
533                     }
534
535                     //
536                     // Attempt to flush any dirty extents to the server. This may be a little
537                     // aggressive, to flush whenever the handle is closed, but it ensures
538                     // coherency.
539                     //
540
541                     if( (pCcb->GrantedAccess & FILE_WRITE_DATA) &&
542                         pFcb->Specific.File.ExtentsDirtyCount != 0)
543                     {
544
545                         AFSFlushExtents( pFcb,
546                                          &pCcb->AuthGroup);
547                     }
548
549                     if( pFcb->OpenHandleCount == 1)
550                     {
551
552                         //
553                         // Wait for any outstanding queued flushes to complete
554                         //
555
556                         AFSWaitOnQueuedFlushes( pFcb);
557
558                         ulNotificationFlags |= AFS_REQUEST_FLAG_FLUSH_FILE;
559                     }
560
561                     //
562                     // Indicate the file access mode that is being released
563                     //
564
565                     stFileCleanup.FileAccess = pCcb->FileAccess;
566
567                     //
568                     // Push the request to the service
569                     //
570
571                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
572                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
573                                                   &pCcb->AuthGroup,
574                                                   &pCcb->DirectoryCB->NameInformation.FileName,
575                                                   &pObjectInfo->FileId,
576                                                   &stFileCleanup,
577                                                   sizeof( AFSFileCleanupCB),
578                                                   pResultCB,
579                                                   &ulResultLen);
580
581                     if ( NT_SUCCESS( ntStatus))
582                     {
583
584                         if ( pObjectInfo->ParentObjectInformation != NULL)
585                         {
586
587                             AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
588                                             TRUE);
589
590                             if ( pObjectInfo->ParentObjectInformation->DataVersion.QuadPart != pResultCB->ParentDataVersion.QuadPart)
591                             {
592
593                                 SetFlag( pObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
594
595                                 pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
596                             }
597
598                             AFSReleaseResource( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
599                         }
600                     }
601
602                     ntStatus = STATUS_SUCCESS;
603                 }
604
605                 //
606                 // Remove the share access at this time since we may not get the close for sometime on this FO.
607                 //
608
609                 IoRemoveShareAccess( pFileObject,
610                                      &pFcb->ShareAccess);
611
612                 //
613                 // We don't need the name array after the user closes the handle on the file
614                 //
615
616                 if( pCcb->NameArray != NULL)
617                 {
618
619                     AFSFreeNameArray( pCcb->NameArray);
620
621                     pCcb->NameArray = NULL;
622                 }
623
624                 //
625                 // Decrement the open child handle count
626                 //
627
628                 if( pObjectInfo->ParentObjectInformation != NULL)
629                 {
630
631                     ASSERT( pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0);
632
633                     lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
634
635                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
636                                   AFS_TRACE_LEVEL_VERBOSE,
637                                   "AFSCleanup (File) Decrement child open handle count on Parent object %08lX Cnt %d\n",
638                                   pObjectInfo->ParentObjectInformation,
639                                   lCount);
640                 }
641
642                 AFSReleaseResource( &pFcb->NPFcb->Resource);
643
644                 if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE))
645                 {
646                     InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
647                     ClearFlag( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
648
649                     AFSPerformObjectInvalidate( pObjectInfo,
650                                                 AFS_INVALIDATE_DATA_VERSION);
651                 }
652
653                 lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
654
655                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
656                               AFS_TRACE_LEVEL_VERBOSE,
657                               "AFSCleanup (File) Decrement handle count on Fcb %08lX Cnt %d\n",
658                               pFcb,
659                               lCount);
660
661                 break;
662             }
663
664             //
665             // Root or directory node
666             //
667
668             case AFS_ROOT_FCB:
669             {
670
671                 //
672                 // Set the root Fcb to this node
673                 //
674
675                 pRootFcb = pFcb;
676
677                 //
678                 // Fall through to below
679                 //
680             }
681
682             case AFS_DIRECTORY_FCB:
683             {
684
685                 //
686                 // We may be performing some cleanup on the Fcb so grab it exclusive to ensure no collisions
687                 //
688
689                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
690                               AFS_TRACE_LEVEL_VERBOSE,
691                               "AFSCleanup Acquiring Dcb lock %08lX EXCL %08lX\n",
692                               &pFcb->NPFcb->Resource,
693                               PsGetCurrentThread());
694
695                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
696                                   TRUE);
697
698                 //
699                 // Perform some final common processing
700                 //
701
702                 ASSERT( pFcb->OpenHandleCount != 0);
703
704                 if( pFcb->ObjectInformation->ParentObjectInformation != NULL)
705                 {
706
707                     stFileCleanup.ParentId = pFcb->ObjectInformation->ParentObjectInformation->FileId;
708                 }
709
710                 stFileCleanup.LastAccessTime = pObjectInfo->LastAccessTime;
711
712                 if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED))
713                 {
714
715                     stFileCleanup.FileAttributes = pObjectInfo->FileAttributes;
716
717                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CREATE_TIME))
718                     {
719
720                         stFileCleanup.CreateTime = pObjectInfo->CreationTime;
721
722                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CREATE_TIME);
723                     }
724
725                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CHANGE_TIME))
726                     {
727
728                         stFileCleanup.ChangeTime = pObjectInfo->ChangeTime;
729
730                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CHANGE_TIME);
731                     }
732
733                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_ACCESS_TIME))
734                     {
735
736                         stFileCleanup.LastAccessTime = pObjectInfo->LastAccessTime;
737
738                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_ACCESS_TIME);
739                     }
740                 }
741
742                 //
743                 // If the count has dropped to one and there is a pending delete
744                 // then delete the node.  The final count will be decremented just
745                 // before the Fcb->NPFcb->Resource is released.
746                 //
747
748                 if( pFcb->OpenHandleCount == 1 &&
749                     BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE))
750                 {
751
752                     //
753                     // Try to notify the service about the delete
754                     //
755
756                     ulNotificationFlags |= AFS_REQUEST_FLAG_FILE_DELETED;
757
758                     //
759                     // Indicate the file access mode that is being released
760                     //
761
762                     stFileCleanup.FileAccess = pCcb->FileAccess;
763
764                     //
765                     // Push the request to the service
766                     //
767
768                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
769                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
770                                                   &pCcb->AuthGroup,
771                                                   &pCcb->DirectoryCB->NameInformation.FileName,
772                                                   &pObjectInfo->FileId,
773                                                   &stFileCleanup,
774                                                   sizeof( AFSFileCleanupCB),
775                                                   pResultCB,
776                                                   &ulResultLen);
777
778                     if( !NT_SUCCESS( ntStatus) &&
779                         ntStatus != STATUS_OBJECT_NAME_NOT_FOUND)
780                     {
781
782                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
783                                       AFS_TRACE_LEVEL_ERROR,
784                                       "AFSCleanup Failed to notify service of deleted directory %wZ Status %08lX\n",
785                                       &pCcb->FullFileName,
786                                       ntStatus);
787
788                         ntStatus = STATUS_SUCCESS;
789
790                         ClearFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
791                     }
792                     else
793                     {
794
795                         ntStatus = STATUS_SUCCESS;
796
797                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
798                                       AFS_TRACE_LEVEL_VERBOSE,
799                                       "AFSCleanup Setting DELETE flag in directory %wZ Dir Entry %p\n",
800                                       &pCcb->FullFileName,
801                                       pCcb->DirectoryCB);
802
803                         SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_DELETED);
804
805                         ASSERT( pObjectInfo->ParentObjectInformation != NULL);
806
807                         AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
808                                         TRUE);
809
810                         if ( pObjectInfo->ParentObjectInformation->DataVersion.QuadPart != pResultCB->ParentDataVersion.QuadPart - 1)
811                         {
812
813                             SetFlag( pObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
814
815                             pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
816                         }
817                         else
818                         {
819
820                             pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = pResultCB->ParentDataVersion.QuadPart;
821                         }
822
823                         //
824                         // Now that the service has the entry has deleted we need to remove it from the parent
825                         // tree so another lookup on the node will fail
826                         //
827
828                         if( !BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE))
829                         {
830
831                             AFSRemoveNameEntry( pObjectInfo->ParentObjectInformation,
832                                                 pCcb->DirectoryCB);
833                         }
834                         else
835                         {
836
837                             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
838                                           AFS_TRACE_LEVEL_VERBOSE,
839                                           "AFSCleanup DE %p for %wZ NOT removing entry due to flag set\n",
840                                           pCcb->DirectoryCB,
841                                           &pCcb->DirectoryCB->NameInformation.FileName);
842                         }
843
844                         AFSReleaseResource( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
845
846                         AFSFsRtlNotifyFullReportChange( pObjectInfo->ParentObjectInformation,
847                                                         pCcb,
848                                                         (ULONG)FILE_NOTIFY_CHANGE_FILE_NAME,
849                                                         (ULONG)FILE_ACTION_REMOVED);
850
851                     }
852                 }
853
854                 //
855                 // If there have been any updates to the node then push it to
856                 // the service
857                 //
858
859                 else
860                 {
861
862                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED))
863                     {
864
865                         ULONG ulNotifyFilter = 0;
866
867                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED);
868
869                         if(  pObjectInfo->ParentObjectInformation != NULL)
870                         {
871
872                             ulNotifyFilter |= (FILE_NOTIFY_CHANGE_ATTRIBUTES);
873
874                             AFSFsRtlNotifyFullReportChange( pObjectInfo->ParentObjectInformation,
875                                                             pCcb,
876                                                             (ULONG)ulNotifyFilter,
877                                                             (ULONG)FILE_ACTION_MODIFIED);
878                         }
879                     }
880
881                     //
882                     // Indicate the file access mode that is being released
883                     //
884
885                     stFileCleanup.FileAccess = pCcb->FileAccess;
886
887                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
888                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
889                                                   &pCcb->AuthGroup,
890                                                   &pCcb->DirectoryCB->NameInformation.FileName,
891                                                   &pObjectInfo->FileId,
892                                                   &stFileCleanup,
893                                                   sizeof( AFSFileCleanupCB),
894                                                   pResultCB,
895                                                   &ulResultLen);
896
897                     if ( NT_SUCCESS( ntStatus))
898                     {
899
900                         if ( pObjectInfo->ParentObjectInformation != NULL)
901                         {
902
903                             AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
904                                               TRUE);
905
906                             if ( pObjectInfo->ParentObjectInformation->DataVersion.QuadPart != pResultCB->ParentDataVersion.QuadPart)
907                             {
908
909                                 SetFlag( pObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
910
911                                 pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
912                             }
913
914                             AFSReleaseResource( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
915                         }
916                     }
917
918                     ntStatus = STATUS_SUCCESS;
919                 }
920
921                 //
922                 // Release the notification for this directory if there is one
923                 //
924
925                 FsRtlNotifyCleanup( pControlDeviceExt->Specific.Control.NotifySync,
926                                     &pControlDeviceExt->Specific.Control.DirNotifyList,
927                                     pCcb);
928
929                 //
930                 // Remove the share access at this time since we may not get the close for sometime on this FO.
931                 //
932
933                 IoRemoveShareAccess( pFileObject,
934                                      &pFcb->ShareAccess);
935
936                 //
937                 // We don't need the name array after the user closes the handle on the file
938                 //
939
940                 if( pCcb->NameArray != NULL)
941                 {
942
943                     AFSFreeNameArray( pCcb->NameArray);
944
945                     pCcb->NameArray = NULL;
946                 }
947
948                 //
949                 // Decrement the open child handle count
950                 //
951
952                 if( pObjectInfo->ParentObjectInformation != NULL)
953                 {
954
955                     ASSERT( pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0);
956
957                     lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
958
959                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
960                                   AFS_TRACE_LEVEL_VERBOSE,
961                                   "AFSCleanup (Dir) Decrement child open handle count on Parent object %08lX Cnt %d\n",
962                                   pObjectInfo->ParentObjectInformation,
963                                   lCount);
964                 }
965
966                 AFSReleaseResource( &pFcb->NPFcb->Resource);
967
968                 lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
969
970                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
971                               AFS_TRACE_LEVEL_VERBOSE,
972                               "AFSCleanup (Dir) Decrement handle count on Fcb %08lX Cnt %d\n",
973                               pFcb,
974                               lCount);
975
976                 break;
977             }
978
979             case AFS_SYMBOLIC_LINK_FCB:
980             case AFS_MOUNT_POINT_FCB:
981             case AFS_DFS_LINK_FCB:
982             case AFS_INVALID_FCB:
983             {
984
985                 //
986                 // We may be performing some cleanup on the Fcb so grab it exclusive to ensure no collisions
987                 //
988
989                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
990                               AFS_TRACE_LEVEL_VERBOSE,
991                               "AFSCleanup (MP/SL) Acquiring Dcb lock %08lX EXCL %08lX\n",
992                               &pFcb->NPFcb->Resource,
993                               PsGetCurrentThread());
994
995                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
996                                   TRUE);
997
998                 //
999                 // Perform some final common processing
1000                 //
1001
1002                 ASSERT( pFcb->OpenHandleCount != 0);
1003
1004                 if( pFcb->ObjectInformation->ParentObjectInformation != NULL)
1005                 {
1006
1007                     stFileCleanup.ParentId = pFcb->ObjectInformation->ParentObjectInformation->FileId;
1008                 }
1009
1010                 stFileCleanup.LastAccessTime = pObjectInfo->LastAccessTime;
1011
1012                 if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED))
1013                 {
1014
1015                     stFileCleanup.FileAttributes = pObjectInfo->FileAttributes;
1016
1017                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CREATE_TIME))
1018                     {
1019
1020                         stFileCleanup.CreateTime = pObjectInfo->CreationTime;
1021
1022                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CREATE_TIME);
1023                     }
1024
1025                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CHANGE_TIME))
1026                     {
1027
1028                         stFileCleanup.ChangeTime = pObjectInfo->ChangeTime;
1029
1030                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_CHANGE_TIME);
1031                     }
1032
1033                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_UPDATE_ACCESS_TIME))
1034                     {
1035
1036                         stFileCleanup.LastAccessTime = pObjectInfo->LastAccessTime;
1037
1038                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_UPDATE_ACCESS_TIME);
1039                     }
1040                 }
1041
1042                 //
1043                 // If the count has dropped to one and there is a pending delete
1044                 // then delete the node.  The final count will be decremented just
1045                 // before the Fcb->NPFcb->Resource is released.
1046                 //
1047
1048                 if( pFcb->OpenHandleCount == 1 &&
1049                     BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE))
1050                 {
1051
1052                     //
1053                     // Try to notify the service about the delete
1054                     //
1055
1056                     ulNotificationFlags |= AFS_REQUEST_FLAG_FILE_DELETED;
1057
1058                     //
1059                     // Indicate the file access mode that is being released
1060                     //
1061
1062                     stFileCleanup.FileAccess = pCcb->FileAccess;
1063
1064                     //
1065                     // Push the request to the service
1066                     //
1067
1068                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
1069                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
1070                                                   &pCcb->AuthGroup,
1071                                                   &pCcb->DirectoryCB->NameInformation.FileName,
1072                                                   &pObjectInfo->FileId,
1073                                                   &stFileCleanup,
1074                                                   sizeof( AFSFileCleanupCB),
1075                                                   pResultCB,
1076                                                   &ulResultLen);
1077
1078                     if( !NT_SUCCESS( ntStatus) &&
1079                         ntStatus != STATUS_OBJECT_NAME_NOT_FOUND)
1080                     {
1081
1082                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1083                                       AFS_TRACE_LEVEL_ERROR,
1084                                       "AFSCleanup Failed to notify service of deleted MP/SL %wZ Status %08lX\n",
1085                                       &pCcb->FullFileName,
1086                                       ntStatus);
1087
1088                         ntStatus = STATUS_SUCCESS;
1089
1090                         ClearFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
1091                     }
1092                     else
1093                     {
1094
1095                         ntStatus = STATUS_SUCCESS;
1096
1097                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1098                                       AFS_TRACE_LEVEL_VERBOSE,
1099                                       "AFSCleanup Setting DELETE flag in MP/SL %wZ Dir Entry %p\n",
1100                                       &pCcb->FullFileName,
1101                                       pCcb->DirectoryCB);
1102
1103                         SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_DELETED);
1104
1105                         ASSERT( pObjectInfo->ParentObjectInformation != NULL);
1106
1107                         AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
1108                                         TRUE);
1109
1110                         if ( pObjectInfo->ParentObjectInformation->DataVersion.QuadPart != pResultCB->ParentDataVersion.QuadPart - 1)
1111                         {
1112
1113                             SetFlag( pObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
1114
1115                             pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
1116                         }
1117                         else
1118                         {
1119                             pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = pResultCB->ParentDataVersion.QuadPart;
1120                         }
1121
1122                         //
1123                         // Now that the service has the entry has deleted we need to remove it from the parent
1124                         // tree so another lookup on the node will fail
1125                         //
1126
1127                         if( !BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_NOT_IN_PARENT_TREE))
1128                         {
1129
1130                             AFSRemoveNameEntry( pObjectInfo->ParentObjectInformation,
1131                                                 pCcb->DirectoryCB);
1132                         }
1133                         else
1134                         {
1135
1136                             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1137                                           AFS_TRACE_LEVEL_VERBOSE,
1138                                           "AFSCleanup DE %p for %wZ NOT removing entry due to flag set\n",
1139                                           pCcb->DirectoryCB,
1140                                           &pCcb->DirectoryCB->NameInformation.FileName);
1141                         }
1142
1143                         AFSReleaseResource( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1144
1145                         AFSFsRtlNotifyFullReportChange( pObjectInfo->ParentObjectInformation,
1146                                                         pCcb,
1147                                                         (ULONG)FILE_NOTIFY_CHANGE_FILE_NAME,
1148                                                         (ULONG)FILE_ACTION_REMOVED);
1149
1150                     }
1151                 }
1152
1153                 //
1154                 // If there have been any updates to the node then push it to
1155                 // the service
1156                 //
1157
1158                 else
1159                 {
1160
1161                     if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED))
1162                     {
1163
1164                         ULONG ulNotifyFilter = 0;
1165
1166                         ClearFlag( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED);
1167
1168                         if(  pObjectInfo->ParentObjectInformation != NULL)
1169                         {
1170
1171                             ulNotifyFilter |= (FILE_NOTIFY_CHANGE_ATTRIBUTES);
1172
1173                             AFSFsRtlNotifyFullReportChange( pObjectInfo->ParentObjectInformation,
1174                                                             pCcb,
1175                                                             (ULONG)ulNotifyFilter,
1176                                                             (ULONG)FILE_ACTION_MODIFIED);
1177                         }
1178                     }
1179
1180                     //
1181                     // Indicate the file access mode that is being released
1182                     //
1183
1184                     stFileCleanup.FileAccess = pCcb->FileAccess;
1185
1186                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
1187                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
1188                                                   &pCcb->AuthGroup,
1189                                                   &pCcb->DirectoryCB->NameInformation.FileName,
1190                                                   &pObjectInfo->FileId,
1191                                                   &stFileCleanup,
1192                                                   sizeof( AFSFileCleanupCB),
1193                                                   pResultCB,
1194                                                   &ulResultLen);
1195
1196                     if ( NT_SUCCESS( ntStatus))
1197                     {
1198
1199                         if ( pObjectInfo->ParentObjectInformation != NULL)
1200                         {
1201
1202                             AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
1203                                               TRUE);
1204
1205                             if ( pObjectInfo->ParentObjectInformation->DataVersion.QuadPart != pResultCB->ParentDataVersion.QuadPart)
1206                             {
1207
1208                                 SetFlag( pObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
1209
1210                                 pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
1211                             }
1212
1213                             AFSReleaseResource( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1214                         }
1215                     }
1216
1217                     ntStatus = STATUS_SUCCESS;
1218                 }
1219
1220                 //
1221                 // Remove the share access at this time since we may not get the close for sometime on this FO.
1222                 //
1223
1224                 IoRemoveShareAccess( pFileObject,
1225                                      &pFcb->ShareAccess);
1226
1227                 //
1228                 // We don't need the name array after the user closes the handle on the file
1229                 //
1230
1231                 if( pCcb->NameArray != NULL)
1232                 {
1233
1234                     AFSFreeNameArray( pCcb->NameArray);
1235
1236                     pCcb->NameArray = NULL;
1237                 }
1238
1239                 //
1240                 // Decrement the open child handle count
1241                 //
1242
1243                 if( pObjectInfo->ParentObjectInformation != NULL)
1244                 {
1245
1246                     ASSERT( pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0);
1247
1248                     lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
1249
1250                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
1251                                   AFS_TRACE_LEVEL_VERBOSE,
1252                                   "AFSCleanup (MP/SL) Decrement child open handle count on Parent object %08lX Cnt %d\n",
1253                                   pObjectInfo->ParentObjectInformation,
1254                                   lCount);
1255                 }
1256
1257                 AFSReleaseResource( &pFcb->NPFcb->Resource);
1258
1259                 lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
1260
1261                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
1262                               AFS_TRACE_LEVEL_VERBOSE,
1263                               "AFSCleanup (MP/SL) Decrement handle count on Fcb %08lX Cnt %d\n",
1264                               pFcb,
1265                               lCount);
1266
1267                 break;
1268             }
1269
1270             case AFS_SPECIAL_SHARE_FCB:
1271             {
1272
1273                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1274                               AFS_TRACE_LEVEL_VERBOSE,
1275                               "AFSCleanup Acquiring SPECIAL SHARE lock %08lX EXCL %08lX\n",
1276                               &pFcb->NPFcb->Resource,
1277                               PsGetCurrentThread());
1278
1279                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
1280                                 TRUE);
1281
1282                 ASSERT( pFcb->OpenHandleCount != 0);
1283
1284                 //
1285                 // Decrement the open child handle count
1286                 //
1287
1288                 if( pObjectInfo->ParentObjectInformation != NULL &&
1289                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0)
1290                 {
1291
1292                     lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
1293
1294                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
1295                                   AFS_TRACE_LEVEL_VERBOSE,
1296                                   "AFSCleanup (Share) Decrement child open handle count on Parent object %08lX Cnt %d\n",
1297                                   pObjectInfo->ParentObjectInformation,
1298                                   lCount);
1299                 }
1300
1301                 AFSReleaseResource( &pFcb->NPFcb->Resource);
1302
1303                 lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
1304
1305                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
1306                               AFS_TRACE_LEVEL_VERBOSE,
1307                               "AFSCleanup (Share) Decrement handle count on Fcb %08lX Cnt %d\n",
1308                               pFcb,
1309                               lCount);
1310
1311                 break;
1312             }
1313
1314             default:
1315
1316                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1317                               AFS_TRACE_LEVEL_WARNING,
1318                               "AFSCleanup Processing unknown node type %d\n",
1319                               pFcb->Header.NodeTypeCode);
1320
1321                 break;
1322         }
1323
1324
1325 try_exit:
1326
1327         if( pResultCB != NULL)
1328         {
1329
1330             AFSExFreePool( pResultCB);
1331         }
1332
1333         if( pFileObject != NULL)
1334         {
1335
1336             //
1337             // Setup the fileobject flags to indicate cleanup is complete.
1338             //
1339
1340             SetFlag( pFileObject->Flags, FO_CLEANUP_COMPLETE);
1341         }
1342
1343         //
1344         // Complete the request
1345         //
1346
1347         AFSCompleteRequest( Irp, ntStatus);
1348     }
1349     __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
1350     {
1351
1352         AFSDbgLogMsg( 0,
1353                       0,
1354                       "EXCEPTION - AFSCleanup\n");
1355     }
1356
1357     return ntStatus;
1358 }