Added cdrom class driver skeleton.
[reactos.git] / reactos / drivers / storage / cdrom / cdrom.c
1 /* $Id: cdrom.c,v 1.1 2002/01/31 15:00:00 ekohl Exp $
2 *
3 */
4
5 // -------------------------------------------------------------------------
6
7 #include <ddk/ntddk.h>
8
9 #include "../include/scsi.h"
10 #include "../include/class2.h"
11 #include "../include/ntddscsi.h"
12
13 //#define NDEBUG
14 #include <debug.h>
15
16 #define VERSION "V0.0.1"
17
18
19
20 BOOLEAN STDCALL
21 CdromFindDevices(PDRIVER_OBJECT DriverObject,
22 PUNICODE_STRING RegistryPath,
23 PCLASS_INIT_DATA InitializationData,
24 PDEVICE_OBJECT PortDeviceObject,
25 ULONG PortNumber);
26
27
28 NTSTATUS STDCALL
29 CdromDeviceControl(IN PDEVICE_OBJECT DeviceObject,
30 IN PIRP Irp);
31
32 NTSTATUS STDCALL
33 CdromShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
34 IN PIRP Irp);
35
36
37
38
39 // DriverEntry
40 //
41 // DESCRIPTION:
42 // This function initializes the driver, locates and claims
43 // hardware resources, and creates various NT objects needed
44 // to process I/O requests.
45 //
46 // RUN LEVEL:
47 // PASSIVE_LEVEL
48 //
49 // ARGUMENTS:
50 // IN PDRIVER_OBJECT DriverObject System allocated Driver Object
51 // for this driver
52 // IN PUNICODE_STRING RegistryPath Name of registry driver service
53 // key
54 //
55 // RETURNS:
56 // NTSTATUS
57
58 NTSTATUS STDCALL
59 DriverEntry(IN PDRIVER_OBJECT DriverObject,
60 IN PUNICODE_STRING RegistryPath)
61 {
62 CLASS_INIT_DATA InitData;
63
64 DbgPrint("CD-ROM Class Driver %s\n",
65 VERSION);
66 DPRINT("RegistryPath '%wZ'\n",
67 RegistryPath);
68
69 InitData.InitializationDataSize = sizeof(CLASS_INIT_DATA);
70 InitData.DeviceExtensionSize = sizeof(DEVICE_EXTENSION); // + sizeof(DISK_DATA)
71 InitData.DeviceType = FILE_DEVICE_CD_ROM;
72 InitData.DeviceCharacteristics = 0;
73
74 InitData.ClassError = NULL; // CdromProcessError;
75 InitData.ClassReadWriteVerification = NULL; // CdromReadWriteVerification;
76 InitData.ClassFindDeviceCallBack = NULL; // CdromDeviceVerification;
77 InitData.ClassFindDevices = CdromFindDevices;
78 InitData.ClassDeviceControl = CdromDeviceControl;
79 InitData.ClassShutdownFlush = CdromShutdownFlush;
80 InitData.ClassCreateClose = NULL;
81 InitData.ClassStartIo = NULL;
82
83 return(ScsiClassInitialize(DriverObject,
84 RegistryPath,
85 &InitData));
86 }
87
88
89 // CdromFindDevices
90 //
91 // DESCRIPTION:
92 // This function searches for device that are attached to the given scsi port.
93 //
94 // RUN LEVEL:
95 // PASSIVE_LEVEL
96 //
97 // ARGUMENTS:
98 // IN PDRIVER_OBJECT DriverObject System allocated Driver Object for this driver
99 // IN PUNICODE_STRING RegistryPath Name of registry driver service key
100 // IN PCLASS_INIT_DATA InitializationData Pointer to the main initialization data
101 // IN PDEVICE_OBJECT PortDeviceObject Scsi port device object
102 // IN ULONG PortNumber Port number
103 //
104 // RETURNS:
105 // TRUE: At least one disk drive was found
106 // FALSE: No disk drive found
107 //
108
109 BOOLEAN STDCALL
110 CdromFindDevices(PDRIVER_OBJECT DriverObject,
111 PUNICODE_STRING RegistryPath,
112 PCLASS_INIT_DATA InitializationData,
113 PDEVICE_OBJECT PortDeviceObject,
114 ULONG PortNumber)
115 {
116 PIO_SCSI_CAPABILITIES PortCapabilities;
117 PSCSI_ADAPTER_BUS_INFO AdapterBusInfo;
118 PCHAR Buffer;
119 #if 0
120 ULONG DeviceCount;
121 #endif
122 ULONG ScsiBus;
123 NTSTATUS Status;
124 // PCONFIGURATION_INFORMATION ConfigInfo;
125
126 DPRINT1("CdromFindDevices() called.\n");
127
128 /* Get port capabilities */
129 Status = ScsiClassGetCapabilities(PortDeviceObject,
130 &PortCapabilities);
131 if (!NT_SUCCESS(Status))
132 {
133 DPRINT("ScsiClassGetCapabilities() failed! (Status 0x%lX)\n", Status);
134 return(FALSE);
135 }
136
137 DPRINT1("MaximumTransferLength: %lu\n", PortCapabilities->MaximumTransferLength);
138
139 /* Get inquiry data */
140 Status = ScsiClassGetInquiryData(PortDeviceObject,
141 (PSCSI_ADAPTER_BUS_INFO *)&Buffer);
142 if (!NT_SUCCESS(Status))
143 {
144 DPRINT("ScsiClassGetInquiryData() failed! (Status 0x%lX)\n", Status);
145 return(FALSE);
146 }
147
148 /* Check whether there are unclaimed devices */
149 AdapterBusInfo = (PSCSI_ADAPTER_BUS_INFO)Buffer;
150 #if 0
151 DeviceCount = ScsiClassFindUnclaimedDevices(InitializationData,
152 AdapterBusInfo);
153 if (DeviceCount == 0)
154 {
155 DPRINT("ScsiClassFindUnclaimedDevices() returned 0!");
156 return(FALSE);
157 }
158 #endif
159
160 // ConfigInfo = IoGetConfigurationInformation();
161 // DPRINT1("Number of SCSI ports: %lu\n", ConfigInfo->ScsiPortCount);
162
163 /* Search each bus of this adapter */
164 for (ScsiBus = 0; ScsiBus < (ULONG)AdapterBusInfo->NumberOfBuses; ScsiBus++)
165 {
166 DPRINT("Searching bus %lu\n", ScsiBus);
167 #if 0
168 lunInfo = (PVOID)(Buffer + adapterInfo->BusData[scsiBus].InquiryDataOffset);
169
170
171 while (AdapterBusInfo->BusData[ScsiBus].InquiryDataOffset)
172 {
173
174 }
175 #endif
176 }
177
178 ExFreePool(Buffer);
179 ExFreePool(PortCapabilities);
180
181 return(TRUE);
182 }
183
184
185 // CdromDeviceControl
186 //
187 // DESCRIPTION:
188 // Answer requests for device control calls
189 //
190 // RUN LEVEL:
191 // PASSIVE_LEVEL
192 //
193 // ARGUMENTS:
194 // Standard dispatch arguments
195 //
196 // RETURNS:
197 // NTSTATUS
198 //
199
200 NTSTATUS STDCALL
201 CdromDeviceControl(IN PDEVICE_OBJECT DeviceObject,
202 IN PIRP Irp)
203 {
204 DPRINT("CdromDeviceControl() called!\n");
205
206 Irp->IoStatus.Status = STATUS_SUCCESS;
207 Irp->IoStatus.Information = 0;
208 IoCompleteRequest(Irp, IO_NO_INCREMENT);
209
210 return(STATUS_SUCCESS);
211 }
212
213
214 // CdromShutdownFlush
215 //
216 // DESCRIPTION:
217 // Answer requests for shutdown and flush calls
218 //
219 // RUN LEVEL:
220 // PASSIVE_LEVEL
221 //
222 // ARGUMENTS:
223 // Standard dispatch arguments
224 //
225 // RETURNS:
226 // NTSTATUS
227 //
228
229 NTSTATUS STDCALL
230 CdromShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
231 IN PIRP Irp)
232 {
233 DPRINT("CdromShutdownFlush() called!\n");
234
235 Irp->IoStatus.Status = STATUS_SUCCESS;
236 Irp->IoStatus.Information = 0;
237 IoCompleteRequest(Irp, IO_NO_INCREMENT);
238
239 return(STATUS_SUCCESS);
240 }
241
242
243 /* EOF */