annotate libdvdcss/device.c @ 33201:70a2195b4904

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