+/**********************************************************************
+ * NAME EXPORTED
+ * CdromClassCheckDevice
+ *
+ * DESCRIPTION
+ * This function checks the InquiryData for the correct device
+ * type and qualifier.
+ *
+ * RUN LEVEL
+ * PASSIVE_LEVEL
+ *
+ * ARGUMENTS
+ * InquiryData
+ * Pointer to the inquiry data for the device in question.
+ *
+ * RETURN VALUE
+ * TRUE: A disk device was found.
+ * FALSE: Otherwise.
+ */
+
+BOOLEAN STDCALL
+CdromClassCheckDevice(IN PINQUIRYDATA InquiryData)
+{
+ return((InquiryData->DeviceType == READ_ONLY_DIRECT_ACCESS_DEVICE) &&
+ (InquiryData->DeviceTypeQualifier == 0));
+}
+
+
+/**********************************************************************
+ * NAME EXPORTED
+ * CdromClassCheckReadWrite
+ *
+ * DESCRIPTION
+ * This function checks the given IRP for correct data.
+ *
+ * RUN LEVEL
+ * PASSIVE_LEVEL
+ *
+ * ARGUMENTS
+ * DeviceObject
+ * Pointer to the device.
+ *
+ * Irp
+ * Irp to check.
+ *
+ * RETURN VALUE
+ * STATUS_SUCCESS: The IRP matches the requirements of the given device.
+ * Others: Failure.
+ */
+
+NTSTATUS STDCALL
+CdromClassCheckReadWrite(IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp)
+{
+ DPRINT1("CdromClassCheckReadWrite() called\n");
+
+ return(STATUS_SUCCESS);
+}
+
+
+// CdromClassCreateDeviceObject
+//
+// DESCRIPTION:
+// Create the raw device and any partition devices on this drive
+//
+// RUN LEVEL:
+// PASSIVE_LEVEL
+//
+// ARGUMENTS:
+// IN PDRIVER_OBJECT DriverObject The system created driver object
+// IN PCONTROLLER_OBJECT ControllerObject
+// IN PIDE_CONTROLLER_EXTENSION ControllerExtension
+// The IDE controller extension for
+// this device
+// IN int DriveIdx The index of the drive on this
+// controller
+// IN int HarddiskIdx The NT device number for this
+// drive
+//
+// RETURNS:
+// TRUE Drive exists and devices were created
+// FALSE no devices were created for this device
+//
+
+static NTSTATUS
+CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
+ IN PUNICODE_STRING RegistryPath, /* what's this used for? */
+ IN PDEVICE_OBJECT PortDeviceObject,
+ IN ULONG PortNumber,
+ IN ULONG DeviceNumber,
+ IN PIO_SCSI_CAPABILITIES Capabilities,
+ IN PSCSI_INQUIRY_DATA InquiryData,
+ IN PCLASS_INIT_DATA InitializationData)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING UnicodeDeviceDirName;
+ CHAR NameBuffer[80];
+ PDEVICE_OBJECT DiskDeviceObject;
+ PDEVICE_EXTENSION DiskDeviceExtension; /* defined in class2.h */
+ HANDLE Handle;
+ PCDROM_DATA CdromData;
+ NTSTATUS Status;
+
+ DPRINT1("CdromClassCreateDeviceObject() called\n");
+
+ /* Claim the cdrom device */
+ Status = ScsiClassClaimDevice(PortDeviceObject,
+ InquiryData,
+ FALSE,
+ &PortDeviceObject);
+ if (!NT_SUCCESS(Status))
+ {
+ DbgPrint("Could not claim cdrom device\n");
+ return(Status);
+ }
+
+ /* Create cdrom device */
+ sprintf(NameBuffer,
+ "\\Device\\CdRom%lu",
+ DeviceNumber);
+
+ Status = ScsiClassCreateDeviceObject(DriverObject,
+ NameBuffer,
+ NULL,
+ &DiskDeviceObject,
+ InitializationData);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("ScsiClassCreateDeviceObject() failed (Status %x)\n", Status);
+
+ /* Release (unclaim) the disk */
+ ScsiClassClaimDevice(PortDeviceObject,
+ InquiryData,
+ TRUE,
+ NULL);
+
+ return(Status);
+ }
+
+ DiskDeviceObject->Flags |= DO_DIRECT_IO;
+ DiskDeviceObject->Characteristics |= FILE_REMOVABLE_MEDIA;
+ DiskDeviceObject->StackSize = (CCHAR)PortDeviceObject->StackSize + 1;
+
+ if (PortDeviceObject->AlignmentRequirement > DiskDeviceObject->AlignmentRequirement)
+ {
+ DiskDeviceObject->AlignmentRequirement = PortDeviceObject->AlignmentRequirement;
+ }
+
+ DiskDeviceExtension = DiskDeviceObject->DeviceExtension;
+ DiskDeviceExtension->LockCount = 0;
+ DiskDeviceExtension->DeviceNumber = DeviceNumber;
+ DiskDeviceExtension->PortDeviceObject = PortDeviceObject;
+
+ /* FIXME: Not yet! Will cause pointer corruption! */
+// DiskDeviceExtension->PortCapabilities = PortCapabilities;
+
+ DiskDeviceExtension->StartingOffset.QuadPart = 0;
+ DiskDeviceExtension->PortNumber = (UCHAR)PortNumber;
+ DiskDeviceExtension->PathId = InquiryData->PathId;
+ DiskDeviceExtension->TargetId = InquiryData->TargetId;
+ DiskDeviceExtension->Lun = InquiryData->Lun;
+
+ /* zero-out disk data */
+ CdromData = (PCDROM_DATA)(DiskDeviceExtension + 1);
+ RtlZeroMemory(CdromData,
+ sizeof(CDROM_DATA));
+
+#if 0
+ /* Get disk geometry */
+ DiskDeviceExtension->DiskGeometry = ExAllocatePool(NonPagedPool,
+ sizeof(DISK_GEOMETRY));
+ if (DiskDeviceExtension->DiskGeometry == NULL)
+ {
+ DPRINT1("Failed to allocate geometry buffer!\n");
+
+ IoDeleteDevice(DiskDeviceObject);
+
+ /* Release (unclaim) the disk */
+ ScsiClassClaimDevice(PortDeviceObject,
+ InquiryData,
+ TRUE,
+ NULL);
+
+ return(STATUS_INSUFFICIENT_RESOURCES);
+ }
+
+ /* Read the drive's capacity */
+ Status = ScsiClassReadDriveCapacity(DiskDeviceObject);
+ if (!NT_SUCCESS(Status) &&
+ (DiskDeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) == 0)
+ {
+ DPRINT1("Failed to retrieve drive capacity!\n");
+ return(STATUS_SUCCESS);
+ }
+ else
+ {
+ /* Clear the verify flag for non-removable media drives. */
+ DiskDeviceObject->Flags &= ~DO_VERIFY_VOLUME;
+ }
+
+ DPRINT1("SectorSize: %lu\n", DiskDeviceExtension->DiskGeometry->BytesPerSector);
+#endif
+
+
+
+ DPRINT1("CdromClassCreateDeviceObjects() done\n");
+
+ return(STATUS_SUCCESS);
+}
+
+
+
+// CdromClassDeviceControl