[RXCE]
[reactos.git] / reactos / sdk / lib / drivers / rdbsslib / rdbss.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2017 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: sdk/lib/drivers/rdbsslib/rdbss.c
23 * PURPOSE: RDBSS library
24 * PROGRAMMER: Pierre Schweitzer (pierre@reactos.org)
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include <rx.h>
30 #include <pseh/pseh2.h>
31 #include <limits.h>
32 #include <dfs.h>
33 #include <copysup.h>
34
35 #define NDEBUG
36 #include <debug.h>
37
38 #define RX_TOPLEVELCTX_FLAG_FROM_POOL 1
39
40 typedef
41 NTSTATUS
42 (NTAPI *PRX_FSD_DISPATCH) (
43 PRX_CONTEXT Context);
44
45 typedef struct _RX_FSD_DISPATCH_VECTOR
46 {
47 PRX_FSD_DISPATCH CommonRoutine;
48 } RX_FSD_DISPATCH_VECTOR, *PRX_FSD_DISPATCH_VECTOR;
49
50 VOID
51 NTAPI
52 RxAcquireFileForNtCreateSection(
53 PFILE_OBJECT FileObject);
54
55 NTSTATUS
56 NTAPI
57 RxAcquireForCcFlush(
58 PFILE_OBJECT FileObject,
59 PDEVICE_OBJECT DeviceObject);
60
61 VOID
62 RxAddToTopLevelIrpAllocatedContextsList(
63 PRX_TOPLEVELIRP_CONTEXT TopLevelContext);
64
65 VOID
66 RxAssert(
67 PVOID Assert,
68 PVOID File,
69 ULONG Line,
70 PVOID Message);
71
72 NTSTATUS
73 NTAPI
74 RxCommonCleanup(
75 PRX_CONTEXT Context);
76
77 NTSTATUS
78 NTAPI
79 RxCommonClose(
80 PRX_CONTEXT Context);
81
82 NTSTATUS
83 NTAPI
84 RxCommonCreate(
85 PRX_CONTEXT Context);
86
87 NTSTATUS
88 NTAPI
89 RxCommonDevFCBCleanup(
90 PRX_CONTEXT Context);
91
92 NTSTATUS
93 NTAPI
94 RxCommonDevFCBClose(
95 PRX_CONTEXT Context);
96
97 NTSTATUS
98 NTAPI
99 RxCommonDevFCBFsCtl(
100 PRX_CONTEXT Context);
101
102 NTSTATUS
103 NTAPI
104 RxCommonDevFCBIoCtl(
105 PRX_CONTEXT Context);
106
107 NTSTATUS
108 NTAPI
109 RxCommonDevFCBQueryVolInfo(
110 PRX_CONTEXT Context);
111
112 NTSTATUS
113 NTAPI
114 RxCommonDeviceControl(
115 PRX_CONTEXT Context);
116
117 NTSTATUS
118 NTAPI
119 RxCommonDirectoryControl(
120 PRX_CONTEXT Context);
121
122 NTSTATUS
123 NTAPI
124 RxCommonDispatchProblem(
125 PRX_CONTEXT Context);
126
127 NTSTATUS
128 NTAPI
129 RxCommonFileSystemControl(
130 PRX_CONTEXT Context);
131
132 NTSTATUS
133 NTAPI
134 RxCommonFlushBuffers(
135 PRX_CONTEXT Context);
136
137 NTSTATUS
138 NTAPI
139 RxCommonLockControl(
140 PRX_CONTEXT Context);
141
142 NTSTATUS
143 NTAPI
144 RxCommonQueryEa(
145 PRX_CONTEXT Context);
146
147 NTSTATUS
148 NTAPI
149 RxCommonQueryInformation(
150 PRX_CONTEXT Context);
151
152 NTSTATUS
153 NTAPI
154 RxCommonQueryQuotaInformation(
155 PRX_CONTEXT Context);
156
157 NTSTATUS
158 NTAPI
159 RxCommonQuerySecurity(
160 PRX_CONTEXT Context);
161
162 NTSTATUS
163 NTAPI
164 RxCommonQueryVolumeInformation(
165 PRX_CONTEXT Context);
166
167 NTSTATUS
168 NTAPI
169 RxCommonRead(
170 PRX_CONTEXT Context);
171
172 NTSTATUS
173 NTAPI
174 RxCommonSetEa(
175 PRX_CONTEXT Context);
176
177 NTSTATUS
178 NTAPI
179 RxCommonSetInformation(
180 PRX_CONTEXT Context);
181
182 NTSTATUS
183 NTAPI
184 RxCommonSetQuotaInformation(
185 PRX_CONTEXT Context);
186
187 NTSTATUS
188 NTAPI
189 RxCommonSetSecurity(
190 PRX_CONTEXT Context);
191
192 NTSTATUS
193 NTAPI
194 RxCommonSetVolumeInformation(
195 PRX_CONTEXT Context);
196
197 NTSTATUS
198 NTAPI
199 RxCommonUnimplemented(
200 PRX_CONTEXT Context);
201
202 NTSTATUS
203 NTAPI
204 RxCommonWrite(
205 PRX_CONTEXT Context);
206
207 VOID
208 RxCopyCreateParameters(
209 IN PRX_CONTEXT RxContext);
210
211 NTSTATUS
212 RxCreateFromNetRoot(
213 PRX_CONTEXT Context,
214 PUNICODE_STRING NetRootName);
215
216 NTSTATUS
217 RxCreateTreeConnect(
218 IN PRX_CONTEXT RxContext);
219
220 BOOLEAN
221 NTAPI
222 RxFastIoCheckIfPossible(
223 PFILE_OBJECT FileObject,
224 PLARGE_INTEGER FileOffset,
225 ULONG Length, BOOLEAN Wait,
226 ULONG LockKey, BOOLEAN CheckForReadOperation,
227 PIO_STATUS_BLOCK IoStatus,
228 PDEVICE_OBJECT DeviceObject);
229
230 BOOLEAN
231 NTAPI
232 RxFastIoDeviceControl(
233 PFILE_OBJECT FileObject,
234 BOOLEAN Wait,
235 PVOID InputBuffer OPTIONAL,
236 ULONG InputBufferLength,
237 PVOID OutputBuffer OPTIONAL,
238 ULONG OutputBufferLength,
239 ULONG IoControlCode,
240 PIO_STATUS_BLOCK IoStatus,
241 PDEVICE_OBJECT DeviceObject);
242
243 BOOLEAN
244 NTAPI
245 RxFastIoRead(
246 PFILE_OBJECT FileObject,
247 PLARGE_INTEGER FileOffset,
248 ULONG Length,
249 BOOLEAN Wait,
250 ULONG LockKey,
251 PVOID Buffer,
252 PIO_STATUS_BLOCK IoStatus,
253 PDEVICE_OBJECT DeviceObject);
254
255 BOOLEAN
256 NTAPI
257 RxFastIoWrite(
258 PFILE_OBJECT FileObject,
259 PLARGE_INTEGER FileOffset,
260 ULONG Length,
261 BOOLEAN Wait,
262 ULONG LockKey,
263 PVOID Buffer,
264 PIO_STATUS_BLOCK IoStatus,
265 PDEVICE_OBJECT DeviceObject);
266
267 NTSTATUS
268 RxFindOrCreateFcb(
269 PRX_CONTEXT RxContext,
270 PUNICODE_STRING NetRootName);
271
272 NTSTATUS
273 RxFirstCanonicalize(
274 PRX_CONTEXT RxContext,
275 PUNICODE_STRING FileName,
276 PUNICODE_STRING CanonicalName,
277 PNET_ROOT_TYPE NetRootType);
278
279 VOID
280 RxFreeCanonicalNameBuffer(
281 PRX_CONTEXT Context);
282
283 VOID
284 NTAPI
285 RxFspDispatch(
286 IN PVOID Context);
287
288 VOID
289 NTAPI
290 RxGetRegistryParameters(
291 IN PUNICODE_STRING RegistryPath);
292
293 NTSTATUS
294 NTAPI
295 RxGetStringRegistryParameter(
296 IN HANDLE KeyHandle,
297 IN PCWSTR KeyName,
298 OUT PUNICODE_STRING OutString,
299 IN PUCHAR Buffer,
300 IN ULONG BufferLength,
301 IN BOOLEAN LogFailure);
302
303 VOID
304 NTAPI
305 RxInitializeDebugSupport(
306 VOID);
307
308 VOID
309 NTAPI
310 RxInitializeDispatchVectors(
311 PDRIVER_OBJECT DriverObject);
312
313 NTSTATUS
314 NTAPI
315 RxInitializeRegistrationStructures(
316 VOID);
317
318 VOID
319 NTAPI
320 RxInitializeTopLevelIrpPackage(
321 VOID);
322
323 VOID
324 NTAPI
325 RxInitUnwind(
326 PDRIVER_OBJECT DriverObject,
327 USHORT State);
328
329 BOOLEAN
330 RxIsThisAnRdbssTopLevelContext(
331 PRX_TOPLEVELIRP_CONTEXT TopLevelContext);
332
333 NTSTATUS
334 NTAPI
335 RxLowIoIoCtlShellCompletion(
336 PRX_CONTEXT RxContext);
337
338 NTSTATUS
339 RxLowIoReadShell(
340 PRX_CONTEXT RxContext);
341
342 NTSTATUS
343 NTAPI
344 RxLowIoReadShellCompletion(
345 PRX_CONTEXT RxContext);
346
347 PVOID
348 RxNewMapUserBuffer(
349 PRX_CONTEXT RxContext);
350
351 NTSTATUS
352 RxNotifyChangeDirectory(
353 PRX_CONTEXT RxContext);
354
355 NTSTATUS
356 RxpQueryInfoMiniRdr(
357 PRX_CONTEXT RxContext,
358 FILE_INFORMATION_CLASS FileInfoClass,
359 PVOID Buffer);
360
361 VOID
362 RxPurgeNetFcb(
363 PFCB Fcb,
364 PRX_CONTEXT LocalContext);
365
366 NTSTATUS
367 RxQueryAlternateNameInfo(
368 PRX_CONTEXT RxContext,
369 PFILE_NAME_INFORMATION AltNameInfo);
370
371 NTSTATUS
372 RxQueryBasicInfo(
373 PRX_CONTEXT RxContext,
374 PFILE_BASIC_INFORMATION BasicInfo);
375
376 NTSTATUS
377 RxQueryCompressedInfo(
378 PRX_CONTEXT RxContext,
379 PFILE_COMPRESSION_INFORMATION CompressionInfo);
380
381 NTSTATUS
382 RxQueryDirectory(
383 PRX_CONTEXT RxContext);
384
385 NTSTATUS
386 RxQueryEaInfo(
387 PRX_CONTEXT RxContext,
388 PFILE_EA_INFORMATION EaInfo);
389
390 NTSTATUS
391 RxQueryInternalInfo(
392 PRX_CONTEXT RxContext,
393 PFILE_INTERNAL_INFORMATION InternalInfo);
394
395 NTSTATUS
396 RxQueryNameInfo(
397 PRX_CONTEXT RxContext,
398 PFILE_NAME_INFORMATION NameInfo);
399
400 NTSTATUS
401 RxQueryPipeInfo(
402 PRX_CONTEXT RxContext,
403 PFILE_PIPE_INFORMATION PipeInfo);
404
405 NTSTATUS
406 RxQueryPositionInfo(
407 PRX_CONTEXT RxContext,
408 PFILE_POSITION_INFORMATION PositionInfo);
409
410 NTSTATUS
411 RxQueryStandardInfo(
412 PRX_CONTEXT RxContext,
413 PFILE_STANDARD_INFORMATION StandardInfo);
414
415 VOID
416 NTAPI
417 RxReadRegistryParameters(
418 VOID);
419
420 VOID
421 NTAPI
422 RxReleaseFileForNtCreateSection(
423 PFILE_OBJECT FileObject);
424
425 NTSTATUS
426 NTAPI
427 RxReleaseForCcFlush(
428 PFILE_OBJECT FileObject,
429 PDEVICE_OBJECT DeviceObject);
430
431 PRX_CONTEXT
432 RxRemoveOverflowEntry(
433 PRDBSS_DEVICE_OBJECT DeviceObject,
434 WORK_QUEUE_TYPE Queue);
435
436 NTSTATUS
437 RxSearchForCollapsibleOpen(
438 PRX_CONTEXT RxContext,
439 ACCESS_MASK DesiredAccess,
440 ULONG ShareAccess);
441
442 VOID
443 RxSetupNetFileObject(
444 PRX_CONTEXT RxContext);
445
446 NTSTATUS
447 RxSystemControl(
448 IN PRDBSS_DEVICE_OBJECT RxDeviceObject,
449 IN PIRP Irp);
450
451 VOID
452 RxUninitializeCacheMap(
453 PRX_CONTEXT RxContext,
454 PFILE_OBJECT FileObject,
455 PLARGE_INTEGER TruncateSize);
456
457 VOID
458 RxUnstart(
459 PRX_CONTEXT Context,
460 PRDBSS_DEVICE_OBJECT DeviceObject);
461
462 NTSTATUS
463 RxXXXControlFileCallthru(
464 PRX_CONTEXT Context);
465
466 PVOID
467 NTAPI
468 _RxAllocatePoolWithTag(
469 _In_ POOL_TYPE PoolType,
470 _In_ SIZE_T NumberOfBytes,
471 _In_ ULONG Tag);
472
473 VOID
474 NTAPI
475 _RxFreePool(
476 _In_ PVOID Buffer);
477
478 VOID
479 NTAPI
480 _RxFreePoolWithTag(
481 _In_ PVOID Buffer,
482 _In_ ULONG Tag);
483
484 WCHAR RxStarForTemplate = '*';
485 WCHAR Rx8QMdot3QM[] = L">>>>>>>>.>>>*";
486 BOOLEAN DisableByteRangeLockingOnReadOnlyFiles = FALSE;
487 BOOLEAN DisableFlushOnCleanup = FALSE;
488 ULONG ReadAheadGranularity = 1 << PAGE_SHIFT;
489 LIST_ENTRY RxActiveContexts;
490 NPAGED_LOOKASIDE_LIST RxContextLookasideList;
491 FAST_MUTEX RxContextPerFileSerializationMutex;
492 RDBSS_DATA RxData;
493 FCB RxDeviceFCB;
494 BOOLEAN RxLoudLowIoOpsEnabled = FALSE;
495 RX_FSD_DISPATCH_VECTOR RxDeviceFCBVector[IRP_MJ_MAXIMUM_FUNCTION + 1] =
496 {
497 { RxCommonDispatchProblem },
498 { RxCommonDispatchProblem },
499 { RxCommonDevFCBClose },
500 { RxCommonDispatchProblem },
501 { RxCommonDispatchProblem },
502 { RxCommonDispatchProblem },
503 { RxCommonDispatchProblem },
504 { RxCommonDispatchProblem },
505 { RxCommonDispatchProblem },
506 { RxCommonDispatchProblem },
507 { RxCommonDevFCBQueryVolInfo },
508 { RxCommonDispatchProblem },
509 { RxCommonDispatchProblem },
510 { RxCommonDevFCBFsCtl },
511 { RxCommonDevFCBIoCtl },
512 { RxCommonDevFCBIoCtl },
513 { RxCommonDispatchProblem },
514 { RxCommonDispatchProblem },
515 { RxCommonDevFCBCleanup },
516 { RxCommonDispatchProblem },
517 { RxCommonDispatchProblem },
518 { RxCommonDispatchProblem },
519 { RxCommonUnimplemented },
520 { RxCommonUnimplemented },
521 { RxCommonUnimplemented },
522 { RxCommonUnimplemented },
523 { RxCommonUnimplemented },
524 { RxCommonUnimplemented },
525 };
526 RDBSS_EXPORTS RxExports;
527 FAST_IO_DISPATCH RxFastIoDispatch;
528 PRDBSS_DEVICE_OBJECT RxFileSystemDeviceObject;
529 RX_FSD_DISPATCH_VECTOR RxFsdDispatchVector[IRP_MJ_MAXIMUM_FUNCTION + 1] =
530 {
531 { RxCommonCreate },
532 { RxCommonUnimplemented },
533 { RxCommonClose },
534 { RxCommonRead },
535 { RxCommonWrite },
536 { RxCommonQueryInformation },
537 { RxCommonSetInformation },
538 { RxCommonQueryEa },
539 { RxCommonSetEa },
540 { RxCommonFlushBuffers },
541 { RxCommonQueryVolumeInformation },
542 { RxCommonSetVolumeInformation },
543 { RxCommonDirectoryControl },
544 { RxCommonFileSystemControl },
545 { RxCommonDeviceControl },
546 { RxCommonDeviceControl },
547 { RxCommonUnimplemented },
548 { RxCommonLockControl },
549 { RxCommonCleanup },
550 { RxCommonUnimplemented },
551 { RxCommonQuerySecurity },
552 { RxCommonSetSecurity },
553 { RxCommonUnimplemented },
554 { RxCommonUnimplemented },
555 { RxCommonUnimplemented },
556 { RxCommonQueryQuotaInformation },
557 { RxCommonSetQuotaInformation },
558 { RxCommonUnimplemented },
559 };
560 ULONG RxFsdEntryCount;
561 LIST_ENTRY RxIrpsList;
562 KSPIN_LOCK RxIrpsListSpinLock;
563 KMUTEX RxScavengerMutex;
564 KMUTEX RxSerializationMutex;
565 UCHAR RxSpaceForTheWrappersDeviceObject[sizeof(*RxFileSystemDeviceObject)];
566 KSPIN_LOCK TopLevelIrpSpinLock;
567 LIST_ENTRY TopLevelIrpAllocatedContextsList;
568 BOOLEAN RxForceQFIPassThrough = FALSE;
569
570 DECLARE_CONST_UNICODE_STRING(unknownId, L"???");
571
572 #if RDBSS_ASSERTS
573 #ifdef ASSERT
574 #undef ASSERT
575 #endif
576
577 #define ASSERT(exp) \
578 if (!(exp)) \
579 { \
580 RxAssert(#exp, __FILE__, __LINE__, NULL); \
581 }
582 #endif
583
584 #if RX_POOL_WRAPPER
585 #undef RxAllocatePool
586 #undef RxAllocatePoolWithTag
587 #undef RxFreePool
588
589 #define RxAllocatePool(P, S) _RxAllocatePoolWithTag(P, S, 0)
590 #define RxAllocatePoolWithTag _RxAllocatePoolWithTag
591 #define RxFreePool _RxFreePool
592 #define RxFreePoolWithTag _RxFreePoolWithTag
593 #endif
594
595 /* FUNCTIONS ****************************************************************/
596
597 /*
598 * @implemented
599 */
600 VOID
601 CheckForLoudOperations(
602 PRX_CONTEXT RxContext)
603 {
604 PAGED_CODE();
605
606 #define ALLSCR_LENGTH (sizeof(L"all.scr") - sizeof(UNICODE_NULL))
607
608 /* Are loud operations enabled? */
609 if (RxLoudLowIoOpsEnabled)
610 {
611 PFCB Fcb;
612
613 /* If so, the operation will be loud only if filename ends with all.scr */
614 Fcb = (PFCB)RxContext->pFcb;
615 if (RtlCompareMemory(Add2Ptr(Fcb->PrivateAlreadyPrefixedName.Buffer, (Fcb->PrivateAlreadyPrefixedName.Length - ALLSCR_LENGTH)),
616 L"all.scr", ALLSCR_LENGTH) == ALLSCR_LENGTH)
617 {
618 SetFlag(RxContext->LowIoContext.Flags, LOWIO_CONTEXT_FLAG_LOUDOPS);
619 }
620 }
621 #undef ALLSCR_LENGTH
622 }
623
624 /*
625 * @implemented
626 */
627 VOID
628 __RxInitializeTopLevelIrpContext(
629 IN OUT PRX_TOPLEVELIRP_CONTEXT TopLevelContext,
630 IN PIRP Irp,
631 IN PRDBSS_DEVICE_OBJECT RxDeviceObject,
632 IN ULONG Flags)
633 {
634 DPRINT("__RxInitializeTopLevelIrpContext(%p, %p, %p, %u)\n", TopLevelContext, Irp, RxDeviceObject, Flags);
635
636 RtlZeroMemory(TopLevelContext, sizeof(RX_TOPLEVELIRP_CONTEXT));
637 TopLevelContext->Irp = Irp;
638 TopLevelContext->Flags = (Flags ? RX_TOPLEVELCTX_FLAG_FROM_POOL : 0);
639 TopLevelContext->Signature = RX_TOPLEVELIRP_CONTEXT_SIGNATURE;
640 TopLevelContext->RxDeviceObject = RxDeviceObject;
641 TopLevelContext->Previous = IoGetTopLevelIrp();
642 TopLevelContext->Thread = PsGetCurrentThread();
643
644 /* We cannot add to list something that'd come from stack */
645 if (BooleanFlagOn(TopLevelContext->Flags, RX_TOPLEVELCTX_FLAG_FROM_POOL))
646 {
647 RxAddToTopLevelIrpAllocatedContextsList(TopLevelContext);
648 }
649 }
650
651 NTSTATUS
652 NTAPI
653 RxAcquireExclusiveFcbResourceInMRx(
654 _Inout_ PMRX_FCB Fcb)
655 {
656 UNIMPLEMENTED;
657 return STATUS_NOT_IMPLEMENTED;
658 }
659
660 BOOLEAN
661 NTAPI
662 RxAcquireFcbForLazyWrite(
663 PVOID Context,
664 BOOLEAN Wait)
665 {
666 UNIMPLEMENTED;
667 return FALSE;
668 }
669
670 BOOLEAN
671 NTAPI
672 RxAcquireFcbForReadAhead(
673 PVOID Context,
674 BOOLEAN Wait)
675 {
676 UNIMPLEMENTED;
677 return FALSE;
678 }
679
680 VOID
681 NTAPI
682 RxAcquireFileForNtCreateSection(
683 PFILE_OBJECT FileObject)
684 {
685 UNIMPLEMENTED;
686 }
687
688 NTSTATUS
689 NTAPI
690 RxAcquireForCcFlush(
691 PFILE_OBJECT FileObject,
692 PDEVICE_OBJECT DeviceObject)
693 {
694 UNIMPLEMENTED;
695 return STATUS_NOT_IMPLEMENTED;
696 }
697
698 /*
699 * @implemented
700 */
701 VOID
702 RxAddToTopLevelIrpAllocatedContextsList(
703 PRX_TOPLEVELIRP_CONTEXT TopLevelContext)
704 {
705 KIRQL OldIrql;
706
707 DPRINT("RxAddToTopLevelIrpAllocatedContextsList(%p)\n", TopLevelContext);
708
709 ASSERT(TopLevelContext->Signature == RX_TOPLEVELIRP_CONTEXT_SIGNATURE);
710 ASSERT(BooleanFlagOn(TopLevelContext->Flags, RX_TOPLEVELCTX_FLAG_FROM_POOL));
711
712 KeAcquireSpinLock(&TopLevelIrpSpinLock, &OldIrql);
713 InsertTailList(&TopLevelIrpAllocatedContextsList, &TopLevelContext->ListEntry);
714 KeReleaseSpinLock(&TopLevelIrpSpinLock, OldIrql);
715 }
716
717 /*
718 * @implemented
719 */
720 VOID
721 RxAddToWorkque(
722 IN PRX_CONTEXT RxContext,
723 IN PIRP Irp)
724 {
725 ULONG Queued;
726 KIRQL OldIrql;
727 WORK_QUEUE_TYPE Queue;
728 PIO_STACK_LOCATION Stack;
729
730 Stack = RxContext->CurrentIrpSp;
731 RxContext->PostRequest = FALSE;
732
733 /* First of all, select the appropriate queue - delayed for prefix claim, critical for the rest */
734 if (RxContext->MajorFunction == IRP_MJ_DEVICE_CONTROL &&
735 Stack->Parameters.DeviceIoControl.IoControlCode == IOCTL_REDIR_QUERY_PATH)
736 {
737 Queue = DelayedWorkQueue;
738 SetFlag(RxContext->Flags, RX_CONTEXT_FLAG_FSP_DELAYED_OVERFLOW_QUEUE);
739 }
740 else
741 {
742 Queue = CriticalWorkQueue;
743 SetFlag(RxContext->Flags, RX_CONTEXT_FLAG_FSP_CRITICAL_OVERFLOW_QUEUE);
744 }
745
746 /* Check for overflow */
747 if (Stack->FileObject != NULL)
748 {
749 KeAcquireSpinLock(&RxFileSystemDeviceObject->OverflowQueueSpinLock, &OldIrql);
750
751 Queued = InterlockedIncrement(&RxFileSystemDeviceObject->PostedRequestCount[Queue]);
752 /* In case of an overflow, add the new queued call to the overflow list */
753 if (Queued > 1)
754 {
755 InterlockedDecrement(&RxFileSystemDeviceObject->PostedRequestCount[Queue]);
756 InsertTailList(&RxFileSystemDeviceObject->OverflowQueue[Queue], &RxContext->OverflowListEntry);
757 ++RxFileSystemDeviceObject->OverflowQueueCount[Queue];
758
759 KeReleaseSpinLock(&RxFileSystemDeviceObject->OverflowQueueSpinLock, OldIrql);
760 return;
761 }
762
763 KeReleaseSpinLock(&RxFileSystemDeviceObject->OverflowQueueSpinLock, OldIrql);
764 }
765
766 ExInitializeWorkItem(&RxContext->WorkQueueItem, RxFspDispatch, RxContext);
767 ExQueueWorkItem((PWORK_QUEUE_ITEM)&RxContext->WorkQueueItem, Queue);
768 }
769
770 /*
771 * @implemented
772 */
773 VOID
774 RxAdjustFileTimesAndSize(
775 PRX_CONTEXT Context)
776 {
777 PFCB Fcb;
778 PFOBX Fobx;
779 NTSTATUS Status;
780 PFILE_OBJECT FileObject;
781 LARGE_INTEGER CurrentTime;
782 FILE_BASIC_INFORMATION FileBasicInfo;
783 FILE_END_OF_FILE_INFORMATION FileEOFInfo;
784 BOOLEAN FileModified, SetLastChange, SetLastAccess, SetLastWrite, NeedUpdate;
785
786 PAGED_CODE();
787
788 FileObject = Context->CurrentIrpSp->FileObject;
789 /* If Cc isn't initialized, the file was not read nor written, nothing to do */
790 if (FileObject->PrivateCacheMap == NULL)
791 {
792 return;
793 }
794
795 /* Get now */
796 KeQuerySystemTime(&CurrentTime);
797
798 Fobx = (PFOBX)Context->pFobx;
799 /* Was the file modified? */
800 FileModified = BooleanFlagOn(FileObject->Flags, FO_FILE_MODIFIED);
801 /* We'll set last write if it was modified and user didn't update yet */
802 SetLastWrite = FileModified && !BooleanFlagOn(Fobx->Flags, FOBX_FLAG_USER_SET_LAST_WRITE);
803 /* File was accessed if: written or read (fastio), we'll update last access if user didn't */
804 SetLastAccess = SetLastWrite ||
805 (BooleanFlagOn(FileObject->Flags, FO_FILE_FAST_IO_READ) &&
806 !BooleanFlagOn(Fobx->Flags, FOBX_FLAG_USER_SET_LAST_ACCESS));
807 /* We'll set last change if it was modified and user didn't update yet */
808 SetLastChange = FileModified && !BooleanFlagOn(Fobx->Flags, FOBX_FLAG_USER_SET_LAST_CHANGE);
809
810 /* Nothing to update? Job done */
811 if (!FileModified && !SetLastWrite && !SetLastAccess && !SetLastChange)
812 {
813 return;
814 }
815
816 Fcb = (PFCB)Context->pFcb;
817 /* By default, we won't issue any MRxSetFileInfoAtCleanup call */
818 NeedUpdate = FALSE;
819 RtlZeroMemory(&FileBasicInfo, sizeof(FileBasicInfo));
820
821 /* Update lastwrite time if required */
822 if (SetLastWrite)
823 {
824 NeedUpdate = TRUE;
825 Fcb->LastWriteTime.QuadPart = CurrentTime.QuadPart;
826 FileBasicInfo.LastWriteTime.QuadPart = CurrentTime.QuadPart;
827 }
828
829 /* Update lastaccess time if required */
830 if (SetLastAccess)
831 {
832 NeedUpdate = TRUE;
833 Fcb->LastAccessTime.QuadPart = CurrentTime.QuadPart;
834 FileBasicInfo.LastAccessTime.QuadPart = CurrentTime.QuadPart;
835 }
836
837 /* Update lastchange time if required */
838 if (SetLastChange)
839 {
840 NeedUpdate = TRUE;
841 Fcb->LastChangeTime.QuadPart = CurrentTime.QuadPart;
842 FileBasicInfo.ChangeTime.QuadPart = CurrentTime.QuadPart;
843 }
844
845 /* If one of the date was modified, issue a call to mini-rdr */
846 if (NeedUpdate)
847 {
848 Context->Info.FileInformationClass = FileBasicInformation;
849 Context->Info.Buffer = &FileBasicInfo;
850 Context->Info.Length = sizeof(FileBasicInfo);
851
852 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxSetFileInfoAtCleanup, (Context));
853 (void)Status;
854 }
855
856 /* If the file was modified, update its EOF */
857 if (FileModified)
858 {
859 FileEOFInfo.EndOfFile.QuadPart = Fcb->Header.FileSize.QuadPart;
860
861 Context->Info.FileInformationClass = FileEndOfFileInformation;
862 Context->Info.Buffer = &FileEOFInfo;
863 Context->Info.Length = sizeof(FileEOFInfo);
864
865 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxSetFileInfoAtCleanup, (Context));
866 (void)Status;
867 }
868 }
869
870 /*
871 * @implemented
872 */
873 NTSTATUS
874 RxAllocateCanonicalNameBuffer(
875 PRX_CONTEXT RxContext,
876 PUNICODE_STRING CanonicalName,
877 USHORT CanonicalLength)
878 {
879 PAGED_CODE();
880
881 DPRINT("RxContext: %p - CanonicalNameBuffer: %p\n", RxContext, RxContext->Create.CanonicalNameBuffer);
882
883 /* Context must be free of any already allocated name */
884 ASSERT(RxContext->Create.CanonicalNameBuffer == NULL);
885
886 /* Validate string length */
887 if (CanonicalLength > USHRT_MAX - 1)
888 {
889 CanonicalName->Buffer = NULL;
890 return STATUS_OBJECT_PATH_INVALID;
891 }
892
893 CanonicalName->Buffer = RxAllocatePoolWithTag(PagedPool | POOL_COLD_ALLOCATION, CanonicalLength, RX_MISC_POOLTAG);
894 if (CanonicalName->Buffer == NULL)
895 {
896 return STATUS_INSUFFICIENT_RESOURCES;
897 }
898
899 CanonicalName->Length = 0;
900 CanonicalName->MaximumLength = CanonicalLength;
901
902 /* Set the two places - they must always be identical */
903 RxContext->Create.CanonicalNameBuffer = CanonicalName->Buffer;
904 RxContext->AlsoCanonicalNameBuffer = CanonicalName->Buffer;
905
906 return STATUS_SUCCESS;
907 }
908
909 VOID
910 RxCancelNotifyChangeDirectoryRequestsForFobx(
911 PFOBX Fobx)
912 {
913 UNIMPLEMENTED;
914 }
915
916 NTSTATUS
917 RxCancelNotifyChangeDirectoryRequestsForVNetRoot(
918 PV_NET_ROOT VNetRoot,
919 BOOLEAN ForceFilesClosed)
920 {
921 UNIMPLEMENTED;
922 return STATUS_NOT_IMPLEMENTED;
923 }
924
925 VOID
926 NTAPI
927 RxCancelRoutine(
928 PDEVICE_OBJECT DeviceObject,
929 PIRP Irp)
930 {
931 UNIMPLEMENTED;
932 }
933
934 /*
935 * @implemented
936 */
937 NTSTATUS
938 RxCanonicalizeFileNameByServerSpecs(
939 PRX_CONTEXT RxContext,
940 PUNICODE_STRING NetRootName)
941 {
942 USHORT NextChar, CurChar;
943 USHORT MaxChars;
944
945 PAGED_CODE();
946
947 /* Validate file name is not empty */
948 MaxChars = NetRootName->Length / sizeof(WCHAR);
949 if (MaxChars == 0)
950 {
951 return STATUS_MORE_PROCESSING_REQUIRED;
952 }
953
954 /* Validate name is correct */
955 for (NextChar = 0, CurChar = 0; CurChar + 1 < MaxChars; NextChar = CurChar + 1)
956 {
957 USHORT i;
958
959 for (i = NextChar + 1; i < MaxChars; ++i)
960 {
961 if (NetRootName->Buffer[i] == '\\' || NetRootName->Buffer[i] == ':')
962 {
963 break;
964 }
965 }
966
967 CurChar = i - 1;
968 if (CurChar == NextChar)
969 {
970 if (((NetRootName->Buffer[NextChar] != '\\' && NetRootName->Buffer[NextChar] != ':') || NextChar == (MaxChars - 1)) && NetRootName->Buffer[NextChar] != '.')
971 {
972 continue;
973 }
974
975 if (CurChar != 0)
976 {
977 if (CurChar >= MaxChars - 1)
978 {
979 continue;
980 }
981
982 if (NetRootName->Buffer[CurChar + 1] != ':')
983 {
984 return STATUS_OBJECT_PATH_SYNTAX_BAD;
985 }
986 }
987 else
988 {
989 if (NetRootName->Buffer[1] != ':')
990 {
991 return STATUS_OBJECT_PATH_SYNTAX_BAD;
992 }
993 }
994 }
995 else
996 {
997 if ((CurChar - NextChar) == 1)
998 {
999 if (NetRootName->Buffer[NextChar + 2] != '.')
1000 {
1001 continue;
1002 }
1003
1004 if (NetRootName->Buffer[NextChar] == '\\' || NetRootName->Buffer[NextChar] == ':' || NetRootName->Buffer[NextChar] == '.')
1005 {
1006 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1007 }
1008 }
1009 else
1010 {
1011 if ((CurChar - NextChar) != 2 || (NetRootName->Buffer[NextChar] != '\\' && NetRootName->Buffer[NextChar] != ':')
1012 || NetRootName->Buffer[NextChar + 1] != '.')
1013 {
1014 continue;
1015 }
1016
1017 if (NetRootName->Buffer[NextChar + 2] == '.')
1018 {
1019 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1020 }
1021 }
1022 }
1023 }
1024
1025 return STATUS_MORE_PROCESSING_REQUIRED;
1026 }
1027
1028 NTSTATUS
1029 RxCanonicalizeNameAndObtainNetRoot(
1030 PRX_CONTEXT RxContext,
1031 PUNICODE_STRING FileName,
1032 PUNICODE_STRING NetRootName)
1033 {
1034 NTSTATUS Status;
1035 NET_ROOT_TYPE NetRootType;
1036 UNICODE_STRING CanonicalName;
1037
1038 PAGED_CODE();
1039
1040 NetRootType = NET_ROOT_WILD;
1041
1042 RtlInitEmptyUnicodeString(NetRootName, NULL, 0);
1043 RtlInitEmptyUnicodeString(&CanonicalName, NULL, 0);
1044
1045 /* if not relative opening, just handle the passed name */
1046 if (RxContext->CurrentIrpSp->FileObject->RelatedFileObject == NULL)
1047 {
1048 Status = RxFirstCanonicalize(RxContext, FileName, &CanonicalName, &NetRootType);
1049 if (!NT_SUCCESS(Status))
1050 {
1051 return Status;
1052 }
1053 }
1054 else
1055 {
1056 PFCB Fcb;
1057
1058 /* Make sure we have a valid FCB and a FOBX */
1059 Fcb = RxContext->CurrentIrpSp->FileObject->RelatedFileObject->FsContext;
1060 if (Fcb == NULL ||
1061 RxContext->CurrentIrpSp->FileObject->RelatedFileObject->FsContext2 == NULL)
1062 {
1063 return STATUS_INVALID_PARAMETER;
1064 }
1065
1066 if (!NodeTypeIsFcb(Fcb))
1067 {
1068 return STATUS_INVALID_PARAMETER;
1069 }
1070
1071 UNIMPLEMENTED;
1072 }
1073
1074 /* Get/Create the associated VNetRoot for opening */
1075 Status = RxFindOrConstructVirtualNetRoot(RxContext, &CanonicalName, NetRootType, NetRootName);
1076 if (!NT_SUCCESS(Status) && Status != STATUS_PENDING &&
1077 BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_MAILSLOT_REPARSE))
1078 {
1079 ASSERT(CanonicalName.Buffer == RxContext->Create.CanonicalNameBuffer);
1080
1081 RxFreeCanonicalNameBuffer(RxContext);
1082 Status = RxFirstCanonicalize(RxContext, FileName, &CanonicalName, &NetRootType);
1083 if (NT_SUCCESS(Status))
1084 {
1085 Status = RxFindOrConstructVirtualNetRoot(RxContext, &CanonicalName, NetRootType, NetRootName);
1086 }
1087 }
1088
1089 /* Filename cannot contain wildcards */
1090 if (FsRtlDoesNameContainWildCards(NetRootName))
1091 {
1092 Status = STATUS_OBJECT_NAME_INVALID;
1093 }
1094
1095 /* Make sure file name is correct */
1096 if (NT_SUCCESS(Status))
1097 {
1098 Status = RxCanonicalizeFileNameByServerSpecs(RxContext, NetRootName);
1099 }
1100
1101 /* Give the mini-redirector a chance to prepare the name */
1102 if (NT_SUCCESS(Status) || Status == STATUS_MORE_PROCESSING_REQUIRED)
1103 {
1104 if (RxContext->Create.pNetRoot != NULL)
1105 {
1106 NTSTATUS IgnoredStatus;
1107
1108 MINIRDR_CALL(IgnoredStatus, RxContext, RxContext->Create.pNetRoot->pSrvCall->RxDeviceObject->Dispatch,
1109 MRxPreparseName, (RxContext, NetRootName));
1110 (void)IgnoredStatus;
1111 }
1112 }
1113
1114 return Status;
1115 }
1116
1117 VOID
1118 NTAPI
1119 RxCheckFcbStructuresForAlignment(
1120 VOID)
1121 {
1122 UNIMPLEMENTED;
1123 }
1124
1125 NTSTATUS
1126 RxCheckShareAccess(
1127 _In_ ACCESS_MASK DesiredAccess,
1128 _In_ ULONG DesiredShareAccess,
1129 _Inout_ PFILE_OBJECT FileObject,
1130 _Inout_ PSHARE_ACCESS ShareAccess,
1131 _In_ BOOLEAN Update,
1132 _In_ PSZ where,
1133 _In_ PSZ wherelogtag)
1134 {
1135 PAGED_CODE();
1136
1137 RxDumpWantedAccess(where, "", wherelogtag, DesiredAccess, DesiredShareAccess);
1138 RxDumpCurrentAccess(where, "", wherelogtag, ShareAccess);
1139
1140 return IoCheckShareAccess(DesiredAccess, DesiredShareAccess, FileObject, ShareAccess, Update);
1141 }
1142
1143 /*
1144 * @implemented
1145 */
1146 NTSTATUS
1147 RxCheckShareAccessPerSrvOpens(
1148 IN PFCB Fcb,
1149 IN ACCESS_MASK DesiredAccess,
1150 IN ULONG DesiredShareAccess)
1151 {
1152 BOOLEAN ReadAccess;
1153 BOOLEAN WriteAccess;
1154 BOOLEAN DeleteAccess;
1155 PSHARE_ACCESS ShareAccess;
1156
1157 PAGED_CODE();
1158
1159 ShareAccess = &Fcb->ShareAccessPerSrvOpens;
1160
1161 RxDumpWantedAccess("RxCheckShareAccessPerSrvOpens", "", "RxCheckShareAccessPerSrvOpens", DesiredAccess, DesiredShareAccess);
1162 RxDumpCurrentAccess("RxCheckShareAccessPerSrvOpens", "", "RxCheckShareAccessPerSrvOpens", ShareAccess);
1163
1164 /* Check if any access wanted */
1165 ReadAccess = (DesiredAccess & (FILE_READ_DATA | FILE_EXECUTE)) != 0;
1166 WriteAccess = (DesiredAccess & (FILE_WRITE_DATA | FILE_APPEND_DATA)) != 0;
1167 DeleteAccess = (DesiredAccess & DELETE) != 0;
1168
1169 if (ReadAccess || WriteAccess || DeleteAccess)
1170 {
1171 BOOLEAN SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0;
1172 BOOLEAN SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0;
1173 BOOLEAN SharedDelete = (DesiredShareAccess & FILE_SHARE_DELETE) != 0;
1174
1175 /* Check whether there's a violation */
1176 if ((ReadAccess &&
1177 (ShareAccess->SharedRead < ShareAccess->OpenCount)) ||
1178 (WriteAccess &&
1179 (ShareAccess->SharedWrite < ShareAccess->OpenCount)) ||
1180 (DeleteAccess &&
1181 (ShareAccess->SharedDelete < ShareAccess->OpenCount)) ||
1182 ((ShareAccess->Readers != 0) && !SharedRead) ||
1183 ((ShareAccess->Writers != 0) && !SharedWrite) ||
1184 ((ShareAccess->Deleters != 0) && !SharedDelete))
1185 {
1186 return STATUS_SHARING_VIOLATION;
1187 }
1188 }
1189
1190 return STATUS_SUCCESS;
1191 }
1192
1193 VOID
1194 RxCleanupPipeQueues(
1195 PRX_CONTEXT Context)
1196 {
1197 UNIMPLEMENTED;
1198 }
1199
1200 /*
1201 * @implemented
1202 */
1203 NTSTATUS
1204 RxCloseAssociatedSrvOpen(
1205 IN PFOBX Fobx,
1206 IN PRX_CONTEXT RxContext OPTIONAL)
1207 {
1208 PFCB Fcb;
1209 NTSTATUS Status;
1210 PSRV_OPEN SrvOpen;
1211 BOOLEAN CloseSrvOpen;
1212 PRX_CONTEXT LocalContext;
1213
1214 PAGED_CODE();
1215
1216 /* Assume SRV_OPEN is already closed */
1217 CloseSrvOpen = FALSE;
1218 /* If we have a FOBX, we'll have to close it */
1219 if (Fobx != NULL)
1220 {
1221 /* If the FOBX isn't closed yet */
1222 if (!BooleanFlagOn(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED))
1223 {
1224 SrvOpen = Fobx->SrvOpen;
1225 Fcb = (PFCB)SrvOpen->pFcb;
1226 /* Check whether we've to close SRV_OPEN first */
1227 if (!BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_CLOSED))
1228 {
1229 CloseSrvOpen = TRUE;
1230 }
1231 else
1232 {
1233 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1234
1235 /* Not much to do */
1236 SetFlag(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED);
1237
1238 if (SrvOpen->OpenCount > 0)
1239 {
1240 --SrvOpen->OpenCount;
1241 }
1242 }
1243 }
1244
1245 /* No need to close SRV_OPEN, so close FOBX */
1246 if (!CloseSrvOpen)
1247 {
1248 RxMarkFobxOnClose(Fobx);
1249
1250 return STATUS_SUCCESS;
1251 }
1252 }
1253 else
1254 {
1255 /* No FOBX? No RX_CONTEXT, ok, job done! */
1256 if (RxContext == NULL)
1257 {
1258 return STATUS_SUCCESS;
1259 }
1260
1261 /* Get the FCB from RX_CONTEXT */
1262 Fcb = (PFCB)RxContext->pFcb;
1263 SrvOpen == NULL;
1264 }
1265
1266 /* If we don't have RX_CONTEXT, allocte one, we'll need it */
1267 if (RxContext == NULL)
1268 {
1269 ASSERT(Fobx != NULL);
1270
1271 LocalContext = RxCreateRxContext(NULL, Fcb->RxDeviceObject, RX_CONTEXT_FLAG_MUST_SUCCEED_NONBLOCKING | RX_CONTEXT_FLAG_WAIT);
1272 if (LocalContext == NULL)
1273 {
1274 return STATUS_INSUFFICIENT_RESOURCES;
1275 }
1276
1277 LocalContext->MajorFunction = 2;
1278 LocalContext->pFcb = RX_GET_MRX_FCB(Fcb);
1279 LocalContext->pFobx = (PMRX_FOBX)Fobx;
1280 LocalContext->pRelevantSrvOpen = (PMRX_SRV_OPEN)Fobx->SrvOpen;
1281 }
1282 else
1283 {
1284 LocalContext = RxContext;
1285 }
1286
1287 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1288
1289 /* Now, close the FOBX */
1290 if (Fobx != NULL)
1291 {
1292 RxMarkFobxOnClose(Fobx);
1293 }
1294 else
1295 {
1296 InterlockedDecrement((volatile long *)&Fcb->OpenCount);
1297 }
1298
1299 /* If not a "standard" file, SRV_OPEN can be null */
1300 if (SrvOpen == NULL)
1301 {
1302 ASSERT((NodeType(Fcb) == RDBSS_NTC_OPENTARGETDIR_FCB) || (NodeType(Fcb) == RDBSS_NTC_IPC_SHARE) || (NodeType(Fcb) == RDBSS_NTC_MAILSLOT));
1303 RxDereferenceNetFcb(Fcb);
1304
1305 if (LocalContext != RxContext)
1306 {
1307 RxDereferenceAndDeleteRxContext(LocalContext);
1308 }
1309
1310 return STATUS_SUCCESS;
1311 }
1312
1313 /* If SRV_OPEN isn't in a good condition, nothing to close */
1314 if (SrvOpen->Condition != Condition_Good)
1315 {
1316 if (LocalContext != RxContext)
1317 {
1318 RxDereferenceAndDeleteRxContext(LocalContext);
1319 }
1320
1321 return STATUS_SUCCESS;
1322 }
1323
1324 /* Decrease open count */
1325 if (SrvOpen->OpenCount > 0)
1326 {
1327 --SrvOpen->OpenCount;
1328 }
1329
1330 /* If we're the only one left, is there a FOBX handled by Scavenger? */
1331 if (SrvOpen->OpenCount == 1)
1332 {
1333 if (!IsListEmpty(&SrvOpen->FobxList))
1334 {
1335 if (!IsListEmpty(&CONTAINING_RECORD(SrvOpen->FobxList.Flink, FOBX, FobxQLinks)->ScavengerFinalizationList))
1336 {
1337 SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_CLOSE_DELAYED);
1338 }
1339 }
1340 }
1341
1342 /* Nothing left, purge FCB */
1343 if (SrvOpen->OpenCount == 0 && RxContext == NULL)
1344 {
1345 RxPurgeNetFcb(Fcb, LocalContext);
1346 }
1347
1348 /* Already closed? Job done! */
1349 SrvOpen = Fobx->SrvOpen;
1350 if (SrvOpen == NULL ||
1351 (SrvOpen->OpenCount != 0 && !BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_BUFFERING_STATE_CHANGE_PENDING)) ||
1352 BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_CLOSED))
1353 {
1354 SetFlag(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED);
1355 if (LocalContext != RxContext)
1356 {
1357 RxDereferenceAndDeleteRxContext(LocalContext);
1358 }
1359
1360 return STATUS_SUCCESS;
1361 }
1362
1363 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1364
1365 /* Inform mini-rdr about closing */
1366 MINIRDR_CALL(Status, LocalContext, Fcb->MRxDispatch, MRxCloseSrvOpen, (LocalContext));
1367 DPRINT("MRxCloseSrvOpen returned: %lx, called with RX_CONTEXT %p for FOBX %p (FCB %p, SRV_OPEN %p)\n ",
1368 Status, RxContext, Fobx, Fcb, SrvOpen);
1369
1370 /* And mark as such */
1371 SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_CLOSED);
1372 SrvOpen->Key = (PVOID)-1;
1373
1374 /* If we were delayed, we're not! */
1375 if (BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_CLOSE_DELAYED))
1376 {
1377 InterlockedDecrement(&((PSRV_CALL)Fcb->pNetRoot->pSrvCall)->NumberOfCloseDelayedFiles);
1378 }
1379
1380 /* Clear access */
1381 RxRemoveShareAccessPerSrvOpens(SrvOpen);
1382 RxPurgeChangeBufferingStateRequestsForSrvOpen(SrvOpen);
1383
1384 /* Dereference */
1385 RxDereferenceSrvOpen(SrvOpen, LHS_ExclusiveLockHeld);
1386
1387 /* Mark the FOBX closed as well */
1388 SetFlag(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED);
1389
1390 if (LocalContext != RxContext)
1391 {
1392 RxDereferenceAndDeleteRxContext(LocalContext);
1393 }
1394
1395 return Status;
1396 }
1397
1398 /*
1399 * @implemented
1400 */
1401 NTSTATUS
1402 RxCollapseOrCreateSrvOpen(
1403 PRX_CONTEXT RxContext)
1404 {
1405 PFCB Fcb;
1406 NTSTATUS Status;
1407 ULONG Disposition;
1408 PSRV_OPEN SrvOpen;
1409 USHORT ShareAccess;
1410 PIO_STACK_LOCATION Stack;
1411 ACCESS_MASK DesiredAccess;
1412 RX_BLOCK_CONDITION FcbCondition;
1413
1414 PAGED_CODE();
1415
1416 DPRINT("RxCollapseOrCreateSrvOpen(%p)\n", RxContext);
1417
1418 Fcb = (PFCB)RxContext->pFcb;
1419 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1420 ++Fcb->UncleanCount;
1421
1422 Stack = RxContext->CurrentIrpSp;
1423 DesiredAccess = Stack->Parameters.Create.SecurityContext->DesiredAccess & FILE_ALL_ACCESS;
1424 ShareAccess = Stack->Parameters.Create.ShareAccess & FILE_SHARE_VALID_FLAGS;
1425
1426 Disposition = RxContext->Create.NtCreateParameters.Disposition;
1427
1428 /* Try to find a reusable SRV_OPEN */
1429 Status = RxSearchForCollapsibleOpen(RxContext, DesiredAccess, ShareAccess);
1430 if (Status == STATUS_NOT_FOUND)
1431 {
1432 /* If none found, create one */
1433 SrvOpen = RxCreateSrvOpen((PV_NET_ROOT)RxContext->Create.pVNetRoot, Fcb);
1434 if (SrvOpen == NULL)
1435 {
1436 Status = STATUS_INSUFFICIENT_RESOURCES;
1437 }
1438 else
1439 {
1440 SrvOpen->DesiredAccess = DesiredAccess;
1441 SrvOpen->ShareAccess = ShareAccess;
1442 Status = STATUS_SUCCESS;
1443 }
1444
1445 RxContext->pRelevantSrvOpen = (PMRX_SRV_OPEN)SrvOpen;
1446
1447 if (Status != STATUS_SUCCESS)
1448 {
1449 FcbCondition = Condition_Bad;
1450 }
1451 else
1452 {
1453 RxInitiateSrvOpenKeyAssociation(SrvOpen);
1454
1455 /* Cookie to check the mini-rdr doesn't mess with RX_CONTEXT */
1456 RxContext->CurrentIrp->IoStatus.Information = 0xABCDEF;
1457 /* Inform the mini-rdr we're handling a create */
1458 MINIRDR_CALL(Status, RxContext, Fcb->MRxDispatch, MRxCreate, (RxContext));
1459 ASSERT(RxContext->CurrentIrp->IoStatus.Information == 0xABCDEF);
1460
1461 DPRINT("MRxCreate returned: %x\n", Status);
1462 if (Status == STATUS_SUCCESS)
1463 {
1464 /* In case of overwrite, reset file size */
1465 if (Disposition == FILE_OVERWRITE || Disposition == FILE_OVERWRITE_IF)
1466 {
1467 RxAcquirePagingIoResource(RxContext, Fcb);
1468 Fcb->Header.AllocationSize.QuadPart = 0LL;
1469 Fcb->Header.FileSize.QuadPart = 0LL;
1470 Fcb->Header.ValidDataLength.QuadPart = 0LL;
1471 RxContext->CurrentIrpSp->FileObject->SectionObjectPointer = &Fcb->NonPaged->SectionObjectPointers;
1472 CcSetFileSizes(RxContext->CurrentIrpSp->FileObject, (PCC_FILE_SIZES)&Fcb->Header.AllocationSize);
1473 RxReleasePagingIoResource(RxContext, Fcb);
1474 }
1475 else
1476 {
1477 /* Otherwise, adjust sizes */
1478 RxContext->CurrentIrpSp->FileObject->SectionObjectPointer = &Fcb->NonPaged->SectionObjectPointers;
1479 if (CcIsFileCached(RxContext->CurrentIrpSp->FileObject))
1480 {
1481 RxAdjustAllocationSizeforCC(Fcb);
1482 }
1483 CcSetFileSizes(RxContext->CurrentIrpSp->FileObject, (PCC_FILE_SIZES)&Fcb->Header.AllocationSize);
1484 }
1485 }
1486
1487 /* Set the IoStatus with information returned by mini-rdr */
1488 RxContext->CurrentIrp->IoStatus.Information = RxContext->Create.ReturnedCreateInformation;
1489
1490 SrvOpen->OpenStatus = Status;
1491 /* Set SRV_OPEN state - good or bad - depending on whether create succeed */
1492 RxTransitionSrvOpen(SrvOpen, (Status == STATUS_SUCCESS ? Condition_Good : Condition_Bad));
1493
1494 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1495
1496 RxCompleteSrvOpenKeyAssociation(SrvOpen);
1497
1498 if (Status == STATUS_SUCCESS)
1499 {
1500 if (BooleanFlagOn(Stack->Parameters.Create.Options, FILE_DELETE_ON_CLOSE))
1501 {
1502 ClearFlag(Fcb->FcbState, FCB_STATE_COLLAPSING_ENABLED);
1503 }
1504 SrvOpen->CreateOptions = RxContext->Create.NtCreateParameters.CreateOptions;
1505 FcbCondition = Condition_Good;
1506 }
1507 else
1508 {
1509 FcbCondition = Condition_Bad;
1510 RxDereferenceSrvOpen(SrvOpen, LHS_ExclusiveLockHeld);
1511 RxContext->pRelevantSrvOpen = NULL;
1512
1513 if (RxContext->pFobx != NULL)
1514 {
1515 RxDereferenceNetFobx(RxContext->pFobx, LHS_ExclusiveLockHeld);
1516 RxContext->pFobx = NULL;
1517 }
1518 }
1519 }
1520
1521 /* Set FCB state - good or bad - depending on whether create succeed */
1522 DPRINT("Transitioning FCB %p to condition %lx\n", Fcb, Fcb->Condition);
1523 RxTransitionNetFcb(Fcb, FcbCondition);
1524 }
1525 else if (Status == STATUS_SUCCESS)
1526 {
1527 BOOLEAN IsGood, ExtraOpen;
1528
1529 /* A reusable SRV_OPEN was found */
1530 RxContext->CurrentIrp->IoStatus.Information = FILE_OPENED;
1531 ExtraOpen = FALSE;
1532
1533 SrvOpen = (PSRV_OPEN)RxContext->pRelevantSrvOpen;
1534
1535 IsGood = (SrvOpen->Condition == Condition_Good);
1536 /* If the SRV_OPEN isn't in a stable situation, wait for it to become stable */
1537 if (!StableCondition(SrvOpen->Condition))
1538 {
1539 RxReferenceSrvOpen(SrvOpen);
1540 ++SrvOpen->OpenCount;
1541 ExtraOpen = TRUE;
1542
1543 RxReleaseFcb(RxContext, Fcb);
1544 RxContext->Create.FcbAcquired = FALSE;
1545
1546 RxWaitForStableSrvOpen(SrvOpen, RxContext);
1547
1548 if (NT_SUCCESS(RxAcquireExclusiveFcb(RxContext, Fcb)))
1549 {
1550 RxContext->Create.FcbAcquired = TRUE;
1551 }
1552
1553 IsGood = (SrvOpen->Condition == Condition_Good);
1554 }
1555
1556 /* Inform the mini-rdr we do an opening with a reused SRV_OPEN */
1557 if (IsGood)
1558 {
1559 MINIRDR_CALL(Status, RxContext, Fcb->MRxDispatch, MRxCollapseOpen, (RxContext));
1560
1561 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1562 }
1563 else
1564 {
1565 Status = SrvOpen->OpenStatus;
1566 }
1567
1568 if (ExtraOpen)
1569 {
1570 --SrvOpen->OpenCount;
1571 RxDereferenceSrvOpen(SrvOpen, LHS_ExclusiveLockHeld);
1572 }
1573 }
1574
1575 --Fcb->UncleanCount;
1576
1577 DPRINT("Status: %x\n", Status);
1578 return Status;
1579 }
1580
1581 NTSTATUS
1582 NTAPI
1583 RxCommonCleanup(
1584 PRX_CONTEXT Context)
1585 {
1586 #define BugCheckFileId RDBSS_BUG_CHECK_CLEANUP
1587 PFCB Fcb;
1588 PFOBX Fobx;
1589 ULONG OpenCount;
1590 NTSTATUS Status;
1591 PNET_ROOT NetRoot;
1592 PFILE_OBJECT FileObject;
1593 LARGE_INTEGER TruncateSize;
1594 PLARGE_INTEGER TruncateSizePtr;
1595 BOOLEAN NeedPurge, FcbTableAcquired, OneLeft, IsFile, FcbAcquired, LeftForDelete;
1596
1597 PAGED_CODE();
1598
1599 Fcb = (PFCB)Context->pFcb;
1600 Fobx = (PFOBX)Context->pFobx;
1601 DPRINT("RxCommonCleanup(%p); FOBX: %p, FCB: %p\n", Context, Fobx, Fcb);
1602
1603 /* File system closing, it's OK */
1604 if (Fobx == NULL)
1605 {
1606 if (Fcb->UncleanCount > 0)
1607 {
1608 InterlockedDecrement((volatile long *)&Fcb->UncleanCount);
1609 }
1610
1611 return STATUS_SUCCESS;
1612 }
1613
1614 /* Check we have a correct FCB type */
1615 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_FILE &&
1616 NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_DIRECTORY &&
1617 NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_UNKNOWN &&
1618 NodeType(Fcb) != RDBSS_NTC_SPOOLFILE)
1619 {
1620 DPRINT1("Invalid Fcb type for %p\n", Fcb);
1621 RxBugCheck(Fcb->Header.NodeTypeCode, 0, 0);
1622 }
1623
1624 FileObject = Context->CurrentIrpSp->FileObject;
1625 ASSERT(!BooleanFlagOn(FileObject->Flags, FO_CLEANUP_COMPLETE));
1626
1627 RxMarkFobxOnCleanup(Fobx, &NeedPurge);
1628
1629 Status = RxAcquireExclusiveFcb(Context, Fcb);
1630 if (!NT_SUCCESS(Status))
1631 {
1632 return Status;
1633 }
1634
1635 FcbAcquired = TRUE;
1636
1637 Fobx->AssociatedFileObject = NULL;
1638
1639 /* In case SRV_OPEN used is part of FCB */
1640 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_SRVOPEN_USED))
1641 {
1642 ASSERT(Fcb->UncleanCount != 0);
1643 InterlockedDecrement((volatile long *)&Fcb->UncleanCount);
1644
1645 if (BooleanFlagOn(FileObject->Flags, FO_NO_INTERMEDIATE_BUFFERING))
1646 {
1647 --Fcb->UncachedUncleanCount;
1648 }
1649
1650 /* Inform mini-rdr */
1651 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxCleanupFobx, (Context));
1652
1653 ASSERT(Fobx->SrvOpen->UncleanFobxCount != 0);
1654 --Fobx->SrvOpen->UncleanFobxCount;
1655
1656 RxUninitializeCacheMap(Context, FileObject, NULL);
1657
1658 RxReleaseFcb(Context, Fcb);
1659
1660 return STATUS_SUCCESS;
1661 }
1662
1663 /* Report the fact that file could be set as delete on close */
1664 if (BooleanFlagOn(Fobx->Flags, FOBX_FLAG_DELETE_ON_CLOSE))
1665 {
1666 SetFlag(Fcb->FcbState, FCB_STATE_DELETE_ON_CLOSE);
1667 }
1668
1669 /* Cancel any pending notification */
1670 RxCancelNotifyChangeDirectoryRequestsForFobx(Fobx);
1671
1672 /* Backup open count before we start playing with it */
1673 OpenCount = Fcb->ShareAccess.OpenCount;
1674
1675 NetRoot = (PNET_ROOT)Fcb->pNetRoot;
1676 FcbTableAcquired = FALSE;
1677 LeftForDelete = FALSE;
1678 OneLeft = (Fcb->UncleanCount == 1);
1679
1680 _SEH2_TRY
1681 {
1682 /* Unclean count and delete on close? Verify whether we're the one */
1683 if (OneLeft && BooleanFlagOn(Fcb->FcbState, FCB_STATE_DELETE_ON_CLOSE))
1684 {
1685 if (RxAcquireFcbTableLockExclusive(&NetRoot->FcbTable, FALSE))
1686 {
1687 FcbTableAcquired = TRUE;
1688 }
1689 else
1690 {
1691 RxReleaseFcb(Context, Fcb);
1692
1693 RxAcquireFcbTableLockExclusive(&NetRoot->FcbTable, TRUE);
1694
1695 Status = RxAcquireExclusiveFcb(Context, Fcb);
1696 if (Status != STATUS_SUCCESS)
1697 {
1698 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1699 return Status;
1700 }
1701
1702 FcbTableAcquired = TRUE;
1703 }
1704
1705 /* That means we'll perform the delete on close! */
1706 if (Fcb->UncleanCount == 1)
1707 {
1708 LeftForDelete = TRUE;
1709 }
1710 else
1711 {
1712 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1713 FcbTableAcquired = FALSE;
1714 }
1715 }
1716
1717 IsFile = FALSE;
1718 TruncateSizePtr = NULL;
1719 /* Handle cleanup for pipes and printers */
1720 if (NetRoot->Type == NET_ROOT_PIPE || NetRoot->Type == NET_ROOT_PRINT)
1721 {
1722 RxCleanupPipeQueues(Context);
1723 }
1724 /* Handle cleanup for files */
1725 else if (NetRoot->Type == NET_ROOT_DISK || NetRoot->Type == NET_ROOT_WILD)
1726 {
1727 Context->LowIoContext.Flags |= LOWIO_CONTEXT_FLAG_SAVEUNLOCKS;
1728 if (NodeType(Fcb) == RDBSS_NTC_STORAGE_TYPE_FILE)
1729 {
1730 /* First, unlock */
1731 FsRtlFastUnlockAll(&Fcb->Specific.Fcb.FileLock, FileObject, RxGetRequestorProcess(Context), Context);
1732
1733 /* If there are still locks to release, proceed */
1734 if (Context->LowIoContext.ParamsFor.Locks.LockList != NULL)
1735 {
1736 RxInitializeLowIoContext(&Context->LowIoContext, LOWIO_OP_UNLOCK_MULTIPLE);
1737 Context->LowIoContext.ParamsFor.Locks.Flags = 0;
1738 Status = RxLowIoLockControlShell(Context);
1739 }
1740
1741 /* Fix times and size */
1742 RxAdjustFileTimesAndSize(Context);
1743
1744 /* If we're the only one left... */
1745 if (OneLeft)
1746 {
1747 /* And if we're supposed to delete on close */
1748 if (LeftForDelete)
1749 {
1750 /* Update the sizes */
1751 RxAcquirePagingIoResource(Context, Fcb);
1752 Fcb->Header.FileSize.QuadPart = 0;
1753 Fcb->Header.ValidDataLength.QuadPart = 0;
1754 RxReleasePagingIoResource(Context, Fcb);
1755 }
1756 /* Otherwise, call the mini-rdr to adjust sizes */
1757 else
1758 {
1759 /* File got grown up, fill with zeroes */
1760 if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_PAGING_FILE) &&
1761 (Fcb->Header.ValidDataLength.QuadPart < Fcb->Header.FileSize.QuadPart))
1762 {
1763 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxZeroExtend, (Context));
1764 Fcb->Header.ValidDataLength.QuadPart = Fcb->Header.FileSize.QuadPart;
1765 }
1766
1767 /* File was truncated, let mini-rdr proceed */
1768 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_TRUNCATE_ON_CLOSE))
1769 {
1770 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxTruncate, (Context));
1771 ClearFlag(Fcb->FcbState, FCB_STATE_TRUNCATE_ON_CLOSE);
1772
1773 /* Keep track of file change for Cc uninit */
1774 TruncateSize.QuadPart = Fcb->Header.FileSize.QuadPart;
1775 TruncateSizePtr = &TruncateSize;
1776 }
1777 }
1778 }
1779
1780 /* If RxMarkFobxOnCleanup() asked for purge, make sure we're the only one left first */
1781 if (NeedPurge)
1782 {
1783 if (!OneLeft)
1784 {
1785 NeedPurge = FALSE;
1786 }
1787 }
1788 /* Otherwise, try to see whether we can purge */
1789 else
1790 {
1791 NeedPurge = (OneLeft && (LeftForDelete || !BooleanFlagOn(Fcb->FcbState, FCB_STATE_COLLAPSING_ENABLED)));
1792 }
1793
1794 IsFile = TRUE;
1795 }
1796 }
1797
1798 /* We have to still be there! */
1799 ASSERT(Fcb->UncleanCount != 0);
1800 InterlockedDecrement((volatile long *)&Fcb->UncleanCount);
1801
1802 if (BooleanFlagOn(FileObject->Flags, FO_NO_INTERMEDIATE_BUFFERING))
1803 {
1804 --Fcb->UncachedUncleanCount;
1805 }
1806
1807 /* Inform mini-rdr about ongoing cleanup */
1808 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxCleanupFobx, (Context));
1809
1810 ASSERT(Fobx->SrvOpen->UncleanFobxCount != 0);
1811 --Fobx->SrvOpen->UncleanFobxCount;
1812
1813 /* Flush cache */
1814 if (DisableFlushOnCleanup)
1815 {
1816 /* Only if we're the last standing */
1817 if (Fcb->NonPaged->SectionObjectPointers.DataSectionObject != NULL &&
1818 Fcb->UncleanCount == Fcb->UncachedUncleanCount)
1819 {
1820 DPRINT("Flushing %p due to last cached handle cleanup\n", Context);
1821 RxFlushFcbInSystemCache(Fcb, TRUE);
1822 }
1823 }
1824 else
1825 {
1826 /* Always */
1827 if (Fcb->NonPaged->SectionObjectPointers.DataSectionObject != NULL)
1828 {
1829 DPRINT("Flushing %p on cleanup\n", Context);
1830 RxFlushFcbInSystemCache(Fcb, TRUE);
1831 }
1832 }
1833
1834 /* If only remaining uncached & unclean, then flush and purge */
1835 if (!BooleanFlagOn(FileObject->Flags, FO_NO_INTERMEDIATE_BUFFERING))
1836 {
1837 if (Fcb->UncachedUncleanCount != 0)
1838 {
1839 if (Fcb->UncachedUncleanCount == Fcb->UncleanCount &&
1840 Fcb->NonPaged->SectionObjectPointers.DataSectionObject != NULL)
1841 {
1842 DPRINT("Flushing FCB in system cache for %p\n", Context);
1843 RxPurgeFcbInSystemCache(Fcb, NULL, 0, FALSE, TRUE);
1844 }
1845 }
1846 }
1847
1848 /* If purge required, and not about to delete, flush */
1849 if (!LeftForDelete && NeedPurge)
1850 {
1851 DPRINT("Flushing FCB in system cache for %p\n", Context);
1852 RxFlushFcbInSystemCache(Fcb, TRUE);
1853 }
1854
1855 /* If it was a file, drop cache */
1856 if (IsFile)
1857 {
1858 DPRINT("Uninit cache map for file\n");
1859 RxUninitializeCacheMap(Context, FileObject, TruncateSizePtr);
1860 }
1861
1862 /* If that's the one left for deletion, or if it needs purge, flush */
1863 if (LeftForDelete || NeedPurge)
1864 {
1865 RxPurgeFcbInSystemCache(Fcb, NULL, 0, FALSE, !LeftForDelete);
1866 /* If that's for deletion, also remove from FCB table */
1867 if (LeftForDelete)
1868 {
1869 RxRemoveNameNetFcb(Fcb);
1870 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1871 FcbTableAcquired = FALSE;
1872 }
1873 }
1874
1875 /* Remove any share access */
1876 if (OpenCount != 0 && NetRoot->Type == NET_ROOT_DISK)
1877 {
1878 RxRemoveShareAccess(FileObject, &Fcb->ShareAccess, "Cleanup the share access", "ClnUpShr");
1879 }
1880
1881 /* In case there's caching, on a file, update file metadata */
1882 if (NodeType(Fcb) == RDBSS_NTC_STORAGE_TYPE_FILE && BooleanFlagOn(Fobx->Flags, 0x20000000) &&
1883 BooleanFlagOn(Fcb->FcbState, FCB_STATE_WRITECACHING_ENABLED) && !BooleanFlagOn(Fobx->pSrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_WRITE_CACHING))
1884 {
1885 UNIMPLEMENTED;
1886 }
1887
1888 /* We're clean! */
1889 SetFlag(FileObject->Flags, FO_CLEANUP_COMPLETE);
1890
1891 FcbAcquired = FALSE;
1892 RxReleaseFcb(Context, Fcb);
1893 }
1894 _SEH2_FINALLY
1895 {
1896 if (FcbAcquired)
1897 {
1898 RxReleaseFcb(Context, Fcb);
1899 }
1900
1901 if (FcbTableAcquired)
1902 {
1903 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1904 }
1905 }
1906 _SEH2_END;
1907
1908 return Status;
1909 #undef BugCheckFileId
1910 }
1911
1912 NTSTATUS
1913 NTAPI
1914 RxCommonClose(
1915 PRX_CONTEXT Context)
1916 {
1917 #define BugCheckFileId RDBSS_BUG_CHECK_CLOSE
1918 PFCB Fcb;
1919 PFOBX Fobx;
1920 NTSTATUS Status;
1921 PFILE_OBJECT FileObject;
1922 BOOLEAN DereferenceFobx, AcquiredFcb;
1923
1924 PAGED_CODE();
1925
1926 Fcb = (PFCB)Context->pFcb;
1927 Fobx = (PFOBX)Context->pFobx;
1928 FileObject = Context->CurrentIrpSp->FileObject;
1929 DPRINT("RxCommonClose(%p); FOBX: %p, FCB: %p, FO: %p\n", Context, Fobx, Fcb, FileObject);
1930
1931 Status = RxAcquireExclusiveFcb(Context, Fcb);
1932 if (!NT_SUCCESS(Status))
1933 {
1934 return Status;
1935 }
1936
1937 AcquiredFcb = TRUE;
1938 _SEH2_TRY
1939 {
1940 BOOLEAN Freed;
1941
1942 /* Check our FCB type is expected */
1943 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_UNKNOWN &&
1944 (NodeType(Fcb) < RDBSS_NTC_STORAGE_TYPE_DIRECTORY || (NodeType(Fcb) > RDBSS_NTC_STORAGE_TYPE_FILE &&
1945 (NodeType(Fcb) < RDBSS_NTC_SPOOLFILE || NodeType(Fcb) > RDBSS_NTC_OPENTARGETDIR_FCB))))
1946 {
1947 RxBugCheck(NodeType(Fcb), 0, 0);
1948 }
1949
1950 RxReferenceNetFcb(Fcb);
1951
1952 DereferenceFobx = FALSE;
1953 /* If we're not closing FS */
1954 if (Fobx != NULL)
1955 {
1956 PSRV_OPEN SrvOpen;
1957 PSRV_CALL SrvCall;
1958
1959 SrvOpen = (PSRV_OPEN)Fobx->pSrvOpen;
1960 SrvCall = (PSRV_CALL)Fcb->pNetRoot->pSrvCall;
1961 /* Handle delayed close */
1962 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_DIRECTORY)
1963 {
1964 if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_DELETE_ON_CLOSE | FCB_STATE_ORPHANED))
1965 {
1966 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_COLLAPSING_ENABLED))
1967 {
1968 DPRINT("Delay close for FOBX: %p, SrvOpen %p\n", Fobx, SrvOpen);
1969
1970 if (SrvOpen->OpenCount == 1 && !BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_COLLAPSING_DISABLED))
1971 {
1972 if (InterlockedIncrement(&SrvCall->NumberOfCloseDelayedFiles) >= SrvCall->MaximumNumberOfCloseDelayedFiles)
1973 {
1974 InterlockedDecrement(&SrvCall->NumberOfCloseDelayedFiles);
1975 }
1976 else
1977 {
1978 DereferenceFobx = TRUE;
1979 SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_CLOSE_DELAYED);
1980 }
1981 }
1982 }
1983 }
1984 }
1985
1986 /* If we reach maximum of delayed close/or if there are no delayed close */
1987 if (!DereferenceFobx)
1988 {
1989 PNET_ROOT NetRoot;
1990
1991 NetRoot = (PNET_ROOT)Fcb->pNetRoot;
1992 if (NetRoot->Type != NET_ROOT_PRINT)
1993 {
1994 /* Delete if asked */
1995 if (BooleanFlagOn(Fobx->Flags, FOBX_FLAG_DELETE_ON_CLOSE))
1996 {
1997 RxScavengeRelatedFobxs(Fcb);
1998 RxSynchronizeWithScavenger(Context);
1999
2000 RxReleaseFcb(Context, Fcb);
2001
2002 RxAcquireFcbTableLockExclusive(&NetRoot->FcbTable, TRUE);
2003 RxOrphanThisFcb(Fcb);
2004 RxReleaseFcbTableLock(&NetRoot->FcbTable);
2005
2006 Status = RxAcquireExclusiveFcb(Context, Fcb);
2007 ASSERT(NT_SUCCESS(Status));
2008 }
2009 }
2010 }
2011
2012 RxMarkFobxOnClose(Fobx);
2013 }
2014
2015 if (DereferenceFobx)
2016 {
2017 ASSERT(Fobx != NULL);
2018 RxDereferenceNetFobx(Fobx, LHS_SharedLockHeld);
2019 }
2020 else
2021 {
2022 RxCloseAssociatedSrvOpen(Fobx, Context);
2023 if (Fobx != NULL)
2024 {
2025 RxDereferenceNetFobx(Fobx, LHS_ExclusiveLockHeld);
2026 }
2027 }
2028
2029 Freed = RxDereferenceAndFinalizeNetFcb(Fcb, Context, FALSE, FALSE);
2030 AcquiredFcb = !Freed;
2031
2032 FileObject->FsContext = (PVOID)-1;
2033
2034 if (Freed)
2035 {
2036 RxTrackerUpdateHistory(Context, NULL, TRACKER_FCB_FREE, __LINE__, __FILE__, 0);
2037 }
2038 else
2039 {
2040 RxReleaseFcb(Context, Fcb);
2041 AcquiredFcb = FALSE;
2042 }
2043 }
2044 _SEH2_FINALLY
2045 {
2046 if (_SEH2_AbnormalTermination())
2047 {
2048 if (AcquiredFcb)
2049 {
2050 RxReleaseFcb(Context, Fcb);
2051 }
2052 }
2053 else
2054 {
2055 ASSERT(!AcquiredFcb);
2056 }
2057 }
2058 _SEH2_END;
2059
2060 DPRINT("Status: %x\n", Status);
2061 return Status;
2062 #undef BugCheckFileId
2063 }
2064
2065 NTSTATUS
2066 NTAPI
2067 RxCommonCreate(
2068 PRX_CONTEXT Context)
2069 {
2070 PIRP Irp;
2071 NTSTATUS Status;
2072 PFILE_OBJECT FileObject;
2073 PIO_STACK_LOCATION Stack;
2074
2075 PAGED_CODE();
2076
2077 DPRINT("RxCommonCreate(%p)\n", Context);
2078
2079 Irp = Context->CurrentIrp;
2080 Stack = Context->CurrentIrpSp;
2081 FileObject = Stack->FileObject;
2082
2083 /* Check whether that's a device opening */
2084 if (FileObject->FileName.Length == 0 && FileObject->RelatedFileObject == NULL)
2085 {
2086 FileObject->FsContext = &RxDeviceFCB;
2087 FileObject->FsContext2 = NULL;
2088
2089 ++RxDeviceFCB.NodeReferenceCount;
2090 ++RxDeviceFCB.OpenCount;
2091
2092 Irp->IoStatus.Information = FILE_OPENED;
2093 DPRINT("Device opening FO: %p, DO: %p, Name: %wZ\n", FileObject, Context->RxDeviceObject, &Context->RxDeviceObject->DeviceName);
2094
2095 Status = STATUS_SUCCESS;
2096 }
2097 else
2098 {
2099 PFCB RelatedFcb = NULL;
2100
2101 /* Make sure caller is consistent */
2102 if (FlagOn(Stack->Parameters.Create.Options, FILE_DIRECTORY_FILE | FILE_NON_DIRECTORY_FILE | FILE_OPEN_REMOTE_INSTANCE) ==
2103 (FILE_DIRECTORY_FILE | FILE_NON_DIRECTORY_FILE | FILE_OPEN_REMOTE_INSTANCE))
2104 {
2105 DPRINT1("Create.Options: %x\n", Stack->Parameters.Create.Options);
2106 return STATUS_INVALID_PARAMETER;
2107 }
2108
2109 DPRINT("Ctxt: %p, FO: %p, Options: %lx, Flags: %lx, Attr: %lx, ShareAccess: %lx, DesiredAccess: %lx\n",
2110 Context, FileObject, Stack->Parameters.Create.Options, Stack->Flags, Stack->Parameters.Create.FileAttributes,
2111 Stack->Parameters.Create.ShareAccess, Stack->Parameters.Create.SecurityContext->DesiredAccess);
2112 DPRINT("FileName: %wZ\n", &FileObject->FileName);
2113
2114 if (FileObject->RelatedFileObject != NULL)
2115 {
2116 RelatedFcb = FileObject->RelatedFileObject->FsContext;
2117 DPRINT("Rel FO: %p, path: %wZ\n", FileObject->RelatedFileObject, RelatedFcb->FcbTableEntry.Path);
2118 }
2119
2120 /* Going to rename? */
2121 if (BooleanFlagOn(Stack->Flags, SL_OPEN_TARGET_DIRECTORY))
2122 {
2123 DPRINT("TargetDir!\n");
2124 }
2125
2126 /* Copy create parameters to the context */
2127 RxCopyCreateParameters(Context);
2128
2129 /* If the caller wants to establish a connection, go ahead */
2130 if (BooleanFlagOn(Stack->Parameters.Create.Options, FILE_CREATE_TREE_CONNECTION))
2131 {
2132 Status = RxCreateTreeConnect(Context);
2133 }
2134 else
2135 {
2136 /* Validate file name */
2137 if (FileObject->FileName.Length > sizeof(WCHAR) &&
2138 FileObject->FileName.Buffer[1] == OBJ_NAME_PATH_SEPARATOR &&
2139 FileObject->FileName.Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
2140 {
2141 FileObject->FileName.Length -= sizeof(WCHAR);
2142 RtlMoveMemory(&FileObject->FileName.Buffer[0], &FileObject->FileName.Buffer[1],
2143 FileObject->FileName.Length);
2144
2145 if (FileObject->FileName.Length > sizeof(WCHAR) &&
2146 FileObject->FileName.Buffer[1] == OBJ_NAME_PATH_SEPARATOR &&
2147 FileObject->FileName.Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
2148 {
2149 return STATUS_OBJECT_NAME_INVALID;
2150 }
2151 }
2152
2153 /* Attempt to open the file */
2154 do
2155 {
2156 UNICODE_STRING NetRootName;
2157
2158 /* Strip last \ if required */
2159 if (FileObject->FileName.Length != 0 &&
2160 FileObject->FileName.Buffer[FileObject->FileName.Length / sizeof(WCHAR) - 1] == OBJ_NAME_PATH_SEPARATOR)
2161 {
2162 if (BooleanFlagOn(Stack->Parameters.Create.Options, FILE_NON_DIRECTORY_FILE))
2163 {
2164 return STATUS_OBJECT_NAME_INVALID;
2165 }
2166
2167 FileObject->FileName.Length -= sizeof(WCHAR);
2168 Context->Create.Flags |= RX_CONTEXT_CREATE_FLAG_STRIPPED_TRAILING_BACKSLASH;
2169 }
2170
2171 if (BooleanFlagOn(Context->Flags, RX_CONTEXT_FLAG_WRITE_THROUGH))
2172 {
2173 FileObject->Flags |= FO_WRITE_THROUGH;
2174 }
2175
2176 /* Get the associated net root to opening */
2177 Status = RxCanonicalizeNameAndObtainNetRoot(Context, &FileObject->FileName, &NetRootName);
2178 if (Status != STATUS_MORE_PROCESSING_REQUIRED)
2179 {
2180 break;
2181 }
2182
2183 /* And attempt to open */
2184 Status = RxCreateFromNetRoot(Context, &NetRootName);
2185 if (Status == STATUS_SHARING_VIOLATION)
2186 {
2187 UNIMPLEMENTED;
2188 }
2189 else if (Status == STATUS_REPARSE)
2190 {
2191 Context->CurrentIrp->IoStatus.Information = 0;
2192 }
2193 else
2194 {
2195 ASSERT(!BooleanFlagOn(Context->Create.Flags, RX_CONTEXT_CREATE_FLAG_REPARSE));
2196 }
2197 }
2198 while (Status == STATUS_MORE_PROCESSING_REQUIRED);
2199 }
2200
2201 if (Status == STATUS_RETRY)
2202 {
2203 RxpPrepareCreateContextForReuse(Context);
2204 }
2205 ASSERT(Status != STATUS_PENDING);
2206 }
2207
2208 DPRINT("Status: %lx\n", Status);
2209 return Status;
2210 }
2211
2212 /*
2213 * @implemented
2214 */
2215 NTSTATUS
2216 NTAPI
2217 RxCommonDevFCBCleanup(
2218 PRX_CONTEXT Context)
2219 {
2220 PMRX_FCB Fcb;
2221 NTSTATUS Status;
2222
2223 PAGED_CODE();
2224
2225 DPRINT("RxCommonDevFCBCleanup(%p)\n", Context);
2226
2227 Fcb = Context->pFcb;
2228 Status = STATUS_SUCCESS;
2229 ASSERT(NodeType(Fcb) == RDBSS_NTC_DEVICE_FCB);
2230
2231 /* Our FOBX if set, has to be a VNetRoot */
2232 if (Context->pFobx != NULL)
2233 {
2234 RxAcquirePrefixTableLockShared(Context->RxDeviceObject->pRxNetNameTable, TRUE);
2235 if (Context->pFobx->NodeTypeCode != RDBSS_NTC_V_NETROOT)
2236 {
2237 Status = STATUS_INVALID_DEVICE_REQUEST;
2238 }
2239 RxReleasePrefixTableLock(Context->RxDeviceObject->pRxNetNameTable);
2240 }
2241 else
2242 {
2243 --Fcb->UncleanCount;
2244 }
2245
2246 return Status;
2247 }
2248
2249 /*
2250 * @implemented
2251 */
2252 NTSTATUS
2253 NTAPI
2254 RxCommonDevFCBClose(
2255 PRX_CONTEXT Context)
2256 {
2257 PMRX_FCB Fcb;
2258 NTSTATUS Status;
2259 PMRX_V_NET_ROOT NetRoot;
2260
2261 PAGED_CODE();
2262
2263 DPRINT("RxCommonDevFCBClose(%p)\n", Context);
2264
2265 Fcb = Context->pFcb;
2266 NetRoot = (PMRX_V_NET_ROOT)Context->pFobx;
2267 Status = STATUS_SUCCESS;
2268 ASSERT(NodeType(Fcb) == RDBSS_NTC_DEVICE_FCB);
2269
2270 /* Our FOBX if set, has to be a VNetRoot */
2271 if (NetRoot != NULL)
2272 {
2273 RxAcquirePrefixTableLockExclusive(Context->RxDeviceObject->pRxNetNameTable, TRUE);
2274 if (NetRoot->NodeTypeCode == RDBSS_NTC_V_NETROOT)
2275 {
2276 --NetRoot->NumberOfOpens;
2277 RxDereferenceVNetRoot(NetRoot, LHS_ExclusiveLockHeld);
2278 }
2279 else
2280 {
2281 Status = STATUS_NOT_IMPLEMENTED;
2282 }
2283 RxReleasePrefixTableLock(Context->RxDeviceObject->pRxNetNameTable);
2284 }
2285 else
2286 {
2287 --Fcb->OpenCount;
2288 }
2289
2290 return Status;
2291 }
2292
2293 NTSTATUS
2294 NTAPI
2295 RxCommonDevFCBFsCtl(
2296 PRX_CONTEXT Context)
2297 {
2298 UNIMPLEMENTED;
2299 return STATUS_NOT_IMPLEMENTED;
2300 }
2301
2302 /*
2303 * @implemented
2304 */
2305 NTSTATUS
2306 NTAPI
2307 RxCommonDevFCBIoCtl(
2308 PRX_CONTEXT Context)
2309 {
2310 NTSTATUS Status;
2311
2312 PAGED_CODE();
2313
2314 DPRINT("RxCommonDevFCBIoCtl(%p)\n", Context);
2315
2316 if (Context->pFobx != NULL)
2317 {
2318 return STATUS_INVALID_HANDLE;
2319 }
2320
2321 /* Is that a prefix claim from MUP? */
2322 if (Context->CurrentIrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_REDIR_QUERY_PATH)
2323 {
2324 return RxPrefixClaim(Context);
2325 }
2326
2327 /* Otherwise, pass through the mini-rdr */
2328 Status = RxXXXControlFileCallthru(Context);
2329 if (Status != STATUS_PENDING)
2330 {
2331 if (Context->PostRequest)
2332 {
2333 Context->ResumeRoutine = RxCommonDevFCBIoCtl;
2334 Status = RxFsdPostRequest(Context);
2335 }
2336 }
2337
2338 DPRINT("Status: %lx\n", Status);
2339 return Status;
2340 }
2341
2342 NTSTATUS
2343 NTAPI
2344 RxCommonDevFCBQueryVolInfo(
2345 PRX_CONTEXT Context)
2346 {
2347 UNIMPLEMENTED;
2348 return STATUS_NOT_IMPLEMENTED;
2349 }
2350
2351 /*
2352 * @implemented
2353 */
2354 NTSTATUS
2355 NTAPI
2356 RxCommonDeviceControl(
2357 PRX_CONTEXT Context)
2358 {
2359 NTSTATUS Status;
2360
2361 PAGED_CODE();
2362
2363 /* Prefix claim is only allowed for device, not files */
2364 if (Context->CurrentIrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_REDIR_QUERY_PATH)
2365 {
2366 return STATUS_INVALID_DEVICE_REQUEST;
2367 }
2368
2369 /* Submit to mini-rdr */
2370 RxInitializeLowIoContext(&Context->LowIoContext, LOWIO_OP_IOCTL);
2371 Status = RxLowIoSubmit(Context, RxLowIoIoCtlShellCompletion);
2372 if (Status == STATUS_PENDING)
2373 {
2374 RxDereferenceAndDeleteRxContext_Real(Context);
2375 }
2376
2377 return Status;
2378 }
2379
2380 /*
2381 * @implemented
2382 */
2383 NTSTATUS
2384 NTAPI
2385 RxCommonDirectoryControl(
2386 PRX_CONTEXT Context)
2387 {
2388 PFCB Fcb;
2389 PFOBX Fobx;
2390 NTSTATUS Status;
2391 PIO_STACK_LOCATION Stack;
2392
2393 PAGED_CODE();
2394
2395 Fcb = (PFCB)Context->pFcb;
2396 Fobx = (PFOBX)Context->pFobx;
2397 Stack = Context->CurrentIrpSp;
2398 DPRINT("RxCommonDirectoryControl(%p) FOBX: %p, FCB: %p, Minor: %d\n", Context, Fobx, Fcb, Stack->MinorFunction);
2399
2400 /* Call the appropriate helper */
2401 if (Stack->MinorFunction == IRP_MN_QUERY_DIRECTORY)
2402 {
2403 Status = RxQueryDirectory(Context);
2404 }
2405 else if (Stack->MinorFunction == IRP_MN_NOTIFY_CHANGE_DIRECTORY)
2406 {
2407 Status = RxNotifyChangeDirectory(Context);
2408 if (Status == STATUS_PENDING)
2409 {
2410 RxDereferenceAndDeleteRxContext_Real(Context);
2411 }
2412 }
2413 else
2414 {
2415 Status = STATUS_INVALID_DEVICE_REQUEST;
2416 }
2417
2418 return Status;
2419 }
2420
2421 NTSTATUS
2422 NTAPI
2423 RxCommonDispatchProblem(
2424 PRX_CONTEXT Context)
2425 {
2426 UNIMPLEMENTED;
2427 return STATUS_NOT_IMPLEMENTED;
2428 }
2429
2430 NTSTATUS
2431 NTAPI
2432 RxCommonFileSystemControl(
2433 PRX_CONTEXT Context)
2434 {
2435 UNIMPLEMENTED;
2436 return STATUS_NOT_IMPLEMENTED;
2437 }
2438
2439 NTSTATUS
2440 NTAPI
2441 RxCommonFlushBuffers(
2442 PRX_CONTEXT Context)
2443 {
2444 UNIMPLEMENTED;
2445 return STATUS_NOT_IMPLEMENTED;
2446 }
2447
2448 NTSTATUS
2449 NTAPI
2450 RxCommonLockControl(
2451 PRX_CONTEXT Context)
2452 {
2453 UNIMPLEMENTED;
2454 return STATUS_NOT_IMPLEMENTED;
2455 }
2456
2457 NTSTATUS
2458 NTAPI
2459 RxCommonQueryEa(
2460 PRX_CONTEXT Context)
2461 {
2462 UNIMPLEMENTED;
2463 return STATUS_NOT_IMPLEMENTED;
2464 }
2465
2466 /*
2467 * @implemented
2468 */
2469 NTSTATUS
2470 NTAPI
2471 RxCommonQueryInformation(
2472 PRX_CONTEXT Context)
2473 {
2474 #define SET_SIZE_AND_QUERY(AlreadyConsummed, Function) \
2475 Context->Info.Length = Stack->Parameters.QueryFile.Length - (AlreadyConsummed); \
2476 Status = Function(Context, Add2Ptr(Buffer, AlreadyConsummed))
2477
2478 PFCB Fcb;
2479 PIRP Irp;
2480 PFOBX Fobx;
2481 BOOLEAN Locked;
2482 NTSTATUS Status;
2483 PIO_STACK_LOCATION Stack;
2484 FILE_INFORMATION_CLASS FileInfoClass;
2485
2486 PAGED_CODE();
2487
2488 Fcb = (PFCB)Context->pFcb;
2489 Fobx = (PFOBX)Context->pFobx;
2490 DPRINT("RxCommonQueryInformation(%p) FCB: %p, FOBX: %p\n", Context, Fcb, Fobx);
2491
2492 Irp = Context->CurrentIrp;
2493 Stack = Context->CurrentIrpSp;
2494 DPRINT("Buffer: %p, Length: %lx, Class: %ld\n", Irp->AssociatedIrp.SystemBuffer,
2495 Stack->Parameters.QueryFile.Length, Stack->Parameters.QueryFile.FileInformationClass);
2496
2497 Context->Info.Length = Stack->Parameters.QueryFile.Length;
2498 FileInfoClass = Stack->Parameters.QueryFile.FileInformationClass;
2499
2500 Locked = FALSE;
2501 _SEH2_TRY
2502 {
2503 PVOID Buffer;
2504
2505 /* Get a writable buffer */
2506 Buffer = RxMapSystemBuffer(Context);
2507 if (Buffer == NULL)
2508 {
2509 Status = STATUS_INSUFFICIENT_RESOURCES;
2510 _SEH2_LEAVE;
2511 }
2512 /* Zero it */
2513 RtlZeroMemory(Buffer, Context->Info.Length);
2514
2515 /* Validate file type */
2516 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_UNKNOWN)
2517 {
2518 if (NodeType(Fcb) < RDBSS_NTC_STORAGE_TYPE_DIRECTORY)
2519 {
2520 Status = STATUS_INVALID_PARAMETER;
2521 _SEH2_LEAVE;
2522 }
2523 else if (NodeType(Fcb) > RDBSS_NTC_STORAGE_TYPE_FILE)
2524 {
2525 if (NodeType(Fcb) == RDBSS_NTC_MAILSLOT)
2526 {
2527 Status = STATUS_NOT_IMPLEMENTED;
2528 }
2529 else
2530 {
2531 Status = STATUS_INVALID_PARAMETER;
2532 }
2533
2534 _SEH2_LEAVE;
2535 }
2536 }
2537
2538 /* Acquire the right lock */
2539 if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_PAGING_FILE) &&
2540 FileInfoClass != FileNameInformation)
2541 {
2542 if (FileInfoClass == FileCompressionInformation)
2543 {
2544 Status = RxAcquireExclusiveFcb(Context, Fcb);
2545 }
2546 else
2547 {
2548 Status = RxAcquireSharedFcb(Context, Fcb);
2549 }
2550
2551 if (Status == STATUS_LOCK_NOT_GRANTED)
2552 {
2553 Status = STATUS_PENDING;
2554 _SEH2_LEAVE;
2555 }
2556 else if (!NT_SUCCESS(Status))
2557 {
2558 _SEH2_LEAVE;
2559 }
2560
2561 Locked = TRUE;
2562 }
2563
2564 /* Dispatch to the right helper */
2565 switch (FileInfoClass)
2566 {
2567 case FileBasicInformation:
2568 Status = RxQueryBasicInfo(Context, Buffer);
2569 break;
2570
2571 case FileStandardInformation:
2572 Status = RxQueryStandardInfo(Context, Buffer);
2573 break;
2574
2575 case FileInternalInformation:
2576 Status = RxQueryInternalInfo(Context, Buffer);
2577 break;
2578
2579 case FileEaInformation:
2580 Status = RxQueryEaInfo(Context, Buffer);
2581 break;
2582
2583 case FileNameInformation:
2584 Status = RxQueryNameInfo(Context, Buffer);
2585 break;
2586
2587 case FileAllInformation:
2588 SET_SIZE_AND_QUERY(0, RxQueryBasicInfo);
2589 if (!NT_SUCCESS(Status))
2590 {
2591 break;
2592 }
2593
2594 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION), RxQueryStandardInfo);
2595 if (!NT_SUCCESS(Status))
2596 {
2597 break;
2598 }
2599
2600 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2601 sizeof(FILE_STANDARD_INFORMATION), RxQueryInternalInfo);
2602 if (!NT_SUCCESS(Status))
2603 {
2604 break;
2605 }
2606
2607 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2608 sizeof(FILE_STANDARD_INFORMATION) +
2609 sizeof(FILE_INTERNAL_INFORMATION), RxQueryEaInfo);
2610 if (!NT_SUCCESS(Status))
2611 {
2612 break;
2613 }
2614
2615 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2616 sizeof(FILE_STANDARD_INFORMATION) +
2617 sizeof(FILE_INTERNAL_INFORMATION) +
2618 sizeof(FILE_EA_INFORMATION), RxQueryPositionInfo);
2619 if (!NT_SUCCESS(Status))
2620 {
2621 break;
2622 }
2623
2624 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2625 sizeof(FILE_STANDARD_INFORMATION) +
2626 sizeof(FILE_INTERNAL_INFORMATION) +
2627 sizeof(FILE_EA_INFORMATION) +
2628 sizeof(FILE_POSITION_INFORMATION), RxQueryNameInfo);
2629 break;
2630
2631 case FileAlternateNameInformation:
2632 Status = RxQueryAlternateNameInfo(Context, Buffer);
2633 break;
2634
2635 case FilePipeInformation:
2636 case FilePipeLocalInformation:
2637 case FilePipeRemoteInformation:
2638 Status = RxQueryPipeInfo(Context, Buffer);
2639 break;
2640
2641 case FileCompressionInformation:
2642 Status = RxQueryCompressedInfo(Context, Buffer);
2643 break;
2644
2645 default:
2646 Context->IoStatusBlock.Status = RxpQueryInfoMiniRdr(Context, FileInfoClass, Buffer);
2647 Status = Context->IoStatusBlock.Status;
2648 break;
2649 }
2650
2651 if (Context->Info.Length < 0)
2652 {
2653 Status = STATUS_BUFFER_OVERFLOW;
2654 Context->Info.Length = Stack->Parameters.QueryFile.Length;
2655 }
2656
2657 Irp->IoStatus.Information = Stack->Parameters.QueryFile.Length - Context->Info.Length;
2658 }
2659 _SEH2_FINALLY
2660 {
2661 if (Locked)
2662 {
2663 RxReleaseFcb(Context, Fcb);
2664 }
2665 }
2666 _SEH2_END;
2667
2668 DPRINT("Status: %x\n", Status);
2669 return Status;
2670
2671 #undef SET_SIZE_AND_QUERY
2672 }
2673
2674 NTSTATUS
2675 NTAPI
2676 RxCommonQueryQuotaInformation(
2677 PRX_CONTEXT Context)
2678 {
2679 UNIMPLEMENTED;
2680 return STATUS_NOT_IMPLEMENTED;
2681 }
2682
2683 NTSTATUS
2684 NTAPI
2685 RxCommonQuerySecurity(
2686 PRX_CONTEXT Context)
2687 {
2688 UNIMPLEMENTED;
2689 return STATUS_NOT_IMPLEMENTED;
2690 }
2691
2692 /*
2693 * @implemented
2694 */
2695 NTSTATUS
2696 NTAPI
2697 RxCommonQueryVolumeInformation(
2698 PRX_CONTEXT Context)
2699 {
2700 PIRP Irp;
2701 PFCB Fcb;
2702 PFOBX Fobx;
2703 NTSTATUS Status;
2704 PIO_STACK_LOCATION Stack;
2705
2706 PAGED_CODE();
2707
2708 Fcb = (PFCB)Context->pFcb;
2709 Fobx = (PFOBX)Context->pFobx;
2710
2711 DPRINT("RxCommonQueryVolumeInformation(%p) FCB: %p, FOBX: %p\n", Context, Fcb, Fobx);
2712
2713 Irp = Context->CurrentIrp;
2714 Stack = Context->CurrentIrpSp;
2715 DPRINT("Length: %lx, Class: %lx, Buffer %p\n", Stack->Parameters.QueryVolume.Length,
2716 Stack->Parameters.QueryVolume.FsInformationClass, Irp->AssociatedIrp.SystemBuffer);
2717
2718 Context->Info.FsInformationClass = Stack->Parameters.QueryVolume.FsInformationClass;
2719 Context->Info.Buffer = Irp->AssociatedIrp.SystemBuffer;
2720 Context->Info.Length = Stack->Parameters.QueryVolume.Length;
2721
2722 /* Forward to mini-rdr */
2723 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxQueryVolumeInfo, (Context));
2724
2725 /* Post request if mini-rdr asked to */
2726 if (Context->PostRequest)
2727 {
2728 Status = RxFsdPostRequest(Context);
2729 }
2730 else
2731 {
2732 Irp->IoStatus.Information = Stack->Parameters.QueryVolume.Length - Context->Info.Length;
2733 }
2734
2735 DPRINT("Status: %x\n", Status);
2736 return Status;
2737 }
2738
2739 NTSTATUS
2740 NTAPI
2741 RxCommonRead(
2742 PRX_CONTEXT RxContext)
2743 {
2744 PFCB Fcb;
2745 PIRP Irp;
2746 PFOBX Fobx;
2747 NTSTATUS Status;
2748 PNET_ROOT NetRoot;
2749 PVOID SystemBuffer;
2750 PFILE_OBJECT FileObject;
2751 LARGE_INTEGER ByteOffset;
2752 PIO_STACK_LOCATION Stack;
2753 PLOWIO_CONTEXT LowIoContext;
2754 PRDBSS_DEVICE_OBJECT RxDeviceObject;
2755 ULONG ReadLength, CapturedRxContextSerialNumber = RxContext->SerialNumber;
2756 BOOLEAN CanWait, PagingIo, NoCache, Sync, PostRequest, IsPipe, ReadCachingEnabled, ReadCachingDisabled, InFsp, OwnerSet;
2757
2758 PAGED_CODE();
2759
2760 Fcb = (PFCB)RxContext->pFcb;
2761 Fobx = (PFOBX)RxContext->pFobx;
2762 DPRINT("RxCommonRead(%p) FOBX: %p, FCB: %p\n", RxContext, Fobx, Fcb);
2763
2764 /* Get some parameters */
2765 Irp = RxContext->CurrentIrp;
2766 Stack = RxContext->CurrentIrpSp;
2767 CanWait = BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_WAIT);
2768 PagingIo = BooleanFlagOn(Irp->Flags, IRP_PAGING_IO);
2769 NoCache = BooleanFlagOn(Irp->Flags, IRP_NOCACHE);
2770 Sync = !BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_ASYNC_OPERATION);
2771 InFsp = BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_IN_FSP);
2772 ReadLength = Stack->Parameters.Read.Length;
2773 ByteOffset.QuadPart = Stack->Parameters.Read.ByteOffset.QuadPart;
2774 DPRINT("Reading: %lx@%I64x %s %s %s %s\n", ReadLength, ByteOffset.QuadPart,
2775 (CanWait ? "CW" : "!CW"), (PagingIo ? "PI" : "!PI"), (NoCache ? "NC" : "!NC"), (Sync ? "S" : "!S"));
2776
2777 RxItsTheSameContext();
2778
2779 Irp->IoStatus.Information = 0;
2780
2781 /* Should the read be loud - so far, it's just ignored on ReactOS:
2782 * s/DPRINT/DPRINT1/g will make it loud
2783 */
2784 LowIoContext = &RxContext->LowIoContext;
2785 CheckForLoudOperations(RxContext);
2786 if (BooleanFlagOn(LowIoContext->Flags, LOWIO_CONTEXT_FLAG_LOUDOPS))
2787 {
2788 DPRINT("LoudRead %I64x/%lx on %lx vdl/size/alloc %I64x/%I64x/%I64x\n",
2789 ByteOffset, ReadLength,
2790 Fcb, Fcb->Header.ValidDataLength, Fcb->Header.FileSize, Fcb->Header.AllocationSize);
2791 }
2792
2793 RxDeviceObject = RxContext->RxDeviceObject;
2794 /* Update stats */
2795 if (!BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_IN_FSP) && Fcb->CachedNetRootType == NET_ROOT_DISK)
2796 {
2797 InterlockedIncrement((volatile long *)&RxDeviceObject->ReadOperations);
2798
2799 if (ByteOffset.QuadPart != Fobx->Specific.DiskFile.PredictedReadOffset)
2800 {
2801 InterlockedIncrement((volatile long *)&RxDeviceObject->RandomReadOperations);
2802 }
2803 Fobx->Specific.DiskFile.PredictedReadOffset = ByteOffset.QuadPart + ReadLength;
2804
2805 if (PagingIo)
2806 {
2807 ExInterlockedAddLargeStatistic(&RxDeviceObject->PagingReadBytesRequested, ReadLength);
2808 }
2809 else if (NoCache)
2810 {
2811 ExInterlockedAddLargeStatistic(&RxDeviceObject->NonPagingReadBytesRequested, ReadLength);
2812 }
2813 else
2814 {
2815 ExInterlockedAddLargeStatistic(&RxDeviceObject->CacheReadBytesRequested, ReadLength);
2816 }
2817 }
2818
2819 /* A pagefile cannot be a pipe */
2820 IsPipe = Fcb->NetRoot->Type == NET_ROOT_PIPE;
2821 if (IsPipe && PagingIo)
2822 {
2823 return STATUS_INVALID_DEVICE_REQUEST;
2824 }
2825
2826 /* Null-length read is no-op */
2827 if (ReadLength == 0)
2828 {
2829 return STATUS_SUCCESS;
2830 }
2831
2832 /* Validate FCB type */
2833 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_FILE && NodeType(Fcb) != RDBSS_NTC_VOLUME_FCB)
2834 {
2835 return STATUS_INVALID_DEVICE_REQUEST;
2836 }
2837
2838 /* Init the lowio context for possible forward */
2839 RxInitializeLowIoContext(LowIoContext, LOWIO_OP_READ);
2840
2841 PostRequest = FALSE;
2842 ReadCachingDisabled = FALSE;
2843 OwnerSet = FALSE;
2844 ReadCachingEnabled = BooleanFlagOn(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
2845 FileObject = Stack->FileObject;
2846 NetRoot = (PNET_ROOT)Fcb->pNetRoot;
2847 _SEH2_TRY
2848 {
2849 LONGLONG FileSize;
2850
2851 /* If no caching, make sure current Cc data have been flushed */
2852 if (!PagingIo && NoCache && !ReadCachingEnabled && FileObject->SectionObjectPointer != NULL)
2853 {
2854 Status = RxAcquireExclusiveFcb(RxContext, Fcb);
2855 if (Status == STATUS_LOCK_NOT_GRANTED)
2856 {
2857 PostRequest = TRUE;
2858 _SEH2_LEAVE;
2859 }
2860 else if (Status != STATUS_SUCCESS)
2861 {
2862 _SEH2_LEAVE;
2863 }
2864
2865 ExAcquireResourceSharedLite(Fcb->Header.PagingIoResource, TRUE);
2866 CcFlushCache(FileObject->SectionObjectPointer, &ByteOffset, ReadLength, &Irp->IoStatus);
2867 RxReleasePagingIoResource(RxContext, Fcb);
2868
2869 if (!NT_SUCCESS(Irp->IoStatus.Status))
2870 {
2871 _SEH2_LEAVE;
2872 }
2873
2874 RxAcquirePagingIoResource(RxContext, Fcb);
2875 RxReleasePagingIoResource(RxContext, Fcb);
2876 }
2877
2878 /* Acquire the appropriate lock */
2879 if (PagingIo && !ReadCachingEnabled)
2880 {
2881 ASSERT(!IsPipe);
2882
2883 if (!ExAcquireResourceSharedLite(Fcb->Header.PagingIoResource, CanWait))
2884 {
2885 PostRequest = TRUE;
2886 _SEH2_LEAVE;
2887 }
2888
2889 if (!CanWait)
2890 {
2891 LowIoContext->Resource = Fcb->Header.PagingIoResource;
2892 }
2893 }
2894 else
2895 {
2896 if (!ReadCachingEnabled)
2897 {
2898 if (!CanWait && NoCache)
2899 {
2900 Status = RxAcquireSharedFcbWaitForEx(RxContext, Fcb);
2901 if (Status == STATUS_LOCK_NOT_GRANTED)
2902 {
2903 DPRINT1("RdAsyLNG %x\n", RxContext);
2904 PostRequest = TRUE;
2905 _SEH2_LEAVE;
2906 }
2907 if (Status != STATUS_SUCCESS)
2908 {
2909 DPRINT1("RdAsyOthr %x\n", RxContext);
2910 _SEH2_LEAVE;
2911 }
2912
2913 if (RxIsFcbAcquiredShared(Fcb) <= 0xF000)
2914 {
2915 LowIoContext->Resource = Fcb->Header.Resource;
2916 }
2917 else
2918 {
2919 PostRequest = TRUE;
2920 _SEH2_LEAVE;
2921 }
2922 }
2923 else
2924 {
2925 Status = RxAcquireSharedFcb(RxContext, Fcb);
2926 if (Status == STATUS_LOCK_NOT_GRANTED)
2927 {
2928 PostRequest = TRUE;
2929 _SEH2_LEAVE;
2930 }
2931 else if (Status != STATUS_SUCCESS)
2932 {
2933 _SEH2_LEAVE;
2934 }
2935 }
2936 }
2937 }
2938
2939 RxItsTheSameContext();
2940
2941 ReadCachingDisabled = (ReadCachingEnabled == FALSE);
2942 if (IsPipe)
2943 {
2944 UNIMPLEMENTED;
2945 }
2946
2947 RxGetFileSizeWithLock(Fcb, &FileSize);
2948
2949 /* Make sure FLOCK doesn't conflict */
2950 if (!PagingIo)
2951 {
2952 if (!FsRtlCheckLockForReadAccess(&Fcb->Specific.Fcb.FileLock, Irp))
2953 {
2954 Status = STATUS_FILE_LOCK_CONFLICT;
2955 _SEH2_LEAVE;
2956 }
2957 }
2958
2959 /* Validate byteoffset vs length */
2960 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED))
2961 {
2962 if (ByteOffset.QuadPart >= FileSize)
2963 {
2964 Status = STATUS_END_OF_FILE;
2965 _SEH2_LEAVE;
2966 }
2967
2968 if (ReadLength > FileSize - ByteOffset.QuadPart)
2969 {
2970 ReadLength = FileSize - ByteOffset.QuadPart;
2971 }
2972 }
2973
2974 /* Read with Cc! */
2975 if (!PagingIo && !NoCache && ReadCachingEnabled &&
2976 !BooleanFlagOn(Fobx->pSrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_READ_CACHING))
2977 {
2978 /* File was not cached yet, do it */
2979 if (FileObject->PrivateCacheMap == NULL)
2980 {
2981 if (BooleanFlagOn(FileObject->Flags, FO_CLEANUP_COMPLETE))
2982 {
2983 Status = STATUS_FILE_CLOSED;
2984 _SEH2_LEAVE;
2985 }
2986
2987 RxAdjustAllocationSizeforCC(Fcb);
2988
2989 CcInitializeCacheMap(FileObject, (PCC_FILE_SIZES)&Fcb->Header.AllocationSize,
2990 FALSE, &RxData.CacheManagerCallbacks, Fcb);
2991
2992 if (BooleanFlagOn(Fcb->MRxDispatch->MRxFlags, RDBSS_NO_DEFERRED_CACHE_READAHEAD))
2993 {
2994 CcSetAdditionalCacheAttributes(FileObject, FALSE, FALSE);
2995 }
2996 else
2997 {
2998 CcSetAdditionalCacheAttributes(FileObject, TRUE, FALSE);
2999 SetFlag(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED);
3000 }
3001
3002 CcSetReadAheadGranularity(FileObject, NetRoot->DiskParameters.ReadAheadGranularity);
3003 }
3004
3005 /* This should never happen - fix your RDR */
3006 if (BooleanFlagOn(RxContext->MinorFunction, IRP_MN_MDL))
3007 {
3008 ASSERT(FALSE);
3009 ASSERT(CanWait);
3010
3011 CcMdlRead(FileObject, &ByteOffset, ReadLength, &Irp->MdlAddress, &Irp->IoStatus);
3012 Status = Irp->IoStatus.Status;
3013 ASSERT(NT_SUCCESS(Status));
3014 }
3015 else
3016 {
3017 /* Map buffer */
3018 SystemBuffer = RxNewMapUserBuffer(RxContext);
3019 if (SystemBuffer == NULL)
3020 {
3021 Status = STATUS_INSUFFICIENT_RESOURCES;
3022 _SEH2_LEAVE;
3023 }
3024
3025 SetFlag(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
3026
3027 RxItsTheSameContext();
3028
3029 /* Perform the read */
3030 if (!CcCopyRead(FileObject, &ByteOffset, ReadLength, CanWait, SystemBuffer, &Irp->IoStatus))
3031 {
3032 if (!ReadCachingEnabled)
3033 {
3034 ClearFlag(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
3035 }
3036
3037 RxItsTheSameContext();
3038
3039 PostRequest = TRUE;
3040 _SEH2_LEAVE;
3041 }
3042
3043 if (!ReadCachingEnabled)
3044 {
3045 ClearFlag(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
3046 }
3047
3048 Status = Irp->IoStatus.Status;
3049 ASSERT(NT_SUCCESS(Status));
3050 }
3051 }
3052 else
3053 {
3054 /* Validate the reading */
3055 if (FileObject->PrivateCacheMap != NULL && BooleanFlagOn(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED) &&
3056 ByteOffset.QuadPart >= 4096)
3057 {
3058 CcSetAdditionalCacheAttributes(FileObject, FALSE, FALSE);
3059 ClearFlag(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED);
3060 }
3061
3062 /* If it's consistent, forward to mini-rdr */
3063 if (Fcb->CachedNetRootType != NET_ROOT_DISK || BooleanFlagOn(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED) ||
3064 ByteOffset.QuadPart < Fcb->Header.ValidDataLength.QuadPart)
3065 {
3066 LowIoContext->ParamsFor.ReadWrite.ByteCount = ReadLength;
3067 LowIoContext->ParamsFor.ReadWrite.ByteOffset = ByteOffset.QuadPart;
3068
3069 RxItsTheSameContext();
3070
3071 if (InFsp && ReadCachingDisabled)
3072 {
3073 ExSetResourceOwnerPointer((PagingIo ? Fcb->Header.PagingIoResource : Fcb->Header.Resource),
3074 (PVOID)((ULONG_PTR)RxContext | 3));
3075 OwnerSet = TRUE;
3076 }
3077
3078 Status = RxLowIoReadShell(RxContext);
3079
3080 RxItsTheSameContext();
3081 }
3082 else
3083 {
3084 if (ByteOffset.QuadPart > FileSize)
3085 {
3086 ReadLength = 0;
3087 Irp->IoStatus.Information = ReadLength;
3088 _SEH2_LEAVE;
3089 }
3090
3091 if (ByteOffset.QuadPart + ReadLength > FileSize)
3092 {
3093 ReadLength = FileSize - ByteOffset.QuadPart;
3094 }
3095
3096 SystemBuffer = RxNewMapUserBuffer(RxContext);
3097 RtlZeroMemory(SystemBuffer, ReadLength);
3098 Irp->IoStatus.Information = ReadLength;
3099 }
3100 }
3101 }
3102 _SEH2_FINALLY
3103 {
3104 RxItsTheSameContext();
3105
3106 /* Post if required */
3107 if (PostRequest)
3108 {
3109 InterlockedIncrement((volatile long *)&RxContext->ReferenceCount);
3110 Status = RxFsdPostRequest(RxContext);
3111 }
3112 else
3113 {
3114 /* Update FO in case of sync IO */
3115 if (!IsPipe && !PagingIo)
3116 {
3117 if (BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
3118 {
3119 FileObject->CurrentByteOffset.QuadPart = ByteOffset.QuadPart + Irp->IoStatus.Information;
3120 }
3121 }
3122 }
3123
3124 /* Set FastIo if read was a success */
3125 if (NT_SUCCESS(Status) && Status != STATUS_PENDING)
3126 {
3127 if (!IsPipe && !PagingIo)
3128 {
3129 SetFlag(FileObject->Flags, FO_FILE_FAST_IO_READ);
3130 }
3131 }
3132
3133 /* In case we're done (not expected any further processing */
3134 if (_SEH2_AbnormalTermination() || Status != STATUS_PENDING || PostRequest)
3135 {
3136 /* Release everything that can be */
3137 if (ReadCachingDisabled)
3138 {
3139 if (PagingIo)
3140 {
3141 if (OwnerSet)
3142 {
3143 RxReleasePagingIoResourceForThread(RxContext, Fcb, LowIoContext->ResourceThreadId);
3144 }
3145 else
3146 {
3147 RxReleasePagingIoResource(RxContext, Fcb);
3148 }
3149 }
3150 else
3151 {
3152 if (OwnerSet)
3153 {
3154 RxReleaseFcbForThread(RxContext, Fcb, LowIoContext->ResourceThreadId);
3155 }
3156 else
3157 {
3158 RxReleaseFcb(RxContext, Fcb);
3159 }
3160 }
3161 }
3162
3163 /* Dereference/Delete context */
3164 if (PostRequest)
3165 {
3166 RxDereferenceAndDeleteRxContext(RxContext);
3167 }
3168 else
3169 {
3170 if (BooleanFlagOn(RxContext->FlagsForLowIo, RXCONTEXT_FLAG4LOWIO_PIPE_SYNC_OPERATION))
3171 {
3172 RxResumeBlockedOperations_Serially(RxContext, &Fobx->Specific.NamedPipe.ReadSerializationQueue);
3173 }
3174 }
3175
3176 /* We cannot return more than asked */
3177 if (Status == STATUS_SUCCESS)
3178 {
3179 ASSERT(Irp->IoStatus.Information <= Stack->Parameters.Read.Length);
3180 }
3181 }
3182 else
3183 {
3184 ASSERT(!Sync);
3185
3186 RxDereferenceAndDeleteRxContext(RxContext);
3187 }
3188 }
3189 _SEH2_END;
3190
3191 return Status;
3192 }
3193
3194 NTSTATUS
3195 NTAPI
3196 RxCommonSetEa(
3197 PRX_CONTEXT Context)
3198 {
3199 UNIMPLEMENTED;
3200 return STATUS_NOT_IMPLEMENTED;
3201 }
3202
3203 NTSTATUS
3204 NTAPI
3205 RxCommonSetInformation(
3206 PRX_CONTEXT Context)
3207 {
3208 UNIMPLEMENTED;
3209 return STATUS_NOT_IMPLEMENTED;
3210 }
3211
3212 NTSTATUS
3213 NTAPI
3214 RxCommonSetQuotaInformation(
3215 PRX_CONTEXT Context)
3216 {
3217 UNIMPLEMENTED;
3218 return STATUS_NOT_IMPLEMENTED;
3219 }
3220
3221 NTSTATUS
3222 NTAPI
3223 RxCommonSetSecurity(
3224 PRX_CONTEXT Context)
3225 {
3226 UNIMPLEMENTED;
3227 return STATUS_NOT_IMPLEMENTED;
3228 }
3229
3230 NTSTATUS
3231 NTAPI
3232 RxCommonSetVolumeInformation(
3233 PRX_CONTEXT Context)
3234 {
3235 UNIMPLEMENTED;
3236 return STATUS_NOT_IMPLEMENTED;
3237 }
3238
3239 NTSTATUS
3240 NTAPI
3241 RxCommonUnimplemented(
3242 PRX_CONTEXT Context)
3243 {
3244 UNIMPLEMENTED;
3245 return STATUS_NOT_IMPLEMENTED;
3246 }
3247
3248 NTSTATUS
3249 NTAPI
3250 RxCommonWrite(
3251 PRX_CONTEXT Context)
3252 {
3253 UNIMPLEMENTED;
3254 return STATUS_NOT_IMPLEMENTED;
3255 }
3256
3257 NTSTATUS
3258 NTAPI
3259 RxCompleteMdl(
3260 IN PRX_CONTEXT RxContext)
3261 {
3262 PAGED_CODE();
3263
3264 UNIMPLEMENTED;
3265 return STATUS_NOT_IMPLEMENTED;
3266 }
3267
3268 /*
3269 * @implemented
3270 */
3271 VOID
3272 RxCopyCreateParameters(
3273 IN PRX_CONTEXT RxContext)
3274 {
3275 PIRP Irp;
3276 PVOID DfsContext;
3277 PFILE_OBJECT FileObject;
3278 PIO_STACK_LOCATION Stack;
3279 PDFS_NAME_CONTEXT DfsNameContext;
3280 PIO_SECURITY_CONTEXT SecurityContext;
3281
3282 Irp = RxContext->CurrentIrp;
3283 Stack = RxContext->CurrentIrpSp;
3284 FileObject = Stack->FileObject;
3285 SecurityContext = Stack->Parameters.Create.SecurityContext;
3286
3287 RxContext->Create.NtCreateParameters.SecurityContext = SecurityContext;
3288 if (SecurityContext->AccessState != NULL && SecurityContext->AccessState->SecurityDescriptor != NULL)
3289 {
3290 RxContext->Create.SdLength = RtlLengthSecurityDescriptor(SecurityContext->AccessState->SecurityDescriptor);
3291 DPRINT("SD Ctxt: %p, Length: %lx\n", RxContext->Create.NtCreateParameters.SecurityContext,
3292 RxContext->Create.SdLength);
3293 }
3294 if (SecurityContext->SecurityQos != NULL)
3295 {
3296 RxContext->Create.NtCreateParameters.ImpersonationLevel = SecurityContext->SecurityQos->ImpersonationLevel;
3297 }
3298 else
3299 {
3300 RxContext->Create.NtCreateParameters.ImpersonationLevel = SecurityImpersonation;
3301 }
3302 RxContext->Create.NtCreateParameters.DesiredAccess = SecurityContext->DesiredAccess;
3303
3304 RxContext->Create.NtCreateParameters.AllocationSize.QuadPart = Irp->Overlay.AllocationSize.QuadPart;
3305 RxContext->Create.NtCreateParameters.FileAttributes = Stack->Parameters.Create.FileAttributes & FILE_ATTRIBUTE_VALID_FLAGS;
3306 RxContext->Create.NtCreateParameters.ShareAccess = Stack->Parameters.Create.ShareAccess & FILE_SHARE_VALID_FLAGS;
3307 RxContext->Create.NtCreateParameters.Disposition = (Stack->Parameters.Create.Options >> 24) & 0x000000FF;
3308 RxContext->Create.NtCreateParameters.CreateOptions = Stack->Parameters.Create.Options & 0xFFFFFF;
3309
3310 DfsContext = FileObject->FsContext2;
3311 DfsNameContext = FileObject->FsContext;
3312 RxContext->Create.NtCreateParameters.DfsContext = DfsContext;
3313 RxContext->Create.NtCreateParameters.DfsNameContext = DfsNameContext;
3314 ASSERT(DfsContext == NULL || DfsContext == UIntToPtr(DFS_OPEN_CONTEXT) ||
3315 DfsContext == UIntToPtr(DFS_DOWNLEVEL_OPEN_CONTEXT) ||
3316 DfsContext == UIntToPtr(DFS_CSCAGENT_NAME_CONTEXT) ||
3317 DfsContext == UIntToPtr(DFS_USER_NAME_CONTEXT));
3318 ASSERT(DfsNameContext == NULL || DfsNameContext->NameContextType == DFS_OPEN_CONTEXT ||
3319 DfsNameContext->NameContextType == DFS_DOWNLEVEL_OPEN_CONTEXT ||
3320 DfsNameContext->NameContextType == DFS_CSCAGENT_NAME_CONTEXT ||
3321 DfsNameContext->NameContextType == DFS_USER_NAME_CONTEXT);
3322 FileObject->FsContext2 = NULL;
3323 FileObject->FsContext = NULL;
3324
3325 RxContext->pFcb = NULL;
3326 RxContext->Create.ReturnedCreateInformation = 0;
3327
3328 /* if we stripped last \, it has to be a directory! */
3329 if (BooleanFlagOn(RxContext->Create.Flags, RX_CONTEXT_CREATE_FLAG_STRIPPED_TRAILING_BACKSLASH))
3330 {
3331 SetFlag(RxContext->Create.NtCreateParameters.CreateOptions, FILE_DIRECTORY_FILE);
3332 }
3333
3334 RxContext->Create.EaLength = Stack->Parameters.Create.EaLength;
3335 if (RxContext->Create.EaLength == 0)
3336 {
3337 RxContext->Create.EaBuffer = NULL;
3338 }
3339 else
3340 {
3341 RxContext->Create.EaBuffer = Irp->AssociatedIrp.SystemBuffer;
3342 DPRINT("EA Buffer: %p, Length: %lx\n", Irp->AssociatedIrp.SystemBuffer, RxContext->Create.EaLength);
3343 }
3344 }
3345
3346 NTSTATUS
3347 RxCreateFromNetRoot(
3348 PRX_CONTEXT Context,
3349 PUNICODE_STRING NetRootName)
3350 {
3351 PFCB Fcb;