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
18 NTSTATUS
PortCreatePdo(_In_ PFDO_DEVICE_EXTENSION FdoDeviceExtension,_In_ ULONG Bus,_In_ ULONG Target,_In_ ULONG Lun,_Out_ PPDO_DEVICE_EXTENSION * PdoDeviceExtension)19 PortCreatePdo(
20 _In_ PFDO_DEVICE_EXTENSION FdoDeviceExtension,
21 _In_ ULONG Bus,
22 _In_ ULONG Target,
23 _In_ ULONG Lun,
24 _Out_ PPDO_DEVICE_EXTENSION *PdoDeviceExtension)
25 {
26 PPDO_DEVICE_EXTENSION DeviceExtension = NULL;
27 PDEVICE_OBJECT Pdo = NULL;
28 KLOCK_QUEUE_HANDLE LockHandle;
29 NTSTATUS Status;
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,
38 FILE_DEVICE_MASS_STORAGE,
39 FILE_DEVICE_SECURE_OPEN | FILE_AUTOGENERATED_DEVICE_NAME,
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 */
49 Pdo->Flags |= DO_DIRECT_IO;
50 Pdo->Flags |= DO_POWER_PAGABLE;
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++;
67 KeReleaseInStackQueuedSpinLock(&LockHandle);
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 */
78 Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
79
80 *PdoDeviceExtension = DeviceExtension;
81
82 return STATUS_SUCCESS;
83 }
84
85
86 NTSTATUS
PortDeletePdo(_In_ PPDO_DEVICE_EXTENSION PdoExtension)87 PortDeletePdo(
88 _In_ PPDO_DEVICE_EXTENSION PdoExtension)
89 {
90 KLOCK_QUEUE_HANDLE LockHandle;
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--;
99 KeReleaseInStackQueuedSpinLock(&LockHandle);
100
101 if (PdoExtension->InquiryBuffer)
102 {
103 ExFreePoolWithTag(PdoExtension->InquiryBuffer, TAG_INQUIRY_DATA);
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
PortPdoScsi(_In_ PDEVICE_OBJECT DeviceObject,_In_ PIRP Irp)120 PortPdoScsi(
121 _In_ PDEVICE_OBJECT DeviceObject,
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;
128 IoCompleteRequest(Irp, IO_NO_INCREMENT);
129 return STATUS_SUCCESS;
130 }
131
132
133 NTSTATUS
134 NTAPI
PortPdoPnp(_In_ PDEVICE_OBJECT DeviceObject,_In_ PIRP Irp)135 PortPdoPnp(
136 _In_ PDEVICE_OBJECT DeviceObject,
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;
143 IoCompleteRequest(Irp, IO_NO_INCREMENT);
144 return STATUS_SUCCESS;
145 }
146
147 /* EOF */
148