annotate libdvdcss/device.c @ 36837:4f59b1b06cf2

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