ReactOS  0.4.15-dev-5462-g4d0d22a
pnp.c File Reference
#include "btrfs_drv.h"
Include dependency graph for pnp.c:

Go to the source code of this file.

Classes

struct  device_usage_context
 

Functions

NTSTATUS pnp_query_remove_device (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
static NTSTATUS pnp_remove_device (PDEVICE_OBJECT DeviceObject)
 
NTSTATUS pnp_surprise_removal (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
static NTSTATUS bus_query_capabilities (PIRP Irp)
 
static NTSTATUS bus_query_device_relations (PIRP Irp)
 
static NTSTATUS bus_query_hardware_ids (PIRP Irp)
 
static NTSTATUS bus_pnp (bus_device_extension *bde, PIRP Irp)
 
static NTSTATUS pdo_query_device_id (pdo_device_extension *pdode, PIRP Irp)
 
static NTSTATUS pdo_query_hardware_ids (PIRP Irp)
 
static NTSTATUS pdo_query_id (pdo_device_extension *pdode, PIRP Irp)
 
 _Function_class_ (IO_COMPLETION_ROUTINE)
 
static NTSTATUS pdo_device_usage_notification (pdo_device_extension *pdode, PIRP Irp)
 
static NTSTATUS pdo_query_device_relations (PDEVICE_OBJECT pdo, PIRP Irp)
 
static NTSTATUS pdo_pnp (PDEVICE_OBJECT pdo, PIRP Irp)
 
static NTSTATUS pnp_device_usage_notification (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
 _Dispatch_type_ (IRP_MJ_PNP)
 

Variables

ERESOURCE pdo_list_lock
 
LIST_ENTRY pdo_list
 

Function Documentation

◆ _Dispatch_type_()

_Dispatch_type_ ( IRP_MJ_PNP  )

Definition at line 458 of file pnp.c.

460  {
462  device_extension* Vcb = DeviceObject->DeviceExtension;
464  bool top_level;
465 
467 
468  top_level = is_top_level(Irp);
469 
470  if (Vcb && Vcb->type == VCB_TYPE_BUS) {
471  Status = bus_pnp(DeviceObject->DeviceExtension, Irp);
472  goto exit;
473  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
474  volume_device_extension* vde = DeviceObject->DeviceExtension;
477  goto exit;
478  } else if (Vcb && Vcb->type == VCB_TYPE_PDO) {
480  goto end;
481  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
483  goto end;
484  }
485 
487 
488  switch (IrpSp->MinorFunction) {
491  break;
492 
495  break;
496 
499  break;
500 
503  break;
504 
507  goto exit;
508 
509  default:
510  TRACE("passing minor function 0x%x on\n", IrpSp->MinorFunction);
511 
513  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
514  goto exit;
515  }
516 
517 end:
518  Irp->IoStatus.Status = Status;
519 
521 
522 exit:
523  TRACE("returning %08lx\n", Status);
524 
525  if (top_level)
527 
529 
530  return Status;
531 }
NTSTATUS pnp_query_remove_device(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:23
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define VCB_TYPE_PDO
Definition: btrfs_drv.h:690
#define IRP_MN_REMOVE_DEVICE
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define VCB_TYPE_FS
Definition: btrfs_drv.h:687
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:278
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:691
static NTSTATUS pnp_remove_device(PDEVICE_OBJECT DeviceObject)
Definition: pnp.c:53
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
#define IoCompleteRequest
Definition: irp.c:1240
Status
Definition: gdiplustypes.h:24
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define TRACE(s)
Definition: solgame.cpp:4
static NTSTATUS bus_pnp(bus_device_extension *bde, PIRP Irp)
Definition: pnp.c:185
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:689
#define Vcb
Definition: cdprocs.h:1415
GLuint GLuint end
Definition: gl.h:1545
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:880
static NTSTATUS pdo_pnp(PDEVICE_OBJECT pdo, PIRP Irp)
Definition: pnp.c:410
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
static NTSTATUS pnp_device_usage_notification(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:437
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
void exit(int exitcode)
Definition: _exit.c:33
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
NTSTATUS pnp_surprise_removal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:77

◆ _Function_class_()

_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 315 of file pnp.c.

316  {
317  device_usage_context* context = conptr;
318 
320 
321  context->Status = Irp->IoStatus.Status;
322 
323  KeSetEvent(&context->Event, 0, false);
324 
326 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
Definition: http.c:7251
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define UNUSED(x)
Definition: btrfs_drv.h:82

◆ bus_pnp()

static NTSTATUS bus_pnp ( bus_device_extension bde,
PIRP  Irp 
)
static

Definition at line 185 of file pnp.c.

185  {
186  NTSTATUS Status = Irp->IoStatus.Status;
188  bool handled = false;
189 
190  switch (IrpSp->MinorFunction) {
191  case IRP_MN_START_DEVICE:
196  handled = true;
197  break;
198 
201  handled = true;
202  break;
203 
206  handled = true;
207  break;
208 
210  if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations || no_pnp)
211  break;
212 
214  handled = true;
215  break;
216 
217  case IRP_MN_QUERY_ID:
218  if (IrpSp->Parameters.QueryId.IdType != BusQueryHardwareIDs)
219  break;
220 
222  handled = true;
223  break;
224  }
225 
226  if (!NT_SUCCESS(Status) && handled) {
227  Irp->IoStatus.Status = Status;
229 
230  return Status;
231  }
232 
233  Irp->IoStatus.Status = Status;
234 
236  return IoCallDriver(bde->attached_device, Irp);
237 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
uint32_t no_pnp
Definition: btrfs.c:87
#define IoCompleteRequest
Definition: irp.c:1240
static NTSTATUS bus_query_capabilities(PIRP Irp)
Definition: pnp.c:101
Status
Definition: gdiplustypes.h:24
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static NTSTATUS bus_query_device_relations(PIRP Irp)
Definition: pnp.c:111
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:849
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
static NTSTATUS bus_query_hardware_ids(PIRP Irp)
Definition: pnp.c:167
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define IRP_MN_QUERY_CAPABILITIES

Referenced by _Dispatch_type_().

◆ bus_query_capabilities()

static NTSTATUS bus_query_capabilities ( PIRP  Irp)
static

Definition at line 101 of file pnp.c.

101  {
103  PDEVICE_CAPABILITIES dc = IrpSp->Parameters.DeviceCapabilities.Capabilities;
104 
105  dc->UniqueID = true;
106  dc->SilentInstall = true;
107 
108  return STATUS_SUCCESS;
109 }
_In_ PIRP Irp
Definition: csq.h:116
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
static const WCHAR dc[]
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137

Referenced by bus_pnp().

◆ bus_query_device_relations()

static NTSTATUS bus_query_device_relations ( PIRP  Irp)
static

Definition at line 111 of file pnp.c.

111  {
113  ULONG num_children;
114  LIST_ENTRY* le;
115  ULONG drsize, i;
116  DEVICE_RELATIONS* dr;
117 
119 
120  num_children = 0;
121 
122  le = pdo_list.Flink;
123  while (le != &pdo_list) {
125 
126  if (!pdode->dont_report)
127  num_children++;
128 
129  le = le->Flink;
130  }
131 
132  drsize = offsetof(DEVICE_RELATIONS, Objects[0]) + (num_children * sizeof(PDEVICE_OBJECT));
134 
135  if (!dr) {
136  ERR("out of memory\n");
138  goto end;
139  }
140 
141  dr->Count = num_children;
142 
143  i = 0;
144  le = pdo_list.Flink;
145  while (le != &pdo_list) {
147 
148  if (!pdode->dont_report) {
149  ObReferenceObject(pdode->pdo);
150  dr->Objects[i] = pdode->pdo;
151  i++;
152  }
153 
154  le = le->Flink;
155  }
156 
157  Irp->IoStatus.Information = (ULONG_PTR)dr;
158 
160 
161 end:
163 
164  return Status;
165 }
ERESOURCE pdo_list_lock
Definition: btrfs.c:103
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _DEVICE_OBJECT * PDEVICE_OBJECT
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:890
#define ALLOC_TAG
Definition: btrfs_drv.h:87
_In_ PIRP Irp
Definition: csq.h:116
#define offsetof(TYPE, MEMBER)
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
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLuint GLuint end
Definition: gl.h:1545
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:119
#define ERR(fmt,...)
Definition: debug.h:110
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
Definition: list.h:27
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
LIST_ENTRY pdo_list
Definition: btrfs.c:104
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by bus_pnp().

◆ bus_query_hardware_ids()

static NTSTATUS bus_query_hardware_ids ( PIRP  Irp)
static

Definition at line 167 of file pnp.c.

167  {
168  WCHAR* out;
169 
170  static const WCHAR ids[] = L"ROOT\\btrfs\0";
171 
173  if (!out) {
174  ERR("out of memory\n");
176  }
177 
178  RtlCopyMemory(out, ids, sizeof(ids));
179 
180  Irp->IoStatus.Information = (ULONG_PTR)out;
181 
182  return STATUS_SUCCESS;
183 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ALLOC_TAG
Definition: btrfs_drv.h:87
GLuint * ids
Definition: glext.h:5907
#define L(x)
Definition: ntvdm.h:50
_In_ PIRP Irp
Definition: csq.h:116
__wchar_t WCHAR
Definition: xmlstorage.h:180
static FILE * out
Definition: regtests2xml.c:44
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:110
#define ULONG_PTR
Definition: config.h:101
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by bus_pnp().

◆ pdo_device_usage_notification()

static NTSTATUS pdo_device_usage_notification ( pdo_device_extension pdode,
PIRP  Irp 
)
static

Definition at line 328 of file pnp.c.

328  {
330  LIST_ENTRY* le;
331 
332  TRACE("(%p, %p)\n", pdode, Irp);
333 
335 
336  le = pdode->children.Flink;
337 
338  while (le != &pdode->children) {
340 
341  if (vc->devobj) {
342  PIRP Irp2;
343  PIO_STACK_LOCATION IrpSp2;
345 
346  Irp2 = IoAllocateIrp(vc->devobj->StackSize, false);
347  if (!Irp2) {
348  ERR("out of memory\n");
351  }
352 
353  IrpSp2 = IoGetNextIrpStackLocation(Irp2);
354  IrpSp2->MajorFunction = IRP_MJ_PNP;
356  IrpSp2->Parameters.UsageNotification = IrpSp->Parameters.UsageNotification;
357  IrpSp2->FileObject = vc->fileobj;
358 
359  context.iosb.Status = STATUS_SUCCESS;
360  Irp2->UserIosb = &context.iosb;
361 
363  Irp2->UserEvent = &context.Event;
364 
365  IoSetCompletionRoutine(Irp2, device_usage_completion, &context, true, true, true);
366 
367  context.Status = IoCallDriver(vc->devobj, Irp2);
368 
369  if (context.Status == STATUS_PENDING)
371 
372  if (!NT_SUCCESS(context.Status)) {
373  ERR("IoCallDriver returned %08lx\n", context.Status);
375  return context.Status;
376  }
377  }
378 
379  le = le->Flink;
380  }
381 
383 
384  return STATUS_SUCCESS;
385 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: http.c:7251
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT devobj
Definition: btrfs_drv.h:857
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
ERESOURCE child_lock
Definition: btrfs_drv.h:896
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
PFILE_OBJECT fileobj
Definition: btrfs_drv.h:858
Definition: typedefs.h:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
Definition: list.h:27
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
LIST_ENTRY children
Definition: btrfs_drv.h:897
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137

Referenced by pdo_pnp().

◆ pdo_pnp()

static NTSTATUS pdo_pnp ( PDEVICE_OBJECT  pdo,
PIRP  Irp 
)
static

Definition at line 410 of file pnp.c.

410  {
413 
414  switch (IrpSp->MinorFunction) {
415  case IRP_MN_QUERY_ID:
416  return pdo_query_id(pdode, Irp);
417 
418  case IRP_MN_START_DEVICE:
422  return STATUS_SUCCESS;
423 
425  return STATUS_UNSUCCESSFUL;
426 
428  return pdo_device_usage_notification(pdode, Irp);
429 
431  return pdo_query_device_relations(pdo, Irp);
432  }
433 
434  return Irp->IoStatus.Status;
435 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
static NTSTATUS pdo_device_usage_notification(pdo_device_extension *pdode, PIRP Irp)
Definition: pnp.c:328
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static NTSTATUS pdo_query_device_relations(PDEVICE_OBJECT pdo, PIRP Irp)
Definition: pnp.c:387
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_START_DEVICE
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IRP_MN_QUERY_DEVICE_RELATIONS
static NTSTATUS pdo_query_id(pdo_device_extension *pdode, PIRP Irp)
Definition: pnp.c:290
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137

Referenced by _Dispatch_type_().

◆ pdo_query_device_id()

static NTSTATUS pdo_query_device_id ( pdo_device_extension pdode,
PIRP  Irp 
)
static

Definition at line 239 of file pnp.c.

239  {
240  WCHAR name[100], *noff, *out;
241  int i;
242 
243  static const WCHAR pref[] = L"Btrfs\\";
244 
245  RtlCopyMemory(name, pref, sizeof(pref) - sizeof(WCHAR));
246 
247  noff = &name[(sizeof(pref) / sizeof(WCHAR)) - 1];
248  for (i = 0; i < 16; i++) {
249  *noff = hex_digit(pdode->uuid.uuid[i] >> 4); noff++;
250  *noff = hex_digit(pdode->uuid.uuid[i] & 0xf); noff++;
251 
252  if (i == 3 || i == 5 || i == 7 || i == 9) {
253  *noff = '-';
254  noff++;
255  }
256  }
257  *noff = 0;
258 
260  if (!out) {
261  ERR("out of memory\n");
263  }
264 
265  RtlCopyMemory(out, name, (wcslen(name) + 1) * sizeof(WCHAR));
266 
267  Irp->IoStatus.Information = (ULONG_PTR)out;
268 
269  return STATUS_SUCCESS;
270 }
#define hex_digit(c)
Definition: btrfs_drv.h:1748
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ALLOC_TAG
Definition: btrfs_drv.h:87
#define L(x)
Definition: ntvdm.h:50
_In_ PIRP Irp
Definition: csq.h:116
__wchar_t WCHAR
Definition: xmlstorage.h:180
static FILE * out
Definition: regtests2xml.c:44
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:110
uint8_t uuid[16]
Definition: btrfs.h:140
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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
Definition: name.c:38
#define ULONG_PTR
Definition: config.h:101
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by pdo_query_id().

◆ pdo_query_device_relations()

static NTSTATUS pdo_query_device_relations ( PDEVICE_OBJECT  pdo,
PIRP  Irp 
)
static

Definition at line 387 of file pnp.c.

387  {
389  PDEVICE_RELATIONS device_relations;
390 
391  if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
392  return Irp->IoStatus.Status;
393 
394  device_relations = ExAllocatePoolWithTag(PagedPool, sizeof(DEVICE_RELATIONS), ALLOC_TAG);
395  if (!device_relations) {
396  ERR("out of memory\n");
398  }
399 
400  device_relations->Count = 1;
401  device_relations->Objects[0] = pdo;
402 
403  ObReferenceObject(pdo);
404 
405  Irp->IoStatus.Information = (ULONG_PTR)device_relations;
406 
407  return STATUS_SUCCESS;
408 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
#define ALLOC_TAG
Definition: btrfs_drv.h:87
_In_ PIRP Irp
Definition: csq.h:116
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define ObReferenceObject
Definition: obfuncs.h:204
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137

Referenced by pdo_pnp().

◆ pdo_query_hardware_ids()

static NTSTATUS pdo_query_hardware_ids ( PIRP  Irp)
static

Definition at line 272 of file pnp.c.

272  {
273  WCHAR* out;
274 
275  static const WCHAR ids[] = L"BtrfsVolume\0";
276 
278  if (!out) {
279  ERR("out of memory\n");
281  }
282 
283  RtlCopyMemory(out, ids, sizeof(ids));
284 
285  Irp->IoStatus.Information = (ULONG_PTR)out;
286 
287  return STATUS_SUCCESS;
288 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ALLOC_TAG
Definition: btrfs_drv.h:87
GLuint * ids
Definition: glext.h:5907
#define L(x)
Definition: ntvdm.h:50
_In_ PIRP Irp
Definition: csq.h:116
__wchar_t WCHAR
Definition: xmlstorage.h:180
static FILE * out
Definition: regtests2xml.c:44
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:110
#define ULONG_PTR
Definition: config.h:101
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by pdo_query_id().

◆ pdo_query_id()

static NTSTATUS pdo_query_id ( pdo_device_extension pdode,
PIRP  Irp 
)
static

Definition at line 290 of file pnp.c.

290  {
292 
293  switch (IrpSp->Parameters.QueryId.IdType) {
294  case BusQueryDeviceID:
295  TRACE("BusQueryDeviceID\n");
296  return pdo_query_device_id(pdode, Irp);
297 
298  case BusQueryHardwareIDs:
299  TRACE("BusQueryHardwareIDs\n");
300  return pdo_query_hardware_ids(Irp);
301 
302  default:
303  break;
304  }
305 
306  return Irp->IoStatus.Status;
307 }
static NTSTATUS pdo_query_hardware_ids(PIRP Irp)
Definition: pnp.c:272
_In_ PIRP Irp
Definition: csq.h:116
#define TRACE(s)
Definition: solgame.cpp:4
static NTSTATUS pdo_query_device_id(pdo_device_extension *pdode, PIRP Irp)
Definition: pnp.c:239
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137

Referenced by pdo_pnp().

◆ pnp_device_usage_notification()

static NTSTATUS pnp_device_usage_notification ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)
static

Definition at line 437 of file pnp.c.

437  {
439  device_extension* Vcb = DeviceObject->DeviceExtension;
440 
441  if (IrpSp->Parameters.UsageNotification.InPath) {
442  switch (IrpSp->Parameters.UsageNotification.Type) {
446  IoAdjustPagingPathCount(&Vcb->page_file_count, IrpSp->Parameters.UsageNotification.InPath);
447  break;
448 
449  default:
450  break;
451  }
452  }
453 
455  return IoCallDriver(Vcb->Vpb->RealDevice, Irp);
456 }
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoAdjustPagingPathCount(_Count, _Increment)
#define Vcb
Definition: cdprocs.h:1415
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137

Referenced by _Dispatch_type_().

◆ pnp_query_remove_device()

NTSTATUS pnp_query_remove_device ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 23 of file pnp.c.

23  {
24  device_extension* Vcb = DeviceObject->DeviceExtension;
26 
27  // We might be going away imminently - do a flush so we're not caught out
28 
29  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
30 
31  if (Vcb->root_fileref && Vcb->root_fileref->fcb && (Vcb->root_fileref->open_count > 0 || has_open_children(Vcb->root_fileref))) {
32  ExReleaseResourceLite(&Vcb->tree_lock);
33  return STATUS_ACCESS_DENIED;
34  }
35 
36  if (Vcb->need_write && !Vcb->readonly) {
37  Status = do_write(Vcb, Irp);
38 
39  free_trees(Vcb);
40 
41  if (!NT_SUCCESS(Status)) {
42  ERR("do_write returned %08lx\n", Status);
43  ExReleaseResourceLite(&Vcb->tree_lock);
44  return Status;
45  }
46  }
47 
48  ExReleaseResourceLite(&Vcb->tree_lock);
49 
50  return STATUS_UNSUCCESSFUL;
51 }
NTSTATUS do_write(device_extension *Vcb, PIRP Irp)
Definition: flushthread.c:7877
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1415
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
bool has_open_children(file_ref *fileref)
Definition: fileinfo.c:442
NTSTATUS NTSTATUS bool bool void free_trees(device_extension *Vcb) __attribute__((nonnull(1)))
#define ERR(fmt,...)
Definition: debug.h:110

Referenced by _Dispatch_type_(), and _Function_class_().

◆ pnp_remove_device()

static NTSTATUS pnp_remove_device ( PDEVICE_OBJECT  DeviceObject)
static

Definition at line 53 of file pnp.c.

53  {
54  device_extension* Vcb = DeviceObject->DeviceExtension;
56 
57  if (DeviceObject->Vpb->Flags & VPB_MOUNTED) {
59  if (!NT_SUCCESS(Status)) {
60  WARN("FsRtlNotifyVolumeEvent returned %08lx\n", Status);
61  }
62 
63  if (Vcb->vde)
64  Vcb->vde->mounted_device = NULL;
65 
66  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
67  Vcb->removing = true;
68  ExReleaseResourceLite(&Vcb->tree_lock);
69 
70  if (Vcb->open_files == 0)
71  uninit(Vcb);
72  }
73 
74  return STATUS_SUCCESS;
75 }
#define FSRTL_VOLUME_DISMOUNT
Definition: ntifs_ex.h:439
#define WARN(fmt,...)
Definition: debug.h:112
LONG NTSTATUS
Definition: precomp.h:26
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:2001
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1415
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
#define VPB_MOUNTED
Definition: iotypes.h:1807

Referenced by _Dispatch_type_().

◆ pnp_surprise_removal()

NTSTATUS pnp_surprise_removal ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 77 of file pnp.c.

77  {
78  device_extension* Vcb = DeviceObject->DeviceExtension;
79 
80  TRACE("(%p, %p)\n", DeviceObject, Irp);
81 
82  UNUSED(Irp);
83 
84  if (DeviceObject->Vpb->Flags & VPB_MOUNTED) {
85  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
86 
87  if (Vcb->vde)
88  Vcb->vde->mounted_device = NULL;
89 
90  Vcb->removing = true;
91 
92  ExReleaseResourceLite(&Vcb->tree_lock);
93 
94  if (Vcb->open_files == 0)
95  uninit(Vcb);
96  }
97 
98  return STATUS_SUCCESS;
99 }
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:2001
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define UNUSED(x)
Definition: btrfs_drv.h:82
#define TRACE(s)
Definition: solgame.cpp:4
#define Vcb
Definition: cdprocs.h:1415
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
#define VPB_MOUNTED
Definition: iotypes.h:1807

Referenced by _Dispatch_type_(), and remove_volume_child().

Variable Documentation

◆ pdo_list

LIST_ENTRY pdo_list

Definition at line 104 of file btrfs.c.

Referenced by bus_query_device_relations().

◆ pdo_list_lock

ERESOURCE pdo_list_lock

Definition at line 103 of file btrfs.c.

Referenced by bus_query_device_relations().