Windows: Permit deletion of reparse points
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSFileInfo.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: AFSFileInfo.cpp
37 //
38
39 #include "AFSCommon.h"
40
41 //
42 // Function: AFSQueryFileInfo
43 //
44 // Description:
45 //
46 //      This function is the dispatch handler for the IRP_MJ_QUERY_FILE_INFORMATION request
47 //
48 // Return:
49 //
50 //      A status is returned for the function
51 //
52
53 NTSTATUS
54 AFSQueryFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
55                   IN PIRP Irp)
56 {
57
58     UNREFERENCED_PARAMETER(LibDeviceObject);
59     NTSTATUS ntStatus = STATUS_SUCCESS;
60     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
61     AFSFcb *pFcb = NULL;
62     AFSCcb *pCcb = NULL;
63     BOOLEAN bReleaseMain = FALSE;
64     LONG lLength = 0;
65     FILE_INFORMATION_CLASS stFileInformationClass;
66     GUID stAuthGroup;
67     PVOID pBuffer;
68
69     __try
70     {
71
72         //
73         // Determine the type of request this request is
74         //
75
76         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
77
78         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
79
80         if( pFcb == NULL)
81         {
82
83             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
84                           AFS_TRACE_LEVEL_ERROR,
85                           "AFSQueryFileInfo Attempted access (%p) when pFcb == NULL\n",
86                           Irp);
87
88             try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
89         }
90
91         lLength = (LONG)pIrpSp->Parameters.QueryFile.Length;
92         stFileInformationClass = pIrpSp->Parameters.QueryFile.FileInformationClass;
93         pBuffer = Irp->AssociatedIrp.SystemBuffer;
94
95         if ( BooleanFlagOn( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY))
96         {
97
98             RtlZeroMemory( &stAuthGroup,
99                            sizeof( GUID));
100
101             AFSRetrieveAuthGroupFnc( (ULONGLONG)PsGetCurrentProcessId(),
102                                      (ULONGLONG)PsGetCurrentThreadId(),
103                                      &stAuthGroup);
104
105             ntStatus = AFSVerifyEntry( &stAuthGroup,
106                                        pCcb->DirectoryCB);
107
108             if ( NT_SUCCESS( ntStatus))
109             {
110
111                 ClearFlag( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
112             }
113             else
114             {
115
116                 ntStatus = STATUS_SUCCESS;
117             }
118         }
119
120         //
121         // Grab the main shared right off the bat
122         //
123
124         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
125                       AFS_TRACE_LEVEL_VERBOSE,
126                       "AFSQueryFileInfo Acquiring Fcb lock %p SHARED %08lX\n",
127                       &pFcb->NPFcb->Resource,
128                       PsGetCurrentThread());
129
130         AFSAcquireShared( &pFcb->NPFcb->Resource,
131                           TRUE);
132
133         bReleaseMain = TRUE;
134
135         //
136         // Don't allow requests against IOCtl nodes
137         //
138
139         if( pFcb->Header.NodeTypeCode == AFS_SPECIAL_SHARE_FCB)
140         {
141
142             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
143                           AFS_TRACE_LEVEL_VERBOSE,
144                           "AFSQueryFileInfo Processing request against SpecialShare Fcb\n");
145
146             ntStatus = AFSProcessShareQueryInfo( Irp,
147                                                  pFcb,
148                                                  pCcb);
149
150             try_return( ntStatus);
151         }
152         else if( pFcb->Header.NodeTypeCode == AFS_IOCTL_FCB)
153         {
154             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
155                           AFS_TRACE_LEVEL_VERBOSE,
156                           "AFSQueryFileInfo request against PIOCtl Fcb\n");
157
158             ntStatus = AFSProcessPIOCtlQueryInfo( Irp,
159                                                   pFcb,
160                                                   pCcb,
161                                                   &lLength);
162
163             try_return( ntStatus);
164         }
165
166         else if( pFcb->Header.NodeTypeCode == AFS_INVALID_FCB)
167         {
168             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
169                           AFS_TRACE_LEVEL_VERBOSE,
170                           "AFSQueryFileInfo request against Invalid Fcb\n");
171
172             try_return( ntStatus = STATUS_ACCESS_DENIED);
173         }
174
175         //
176         // Process the request
177         //
178
179         switch( stFileInformationClass)
180         {
181
182             case FileAllInformation:
183             {
184
185                 PFILE_ALL_INFORMATION pAllInfo;
186
187                 //
188                 //  For the all information class we'll typecast a local
189                 //  pointer to the output buffer and then call the
190                 //  individual routines to fill in the buffer.
191                 //
192
193                 pAllInfo = (PFILE_ALL_INFORMATION)pBuffer;
194
195                 ntStatus = AFSQueryBasicInfo( Irp,
196                                               pCcb->DirectoryCB,
197                                               &pAllInfo->BasicInformation,
198                                               &lLength);
199
200                 if( !NT_SUCCESS( ntStatus))
201                 {
202
203                     try_return( ntStatus);
204                 }
205
206                 ntStatus = AFSQueryStandardInfo( Irp,
207                                                  pCcb->DirectoryCB,
208                                                  &pAllInfo->StandardInformation,
209                                                  &lLength);
210
211                 if( !NT_SUCCESS( ntStatus))
212                 {
213
214                     try_return( ntStatus);
215                 }
216
217                 ntStatus = AFSQueryInternalInfo( Irp,
218                                                  pFcb,
219                                                  &pAllInfo->InternalInformation,
220                                                  &lLength);
221
222                 if( !NT_SUCCESS( ntStatus))
223                 {
224
225                     try_return( ntStatus);
226                 }
227
228                 ntStatus = AFSQueryEaInfo( Irp,
229                                            pCcb->DirectoryCB,
230                                            &pAllInfo->EaInformation,
231                                            &lLength);
232
233                 if( !NT_SUCCESS( ntStatus))
234                 {
235
236                     try_return( ntStatus);
237                 }
238
239                 ntStatus = AFSQueryAccess( Irp,
240                                            pFcb,
241                                            &pAllInfo->AccessInformation,
242                                            &lLength);
243
244                 if( !NT_SUCCESS( ntStatus))
245                 {
246
247                     try_return( ntStatus);
248                 }
249
250                 ntStatus = AFSQueryPositionInfo( Irp,
251                                                  pFcb,
252                                                  &pAllInfo->PositionInformation,
253                                                  &lLength);
254
255                 if( !NT_SUCCESS( ntStatus))
256                 {
257
258                     try_return( ntStatus);
259                 }
260
261                 ntStatus = AFSQueryMode( Irp,
262                                          pFcb,
263                                          &pAllInfo->ModeInformation,
264                                          &lLength);
265
266                 if( !NT_SUCCESS( ntStatus))
267                 {
268
269                     try_return( ntStatus);
270                 }
271
272                 ntStatus = AFSQueryAlignment( Irp,
273                                               pFcb,
274                                               &pAllInfo->AlignmentInformation,
275                                               &lLength);
276
277                 if( !NT_SUCCESS( ntStatus))
278                 {
279
280                     try_return( ntStatus);
281                 }
282
283                 ntStatus = AFSQueryNameInfo( Irp,
284                                              pCcb->DirectoryCB,
285                                              &pAllInfo->NameInformation,
286                                              &lLength);
287
288                 if( !NT_SUCCESS( ntStatus))
289                 {
290
291                     try_return( ntStatus);
292                 }
293
294                 break;
295             }
296
297             case FileBasicInformation:
298             {
299
300                 ntStatus = AFSQueryBasicInfo( Irp,
301                                               pCcb->DirectoryCB,
302                                               (PFILE_BASIC_INFORMATION)pBuffer,
303                                               &lLength);
304
305                 break;
306             }
307
308             case FileStandardInformation:
309             {
310
311                 ntStatus = AFSQueryStandardInfo( Irp,
312                                                  pCcb->DirectoryCB,
313                                                  (PFILE_STANDARD_INFORMATION)pBuffer,
314                                                  &lLength);
315
316                 break;
317             }
318
319             case FileInternalInformation:
320             {
321
322                 ntStatus = AFSQueryInternalInfo( Irp,
323                                                  pFcb,
324                                                  (PFILE_INTERNAL_INFORMATION)pBuffer,
325                                                  &lLength);
326
327                 break;
328             }
329
330             case FileEaInformation:
331             {
332
333                 ntStatus = AFSQueryEaInfo( Irp,
334                                            pCcb->DirectoryCB,
335                                            (PFILE_EA_INFORMATION)pBuffer,
336                                            &lLength);
337
338                 break;
339             }
340
341             case FilePositionInformation:
342             {
343
344                 ntStatus = AFSQueryPositionInfo( Irp,
345                                       pFcb,
346                                       (PFILE_POSITION_INFORMATION)pBuffer,
347                                       &lLength);
348
349                 break;
350             }
351
352             case FileNormalizedNameInformation:
353             case FileNameInformation:
354             {
355
356                 ntStatus = AFSQueryNameInfo( Irp,
357                                   pCcb->DirectoryCB,
358                                   (PFILE_NAME_INFORMATION)pBuffer,
359                                   &lLength);
360
361                 break;
362             }
363
364             case FileAlternateNameInformation:
365             {
366
367                 ntStatus = AFSQueryShortNameInfo( Irp,
368                                        pCcb->DirectoryCB,
369                                        (PFILE_NAME_INFORMATION)pBuffer,
370                                        &lLength);
371
372                 break;
373             }
374
375             case FileNetworkOpenInformation:
376             {
377
378                 ntStatus = AFSQueryNetworkInfo( Irp,
379                                      pCcb->DirectoryCB,
380                                      (PFILE_NETWORK_OPEN_INFORMATION)pBuffer,
381                                      &lLength);
382
383                 break;
384             }
385
386             case FileStreamInformation:
387             {
388
389                 ntStatus = AFSQueryStreamInfo( Irp,
390                                                pCcb->DirectoryCB,
391                                                (FILE_STREAM_INFORMATION *)pBuffer,
392                                                &lLength);
393
394                 break;
395             }
396
397
398             case FileAttributeTagInformation:
399             {
400
401                 ntStatus = AFSQueryAttribTagInfo( Irp,
402                                                   pCcb->DirectoryCB,
403                                                   (FILE_ATTRIBUTE_TAG_INFORMATION *)pBuffer,
404                                                   &lLength);
405
406                 break;
407             }
408
409             case FileRemoteProtocolInformation:
410             {
411
412                     ntStatus = AFSQueryRemoteProtocolInfo( Irp,
413                                                            pCcb->DirectoryCB,
414                                                            (FILE_REMOTE_PROTOCOL_INFORMATION *)pBuffer,
415                                                            &lLength);
416
417                 break;
418             }
419
420             case FileNetworkPhysicalNameInformation:
421             {
422
423                 ntStatus = AFSQueryPhysicalNameInfo( Irp,
424                                                      pCcb->DirectoryCB,
425                                                      (FILE_NETWORK_PHYSICAL_NAME_INFORMATION *)pBuffer,
426                                                      &lLength);
427
428                 break;
429             }
430
431             default:
432             {
433                 ntStatus = STATUS_INVALID_PARAMETER;
434                 break;
435             }
436         }
437
438 try_exit:
439
440         Irp->IoStatus.Information = pIrpSp->Parameters.QueryFile.Length - lLength;
441
442         if( bReleaseMain)
443         {
444
445             AFSReleaseResource( &pFcb->NPFcb->Resource);
446         }
447
448         if( !NT_SUCCESS( ntStatus) &&
449             ntStatus != STATUS_INVALID_PARAMETER &&
450             ntStatus != STATUS_BUFFER_OVERFLOW)
451         {
452
453             if( pCcb != NULL &&
454                 pCcb->DirectoryCB != NULL)
455             {
456
457                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
458                               AFS_TRACE_LEVEL_ERROR,
459                               "AFSQueryFileInfo Failed to process request for %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
460                               &pCcb->DirectoryCB->NameInformation.FileName,
461                               pCcb->DirectoryCB->ObjectInformation->FileId.Cell,
462                               pCcb->DirectoryCB->ObjectInformation->FileId.Volume,
463                               pCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
464                               pCcb->DirectoryCB->ObjectInformation->FileId.Unique,
465                               ntStatus);
466             }
467         }
468     }
469     __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
470     {
471
472         AFSDbgLogMsg( 0,
473                       0,
474                       "EXCEPTION - AFSQueryFileInfo\n");
475
476         AFSDumpTraceFilesFnc();
477
478         ntStatus = STATUS_UNSUCCESSFUL;
479
480         if( bReleaseMain)
481         {
482
483             AFSReleaseResource( &pFcb->NPFcb->Resource);
484         }
485     }
486
487     AFSCompleteRequest( Irp,
488                         ntStatus);
489
490     return ntStatus;
491 }
492
493 //
494 // Function: AFSSetFileInfo
495 //
496 // Description:
497 //
498 //      This function is the dispatch handler for the IRP_MJ_SET_FILE_INFORMATION request
499 //
500 // Return:
501 //
502 //      A status is returned for the function
503 //
504
505 NTSTATUS
506 AFSSetFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
507                 IN PIRP Irp)
508 {
509
510     UNREFERENCED_PARAMETER(LibDeviceObject);
511     NTSTATUS ntStatus = STATUS_SUCCESS;
512     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
513     AFSFcb *pFcb = NULL;
514     AFSCcb *pCcb = NULL;
515     FILE_INFORMATION_CLASS FileInformationClass;
516     BOOLEAN bCanQueueRequest = FALSE;
517     PFILE_OBJECT pFileObject = NULL;
518     BOOLEAN bReleaseMain = FALSE;
519     BOOLEAN bUpdateFileInfo = FALSE;
520     AFSFileID stParentFileId;
521
522     __try
523     {
524
525         pFileObject = pIrpSp->FileObject;
526
527         pFcb = (AFSFcb *)pFileObject->FsContext;
528         pCcb = (AFSCcb *)pFileObject->FsContext2;
529
530         if( pFcb == NULL)
531         {
532
533             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
534                           AFS_TRACE_LEVEL_ERROR,
535                           "AFSSetFileInfo Attempted access (%p) when pFcb == NULL\n",
536                           Irp);
537
538             try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
539         }
540
541         bCanQueueRequest = !(IoIsOperationSynchronous( Irp) | (KeGetCurrentIrql() != PASSIVE_LEVEL));
542         FileInformationClass = pIrpSp->Parameters.SetFile.FileInformationClass;
543
544         //
545         // Grab the Fcb EXCL
546         //
547
548         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
549                       AFS_TRACE_LEVEL_VERBOSE,
550                       "AFSSetFileInfo Acquiring Fcb lock %p EXCL %08lX\n",
551                       &pFcb->NPFcb->Resource,
552                       PsGetCurrentThread());
553
554         AFSAcquireExcl( &pFcb->NPFcb->Resource,
555                         TRUE);
556
557         bReleaseMain = TRUE;
558
559         //
560         // Don't allow requests against IOCtl nodes
561         //
562
563         if( pFcb->Header.NodeTypeCode == AFS_IOCTL_FCB)
564         {
565
566             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
567                           AFS_TRACE_LEVEL_ERROR,
568                           "AFSSetFileInfo Failing request against PIOCtl Fcb\n");
569
570             try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
571         }
572         else if( pFcb->Header.NodeTypeCode == AFS_SPECIAL_SHARE_FCB)
573         {
574
575             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
576                           AFS_TRACE_LEVEL_VERBOSE,
577                           "AFSSetFileInfo Processing request against SpecialShare Fcb\n");
578
579             ntStatus = AFSProcessShareSetInfo( Irp,
580                                                pFcb,
581                                                pCcb);
582
583             try_return( ntStatus);
584         }
585
586         if( BooleanFlagOn( pFcb->ObjectInformation->VolumeCB->VolumeInformation.Characteristics, FILE_READ_ONLY_DEVICE))
587         {
588
589             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
590                           AFS_TRACE_LEVEL_ERROR,
591                           "AFSSetFileInfo Request failed due to read only volume\n",
592                           Irp);
593
594             try_return( ntStatus = STATUS_MEDIA_WRITE_PROTECTED);
595         }
596
597         if( pFcb->Header.NodeTypeCode == AFS_INVALID_FCB &&
598             FileInformationClass != FileDispositionInformation)
599         {
600             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
601                           AFS_TRACE_LEVEL_VERBOSE,
602                           "AFSSetFileInfo request against Invalid Fcb\n");
603
604             try_return( ntStatus = STATUS_ACCESS_DENIED);
605         }
606
607         //
608         // Ensure rename operations are synchronous
609         //
610
611         if( FileInformationClass == FileRenameInformation)
612         {
613
614             bCanQueueRequest = FALSE;
615         }
616
617         //
618         // Store away the parent fid
619         //
620
621         RtlZeroMemory( &stParentFileId,
622                        sizeof( AFSFileID));
623
624         if( BooleanFlagOn( pFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
625         {
626
627             stParentFileId = pFcb->ObjectInformation->ParentFileId;
628         }
629
630         //
631         // Process the request
632         //
633
634         switch( FileInformationClass)
635         {
636
637             case FileBasicInformation:
638             {
639
640                 bUpdateFileInfo = TRUE;
641
642                 ntStatus = AFSSetBasicInfo( Irp,
643                                             pCcb->DirectoryCB);
644
645                 break;
646             }
647
648             case FileDispositionInformation:
649             {
650
651                 ntStatus = AFSSetDispositionInfo( Irp,
652                                                   pCcb->DirectoryCB);
653
654                 break;
655             }
656
657             case FileRenameInformation:
658             {
659
660                 ntStatus = AFSSetRenameInfo( Irp);
661
662                 break;
663             }
664
665             case FilePositionInformation:
666             {
667
668                 ntStatus = AFSSetPositionInfo( Irp,
669                                                pCcb->DirectoryCB);
670
671                 break;
672             }
673
674             case FileLinkInformation:
675             {
676
677                 ntStatus = AFSSetFileLinkInfo( Irp);
678
679                 break;
680             }
681
682             case FileAllocationInformation:
683             {
684
685                 ntStatus = AFSSetAllocationInfo( Irp,
686                                                  pCcb->DirectoryCB);
687
688                 break;
689             }
690
691             case FileEndOfFileInformation:
692             {
693
694                 ntStatus = AFSSetEndOfFileInfo( Irp,
695                                                 pCcb->DirectoryCB);
696
697                 break;
698             }
699
700             default:
701
702                 ntStatus = STATUS_INVALID_PARAMETER;
703
704                 break;
705         }
706
707 try_exit:
708
709         if( bReleaseMain)
710         {
711
712             AFSReleaseResource( &pFcb->NPFcb->Resource);
713         }
714
715         if( NT_SUCCESS( ntStatus) &&
716             bUpdateFileInfo)
717         {
718
719             ntStatus = AFSUpdateFileInformation( &stParentFileId,
720                                                  pFcb->ObjectInformation,
721                                                  &pCcb->AuthGroup);
722
723             if( !NT_SUCCESS( ntStatus))
724             {
725
726                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
727                                 TRUE);
728
729                 //
730                 // Unwind the update and fail the request
731                 //
732
733                 AFSUnwindFileInfo( pFcb,
734                                    pCcb);
735
736                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
737                               AFS_TRACE_LEVEL_ERROR,
738                               "AFSSetFileInfo Failed to send file info update to service request for %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
739                               &pCcb->DirectoryCB->NameInformation.FileName,
740                               pCcb->DirectoryCB->ObjectInformation->FileId.Cell,
741                               pCcb->DirectoryCB->ObjectInformation->FileId.Volume,
742                               pCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
743                               pCcb->DirectoryCB->ObjectInformation->FileId.Unique,
744                               ntStatus);
745
746                 AFSReleaseResource( &pFcb->NPFcb->Resource);
747             }
748         }
749
750         if( !NT_SUCCESS( ntStatus))
751         {
752
753             if( pCcb != NULL &&
754                 pCcb->DirectoryCB != NULL)
755             {
756
757                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
758                               AFS_TRACE_LEVEL_ERROR,
759                               "AFSSetFileInfo Failed to process request for %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
760                               &pCcb->DirectoryCB->NameInformation.FileName,
761                               pCcb->DirectoryCB->ObjectInformation->FileId.Cell,
762                               pCcb->DirectoryCB->ObjectInformation->FileId.Volume,
763                               pCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
764                               pCcb->DirectoryCB->ObjectInformation->FileId.Unique,
765                               ntStatus);
766             }
767         }
768     }
769     __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
770     {
771
772         AFSDbgLogMsg( 0,
773                       0,
774                       "EXCEPTION - AFSSetFileInfo\n");
775
776         AFSDumpTraceFilesFnc();
777
778         ntStatus = STATUS_UNSUCCESSFUL;
779
780         if( bReleaseMain)
781         {
782
783             AFSReleaseResource( &pFcb->NPFcb->Resource);
784         }
785     }
786
787     AFSCompleteRequest( Irp,
788                         ntStatus);
789
790     return ntStatus;
791 }
792
793 //
794 // Function: AFSQueryBasicInfo
795 //
796 // Description:
797 //
798 //      This function is the handler for the query basic information request
799 //
800 // Return:
801 //
802 //      A status is returned for the function
803 //
804
805 NTSTATUS
806 AFSQueryBasicInfo( IN PIRP Irp,
807                    IN AFSDirectoryCB *DirectoryCB,
808                    IN OUT PFILE_BASIC_INFORMATION Buffer,
809                    IN OUT PLONG Length)
810 {
811     NTSTATUS ntStatus = STATUS_SUCCESS;
812     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
813     ULONG ulFileAttribs = 0;
814     AFSFcb *pFcb = NULL;
815     AFSCcb *pCcb = NULL;
816     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
817     AFSFileInfoCB stFileInfo;
818     AFSDirectoryCB *pParentDirectoryCB = NULL;
819     UNICODE_STRING uniParentPath;
820
821     if( *Length >= sizeof( FILE_BASIC_INFORMATION))
822     {
823
824         RtlZeroMemory( Buffer,
825                        *Length);
826
827         ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
828
829         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
830         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
831
832         if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
833         {
834
835             pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
836
837             AFSRetrieveParentPath( &pCcb->FullFileName,
838                                    &uniParentPath);
839
840             RtlZeroMemory( &stFileInfo,
841                            sizeof( AFSFileInfoCB));
842
843             //
844             // Can't hold the Fcb while evaluating the path, leads to lock inversion
845             //
846
847             AFSReleaseResource( &pFcb->NPFcb->Resource);
848
849             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
850                                                        DirectoryCB,
851                                                        &uniParentPath,
852                                                        pCcb->NameArray,
853                                                        &pCcb->AuthGroup,
854                                                        &stFileInfo)))
855             {
856
857                 if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
858                 {
859
860                     ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
861                 }
862                 else
863                 {
864
865                     ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
866                 }
867
868                 if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
869                 {
870
871                     ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
872                 }
873             }
874
875             AFSAcquireShared( &pFcb->NPFcb->Resource,
876                               TRUE);
877         }
878
879
880         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
881                       AFS_TRACE_LEVEL_VERBOSE_2,
882                       "AFSQueryBasicInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
883                       &pCcb->DirectoryCB->NameInformation.FileName,
884                       pCcb->DirectoryCB->ObjectInformation->FileType,
885                       pCcb->DirectoryCB->ObjectInformation->FileAttributes,
886                       ulFileAttribs);
887
888         Buffer->CreationTime = DirectoryCB->ObjectInformation->CreationTime;
889         Buffer->LastAccessTime = DirectoryCB->ObjectInformation->LastAccessTime;
890         Buffer->LastWriteTime = DirectoryCB->ObjectInformation->LastWriteTime;
891         Buffer->ChangeTime = DirectoryCB->ObjectInformation->ChangeTime;
892         Buffer->FileAttributes = ulFileAttribs;
893
894         if( DirectoryCB->NameInformation.FileName.Buffer[ 0] == L'.' &&
895             BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_HIDE_DOT_NAMES))
896         {
897
898             if ( Buffer->FileAttributes != FILE_ATTRIBUTE_NORMAL)
899             {
900                 Buffer->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
901             }
902             else
903             {
904                 Buffer->FileAttributes = FILE_ATTRIBUTE_HIDDEN;
905             }
906         }
907
908         *Length -= sizeof( FILE_BASIC_INFORMATION);
909     }
910     else
911     {
912
913         ntStatus = STATUS_BUFFER_TOO_SMALL;
914     }
915
916     return ntStatus;
917 }
918
919 NTSTATUS
920 AFSQueryStandardInfo( IN PIRP Irp,
921                       IN AFSDirectoryCB *DirectoryCB,
922                       IN OUT PFILE_STANDARD_INFORMATION Buffer,
923                       IN OUT PLONG Length)
924 {
925
926     NTSTATUS ntStatus = STATUS_SUCCESS;
927     AFSFcb *pFcb = NULL;
928     AFSCcb *pCcb = NULL;
929     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
930     AFSFileInfoCB stFileInfo;
931     AFSDirectoryCB *pParentDirectoryCB = NULL;
932     UNICODE_STRING uniParentPath;
933     ULONG ulFileAttribs = 0;
934
935     if( *Length >= sizeof( FILE_STANDARD_INFORMATION))
936     {
937
938         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
939         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
940
941         RtlZeroMemory( Buffer,
942                        *Length);
943
944         Buffer->NumberOfLinks = 1;
945         Buffer->DeletePending = BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
946
947         Buffer->AllocationSize.QuadPart = (ULONGLONG)((DirectoryCB->ObjectInformation->AllocationSize.QuadPart/PAGE_SIZE) + 1) * PAGE_SIZE;
948
949         Buffer->EndOfFile = DirectoryCB->ObjectInformation->EndOfFile;
950
951         ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
952
953         if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
954         {
955
956             pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
957
958             AFSRetrieveParentPath( &pCcb->FullFileName,
959                                    &uniParentPath);
960
961             RtlZeroMemory( &stFileInfo,
962                            sizeof( AFSFileInfoCB));
963
964             //
965             // Can't hold the Fcb while evaluating the path, leads to lock inversion
966             //
967
968             AFSReleaseResource( &pFcb->NPFcb->Resource);
969
970             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
971                                                        DirectoryCB,
972                                                        &uniParentPath,
973                                                        pCcb->NameArray,
974                                                        &pCcb->AuthGroup,
975                                                        &stFileInfo)))
976             {
977
978                 if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
979                 {
980
981                     ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
982                 }
983                 else
984                 {
985
986                     ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
987                 }
988
989                 if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
990                 {
991
992                     ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
993                 }
994             }
995
996             AFSAcquireShared( &pFcb->NPFcb->Resource,
997                               TRUE);
998         }
999
1000         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1001                       AFS_TRACE_LEVEL_VERBOSE_2,
1002                       "AFSQueryStandardInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
1003                       &pCcb->DirectoryCB->NameInformation.FileName,
1004                       pCcb->DirectoryCB->ObjectInformation->FileType,
1005                       pCcb->DirectoryCB->ObjectInformation->FileAttributes,
1006                       ulFileAttribs);
1007
1008         Buffer->Directory = BooleanFlagOn( ulFileAttribs, FILE_ATTRIBUTE_DIRECTORY);
1009
1010         *Length -= sizeof( FILE_STANDARD_INFORMATION);
1011     }
1012     else
1013     {
1014
1015         ntStatus = STATUS_BUFFER_TOO_SMALL;
1016     }
1017
1018     return ntStatus;
1019 }
1020
1021 NTSTATUS
1022 AFSQueryInternalInfo( IN PIRP Irp,
1023                       IN AFSFcb *Fcb,
1024                       IN OUT PFILE_INTERNAL_INFORMATION Buffer,
1025                       IN OUT PLONG Length)
1026 {
1027
1028     UNREFERENCED_PARAMETER(Irp);
1029     NTSTATUS ntStatus = STATUS_SUCCESS;
1030
1031     if( *Length >= sizeof( FILE_INTERNAL_INFORMATION))
1032     {
1033
1034         Buffer->IndexNumber.HighPart = Fcb->ObjectInformation->FileId.Vnode;
1035
1036         Buffer->IndexNumber.LowPart = Fcb->ObjectInformation->FileId.Unique;
1037
1038         *Length -= sizeof( FILE_INTERNAL_INFORMATION);
1039     }
1040     else
1041     {
1042
1043         ntStatus = STATUS_BUFFER_TOO_SMALL;
1044     }
1045
1046     return ntStatus;
1047 }
1048
1049 NTSTATUS
1050 AFSQueryEaInfo( IN PIRP Irp,
1051                 IN AFSDirectoryCB *DirectoryCB,
1052                 IN OUT PFILE_EA_INFORMATION Buffer,
1053                 IN OUT PLONG Length)
1054 {
1055
1056     UNREFERENCED_PARAMETER(Irp);
1057     UNREFERENCED_PARAMETER(DirectoryCB);
1058     NTSTATUS ntStatus = STATUS_SUCCESS;
1059
1060     RtlZeroMemory( Buffer,
1061                    *Length);
1062
1063     if( *Length >= sizeof( FILE_EA_INFORMATION))
1064     {
1065
1066         Buffer->EaSize = 0;
1067
1068         *Length -= sizeof( FILE_EA_INFORMATION);
1069     }
1070     else
1071     {
1072
1073         ntStatus = STATUS_BUFFER_TOO_SMALL;
1074     }
1075
1076     return ntStatus;
1077 }
1078
1079 NTSTATUS
1080 AFSQueryPositionInfo( IN PIRP Irp,
1081                       IN AFSFcb *Fcb,
1082                       IN OUT PFILE_POSITION_INFORMATION Buffer,
1083                       IN OUT PLONG Length)
1084 {
1085
1086     UNREFERENCED_PARAMETER(Fcb);
1087     NTSTATUS ntStatus = STATUS_SUCCESS;
1088     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1089
1090     if( *Length >= sizeof( FILE_POSITION_INFORMATION))
1091     {
1092
1093         RtlZeroMemory( Buffer,
1094                        *Length);
1095
1096         Buffer->CurrentByteOffset.QuadPart = pIrpSp->FileObject->CurrentByteOffset.QuadPart;
1097
1098         *Length -= sizeof( FILE_POSITION_INFORMATION);
1099     }
1100     else
1101     {
1102
1103         ntStatus = STATUS_BUFFER_TOO_SMALL;
1104     }
1105
1106     return ntStatus;
1107 }
1108
1109 NTSTATUS
1110 AFSQueryAccess( IN PIRP Irp,
1111                 IN AFSFcb *Fcb,
1112                 IN OUT PFILE_ACCESS_INFORMATION Buffer,
1113                 IN OUT PLONG Length)
1114 {
1115
1116     UNREFERENCED_PARAMETER(Irp);
1117     UNREFERENCED_PARAMETER(Fcb);
1118     NTSTATUS ntStatus = STATUS_SUCCESS;
1119
1120     if( *Length >= sizeof( FILE_ACCESS_INFORMATION))
1121     {
1122
1123         RtlZeroMemory( Buffer,
1124                        *Length);
1125
1126         Buffer->AccessFlags = 0;
1127
1128         *Length -= sizeof( FILE_ACCESS_INFORMATION);
1129     }
1130     else
1131     {
1132
1133         ntStatus = STATUS_BUFFER_TOO_SMALL;
1134     }
1135
1136     return ntStatus;
1137 }
1138
1139 NTSTATUS
1140 AFSQueryMode( IN PIRP Irp,
1141               IN AFSFcb *Fcb,
1142               IN OUT PFILE_MODE_INFORMATION Buffer,
1143               IN OUT PLONG Length)
1144 {
1145
1146     UNREFERENCED_PARAMETER(Irp);
1147     UNREFERENCED_PARAMETER(Fcb);
1148     NTSTATUS ntStatus = STATUS_SUCCESS;
1149
1150     if( *Length >= sizeof( FILE_MODE_INFORMATION))
1151     {
1152
1153         RtlZeroMemory( Buffer,
1154                        *Length);
1155
1156         Buffer->Mode = 0;
1157
1158         *Length -= sizeof( FILE_MODE_INFORMATION);
1159     }
1160     else
1161     {
1162
1163         ntStatus = STATUS_BUFFER_TOO_SMALL;
1164     }
1165
1166     return ntStatus;
1167 }
1168
1169 NTSTATUS
1170 AFSQueryAlignment( IN PIRP Irp,
1171                    IN AFSFcb *Fcb,
1172                    IN OUT PFILE_ALIGNMENT_INFORMATION Buffer,
1173                    IN OUT PLONG Length)
1174 {
1175
1176     UNREFERENCED_PARAMETER(Irp);
1177     UNREFERENCED_PARAMETER(Fcb);
1178     NTSTATUS ntStatus = STATUS_SUCCESS;
1179
1180     if( *Length >= sizeof( FILE_ALIGNMENT_INFORMATION))
1181     {
1182
1183         RtlZeroMemory( Buffer,
1184                        *Length);
1185
1186         Buffer->AlignmentRequirement = 1;
1187
1188         *Length -= sizeof( FILE_ALIGNMENT_INFORMATION);
1189     }
1190     else
1191     {
1192
1193         ntStatus = STATUS_BUFFER_TOO_SMALL;
1194     }
1195
1196     return ntStatus;
1197 }
1198
1199 NTSTATUS
1200 AFSQueryNameInfo( IN PIRP Irp,
1201                   IN AFSDirectoryCB *DirectoryCB,
1202                   IN OUT PFILE_NAME_INFORMATION Buffer,
1203                   IN OUT PLONG Length)
1204 {
1205
1206     UNREFERENCED_PARAMETER(DirectoryCB);
1207     NTSTATUS ntStatus = STATUS_SUCCESS;
1208     ULONG ulCopyLength = 0;
1209     ULONG cchCopied = 0;
1210     AFSFcb *pFcb = NULL;
1211     AFSCcb *pCcb = NULL;
1212     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1213     BOOLEAN bAddLeadingSlash = FALSE;
1214     BOOLEAN bAddTrailingSlash = FALSE;
1215     USHORT usFullNameLength = 0;
1216
1217     pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
1218
1219     pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1220
1221     if( *Length >= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName))
1222     {
1223
1224         RtlZeroMemory( Buffer,
1225                        *Length);
1226
1227         if( pCcb->FullFileName.Length == 0 ||
1228             pCcb->FullFileName.Buffer[ 0] != L'\\')
1229         {
1230             bAddLeadingSlash = TRUE;
1231         }
1232
1233         if( pFcb->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY &&
1234             pCcb->FullFileName.Length > 0 &&
1235             pCcb->FullFileName.Buffer[ (pCcb->FullFileName.Length/sizeof( WCHAR)) - 1] != L'\\')
1236         {
1237             bAddTrailingSlash = TRUE;
1238         }
1239
1240         usFullNameLength = sizeof( WCHAR) +
1241                                     AFSServerName.Length +
1242                                     pCcb->FullFileName.Length;
1243
1244         if( bAddLeadingSlash)
1245         {
1246             usFullNameLength += sizeof( WCHAR);
1247         }
1248
1249         if( bAddTrailingSlash)
1250         {
1251             usFullNameLength += sizeof( WCHAR);
1252         }
1253
1254         if( *Length >= (LONG)(FIELD_OFFSET( FILE_NAME_INFORMATION, FileName) + (LONG)usFullNameLength))
1255         {
1256
1257             ulCopyLength = (LONG)usFullNameLength;
1258         }
1259         else
1260         {
1261
1262             ulCopyLength = *Length - FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
1263
1264             ntStatus = STATUS_BUFFER_OVERFLOW;
1265         }
1266
1267         Buffer->FileNameLength = (ULONG)usFullNameLength;
1268
1269         *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
1270
1271         if( ulCopyLength > 0)
1272         {
1273
1274             Buffer->FileName[ 0] = L'\\';
1275             ulCopyLength -= sizeof( WCHAR);
1276
1277             *Length -= sizeof( WCHAR);
1278             cchCopied += 1;
1279
1280             if( ulCopyLength >= AFSServerName.Length)
1281             {
1282
1283                 RtlCopyMemory( &Buffer->FileName[ 1],
1284                                AFSServerName.Buffer,
1285                                AFSServerName.Length);
1286
1287                 ulCopyLength -= AFSServerName.Length;
1288                 *Length -= AFSServerName.Length;
1289                 cchCopied += AFSServerName.Length/sizeof( WCHAR);
1290
1291                 if ( ulCopyLength > 0 &&
1292                      bAddLeadingSlash)
1293                 {
1294
1295                     Buffer->FileName[ cchCopied] = L'\\';
1296
1297                     ulCopyLength -= sizeof( WCHAR);
1298                     *Length -= sizeof( WCHAR);
1299                     cchCopied++;
1300                 }
1301
1302                 if( ulCopyLength >= pCcb->FullFileName.Length)
1303                 {
1304
1305                     RtlCopyMemory( &Buffer->FileName[ cchCopied],
1306                                    pCcb->FullFileName.Buffer,
1307                                    pCcb->FullFileName.Length);
1308
1309                     ulCopyLength -= pCcb->FullFileName.Length;
1310                     *Length -= pCcb->FullFileName.Length;
1311                     cchCopied += pCcb->FullFileName.Length/sizeof( WCHAR);
1312
1313                     if( ulCopyLength > 0 &&
1314                         bAddTrailingSlash)
1315                     {
1316                         Buffer->FileName[ cchCopied] = L'\\';
1317
1318                         *Length -= sizeof( WCHAR);
1319                     }
1320                 }
1321                 else
1322                 {
1323
1324                     RtlCopyMemory( &Buffer->FileName[ cchCopied],
1325                                    pCcb->FullFileName.Buffer,
1326                                    ulCopyLength);
1327
1328                     *Length -= ulCopyLength;
1329                 }
1330             }
1331         }
1332     }
1333     else
1334     {
1335
1336         ntStatus = STATUS_BUFFER_TOO_SMALL;
1337     }
1338
1339     return ntStatus;
1340 }
1341
1342 NTSTATUS
1343 AFSQueryShortNameInfo( IN PIRP Irp,
1344                        IN AFSDirectoryCB *DirectoryCB,
1345                        IN OUT PFILE_NAME_INFORMATION Buffer,
1346                        IN OUT PLONG Length)
1347 {
1348
1349     UNREFERENCED_PARAMETER(Irp);
1350     NTSTATUS ntStatus = STATUS_BUFFER_TOO_SMALL;
1351     ULONG ulCopyLength = 0;
1352
1353     RtlZeroMemory( Buffer,
1354                    *Length);
1355
1356     if( DirectoryCB->NameInformation.ShortNameLength == 0)
1357     {
1358
1359         //
1360         // The short name IS the long name
1361         //
1362
1363         if( *Length >= (LONG)FIELD_OFFSET( FILE_NAME_INFORMATION, FileName))
1364         {
1365
1366             if( *Length >= (LONG)(FIELD_OFFSET( FILE_NAME_INFORMATION, FileName) + (LONG)DirectoryCB->NameInformation.FileName.Length))
1367             {
1368
1369                 ulCopyLength = (LONG)DirectoryCB->NameInformation.FileName.Length;
1370
1371                 ntStatus = STATUS_SUCCESS;
1372             }
1373             else
1374             {
1375
1376                 ulCopyLength = *Length - FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
1377
1378                 ntStatus = STATUS_BUFFER_OVERFLOW;
1379             }
1380
1381             Buffer->FileNameLength = DirectoryCB->NameInformation.FileName.Length;
1382
1383             *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
1384
1385             if( ulCopyLength > 0)
1386             {
1387
1388                 RtlCopyMemory( Buffer->FileName,
1389                                DirectoryCB->NameInformation.FileName.Buffer,
1390                                ulCopyLength);
1391
1392                 *Length -= ulCopyLength;
1393             }
1394         }
1395     }
1396     else
1397     {
1398
1399         if( *Length >= (LONG)FIELD_OFFSET( FILE_NAME_INFORMATION, FileName))
1400         {
1401
1402             if( *Length >= (LONG)(FIELD_OFFSET( FILE_NAME_INFORMATION, FileName) + (LONG)DirectoryCB->NameInformation.FileName.Length))
1403             {
1404
1405                 ulCopyLength = (LONG)DirectoryCB->NameInformation.ShortNameLength;
1406
1407                 ntStatus = STATUS_SUCCESS;
1408             }
1409             else
1410             {
1411
1412                 ulCopyLength = *Length - FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
1413
1414                 ntStatus = STATUS_BUFFER_OVERFLOW;
1415             }
1416
1417             Buffer->FileNameLength = DirectoryCB->NameInformation.ShortNameLength;
1418
1419             *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
1420
1421             if( ulCopyLength > 0)
1422             {
1423
1424                 RtlCopyMemory( Buffer->FileName,
1425                                DirectoryCB->NameInformation.ShortName,
1426                                Buffer->FileNameLength);
1427
1428                 *Length -= ulCopyLength;
1429             }
1430         }
1431     }
1432
1433     return ntStatus;
1434 }
1435
1436 NTSTATUS
1437 AFSQueryNetworkInfo( IN PIRP Irp,
1438                      IN AFSDirectoryCB *DirectoryCB,
1439                      IN OUT PFILE_NETWORK_OPEN_INFORMATION Buffer,
1440                      IN OUT PLONG Length)
1441 {
1442
1443     NTSTATUS ntStatus = STATUS_SUCCESS;
1444     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1445     AFSFcb *pFcb = NULL;
1446     AFSCcb *pCcb = NULL;
1447     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1448     AFSFileInfoCB stFileInfo;
1449     AFSDirectoryCB *pParentDirectoryCB = NULL;
1450     UNICODE_STRING uniParentPath;
1451     ULONG ulFileAttribs = 0;
1452
1453     RtlZeroMemory( Buffer,
1454                    *Length);
1455
1456     if( *Length >= sizeof( FILE_NETWORK_OPEN_INFORMATION))
1457     {
1458
1459         ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
1460
1461         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
1462         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1463
1464         if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
1465         {
1466
1467             pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
1468
1469             AFSRetrieveParentPath( &pCcb->FullFileName,
1470                                    &uniParentPath);
1471
1472             RtlZeroMemory( &stFileInfo,
1473                            sizeof( AFSFileInfoCB));
1474
1475             //
1476             // Can't hold the Fcb while evaluating the path, leads to lock inversion
1477             //
1478
1479             AFSReleaseResource( &pFcb->NPFcb->Resource);
1480
1481             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
1482                                                        DirectoryCB,
1483                                                        &uniParentPath,
1484                                                        pCcb->NameArray,
1485                                                        &pCcb->AuthGroup,
1486                                                        &stFileInfo)))
1487             {
1488
1489                 if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
1490                 {
1491
1492                     ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
1493                 }
1494                 else
1495                 {
1496
1497                     ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
1498                 }
1499
1500                 if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1501                 {
1502
1503                     ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
1504                 }
1505             }
1506
1507             AFSAcquireShared( &pFcb->NPFcb->Resource,
1508                               TRUE);
1509         }
1510
1511         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1512                       AFS_TRACE_LEVEL_VERBOSE_2,
1513                       "AFSQueryNetworkInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
1514                       &pCcb->DirectoryCB->NameInformation.FileName,
1515                       pCcb->DirectoryCB->ObjectInformation->FileType,
1516                       pCcb->DirectoryCB->ObjectInformation->FileAttributes,
1517                       ulFileAttribs);
1518
1519         Buffer->CreationTime.QuadPart = DirectoryCB->ObjectInformation->CreationTime.QuadPart;
1520         Buffer->LastAccessTime.QuadPart = DirectoryCB->ObjectInformation->LastAccessTime.QuadPart;
1521         Buffer->LastWriteTime.QuadPart = DirectoryCB->ObjectInformation->LastWriteTime.QuadPart;
1522         Buffer->ChangeTime.QuadPart = DirectoryCB->ObjectInformation->ChangeTime.QuadPart;
1523
1524         Buffer->AllocationSize.QuadPart = DirectoryCB->ObjectInformation->AllocationSize.QuadPart;
1525         Buffer->EndOfFile.QuadPart = DirectoryCB->ObjectInformation->EndOfFile.QuadPart;
1526
1527         Buffer->FileAttributes = ulFileAttribs;
1528
1529         if( DirectoryCB->NameInformation.FileName.Buffer[ 0] == L'.' &&
1530             BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_HIDE_DOT_NAMES))
1531         {
1532
1533             if ( Buffer->FileAttributes != FILE_ATTRIBUTE_NORMAL)
1534             {
1535
1536                 Buffer->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
1537             }
1538             else
1539             {
1540
1541                 Buffer->FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1542             }
1543         }
1544
1545         *Length -= sizeof( FILE_NETWORK_OPEN_INFORMATION);
1546     }
1547     else
1548     {
1549
1550         ntStatus = STATUS_BUFFER_TOO_SMALL;
1551     }
1552
1553     return ntStatus;
1554 }
1555
1556 NTSTATUS
1557 AFSQueryStreamInfo( IN PIRP Irp,
1558                     IN AFSDirectoryCB *DirectoryCB,
1559                     IN OUT FILE_STREAM_INFORMATION *Buffer,
1560                     IN OUT PLONG Length)
1561 {
1562
1563     UNREFERENCED_PARAMETER(Irp);
1564     NTSTATUS ntStatus = STATUS_BUFFER_TOO_SMALL;
1565     ULONG ulCopyLength = 0;
1566
1567     if( *Length >= FIELD_OFFSET( FILE_STREAM_INFORMATION, StreamName))
1568     {
1569
1570         RtlZeroMemory( Buffer,
1571                        *Length);
1572
1573         Buffer->NextEntryOffset = 0;
1574
1575
1576         if( !BooleanFlagOn( DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
1577         {
1578
1579             if( *Length >= (LONG)(FIELD_OFFSET( FILE_STREAM_INFORMATION, StreamName) + 14))  // ::$DATA
1580             {
1581
1582                 ulCopyLength = 14;
1583
1584                 ntStatus = STATUS_SUCCESS;
1585             }
1586             else
1587             {
1588
1589                 ulCopyLength = *Length - FIELD_OFFSET( FILE_STREAM_INFORMATION, StreamName);
1590
1591                 ntStatus = STATUS_BUFFER_OVERFLOW;
1592             }
1593
1594             Buffer->StreamNameLength = 14; // ::$DATA
1595
1596             Buffer->StreamSize.QuadPart = DirectoryCB->ObjectInformation->EndOfFile.QuadPart;
1597
1598             Buffer->StreamAllocationSize.QuadPart = DirectoryCB->ObjectInformation->AllocationSize.QuadPart;
1599
1600             *Length -= FIELD_OFFSET( FILE_STREAM_INFORMATION, StreamName);
1601
1602             if( ulCopyLength > 0)
1603             {
1604
1605                 RtlCopyMemory( Buffer->StreamName,
1606                                L"::$DATA",
1607                                ulCopyLength);
1608
1609                 *Length -= ulCopyLength;
1610             }
1611         }
1612         else
1613         {
1614
1615             Buffer->StreamNameLength = 0;       // No stream for a directory
1616
1617             // The response size is zero
1618
1619             ntStatus = STATUS_SUCCESS;
1620         }
1621     }
1622
1623     return ntStatus;
1624 }
1625
1626 NTSTATUS
1627 AFSQueryAttribTagInfo( IN PIRP Irp,
1628                        IN AFSDirectoryCB *DirectoryCB,
1629                        IN OUT FILE_ATTRIBUTE_TAG_INFORMATION *Buffer,
1630                        IN OUT PLONG Length)
1631 {
1632
1633     NTSTATUS ntStatus = STATUS_BUFFER_TOO_SMALL;
1634     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1635     AFSFcb *pFcb = NULL;
1636     AFSCcb *pCcb = NULL;
1637     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1638     AFSFileInfoCB stFileInfo;
1639     AFSDirectoryCB *pParentDirectoryCB = NULL;
1640     UNICODE_STRING uniParentPath;
1641     ULONG ulFileAttribs = 0;
1642
1643     if( *Length >= sizeof( FILE_ATTRIBUTE_TAG_INFORMATION))
1644     {
1645
1646         RtlZeroMemory( Buffer,
1647                        *Length);
1648
1649         ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
1650
1651         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
1652         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1653
1654         if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
1655         {
1656
1657             pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
1658
1659             AFSRetrieveParentPath( &pCcb->FullFileName,
1660                                    &uniParentPath);
1661
1662             RtlZeroMemory( &stFileInfo,
1663                            sizeof( AFSFileInfoCB));
1664
1665             //
1666             // Can't hold the Fcb while evaluating the path, leads to lock inversion
1667             //
1668
1669             AFSReleaseResource( &pFcb->NPFcb->Resource);
1670
1671             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
1672                                                        DirectoryCB,
1673                                                        &uniParentPath,
1674                                                        pCcb->NameArray,
1675                                                        &pCcb->AuthGroup,
1676                                                        &stFileInfo)))
1677             {
1678
1679                 if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
1680                 {
1681
1682                     ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
1683                 }
1684                 else
1685                 {
1686
1687                     ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
1688                 }
1689
1690                 if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1691                 {
1692
1693                     ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
1694                 }
1695             }
1696
1697             AFSAcquireShared( &pFcb->NPFcb->Resource,
1698                               TRUE);
1699         }
1700
1701         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1702                       AFS_TRACE_LEVEL_VERBOSE_2,
1703                       "AFSAttribTagInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
1704                       &pCcb->DirectoryCB->NameInformation.FileName,
1705                       pCcb->DirectoryCB->ObjectInformation->FileType,
1706                       pCcb->DirectoryCB->ObjectInformation->FileAttributes,
1707                       ulFileAttribs);
1708
1709         Buffer->FileAttributes = ulFileAttribs;
1710
1711         if( DirectoryCB->NameInformation.FileName.Buffer[ 0] == L'.' &&
1712             BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_HIDE_DOT_NAMES))
1713         {
1714
1715             if ( Buffer->FileAttributes != FILE_ATTRIBUTE_NORMAL)
1716             {
1717
1718                 Buffer->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
1719             }
1720             else
1721             {
1722
1723                 Buffer->FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1724             }
1725         }
1726
1727         if( BooleanFlagOn( DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
1728         {
1729             Buffer->ReparseTag = IO_REPARSE_TAG_SURROGATE|IO_REPARSE_TAG_OPENAFS_DFS;
1730         }
1731
1732         *Length -= sizeof( FILE_ATTRIBUTE_TAG_INFORMATION);
1733
1734         ntStatus = STATUS_SUCCESS;
1735     }
1736
1737     return ntStatus;
1738 }
1739
1740 NTSTATUS
1741 AFSQueryRemoteProtocolInfo( IN PIRP Irp,
1742                             IN AFSDirectoryCB *DirectoryCB,
1743                             IN OUT FILE_REMOTE_PROTOCOL_INFORMATION *Buffer,
1744                             IN OUT PLONG Length)
1745 {
1746
1747     UNREFERENCED_PARAMETER(Irp);
1748     UNREFERENCED_PARAMETER(DirectoryCB);
1749     NTSTATUS ntStatus = STATUS_BUFFER_TOO_SMALL;
1750
1751     if( *Length >= sizeof( FILE_REMOTE_PROTOCOL_INFORMATION))
1752     {
1753
1754         RtlZeroMemory( Buffer,
1755                        *Length);
1756
1757         Buffer->StructureVersion = 1;
1758
1759         Buffer->StructureSize = sizeof(FILE_REMOTE_PROTOCOL_INFORMATION);
1760
1761         Buffer->Protocol = WNNC_NET_OPENAFS;
1762
1763         Buffer->ProtocolMajorVersion = 3;
1764
1765         Buffer->ProtocolMinorVersion = 0;
1766
1767         Buffer->ProtocolRevision = 0;
1768
1769         *Length -= sizeof( FILE_REMOTE_PROTOCOL_INFORMATION);
1770
1771         ntStatus = STATUS_SUCCESS;
1772     }
1773
1774     return ntStatus;
1775 }
1776
1777 NTSTATUS
1778 AFSQueryPhysicalNameInfo( IN PIRP Irp,
1779                           IN AFSDirectoryCB *DirectoryCB,
1780                           IN OUT PFILE_NETWORK_PHYSICAL_NAME_INFORMATION Buffer,
1781                           IN OUT PLONG Length)
1782 {
1783
1784     UNREFERENCED_PARAMETER(DirectoryCB);
1785     NTSTATUS ntStatus = STATUS_SUCCESS;
1786     ULONG ulCopyLength = 0;
1787     ULONG cchCopied = 0;
1788     AFSFcb *pFcb = NULL;
1789     AFSCcb *pCcb = NULL;
1790     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1791     BOOLEAN bAddLeadingSlash = FALSE;
1792     USHORT usFullNameLength = 0;
1793
1794     pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
1795
1796     pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1797
1798     if( *Length >= FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName))
1799     {
1800
1801         RtlZeroMemory( Buffer,
1802                        *Length);
1803
1804         if( pCcb->FullFileName.Length == 0 ||
1805             pCcb->FullFileName.Buffer[ 0] != L'\\')
1806         {
1807             bAddLeadingSlash = TRUE;
1808         }
1809
1810         usFullNameLength = pCcb->FullFileName.Length;
1811
1812         if( bAddLeadingSlash)
1813         {
1814             usFullNameLength += sizeof( WCHAR);
1815         }
1816
1817         if( *Length >= (LONG)(FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName) + (LONG)usFullNameLength))
1818         {
1819             ulCopyLength = (LONG)usFullNameLength;
1820         }
1821         else
1822         {
1823
1824             ulCopyLength = *Length - FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName);
1825
1826             ntStatus = STATUS_BUFFER_OVERFLOW;
1827         }
1828
1829         Buffer->FileNameLength = (ULONG)usFullNameLength;
1830
1831         *Length -= FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName);
1832
1833         if( ulCopyLength > 0)
1834         {
1835
1836             if( bAddLeadingSlash)
1837             {
1838
1839                 Buffer->FileName[ cchCopied] = L'\\';
1840
1841                 ulCopyLength -= sizeof( WCHAR);
1842                 *Length -= sizeof( WCHAR);
1843                 cchCopied++;
1844             }
1845
1846             if( ulCopyLength >= pCcb->FullFileName.Length)
1847             {
1848
1849                 RtlCopyMemory( &Buffer->FileName[ cchCopied],
1850                                pCcb->FullFileName.Buffer,
1851                                pCcb->FullFileName.Length);
1852
1853                 ulCopyLength -= pCcb->FullFileName.Length;
1854                 *Length -= pCcb->FullFileName.Length;
1855                 cchCopied += pCcb->FullFileName.Length/sizeof( WCHAR);
1856             }
1857             else
1858             {
1859
1860                 RtlCopyMemory( &Buffer->FileName[ cchCopied],
1861                                pCcb->FullFileName.Buffer,
1862                                ulCopyLength);
1863
1864                 *Length -= ulCopyLength;
1865             }
1866         }
1867     }
1868     else
1869     {
1870
1871         ntStatus = STATUS_BUFFER_TOO_SMALL;
1872     }
1873
1874     return ntStatus;
1875 }
1876
1877 NTSTATUS
1878 AFSSetBasicInfo( IN PIRP Irp,
1879                  IN AFSDirectoryCB *DirectoryCB)
1880 {
1881     NTSTATUS ntStatus = STATUS_SUCCESS;
1882     PFILE_BASIC_INFORMATION pBuffer;
1883     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1884     ULONG ulNotifyFilter = 0;
1885     AFSCcb *pCcb = NULL;
1886
1887     __Enter
1888     {
1889
1890         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
1891
1892         pBuffer = (PFILE_BASIC_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
1893
1894         pCcb->FileUnwindInfo.FileAttributes = (ULONG)-1;
1895
1896         if( pBuffer->FileAttributes != (ULONGLONG)0)
1897         {
1898
1899             if( DirectoryCB->ObjectInformation->Fcb->Header.NodeTypeCode == AFS_FILE_FCB &&
1900                 BooleanFlagOn( pBuffer->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
1901             {
1902
1903                 try_return( ntStatus = STATUS_INVALID_PARAMETER);
1904             }
1905
1906             if( DirectoryCB->ObjectInformation->Fcb->Header.NodeTypeCode == AFS_DIRECTORY_FCB)
1907             {
1908
1909                 pBuffer->FileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
1910             }
1911
1912             pCcb->FileUnwindInfo.FileAttributes = DirectoryCB->ObjectInformation->FileAttributes;
1913
1914             DirectoryCB->ObjectInformation->FileAttributes = pBuffer->FileAttributes;
1915
1916             ulNotifyFilter |= FILE_NOTIFY_CHANGE_ATTRIBUTES;
1917
1918             SetFlag( DirectoryCB->ObjectInformation->Fcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED);
1919         }
1920
1921         pCcb->FileUnwindInfo.CreationTime.QuadPart = (ULONGLONG)-1;
1922
1923         if( pBuffer->CreationTime.QuadPart != (ULONGLONG)-1 &&
1924             pBuffer->CreationTime.QuadPart != (ULONGLONG)0)
1925         {
1926
1927             pCcb->FileUnwindInfo.CreationTime.QuadPart = DirectoryCB->ObjectInformation->CreationTime.QuadPart;
1928
1929             DirectoryCB->ObjectInformation->CreationTime.QuadPart = pBuffer->CreationTime.QuadPart;
1930
1931             ulNotifyFilter |= FILE_NOTIFY_CHANGE_CREATION;
1932
1933             SetFlag( DirectoryCB->ObjectInformation->Fcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED | AFS_FCB_FLAG_UPDATE_CREATE_TIME);
1934         }
1935
1936         pCcb->FileUnwindInfo.LastAccessTime.QuadPart = (ULONGLONG)-1;
1937
1938         if( pBuffer->LastAccessTime.QuadPart != (ULONGLONG)-1 &&
1939             pBuffer->LastAccessTime.QuadPart != (ULONGLONG)0)
1940         {
1941
1942             pCcb->FileUnwindInfo.LastAccessTime.QuadPart = DirectoryCB->ObjectInformation->LastAccessTime.QuadPart;
1943
1944             DirectoryCB->ObjectInformation->LastAccessTime.QuadPart = pBuffer->LastAccessTime.QuadPart;
1945
1946             ulNotifyFilter |= FILE_NOTIFY_CHANGE_LAST_ACCESS;
1947
1948             SetFlag( DirectoryCB->ObjectInformation->Fcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED | AFS_FCB_FLAG_UPDATE_ACCESS_TIME);
1949         }
1950
1951         pCcb->FileUnwindInfo.LastWriteTime.QuadPart = (ULONGLONG)-1;
1952
1953         if( pBuffer->LastWriteTime.QuadPart != (ULONGLONG)-1 &&
1954             pBuffer->LastWriteTime.QuadPart != (ULONGLONG)0)
1955         {
1956
1957             pCcb->FileUnwindInfo.LastWriteTime.QuadPart = DirectoryCB->ObjectInformation->LastWriteTime.QuadPart;
1958
1959             DirectoryCB->ObjectInformation->LastWriteTime.QuadPart = pBuffer->LastWriteTime.QuadPart;
1960
1961             ulNotifyFilter |= FILE_NOTIFY_CHANGE_LAST_WRITE;
1962
1963             SetFlag( DirectoryCB->ObjectInformation->Fcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED | AFS_FCB_FLAG_UPDATE_LAST_WRITE_TIME);
1964         }
1965
1966         pCcb->FileUnwindInfo.ChangeTime.QuadPart = (ULONGLONG)-1;
1967
1968         if( pBuffer->ChangeTime.QuadPart != (ULONGLONG)-1 &&
1969             pBuffer->ChangeTime.QuadPart != (ULONGLONG)0)
1970         {
1971
1972             pCcb->FileUnwindInfo.ChangeTime.QuadPart = DirectoryCB->ObjectInformation->ChangeTime.QuadPart;
1973
1974             DirectoryCB->ObjectInformation->ChangeTime.QuadPart = pBuffer->ChangeTime.QuadPart;
1975
1976             ulNotifyFilter |= FILE_NOTIFY_CHANGE_LAST_ACCESS;
1977
1978             SetFlag( DirectoryCB->ObjectInformation->Fcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED | AFS_FCB_FLAG_UPDATE_CHANGE_TIME);
1979         }
1980
1981         if( ulNotifyFilter > 0)
1982         {
1983
1984             if( BooleanFlagOn( DirectoryCB->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
1985             {
1986
1987                 AFSObjectInfoCB * pParentObjectInfo = AFSFindObjectInfo( DirectoryCB->ObjectInformation->VolumeCB,
1988                                                                          &DirectoryCB->ObjectInformation->ParentFileId);
1989
1990                 if ( pParentObjectInfo != NULL)
1991                 {
1992                     AFSFsRtlNotifyFullReportChange( pParentObjectInfo,
1993                                                     pCcb,
1994                                                     (ULONG)ulNotifyFilter,
1995                                                     (ULONG)FILE_ACTION_MODIFIED);
1996
1997                     AFSReleaseObjectInfo( &pParentObjectInfo);
1998                 }
1999             }
2000         }
2001
2002 try_exit:
2003
2004         NOTHING;
2005     }
2006
2007     return ntStatus;
2008 }
2009
2010 NTSTATUS
2011 AFSSetDispositionInfo( IN PIRP Irp,
2012                        IN AFSDirectoryCB *DirectoryCB)
2013 {
2014     NTSTATUS ntStatus = STATUS_SUCCESS;
2015     PFILE_DISPOSITION_INFORMATION pBuffer;
2016     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
2017     AFSFcb *pFcb = NULL;
2018     AFSCcb *pCcb = NULL;
2019
2020     __Enter
2021     {
2022
2023         pBuffer = (PFILE_DISPOSITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2024
2025         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
2026
2027         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
2028
2029         //
2030         // Can't delete the root
2031         //
2032
2033         if( pFcb->Header.NodeTypeCode == AFS_ROOT_FCB)
2034         {
2035
2036             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2037                           AFS_TRACE_LEVEL_ERROR,
2038                           "AFSSetDispositionInfo Attempt to delete root entry\n");
2039
2040             try_return( ntStatus = STATUS_CANNOT_DELETE);
2041         }
2042
2043         //
2044         // If the file is read only then do not allow the delete
2045         //
2046
2047         if( BooleanFlagOn( DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_READONLY))
2048         {
2049
2050             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2051                           AFS_TRACE_LEVEL_ERROR,
2052                           "AFSSetDispositionInfo Attempt to delete read only entry %wZ\n",
2053                           &DirectoryCB->NameInformation.FileName);
2054
2055             try_return( ntStatus = STATUS_CANNOT_DELETE);
2056         }
2057
2058         if( pBuffer->DeleteFile)
2059         {
2060
2061             //
2062             // Check if the caller can delete the file
2063             //
2064
2065             ntStatus = AFSNotifyDelete( DirectoryCB,
2066                                         &pCcb->AuthGroup,
2067                                         TRUE);
2068
2069             if( !NT_SUCCESS( ntStatus))
2070             {
2071
2072                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2073                               AFS_TRACE_LEVEL_ERROR,
2074                               "AFSSetDispositionInfo Cannot delete entry %wZ Status %08lX\n",
2075                               &DirectoryCB->NameInformation.FileName,
2076                               ntStatus);
2077
2078                 try_return( ntStatus);
2079             }
2080
2081             if( pFcb->Header.NodeTypeCode == AFS_DIRECTORY_FCB)
2082             {
2083
2084                 //
2085                 // Reduce the Link count in the object information block
2086                 // to correspond with the deletion of the directory entry.
2087                 //
2088
2089                 pFcb->ObjectInformation->Links--;
2090
2091                 //
2092                 // Check if this is a directory that there are not currently other opens
2093                 //
2094
2095                 if( pFcb->ObjectInformation->Specific.Directory.ChildOpenHandleCount > 0)
2096                 {
2097
2098                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2099                                   AFS_TRACE_LEVEL_ERROR,
2100                                   "AFSSetDispositionInfo Attempt to delete directory %wZ with open %u handles\n",
2101                                   &DirectoryCB->NameInformation.FileName,
2102                                   pFcb->ObjectInformation->Specific.Directory.ChildOpenHandleCount);
2103
2104                     try_return( ntStatus = STATUS_DIRECTORY_NOT_EMPTY);
2105                 }
2106
2107                 if( !AFSIsDirectoryEmptyForDelete( pFcb))
2108                 {
2109
2110                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2111                                   AFS_TRACE_LEVEL_ERROR,
2112                                   "AFSSetDispositionInfo Attempt to delete non-empty directory %wZ\n",
2113                                   &DirectoryCB->NameInformation.FileName);
2114
2115                     try_return( ntStatus = STATUS_DIRECTORY_NOT_EMPTY);
2116                 }
2117
2118                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2119                               AFS_TRACE_LEVEL_VERBOSE,
2120                               "AFSSetDispositionInfo Setting PENDING_DELETE on DirEntry  %p Name %wZ\n",
2121                               DirectoryCB,
2122                               &DirectoryCB->NameInformation.FileName);
2123
2124                 SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
2125             }
2126             else if( pFcb->Header.NodeTypeCode == AFS_FILE_FCB)
2127             {
2128                 BOOLEAN bMmFlushed;
2129
2130                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
2131                               AFS_TRACE_LEVEL_VERBOSE,
2132                               "AFSSetDispositionInfo Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
2133                               &pFcb->NPFcb->SectionObjectResource,
2134                               PsGetCurrentThread());
2135
2136                 AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
2137                                 TRUE);
2138
2139                 //
2140                 // Attempt to flush any outstanding data
2141                 //
2142
2143                 bMmFlushed = MmFlushImageSection( &pFcb->NPFcb->SectionObjectPointers,
2144                                                   MmFlushForDelete);
2145
2146                 if ( bMmFlushed)
2147                 {
2148
2149                     //
2150                     // Set PENDING_DELETE before CcPurgeCacheSection to avoid a
2151                     // deadlock with Trend Micro's Enterprise anti-virus product
2152                     // which attempts to open the file which is being deleted.
2153                     //
2154
2155                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2156                                   AFS_TRACE_LEVEL_VERBOSE,
2157                                   "AFSSetDispositionInfo Setting PENDING_DELETE on DirEntry %p Name %wZ\n",
2158                                   DirectoryCB,
2159                                   &DirectoryCB->NameInformation.FileName);
2160
2161                     SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
2162
2163                     //
2164                     // Purge the cache as well
2165                     //
2166
2167                     if( pFcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL)
2168                     {
2169
2170                         if ( !CcPurgeCacheSection( &pFcb->NPFcb->SectionObjectPointers,
2171                                                    NULL,
2172                                                    0,
2173                                                    TRUE))
2174                         {
2175
2176                             SetFlag( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
2177                         }
2178                     }
2179                 }
2180
2181                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
2182                               AFS_TRACE_LEVEL_VERBOSE,
2183                               "AFSSetDispositionInfo Releasing Fcb SectionObject lock %p EXCL %08lX\n",
2184                               &pFcb->NPFcb->SectionObjectResource,
2185                               PsGetCurrentThread());
2186
2187                 AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
2188
2189                 if ( !bMmFlushed)
2190                 {
2191
2192                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2193                                   AFS_TRACE_LEVEL_ERROR,
2194                                   "AFSSetDispositionInfo Failed to flush image section for delete Entry %wZ\n",
2195                                   &DirectoryCB->NameInformation.FileName);
2196
2197                     try_return( ntStatus = STATUS_CANNOT_DELETE);
2198                 }
2199             }
2200             else if( pFcb->Header.NodeTypeCode == AFS_SYMBOLIC_LINK_FCB ||
2201                      pFcb->Header.NodeTypeCode == AFS_MOUNT_POINT_FCB ||
2202                      pFcb->Header.NodeTypeCode == AFS_DFS_LINK_FCB ||
2203                      pFcb->Header.NodeTypeCode == AFS_INVALID_FCB)
2204             {
2205
2206                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2207                               AFS_TRACE_LEVEL_VERBOSE,
2208                               "AFSSetDispositionInfo Setting PENDING_DELETE on DirEntry %p Name %wZ\n",
2209                               DirectoryCB,
2210                               &DirectoryCB->NameInformation.FileName);
2211
2212                 SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
2213             }
2214         }
2215         else
2216         {
2217
2218             ClearFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
2219         }
2220
2221         //
2222         // OK, should be good to go, set the flag in the file object
2223         //
2224
2225         pIrpSp->FileObject->DeletePending = pBuffer->DeleteFile;
2226
2227 try_exit:
2228
2229         NOTHING;
2230     }
2231
2232     return ntStatus;
2233 }
2234
2235 NTSTATUS
2236 AFSSetFileLinkInfo( IN PIRP Irp)
2237 {
2238
2239     NTSTATUS ntStatus = STATUS_SUCCESS;
2240     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
2241     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
2242     PFILE_LINK_INFORMATION pFileLinkInfo = NULL;
2243     PFILE_OBJECT pSrcFileObj = NULL;
2244     PFILE_OBJECT pTargetFileObj = pIrpSp->Parameters.SetFile.FileObject;
2245     AFSFcb *pSrcFcb = NULL, *pTargetDcb = NULL;
2246     AFSCcb *pSrcCcb = NULL, *pTargetDirCcb = NULL;
2247     AFSObjectInfoCB *pSrcObject = NULL;
2248     AFSObjectInfoCB *pSrcParentObject = NULL, *pTargetParentObject = NULL;
2249     UNICODE_STRING uniSourceName, uniTargetName;
2250     UNICODE_STRING uniFullTargetName, uniTargetParentName;
2251     BOOLEAN bCommonParent = FALSE;
2252     AFSDirectoryCB *pTargetDirEntry = NULL;
2253     AFSDirectoryCB *pNewTargetDirEntry = NULL;
2254     ULONG ulTargetCRC;
2255     BOOLEAN bTargetEntryExists = FALSE;
2256     LONG lCount;
2257     BOOLEAN bReleaseTargetDirLock = FALSE;
2258     ULONG ulNotificationAction = 0, ulNotifyFilter = 0;
2259
2260     __Enter
2261     {
2262
2263         pSrcFileObj = pIrpSp->FileObject;
2264
2265         pSrcFcb = (AFSFcb *)pSrcFileObj->FsContext;
2266         pSrcCcb = (AFSCcb *)pSrcFileObj->FsContext2;
2267
2268         pSrcObject = pSrcFcb->ObjectInformation;
2269
2270         if ( BooleanFlagOn( pSrcFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
2271         {
2272
2273             pSrcParentObject = AFSFindObjectInfo( pSrcFcb->ObjectInformation->VolumeCB,
2274                                                   &pSrcFcb->ObjectInformation->ParentFileId);
2275         }
2276
2277         pFileLinkInfo = (PFILE_LINK_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2278
2279         //
2280         // Perform some basic checks to ensure FS integrity
2281         //
2282
2283         if( pSrcFcb->Header.NodeTypeCode != AFS_FILE_FCB)
2284         {
2285
2286             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2287                           AFS_TRACE_LEVEL_ERROR,
2288                           "AFSSetFileLinkInfo Attempt to non-file (INVALID_PARAMETER)\n");
2289
2290             try_return( ntStatus = STATUS_INVALID_PARAMETER);
2291         }
2292
2293         if( pTargetFileObj == NULL)
2294         {
2295
2296             if ( pFileLinkInfo->RootDirectory)
2297             {
2298
2299                 //
2300                 // The target directory is provided by HANDLE
2301                 // RootDirectory is only set when the target directory is not the same
2302                 // as the source directory.
2303                 //
2304                 // AFS only supports hard links within a single directory.
2305                 //
2306                 // The IOManager should translate any Handle to a FileObject for us.
2307                 // However, the failure to receive a FileObject is treated as a fatal
2308                 // error.
2309                 //
2310
2311                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2312                               AFS_TRACE_LEVEL_ERROR,
2313                               "AFSSetFileLinkInfo Attempt to link %wZ to alternate directory by handle INVALID_PARAMETER\n",
2314                               &pSrcCcb->DirectoryCB->NameInformation.FileName);
2315
2316                 try_return( ntStatus = STATUS_INVALID_PARAMETER);
2317             }
2318             else
2319             {
2320
2321                 uniFullTargetName.Length = (USHORT)pFileLinkInfo->FileNameLength;
2322
2323                 uniFullTargetName.Buffer = (PWSTR)&pFileLinkInfo->FileName;
2324
2325                 AFSRetrieveFinalComponent( &uniFullTargetName,
2326                                            &uniTargetName);
2327
2328                 AFSRetrieveParentPath( &uniFullTargetName,
2329                                        &uniTargetParentName);
2330
2331                 if ( uniTargetParentName.Length == 0)
2332                 {
2333
2334                     //
2335                     // This is a simple rename. Here the target directory is the same as the source parent directory
2336                     // and the name is retrieved from the system buffer information
2337                     //
2338
2339                     pTargetParentObject = pSrcParentObject;
2340                 }
2341                 else
2342                 {
2343                     //
2344                     // uniTargetParentName contains the directory the renamed object
2345                     // will be moved to.  Must obtain the TargetParentObject.
2346                     //
2347
2348                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2349                                   AFS_TRACE_LEVEL_ERROR,
2350                                   "AFSSetFileLinkInfo Attempt to link  %wZ to alternate directory %wZ (NOT_SAME_DEVICE)\n",
2351                                   &pSrcCcb->DirectoryCB->NameInformation.FileName,
2352                                   &uniFullTargetName);
2353
2354                     try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
2355                 }
2356             }
2357
2358             pTargetDcb = pTargetParentObject->Fcb;
2359         }
2360         else
2361         {
2362
2363             //
2364             // So here we have the target directory taken from the targetfile object
2365             //
2366
2367             pTargetDcb = (AFSFcb *)pTargetFileObj->FsContext;
2368
2369             pTargetDirCcb = (AFSCcb *)pTargetFileObj->FsContext2;
2370
2371             pTargetParentObject = (AFSObjectInfoCB *)pTargetDcb->ObjectInformation;
2372
2373             //
2374             // Grab the target name which we setup in the IRP_MJ_CREATE handler. By how we set this up
2375             // it is only the target component of the rename operation
2376             //
2377
2378             uniTargetName = *((PUNICODE_STRING)&pTargetFileObj->FileName);
2379         }
2380
2381         //
2382         // The quick check to see if they are self linking.
2383         // Do the names match? Only do this where the parent directories are
2384         // the same
2385         //
2386
2387         if( pTargetParentObject == pSrcParentObject)
2388         {
2389
2390             if( FsRtlAreNamesEqual( &uniTargetName,
2391                                     &uniSourceName,
2392                                     FALSE,
2393                                     NULL))
2394             {
2395                 try_return( ntStatus = STATUS_SUCCESS);
2396             }
2397
2398             bCommonParent = TRUE;
2399         }
2400         else
2401         {
2402
2403             //
2404             // We do not allow cross-volume hard links
2405             //
2406
2407             if( pTargetParentObject->VolumeCB != pSrcObject->VolumeCB)
2408             {
2409
2410                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2411                               AFS_TRACE_LEVEL_ERROR,
2412                               "AFSSetFileLinkInfo Attempt to link to different volume %wZ\n",
2413                               &pSrcCcb->DirectoryCB->NameInformation.FileName);
2414
2415                 try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
2416             }
2417         }
2418
2419         ulTargetCRC = AFSGenerateCRC( &uniTargetName,
2420                                       FALSE);
2421
2422         AFSAcquireExcl( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
2423                         TRUE);
2424
2425         bReleaseTargetDirLock = TRUE;
2426
2427         AFSLocateCaseSensitiveDirEntry( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
2428                                         ulTargetCRC,
2429                                         &pTargetDirEntry);
2430
2431         if( pTargetDirEntry == NULL)
2432         {
2433
2434             //
2435             // Missed so perform a case insensitive lookup
2436             //
2437
2438             ulTargetCRC = AFSGenerateCRC( &uniTargetName,
2439                                           TRUE);
2440
2441             AFSLocateCaseInsensitiveDirEntry( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
2442                                               ulTargetCRC,
2443                                               &pTargetDirEntry);
2444         }
2445
2446         if ( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
2447              pTargetDirEntry == NULL && RtlIsNameLegalDOS8Dot3( &uniTargetName,
2448                                                                 NULL,
2449                                                                 NULL))
2450         {
2451             //
2452             // Try the short name
2453             //
2454             AFSLocateShortNameDirEntry( pTargetParentObject->Specific.Directory.ShortNameTree,
2455                                         ulTargetCRC,
2456                                         &pTargetDirEntry);
2457         }
2458
2459         //
2460         // Increment our ref count on the dir entry
2461         //
2462
2463         if( pTargetDirEntry != NULL)
2464         {
2465
2466             ASSERT( BooleanFlagOn( pTargetDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID) &&
2467                     AFSIsEqualFID( &pTargetParentObject->FileId, &pTargetDirEntry->ObjectInformation->ParentFileId));
2468
2469             lCount = InterlockedIncrement( &pTargetDirEntry->DirOpenReferenceCount);
2470
2471             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2472                           AFS_TRACE_LEVEL_VERBOSE,
2473                           "AFSSetFileLinkInfo Increment count on %wZ DE %p Ccb %p Cnt %d\n",
2474                           &pTargetDirEntry->NameInformation.FileName,
2475                           pTargetDirEntry,
2476                           pSrcCcb,
2477                           lCount);
2478
2479             ASSERT( lCount >= 0);
2480
2481             if( !pFileLinkInfo->ReplaceIfExists)
2482             {
2483
2484                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2485                               AFS_TRACE_LEVEL_ERROR,
2486                               "AFSSetFileLinkInfo Attempt to link with target collision %wZ Target %wZ\n",
2487                               &pSrcCcb->DirectoryCB->NameInformation.FileName,
2488                               &pTargetDirEntry->NameInformation.FileName);
2489
2490                 try_return( ntStatus = STATUS_OBJECT_NAME_COLLISION);
2491             }
2492
2493             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2494                           AFS_TRACE_LEVEL_ERROR,
2495                           "AFSSetFileLinkInfo Target %wZ exists DE %p Count %d, performing delete of target\n",
2496                           &pTargetDirEntry->NameInformation.FileName,
2497                           pTargetDirEntry,
2498                           lCount);
2499
2500             //
2501             // Pull the directory entry from the parent
2502             //
2503
2504             AFSRemoveDirNodeFromParent( pTargetParentObject,
2505                                         pTargetDirEntry,
2506                                         FALSE);
2507
2508             bTargetEntryExists = TRUE;
2509         }
2510         else
2511         {
2512             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2513                           AFS_TRACE_LEVEL_VERBOSE,
2514                           "AFSSetFileLinkInfo Target does NOT exist, normal linking\n");
2515         }
2516
2517         //
2518         // OK, this is a simple rename. Issue the rename
2519         // request to the service.
2520         //
2521
2522         ntStatus = AFSNotifyHardLink( pSrcFcb->ObjectInformation,
2523                                       &pSrcCcb->AuthGroup,
2524                                       pSrcParentObject,
2525                                       pTargetDcb->ObjectInformation,
2526                                       pSrcCcb->DirectoryCB,
2527                                       &uniTargetName,
2528                                       pFileLinkInfo->ReplaceIfExists,
2529                                       &pNewTargetDirEntry);
2530
2531         if( ntStatus != STATUS_REPARSE &&
2532             !NT_SUCCESS( ntStatus))
2533         {
2534
2535             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2536                           AFS_TRACE_LEVEL_ERROR,
2537                           "AFSSetFileLinkInfo Failed link of %wZ to target %wZ Status %08lX\n",
2538                           &pSrcCcb->DirectoryCB->NameInformation.FileName,
2539                           &uniTargetName,
2540                           ntStatus);
2541
2542             try_return( ntStatus);
2543         }
2544
2545         if ( ntStatus != STATUS_REPARSE)
2546         {
2547
2548             AFSInsertDirectoryNode( pTargetDcb->ObjectInformation,
2549                                     pNewTargetDirEntry,
2550                                     TRUE);
2551         }
2552
2553         //
2554         // Send notification for the target link file
2555         //
2556
2557         if( bTargetEntryExists || pNewTargetDirEntry)
2558         {
2559
2560             ulNotificationAction = FILE_ACTION_MODIFIED;
2561         }
2562         else
2563         {
2564
2565             ulNotificationAction = FILE_ACTION_ADDED;
2566         }
2567
2568         AFSFsRtlNotifyFullReportChange( pTargetParentObject,
2569                                         pSrcCcb,
2570                                         (ULONG)ulNotifyFilter,
2571                                         (ULONG)ulNotificationAction);
2572
2573       try_exit:
2574
2575         if( !NT_SUCCESS( ntStatus))
2576         {
2577
2578             if( bTargetEntryExists)
2579             {
2580
2581                 AFSInsertDirectoryNode( pTargetParentObject,
2582                                         pTargetDirEntry,
2583                                         FALSE);
2584             }
2585         }
2586
2587         if( pTargetDirEntry != NULL)
2588         {
2589
2590             //
2591             // Release DirOpenReferenceCount obtained above
2592             //
2593
2594             lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
2595
2596             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2597                           AFS_TRACE_LEVEL_VERBOSE,
2598                           "AFSSetFileLinkInfo Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
2599                           &pTargetDirEntry->NameInformation.FileName,
2600                           pTargetDirEntry,
2601                           pSrcCcb,
2602                           lCount);
2603
2604             ASSERT( lCount >= 0);
2605         }
2606
2607         if( pNewTargetDirEntry != NULL)
2608         {
2609
2610             //
2611             // Release DirOpenReferenceCount obtained from AFSNotifyHardLink
2612             //
2613
2614             lCount = InterlockedDecrement( &pNewTargetDirEntry->DirOpenReferenceCount);
2615
2616             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2617                           AFS_TRACE_LEVEL_VERBOSE,
2618                           "AFSSetFileLinkInfo Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
2619                           &pNewTargetDirEntry->NameInformation.FileName,
2620                           pNewTargetDirEntry,
2621                           pSrcCcb,
2622                           lCount);
2623
2624             ASSERT( lCount >= 0);
2625         }
2626
2627         if( bReleaseTargetDirLock)
2628         {
2629
2630             AFSReleaseResource( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
2631         }
2632
2633         if ( pSrcParentObject != NULL)
2634         {
2635
2636             AFSReleaseObjectInfo( &pSrcParentObject);
2637         }
2638
2639         //
2640         // No need to release pTargetParentObject as it is either a copy of pSrcParentObject
2641         // or (AFSFcb *)pTargetFileObj->FsContext->ObjectInformation
2642         //
2643
2644         pTargetParentObject = NULL;
2645     }
2646
2647     return ntStatus;
2648 }
2649
2650 NTSTATUS
2651 AFSSetRenameInfo( IN PIRP Irp)
2652 {
2653
2654     NTSTATUS ntStatus = STATUS_SUCCESS;
2655     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
2656     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
2657     AFSFcb *pSrcFcb = NULL, *pTargetDcb = NULL, *pTargetFcb = NULL;
2658     AFSCcb *pSrcCcb = NULL, *pTargetDirCcb = NULL;
2659     PFILE_OBJECT pSrcFileObj = pIrpSp->FileObject;
2660     PFILE_OBJECT pTargetFileObj = pIrpSp->Parameters.SetFile.FileObject;
2661     PFILE_OBJECT pTargetParentFileObj = NULL;
2662     PFILE_RENAME_INFORMATION pRenameInfo = NULL;
2663     UNICODE_STRING uniTargetName, uniSourceName, uniTargetParentName;
2664     BOOLEAN bReplaceIfExists = FALSE;
2665     UNICODE_STRING uniShortName;
2666     AFSDirectoryCB *pTargetDirEntry = NULL;
2667     ULONG ulTargetCRC = 0;
2668     BOOLEAN bTargetEntryExists = FALSE;
2669     AFSObjectInfoCB *pSrcObject = NULL;
2670     AFSObjectInfoCB *pSrcParentObject = NULL, *pTargetParentObject = NULL;
2671     AFSFileID stNewFid;
2672     ULONG ulNotificationAction = 0, ulNotifyFilter = 0;
2673     UNICODE_STRING uniFullTargetName;
2674     BOOLEAN bCommonParent = FALSE;
2675     BOOLEAN bReleaseTargetDirLock = FALSE;
2676     BOOLEAN bReleaseSourceDirLock = FALSE;
2677     BOOLEAN bDereferenceTargetParentObject = FALSE;
2678     PERESOURCE  pSourceDirLock = NULL;
2679     LONG lCount;
2680
2681     __Enter
2682     {
2683
2684         bReplaceIfExists = pIrpSp->Parameters.SetFile.ReplaceIfExists;
2685
2686         pRenameInfo = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2687
2688         pSrcFcb = (AFSFcb *)pSrcFileObj->FsContext;
2689         pSrcCcb = (AFSCcb *)pSrcFileObj->FsContext2;
2690
2691         pSrcObject = pSrcFcb->ObjectInformation;
2692
2693         if ( BooleanFlagOn( pSrcFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
2694         {
2695
2696             pSrcParentObject = AFSFindObjectInfo( pSrcFcb->ObjectInformation->VolumeCB,
2697                                                   &pSrcFcb->ObjectInformation->ParentFileId);
2698         }
2699
2700         //
2701         // Perform some basic checks to ensure FS integrity
2702         //
2703
2704         if( pSrcFcb->Header.NodeTypeCode == AFS_ROOT_FCB)
2705         {
2706
2707             //
2708             // Can't rename the root directory
2709             //
2710
2711             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2712                           AFS_TRACE_LEVEL_ERROR,
2713                           "AFSSetRenameInfo Attempt to rename root entry\n");
2714
2715             try_return( ntStatus = STATUS_INVALID_PARAMETER);
2716         }
2717
2718         if( pSrcFcb->Header.NodeTypeCode == AFS_DIRECTORY_FCB)
2719         {
2720
2721             //
2722             // If there are any open children then fail the rename
2723             //
2724
2725             if( pSrcFcb->ObjectInformation->Specific.Directory.ChildOpenHandleCount > 0)
2726             {
2727
2728                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2729                               AFS_TRACE_LEVEL_ERROR,
2730                               "AFSSetRenameInfo Attempt to rename directory with open children %wZ\n",
2731                               &pSrcCcb->DirectoryCB->NameInformation.FileName);
2732
2733                 try_return( ntStatus = STATUS_ACCESS_DENIED);
2734             }
2735         }
2736
2737
2738         //
2739         // Extract off the final component name from the Fcb
2740         //
2741
2742         uniSourceName.Length = (USHORT)pSrcCcb->DirectoryCB->NameInformation.FileName.Length;
2743         uniSourceName.MaximumLength = uniSourceName.Length;
2744
2745         uniSourceName.Buffer = pSrcCcb->DirectoryCB->NameInformation.FileName.Buffer;
2746
2747         //
2748         // Resolve the target fileobject
2749         //
2750
2751         if( pTargetFileObj == NULL)
2752         {
2753
2754             if ( pRenameInfo->RootDirectory)
2755             {
2756
2757                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2758                               AFS_TRACE_LEVEL_ERROR,
2759                               "AFSSetRenameInfo Handle provided but no FileObject ntStatus INVALID_PARAMETER\n");
2760
2761                 try_return( ntStatus = STATUS_INVALID_PARAMETER);
2762             }
2763             else
2764             {
2765
2766                 uniFullTargetName.Length = (USHORT)pRenameInfo->FileNameLength;
2767
2768                 uniFullTargetName.Buffer = (PWSTR)&pRenameInfo->FileName;
2769
2770                 AFSRetrieveFinalComponent( &uniFullTargetName,
2771                                            &uniTargetName);
2772
2773                 AFSRetrieveParentPath( &uniFullTargetName,
2774                                        &uniTargetParentName);
2775
2776                 if ( uniTargetParentName.Length == 0)
2777                 {
2778
2779                     //
2780                     // This is a simple rename. Here the target directory is the same as the source parent directory
2781                     // and the name is retrieved from the system buffer information
2782                     //
2783
2784                     pTargetParentObject = pSrcParentObject;
2785                 }
2786                 else
2787                 {
2788                     //
2789                     // uniTargetParentName contains the directory the renamed object
2790                     // will be moved to.  Must obtain the TargetParentObject.
2791                     //
2792
2793                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2794                                   AFS_TRACE_LEVEL_ERROR,
2795                                   "AFSSetRenameInfo Attempt to move %wZ to %wZ -- not yet supported (NOT_SAME_DEVICE)\n",
2796                                   &pSrcCcb->DirectoryCB->NameInformation.FileName,
2797                                   &uniFullTargetName);
2798
2799                     try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
2800                 }
2801             }
2802
2803             pTargetDcb = pTargetParentObject->Fcb;
2804         }
2805         else
2806         {
2807
2808             //
2809             // So here we have the target directory taken from the targetfile object
2810             //
2811
2812             pTargetDcb = (AFSFcb *)pTargetFileObj->FsContext;
2813
2814             pTargetDirCcb = (AFSCcb *)pTargetFileObj->FsContext2;
2815
2816             pTargetParentObject = (AFSObjectInfoCB *)pTargetDcb->ObjectInformation;
2817
2818             //
2819             // Grab the target name which we setup in the IRP_MJ_CREATE handler. By how we set this up
2820             // it is only the target component of the rename operation
2821             //
2822
2823             uniTargetName = *((PUNICODE_STRING)&pTargetFileObj->FileName);
2824         }
2825
2826         //
2827         // The quick check to see if they are not really performing a rename
2828         // Do the names match? Only do this where the parent directories are
2829         // the same
2830         //
2831
2832         if( pTargetParentObject == pSrcParentObject)
2833         {
2834
2835             if( FsRtlAreNamesEqual( &uniTargetName,
2836                                     &uniSourceName,
2837                                     FALSE,
2838                                     NULL))
2839             {
2840                 try_return( ntStatus = STATUS_SUCCESS);
2841             }
2842
2843             bCommonParent = TRUE;
2844         }
2845         else
2846         {
2847
2848             bCommonParent = FALSE;
2849         }
2850
2851         //
2852         // We do not allow cross-volume renames to occur
2853         //
2854
2855         if( pTargetParentObject->VolumeCB != pSrcObject->VolumeCB)
2856         {
2857
2858             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2859                           AFS_TRACE_LEVEL_ERROR,
2860                           "AFSSetRenameInfo Attempt to rename directory to different volume %wZ\n",
2861                           &pSrcCcb->DirectoryCB->NameInformation.FileName);
2862
2863             try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
2864         }
2865
2866         ulTargetCRC = AFSGenerateCRC( &uniTargetName,
2867                                       FALSE);
2868
2869         AFSAcquireExcl( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
2870                         TRUE);
2871
2872         bReleaseTargetDirLock = TRUE;
2873
2874         if( pTargetParentObject != pSrcParentObject)
2875         {
2876             AFSAcquireExcl( pSrcParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
2877                             TRUE);
2878
2879             bReleaseSourceDirLock = TRUE;
2880
2881             pSourceDirLock = pSrcParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock;
2882         }
2883
2884         AFSLocateCaseSensitiveDirEntry( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
2885                                         ulTargetCRC,
2886                                         &pTargetDirEntry);
2887
2888         if( pTargetDirEntry == NULL)
2889         {
2890
2891             //
2892             // Missed so perform a case insensitive lookup
2893             //
2894
2895             ulTargetCRC = AFSGenerateCRC( &uniTargetName,
2896                                           TRUE);
2897
2898             AFSLocateCaseInsensitiveDirEntry( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
2899                                               ulTargetCRC,
2900                                               &pTargetDirEntry);
2901         }
2902
2903         if ( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
2904              pTargetDirEntry == NULL && RtlIsNameLegalDOS8Dot3( &uniTargetName,
2905                                                                NULL,
2906                                                                NULL))
2907         {
2908             //
2909             // Try the short name
2910             //
2911             AFSLocateShortNameDirEntry( pTargetParentObject->Specific.Directory.ShortNameTree,
2912                                         ulTargetCRC,
2913                                         &pTargetDirEntry);
2914         }
2915
2916         //
2917         // Increment our ref count on the dir entry
2918         //
2919
2920         if( pTargetDirEntry != NULL)
2921         {
2922
2923             ASSERT( BooleanFlagOn( pTargetDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID) &&
2924                     AFSIsEqualFID( &pTargetParentObject->FileId, &pTargetDirEntry->ObjectInformation->ParentFileId));
2925
2926             lCount = InterlockedIncrement( &pTargetDirEntry->DirOpenReferenceCount);
2927
2928             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2929                           AFS_TRACE_LEVEL_VERBOSE,
2930                           "AFSSetRenameInfo Increment count on %wZ DE %p Ccb %p Cnt %d\n",
2931                           &pTargetDirEntry->NameInformation.FileName,
2932                           pTargetDirEntry,
2933                           pSrcCcb,
2934                           lCount);
2935
2936             ASSERT( lCount >= 0);
2937
2938             if( !bReplaceIfExists)
2939             {
2940
2941                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2942                               AFS_TRACE_LEVEL_ERROR,
2943                               "AFSSetRenameInfo Attempt to rename directory with target collision %wZ Target %wZ\n",
2944                               &pSrcCcb->DirectoryCB->NameInformation.FileName,
2945                               &pTargetDirEntry->NameInformation.FileName);
2946
2947                 try_return( ntStatus = STATUS_OBJECT_NAME_COLLISION);
2948             }
2949
2950             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
2951                           AFS_TRACE_LEVEL_ERROR,
2952                           "AFSSetRenameInfo Target %wZ exists DE %p Count %d, performing delete of target\n",
2953                           &pTargetDirEntry->NameInformation.FileName,
2954                           pTargetDirEntry,
2955                           lCount);
2956
2957             //
2958             // Pull the directory entry from the parent
2959             //
2960
2961             AFSRemoveDirNodeFromParent( pTargetParentObject,
2962                                         pTargetDirEntry,
2963                                         FALSE);
2964
2965             bTargetEntryExists = TRUE;
2966         }
2967         else
2968         {
2969             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2970                           AFS_TRACE_LEVEL_VERBOSE,
2971                           "AFSSetRenameInfo Target does NOT exist, normal rename\n");
2972         }
2973
2974         //
2975         // We need to remove the DirEntry from the parent node, update the index
2976         // and reinsert it into the parent tree. Note that for entries with the
2977         // same parent we do not pull the node from the enumeration list
2978         //
2979
2980         AFSRemoveDirNodeFromParent( pSrcParentObject,
2981                                     pSrcCcb->DirectoryCB,
2982                                     !bCommonParent);
2983
2984         //
2985         // OK, this is a simple rename. Issue the rename
2986         // request to the service.
2987         //
2988
2989         ntStatus = AFSNotifyRename( pSrcFcb->ObjectInformation,
2990                                     &pSrcCcb->AuthGroup,
2991                                     pSrcParentObject,
2992                                     pTargetDcb->ObjectInformation,
2993                                     pSrcCcb->DirectoryCB,
2994                                     &uniTargetName,
2995                                     &stNewFid);
2996
2997         if( !NT_SUCCESS( ntStatus))
2998         {
2999
3000             //
3001             // Attempt to re-insert the directory entry
3002             //
3003
3004             AFSInsertDirectoryNode( pSrcParentObject,
3005                                     pSrcCcb->DirectoryCB,
3006                                     !bCommonParent);
3007
3008             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3009                           AFS_TRACE_LEVEL_ERROR,
3010                           "AFSSetRenameInfo Failed rename of %wZ to target %wZ Status %08lX\n",
3011                           &pSrcCcb->DirectoryCB->NameInformation.FileName,
3012                           &uniTargetName,
3013                           ntStatus);
3014
3015             try_return( ntStatus);
3016         }
3017
3018         //
3019         // Set the notification up for the source file
3020         //
3021
3022         if( pSrcParentObject == pTargetParentObject &&
3023             !bTargetEntryExists)
3024         {
3025
3026             ulNotificationAction = FILE_ACTION_RENAMED_OLD_NAME;
3027         }
3028         else
3029         {
3030
3031             ulNotificationAction = FILE_ACTION_REMOVED;
3032         }
3033
3034         if( pSrcCcb->DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY)
3035         {
3036
3037             ulNotifyFilter = FILE_NOTIFY_CHANGE_DIR_NAME;
3038         }
3039         else
3040         {
3041
3042             ulNotifyFilter = FILE_NOTIFY_CHANGE_FILE_NAME;
3043         }
3044
3045         AFSFsRtlNotifyFullReportChange( pSrcParentObject,
3046                                         pSrcCcb,
3047                                         (ULONG)ulNotifyFilter,
3048                                         (ULONG)ulNotificationAction);
3049
3050         //
3051         // Update the name in the dir entry.
3052         //
3053
3054         ntStatus = AFSUpdateDirEntryName( pSrcCcb->DirectoryCB,
3055                                           &uniTargetName);
3056
3057         if( !NT_SUCCESS( ntStatus))
3058         {
3059
3060             //
3061             // Attempt to re-insert the directory entry
3062             //
3063
3064             AFSInsertDirectoryNode( pSrcParentObject,
3065                                     pSrcCcb->DirectoryCB,
3066                                     !bCommonParent);
3067
3068             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3069                           AFS_TRACE_LEVEL_ERROR,
3070                           "AFSSetRenameInfo Failed update of dir entry %wZ to target %wZ Status %08lX\n",
3071                           &pSrcCcb->DirectoryCB->NameInformation.FileName,
3072                           &uniTargetName,
3073                           ntStatus);
3074
3075             try_return( ntStatus);
3076         }
3077
3078         //
3079         // Update the object information block, if needed
3080         //
3081
3082         if( !AFSIsEqualFID( &pSrcObject->FileId,
3083                             &stNewFid))
3084         {
3085
3086             AFSAcquireExcl( pSrcObject->VolumeCB->ObjectInfoTree.TreeLock,
3087                             TRUE);
3088
3089             //
3090             // Remove the old information entry
3091             //
3092
3093             AFSRemoveHashEntry( &pSrcObject->VolumeCB->ObjectInfoTree.TreeHead,
3094                                 &pSrcObject->TreeEntry);
3095
3096             RtlCopyMemory( &pSrcObject->FileId,
3097                            &stNewFid,
3098                            sizeof( AFSFileID));
3099
3100             //
3101             // Insert the entry into the new object table.
3102             //
3103
3104             pSrcObject->TreeEntry.HashIndex = AFSCreateLowIndex( &pSrcObject->FileId);
3105
3106             if( pSrcObject->VolumeCB->ObjectInfoTree.TreeHead == NULL)
3107             {
3108
3109                 pSrcObject->VolumeCB->ObjectInfoTree.TreeHead = &pSrcObject->TreeEntry;
3110             }
3111             else
3112             {
3113
3114                 if ( !NT_SUCCESS( AFSInsertHashEntry( pSrcObject->VolumeCB->ObjectInfoTree.TreeHead,
3115                                                      &pSrcObject->TreeEntry)))
3116                 {
3117
3118                     //
3119                     // Lost a race, an ObjectInfo object already exists for this FID.
3120                     // Let this copy be garbage collected.
3121                     //
3122
3123                     ClearFlag( pSrcObject->Flags, AFS_OBJECT_INSERTED_HASH_TREE);
3124                 }
3125             }
3126
3127             AFSReleaseResource( pSrcObject->VolumeCB->ObjectInfoTree.TreeLock);
3128         }
3129
3130         //
3131         // Update the hash values for the name trees.
3132         //
3133
3134         pSrcCcb->DirectoryCB->CaseSensitiveTreeEntry.HashIndex = AFSGenerateCRC( &pSrcCcb->DirectoryCB->NameInformation.FileName,
3135                                                                                  FALSE);
3136
3137         pSrcCcb->DirectoryCB->CaseInsensitiveTreeEntry.HashIndex = AFSGenerateCRC( &pSrcCcb->DirectoryCB->NameInformation.FileName,
3138                                                                                    TRUE);
3139
3140         if( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
3141             pSrcCcb->DirectoryCB->NameInformation.ShortNameLength > 0 &&
3142             !RtlIsNameLegalDOS8Dot3( &pSrcCcb->DirectoryCB->NameInformation.FileName,
3143                                      NULL,
3144                                      NULL))
3145         {
3146
3147             uniShortName.Length = pSrcCcb->DirectoryCB->NameInformation.ShortNameLength;
3148             uniShortName.MaximumLength = uniShortName.Length;
3149             uniShortName.Buffer = pSrcCcb->DirectoryCB->NameInformation.ShortName;
3150
3151             pSrcCcb->DirectoryCB->Type.Data.ShortNameTreeEntry.HashIndex = AFSGenerateCRC( &uniShortName,
3152                                                                                            TRUE);
3153
3154             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
3155                           AFS_TRACE_LEVEL_VERBOSE,
3156                           "AFSSetRenameInfo Initialized short name hash for %wZ longname %wZ\n",
3157                           &uniShortName,
3158                           &pSrcCcb->DirectoryCB->NameInformation.FileName);
3159         }
3160         else
3161         {
3162
3163             pSrcCcb->DirectoryCB->Type.Data.ShortNameTreeEntry.HashIndex = 0;
3164         }
3165
3166         if( !bCommonParent)
3167         {
3168
3169             //
3170             // Update the file index for the object in the new parent
3171             //
3172
3173             pSrcCcb->DirectoryCB->FileIndex = (ULONG)InterlockedIncrement( &pTargetParentObject->Specific.Directory.DirectoryNodeHdr.ContentIndex);
3174         }
3175
3176         //
3177         // Re-insert the directory entry
3178         //
3179
3180         AFSInsertDirectoryNode( pTargetParentObject,
3181                                 pSrcCcb->DirectoryCB,
3182                                 !bCommonParent);
3183
3184         //
3185         // Update the parent pointer in the source object if they are different
3186         //
3187
3188         if( pSrcParentObject != pTargetParentObject)
3189         {
3190
3191             lCount = InterlockedDecrement( &pSrcParentObject->Specific.Directory.ChildOpenHandleCount);
3192
3193             lCount = InterlockedDecrement( &pSrcParentObject->Specific.Directory.ChildOpenReferenceCount);
3194
3195             lCount = InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenHandleCount);
3196
3197             lCount = InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenReferenceCount);
3198
3199             lCount = AFSObjectInfoIncrement( pTargetParentObject,
3200                                              AFS_OBJECT_REFERENCE_CHILD);
3201
3202             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
3203                           AFS_TRACE_LEVEL_VERBOSE,
3204                           "AFSSetRenameInfo Increment count on parent object %p Cnt %d\n",
3205                           pTargetParentObject,
3206                           lCount);
3207
3208             lCount = AFSObjectInfoDecrement( pSrcParentObject,
3209                                              AFS_OBJECT_REFERENCE_CHILD);
3210
3211             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
3212                           AFS_TRACE_LEVEL_VERBOSE,
3213                           "AFSSetRenameInfo Decrement count on parent object %p Cnt %d\n",
3214                           pSrcParentObject,
3215                           lCount);
3216
3217             pSrcCcb->DirectoryCB->ObjectInformation->ParentFileId = pTargetParentObject->FileId;
3218
3219             SetFlag( pSrcCcb->DirectoryCB->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID);
3220
3221             pSrcParentObject = pTargetParentObject;
3222
3223             ulNotificationAction = FILE_ACTION_ADDED;
3224         }
3225         else