ReactOS  0.4.15-dev-976-g0f66c66
fdo.c File Reference
#include "serenum.h"
#include <debug.h>
Include dependency graph for fdo.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI SerenumAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
 
static NTSTATUS NTAPI SerenumFdoStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS SerenumFdoQueryBusRelations (IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS *pDeviceRelations)
 
NTSTATUS SerenumFdoPnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Function Documentation

◆ SerenumAddDevice()

NTSTATUS NTAPI SerenumAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  Pdo 
)

Definition at line 15 of file fdo.c.

18 {
19  PDEVICE_OBJECT Fdo;
20  PFDO_DEVICE_EXTENSION DeviceExtension;
22 
23  TRACE_(SERENUM, "SerenumAddDevice called. Pdo = %p\n", Pdo);
24 
25  /* Create new device object */
27  sizeof(FDO_DEVICE_EXTENSION),
28  NULL,
31  FALSE,
32  &Fdo);
33  if (!NT_SUCCESS(Status))
34  {
35  WARN_(SERENUM, "IoCreateDevice() failed with status 0x%08lx\n", Status);
36  return Status;
37  }
38  DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
39  RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
40 
41  /* Register device interface */
43  Pdo,
44  &GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR,
45  NULL,
46  &DeviceExtension->SerenumInterfaceName);
47  if (!NT_SUCCESS(Status))
48  {
49  WARN_(SERENUM, "IoRegisterDeviceInterface() failed with status 0x%08lx\n", Status);
50  IoDeleteDevice(Fdo);
51  return Status;
52  }
53 
54  DeviceExtension->Common.IsFDO = TRUE;
55  DeviceExtension->Common.PnpState = dsStopped;
56  DeviceExtension->Pdo = Pdo;
57  IoInitializeRemoveLock(&DeviceExtension->RemoveLock, SERENUM_TAG, 0, 0);
58  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
59  if (!NT_SUCCESS(Status))
60  {
61  WARN_(SERENUM, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
62  IoDeleteDevice(Fdo);
63  return Status;
64  }
65  if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
66  Fdo->Flags |= DO_POWER_PAGABLE;
67  if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
68  Fdo->Flags |= DO_BUFFERED_IO;
69  if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
70  Fdo->Flags |= DO_DIRECT_IO;
72 
73  return STATUS_SUCCESS;
74 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:318
#define TRUE
Definition: types.h:120
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2829
LONG NTSTATUS
Definition: precomp.h:26
#define SERENUM_TAG
Definition: serenum.h:58
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define TRACE_(x)
Definition: compat.h:76
UNICODE_STRING SerenumInterfaceName
Definition: serenum.h:39
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
Status
Definition: gdiplustypes.h:24
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
PDEVICE_OBJECT Pdo
Definition: i8042prt.h:128
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130
IO_REMOVE_LOCK RemoveLock
Definition: serenum.h:37
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:147
#define WARN_(ch,...)
Definition: debug.h:157

◆ SerenumFdoPnp()

NTSTATUS SerenumFdoPnp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 152 of file fdo.c.

155 {
157  PIO_STACK_LOCATION Stack;
160 
162  MinorFunction = Stack->MinorFunction;
163 
164  switch (MinorFunction)
165  {
166  /* FIXME: do all these minor functions
167  IRP_MN_QUERY_REMOVE_DEVICE 0x1
168  IRP_MN_REMOVE_DEVICE 0x2
169  IRP_MN_CANCEL_REMOVE_DEVICE 0x3
170  IRP_MN_STOP_DEVICE 0x4
171  IRP_MN_QUERY_STOP_DEVICE 0x5
172  IRP_MN_CANCEL_STOP_DEVICE 0x6
173  IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations (optional) 0x7
174  IRP_MN_QUERY_INTERFACE (optional) 0x8
175  IRP_MN_QUERY_CAPABILITIES (optional) 0x9
176  IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
177  IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
178  IRP_MN_SURPRISE_REMOVAL 0x17
179  */
180  case IRP_MN_START_DEVICE: /* 0x0 */
181  {
182  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
183  /* Call lower driver */
185  if (NT_SUCCESS(Status))
187  break;
188  }
189  case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
190  {
191  switch (Stack->Parameters.QueryDeviceRelations.Type)
192  {
193  case BusRelations:
194  {
195  PDEVICE_RELATIONS DeviceRelations = NULL;
196  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
197  Status = SerenumFdoQueryBusRelations(DeviceObject, &DeviceRelations);
198  Information = (ULONG_PTR)DeviceRelations;
199  break;
200  }
201  default:
202  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
203  Stack->Parameters.QueryDeviceRelations.Type);
205  }
206  break;
207  }
209  {
210  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
212  }
213  default:
214  {
215  TRACE_(SERENUM, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
217  }
218  }
219 
220  Irp->IoStatus.Information = Information;
221  Irp->IoStatus.Status = Status;
223  return Status;
224 }
NTSTATUS NTAPI ForwardIrpAndForget(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:66
NTSTATUS NTAPI ForwardIrpAndWait(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:32
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
LONG NTSTATUS
Definition: precomp.h:26
Iosb Information
Definition: create.c:4353
uint32_t ULONG_PTR
Definition: typedefs.h:65
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:76
static NTSTATUS SerenumFdoQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS *pDeviceRelations)
Definition: fdo.c:102
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
Status
Definition: gdiplustypes.h:24
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define IRP_MN_QUERY_DEVICE_RELATIONS
static NTSTATUS NTAPI SerenumFdoStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:77
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:570
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2779

Referenced by SerenumPnp().

◆ SerenumFdoQueryBusRelations()

static NTSTATUS SerenumFdoQueryBusRelations ( IN PDEVICE_OBJECT  DeviceObject,
OUT PDEVICE_RELATIONS pDeviceRelations 
)
static

Definition at line 102 of file fdo.c.

105 {
106  PFDO_DEVICE_EXTENSION DeviceExtension;
107  PDEVICE_RELATIONS DeviceRelations;
108  ULONG NumPDO;
109  ULONG i;
111 
113  ASSERT(DeviceExtension->Common.IsFDO);
114 
115  /* Do enumeration if needed */
116  if (!(DeviceExtension->Flags & FLAG_ENUMERATION_DONE))
117  {
118  ASSERT(DeviceExtension->AttachedPdo == NULL);
119  /* Detect plug-and-play devices */
122  {
123  /* Detect legacy devices */
127  }
128  DeviceExtension->Flags |= FLAG_ENUMERATION_DONE;
129  }
130  NumPDO = (DeviceExtension->AttachedPdo != NULL ? 1 : 0);
131 
132  DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePoolWithTag(
133  PagedPool,
134  sizeof(DEVICE_RELATIONS) + sizeof(PDEVICE_OBJECT) * (NumPDO - 1),
135  SERENUM_TAG);
136  if (!DeviceRelations)
138 
139  /* Fill returned structure */
140  DeviceRelations->Count = NumPDO;
141  for (i = 0; i < NumPDO; i++)
142  {
143  ObReferenceObject(DeviceExtension->AttachedPdo);
144  DeviceRelations->Objects[i] = DeviceExtension->AttachedPdo;
145  }
146 
147  *pDeviceRelations = DeviceRelations;
148  return Status;
149 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _DEVICE_OBJECT * PDEVICE_OBJECT
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2062
LONG NTSTATUS
Definition: precomp.h:26
#define SERENUM_TAG
Definition: serenum.h:58
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
NTSTATUS SerenumDetectLegacyDevice(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:444
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define FLAG_ENUMERATION_DONE
Definition: serenum.h:61
NTSTATUS SerenumDetectPnpDevice(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:223
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130
PDEVICE_OBJECT AttachedPdo[2]
Definition: parport.h:44
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by SerenumFdoPnp().

◆ SerenumFdoStartDevice()

static NTSTATUS NTAPI SerenumFdoStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 77 of file fdo.c.

80 {
81  PFDO_DEVICE_EXTENSION DeviceExtension;
83 
84  TRACE_(SERENUM, "SerenumFdoStartDevice() called\n");
86 
87  ASSERT(DeviceExtension->Common.PnpState == dsStopped);
88 
90  if (!NT_SUCCESS(Status))
91  {
92  WARN_(SERENUM, "IoSetDeviceInterfaceState() failed with status 0x%08lx\n", Status);
93  return Status;
94  }
95 
96  DeviceExtension->Common.PnpState = dsStarted;
97 
98  return STATUS_SUCCESS;
99 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
PVOID DeviceExtension
Definition: env_spec_w32.h:418
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define TRACE_(x)
Definition: compat.h:76
UNICODE_STRING SerenumInterfaceName
Definition: serenum.h:39
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by SerenumFdoPnp().