ReactOS  0.4.14-dev-614-gbfd8a84
pdo.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Storport Driver
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Storport PDO code
5  * COPYRIGHT: Copyright 2017 Eric Kohl (eric.kohl@reactos.org)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include "precomp.h"
11 
12 #define NDEBUG
13 #include <debug.h>
14 
15 
16 /* FUNCTIONS ******************************************************************/
17 
20  _In_ PFDO_DEVICE_EXTENSION FdoDeviceExtension,
21  _In_ ULONG Bus,
23  _In_ ULONG Lun,
24  _Out_ PPDO_DEVICE_EXTENSION *PdoDeviceExtension)
25 {
26  PPDO_DEVICE_EXTENSION DeviceExtension = NULL;
30 
31  DPRINT("PortCreatePdo(%p %p)\n",
32  FdoDeviceExtension, PdoDeviceExtension);
33 
34  /* Create the port device */
35  Status = IoCreateDevice(FdoDeviceExtension->Device->DriverObject,
36  sizeof(PDO_DEVICE_EXTENSION),
37  NULL,
40  FALSE,
41  &Pdo);
42  if (!NT_SUCCESS(Status))
43  {
44  DPRINT1("IoCreateDevice() failed (Status 0x%lX)\n", Status);
45  return Status;
46  }
47 
48  /* Initialize the device */
51 
52  DeviceExtension = (PPDO_DEVICE_EXTENSION)Pdo->DeviceExtension;
53  RtlZeroMemory(DeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
54 
55  DeviceExtension->ExtensionType = PdoExtension;
56 
57  DeviceExtension->Device = Pdo;
58  DeviceExtension->FdoExtension = FdoDeviceExtension;
59  DeviceExtension->PnpState = dsStopped;
60 
61  /* Add the PDO to the PDO list*/
62  KeAcquireInStackQueuedSpinLock(&FdoDeviceExtension->PdoListLock,
63  &LockHandle);
64  InsertHeadList(&FdoDeviceExtension->PdoListHead,
65  &DeviceExtension->PdoListEntry);
66  FdoDeviceExtension->PdoCount++;
68 
69  DeviceExtension->Bus = Bus;
70  DeviceExtension->Target = Target;
71  DeviceExtension->Lun = Lun;
72 
73 
74  // FIXME: More initialization
75 
76 
77  /* The device has been initialized */
79 
80  *PdoDeviceExtension = DeviceExtension;
81 
82  return STATUS_SUCCESS;
83 }
84 
85 
89 {
91 
92  DPRINT("PortDeletePdo(%p)\n", PdoExtension);
93 
94  /* Remove the PDO from the PDO list*/
95  KeAcquireInStackQueuedSpinLock(&PdoExtension->FdoExtension->PdoListLock,
96  &LockHandle);
97  RemoveEntryList(&PdoExtension->PdoListEntry);
98  PdoExtension->FdoExtension->PdoCount--;
100 
101  if (PdoExtension->InquiryBuffer)
102  {
104  PdoExtension->InquiryBuffer = NULL;
105  }
106 
107 
108  // FIXME: More uninitialization
109 
110 
111  /* Delete the PDO */
112  IoDeleteDevice(PdoExtension->Device);
113 
114  return STATUS_SUCCESS;
115 }
116 
117 
118 NTSTATUS
119 NTAPI
122  _In_ PIRP Irp)
123 {
124  DPRINT1("PortPdoScsi(%p %p)\n", DeviceObject, Irp);
125 
126  Irp->IoStatus.Information = 0;
127  Irp->IoStatus.Status = STATUS_SUCCESS;
129  return STATUS_SUCCESS;
130 }
131 
132 
133 NTSTATUS
134 NTAPI
137  _In_ PIRP Irp)
138 {
139  DPRINT1("PortPdoPnp(%p %p)\n", DeviceObject, Irp);
140 
141  Irp->IoStatus.Information = 0;
142  Irp->IoStatus.Status = STATUS_SUCCESS;
144  return STATUS_SUCCESS;
145 }
146 
147 /* EOF */
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR _In_ UCHAR Lun
Definition: classpnp.h:1117
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI PortPdoPnp(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: pdo.c:135
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
DEVICE_STATE PnpState
Definition: precomp.h:127
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define FILE_DEVICE_MASS_STORAGE
Definition: imports.h:62
VOID FASTCALL KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:130
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PFDO_DEVICE_EXTENSION FdoExtension
Definition: precomp.h:126
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
NTSTATUS PortDeletePdo(_In_ PPDO_DEVICE_EXTENSION PdoExtension)
Definition: pdo.c:87
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LIST_ENTRY PdoListEntry
Definition: precomp.h:128
NTSTATUS NTAPI PortPdoScsi(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: pdo.c:120
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
PDEVICE_OBJECT Device
Definition: precomp.h:125
Status
Definition: gdiplustypes.h:24
EXTENSION_TYPE ExtensionType
Definition: precomp.h:123
NTSTATUS PortCreatePdo(_In_ PFDO_DEVICE_EXTENSION FdoDeviceExtension, _In_ ULONG Bus, _In_ ULONG Target, _In_ ULONG Lun, _Out_ PPDO_DEVICE_EXTENSION *PdoDeviceExtension)
Definition: pdo.c:19
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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:261
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:742
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define TAG_INQUIRY_DATA
Definition: precomp.h:32