atapi.c
资源名称:xtractor.zip [点击查看]
上传用户:xmgzy123
上传日期:2007-01-07
资源大小:373k
文件大小:5k
源码类别:
SCSI/ASPI
开发平台:
WINDOWS
- /*
- * atapi.c - Copyright (C) 1999 Jay A. Key
- *
- * Functions for the CDR_ATAPI1, CDR_ATAPI2 class of read/init/deinit functions
- *
- **********************************************************************
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- **********************************************************************
- *
- * $Id: atapi.c,v 1.2 2000/02/25 10:47:37 akey Exp $
- * $Date: 2000/02/25 10:47:37 $
- * $Locker: $
- * $Log: atapi.c,v $
- * Revision 1.2 2000/02/25 10:47:37 akey
- * sync'ed with akrip32.dll v0.94
- *
- * Revision 1.3 2000/02/14 09:56:25 akey
- * cleaned up #ifdef _DEBUG code considerably
- *
- * Revision 1.2 2000/01/03 12:29:43 akey
- * v0.91 release -- added CDDB and bug fixes
- *
- *
- */
- #define _AKRIP32_
- #include <windows.h>
- #include <stdio.h>
- #include "myaspi32.h"
- #include "scsidefs.h"
- #include "aspilib.h"
- #include "akrip32.h"
- extern CDHANDLEREC *cdHandles;
- extern HANDLE *cdMutexes;
- extern CRITICAL_SECTION getHandle;
- extern int alErrCode;
- extern BYTE alAspiErr;
- extern int *nextHandle;
- extern DWORD (*pfnSendASPI32Command)(LPSRB);
- /***************************************************************************
- * readCDAudioLBA_ATAPI
- ***************************************************************************/
- DWORD readCDAudioLBA_ATAPI( HCDROM hCD, LPTRACKBUF t )
- {
- DWORD dwStatus;
- HANDLE heventSRB;
- SRB_ExecSCSICmd s;
- int idx = (int)hCD - 1;
- if ( (idx<0) || (idx>=MAXCDHAND) || !cdHandles[idx].used )
- {
- alErrCode = ALERR_INVHANDLE;
- return SS_ERR;
- }
- if ( t->numFrames * 2352 > t->maxLen )
- {
- alErrCode = ALERR_BUFTOOSMALL;
- return SS_ERR;
- }
- dwStatus = WaitForSingleObject( cdMutexes[idx], TIMEOUT );
- if ( dwStatus != WAIT_OBJECT_0 )
- {
- alErrCode = ALERR_LOCK;
- return SS_ERR;
- }
- #ifdef _DEBUG
- dbprintf( "akrip32: readCDAudioLBA_ATAPI: (%d:%d:%d) %06X:%02X",
- cdHandles[idx].ha, cdHandles[idx].tgt, cdHandles[idx].lun,
- t->startFrame, t->numFrames );
- #endif
- heventSRB = CreateEvent( NULL, TRUE, FALSE, NULL );
- memset( &s, 0, sizeof( s ) );
- s.SRB_Cmd = SC_EXEC_SCSI_CMD;
- s.SRB_HaID = cdHandles[idx].ha;
- s.SRB_Target = cdHandles[idx].tgt;
- s.SRB_Lun = cdHandles[idx].lun;
- s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
- s.SRB_BufLen = t->maxLen;
- s.SRB_BufPointer = &(t->buf[0]);
- s.SRB_SenseLen = SENSE_LEN;
- s.SRB_CDBLen = 12;
- s.SRB_PostProc = (LPVOID)heventSRB;
- s.CDBByte[0] = 0xBE;
- //s.CDBByte[1] = 0x04;
- s.CDBByte[3] = (t->startFrame >> 16) & 0xFF;
- s.CDBByte[4] = (t->startFrame >> 8) & 0xFF;
- s.CDBByte[5] = t->startFrame & 0xFF;
- s.CDBByte[8] = t->numFrames & 0xFF;
- s.CDBByte[9] = (cdHandles[idx].readType==CDR_ATAPI1)?0x10:0xF0;
- ResetEvent( heventSRB );
- dwStatus = pfnSendASPI32Command( (LPSRB)&s );
- if ( dwStatus == SS_PENDING )
- {
- WaitForSingleObject( heventSRB, DEFWAITLEN );
- }
- CloseHandle( heventSRB );
- if ( s.SRB_Status != SS_COMP )
- {
- #ifdef _DEBUG
- BYTE *p;
- dbprintf( "akrip32: readCDAudioLBA_ATAPI: ERROR! 0x%08Xn", s.SRB_Status );
- dbprintf( "akrip32: haStat == %d (0x%04X), tgtStat == %d (0x%04X)",
- s.SRB_HaStat, s.SRB_HaStat, s.SRB_TargStat, s.SRB_TargStat );
- p = s.SenseArea;
- dbprintf( " %02X %02X %02X %02X %02X %02X %02X %02X",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );
- p = &(s.SenseArea[8]);
- dbprintf( " %02X %02X %02X %02X %02X %02X %02X %02X",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );
- #endif
- alErrCode = ALERR_ASPI;
- alAspiErr = s.SRB_Status;
- ReleaseMutex( cdMutexes[idx] );
- return SS_ERR;
- }
- t->len = t->numFrames * 2352;
- t->startOffset = 0;
- t->status = s.SRB_Status;
- ReleaseMutex( cdMutexes[idx] );
- return s.SRB_Status;
- }