2002-08-16 22:35:45 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* device.h: DVD device access
|
|
|
|
|
*****************************************************************************
|
|
|
|
|
* Copyright (C) 1998-2002 VideoLAN
|
2005-10-01 17:58:37 +00:00
|
|
|
|
*
|
|
|
|
|
* Modified for use with MPlayer, changes contained in libdvdcss_changes.diff.
|
2006-06-22 13:34:00 +00:00
|
|
|
|
* detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
|
2002-08-16 22:35:45 +00:00
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Authors: St<EFBFBD>phane Borel <stef@via.ecp.fr>
|
|
|
|
|
* Samuel Hocevar <sam@zoy.org>
|
|
|
|
|
* H<EFBFBD>kan Hjort <d95hjort@dtek.chalmers.se>
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
2003-02-08 00:22:39 +00:00
|
|
|
|
*
|
2002-08-16 22:35:45 +00:00
|
|
|
|
* 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 General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* Preamble
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2005-10-09 10:18:24 +00:00
|
|
|
|
#ifdef HAVE_ERRNO_H
|
2005-10-01 17:19:33 +00:00
|
|
|
|
# include <errno.h>
|
2005-10-09 10:18:24 +00:00
|
|
|
|
#endif
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
2005-10-09 10:18:24 +00:00
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
|
# include <sys/param.h>
|
|
|
|
|
#endif
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#include <fcntl.h>
|
2005-10-09 10:18:24 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-10-01 17:19:33 +00:00
|
|
|
|
# include <unistd.h>
|
2005-10-09 10:18:24 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LIMITS_H
|
2005-10-01 17:19:33 +00:00
|
|
|
|
# include <limits.h>
|
2005-10-09 10:18:24 +00:00
|
|
|
|
#endif
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
#if defined( WIN32 ) && !defined( SYS_CYGWIN )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
# include <io.h> /* read() */
|
|
|
|
|
#else
|
|
|
|
|
# include <sys/uio.h> /* struct iovec */
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-08-16 22:50:22 +00:00
|
|
|
|
#include "dvdcss.h"
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "css.h"
|
|
|
|
|
#include "libdvdcss.h"
|
|
|
|
|
#include "ioctl.h"
|
|
|
|
|
#include "device.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2002-12-29 15:32:56 +00:00
|
|
|
|
* Device reading prototypes
|
2002-08-16 22:35:45 +00:00
|
|
|
|
*****************************************************************************/
|
2002-12-29 15:32:56 +00:00
|
|
|
|
static int libc_open ( dvdcss_t, char const * );
|
|
|
|
|
static int libc_seek ( dvdcss_t, int );
|
|
|
|
|
static int libc_read ( dvdcss_t, void *, int );
|
|
|
|
|
static int libc_readv ( dvdcss_t, struct iovec *, int );
|
|
|
|
|
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#ifdef WIN32
|
2002-12-29 15:32:56 +00:00
|
|
|
|
static int win2k_open ( dvdcss_t, char const * );
|
|
|
|
|
static int aspi_open ( dvdcss_t, char const * );
|
|
|
|
|
static int win2k_seek ( dvdcss_t, int );
|
|
|
|
|
static int aspi_seek ( dvdcss_t, int );
|
|
|
|
|
static int win2k_read ( dvdcss_t, void *, int );
|
|
|
|
|
static int aspi_read ( dvdcss_t, void *, int );
|
|
|
|
|
static int win_readv ( dvdcss_t, struct iovec *, int );
|
|
|
|
|
|
|
|
|
|
static int aspi_read_internal ( int, void *, int );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
int _dvdcss_use_ioctls( dvdcss_t dvdcss )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2002-12-29 15:32:56 +00:00
|
|
|
|
#if defined( WIN32 )
|
|
|
|
|
if( dvdcss->b_file )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return 0;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
/* FIXME: implement this for Windows */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
if( WIN2K )
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
return 1;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
return 1;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
struct stat fileinfo;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = fstat( dvdcss->i_fd, &fileinfo );
|
|
|
|
|
if( ret < 0 )
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
return 1; /* What to do? Be conservative and try to use the ioctls */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
|
|
|
|
/* Complete this list and check that we test for the right things
|
2002-08-16 22:35:45 +00:00
|
|
|
|
* (I've assumed for all OSs that 'r', (raw) device, are char devices
|
|
|
|
|
* and those that don't contain/use an 'r' in the name are block devices)
|
|
|
|
|
*
|
|
|
|
|
* Linux needs a block device
|
|
|
|
|
* Solaris needs a char device
|
2003-02-08 00:22:39 +00:00
|
|
|
|
* Darwin needs a char device
|
2002-08-16 22:35:45 +00:00
|
|
|
|
* OpenBSD needs a char device
|
|
|
|
|
* NetBSD needs a char device
|
|
|
|
|
* FreeBSD can use either the block or the char device
|
|
|
|
|
* BSD/OS can use either the block or the char device
|
|
|
|
|
*/
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2002-08-16 22:35:45 +00:00
|
|
|
|
/* Check if this is a block/char device */
|
2003-02-08 00:22:39 +00:00
|
|
|
|
if( S_ISBLK( fileinfo.st_mode ) ||
|
|
|
|
|
S_ISCHR( fileinfo.st_mode ) )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
return 1;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
return 0;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _dvdcss_open ( dvdcss_t dvdcss )
|
|
|
|
|
{
|
2002-12-29 15:32:56 +00:00
|
|
|
|
char const *psz_device = dvdcss->psz_device;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_debug( dvdcss, "opening target `%s'", psz_device );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
#if defined( WIN32 )
|
2004-08-12 22:37:08 +00:00
|
|
|
|
dvdcss->b_file = 1;
|
|
|
|
|
/* If device is "X:" or "X:\", we are not actually opening a file. */
|
|
|
|
|
if (psz_device[0] && psz_device[1] == ':' &&
|
|
|
|
|
(!psz_device[2] || (psz_device[2] == '\\' && !psz_device[3])))
|
|
|
|
|
dvdcss->b_file = 0;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
/* Initialize readv temporary buffer */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
dvdcss->p_readv_buffer = NULL;
|
|
|
|
|
dvdcss->i_readv_buf_size = 0;
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
if( !dvdcss->b_file && WIN2K )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_debug( dvdcss, "using Win2K API for access" );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
dvdcss->pf_seek = win2k_seek;
|
|
|
|
|
dvdcss->pf_read = win2k_read;
|
|
|
|
|
dvdcss->pf_readv = win_readv;
|
|
|
|
|
return win2k_open( dvdcss, psz_device );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
2002-12-29 15:32:56 +00:00
|
|
|
|
else if( !dvdcss->b_file )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_debug( dvdcss, "using ASPI for access" );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
dvdcss->pf_seek = aspi_seek;
|
|
|
|
|
dvdcss->pf_read = aspi_read;
|
|
|
|
|
dvdcss->pf_readv = win_readv;
|
|
|
|
|
return aspi_open( dvdcss, psz_device );
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#endif
|
2002-12-29 15:32:56 +00:00
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_debug( dvdcss, "using libc for access" );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
dvdcss->pf_seek = libc_seek;
|
|
|
|
|
dvdcss->pf_read = libc_read;
|
|
|
|
|
dvdcss->pf_readv = libc_readv;
|
|
|
|
|
return libc_open( dvdcss, psz_device );
|
|
|
|
|
}
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32
|
2002-12-29 15:32:56 +00:00
|
|
|
|
int _dvdcss_raw_open ( dvdcss_t dvdcss, char const *psz_device )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
|
|
|
|
dvdcss->i_raw_fd = open( psz_device, 0 );
|
|
|
|
|
|
|
|
|
|
if( dvdcss->i_raw_fd == -1 )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_debug( dvdcss, "cannot open %s (%s)",
|
|
|
|
|
psz_device, strerror(errno) );
|
|
|
|
|
print_error( dvdcss, "failed to open raw device, but continuing" );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dvdcss->i_read_fd = dvdcss->i_raw_fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int _dvdcss_close ( dvdcss_t dvdcss )
|
|
|
|
|
{
|
|
|
|
|
#if defined( WIN32 )
|
2002-12-29 15:32:56 +00:00
|
|
|
|
if( dvdcss->b_file )
|
|
|
|
|
{
|
|
|
|
|
close( dvdcss->i_fd );
|
|
|
|
|
}
|
|
|
|
|
else if( WIN2K )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
|
|
|
|
CloseHandle( (HANDLE) dvdcss->i_fd );
|
|
|
|
|
}
|
2002-12-29 15:32:56 +00:00
|
|
|
|
else /* ASPI */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2002-12-29 15:32:56 +00:00
|
|
|
|
struct w32_aspidev *fd = (struct w32_aspidev *) dvdcss->i_fd;
|
|
|
|
|
|
|
|
|
|
/* Unload aspi and free w32_aspidev structure */
|
|
|
|
|
FreeLibrary( (HMODULE) fd->hASPI );
|
|
|
|
|
free( (void*) dvdcss->i_fd );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free readv temporary buffer */
|
|
|
|
|
if( dvdcss->p_readv_buffer )
|
|
|
|
|
{
|
|
|
|
|
free( dvdcss->p_readv_buffer );
|
|
|
|
|
dvdcss->p_readv_buffer = NULL;
|
|
|
|
|
dvdcss->i_readv_buf_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return 0;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#else
|
|
|
|
|
close( dvdcss->i_fd );
|
|
|
|
|
|
|
|
|
|
if( dvdcss->i_raw_fd >= 0 )
|
|
|
|
|
{
|
|
|
|
|
close( dvdcss->i_raw_fd );
|
|
|
|
|
dvdcss->i_raw_fd = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
/* Following functions are local */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* Open commands.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static int libc_open ( dvdcss_t dvdcss, char const *psz_device )
|
|
|
|
|
{
|
|
|
|
|
#if !defined( WIN32 )
|
|
|
|
|
dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, 0 );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#else
|
2002-12-29 15:32:56 +00:00
|
|
|
|
dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, O_BINARY );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
if( dvdcss->i_fd == -1 )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_debug( dvdcss, "cannot open %s (%s)",
|
|
|
|
|
psz_device, strerror(errno) );
|
|
|
|
|
print_error( dvdcss, "failed to open device" );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = 0;
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return 0;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined( WIN32 )
|
2002-12-29 15:32:56 +00:00
|
|
|
|
static int win2k_open ( dvdcss_t dvdcss, char const *psz_device )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2002-12-29 15:32:56 +00:00
|
|
|
|
char psz_dvd[7];
|
|
|
|
|
_snprintf( psz_dvd, 7, "\\\\.\\%c:", psz_device[0] );
|
|
|
|
|
|
|
|
|
|
/* To work around an M$ bug in IOCTL_DVD_READ_STRUCTURE, we need read
|
|
|
|
|
* _and_ write access to the device (so we can make SCSI Pass Through
|
|
|
|
|
* Requests). Unfortunately this is only allowed if you have
|
|
|
|
|
* administrator priviledges so we allow for a fallback method with
|
|
|
|
|
* only read access to the device (in this case ioctl_ReadCopyright()
|
|
|
|
|
* won't send back the right result).
|
|
|
|
|
* (See Microsoft Q241374: Read and Write Access Required for SCSI
|
|
|
|
|
* Pass Through Requests) */
|
2005-06-07 13:36:21 +00:00
|
|
|
|
dvdcss->i_fd = (int)
|
2002-12-29 15:32:56 +00:00
|
|
|
|
CreateFile( psz_dvd, GENERIC_READ | GENERIC_WRITE,
|
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
|
NULL, OPEN_EXISTING,
|
|
|
|
|
FILE_FLAG_RANDOM_ACCESS, NULL );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
|
2005-06-07 13:36:21 +00:00
|
|
|
|
dvdcss->i_fd = (int)
|
2002-12-29 15:32:56 +00:00
|
|
|
|
CreateFile( psz_dvd, GENERIC_READ, FILE_SHARE_READ,
|
|
|
|
|
NULL, OPEN_EXISTING,
|
|
|
|
|
FILE_FLAG_RANDOM_ACCESS, NULL );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "failed opening device" );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = 0;
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return 0;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
|
|
|
|
HMODULE hASPI;
|
|
|
|
|
DWORD dwSupportInfo;
|
|
|
|
|
struct w32_aspidev *fd;
|
|
|
|
|
int i, j, i_hostadapters;
|
2005-06-07 13:36:21 +00:00
|
|
|
|
GETASPI32SUPPORTINFO lpGetSupport;
|
|
|
|
|
SENDASPI32COMMAND lpSendCommand;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
char c_drive = psz_device[0];
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
/* load aspi and init w32_aspidev structure */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
hASPI = LoadLibrary( "wnaspi32.dll" );
|
|
|
|
|
if( hASPI == NULL )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "unable to load wnaspi32.dll" );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-07 13:36:21 +00:00
|
|
|
|
lpGetSupport = (GETASPI32SUPPORTINFO) GetProcAddress( hASPI, "GetASPI32SupportInfo" );
|
|
|
|
|
lpSendCommand = (SENDASPI32COMMAND) GetProcAddress( hASPI, "SendASPI32Command" );
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2002-08-16 22:35:45 +00:00
|
|
|
|
if(lpGetSupport == NULL || lpSendCommand == NULL )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "unable to get aspi function pointers" );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
FreeLibrary( hASPI );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dwSupportInfo = lpGetSupport();
|
|
|
|
|
|
|
|
|
|
if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "no ASPI adapters found" );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
FreeLibrary( hASPI );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "unable to initalize aspi layer" );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
FreeLibrary( hASPI );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) );
|
|
|
|
|
if( i_hostadapters == 0 )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "no ASPI adapters ready" );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
FreeLibrary( hASPI );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd = malloc( sizeof( struct w32_aspidev ) );
|
|
|
|
|
if( fd == NULL )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "not enough memory" );
|
2002-08-16 22:35:45 +00:00
|
|
|
|
FreeLibrary( hASPI );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd->i_blocks = 0;
|
|
|
|
|
fd->hASPI = (long) hASPI;
|
|
|
|
|
fd->lpSendCommand = lpSendCommand;
|
|
|
|
|
|
|
|
|
|
c_drive = c_drive > 'Z' ? c_drive - 'a' : c_drive - 'A';
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < i_hostadapters; i++ )
|
|
|
|
|
{
|
|
|
|
|
for( j = 0; j < 15; j++ )
|
|
|
|
|
{
|
|
|
|
|
struct SRB_GetDiskInfo srbDiskInfo;
|
|
|
|
|
|
|
|
|
|
srbDiskInfo.SRB_Cmd = SC_GET_DISK_INFO;
|
|
|
|
|
srbDiskInfo.SRB_HaId = i;
|
|
|
|
|
srbDiskInfo.SRB_Flags = 0;
|
|
|
|
|
srbDiskInfo.SRB_Hdr_Rsvd = 0;
|
|
|
|
|
srbDiskInfo.SRB_Target = j;
|
|
|
|
|
srbDiskInfo.SRB_Lun = 0;
|
|
|
|
|
|
|
|
|
|
lpSendCommand( (void*) &srbDiskInfo );
|
|
|
|
|
|
|
|
|
|
if( (srbDiskInfo.SRB_Status == SS_COMP) &&
|
|
|
|
|
(srbDiskInfo.SRB_Int13HDriveInfo == c_drive) )
|
|
|
|
|
{
|
2002-12-29 15:32:56 +00:00
|
|
|
|
/* Make sure this is a cdrom device */
|
|
|
|
|
struct SRB_GDEVBlock srbGDEVBlock;
|
|
|
|
|
|
|
|
|
|
memset( &srbGDEVBlock, 0, sizeof(struct SRB_GDEVBlock) );
|
|
|
|
|
srbGDEVBlock.SRB_Cmd = SC_GET_DEV_TYPE;
|
|
|
|
|
srbGDEVBlock.SRB_HaId = i;
|
|
|
|
|
srbGDEVBlock.SRB_Target = j;
|
|
|
|
|
|
|
|
|
|
lpSendCommand( (void*) &srbGDEVBlock );
|
|
|
|
|
|
|
|
|
|
if( ( srbGDEVBlock.SRB_Status == SS_COMP ) &&
|
|
|
|
|
( srbGDEVBlock.SRB_DeviceType == DTYPE_CDROM ) )
|
|
|
|
|
{
|
|
|
|
|
fd->i_sid = MAKEWORD( i, j );
|
|
|
|
|
dvdcss->i_fd = (int) fd;
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = 0;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
free( (void*) fd );
|
|
|
|
|
FreeLibrary( hASPI );
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss,"this is not a cdrom drive" );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free( (void*) fd );
|
|
|
|
|
FreeLibrary( hASPI );
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "unable to get haid and target (aspi)" );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
2002-12-29 15:32:56 +00:00
|
|
|
|
#endif
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2002-12-29 15:32:56 +00:00
|
|
|
|
* Seek commands.
|
2002-08-16 22:35:45 +00:00
|
|
|
|
*****************************************************************************/
|
2002-12-29 15:32:56 +00:00
|
|
|
|
static int libc_seek( dvdcss_t dvdcss, int i_blocks )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
off_t i_seek;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
if( dvdcss->i_pos == i_blocks )
|
|
|
|
|
{
|
|
|
|
|
/* We are already in position */
|
|
|
|
|
return i_blocks;
|
|
|
|
|
}
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
2005-10-01 17:19:33 +00:00
|
|
|
|
i_seek = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
|
|
|
|
|
i_seek = lseek( dvdcss->i_read_fd, i_seek, SEEK_SET );
|
2002-12-29 15:32:56 +00:00
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
if( i_seek < 0 )
|
2002-12-29 15:32:56 +00:00
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "seek error" );
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
|
|
|
|
return i_seek;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = i_seek / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
|
|
|
|
|
return dvdcss->i_pos;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
#if defined( WIN32 )
|
|
|
|
|
static int win2k_seek( dvdcss_t dvdcss, int i_blocks )
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
LARGE_INTEGER li_seek;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
|
|
|
|
|
#ifndef INVALID_SET_FILE_POINTER
|
|
|
|
|
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
if( dvdcss->i_pos == i_blocks )
|
|
|
|
|
{
|
|
|
|
|
/* We are already in position */
|
|
|
|
|
return i_blocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li_seek.QuadPart = (LONGLONG)i_blocks * DVDCSS_BLOCK_SIZE;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
li_seek.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd,
|
|
|
|
|
li_seek.LowPart,
|
|
|
|
|
&li_seek.HighPart, FILE_BEGIN );
|
|
|
|
|
if( (li_seek.LowPart == INVALID_SET_FILE_POINTER)
|
2002-12-29 15:32:56 +00:00
|
|
|
|
&& GetLastError() != NO_ERROR)
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
|
|
|
|
return -1;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = li_seek.QuadPart / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
|
|
|
|
|
return dvdcss->i_pos;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int aspi_seek( dvdcss_t dvdcss, int i_blocks )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
|
|
|
|
int i_old_blocks;
|
|
|
|
|
char sz_buf[ DVDCSS_BLOCK_SIZE ];
|
2002-12-29 15:32:56 +00:00
|
|
|
|
struct w32_aspidev *fd = (struct w32_aspidev *) dvdcss->i_fd;
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
|
|
|
|
if( dvdcss->i_pos == i_blocks )
|
|
|
|
|
{
|
|
|
|
|
/* We are already in position */
|
|
|
|
|
return i_blocks;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-16 22:35:45 +00:00
|
|
|
|
i_old_blocks = fd->i_blocks;
|
|
|
|
|
fd->i_blocks = i_blocks;
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
if( aspi_read_internal( dvdcss->i_fd, sz_buf, 1 ) == -1 )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
|
|
|
|
fd->i_blocks = i_old_blocks;
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(fd->i_blocks)--;
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = fd->i_blocks;
|
|
|
|
|
|
|
|
|
|
return dvdcss->i_pos;
|
2002-08-16 22:35:45 +00:00
|
|
|
|
}
|
2002-12-29 15:32:56 +00:00
|
|
|
|
#endif
|
2002-08-16 22:35:45 +00:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2002-12-29 15:32:56 +00:00
|
|
|
|
* Read commands.
|
2002-08-16 22:35:45 +00:00
|
|
|
|
*****************************************************************************/
|
2002-12-29 15:32:56 +00:00
|
|
|
|
static int libc_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
off_t i_size, i_ret;
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2005-10-01 17:19:33 +00:00
|
|
|
|
i_size = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
|
|
|
|
|
i_ret = read( dvdcss->i_read_fd, p_buffer, i_size );
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
if( i_ret < 0 )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, "read error" );
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return i_ret;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
/* Handle partial reads */
|
2005-10-01 17:19:33 +00:00
|
|
|
|
if( i_ret != i_size )
|
2003-02-08 00:22:39 +00:00
|
|
|
|
{
|
|
|
|
|
int i_seek;
|
|
|
|
|
|
|
|
|
|
dvdcss->i_pos = -1;
|
|
|
|
|
i_seek = libc_seek( dvdcss, i_ret / DVDCSS_BLOCK_SIZE );
|
|
|
|
|
if( i_seek < 0 )
|
|
|
|
|
{
|
|
|
|
|
return i_seek;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We have to return now so that i_pos isn't clobbered */
|
|
|
|
|
return i_ret / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dvdcss->i_pos += i_ret / DVDCSS_BLOCK_SIZE;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return i_ret / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined( WIN32 )
|
|
|
|
|
static int win2k_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
|
|
|
|
|
{
|
|
|
|
|
int i_bytes;
|
|
|
|
|
|
|
|
|
|
if( !ReadFile( (HANDLE) dvdcss->i_fd, p_buffer,
|
|
|
|
|
i_blocks * DVDCSS_BLOCK_SIZE,
|
|
|
|
|
(LPDWORD)&i_bytes, NULL ) )
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos += i_bytes / DVDCSS_BLOCK_SIZE;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return i_bytes / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int aspi_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
int i_read = aspi_read_internal( dvdcss->i_fd, p_buffer, i_blocks );
|
|
|
|
|
|
|
|
|
|
if( i_read < 0 )
|
|
|
|
|
{
|
|
|
|
|
dvdcss->i_pos = -1;
|
|
|
|
|
return i_read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dvdcss->i_pos += i_read;
|
|
|
|
|
return i_read;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* Readv commands.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static int libc_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks )
|
|
|
|
|
{
|
|
|
|
|
#if defined( WIN32 )
|
|
|
|
|
int i_index, i_len, i_total = 0;
|
|
|
|
|
unsigned char *p_base;
|
|
|
|
|
int i_bytes;
|
|
|
|
|
|
|
|
|
|
for( i_index = i_blocks;
|
|
|
|
|
i_index;
|
|
|
|
|
i_index--, p_iovec++ )
|
|
|
|
|
{
|
|
|
|
|
i_len = p_iovec->iov_len;
|
|
|
|
|
p_base = p_iovec->iov_base;
|
|
|
|
|
|
|
|
|
|
if( i_len <= 0 )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i_bytes = read( dvdcss->i_fd, p_base, i_len );
|
|
|
|
|
|
|
|
|
|
if( i_bytes < 0 )
|
|
|
|
|
{
|
|
|
|
|
/* One of the reads failed, too bad.
|
|
|
|
|
* We won't even bother returning the reads that went ok,
|
|
|
|
|
* and as in the posix spec the file postition is left
|
|
|
|
|
* unspecified after a failure */
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i_total += i_bytes;
|
|
|
|
|
|
|
|
|
|
if( i_bytes != i_len )
|
|
|
|
|
{
|
|
|
|
|
/* We reached the end of the file or a signal interrupted
|
|
|
|
|
* the read. Return a partial read. */
|
2003-02-08 00:22:39 +00:00
|
|
|
|
int i_seek;
|
|
|
|
|
|
|
|
|
|
dvdcss->i_pos = -1;
|
|
|
|
|
i_seek = libc_seek( dvdcss, i_total / DVDCSS_BLOCK_SIZE );
|
|
|
|
|
if( i_seek < 0 )
|
|
|
|
|
{
|
|
|
|
|
return i_seek;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We have to return now so that i_pos isn't clobbered */
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return i_total / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos += i_total / DVDCSS_BLOCK_SIZE;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return i_total / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
#else
|
|
|
|
|
int i_read = readv( dvdcss->i_read_fd, p_iovec, i_blocks );
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
if( i_read < 0 )
|
|
|
|
|
{
|
|
|
|
|
dvdcss->i_pos = -1;
|
|
|
|
|
return i_read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dvdcss->i_pos += i_read / DVDCSS_BLOCK_SIZE;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return i_read / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined( WIN32 )
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* win_readv: vectored read using ReadFile for Win2K and ASPI for win9x
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static int win_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks )
|
|
|
|
|
{
|
|
|
|
|
int i_index;
|
|
|
|
|
int i_blocks_read, i_blocks_total = 0;
|
|
|
|
|
|
|
|
|
|
/* Check the size of the readv temp buffer, just in case we need to
|
|
|
|
|
* realloc something bigger */
|
|
|
|
|
if( dvdcss->i_readv_buf_size < i_blocks * DVDCSS_BLOCK_SIZE )
|
|
|
|
|
{
|
|
|
|
|
dvdcss->i_readv_buf_size = i_blocks * DVDCSS_BLOCK_SIZE;
|
|
|
|
|
|
|
|
|
|
if( dvdcss->p_readv_buffer ) free( dvdcss->p_readv_buffer );
|
|
|
|
|
|
|
|
|
|
/* Allocate a buffer which will be used as a temporary storage
|
|
|
|
|
* for readv */
|
|
|
|
|
dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
|
|
|
|
|
if( !dvdcss->p_readv_buffer )
|
|
|
|
|
{
|
2005-10-01 17:19:33 +00:00
|
|
|
|
print_error( dvdcss, " failed (readv)" );
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( i_index = i_blocks; i_index; i_index-- )
|
|
|
|
|
{
|
2003-02-08 00:22:39 +00:00
|
|
|
|
i_blocks_total += p_iovec[i_index-1].iov_len;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( i_blocks_total <= 0 ) return 0;
|
|
|
|
|
|
|
|
|
|
i_blocks_total /= DVDCSS_BLOCK_SIZE;
|
|
|
|
|
|
|
|
|
|
if( WIN2K )
|
|
|
|
|
{
|
|
|
|
|
unsigned long int i_bytes;
|
|
|
|
|
if( !ReadFile( (HANDLE)dvdcss->i_fd, dvdcss->p_readv_buffer,
|
|
|
|
|
i_blocks_total * DVDCSS_BLOCK_SIZE, &i_bytes, NULL ) )
|
|
|
|
|
{
|
|
|
|
|
/* The read failed... too bad.
|
|
|
|
|
* As in the posix spec the file postition is left
|
|
|
|
|
* unspecified after a failure */
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
i_blocks_read = i_bytes / DVDCSS_BLOCK_SIZE;
|
|
|
|
|
}
|
|
|
|
|
else /* Win9x */
|
|
|
|
|
{
|
|
|
|
|
i_blocks_read = aspi_read_internal( dvdcss->i_fd,
|
|
|
|
|
dvdcss->p_readv_buffer,
|
|
|
|
|
i_blocks_total );
|
|
|
|
|
if( i_blocks_read < 0 )
|
|
|
|
|
{
|
|
|
|
|
/* See above */
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos = -1;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We just have to copy the content of the temp buffer into the iovecs */
|
|
|
|
|
for( i_index = 0, i_blocks_total = i_blocks_read;
|
|
|
|
|
i_blocks_total > 0;
|
|
|
|
|
i_index++ )
|
|
|
|
|
{
|
|
|
|
|
memcpy( p_iovec[i_index].iov_base,
|
|
|
|
|
dvdcss->p_readv_buffer + (i_blocks_read - i_blocks_total)
|
|
|
|
|
* DVDCSS_BLOCK_SIZE,
|
|
|
|
|
p_iovec[i_index].iov_len );
|
|
|
|
|
/* if we read less blocks than asked, we'll just end up copying
|
|
|
|
|
* garbage, this isn't an issue as we return the number of
|
|
|
|
|
* blocks actually read */
|
|
|
|
|
i_blocks_total -= ( p_iovec[i_index].iov_len / DVDCSS_BLOCK_SIZE );
|
2003-02-08 00:22:39 +00:00
|
|
|
|
}
|
2002-12-29 15:32:56 +00:00
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
dvdcss->i_pos += i_blocks_read;
|
2002-12-29 15:32:56 +00:00
|
|
|
|
return i_blocks_read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int aspi_read_internal( int i_fd, void *p_data, int i_blocks )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
|
|
|
|
HANDLE hEvent;
|
|
|
|
|
struct SRB_ExecSCSICmd ssc;
|
|
|
|
|
struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
|
|
|
|
|
|
|
|
|
|
/* Create the transfer completion event */
|
|
|
|
|
hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
|
|
|
|
|
if( hEvent == NULL )
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset( &ssc, 0, sizeof( ssc ) );
|
|
|
|
|
|
|
|
|
|
ssc.SRB_Cmd = SC_EXEC_SCSI_CMD;
|
|
|
|
|
ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
|
|
|
|
|
ssc.SRB_HaId = LOBYTE( fd->i_sid );
|
|
|
|
|
ssc.SRB_Target = HIBYTE( fd->i_sid );
|
|
|
|
|
ssc.SRB_SenseLen = SENSE_LEN;
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2002-08-16 22:35:45 +00:00
|
|
|
|
ssc.SRB_PostProc = (LPVOID) hEvent;
|
|
|
|
|
ssc.SRB_BufPointer = p_data;
|
|
|
|
|
ssc.SRB_CDBLen = 12;
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2002-08-16 22:35:45 +00:00
|
|
|
|
ssc.CDBByte[0] = 0xA8; /* RAW */
|
|
|
|
|
ssc.CDBByte[2] = (UCHAR) (fd->i_blocks >> 24);
|
|
|
|
|
ssc.CDBByte[3] = (UCHAR) (fd->i_blocks >> 16) & 0xff;
|
|
|
|
|
ssc.CDBByte[4] = (UCHAR) (fd->i_blocks >> 8) & 0xff;
|
|
|
|
|
ssc.CDBByte[5] = (UCHAR) (fd->i_blocks) & 0xff;
|
2003-02-08 00:22:39 +00:00
|
|
|
|
|
2002-08-16 22:35:45 +00:00
|
|
|
|
/* We have to break down the reads into 64kb pieces (ASPI restriction) */
|
|
|
|
|
if( i_blocks > 32 )
|
|
|
|
|
{
|
|
|
|
|
ssc.SRB_BufLen = 32 * DVDCSS_BLOCK_SIZE;
|
|
|
|
|
ssc.CDBByte[9] = 32;
|
|
|
|
|
fd->i_blocks += 32;
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
/* Initiate transfer */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
ResetEvent( hEvent );
|
|
|
|
|
fd->lpSendCommand( (void*) &ssc );
|
|
|
|
|
|
2002-12-29 15:32:56 +00:00
|
|
|
|
/* transfer the next 64kb (aspi_read_internal is called recursively)
|
2002-08-16 22:35:45 +00:00
|
|
|
|
* We need to check the status of the read on return */
|
2003-02-08 00:22:39 +00:00
|
|
|
|
if( aspi_read_internal( i_fd,
|
|
|
|
|
(uint8_t*) p_data + 32 * DVDCSS_BLOCK_SIZE,
|
|
|
|
|
i_blocks - 32) < 0 )
|
2002-08-16 22:35:45 +00:00
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* This is the last transfer */
|
|
|
|
|
ssc.SRB_BufLen = i_blocks * DVDCSS_BLOCK_SIZE;
|
|
|
|
|
ssc.CDBByte[9] = (UCHAR) i_blocks;
|
|
|
|
|
fd->i_blocks += i_blocks;
|
|
|
|
|
|
2003-02-08 00:22:39 +00:00
|
|
|
|
/* Initiate transfer */
|
2002-08-16 22:35:45 +00:00
|
|
|
|
ResetEvent( hEvent );
|
|
|
|
|
fd->lpSendCommand( (void*) &ssc );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If the command has still not been processed, wait until it's finished */
|
|
|
|
|
if( ssc.SRB_Status == SS_PENDING )
|
|
|
|
|
{
|
|
|
|
|
WaitForSingleObject( hEvent, INFINITE );
|
|
|
|
|
}
|
|
|
|
|
CloseHandle( hEvent );
|
|
|
|
|
|
|
|
|
|
/* check that the transfer went as planned */
|
|
|
|
|
if( ssc.SRB_Status != SS_COMP )
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return i_blocks;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|