f995291fcc961d4ce1ced1f914300b6977bbb5c6
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSFSControl.cpp
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Kernel Drivers, LLC.
3  * Copyright (c) 2009, 2010, 2011, 2012, 2013 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, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
16  *   nor the names of their contributors may be used to endorse or promote
17  *   products derived from this software without specific prior written
18  *   permission from Kernel Drivers, LLC and Your File System, Inc.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
24  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 //
34 // File: AFSFSControl.cpp
35 //
36
37 #include "AFSCommon.h"
38
39 NTSTATUS
40 AFSFSControl( IN PDEVICE_OBJECT LibDeviceObject,
41               IN PIRP Irp)
42 {
43
44     UNREFERENCED_PARAMETER(LibDeviceObject);
45     NTSTATUS ntStatus = STATUS_SUCCESS;
46     IO_STACK_LOCATION *pIrpSp;
47
48     pIrpSp = IoGetCurrentIrpStackLocation( Irp);
49
50     __try
51     {
52
53         switch( pIrpSp->MinorFunction)
54         {
55
56             case IRP_MN_USER_FS_REQUEST:
57
58                 ntStatus = AFSProcessUserFsRequest( Irp);
59
60                 break;
61
62             case IRP_MN_MOUNT_VOLUME:
63
64                 break;
65
66             case IRP_MN_VERIFY_VOLUME:
67
68                 break;
69
70             default:
71
72                 break;
73         }
74
75         AFSCompleteRequest( Irp,
76                               ntStatus);
77
78     }
79     __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
80     {
81
82         AFSDbgTrace(( 0,
83                       0,
84                       "EXCEPTION - AFSFSControl\n"));
85
86         AFSDumpTraceFilesFnc();
87     }
88
89     return ntStatus;
90 }
91
92 static BOOLEAN
93 AFSParseMountPointTarget( IN  UNICODE_STRING *Target,
94                           OUT USHORT         *Type,
95                           OUT UNICODE_STRING *Volume,
96                           OUT UNICODE_STRING *Cell)
97 {
98     // Targets are of the form <type>[<cell>:]<volume>
99
100     *Type = Target->Buffer[ 0];
101
102     // Extract the cell name (if any)
103
104     Cell->Buffer = &Target->Buffer[ 1];
105
106     // Search for colon separator or end of counted string
107
108     for ( Cell->Length = 0; Cell->Length < Target->Length - sizeof( WCHAR); Cell->Length += sizeof( WCHAR))
109     {
110
111         if ( Cell->Buffer[ Cell->Length / sizeof( WCHAR)] == L':')
112         {
113             break;
114         }
115     }
116
117     // If a colon is not found, it means there is no cell
118
119     if ( Cell->Length < Target->Length - sizeof( WCHAR) &&
120          Cell->Buffer[ Cell->Length / sizeof( WCHAR)] == L':')
121     {
122
123         Cell->MaximumLength = Cell->Length;
124
125         if ( Cell->Length > Target->Length - 2 * sizeof( WCHAR))
126         {
127             // Invalid target string if there is no room for
128             // the volume name.
129
130             return FALSE;
131         }
132
133         Volume->Length = Volume->MaximumLength = (Target->Length - Cell->Length - 2 * sizeof( WCHAR));
134
135         Volume->Buffer = &Target->Buffer[ Cell->Length / sizeof( WCHAR) + 2];
136     }
137     else
138     {
139         // There is no cell
140
141         Volume->Length = Volume->MaximumLength = Cell->Length;
142
143         Volume->Buffer = Cell->Buffer;
144
145         Cell->Length = Cell->MaximumLength = 0;
146
147         Cell->Buffer = NULL;
148     }
149
150     return TRUE;
151 }
152
153 NTSTATUS
154 AFSProcessUserFsRequest( IN PIRP Irp)
155 {
156
157     NTSTATUS ntStatus = STATUS_SUCCESS;
158     ULONG ulFsControlCode;
159     AFSFcb *pFcb = NULL;
160     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp );
161     AFSCcb *pCcb = NULL;
162     ULONG ulOutputBufferLen, ulInputBufferLen;
163
164     __Enter
165     {
166
167         ulFsControlCode = pIrpSp->Parameters.FileSystemControl.FsControlCode;
168
169         pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
170
171         pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
172
173         if( pFcb == NULL ||
174             pCcb == NULL ||
175             pCcb->DirectoryCB == NULL)
176         {
177
178             AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 AFSDbgTrace(( 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                 REPARSE_DATA_BUFFER *pMSFTReparseBuffer = (REPARSE_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
323                 ULONG ulRemainingLen = ulOutputBufferLen;
324                 AFSReparseTagInfo *pReparseInfo = NULL;
325                 BOOLEAN bRelative = FALSE;
326                 BOOLEAN bDriveLetter = FALSE;
327                 WCHAR * PathBuffer = NULL;
328
329                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
330                               AFS_TRACE_LEVEL_VERBOSE_2,
331                               "AFSProcessUserFsRequest Processing FSCTL_GET_REPARSE_POINT request %wZ Type 0x%x Attrib 0x%x\n",
332                               &pCcb->DirectoryCB->NameInformation.FileName,
333                               pCcb->DirectoryCB->ObjectInformation->FileType,
334                               pCcb->DirectoryCB->ObjectInformation->FileAttributes));
335
336                 //
337                 // Check if we have the reparse entry set on the entry
338                 //
339
340                 if( !BooleanFlagOn( pCcb->DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
341                 {
342
343                     ntStatus = STATUS_NOT_A_REPARSE_POINT;
344
345                     break;
346                 }
347
348
349                 switch ( pCcb->DirectoryCB->ObjectInformation->FileType) {
350                 case AFS_FILE_TYPE_MOUNTPOINT:
351
352                     if( ulOutputBufferLen < FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer))
353                     {
354
355                         ntStatus = STATUS_BUFFER_TOO_SMALL;
356
357                         Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer);
358
359                         break;
360                     }
361
362                     ulRemainingLen -= FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer);
363
364                     break;
365
366                 default:
367
368                     if( ulOutputBufferLen < FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer))
369                     {
370
371                         ntStatus = STATUS_BUFFER_TOO_SMALL;
372
373                         Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer);
374
375                         break;
376                     }
377
378                     ulRemainingLen -= FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer);
379
380                     break;
381                 }
382
383                 //
384                 // Populate the data in the reparse buffer
385                 //
386
387                 pReparseBuffer->ReparseDataLength  = 0;
388
389                 AFSAcquireExcl( &pCcb->DirectoryCB->NonPaged->Lock,
390                                 TRUE);
391
392                 if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
393                 {
394
395                     //
396                     // We'll reset the DV to ensure we validate the metadata content
397                     //
398
399                     pCcb->DirectoryCB->ObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
400
401                     SetFlag( pCcb->DirectoryCB->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
402
403                     AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
404                                   AFS_TRACE_LEVEL_VERBOSE,
405                                   "AFSProcessUserFsRequest Verifying symlink %wZ FID %08lX-%08lX-%08lX-%08lX\n",
406                                   &pCcb->DirectoryCB->NameInformation.FileName,
407                                   pCcb->DirectoryCB->ObjectInformation->FileId.Cell,
408                                   pCcb->DirectoryCB->ObjectInformation->FileId.Volume,
409                                   pCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
410                                   pCcb->DirectoryCB->ObjectInformation->FileId.Unique));
411
412                     ntStatus = AFSVerifyEntry( &pCcb->AuthGroup,
413                                                pCcb->DirectoryCB);
414
415                     if( !NT_SUCCESS( ntStatus))
416                     {
417
418                         AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
419                                       AFS_TRACE_LEVEL_ERROR,
420                                       "AFSProcessUserFsRequest Failed to verify symlink %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
421                                       &pCcb->DirectoryCB->NameInformation.FileName,
422                                       pCcb->DirectoryCB->ObjectInformation->FileId.Cell,
423                                       pCcb->DirectoryCB->ObjectInformation->FileId.Volume,
424                                       pCcb->DirectoryCB->ObjectInformation->FileId.Vnode,
425                                       pCcb->DirectoryCB->ObjectInformation->FileId.Unique,
426                                       ntStatus));
427
428                         AFSReleaseResource( &pCcb->DirectoryCB->NonPaged->Lock);
429
430                         break;
431                     }
432                 }
433
434                 pReparseInfo = (AFSReparseTagInfo *)&pReparseBuffer->GenericReparseBuffer.DataBuffer[ 0];
435
436                 switch( pCcb->DirectoryCB->ObjectInformation->FileType)
437                 {
438
439                     case AFS_FILE_TYPE_SYMLINK:
440                     {
441
442                         if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
443                         {
444
445                             ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
446
447                             break;
448                         }
449
450                         bRelative = AFSIsRelativeName( &pCcb->DirectoryCB->NameInformation.TargetName);
451
452                         if ( bRelative)
453                         {
454
455                             if( ulRemainingLen < (ULONG) FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
456                                 pCcb->DirectoryCB->NameInformation.TargetName.Length)
457                             {
458
459                                 ntStatus = STATUS_BUFFER_TOO_SMALL;
460
461                                 Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
462                                     pCcb->DirectoryCB->NameInformation.TargetName.Length;
463
464                                 break;
465                             }
466
467                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.Flags = SYMLINK_FLAG_RELATIVE;
468
469                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength =
470                                 pCcb->DirectoryCB->NameInformation.TargetName.Length;
471
472                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength =
473                                 pCcb->DirectoryCB->NameInformation.TargetName.Length;
474
475                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameOffset = 0;
476
477                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameOffset = 0;
478
479                             PathBuffer = pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PathBuffer;
480
481                             RtlCopyMemory( PathBuffer,
482                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
483                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
484
485                             pReparseBuffer->ReparseDataLength = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) -
486                                 FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
487                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength;
488                         }
489                         else
490                         {
491
492                             if( ulRemainingLen < (ULONG) FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
493                                 /* Display Name */
494                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 1 * sizeof( WCHAR) +
495                                 /* Substitute Name */
496                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 7 * sizeof( WCHAR))
497                             {
498
499                                 ntStatus = STATUS_BUFFER_TOO_SMALL;
500
501                                 Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
502                                     pCcb->DirectoryCB->NameInformation.TargetName.Length + 1 * sizeof( WCHAR) +
503                                     pCcb->DirectoryCB->NameInformation.TargetName.Length + 7 * sizeof( WCHAR);
504
505                                 break;
506                             }
507
508                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.Flags = 0;
509
510                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength =
511                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 7 * sizeof( WCHAR);
512
513                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength =
514                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 1 * sizeof( WCHAR);
515
516                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameOffset =
517                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength;
518
519                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameOffset = 0;
520
521                             PathBuffer = pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PathBuffer;
522
523                             /* Display Name */
524                             *PathBuffer++ = L'\\';
525
526                             RtlCopyMemory( PathBuffer,
527                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
528                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
529
530                             PathBuffer += pCcb->DirectoryCB->NameInformation.TargetName.Length / sizeof( WCHAR);
531
532                             /* Substitute Name */
533                             *PathBuffer++ = L'\\';
534                             *PathBuffer++ = L'?';
535                             *PathBuffer++ = L'?';
536                             *PathBuffer++ = L'\\';
537                             *PathBuffer++ = L'U';
538                             *PathBuffer++ = L'N';
539                             *PathBuffer++ = L'C';
540
541                             RtlCopyMemory( PathBuffer,
542                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
543                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
544
545                             pReparseBuffer->ReparseDataLength = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) -
546                                 FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
547                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength +
548                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength;
549                         }
550
551                         break;
552                     }
553
554                     case AFS_FILE_TYPE_MOUNTPOINT:
555                     {
556                         UNICODE_STRING Cell, Volume;
557                         USHORT Type;
558
559                         if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
560                         {
561                             ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
562
563                             break;
564                         }
565
566                         if ( !AFSParseMountPointTarget( &pCcb->DirectoryCB->NameInformation.TargetName,
567                                                         &Type,
568                                                         &Volume,
569                                                         &Cell))
570                         {
571                             ntStatus = STATUS_INVALID_PARAMETER;
572
573                             break;
574                         }
575
576                         if( ulRemainingLen < (ULONG) FIELD_OFFSET( AFSReparseTagInfo, AFSMountPoint.Buffer) + Volume.Length + Cell.Length)
577                         {
578
579                             ntStatus = STATUS_BUFFER_TOO_SMALL;
580
581                             Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
582                                                         FIELD_OFFSET( AFSReparseTagInfo, AFSMountPoint.Buffer) +
583                                                         Volume.Length + Cell.Length;
584
585                             break;
586                         }
587
588                         pReparseInfo->SubTag = OPENAFS_SUBTAG_MOUNTPOINT;
589
590                         pReparseInfo->AFSMountPoint.Type = Type;
591
592                         pReparseInfo->AFSMountPoint.MountPointCellLength = Cell.Length;
593
594                         pReparseInfo->AFSMountPoint.MountPointVolumeLength = Volume.Length;
595
596                         RtlCopyMemory( pReparseInfo->AFSMountPoint.Buffer,
597                                        Cell.Buffer,
598                                        Cell.Length);
599
600                         RtlCopyMemory( &pReparseInfo->AFSMountPoint.Buffer[ Cell.Length / sizeof( WCHAR)],
601                                        Volume.Buffer,
602                                        Volume.Length);
603
604                         pReparseBuffer->ReparseDataLength = (FIELD_OFFSET( AFSReparseTagInfo, AFSMountPoint.Buffer) + Volume.Length + Cell.Length);
605
606                         break;
607                     }
608
609                     case AFS_FILE_TYPE_DFSLINK:
610                     {
611
612                         if( pCcb->DirectoryCB->NameInformation.TargetName.Length == 0)
613                         {
614
615                             ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
616
617                             break;
618                         }
619
620                         bRelative = ( pCcb->DirectoryCB->NameInformation.TargetName.Buffer[0] == L'\\');
621
622                         bDriveLetter = (bRelative == FALSE && pCcb->DirectoryCB->NameInformation.TargetName.Buffer[1] == L':');
623
624                         if ( bRelative)
625                         {
626
627                             if( ulRemainingLen < (ULONG) FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
628                                 pCcb->DirectoryCB->NameInformation.TargetName.Length)
629                             {
630
631                                 ntStatus = STATUS_BUFFER_TOO_SMALL;
632
633                                 Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
634                                     pCcb->DirectoryCB->NameInformation.TargetName.Length;
635
636                                 break;
637                             }
638
639                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.Flags = SYMLINK_FLAG_RELATIVE;
640
641                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength =
642                                 pCcb->DirectoryCB->NameInformation.TargetName.Length;
643
644                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength =
645                                 pCcb->DirectoryCB->NameInformation.TargetName.Length;
646
647                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameOffset = 0;
648
649                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameOffset = 0;
650
651                             PathBuffer = pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PathBuffer;
652
653                             RtlCopyMemory( PathBuffer,
654                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
655                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
656
657                             pReparseBuffer->ReparseDataLength = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) -
658                                 FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
659                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength;
660                         }
661                         else if ( bDriveLetter)
662                         {
663
664                             if( ulRemainingLen < (ULONG) FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
665                                 /* Display Name */
666                                 pCcb->DirectoryCB->NameInformation.TargetName.Length +
667                                 /* Substitute Name */
668                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 4 * sizeof( WCHAR))
669                             {
670
671                                 ntStatus = STATUS_BUFFER_TOO_SMALL;
672
673                                 Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
674                                     pCcb->DirectoryCB->NameInformation.TargetName.Length +
675                                     pCcb->DirectoryCB->NameInformation.TargetName.Length + 4 * sizeof( WCHAR);
676
677                                 break;
678                             }
679
680                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.Flags = 0;
681
682                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength =
683                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 4 * sizeof( WCHAR);
684
685                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength =
686                                 pCcb->DirectoryCB->NameInformation.TargetName.Length;
687
688                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameOffset =
689                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength;
690
691                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameOffset = 0;
692
693                             PathBuffer = pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PathBuffer;
694
695                             /* Display Name */
696                             RtlCopyMemory( PathBuffer,
697                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
698                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
699
700                             PathBuffer += pCcb->DirectoryCB->NameInformation.TargetName.Length / sizeof( WCHAR);
701
702                             /* Substitute Name */
703                             *PathBuffer++ = L'\\';
704                             *PathBuffer++ = L'?';
705                             *PathBuffer++ = L'?';
706                             *PathBuffer++ = L'\\';
707
708                             RtlCopyMemory( PathBuffer,
709                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
710                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
711
712                             pReparseBuffer->ReparseDataLength = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) -
713                                 FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
714                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength +
715                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength;
716                         }
717                         else
718                         {
719
720                             if( ulRemainingLen < (ULONG) FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
721                                 /* Display Name */
722                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 1 * sizeof( WCHAR) +
723                                 /* Substitute Name */
724                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 7 * sizeof( WCHAR))
725                             {
726
727                                 ntStatus = STATUS_BUFFER_TOO_SMALL;
728
729                                 Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) +
730                                     pCcb->DirectoryCB->NameInformation.TargetName.Length + 1 * sizeof( WCHAR) +
731                                     pCcb->DirectoryCB->NameInformation.TargetName.Length + 7 * sizeof( WCHAR);
732
733                                 break;
734                             }
735
736                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.Flags = 0;
737
738                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength =
739                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 7 * sizeof( WCHAR);
740
741                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength =
742                                 pCcb->DirectoryCB->NameInformation.TargetName.Length + 1 * sizeof( WCHAR);
743
744                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameOffset =
745                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength;
746
747                             pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameOffset = 0;
748
749                             PathBuffer = pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PathBuffer;
750
751                             /* Display Name */
752                             *PathBuffer++ = L'\\';
753
754                             RtlCopyMemory( PathBuffer,
755                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
756                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
757
758                             PathBuffer += pCcb->DirectoryCB->NameInformation.TargetName.Length / sizeof( WCHAR);
759
760                             /* Substitute Name */
761                             *PathBuffer++ = L'\\';
762                             *PathBuffer++ = L'?';
763                             *PathBuffer++ = L'?';
764                             *PathBuffer++ = L'\\';
765                             *PathBuffer++ = L'U';
766                             *PathBuffer++ = L'N';
767                             *PathBuffer++ = L'C';
768
769                             RtlCopyMemory( PathBuffer,
770                                            pCcb->DirectoryCB->NameInformation.TargetName.Buffer,
771                                            pCcb->DirectoryCB->NameInformation.TargetName.Length);
772
773                             pReparseBuffer->ReparseDataLength = FIELD_OFFSET( REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer) -
774                                 FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
775                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.PrintNameLength +
776                                 pMSFTReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength;
777                         }
778
779                         break;
780                     }
781
782                     default:
783
784                         ntStatus = STATUS_NOT_A_REPARSE_POINT;
785
786                         break;
787                 }
788
789                 if ( ntStatus == STATUS_SUCCESS)
790                 {
791
792                     ulRemainingLen -= pReparseBuffer->ReparseDataLength;
793
794                     if ( pCcb->DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_MOUNTPOINT)
795                     {
796
797                         pReparseBuffer->ReparseTag = IO_REPARSE_TAG_SURROGATE|IO_REPARSE_TAG_OPENAFS_DFS;
798
799                         RtlCopyMemory( &pReparseBuffer->ReparseGuid,
800                                        &GUID_AFS_REPARSE_GUID,
801                                        sizeof( GUID));
802
803                         Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer)
804                             + pReparseBuffer->ReparseDataLength;
805                     }
806                     else
807                     {
808
809                         pReparseBuffer->ReparseTag = IO_REPARSE_TAG_SYMLINK;
810
811                         Irp->IoStatus.Information = FIELD_OFFSET( REPARSE_DATA_BUFFER, GenericReparseBuffer.DataBuffer)
812                             + pReparseBuffer->ReparseDataLength;
813                     }
814                 }
815
816                 AFSReleaseResource( &pCcb->DirectoryCB->NonPaged->Lock);
817
818                 break;
819             }
820
821             case FSCTL_SET_REPARSE_POINT:
822             {
823
824                 REPARSE_GUID_DATA_BUFFER *pReparseGUIDBuffer = (REPARSE_GUID_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
825                 REPARSE_DATA_BUFFER *pReparseBuffer = NULL;
826                 AFSReparseTagInfo *pReparseInfo = NULL;
827                 AFSObjectInfoCB *pParentObjectInfo = NULL;
828                 UNICODE_STRING uniTargetName;
829                 ULONGLONG ullIndex = 0;
830                 LONG lCount;
831
832                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
833                               AFS_TRACE_LEVEL_VERBOSE,
834                               "AFSProcessUserFsRequest Processing FSCTL_SET_REPARSE_POINT request %wZ Type 0x%x Attrib 0x%x\n",
835                               &pCcb->DirectoryCB->NameInformation.FileName,
836                               pCcb->DirectoryCB->ObjectInformation->FileType,
837                               pCcb->DirectoryCB->ObjectInformation->FileAttributes));
838
839                 if( ulInputBufferLen < FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer))
840                 {
841
842                     ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
843
844                     break;
845                 }
846
847                 if( (pReparseGUIDBuffer->ReparseTag & 0x0000FFFF) == IO_REPARSE_TAG_OPENAFS_DFS)
848                 {
849
850                     if( RtlCompareMemory( &pReparseGUIDBuffer->ReparseGuid,
851                                           &GUID_AFS_REPARSE_GUID,
852                                           sizeof( GUID)) != sizeof( GUID))
853                     {
854
855                         ntStatus = STATUS_REPARSE_ATTRIBUTE_CONFLICT;
856
857                         break;
858                     }
859
860                     if( ulInputBufferLen < FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
861                                                                         sizeof( AFSReparseTagInfo))
862                     {
863
864                         ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
865
866                         break;
867                     }
868
869                     pReparseInfo = (AFSReparseTagInfo *)pReparseGUIDBuffer->GenericReparseBuffer.DataBuffer;
870
871                     switch( pReparseInfo->SubTag)
872                     {
873
874                         case OPENAFS_SUBTAG_SYMLINK:
875                         {
876
877                             if( ulInputBufferLen < (ULONG)(FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
878                                                            FIELD_OFFSET( AFSReparseTagInfo, AFSSymLink.Buffer) +
879                                                            pReparseInfo->AFSSymLink.SymLinkTargetLength))
880                             {
881
882                                 ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
883
884                                 break;
885                             }
886
887                             uniTargetName.Length = pReparseInfo->AFSSymLink.SymLinkTargetLength;
888                             uniTargetName.MaximumLength = uniTargetName.Length;
889
890                             uniTargetName.Buffer = (WCHAR *)pReparseInfo->AFSSymLink.Buffer;
891
892                             break;
893                         }
894
895                         case OPENAFS_SUBTAG_UNC:
896                         {
897
898                             if( ulInputBufferLen < (ULONG)(FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer) +
899                                                            FIELD_OFFSET( AFSReparseTagInfo, UNCReferral.Buffer) +
900                                                            pReparseInfo->UNCReferral.UNCTargetLength))
901                             {
902
903                                 ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
904
905                                 break;
906                             }
907
908                             uniTargetName.Length = pReparseInfo->UNCReferral.UNCTargetLength;
909                             uniTargetName.MaximumLength = uniTargetName.Length;
910
911                             uniTargetName.Buffer = (WCHAR *)pReparseInfo->UNCReferral.Buffer;
912
913                             break;
914                         }
915
916                         case OPENAFS_SUBTAG_MOUNTPOINT:
917                             //
918                             // Not yet handled
919                             //
920                         default:
921                         {
922
923                             ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
924
925                             break;
926                         }
927                     }
928                 }
929                 else
930                 {
931                     //
932                     // Handle Microsoft Reparse Tags
933                     //
934
935                     switch( pReparseGUIDBuffer->ReparseTag)
936                     {
937
938                         case IO_REPARSE_TAG_MOUNT_POINT:
939                         {
940
941                             pReparseBuffer = (REPARSE_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
942
943                             uniTargetName.Length = pReparseBuffer->MountPointReparseBuffer.PrintNameLength;
944                             uniTargetName.MaximumLength = uniTargetName.Length;
945
946                             uniTargetName.Buffer = (WCHAR *)((char *)pReparseBuffer->MountPointReparseBuffer.PathBuffer +
947                                                               pReparseBuffer->MountPointReparseBuffer.PrintNameOffset);
948
949                             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
950                                           AFS_TRACE_LEVEL_VERBOSE_2,
951                                           "AFSProcessUserFsRequest IO_REPARSE_TAG_MOUNT_POINT request %wZ\n",
952                                           &uniTargetName));
953
954                             ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
955
956                             break;
957                         }
958
959                         case IO_REPARSE_TAG_SYMLINK:
960                         {
961
962                             pReparseBuffer = (REPARSE_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
963
964                             uniTargetName.Length = pReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength;
965                             uniTargetName.MaximumLength = uniTargetName.Length;
966
967                             uniTargetName.Buffer = (WCHAR *)((char *)pReparseBuffer->SymbolicLinkReparseBuffer.PathBuffer +
968                                                               pReparseBuffer->SymbolicLinkReparseBuffer.SubstituteNameOffset);
969
970                             AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
971                                           AFS_TRACE_LEVEL_VERBOSE_2,
972                                           "AFSProcessUserFsRequest IO_REPARSE_TAG_SYMLINK request %wZ\n",
973                                           &uniTargetName));
974                             break;
975                         }
976
977                         default:
978                         {
979
980                             ntStatus = STATUS_IO_REPARSE_DATA_INVALID;
981
982                             break;
983                         }
984                     }
985                 }
986
987                 if( !NT_SUCCESS( ntStatus))
988                 {
989
990                     break;
991                 }
992
993                 //
994                 // First thing is to locate/create our object information block
995                 // for this entry
996                 //
997
998                 AFSAcquireExcl( pCcb->DirectoryCB->ObjectInformation->VolumeCB->ObjectInfoTree.TreeLock,
999                                 TRUE);
1000
1001                 if ( AFSIsVolumeFID( &pCcb->DirectoryCB->ObjectInformation->ParentFileId))
1002                 {
1003
1004                     pParentObjectInfo = &pCcb->DirectoryCB->ObjectInformation->VolumeCB->ObjectInformation;
1005                 }
1006                 else
1007                 {
1008                     ullIndex = AFSCreateLowIndex( &pCcb->DirectoryCB->ObjectInformation->ParentFileId);
1009
1010                     ntStatus = AFSLocateHashEntry( pCcb->DirectoryCB->ObjectInformation->VolumeCB->ObjectInfoTree.TreeHead,
1011                                                    ullIndex,
1012                                                    (AFSBTreeEntry **)&pParentObjectInfo);
1013                 }
1014
1015                 if ( NT_SUCCESS( ntStatus))
1016                 {
1017
1018                     lCount = AFSObjectInfoIncrement( pParentObjectInfo,
1019                                                      AFS_OBJECT_REFERENCE_FS_REQ);
1020
1021                     AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
1022                                   AFS_TRACE_LEVEL_VERBOSE,
1023                                   "AFSProcessUserFsRequest Increment count on object %p Cnt %d\n",
1024                                   pParentObjectInfo,
1025                                   lCount));
1026                 }
1027
1028                 AFSReleaseResource( pCcb->DirectoryCB->ObjectInformation->VolumeCB->ObjectInfoTree.TreeLock);
1029
1030                 if ( NT_SUCCESS( ntStatus))
1031                 {
1032
1033                     //
1034                     // Extract out the information to the call to the service
1035                     //
1036
1037                     ntStatus = AFSCreateSymlink( &pCcb->AuthGroup,
1038                                                  pParentObjectInfo,
1039                                                  &pCcb->DirectoryCB->NameInformation.FileName,
1040                                                  pCcb->DirectoryCB->ObjectInformation,
1041                                                  &uniTargetName);
1042
1043                     AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1044                                   AFS_TRACE_LEVEL_VERBOSE_2,
1045                                   "AFSProcessUserFsRequest Processed FSCTL_SET_REPARSE_POINT request %wZ Type 0x%x Attrib 0x%x Status %08lX\n",
1046                                   &pCcb->DirectoryCB->NameInformation.FileName,
1047                                   pCcb->DirectoryCB->ObjectInformation->FileType,
1048                                   pCcb->DirectoryCB->ObjectInformation->FileAttributes,
1049                                   ntStatus));
1050
1051                     lCount = AFSObjectInfoDecrement( pParentObjectInfo,
1052                                                      AFS_OBJECT_REFERENCE_FS_REQ);
1053
1054                     AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
1055                                   AFS_TRACE_LEVEL_VERBOSE,
1056                                   "AFSProcessUserFsRequest Decrement count on object %p Cnt %d\n",
1057                                   pParentObjectInfo,
1058                                   lCount));
1059                 }
1060
1061                 break;
1062             }
1063
1064             case FSCTL_DELETE_REPARSE_POINT:
1065             {
1066
1067                 REPARSE_GUID_DATA_BUFFER *pReparseBuffer = (REPARSE_GUID_DATA_BUFFER *)Irp->AssociatedIrp.SystemBuffer;
1068
1069                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1070                               AFS_TRACE_LEVEL_VERBOSE_2,
1071                               "AFSProcessUserFsRequest Processing FSCTL_DELETE_REPARSE_POINT request %wZ Type 0x%x Attrib 0x%x\n",
1072                               &pCcb->DirectoryCB->NameInformation.FileName,
1073                               pCcb->DirectoryCB->ObjectInformation->FileType,
1074                               pCcb->DirectoryCB->ObjectInformation->FileAttributes));
1075
1076                 //
1077                 // Check if we have the reparse entry set on the entry
1078                 //
1079
1080                 if( !BooleanFlagOn( pCcb->DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
1081                 {
1082
1083                     ntStatus = STATUS_NOT_A_REPARSE_POINT;
1084
1085                     break;
1086                 }
1087
1088                 if( ulInputBufferLen < FIELD_OFFSET( REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer.DataBuffer))
1089                 {
1090
1091                     ntStatus = STATUS_INVALID_PARAMETER;
1092
1093                     break;
1094                 }
1095
1096                 if( (pReparseBuffer->ReparseTag & 0x0000FFFF) != IO_REPARSE_TAG_OPENAFS_DFS)
1097                 {
1098
1099                     ntStatus = STATUS_IO_REPARSE_TAG_MISMATCH;
1100
1101                     break;
1102                 }
1103
1104                 if( RtlCompareMemory( &pReparseBuffer->ReparseGuid,
1105                                       &GUID_AFS_REPARSE_GUID,
1106                                       sizeof( GUID)) != sizeof( GUID))
1107                 {
1108
1109                     ntStatus = STATUS_REPARSE_ATTRIBUTE_CONFLICT;
1110
1111                     break;
1112                 }
1113
1114                 //
1115                 // Claim success.  The typical usage is setting delete on close
1116                 // as the next operation on the reparse point before closing
1117                 // the handle.
1118                 //
1119
1120                 ntStatus = STATUS_SUCCESS;
1121
1122                 break;
1123             }
1124
1125 #ifndef FSCTL_SET_PURGE_FAILURE_MODE
1126 #define FSCTL_SET_PURGE_FAILURE_MODE        CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 156, METHOD_BUFFERED, FILE_ANY_ACCESS)
1127 #endif
1128
1129             case FSCTL_SET_PURGE_FAILURE_MODE:
1130             {
1131
1132                 //
1133                 // For the time being just succeed this call
1134                 //
1135
1136                 ntStatus = STATUS_SUCCESS;
1137
1138                 break;
1139             }
1140
1141             default :
1142             {
1143
1144                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
1145                               AFS_TRACE_LEVEL_VERBOSE_2,
1146                               "AFSProcessUserFsRequest Processing default (%08lX) request\n",
1147                               ulFsControlCode));
1148
1149                 ntStatus = STATUS_INVALID_DEVICE_REQUEST;
1150
1151                 break;
1152             }
1153         }
1154
1155 try_exit:
1156
1157         NOTHING;
1158     }
1159
1160     return ntStatus;
1161 }
1162
1163 NTSTATUS
1164 AFSProcessShareFsCtrl( IN IRP *Irp,
1165                        IN AFSFcb *Fcb,
1166                        IN AFSCcb *Ccb)
1167 {
1168
1169     UNREFERENCED_PARAMETER(Fcb);
1170     NTSTATUS ntStatus = STATUS_SUCCESS;
1171     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
1172     ULONG ulOutputBufferLen = 0, ulInputBufferLen;
1173     ULONG ulFsControlCode;
1174
1175     __Enter
1176     {
1177
1178         ulFsControlCode = pIrpSp->Parameters.FileSystemControl.FsControlCode;
1179
1180         ulOutputBufferLen = pIrpSp->Parameters.FileSystemControl.OutputBufferLength;
1181         ulInputBufferLen = pIrpSp->Parameters.FileSystemControl.InputBufferLength;
1182
1183         switch( ulFsControlCode)
1184         {
1185
1186             case FSCTL_PIPE_TRANSCEIVE:
1187             {
1188
1189                 AFSDbgTrace(( AFS_SUBSYSTEM_PIPE_PROCESSING,
1190                               AFS_TRACE_LEVEL_VERBOSE,
1191                               "AFSProcessShareFsCtrl On pipe %wZ Class FSCTL_PIPE_TRANSCEIVE\n",
1192                               &Ccb->DirectoryCB->NameInformation.FileName));
1193
1194                 ntStatus = AFSNotifyPipeTransceive( Ccb,
1195                                                     ulInputBufferLen,
1196                                                     ulOutputBufferLen,
1197                                                     pIrpSp->Parameters.FileSystemControl.Type3InputBuffer,
1198                                                     Irp->UserBuffer,
1199                                                     (ULONG *)&Irp->IoStatus.Information);
1200
1201                 if( !NT_SUCCESS( ntStatus))
1202                 {
1203
1204                     AFSDbgTrace(( AFS_SUBSYSTEM_PIPE_PROCESSING,
1205                                   AFS_TRACE_LEVEL_VERBOSE,
1206                                   "AFSProcessShareFsCtrl Failure on pipe %wZ Class FSCTL_PIPE_TRANSCEIVE Status %08lX\n",
1207                                   &Ccb->DirectoryCB->NameInformation.FileName,
1208                                   ntStatus));
1209                 }
1210
1211                 break;
1212             }
1213
1214             default:
1215             {
1216
1217                 AFSPrint( "AFSProcessShareFsCtrl (%08lX) For IPC$ input %08lX output %08lX\n",
1218                           ulFsControlCode,
1219                           ulInputBufferLen,
1220                           ulOutputBufferLen);
1221
1222                 break;
1223             }
1224         }
1225     }
1226
1227     return ntStatus;
1228 }