annotate libdvdcss/device.c @ 25927:f4c83afa0683

Add aspect_fit declaration missing for w32_common.
author reimar
date Thu, 07 Feb 2008 21:04:17 +0000
parents 66c2f233ccff
children afa2cc0166be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
1 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
2 * device.h: DVD device access
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
3 *****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
4 * Copyright (C) 1998-2006 VideoLAN
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
5 * $Id$
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
6 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
7 * Authors: Stéphane Borel <stef@via.ecp.fr>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
8 * Sam Hocevar <sam@zoy.org>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
9 * Håkan Hjort <d95hjort@dtek.chalmers.se>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
10 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
14 * (at your option) any later version.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
15 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
19 * GNU General Public License for more details.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
20 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
24 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
25
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
26 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
27 * Preamble
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
28 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
29 #include "config.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
30
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
31 #include <stdio.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
32 #include <stdlib.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
33 #include <string.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
34 #ifdef HAVE_ERRNO_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
35 # include <errno.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
36 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
37 #include <sys/types.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
38 #include <sys/stat.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
39 #ifdef HAVE_SYS_PARAM_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
40 # include <sys/param.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
41 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
42 #include <fcntl.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
43
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
44 #ifdef HAVE_UNISTD_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
45 # include <unistd.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
46 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
47
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
48 #ifdef HAVE_LIMITS_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
49 # include <limits.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
50 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
51
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
52 #if defined( WIN32 ) && !defined( SYS_CYGWIN )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
53 # include <io.h> /* read() */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
54 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
55 # include <sys/uio.h> /* struct iovec */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
56 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
57
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
58 #ifdef DARWIN_DVD_IOCTL
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
59 # include <paths.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
60 # include <CoreFoundation/CoreFoundation.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
61 # include <IOKit/IOKitLib.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
62 # include <IOKit/IOBSD.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
63 # include <IOKit/storage/IOMedia.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
64 # include <IOKit/storage/IOCDMedia.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
65 # include <IOKit/storage/IODVDMedia.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
66 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
67
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
68 #include "dvdcss/dvdcss.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
69
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
70 #include "common.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
71 #include "css.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
72 #include "libdvdcss.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
73 #include "ioctl.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
74 #include "device.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
75
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
76 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
77 * Device reading prototypes
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
78 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
79 static int libc_open ( dvdcss_t, char const * );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
80 static int libc_seek ( dvdcss_t, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
81 static int libc_read ( dvdcss_t, void *, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
82 static int libc_readv ( dvdcss_t, struct iovec *, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
83
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
84 #ifdef WIN32
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
85 static int win2k_open ( dvdcss_t, char const * );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
86 static int aspi_open ( dvdcss_t, char const * );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
87 static int win2k_seek ( dvdcss_t, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
88 static int aspi_seek ( dvdcss_t, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
89 static int win2k_read ( dvdcss_t, void *, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
90 static int aspi_read ( dvdcss_t, void *, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
91 static int win_readv ( dvdcss_t, struct iovec *, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
92
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
93 static int aspi_read_internal ( int, void *, int );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
94 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
95
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
96 int _dvdcss_use_ioctls( dvdcss_t dvdcss )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
97 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
98 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
99 if( dvdcss->b_file )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
100 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
101 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
102 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
103
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
104 /* FIXME: implement this for Windows */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
105 if( WIN2K )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
106 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
107 return 1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
108 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
109 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
110 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
111 return 1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
112 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
113 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
114 struct stat fileinfo;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
115 int ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
116
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
117 ret = fstat( dvdcss->i_fd, &fileinfo );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
118 if( ret < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
119 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
120 return 1; /* What to do? Be conservative and try to use the ioctls */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
121 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
122
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
123 /* Complete this list and check that we test for the right things
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
124 * (I've assumed for all OSs that 'r', (raw) device, are char devices
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
125 * and those that don't contain/use an 'r' in the name are block devices)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
126 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
127 * Linux needs a block device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
128 * Solaris needs a char device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
129 * Darwin needs a char device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
130 * OpenBSD needs a char device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
131 * NetBSD needs a char device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
132 * FreeBSD can use either the block or the char device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
133 * BSD/OS can use either the block or the char device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
134 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
135
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
136 /* Check if this is a block/char device */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
137 if( S_ISBLK( fileinfo.st_mode ) ||
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
138 S_ISCHR( fileinfo.st_mode ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
139 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
140 return 1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
141 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
142 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
143 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
144 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
145 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
146 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
147 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
148
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
149 void _dvdcss_check ( dvdcss_t dvdcss )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
150 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
151 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
152 DWORD drives;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
153 int i;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
154 #elif defined( DARWIN_DVD_IOCTL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
155 io_object_t next_media;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
156 mach_port_t master_port;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
157 kern_return_t kern_result;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
158 io_iterator_t media_iterator;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
159 CFMutableDictionaryRef classes_to_match;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
160 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
161 char *ppsz_devices[] = { "/dev/dvd", "/dev/cdrom", "/dev/hdc", NULL };
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
162 int i, i_fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
163 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
164
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
165 /* If the device name is non-null, return */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
166 if( dvdcss->psz_device[0] )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
167 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
168 return;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
169 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
170
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
171 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
172 drives = GetLogicalDrives();
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
173
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
174 for( i = 0; drives; i++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
175 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
176 char psz_device[5];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
177 DWORD cur = 1 << i;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
178 UINT i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
179
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
180 if( (drives & cur) == 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
181 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
182 continue;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
183 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
184 drives &= ~cur;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
185
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
186 sprintf( psz_device, "%c:\\", 'A' + i );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
187 i_ret = GetDriveType( psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
188 if( i_ret != DRIVE_CDROM )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
189 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
190 continue;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
191 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
192
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
193 /* Remove trailing backslash */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
194 psz_device[2] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
195
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
196 /* FIXME: we want to differenciate between CD and DVD drives
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
197 * using DeviceIoControl() */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
198 print_debug( dvdcss, "defaulting to drive `%s'", psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
199 free( dvdcss->psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
200 dvdcss->psz_device = strdup( psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
201 return;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
202 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
203 #elif defined( DARWIN_DVD_IOCTL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
204
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
205 kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
206 if( kern_result != KERN_SUCCESS )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
207 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
208 return;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
209 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
210
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
211 classes_to_match = IOServiceMatching( kIODVDMediaClass );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
212 if( classes_to_match == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
213 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
214 return;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
215 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
216
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
217 CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ),
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
218 kCFBooleanTrue );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
219
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
220 kern_result = IOServiceGetMatchingServices( master_port, classes_to_match,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
221 &media_iterator );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
222 if( kern_result != KERN_SUCCESS )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
223 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
224 return;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
225 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
226
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
227 next_media = IOIteratorNext( media_iterator );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
228 for( ; ; )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
229 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
230 char psz_buf[0x32];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
231 size_t i_pathlen;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
232 CFTypeRef psz_path;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
233
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
234 next_media = IOIteratorNext( media_iterator );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
235 if( next_media == 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
236 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
237 break;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
238 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
239
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
240 psz_path = IORegistryEntryCreateCFProperty( next_media,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
241 CFSTR( kIOBSDNameKey ),
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
242 kCFAllocatorDefault,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
243 0 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
244 if( psz_path == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
245 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
246 IOObjectRelease( next_media );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
247 continue;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
248 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
249
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
250 snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
251 i_pathlen = strlen( psz_buf );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
252
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
253 if( CFStringGetCString( psz_path,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
254 (char*)&psz_buf + i_pathlen,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
255 sizeof(psz_buf) - i_pathlen,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
256 kCFStringEncodingASCII ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
257 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
258 print_debug( dvdcss, "defaulting to drive `%s'", psz_buf );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
259 CFRelease( psz_path );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
260 IOObjectRelease( next_media );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
261 IOObjectRelease( media_iterator );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
262 free( dvdcss->psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
263 dvdcss->psz_device = strdup( psz_buf );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
264 return;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
265 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
266
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
267 CFRelease( psz_path );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
268
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
269 IOObjectRelease( next_media );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
270 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
271
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
272 IOObjectRelease( media_iterator );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
273 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
274 for( i = 0; ppsz_devices[i]; i++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
275 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
276 i_fd = open( ppsz_devices[i], 0 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
277 if( i_fd != -1 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
278 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
279 print_debug( dvdcss, "defaulting to drive `%s'", ppsz_devices[i] );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
280 close( i_fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
281 free( dvdcss->psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
282 dvdcss->psz_device = strdup( ppsz_devices[i] );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
283 return;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
284 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
285 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
286 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
287
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
288 print_error( dvdcss, "could not find a suitable default drive" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
289 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
290
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
291 int _dvdcss_open ( dvdcss_t dvdcss )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
292 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
293 char const *psz_device = dvdcss->psz_device;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
294
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
295 print_debug( dvdcss, "opening target `%s'", psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
296
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
297 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
298 dvdcss->b_file = 1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
299 /* If device is "X:" or "X:\", we are not actually opening a file. */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
300 if (psz_device[0] && psz_device[1] == ':' &&
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
301 (!psz_device[2] || (psz_device[2] == '\\' && !psz_device[3])))
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
302 dvdcss->b_file = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
303
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
304 /* Initialize readv temporary buffer */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
305 dvdcss->p_readv_buffer = NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
306 dvdcss->i_readv_buf_size = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
307
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
308 if( !dvdcss->b_file && WIN2K )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
309 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
310 print_debug( dvdcss, "using Win2K API for access" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
311 dvdcss->pf_seek = win2k_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
312 dvdcss->pf_read = win2k_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
313 dvdcss->pf_readv = win_readv;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
314 return win2k_open( dvdcss, psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
315 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
316 else if( !dvdcss->b_file )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
317 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
318 print_debug( dvdcss, "using ASPI for access" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
319 dvdcss->pf_seek = aspi_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
320 dvdcss->pf_read = aspi_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
321 dvdcss->pf_readv = win_readv;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
322 return aspi_open( dvdcss, psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
323 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
324 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
325 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
326 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
327 print_debug( dvdcss, "using libc for access" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
328 dvdcss->pf_seek = libc_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
329 dvdcss->pf_read = libc_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
330 dvdcss->pf_readv = libc_readv;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
331 return libc_open( dvdcss, psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
332 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
333 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
334
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
335 #ifndef WIN32
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
336 int _dvdcss_raw_open ( dvdcss_t dvdcss, char const *psz_device )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
337 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
338 dvdcss->i_raw_fd = open( psz_device, 0 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
339
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
340 if( dvdcss->i_raw_fd == -1 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
341 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
342 print_debug( dvdcss, "cannot open %s (%s)",
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
343 psz_device, strerror(errno) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
344 print_error( dvdcss, "failed to open raw device, but continuing" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
345 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
346 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
347 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
348 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
349 dvdcss->i_read_fd = dvdcss->i_raw_fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
350 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
351
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
352 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
353 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
354 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
355
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
356 int _dvdcss_close ( dvdcss_t dvdcss )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
357 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
358 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
359 if( dvdcss->b_file )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
360 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
361 close( dvdcss->i_fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
362 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
363 else if( WIN2K )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
364 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
365 CloseHandle( (HANDLE) dvdcss->i_fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
366 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
367 else /* ASPI */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
368 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
369 struct w32_aspidev *fd = (struct w32_aspidev *) dvdcss->i_fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
370
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
371 /* Unload aspi and free w32_aspidev structure */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
372 FreeLibrary( (HMODULE) fd->hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
373 free( (void*) dvdcss->i_fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
374 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
375
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
376 /* Free readv temporary buffer */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
377 if( dvdcss->p_readv_buffer )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
378 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
379 free( dvdcss->p_readv_buffer );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
380 dvdcss->p_readv_buffer = NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
381 dvdcss->i_readv_buf_size = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
382 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
383
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
384 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
385 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
386 close( dvdcss->i_fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
387
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
388 if( dvdcss->i_raw_fd >= 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
389 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
390 close( dvdcss->i_raw_fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
391 dvdcss->i_raw_fd = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
392 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
393
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
394 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
395 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
396 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
397
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
398 /* Following functions are local */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
399
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
400 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
401 * Open commands.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
402 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
403 static int libc_open ( dvdcss_t dvdcss, char const *psz_device )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
404 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
405 #if !defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
406 dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, 0 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
407 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
408 dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, O_BINARY );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
409 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
410
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
411 if( dvdcss->i_fd == -1 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
412 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
413 print_debug( dvdcss, "cannot open %s (%s)",
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
414 psz_device, strerror(errno) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
415 print_error( dvdcss, "failed to open device" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
416 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
417 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
418
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
419 dvdcss->i_pos = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
420
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
421 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
422 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
423
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
424 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
425 static int win2k_open ( dvdcss_t dvdcss, char const *psz_device )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
426 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
427 char psz_dvd[7];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
428 _snprintf( psz_dvd, 7, "\\\\.\\%c:", psz_device[0] );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
429
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
430 /* To work around an M$ bug in IOCTL_DVD_READ_STRUCTURE, we need read
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
431 * _and_ write access to the device (so we can make SCSI Pass Through
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
432 * Requests). Unfortunately this is only allowed if you have
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
433 * administrator priviledges so we allow for a fallback method with
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
434 * only read access to the device (in this case ioctl_ReadCopyright()
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
435 * won't send back the right result).
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
436 * (See Microsoft Q241374: Read and Write Access Required for SCSI
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
437 * Pass Through Requests) */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
438 dvdcss->i_fd = (int)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
439 CreateFile( psz_dvd, GENERIC_READ | GENERIC_WRITE,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
440 FILE_SHARE_READ | FILE_SHARE_WRITE,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
441 NULL, OPEN_EXISTING,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
442 FILE_FLAG_RANDOM_ACCESS, NULL );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
443
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
444 if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
445 dvdcss->i_fd = (int)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
446 CreateFile( psz_dvd, GENERIC_READ, FILE_SHARE_READ,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
447 NULL, OPEN_EXISTING,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
448 FILE_FLAG_RANDOM_ACCESS, NULL );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
449
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
450 if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
451 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
452 print_error( dvdcss, "failed opening device" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
453 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
454 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
455
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
456 dvdcss->i_pos = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
457
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
458 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
459 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
460
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
461 static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
462 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
463 HMODULE hASPI;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
464 DWORD dwSupportInfo;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
465 struct w32_aspidev *fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
466 int i, j, i_hostadapters;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
467 GETASPI32SUPPORTINFO lpGetSupport;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
468 SENDASPI32COMMAND lpSendCommand;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
469 char c_drive = psz_device[0];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
470
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
471 /* load aspi and init w32_aspidev structure */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
472 hASPI = LoadLibrary( "wnaspi32.dll" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
473 if( hASPI == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
474 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
475 print_error( dvdcss, "unable to load wnaspi32.dll" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
476 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
477 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
478
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
479 lpGetSupport = (GETASPI32SUPPORTINFO) GetProcAddress( hASPI, "GetASPI32SupportInfo" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
480 lpSendCommand = (SENDASPI32COMMAND) GetProcAddress( hASPI, "SendASPI32Command" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
481
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
482 if(lpGetSupport == NULL || lpSendCommand == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
483 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
484 print_error( dvdcss, "unable to get aspi function pointers" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
485 FreeLibrary( hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
486 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
487 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
488
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
489 dwSupportInfo = lpGetSupport();
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
490
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
491 if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
492 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
493 print_error( dvdcss, "no ASPI adapters found" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
494 FreeLibrary( hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
495 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
496 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
497
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
498 if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
499 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
500 print_error( dvdcss, "unable to initalize aspi layer" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
501 FreeLibrary( hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
502 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
503 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
504
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
505 i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
506 if( i_hostadapters == 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
507 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
508 print_error( dvdcss, "no ASPI adapters ready" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
509 FreeLibrary( hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
510 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
511 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
512
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
513 fd = malloc( sizeof( struct w32_aspidev ) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
514 if( fd == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
515 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
516 print_error( dvdcss, "not enough memory" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
517 FreeLibrary( hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
518 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
519 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
520
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
521 fd->i_blocks = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
522 fd->hASPI = (long) hASPI;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
523 fd->lpSendCommand = lpSendCommand;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
524
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
525 c_drive = c_drive > 'Z' ? c_drive - 'a' : c_drive - 'A';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
526
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
527 for( i = 0; i < i_hostadapters; i++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
528 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
529 for( j = 0; j < 15; j++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
530 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
531 struct SRB_GetDiskInfo srbDiskInfo;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
532
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
533 srbDiskInfo.SRB_Cmd = SC_GET_DISK_INFO;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
534 srbDiskInfo.SRB_HaId = i;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
535 srbDiskInfo.SRB_Flags = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
536 srbDiskInfo.SRB_Hdr_Rsvd = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
537 srbDiskInfo.SRB_Target = j;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
538 srbDiskInfo.SRB_Lun = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
539
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
540 lpSendCommand( (void*) &srbDiskInfo );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
541
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
542 if( (srbDiskInfo.SRB_Status == SS_COMP) &&
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
543 (srbDiskInfo.SRB_Int13HDriveInfo == c_drive) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
544 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
545 /* Make sure this is a cdrom device */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
546 struct SRB_GDEVBlock srbGDEVBlock;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
547
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
548 memset( &srbGDEVBlock, 0, sizeof(struct SRB_GDEVBlock) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
549 srbGDEVBlock.SRB_Cmd = SC_GET_DEV_TYPE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
550 srbGDEVBlock.SRB_HaId = i;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
551 srbGDEVBlock.SRB_Target = j;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
552
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
553 lpSendCommand( (void*) &srbGDEVBlock );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
554
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
555 if( ( srbGDEVBlock.SRB_Status == SS_COMP ) &&
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
556 ( srbGDEVBlock.SRB_DeviceType == DTYPE_CDROM ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
557 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
558 fd->i_sid = MAKEWORD( i, j );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
559 dvdcss->i_fd = (int) fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
560 dvdcss->i_pos = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
561 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
562 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
563 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
564 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
565 free( (void*) fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
566 FreeLibrary( hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
567 print_error( dvdcss,"this is not a cdrom drive" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
568 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
569 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
570 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
571 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
572 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
573
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
574 free( (void*) fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
575 FreeLibrary( hASPI );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
576 print_error( dvdcss, "unable to get haid and target (aspi)" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
577 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
578 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
579 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
580
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
581 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
582 * Seek commands.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
583 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
584 static int libc_seek( dvdcss_t dvdcss, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
585 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
586 off_t i_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
587
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
588 if( dvdcss->i_pos == i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
589 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
590 /* We are already in position */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
591 return i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
592 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
593
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
594 i_seek = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
20730
66c2f233ccff Fix linking on Cygwin and remove nonsense lseek64 --> lseek indirection,
diego
parents: 20613
diff changeset
595 i_seek = lseek( dvdcss->i_read_fd, i_seek, SEEK_SET );
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
596
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
597 if( i_seek < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
598 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
599 print_error( dvdcss, "seek error" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
600 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
601 return i_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
602 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
603
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
604 dvdcss->i_pos = i_seek / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
605
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
606 return dvdcss->i_pos;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
607 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
608
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
609 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
610 static int win2k_seek( dvdcss_t dvdcss, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
611 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
612 LARGE_INTEGER li_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
614 #ifndef INVALID_SET_FILE_POINTER
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
615 # define INVALID_SET_FILE_POINTER ((DWORD)-1)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
616 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
617
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
618 if( dvdcss->i_pos == i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
619 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
620 /* We are already in position */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
621 return i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
622 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
623
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
624 li_seek.QuadPart = (LONGLONG)i_blocks * DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
625
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
626 li_seek.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
627 li_seek.LowPart,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
628 &li_seek.HighPart, FILE_BEGIN );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
629 if( (li_seek.LowPart == INVALID_SET_FILE_POINTER)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
630 && GetLastError() != NO_ERROR)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
631 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
632 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
633 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
634 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
635
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
636 dvdcss->i_pos = li_seek.QuadPart / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
637
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
638 return dvdcss->i_pos;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
639 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
640
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
641 static int aspi_seek( dvdcss_t dvdcss, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
642 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
643 int i_old_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
644 char sz_buf[ DVDCSS_BLOCK_SIZE ];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
645 struct w32_aspidev *fd = (struct w32_aspidev *) dvdcss->i_fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
646
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
647 if( dvdcss->i_pos == i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
648 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
649 /* We are already in position */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
650 return i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
651 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
652
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
653 i_old_blocks = fd->i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
654 fd->i_blocks = i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
655
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
656 if( aspi_read_internal( dvdcss->i_fd, sz_buf, 1 ) == -1 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
657 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
658 fd->i_blocks = i_old_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
659 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
660 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
661 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
662
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
663 (fd->i_blocks)--;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
664
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
665 dvdcss->i_pos = fd->i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
666
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
667 return dvdcss->i_pos;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
668 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
669 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
670
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
671 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
672 * Read commands.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
673 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
674 static int libc_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
675 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
676 off_t i_size, i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
677
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
678 i_size = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
679 i_ret = read( dvdcss->i_read_fd, p_buffer, i_size );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
680
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
681 if( i_ret < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
682 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
683 print_error( dvdcss, "read error" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
684 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
685 return i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
686 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
687
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
688 /* Handle partial reads */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
689 if( i_ret != i_size )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
690 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
691 int i_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
692
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
693 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
694 i_seek = libc_seek( dvdcss, i_ret / DVDCSS_BLOCK_SIZE );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
695 if( i_seek < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
696 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
697 return i_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
698 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
699
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
700 /* We have to return now so that i_pos isn't clobbered */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
701 return i_ret / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
702 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
703
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
704 dvdcss->i_pos += i_ret / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
705 return i_ret / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
706 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
707
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
708 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
709 static int win2k_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
710 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
711 int i_bytes;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
712
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
713 if( !ReadFile( (HANDLE) dvdcss->i_fd, p_buffer,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
714 i_blocks * DVDCSS_BLOCK_SIZE,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
715 (LPDWORD)&i_bytes, NULL ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
716 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
717 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
718 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
719 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
720
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
721 dvdcss->i_pos += i_bytes / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
722 return i_bytes / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
723 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
724
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
725 static int aspi_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
726 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
727 int i_read = aspi_read_internal( dvdcss->i_fd, p_buffer, i_blocks );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
728
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
729 if( i_read < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
730 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
731 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
732 return i_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
733 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
734
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
735 dvdcss->i_pos += i_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
736 return i_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
737 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
738 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
739
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
740 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
741 * Readv commands.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
742 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
743 static int libc_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
744 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
745 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
746 int i_index, i_len, i_total = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
747 unsigned char *p_base;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
748 int i_bytes;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
749
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
750 for( i_index = i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
751 i_index;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
752 i_index--, p_iovec++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
753 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
754 i_len = p_iovec->iov_len;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
755 p_base = p_iovec->iov_base;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
756
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
757 if( i_len <= 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
758 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
759 continue;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
760 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
761
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
762 i_bytes = read( dvdcss->i_fd, p_base, i_len );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
763
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
764 if( i_bytes < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
765 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
766 /* One of the reads failed, too bad.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
767 * We won't even bother returning the reads that went ok,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
768 * and as in the posix spec the file postition is left
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
769 * unspecified after a failure */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
770 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
771 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
772 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
773
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
774 i_total += i_bytes;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
775
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
776 if( i_bytes != i_len )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
777 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
778 /* We reached the end of the file or a signal interrupted
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
779 * the read. Return a partial read. */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
780 int i_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
781
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
782 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
783 i_seek = libc_seek( dvdcss, i_total / DVDCSS_BLOCK_SIZE );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
784 if( i_seek < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
785 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
786 return i_seek;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
787 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
788
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
789 /* We have to return now so that i_pos isn't clobbered */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
790 return i_total / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
791 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
792 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
793
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
794 dvdcss->i_pos += i_total / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
795 return i_total / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
796 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
797 int i_read = readv( dvdcss->i_read_fd, p_iovec, i_blocks );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
798
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
799 if( i_read < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
800 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
801 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
802 return i_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
803 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
804
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
805 dvdcss->i_pos += i_read / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
806 return i_read / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
807 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
808 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
809
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
810 #if defined( WIN32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
811 /*****************************************************************************
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
812 * win_readv: vectored read using ReadFile for Win2K and ASPI for win9x
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
813 *****************************************************************************/
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
814 static int win_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
815 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
816 int i_index;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
817 int i_blocks_read, i_blocks_total = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
818
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
819 /* Check the size of the readv temp buffer, just in case we need to
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
820 * realloc something bigger */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
821 if( dvdcss->i_readv_buf_size < i_blocks * DVDCSS_BLOCK_SIZE )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
822 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
823 dvdcss->i_readv_buf_size = i_blocks * DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
824
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
825 if( dvdcss->p_readv_buffer ) free( dvdcss->p_readv_buffer );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
826
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
827 /* Allocate a buffer which will be used as a temporary storage
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
828 * for readv */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
829 dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
830 if( !dvdcss->p_readv_buffer )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
831 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
832 print_error( dvdcss, " failed (readv)" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
833 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
834 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
835 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
836 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
837
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
838 for( i_index = i_blocks; i_index; i_index-- )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
839 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
840 i_blocks_total += p_iovec[i_index-1].iov_len;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
841 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
842
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
843 if( i_blocks_total <= 0 ) return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
844
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
845 i_blocks_total /= DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
846
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
847 if( WIN2K )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
848 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
849 unsigned long int i_bytes;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
850 if( !ReadFile( (HANDLE)dvdcss->i_fd, dvdcss->p_readv_buffer,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
851 i_blocks_total * DVDCSS_BLOCK_SIZE, &i_bytes, NULL ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
852 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
853 /* The read failed... too bad.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
854 * As in the posix spec the file postition is left
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
855 * unspecified after a failure */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
856 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
857 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
858 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
859 i_blocks_read = i_bytes / DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
860 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
861 else /* Win9x */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
862 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
863 i_blocks_read = aspi_read_internal( dvdcss->i_fd,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
864 dvdcss->p_readv_buffer,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
865 i_blocks_total );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
866 if( i_blocks_read < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
867 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
868 /* See above */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
869 dvdcss->i_pos = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
870 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
871 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
872 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
873
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
874 /* We just have to copy the content of the temp buffer into the iovecs */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
875 for( i_index = 0, i_blocks_total = i_blocks_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
876 i_blocks_total > 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
877 i_index++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
878 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
879 memcpy( p_iovec[i_index].iov_base,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
880 dvdcss->p_readv_buffer + (i_blocks_read - i_blocks_total)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
881 * DVDCSS_BLOCK_SIZE,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
882 p_iovec[i_index].iov_len );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
883 /* if we read less blocks than asked, we'll just end up copying
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
884 * garbage, this isn't an issue as we return the number of
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
885 * blocks actually read */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
886 i_blocks_total -= ( p_iovec[i_index].iov_len / DVDCSS_BLOCK_SIZE );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
887 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
888
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
889 dvdcss->i_pos += i_blocks_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
890 return i_blocks_read;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
891 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
892
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
893 static int aspi_read_internal( int i_fd, void *p_data, int i_blocks )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
894 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
895 HANDLE hEvent;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
896 struct SRB_ExecSCSICmd ssc;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
897 struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
898
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
899 /* Create the transfer completion event */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
900 hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
901 if( hEvent == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
902 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
903 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
904 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
905
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
906 memset( &ssc, 0, sizeof( ssc ) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
907
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
908 ssc.SRB_Cmd = SC_EXEC_SCSI_CMD;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
909 ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
910 ssc.SRB_HaId = LOBYTE( fd->i_sid );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
911 ssc.SRB_Target = HIBYTE( fd->i_sid );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
912 ssc.SRB_SenseLen = SENSE_LEN;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
913
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
914 ssc.SRB_PostProc = (LPVOID) hEvent;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
915 ssc.SRB_BufPointer = p_data;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
916 ssc.SRB_CDBLen = 12;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
917
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
918 ssc.CDBByte[0] = 0xA8; /* RAW */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
919 ssc.CDBByte[2] = (UCHAR) (fd->i_blocks >> 24);
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
920 ssc.CDBByte[3] = (UCHAR) (fd->i_blocks >> 16) & 0xff;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
921 ssc.CDBByte[4] = (UCHAR) (fd->i_blocks >> 8) & 0xff;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
922 ssc.CDBByte[5] = (UCHAR) (fd->i_blocks) & 0xff;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
923
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
924 /* We have to break down the reads into 64kb pieces (ASPI restriction) */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
925 if( i_blocks > 32 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
926 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
927 ssc.SRB_BufLen = 32 * DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
928 ssc.CDBByte[9] = 32;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
929 fd->i_blocks += 32;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
930
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
931 /* Initiate transfer */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
932 ResetEvent( hEvent );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
933 fd->lpSendCommand( (void*) &ssc );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
934
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
935 /* transfer the next 64kb (aspi_read_internal is called recursively)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
936 * We need to check the status of the read on return */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
937 if( aspi_read_internal( i_fd,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
938 (uint8_t*) p_data + 32 * DVDCSS_BLOCK_SIZE,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
939 i_blocks - 32) < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
940 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
941 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
942 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
943 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
944 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
945 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
946 /* This is the last transfer */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
947 ssc.SRB_BufLen = i_blocks * DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
948 ssc.CDBByte[9] = (UCHAR) i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
949 fd->i_blocks += i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
950
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
951 /* Initiate transfer */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
952 ResetEvent( hEvent );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
953 fd->lpSendCommand( (void*) &ssc );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
954
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
955 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
956
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
957 /* If the command has still not been processed, wait until it's finished */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
958 if( ssc.SRB_Status == SS_PENDING )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
959 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
960 WaitForSingleObject( hEvent, INFINITE );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
961 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
962 CloseHandle( hEvent );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
963
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
964 /* check that the transfer went as planned */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
965 if( ssc.SRB_Status != SS_COMP )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
966 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
967 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
968 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
969
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
970 return i_blocks;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
971 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
972 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
973