ReactOS  0.4.13-dev-79-gcd489d8
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 */
18 PKSDEVICE
19 NTAPI
22 {
23  PDEVICE_EXTENSION DeviceExtension;
24 
25  /* get device extension */
27 
28  return &DeviceExtension->DeviceHeader->KsDevice;
29 }
30 
31 /*
32  @implemented
33 */
35 PKSDEVICE
36 NTAPI
38  IN PVOID Object)
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 */
64 NTAPI
68  IN const KSDEVICE_DESCRIPTOR* Descriptor OPTIONAL,
69  IN ULONG ExtensionSize OPTIONAL,
70  OUT PKSDEVICE* Device OPTIONAL)
71 {
74  PDEVICE_OBJECT OldHighestDeviceObject;
75  if (!ExtensionSize)
76  ExtensionSize = sizeof(KSDEVICE_HEADER);
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 */
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 */
126 KSDDKAPI
127 NTSTATUS
128 NTAPI
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 */
152 KSDDKAPI
153 NTSTATUS
154 NTAPI
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 */
186 
187  /* The driver unload routine */
189 
190  /* The driver-supplied AddDevice */
192 
193  /* KS handles these */
194  DPRINT1("KsInitializeDriver Setting KS function handlers\n");
197 
198 
199  return STATUS_SUCCESS;
200 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
struct KSBASIC_HEADER * PKSBASIC_HEADER
NTSTATUS NTAPI IKsDevice_Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:406
#define IN
Definition: typedefs.h:38
PVOID KSDEVICE_HEADER
Definition: ks.h:1037
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:795
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
const KSDEVICE_DESCRIPTOR * Descriptor
Definition: kstypes.h:10
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1755
NTSTATUS NTAPI IKsDevice_Power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:574
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
KSDDKAPI VOID NTAPI KsNullDriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: irp.c:1145
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1295
#define KSDDKAPI
Definition: ks.h:40
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler(IN PDRIVER_OBJECT DriverObject, IN ULONG MajorFunction)
Definition: irp.c:2017
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2173
PVOID DeviceExtension
Definition: env_spec_w32.h:418
KSDDKAPI NTSTATUS NTAPI KsAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: driver.c:129
smooth NULL
Definition: ftsmooth.c:416
KSDDKAPI PKSDEVICE NTAPI KsGetDeviceForDeviceObject(IN PDEVICE_OBJECT FunctionalDeviceObject)
Definition: driver.c:20
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
KSOBJECTTYPE Type
Definition: kstypes.h:56
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:678
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
PKSDEVICE KsDevice
Definition: kstypes.h:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1833
#define IRP_MJ_SYSTEM_CONTROL
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2111
KSDDKAPI NTSTATUS NTAPI KsDefaultForwardIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: api.c:227
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
#define FILE_DEVICE_KS
Definition: winioctl.h:152
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * FunctionalDeviceObject
Definition: ndis.h:4622
#define DPRINT1
Definition: precomp.h:8
KSDDKAPI NTSTATUS NTAPI KsInitializeDriver(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL)
Definition: driver.c:155
#define OUT
Definition: typedefs.h:39
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
unsigned int ULONG
Definition: retypes.h:1
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
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
return STATUS_SUCCESS
Definition: btrfs.c:2725
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
NTSTATUS NTAPI IKsDevice_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:591
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
KSDDKAPI PKSDEVICE NTAPI KsGetDevice(IN PVOID Object)
Definition: driver.c:37
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68