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