2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/ksfilter/ks/factory.c
5 * PURPOSE: KS Allocator functions
6 * PROGRAMMER: Johannes Anderwald
18 KsDispatchQuerySecurity(
19 IN PDEVICE_OBJECT DeviceObject
,
22 PKSOBJECT_CREATE_ITEM CreateItem
;
23 PIO_STACK_LOCATION IoStack
;
27 /* get current irp stack */
28 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
31 CreateItem
= KSCREATE_ITEM_IRP_STORAGE(Irp
);
33 if (!CreateItem
|| !CreateItem
->SecurityDescriptor
)
36 Irp
->IoStatus
.Status
= STATUS_NO_SECURITY_ON_OBJECT
;
37 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
38 return STATUS_NO_SECURITY_ON_OBJECT
;
42 /* get input length */
43 Length
= IoStack
->Parameters
.QuerySecurity
.Length
;
45 /* clone the security descriptor */
46 Status
= SeQuerySecurityDescriptorInfo(&IoStack
->Parameters
.QuerySecurity
.SecurityInformation
, (PSECURITY_DESCRIPTOR
)Irp
->UserBuffer
, &Length
, &CreateItem
->SecurityDescriptor
);
48 DPRINT("SeQuerySecurityDescriptorInfo Status %x\n", Status
);
50 Irp
->IoStatus
.Status
= Status
;
51 Irp
->IoStatus
.Information
= Length
;
53 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
63 KsDispatchSetSecurity(
64 IN PDEVICE_OBJECT DeviceObject
,
67 PKSOBJECT_CREATE_ITEM CreateItem
;
68 PIO_STACK_LOCATION IoStack
;
69 PGENERIC_MAPPING Mapping
;
70 PSECURITY_DESCRIPTOR Descriptor
;
73 /* get current irp stack */
74 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
77 CreateItem
= KSCREATE_ITEM_IRP_STORAGE(Irp
);
79 if (!CreateItem
|| !CreateItem
->SecurityDescriptor
)
82 Irp
->IoStatus
.Status
= STATUS_NO_SECURITY_ON_OBJECT
;
83 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
84 return STATUS_NO_SECURITY_ON_OBJECT
;
87 /* backup old descriptor */
88 Descriptor
= CreateItem
->SecurityDescriptor
;
90 /* get generic mapping */
91 Mapping
= IoGetFileObjectGenericMapping();
93 /* change security descriptor */
94 Status
= SeSetSecurityDescriptorInfo(NULL
, /*FIXME */
95 &IoStack
->Parameters
.SetSecurity
.SecurityInformation
,
96 IoStack
->Parameters
.SetSecurity
.SecurityDescriptor
,
97 &CreateItem
->SecurityDescriptor
,
101 if (NT_SUCCESS(Status
))
103 /* free old descriptor */
104 ExFreePool(Descriptor
);
106 /* mark create item as changed */
107 CreateItem
->Flags
|= KSCREATE_ITEM_SECURITYCHANGED
;
111 Irp
->IoStatus
.Status
= Status
;
112 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
123 KsDispatchSpecificMethod(
125 IN PFNKSHANDLER Handler
)
128 return STATUS_UNSUCCESSFUL
;
139 IN PFILE_OBJECT FileObject
,
140 IN PKEVENT Event OPTIONAL
,
141 IN PVOID PortContext OPTIONAL
,
142 OUT PIO_STATUS_BLOCK IoStatusBlock
,
145 IN ULONG Key OPTIONAL
,
146 IN KPROCESSOR_MODE RequestorMode
)
148 PDEVICE_OBJECT DeviceObject
;
156 /* make sure event is reset */
160 if (RequestorMode
== UserMode
)
162 /* probe the user buffer */
165 ProbeForWrite(Buffer
, Length
, sizeof(UCHAR
));
166 Status
= STATUS_SUCCESS
;
168 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
170 /* Exception, get the error code */
171 Status
= _SEH2_GetExceptionCode();
175 if (!NT_SUCCESS(Status
))
177 DPRINT1("Invalid user buffer provided\n");
182 /* get corresponding device object */
183 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
185 /* fast-io read is only available for kernel mode clients */
186 if (RequestorMode
== KernelMode
&& ExGetPreviousMode() == KernelMode
&&
187 DeviceObject
->DriverObject
->FastIoDispatch
->FastIoRead
)
189 /* call fast io write */
190 Result
= DeviceObject
->DriverObject
->FastIoDispatch
->FastIoRead(FileObject
, &FileObject
->CurrentByteOffset
, Length
, TRUE
, Key
, Buffer
, IoStatusBlock
, DeviceObject
);
192 if (Result
&& NT_SUCCESS(IoStatusBlock
->Status
))
194 /* request was handeled and succeeded */
195 return STATUS_SUCCESS
;
199 /* do the slow way */
202 /* initialize temp event */
203 KeInitializeEvent(&LocalEvent
, NotificationEvent
, FALSE
);
207 /* build the irp packet */
208 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
, DeviceObject
, Buffer
, Length
, &FileObject
->CurrentByteOffset
, Event
, IoStatusBlock
);
211 /* not enough resources */
212 return STATUS_INSUFFICIENT_RESOURCES
;
215 /* send the packet */
216 Status
= IoCallDriver(DeviceObject
, Irp
);
218 if (Status
== STATUS_PENDING
)
220 /* operation is pending, is sync file object */
221 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
224 KeWaitForSingleObject(Event
, Executive
, RequestorMode
, FALSE
, NULL
);
225 Status
= IoStatusBlock
->Status
;
239 IN PFILE_OBJECT FileObject
,
240 IN PKEVENT Event OPTIONAL
,
241 IN PVOID PortContext OPTIONAL
,
242 OUT PIO_STATUS_BLOCK IoStatusBlock
,
245 IN ULONG Key OPTIONAL
,
246 IN KPROCESSOR_MODE RequestorMode
)
248 PDEVICE_OBJECT DeviceObject
;
256 /* make sure event is reset */
260 if (RequestorMode
== UserMode
)
262 /* probe the user buffer */
265 ProbeForRead(Buffer
, Length
, sizeof(UCHAR
));
266 Status
= STATUS_SUCCESS
;
268 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
270 /* Exception, get the error code */
271 Status
= _SEH2_GetExceptionCode();
275 if (!NT_SUCCESS(Status
))
277 DPRINT1("Invalid user buffer provided\n");
282 /* get corresponding device object */
283 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
285 /* fast-io write is only available for kernel mode clients */
286 if (RequestorMode
== KernelMode
&& ExGetPreviousMode() == KernelMode
&&
287 DeviceObject
->DriverObject
->FastIoDispatch
->FastIoWrite
)
289 /* call fast io write */
290 Result
= DeviceObject
->DriverObject
->FastIoDispatch
->FastIoWrite(FileObject
, &FileObject
->CurrentByteOffset
, Length
, TRUE
, Key
, Buffer
, IoStatusBlock
, DeviceObject
);
292 if (Result
&& NT_SUCCESS(IoStatusBlock
->Status
))
294 /* request was handeled and succeeded */
295 return STATUS_SUCCESS
;
299 /* do the slow way */
302 /* initialize temp event */
303 KeInitializeEvent(&LocalEvent
, NotificationEvent
, FALSE
);
307 /* build the irp packet */
308 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_WRITE
, DeviceObject
, Buffer
, Length
, &FileObject
->CurrentByteOffset
, Event
, IoStatusBlock
);
311 /* not enough resources */
312 return STATUS_INSUFFICIENT_RESOURCES
;
315 /* send the packet */
316 Status
= IoCallDriver(DeviceObject
, Irp
);
318 if (Status
== STATUS_PENDING
)
320 /* operation is pending, is sync file object */
321 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
324 KeWaitForSingleObject(Event
, Executive
, RequestorMode
, FALSE
, NULL
);
325 Status
= IoStatusBlock
->Status
;
338 KsQueryInformationFile(
339 IN PFILE_OBJECT FileObject
,
340 OUT PVOID FileInformation
,
342 IN FILE_INFORMATION_CLASS FileInformationClass
)
344 PDEVICE_OBJECT DeviceObject
;
345 PFAST_IO_DISPATCH FastIoDispatch
;
347 PIO_STACK_LOCATION IoStack
;
348 IO_STATUS_BLOCK IoStatus
;
350 LARGE_INTEGER Offset
;
351 IO_STATUS_BLOCK StatusBlock
;
354 /* get related file object */
355 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
357 /* get fast i/o table */
358 FastIoDispatch
= DeviceObject
->DriverObject
->FastIoDispatch
;
360 /* is there a fast table */
363 /* check the class */
364 if (FileInformationClass
== FileBasicInformation
)
366 /* use FastIoQueryBasicInfo routine */
367 if (FastIoDispatch
->FastIoQueryBasicInfo
)
369 return FastIoDispatch
->FastIoQueryBasicInfo(FileObject
, TRUE
, (PFILE_BASIC_INFORMATION
)FileInformation
, &IoStatus
, DeviceObject
);
372 else if (FileInformationClass
== FileStandardInformation
)
374 /* use FastIoQueryBasicInfo routine */
375 if (FastIoDispatch
->FastIoQueryBasicInfo
)
377 return FastIoDispatch
->FastIoQueryStandardInfo(FileObject
, TRUE
, (PFILE_STANDARD_INFORMATION
)FileInformation
, &IoStatus
, DeviceObject
);
382 KeClearEvent(&FileObject
->Event
);
384 /* initialize event */
385 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
387 /* set offset to zero */
388 Offset
.QuadPart
= 0L;
390 /* build the request */
391 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_QUERY_INFORMATION
, IoGetRelatedDeviceObject(FileObject
), NULL
, 0, &Offset
, &Event
, &StatusBlock
);
394 return STATUS_INSUFFICIENT_RESOURCES
;
396 /* get next stack location */
397 IoStack
= IoGetNextIrpStackLocation(Irp
);
399 /* setup parameters */
400 IoStack
->Parameters
.QueryFile
.FileInformationClass
= FileInformationClass
;
401 IoStack
->Parameters
.QueryFile
.Length
= Length
;
402 Irp
->AssociatedIrp
.SystemBuffer
= FileInformation
;
405 /* call the driver */
406 Status
= IoCallDriver(IoGetRelatedDeviceObject(FileObject
), Irp
);
408 if (Status
== STATUS_PENDING
)
410 /* wait for the operation to complete */
411 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
414 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
415 Status
= FileObject
->FinalStatus
;
417 Status
= StatusBlock
.Status
;
430 KsSetInformationFile(
431 IN PFILE_OBJECT FileObject
,
432 IN PVOID FileInformation
,
434 IN FILE_INFORMATION_CLASS FileInformationClass
)
436 PIO_STACK_LOCATION IoStack
;
437 PDEVICE_OBJECT DeviceObject
;
441 LARGE_INTEGER Offset
;
442 IO_STATUS_BLOCK IoStatus
;
445 /* get related device object */
446 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
448 /* copy file information */
449 Buffer
= AllocateItem(NonPagedPool
, Length
);
451 return STATUS_INSUFFICIENT_RESOURCES
;
455 ProbeForRead(Buffer
, Length
, sizeof(UCHAR
));
456 RtlMoveMemory(Buffer
, FileInformation
, Length
);
457 Status
= STATUS_SUCCESS
;
459 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
461 /* Exception, get the error code */
462 Status
= _SEH2_GetExceptionCode();
466 if (!NT_SUCCESS(Status
))
468 /* invalid user buffer */
473 /* initialize the event */
474 KeInitializeEvent(&Event
, SynchronizationEvent
, FALSE
);
477 Offset
.QuadPart
= 0LL;
480 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_SET_INFORMATION
, DeviceObject
, NULL
, 0, &Offset
, &Event
, &IoStatus
);
484 /* failed to allocate irp */
486 return STATUS_INSUFFICIENT_RESOURCES
;
489 /* get next stack location */
490 IoStack
= IoGetNextIrpStackLocation(Irp
);
492 /* set irp parameters */
493 IoStack
->Parameters
.SetFile
.FileInformationClass
= FileInformationClass
;
494 IoStack
->Parameters
.SetFile
.Length
= Length
;
495 IoStack
->Parameters
.SetFile
.FileObject
= FileObject
;
496 Irp
->AssociatedIrp
.SystemBuffer
= Buffer
;
497 Irp
->UserBuffer
= FileInformation
;
499 /* dispatch the irp */
500 Status
= IoCallDriver(DeviceObject
, Irp
);
502 if (Status
== STATUS_PENDING
)
504 /* wait untill the operation has completed */
505 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
506 /* is a sync file object */
507 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
508 Status
= FileObject
->FinalStatus
;
510 Status
= IoStatus
.Status
;
523 IN PFILE_OBJECT FileObject
,
524 IN PKEVENT Event OPTIONAL
,
525 IN PVOID PortContext OPTIONAL
,
526 IN PIO_COMPLETION_ROUTINE CompletionRoutine OPTIONAL
,
527 IN PVOID CompletionContext OPTIONAL
,
528 IN KSCOMPLETION_INVOCATION CompletionInvocationFlags OPTIONAL
,
529 OUT PIO_STATUS_BLOCK IoStatusBlock
,
530 IN OUT PVOID StreamHeaders
,
533 IN KPROCESSOR_MODE RequestorMode
)
536 PIO_STACK_LOCATION IoStack
;
537 PDEVICE_OBJECT DeviceObject
;
539 LARGE_INTEGER Offset
;
540 PKSIOBJECT_HEADER ObjectHeader
;
543 /* get related device object */
544 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
546 ASSERT(DeviceObject
!= NULL
);
548 /* is there a event provided */
555 if (RequestorMode
|| ExGetPreviousMode() == KernelMode
)
557 /* requestor is from kernel land */
558 ObjectHeader
= (PKSIOBJECT_HEADER
)FileObject
->FsContext2
;
562 /* there is a object header */
563 if (Flags
== KSSTREAM_READ
)
565 /* is fast read supported */
566 if (ObjectHeader
->DispatchTable
.FastRead
)
568 /* call fast read dispatch routine */
569 Ret
= ObjectHeader
->DispatchTable
.FastRead(FileObject
, NULL
, Length
, FALSE
, 0, StreamHeaders
, IoStatusBlock
, DeviceObject
);
573 /* the request was handeled */
574 return IoStatusBlock
->Status
;
578 else if (Flags
== KSSTREAM_WRITE
)
580 /* is fast write supported */
581 if (ObjectHeader
->DispatchTable
.FastWrite
)
583 /* call fast write dispatch routine */
584 Ret
= ObjectHeader
->DispatchTable
.FastWrite(FileObject
, NULL
, Length
, FALSE
, 0, StreamHeaders
, IoStatusBlock
, DeviceObject
);
588 /* the request was handeled */
589 return IoStatusBlock
->Status
;
596 /* clear file object event */
597 KeClearEvent(&FileObject
->Event
);
599 /* set the offset to zero */
600 Offset
.QuadPart
= 0LL;
602 /* now build the irp */
603 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_DEVICE_CONTROL
,
604 DeviceObject
, (PVOID
)StreamHeaders
, Length
, &Offset
, Event
, IoStatusBlock
);
607 /* not enough memory */
608 return STATUS_INSUFFICIENT_RESOURCES
;
611 /* setup irp parameters */
612 Irp
->RequestorMode
= RequestorMode
;
613 Irp
->Overlay
.AsynchronousParameters
.UserApcContext
= PortContext
;
614 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
615 Irp
->UserBuffer
= StreamHeaders
;
617 /* get next irp stack location */
618 IoStack
= IoGetNextIrpStackLocation(Irp
);
619 /* setup stack parameters */
620 IoStack
->FileObject
= FileObject
;
621 IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
= Length
;
622 IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
= StreamHeaders
;
623 IoStack
->Parameters
.DeviceIoControl
.IoControlCode
= (Flags
== KSSTREAM_READ
? IOCTL_KS_READ_STREAM
: IOCTL_KS_WRITE_STREAM
);
625 if (CompletionRoutine
)
627 /* setup completion routine for async processing */
628 IoSetCompletionRoutine(Irp
, CompletionRoutine
, CompletionContext
, (CompletionInvocationFlags
& KsInvokeOnSuccess
), (CompletionInvocationFlags
& KsInvokeOnError
), (CompletionInvocationFlags
& KsInvokeOnCancel
));
631 /* now call the driver */
632 Status
= IoCallDriver(DeviceObject
, Irp
);
650 LOCK_OPERATION Operation
;
651 NTSTATUS Status
= STATUS_SUCCESS
;
652 PKSSTREAM_HEADER StreamHeader
;
653 PIO_STACK_LOCATION IoStack
;
655 BOOLEAN AllocateMdl
= FALSE
;
657 /* get current irp stack */
658 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
660 Length
= IoStack
->Parameters
.DeviceIoControl
.OutputBufferLength
;
662 if (Irp
->RequestorMode
== KernelMode
|| Irp
->AssociatedIrp
.SystemBuffer
)
665 /* check if alloc mdl flag is passed */
666 if (!(ProbeFlags
& KSPROBE_ALLOCATEMDL
))
668 /* nothing more to do */
669 return STATUS_SUCCESS
;
674 if (ProbeFlags
& KSPROBE_PROBEANDLOCK
)
676 if (Irp
->MdlAddress
->MdlFlags
& (MDL_PAGES_LOCKED
| MDL_SOURCE_IS_NONPAGED_POOL
))
678 if (ProbeFlags
& KSPROBE_SYSTEMADDRESS
)
682 /* loop through all mdls and probe them */
683 Mdl
= Irp
->MdlAddress
;
686 /* the mapping can fail */
687 Mdl
->MdlFlags
|= MDL_MAPPING_CAN_FAIL
;
689 if (Mdl
->MdlFlags
& (MDL_MAPPED_TO_SYSTEM_VA
| MDL_SOURCE_IS_NONPAGED_POOL
))
691 /* no need to probe these pages */
692 Buffer
= Mdl
->MappedSystemVa
;
697 Buffer
= MmMapLockedPages(Mdl
, KernelMode
);
700 /* check if the mapping succeeded */
703 /* raise exception we'll catch */
704 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
707 /* iterate to next mdl */
712 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
714 /* Exception, get the error code */
715 Status
= _SEH2_GetExceptionCode();
723 /* loop through all mdls and probe them */
724 Mdl
= Irp
->MdlAddress
;
726 /* determine operation */
727 Operation
= (ProbeFlags
& KSPROBE_STREAMWRITE
) ? IoWriteAccess
: IoReadAccess
;
731 /* probe the pages */
732 MmProbeAndLockPages(Mdl
, Irp
->RequestorMode
, Operation
);
734 if (ProbeFlags
& KSPROBE_SYSTEMADDRESS
)
736 /* the mapping can fail */
737 Mdl
->MdlFlags
|= MDL_MAPPING_CAN_FAIL
;
739 if (Mdl
->MdlFlags
& (MDL_MAPPED_TO_SYSTEM_VA
| MDL_SOURCE_IS_NONPAGED_POOL
))
741 /* no need to probe these pages */
742 Buffer
= Mdl
->MappedSystemVa
;
747 Buffer
= MmMapLockedPages(Mdl
, KernelMode
);
750 /* check if the mapping succeeded */
753 /* raise exception we'll catch */
754 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
758 /* iterate to next mdl */
763 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
765 /* Exception, get the error code */
766 Status
= _SEH2_GetExceptionCode();
773 /* check all stream headers */
774 StreamHeader
= (PKSSTREAM_HEADER
)Irp
->AssociatedIrp
.SystemBuffer
;
782 /* does the supplied header size match stream header size and no type changed */
783 if (StreamHeader
->Size
!= HeaderSize
&& !(StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
))
785 /* invalid stream header */
786 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
791 /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
792 if (StreamHeader
->Size
< sizeof(KSSTREAM_HEADER
) || (StreamHeader
->Size
& 7))
794 /* invalid stream header */
795 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
799 if (Length
< StreamHeader
->Size
)
801 /* length is too short */
802 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
805 if (ProbeFlags
& KSPROBE_STREAMWRITE
)
807 if (StreamHeader
->DataUsed
> StreamHeader
->FrameExtent
)
809 /* frame extend can never be smaller */
810 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
813 /* is this stream change packet */
814 if (StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
)
816 if (Length
!= sizeof(KSSTREAM_HEADER
) || (PVOID
)StreamHeader
!= Irp
->AssociatedIrp
.SystemBuffer
)
818 /* stream changed - must be send in a single packet */
819 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
822 if (!(ProbeFlags
& KSPROBE_ALLOWFORMATCHANGE
))
824 /* caller does not permit format changes */
825 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
828 if (StreamHeader
->FrameExtent
)
830 /* allocate an mdl */
831 Mdl
= IoAllocateMdl(StreamHeader
->Data
, StreamHeader
->FrameExtent
, FALSE
, TRUE
, Irp
);
835 /* not enough memory */
836 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
839 /* break-out to probe for the irp */
846 if (StreamHeader
->DataUsed
)
848 /* DataUsed must be zero for stream read operation */
849 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
852 if (StreamHeader
->OptionsFlags
)
854 /* no flags supported for reading */
855 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
859 if (StreamHeader
->FrameExtent
)
861 /* allocate an mdl */
862 Mdl
= IoAllocateMdl(StreamHeader
->Data
, StreamHeader
->FrameExtent
, Irp
->MdlAddress
!= NULL
, TRUE
, Irp
);
865 /* not enough memory */
866 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
870 /* move to next stream header */
871 Length
-= StreamHeader
->Size
;
872 StreamHeader
= (PKSSTREAM_HEADER
)((ULONG_PTR
)StreamHeader
+ StreamHeader
->Size
);
875 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
877 /* Exception, get the error code */
878 Status
= _SEH2_GetExceptionCode();
881 /* now probe the allocated mdl's */
882 if (!NT_SUCCESS(Status
))
888 /* probe user mode buffers */
889 if (Length
&& ( (!HeaderSize
) || (Length
% HeaderSize
== 0) || ((ProbeFlags
& KSPROBE_ALLOWFORMATCHANGE
) && (Length
== sizeof(KSSTREAM_HEADER
))) ) )
891 /* allocate stream header buffer */
892 Irp
->AssociatedIrp
.SystemBuffer
= ExAllocatePool(NonPagedPool
, Length
);
894 if (!Irp
->AssociatedIrp
.SystemBuffer
)
897 return STATUS_INSUFFICIENT_RESOURCES
;
902 if (ProbeFlags
& KSPROBE_STREAMWRITE
)
904 if (ProbeFlags
& KSPROBE_MODIFY
)
905 ProbeForWrite(Irp
->UserBuffer
, Length
, sizeof(UCHAR
));
907 ProbeForRead(Irp
->UserBuffer
, Length
, sizeof(UCHAR
));
911 /* stream reads means writing */
912 ProbeForWrite(Irp
->UserBuffer
, Length
, sizeof(UCHAR
));
915 /* copy stream buffer */
916 RtlMoveMemory(Irp
->AssociatedIrp
.SystemBuffer
, Irp
->UserBuffer
, Length
);
918 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
920 /* Exception, get the error code */
921 Status
= _SEH2_GetExceptionCode();
924 if (!NT_SUCCESS(Status
))
930 if (ProbeFlags
& KSPROBE_ALLOCATEMDL
)
936 /* check all stream headers */
937 StreamHeader
= (PKSSTREAM_HEADER
)Irp
->AssociatedIrp
.SystemBuffer
;
945 /* does the supplied header size match stream header size and no type changed */
946 if (StreamHeader
->Size
!= HeaderSize
&& !(StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
))
948 /* invalid stream header */
949 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
954 /* stream must be at least of size KSSTREAM_HEADER and size must be 8-byte block aligned */
955 if (StreamHeader
->Size
< sizeof(KSSTREAM_HEADER
) || (StreamHeader
->Size
& 7))
957 /* invalid stream header */
958 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
962 if (Length
< StreamHeader
->Size
)
964 /* length is too short */
965 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
968 if (ProbeFlags
& KSPROBE_STREAMWRITE
)
970 if (StreamHeader
->DataUsed
> StreamHeader
->FrameExtent
)
972 /* frame extend can never be smaller */
973 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
976 /* is this stream change packet */
977 if (StreamHeader
->OptionsFlags
& KSSTREAM_HEADER_OPTIONSF_TYPECHANGED
)
979 if (Length
!= sizeof(KSSTREAM_HEADER
) || (PVOID
)StreamHeader
!= Irp
->AssociatedIrp
.SystemBuffer
)
981 /* stream changed - must be send in a single packet */
982 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
985 if (!(ProbeFlags
& KSPROBE_ALLOWFORMATCHANGE
))
987 /* caller does not permit format changes */
988 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
991 if (StreamHeader
->FrameExtent
)
993 /* allocate an mdl */
994 Mdl
= IoAllocateMdl(StreamHeader
->Data
, StreamHeader
->FrameExtent
, FALSE
, TRUE
, Irp
);
998 /* not enough memory */
999 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES
);
1002 /* break out to probe for the irp */
1010 if (StreamHeader
->DataUsed
)
1012 /* DataUsed must be zero for stream read operation */
1013 ExRaiseStatus(STATUS_INVALID_BUFFER_SIZE
);
1016 if (StreamHeader
->OptionsFlags
)
1018 /* no flags supported for reading */
1019 ExRaiseStatus(STATUS_INVALID_PARAMETER
);
1023 /* move to next stream header */
1024 Length
-= StreamHeader
->Size
;
1025 StreamHeader
= (PKSSTREAM_HEADER
)((ULONG_PTR
)StreamHeader
+ StreamHeader
->Size
);
1028 }_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1030 /* Exception, get the error code */
1031 Status
= _SEH2_GetExceptionCode();
1034 /* now probe the allocated mdl's */
1035 if (NT_SUCCESS(Status
))
1041 return STATUS_INVALID_BUFFER_SIZE
;
1050 KsAllocateExtraData(
1053 OUT PVOID
* ExtraBuffer
)
1055 PIO_STACK_LOCATION IoStack
;
1057 PUCHAR Buffer
, BufferOrg
;
1058 PKSSTREAM_HEADER Header
;
1059 NTSTATUS Status
= STATUS_SUCCESS
;
1061 /* get current irp stack */
1062 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1065 ASSERT(IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
>= sizeof(KSSTREAM_HEADER
));
1067 /* get total length */
1068 Count
= IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
/ sizeof(KSSTREAM_HEADER
);
1070 /* allocate buffer */
1071 Buffer
= BufferOrg
= AllocateItem(NonPagedPool
, Count
* (sizeof(KSSTREAM_HEADER
) + ExtraSize
));
1073 return STATUS_INSUFFICIENT_RESOURCES
;
1077 /* get input buffer */
1078 Header
= (PKSSTREAM_HEADER
)IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
1079 for(Index
= 0; Index
< Count
; Index
++)
1081 /* copy stream header */
1082 RtlMoveMemory(Buffer
, Header
, sizeof(KSSTREAM_HEADER
));
1084 /* move to next header */
1086 /* increment output buffer offset */
1087 Buffer
+= sizeof(KSSTREAM_HEADER
) + ExtraSize
;
1090 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1092 /* Exception, get the error code */
1093 Status
= _SEH2_GetExceptionCode();
1097 if (!NT_SUCCESS(Status
))
1099 /* free buffer on exception */
1105 *ExtraBuffer
= BufferOrg
;
1108 return STATUS_SUCCESS
;
1118 IN PDRIVER_OBJECT DriverObject
)
1128 KsDispatchInvalidDeviceRequest(
1129 IN PDEVICE_OBJECT DeviceObject
,
1132 Irp
->IoStatus
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
1133 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1135 return STATUS_INVALID_DEVICE_REQUEST
;
1144 KsDefaultDeviceIoCompletion(
1145 IN PDEVICE_OBJECT DeviceObject
,
1148 PIO_STACK_LOCATION IoStack
;
1151 /* get current irp stack */
1152 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1154 if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_KS_PROPERTY
&&
1155 IoStack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_KS_METHOD
&&
1156 IoStack
->Parameters
.DeviceIoControl
.IoControlCode
!= IOCTL_KS_PROPERTY
)
1158 if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_KS_RESET_STATE
)
1161 Status
= STATUS_SUCCESS
;
1165 /* request unsupported */
1166 Status
= STATUS_INVALID_DEVICE_REQUEST
;
1171 /* property / method / event not found */
1172 Status
= STATUS_PROPSET_NOT_FOUND
;
1175 /* complete request */
1176 Irp
->IoStatus
.Status
= Status
;
1177 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1189 KsDispatchFastIoDeviceControlFailure(
1190 IN PFILE_OBJECT FileObject
,
1192 IN PVOID InputBuffer OPTIONAL
,
1193 IN ULONG InputBufferLength
,
1194 OUT PVOID OutputBuffer OPTIONAL
,
1195 IN ULONG OutputBufferLength
,
1196 IN ULONG IoControlCode
,
1197 OUT PIO_STATUS_BLOCK IoStatus
,
1198 IN PDEVICE_OBJECT DeviceObject
)
1209 KsDispatchFastReadFailure(
1210 IN PFILE_OBJECT FileObject
,
1211 IN PLARGE_INTEGER FileOffset
,
1216 OUT PIO_STATUS_BLOCK IoStatus
,
1217 IN PDEVICE_OBJECT DeviceObject
)
1230 IN OUT PLIST_ENTRY QueueHead
,
1231 IN PKSPIN_LOCK SpinLock
)
1233 PDRIVER_CANCEL OldDriverCancel
;
1234 PIO_STACK_LOCATION IoStack
;
1239 /* acquire spinlock */
1240 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1241 /* point to first entry */
1242 Entry
= QueueHead
->Flink
;
1243 /* loop all items */
1244 while(Entry
!= QueueHead
)
1246 /* get irp offset */
1247 Irp
= (PIRP
)CONTAINING_RECORD(Entry
, IRP
, Tail
.Overlay
.ListEntry
);
1249 /* set cancelled bit */
1252 /* now set the cancel routine */
1253 OldDriverCancel
= IoSetCancelRoutine(Irp
, NULL
);
1254 if (OldDriverCancel
)
1256 /* this irp hasnt been yet used, so free to cancel */
1257 KeReleaseSpinLock(SpinLock
, OldLevel
);
1259 /* get current irp stack */
1260 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1262 /* acquire cancel spinlock */
1263 IoAcquireCancelSpinLock(&Irp
->CancelIrql
);
1265 /* call provided cancel routine */
1266 OldDriverCancel(IoStack
->DeviceObject
, Irp
);
1268 /* re-acquire spinlock */
1269 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1271 /* move on to next entry */
1272 Entry
= Entry
->Flink
;
1275 /* the irp has already been canceled */
1276 KeReleaseSpinLock(SpinLock
, OldLevel
);
1286 KsReleaseIrpOnCancelableQueue(
1288 IN PDRIVER_CANCEL DriverCancel OPTIONAL
)
1290 PKSPIN_LOCK SpinLock
;
1291 PDRIVER_CANCEL OldDriverCancel
;
1292 PIO_STACK_LOCATION IoStack
;
1295 /* check for required parameters */
1301 /* default to KsCancelRoutine */
1302 DriverCancel
= KsCancelRoutine
;
1305 /* get current irp stack */
1306 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1308 /* get internal queue lock */
1309 SpinLock
= KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
);
1311 /* acquire spinlock */
1312 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1314 /* now set the cancel routine */
1315 OldDriverCancel
= IoSetCancelRoutine(Irp
, DriverCancel
);
1317 if (Irp
->Cancel
&& OldDriverCancel
== NULL
)
1319 /* the irp has already been canceled */
1320 KeReleaseSpinLock(SpinLock
, OldLevel
);
1322 /* cancel routine requires that cancel spinlock is held */
1323 IoAcquireCancelSpinLock(&Irp
->CancelIrql
);
1326 DriverCancel(IoStack
->DeviceObject
, Irp
);
1331 KeReleaseSpinLock(SpinLock
, OldLevel
);
1341 KsRemoveIrpFromCancelableQueue(
1342 IN OUT PLIST_ENTRY QueueHead
,
1343 IN PKSPIN_LOCK SpinLock
,
1344 IN KSLIST_ENTRY_LOCATION ListLocation
,
1345 IN KSIRP_REMOVAL_OPERATION RemovalOperation
)
1348 PLIST_ENTRY CurEntry
;
1351 DPRINT("KsRemoveIrpFromCancelableQueue ListHead %p SpinLock %p ListLocation %x RemovalOperation %x\n", QueueHead
, SpinLock
, ListLocation
, RemovalOperation
);
1353 /* check parameters */
1354 if (!QueueHead
|| !SpinLock
)
1357 /* check if parameter ListLocation is valid */
1358 if (ListLocation
!= KsListEntryTail
&& ListLocation
!= KsListEntryHead
)
1361 /* acquire list lock */
1362 KeAcquireSpinLock(SpinLock
, &OldIrql
);
1364 /* point to queue head */
1365 CurEntry
= QueueHead
;
1369 /* reset irp to null */
1372 /* iterate to next entry */
1373 if (ListLocation
== KsListEntryHead
)
1374 CurEntry
= CurEntry
->Flink
;
1376 CurEntry
= CurEntry
->Blink
;
1378 /* is the end of list reached */
1379 if (CurEntry
== QueueHead
)
1381 /* reached end of list */
1385 /* get irp offset */
1386 Irp
= (PIRP
)CONTAINING_RECORD(CurEntry
, IRP
, Tail
.Overlay
.ListEntry
);
1390 /* irp has been canceled */
1394 if (Irp
->CancelRoutine
)
1396 /* remove cancel routine */
1397 Irp
->CancelRoutine
= NULL
;
1399 if (RemovalOperation
== KsAcquireAndRemove
|| RemovalOperation
== KsAcquireAndRemoveOnlySingleItem
)
1401 /* remove irp from list */
1402 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1405 if (RemovalOperation
== KsAcquireAndRemoveOnlySingleItem
|| RemovalOperation
== KsAcquireOnlySingleItem
)
1412 KeReleaseSpinLock(SpinLock
, OldIrql
);
1414 if (!Irp
|| Irp
->CancelRoutine
== NULL
)
1416 /* either an irp has been acquired or nothing found */
1420 /* time to remove the canceled irp */
1421 IoAcquireCancelSpinLock(&OldIrql
);
1422 /* acquire list lock */
1423 KeAcquireSpinLockAtDpcLevel(SpinLock
);
1425 if (RemovalOperation
== KsAcquireAndRemove
|| RemovalOperation
== KsAcquireAndRemoveOnlySingleItem
)
1428 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1431 /* release list lock */
1432 KeReleaseSpinLockFromDpcLevel(SpinLock
);
1434 /* release cancel spinlock */
1435 IoReleaseCancelSpinLock(OldIrql
);
1436 /* no non canceled irp has been found */
1446 KsMoveIrpsOnCancelableQueue(
1447 IN OUT PLIST_ENTRY SourceList
,
1448 IN PKSPIN_LOCK SourceLock
,
1449 IN OUT PLIST_ENTRY DestinationList
,
1450 IN PKSPIN_LOCK DestinationLock OPTIONAL
,
1451 IN KSLIST_ENTRY_LOCATION ListLocation
,
1452 IN PFNKSIRPLISTCALLBACK ListCallback
,
1456 PLIST_ENTRY SrcEntry
;
1458 NTSTATUS Status
= STATUS_SUCCESS
;
1460 if (!DestinationLock
)
1462 /* no destination lock just acquire the source lock */
1463 KeAcquireSpinLock(SourceLock
, &OldLevel
);
1467 /* acquire cancel spinlock */
1468 IoAcquireCancelSpinLock(&OldLevel
);
1470 /* now acquire source lock */
1471 KeAcquireSpinLockAtDpcLevel(SourceLock
);
1473 /* now acquire destination lock */
1474 KeAcquireSpinLockAtDpcLevel(DestinationLock
);
1477 /* point to list head */
1478 SrcEntry
= SourceList
;
1480 /* now move all irps */
1483 if (ListLocation
== KsListEntryTail
)
1485 /* move queue downwards */
1486 SrcEntry
= SrcEntry
->Flink
;
1490 /* move queue upwards */
1491 SrcEntry
= SrcEntry
->Blink
;
1494 if (SrcEntry
== SourceList
)
1496 /* eof list reached */
1500 /* get irp offset */
1501 Irp
= (PIRP
)CONTAINING_RECORD(SrcEntry
, IRP
, Tail
.Overlay
.ListEntry
);
1503 /* now check if irp can be moved */
1504 Status
= ListCallback(Irp
, Context
);
1506 /* check if irp can be moved */
1507 if (Status
== STATUS_SUCCESS
)
1509 /* remove irp from src list */
1510 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1512 if (ListLocation
== KsListEntryTail
)
1514 /* insert irp end of list */
1515 InsertTailList(DestinationList
, &Irp
->Tail
.Overlay
.ListEntry
);
1519 /* insert irp head of list */
1520 InsertHeadList(DestinationList
, &Irp
->Tail
.Overlay
.ListEntry
);
1523 /* do we need to update the irp lock */
1524 if (DestinationLock
)
1526 /* update irp lock */
1527 KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
) = DestinationLock
;
1532 if (Status
!= STATUS_NO_MATCH
)
1534 /* callback decided to stop enumeration */
1538 /* reset return value */
1539 Status
= STATUS_SUCCESS
;
1543 if (!DestinationLock
)
1545 /* release source lock */
1546 KeReleaseSpinLock(SourceLock
, OldLevel
);
1550 /* now release destination lock */
1551 KeReleaseSpinLockFromDpcLevel(DestinationLock
);
1553 /* now release source lock */
1554 KeReleaseSpinLockFromDpcLevel(SourceLock
);
1557 /* now release cancel spinlock */
1558 IoReleaseCancelSpinLock(OldLevel
);
1571 KsRemoveSpecificIrpFromCancelableQueue(
1574 PKSPIN_LOCK SpinLock
;
1577 DPRINT("KsRemoveSpecificIrpFromCancelableQueue %p\n", Irp
);
1579 /* get internal queue lock */
1580 SpinLock
= KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
);
1582 /* acquire spinlock */
1583 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1585 /* remove the irp from the list */
1586 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1588 /* release spinlock */
1589 KeReleaseSpinLock(SpinLock
, OldLevel
);
1599 KsAddIrpToCancelableQueue(
1600 IN OUT PLIST_ENTRY QueueHead
,
1601 IN PKSPIN_LOCK SpinLock
,
1603 IN KSLIST_ENTRY_LOCATION ListLocation
,
1604 IN PDRIVER_CANCEL DriverCancel OPTIONAL
)
1606 PDRIVER_CANCEL OldDriverCancel
;
1607 PIO_STACK_LOCATION IoStack
;
1610 DPRINT1("KsAddIrpToCancelableQueue QueueHead %p SpinLock %p Irp %p ListLocation %x DriverCancel %p\n", QueueHead
, SpinLock
, Irp
, ListLocation
, DriverCancel
);
1611 /* check for required parameters */
1612 if (!QueueHead
|| !SpinLock
|| !Irp
)
1617 /* default to KsCancelRoutine */
1618 DriverCancel
= KsCancelRoutine
;
1621 /* get current irp stack */
1622 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1624 /* acquire spinlock */
1625 KeAcquireSpinLock(SpinLock
, &OldLevel
);
1627 if (ListLocation
== KsListEntryTail
)
1629 /* insert irp to tail of list */
1630 InsertTailList(QueueHead
, &Irp
->Tail
.Overlay
.ListEntry
);
1634 /* insert irp to head of list */
1635 InsertHeadList(QueueHead
, &Irp
->Tail
.Overlay
.ListEntry
);
1638 /* store internal queue lock */
1639 KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
) = SpinLock
;
1641 /* now set the cancel routine */
1642 OldDriverCancel
= IoSetCancelRoutine(Irp
, DriverCancel
);
1644 if (Irp
->Cancel
&& OldDriverCancel
== NULL
)
1646 /* the irp has already been canceled */
1647 KeReleaseSpinLock(SpinLock
, OldLevel
);
1649 /* cancel routine requires that cancel spinlock is held */
1650 IoAcquireCancelSpinLock(&Irp
->CancelIrql
);
1653 DriverCancel(IoStack
->DeviceObject
, Irp
);
1658 KeReleaseSpinLock(SpinLock
, OldLevel
);
1669 IN PDEVICE_OBJECT DeviceObject
,
1672 PKSPIN_LOCK SpinLock
;
1674 /* get internal queue lock */
1675 SpinLock
= KSQUEUE_SPINLOCK_IRP_STORAGE(Irp
);
1677 /* acquire spinlock */
1678 KeAcquireSpinLockAtDpcLevel(SpinLock
);
1681 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
1683 /* release cancel spinlock */
1684 IoReleaseCancelSpinLock(Irp
->CancelIrql
);
1686 /* remove the irp from the list */
1687 RemoveEntryList(&Irp
->Tail
.Overlay
.ListEntry
);
1689 /* release spinlock */
1690 KeReleaseSpinLockFromDpcLevel(SpinLock
);
1692 /* has the irp already been canceled */
1693 if (Irp
->IoStatus
.Status
!= STATUS_CANCELLED
)
1695 /* let's complete it */
1696 Irp
->IoStatus
.Status
= STATUS_CANCELLED
;
1697 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1702 FindMatchingCreateItem(
1703 PLIST_ENTRY ListHead
,
1706 OUT PCREATE_ITEM_ENTRY
*OutCreateItem
)
1709 PCREATE_ITEM_ENTRY CreateItemEntry
;
1711 /* remove '\' slash */
1713 BufferSize
-= sizeof(WCHAR
);
1715 /* point to first entry */
1716 Entry
= ListHead
->Flink
;
1718 /* loop all device items */
1719 while(Entry
!= ListHead
)
1721 /* get create item entry */
1722 CreateItemEntry
= (PCREATE_ITEM_ENTRY
)CONTAINING_RECORD(Entry
, CREATE_ITEM_ENTRY
, Entry
);
1724 ASSERT(CreateItemEntry
->CreateItem
);
1726 if(CreateItemEntry
->CreateItem
->Flags
& KSCREATE_ITEM_WILDCARD
)
1728 /* create item is default */
1729 *OutCreateItem
= CreateItemEntry
;
1730 return STATUS_SUCCESS
;
1733 if (!CreateItemEntry
->CreateItem
->Create
)
1735 /* skip free create item */
1736 Entry
= Entry
->Flink
;
1740 ASSERT(CreateItemEntry
->CreateItem
->ObjectClass
.Buffer
);
1742 DPRINT1("CreateItem %S Length %u Request %S %u\n", CreateItemEntry
->CreateItem
->ObjectClass
.Buffer
,
1743 CreateItemEntry
->CreateItem
->ObjectClass
.Length
,
1747 if (CreateItemEntry
->CreateItem
->ObjectClass
.Length
> BufferSize
)
1749 /* create item doesnt match in length */
1750 Entry
= Entry
->Flink
;
1754 /* now check if the object class is the same */
1755 if (RtlCompareMemory(CreateItemEntry
->CreateItem
->ObjectClass
.Buffer
, Buffer
, CreateItemEntry
->CreateItem
->ObjectClass
.Length
) == CreateItemEntry
->CreateItem
->ObjectClass
.Length
)
1757 /* found matching create item */
1758 *OutCreateItem
= CreateItemEntry
;
1759 return STATUS_SUCCESS
;
1761 /* iterate to next */
1762 Entry
= Entry
->Flink
;
1765 return STATUS_NOT_FOUND
;
1771 IN PDEVICE_OBJECT DeviceObject
,
1774 PCREATE_ITEM_ENTRY CreateItemEntry
;
1775 PIO_STACK_LOCATION IoStack
;
1776 PDEVICE_EXTENSION DeviceExtension
;
1777 PKSIDEVICE_HEADER DeviceHeader
;
1778 PKSIOBJECT_HEADER ObjectHeader
;
1781 DPRINT("KS / CREATE\n");
1782 /* get current stack location */
1783 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1784 /* get device extension */
1785 DeviceExtension
= (PDEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
1786 /* get device header */
1787 DeviceHeader
= DeviceExtension
->DeviceHeader
;
1790 if (IoStack
->FileObject
->FileName
.Buffer
== NULL
)
1792 /* FIXME Pnp-Issue */
1793 DPRINT("Using reference string hack\n");
1794 Irp
->IoStatus
.Information
= 0;
1795 /* set return status */
1796 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
1797 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1798 return STATUS_SUCCESS
;
1801 if (IoStack
->FileObject
->RelatedFileObject
!= NULL
)
1803 /* request is to instantiate a pin / node / clock / allocator */
1804 ObjectHeader
= (PKSIOBJECT_HEADER
)IoStack
->FileObject
->RelatedFileObject
->FsContext2
;
1807 ASSERT(ObjectHeader
);
1809 /* find a matching a create item */
1810 Status
= FindMatchingCreateItem(&ObjectHeader
->ItemList
, IoStack
->FileObject
->FileName
.Length
, IoStack
->FileObject
->FileName
.Buffer
, &CreateItemEntry
);
1814 /* request to create a filter */
1815 Status
= FindMatchingCreateItem(&DeviceHeader
->ItemList
, IoStack
->FileObject
->FileName
.Length
, IoStack
->FileObject
->FileName
.Buffer
, &CreateItemEntry
);
1818 if (NT_SUCCESS(Status
))
1820 /* set object create item */
1821 KSCREATE_ITEM_IRP_STORAGE(Irp
) = CreateItemEntry
->CreateItem
;
1823 /* call create function */
1824 Status
= CreateItemEntry
->CreateItem
->Create(DeviceObject
, Irp
);
1826 if (NT_SUCCESS(Status
))
1828 /* increment create item reference count */
1829 InterlockedIncrement(&CreateItemEntry
->ReferenceCount
);
1835 Irp
->IoStatus
.Information
= 0;
1836 /* set return status */
1837 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
1838 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1839 return STATUS_UNSUCCESSFUL
;
1845 IN PDEVICE_OBJECT DeviceObject
,
1848 PIO_STACK_LOCATION IoStack
;
1849 PDEVICE_EXTENSION DeviceExtension
;
1850 PKSIOBJECT_HEADER ObjectHeader
;
1851 PKSIDEVICE_HEADER DeviceHeader
;
1852 PDRIVER_DISPATCH Dispatch
;
1855 /* get current stack location */
1856 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1858 /* get device extension */
1859 DeviceExtension
= (PDEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
1860 /* get device header */
1861 DeviceHeader
= DeviceExtension
->DeviceHeader
;
1863 ASSERT(IoStack
->FileObject
);
1865 /* get object header */
1866 ObjectHeader
= (PKSIOBJECT_HEADER
) IoStack
->FileObject
->FsContext2
;
1870 /* FIXME Pnp-Issue*/
1871 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
1872 Irp
->IoStatus
.Information
= 0;
1873 /* complete and forget */
1874 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1875 return STATUS_SUCCESS
;
1879 ASSERT(ObjectHeader
);
1880 /* store create item */
1881 //KSCREATE_ITEM_IRP_STORAGE(Irp) = (PKSOBJECT_CREATE_ITEM)0x12345678; //ObjectHeader->CreateItem;
1883 /* retrieve matching dispatch function */
1884 switch(IoStack
->MajorFunction
)
1887 Dispatch
= ObjectHeader
->DispatchTable
.Close
;
1889 case IRP_MJ_DEVICE_CONTROL
:
1890 Dispatch
= ObjectHeader
->DispatchTable
.DeviceIoControl
;
1893 Dispatch
= ObjectHeader
->DispatchTable
.Read
;
1896 Dispatch
= ObjectHeader
->DispatchTable
.Write
;
1898 case IRP_MJ_FLUSH_BUFFERS
:
1899 Dispatch
= ObjectHeader
->DispatchTable
.Flush
;
1901 case IRP_MJ_QUERY_SECURITY
:
1902 Dispatch
= ObjectHeader
->DispatchTable
.QuerySecurity
;
1904 case IRP_MJ_SET_SECURITY
:
1905 Dispatch
= ObjectHeader
->DispatchTable
.SetSecurity
;
1908 Dispatch
= KsDefaultDispatchPnp
;
1913 /* is the request supported */
1916 /* now call the dispatch function */
1917 Status
= Dispatch(DeviceObject
, Irp
);
1921 /* not supported request */
1922 Status
= KsDispatchInvalidDeviceRequest(DeviceObject
, Irp
);
1935 KsSetMajorFunctionHandler(
1936 IN PDRIVER_OBJECT DriverObject
,
1937 IN ULONG MajorFunction
)
1939 DPRINT("KsSetMajorFunctionHandler Function %x\n", MajorFunction
);
1944 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = KspCreate
;
1947 switch ( MajorFunction
)
1950 DriverObject
->MajorFunction
[MajorFunction
] = KspCreate
;
1952 case IRP_MJ_DEVICE_CONTROL
:
1956 case IRP_MJ_FLUSH_BUFFERS
:
1957 case IRP_MJ_QUERY_SECURITY
:
1958 case IRP_MJ_SET_SECURITY
:
1959 DriverObject
->MajorFunction
[MajorFunction
] = KspDispatchIrp
;
1962 DPRINT1("NotSupported %x\n", MajorFunction
);
1963 return STATUS_INVALID_PARAMETER
;
1966 return STATUS_SUCCESS
;
1976 IN PDEVICE_OBJECT DeviceObject
,
1979 PIO_STACK_LOCATION IoStack
;
1980 PKSIDEVICE_HEADER DeviceHeader
;
1981 PDEVICE_EXTENSION DeviceExtension
;
1983 DPRINT("KsDispatchIrp DeviceObject %p Irp %p\n", DeviceObject
, Irp
);
1985 /* get device extension */
1986 DeviceExtension
= (PDEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
1987 /* get device header */
1988 DeviceHeader
= DeviceExtension
->DeviceHeader
;
1991 /* get current irp stack */
1992 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
1994 if (IoStack
->MajorFunction
<= IRP_MJ_DEVICE_CONTROL
)
1996 if (IoStack
->MajorFunction
== IRP_MJ_CREATE
)
1998 /* check internal type */
1999 if (DeviceHeader
->lpVtblIKsDevice
) /* FIXME improve check */
2001 /* AVStream client */
2002 return IKsDevice_Create(DeviceObject
, Irp
);
2006 /* external client (portcls) */
2007 return KspCreate(DeviceObject
, Irp
);
2011 switch (IoStack
->MajorFunction
)
2016 case IRP_MJ_FLUSH_BUFFERS
:
2017 case IRP_MJ_QUERY_SECURITY
:
2018 case IRP_MJ_SET_SECURITY
:
2020 case IRP_MJ_DEVICE_CONTROL
:
2021 return KspDispatchIrp(DeviceObject
, Irp
);
2023 return KsDispatchInvalidDeviceRequest(DeviceObject
, Irp
);
2027 /* dispatch power */
2028 if (IoStack
->MajorFunction
== IRP_MJ_POWER
)
2030 /* check internal type */
2031 if (DeviceHeader
->lpVtblIKsDevice
) /* FIXME improve check */
2033 /* AVStream client */
2034 return IKsDevice_Power(DeviceObject
, Irp
);
2038 /* external client (portcls) */
2039 return KsDefaultDispatchPower(DeviceObject
, Irp
);
2042 else if (IoStack
->MajorFunction
== IRP_MJ_PNP
) /* dispatch pnp */
2044 /* check internal type */
2045 if (DeviceHeader
->lpVtblIKsDevice
) /* FIXME improve check */
2047 /* AVStream client */
2048 return IKsDevice_Pnp(DeviceObject
, Irp
);
2052 /* external client (portcls) */
2053 return KsDefaultDispatchPnp(DeviceObject
, Irp
);
2056 else if (IoStack
->MajorFunction
== IRP_MJ_SYSTEM_CONTROL
)
2059 return KsDefaultForwardIrp(DeviceObject
, Irp
);
2064 return KsDispatchInvalidDeviceRequest(DeviceObject
, Irp
);