[RDBSS]
[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 /*
917 * @implemented
918 */
919 NTSTATUS
920 RxCancelNotifyChangeDirectoryRequestsForVNetRoot(
921 PV_NET_ROOT VNetRoot,
922 BOOLEAN ForceFilesClosed)
923 {
924 KIRQL OldIrql;
925 NTSTATUS Status;
926 PLIST_ENTRY Entry;
927 PRX_CONTEXT Context;
928 LIST_ENTRY ContextsToCancel;
929
930 /* Init a list for the contexts to cancel */
931 InitializeListHead(&ContextsToCancel);
932
933 /* Lock our list lock */
934 KeAcquireSpinLock(&RxStrucSupSpinLock, &OldIrql);
935
936 /* Now, browse all the active contexts, to find the associated ones */
937 Entry = RxActiveContexts.Flink;
938 while (Entry != &RxActiveContexts)
939 {
940 Context = CONTAINING_RECORD(Entry, RX_CONTEXT, ContextListEntry);
941 Entry = Entry->Flink;
942
943 /* Not the IRP we're looking for, ignore */
944 if (Context->MajorFunction != IRP_MJ_DIRECTORY_CONTROL ||
945 Context->MinorFunction != IRP_MN_NOTIFY_CHANGE_DIRECTORY)
946 {
947 continue;
948 }
949
950 /* Not the VNetRoot we're looking for, ignore */
951 if (Context->pFcb == NULL ||
952 (PV_NET_ROOT)Context->NotifyChangeDirectory.pVNetRoot != VNetRoot)
953 {
954 continue;
955 }
956
957 /* No cancel routine (can't be cancel, then), ignore */
958 if (Context->MRxCancelRoutine == NULL)
959 {
960 continue;
961 }
962
963 /* At that point, we found a matching context
964 * If we're not asked to force close, then fail - it's still open
965 */
966 if (!ForceFilesClosed)
967 {
968 Status = STATUS_FILES_OPEN;
969 break;
970 }
971
972 /* Mark our context as cancelled */
973 SetFlag(Context->Flags, RX_CONTEXT_FLAG_CANCELLED);
974
975 /* Move it to our list */
976 RemoveEntryList(&Context->ContextListEntry);
977 InsertTailList(&ContextsToCancel, &Context->ContextListEntry);
978
979 InterlockedIncrement((volatile long *)&Context->ReferenceCount);
980 }
981
982 /* Done with the contexts */
983 KeReleaseSpinLock(&RxStrucSupSpinLock, OldIrql);
984
985 if (Status != STATUS_SUCCESS)
986 {
987 return Status;
988 }
989
990 /* Now, handle all our "extracted" contexts */
991 while (!IsListEmpty(&ContextsToCancel))
992 {
993 Entry = RemoveHeadList(&ContextsToCancel);
994 Context = CONTAINING_RECORD(Entry, RX_CONTEXT, ContextListEntry);
995
996 /* If they had an associated IRP (should be always true) */
997 if (Context->CurrentIrp != NULL)
998 {
999 /* Then, call cancel routine */
1000 ASSERT(Context->MRxCancelRoutine != NULL);
1001 DPRINT1("Canceling %p with %p\n", Context, Context->MRxCancelRoutine);
1002 Context->MRxCancelRoutine(Context);
1003 }
1004
1005 /* And delete the context */
1006 RxDereferenceAndDeleteRxContext(Context);
1007 }
1008
1009 return Status;
1010 }
1011
1012 VOID
1013 NTAPI
1014 RxCancelRoutine(
1015 PDEVICE_OBJECT DeviceObject,
1016 PIRP Irp)
1017 {
1018 UNIMPLEMENTED;
1019 }
1020
1021 /*
1022 * @implemented
1023 */
1024 NTSTATUS
1025 RxCanonicalizeFileNameByServerSpecs(
1026 PRX_CONTEXT RxContext,
1027 PUNICODE_STRING NetRootName)
1028 {
1029 USHORT NextChar, CurChar;
1030 USHORT MaxChars;
1031
1032 PAGED_CODE();
1033
1034 /* Validate file name is not empty */
1035 MaxChars = NetRootName->Length / sizeof(WCHAR);
1036 if (MaxChars == 0)
1037 {
1038 return STATUS_MORE_PROCESSING_REQUIRED;
1039 }
1040
1041 /* Validate name is correct */
1042 for (NextChar = 0, CurChar = 0; CurChar + 1 < MaxChars; NextChar = CurChar + 1)
1043 {
1044 USHORT i;
1045
1046 for (i = NextChar + 1; i < MaxChars; ++i)
1047 {
1048 if (NetRootName->Buffer[i] == '\\' || NetRootName->Buffer[i] == ':')
1049 {
1050 break;
1051 }
1052 }
1053
1054 CurChar = i - 1;
1055 if (CurChar == NextChar)
1056 {
1057 if (((NetRootName->Buffer[NextChar] != '\\' && NetRootName->Buffer[NextChar] != ':') || NextChar == (MaxChars - 1)) && NetRootName->Buffer[NextChar] != '.')
1058 {
1059 continue;
1060 }
1061
1062 if (CurChar != 0)
1063 {
1064 if (CurChar >= MaxChars - 1)
1065 {
1066 continue;
1067 }
1068
1069 if (NetRootName->Buffer[CurChar + 1] != ':')
1070 {
1071 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1072 }
1073 }
1074 else
1075 {
1076 if (NetRootName->Buffer[1] != ':')
1077 {
1078 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1079 }
1080 }
1081 }
1082 else
1083 {
1084 if ((CurChar - NextChar) == 1)
1085 {
1086 if (NetRootName->Buffer[NextChar + 2] != '.')
1087 {
1088 continue;
1089 }
1090
1091 if (NetRootName->Buffer[NextChar] == '\\' || NetRootName->Buffer[NextChar] == ':' || NetRootName->Buffer[NextChar] == '.')
1092 {
1093 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1094 }
1095 }
1096 else
1097 {
1098 if ((CurChar - NextChar) != 2 || (NetRootName->Buffer[NextChar] != '\\' && NetRootName->Buffer[NextChar] != ':')
1099 || NetRootName->Buffer[NextChar + 1] != '.')
1100 {
1101 continue;
1102 }
1103
1104 if (NetRootName->Buffer[NextChar + 2] == '.')
1105 {
1106 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1107 }
1108 }
1109 }
1110 }
1111
1112 return STATUS_MORE_PROCESSING_REQUIRED;
1113 }
1114
1115 NTSTATUS
1116 RxCanonicalizeNameAndObtainNetRoot(
1117 PRX_CONTEXT RxContext,
1118 PUNICODE_STRING FileName,
1119 PUNICODE_STRING NetRootName)
1120 {
1121 NTSTATUS Status;
1122 NET_ROOT_TYPE NetRootType;
1123 UNICODE_STRING CanonicalName;
1124
1125 PAGED_CODE();
1126
1127 NetRootType = NET_ROOT_WILD;
1128
1129 RtlInitEmptyUnicodeString(NetRootName, NULL, 0);
1130 RtlInitEmptyUnicodeString(&CanonicalName, NULL, 0);
1131
1132 /* if not relative opening, just handle the passed name */
1133 if (RxContext->CurrentIrpSp->FileObject->RelatedFileObject == NULL)
1134 {
1135 Status = RxFirstCanonicalize(RxContext, FileName, &CanonicalName, &NetRootType);
1136 if (!NT_SUCCESS(Status))
1137 {
1138 return Status;
1139 }
1140 }
1141 else
1142 {
1143 PFCB Fcb;
1144
1145 /* Make sure we have a valid FCB and a FOBX */
1146 Fcb = RxContext->CurrentIrpSp->FileObject->RelatedFileObject->FsContext;
1147 if (Fcb == NULL ||
1148 RxContext->CurrentIrpSp->FileObject->RelatedFileObject->FsContext2 == NULL)
1149 {
1150 return STATUS_INVALID_PARAMETER;
1151 }
1152
1153 if (!NodeTypeIsFcb(Fcb))
1154 {
1155 return STATUS_INVALID_PARAMETER;
1156 }
1157
1158 UNIMPLEMENTED;
1159 }
1160
1161 /* Get/Create the associated VNetRoot for opening */
1162 Status = RxFindOrConstructVirtualNetRoot(RxContext, &CanonicalName, NetRootType, NetRootName);
1163 if (!NT_SUCCESS(Status) && Status != STATUS_PENDING &&
1164 BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_MAILSLOT_REPARSE))
1165 {
1166 ASSERT(CanonicalName.Buffer == RxContext->Create.CanonicalNameBuffer);
1167
1168 RxFreeCanonicalNameBuffer(RxContext);
1169 Status = RxFirstCanonicalize(RxContext, FileName, &CanonicalName, &NetRootType);
1170 if (NT_SUCCESS(Status))
1171 {
1172 Status = RxFindOrConstructVirtualNetRoot(RxContext, &CanonicalName, NetRootType, NetRootName);
1173 }
1174 }
1175
1176 /* Filename cannot contain wildcards */
1177 if (FsRtlDoesNameContainWildCards(NetRootName))
1178 {
1179 Status = STATUS_OBJECT_NAME_INVALID;
1180 }
1181
1182 /* Make sure file name is correct */
1183 if (NT_SUCCESS(Status))
1184 {
1185 Status = RxCanonicalizeFileNameByServerSpecs(RxContext, NetRootName);
1186 }
1187
1188 /* Give the mini-redirector a chance to prepare the name */
1189 if (NT_SUCCESS(Status) || Status == STATUS_MORE_PROCESSING_REQUIRED)
1190 {
1191 if (RxContext->Create.pNetRoot != NULL)
1192 {
1193 NTSTATUS IgnoredStatus;
1194
1195 MINIRDR_CALL(IgnoredStatus, RxContext, RxContext->Create.pNetRoot->pSrvCall->RxDeviceObject->Dispatch,
1196 MRxPreparseName, (RxContext, NetRootName));
1197 (void)IgnoredStatus;
1198 }
1199 }
1200
1201 return Status;
1202 }
1203
1204 VOID
1205 NTAPI
1206 RxCheckFcbStructuresForAlignment(
1207 VOID)
1208 {
1209 UNIMPLEMENTED;
1210 }
1211
1212 NTSTATUS
1213 RxCheckShareAccess(
1214 _In_ ACCESS_MASK DesiredAccess,
1215 _In_ ULONG DesiredShareAccess,
1216 _Inout_ PFILE_OBJECT FileObject,
1217 _Inout_ PSHARE_ACCESS ShareAccess,
1218 _In_ BOOLEAN Update,
1219 _In_ PSZ where,
1220 _In_ PSZ wherelogtag)
1221 {
1222 PAGED_CODE();
1223
1224 RxDumpWantedAccess(where, "", wherelogtag, DesiredAccess, DesiredShareAccess);
1225 RxDumpCurrentAccess(where, "", wherelogtag, ShareAccess);
1226
1227 return IoCheckShareAccess(DesiredAccess, DesiredShareAccess, FileObject, ShareAccess, Update);
1228 }
1229
1230 /*
1231 * @implemented
1232 */
1233 NTSTATUS
1234 RxCheckShareAccessPerSrvOpens(
1235 IN PFCB Fcb,
1236 IN ACCESS_MASK DesiredAccess,
1237 IN ULONG DesiredShareAccess)
1238 {
1239 BOOLEAN ReadAccess;
1240 BOOLEAN WriteAccess;
1241 BOOLEAN DeleteAccess;
1242 PSHARE_ACCESS ShareAccess;
1243
1244 PAGED_CODE();
1245
1246 ShareAccess = &Fcb->ShareAccessPerSrvOpens;
1247
1248 RxDumpWantedAccess("RxCheckShareAccessPerSrvOpens", "", "RxCheckShareAccessPerSrvOpens", DesiredAccess, DesiredShareAccess);
1249 RxDumpCurrentAccess("RxCheckShareAccessPerSrvOpens", "", "RxCheckShareAccessPerSrvOpens", ShareAccess);
1250
1251 /* Check if any access wanted */
1252 ReadAccess = (DesiredAccess & (FILE_READ_DATA | FILE_EXECUTE)) != 0;
1253 WriteAccess = (DesiredAccess & (FILE_WRITE_DATA | FILE_APPEND_DATA)) != 0;
1254 DeleteAccess = (DesiredAccess & DELETE) != 0;
1255
1256 if (ReadAccess || WriteAccess || DeleteAccess)
1257 {
1258 BOOLEAN SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0;
1259 BOOLEAN SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0;
1260 BOOLEAN SharedDelete = (DesiredShareAccess & FILE_SHARE_DELETE) != 0;
1261
1262 /* Check whether there's a violation */
1263 if ((ReadAccess &&
1264 (ShareAccess->SharedRead < ShareAccess->OpenCount)) ||
1265 (WriteAccess &&
1266 (ShareAccess->SharedWrite < ShareAccess->OpenCount)) ||
1267 (DeleteAccess &&
1268 (ShareAccess->SharedDelete < ShareAccess->OpenCount)) ||
1269 ((ShareAccess->Readers != 0) && !SharedRead) ||
1270 ((ShareAccess->Writers != 0) && !SharedWrite) ||
1271 ((ShareAccess->Deleters != 0) && !SharedDelete))
1272 {
1273 return STATUS_SHARING_VIOLATION;
1274 }
1275 }
1276
1277 return STATUS_SUCCESS;
1278 }
1279
1280 VOID
1281 RxCleanupPipeQueues(
1282 PRX_CONTEXT Context)
1283 {
1284 UNIMPLEMENTED;
1285 }
1286
1287 /*
1288 * @implemented
1289 */
1290 NTSTATUS
1291 RxCloseAssociatedSrvOpen(
1292 IN PFOBX Fobx,
1293 IN PRX_CONTEXT RxContext OPTIONAL)
1294 {
1295 PFCB Fcb;
1296 NTSTATUS Status;
1297 PSRV_OPEN SrvOpen;
1298 BOOLEAN CloseSrvOpen;
1299 PRX_CONTEXT LocalContext;
1300
1301 PAGED_CODE();
1302
1303 /* Assume SRV_OPEN is already closed */
1304 CloseSrvOpen = FALSE;
1305 /* If we have a FOBX, we'll have to close it */
1306 if (Fobx != NULL)
1307 {
1308 /* If the FOBX isn't closed yet */
1309 if (!BooleanFlagOn(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED))
1310 {
1311 SrvOpen = Fobx->SrvOpen;
1312 Fcb = (PFCB)SrvOpen->pFcb;
1313 /* Check whether we've to close SRV_OPEN first */
1314 if (!BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_CLOSED))
1315 {
1316 CloseSrvOpen = TRUE;
1317 }
1318 else
1319 {
1320 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1321
1322 /* Not much to do */
1323 SetFlag(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED);
1324
1325 if (SrvOpen->OpenCount > 0)
1326 {
1327 --SrvOpen->OpenCount;
1328 }
1329 }
1330 }
1331
1332 /* No need to close SRV_OPEN, so close FOBX */
1333 if (!CloseSrvOpen)
1334 {
1335 RxMarkFobxOnClose(Fobx);
1336
1337 return STATUS_SUCCESS;
1338 }
1339 }
1340 else
1341 {
1342 /* No FOBX? No RX_CONTEXT, ok, job done! */
1343 if (RxContext == NULL)
1344 {
1345 return STATUS_SUCCESS;
1346 }
1347
1348 /* Get the FCB from RX_CONTEXT */
1349 Fcb = (PFCB)RxContext->pFcb;
1350 SrvOpen = NULL;
1351 }
1352
1353 /* If we don't have RX_CONTEXT, allocte one, we'll need it */
1354 if (RxContext == NULL)
1355 {
1356 ASSERT(Fobx != NULL);
1357
1358 LocalContext = RxCreateRxContext(NULL, Fcb->RxDeviceObject, RX_CONTEXT_FLAG_MUST_SUCCEED_NONBLOCKING | RX_CONTEXT_FLAG_WAIT);
1359 if (LocalContext == NULL)
1360 {
1361 return STATUS_INSUFFICIENT_RESOURCES;
1362 }
1363
1364 LocalContext->MajorFunction = 2;
1365 LocalContext->pFcb = RX_GET_MRX_FCB(Fcb);
1366 LocalContext->pFobx = (PMRX_FOBX)Fobx;
1367 LocalContext->pRelevantSrvOpen = (PMRX_SRV_OPEN)Fobx->SrvOpen;
1368 }
1369 else
1370 {
1371 LocalContext = RxContext;
1372 }
1373
1374 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1375
1376 /* Now, close the FOBX */
1377 if (Fobx != NULL)
1378 {
1379 RxMarkFobxOnClose(Fobx);
1380 }
1381 else
1382 {
1383 InterlockedDecrement((volatile long *)&Fcb->OpenCount);
1384 }
1385
1386 /* If not a "standard" file, SRV_OPEN can be null */
1387 if (SrvOpen == NULL)
1388 {
1389 ASSERT((NodeType(Fcb) == RDBSS_NTC_OPENTARGETDIR_FCB) || (NodeType(Fcb) == RDBSS_NTC_IPC_SHARE) || (NodeType(Fcb) == RDBSS_NTC_MAILSLOT));
1390 RxDereferenceNetFcb(Fcb);
1391
1392 if (LocalContext != RxContext)
1393 {
1394 RxDereferenceAndDeleteRxContext(LocalContext);
1395 }
1396
1397 return STATUS_SUCCESS;
1398 }
1399
1400 /* If SRV_OPEN isn't in a good condition, nothing to close */
1401 if (SrvOpen->Condition != Condition_Good)
1402 {
1403 if (LocalContext != RxContext)
1404 {
1405 RxDereferenceAndDeleteRxContext(LocalContext);
1406 }
1407
1408 return STATUS_SUCCESS;
1409 }
1410
1411 /* Decrease open count */
1412 if (SrvOpen->OpenCount > 0)
1413 {
1414 --SrvOpen->OpenCount;
1415 }
1416
1417 /* If we're the only one left, is there a FOBX handled by Scavenger? */
1418 if (SrvOpen->OpenCount == 1)
1419 {
1420 if (!IsListEmpty(&SrvOpen->FobxList))
1421 {
1422 if (!IsListEmpty(&CONTAINING_RECORD(SrvOpen->FobxList.Flink, FOBX, FobxQLinks)->ScavengerFinalizationList))
1423 {
1424 SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_CLOSE_DELAYED);
1425 }
1426 }
1427 }
1428
1429 /* Nothing left, purge FCB */
1430 if (SrvOpen->OpenCount == 0 && RxContext == NULL)
1431 {
1432 RxPurgeNetFcb(Fcb, LocalContext);
1433 }
1434
1435 /* Already closed? Job done! */
1436 SrvOpen = Fobx->SrvOpen;
1437 if (SrvOpen == NULL ||
1438 (SrvOpen->OpenCount != 0 && !BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_BUFFERING_STATE_CHANGE_PENDING)) ||
1439 BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_CLOSED))
1440 {
1441 SetFlag(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED);
1442 if (LocalContext != RxContext)
1443 {
1444 RxDereferenceAndDeleteRxContext(LocalContext);
1445 }
1446
1447 return STATUS_SUCCESS;
1448 }
1449
1450 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1451
1452 /* Inform mini-rdr about closing */
1453 MINIRDR_CALL(Status, LocalContext, Fcb->MRxDispatch, MRxCloseSrvOpen, (LocalContext));
1454 DPRINT("MRxCloseSrvOpen returned: %lx, called with RX_CONTEXT %p for FOBX %p (FCB %p, SRV_OPEN %p)\n ",
1455 Status, RxContext, Fobx, Fcb, SrvOpen);
1456
1457 /* And mark as such */
1458 SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_CLOSED);
1459 SrvOpen->Key = (PVOID)-1;
1460
1461 /* If we were delayed, we're not! */
1462 if (BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_CLOSE_DELAYED))
1463 {
1464 InterlockedDecrement(&((PSRV_CALL)Fcb->pNetRoot->pSrvCall)->NumberOfCloseDelayedFiles);
1465 }
1466
1467 /* Clear access */
1468 RxRemoveShareAccessPerSrvOpens(SrvOpen);
1469 RxPurgeChangeBufferingStateRequestsForSrvOpen(SrvOpen);
1470
1471 /* Dereference */
1472 RxDereferenceSrvOpen(SrvOpen, LHS_ExclusiveLockHeld);
1473
1474 /* Mark the FOBX closed as well */
1475 SetFlag(Fobx->Flags, FOBX_FLAG_SRVOPEN_CLOSED);
1476
1477 if (LocalContext != RxContext)
1478 {
1479 RxDereferenceAndDeleteRxContext(LocalContext);
1480 }
1481
1482 return Status;
1483 }
1484
1485 /*
1486 * @implemented
1487 */
1488 NTSTATUS
1489 RxCollapseOrCreateSrvOpen(
1490 PRX_CONTEXT RxContext)
1491 {
1492 PFCB Fcb;
1493 NTSTATUS Status;
1494 ULONG Disposition;
1495 PSRV_OPEN SrvOpen;
1496 USHORT ShareAccess;
1497 PIO_STACK_LOCATION Stack;
1498 ACCESS_MASK DesiredAccess;
1499 RX_BLOCK_CONDITION FcbCondition;
1500
1501 PAGED_CODE();
1502
1503 DPRINT("RxCollapseOrCreateSrvOpen(%p)\n", RxContext);
1504
1505 Fcb = (PFCB)RxContext->pFcb;
1506 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1507 ++Fcb->UncleanCount;
1508
1509 Stack = RxContext->CurrentIrpSp;
1510 DesiredAccess = Stack->Parameters.Create.SecurityContext->DesiredAccess & FILE_ALL_ACCESS;
1511 ShareAccess = Stack->Parameters.Create.ShareAccess & FILE_SHARE_VALID_FLAGS;
1512
1513 Disposition = RxContext->Create.NtCreateParameters.Disposition;
1514
1515 /* Try to find a reusable SRV_OPEN */
1516 Status = RxSearchForCollapsibleOpen(RxContext, DesiredAccess, ShareAccess);
1517 if (Status == STATUS_NOT_FOUND)
1518 {
1519 /* If none found, create one */
1520 SrvOpen = RxCreateSrvOpen((PV_NET_ROOT)RxContext->Create.pVNetRoot, Fcb);
1521 if (SrvOpen == NULL)
1522 {
1523 Status = STATUS_INSUFFICIENT_RESOURCES;
1524 }
1525 else
1526 {
1527 SrvOpen->DesiredAccess = DesiredAccess;
1528 SrvOpen->ShareAccess = ShareAccess;
1529 Status = STATUS_SUCCESS;
1530 }
1531
1532 RxContext->pRelevantSrvOpen = (PMRX_SRV_OPEN)SrvOpen;
1533
1534 if (Status != STATUS_SUCCESS)
1535 {
1536 FcbCondition = Condition_Bad;
1537 }
1538 else
1539 {
1540 RxInitiateSrvOpenKeyAssociation(SrvOpen);
1541
1542 /* Cookie to check the mini-rdr doesn't mess with RX_CONTEXT */
1543 RxContext->CurrentIrp->IoStatus.Information = 0xABCDEF;
1544 /* Inform the mini-rdr we're handling a create */
1545 MINIRDR_CALL(Status, RxContext, Fcb->MRxDispatch, MRxCreate, (RxContext));
1546 ASSERT(RxContext->CurrentIrp->IoStatus.Information == 0xABCDEF);
1547
1548 DPRINT("MRxCreate returned: %x\n", Status);
1549 if (Status == STATUS_SUCCESS)
1550 {
1551 /* In case of overwrite, reset file size */
1552 if (Disposition == FILE_OVERWRITE || Disposition == FILE_OVERWRITE_IF)
1553 {
1554 RxAcquirePagingIoResource(RxContext, Fcb);
1555 Fcb->Header.AllocationSize.QuadPart = 0LL;
1556 Fcb->Header.FileSize.QuadPart = 0LL;
1557 Fcb->Header.ValidDataLength.QuadPart = 0LL;
1558 RxContext->CurrentIrpSp->FileObject->SectionObjectPointer = &Fcb->NonPaged->SectionObjectPointers;
1559 CcSetFileSizes(RxContext->CurrentIrpSp->FileObject, (PCC_FILE_SIZES)&Fcb->Header.AllocationSize);
1560 RxReleasePagingIoResource(RxContext, Fcb);
1561 }
1562 else
1563 {
1564 /* Otherwise, adjust sizes */
1565 RxContext->CurrentIrpSp->FileObject->SectionObjectPointer = &Fcb->NonPaged->SectionObjectPointers;
1566 if (CcIsFileCached(RxContext->CurrentIrpSp->FileObject))
1567 {
1568 RxAdjustAllocationSizeforCC(Fcb);
1569 }
1570 CcSetFileSizes(RxContext->CurrentIrpSp->FileObject, (PCC_FILE_SIZES)&Fcb->Header.AllocationSize);
1571 }
1572 }
1573
1574 /* Set the IoStatus with information returned by mini-rdr */
1575 RxContext->CurrentIrp->IoStatus.Information = RxContext->Create.ReturnedCreateInformation;
1576
1577 SrvOpen->OpenStatus = Status;
1578 /* Set SRV_OPEN state - good or bad - depending on whether create succeed */
1579 RxTransitionSrvOpen(SrvOpen, (Status == STATUS_SUCCESS ? Condition_Good : Condition_Bad));
1580
1581 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1582
1583 RxCompleteSrvOpenKeyAssociation(SrvOpen);
1584
1585 if (Status == STATUS_SUCCESS)
1586 {
1587 if (BooleanFlagOn(Stack->Parameters.Create.Options, FILE_DELETE_ON_CLOSE))
1588 {
1589 ClearFlag(Fcb->FcbState, FCB_STATE_COLLAPSING_ENABLED);
1590 }
1591 SrvOpen->CreateOptions = RxContext->Create.NtCreateParameters.CreateOptions;
1592 FcbCondition = Condition_Good;
1593 }
1594 else
1595 {
1596 FcbCondition = Condition_Bad;
1597 RxDereferenceSrvOpen(SrvOpen, LHS_ExclusiveLockHeld);
1598 RxContext->pRelevantSrvOpen = NULL;
1599
1600 if (RxContext->pFobx != NULL)
1601 {
1602 RxDereferenceNetFobx(RxContext->pFobx, LHS_ExclusiveLockHeld);
1603 RxContext->pFobx = NULL;
1604 }
1605 }
1606 }
1607
1608 /* Set FCB state - good or bad - depending on whether create succeed */
1609 DPRINT("Transitioning FCB %p to condition %lx\n", Fcb, Fcb->Condition);
1610 RxTransitionNetFcb(Fcb, FcbCondition);
1611 }
1612 else if (Status == STATUS_SUCCESS)
1613 {
1614 BOOLEAN IsGood, ExtraOpen;
1615
1616 /* A reusable SRV_OPEN was found */
1617 RxContext->CurrentIrp->IoStatus.Information = FILE_OPENED;
1618 ExtraOpen = FALSE;
1619
1620 SrvOpen = (PSRV_OPEN)RxContext->pRelevantSrvOpen;
1621
1622 IsGood = (SrvOpen->Condition == Condition_Good);
1623 /* If the SRV_OPEN isn't in a stable situation, wait for it to become stable */
1624 if (!StableCondition(SrvOpen->Condition))
1625 {
1626 RxReferenceSrvOpen(SrvOpen);
1627 ++SrvOpen->OpenCount;
1628 ExtraOpen = TRUE;
1629
1630 RxReleaseFcb(RxContext, Fcb);
1631 RxContext->Create.FcbAcquired = FALSE;
1632
1633 RxWaitForStableSrvOpen(SrvOpen, RxContext);
1634
1635 if (NT_SUCCESS(RxAcquireExclusiveFcb(RxContext, Fcb)))
1636 {
1637 RxContext->Create.FcbAcquired = TRUE;
1638 }
1639
1640 IsGood = (SrvOpen->Condition == Condition_Good);
1641 }
1642
1643 /* Inform the mini-rdr we do an opening with a reused SRV_OPEN */
1644 if (IsGood)
1645 {
1646 MINIRDR_CALL(Status, RxContext, Fcb->MRxDispatch, MRxCollapseOpen, (RxContext));
1647
1648 ASSERT(RxIsFcbAcquiredExclusive(Fcb));
1649 }
1650 else
1651 {
1652 Status = SrvOpen->OpenStatus;
1653 }
1654
1655 if (ExtraOpen)
1656 {
1657 --SrvOpen->OpenCount;
1658 RxDereferenceSrvOpen(SrvOpen, LHS_ExclusiveLockHeld);
1659 }
1660 }
1661
1662 --Fcb->UncleanCount;
1663
1664 DPRINT("Status: %x\n", Status);
1665 return Status;
1666 }
1667
1668 NTSTATUS
1669 NTAPI
1670 RxCommonCleanup(
1671 PRX_CONTEXT Context)
1672 {
1673 #define BugCheckFileId RDBSS_BUG_CHECK_CLEANUP
1674 PFCB Fcb;
1675 PFOBX Fobx;
1676 ULONG OpenCount;
1677 NTSTATUS Status;
1678 PNET_ROOT NetRoot;
1679 PFILE_OBJECT FileObject;
1680 LARGE_INTEGER TruncateSize;
1681 PLARGE_INTEGER TruncateSizePtr;
1682 BOOLEAN NeedPurge, FcbTableAcquired, OneLeft, IsFile, FcbAcquired, LeftForDelete;
1683
1684 PAGED_CODE();
1685
1686 Fcb = (PFCB)Context->pFcb;
1687 Fobx = (PFOBX)Context->pFobx;
1688 DPRINT("RxCommonCleanup(%p); FOBX: %p, FCB: %p\n", Context, Fobx, Fcb);
1689
1690 /* File system closing, it's OK */
1691 if (Fobx == NULL)
1692 {
1693 if (Fcb->UncleanCount > 0)
1694 {
1695 InterlockedDecrement((volatile long *)&Fcb->UncleanCount);
1696 }
1697
1698 return STATUS_SUCCESS;
1699 }
1700
1701 /* Check we have a correct FCB type */
1702 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_FILE &&
1703 NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_DIRECTORY &&
1704 NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_UNKNOWN &&
1705 NodeType(Fcb) != RDBSS_NTC_SPOOLFILE)
1706 {
1707 DPRINT1("Invalid Fcb type for %p\n", Fcb);
1708 RxBugCheck(Fcb->Header.NodeTypeCode, 0, 0);
1709 }
1710
1711 FileObject = Context->CurrentIrpSp->FileObject;
1712 ASSERT(!BooleanFlagOn(FileObject->Flags, FO_CLEANUP_COMPLETE));
1713
1714 RxMarkFobxOnCleanup(Fobx, &NeedPurge);
1715
1716 Status = RxAcquireExclusiveFcb(Context, Fcb);
1717 if (!NT_SUCCESS(Status))
1718 {
1719 return Status;
1720 }
1721
1722 FcbAcquired = TRUE;
1723
1724 Fobx->AssociatedFileObject = NULL;
1725
1726 /* In case SRV_OPEN used is part of FCB */
1727 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_SRVOPEN_USED))
1728 {
1729 ASSERT(Fcb->UncleanCount != 0);
1730 InterlockedDecrement((volatile long *)&Fcb->UncleanCount);
1731
1732 if (BooleanFlagOn(FileObject->Flags, FO_NO_INTERMEDIATE_BUFFERING))
1733 {
1734 --Fcb->UncachedUncleanCount;
1735 }
1736
1737 /* Inform mini-rdr */
1738 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxCleanupFobx, (Context));
1739
1740 ASSERT(Fobx->SrvOpen->UncleanFobxCount != 0);
1741 --Fobx->SrvOpen->UncleanFobxCount;
1742
1743 RxUninitializeCacheMap(Context, FileObject, NULL);
1744
1745 RxReleaseFcb(Context, Fcb);
1746
1747 return STATUS_SUCCESS;
1748 }
1749
1750 /* Report the fact that file could be set as delete on close */
1751 if (BooleanFlagOn(Fobx->Flags, FOBX_FLAG_DELETE_ON_CLOSE))
1752 {
1753 SetFlag(Fcb->FcbState, FCB_STATE_DELETE_ON_CLOSE);
1754 }
1755
1756 /* Cancel any pending notification */
1757 RxCancelNotifyChangeDirectoryRequestsForFobx(Fobx);
1758
1759 /* Backup open count before we start playing with it */
1760 OpenCount = Fcb->ShareAccess.OpenCount;
1761
1762 NetRoot = (PNET_ROOT)Fcb->pNetRoot;
1763 FcbTableAcquired = FALSE;
1764 LeftForDelete = FALSE;
1765 OneLeft = (Fcb->UncleanCount == 1);
1766
1767 _SEH2_TRY
1768 {
1769 /* Unclean count and delete on close? Verify whether we're the one */
1770 if (OneLeft && BooleanFlagOn(Fcb->FcbState, FCB_STATE_DELETE_ON_CLOSE))
1771 {
1772 if (RxAcquireFcbTableLockExclusive(&NetRoot->FcbTable, FALSE))
1773 {
1774 FcbTableAcquired = TRUE;
1775 }
1776 else
1777 {
1778 RxReleaseFcb(Context, Fcb);
1779
1780 RxAcquireFcbTableLockExclusive(&NetRoot->FcbTable, TRUE);
1781
1782 Status = RxAcquireExclusiveFcb(Context, Fcb);
1783 if (Status != STATUS_SUCCESS)
1784 {
1785 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1786 return Status;
1787 }
1788
1789 FcbTableAcquired = TRUE;
1790 }
1791
1792 /* That means we'll perform the delete on close! */
1793 if (Fcb->UncleanCount == 1)
1794 {
1795 LeftForDelete = TRUE;
1796 }
1797 else
1798 {
1799 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1800 FcbTableAcquired = FALSE;
1801 }
1802 }
1803
1804 IsFile = FALSE;
1805 TruncateSizePtr = NULL;
1806 /* Handle cleanup for pipes and printers */
1807 if (NetRoot->Type == NET_ROOT_PIPE || NetRoot->Type == NET_ROOT_PRINT)
1808 {
1809 RxCleanupPipeQueues(Context);
1810 }
1811 /* Handle cleanup for files */
1812 else if (NetRoot->Type == NET_ROOT_DISK || NetRoot->Type == NET_ROOT_WILD)
1813 {
1814 Context->LowIoContext.Flags |= LOWIO_CONTEXT_FLAG_SAVEUNLOCKS;
1815 if (NodeType(Fcb) == RDBSS_NTC_STORAGE_TYPE_FILE)
1816 {
1817 /* First, unlock */
1818 FsRtlFastUnlockAll(&Fcb->Specific.Fcb.FileLock, FileObject, RxGetRequestorProcess(Context), Context);
1819
1820 /* If there are still locks to release, proceed */
1821 if (Context->LowIoContext.ParamsFor.Locks.LockList != NULL)
1822 {
1823 RxInitializeLowIoContext(&Context->LowIoContext, LOWIO_OP_UNLOCK_MULTIPLE);
1824 Context->LowIoContext.ParamsFor.Locks.Flags = 0;
1825 Status = RxLowIoLockControlShell(Context);
1826 }
1827
1828 /* Fix times and size */
1829 RxAdjustFileTimesAndSize(Context);
1830
1831 /* If we're the only one left... */
1832 if (OneLeft)
1833 {
1834 /* And if we're supposed to delete on close */
1835 if (LeftForDelete)
1836 {
1837 /* Update the sizes */
1838 RxAcquirePagingIoResource(Context, Fcb);
1839 Fcb->Header.FileSize.QuadPart = 0;
1840 Fcb->Header.ValidDataLength.QuadPart = 0;
1841 RxReleasePagingIoResource(Context, Fcb);
1842 }
1843 /* Otherwise, call the mini-rdr to adjust sizes */
1844 else
1845 {
1846 /* File got grown up, fill with zeroes */
1847 if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_PAGING_FILE) &&
1848 (Fcb->Header.ValidDataLength.QuadPart < Fcb->Header.FileSize.QuadPart))
1849 {
1850 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxZeroExtend, (Context));
1851 Fcb->Header.ValidDataLength.QuadPart = Fcb->Header.FileSize.QuadPart;
1852 }
1853
1854 /* File was truncated, let mini-rdr proceed */
1855 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_TRUNCATE_ON_CLOSE))
1856 {
1857 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxTruncate, (Context));
1858 ClearFlag(Fcb->FcbState, FCB_STATE_TRUNCATE_ON_CLOSE);
1859
1860 /* Keep track of file change for Cc uninit */
1861 TruncateSize.QuadPart = Fcb->Header.FileSize.QuadPart;
1862 TruncateSizePtr = &TruncateSize;
1863 }
1864 }
1865 }
1866
1867 /* If RxMarkFobxOnCleanup() asked for purge, make sure we're the only one left first */
1868 if (NeedPurge)
1869 {
1870 if (!OneLeft)
1871 {
1872 NeedPurge = FALSE;
1873 }
1874 }
1875 /* Otherwise, try to see whether we can purge */
1876 else
1877 {
1878 NeedPurge = (OneLeft && (LeftForDelete || !BooleanFlagOn(Fcb->FcbState, FCB_STATE_COLLAPSING_ENABLED)));
1879 }
1880
1881 IsFile = TRUE;
1882 }
1883 }
1884
1885 /* We have to still be there! */
1886 ASSERT(Fcb->UncleanCount != 0);
1887 InterlockedDecrement((volatile long *)&Fcb->UncleanCount);
1888
1889 if (BooleanFlagOn(FileObject->Flags, FO_NO_INTERMEDIATE_BUFFERING))
1890 {
1891 --Fcb->UncachedUncleanCount;
1892 }
1893
1894 /* Inform mini-rdr about ongoing cleanup */
1895 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxCleanupFobx, (Context));
1896
1897 ASSERT(Fobx->SrvOpen->UncleanFobxCount != 0);
1898 --Fobx->SrvOpen->UncleanFobxCount;
1899
1900 /* Flush cache */
1901 if (DisableFlushOnCleanup)
1902 {
1903 /* Only if we're the last standing */
1904 if (Fcb->NonPaged->SectionObjectPointers.DataSectionObject != NULL &&
1905 Fcb->UncleanCount == Fcb->UncachedUncleanCount)
1906 {
1907 DPRINT("Flushing %p due to last cached handle cleanup\n", Context);
1908 RxFlushFcbInSystemCache(Fcb, TRUE);
1909 }
1910 }
1911 else
1912 {
1913 /* Always */
1914 if (Fcb->NonPaged->SectionObjectPointers.DataSectionObject != NULL)
1915 {
1916 DPRINT("Flushing %p on cleanup\n", Context);
1917 RxFlushFcbInSystemCache(Fcb, TRUE);
1918 }
1919 }
1920
1921 /* If only remaining uncached & unclean, then flush and purge */
1922 if (!BooleanFlagOn(FileObject->Flags, FO_NO_INTERMEDIATE_BUFFERING))
1923 {
1924 if (Fcb->UncachedUncleanCount != 0)
1925 {
1926 if (Fcb->UncachedUncleanCount == Fcb->UncleanCount &&
1927 Fcb->NonPaged->SectionObjectPointers.DataSectionObject != NULL)
1928 {
1929 DPRINT("Flushing FCB in system cache for %p\n", Context);
1930 RxPurgeFcbInSystemCache(Fcb, NULL, 0, FALSE, TRUE);
1931 }
1932 }
1933 }
1934
1935 /* If purge required, and not about to delete, flush */
1936 if (!LeftForDelete && NeedPurge)
1937 {
1938 DPRINT("Flushing FCB in system cache for %p\n", Context);
1939 RxFlushFcbInSystemCache(Fcb, TRUE);
1940 }
1941
1942 /* If it was a file, drop cache */
1943 if (IsFile)
1944 {
1945 DPRINT("Uninit cache map for file\n");
1946 RxUninitializeCacheMap(Context, FileObject, TruncateSizePtr);
1947 }
1948
1949 /* If that's the one left for deletion, or if it needs purge, flush */
1950 if (LeftForDelete || NeedPurge)
1951 {
1952 RxPurgeFcbInSystemCache(Fcb, NULL, 0, FALSE, !LeftForDelete);
1953 /* If that's for deletion, also remove from FCB table */
1954 if (LeftForDelete)
1955 {
1956 RxRemoveNameNetFcb(Fcb);
1957 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1958 FcbTableAcquired = FALSE;
1959 }
1960 }
1961
1962 /* Remove any share access */
1963 if (OpenCount != 0 && NetRoot->Type == NET_ROOT_DISK)
1964 {
1965 RxRemoveShareAccess(FileObject, &Fcb->ShareAccess, "Cleanup the share access", "ClnUpShr");
1966 }
1967
1968 /* In case there's caching, on a file, update file metadata */
1969 if (NodeType(Fcb) == RDBSS_NTC_STORAGE_TYPE_FILE && BooleanFlagOn(Fobx->Flags, 0x20000000) &&
1970 BooleanFlagOn(Fcb->FcbState, FCB_STATE_WRITECACHING_ENABLED) && !BooleanFlagOn(Fobx->pSrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_WRITE_CACHING))
1971 {
1972 UNIMPLEMENTED;
1973 }
1974
1975 /* We're clean! */
1976 SetFlag(FileObject->Flags, FO_CLEANUP_COMPLETE);
1977
1978 FcbAcquired = FALSE;
1979 RxReleaseFcb(Context, Fcb);
1980 }
1981 _SEH2_FINALLY
1982 {
1983 if (FcbAcquired)
1984 {
1985 RxReleaseFcb(Context, Fcb);
1986 }
1987
1988 if (FcbTableAcquired)
1989 {
1990 RxReleaseFcbTableLock(&NetRoot->FcbTable);
1991 }
1992 }
1993 _SEH2_END;
1994
1995 return Status;
1996 #undef BugCheckFileId
1997 }
1998
1999 NTSTATUS
2000 NTAPI
2001 RxCommonClose(
2002 PRX_CONTEXT Context)
2003 {
2004 #define BugCheckFileId RDBSS_BUG_CHECK_CLOSE
2005 PFCB Fcb;
2006 PFOBX Fobx;
2007 NTSTATUS Status;
2008 PFILE_OBJECT FileObject;
2009 BOOLEAN DereferenceFobx, AcquiredFcb;
2010
2011 PAGED_CODE();
2012
2013 Fcb = (PFCB)Context->pFcb;
2014 Fobx = (PFOBX)Context->pFobx;
2015 FileObject = Context->CurrentIrpSp->FileObject;
2016 DPRINT("RxCommonClose(%p); FOBX: %p, FCB: %p, FO: %p\n", Context, Fobx, Fcb, FileObject);
2017
2018 Status = RxAcquireExclusiveFcb(Context, Fcb);
2019 if (!NT_SUCCESS(Status))
2020 {
2021 return Status;
2022 }
2023
2024 AcquiredFcb = TRUE;
2025 _SEH2_TRY
2026 {
2027 BOOLEAN Freed;
2028
2029 /* Check our FCB type is expected */
2030 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_UNKNOWN &&
2031 (NodeType(Fcb) < RDBSS_NTC_STORAGE_TYPE_DIRECTORY || (NodeType(Fcb) > RDBSS_NTC_STORAGE_TYPE_FILE &&
2032 (NodeType(Fcb) < RDBSS_NTC_SPOOLFILE || NodeType(Fcb) > RDBSS_NTC_OPENTARGETDIR_FCB))))
2033 {
2034 RxBugCheck(NodeType(Fcb), 0, 0);
2035 }
2036
2037 RxReferenceNetFcb(Fcb);
2038
2039 DereferenceFobx = FALSE;
2040 /* If we're not closing FS */
2041 if (Fobx != NULL)
2042 {
2043 PSRV_OPEN SrvOpen;
2044 PSRV_CALL SrvCall;
2045
2046 SrvOpen = (PSRV_OPEN)Fobx->pSrvOpen;
2047 SrvCall = (PSRV_CALL)Fcb->pNetRoot->pSrvCall;
2048 /* Handle delayed close */
2049 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_DIRECTORY)
2050 {
2051 if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_DELETE_ON_CLOSE | FCB_STATE_ORPHANED))
2052 {
2053 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_COLLAPSING_ENABLED))
2054 {
2055 DPRINT("Delay close for FOBX: %p, SrvOpen %p\n", Fobx, SrvOpen);
2056
2057 if (SrvOpen->OpenCount == 1 && !BooleanFlagOn(SrvOpen->Flags, SRVOPEN_FLAG_COLLAPSING_DISABLED))
2058 {
2059 if (InterlockedIncrement(&SrvCall->NumberOfCloseDelayedFiles) >= SrvCall->MaximumNumberOfCloseDelayedFiles)
2060 {
2061 InterlockedDecrement(&SrvCall->NumberOfCloseDelayedFiles);
2062 }
2063 else
2064 {
2065 DereferenceFobx = TRUE;
2066 SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_CLOSE_DELAYED);
2067 }
2068 }
2069 }
2070 }
2071 }
2072
2073 /* If we reach maximum of delayed close/or if there are no delayed close */
2074 if (!DereferenceFobx)
2075 {
2076 PNET_ROOT NetRoot;
2077
2078 NetRoot = (PNET_ROOT)Fcb->pNetRoot;
2079 if (NetRoot->Type != NET_ROOT_PRINT)
2080 {
2081 /* Delete if asked */
2082 if (BooleanFlagOn(Fobx->Flags, FOBX_FLAG_DELETE_ON_CLOSE))
2083 {
2084 RxScavengeRelatedFobxs(Fcb);
2085 RxSynchronizeWithScavenger(Context);
2086
2087 RxReleaseFcb(Context, Fcb);
2088
2089 RxAcquireFcbTableLockExclusive(&NetRoot->FcbTable, TRUE);
2090 RxOrphanThisFcb(Fcb);
2091 RxReleaseFcbTableLock(&NetRoot->FcbTable);
2092
2093 Status = RxAcquireExclusiveFcb(Context, Fcb);
2094 ASSERT(NT_SUCCESS(Status));
2095 }
2096 }
2097 }
2098
2099 RxMarkFobxOnClose(Fobx);
2100 }
2101
2102 if (DereferenceFobx)
2103 {
2104 ASSERT(Fobx != NULL);
2105 RxDereferenceNetFobx(Fobx, LHS_SharedLockHeld);
2106 }
2107 else
2108 {
2109 RxCloseAssociatedSrvOpen(Fobx, Context);
2110 if (Fobx != NULL)
2111 {
2112 RxDereferenceNetFobx(Fobx, LHS_ExclusiveLockHeld);
2113 }
2114 }
2115
2116 Freed = RxDereferenceAndFinalizeNetFcb(Fcb, Context, FALSE, FALSE);
2117 AcquiredFcb = !Freed;
2118
2119 FileObject->FsContext = (PVOID)-1;
2120
2121 if (Freed)
2122 {
2123 RxTrackerUpdateHistory(Context, NULL, TRACKER_FCB_FREE, __LINE__, __FILE__, 0);
2124 }
2125 else
2126 {
2127 RxReleaseFcb(Context, Fcb);
2128 AcquiredFcb = FALSE;
2129 }
2130 }
2131 _SEH2_FINALLY
2132 {
2133 if (_SEH2_AbnormalTermination())
2134 {
2135 if (AcquiredFcb)
2136 {
2137 RxReleaseFcb(Context, Fcb);
2138 }
2139 }
2140 else
2141 {
2142 ASSERT(!AcquiredFcb);
2143 }
2144 }
2145 _SEH2_END;
2146
2147 DPRINT("Status: %x\n", Status);
2148 return Status;
2149 #undef BugCheckFileId
2150 }
2151
2152 NTSTATUS
2153 NTAPI
2154 RxCommonCreate(
2155 PRX_CONTEXT Context)
2156 {
2157 PIRP Irp;
2158 NTSTATUS Status;
2159 PFILE_OBJECT FileObject;
2160 PIO_STACK_LOCATION Stack;
2161
2162 PAGED_CODE();
2163
2164 DPRINT("RxCommonCreate(%p)\n", Context);
2165
2166 Irp = Context->CurrentIrp;
2167 Stack = Context->CurrentIrpSp;
2168 FileObject = Stack->FileObject;
2169
2170 /* Check whether that's a device opening */
2171 if (FileObject->FileName.Length == 0 && FileObject->RelatedFileObject == NULL)
2172 {
2173 FileObject->FsContext = &RxDeviceFCB;
2174 FileObject->FsContext2 = NULL;
2175
2176 ++RxDeviceFCB.NodeReferenceCount;
2177 ++RxDeviceFCB.OpenCount;
2178
2179 Irp->IoStatus.Information = FILE_OPENED;
2180 DPRINT("Device opening FO: %p, DO: %p, Name: %wZ\n", FileObject, Context->RxDeviceObject, &Context->RxDeviceObject->DeviceName);
2181
2182 Status = STATUS_SUCCESS;
2183 }
2184 else
2185 {
2186 PFCB RelatedFcb = NULL;
2187
2188 /* Make sure caller is consistent */
2189 if (FlagOn(Stack->Parameters.Create.Options, FILE_DIRECTORY_FILE | FILE_NON_DIRECTORY_FILE | FILE_OPEN_REMOTE_INSTANCE) ==
2190 (FILE_DIRECTORY_FILE | FILE_NON_DIRECTORY_FILE | FILE_OPEN_REMOTE_INSTANCE))
2191 {
2192 DPRINT1("Create.Options: %x\n", Stack->Parameters.Create.Options);
2193 return STATUS_INVALID_PARAMETER;
2194 }
2195
2196 DPRINT("Ctxt: %p, FO: %p, Options: %lx, Flags: %lx, Attr: %lx, ShareAccess: %lx, DesiredAccess: %lx\n",
2197 Context, FileObject, Stack->Parameters.Create.Options, Stack->Flags, Stack->Parameters.Create.FileAttributes,
2198 Stack->Parameters.Create.ShareAccess, Stack->Parameters.Create.SecurityContext->DesiredAccess);
2199 DPRINT("FileName: %wZ\n", &FileObject->FileName);
2200
2201 if (FileObject->RelatedFileObject != NULL)
2202 {
2203 RelatedFcb = FileObject->RelatedFileObject->FsContext;
2204 DPRINT("Rel FO: %p, path: %wZ\n", FileObject->RelatedFileObject, RelatedFcb->FcbTableEntry.Path);
2205 }
2206
2207 /* Going to rename? */
2208 if (BooleanFlagOn(Stack->Flags, SL_OPEN_TARGET_DIRECTORY))
2209 {
2210 DPRINT("TargetDir!\n");
2211 }
2212
2213 /* Copy create parameters to the context */
2214 RxCopyCreateParameters(Context);
2215
2216 /* If the caller wants to establish a connection, go ahead */
2217 if (BooleanFlagOn(Stack->Parameters.Create.Options, FILE_CREATE_TREE_CONNECTION))
2218 {
2219 Status = RxCreateTreeConnect(Context);
2220 }
2221 else
2222 {
2223 /* Validate file name */
2224 if (FileObject->FileName.Length > sizeof(WCHAR) &&
2225 FileObject->FileName.Buffer[1] == OBJ_NAME_PATH_SEPARATOR &&
2226 FileObject->FileName.Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
2227 {
2228 FileObject->FileName.Length -= sizeof(WCHAR);
2229 RtlMoveMemory(&FileObject->FileName.Buffer[0], &FileObject->FileName.Buffer[1],
2230 FileObject->FileName.Length);
2231
2232 if (FileObject->FileName.Length > sizeof(WCHAR) &&
2233 FileObject->FileName.Buffer[1] == OBJ_NAME_PATH_SEPARATOR &&
2234 FileObject->FileName.Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
2235 {
2236 return STATUS_OBJECT_NAME_INVALID;
2237 }
2238 }
2239
2240 /* Attempt to open the file */
2241 do
2242 {
2243 UNICODE_STRING NetRootName;
2244
2245 /* Strip last \ if required */
2246 if (FileObject->FileName.Length != 0 &&
2247 FileObject->FileName.Buffer[FileObject->FileName.Length / sizeof(WCHAR) - 1] == OBJ_NAME_PATH_SEPARATOR)
2248 {
2249 if (BooleanFlagOn(Stack->Parameters.Create.Options, FILE_NON_DIRECTORY_FILE))
2250 {
2251 return STATUS_OBJECT_NAME_INVALID;
2252 }
2253
2254 FileObject->FileName.Length -= sizeof(WCHAR);
2255 Context->Create.Flags |= RX_CONTEXT_CREATE_FLAG_STRIPPED_TRAILING_BACKSLASH;
2256 }
2257
2258 if (BooleanFlagOn(Context->Flags, RX_CONTEXT_FLAG_WRITE_THROUGH))
2259 {
2260 FileObject->Flags |= FO_WRITE_THROUGH;
2261 }
2262
2263 /* Get the associated net root to opening */
2264 Status = RxCanonicalizeNameAndObtainNetRoot(Context, &FileObject->FileName, &NetRootName);
2265 if (Status != STATUS_MORE_PROCESSING_REQUIRED)
2266 {
2267 break;
2268 }
2269
2270 /* And attempt to open */
2271 Status = RxCreateFromNetRoot(Context, &NetRootName);
2272 if (Status == STATUS_SHARING_VIOLATION)
2273 {
2274 UNIMPLEMENTED;
2275 }
2276 else if (Status == STATUS_REPARSE)
2277 {
2278 Context->CurrentIrp->IoStatus.Information = 0;
2279 }
2280 else
2281 {
2282 ASSERT(!BooleanFlagOn(Context->Create.Flags, RX_CONTEXT_CREATE_FLAG_REPARSE));
2283 }
2284 }
2285 while (Status == STATUS_MORE_PROCESSING_REQUIRED);
2286 }
2287
2288 if (Status == STATUS_RETRY)
2289 {
2290 RxpPrepareCreateContextForReuse(Context);
2291 }
2292 ASSERT(Status != STATUS_PENDING);
2293 }
2294
2295 DPRINT("Status: %lx\n", Status);
2296 return Status;
2297 }
2298
2299 /*
2300 * @implemented
2301 */
2302 NTSTATUS
2303 NTAPI
2304 RxCommonDevFCBCleanup(
2305 PRX_CONTEXT Context)
2306 {
2307 PMRX_FCB Fcb;
2308 NTSTATUS Status;
2309
2310 PAGED_CODE();
2311
2312 DPRINT("RxCommonDevFCBCleanup(%p)\n", Context);
2313
2314 Fcb = Context->pFcb;
2315 Status = STATUS_SUCCESS;
2316 ASSERT(NodeType(Fcb) == RDBSS_NTC_DEVICE_FCB);
2317
2318 /* Our FOBX if set, has to be a VNetRoot */
2319 if (Context->pFobx != NULL)
2320 {
2321 RxAcquirePrefixTableLockShared(Context->RxDeviceObject->pRxNetNameTable, TRUE);
2322 if (Context->pFobx->NodeTypeCode != RDBSS_NTC_V_NETROOT)
2323 {
2324 Status = STATUS_INVALID_DEVICE_REQUEST;
2325 }
2326 RxReleasePrefixTableLock(Context->RxDeviceObject->pRxNetNameTable);
2327 }
2328 else
2329 {
2330 --Fcb->UncleanCount;
2331 }
2332
2333 return Status;
2334 }
2335
2336 /*
2337 * @implemented
2338 */
2339 NTSTATUS
2340 NTAPI
2341 RxCommonDevFCBClose(
2342 PRX_CONTEXT Context)
2343 {
2344 PMRX_FCB Fcb;
2345 NTSTATUS Status;
2346 PMRX_V_NET_ROOT NetRoot;
2347
2348 PAGED_CODE();
2349
2350 DPRINT("RxCommonDevFCBClose(%p)\n", Context);
2351
2352 Fcb = Context->pFcb;
2353 NetRoot = (PMRX_V_NET_ROOT)Context->pFobx;
2354 Status = STATUS_SUCCESS;
2355 ASSERT(NodeType(Fcb) == RDBSS_NTC_DEVICE_FCB);
2356
2357 /* Our FOBX if set, has to be a VNetRoot */
2358 if (NetRoot != NULL)
2359 {
2360 RxAcquirePrefixTableLockExclusive(Context->RxDeviceObject->pRxNetNameTable, TRUE);
2361 if (NetRoot->NodeTypeCode == RDBSS_NTC_V_NETROOT)
2362 {
2363 --NetRoot->NumberOfOpens;
2364 RxDereferenceVNetRoot(NetRoot, LHS_ExclusiveLockHeld);
2365 }
2366 else
2367 {
2368 Status = STATUS_NOT_IMPLEMENTED;
2369 }
2370 RxReleasePrefixTableLock(Context->RxDeviceObject->pRxNetNameTable);
2371 }
2372 else
2373 {
2374 --Fcb->OpenCount;
2375 }
2376
2377 return Status;
2378 }
2379
2380 NTSTATUS
2381 NTAPI
2382 RxCommonDevFCBFsCtl(
2383 PRX_CONTEXT Context)
2384 {
2385 UNIMPLEMENTED;
2386 return STATUS_NOT_IMPLEMENTED;
2387 }
2388
2389 /*
2390 * @implemented
2391 */
2392 NTSTATUS
2393 NTAPI
2394 RxCommonDevFCBIoCtl(
2395 PRX_CONTEXT Context)
2396 {
2397 NTSTATUS Status;
2398
2399 PAGED_CODE();
2400
2401 DPRINT("RxCommonDevFCBIoCtl(%p)\n", Context);
2402
2403 if (Context->pFobx != NULL)
2404 {
2405 return STATUS_INVALID_HANDLE;
2406 }
2407
2408 /* Is that a prefix claim from MUP? */
2409 if (Context->CurrentIrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_REDIR_QUERY_PATH)
2410 {
2411 return RxPrefixClaim(Context);
2412 }
2413
2414 /* Otherwise, pass through the mini-rdr */
2415 Status = RxXXXControlFileCallthru(Context);
2416 if (Status != STATUS_PENDING)
2417 {
2418 if (Context->PostRequest)
2419 {
2420 Context->ResumeRoutine = RxCommonDevFCBIoCtl;
2421 Status = RxFsdPostRequest(Context);
2422 }
2423 }
2424
2425 DPRINT("Status: %lx\n", Status);
2426 return Status;
2427 }
2428
2429 NTSTATUS
2430 NTAPI
2431 RxCommonDevFCBQueryVolInfo(
2432 PRX_CONTEXT Context)
2433 {
2434 UNIMPLEMENTED;
2435 return STATUS_NOT_IMPLEMENTED;
2436 }
2437
2438 /*
2439 * @implemented
2440 */
2441 NTSTATUS
2442 NTAPI
2443 RxCommonDeviceControl(
2444 PRX_CONTEXT Context)
2445 {
2446 NTSTATUS Status;
2447
2448 PAGED_CODE();
2449
2450 /* Prefix claim is only allowed for device, not files */
2451 if (Context->CurrentIrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_REDIR_QUERY_PATH)
2452 {
2453 return STATUS_INVALID_DEVICE_REQUEST;
2454 }
2455
2456 /* Submit to mini-rdr */
2457 RxInitializeLowIoContext(&Context->LowIoContext, LOWIO_OP_IOCTL);
2458 Status = RxLowIoSubmit(Context, RxLowIoIoCtlShellCompletion);
2459 if (Status == STATUS_PENDING)
2460 {
2461 RxDereferenceAndDeleteRxContext_Real(Context);
2462 }
2463
2464 return Status;
2465 }
2466
2467 /*
2468 * @implemented
2469 */
2470 NTSTATUS
2471 NTAPI
2472 RxCommonDirectoryControl(
2473 PRX_CONTEXT Context)
2474 {
2475 PFCB Fcb;
2476 PFOBX Fobx;
2477 NTSTATUS Status;
2478 PIO_STACK_LOCATION Stack;
2479
2480 PAGED_CODE();
2481
2482 Fcb = (PFCB)Context->pFcb;
2483 Fobx = (PFOBX)Context->pFobx;
2484 Stack = Context->CurrentIrpSp;
2485 DPRINT("RxCommonDirectoryControl(%p) FOBX: %p, FCB: %p, Minor: %d\n", Context, Fobx, Fcb, Stack->MinorFunction);
2486
2487 /* Call the appropriate helper */
2488 if (Stack->MinorFunction == IRP_MN_QUERY_DIRECTORY)
2489 {
2490 Status = RxQueryDirectory(Context);
2491 }
2492 else if (Stack->MinorFunction == IRP_MN_NOTIFY_CHANGE_DIRECTORY)
2493 {
2494 Status = RxNotifyChangeDirectory(Context);
2495 if (Status == STATUS_PENDING)
2496 {
2497 RxDereferenceAndDeleteRxContext_Real(Context);
2498 }
2499 }
2500 else
2501 {
2502 Status = STATUS_INVALID_DEVICE_REQUEST;
2503 }
2504
2505 return Status;
2506 }
2507
2508 NTSTATUS
2509 NTAPI
2510 RxCommonDispatchProblem(
2511 PRX_CONTEXT Context)
2512 {
2513 UNIMPLEMENTED;
2514 return STATUS_NOT_IMPLEMENTED;
2515 }
2516
2517 NTSTATUS
2518 NTAPI
2519 RxCommonFileSystemControl(
2520 PRX_CONTEXT Context)
2521 {
2522 UNIMPLEMENTED;
2523 return STATUS_NOT_IMPLEMENTED;
2524 }
2525
2526 NTSTATUS
2527 NTAPI
2528 RxCommonFlushBuffers(
2529 PRX_CONTEXT Context)
2530 {
2531 UNIMPLEMENTED;
2532 return STATUS_NOT_IMPLEMENTED;
2533 }
2534
2535 NTSTATUS
2536 NTAPI
2537 RxCommonLockControl(
2538 PRX_CONTEXT Context)
2539 {
2540 UNIMPLEMENTED;
2541 return STATUS_NOT_IMPLEMENTED;
2542 }
2543
2544 NTSTATUS
2545 NTAPI
2546 RxCommonQueryEa(
2547 PRX_CONTEXT Context)
2548 {
2549 UNIMPLEMENTED;
2550 return STATUS_NOT_IMPLEMENTED;
2551 }
2552
2553 /*
2554 * @implemented
2555 */
2556 NTSTATUS
2557 NTAPI
2558 RxCommonQueryInformation(
2559 PRX_CONTEXT Context)
2560 {
2561 #define SET_SIZE_AND_QUERY(AlreadyConsummed, Function) \
2562 Context->Info.Length = Stack->Parameters.QueryFile.Length - (AlreadyConsummed); \
2563 Status = Function(Context, Add2Ptr(Buffer, AlreadyConsummed))
2564
2565 PFCB Fcb;
2566 PIRP Irp;
2567 PFOBX Fobx;
2568 BOOLEAN Locked;
2569 NTSTATUS Status;
2570 PIO_STACK_LOCATION Stack;
2571 FILE_INFORMATION_CLASS FileInfoClass;
2572
2573 PAGED_CODE();
2574
2575 Fcb = (PFCB)Context->pFcb;
2576 Fobx = (PFOBX)Context->pFobx;
2577 DPRINT("RxCommonQueryInformation(%p) FCB: %p, FOBX: %p\n", Context, Fcb, Fobx);
2578
2579 Irp = Context->CurrentIrp;
2580 Stack = Context->CurrentIrpSp;
2581 DPRINT("Buffer: %p, Length: %lx, Class: %ld\n", Irp->AssociatedIrp.SystemBuffer,
2582 Stack->Parameters.QueryFile.Length, Stack->Parameters.QueryFile.FileInformationClass);
2583
2584 Context->Info.Length = Stack->Parameters.QueryFile.Length;
2585 FileInfoClass = Stack->Parameters.QueryFile.FileInformationClass;
2586
2587 Locked = FALSE;
2588 _SEH2_TRY
2589 {
2590 PVOID Buffer;
2591
2592 /* Get a writable buffer */
2593 Buffer = RxMapSystemBuffer(Context);
2594 if (Buffer == NULL)
2595 {
2596 Status = STATUS_INSUFFICIENT_RESOURCES;
2597 _SEH2_LEAVE;
2598 }
2599 /* Zero it */
2600 RtlZeroMemory(Buffer, Context->Info.Length);
2601
2602 /* Validate file type */
2603 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_UNKNOWN)
2604 {
2605 if (NodeType(Fcb) < RDBSS_NTC_STORAGE_TYPE_DIRECTORY)
2606 {
2607 Status = STATUS_INVALID_PARAMETER;
2608 _SEH2_LEAVE;
2609 }
2610 else if (NodeType(Fcb) > RDBSS_NTC_STORAGE_TYPE_FILE)
2611 {
2612 if (NodeType(Fcb) == RDBSS_NTC_MAILSLOT)
2613 {
2614 Status = STATUS_NOT_IMPLEMENTED;
2615 }
2616 else
2617 {
2618 Status = STATUS_INVALID_PARAMETER;
2619 }
2620
2621 _SEH2_LEAVE;
2622 }
2623 }
2624
2625 /* Acquire the right lock */
2626 if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_PAGING_FILE) &&
2627 FileInfoClass != FileNameInformation)
2628 {
2629 if (FileInfoClass == FileCompressionInformation)
2630 {
2631 Status = RxAcquireExclusiveFcb(Context, Fcb);
2632 }
2633 else
2634 {
2635 Status = RxAcquireSharedFcb(Context, Fcb);
2636 }
2637
2638 if (Status == STATUS_LOCK_NOT_GRANTED)
2639 {
2640 Status = STATUS_PENDING;
2641 _SEH2_LEAVE;
2642 }
2643 else if (!NT_SUCCESS(Status))
2644 {
2645 _SEH2_LEAVE;
2646 }
2647
2648 Locked = TRUE;
2649 }
2650
2651 /* Dispatch to the right helper */
2652 switch (FileInfoClass)
2653 {
2654 case FileBasicInformation:
2655 Status = RxQueryBasicInfo(Context, Buffer);
2656 break;
2657
2658 case FileStandardInformation:
2659 Status = RxQueryStandardInfo(Context, Buffer);
2660 break;
2661
2662 case FileInternalInformation:
2663 Status = RxQueryInternalInfo(Context, Buffer);
2664 break;
2665
2666 case FileEaInformation:
2667 Status = RxQueryEaInfo(Context, Buffer);
2668 break;
2669
2670 case FileNameInformation:
2671 Status = RxQueryNameInfo(Context, Buffer);
2672 break;
2673
2674 case FileAllInformation:
2675 SET_SIZE_AND_QUERY(0, RxQueryBasicInfo);
2676 if (!NT_SUCCESS(Status))
2677 {
2678 break;
2679 }
2680
2681 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION), RxQueryStandardInfo);
2682 if (!NT_SUCCESS(Status))
2683 {
2684 break;
2685 }
2686
2687 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2688 sizeof(FILE_STANDARD_INFORMATION), RxQueryInternalInfo);
2689 if (!NT_SUCCESS(Status))
2690 {
2691 break;
2692 }
2693
2694 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2695 sizeof(FILE_STANDARD_INFORMATION) +
2696 sizeof(FILE_INTERNAL_INFORMATION), RxQueryEaInfo);
2697 if (!NT_SUCCESS(Status))
2698 {
2699 break;
2700 }
2701
2702 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2703 sizeof(FILE_STANDARD_INFORMATION) +
2704 sizeof(FILE_INTERNAL_INFORMATION) +
2705 sizeof(FILE_EA_INFORMATION), RxQueryPositionInfo);
2706 if (!NT_SUCCESS(Status))
2707 {
2708 break;
2709 }
2710
2711 SET_SIZE_AND_QUERY(sizeof(FILE_BASIC_INFORMATION) +
2712 sizeof(FILE_STANDARD_INFORMATION) +
2713 sizeof(FILE_INTERNAL_INFORMATION) +
2714 sizeof(FILE_EA_INFORMATION) +
2715 sizeof(FILE_POSITION_INFORMATION), RxQueryNameInfo);
2716 break;
2717
2718 case FileAlternateNameInformation:
2719 Status = RxQueryAlternateNameInfo(Context, Buffer);
2720 break;
2721
2722 case FilePipeInformation:
2723 case FilePipeLocalInformation:
2724 case FilePipeRemoteInformation:
2725 Status = RxQueryPipeInfo(Context, Buffer);
2726 break;
2727
2728 case FileCompressionInformation:
2729 Status = RxQueryCompressedInfo(Context, Buffer);
2730 break;
2731
2732 default:
2733 Context->IoStatusBlock.Status = RxpQueryInfoMiniRdr(Context, FileInfoClass, Buffer);
2734 Status = Context->IoStatusBlock.Status;
2735 break;
2736 }
2737
2738 if (Context->Info.Length < 0)
2739 {
2740 Status = STATUS_BUFFER_OVERFLOW;
2741 Context->Info.Length = Stack->Parameters.QueryFile.Length;
2742 }
2743
2744 Irp->IoStatus.Information = Stack->Parameters.QueryFile.Length - Context->Info.Length;
2745 }
2746 _SEH2_FINALLY
2747 {
2748 if (Locked)
2749 {
2750 RxReleaseFcb(Context, Fcb);
2751 }
2752 }
2753 _SEH2_END;
2754
2755 DPRINT("Status: %x\n", Status);
2756 return Status;
2757
2758 #undef SET_SIZE_AND_QUERY
2759 }
2760
2761 NTSTATUS
2762 NTAPI
2763 RxCommonQueryQuotaInformation(
2764 PRX_CONTEXT Context)
2765 {
2766 UNIMPLEMENTED;
2767 return STATUS_NOT_IMPLEMENTED;
2768 }
2769
2770 NTSTATUS
2771 NTAPI
2772 RxCommonQuerySecurity(
2773 PRX_CONTEXT Context)
2774 {
2775 UNIMPLEMENTED;
2776 return STATUS_NOT_IMPLEMENTED;
2777 }
2778
2779 /*
2780 * @implemented
2781 */
2782 NTSTATUS
2783 NTAPI
2784 RxCommonQueryVolumeInformation(
2785 PRX_CONTEXT Context)
2786 {
2787 PIRP Irp;
2788 PFCB Fcb;
2789 PFOBX Fobx;
2790 NTSTATUS Status;
2791 PIO_STACK_LOCATION Stack;
2792
2793 PAGED_CODE();
2794
2795 Fcb = (PFCB)Context->pFcb;
2796 Fobx = (PFOBX)Context->pFobx;
2797
2798 DPRINT("RxCommonQueryVolumeInformation(%p) FCB: %p, FOBX: %p\n", Context, Fcb, Fobx);
2799
2800 Irp = Context->CurrentIrp;
2801 Stack = Context->CurrentIrpSp;
2802 DPRINT("Length: %lx, Class: %lx, Buffer %p\n", Stack->Parameters.QueryVolume.Length,
2803 Stack->Parameters.QueryVolume.FsInformationClass, Irp->AssociatedIrp.SystemBuffer);
2804
2805 Context->Info.FsInformationClass = Stack->Parameters.QueryVolume.FsInformationClass;
2806 Context->Info.Buffer = Irp->AssociatedIrp.SystemBuffer;
2807 Context->Info.Length = Stack->Parameters.QueryVolume.Length;
2808
2809 /* Forward to mini-rdr */
2810 MINIRDR_CALL(Status, Context, Fcb->MRxDispatch, MRxQueryVolumeInfo, (Context));
2811
2812 /* Post request if mini-rdr asked to */
2813 if (Context->PostRequest)
2814 {
2815 Status = RxFsdPostRequest(Context);
2816 }
2817 else
2818 {
2819 Irp->IoStatus.Information = Stack->Parameters.QueryVolume.Length - Context->Info.Length;
2820 }
2821
2822 DPRINT("Status: %x\n", Status);
2823 return Status;
2824 }
2825
2826 NTSTATUS
2827 NTAPI
2828 RxCommonRead(
2829 PRX_CONTEXT RxContext)
2830 {
2831 PFCB Fcb;
2832 PIRP Irp;
2833 PFOBX Fobx;
2834 NTSTATUS Status;
2835 PNET_ROOT NetRoot;
2836 PVOID SystemBuffer;
2837 PFILE_OBJECT FileObject;
2838 LARGE_INTEGER ByteOffset;
2839 PIO_STACK_LOCATION Stack;
2840 PLOWIO_CONTEXT LowIoContext;
2841 PRDBSS_DEVICE_OBJECT RxDeviceObject;
2842 ULONG ReadLength, CapturedRxContextSerialNumber = RxContext->SerialNumber;
2843 BOOLEAN CanWait, PagingIo, NoCache, Sync, PostRequest, IsPipe, ReadCachingEnabled, ReadCachingDisabled, InFsp, OwnerSet;
2844
2845 PAGED_CODE();
2846
2847 Fcb = (PFCB)RxContext->pFcb;
2848 Fobx = (PFOBX)RxContext->pFobx;
2849 DPRINT("RxCommonRead(%p) FOBX: %p, FCB: %p\n", RxContext, Fobx, Fcb);
2850
2851 /* Get some parameters */
2852 Irp = RxContext->CurrentIrp;
2853 Stack = RxContext->CurrentIrpSp;
2854 CanWait = BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_WAIT);
2855 PagingIo = BooleanFlagOn(Irp->Flags, IRP_PAGING_IO);
2856 NoCache = BooleanFlagOn(Irp->Flags, IRP_NOCACHE);
2857 Sync = !BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_ASYNC_OPERATION);
2858 InFsp = BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_IN_FSP);
2859 ReadLength = Stack->Parameters.Read.Length;
2860 ByteOffset.QuadPart = Stack->Parameters.Read.ByteOffset.QuadPart;
2861 DPRINT("Reading: %lx@%I64x %s %s %s %s\n", ReadLength, ByteOffset.QuadPart,
2862 (CanWait ? "CW" : "!CW"), (PagingIo ? "PI" : "!PI"), (NoCache ? "NC" : "!NC"), (Sync ? "S" : "!S"));
2863
2864 RxItsTheSameContext();
2865
2866 Irp->IoStatus.Information = 0;
2867
2868 /* Should the read be loud - so far, it's just ignored on ReactOS:
2869 * s/DPRINT/DPRINT1/g will make it loud
2870 */
2871 LowIoContext = &RxContext->LowIoContext;
2872 CheckForLoudOperations(RxContext);
2873 if (BooleanFlagOn(LowIoContext->Flags, LOWIO_CONTEXT_FLAG_LOUDOPS))
2874 {
2875 DPRINT("LoudRead %I64x/%lx on %lx vdl/size/alloc %I64x/%I64x/%I64x\n",
2876 ByteOffset, ReadLength,
2877 Fcb, Fcb->Header.ValidDataLength, Fcb->Header.FileSize, Fcb->Header.AllocationSize);
2878 }
2879
2880 RxDeviceObject = RxContext->RxDeviceObject;
2881 /* Update stats */
2882 if (!BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_IN_FSP) && Fcb->CachedNetRootType == NET_ROOT_DISK)
2883 {
2884 InterlockedIncrement((volatile long *)&RxDeviceObject->ReadOperations);
2885
2886 if (ByteOffset.QuadPart != Fobx->Specific.DiskFile.PredictedReadOffset)
2887 {
2888 InterlockedIncrement((volatile long *)&RxDeviceObject->RandomReadOperations);
2889 }
2890 Fobx->Specific.DiskFile.PredictedReadOffset = ByteOffset.QuadPart + ReadLength;
2891
2892 if (PagingIo)
2893 {
2894 ExInterlockedAddLargeStatistic(&RxDeviceObject->PagingReadBytesRequested, ReadLength);
2895 }
2896 else if (NoCache)
2897 {
2898 ExInterlockedAddLargeStatistic(&RxDeviceObject->NonPagingReadBytesRequested, ReadLength);
2899 }
2900 else
2901 {
2902 ExInterlockedAddLargeStatistic(&RxDeviceObject->CacheReadBytesRequested, ReadLength);
2903 }
2904 }
2905
2906 /* A pagefile cannot be a pipe */
2907 IsPipe = Fcb->NetRoot->Type == NET_ROOT_PIPE;
2908 if (IsPipe && PagingIo)
2909 {
2910 return STATUS_INVALID_DEVICE_REQUEST;
2911 }
2912
2913 /* Null-length read is no-op */
2914 if (ReadLength == 0)
2915 {
2916 return STATUS_SUCCESS;
2917 }
2918
2919 /* Validate FCB type */
2920 if (NodeType(Fcb) != RDBSS_NTC_STORAGE_TYPE_FILE && NodeType(Fcb) != RDBSS_NTC_VOLUME_FCB)
2921 {
2922 return STATUS_INVALID_DEVICE_REQUEST;
2923 }
2924
2925 /* Init the lowio context for possible forward */
2926 RxInitializeLowIoContext(LowIoContext, LOWIO_OP_READ);
2927
2928 PostRequest = FALSE;
2929 ReadCachingDisabled = FALSE;
2930 OwnerSet = FALSE;
2931 ReadCachingEnabled = BooleanFlagOn(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
2932 FileObject = Stack->FileObject;
2933 NetRoot = (PNET_ROOT)Fcb->pNetRoot;
2934 _SEH2_TRY
2935 {
2936 LONGLONG FileSize;
2937
2938 /* If no caching, make sure current Cc data have been flushed */
2939 if (!PagingIo && NoCache && !ReadCachingEnabled && FileObject->SectionObjectPointer != NULL)
2940 {
2941 Status = RxAcquireExclusiveFcb(RxContext, Fcb);
2942 if (Status == STATUS_LOCK_NOT_GRANTED)
2943 {
2944 PostRequest = TRUE;
2945 _SEH2_LEAVE;
2946 }
2947 else if (Status != STATUS_SUCCESS)
2948 {
2949 _SEH2_LEAVE;
2950 }
2951
2952 ExAcquireResourceSharedLite(Fcb->Header.PagingIoResource, TRUE);
2953 CcFlushCache(FileObject->SectionObjectPointer, &ByteOffset, ReadLength, &Irp->IoStatus);
2954 RxReleasePagingIoResource(RxContext, Fcb);
2955
2956 if (!NT_SUCCESS(Irp->IoStatus.Status))
2957 {
2958 _SEH2_LEAVE;
2959 }
2960
2961 RxAcquirePagingIoResource(RxContext, Fcb);
2962 RxReleasePagingIoResource(RxContext, Fcb);
2963 }
2964
2965 /* Acquire the appropriate lock */
2966 if (PagingIo && !ReadCachingEnabled)
2967 {
2968 ASSERT(!IsPipe);
2969
2970 if (!ExAcquireResourceSharedLite(Fcb->Header.PagingIoResource, CanWait))
2971 {
2972 PostRequest = TRUE;
2973 _SEH2_LEAVE;
2974 }
2975
2976 if (!CanWait)
2977 {
2978 LowIoContext->Resource = Fcb->Header.PagingIoResource;
2979 }
2980 }
2981 else
2982 {
2983 if (!ReadCachingEnabled)
2984 {
2985 if (!CanWait && NoCache)
2986 {
2987 Status = RxAcquireSharedFcbWaitForEx(RxContext, Fcb);
2988 if (Status == STATUS_LOCK_NOT_GRANTED)
2989 {
2990 DPRINT1("RdAsyLNG %x\n", RxContext);
2991 PostRequest = TRUE;
2992 _SEH2_LEAVE;
2993 }
2994 if (Status != STATUS_SUCCESS)
2995 {
2996 DPRINT1("RdAsyOthr %x\n", RxContext);
2997 _SEH2_LEAVE;
2998 }
2999
3000 if (RxIsFcbAcquiredShared(Fcb) <= 0xF000)
3001 {
3002 LowIoContext->Resource = Fcb->Header.Resource;
3003 }
3004 else
3005 {
3006 PostRequest = TRUE;
3007 _SEH2_LEAVE;
3008 }
3009 }
3010 else
3011 {
3012 Status = RxAcquireSharedFcb(RxContext, Fcb);
3013 if (Status == STATUS_LOCK_NOT_GRANTED)
3014 {
3015 PostRequest = TRUE;
3016 _SEH2_LEAVE;
3017 }
3018 else if (Status != STATUS_SUCCESS)
3019 {
3020 _SEH2_LEAVE;
3021 }
3022 }
3023 }
3024 }
3025
3026 RxItsTheSameContext();
3027
3028 ReadCachingDisabled = (ReadCachingEnabled == FALSE);
3029 if (IsPipe)
3030 {
3031 UNIMPLEMENTED;
3032 }
3033
3034 RxGetFileSizeWithLock(Fcb, &FileSize);
3035
3036 /* Make sure FLOCK doesn't conflict */
3037 if (!PagingIo)
3038 {
3039 if (!FsRtlCheckLockForReadAccess(&Fcb->Specific.Fcb.FileLock, Irp))
3040 {
3041 Status = STATUS_FILE_LOCK_CONFLICT;
3042 _SEH2_LEAVE;
3043 }
3044 }
3045
3046 /* Validate byteoffset vs length */
3047 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED))
3048 {
3049 if (ByteOffset.QuadPart >= FileSize)
3050 {
3051 Status = STATUS_END_OF_FILE;
3052 _SEH2_LEAVE;
3053 }
3054
3055 if (ReadLength > FileSize - ByteOffset.QuadPart)
3056 {
3057 ReadLength = FileSize - ByteOffset.QuadPart;
3058 }
3059 }
3060
3061 /* Read with Cc! */
3062 if (!PagingIo && !NoCache && ReadCachingEnabled &&
3063 !BooleanFlagOn(Fobx->pSrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_READ_CACHING))
3064 {
3065 /* File was not cached yet, do it */
3066 if (FileObject->PrivateCacheMap == NULL)
3067 {
3068 if (BooleanFlagOn(FileObject->Flags, FO_CLEANUP_COMPLETE))
3069 {
3070 Status = STATUS_FILE_CLOSED;
3071 _SEH2_LEAVE;
3072 }
3073
3074 RxAdjustAllocationSizeforCC(Fcb);
3075
3076 CcInitializeCacheMap(FileObject, (PCC_FILE_SIZES)&Fcb->Header.AllocationSize,
3077 FALSE, &RxData.CacheManagerCallbacks, Fcb);
3078
3079 if (BooleanFlagOn(Fcb->MRxDispatch->MRxFlags, RDBSS_NO_DEFERRED_CACHE_READAHEAD))
3080 {
3081 CcSetAdditionalCacheAttributes(FileObject, FALSE, FALSE);
3082 }
3083 else
3084 {
3085 CcSetAdditionalCacheAttributes(FileObject, TRUE, FALSE);
3086 SetFlag(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED);
3087 }
3088
3089 CcSetReadAheadGranularity(FileObject, NetRoot->DiskParameters.ReadAheadGranularity);
3090 }
3091
3092 /* This should never happen - fix your RDR */
3093 if (BooleanFlagOn(RxContext->MinorFunction, IRP_MN_MDL))
3094 {
3095 ASSERT(FALSE);
3096 ASSERT(CanWait);
3097
3098 CcMdlRead(FileObject, &ByteOffset, ReadLength, &Irp->MdlAddress, &Irp->IoStatus);
3099 Status = Irp->IoStatus.Status;
3100 ASSERT(NT_SUCCESS(Status));
3101 }
3102 else
3103 {
3104 /* Map buffer */
3105 SystemBuffer = RxNewMapUserBuffer(RxContext);
3106 if (SystemBuffer == NULL)
3107 {
3108 Status = STATUS_INSUFFICIENT_RESOURCES;
3109 _SEH2_LEAVE;
3110 }
3111
3112 SetFlag(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
3113
3114 RxItsTheSameContext();
3115
3116 /* Perform the read */
3117 if (!CcCopyRead(FileObject, &ByteOffset, ReadLength, CanWait, SystemBuffer, &Irp->IoStatus))
3118 {
3119 if (!ReadCachingEnabled)
3120 {
3121 ClearFlag(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
3122 }
3123
3124 RxItsTheSameContext();
3125
3126 PostRequest = TRUE;
3127 _SEH2_LEAVE;
3128 }
3129
3130 if (!ReadCachingEnabled)
3131 {
3132 ClearFlag(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED);
3133 }
3134
3135 Status = Irp->IoStatus.Status;
3136 ASSERT(NT_SUCCESS(Status));
3137 }
3138 }
3139 else
3140 {
3141 /* Validate the reading */
3142 if (FileObject->PrivateCacheMap != NULL && BooleanFlagOn(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED) &&
3143 ByteOffset.QuadPart >= 4096)
3144 {
3145 CcSetAdditionalCacheAttributes(FileObject, FALSE, FALSE);
3146 ClearFlag(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED);
3147 }
3148
3149 /* If it's consistent, forward to mini-rdr */
3150 if (Fcb->CachedNetRootType != NET_ROOT_DISK || BooleanFlagOn(Fcb->FcbState, FCB_STATE_READAHEAD_DEFERRED) ||
3151 ByteOffset.QuadPart < Fcb->Header.ValidDataLength.QuadPart)
3152 {
3153 LowIoContext->ParamsFor.ReadWrite.ByteCount = ReadLength;
3154 LowIoContext->ParamsFor.ReadWrite.ByteOffset = ByteOffset.QuadPart;
3155
3156 RxItsTheSameContext();
3157
3158 if (InFsp && ReadCachingDisabled)
3159 {
3160 ExSetResourceOwnerPointer((PagingIo ? Fcb->Header.PagingIoResource : Fcb->Header.Resource),
3161 (PVOID)((ULONG_PTR)RxContext | 3));
3162 OwnerSet = TRUE;
3163 }
3164
3165 Status = RxLowIoReadShell(RxContext);
3166
3167 RxItsTheSameContext();
3168 }
3169 else
3170 {
3171 if (ByteOffset.QuadPart > FileSize)
3172 {
3173 ReadLength = 0;
3174 Irp->IoStatus.Information = ReadLength;
3175 _SEH2_LEAVE;
3176 }
3177
3178 if (ByteOffset.QuadPart + ReadLength > FileSize)
3179 {
3180 ReadLength = FileSize - ByteOffset.QuadPart;
3181 }
3182
3183 SystemBuffer = RxNewMapUserBuffer(RxContext);
3184 RtlZeroMemory(SystemBuffer, ReadLength);
3185 Irp->IoStatus.Information = ReadLength;
3186 }
3187 }
3188 }
3189 _SEH2_FINALLY
3190 {
3191 RxItsTheSameContext();
3192
3193 /* Post if required */
3194 if (PostRequest)
3195 {
3196 InterlockedIncrement((volatile long *)&RxContext->ReferenceCount);
3197 Status = RxFsdPostRequest(RxContext);
3198 }
3199 else
3200 {
3201 /* Update FO in case of sync IO */
3202 if (!IsPipe && !PagingIo)
3203 {
3204 if (BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO))
3205 {
3206 FileObject->CurrentByteOffset.QuadPart = ByteOffset.QuadPart + Irp->IoStatus.Information;
3207 }
3208 }
3209 }
3210
3211 /* Set FastIo if read was a success */
3212 if (NT_SUCCESS(Status) && Status != STATUS_PENDING)
3213 {
3214 if (!IsPipe && !PagingIo)
3215 {
3216 SetFlag(FileObject->Flags, FO_FILE_FAST_IO_READ);
3217 }
3218 }
3219
3220 /* In case we're done (not expected any further processing */
3221 if (_SEH2_AbnormalTermination() || Status != STATUS_PENDING || PostRequest)
3222 {
3223 /* Release everything that can be */
3224 if (ReadCachingDisabled)
3225 {
3226 if (PagingIo)
3227 {
3228 if (OwnerSet)
3229 {
3230 RxReleasePagingIoResourceForThread(RxContext, Fcb, LowIoContext->ResourceThreadId);
3231 }
3232 else
3233 {
3234 RxReleasePagingIoResource(RxContext, Fcb);
3235 }
3236 }
3237 else
3238 {
3239 if (OwnerSet)
3240 {
3241 RxReleaseFcbForThread(RxContext, Fcb, LowIoContext->ResourceThreadId);
3242 }
3243 else
3244 {
3245 RxReleaseFcb(RxContext, Fcb);
3246 }
3247 }
3248 }
3249
3250 /* Dereference/Delete context */
3251 if (PostRequest)
3252 {
3253 RxDereferenceAndDeleteRxContext(RxContext);
3254 }
3255 else
3256 {
3257 if (BooleanFlagOn(RxContext->FlagsForLowIo, RXCONTEXT_FLAG4LOWIO_PIPE_SYNC_OPERATION))
3258 {
3259 RxResumeBlockedOperations_Serially(RxContext, &Fobx->Specific.NamedPipe.ReadSerializationQueue);
3260 }
3261 }
3262
3263 /* We cannot return more than asked */
3264 if (Status == STATUS_SUCCESS)
3265 {
3266 ASSERT(Irp->IoStatus.Information <= Stack->Parameters.Read.Length);
3267 }
3268 }
3269 else
3270 {
3271 ASSERT(!Sync);
3272
3273 RxDereferenceAndDeleteRxContext(RxContext);
3274 }
3275 }
3276 _SEH2_END;
3277
3278 return Status;
3279 }
3280
3281 NTSTATUS
3282 NTAPI
3283 RxCommonSetEa(
3284 PRX_CONTEXT Context)
3285 {
3286 UNIMPLEMENTED;
3287 return STATUS_NOT_IMPLEMENTED;
3288 }
3289
3290 NTSTATUS
3291 NTAPI
3292 RxCommonSetInformation(
3293 PRX_CONTEXT Context)
3294 {
3295 UNIMPLEMENTED;
3296 return STATUS_NOT_IMPLEMENTED;
3297 }
3298
3299 NTSTATUS
3300 NTAPI
3301 RxCommonSetQuotaInformation(
3302 PRX_CONTEXT Context)
3303 {
3304 UNIMPLEMENTED;
3305 return STATUS_NOT_IMPLEMENTED;
3306 }
3307
3308 NTSTATUS
3309 NTAPI
3310 RxCommonSetSecurity(
3311 PRX_CONTEXT Context)
3312 {
3313 UNIMPLEMENTED;
3314 return STATUS_NOT_IMPLEMENTED;
3315 }
3316
3317 NTSTATUS
3318 NTAPI
3319 RxCommonSetVolumeInformation(
3320 PRX_CONTEXT Context)
3321 {
3322 UNIMPLEMENTED;
3323 return STATUS_NOT_IMPLEMENTED;
3324 }
3325
3326 NTSTATUS
3327 NTAPI
3328 RxCommonUnimplemented(
3329 PRX_CONTEXT Context)
3330 {
3331 UNIMPLEMENTED;
3332 return STATUS_NOT_IMPLEMENTED;
3333 }
3334
3335 NTSTATUS
3336 NTAPI
3337 RxCommonWrite(
3338 PRX_CONTEXT Context)
3339 {
3340 UNIMPLEMENTED;
3341 return STATUS_NOT_IMPLEMENTED;
3342 }
3343
3344 NTSTATUS
3345 NTAPI
3346 RxCompleteMdl(
3347 IN PRX_CONTEXT RxContext)
3348 {
3349 PAGED_CODE();
3350
3351 UNIMPLEMENTED;
3352 return STATUS_NOT_IMPLEMENTED;
3353 }
3354
3355 /*
3356 * @implemented
3357 */
3358 VOID
3359 RxCopyCreateParameters(
3360 IN PRX_CONTEXT RxContext)
3361 {
3362 PIRP Irp;
3363 PVOID DfsContext;
3364 PFILE_OBJECT FileObject;
3365 PIO_STACK_LOCATION Stack;