atapi, buslogic, cdrom, class2.
[reactos.git] / reactos / drivers / storage / cdrom / cdrom.c
index 2a41355..8b68040 100644 (file)
 
 /* INCLUDES *****************************************************************/
 
-#include <ddk/ntddk.h>
-#include <ddk/scsi.h>
-#include <ddk/class2.h>
-#include <ddk/ntddscsi.h>
-#include <ntos/minmax.h>
+#include <ntddk.h>
+#include <scsi.h>
+#include <ntddscsi.h>
+#include <ntdddisk.h>
+#include <ntddcdrm.h>
+#include <include/class2.h>
+#include <stdio.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -61,6 +63,26 @@ typedef struct _ERROR_RECOVERY_DATA10
   MODE_READ_RECOVERY_PAGE ReadRecoveryPage;
 } ERROR_RECOVERY_DATA10, *PERROR_RECOVERY_DATA10;
 
+typedef struct _MODE_CAPABILITIES_PAGE2
+{
+  UCHAR PageCode:6;
+  UCHAR Reserved1:1;
+  UCHAR PSBit:1;
+  UCHAR PageLength;
+  UCHAR Reserved2[2];
+  UCHAR Capabilities[4];
+  UCHAR MaximumSpeedSupported[2];
+  UCHAR Reserved3;
+  UCHAR NumberVolumeLevels;
+  UCHAR BufferSize[2];
+  UCHAR CurrentSpeed[2];
+  UCHAR Reserved4;
+  UCHAR Reserved5:1;
+  UCHAR DigitalOutput:4;
+  UCHAR Reserved6:3;
+  UCHAR Reserved7[2];
+} MODE_CAPABILITIES_PAGE2, *PMODE_CAPABILITIES_PAGE2;
+
 typedef struct _MODE_CAPABILITIES_DATA6
 {
   MODE_PARAMETER_HEADER Header;
@@ -134,7 +156,7 @@ VOID STDCALL
 CdromTimerRoutine(IN PDEVICE_OBJECT DeviceObject,
                  IN PVOID Context);
 
-VOID
+VOID STDCALL
 CdromWorkItem(IN PDEVICE_OBJECT DeviceObject,
              IN PVOID Context);
 
@@ -146,7 +168,7 @@ CdromWorkItem(IN PDEVICE_OBJECT DeviceObject,
  *     DriverEntry
  *
  * DESCRIPTION:
- *     This function initializes the driver, locates and claims 
+ *     This function initializes the driver, locates and claims
  *     hardware resources, and creates various NT objects needed
  *     to process I/O requests.
  *
@@ -391,17 +413,10 @@ static VOID
 CdromClassCreateMediaChangeEvent(IN PDEVICE_EXTENSION DeviceExtension,
                                 IN ULONG DeviceNumber)
 {
-  WCHAR NameBuffer[MAX_PATH];
-  UNICODE_STRING Name;
 
-  swprintf (NameBuffer,
-           L"\\Device\\MediaChangeEvent%lu",
-           DeviceNumber);
-  RtlInitUnicodeString (&Name,
-                       NameBuffer);
 
   DeviceExtension->MediaChangeEvent =
-    IoCreateSynchronizationEvent (&Name,
+    IoCreateSynchronizationEvent (NULL,
                                  &DeviceExtension->MediaChangeEventHandle);
 
   KeClearEvent (DeviceExtension->MediaChangeEvent);
@@ -610,9 +625,9 @@ CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
   Cdb->MODE_SENSE.AllocationLength = (UCHAR)Length;
 
   Buffer = ExAllocatePool (NonPagedPool,
-                           max(sizeof(ERROR_RECOVERY_DATA6), 
-                              max(sizeof(ERROR_RECOVERY_DATA10), 
-                                  max(sizeof(MODE_CAPABILITIES_DATA6), 
+                           max(sizeof(ERROR_RECOVERY_DATA6),
+                              max(sizeof(ERROR_RECOVERY_DATA10),
+                                  max(sizeof(MODE_CAPABILITIES_DATA6),
                                       sizeof(MODE_CAPABILITIES_DATA10)))));
   if (Buffer == NULL)
     {
@@ -633,7 +648,7 @@ CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
       /* Try the 10 byte version */
       Length = sizeof(MODE_READ_RECOVERY_PAGE) + MODE_HEADER_LENGTH10;
 
-      RtlZeroMemory (&Srb, 
+      RtlZeroMemory (&Srb,
                     sizeof(SCSI_REQUEST_BLOCK));
       Srb.CdbLength = 10;
       Srb.TimeOutValue = DiskDeviceExtension->TimeOutValue;
@@ -879,17 +894,17 @@ CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
            {
              DbgPrint("  Drive supports software slot selection\n");
            }
-         DbgPrint("  Maximum speed is %d kB/s\n", 
-                 (CapabilitiesData->MaximumSpeedSupported[0] << 8) 
+         DbgPrint("  Maximum speed is %d kB/s\n",
+                 (CapabilitiesData->MaximumSpeedSupported[0] << 8)
                  | CapabilitiesData->MaximumSpeedSupported[1]);
-         DbgPrint("  Current speed is %d kB/s\n", 
-                 (CapabilitiesData->CurrentSpeed[0] << 8) 
+         DbgPrint("  Current speed is %d kB/s\n",
+                 (CapabilitiesData->CurrentSpeed[0] << 8)
                  | CapabilitiesData->CurrentSpeed[1]);
          DbgPrint("  Number of discrete volume levels is %d\n",
-                 (CapabilitiesData->Reserved3 << 8) 
+                 (CapabilitiesData->Reserved3 << 8)
                  | CapabilitiesData->NumberVolumeLevels);
          DbgPrint("  Buffer size is %d kB\n",
-                 (CapabilitiesData->BufferSize[0] << 8) 
+                 (CapabilitiesData->BufferSize[0] << 8)
                  | CapabilitiesData->BufferSize[1]);
 #endif
        }
@@ -931,9 +946,9 @@ CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
  */
 static NTSTATUS
 CdromClassReadTocEntry (PDEVICE_OBJECT DeviceObject,
-                       UINT TrackNo,
+                       SIZE_T TrackNo,
                        PVOID Buffer,
-                       UINT Length)
+                       SIZE_T Length)
 {
   PDEVICE_EXTENSION DeviceExtension;
   SCSI_REQUEST_BLOCK Srb;
@@ -963,9 +978,9 @@ CdromClassReadTocEntry (PDEVICE_OBJECT DeviceObject,
 
 static NTSTATUS
 CdromClassReadLastSession (PDEVICE_OBJECT DeviceObject,
-                          UINT TrackNo,
+                          SIZE_T TrackNo,
                           PVOID Buffer,
-                          UINT Length)
+                          SIZE_T Length)
 {
   PDEVICE_EXTENSION DeviceExtension;
   SCSI_REQUEST_BLOCK Srb;
@@ -1470,10 +1485,10 @@ CdromDeviceControlCompletion (IN PDEVICE_OBJECT DeviceObject,
       if (Retry == TRUE &&
          (ULONG)OrigNextIrpStack->Parameters.Others.Argument1 > 0)
        {
-         DPRINT1 ("Try again (Retry count %lu)\n",
+         DPRINT1 ("Try again (Retry count 0x%p)\n",
                   (ULONG)OrigNextIrpStack->Parameters.Others.Argument1);
 
-         (ULONG)OrigNextIrpStack->Parameters.Others.Argument1--;
+         OrigNextIrpStack->Parameters.Others.Argument1 = (PVOID)((ULONG_PTR)OrigNextIrpStack->Parameters.Others.Argument1 - 1);
 
          /* Release 'old' buffers */
          ExFreePool (Srb->SenseInfoBuffer);
@@ -1640,7 +1655,7 @@ CdromTimerRoutine(IN PDEVICE_OBJECT DeviceObject,
 }
 
 
-VOID
+VOID STDCALL
 CdromWorkItem(IN PDEVICE_OBJECT DeviceObject,
              IN PVOID Context)
 {