Windows: More useful AFSDumpFile exception info
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSFSControl.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: AFSFSControl.cpp
37 //
38
39 #include "AFSCommon.h"
40
41 NTSTATUS
42 AFSFSControl( IN PDEVICE_OBJECT LibDeviceObject,
43               IN PIRP Irp)
44 {
45
46     NTSTATUS ntStatus = STATUS_SUCCESS;
47     IO_STACK_LOCATION *pIrpSp;
48
49     pIrpSp = IoGetCurrentIrpStackLocation( Irp);
50
51     __try
52     {
53
54         switch( pIrpSp->MinorFunction)
55         {
56
57             case IRP_MN_USER_FS_REQUEST:
58
59                 ntStatus = AFSProcessUserFsRequest( Irp);
60
61                 break;
62
63             case IRP_MN_MOUNT_VOLUME:
64
65                 break;
66
67             case IRP_MN_VERIFY_VOLUME:
68
69                 break;
70
71             default:
72
73                 break;
74         }
75
76         AFSCompleteRequest( Irp,
77                               ntStatus);
78
79     }
80     __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
81     {
82
83         AFSDbgLogMsg( 0,
84                       0,
85                       "EXCEPTION - AFSFSControl\n");
86
87         AFSDumpTraceFilesFnc();
88     }
89
90     return ntStatus;
91 }
92
93 static BOOLEAN
94 AFSParseMountPointTarget( IN  UNICODE_STRING *Target,
95                           OUT USHORT         *Type,
96                           OUT UNICODE_STRING *Volume,
97                           OUT UNICODE_STRING *Cell)
98 {
99     // Targets are of the form <type>[<cell>:]<volume>
100
101     *Type = Target->Buffer[ 0];
102
103     // Extract the cell name (if any)
104
105     Cell->Buffer = &Target->Buffer[ 1];
106
107     // Search for colon separator or end of counted string
108
109     for ( Cell->Length = 0; Cell->Length < Target->Length - sizeof( WCHAR); Cell->Length += sizeof( WCHAR))
110     {
111
112         if ( Cell->Buffer[ Cell->Length / sizeof( WCHAR)] == L':')
113         {
114             break;
115         }
116     }
117
118     // If a colon is not found, it means there is no cell
119
120     if ( Cell->Length < Target->Length - sizeof( WCHAR) &&
121          Cell->Buffer[ Cell->Length / sizeof( WCHAR)] == L':')
122     {
123
124         Cell->MaximumLength = Cell->Length;
125
126         if ( Cell->Length > Target->Length - 2 * sizeof( WCHAR))
127         {
128             // Invalid target string if there is no room for
129             // the volume name.
130
131             return FALSE;
132         }
133
134         Volume->Length = Volume->MaximumLength = (Target->Length - Cell->Length - 2 * sizeof( WCHAR));
135
136         Volume->Buffer = &Target->Buffer[ Cell->Length / sizeof( WCHAR) + 2];
137     }
138     else
139     {
140         // There is no cell
141
142         Volume->Length = Volume->MaximumLength = Cell->Length;
143
144         Volume->Buffer = Cell->Buffer;
145
146         Cell->Length = Cell->MaximumLength = 0;
147
148         Cell->Buffer = NULL;
149     }
150
151     return TRUE;
152 }
153
154 NTSTATUS
155 AFSProcessUserFsRequest( IN PIRP Irp)
156 {
157
158     NTSTATUS ntStatus = STATUS_SUCCESS;
159     ULONG ulFsControlCode;
160     AFSFcb *pFcb = NULL;
161     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp );
162     AFSCcb *pCcb = NULL;
163     ULONG ulOutputBufferLen, ulInputBufferLen;
164
165     __Enter
166     {
167
168         ulFsControlCode = pIrpSp->Parameters.FileSystemControl.FsControlCode;
169
170         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
171
172         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
173
174         if( pFcb == NULL ||
175             pCcb->DirectoryCB == NULL)
176         {
177
178             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
179                           AFS_TRACE_LEVEL_VERBOSE_2,
180                           "AFSProcessUserFsRequest Invalid Fcb\n");
181
182             try_return( ntStatus = STATUS_INVALID_DEVICE_REQUEST);
183         }
184
185         if( pFcb->Header.NodeTypeCode == AFS_SPECIAL_SHARE_FCB)
186         {
187
188             ntStatus = AFSProcessShareFsCtrl( Irp,
189                                               pFcb,
190                                               pCcb);
191
192             try_return( ntStatus);
193         }
194
195         ulOutputBufferLen = pIrpSp->Parameters.FileSystemControl.OutputBufferLength;
196         ulInputBufferLen = pIrpSp->Parameters.FileSystemControl.InputBufferLength;
197
198         //
199         // Process the request
200         //
201
202         switch( ulFsControlCode )
203         {
204
205             case FSCTL_REQUEST_OPLOCK_LEVEL_1:
206             case FSCTL_REQUEST_OPLOCK_LEVEL_2:
207             case FSCTL_REQUEST_BATCH_OPLOCK:
208             case FSCTL_OPLOCK_BREAK_ACKNOWLEDGE:
209             case FSCTL_OPBATCH_ACK_CLOSE_PENDING:
210             case FSCTL_OPLOCK_BREAK_NOTIFY:
211             case FSCTL_OPLOCK_BREAK_ACK_NO_2:
212             case FSCTL_REQUEST_FILTER_OPLOCK :
213             {
214                 //
215                 // Note that implementing this call will probably need us
216                 // to call the server as well as adding code in read and
217                 // write and caching.  Also that it is unlikely that
218                 // anyone will ever call us at this point - RDR doesn't
219                 // allow it
220                 //
221
222                 ntStatus = STATUS_NOT_IMPLEMENTED;
223
224                 break;
225             }
226
227             case FSCTL_LOCK_VOLUME:
228             {
229                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
230                               AFS_TRACE_LEVEL_VERBOSE_2,
231                               "AFSProcessUserFsRequest Processing FSCTL_LOCK_VOLUME request\n");
232
233                 ntStatus = STATUS_NOT_IMPLEMENTED;
234
235                 break;
236             }
237
238             case FSCTL_UNLOCK_VOLUME:
239             {
240                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
241                               AFS_TRACE_LEVEL_VERBOSE_2,
242                               "AFSProcessUserFsRequest Processing FSCTL_UNLOCK_VOLUME request\n");
243
244                 ntStatus = STATUS_NOT_IMPLEMENTED;
245
246                 break;
247             }
248
249             case FSCTL_DISMOUNT_VOLUME:
250             {
251                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
252                               AFS_TRACE_LEVEL_VERBOSE_2,
253                               "AFSProcessUserFsRequest Processing FSCTL_DISMOUNT_VOLUME request\n");
254
255                 ntStatus = STATUS_NOT_IMPLEMENTED;
256
257                 break;
258             }
259
260             case FSCTL_MARK_VOLUME_DIRTY:
261             {
262                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
263                               AFS_TRACE_LEVEL_VERBOSE_2,
264                               "AFSProcessUserFsRequest Processing FSCTL_MARK_VOLUME_DIRTY request\n");
265
266                 ntStatus = STATUS_NOT_IMPLEMENTED;
267
268                 break;
269             }
270
271             case FSCTL_IS_VOLUME_DIRTY:
272             {
273                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
274                               AFS_TRACE_LEVEL_VERBOSE_2,
275                               "AFSProcessUserFsRequest Processing FSCTL_IS_VOLUME_DIRTY request\n");
276
277                 ntStatus = STATUS_NOT_IMPLEMENTED;
278
279                 break;
280             }
281
282             case FSCTL_IS_VOLUME_MOUNTED:
283             {
284                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
285                               AFS_TRACE_LEVEL_VERBOSE_2,
286                               "AFSProcessUserFsRequest Processing FSCTL_IS_VOLUME_MOUNTED request\n");
287
288                 ntStatus = STATUS_NOT_IMPLEMENTED;
289
290                 break;
291             }
292
293             case FSCTL_IS_PATHNAME_VALID:
294             {
295                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
296                               AFS_TRACE_LEVEL_VERBOSE_2,
297                               "AFSProcessUserFsRequest Processing FSCTL_IS_PATHNAME_VALID request\n");
298
299                 ntStatus = STATUS_SUCCESS;
300
301                 break;
302             }
303
304 #ifndef FSCTL_CSC_INTERNAL
305 #define FSCTL_CSC_INTERNAL                  CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 107, METHOD_NEITHER, FILE_ANY_ACCESS)
306 #endif
307             case FSCTL_CSC_INTERNAL:
308             {
309                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
310                               AFS_TRACE_LEVEL_VERBOSE_2,
311                               "AFSProcessUserFsRequest Processing FSCTL_CSC_INTERNAL request\n");
312
313                 ntStatus = STATUS_INVALID_DEVICE_REQUEST;
314
315                 break;
316             }
317
318             case FSCTL_GET_REPARSE_POINT:
319             {
320
321                 REPARSE_GUID_DATA_BUFFER *pReparseBuffer = (REPARSE_GUID_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
322                 ULONG ulRemainingLen = ulOutputBufferLen;
323                 AFSReparseTagInfo *pReparseInfo = NULL;
324
325                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
326                               AFS_TRACE_LEVEL_VERBOSE_2,
327                               "AFSProcessUserFsRequest Processing FSCTL_GET_REPARSE_POINT request %wZ Type 0x%x Attrib 0x%x\n",
328                               &pCcb->DirectoryCB->NameInformation.FileName,
329                               pCcb->DirectoryCB->ObjectInformation->FileType,
330                               pCcb->DirectoryCB->ObjectInformation->FileAttributes);
331
332                 //
333                 // Check if we have the reparse entry set on the entry
334                 //
335
336                 if( !BooleanFlagOn( pCcb->DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
337                 {
338
339                     ntStatus = STATUS_NOT_A_REPARSE_POINT;
340
341                     break;
342                 }
343
344                 if( ulOutputBufferLen < FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer))
345                 {
346
347                     ntStatus = STATUS_BUFFER_TOO_SMALL;
348
349                     Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer);
350
351                     break;
352                 }
353
354                 ulRemainingLen -= FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer);
355
356                 //
357                 // Populate the data in the reparse buffer
358                 //
359
360                 pReparseBuffer->ReparseDataLength  = 0;
361
362                 AFSAcquireExcl( &pCcb->DirectoryCB->NonPaged->Lock,
363                                 TRUE);
364
365                 if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
366                 {
367
368                     //
369                     // We'll reset the DV to ensure we validate the metadata content
370                     //
371
372                     pCcb->DirectoryCB->ObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
373
374                     SetFlag( pCcb->DirectoryCB->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
375
376                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
377                                   AFS_TRACE_LEVEL_VERBOSE,
378                                   "AFSProcessUserFsRequest Verifying symlink %wZ FID %08lX-%08lX-%08lX-%08lX\n",
379                                   &pCcb->DirectoryCB->NameInformation.FileName,
380                                   pCcb->DirectoryCB->ObjectInformation->FileId.Cell,
381                                   pCcb->DirectoryCB->ObjectInformation->FileId.Volume,
382                                   pCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
383                                   pCcb->DirectoryCB->ObjectInformation->FileId.Unique);
384
385                     ntStatus = AFSVerifyEntry( &pCcb->AuthGroup,
386                                                pCcb->DirectoryCB);
387
388                     if( !NT_SUCCESS( ntStatus))
389                     {
390
391                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
392                                       AFS_TRACE_LEVEL_ERROR,
393                                       "AFSProcessUserFsRequest Failed to verify symlink %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
394                                       &pCcb->DirectoryCB->NameInformation.FileName,
395                                       pCcb->DirectoryCB->ObjectInformation->FileId.Cell,
396                                       pCcb->DirectoryCB->ObjectInformation->FileId.Volume,
397                                       pCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
398                                       pCcb->DirectoryCB->ObjectInformation->FileId.Unique,
399                                       ntStatus);
400
401                         AFSReleaseResource( &pCcb->DirectoryCB->NonPaged->Lock);
402
403                         break;
404                     }
405                 }
406
407                 pReparseInfo = (AFSReparseTagInfo *)&pReparseBuffer->GenericReparseBuffer.DataBuffer[ 0];
408
409                 switch( pCcb->DirectoryCB->ObjectInformation->FileType)
410                 {
411
412                     case AFS_FILE_TYPE_SYMLINK:
413                     {
414
415                         if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
416                         {
417
418                             ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
419
420                             break;
421                         }
422
423                         if( ulRemainingLen < (ULONG) FIELD_OFFSET( AFSReparseTagInfo, AFSSymLink.Buffer) + pCcb->DirectoryCB->NameInformation.TargetName.Length)
424                         {
425
426                             ntStatus = STATUS_BUFFER_TOO_SMALL;
427
428                             Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
429                                                         FIELD_OFFSET( AFSReparseTagInfo, AFSSymLink.Buffer) +
430                                                         pCcb->DirectoryCB->NameInformation.TargetName.Length;
431
432                             break;
433                         }
434
435                         pReparseInfo->SubTag = OPENAFS_SUBTAG_SYMLINK;
436
437                         pReparseInfo->AFSSymLink.RelativeLink = AFSIsRelativeName( &pCcb->DirectoryCB->NameInformation.TargetName);
438
439                         pReparseInfo->AFSSymLink.SymLinkTargetLength = pCcb->DirectoryCB->NameInformation.TargetName.Length;
440
441                         RtlCopyMemory( pReparseInfo->AFSSymLink.Buffer,
442                                        pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
443                                        pCcb->DirectoryCB->NameInformation.TargetName.Length);
444
445                         pReparseBuffer->ReparseDataLength = (FIELD_OFFSET( AFSReparseTagInfo, AFSSymLink.Buffer) + pCcb->DirectoryCB->NameInformation.TargetName.Length);
446
447                         break;
448                     }
449
450                     case AFS_FILE_TYPE_MOUNTPOINT:
451                     {
452                         UNICODE_STRING Cell, Volume;
453                         USHORT Type;
454
455                         if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
456                         {
457                             ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
458
459                             break;
460                         }
461
462                         if ( !AFSParseMountPointTarget( &pCcb->DirectoryCB->NameInformation.TargetName,
463                                                         &Type,
464                                                         &Volume,
465                                                         &Cell))
466                         {
467                             ntStatus = STATUS_INVALID_PARAMETER;
468
469                             break;
470                         }
471
472                         if( ulRemainingLen < (ULONG) FIELD_OFFSET( AFSReparseTagInfo, AFSMountPoint.Buffer) + Volume.Length + Cell.Length)
473                         {
474
475                             ntStatus = STATUS_BUFFER_TOO_SMALL;
476
477                             Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
478                                                         FIELD_OFFSET( AFSReparseTagInfo, AFSMountPoint.Buffer) +
479                                                         Volume.Length + Cell.Length;
480
481                             break;
482                         }
483
484                         pReparseInfo->SubTag = OPENAFS_SUBTAG_MOUNTPOINT;
485
486                         pReparseInfo->AFSMountPoint.Type = Type;
487
488                         pReparseInfo->AFSMountPoint.MountPointCellLength = Cell.Length;
489
490                         pReparseInfo->AFSMountPoint.MountPointVolumeLength = Volume.Length;
491
492                         RtlCopyMemory( pReparseInfo->AFSMountPoint.Buffer,
493                                        Cell.Buffer,
494                                        Cell.Length);
495
496                         RtlCopyMemory( &pReparseInfo->AFSMountPoint.Buffer[ Cell.Length / sizeof( WCHAR)],
497                                        Volume.Buffer,
498                                        Volume.Length);
499
500                         pReparseBuffer->ReparseDataLength = (FIELD_OFFSET( AFSReparseTagInfo, AFSMountPoint.Buffer) + Volume.Length + Cell.Length);
501
502                         break;
503                     }
504
505                     case AFS_FILE_TYPE_DFSLINK:
506                     {
507
508                         if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
509                         {
510
511                             ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
512
513                             break;
514                         }
515
516                         if( ulRemainingLen < (ULONG) FIELD_OFFSET( AFSReparseTagInfo, UNCReferral.Buffer) + pCcb->DirectoryCB->NameInformation.TargetName.Length)
517                         {
518
519                             ntStatus = STATUS_BUFFER_TOO_SMALL;
520
521                             Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
522                                                         FIELD_OFFSET( AFSReparseTagInfo, UNCReferral.Buffer) +
523                                                         pCcb->DirectoryCB->NameInformation.TargetName.Length;
524
525                             break;
526                         }
527
528                         pReparseInfo->SubTag = OPENAFS_SUBTAG_UNC;
529
530                         pReparseInfo->UNCReferral.UNCTargetLength = pCcb->DirectoryCB->NameInformation.TargetName.Length;
531
532                         RtlCopyMemory( pReparseInfo->UNCReferral.Buffer,
533                                        pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
534                                        pCcb->DirectoryCB->NameInformation.TargetName.Length);
535
536                         pReparseBuffer->ReparseDataLength = (FIELD_OFFSET( AFSReparseTagInfo, UNCReferral.Buffer) + pCcb->DirectoryCB->NameInformation.TargetName.Length);
537
538                         break;
539                     }
540
541                     default:
542
543                         ntStatus = STATUS_NOT_A_REPARSE_POINT;
544
545                         break;
546                 }
547
548                 if ( ntStatus == STATUS_SUCCESS)
549                 {
550
551                     ulRemainingLen -= pReparseBuffer->ReparseDataLength;
552
553                     pReparseBuffer->ReparseTag = IO_REPARSE_TAG_SURROGATE|IO_REPARSE_TAG_OPENAFS_DFS;
554
555                     RtlCopyMemory( &pReparseBuffer->ReparseGuid,
556                                    &GUID_AFS_REPARSE_GUID,
557                                    sizeof( GUID));
558
559                     Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
560                                                               pReparseBuffer->ReparseDataLength;
561                 }
562
563                 AFSReleaseResource( &pCcb->DirectoryCB->NonPaged->Lock);
564
565                 break;
566             }
567
568             case FSCTL_SET_REPARSE_POINT:
569             {
570
571                 REPARSE_GUID_DATA_BUFFER *pReparseBuffer = (REPARSE_GUID_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
572
573                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
574                               AFS_TRACE_LEVEL_VERBOSE_2,
575                               "AFSProcessUserFsRequest Processing FSCTL_SET_REPARSE_POINT request %wZ Type 0x%x Attrib 0x%x\n",
576                               &pCcb->DirectoryCB->NameInformation.FileName,
577                               pCcb->DirectoryCB->ObjectInformation->FileType,
578                               pCcb->DirectoryCB->ObjectInformation->FileAttributes);
579
580                 //
581                 // Check if we have the reparse entry set on the entry
582                 //
583
584                 if( !BooleanFlagOn( pCcb->DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
585                 {
586
587                     ntStatus = STATUS_NOT_A_REPARSE_POINT;
588
589                     break;
590                 }
591
592                 if( ulInputBufferLen < FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer))
593                 {
594
595                     ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
596
597                     break;
598                 }
599
600                 if( (pReparseBuffer->ReparseTag & 0x0000FFFF) != IO_REPARSE_TAG_OPENAFS_DFS)
601                 {
602
603                     ntStatus = STATUS_IO_REPARSE_TAG_MISMATCH;
604
605                     break;
606                 }
607
608                 if( RtlCompareMemory( &pReparseBuffer->ReparseGuid,
609                                       &GUID_AFS_REPARSE_GUID,
610                                       sizeof( GUID)) != sizeof( GUID))
611                 {
612
613                     ntStatus = STATUS_REPARSE_ATTRIBUTE_CONFLICT;
614
615                     break;
616                 }
617
618                 //
619                 // For now deny access on this call
620                 //
621
622                 ntStatus = STATUS_INVALID_PARAMETER;
623
624                 break;
625             }
626
627             case FSCTL_DELETE_REPARSE_POINT:
628             {
629
630                 REPARSE_GUID_DATA_BUFFER *pReparseBuffer = (REPARSE_GUID_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
631
632                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
633                               AFS_TRACE_LEVEL_VERBOSE_2,
634                               "AFSProcessUserFsRequest Processing FSCTL_DELETE_REPARSE_POINT request %wZ Type 0x%x Attrib 0x%x\n",
635                               &pCcb->DirectoryCB->NameInformation.FileName,
636                               pCcb->DirectoryCB->ObjectInformation->FileType,
637                               pCcb->DirectoryCB->ObjectInformation->FileAttributes);
638
639                 //
640                 // Check if we have the reparse entry set on the entry
641                 //
642
643                 if( !BooleanFlagOn( pCcb->DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
644                 {
645
646                     ntStatus = STATUS_NOT_A_REPARSE_POINT;
647
648                     break;
649                 }
650
651                 if( ulInputBufferLen < FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer))
652                 {
653
654                     ntStatus = STATUS_INVALID_PARAMETER;
655
656                     break;
657                 }
658
659                 if( (pReparseBuffer->ReparseTag & 0x0000FFFF) != IO_REPARSE_TAG_OPENAFS_DFS)
660                 {
661
662                     ntStatus = STATUS_IO_REPARSE_TAG_MISMATCH;
663
664                     break;
665                 }
666
667                 if( RtlCompareMemory( &pReparseBuffer->ReparseGuid,
668                                       &GUID_AFS_REPARSE_GUID,
669                                       sizeof( GUID)) != sizeof( GUID))
670                 {
671
672                     ntStatus = STATUS_REPARSE_ATTRIBUTE_CONFLICT;
673
674                     break;
675                 }
676
677                 //
678                 // For now deny access on this call
679                 //
680
681                 ntStatus = STATUS_ACCESS_DENIED;
682
683                 break;
684             }
685
686             default :
687
688                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
689                               AFS_TRACE_LEVEL_VERBOSE_2,
690                               "AFSProcessUserFsRequest Processing default (%08lX) request\n", ulFsControlCode);
691
692                 ntStatus = STATUS_INVALID_DEVICE_REQUEST;
693
694                 break;
695         }
696
697 try_exit:
698
699         NOTHING;
700     }
701
702     return ntStatus;
703 }
704
705 NTSTATUS
706 AFSProcessShareFsCtrl( IN IRP *Irp,
707                        IN AFSFcb *Fcb,
708                        IN AFSCcb *Ccb)
709 {
710
711     NTSTATUS ntStatus = STATUS_SUCCESS;
712     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
713     ULONG ulOutputBufferLen = 0, ulInputBufferLen;
714     ULONG ulFsControlCode;
715
716     __Enter
717     {
718
719         ulFsControlCode = pIrpSp->Parameters.FileSystemControl.FsControlCode;
720
721         ulOutputBufferLen = pIrpSp->Parameters.FileSystemControl.OutputBufferLength;
722         ulInputBufferLen = pIrpSp->Parameters.FileSystemControl.InputBufferLength;
723
724         switch( ulFsControlCode)
725         {
726
727             case FSCTL_PIPE_TRANSCEIVE:
728             {
729
730                 AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
731                               AFS_TRACE_LEVEL_VERBOSE,
732                               "AFSProcessShareFsCtrl On pipe %wZ Class FSCTL_PIPE_TRANSCEIVE\n",
733                               &Ccb->DirectoryCB->NameInformation.FileName);
734
735                 ntStatus = AFSNotifyPipeTransceive( Ccb,
736                                                     ulInputBufferLen,
737                                                     ulOutputBufferLen,
738                                                     pIrpSp->Parameters.FileSystemControl.Type3InputBuffer,
739                                                     Irp->UserBuffer,
740                                                     (ULONG *)&Irp->IoStatus.Information);
741
742                 if( !NT_SUCCESS( ntStatus))
743                 {
744
745                     AFSDbgLogMsg( AFS_SUBSYSTEM_PIPE_PROCESSING,
746                                   AFS_TRACE_LEVEL_VERBOSE,
747                                   "AFSProcessShareFsCtrl Failure on pipe %wZ Class FSCTL_PIPE_TRANSCEIVE Status %08lX\n",
748                                   &Ccb->DirectoryCB->NameInformation.FileName,
749                                   ntStatus);
750                 }
751
752                 break;
753             }
754
755             default:
756             {
757
758                 if( BooleanFlagOn( Ccb->DirectoryCB->Flags, AFS_DIR_ENTRY_SERVER_SERVICE))
759                 {
760
761                     //AFSPrint("AFSProcessShareFsCtrl (%08lX) For srvsvc input %08lX output %08lX\n",
762                     //                                                            ulFsControlCode,
763                     //                                                            ulInputBufferLen,
764                     //                                                            ulOutputBufferLen);
765                 }
766                 else if( BooleanFlagOn( Ccb->DirectoryCB->Flags, AFS_DIR_ENTRY_WORKSTATION_SERVICE))
767                 {
768
769                     //AFSPrint("AFSProcessShareFsCtrl (%08lX) For wkssvc input %08lX output %08lX\n",
770                     //                                                            ulFsControlCode,
771                     //                                                            ulInputBufferLen,
772                     //                                                            ulOutputBufferLen);
773                 }
774                 else
775                 {
776
777                     //AFSPrint("AFSProcessShareFsCtrl (%08lX) For IPC$ input %08lX output %08lX\n",
778                     //                                                            ulFsControlCode,
779                     //                                                            ulInputBufferLen,
780                     //                                                            ulOutputBufferLen);
781                 }
782
783                 break;
784             }
785         }
786     }
787
788     return ntStatus;
789 }