--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -2,16 +2,14 @@
  * ioctl.c: DVD ioctl replacement function
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id$
+ * $Id: ioctl.c,v 1.1 2001/12/22 00:08:13 sam Exp $
  *
  * Authors: Markus Kuespert <ltlBeBoy@beosmail.com>
- *          Sam Hocevar <sam@zoy.org>
+ *          Samuel Hocevar <sam@zoy.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
- *          HĂĽkan Hjort <d95hjort@dtek.chalmers.se>
+ *          Hĺkan Hjort <d95hjort@dtek.chalmers.se>
  *          Eugenio Jarosiewicz <ej0@cise.ufl.edu>
- *          David SiebĂśrger <drs-videolan@rucus.ru.ac.za>
- *          Alex Strelnikov <lelik@os2.ru>
- *          Gildas Bazin <gbazin@netcourrier.com>
+ *          David Siebörger <drs-videolan@rucus.ru.ac.za>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -41,13 +39,6 @@
 #if defined( WIN32 )
 #   include <windows.h>
 #   include <winioctl.h>
-#elif defined ( SYS_OS2 )
-#   define INCL_DOSFILEMGR
-#   define INCL_DOSDEVICES
-#   define INCL_DOSDEVIOCTL
-#   define INCL_DOSERRORS
-#   include <os2.h>
-#   include <sys/ioctl.h>
 #else
 #   include <netinet/in.h>
 #   include <sys/ioctl.h>
@@ -76,18 +67,15 @@
 #   include <sys/scsi.h>
 #endif
 #ifdef SOLARIS_USCSI
-#   include <dlfcn.h>
 #   include <unistd.h>
 #   include <stropts.h>
 #   include <sys/scsi/scsi_types.h>
 #   include <sys/scsi/impl/uscsi.h>
 #endif
-#ifdef DARWIN_DVD_IOCTL
+
+#ifdef SYS_DARWIN
 #   include <IOKit/storage/IODVDMediaBSDClient.h>
-#endif
-#ifdef __QNXNTO__
-#   include <sys/mman.h>
-#   include <sys/dcmd_cam.h>
+/* #   include "DVDioctl/DVDioctl.h" */
 #endif
 
 #include "common.h"
@@ -113,30 +101,14 @@
  *****************************************************************************/
 #if defined( SOLARIS_USCSI )
 static void SolarisInitUSCSI( struct uscsi_cmd *p_sc, int i_type );
-static int SolarisSendUSCSI( int fd, struct uscsi_cmd *p_sc );
 #endif
 
 /*****************************************************************************
  * Local prototypes, win32 (aspi) specific
  *****************************************************************************/
 #if defined( WIN32 )
-static void WinInitSPTD ( SCSI_PASS_THROUGH_DIRECT *, int );
-static void WinInitSSC  ( struct SRB_ExecSCSICmd *, int );
-static int  WinSendSSC  ( int, struct SRB_ExecSCSICmd * );
-#endif
-
-/*****************************************************************************
- * Local prototypes, QNX specific
- *****************************************************************************/
-#if defined( __QNXNTO__ )
-static void QNXInitCPT ( CAM_PASS_THRU *, int );
-#endif
-
-/*****************************************************************************
- * Local prototypes, OS2 specific
- *****************************************************************************/
-#if defined( SYS_OS2 )
-static void OS2InitSDC( struct OS2_ExecSCSICmd *, int );
+static void WinInitSSC ( struct SRB_ExecSCSICmd *, int );
+static int  WinSendSSC ( int, struct SRB_ExecSCSICmd * );
 #endif
 
 /*****************************************************************************
@@ -190,49 +162,71 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_READ_DVD_STRUCTURE, 8 );
-
+    
     rs_cdb.cdb_opaque[ 6 ] = i_layer;
     rs_cdb.cdb_opaque[ 7 ] = DVD_STRUCT_COPYRIGHT;
 
-    i_ret = SolarisSendUSCSI(i_fd, &sc);
+    i_ret = ioctl(i_fd, USCSICMD, &sc);
 
     if( i_ret < 0 || sc.uscsi_status ) {
         i_ret = -1;
     }
-
+    
     *pi_copyright = p_buffer[ 4 ];
     /* s->copyright.rmi = p_buffer[ 5 ]; */
 
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_read_structure_t, DVDCopyrightInfo,
-                   kDVDStructureFormatCopyrightInfo );
-
+#elif defined( SYS_DARWIN )
+    dk_dvd_read_structure_t dvd;
+    DVDCopyrightInfo dvdcpi;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdcpi, 0, sizeof(dvdcpi));
+
+    dvd.buffer = &dvdcpi;
+    dvd.bufferLength = sizeof(dvdcpi);
+    dvd.format = kDVDStructureFormatCopyrightInfo;
     dvd.layer = i_layer;
 
+    /* dvdcpi.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    /* dvdcpi.dataLength[1] = 0x06; */
+    
     i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd );
 
-    *pi_copyright = dvdbs.copyrightProtectionSystemType;
+    *pi_copyright = dvdcpi.copyrightProtectionSystemType;
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
-    {
-        INIT_SPTD( GPCMD_READ_DVD_STRUCTURE, 8 );
-
-        /*  When using IOCTL_DVD_READ_STRUCTURE and
+    if( WIN2K ) /* NT/Win2000/Whistler */
+    {
+        DWORD tmp;
+        u8 p_buffer[ 8 ];
+        SCSI_PASS_THROUGH_DIRECT sptd;
+
+        memset( &sptd, 0, sizeof( sptd ) );
+        memset( &p_buffer, 0, sizeof( p_buffer ) );
+   
+        /*  When using IOCTL_DVD_READ_STRUCTURE and 
             DVD_COPYRIGHT_DESCRIPTOR, CopyrightProtectionType
-            seems to be always 6 ???
-            To work around this MS bug we try to send a raw scsi command
-            instead (if we've got enough privileges to do so). */
-
-        sptd.Cdb[ 6 ] = i_layer;
-        sptd.Cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;
-
-        i_ret = SEND_SPTD( i_fd, &sptd, &tmp );
-
-        if( i_ret == 0 )
-        {
-            *pi_copyright = p_buffer[ 4 ];
-        }
+            is always 6. So we send a raw scsi command instead. */
+
+        sptd.Length             = sizeof( SCSI_PASS_THROUGH_DIRECT );
+        sptd.CdbLength          = 12;
+        sptd.DataIn             = SCSI_IOCTL_DATA_IN;
+        sptd.DataTransferLength = 8;
+        sptd.TimeOutValue       = 2;
+        sptd.DataBuffer         = p_buffer;
+        sptd.Cdb[ 0 ]           = GPCMD_READ_DVD_STRUCTURE;
+        sptd.Cdb[ 6 ]           = i_layer;
+        sptd.Cdb[ 7 ]           = DVD_STRUCT_COPYRIGHT;
+        sptd.Cdb[ 8 ]           = (8 >> 8) & 0xff;
+        sptd.Cdb[ 9 ]           =  8       & 0xff;
+
+        i_ret = DeviceIoControl( (HANDLE) i_fd,
+                             IOCTL_SCSI_PASS_THROUGH_DIRECT,
+                             &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+                             &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+                             &tmp, NULL ) ? 0 : -1;
+
+        *pi_copyright = p_buffer[ 4 ];
     }
     else
     {
@@ -247,30 +241,18 @@
     }
 
 #elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_READ_DVD_STRUCTURE, 8 );
-
-    p_cpt->cam_cdb[ 6 ] = i_layer;
-    p_cpt->cam_cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    *pi_copyright = p_buffer[4];
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_READ_DVD_STRUCTURE, 8 );
-
-    sdc.command[ 6 ] = i_layer;
-    sdc.command[ 7 ] = DVD_STRUCT_COPYRIGHT;
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    *pi_copyright = p_buffer[ 4 ];
+    /*
+        QNX RTOS currently doesn't have a CAM
+        interface (they're working on it though).
+        Assume DVD is not encrypted.
+    */
+
+    *pi_copyright = 0;
+    i_ret = 0;
 
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -279,7 +261,7 @@
 /*****************************************************************************
  * ioctl_ReadDiscKey: get the disc key
  *****************************************************************************/
-int ioctl_ReadDiscKey( int i_fd, int *pi_agid, uint8_t *p_key )
+int ioctl_ReadDiscKey( int i_fd, int *pi_agid, u8 *p_key )
 {
     int i_ret;
 
@@ -322,7 +304,7 @@
 
     rdc.command[ 7 ]  = DVD_STRUCT_DISCKEY;
     rdc.command[ 10 ] = *pi_agid << 6;
-
+    
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
 
     if( i_ret < 0 )
@@ -337,7 +319,7 @@
 
     sctl_io.cdb[ 7 ]  = DVD_STRUCT_DISCKEY;
     sctl_io.cdb[ 10 ] = *pi_agid << 6;
-
+    
     i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
 
     if( i_ret < 0 )
@@ -349,12 +331,12 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
-
+    
     rs_cdb.cdb_opaque[ 7 ] = DVD_STRUCT_DISCKEY;
     rs_cdb.cdb_opaque[ 10 ] = *pi_agid << 6;
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
     if( i_ret < 0 || sc.uscsi_status )
     {
         i_ret = -1;
@@ -363,21 +345,31 @@
 
     memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
 
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_read_structure_t, DVDDiscKeyInfo,
-                   kDVDStructureFormatDiscKeyInfo );
-
+#elif defined( SYS_DARWIN )
+    dk_dvd_read_structure_t dvd;
+    DVDDiscKeyInfo dvddki;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvddki, 0, sizeof(dvddki));
+
+    dvd.buffer = &dvddki;
+    dvd.bufferLength = sizeof(dvddki);
+    dvd.format = kDVDStructureFormatDiscKeyInfo;
     dvd.grantID = *pi_agid;
 
+    /* 2048+2 ; maybe we should do bit shifts to value of (sizeof(dvddki)-2) */
+    dvddki.dataLength[ 0 ] = 0x04;
+    dvddki.dataLength[ 1 ] = 0x02;
+
     i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd );
 
-    memcpy( p_key, dvdbs.discKeyStructures, DVD_DISCKEY_SIZE );
+    memcpy( p_key, dvddki.discKeyStructures, DVD_DISCKEY_SIZE );
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_DISK_KEY_LENGTH];
+        u8 buffer[DVD_DISK_KEY_LENGTH];
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
@@ -387,63 +379,36 @@
         key->KeyType    = DvdDiskKey;
         key->KeyFlags   = 0;
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key, 
                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
+
+        if( i_ret < 0 )
+        {   
+            return i_ret;
+        }
+
+        memcpy( p_key, key->KeyData, DVD_DISCKEY_SIZE );
+    }
+    else
+    {
+        INIT_SSC( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
+
+        ssc.CDBByte[ 7 ]  = DVD_STRUCT_DISCKEY;
+        ssc.CDBByte[ 10 ] = *pi_agid << 6;
+    
+        i_ret = WinSendSSC( i_fd, &ssc );
 
         if( i_ret < 0 )
         {
             return i_ret;
         }
 
-        memcpy( p_key, key->KeyData, DVD_DISCKEY_SIZE );
-    }
-    else
-    {
-        INIT_SSC( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
-
-        ssc.CDBByte[ 7 ]  = DVD_STRUCT_DISCKEY;
-        ssc.CDBByte[ 10 ] = *pi_agid << 6;
-
-        i_ret = WinSendSSC( i_fd, &ssc );
-
-        if( i_ret < 0 )
-        {
-            return i_ret;
-        }
-
         memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
-
-    p_cpt->cam_cdb[ 7 ] = DVD_STRUCT_DISCKEY;
-    p_cpt->cam_cdb[ 10 ] = *pi_agid << 6;
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
-
-#elif defined ( SYS_OS2 )
-    INIT_SSC( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
-
-    sdc.command[ 7 ]  = DVD_STRUCT_DISCKEY;
-    sdc.command[ 10 ] = *pi_agid << 6;
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    if( i_ret < 0 )
-    {
-        return i_ret;
-    }
-
-    memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
-
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -452,7 +417,7 @@
 /*****************************************************************************
  * ioctl_ReadTitleKey: get the title key
  *****************************************************************************/
-int ioctl_ReadTitleKey( int i_fd, int *pi_agid, int i_pos, uint8_t *p_key )
+int ioctl_ReadTitleKey( int i_fd, int *pi_agid, int i_pos, u8 *p_key )
 {
     int i_ret;
 
@@ -508,15 +473,15 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_REPORT_KEY, 12 );
-
+    
     rs_cdb.cdb_opaque[ 2 ] = ( i_pos >> 24 ) & 0xff;
     rs_cdb.cdb_opaque[ 3 ] = ( i_pos >> 16 ) & 0xff;
     rs_cdb.cdb_opaque[ 4 ] = ( i_pos >>  8 ) & 0xff;
     rs_cdb.cdb_opaque[ 5 ] = ( i_pos       ) & 0xff;
     rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
     if( i_ret < 0 || sc.uscsi_status )
     {
         i_ret = -1;
@@ -526,38 +491,51 @@
     /* a->lstk.cpm    = (buf[ 4 ] >> 7) & 1; */
     /* a->lstk.cp_sec = (buf[ 4 ] >> 6) & 1; */
     /* a->lstk.cgms   = (buf[ 4 ] >> 4) & 3; */
-
-    memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_report_key_t, DVDTitleKeyInfo,
-                   kDVDKeyFormatTitleKey );
-
-    dvd.address = i_pos;
+ 
+    memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE ); 
+    
+#elif defined( SYS_DARWIN )
+    dk_dvd_report_key_t dvd;
+    DVDTitleKeyInfo dvdtki;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdtki, 0, sizeof(dvdtki));
+
+    dvd.buffer = &dvdtki;
+    dvd.bufferLength = sizeof(dvdtki);
+    dvd.format = kDVDKeyFormatTitleKey;
     dvd.grantID = *pi_agid;
-    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
+    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM; /* or this - this is memset 0x00 anyways */
+
+    /* dvdtki.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    dvdtki.dataLength[ 1 ] = 0x0a;
+    
+    /* What are DVDTitleKeyInfo.{CP_MOD,CGMS,CP_SEC,CPM} and do they need to be set? */
+#warning "Correct title key reading for MacOSX / Darwin!"
+    /* hh: No that should be part of the result I belive.
+     * You do need to set the sector/lba/position somehow though! */
 
     i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
 
-    memcpy( p_key, dvdbs.titleKeyValue, DVD_KEY_SIZE );
+    memcpy( p_key, dvdtki.titleKeyValue, DVD_KEY_SIZE );
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_TITLE_KEY_LENGTH];
+        u8 buffer[DVD_BUS_KEY_LENGTH];
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
 
-        key->KeyLength  = DVD_TITLE_KEY_LENGTH;
+        key->KeyLength  = DVD_BUS_KEY_LENGTH;
         key->SessionId  = *pi_agid;
         key->KeyType    = DvdTitleKey;
         key->KeyFlags   = 0;
-        key->Parameters.TitleOffset.QuadPart = (LONGLONG) i_pos *
-                                                   2048 /*DVDCSS_BLOCK_SIZE*/;
-
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
+#warning "Fix ReadTitleKey for WIN32!"
+        //key->Parameters.TitleOffset = i_pos; // is this ok?
+
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key, 
                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
 
         memcpy( p_key, key->KeyData, DVD_KEY_SIZE );
@@ -577,37 +555,9 @@
         memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_REPORT_KEY, 12 );
-
-    p_cpt->cam_cdb[ 2 ] = ( i_pos >> 24 ) & 0xff;
-    p_cpt->cam_cdb[ 3 ] = ( i_pos >> 16 ) & 0xff;
-    p_cpt->cam_cdb[ 4 ] = ( i_pos >>  8 ) & 0xff;
-    p_cpt->cam_cdb[ 5 ] = ( i_pos       ) & 0xff;
-    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_REPORT_KEY, 12 );
-
-    sdc.command[ 2 ] = ( i_pos >> 24 ) & 0xff;
-    sdc.command[ 3 ] = ( i_pos >> 16 ) & 0xff;
-    sdc.command[ 4 ] = ( i_pos >>  8 ) & 0xff;
-    sdc.command[ 5 ] = ( i_pos       ) & 0xff;
-    sdc.command[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
-
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
 
@@ -664,36 +614,46 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_REPORT_KEY, 8 );
-
+    
     rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
     if( i_ret < 0 || sc.uscsi_status )
     {
         i_ret = -1;
     }
 
     *pi_agid = p_buffer[ 7 ] >> 6;
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_report_key_t, DVDAuthenticationGrantIDInfo,
-                   kDVDKeyFormatAGID_CSS );
-
+    
+#elif defined( SYS_DARWIN )
+    dk_dvd_report_key_t dvd;
+    DVDAuthenticationGrantIDInfo dvdagid;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdagid, 0, sizeof(dvdagid));
+
+    dvd.buffer = &dvdagid;
+    dvd.bufferLength = sizeof(dvdagid);
+    dvd.format = kDVDKeyFormatAGID_CSS;
     dvd.grantID = *pi_agid;
-    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
+    dvdagid.grantID = *pi_agid; /* do we need this? */
+    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM; /* or this - this is memset 0x00 anyways */
+
+    /* dvdagid.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    /* dvdagid.dataLength[1] = 0x06; */
 
     i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
 
-    *pi_agid = dvdbs.grantID;
+    *pi_agid = dvdagid.grantID;
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         ULONG id;
         DWORD tmp;
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_START_SESSION,
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_START_SESSION, 
                         &tmp, 4, &id, sizeof( id ), &tmp, NULL ) ? 0 : -1;
 
         *pi_agid = id;
@@ -709,29 +669,9 @@
         *pi_agid = p_buffer[ 7 ] >> 6;
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_REPORT_KEY, 8 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    *pi_agid = p_buffer[ 7 ] >> 6;
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_REPORT_KEY, 8 );
-
-    sdc.command[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    *pi_agid = p_buffer[ 7 ] >> 6;
-
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -740,7 +680,7 @@
 /*****************************************************************************
  * ioctl_ReportChallenge: get challenge from the drive
  *****************************************************************************/
-int ioctl_ReportChallenge( int i_fd, int *pi_agid, uint8_t *p_challenge )
+int ioctl_ReportChallenge( int i_fd, int *pi_agid, u8 *p_challenge )
 {
     int i_ret;
 
@@ -786,33 +726,42 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_REPORT_KEY, 16 );
-
+    
     rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
     if( i_ret < 0 || sc.uscsi_status )
     {
         i_ret = -1;
     }
 
     memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_report_key_t, DVDChallengeKeyInfo,
-                   kDVDKeyFormatChallengeKey );
-
+    
+#elif defined( SYS_DARWIN )
+    dk_dvd_report_key_t dvd;
+    DVDChallengeKeyInfo dvdcki;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdcki, 0, sizeof(dvdcki));
+
+    dvd.buffer = &dvdcki;
+    dvd.bufferLength = sizeof(dvdcki);
+    dvd.format = kDVDKeyFormatChallengeKey;
     dvd.grantID = *pi_agid;
 
+    /* dvdcki.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    dvdcki.dataLength[ 1 ] = 0x0e;
+
     i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
 
-    memcpy( p_challenge, dvdbs.challengeKeyValue, DVD_CHALLENGE_SIZE );
+    memcpy( p_challenge, dvdcki.challengeKeyValue, DVD_CHALLENGE_SIZE );
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_CHALLENGE_KEY_LENGTH];
+        u8 buffer[DVD_CHALLENGE_KEY_LENGTH];
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
@@ -822,7 +771,7 @@
         key->KeyType    = DvdChallengeKey;
         key->KeyFlags   = 0;
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key, 
                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
 
         if( i_ret < 0 )
@@ -843,29 +792,9 @@
         memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_REPORT_KEY, 16 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_REPORT_KEY, 16 );
-
-    sdc.command[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
-
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -920,31 +849,42 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_REPORT_KEY, 8 );
-
+    
     rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_ASF;
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
     if( i_ret < 0 || sc.uscsi_status )
     {
         i_ret = -1;
     }
 
     *pi_asf = p_buffer[ 7 ] & 1;
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_report_key_t, DVDAuthenticationSuccessFlagInfo,
-                   kDVDKeyFormatASF );
-
+    
+#elif defined( SYS_DARWIN )
+    dk_dvd_report_key_t dvd;
+    DVDAuthenticationSuccessFlagInfo dvdasfi;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdasfi, 0, sizeof(dvdasfi));
+
+    dvd.buffer = &dvdasfi;
+    dvd.bufferLength = sizeof(dvdasfi);
+    dvd.format = kDVDKeyFormatASF;
+    dvdasfi.successFlag = *pi_asf;
+
+    /* dvdasfi.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    dvdasfi.dataLength[ 1 ] = 0x06;
+    
     i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
 
-    *pi_asf = dvdbs.successFlag;
+    *pi_asf = dvdasfi.successFlag;
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_ASF_LENGTH];
+        u8 buffer[DVD_ASF_LENGTH];
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
@@ -955,7 +895,7 @@
 
         ((PDVD_ASF)key->KeyData)->SuccessFlag = *pi_asf;
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key, 
                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
 
         if( i_ret < 0 )
@@ -976,29 +916,9 @@
         *pi_asf = p_buffer[ 7 ] & 1;
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_REPORT_KEY, 8 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_ASF;
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    *pi_asf = p_buffer[ 7 ] & 1;
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_REPORT_KEY, 8 );
-
-    sdc.command[ 10 ] = DVD_REPORT_ASF;
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    *pi_asf = p_buffer[ 7 ] & 1;
-
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -1007,7 +927,7 @@
 /*****************************************************************************
  * ioctl_ReportKey1: get the first key from the drive
  *****************************************************************************/
-int ioctl_ReportKey1( int i_fd, int *pi_agid, uint8_t *p_key )
+int ioctl_ReportKey1( int i_fd, int *pi_agid, u8 *p_key )
 {
     int i_ret;
 
@@ -1053,33 +973,42 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_REPORT_KEY, 12 );
-
+    
     rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
     if( i_ret < 0 || sc.uscsi_status )
     {
         i_ret = -1;
     }
 
     memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_report_key_t, DVDKey1Info,
-                   kDVDKeyFormatKey1 );
-
+    
+#elif defined( SYS_DARWIN )
+    dk_dvd_report_key_t dvd;
+    DVDKey1Info dvdk1i;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdk1i, 0, sizeof(dvdk1i));
+
+    dvd.buffer = &dvdk1i;
+    dvd.bufferLength = sizeof(dvdk1i);
+    dvd.format = kDVDKeyFormatKey1;
     dvd.grantID = *pi_agid;
+    
+    /* dvdk1i.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    dvdk1i.dataLength[ 1 ] = 0x0a;
 
     i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
 
-    memcpy( p_key, dvdbs.key1Value, DVD_KEY_SIZE );
+    memcpy( p_key, dvdk1i.key1Value, DVD_KEY_SIZE );
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_BUS_KEY_LENGTH];
+        u8 buffer[DVD_BUS_KEY_LENGTH];
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
@@ -1089,7 +1018,7 @@
         key->KeyType    = DvdBusKey1;
         key->KeyFlags   = 0;
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key, 
                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
 
         memcpy( p_key, key->KeyData, DVD_KEY_SIZE );
@@ -1105,29 +1034,9 @@
         memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_REPORT_KEY, 12 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_REPORT_KEY, 12 );
-
-    sdc.command[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
-
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -1174,30 +1083,40 @@
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_REPORT_KEY, 0 );
-
+    
     rs_cdb.cdb_opaque[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
     if( i_ret < 0 || sc.uscsi_status )
     {
         i_ret = -1;
     }
 
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_send_key_t, DVDAuthenticationGrantIDInfo,
-                   kDVDKeyFormatAGID_Invalidate );
-
+#elif defined( SYS_DARWIN )
+    dk_dvd_send_key_t dvd;
+    DVDAuthenticationGrantIDInfo dvdagid;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdagid, 0, sizeof(dvdagid));
+
+    dvd.buffer = &dvdagid;
+    dvd.bufferLength = sizeof(dvdagid);
+    dvd.format = kDVDKeyFormatAGID_Invalidate;
     dvd.grantID = *pi_agid;
+    dvdagid.grantID = *pi_agid; /* we need this? */
+    
+    /* dvdagid.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    /* dvdagid.dataLength[1] = 0x06; */
 
     i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_END_SESSION,
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_END_SESSION, 
                     pi_agid, sizeof( *pi_agid ), NULL, 0, &tmp, NULL ) ? 0 : -1;
     }
     else
@@ -1217,28 +1136,9 @@
         i_ret = WinSendSSC( i_fd, &ssc );
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_REPORT_KEY, 0 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_REPORT_KEY, 1 );
-
-    sdc.data_length = 0;
-    sdc.command[ 8 ] = 0;
-    sdc.command[ 9 ] = 0;
-
-    sdc.command[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        NULL, 0, &ulDataLen);
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -1247,7 +1147,7 @@
 /*****************************************************************************
  * ioctl_SendChallenge: send challenge to the drive
  *****************************************************************************/
-int ioctl_SendChallenge( int i_fd, int *pi_agid, uint8_t *p_challenge )
+int ioctl_SendChallenge( int i_fd, int *pi_agid, u8 *p_challenge )
 {
     int i_ret;
 
@@ -1260,7 +1160,7 @@
 
     memcpy( auth_info.hsc.chal, p_challenge, DVD_CHALLENGE_SIZE );
 
-    i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
+    return ioctl( i_fd, DVD_AUTH, &auth_info );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
     struct dvd_authinfo auth_info;
@@ -1271,7 +1171,7 @@
 
     memcpy( auth_info.keychal, p_challenge, DVD_CHALLENGE_SIZE );
 
-    i_ret = ioctl( i_fd, DVDIOCSENDKEY, &auth_info );
+    return ioctl( i_fd, DVDIOCSENDKEY, &auth_info );
 
 #elif defined( SYS_BEOS )
     INIT_RDC( GPCMD_SEND_KEY, 16 );
@@ -1281,7 +1181,7 @@
     p_buffer[ 1 ] = 0xe;
     memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
 
-    i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    return ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
 
 #elif defined( HPUX_SCTL_IO )
     INIT_SCTL_IO( GPCMD_SEND_KEY, 16 );
@@ -1291,40 +1191,47 @@
     p_buffer[ 1 ] = 0xe;
     memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
 
-    i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
+    return ioctl( i_fd, SIOC_IO, &sctl_io );
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_SEND_KEY, 16 );
-
+    
     rs_cdb.cdb_opaque[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
-
+    
     p_buffer[ 1 ] = 0xe;
     memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
-
-    if( SolarisSendUSCSI( i_fd, &sc ) < 0 || sc.uscsi_status )
+    
+    if( ioctl( i_fd, USCSICMD, &sc ) < 0 || sc.uscsi_status )
     {
         return -1;
     }
 
-    i_ret = 0;
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_send_key_t, DVDChallengeKeyInfo,
-                   kDVDKeyFormatChallengeKey );
-
+    return 0;
+    
+#elif defined( SYS_DARWIN )
+    dk_dvd_send_key_t dvd;
+    DVDChallengeKeyInfo dvdcki;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdcki, 0, sizeof(dvdcki));
+
+    dvd.buffer = &dvdcki;
+    dvd.bufferLength = sizeof(dvdcki);
+    dvd.format = kDVDKeyFormatChallengeKey;
     dvd.grantID = *pi_agid;
-    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
-
-    dvdbs.dataLength[ 1 ] = 0xe;
-    memcpy( dvdbs.challengeKeyValue, p_challenge, DVD_CHALLENGE_SIZE );
+
+    /* dvdcki.dataLength[0] = 0x00; */ /* dataLength[0] is already memset to 0 */
+    dvdcki.dataLength[ 1 ] = 0x0e;
+
+    memcpy( dvdcki.challengeKeyValue, p_challenge, DVD_CHALLENGE_SIZE );
 
     i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_CHALLENGE_KEY_LENGTH];
+        u8 buffer[DVD_CHALLENGE_KEY_LENGTH];
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
@@ -1336,8 +1243,8 @@
 
         memcpy( key->KeyData, p_challenge, DVD_CHALLENGE_SIZE );
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_SEND_KEY, key,
-                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
+        return DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_SEND_KEY, key, 
+                key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
     }
     else
     {
@@ -1348,34 +1255,12 @@
         p_buffer[ 1 ] = 0xe;
         memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
 
-        i_ret = WinSendSSC( i_fd, &ssc );
-    }
-
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_SEND_KEY, 16 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
-
-    p_buffer[ 1 ] = 0xe;
-    memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_SEND_KEY, 16 );
-
-    sdc.command[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
-
-    p_buffer[ 1 ] = 0xe;
-    memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
-
-    i_ret = DosDevIOCtl( i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                         &sdc, sizeof(sdc), &ulParamLen,
-                         p_buffer, sizeof(p_buffer), &ulDataLen );
+        return WinSendSSC( i_fd, &ssc );
+    }
 
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    return -1;
 
 #endif
     return i_ret;
@@ -1384,7 +1269,7 @@
 /*****************************************************************************
  * ioctl_SendKey2: send the second key to the drive
  *****************************************************************************/
-int ioctl_SendKey2( int i_fd, int *pi_agid, uint8_t *p_key )
+int ioctl_SendKey2( int i_fd, int *pi_agid, u8 *p_key )
 {
     int i_ret;
 
@@ -1397,7 +1282,7 @@
 
     memcpy( auth_info.hsk.key, p_key, DVD_KEY_SIZE );
 
-    i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
+    return ioctl( i_fd, DVD_AUTH, &auth_info );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
     struct dvd_authinfo auth_info;
@@ -1408,7 +1293,7 @@
 
     memcpy( auth_info.keychal, p_key, DVD_KEY_SIZE );
 
-    i_ret = ioctl( i_fd, DVDIOCSENDKEY, &auth_info );
+    return ioctl( i_fd, DVDIOCSENDKEY, &auth_info );
 
 #elif defined( SYS_BEOS )
     INIT_RDC( GPCMD_SEND_KEY, 12 );
@@ -1418,7 +1303,7 @@
     p_buffer[ 1 ] = 0xa;
     memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
 
-    i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    return ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
 
 #elif defined( HPUX_SCTL_IO )
     INIT_SCTL_IO( GPCMD_SEND_KEY, 12 );
@@ -1428,40 +1313,47 @@
     p_buffer[ 1 ] = 0xa;
     memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
 
-    i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
+    return ioctl( i_fd, SIOC_IO, &sctl_io );
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_SEND_KEY, 12 );
-
+    
     rs_cdb.cdb_opaque[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
-
+    
     p_buffer[ 1 ] = 0xa;
     memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
-
-    if( SolarisSendUSCSI( i_fd, &sc ) < 0 || sc.uscsi_status )
+    
+    if( ioctl( i_fd, USCSICMD, &sc ) < 0 || sc.uscsi_status )
     {
         return -1;
     }
 
-    i_ret = 0;
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_send_key_t, DVDKey2Info,
-                   kDVDKeyFormatKey2 );
-
+    return 0;
+    
+#elif defined( SYS_DARWIN )
+    dk_dvd_send_key_t dvd;
+    DVDKey2Info dvdk2i;
+    
+    memset(&dvd, 0, sizeof(dvd));
+    memset(&dvdk2i, 0, sizeof(dvdk2i));
+
+    dvd.buffer = &dvdk2i;
+    dvd.bufferLength = sizeof(dvdk2i);
+    dvd.format = kDVDKeyFormatKey2;
     dvd.grantID = *pi_agid;
-    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
-
-    dvdbs.dataLength[ 1 ] = 0xa;
-    memcpy( dvdbs.key2Value, p_key, DVD_KEY_SIZE );
+
+    /* dvdk2i.dataLength[0] = 0x00; */ /*dataLength[0] is already memset to 0 */
+    dvdk2i.dataLength[ 1 ] = 0x0a;
+    
+    memcpy( dvdk2i.key2Value, p_key, DVD_KEY_SIZE );
 
     i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
 
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_BUS_KEY_LENGTH];
+        u8 buffer[DVD_BUS_KEY_LENGTH];
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
@@ -1473,8 +1365,8 @@
 
         memcpy( key->KeyData, p_key, DVD_KEY_SIZE );
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_SEND_KEY, key,
-                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
+        return DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_SEND_KEY, key, 
+                key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
     }
     else
     {
@@ -1485,34 +1377,12 @@
         p_buffer[ 1 ] = 0xa;
         memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
 
-        i_ret = WinSendSSC( i_fd, &ssc );
-    }
-
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_SEND_KEY, 12 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
-
-    p_buffer[ 1 ] = 0xa;
-    memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_SEND_KEY, 12 );
-
-    sdc.command[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
-
-    p_buffer[ 1 ] = 0xa;
-    memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
-
-    i_ret = DosDevIOCtl( i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                         &sdc, sizeof(sdc), &ulParamLen,
-                         p_buffer, sizeof(p_buffer), &ulDataLen );
+        return WinSendSSC( i_fd, &ssc );
+    }
 
 #else
-#   error "DVD ioctls are unavailable on this system"
+    /* DVD ioctls unavailable - do as if the ioctl failed */
+    i_ret = -1;
 
 #endif
     return i_ret;
@@ -1525,7 +1395,7 @@
 {
     int i_ret;
 
-#if defined( HAVE_LINUX_DVD_STRUCT ) && defined( DVD_LU_SEND_RPC_STATE )
+#if defined( HAVE_LINUX_DVD_STRUCT ) && !defined(__OpenBSD__)
     dvd_authinfo auth_info;
 
     memset( &auth_info, 0, sizeof( auth_info ) );
@@ -1537,10 +1407,6 @@
     *p_mask = auth_info.lrpcs.region_mask;
     *p_scheme = auth_info.lrpcs.rpc_scheme;
 
-#elif defined( HAVE_LINUX_DVD_STRUCT )
-    /* FIXME: OpenBSD doesn't know this */
-    i_ret = -1;
-
 #elif defined( HAVE_BSD_DVD_STRUCT )
     struct dvd_authinfo auth_info;
 
@@ -1564,69 +1430,51 @@
     *p_mask = p_buffer[ 5 ];
     *p_scheme = p_buffer[ 6 ];
 
-#elif defined( HPUX_SCTL_IO )
-    INIT_SCTL_IO( GPCMD_REPORT_KEY, 8 );
-
-    sctl_io.cdb[ 10 ] = DVD_REPORT_RPC;
-
-    i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
-
+#elif defined( SOLARIS_USCSI )
+    INIT_USCSI( GPCMD_REPORT_KEY, 8 );
+    
+    rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_RPC;
+    
+    i_ret = ioctl( i_fd, USCSICMD, &sc );
+    
+    if( i_ret < 0 || sc.uscsi_status )
+    {
+        i_ret = -1;
+    }
+    
     *p_type = p_buffer[ 4 ] >> 6;
     *p_mask = p_buffer[ 5 ];
     *p_scheme = p_buffer[ 6 ];
-
-#elif defined( SOLARIS_USCSI )
-    INIT_USCSI( GPCMD_REPORT_KEY, 8 );
-
-    rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_RPC;
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
-    if( i_ret < 0 || sc.uscsi_status )
-    {
-        i_ret = -1;
-    }
-
-    *p_type = p_buffer[ 4 ] >> 6;
-    *p_mask = p_buffer[ 5 ];
-    *p_scheme = p_buffer[ 6 ];
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_report_key_t, DVDRegionPlaybackControlInfo,
-                   kDVDKeyFormatRegionState );
-
-    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
-
-    i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
-
-    *p_type = dvdbs.typeCode;
-    *p_mask = dvdbs.driveRegion;
-    *p_scheme = dvdbs.rpcScheme;
-
+    
+#elif defined( SYS_DARWIN )
+    /* The headers for Darwin / MacOSX are unavaialbe. */
+    /* Someone who has them should have no problem implementing this. */
+    i_ret = -1;
+    
 #elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
+    if( WIN2K ) /* NT/Win2000/Whistler */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_RPC_KEY_LENGTH];
+        u8 buffer[ DVD_ASF_LENGTH ]; /* correct this */
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
         memset( &buffer, 0, sizeof( buffer ) );
 
-        key->KeyLength  = DVD_RPC_KEY_LENGTH;
+        key->KeyLength  = DVD_ASF_LENGTH; /* correct this */
         key->KeyType    = DvdGetRpcKey;
         key->KeyFlags   = 0;
 
-        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
+#warning "Fix ReportRPC for WIN32!"
+        /* The IOCTL_DVD_READ_KEY might be the right IOCTL */
+        i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key, 
                 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
 
-        if( i_ret < 0 )
-        {
-            return i_ret;
-        }
-
-        *p_type = ((PDVD_RPC_KEY)key->KeyData)->TypeCode;
-        *p_mask = ((PDVD_RPC_KEY)key->KeyData)->RegionMask;
-        *p_scheme = ((PDVD_RPC_KEY)key->KeyData)->RpcScheme;
+        /* Someone who has the headers should correct all this. */
+        *p_type = 0;
+        *p_mask = 0;
+        *p_scheme = 0;
+        i_ret = -1; /* Remove this line when implemented. */
+
     }
     else
     {
@@ -1641,160 +1489,9 @@
         *p_scheme = p_buffer[ 6 ];
     }
 
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_REPORT_KEY, 8 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_RPC;
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-    *p_type = p_buffer[ 4 ] >> 6;
-    *p_mask = p_buffer[ 5 ];
-    *p_scheme = p_buffer[ 6 ];
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_REPORT_KEY, 8 );
-
-    sdc.command[ 10 ] = DVD_REPORT_RPC;
-
-    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                        &sdc, sizeof(sdc), &ulParamLen,
-                        p_buffer, sizeof(p_buffer), &ulDataLen);
-
-    *p_type = p_buffer[ 4 ] >> 6;
-    *p_mask = p_buffer[ 5 ];
-    *p_scheme = p_buffer[ 6 ];
-
 #else
-#   error "DVD ioctls are unavailable on this system"
-
-#endif
-    return i_ret;
-}
-
-/*****************************************************************************
- * ioctl_SendRPC: set RPC status for the drive
- *****************************************************************************/
-int ioctl_SendRPC( int i_fd, int i_pdrc )
-{
-    int i_ret;
-
-#if defined( HAVE_LINUX_DVD_STRUCT ) && defined( DVD_HOST_SEND_RPC_STATE )
-    dvd_authinfo auth_info;
-
-    memset( &auth_info, 0, sizeof( auth_info ) );
-    auth_info.type = DVD_HOST_SEND_RPC_STATE;
-    auth_info.hrpcs.pdrc = i_pdrc;
-
-    i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
-
-#elif defined( HAVE_LINUX_DVD_STRUCT )
-    /* FIXME: OpenBSD doesn't know this */
+    /* DVD ioctls unavailable - do as if the ioctl failed */
     i_ret = -1;
-
-#elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
-
-    memset( &auth_info, 0, sizeof( auth_info ) );
-    auth_info.format = DVD_SEND_RPC;
-    auth_info.region = i_pdrc;
-
-    i_ret = ioctl( i_fd, DVDIOCSENDKEY, &auth_info );
-
-#elif defined( SYS_BEOS )
-    INIT_RDC( GPCMD_SEND_KEY, 8 );
-
-    rdc.command[ 10 ] = DVD_SEND_RPC;
-
-    p_buffer[ 1 ] = 6;
-    p_buffer[ 4 ] = i_pdrc;
-
-    i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
-
-#elif defined( HPUX_SCTL_IO )
-    INIT_SCTL_IO( GPCMD_SEND_KEY, 8 );
-
-    sctl_io.cdb[ 10 ] = DVD_SEND_RPC;
-
-    p_buffer[ 1 ] = 6;
-    p_buffer[ 4 ] = i_pdrc;
-
-    i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
-
-#elif defined( SOLARIS_USCSI )
-    INIT_USCSI( GPCMD_SEND_KEY, 8 );
-
-    rs_cdb.cdb_opaque[ 10 ] = DVD_SEND_RPC;
-
-    p_buffer[ 1 ] = 6;
-    p_buffer[ 4 ] = i_pdrc;
-
-    i_ret = SolarisSendUSCSI( i_fd, &sc );
-
-    if( i_ret < 0 || sc.uscsi_status )
-    {
-        i_ret = -1;
-    }
-
-#elif defined( DARWIN_DVD_IOCTL )
-    INIT_DVDIOCTL( dk_dvd_send_key_t, DVDRegionPlaybackControlInfo,
-                   kDVDKeyFormatSetRegion );
-
-    dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
-    dvdbs.driveRegion = i_pdrc;
-
-    i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
-
-#elif defined( WIN32 )
-    if( WIN2K ) /* NT/2k/XP */
-    {
-        INIT_SPTD( GPCMD_SEND_KEY, 8 );
-
-        sptd.Cdb[ 10 ] = DVD_SEND_RPC;
-
-        p_buffer[ 1 ] = 6;
-        p_buffer[ 4 ] = i_pdrc;
-
-        i_ret = SEND_SPTD( i_fd, &sptd, &tmp );
-    }
-    else
-    {
-        INIT_SSC( GPCMD_SEND_KEY, 8 );
-
-        ssc.CDBByte[ 10 ] = DVD_SEND_RPC;
-
-        p_buffer[ 1 ] = 6;
-        p_buffer[ 4 ] = i_pdrc;
-
-        i_ret = WinSendSSC( i_fd, &ssc );
-    }
-
-#elif defined( __QNXNTO__ )
-
-    INIT_CPT( GPCMD_SEND_KEY, 8 );
-
-    p_cpt->cam_cdb[ 10 ] = DVD_SEND_RPC;
-
-    p_buffer[ 1 ] = 6;
-    p_buffer[ 4 ] = i_pdrc;
-
-    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
-
-#elif defined( SYS_OS2 )
-    INIT_SSC( GPCMD_SEND_KEY, 8 );
-
-    sdc.command[ 10 ] = DVD_SEND_RPC;
-
-    p_buffer[ 1 ] = 6;
-    p_buffer[ 4 ] = i_pdrc;
-
-    i_ret = DosDevIOCtl( i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
-                         &sdc, sizeof(sdc), &ulParamLen,
-                         p_buffer, sizeof(p_buffer), &ulDataLen );
-
-#else
-#   error "DVD ioctls are unavailable on this system"
 
 #endif
     return i_ret;
@@ -1819,8 +1516,11 @@
             /* leave the flags to 0 */
             break;
 
-        case GPCMD_READ_DVD_STRUCTURE: case GPCMD_REPORT_KEY:
-    p_rdc->flags = B_RAW_DEVICE_DATA_IN; break; }
+        case GPCMD_READ_DVD_STRUCTURE:
+        case GPCMD_REPORT_KEY:
+            p_rdc->flags = B_RAW_DEVICE_DATA_IN;
+            break;
+    }
 
     p_rdc->command[ 0 ]      = i_type;
 
@@ -1872,15 +1572,15 @@
 /*****************************************************************************
  * SolarisInitUSCSI: initialize a USCSICMD structure for the Solaris kernel
  *****************************************************************************
- * This function initializes a Solaris userspace scsi command structure for
+ * This function initializes a Solaris userspace scsi command structure for 
  * future use, either a read command or a write command.
  *****************************************************************************/
 static void SolarisInitUSCSI( struct uscsi_cmd *p_sc, int i_type )
-{
+{   
     union scsi_cdb *rs_cdb;
     memset( p_sc->uscsi_cdb, 0, sizeof( union scsi_cdb ) );
     memset( p_sc->uscsi_bufaddr, 0, p_sc->uscsi_buflen );
-
+    
     switch( i_type )
     {
         case GPCMD_SEND_KEY:
@@ -1892,9 +1592,9 @@
             p_sc->uscsi_flags = USCSI_ISOLATE | USCSI_READ;
             break;
     }
-
+    
     rs_cdb = (union scsi_cdb *)p_sc->uscsi_cdb;
-
+    
     rs_cdb->scc_cmd = i_type;
 
     rs_cdb->cdb_opaque[ 8 ] = (p_sc->uscsi_buflen >> 8) & 0xff;
@@ -1903,103 +1603,9 @@
 
     USCSI_TIMEOUT( p_sc, 15 );
 }
-
-/*****************************************************************************
- * SolarisSendUSCSI: send a USCSICMD structure to the Solaris kernel
- * for execution
- *****************************************************************************
- * When available, this function uses the function smedia_uscsi_cmd()
- * from Solaris' libsmedia library (Solaris 9 or newer) to execute the
- * USCSI command.  smedia_uscsi_cmd() allows USCSI commands for
- * non-root users on removable media devices on Solaris 9; sending the
- * USCSI command directly to the device using the USCSICMD ioctl fails
- * with an EPERM error on Solaris 9.
- *
- * The code will fall back to the USCSICMD ioctl method, when
- * libsmedia.so is not available or does not export the
- * smedia_uscsi_cmd() function (on Solaris releases upto and including
- * Solaris 8). Fortunatelly, on these old releases non-root users are
- * allowed to perform USCSICMD ioctls on removable media devices.
- *****************************************************************************/
-static int SolarisSendUSCSI( int i_fd, struct uscsi_cmd *p_sc )
-{
-    void *p_handle;
-
-    /* We use static variables to keep track of the libsmedia symbols, which
-     * is harmless even in a multithreaded program because the library and
-     * its symbols will always be mapped at the same address. */
-    static int b_tried = 0;
-    static int b_have_sm = 0;
-    static void * (*p_get_handle) ( int32_t );
-    static int (*p_uscsi_cmd) ( void *, struct uscsi_cmd * );
-    static int (*p_release_handle) ( void * );
-
-    if( !b_tried )
-    {
-        void *p_lib;
-
-        p_lib = dlopen( "libsmedia.so", RTLD_NOW );
-        if( p_lib )
-        {
-            p_get_handle = dlsym( p_lib, "smedia_get_handle" );
-            p_uscsi_cmd = dlsym( p_lib, "smedia_uscsi_cmd" );
-            p_release_handle = dlsym( p_lib, "smedia_release_handle" );
-
-            if( p_get_handle && p_uscsi_cmd && p_release_handle )
-            {
-                b_have_sm = 1;
-            }
-            else
-            {
-                dlclose( p_lib );
-            }
-        }
-
-        b_tried = 1;
-    }
-
-    if( b_have_sm && (p_handle = p_get_handle(i_fd)) )
-    {
-        int i_ret = p_uscsi_cmd( p_handle, p_sc );
-        p_release_handle( p_handle );
-        return i_ret;
-    }
-
-    return ioctl( i_fd, USCSICMD, p_sc );
-}
 #endif
 
 #if defined( WIN32 )
-/*****************************************************************************
- * WinInitSPTD: initialize a sptd structure
- *****************************************************************************
- * This function initializes a SCSI pass through command structure for future
- * use, either a read command or a write command.
- *****************************************************************************/
-static void WinInitSPTD( SCSI_PASS_THROUGH_DIRECT *p_sptd, int i_type )
-{
-    memset( p_sptd->DataBuffer, 0, p_sptd->DataTransferLength );
-
-    switch( i_type )
-    {
-        case GPCMD_SEND_KEY:
-            p_sptd->DataIn = SCSI_IOCTL_DATA_OUT;
-            break;
-
-        case GPCMD_READ_DVD_STRUCTURE:
-        case GPCMD_REPORT_KEY:
-            p_sptd->DataIn = SCSI_IOCTL_DATA_IN;
-            break;
-    }
-
-    p_sptd->Cdb[ 0 ] = i_type;
-    p_sptd->Cdb[ 8 ] = (uint8_t)(p_sptd->DataTransferLength >> 8) & 0xff;
-    p_sptd->Cdb[ 9 ] = (uint8_t) p_sptd->DataTransferLength       & 0xff;
-    p_sptd->CdbLength = 12;
-
-    p_sptd->TimeOutValue = 2;
-}
-
 /*****************************************************************************
  * WinInitSSC: initialize a ssc structure for the win32 aspi layer
  *****************************************************************************
@@ -2027,8 +1633,8 @@
 
     p_ssc->CDBByte[ 0 ] = i_type;
 
-    p_ssc->CDBByte[ 8 ] = (uint8_t)(p_ssc->SRB_BufLen >> 8) & 0xff;
-    p_ssc->CDBByte[ 9 ] = (uint8_t) p_ssc->SRB_BufLen       & 0xff;
+    p_ssc->CDBByte[ 8 ] = (u8)(p_ssc->SRB_BufLen >> 8) & 0xff;
+    p_ssc->CDBByte[ 9 ] = (u8) p_ssc->SRB_BufLen       & 0xff;
     p_ssc->SRB_CDBLen   = 12;
 
     p_ssc->SRB_SenseLen = SENSE_LEN;
@@ -2062,62 +1668,3 @@
 }
 #endif
 
-#if defined( __QNXNTO__ )
-/*****************************************************************************
- * QNXInitCPT: initialize a CPT structure for QNX Neutrino
- *****************************************************************************
- * This function initializes a cpt command structure for future use,
- * either a read command or a write command.
- *****************************************************************************/
-static void QNXInitCPT( CAM_PASS_THRU * p_cpt, int i_type )
-{
-    switch( i_type )
-    {
-        case GPCMD_SEND_KEY:
-            p_cpt->cam_flags = CAM_DIR_OUT;
-            break;
-
-        case GPCMD_READ_DVD_STRUCTURE:
-        case GPCMD_REPORT_KEY:
-            p_cpt->cam_flags = CAM_DIR_IN;
-            break;
-    }
-
-    p_cpt->cam_cdb[0] = i_type;
-
-    p_cpt->cam_cdb[ 8 ] = (p_cpt->cam_dxfer_len >> 8) & 0xff;
-    p_cpt->cam_cdb[ 9 ] =  p_cpt->cam_dxfer_len       & 0xff;
-    p_cpt->cam_cdb_len = 12;
-
-    p_cpt->cam_timeout = CAM_TIME_DEFAULT;
-}
-#endif
-
-#if defined( SYS_OS2 )
-/*****************************************************************************
- * OS2InitSDC: initialize a SDC structure for the Execute SCSI-command
- *****************************************************************************
- * This function initializes a OS2 'execute SCSI command' structure for
- * future use, either a read command or a write command.
- *****************************************************************************/
-static void OS2InitSDC( struct OS2_ExecSCSICmd *p_sdc, int i_type )
-{
-    switch( i_type )
-    {
-        case GPCMD_SEND_KEY:
-            p_sdc->flags = 0;
-            break;
-
-        case GPCMD_READ_DVD_STRUCTURE:
-        case GPCMD_REPORT_KEY:
-            p_sdc->flags = EX_DIRECTION_IN;
-            break;
-    }
-
-    p_sdc->command[ 0 ] = i_type;
-    p_sdc->command[ 8 ] = (p_sdc->data_length >> 8) & 0xff;
-    p_sdc->command[ 9 ] = p_sdc->data_length        & 0xff;
-    p_sdc->id_code      = 0x31304443;    // 'CD01'
-    p_sdc->cmd_length   = 12;
-}
-#endif