ReactOS  0.4.10-dev-234-g15c29d0
fsctrl.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Named Pipe FileSystem
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * FILE: drivers/filesystems/npfs/fsctrl.c
5  * PURPOSE: Named Pipe FileSystem I/O Controls
6  * PROGRAMMERS: ReactOS Portable Systems Group
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "npfs.h"
12 
13 // File ID number for NPFS bugchecking support
14 #define NPFS_BUGCHECK_FILE_ID (NPFS_BUGCHECK_FSCTRL)
15 
16 /* GLOBALS ********************************************************************/
17 
19 
20 /* FUNCTIONS ******************************************************************/
21 
23 NTAPI
25  IN PIRP Irp,
27 {
30 }
31 
33 NTAPI
35  IN PIRP Irp,
36  IN BOOLEAN Overflow,
38 {
41 }
42 
44 NTAPI
46  IN PIRP Irp,
48 {
51 }
52 
54 NTAPI
56  IN PIRP Irp)
57 {
58  PIO_STACK_LOCATION IoStackLocation;
59  NODE_TYPE_CODE NodeTypeCode;
60  PNP_CCB Ccb;
61  PNP_CLIENT_PROCESS ClientSession, QueryBuffer;
62  ULONG Length;
63  PAGED_CODE();
64 
65  /* Get the current stack location */
66  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
67 
68  /* Decode the file object and check the node type */
69  NodeTypeCode = NpDecodeFileObject(IoStackLocation->FileObject, 0, &Ccb, 0);
70  if (NodeTypeCode != NPFS_NTC_CCB)
71  {
73  }
74 
75  /* Get the length of the query buffer */
76  Length = IoStackLocation->Parameters.QueryFile.Length;
77  if (Length < 8)
78  {
80  }
81 
82  QueryBuffer = Irp->AssociatedIrp.SystemBuffer;
83 
84  /* Lock the Ccb */
86 
87  /* Get the CCBs client session and check if it's set */
88  ClientSession = Ccb->ClientSession;
89  if (ClientSession != NULL)
90  {
91  /* Copy first 2 fields */
92  QueryBuffer->Unknown = ClientSession->Unknown;
93  QueryBuffer->Process = ClientSession->Process;
94  }
95  else
96  {
97  /* Copy the process from the CCB */
98  QueryBuffer->Unknown = NULL;
99  QueryBuffer->Process = Ccb->Process;
100  }
101 
102  /* Does the caller provide a large enough buffer for the full data? */
103  if (Length >= sizeof(NP_CLIENT_PROCESS))
104  {
105  Irp->IoStatus.Information = sizeof(NP_CLIENT_PROCESS);
106 
107  /* Do we have a ClientSession structure? */
108  if (ClientSession != NULL)
109  {
110  /* Copy length and the data */
111  QueryBuffer->DataLength = ClientSession->DataLength;
112  RtlCopyMemory(QueryBuffer->Buffer,
113  ClientSession->Buffer,
114  ClientSession->DataLength);
115 
116  /* NULL terminate the buffer */
117  NT_ASSERT(QueryBuffer->DataLength <= 30);
118  QueryBuffer->Buffer[QueryBuffer->DataLength / sizeof(WCHAR)] = 0;
119  }
120  else
121  {
122  /* No data */
123  QueryBuffer->DataLength = 0;
124  QueryBuffer->Buffer[0] = 0;
125  }
126  }
127  else
128  {
129  Irp->IoStatus.Information = FIELD_OFFSET(NP_CLIENT_PROCESS, DataLength);
130  }
131 
132  /* Unlock the Ccb */
134 
135  return STATUS_SUCCESS;
136 }
137 
138 NTSTATUS
139 NTAPI
141  IN PIRP Irp)
142 {
143  PIO_STACK_LOCATION IoStackLocation;
144  NODE_TYPE_CODE NodeTypeCode;
145  PNP_CCB Ccb;
146  ULONG Length;
147  PNP_CLIENT_PROCESS InputBuffer, ClientSession, OldClientSession;
148  PAGED_CODE();
149 
150  /* Get the current stack location */
151  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
152 
153  /* Only kernel calls are allowed! */
154  if (IoStackLocation->MinorFunction != IRP_MN_KERNEL_CALL)
155  {
156  return STATUS_ACCESS_DENIED;
157  }
158 
159  /* Decode the file object and check the node type */
160  NodeTypeCode = NpDecodeFileObject(IoStackLocation->FileObject, 0, &Ccb, 0);
161  if (NodeTypeCode != NPFS_NTC_CCB)
162  {
164  }
165 
166  /* Get the length of the query buffer and check if it's valid */
167  Length = IoStackLocation->Parameters.QueryFile.Length;
168  if (Length != sizeof(NP_CLIENT_PROCESS))
169  {
171  }
172 
173  /* Get the buffer and check if the data Length is valid */
174  InputBuffer = Irp->AssociatedIrp.SystemBuffer;
175  if (InputBuffer->DataLength > 30)
176  {
178  }
179 
180  /* Allocate a new structure */
181  ClientSession = ExAllocatePoolWithQuotaTag(PagedPool,
182  sizeof(NP_CLIENT_PROCESS),
183  'iFpN');
184 
185  /* Copy the full input buffer */
186  RtlCopyMemory(ClientSession, InputBuffer, sizeof(NP_CLIENT_PROCESS));
187 
188  /* Lock the Ccb */
190 
191  /* Get the old ClientSession and set the new */
192  OldClientSession = Ccb->ClientSession;
193  Ccb->ClientSession = ClientSession;
194 
195  /* Copy the process to the CCB */
196  Ccb->Process = ClientSession->Process;
197 
198  /* Unlock the Ccb */
200 
201  /* Check if there was already a ClientSession */
202  if (OldClientSession != NULL)
203  {
204  /* Free it */
205  ExFreePoolWithTag(OldClientSession, 'iFpN');
206  }
207 
208  return STATUS_SUCCESS;
209 }
210 
211 NTSTATUS
212 NTAPI
214  IN PIRP Irp)
215 {
217  return STATUS_NOT_IMPLEMENTED;
218 }
219 
220 NTSTATUS
221 NTAPI
223  IN PIRP Irp)
224 {
226  return STATUS_NOT_IMPLEMENTED;
227 }
228 
229 NTSTATUS
230 NTAPI
232  IN PIRP Irp)
233 {
234  ULONG NamedPipeEnd;
235  PNP_CCB Ccb;
237  NODE_TYPE_CODE NodeTypeCode;
238  PIO_STACK_LOCATION IoStack;
239  PAGED_CODE();
240 
241  IoStack = IoGetCurrentIrpStackLocation(Irp);
242 
243  NodeTypeCode = NpDecodeFileObject(IoStack->FileObject, NULL, &Ccb, &NamedPipeEnd);
244  if (NodeTypeCode == NPFS_NTC_CCB && NamedPipeEnd == FILE_PIPE_SERVER_END)
245  {
246  Status = NpImpersonateClientContext(Ccb);
247  }
248  else
249  {
250  Status = STATUS_ILLEGAL_FUNCTION;
251  }
252 
253  return Status;
254 }
255 
256 NTSTATUS
257 NTAPI
259  IN PIRP Irp,
261 {
262  ULONG NamedPipeEnd;
263  PNP_CCB Ccb;
265  NODE_TYPE_CODE NodeTypeCode;
266  PIO_STACK_LOCATION IoStack;
267  PAGED_CODE();
268 
269  IoStack = IoGetCurrentIrpStackLocation(Irp);
270 
271  NodeTypeCode = NpDecodeFileObject(IoStack->FileObject, NULL, &Ccb, &NamedPipeEnd);
272  if (NodeTypeCode == NPFS_NTC_CCB)
273  {
274  if (NamedPipeEnd == FILE_PIPE_SERVER_END)
275  {
277 
278  Status = NpSetDisconnectedPipeState(Ccb, List);
279 
281 
283  }
284  else
285  {
286  Status = STATUS_ILLEGAL_FUNCTION;
287  }
288  }
289  else
290  {
291  Status = STATUS_PIPE_DISCONNECTED;
292  }
293 
294  return Status;
295 }
296 
297 NTSTATUS
298 NTAPI
300  IN PIRP Irp,
302 {
303  ULONG NamedPipeEnd;
304  PNP_CCB Ccb;
306  NODE_TYPE_CODE NodeTypeCode;
307  PIO_STACK_LOCATION IoStack;
308  PAGED_CODE();
309 
310  IoStack = IoGetCurrentIrpStackLocation(Irp);
311 
312  NodeTypeCode = NpDecodeFileObject(IoStack->FileObject, NULL, &Ccb, &NamedPipeEnd);
313  if (NodeTypeCode == NPFS_NTC_CCB)
314  {
315  if (NamedPipeEnd == FILE_PIPE_SERVER_END)
316  {
318 
319  Status = NpSetListeningPipeState(Ccb, Irp, List);
320 
322 
324  }
325  else
326  {
327  Status = STATUS_ILLEGAL_FUNCTION;
328  }
329  }
330  else
331  {
332  Status = STATUS_ILLEGAL_FUNCTION;
333  }
334 
335  return Status;
336 }
337 
338 NTSTATUS
339 NTAPI
341  IN PIRP Irp,
343 {
344  PIO_STACK_LOCATION IoStack;
346  ULONG OutputLength;
347  ULONG NamedPipeEnd;
348  PNP_CCB Ccb;
349  PFILE_PIPE_PEEK_BUFFER PeekBuffer;
350  PNP_DATA_QUEUE DataQueue;
351  ULONG_PTR BytesPeeked;
354  PNP_DATA_QUEUE_ENTRY DataEntry;
355  PAGED_CODE();
356 
357  IoStack = IoGetCurrentIrpStackLocation(Irp);
358  OutputLength = IoStack->Parameters.FileSystemControl.OutputBufferLength;
359  Type = NpDecodeFileObject(IoStack->FileObject, NULL, &Ccb, &NamedPipeEnd);
360 
361  if (!Type)
362  {
364  }
365 
366  if ((Type != NPFS_NTC_CCB) &&
367  (OutputLength < FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data)))
368  {
370  }
371 
372  PeekBuffer = Irp->AssociatedIrp.SystemBuffer;
373  if (NamedPipeEnd != FILE_PIPE_CLIENT_END)
374  {
375  if (NamedPipeEnd != FILE_PIPE_SERVER_END)
376  {
377  NpBugCheck(NamedPipeEnd, 0, 0);
378  }
379 
380  DataQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
381  }
382  else
383  {
384  DataQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
385  }
386 
388  {
390  {
392  }
393 
394  if (DataQueue->QueueState != WriteEntries)
395  {
396  return STATUS_PIPE_BROKEN;
397  }
398  }
399 
400  PeekBuffer->NamedPipeState = 0;
401  PeekBuffer->ReadDataAvailable = 0;
402  PeekBuffer->NumberOfMessages = 0;
403  PeekBuffer->MessageLength = 0;
404  PeekBuffer->NamedPipeState = Ccb->NamedPipeState;
405  BytesPeeked = FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data);
406 
407  if (DataQueue->QueueState == WriteEntries)
408  {
409  DataEntry = CONTAINING_RECORD(DataQueue->Queue.Flink,
411  QueueEntry);
412  ASSERT((DataEntry->DataEntryType == Buffered) || (DataEntry->DataEntryType == Unbuffered));
413 
414  PeekBuffer->ReadDataAvailable = DataQueue->BytesInQueue - DataQueue->ByteOffset;
416  {
417  PeekBuffer->NumberOfMessages = DataQueue->EntriesInQueue;
418  PeekBuffer->MessageLength = DataEntry->DataSize - DataQueue->ByteOffset;
419  }
420 
421  if (OutputLength == FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data))
422  {
424  }
425  else
426  {
427  IoStatus = NpReadDataQueue(DataQueue,
428  TRUE,
429  FALSE,
430  PeekBuffer->Data,
431  OutputLength - FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data),
433  Ccb,
434  List);
435  Status = IoStatus.Status;
436  BytesPeeked += IoStatus.Information;
437  }
438  }
439  else
440  {
441  Status = STATUS_SUCCESS;
442  }
443 
444  Irp->IoStatus.Information = BytesPeeked;
445  return Status;
446 }
447 
448 NTSTATUS
449 NTAPI
451  IN PIRP Irp,
452  IN PVOID Context)
453 {
454  PAGED_CODE();
455 
456  if (Irp->AssociatedIrp.SystemBuffer)
457  {
458  ExFreePool(Irp->AssociatedIrp.SystemBuffer);
459  }
460 
461  IoFreeIrp(Irp);
463 }
464 
465 NTSTATUS
466 NTAPI
468  IN PIRP Irp,
470 {
471  PIO_STACK_LOCATION IoStack;
472  PVOID InBuffer, OutBuffer;
473  ULONG InLength, OutLength, BytesWritten;
474  NODE_TYPE_CODE NodeTypeCode;
475  PNP_CCB Ccb;
476  ULONG NamedPipeEnd;
477  PNP_NONPAGED_CCB NonPagedCcb;
478  PNP_DATA_QUEUE ReadQueue, WriteQueue;
479  PNP_EVENT_BUFFER EventBuffer;
481  PIRP NewIrp;
482  PAGED_CODE();
483 
484  IoStack = IoGetCurrentIrpStackLocation(Irp);
485  InLength = IoStack->Parameters.FileSystemControl.InputBufferLength;
486  InBuffer = IoStack->Parameters.FileSystemControl.Type3InputBuffer;
487  OutLength = IoStack->Parameters.FileSystemControl.OutputBufferLength;
488  OutBuffer = Irp->UserBuffer;
489 
490  if (Irp->RequestorMode == UserMode)
491  {
492  _SEH2_TRY
493  {
494  ProbeForRead(InBuffer, InLength, sizeof(CHAR));
495  ProbeForWrite(OutBuffer, OutLength, sizeof(CHAR));
496  }
498  {
500  }
501  _SEH2_END;
502  }
503 
504  NodeTypeCode = NpDecodeFileObject(IoStack->FileObject, NULL, &Ccb, &NamedPipeEnd);
505  if (NodeTypeCode != NPFS_NTC_CCB)
506  {
508  }
509 
510  NonPagedCcb = Ccb->NonPagedCcb;
511  ExAcquireResourceExclusiveLite(&NonPagedCcb->Lock, TRUE);
512 
514  {
515  Status = STATUS_INVALID_PIPE_STATE;
516  goto Quickie;
517  }
518 
519  if (NamedPipeEnd != FILE_PIPE_CLIENT_END)
520  {
521  if (NamedPipeEnd != FILE_PIPE_SERVER_END)
522  {
523  NpBugCheck(NamedPipeEnd, 0, 0);
524  }
525  ReadQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
526  WriteQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
527  }
528  else
529  {
530  ReadQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
531  WriteQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
532  }
533 
534  EventBuffer = NonPagedCcb->EventBuffer[NamedPipeEnd];
535 
537  Ccb->ReadMode[NamedPipeEnd] != FILE_PIPE_MESSAGE_MODE)
538  {
539  Status = STATUS_INVALID_PIPE_STATE;
540  goto Quickie;
541  }
542 
543  if (ReadQueue->QueueState != Empty)
544  {
545  Status = STATUS_PIPE_BUSY;
546  goto Quickie;
547  }
548 
549  Status = NpWriteDataQueue(WriteQueue,
551  InBuffer,
552  InLength,
553  Ccb->Fcb->NamedPipeType,
554  &BytesWritten,
555  Ccb,
556  NamedPipeEnd,
557  Irp->Tail.Overlay.Thread,
558  List);
559  if (Status == STATUS_MORE_PROCESSING_REQUIRED)
560  {
561  ASSERT(WriteQueue->QueueState != ReadEntries);
562  NewIrp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
563  if (!NewIrp)
564  {
566  goto Quickie;
567  }
568 
570 
571  if (BytesWritten)
572  {
573  NewIrp->AssociatedIrp.SystemBuffer = ExAllocatePoolWithQuotaTag(PagedPool | POOL_QUOTA_FAIL_INSTEAD_OF_RAISE,
574  BytesWritten,
576  if (!NewIrp->AssociatedIrp.SystemBuffer)
577  {
578  IoFreeIrp(NewIrp);
580  goto Quickie;
581  }
582 
583  _SEH2_TRY
584  {
585  RtlCopyMemory(NewIrp->AssociatedIrp.SystemBuffer,
586  (PVOID)((ULONG_PTR)InBuffer + InLength - BytesWritten),
587  BytesWritten);
588  }
590  {
591  Status = _SEH2_GetExceptionCode();
592  _SEH2_YIELD(goto Quickie);
593  }
594  _SEH2_END;
595  }
596  else
597  {
598  NewIrp->AssociatedIrp.SystemBuffer = NULL;
599  }
600 
601  IoStack = IoGetNextIrpStackLocation(NewIrp);
603 
604  NewIrp->Tail.Overlay.Thread = Irp->Tail.Overlay.Thread;
605  NewIrp->IoStatus.Information = BytesWritten;
606 
607  IoStack->Parameters.Read.Length = BytesWritten;
608  IoStack->MajorFunction = IRP_MJ_WRITE;
609 
610  if (BytesWritten > 0) NewIrp->Flags = IRP_DEALLOCATE_BUFFER | IRP_BUFFERED_IO;
611  NewIrp->UserIosb = &NpUserIoStatusBlock;
612 
613  Status = NpAddDataQueueEntry(NamedPipeEnd,
614  Ccb,
615  WriteQueue,
616  WriteEntries,
617  Unbuffered,
618  BytesWritten,
619  NewIrp,
620  NULL,
621  0);
622  if (Status != STATUS_PENDING)
623  {
624  NewIrp->IoStatus.Status = Status;
625  InsertTailList(List, &NewIrp->Tail.Overlay.ListEntry);
626  }
627  }
628 
629  if (!NT_SUCCESS(Status)) goto Quickie;
630 
631  if (EventBuffer) KeSetEvent(EventBuffer->Event, IO_NO_INCREMENT, FALSE);
632  ASSERT(ReadQueue->QueueState == Empty);
633  Status = NpAddDataQueueEntry(NamedPipeEnd,
634  Ccb,
635  ReadQueue,
636  ReadEntries,
637  Buffered,
638  OutLength,
639  Irp,
640  NULL,
641  0);
642  if (NT_SUCCESS(Status))
643  {
644  if (EventBuffer) KeSetEvent(EventBuffer->Event, IO_NO_INCREMENT, FALSE);
645  }
646 
647 Quickie:
649  return Status;
650 }
651 
652 NTSTATUS
653 NTAPI
655  IN PIRP Irp)
656 {
657  PIO_STACK_LOCATION IoStack;
658  ULONG InLength, NameLength;
660  ULONG NamedPipeEnd;
661  PNP_CCB Ccb;
664  NODE_TYPE_CODE NodeTypeCode;
665  PLIST_ENTRY NextEntry;
666  PNP_FCB Fcb;
667  PWCHAR OriginalBuffer;
668  PAGED_CODE();
669 
670  IoStack = IoGetCurrentIrpStackLocation(Irp);
671  InLength = IoStack->Parameters.FileSystemControl.InputBufferLength;
672 
673  SourceString.Buffer = NULL;
674 
675  if (NpDecodeFileObject(IoStack->FileObject,
676  NULL,
677  &Ccb,
678  &NamedPipeEnd) != NPFS_NTC_ROOT_DCB)
679  {
680  Status = STATUS_ILLEGAL_FUNCTION;
681  goto Quickie;
682  }
683 
684  Buffer = (PFILE_PIPE_WAIT_FOR_BUFFER)Irp->AssociatedIrp.SystemBuffer;
685  if (InLength < sizeof(*Buffer))
686  {
687  Status = STATUS_INVALID_PARAMETER;
688  goto Quickie;
689  }
690 
691  NameLength = Buffer->NameLength;
692  if ((NameLength > (0xFFFF - sizeof(UNICODE_NULL))) ||
693  ((NameLength + FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name)) > InLength))
694  {
695  Status = STATUS_INVALID_PARAMETER;
696  goto Quickie;
697  }
698 
699  SourceString.Length = (USHORT)NameLength + sizeof(OBJ_NAME_PATH_SEPARATOR);
700  SourceString.Buffer = ExAllocatePoolWithTag(PagedPool,
701  SourceString.Length,
703  if (!SourceString.Buffer)
704  {
706  goto Quickie;
707  }
708 
709  SourceString.Buffer[0] = OBJ_NAME_PATH_SEPARATOR;
710  RtlCopyMemory(&SourceString.Buffer[1], Buffer->Name, Buffer->NameLength);
711 
712  Status = STATUS_SUCCESS;
713  OriginalBuffer = SourceString.Buffer;
714  //Status = NpTranslateAlias(&SourceString);
715  if (!NT_SUCCESS(Status)) goto Quickie;
716 
717  Fcb = NpFindPrefix(&SourceString, 1, &Prefix);
718  Fcb = (PNP_FCB)((ULONG_PTR)Fcb & ~1);
719 
720  NodeTypeCode = Fcb ? Fcb->NodeType : 0;
721  if (NodeTypeCode != NPFS_NTC_FCB)
722  {
724  goto Quickie;
725  }
726 
727  for (NextEntry = Fcb->CcbList.Flink;
728  NextEntry != &Fcb->CcbList;
729  NextEntry = NextEntry->Flink)
730  {
731  Ccb = CONTAINING_RECORD(NextEntry, NP_CCB, CcbEntry);
732  if (Ccb->NamedPipeState == FILE_PIPE_LISTENING_STATE) break;
733  }
734 
735  if (NextEntry != &Fcb->CcbList)
736  {
737  Status = STATUS_SUCCESS;
738  }
739  else
740  {
741  Status = NpAddWaiter(&NpVcb->WaitQueue,
742  Fcb->Timeout,
743  Irp,
744  OriginalBuffer == SourceString.Buffer ?
745  NULL : &SourceString);
746  }
747 
748 Quickie:
749  if (SourceString.Buffer) ExFreePool(SourceString.Buffer);
750  return Status;
751 }
752 
753 NTSTATUS
754 NTAPI
756  IN PIRP Irp)
757 {
758  ULONG Fsctl;
759  BOOLEAN Overflow = FALSE;
760  LIST_ENTRY DeferredList;
762  PAGED_CODE();
763 
764  InitializeListHead(&DeferredList);
765  Fsctl = IoGetCurrentIrpStackLocation(Irp)->Parameters.FileSystemControl.FsControlCode;
766 
767  switch (Fsctl)
768  {
769  case FSCTL_PIPE_PEEK:
771  Status = NpPeek(DeviceObject, Irp, &DeferredList);
772  break;
773 
776  Status = NpInternalWrite(DeviceObject, Irp, &DeferredList);
777  break;
778 
781  Status = NpTransceive(DeviceObject, Irp, &DeferredList);
782  break;
783 
786  Status = NpInternalTransceive(DeviceObject, Irp, &DeferredList);
787  break;
788 
790  Overflow = TRUE;
791  // on purpose
792 
795  Status = NpInternalRead(DeviceObject, Irp, Overflow, &DeferredList);
796  break;
797 
799 
801  Status = NpQueryClientProcess(DeviceObject, Irp);
802  break;
803 
805 
807  Status = NpAssignEvent(DeviceObject, Irp);
808  break;
809 
811 
813  Status = NpDisconnect(DeviceObject, Irp, &DeferredList);
814  break;
815 
816  case FSCTL_PIPE_LISTEN:
817 
819  Status = NpListen(DeviceObject, Irp, &DeferredList);
820  break;
821 
823 
825  Status = NpQueryEvent(DeviceObject, Irp);
826  break;
827 
828  case FSCTL_PIPE_WAIT:
829 
831  Status = NpWaitForNamedPipe(DeviceObject, Irp);
832  break;
833 
835 
837  Status = NpImpersonate(DeviceObject, Irp);
838  break;
839 
842  Status = NpSetClientProcess(DeviceObject, Irp);
843  break;
844 
845  default:
846  return STATUS_NOT_SUPPORTED;
847  }
848 
849  NpReleaseVcb();
850  NpCompleteDeferredIrps(&DeferredList);
851 
852  return Status;
853 }
854 
855 NTSTATUS
856 NTAPI
858  IN PIRP Irp)
859 {
861  PAGED_CODE();
862 
864 
865  Status = NpCommonFileSystemControl(DeviceObject, Irp);
866 
868 
869  if (Status != STATUS_PENDING)
870  {
871  Irp->IoStatus.Status = Status;
873  }
874 
875  return Status;
876 }
877 
878 /* EOF */
DWORD *typedef PVOID
Definition: winlogon.h:52
NTSTATUS NTAPI NpWriteDataQueue(IN PNP_DATA_QUEUE WriteQueue, IN ULONG Mode, IN PVOID OutBuffer, IN ULONG OutBufferSize, IN ULONG PipeType, OUT PULONG BytesWritten, IN PNP_CCB Ccb, IN ULONG NamedPipeEnd, IN PETHREAD Thread, IN PLIST_ENTRY List)
Definition: writesup.c:20
#define IN
Definition: typedefs.h:38
#define FSCTL_PIPE_INTERNAL_READ
Definition: winioctl.h:203
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PVOID ClientSession
Definition: npfs.h:269
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
FORCEINLINE VOID NpAcquireSharedVcb(VOID)
Definition: npfs.h:328
#define FsRtlEnterFileSystem
#define FSCTL_PIPE_DISCONNECT
Definition: winioctl.h:194
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:398
NP_WAIT_QUEUE WaitQueue
Definition: npfs.h:285
PVOID NTAPI ExAllocatePoolWithQuotaTag(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes, IN ULONG Tag)
Definition: expool.c:2803
Type
Definition: Type.h:6
NTSTATUS NTAPI NpImpersonate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:231
PNP_EVENT_BUFFER EventBuffer[2]
Definition: npfs.h:253
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
UCHAR ReadMode[2]
Definition: npfs.h:262
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:51
#define FSCTL_PIPE_IMPERSONATE
Definition: winioctl.h:85
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
PNP_NONPAGED_CCB NonPagedCcb
Definition: npfs.h:270
_In_ PIRP Irp
Definition: csq.h:116
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
return STATUS_SUCCESS
Definition: btrfs.c:2690
char CHAR
Definition: xmlstorage.h:175
NTSTATUS NTAPI NpFsdFileSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:857
#define FILE_PIPE_MESSAGE_TYPE
Definition: iotypes.h:76
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
#define FILE_PIPE_CONNECTED_STATE
Definition: winternl.h:792
PNP_FCB NTAPI NpFindPrefix(IN PUNICODE_STRING Name, IN ULONG CaseInsensitiveIndex, IN PUNICODE_STRING Prefix)
Definition: prefxsup.c:20
#define NPFS_NTC_CCB
Definition: npfs.h:115
NTSTATUS NTAPI NpDisconnect(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: fsctrl.c:258
uint16_t * PWCHAR
Definition: typedefs.h:54
Definition: npfs.h:131
#define InsertTailList(ListHead, Entry)
#define WCHAR
Definition: msvc.h:43
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
struct _IO_STACK_LOCATION::@3564::@3566 Read
PNP_FCB Fcb
Definition: npfs.h:266
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
_SEH2_TRY
Definition: create.c:4250
ULONG EntriesInQueue
Definition: npfs.h:141
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI NpPeek(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: fsctrl.c:340
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
LIST_ENTRY CcbList
Definition: npfs.h:238
Definition: npfs.h:228
Definition: npfs.h:258
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
NTSTATUS NTAPI NpCompleteTransceiveIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: fsctrl.c:450
NTSTATUS NTAPI NpQueryClientProcess(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:55
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:27
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
WCHAR Buffer[17]
Definition: npfs.h:319
UCHAR NamedPipeState
Definition: npfs.h:261
NTSTATUS NTAPI NpAssignEvent(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:213
union _IO_STACK_LOCATION::@3564 Parameters
#define FSCTL_PIPE_INTERNAL_READ_OVFLOW
Definition: winioctl.h:206
smooth NULL
Definition: ftsmooth.c:416
#define FSCTL_PIPE_ASSIGN_EVENT
Definition: winioctl.h:193
#define IoCompleteRequest
Definition: irp.c:1240
USHORT NamedPipeConfiguration
Definition: npfs.h:235
USHORT DataLength
Definition: npfs.h:318
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define FSCTL_PIPE_QUERY_EVENT
Definition: winioctl.h:197
#define FSCTL_PIPE_LISTEN
Definition: pipe.c:63
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
ULONG QueueState
Definition: npfs.h:139
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define FSCTL_PIPE_WAIT
Definition: winioctl.h:199
unsigned char BOOLEAN
#define NpBugCheck(p1, p2, p3)
Definition: npfs.h:106
USHORT NODE_TYPE_CODE
Definition: nodetype.h:22
LONG NTSTATUS
Definition: precomp.h:26
ULONG DataSize
Definition: npfs.h:155
ULONG BytesInQueue
Definition: npfs.h:140
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
LIST_ENTRY List
Definition: psmgr.c:57
if(!(yy_init))
Definition: macro.lex.yy.c:717
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI NpInternalTransceive(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: fsctrl.c:24
struct _FILE_PIPE_WAIT_FOR_BUFFER * PFILE_PIPE_WAIT_FOR_BUFFER
IO_STATUS_BLOCK NTAPI NpReadDataQueue(IN PNP_DATA_QUEUE DataQueue, IN BOOLEAN Peek, IN BOOLEAN ReadOverflowOperation, IN PVOID Buffer, IN ULONG BufferSize, IN ULONG Mode, IN PNP_CCB Ccb, IN PLIST_ENTRY List)
Definition: readsup.c:20
NTSTATUS NTAPI NpAddWaiter(IN PNP_WAIT_QUEUE WaitQueue, IN LARGE_INTEGER WaitTime, IN PIRP Irp, IN PUNICODE_STRING AliasName)
Definition: waitsup.c:221
NTSTATUS NTAPI NpTransceive(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: fsctrl.c:467
NTSTATUS NTAPI NpImpersonateClientContext(IN PNP_CCB Ccb)
Definition: secursup.c:20
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
PVOID Unknown
Definition: npfs.h:316
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
UINTN VOID * Buffer
Definition: acefiex.h:370
ULONG ByteOffset
Definition: npfs.h:143
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
PNP_VCB NpVcb
Definition: strucsup.c:19
#define IO_NAMED_PIPE_INCREMENT
Definition: iotypes.h:571
NTSTATUS NTAPI NpSetListeningPipeState(IN PNP_CCB Ccb, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: statesup.c:188
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define STATUS_PIPE_BROKEN
Definition: ntstatus.h:553
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
#define STATUS_INVALID_PIPE_STATE
Definition: ntstatus.h:395
#define IRP_MN_KERNEL_CALL
Definition: iotypes.h:4019
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1869
#define FSCTL_PIPE_SET_CLIENT_PROCESS
Definition: winioctl.h:201
VOID UINTN Length
Definition: acefiex.h:744
Definition: npfs.h:148
NTSTATUS NTAPI NpWaitForNamedPipe(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:654
NTSTATUS NTAPI NpInternalWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: fsctrl.c:45
PEPROCESS Process
Definition: npfs.h:268
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FSCTL_PIPE_TRANSCEIVE
Definition: winioctl.h:198
Definition: typedefs.h:117
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define NPFS_WRITE_BLOCK_TAG
Definition: npfs.h:64
struct _IO_STACK_LOCATION::@3564::@3570 QueryFile
#define NPFS_NTC_ROOT_DCB
Definition: npfs.h:113
VOID NTAPI NpUninitializeSecurity(IN PNP_CCB Ccb)
Definition: secursup.c:72
Status
Definition: gdiplustypes.h:24
#define FSCTL_PIPE_INTERNAL_WRITE
Definition: winioctl.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2787
_SEH2_END
Definition: create.c:4424
#define IRP_BUFFERED_IO
PKEVENT Event
Definition: npfs.h:179
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
NTSTATUS NTAPI NpSetDisconnectedPipeState(IN PNP_CCB Ccb, IN PLIST_ENTRY List)
Definition: statesup.c:77
LIST_ENTRY Queue
Definition: npfs.h:138
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:49
#define FSCTL_PIPE_PEEK
Definition: winioctl.h:196
unsigned short USHORT
Definition: pedump.c:61
FORCEINLINE VOID NpReleaseVcb(VOID)
Definition: npfs.h:344
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define FILE_PIPE_MESSAGE_MODE
Definition: iotypes.h:78
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
ULONG DataEntryType
Definition: npfs.h:151
NTSTATUS NTAPI NpCommonFileSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:755
NTSTATUS NTAPI NpSetClientProcess(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:140
NTSTATUS NTAPI NpAddDataQueueEntry(IN ULONG NamedPipeEnd, IN PNP_CCB Ccb, IN PNP_DATA_QUEUE DataQueue, IN ULONG Who, IN ULONG Type, IN ULONG DataSize, IN PIRP Irp, IN PVOID Buffer, IN ULONG ByteOffset)
Definition: datasup.c:295
struct _NP_CLIENT_PROCESS NP_CLIENT_PROCESS
#define IRP_DEALLOCATE_BUFFER
#define FSCTL_PIPE_QUERY_CLIENT_PROCESS
Definition: winioctl.h:202
LARGE_INTEGER Timeout
Definition: npfs.h:237
#define FILE_PIPE_CLOSING_STATE
Definition: winternl.h:793
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
NP_DATA_QUEUE DataQueue[2]
Definition: npfs.h:271
#define NPFS_NTC_FCB
Definition: npfs.h:114
PVOID PIRP
Definition: usb.h:38
IO_STATUS_BLOCK NpUserIoStatusBlock
Definition: fsctrl.c:18
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
struct _IO_STACK_LOCATION::@3564::@3576 FileSystemControl
NTSTATUS NTAPI NpListen(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: fsctrl.c:299
#define UNIMPLEMENTED
Definition: debug.h:114
NODE_TYPE_CODE NTAPI NpDecodeFileObject(IN PFILE_OBJECT FileObject, OUT PVOID *PrimaryContext OPTIONAL, OUT PNP_CCB *Ccb, OUT PULONG NamedPipeEnd OPTIONAL)
Definition: fileobsup.c:20
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
FORCEINLINE VOID NpAcquireExclusiveVcb(VOID)
Definition: npfs.h:336
ERESOURCE Lock
Definition: npfs.h:254
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
NTSTATUS NTAPI NpQueryEvent(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fsctrl.c:222
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE
#define FILE_PIPE_FULL_DUPLEX
Definition: iotypes.h:83
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define FSCTL_PIPE_INTERNAL_TRANSCEIVE
Definition: winioctl.h:205
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
#define STATUS_PIPE_BUSY
Definition: ntstatus.h:396
_In_ PFCB Fcb
Definition: cdprocs.h:151
USHORT NamedPipeType
Definition: npfs.h:236
struct _NP_FCB * PNP_FCB
#define STATUS_ILLEGAL_FUNCTION
Definition: ntstatus.h:397
PVOID Process
Definition: npfs.h:317
FORCEINLINE VOID NpCompleteDeferredIrps(IN PLIST_ENTRY DeferredList)
Definition: npfs.h:356
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2632
NTSTATUS NTAPI NpInternalRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN BOOLEAN Overflow, IN PLIST_ENTRY List)
Definition: fsctrl.c:34
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: npfs.h:125
#define NT_ASSERT
Definition: rtlfuncs.h:3312