From 9e827ca7a470f8b0c7aea4a4e62cebb5931b1d04 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 25 Jun 2004 01:47:06 +0000 Subject: [PATCH] Fill in LUN's on requests. Add common routine for checking/initializing ASPI availability. --- lib/MSWindows/aspi32.c | 76 +++++++++++++++++++++++++----------------- lib/MSWindows/win32.h | 3 +- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/lib/MSWindows/aspi32.c b/lib/MSWindows/aspi32.c index 4d5b63e8..f3b81c14 100644 --- a/lib/MSWindows/aspi32.c +++ b/lib/MSWindows/aspi32.c @@ -1,5 +1,5 @@ /* - $Id: aspi32.c,v 1.8 2004/06/21 03:22:58 rocky Exp $ + $Id: aspi32.c,v 1.9 2004/06/25 01:47:06 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -27,7 +27,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: aspi32.c,v 1.8 2004/06/21 03:22:58 rocky Exp $"; +static const char _rcsid[] = "$Id: aspi32.c,v 1.9 2004/06/25 01:47:06 rocky Exp $"; #include #include @@ -69,6 +69,38 @@ mciSendCommand_aspi(int id, UINT msg, DWORD flags, void *arg) return(mci_error == 0); } +/* + See if the ASPI DLL is loadable. If so pointers are returned + and we return true. Return false if there was a problem. + */ +static bool +have_aspi( HMODULE *hASPI, + long (**lpGetSupport)( void ), + long (**lpSendCommand)( void* ) ) +{ + /* check if aspi is available */ + *hASPI = LoadLibrary( "wnaspi32.dll" ); + + if( *hASPI == NULL ) { + cdio_debug("Unable to load ASPI DLL"); + return false; + } + + (FARPROC) *lpGetSupport = GetProcAddress( *hASPI, + "GetASPI32SupportInfo" ); + (FARPROC) *lpSendCommand = GetProcAddress( *hASPI, + "SendASPI32Command" ); + + /* make sure that we've got both function addresses */ + if( *lpGetSupport == NULL || *lpSendCommand == NULL ) { + cdio_debug("Unable to get ASPI function pointers"); + FreeLibrary( *hASPI ); + return false; + } + + return true; +} + const char * is_cdrom_aspi(const char drive_letter) { @@ -79,21 +111,10 @@ is_cdrom_aspi(const char drive_letter) DWORD dwSupportInfo; int i_adapter, i_hostadapters; char c_drive; - - hASPI = LoadLibrary( "wnaspi32.dll" ); - if( hASPI != NULL ) { - (FARPROC) lpGetSupport = GetProcAddress( hASPI, - "GetASPI32SupportInfo" ); - (FARPROC) lpSendCommand = GetProcAddress( hASPI, - "SendASPI32Command" ); - } - - if( hASPI == NULL || lpGetSupport == NULL || lpSendCommand == NULL ) { - cdio_debug("Unable to load ASPI or get ASPI function pointers"); - if( hASPI ) FreeLibrary( hASPI ); + + if ( !have_aspi(&hASPI, &lpGetSupport, &lpSendCommand) ) return NULL; - } - + /* ASPI support seems to be there. */ dwSupportInfo = lpGetSupport(); @@ -154,6 +175,7 @@ is_cdrom_aspi(const char drive_letter) srbGDEVBlock.SRB_Cmd = SC_GET_DEV_TYPE; srbDiskInfo.SRB_HaId = i_adapter; srbGDEVBlock.SRB_Target = i_target; + srbGDEVBlock.SRB_Lun = i_lun; lpSendCommand( (void*) &srbGDEVBlock ); @@ -192,20 +214,9 @@ init_aspi (_img_private_t *env) c_drive = env->gen.source_name[4]; } - hASPI = LoadLibrary( "wnaspi32.dll" ); - if( hASPI != NULL ) { - (FARPROC) lpGetSupport = GetProcAddress( hASPI, - "GetASPI32SupportInfo" ); - (FARPROC) lpSendCommand = GetProcAddress( hASPI, - "SendASPI32Command" ); - } - - if( hASPI == NULL || lpGetSupport == NULL || lpSendCommand == NULL ) { - cdio_debug("Unable to load ASPI or get ASPI function pointers"); - if( hASPI ) FreeLibrary( hASPI ); - return false; - } - + if ( !have_aspi(&hASPI, &lpGetSupport, &lpSendCommand) ) + return NULL; + /* ASPI support seems to be there. */ dwSupportInfo = lpGetSupport(); @@ -278,6 +289,7 @@ init_aspi (_img_private_t *env) env->hASPI = (long)hASPI; env->lpSendCommand = lpSendCommand; env->b_aspi_init = true; + env->i_lun = i_lun; cdio_debug("Using ASPI layer"); return true; @@ -333,6 +345,7 @@ mmc_read_sectors_aspi (const _img_private_t *env, void *data, lsn_t lsn, ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; ssc.SRB_HaId = LOBYTE( env->i_sid ); ssc.SRB_Target = HIBYTE( env->i_sid ); + ssc.SRB_Lun = env->i_lun; ssc.SRB_SenseLen = SENSE_LEN; ssc.SRB_PostProc = (LPVOID) hEvent; @@ -457,6 +470,7 @@ read_toc_aspi (_img_private_t *env) ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; ssc.SRB_HaId = LOBYTE( env->i_sid ); ssc.SRB_Target = HIBYTE( env->i_sid ); + ssc.SRB_Lun = env->i_lun; ssc.SRB_SenseLen = SENSE_LEN; ssc.SRB_PostProc = (LPVOID) hEvent; @@ -620,7 +634,7 @@ get_drive_cap_aspi (const _img_private_t *env) ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; ssc.SRB_HaId = LOBYTE( env->i_sid ); ssc.SRB_Target = HIBYTE( env->i_sid ); - ssc.SRB_Lun = 0; /* FIXME */ + ssc.SRB_Lun = env->i_lun; ssc.SRB_SenseLen = SENSE_LEN; ssc.SRB_PostProc = (LPVOID) hEvent; diff --git a/lib/MSWindows/win32.h b/lib/MSWindows/win32.h index fd36f20f..388717c4 100644 --- a/lib/MSWindows/win32.h +++ b/lib/MSWindows/win32.h @@ -1,5 +1,5 @@ /* - $Id: win32.h,v 1.6 2004/06/21 03:22:58 rocky Exp $ + $Id: win32.h,v 1.7 2004/06/25 01:47:06 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -47,6 +47,7 @@ typedef struct { HANDLE h_device_handle; /* device descriptor */ long hASPI; short i_sid; + short i_lun; long (*lpSendCommand)( void* ); /* Track information */