Windows: More specific error values
[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
2087     __Enter
2088     {
2089
2090         bReplaceIfExists = pIrpSp->Parameters.SetFile.ReplaceIfExists;
2091
2092         pSrcFcb = (AFSFcb *)pSrcFileObj->FsContext;
2093         pSrcCcb = (AFSCcb *)pSrcFileObj->FsContext2;
2094
2095         pSrcObject = pSrcFcb->ObjectInformation;
2096
2097         //
2098         // Perform some basic checks to ensure FS integrity
2099         //
2100
2101         if( pSrcFcb->Header.NodeTypeCode == AFS_ROOT_FCB)
2102         {
2103
2104             //
2105             // Can't rename the root directory
2106             //
2107
2108             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2109                           AFS_TRACE_LEVEL_ERROR,
2110                           "AFSSetRenameInfo Attempt to rename root entry\n");
2111
2112             try_return( ntStatus = STATUS_INVALID_PARAMETER);
2113         }
2114
2115         if( pSrcFcb->Header.NodeTypeCode == AFS_DIRECTORY_FCB)
2116         {
2117
2118             //
2119             // If there are any open children then fail the rename
2120             //
2121
2122             if( pSrcFcb->ObjectInformation->Specific.Directory.ChildOpenHandleCount > 0)
2123             {
2124
2125                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2126                               AFS_TRACE_LEVEL_ERROR,
2127                               "AFSSetRenameInfo Attempt to rename directory with open children %wZ\n",
2128                               &pSrcCcb->DirectoryCB->NameInformation.FileName);
2129
2130                 try_return( ntStatus = STATUS_ACCESS_DENIED);
2131             }
2132         }
2133         else
2134         {
2135
2136             if( pSrcFcb->OpenHandleCount > 1)
2137             {
2138
2139                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2140                               AFS_TRACE_LEVEL_ERROR,
2141                               "AFSSetRenameInfo Attempt to rename directory with open references %wZ\n",
2142                               &pSrcCcb->DirectoryCB->NameInformation.FileName);
2143
2144                 try_return( ntStatus = STATUS_ACCESS_DENIED);
2145             }
2146         }
2147
2148         //
2149         // Resolve the target fileobject
2150         //
2151
2152         if( pTargetFileObj == NULL)
2153         {
2154
2155             //
2156             // This is a simple rename. Here the target directory is the same as the source parent directory
2157             // and the name is retrieved from the system buffer information
2158             //
2159
2160             pRenameInfo = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2161
2162             pTargetParentObject = pSrcFcb->ObjectInformation->ParentObjectInformation;
2163
2164             pTargetDcb = pTargetParentObject->Fcb;
2165
2166             uniTargetName.Length = (USHORT)pRenameInfo->FileNameLength;
2167             uniTargetName.Buffer = (PWSTR)&pRenameInfo->FileName;
2168         }
2169         else
2170         {
2171
2172             //
2173             // So here we have the target directory taken from the targetfile object
2174             //
2175
2176             pTargetDcb = (AFSFcb *)pTargetFileObj->FsContext;
2177
2178             pTargetDirCcb = (AFSCcb *)pTargetFileObj->FsContext2;
2179
2180             pTargetParentObject = (AFSObjectInfoCB *)pTargetDcb->ObjectInformation;
2181
2182             //
2183             // Grab the target name which we setup in the IRP_MJ_CREATE handler. By how we set this up
2184             // it is only the target component of the rename operation
2185             //
2186
2187             uniTargetName = *((PUNICODE_STRING)&pTargetFileObj->FileName);
2188         }
2189
2190         //
2191         // We do not allow cross-volume renames to occur
2192         //
2193
2194         if( pTargetParentObject->VolumeCB != pSrcObject->VolumeCB)
2195         {
2196
2197             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2198                           AFS_TRACE_LEVEL_ERROR,
2199                           "AFSSetRenameInfo Attempt to rename directory to different volume %wZ\n",
2200                           &pSrcCcb->DirectoryCB->NameInformation.FileName);
2201
2202             try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
2203         }
2204
2205         ulTargetCRC = AFSGenerateCRC( &uniTargetName,
2206                                       FALSE);
2207
2208         AFSAcquireExcl( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
2209                         TRUE);
2210
2211         bReleaseTargetDirLock = TRUE;
2212
2213         if( pTargetParentObject != pSrcFcb->ObjectInformation->ParentObjectInformation)
2214         {
2215             AFSAcquireExcl( pSrcFcb->ObjectInformation->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
2216                             TRUE);
2217
2218             bReleaseSourceDirLock = TRUE;
2219
2220             pSourceDirLock = pSrcFcb->ObjectInformation->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock;
2221         }
2222
2223         AFSLocateCaseSensitiveDirEntry( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
2224                                         ulTargetCRC,
2225                                         &pTargetDirEntry);
2226
2227         if( pTargetDirEntry == NULL)
2228         {
2229
2230             //
2231             // Missed so perform a case insensitive lookup
2232             //
2233
2234             ulTargetCRC = AFSGenerateCRC( &uniTargetName,
2235                                           TRUE);
2236
2237             AFSLocateCaseInsensitiveDirEntry( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
2238                                               ulTargetCRC,
2239                                               &pTargetDirEntry);
2240         }
2241
2242         if( pTargetDirEntry == NULL && RtlIsNameLegalDOS8Dot3( &uniTargetName,
2243                                                                NULL,
2244                                                                NULL))
2245         {
2246             //
2247             // Try the short name
2248             //
2249             AFSLocateShortNameDirEntry( pTargetParentObject->Specific.Directory.ShortNameTree,
2250                                         ulTargetCRC,
2251                                         &pTargetDirEntry);
2252         }
2253
2254         //
2255         // Increment our ref count on the dir entry
2256         //
2257
2258         if( pTargetDirEntry != NULL)
2259         {
2260
2261             ASSERT( pTargetParentObject == pTargetDirEntry->ObjectInformation->ParentObjectInformation);
2262
2263             InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
2264
2265             if( !bReplaceIfExists)
2266             {
2267
2268                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2269                               AFS_TRACE_LEVEL_ERROR,
2270                               "AFSSetRenameInfo Attempt to rename directory with target collision %wZ Target %wZ\n",
2271                               &pSrcCcb->DirectoryCB->NameInformation.FileName,
2272                               &pTargetDirEntry->NameInformation.FileName);
2273
2274                 try_return( ntStatus = STATUS_OBJECT_NAME_COLLISION);
2275             }
2276
2277             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2278                           AFS_TRACE_LEVEL_ERROR,
2279                           "AFSSetRenameInfo Target %wZ exists DE %p Count %08lX, performing delete of target\n",
2280                           &pTargetDirEntry->NameInformation.FileName,
2281                           pTargetDirEntry,
2282                           pTargetDirEntry->OpenReferenceCount);
2283
2284             //
2285             // Pull the directory entry from the parent
2286             //
2287
2288             AFSRemoveDirNodeFromParent( pTargetParentObject,
2289                                         pTargetDirEntry,
2290                                         FALSE);
2291
2292             bTargetEntryExists = TRUE;
2293         }
2294         else
2295         {
2296             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2297                           AFS_TRACE_LEVEL_VERBOSE,
2298                           "AFSSetRenameInfo Target does NOT exist, normal rename\n");
2299         }
2300
2301         //
2302         // Extract off the final component name from the Fcb
2303         //
2304
2305         uniSourceName.Length = (USHORT)pSrcCcb->DirectoryCB->NameInformation.FileName.Length;
2306         uniSourceName.MaximumLength = uniSourceName.Length;
2307
2308         uniSourceName.Buffer = pSrcCcb->DirectoryCB->NameInformation.FileName.Buffer;
2309
2310         //
2311         // The quick check to see if they are not really performing a rename
2312         // Do the names match? Only do this where the parent directories are
2313         // the same
2314         //
2315
2316         if( pTargetParentObject == pSrcFcb->ObjectInformation->ParentObjectInformation)
2317         {
2318
2319             bCommonParent = TRUE;
2320
2321             if( FsRtlAreNamesEqual( &uniTargetName,
2322                                     &uniSourceName,
2323                                     FALSE,
2324                                     NULL))
2325             {
2326                 try_return( ntStatus = STATUS_SUCCESS);
2327             }
2328         }
2329         else
2330         {
2331
2332             bCommonParent = FALSE;
2333         }
2334
2335         //
2336         // We need to remove the DirEntry from the parent node, update the index
2337         // and reinsert it into the parent tree. Note that for entries with the
2338         // same parent we do not pull the node from the enumeration list
2339         //
2340
2341         AFSRemoveDirNodeFromParent( pSrcFcb->ObjectInformation->ParentObjectInformation,
2342                                     pSrcCcb->DirectoryCB,
2343                                     !bCommonParent);
2344
2345         //
2346         // OK, this is a simple rename. Issue the rename
2347         // request to the service.
2348         //
2349
2350         ntStatus = AFSNotifyRename( pSrcFcb->ObjectInformation,
2351                                     &pSrcCcb->AuthGroup,
2352                                     pSrcFcb->ObjectInformation->ParentObjectInformation,
2353                                     pTargetDcb->ObjectInformation,
2354                                     pSrcCcb->DirectoryCB,
2355                                     &uniTargetName,
2356                                     &stNewFid);
2357
2358         if( !NT_SUCCESS( ntStatus))
2359         {
2360
2361             //
2362             // Attempt to re-insert the directory entry
2363             //
2364
2365             AFSInsertDirectoryNode( pSrcFcb->ObjectInformation->ParentObjectInformation,
2366                                     pSrcCcb->DirectoryCB,
2367                                     !bCommonParent);
2368
2369             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2370                           AFS_TRACE_LEVEL_ERROR,
2371                           "AFSSetRenameInfo Failed rename of %wZ to target %wZ Status %08lX\n",
2372                           &pSrcCcb->DirectoryCB->NameInformation.FileName,
2373                           &uniTargetName,
2374                           ntStatus);
2375
2376             try_return( ntStatus);
2377         }
2378
2379         //
2380         // Set the notification up for the source file
2381         //
2382
2383         if( pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation == pTargetParentObject &&
2384             !bTargetEntryExists)
2385         {
2386
2387             ulNotificationAction = FILE_ACTION_RENAMED_OLD_NAME;
2388         }
2389         else
2390         {
2391
2392             ulNotificationAction = FILE_ACTION_REMOVED;
2393         }
2394
2395         if( pSrcCcb->DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY)
2396         {
2397
2398             ulNotifyFilter = FILE_NOTIFY_CHANGE_DIR_NAME;
2399         }
2400         else
2401         {
2402
2403             ulNotifyFilter = FILE_NOTIFY_CHANGE_FILE_NAME;
2404         }
2405
2406         AFSFsRtlNotifyFullReportChange( pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation,
2407                                         pSrcCcb,
2408                                         (ULONG)ulNotifyFilter,
2409                                         (ULONG)ulNotificationAction);
2410
2411         //
2412         // Update the name in the dir entry.
2413         //
2414
2415         ntStatus = AFSUpdateDirEntryName( pSrcCcb->DirectoryCB,
2416                                           &uniTargetName);
2417
2418         if( !NT_SUCCESS( ntStatus))
2419         {
2420
2421             //
2422             // Attempt to re-insert the directory entry
2423             //
2424
2425             AFSInsertDirectoryNode( pSrcFcb->ObjectInformation->ParentObjectInformation,
2426                                     pSrcCcb->DirectoryCB,
2427                                     !bCommonParent);
2428
2429             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2430                           AFS_TRACE_LEVEL_ERROR,
2431                           "AFSSetRenameInfo Failed update of dir entry %wZ to target %wZ Status %08lX\n",
2432                           &pSrcCcb->DirectoryCB->NameInformation.FileName,
2433                           &uniTargetName,
2434                           ntStatus);
2435
2436             try_return( ntStatus);
2437         }
2438
2439         //
2440         // Update the object information block, if needed
2441         //
2442
2443         if( !AFSIsEqualFID( &pSrcObject->FileId,
2444                             &stNewFid))
2445         {
2446
2447             AFSAcquireExcl( pSrcObject->VolumeCB->ObjectInfoTree.TreeLock,
2448                             TRUE);
2449
2450             //
2451             // Remove the old information entry
2452             //
2453
2454             AFSRemoveHashEntry( &pSrcObject->VolumeCB->ObjectInfoTree.TreeHead,
2455                                 &pSrcObject->TreeEntry);
2456
2457             RtlCopyMemory( &pSrcObject->FileId,
2458                            &stNewFid,
2459                            sizeof( AFSFileID));
2460
2461             //
2462             // Insert the entry into the new object table.
2463             //
2464
2465             pSrcObject->TreeEntry.HashIndex = AFSCreateLowIndex( &pSrcObject->FileId);
2466
2467             if( pSrcObject->VolumeCB->ObjectInfoTree.TreeHead == NULL)
2468             {
2469
2470                 pSrcObject->VolumeCB->ObjectInfoTree.TreeHead = &pSrcObject->TreeEntry;
2471             }
2472             else
2473             {
2474
2475                 if ( !NT_SUCCESS( AFSInsertHashEntry( pSrcObject->VolumeCB->ObjectInfoTree.TreeHead,
2476                                                      &pSrcObject->TreeEntry)))
2477                 {
2478
2479                     //
2480                     // Lost a race, an ObjectInfo object already exists for this FID.
2481                     // Let this copy be garbage collected.
2482                     //
2483
2484                     ClearFlag( pSrcObject->Flags, AFS_OBJECT_INSERTED_HASH_TREE);
2485                 }
2486             }
2487
2488             AFSReleaseResource( pSrcObject->VolumeCB->ObjectInfoTree.TreeLock);
2489         }
2490
2491         //
2492         // Update the hash values for the name trees.
2493         //
2494
2495         pSrcCcb->DirectoryCB->CaseSensitiveTreeEntry.HashIndex = AFSGenerateCRC( &pSrcCcb->DirectoryCB->NameInformation.FileName,
2496                                                                                  FALSE);
2497
2498         pSrcCcb->DirectoryCB->CaseInsensitiveTreeEntry.HashIndex = AFSGenerateCRC( &pSrcCcb->DirectoryCB->NameInformation.FileName,
2499                                                                                    TRUE);
2500
2501         if( pSrcCcb->DirectoryCB->NameInformation.ShortNameLength > 0 &&
2502             !RtlIsNameLegalDOS8Dot3( &pSrcCcb->DirectoryCB->NameInformation.FileName,
2503                                      NULL,
2504                                      NULL))
2505         {
2506
2507             uniShortName.Length = pSrcCcb->DirectoryCB->NameInformation.ShortNameLength;
2508             uniShortName.MaximumLength = uniShortName.Length;
2509             uniShortName.Buffer = pSrcCcb->DirectoryCB->NameInformation.ShortName;
2510
2511             pSrcCcb->DirectoryCB->Type.Data.ShortNameTreeEntry.HashIndex = AFSGenerateCRC( &uniShortName,
2512                                                                                            TRUE);
2513
2514             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2515                           AFS_TRACE_LEVEL_VERBOSE,
2516                           "AFSSetRenameInfo Initialized short name hash for %wZ longname %wZ\n",
2517                           &uniShortName,
2518                           &pSrcCcb->DirectoryCB->NameInformation.FileName);
2519         }
2520         else
2521         {
2522
2523             pSrcCcb->DirectoryCB->Type.Data.ShortNameTreeEntry.HashIndex = 0;
2524         }
2525
2526         if( !bCommonParent)
2527         {
2528
2529             //
2530             // Update the file index for the object in the new parent
2531             //
2532
2533             pSrcCcb->DirectoryCB->FileIndex = (ULONG)InterlockedIncrement( &pTargetParentObject->Specific.Directory.DirectoryNodeHdr.ContentIndex);
2534         }
2535
2536         //
2537         // Re-insert the directory entry
2538         //
2539
2540         AFSInsertDirectoryNode( pTargetParentObject,
2541                                 pSrcCcb->DirectoryCB,
2542                                 !bCommonParent);
2543
2544         //
2545         // Update the parent pointer in the source object if they are different
2546         //
2547
2548         if( pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation != pTargetParentObject)
2549         {
2550
2551             InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
2552
2553             InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
2554
2555             InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenHandleCount);
2556
2557             InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenReferenceCount);
2558
2559             pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation = pTargetParentObject;
2560
2561             ulNotificationAction = FILE_ACTION_ADDED;
2562         }
2563         else
2564         {
2565
2566             ulNotificationAction = FILE_ACTION_RENAMED_NEW_NAME;
2567         }
2568
2569         //
2570         // Now update the notification for the target file
2571         //
2572
2573         AFSFsRtlNotifyFullReportChange( pTargetParentObject->ParentObjectInformation,
2574                                         pSrcCcb,
2575                                         (ULONG)ulNotifyFilter,
2576                                         (ULONG)ulNotificationAction);
2577
2578         //
2579         // If we performed the rename of the target because it existed, we now need to
2580         // delete the tmp target we created above
2581         //
2582
2583         if( bTargetEntryExists)
2584         {
2585
2586             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2587                           AFS_TRACE_LEVEL_VERBOSE,
2588                           "AFSSetRenameInfo Setting DELETE flag in dir entry %p name %wZ\n",
2589                           pTargetDirEntry,
2590                           &pTargetDirEntry->NameInformation.FileName);
2591
2592             SetFlag( pTargetDirEntry->Flags, AFS_DIR_ENTRY_DELETED);
2593
2594             //
2595             // Try and purge the cache map if this is a file
2596             //
2597
2598             if( pTargetDirEntry->ObjectInformation->FileType == AFS_FILE_TYPE_FILE &&
2599                 pTargetDirEntry->ObjectInformation->Fcb != NULL &&
2600                 pTargetDirEntry->OpenReferenceCount > 1)
2601             {
2602
2603                 pTargetFcb = pTargetDirEntry->ObjectInformation->Fcb;
2604
2605                 AFSAcquireExcl( &pTargetFcb->NPFcb->Resource,
2606                                 TRUE);
2607
2608                 //
2609                 // Close the section in the event it was mapped
2610                 //
2611
2612                 if( !MmForceSectionClosed( &pTargetFcb->NPFcb->SectionObjectPointers,
2613                                            TRUE))
2614                 {
2615
2616                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2617                                   AFS_TRACE_LEVEL_ERROR,
2618                                   "AFSSetRenameInfo Failed to delete section for target file %wZ\n",
2619                                   &pTargetDirEntry->NameInformation.FileName);
2620                 }
2621
2622                 AFSReleaseResource( &pTargetFcb->NPFcb->Resource);
2623             }
2624
2625             ASSERT( pTargetDirEntry->OpenReferenceCount > 0);
2626
2627             InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount); // The count we added above
2628
2629             if( pTargetDirEntry->OpenReferenceCount == 0)
2630             {
2631
2632                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
2633                               AFS_TRACE_LEVEL_VERBOSE,
2634                               "AFSSetRenameInfo Deleting dir entry %p name %wZ\n",
2635                               pTargetDirEntry,
2636                               &pTargetDirEntry->NameInformation.FileName);
2637
2638                 AFSDeleteDirEntry( pTargetParentObject,
2639                                    pTargetDirEntry);
2640             }
2641
2642             pTargetDirEntry = NULL;
2643         }
2644
2645 try_exit:
2646
2647
2648         if( !NT_SUCCESS( ntStatus))
2649         {
2650
2651             if( bTargetEntryExists)
2652             {
2653                 AFSInsertDirectoryNode( pTargetDirEntry->ObjectInformation->ParentObjectInformation,
2654                                         pTargetDirEntry,
2655                                         FALSE);
2656             }
2657         }
2658
2659         if( pTargetDirEntry != NULL)
2660         {
2661
2662             InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
2663         }
2664
2665         if( bReleaseTargetDirLock)
2666         {
2667             AFSReleaseResource( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
2668         }
2669
2670         if( bReleaseSourceDirLock)
2671         {
2672             AFSReleaseResource( pSourceDirLock);
2673         }
2674     }
2675
2676     return ntStatus;
2677 }
2678
2679 NTSTATUS
2680 AFSSetPositionInfo( IN PIRP Irp,
2681                     IN AFSDirectoryCB *DirectoryCB)
2682 {
2683     NTSTATUS ntStatus = STATUS_SUCCESS;
2684     PFILE_POSITION_INFORMATION pBuffer;
2685     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
2686
2687     pBuffer = (PFILE_POSITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2688
2689     pIrpSp->FileObject->CurrentByteOffset.QuadPart = pBuffer->CurrentByteOffset.QuadPart;
2690
2691     return ntStatus;
2692 }
2693
2694 NTSTATUS
2695 AFSSetAllocationInfo( IN PIRP Irp,
2696                       IN AFSDirectoryCB *DirectoryCB)
2697 {
2698     NTSTATUS ntStatus = STATUS_SUCCESS;
2699     PFILE_ALLOCATION_INFORMATION pBuffer;
2700     BOOLEAN bReleasePaging = FALSE;
2701     BOOLEAN bTellCc = FALSE;
2702     BOOLEAN bTellService = FALSE;
2703     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
2704     PFILE_OBJECT pFileObject = pIrpSp->FileObject;
2705     AFSFcb *pFcb = NULL;
2706     AFSCcb *pCcb = NULL;
2707     LARGE_INTEGER liSaveAlloc;
2708     LARGE_INTEGER liSaveFileSize;
2709     LARGE_INTEGER liSaveVDL;
2710
2711     pBuffer = (PFILE_ALLOCATION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2712
2713     pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
2714
2715     pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
2716
2717     //
2718     // save values to put back
2719     //
2720     liSaveAlloc = pFcb->Header.AllocationSize;
2721     liSaveFileSize = pFcb->Header.FileSize;
2722     liSaveVDL = pFcb->Header.ValidDataLength;
2723
2724     if( pFcb->Header.AllocationSize.QuadPart == pBuffer->AllocationSize.QuadPart ||
2725         pIrpSp->Parameters.SetFile.AdvanceOnly)
2726     {
2727         return STATUS_SUCCESS ;
2728     }
2729
2730     if( pFcb->Header.AllocationSize.QuadPart > pBuffer->AllocationSize.QuadPart)
2731     {
2732         //
2733         // Truncating the file
2734         //
2735         if( !MmCanFileBeTruncated( pFileObject->SectionObjectPointer,
2736                                    &pBuffer->AllocationSize))
2737         {
2738
2739             ntStatus = STATUS_USER_MAPPED_FILE ;
2740         }
2741         else
2742         {
2743             //
2744             // If this is a truncation we need to grab the paging IO resource.
2745             //
2746             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
2747                           AFS_TRACE_LEVEL_VERBOSE,
2748                           "AFSSetAllocationInfo Acquiring Fcb PagingIo lock %08lX EXCL %08lX\n",
2749                           &pFcb->NPFcb->PagingResource,
2750                           PsGetCurrentThread());
2751
2752             AFSAcquireExcl( &pFcb->NPFcb->PagingResource,
2753                             TRUE);
2754
2755             bReleasePaging = TRUE;
2756
2757
2758             pFcb->Header.AllocationSize = pBuffer->AllocationSize;
2759
2760             pFcb->ObjectInformation->AllocationSize = pBuffer->AllocationSize;
2761
2762             //
2763             // Tell Cc that Allocation is moved.
2764             //
2765             bTellCc = TRUE;
2766
2767             if( pFcb->Header.FileSize.QuadPart > pBuffer->AllocationSize.QuadPart)
2768             {
2769                 //
2770                 // We are pulling the EOF back as well so we need to tell
2771                 // the service.
2772                 //
2773                 bTellService = TRUE;
2774
2775                 pFcb->Header.FileSize = pBuffer->AllocationSize;
2776
2777                 pFcb->ObjectInformation->EndOfFile = pBuffer->AllocationSize;
2778             }
2779
2780         }
2781     }
2782     else
2783     {
2784         //
2785         // Tell Cc if allocation is increased.
2786         //
2787         bTellCc = pBuffer->AllocationSize.QuadPart > pFcb->Header.AllocationSize.QuadPart;
2788
2789         pFcb->Header.AllocationSize = pBuffer->AllocationSize;
2790
2791         pFcb->ObjectInformation->AllocationSize = pBuffer->AllocationSize;
2792     }
2793
2794     //
2795     // Now Tell the server if we have to
2796     //
2797     if (bTellService)
2798     {
2799         ntStatus = AFSUpdateFileInformation( &pFcb->ObjectInformation->ParentObjectInformation->FileId,
2800                                              pFcb->ObjectInformation,
2801                                              &pCcb->AuthGroup);
2802     }
2803
2804     if (NT_SUCCESS(ntStatus))
2805     {
2806         //
2807         // Trim extents if we told the service - the update has done an implicit
2808         // trim at the service.
2809         //
2810         if (bTellService)
2811         {
2812             AFSTrimExtents( pFcb,
2813                             &pFcb->Header.FileSize);
2814         }
2815
2816         KeQuerySystemTime( &pFcb->ObjectInformation->ChangeTime);
2817
2818         SetFlag( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED | AFS_FCB_FLAG_UPDATE_CHANGE_TIME);
2819
2820         if (bTellCc &&
2821             CcIsFileCached( pFileObject))
2822         {
2823             CcSetFileSizes( pFileObject,
2824                             (PCC_FILE_SIZES)&pFcb->Header.AllocationSize);
2825         }
2826     }
2827     else
2828     {
2829         //
2830         // Put the saved values back
2831         //
2832         pFcb->Header.ValidDataLength = liSaveVDL;
2833         pFcb->Header.FileSize = liSaveFileSize;
2834         pFcb->Header.AllocationSize = liSaveAlloc;
2835         pFcb->ObjectInformation->EndOfFile = liSaveFileSize;
2836         pFcb->ObjectInformation->AllocationSize = liSaveAlloc;
2837     }
2838
2839     if( bReleasePaging)
2840     {
2841
2842         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
2843     }
2844
2845     return ntStatus;
2846 }
2847
2848 NTSTATUS
2849 AFSSetEndOfFileInfo( IN PIRP Irp,
2850                      IN AFSDirectoryCB *DirectoryCB)
2851 {
2852     NTSTATUS ntStatus = STATUS_SUCCESS;
2853     PFILE_END_OF_FILE_INFORMATION pBuffer;
2854     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
2855     PFILE_OBJECT pFileObject = pIrpSp->FileObject;
2856     LARGE_INTEGER liSaveSize;
2857     LARGE_INTEGER liSaveVDL;
2858     LARGE_INTEGER liSaveAlloc;
2859     BOOLEAN bModified = FALSE;
2860     BOOLEAN bReleasePaging = FALSE;
2861     BOOLEAN bTruncated = FALSE;
2862     AFSFcb *pFcb = NULL;
2863     AFSCcb *pCcb = NULL;
2864
2865     pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
2866
2867     pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
2868
2869     pBuffer = (PFILE_END_OF_FILE_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2870
2871     liSaveSize = pFcb->Header.FileSize;
2872     liSaveAlloc = pFcb->Header.AllocationSize;
2873     liSaveVDL = pFcb->Header.ValidDataLength;
2874
2875     if( pFcb->Header.FileSize.QuadPart != pBuffer->EndOfFile.QuadPart &&
2876         !pIrpSp->Parameters.SetFile.AdvanceOnly)
2877     {
2878
2879         if( pBuffer->EndOfFile.QuadPart < pFcb->Header.FileSize.QuadPart)
2880         {
2881
2882             // Truncating the file
2883             if( !MmCanFileBeTruncated( pFileObject->SectionObjectPointer,
2884                                        &pBuffer->EndOfFile))
2885             {
2886
2887                 ntStatus = STATUS_USER_MAPPED_FILE;
2888             }
2889             else
2890             {
2891                 //
2892                 // If this is a truncation we need to grab the paging
2893                 // IO resource.
2894                 //
2895                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
2896                               AFS_TRACE_LEVEL_VERBOSE,
2897                               "AFSSetAllocationInfo Acquiring Fcb PagingIo lock %08lX EXCL %08lX\n",
2898                               &pFcb->NPFcb->PagingResource,
2899                               PsGetCurrentThread());
2900
2901                 AFSAcquireExcl( &pFcb->NPFcb->PagingResource,
2902                                 TRUE);
2903
2904                 bReleasePaging = TRUE;
2905
2906                 pFcb->Header.AllocationSize = pBuffer->EndOfFile;
2907
2908                 pFcb->Header.FileSize = pBuffer->EndOfFile;
2909
2910                 pFcb->ObjectInformation->EndOfFile = pBuffer->EndOfFile;
2911
2912                 pFcb->ObjectInformation->AllocationSize = pBuffer->EndOfFile;
2913
2914                 if( pFcb->Header.ValidDataLength.QuadPart > pFcb->Header.FileSize.QuadPart)
2915                 {
2916
2917                     pFcb->Header.ValidDataLength = pFcb->Header.FileSize;
2918                 }
2919
2920                 bTruncated = TRUE;
2921
2922                 bModified = TRUE;
2923             }
2924         }
2925         else
2926         {
2927             //
2928             // extending the file, move EOF
2929             //
2930
2931             pFcb->Header.FileSize = pBuffer->EndOfFile;
2932
2933             pFcb->ObjectInformation->EndOfFile = pBuffer->EndOfFile;
2934
2935             if (pFcb->Header.FileSize.QuadPart > pFcb->Header.AllocationSize.QuadPart)
2936             {
2937                 //
2938                 // And Allocation as needed.
2939                 //
2940                 pFcb->Header.AllocationSize = pBuffer->EndOfFile;
2941
2942                 pFcb->ObjectInformation->AllocationSize = pBuffer->EndOfFile;
2943             }
2944
2945             bModified = TRUE;
2946         }
2947     }
2948
2949     if (bModified)
2950     {
2951
2952         KeQuerySystemTime( &pFcb->ObjectInformation->ChangeTime);
2953
2954         SetFlag( pFcb->Flags, AFS_FCB_FLAG_FILE_MODIFIED | AFS_FCB_FLAG_UPDATE_CHANGE_TIME);
2955
2956         //
2957         // Tell the server
2958         //
2959
2960         ntStatus = AFSUpdateFileInformation( &pFcb->ObjectInformation->ParentObjectInformation->FileId,
2961                                              pFcb->ObjectInformation,
2962                                              &pCcb->AuthGroup);
2963
2964         if( NT_SUCCESS(ntStatus))
2965         {
2966             //
2967             // We are now good to go so tell CC.
2968             //
2969             CcSetFileSizes( pFileObject,
2970                             (PCC_FILE_SIZES)&pFcb->Header.AllocationSize);
2971
2972             //
2973             // And give up those extents
2974             //
2975             if( bTruncated)
2976             {
2977
2978                 AFSTrimExtents( pFcb,
2979                                 &pFcb->Header.FileSize);
2980             }
2981         }
2982         else
2983         {
2984             pFcb->Header.ValidDataLength = liSaveVDL;
2985             pFcb->Header.FileSize = liSaveSize;
2986             pFcb->Header.AllocationSize = liSaveAlloc;
2987             pFcb->ObjectInformation->EndOfFile = liSaveSize;
2988             pFcb->ObjectInformation->AllocationSize = liSaveAlloc;
2989         }
2990     }
2991
2992     if( bReleasePaging)
2993     {
2994
2995         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
2996     }
2997
2998     return ntStatus;
2999 }
3000
3001 NTSTATUS
3002 AFSProcessShareSetInfo( IN IRP *Irp,
3003                         IN AFSFcb *Fcb,
3004                         IN AFSCcb *Ccb)
3005 {
3006
3007     NTSTATUS ntStatus = STATUS_SUCCESS;
3008     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
3009     ULONG ulOutputBufferLen = 0, ulInputBufferLen;
3010     FILE_INFORMATION_CLASS ulFileInformationClass;
3011     void *pPipeInfo = NULL;
3012
3013     __Enter
3014     {
3015         ulFileInformationClass = pIrpSp->Parameters.SetFile.FileInformationClass;
3016
3017         AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3018                       AFS_TRACE_LEVEL_VERBOSE,
3019                       "AFSProcessShareSetInfo On pipe %wZ Class %08lX\n",
3020                       &Ccb->DirectoryCB->NameInformation.FileName,
3021                       ulFileInformationClass);
3022
3023         pPipeInfo = AFSLockSystemBuffer( Irp,
3024                                          pIrpSp->Parameters.SetFile.Length);
3025
3026         if( pPipeInfo == NULL)
3027         {
3028
3029             AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3030                           AFS_TRACE_LEVEL_ERROR,
3031                           "AFSProcessShareSetInfo Failed to lock buffer on pipe %wZ\n",
3032                           &Ccb->DirectoryCB->NameInformation.FileName);
3033
3034             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
3035         }
3036
3037         //
3038         // Send the request to the service
3039         //
3040
3041         ntStatus = AFSNotifySetPipeInfo( Ccb,
3042                                          (ULONG)ulFileInformationClass,
3043                                          pIrpSp->Parameters.SetFile.Length,
3044                                          pPipeInfo);
3045
3046         if( !NT_SUCCESS( ntStatus))
3047         {
3048
3049             AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3050                           AFS_TRACE_LEVEL_ERROR,
3051                           "AFSProcessShareSetInfo Failed to send request to service on pipe %wZ Status %08lX\n",
3052                           &Ccb->DirectoryCB->NameInformation.FileName,
3053                           ntStatus);
3054
3055             try_return( ntStatus);
3056         }
3057
3058         AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3059                       AFS_TRACE_LEVEL_VERBOSE,
3060                       "AFSProcessShareSetInfo Completed request on pipe %wZ Class %08lX\n",
3061                       &Ccb->DirectoryCB->NameInformation.FileName,
3062                       ulFileInformationClass);
3063
3064 try_exit:
3065
3066         NOTHING;
3067     }
3068
3069     return ntStatus;
3070 }
3071
3072 NTSTATUS
3073 AFSProcessShareQueryInfo( IN IRP *Irp,
3074                           IN AFSFcb *Fcb,
3075                           IN AFSCcb *Ccb)
3076 {
3077
3078     NTSTATUS ntStatus = STATUS_SUCCESS;
3079     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
3080     ULONG ulOutputBufferLen = 0, ulInputBufferLen;
3081     FILE_INFORMATION_CLASS ulFileInformationClass;
3082     void *pPipeInfo = NULL;
3083
3084     __Enter
3085     {
3086
3087         ulFileInformationClass = pIrpSp->Parameters.QueryFile.FileInformationClass;
3088
3089         AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3090                       AFS_TRACE_LEVEL_VERBOSE,
3091                       "AFSProcessShareQueryInfo On pipe %wZ Class %08lX\n",
3092                       &Ccb->DirectoryCB->NameInformation.FileName,
3093                       ulFileInformationClass);
3094
3095         pPipeInfo = AFSLockSystemBuffer( Irp,
3096                                          pIrpSp->Parameters.QueryFile.Length);
3097
3098         if( pPipeInfo == NULL)
3099         {
3100
3101             AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3102                           AFS_TRACE_LEVEL_ERROR,
3103                           "AFSProcessShareQueryInfo Failed to lock buffer on pipe %wZ\n",
3104                           &Ccb->DirectoryCB->NameInformation.FileName);
3105
3106             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
3107         }
3108
3109         //
3110         // Send the request to the service
3111         //
3112
3113         ntStatus = AFSNotifyQueryPipeInfo( Ccb,
3114                                            (ULONG)ulFileInformationClass,
3115                                            pIrpSp->Parameters.QueryFile.Length,
3116                                            pPipeInfo,
3117                                            (ULONG *)&Irp->IoStatus.Information);
3118
3119         if( !NT_SUCCESS( ntStatus))
3120         {
3121
3122             AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3123                           AFS_TRACE_LEVEL_ERROR,
3124                           "AFSProcessShareQueryInfo Failed to send request to service on pipe %wZ Status %08lX\n",
3125                           &Ccb->DirectoryCB->NameInformation.FileName,
3126                           ntStatus);
3127
3128             try_return( ntStatus);
3129         }
3130
3131         AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
3132                       AFS_TRACE_LEVEL_VERBOSE,
3133                       "AFSProcessShareQueryInfo Completed request on pipe %wZ Class %08lX\n",
3134                       &Ccb->DirectoryCB->NameInformation.FileName,
3135                       ulFileInformationClass);
3136
3137 try_exit:
3138
3139         NOTHING;
3140     }
3141
3142     return ntStatus;
3143 }
3144
3145 NTSTATUS
3146 AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
3147                            IN AFSFcb *Fcb,
3148                            IN AFSCcb *Ccb,
3149                            IN OUT LONG *Length)
3150 {
3151
3152     NTSTATUS ntStatus = STATUS_SUCCESS;
3153     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
3154     FILE_INFORMATION_CLASS ulFileInformationClass;
3155
3156     __Enter
3157     {
3158
3159         ulFileInformationClass = pIrpSp->Parameters.QueryFile.FileInformationClass;
3160
3161         switch( ulFileInformationClass)
3162         {
3163
3164             case FileBasicInformation:
3165             {
3166
3167                 AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
3168                               AFS_TRACE_LEVEL_VERBOSE,
3169                               "AFSProcessPIOCtlQueryInfo (FileBasicInformation)\n");
3170
3171                 if ( *Length >= sizeof( FILE_BASIC_INFORMATION))
3172                 {
3173                     PFILE_BASIC_INFORMATION pBasic = (PFILE_BASIC_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
3174
3175                     pBasic->CreationTime.QuadPart = 0;
3176                     pBasic->LastAccessTime.QuadPart = 0;
3177                     pBasic->ChangeTime.QuadPart = 0;
3178                     pBasic->LastWriteTime.QuadPart = 0;
3179                     pBasic->FileAttributes = FILE_ATTRIBUTE_SYSTEM;
3180
3181                     *Length -= sizeof( FILE_BASIC_INFORMATION);
3182                 }
3183                 else
3184                 {
3185                     ntStatus = STATUS_BUFFER_TOO_SMALL;
3186                 }
3187
3188                 break;
3189             }
3190
3191             case FileStandardInformation:
3192             {
3193
3194                 AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
3195                               AFS_TRACE_LEVEL_VERBOSE,
3196                               "AFSProcessPIOCtlQueryInfo (FileStandardInformation)\n");
3197
3198                 if ( *Length >= sizeof( FILE_STANDARD_INFORMATION))
3199                 {
3200                     PFILE_STANDARD_INFORMATION pStandard = (PFILE_STANDARD_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
3201
3202                     pStandard->NumberOfLinks = 1;
3203                     pStandard->DeletePending = 0;
3204                     pStandard->AllocationSize.QuadPart = 0;
3205                     pStandard->EndOfFile.QuadPart = 0;
3206                     pStandard->Directory = 0;
3207
3208                     *Length -= sizeof( FILE_STANDARD_INFORMATION);
3209                 }
3210                 else
3211                 {
3212                     ntStatus = STATUS_BUFFER_TOO_SMALL;
3213                 }
3214
3215                 break;
3216             }
3217
3218             case FileNameInformation:
3219             {
3220
3221                 ULONG ulCopyLength = 0;
3222                 AFSFcb *pFcb = NULL;
3223                 AFSCcb *pCcb = NULL;
3224                 USHORT usFullNameLength = 0;
3225                 PFILE_NAME_INFORMATION pNameInfo = (PFILE_NAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
3226                 UNICODE_STRING uniName;
3227
3228                 AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
3229                               AFS_TRACE_LEVEL_VERBOSE,
3230                               "AFSProcessPIOCtlQueryInfo (FileNameInformation)\n");
3231
3232                 pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
3233                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
3234
3235                 if( *Length < FIELD_OFFSET( FILE_NAME_INFORMATION, FileName))
3236                 {
3237                     ntStatus = STATUS_BUFFER_TOO_SMALL;
3238                     break;
3239                 }
3240
3241                 RtlZeroMemory( pNameInfo,
3242                                *Length);
3243
3244                 usFullNameLength = sizeof( WCHAR) +
3245                                             AFSServerName.Length +
3246                                             pCcb->FullFileName.Length;
3247
3248                 if( *Length >= (LONG)(FIELD_OFFSET( FILE_NAME_INFORMATION, FileName) + (LONG)usFullNameLength))
3249                 {
3250                     ulCopyLength = (LONG)usFullNameLength;
3251                 }
3252                 else
3253                 {
3254                     ulCopyLength = *Length - FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
3255                     ntStatus = STATUS_BUFFER_OVERFLOW;
3256                 }
3257
3258                 pNameInfo->FileNameLength = (ULONG)usFullNameLength;
3259
3260                 *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
3261
3262                 if( ulCopyLength > 0)
3263                 {
3264