Can now get drive capabilities in ASPI driver

ASPI headers from win32.h moved to aspi32.h
some more cleanups.
This commit is contained in:
rocky
2004-06-21 03:22:58 +00:00
parent bf964b72fd
commit a87aac092c
3 changed files with 121 additions and 94 deletions

View File

@@ -1,5 +1,5 @@
/* /*
$Id: aspi32.c,v 1.7 2004/06/20 15:06:42 rocky Exp $ $Id: aspi32.c,v 1.8 2004/06/21 03:22:58 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
@@ -27,7 +27,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: aspi32.c,v 1.7 2004/06/20 15:06:42 rocky Exp $"; static const char _rcsid[] = "$Id: aspi32.c,v 1.8 2004/06/21 03:22:58 rocky Exp $";
#include <cdio/cdio.h> #include <cdio/cdio.h>
#include <cdio/sector.h> #include <cdio/sector.h>
@@ -306,17 +306,11 @@ static int
mmc_read_sectors_aspi (const _img_private_t *env, void *data, lsn_t lsn, mmc_read_sectors_aspi (const _img_private_t *env, void *data, lsn_t lsn,
int sector_type, unsigned int nblocks) int sector_type, unsigned int nblocks)
{ {
unsigned char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
HANDLE hEvent; HANDLE hEvent;
struct SRB_ExecSCSICmd ssc; struct SRB_ExecSCSICmd ssc;
#if 0 #if 0
sector_type = 0; /*all types */ sector_type = 0; /*all types */
/*sector_type = 1;*/ /* CD-DA */
/*sector_type = 2;*/ /* mode1 */
/*sector_type = 3;*/ /* mode2 */
/*sector_type = 4;*/ /* mode2/form1 */
/*sector_type = 5;*/ /* mode2/form2 */
#endif #endif
int sync = 0; int sync = 0;
int header_code = 2; int header_code = 2;
@@ -362,8 +356,25 @@ mmc_read_sectors_aspi (const _img_private_t *env, void *data, lsn_t lsn,
#endif #endif
/* Result buffer */ /* Result buffer */
ssc.SRB_BufPointer = buf; ssc.SRB_BufPointer = data;
ssc.SRB_BufLen = CDIO_CD_FRAMESIZE_RAW;
switch (sector_type) {
case CDIO_MMC_READ_TYPE_ANY:
case CDIO_MMC_READ_TYPE_CDDA:
ssc.SRB_BufLen = CDIO_CD_FRAMESIZE_RAW;
break;
case CDIO_MMC_READ_TYPE_M2F1:
ssc.SRB_BufLen = CDIO_CD_FRAMESIZE;
break;
case CDIO_MMC_READ_TYPE_M2F2:
ssc.SRB_BufLen = 2324;
break;
case CDIO_MMC_READ_TYPE_MODE1:
ssc.SRB_BufLen = CDIO_CD_FRAMESIZE;
break;
default:
ssc.SRB_BufLen = CDIO_CD_FRAMESIZE_RAW;
}
/* Initiate transfer */ /* Initiate transfer */
ResetEvent( hEvent ); ResetEvent( hEvent );
@@ -380,10 +391,7 @@ mmc_read_sectors_aspi (const _img_private_t *env, void *data, lsn_t lsn,
if( ssc.SRB_Status != SS_COMP ) { if( ssc.SRB_Status != SS_COMP ) {
return 1; return 1;
} }
/* FIXME! remove the 8 (SUBHEADER size) below... */
memcpy (data, buf, CDIO_CD_FRAMESIZE_RAW);
return 0; return 0;
} }
@@ -409,14 +417,10 @@ int
read_mode2_sector_aspi (const _img_private_t *env, void *data, lsn_t lsn, read_mode2_sector_aspi (const _img_private_t *env, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
return mmc_read_sectors_aspi(env, data, lsn, b_form2
if (mmc_read_sectors_aspi(env, data, lsn, b_form2 ? CDIO_MMC_READ_TYPE_M2F2
? CDIO_MMC_READ_TYPE_M2F2 : CDIO_MMC_READ_TYPE_M2F1,
: CDIO_MMC_READ_TYPE_M2F1, 1);
1)) {
return mmc_read_sectors_aspi(env, data, lsn, CDIO_MMC_READ_TYPE_ANY, 1);
}
return 0;
} }
/*! /*!
@@ -427,10 +431,7 @@ int
read_mode1_sector_aspi (const _img_private_t *env, void *data, lsn_t lsn, read_mode1_sector_aspi (const _img_private_t *env, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
if (mmc_read_sectors_aspi(env, data, lsn, CDIO_MMC_READ_TYPE_MODE1, 1)) { return mmc_read_sectors_aspi(env, data, lsn, CDIO_MMC_READ_TYPE_MODE1, 1);
return mmc_read_sectors_aspi(env, data, lsn, CDIO_MMC_READ_TYPE_ANY, 1);
}
return 0;
} }
/*! /*!
@@ -594,16 +595,12 @@ wnaspi32_eject_media (void *user_data) {
/*! /*!
Return the the kind of drive capabilities of device. Return the the kind of drive capabilities of device.
Note: string is malloc'd so caller should free() then returned
string when done with it.
*/ */
cdio_drive_cap_t cdio_drive_cap_t
get_drive_cap_aspi (const _img_private_t *env) get_drive_cap_aspi (const _img_private_t *env)
{ {
int32_t i_drivetype = CDIO_DRIVE_CAP_CD_AUDIO | CDIO_DRIVE_CAP_UNKNOWN; int32_t i_drivetype = CDIO_DRIVE_CAP_CD_AUDIO | CDIO_DRIVE_CAP_UNKNOWN;
unsigned char buf[192] = { 0, }; BYTE buf[256] = { 0, };
HANDLE hEvent; HANDLE hEvent;
struct SRB_ExecSCSICmd ssc; struct SRB_ExecSCSICmd ssc;
@@ -619,24 +616,22 @@ get_drive_cap_aspi (const _img_private_t *env)
capabilities, i.e. ability to read/write to CD-ROM/R/RW capabilities, i.e. ability to read/write to CD-ROM/R/RW
or/and read/write to DVD-ROM/R/RW. */ or/and read/write to DVD-ROM/R/RW. */
ssc.SRB_Cmd = SC_EXEC_SCSI_CMD; ssc.SRB_Cmd = SC_EXEC_SCSI_CMD;
ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
ssc.SRB_HaId = LOBYTE( env->i_sid ); ssc.SRB_HaId = LOBYTE( env->i_sid );
ssc.SRB_Target = HIBYTE( env->i_sid ); ssc.SRB_Target = HIBYTE( env->i_sid );
ssc.SRB_SenseLen = SENSE_LEN; ssc.SRB_Lun = 0; /* FIXME */
ssc.SRB_SenseLen = SENSE_LEN;
ssc.SRB_PostProc = (LPVOID) hEvent; ssc.SRB_PostProc = (LPVOID) hEvent;
ssc.SRB_CDBLen = 6; ssc.SRB_CDBLen = 12;
/* Operation code */ /* Operation code */
CDIO_MMC_SET_COMMAND(ssc.CDBByte, CDIO_MMC_MODE_SENSE); CDIO_MMC_SET_COMMAND(ssc.CDBByte, CDIO_MMC_MODE_SENSE_10);
/*ssc.CDBByte[1] = 0x08; /+ doesn't return block descriptors */
ssc.CDBByte[1] = 0x0; ssc.CDBByte[1] = 0x0;
ssc.CDBByte[2] = 0x2a; /*MODE_PAGE_CAPABILITIES*/; ssc.CDBByte[2] = 0x3F; /* try narrower 0x2a "mode-page" ? */
ssc.CDBByte[3] = 0; /* Not used */ ssc.CDBByte[7] = 0x01;
ssc.CDBByte[4] = 128; ssc.CDBByte[8] = 0x00;
ssc.CDBByte[5] = 0; /* Not used */
/* Allocation length and buffer */ /* Allocation length and buffer */
ssc.SRB_BufPointer = buf; ssc.SRB_BufPointer = buf;
@@ -651,26 +646,49 @@ get_drive_cap_aspi (const _img_private_t *env)
if( ssc.SRB_Status == SS_PENDING ) if( ssc.SRB_Status == SS_PENDING )
WaitForSingleObject( hEvent, INFINITE ); WaitForSingleObject( hEvent, INFINITE );
CloseHandle( hEvent );
/* check that the transfer went as planned */ /* check that the transfer went as planned */
if( ssc.SRB_Status != SS_COMP ) { if( ssc.SRB_Status != SS_COMP ) {
CloseHandle( hEvent );
return i_drivetype; return i_drivetype;
} } else {
{ BYTE *p;
unsigned int n=buf[3]+4; int lenData = ((unsigned int)buf[0] << 8) + buf[1];
/* Reader? */ BYTE *pMax = buf + 256;
if (buf[n+5] & 0x01) i_drivetype |= CDIO_DRIVE_CAP_CD_AUDIO;
if (buf[n+2] & 0x02) i_drivetype |= CDIO_DRIVE_CAP_CD_RW; i_drivetype = 0;
if (buf[n+2] & 0x08) i_drivetype |= CDIO_DRIVE_CAP_DVD; /* set to first sense mask, and then walk through the masks */
p = buf + 8;
/* Writer? */ while( (p < &(buf[2+lenData])) && (p < pMax) ) {
if (buf[n+3] & 0x01) i_drivetype |= CDIO_DRIVE_CAP_CD_R; BYTE which;
if (buf[n+3] & 0x10) i_drivetype |= CDIO_DRIVE_CAP_DVD_R;
if (buf[n+3] & 0x20) i_drivetype |= CDIO_DRIVE_CAP_DVD_RAM; which = p[0] & 0x3F;
switch( which )
if (buf[n+6] & 0x08) i_drivetype |= CDIO_DRIVE_CAP_OPEN_TRAY; {
if (buf[n+6] >> 5 != 0) case CDRAUDIOCTL:
i_drivetype |= CDIO_DRIVE_CAP_CLOSE_TRAY; case READERRREC:
case CDRPARMS:
/* Don't handle theses yet. */
break;
case CDRCAPS:
/* Reader? */
if (p[5] & 0x01) i_drivetype |= CDIO_DRIVE_CAP_CD_AUDIO;
if (p[2] & 0x02) i_drivetype |= CDIO_DRIVE_CAP_CD_RW;
if (p[2] & 0x08) i_drivetype |= CDIO_DRIVE_CAP_DVD;
/* Writer? */
if (p[3] & 0x01) i_drivetype |= CDIO_DRIVE_CAP_CD_R;
if (p[3] & 0x10) i_drivetype |= CDIO_DRIVE_CAP_DVD_R;
if (p[3] & 0x20) i_drivetype |= CDIO_DRIVE_CAP_DVD_RAM;
if (p[6] & 0x08) i_drivetype |= CDIO_DRIVE_CAP_OPEN_TRAY;
if (p[6] >> 5 != 0)
i_drivetype |= CDIO_DRIVE_CAP_CLOSE_TRAY;
break;
default: ;
}
p += (p[1] + 2);
}
} }
return i_drivetype; return i_drivetype;
} }

View File

@@ -1,6 +1,6 @@
/* Win32 aspi specific */ /* Win32 aspi specific */
/* /*
$Id: aspi32.h,v 1.1 2004/03/05 12:32:45 rocky Exp $ $Id: aspi32.h,v 1.2 2004/06/21 03:22:58 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -94,6 +94,14 @@ struct SRB_ExecSCSICmd
unsigned char SenseArea[SENSE_LEN+2]; unsigned char SenseArea[SENSE_LEN+2];
}; };
/*!
Values and structures used in MODE SENSE 10 command.
*/
#define READERRREC 0x01
#define CDRPARMS 0x0D
#define CDRAUDIOCTL 0x0E
#define CDRCAPS 0x2A
/***************************************************************************** /*****************************************************************************
%%% SRB - HOST ADAPTER INQUIRY - SC_HA_INQUIRY (0) %%% %%% SRB - HOST ADAPTER INQUIRY - SC_HA_INQUIRY (0) %%%
*****************************************************************************/ *****************************************************************************/
@@ -114,33 +122,50 @@ typedef struct // Offset
} }
SRB_HAInquiry; SRB_HAInquiry;
const char * wnaspi32_is_cdrom(const char drive_letter); /*!
Return the the kind of drive capabilities of device.
Note: string is malloc'd so caller should free() then returned
string when done with it.
*/
cdio_drive_cap_t get_drive_cap_aspi (const _img_private_t *env);
/*!
Get the format (XA, DATA, AUDIO) of a track.
*/
track_format_t get_track_format_aspi(const _img_private_t *env,
track_t i_track);
/*! /*!
Initialize CD device. Initialize internal structures for CD device.
*/ */
bool wnaspi32_init_win32 (_img_private_t *env); bool init_aspi (_img_private_t *env);
const char *is_cdrom_aspi(const char drive_letter);
/*! /*!
Reads an audio device into data starting from lsn. Reads an audio device using the DeviceIoControl method into data
Returns 0 if no error. starting from lsn. Returns 0 if no error.
*/ */
int wnaspi32_read_audio_sectors (_img_private_t *env, void *data, lsn_t lsn, int read_audio_sectors_aspi (_img_private_t *obj, void *data, lsn_t lsn,
unsigned int nblocks); unsigned int nblocks);
/*!
Reads a single mode1 sector using the DeviceIoControl method into
data starting from lsn. Returns 0 if no error.
*/
int read_mode1_sector_aspi (const _img_private_t *env, void *data,
lsn_t lsn, bool b_form2);
/*! /*!
Reads a single mode2 sector from cd device into data starting Reads a single mode2 sector from cd device into data starting
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
int wnaspi32_read_mode2_sector (_img_private_t *env, void *data, lsn_t lsn); int read_mode2_sector_aspi (const _img_private_t *env, void *data, lsn_t lsn,
bool b_form2);
/*! /*!
Read and cache the CD's Track Table of Contents and track info. Read and cache the CD's Track Table of Contents and track info.
Return true if successful or false if an error. Return true if successful or false if an error.
*/ */
bool wnaspi32_read_toc (_img_private_t *env); bool read_toc_aspi (_img_private_t *env);
/*!
Get format of track.
*/
track_format_t wnaspi32_get_track_format(_img_private_t *env,
track_t track_num);

View File

@@ -1,5 +1,5 @@
/* /*
$Id: win32.h,v 1.5 2004/06/20 15:06:42 rocky Exp $ $Id: win32.h,v 1.6 2004/06/21 03:22:58 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
@@ -60,21 +60,13 @@ typedef struct {
/*! /*!
Reads an audio device using the DeviceIoControl method into data Reads an audio device using the DeviceIoControl method into data
starting from lsn. Returns 0 if no error. starting from lsn. Returns 0 if no error.
*/ */
int read_audio_sectors_aspi (_img_private_t *obj, void *data, lsn_t lsn,
unsigned int nblocks);
/*!
Reads an audio device using the DeviceIoControl method into data
starting from lsn. Returns 0 if no error.
*/
int read_audio_sectors_win32ioctl (_img_private_t *obj, void *data, lsn_t lsn, int read_audio_sectors_win32ioctl (_img_private_t *obj, void *data, lsn_t lsn,
unsigned int nblocks); unsigned int nblocks);
/*! /*!
Reads a single mode2 sector using the DeviceIoControl method into Reads a single mode2 sector using the DeviceIoControl method into
data starting from lsn. Returns 0 if no error. data starting from lsn. Returns 0 if no error.
*/ */
int read_mode2_sector_aspi (const _img_private_t *env, void *data, lsn_t lsn,
bool b_form2);
int read_mode2_sector_win32ioctl (const _img_private_t *env, void *data, int read_mode2_sector_win32ioctl (const _img_private_t *env, void *data,
lsn_t lsn, bool b_form2); lsn_t lsn, bool b_form2);
@@ -82,18 +74,14 @@ int read_mode2_sector_win32ioctl (const _img_private_t *env, void *data,
Reads a single mode1 sector using the DeviceIoControl method into Reads a single mode1 sector using the DeviceIoControl method into
data starting from lsn. Returns 0 if no error. data starting from lsn. Returns 0 if no error.
*/ */
int read_mode1_sector_aspi (const _img_private_t *env, void *data,
lsn_t lsn, bool b_form2);
int read_mode1_sector_win32ioctl (const _img_private_t *env, void *data, int read_mode1_sector_win32ioctl (const _img_private_t *env, void *data,
lsn_t lsn, bool b_form2); lsn_t lsn, bool b_form2);
const char *is_cdrom_aspi(const char drive_letter);
const char *is_cdrom_win32ioctl (const char drive_letter); const char *is_cdrom_win32ioctl (const char drive_letter);
/*! /*!
Initialize internal structures for CD device. Initialize internal structures for CD device.
*/ */
bool init_aspi (_img_private_t *env);
bool init_win32ioctl (_img_private_t *env); bool init_win32ioctl (_img_private_t *env);
/*! /*!
@@ -101,7 +89,6 @@ bool init_win32ioctl (_img_private_t *env);
Return true if successful or false if an error. Return true if successful or false if an error.
*/ */
bool read_toc_win32ioctl (_img_private_t *env); bool read_toc_win32ioctl (_img_private_t *env);
bool read_toc_aspi (_img_private_t *env);
char *get_mcn_win32ioctl (const _img_private_t *env); char *get_mcn_win32ioctl (const _img_private_t *env);
@@ -128,6 +115,3 @@ cdio_drive_cap_t get_drive_cap_win32ioctl (const _img_private_t *env);
*/ */
track_format_t get_track_format_win32ioctl(const _img_private_t *env, track_format_t get_track_format_win32ioctl(const _img_private_t *env,
track_t i_track); track_t i_track);
track_format_t get_track_format_aspi(const _img_private_t *env,
track_t i_track);