ReactOS 0.4.15-dev-8102-g108db8f
driver.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/ksfilter/ks/driver.c
5 * PURPOSE: KS Driver functions
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9#include "precomp.h"
10
11#define NDEBUG
12#include <debug.h>
13
14/*
15 @implemented
16*/
18PKSDEVICE
22{
23 PDEVICE_EXTENSION DeviceExtension;
24
25 /* get device extension */
27
28 return &DeviceExtension->DeviceHeader->KsDevice;
29}
30
31/*
32 @implemented
33*/
35PKSDEVICE
39{
41
42 DPRINT("KsGetDevice Type %lu KsDevice %p\n", BasicHeader->Type, BasicHeader->KsDevice);
43
44 ASSERT(BasicHeader->Type == KsObjectTypeFilterFactory || BasicHeader->Type == KsObjectTypeFilter || BasicHeader->Type == KsObjectTypePin);
45 ASSERT(BasicHeader->KsDevice);
46 ASSERT(BasicHeader->KsDevice->Descriptor);
47 ASSERT(BasicHeader->KsDevice->Bag);
48 ASSERT(BasicHeader->KsDevice->Context);
49 ASSERT(BasicHeader->KsDevice->FunctionalDeviceObject);
50 ASSERT(BasicHeader->KsDevice->PhysicalDeviceObject);
51 ASSERT(BasicHeader->KsDevice->NextDeviceObject);
52 ASSERT(BasicHeader->KsDevice->Started);
53 ASSERT(BasicHeader->KsDevice->SystemPowerState == PowerSystemWorking);
54 ASSERT(BasicHeader->KsDevice->DevicePowerState == PowerDeviceD0);
55
56 return BasicHeader->KsDevice;
57}
58
59/*
60 @implemented
61*/
68 IN const KSDEVICE_DESCRIPTOR* Descriptor OPTIONAL,
70 OUT PKSDEVICE* Device OPTIONAL)
71{
74 PDEVICE_OBJECT OldHighestDeviceObject;
75 if (!ExtensionSize)
77
78 DPRINT("KsCreateDevice Descriptor %p ExtensionSize %lu\n", Descriptor, ExtensionSize);
79
81 if (!NT_SUCCESS(Status))
82 return Status;
83
85 if (OldHighestDeviceObject)
86 {
88 }
89 else
90 {
92 }
93
94 /* check if all succeeded */
95 if (!NT_SUCCESS(Status))
96 {
97 if (OldHighestDeviceObject)
98 IoDetachDevice(OldHighestDeviceObject);
99
101 return Status;
102 }
103
104 /* set device flags */
106 FunctionalDeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;
107
108 if (Device)
109 {
110 /* get PKSDEVICE struct */
112
113 if (ExtensionSize > sizeof(KSDEVICE_HEADER))
114 {
115 /* caller needs a device extension */
116 (*Device)->Context = (PVOID)((ULONG_PTR)FunctionalDeviceObject->DeviceExtension + sizeof(KSDEVICE_HEADER));
117 }
118 }
119
120 return Status;
121}
122
123/*
124 @implemented
125*/
128NTAPI
132{
133 PKS_DRIVER_EXTENSION DriverObjectExtension;
134 const KSDEVICE_DESCRIPTOR *Descriptor = NULL;
135
136 /* get stored driver object extension */
137
139
140 if (DriverObjectExtension)
141 {
142 /* get the stored descriptor see KsInitializeDriver */
143 Descriptor = DriverObjectExtension->Descriptor;
144 }
145
147}
148
149/*
150 @implemented
151*/
154NTAPI
158 IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL
159)
160{
161 PKS_DRIVER_EXTENSION DriverObjectExtension;
163
164 DPRINT("KsInitializeDriver\n");
165
166 if (Descriptor)
167 {
169 if (NT_SUCCESS(Status))
170 {
171 DriverObjectExtension->Descriptor = Descriptor;
172 }
173 }
174
175 /* sanity check */
177
178 if (!NT_SUCCESS(Status))
179 return Status;
180
181 /* Setting our IRP handlers */
183 DriverObject->MajorFunction[IRP_MJ_PNP] = IKsDevice_Pnp;
184 DriverObject->MajorFunction[IRP_MJ_POWER] = IKsDevice_Power;
186
187 /* The driver unload routine */
188 DriverObject->DriverUnload = KsNullDriverUnload;
189
190 /* The driver-supplied AddDevice */
191 DriverObject->DriverExtension->AddDevice = KsAddDevice;
192
193 /* KS handles these */
194 DPRINT1("KsInitializeDriver Setting KS function handlers\n");
197
198
199 return STATUS_SUCCESS;
200}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
KSDDKAPI NTSTATUS NTAPI KsDefaultForwardIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:227
NTSTATUS NTAPI IKsDevice_Power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:549
KSDDKAPI NTSTATUS NTAPI KsInitializeDevice(IN PDEVICE_OBJECT FunctionalDeviceObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_OBJECT NextDeviceObject, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL)
Definition: device.c:653
NTSTATUS NTAPI IKsDevice_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:566
NTSTATUS NTAPI IKsDevice_Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:409
KSDDKAPI PKSDEVICE NTAPI KsGetDevice(IN PVOID Object)
Definition: driver.c:37
KSDDKAPI PKSDEVICE NTAPI KsGetDeviceForDeviceObject(IN PDEVICE_OBJECT FunctionalDeviceObject)
Definition: driver.c:20
KSDDKAPI NTSTATUS NTAPI KsInitializeDriver(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL)
Definition: driver.c:155
KSDDKAPI NTSTATUS NTAPI KsCreateDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL, IN ULONG ExtensionSize OPTIONAL, OUT PKSDEVICE *Device OPTIONAL)
Definition: driver.c:65
KSDDKAPI NTSTATUS NTAPI KsAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: driver.c:129
KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler(IN PDRIVER_OBJECT DriverObject, IN ULONG MajorFunction)
Definition: irp.c:2050
KSDDKAPI VOID NTAPI KsNullDriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: irp.c:1178
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
Status
Definition: gdiplustypes.h:25
@ KsObjectTypeFilter
Definition: ks.h:1210
@ KsObjectTypePin
Definition: ks.h:1211
@ KsObjectTypeFilterFactory
Definition: ks.h:1209
PVOID KSDEVICE_HEADER
Definition: ks.h:1007
#define KSDDKAPI
Definition: ks.h:40
struct KSBASIC_HEADER * PKSBASIC_HEADER
#define ASSERT(a)
Definition: mode.c:44
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * FunctionalDeviceObject
Definition: ndis.h:4641
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1826
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
#define FILE_DEVICE_KS
Definition: winioctl.h:153
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
WORD ExtensionSize
Definition: apisets.c:17
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
PKSDEVICE KsDevice
Definition: kstypes.h:57
KSOBJECTTYPE Type
Definition: kstypes.h:56
const KSDEVICE_DESCRIPTOR * Descriptor
Definition: kstypes.h:10
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
#define DO_POWER_PAGABLE
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_POWER