Windows: afsredirlib log messages
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSClose.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: AFSClose.cpp
37 //
38
39 #include "AFSCommon.h"
40
41 //
42 // Function: AFSClose
43 //
44 // Description:
45 //
46 //      This function is the IRP_MJ_CLOSE dispatch handler
47 //
48 // Return:
49 //
50 //       A status is returned for the handling of this request
51 //
52
53 NTSTATUS
54 AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
55           IN PIRP Irp)
56 {
57
58     NTSTATUS ntStatus = STATUS_SUCCESS;
59     ULONG ulRequestType = 0;
60     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
61     AFSFcb *pFcb = NULL;
62     AFSDeviceExt *pDeviceExt = NULL;
63     AFSCcb *pCcb = NULL;
64     AFSObjectInfoCB *pObjectInfo = NULL;
65     AFSDirectoryCB *pDirCB = NULL;
66
67     __try
68     {
69
70         if( AFSRDRDeviceObject == NULL)
71         {
72
73             //
74             // Let this through, it's an close on the library control device
75             //
76
77             try_return( ntStatus);
78         }
79
80         pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
81
82         pIrpSp = IoGetCurrentIrpStackLocation( Irp);
83
84         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
85
86         if( pFcb == NULL)
87         {
88             try_return( ntStatus);
89         }
90
91         pObjectInfo = pFcb->ObjectInformation;
92
93         //
94         // Perform the close functionality depending on the type of node it is
95         //
96
97         switch( pFcb->Header.NodeTypeCode)
98         {
99
100             case AFS_IOCTL_FCB:
101             {
102
103                 AFSPIOCtlOpenCloseRequestCB stPIOCtlClose;
104                 AFSFileID stParentFileId;
105
106                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
107                               AFS_TRACE_LEVEL_VERBOSE,
108                               "AFSClose Acquiring GlobalRoot lock %08lX EXCL %08lX\n",
109                               &pFcb->NPFcb->Resource,
110                               PsGetCurrentThread());
111
112                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
113                                   TRUE);
114
115                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
116
117                 //
118                 // Send the close to the CM
119                 //
120
121                 RtlZeroMemory( &stPIOCtlClose,
122                                sizeof( AFSPIOCtlOpenCloseRequestCB));
123
124                 stPIOCtlClose.RequestId = pCcb->RequestID;
125
126                 stPIOCtlClose.RootId = pObjectInfo->VolumeCB->ObjectInformation.FileId;
127
128                 RtlZeroMemory( &stParentFileId,
129                                sizeof( AFSFileID));
130
131                 stParentFileId = pObjectInfo->ParentObjectInformation->FileId;
132
133                 //
134                 // Issue the close request to the service
135                 //
136
137                 AFSProcessRequest( AFS_REQUEST_TYPE_PIOCTL_CLOSE,
138                                    AFS_REQUEST_FLAG_SYNCHRONOUS,
139                                    &pCcb->AuthGroup,
140                                    NULL,
141                                    &stParentFileId,
142                                    (void *)&stPIOCtlClose,
143                                    sizeof( AFSPIOCtlOpenCloseRequestCB),
144                                    NULL,
145                                    NULL);
146
147                 pDirCB = pCcb->DirectoryCB;
148
149                 //
150                 // Remove the Ccb and de-allocate it
151                 //
152
153                 ntStatus = AFSRemoveCcb( pFcb,
154                                          pCcb);
155
156                 if( !NT_SUCCESS( ntStatus))
157                 {
158
159                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
160                                   AFS_TRACE_LEVEL_WARNING,
161                                   "AFSClose Failed to remove Ccb from Fcb Status %08lX\n", ntStatus);
162
163                     //
164                     // We can't actually fail a close operation so reset the status
165                     //
166
167                     ntStatus = STATUS_SUCCESS;
168                 }
169
170                 ASSERT( pDirCB->OpenReferenceCount > 0);
171
172                 InterlockedDecrement( &pDirCB->OpenReferenceCount);
173
174                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
175                               AFS_TRACE_LEVEL_VERBOSE,
176                               "AFSClose (IOCtl) Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
177                               &pDirCB->NameInformation.FileName,
178                               pDirCB,
179                               pCcb,
180                               pDirCB->OpenReferenceCount);
181
182                 //
183                 // If this is not the root then decrement the open child reference count
184                 //
185
186                 if( pObjectInfo->ParentObjectInformation != NULL &&
187                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount > 0)
188                 {
189
190                     InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
191
192                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
193                                   AFS_TRACE_LEVEL_VERBOSE,
194                                   "AFSClose (IOCtl) Decrement child open ref count on Parent object %08lX Cnt %d\n",
195                                   pObjectInfo->ParentObjectInformation,
196                                   pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
197                 }
198
199                 AFSReleaseResource( &pFcb->NPFcb->Resource);
200
201                 ASSERT( pFcb->OpenReferenceCount != 0);
202
203                 InterlockedDecrement( &pFcb->OpenReferenceCount);
204
205                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
206                               AFS_TRACE_LEVEL_VERBOSE,
207                               "AFSClose (IOCtl) Decrement count on Fcb %08lX Cnt %d\n",
208                               pFcb,
209                               pFcb->OpenReferenceCount);
210
211                 break;
212             }
213
214             case AFS_ROOT_ALL:
215             {
216
217                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
218                               AFS_TRACE_LEVEL_VERBOSE,
219                               "AFSClose Acquiring Special Root ALL lock %08lX EXCL %08lX\n",
220                               &pFcb->NPFcb->Resource,
221                               PsGetCurrentThread());
222
223                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
224                                 TRUE);
225
226                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
227
228                 pDirCB = pCcb->DirectoryCB;
229
230                 //
231                 // Remove the Ccb and de-allocate it
232                 //
233
234                 ntStatus = AFSRemoveCcb( pFcb,
235                                          pCcb);
236
237                 if( !NT_SUCCESS( ntStatus))
238                 {
239
240                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
241                                   AFS_TRACE_LEVEL_WARNING,
242                                   "AFSClose Failed to remove Ccb from Fcb Status %08lX\n", ntStatus);
243
244                     //
245                     // We can't actually fail a close operation so reset the status
246                     //
247
248                     ntStatus = STATUS_SUCCESS;
249                 }
250
251                 ASSERT( pDirCB->OpenReferenceCount > 0);
252
253                 InterlockedDecrement( &pDirCB->OpenReferenceCount);
254
255                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
256                               AFS_TRACE_LEVEL_VERBOSE,
257                               "AFSClose Decrement (Root ALL) count on %wZ DE %p Ccb %p Cnt %d\n",
258                               &pDirCB->NameInformation.FileName,
259                               pDirCB,
260                               pCcb,
261                               pDirCB->OpenReferenceCount);
262
263                 AFSReleaseResource( &pFcb->NPFcb->Resource);
264
265                 ASSERT( pFcb->OpenReferenceCount > 0);
266
267                 InterlockedDecrement( &pFcb->OpenReferenceCount);
268
269                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
270                               AFS_TRACE_LEVEL_VERBOSE,
271                               "AFSClose (RootAll) Decrement count on Fcb %08lX Cnt %d\n",
272                               pFcb,
273                               pFcb->OpenReferenceCount);
274
275                 break;
276             }
277
278             //
279             // Root, file or directory node
280             //
281
282             case AFS_FILE_FCB:
283             case AFS_ROOT_FCB:
284             case AFS_DIRECTORY_FCB:
285             case AFS_SYMBOLIC_LINK_FCB:
286             case AFS_MOUNT_POINT_FCB:
287             case AFS_DFS_LINK_FCB:
288             {
289
290                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
291
292                 //
293                 // We may be performing some cleanup on the Fcb so grab it exclusive to ensure no collisions
294                 //
295
296                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
297                               AFS_TRACE_LEVEL_VERBOSE,
298                               "AFSClose Acquiring Dcb lock %08lX EXCL %08lX\n",
299                               &pFcb->NPFcb->Resource,
300                               PsGetCurrentThread());
301
302                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
303                                 TRUE);
304
305                 KeQueryTickCount( &pFcb->ObjectInformation->LastAccessCount);
306
307                 pDirCB = pCcb->DirectoryCB;
308
309                 //
310                 // If this entry is deleted then remove the object from the volume tree
311                 //
312
313                 if( BooleanFlagOn( pDirCB->Flags, AFS_DIR_ENTRY_DELETED))
314                 {
315
316                     if( pFcb->Header.NodeTypeCode == AFS_FILE_FCB)
317                     {
318
319                         //
320                         // Stop anything possibly in process
321                         //
322
323                         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
324                                       AFS_TRACE_LEVEL_VERBOSE,
325                                       "AFSClose Acquiring Fcb extents lock %08lX EXCL %08lX\n",
326                                       &pFcb->NPFcb->Specific.File.ExtentsResource,
327                                       PsGetCurrentThread());
328
329                         AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource,
330                                         TRUE);
331
332                         pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsRequestStatus = STATUS_FILE_DELETED;
333
334                         KeSetEvent( &pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsRequestComplete,
335                                     0,
336                                     FALSE);
337
338                         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
339                                       AFS_TRACE_LEVEL_VERBOSE,
340                                       "AFSClose Releasing Fcb extents lock %08lX EXCL %08lX\n",
341                                       &pFcb->NPFcb->Specific.File.ExtentsResource,
342                                       PsGetCurrentThread());
343
344                         AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource);
345                     }
346
347                     AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
348                                     TRUE);
349
350                     AFSAcquireExcl( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock,
351                                     TRUE);
352
353                     if ( pDirCB->OpenReferenceCount == 0)
354                     {
355                         AFSDbgLogMsg( 0,
356                                       0,
357                                       "AFSClose (Other) OpenReferenceCount is Zero on DE %08lX Ccb %08lX FileName %wZ\n",
358                                       pDirCB,
359                                       pCcb,
360                                       &pDirCB->NameInformation.FileName);
361                     }
362
363                     ASSERT( pDirCB->OpenReferenceCount > 0);
364
365                     InterlockedDecrement( &pDirCB->OpenReferenceCount);
366
367                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
368                                   AFS_TRACE_LEVEL_VERBOSE,
369                                   "AFSClose (Other) Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
370                                   &pDirCB->NameInformation.FileName,
371                                   pDirCB,
372                                   pCcb,
373                                   pDirCB->OpenReferenceCount);
374
375                     if( pDirCB->OpenReferenceCount == 0)
376                     {
377
378                         AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
379                                       AFS_TRACE_LEVEL_VERBOSE,
380                                       "AFSClose Deleting dir entry %08lX (%08lX) for %wZ  FID %08lX-%08lX-%08lX-%08lX\n",
381                                       pDirCB,
382                                       pObjectInfo,
383                                       &pDirCB->NameInformation.FileName,
384                                       pObjectInfo->FileId.Cell,
385                                       pObjectInfo->FileId.Volume,
386                                       pObjectInfo->FileId.Vnode,
387                                       pObjectInfo->FileId.Unique);
388
389                         //
390                         // Remove and delete the directory entry from the parent list
391                         //
392
393                         AFSDeleteDirEntry( pObjectInfo->ParentObjectInformation,
394                                            pDirCB);
395
396                         if( pObjectInfo->ObjectReferenceCount == 0)
397                         {
398
399                             if( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_INSERTED_HASH_TREE))
400                             {
401
402                                 AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
403                                               AFS_TRACE_LEVEL_VERBOSE,
404                                               "AFSClose Removing object %08lX from volume tree\n",
405                                               pObjectInfo);
406
407                                 AFSRemoveHashEntry( &pObjectInfo->VolumeCB->ObjectInfoTree.TreeHead,
408                                                     &pObjectInfo->TreeEntry);
409
410                                 ClearFlag( pObjectInfo->Flags, AFS_OBJECT_INSERTED_HASH_TREE);
411                             }
412
413                             SetFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_DELETED);
414                         }
415                     }
416
417                     AFSReleaseResource( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
418
419                     AFSReleaseResource( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
420                 }
421                 else
422                 {
423
424                     ASSERT( pDirCB->OpenReferenceCount > 0);
425
426                     InterlockedDecrement( &pDirCB->OpenReferenceCount);
427
428                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
429                                   AFS_TRACE_LEVEL_VERBOSE,
430                                   "AFSClose (Other2) Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
431                                   &pDirCB->NameInformation.FileName,
432                                   pDirCB,
433                                   pCcb,
434                                   pDirCB->OpenReferenceCount);
435                 }
436
437                 //
438                 // If this is not the root then decrement the open child reference count
439                 //
440
441                 if( pObjectInfo != NULL &&
442                     pObjectInfo->ParentObjectInformation != NULL &&
443                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount > 0)
444                 {
445
446                     InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
447
448                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
449                                   AFS_TRACE_LEVEL_VERBOSE,
450                                   "AFSClose Decrement child open ref count on Parent object %08lX Cnt %d\n",
451                                   pObjectInfo->ParentObjectInformation,
452                                   pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
453                 }
454
455                 if( pFcb->OpenReferenceCount == 1 &&
456                     pFcb->Header.NodeTypeCode == AFS_FILE_FCB)
457                 {
458
459                     SetFlag( pFcb->Flags, AFS_FCB_FILE_CLOSED);
460
461                     //
462                     // Attempt to tear down our extent list for the file
463                     // If there are remaining dirty extents then attempt to
464                     // flush them as well
465                     //
466
467                     if( pFcb->Specific.File.ExtentsDirtyCount)
468                     {
469
470                         AFSFlushExtents( pFcb,
471                                          &pCcb->AuthGroup);
472                     }
473
474                     //
475                     // Wait for any outstanding queued flushes to complete
476                     //
477
478                     AFSWaitOnQueuedFlushes( pFcb);
479
480                     ASSERT( pFcb->Specific.File.ExtentsDirtyCount == 0 &&
481                             pFcb->Specific.File.QueuedFlushCount == 0);
482
483                     AFSReleaseResource( &pFcb->NPFcb->Resource);
484
485                     //
486                     // Tear 'em down, we'll not be needing them again
487                     //
488
489                     if( AFSTearDownFcbExtents( pFcb,
490                                                &pCcb->AuthGroup))
491                     {
492
493                         //
494                         // Indicate to the service that the file required complete flushing to the
495                         // server.
496                         //
497
498                         AFSProcessRequest( AFS_REQUEST_TYPE_FLUSH_FILE,
499                                            AFS_REQUEST_FLAG_SYNCHRONOUS,
500                                            &pCcb->AuthGroup,
501                                            NULL,
502                                            &pFcb->ObjectInformation->FileId,
503                                            NULL,
504                                            0,
505                                            NULL,
506                                            NULL);
507                     }
508                 }
509                 else
510                 {
511
512                     if( pFcb->Header.NodeTypeCode == AFS_FILE_FCB)
513                     {
514
515                         if( pFcb->Specific.File.ExtentsDirtyCount)
516                         {
517
518                             AFSFlushExtents( pFcb,
519                                              &pCcb->AuthGroup);
520                         }
521                     }
522
523                     AFSReleaseResource( &pFcb->NPFcb->Resource);
524                 }
525
526                 //
527                 // Remove the Ccb and de-allocate it
528                 //
529
530                 ntStatus = AFSRemoveCcb( pFcb,
531                                          pCcb);
532
533                 if( !NT_SUCCESS( ntStatus))
534                 {
535
536                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
537                                   AFS_TRACE_LEVEL_WARNING,
538                                   "AFSClose Failed to remove Ccb from Fcb Status %08lX\n",
539                                   ntStatus);
540
541                     //
542                     // We can't actually fail a close operation so reset the status
543                     //
544
545                     ntStatus = STATUS_SUCCESS;
546                 }
547
548                 //
549                 // Decrement the reference count on the Fcb. this is protecting it from teardown.
550                 //
551
552                 ASSERT( pFcb->OpenReferenceCount != 0);
553
554                 InterlockedDecrement( &pFcb->OpenReferenceCount);
555
556                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
557                               AFS_TRACE_LEVEL_VERBOSE,
558                               "AFSClose Decrement count on Fcb %08lX Cnt %d\n",
559                               pFcb,
560                               pFcb->OpenReferenceCount);
561
562                 break;
563             }
564
565             case AFS_SPECIAL_SHARE_FCB:
566             {
567
568                 AFSPipeOpenCloseRequestCB stPipeClose;
569
570                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
571                               AFS_TRACE_LEVEL_VERBOSE,
572                               "AFSClose Acquiring Special Share lock %08lX EXCL %08lX\n",
573                               &pFcb->NPFcb->Resource,
574                               PsGetCurrentThread());
575
576                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
577                                 TRUE);
578
579                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
580
581                 pDirCB = pCcb->DirectoryCB;
582
583                 RtlZeroMemory( &stPipeClose,
584                                sizeof( AFSPipeOpenCloseRequestCB));
585
586                 stPipeClose.RequestId = pCcb->RequestID;
587
588                 stPipeClose.RootId = pObjectInfo->VolumeCB->ObjectInformation.FileId;
589
590                 //
591                 // Issue the open request to the service
592                 //
593
594                 /*
595                 AFSProcessRequest( AFS_REQUEST_TYPE_PIPE_CLOSE,
596                                    AFS_REQUEST_FLAG_SYNCHRONOUS,
597                                    &pFcb->AuthGroup,
598                                    &pDirCB->NameInformation.FileName,
599                                    NULL,
600                                    (void *)&stPipeClose,
601                                    sizeof( AFSPipeOpenCloseRequestCB),
602                                    NULL,
603                                    NULL);
604                 */
605
606                 //
607                 // Remove the Ccb and de-allocate it
608                 //
609
610                 ntStatus = AFSRemoveCcb( pFcb,
611                                          pCcb);
612
613                 if( !NT_SUCCESS( ntStatus))
614                 {
615
616                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
617                                   AFS_TRACE_LEVEL_WARNING,
618                                   "AFSClose Failed to remove Ccb from Fcb Status %08lX\n", ntStatus);
619
620                     //
621                     // We can't actually fail a close operation so reset the status
622                     //
623
624                     ntStatus = STATUS_SUCCESS;
625                 }
626
627                 ASSERT( pDirCB->OpenReferenceCount > 0);
628
629                 InterlockedDecrement( &pDirCB->OpenReferenceCount);
630
631                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
632                               AFS_TRACE_LEVEL_VERBOSE,
633                               "AFSClose (Share) Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
634                               &pDirCB->NameInformation.FileName,
635                               pDirCB,
636                               pCcb,
637                               pDirCB->OpenReferenceCount);
638
639                 //
640                 // If this is not the root then decrement the open child reference count
641                 //
642
643                 if( pObjectInfo->ParentObjectInformation != NULL &&
644                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount > 0)
645                 {
646
647                     InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
648
649                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
650                                   AFS_TRACE_LEVEL_VERBOSE,
651                                   "AFSClose (Share) Decrement child open ref count on Parent object %08lX Cnt %d\n",
652                                   pObjectInfo->ParentObjectInformation,
653                                   pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
654                 }
655
656                 AFSReleaseResource( &pFcb->NPFcb->Resource);
657
658                 ASSERT( pFcb->OpenReferenceCount != 0);
659
660                 InterlockedDecrement( &pFcb->OpenReferenceCount);
661
662                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
663                               AFS_TRACE_LEVEL_VERBOSE,
664                               "AFSClose (Share) Decrement count on Fcb %08lX Cnt %d\n",
665                               pFcb,
666                               pFcb->OpenReferenceCount);
667
668                 break;
669             }
670
671             default:
672
673                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
674                               AFS_TRACE_LEVEL_ERROR,
675                               "AFSClose Processing unknown node type %d\n",
676                               pFcb->Header.NodeTypeCode);
677
678                 break;
679         }
680
681 try_exit:
682
683         //
684         // Complete the request
685         //
686
687         AFSCompleteRequest( Irp,
688                             ntStatus);
689     }
690     __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
691     {
692
693         AFSDbgLogMsg( 0,
694                       0,
695                       "EXCEPTION - AFSClose\n");
696     }
697
698     return ntStatus;
699 }