shithub: libdvdcss

Download patch

ref: 068c36acd9849d770f1a263f06b6aa3d88fa176d
parent: 3e4c0bab24070a6ff4ae03dce631d74bc3a32133
author: Sam Hocevar <[email protected]>
date: Fri Aug 9 10:10:43 EDT 2002

* ./src/css.c: when the ReadTitleKey ioctl failed, reopen the device before
    falling back to the title method.

   Note: on my drive, this fixes the "ioctl_ReadTitleKey failed" error
         many users have been reporting. Please test!

   Note 2: I could not find any other way to reset the drive after a failed
           ReadTitleKey ioctl than closing and opening the device again. If
           I don't do that, read() fails with an Input/output error after a
           while (but not immediately).

  * ALL: libdvdcss builds with -ansi -pedantic. Yeah I like that :-)
  * ./src/css.c: renamed a few functions so that they make more sense, added
    debug messages here and there, fixed typos and speling.
  * ./src/error.c: moved _dvdcss_error and _dvdcss_debug here.
  * ./src/device.c: moved device reading functions from libdvdcss.c to here.
  * ./src/device.c: errors from dvdcss_read are now properly handled; partial
    reads still aren't though.
  * ./src/libdvdcss.c: default verbosity is now 0, a library should not be
    intrusive by default.
  * ./test/csstest.c: additional error check.
  * ./configure.in: removed the crap boolean_t detection.


--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -69,6 +69,7 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_LIB = @EXTRA_LIB@
+EXTRA_SOURCES = @EXTRA_SOURCES@
 LIBTOOL = @LIBTOOL@
 LN_S = @LN_S@
 MAKEINFO = @MAKEINFO@
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,4 +1,4 @@
-dnl aclocal.m4 generated automatically by aclocal 1.4-p5
+dnl aclocal.m4 generated automatically by aclocal 1.4-p6
 
 dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
@@ -20,7 +20,8 @@
 dnl AM_INIT_AUTOMAKE(package,version, [no-define])
 
 AC_DEFUN([AM_INIT_AUTOMAKE],
-[AC_REQUIRE([AC_PROG_INSTALL])
+[AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])
 PACKAGE=[$1]
 AC_SUBST(PACKAGE)
 VERSION=[$2]
@@ -36,12 +37,41 @@
 AC_REQUIRE([AC_ARG_PROGRAM])
 dnl FIXME This is truly gross.
 missing_dir=`cd $ac_aux_dir && pwd`
-AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}, $missing_dir)
 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
-AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}, $missing_dir)
 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
 AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
 AC_REQUIRE([AC_PROG_MAKE_SET])])
+
+# Copyright 2002  Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+AC_DEFUN([AM_AUTOMAKE_VERSION],[am__api_version="1.4"])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION so it can be traced.
+# This function is AC_REQUIREd by AC_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+	 [AM_AUTOMAKE_VERSION([1.4-p6])])
 
 #
 # Check to make sure that the build environment is sane.
--- a/configure
+++ b/configure
@@ -802,6 +802,7 @@
   program_prefix=${target_alias}-
 
 
+am__api_version="1.4"
 # Find a good install program.  We prefer a C program (faster),
 # so one script is as good as another.  But avoid the broken or
 # incompatible versions:
@@ -814,7 +815,7 @@
 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
 # ./install, which can be erroneously created by make from ./install.sh.
 echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:818: checking for a BSD compatible install" >&5
+echo "configure:819: checking for a BSD compatible install" >&5
 if test -z "$INSTALL"; then
 if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -867,7 +868,7 @@
 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 
 echo $ac_n "checking whether build environment is sane""... $ac_c" 1>&6
-echo "configure:871: checking whether build environment is sane" >&5
+echo "configure:872: checking whether build environment is sane" >&5
 # Just in case
 sleep 1
 echo timestamp > conftestfile
@@ -924,7 +925,7 @@
 test "$program_transform_name" = "" && program_transform_name="s,x,x,"
 
 echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
-echo "configure:928: checking whether ${MAKE-make} sets \${MAKE}" >&5
+echo "configure:929: checking whether ${MAKE-make} sets \${MAKE}" >&5
 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -969,21 +970,21 @@
 
 
 missing_dir=`cd $ac_aux_dir && pwd`
-echo $ac_n "checking for working aclocal""... $ac_c" 1>&6
-echo "configure:974: checking for working aclocal" >&5
+echo $ac_n "checking for working aclocal-${am__api_version}""... $ac_c" 1>&6
+echo "configure:975: checking for working aclocal-${am__api_version}" >&5
 # Run test in a subshell; some versions of sh will print an error if
 # an executable is not found, even if stderr is redirected.
 # Redirect stdin to placate older versions of autoconf.  Sigh.
-if (aclocal --version) < /dev/null > /dev/null 2>&1; then
-   ACLOCAL=aclocal
+if (aclocal-${am__api_version} --version) < /dev/null > /dev/null 2>&1; then
+   ACLOCAL=aclocal-${am__api_version}
    echo "$ac_t""found" 1>&6
 else
-   ACLOCAL="$missing_dir/missing aclocal"
+   ACLOCAL="$missing_dir/missing aclocal-${am__api_version}"
    echo "$ac_t""missing" 1>&6
 fi
 
 echo $ac_n "checking for working autoconf""... $ac_c" 1>&6
-echo "configure:987: checking for working autoconf" >&5
+echo "configure:988: checking for working autoconf" >&5
 # Run test in a subshell; some versions of sh will print an error if
 # an executable is not found, even if stderr is redirected.
 # Redirect stdin to placate older versions of autoconf.  Sigh.
@@ -995,21 +996,21 @@
    echo "$ac_t""missing" 1>&6
 fi
 
-echo $ac_n "checking for working automake""... $ac_c" 1>&6
-echo "configure:1000: checking for working automake" >&5
+echo $ac_n "checking for working automake-${am__api_version}""... $ac_c" 1>&6
+echo "configure:1001: checking for working automake-${am__api_version}" >&5
 # Run test in a subshell; some versions of sh will print an error if
 # an executable is not found, even if stderr is redirected.
 # Redirect stdin to placate older versions of autoconf.  Sigh.
-if (automake --version) < /dev/null > /dev/null 2>&1; then
-   AUTOMAKE=automake
+if (automake-${am__api_version} --version) < /dev/null > /dev/null 2>&1; then
+   AUTOMAKE=automake-${am__api_version}
    echo "$ac_t""found" 1>&6
 else
-   AUTOMAKE="$missing_dir/missing automake"
+   AUTOMAKE="$missing_dir/missing automake-${am__api_version}"
    echo "$ac_t""missing" 1>&6
 fi
 
 echo $ac_n "checking for working autoheader""... $ac_c" 1>&6
-echo "configure:1013: checking for working autoheader" >&5
+echo "configure:1014: checking for working autoheader" >&5
 # Run test in a subshell; some versions of sh will print an error if
 # an executable is not found, even if stderr is redirected.
 # Redirect stdin to placate older versions of autoconf.  Sigh.
@@ -1022,7 +1023,7 @@
 fi
 
 echo $ac_n "checking for working makeinfo""... $ac_c" 1>&6
-echo "configure:1026: checking for working makeinfo" >&5
+echo "configure:1027: checking for working makeinfo" >&5
 # Run test in a subshell; some versions of sh will print an error if
 # an executable is not found, even if stderr is redirected.
 # Redirect stdin to placate older versions of autoconf.  Sigh.
@@ -1042,7 +1043,7 @@
 # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1046: checking for $ac_word" >&5
+echo "configure:1047: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1072,7 +1073,7 @@
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1076: checking for $ac_word" >&5
+echo "configure:1077: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1123,7 +1124,7 @@
       # Extract the first word of "cl", so it can be a program name with args.
 set dummy cl; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1127: checking for $ac_word" >&5
+echo "configure:1128: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1155,7 +1156,7 @@
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:1159: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:1160: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -1166,12 +1167,12 @@
 
 cat > conftest.$ac_ext << EOF
 
-#line 1170 "configure"
+#line 1171 "configure"
 #include "confdefs.h"
 
 main(){return(0);}
 EOF
-if { (eval echo configure:1175: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1176: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
@@ -1197,12 +1198,12 @@
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:1201: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:1202: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:1206: checking whether we are using GNU C" >&5
+echo "configure:1207: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1211,7 +1212,7 @@
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1215: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1216: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
@@ -1230,7 +1231,7 @@
 ac_save_CFLAGS="$CFLAGS"
 CFLAGS=
 echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:1234: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:1235: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1262,7 +1263,7 @@
 fi
 
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:1266: checking how to run the C preprocessor" >&5
+echo "configure:1267: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
@@ -1277,13 +1278,13 @@
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 1281 "configure"
+#line 1282 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1287: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1288: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1294,13 +1295,13 @@
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 1298 "configure"
+#line 1299 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1304: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1305: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1311,13 +1312,13 @@
   rm -rf conftest*
   CPP="${CC-cc} -nologo -E"
   cat > conftest.$ac_ext <<EOF
-#line 1315 "configure"
+#line 1316 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1321: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1322: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1342,12 +1343,12 @@
 echo "$ac_t""$CPP" 1>&6
 
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:1346: checking for ANSI C header files" >&5
+echo "configure:1347: checking for ANSI C header files" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1351 "configure"
+#line 1352 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdarg.h>
@@ -1355,7 +1356,7 @@
 #include <float.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1359: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1360: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1372,7 +1373,7 @@
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1376 "configure"
+#line 1377 "configure"
 #include "confdefs.h"
 #include <string.h>
 EOF
@@ -1390,7 +1391,7 @@
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1394 "configure"
+#line 1395 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 EOF
@@ -1411,7 +1412,7 @@
   :
 else
   cat > conftest.$ac_ext <<EOF
-#line 1415 "configure"
+#line 1416 "configure"
 #include "confdefs.h"
 #include <ctype.h>
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
@@ -1422,7 +1423,7 @@
 exit (0); }
 
 EOF
-if { (eval echo configure:1426: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1427: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   :
 else
@@ -1458,12 +1459,12 @@
 fi
 
 echo $ac_n "checking for Cygwin environment""... $ac_c" 1>&6
-echo "configure:1462: checking for Cygwin environment" >&5
+echo "configure:1463: checking for Cygwin environment" >&5
 if eval "test \"`echo '$''{'ac_cv_cygwin'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1467 "configure"
+#line 1468 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -1474,7 +1475,7 @@
 return __CYGWIN__;
 ; return 0; }
 EOF
-if { (eval echo configure:1478: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1479: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_cygwin=yes
 else
@@ -1491,12 +1492,12 @@
 CYGWIN=
 test "$ac_cv_cygwin" = yes && CYGWIN=yes
 echo $ac_n "checking for mingw32 environment""... $ac_c" 1>&6
-echo "configure:1495: checking for mingw32 environment" >&5
+echo "configure:1496: checking for mingw32 environment" >&5
 if eval "test \"`echo '$''{'ac_cv_mingw32'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1500 "configure"
+#line 1501 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -1503,7 +1504,7 @@
 return __MINGW32__;
 ; return 0; }
 EOF
-if { (eval echo configure:1507: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1508: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_mingw32=yes
 else
@@ -1600,7 +1601,7 @@
 if test "$GCC" = yes; then
   # Check if gcc -print-prog-name=ld gives a path.
   echo $ac_n "checking for ld used by GCC""... $ac_c" 1>&6
-echo "configure:1604: checking for ld used by GCC" >&5
+echo "configure:1605: checking for ld used by GCC" >&5
   case $host in
   *-*-mingw*)
     # gcc leaves a trailing carriage return which upsets mingw
@@ -1630,10 +1631,10 @@
   esac
 elif test "$with_gnu_ld" = yes; then
   echo $ac_n "checking for GNU ld""... $ac_c" 1>&6
-echo "configure:1634: checking for GNU ld" >&5
+echo "configure:1635: checking for GNU ld" >&5
 else
   echo $ac_n "checking for non-GNU ld""... $ac_c" 1>&6
-echo "configure:1637: checking for non-GNU ld" >&5
+echo "configure:1638: checking for non-GNU ld" >&5
 fi
 if eval "test \"`echo '$''{'lt_cv_path_LD'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1668,7 +1669,7 @@
 fi
 test -z "$LD" && { echo "configure: error: no acceptable ld found in \$PATH" 1>&2; exit 1; }
 echo $ac_n "checking if the linker ($LD) is GNU ld""... $ac_c" 1>&6
-echo "configure:1672: checking if the linker ($LD) is GNU ld" >&5
+echo "configure:1673: checking if the linker ($LD) is GNU ld" >&5
 if eval "test \"`echo '$''{'lt_cv_prog_gnu_ld'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1685,7 +1686,7 @@
 
 
 echo $ac_n "checking for $LD option to reload object files""... $ac_c" 1>&6
-echo "configure:1689: checking for $LD option to reload object files" >&5
+echo "configure:1690: checking for $LD option to reload object files" >&5
 if eval "test \"`echo '$''{'lt_cv_ld_reload_flag'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1697,7 +1698,7 @@
 test -n "$reload_flag" && reload_flag=" $reload_flag"
 
 echo $ac_n "checking for BSD-compatible nm""... $ac_c" 1>&6
-echo "configure:1701: checking for BSD-compatible nm" >&5
+echo "configure:1702: checking for BSD-compatible nm" >&5
 if eval "test \"`echo '$''{'lt_cv_path_NM'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1735,7 +1736,7 @@
 echo "$ac_t""$NM" 1>&6
 
 echo $ac_n "checking for a sed that does not truncate output""... $ac_c" 1>&6
-echo "configure:1739: checking for a sed that does not truncate output" >&5
+echo "configure:1740: checking for a sed that does not truncate output" >&5
 if eval "test \"`echo '$''{'lt_cv_path_SED'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1819,7 +1820,7 @@
 echo "$ac_t""$SED" 1>&6
 
 echo $ac_n "checking whether ln -s works""... $ac_c" 1>&6
-echo "configure:1823: checking whether ln -s works" >&5
+echo "configure:1824: checking whether ln -s works" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_LN_S'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1840,7 +1841,7 @@
 fi
 
 echo $ac_n "checking how to recognise dependent libraries""... $ac_c" 1>&6
-echo "configure:1844: checking how to recognise dependent libraries" >&5
+echo "configure:1845: checking how to recognise dependent libraries" >&5
 if eval "test \"`echo '$''{'lt_cv_deplibs_check_method'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2026,13 +2027,13 @@
 deplibs_check_method=$lt_cv_deplibs_check_method
 
 echo $ac_n "checking for object suffix""... $ac_c" 1>&6
-echo "configure:2030: checking for object suffix" >&5
+echo "configure:2031: checking for object suffix" >&5
 if eval "test \"`echo '$''{'ac_cv_objext'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   rm -f conftest*
 echo 'int i = 1;' > conftest.$ac_ext
-if { (eval echo configure:2036: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2037: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   for ac_file in conftest.*; do
     case $ac_file in
     *.c) ;;
@@ -2052,7 +2053,7 @@
 
 
 echo $ac_n "checking for executable suffix""... $ac_c" 1>&6
-echo "configure:2056: checking for executable suffix" >&5
+echo "configure:2057: checking for executable suffix" >&5
 if eval "test \"`echo '$''{'ac_cv_exeext'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2062,7 +2063,7 @@
   rm -f conftest*
   echo 'int main () { return 0; }' > conftest.$ac_ext
   ac_cv_exeext=
-  if { (eval echo configure:2066: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
+  if { (eval echo configure:2067: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
     for file in conftest.*; do
       case $file in
       *.$ac_ext | *.c | *.o | *.obj) ;;
@@ -2093,7 +2094,7 @@
 
 # Check for command to grab the raw symbol name followed by C symbol from nm.
 echo $ac_n "checking command to parse $NM output""... $ac_c" 1>&6
-echo "configure:2097: checking command to parse $NM output" >&5
+echo "configure:2098: checking command to parse $NM output" >&5
 if eval "test \"`echo '$''{'lt_cv_sys_global_symbol_pipe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2173,10 +2174,10 @@
 int main(){nm_test_var='a';nm_test_func();return(0);}
 EOF
 
-  if { (eval echo configure:2177: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  if { (eval echo configure:2178: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
     # Now try to grab the symbols.
     nlist=conftest.nm
-    if { (eval echo configure:2180: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\") 1>&5; (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5; } && test -s "$nlist"; then
+    if { (eval echo configure:2181: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\") 1>&5; (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5; } && test -s "$nlist"; then
       # Try sorting and uniquifying the output.
       if sort "$nlist" | uniq > "$nlist"T; then
 	mv -f "$nlist"T "$nlist"
@@ -2227,7 +2228,7 @@
 	  save_CFLAGS="$CFLAGS"
 	  LIBS="conftstm.$ac_objext"
 	  CFLAGS="$CFLAGS$no_builtin_flag"
-	  if { (eval echo configure:2231: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+	  if { (eval echo configure:2232: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
 	    pipe_works=yes
 	  fi
 	  LIBS="$save_LIBS"
@@ -2276,17 +2277,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:2280: checking for $ac_hdr" >&5
+echo "configure:2281: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2285 "configure"
+#line 2286 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2290: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2291: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2322,7 +2323,7 @@
 file_magic*)
   if test "$file_magic_cmd" = '$MAGIC_CMD'; then
     echo $ac_n "checking for ${ac_tool_prefix}file""... $ac_c" 1>&6
-echo "configure:2326: checking for ${ac_tool_prefix}file" >&5
+echo "configure:2327: checking for ${ac_tool_prefix}file" >&5
 if eval "test \"`echo '$''{'lt_cv_path_MAGIC_CMD'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2384,7 +2385,7 @@
 if test -z "$lt_cv_path_MAGIC_CMD"; then
   if test -n "$ac_tool_prefix"; then
     echo $ac_n "checking for file""... $ac_c" 1>&6
-echo "configure:2388: checking for file" >&5
+echo "configure:2389: checking for file" >&5
 if eval "test \"`echo '$''{'lt_cv_path_MAGIC_CMD'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2455,7 +2456,7 @@
 # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
 set dummy ${ac_tool_prefix}ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2459: checking for $ac_word" >&5
+echo "configure:2460: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2487,7 +2488,7 @@
   # Extract the first word of "ranlib", so it can be a program name with args.
 set dummy ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2491: checking for $ac_word" >&5
+echo "configure:2492: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2522,7 +2523,7 @@
 # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
 set dummy ${ac_tool_prefix}strip; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2526: checking for $ac_word" >&5
+echo "configure:2527: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_STRIP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2554,7 +2555,7 @@
   # Extract the first word of "strip", so it can be a program name with args.
 set dummy strip; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2558: checking for $ac_word" >&5
+echo "configure:2559: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_STRIP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2603,8 +2604,8 @@
 case $host in
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 2607 "configure"' > conftest.$ac_ext
-  if { (eval echo configure:2608: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  echo '#line 2608 "configure"' > conftest.$ac_ext
+  if { (eval echo configure:2609: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
     case `/usr/bin/file conftest.$ac_objext` in
     *32-bit*)
       LD="${LD-ld} -32"
@@ -2625,7 +2626,7 @@
   SAVE_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS -belf"
   echo $ac_n "checking whether the C compiler needs -belf""... $ac_c" 1>&6
-echo "configure:2629: checking whether the C compiler needs -belf" >&5
+echo "configure:2630: checking whether the C compiler needs -belf" >&5
 if eval "test \"`echo '$''{'lt_cv_cc_needs_belf'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2638,7 +2639,7 @@
 cross_compiling=$ac_cv_prog_cc_cross
 
      cat > conftest.$ac_ext <<EOF
-#line 2642 "configure"
+#line 2643 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -2645,7 +2646,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:2649: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2650: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   lt_cv_cc_needs_belf=yes
 else
@@ -2765,7 +2766,7 @@
 compiler="$2"
 
 echo $ac_n "checking for objdir""... $ac_c" 1>&6
-echo "configure:2769: checking for objdir" >&5
+echo "configure:2770: checking for objdir" >&5
 rm -f .libs 2>/dev/null
 mkdir .libs 2>/dev/null
 if test -d .libs; then
@@ -2792,7 +2793,7 @@
 # in isolation, and that seeing it set (from the cache) indicates that
 # the associated values are set (in the cache) correctly too.
 echo $ac_n "checking for $compiler option to produce PIC""... $ac_c" 1>&6
-echo "configure:2796: checking for $compiler option to produce PIC" >&5
+echo "configure:2797: checking for $compiler option to produce PIC" >&5
 if eval "test \"`echo '$''{'lt_cv_prog_cc_pic'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2940,7 +2941,7 @@
 
   # Check to make sure the pic_flag actually works.
   echo $ac_n "checking if $compiler PIC flag $lt_cv_prog_cc_pic works""... $ac_c" 1>&6
-echo "configure:2944: checking if $compiler PIC flag $lt_cv_prog_cc_pic works" >&5
+echo "configure:2945: checking if $compiler PIC flag $lt_cv_prog_cc_pic works" >&5
   if eval "test \"`echo '$''{'lt_cv_prog_cc_pic_works'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2947,7 +2948,7 @@
       save_CFLAGS="$CFLAGS"
     CFLAGS="$CFLAGS $lt_cv_prog_cc_pic -DPIC"
     cat > conftest.$ac_ext <<EOF
-#line 2951 "configure"
+#line 2952 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -2954,7 +2955,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:2958: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2959: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
         case $host_os in
       hpux9* | hpux10* | hpux11*)
@@ -3006,7 +3007,7 @@
 fi
 
 echo $ac_n "checking if $compiler static flag $lt_cv_prog_cc_static works""... $ac_c" 1>&6
-echo "configure:3010: checking if $compiler static flag $lt_cv_prog_cc_static works" >&5
+echo "configure:3011: checking if $compiler static flag $lt_cv_prog_cc_static works" >&5
 if eval "test \"`echo '$''{'lt_cv_prog_cc_static_works'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3014,7 +3015,7 @@
   save_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS $lt_cv_prog_cc_static"
   cat > conftest.$ac_ext <<EOF
-#line 3018 "configure"
+#line 3019 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -3021,7 +3022,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:3025: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3026: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   lt_cv_prog_cc_static_works=yes
 else
@@ -3048,7 +3049,7 @@
 
 # Check to see if options -o and -c are simultaneously supported by compiler
 echo $ac_n "checking if $compiler supports -c -o file.$ac_objext""... $ac_c" 1>&6
-echo "configure:3052: checking if $compiler supports -c -o file.$ac_objext" >&5
+echo "configure:3053: checking if $compiler supports -c -o file.$ac_objext" >&5
 if eval "test \"`echo '$''{'lt_cv_compiler_c_o'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3067,7 +3068,7 @@
 save_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -o out/conftest2.$ac_objext"
 compiler_c_o=no
-if { (eval echo configure:3071: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then
+if { (eval echo configure:3072: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then
   # The compiler can only warn and ignore the option if not recognized
   # So say no if there are warnings
   if test -s out/conftest.err; then
@@ -3096,7 +3097,7 @@
 if test x"$compiler_c_o" = x"yes"; then
   # Check to see if we can write to a .lo
   echo $ac_n "checking if $compiler supports -c -o file.lo""... $ac_c" 1>&6
-echo "configure:3100: checking if $compiler supports -c -o file.lo" >&5
+echo "configure:3101: checking if $compiler supports -c -o file.lo" >&5
   if eval "test \"`echo '$''{'lt_cv_compiler_o_lo'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3107,7 +3108,7 @@
   save_objext="$ac_objext"
   ac_objext=lo
   cat > conftest.$ac_ext <<EOF
-#line 3111 "configure"
+#line 3112 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -3114,7 +3115,7 @@
 int some_variable = 0;
 ; return 0; }
 EOF
-if { (eval echo configure:3118: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3119: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
       # The compiler can only warn and ignore the option if not recognized
     # So say no if there are warnings
@@ -3145,7 +3146,7 @@
 if test "$compiler_c_o" = no && test "$need_locks" != no; then
   # do not overwrite the value of need_locks provided by the user
   echo $ac_n "checking if we can lock with hard links""... $ac_c" 1>&6
-echo "configure:3149: checking if we can lock with hard links" >&5
+echo "configure:3150: checking if we can lock with hard links" >&5
   hard_links=yes
   $rm conftest*
   ln conftest.a conftest.b 2>/dev/null && hard_links=no
@@ -3164,13 +3165,13 @@
 if test "$GCC" = yes; then
   # Check to see if options -fno-rtti -fno-exceptions are supported by compiler
   echo $ac_n "checking if $compiler supports -fno-rtti -fno-exceptions""... $ac_c" 1>&6
-echo "configure:3168: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
+echo "configure:3169: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
   echo "int some_variable = 0;" > conftest.$ac_ext
   save_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -c conftest.$ac_ext"
   compiler_rtti_exceptions=no
   cat > conftest.$ac_ext <<EOF
-#line 3174 "configure"
+#line 3175 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -3177,7 +3178,7 @@
 int some_variable = 0;
 ; return 0; }
 EOF
-if { (eval echo configure:3181: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3182: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
       # The compiler can only warn and ignore the option if not recognized
     # So say no if there are warnings
@@ -3204,7 +3205,7 @@
 
 # See if the linker supports building shared libraries.
 echo $ac_n "checking whether the linker ($LD) supports shared libraries""... $ac_c" 1>&6
-echo "configure:3208: checking whether the linker ($LD) supports shared libraries" >&5
+echo "configure:3209: checking whether the linker ($LD) supports shared libraries" >&5
 
 allow_undefined_flag=
 no_undefined_flag=
@@ -3900,7 +3901,7 @@
 
 # Check hardcoding attributes.
 echo $ac_n "checking how to hardcode library paths into programs""... $ac_c" 1>&6
-echo "configure:3904: checking how to hardcode library paths into programs" >&5
+echo "configure:3905: checking how to hardcode library paths into programs" >&5
 hardcode_action=
 if test -n "$hardcode_libdir_flag_spec" || \
    test -n "$runpath_var"; then
@@ -3928,7 +3929,7 @@
 striplib=
 old_striplib=
 echo $ac_n "checking whether stripping libraries is possible""... $ac_c" 1>&6
-echo "configure:3932: checking whether stripping libraries is possible" >&5
+echo "configure:3933: checking whether stripping libraries is possible" >&5
 if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then
   test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
   test -z "$striplib" && striplib="$STRIP --strip-unneeded"
@@ -3942,7 +3943,7 @@
 
 # PORTME Fill in your ld.so characteristics
 echo $ac_n "checking dynamic linker characteristics""... $ac_c" 1>&6
-echo "configure:3946: checking dynamic linker characteristics" >&5
+echo "configure:3947: checking dynamic linker characteristics" >&5
 library_names_spec=
 libname_spec='lib$name'
 soname_spec=
@@ -4348,11 +4349,11 @@
 
 # Report the final consequences.
 echo $ac_n "checking if libtool supports shared libraries""... $ac_c" 1>&6
-echo "configure:4352: checking if libtool supports shared libraries" >&5
+echo "configure:4353: checking if libtool supports shared libraries" >&5
 echo "$ac_t""$can_build_shared" 1>&6
 
 echo $ac_n "checking whether to build shared libraries""... $ac_c" 1>&6
-echo "configure:4356: checking whether to build shared libraries" >&5
+echo "configure:4357: checking whether to build shared libraries" >&5
 test "$can_build_shared" = "no" && enable_shared=no
 
 # On AIX, shared libraries and static libraries use the same namespace, and
@@ -4375,7 +4376,7 @@
 echo "$ac_t""$enable_shared" 1>&6
 
 echo $ac_n "checking whether to build static libraries""... $ac_c" 1>&6
-echo "configure:4379: checking whether to build static libraries" >&5
+echo "configure:4380: checking whether to build static libraries" >&5
 # Make sure either enable_shared or enable_static is yes.
 test "$enable_shared" = yes || enable_static=yes
 echo "$ac_t""$enable_static" 1>&6
@@ -4416,12 +4417,12 @@
 
   *)
     echo $ac_n "checking for shl_load""... $ac_c" 1>&6
-echo "configure:4420: checking for shl_load" >&5
+echo "configure:4421: checking for shl_load" >&5
 if eval "test \"`echo '$''{'ac_cv_func_shl_load'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4425 "configure"
+#line 4426 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char shl_load(); below.  */
@@ -4444,7 +4445,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:4448: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4449: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_shl_load=yes"
 else
@@ -4462,7 +4463,7 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for shl_load in -ldld""... $ac_c" 1>&6
-echo "configure:4466: checking for shl_load in -ldld" >&5
+echo "configure:4467: checking for shl_load in -ldld" >&5
 ac_lib_var=`echo dld'_'shl_load | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -4470,7 +4471,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-ldld  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4474 "configure"
+#line 4475 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -4481,7 +4482,7 @@
 shl_load()
 ; return 0; }
 EOF
-if { (eval echo configure:4485: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4486: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -4500,12 +4501,12 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for dlopen""... $ac_c" 1>&6
-echo "configure:4504: checking for dlopen" >&5
+echo "configure:4505: checking for dlopen" >&5
 if eval "test \"`echo '$''{'ac_cv_func_dlopen'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4509 "configure"
+#line 4510 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char dlopen(); below.  */
@@ -4528,7 +4529,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:4532: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4533: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_dlopen=yes"
 else
@@ -4546,7 +4547,7 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4550: checking for dlopen in -ldl" >&5
+echo "configure:4551: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -4554,7 +4555,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4558 "configure"
+#line 4559 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -4565,7 +4566,7 @@
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4569: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4570: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -4584,7 +4585,7 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for dlopen in -lsvld""... $ac_c" 1>&6
-echo "configure:4588: checking for dlopen in -lsvld" >&5
+echo "configure:4589: checking for dlopen in -lsvld" >&5
 ac_lib_var=`echo svld'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -4592,7 +4593,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-lsvld  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4596 "configure"
+#line 4597 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -4603,7 +4604,7 @@
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4607: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4608: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -4622,7 +4623,7 @@
 else
   echo "$ac_t""no" 1>&6
 echo $ac_n "checking for dld_link in -ldld""... $ac_c" 1>&6
-echo "configure:4626: checking for dld_link in -ldld" >&5
+echo "configure:4627: checking for dld_link in -ldld" >&5
 ac_lib_var=`echo dld'_'dld_link | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -4630,7 +4631,7 @@
   ac_save_LIBS="$LIBS"
 LIBS="-ldld  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4634 "configure"
+#line 4635 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -4641,7 +4642,7 @@
 dld_link()
 ; return 0; }
 EOF
-if { (eval echo configure:4645: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4646: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -4697,7 +4698,7 @@
     LIBS="$lt_cv_dlopen_libs $LIBS"
 
     echo $ac_n "checking whether a program can dlopen itself""... $ac_c" 1>&6
-echo "configure:4701: checking whether a program can dlopen itself" >&5
+echo "configure:4702: checking whether a program can dlopen itself" >&5
 if eval "test \"`echo '$''{'lt_cv_dlopen_self'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -4707,7 +4708,7 @@
     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 4711 "configure"
+#line 4712 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -4768,7 +4769,7 @@
     exit (status);
 }
 EOF
-  if { (eval echo configure:4772: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} 2>/dev/null; then
+  if { (eval echo configure:4773: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} 2>/dev/null; then
     (./conftest; exit; ) 2>/dev/null
     lt_status=$?
     case x$lt_status in
@@ -4791,7 +4792,7 @@
     if test "x$lt_cv_dlopen_self" = xyes; then
       LDFLAGS="$LDFLAGS $link_static_flag"
       echo $ac_n "checking whether a statically linked program can dlopen itself""... $ac_c" 1>&6
-echo "configure:4795: checking whether a statically linked program can dlopen itself" >&5
+echo "configure:4796: checking whether a statically linked program can dlopen itself" >&5
 if eval "test \"`echo '$''{'lt_cv_dlopen_self_static'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -4801,7 +4802,7 @@
     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 4805 "configure"
+#line 4806 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -4862,7 +4863,7 @@
     exit (status);
 }
 EOF
-  if { (eval echo configure:4866: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} 2>/dev/null; then
+  if { (eval echo configure:4867: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} 2>/dev/null; then
     (./conftest; exit; ) 2>/dev/null
     lt_status=$?
     case x$lt_status in
@@ -4911,7 +4912,7 @@
     # systems, -lgcc has to come before -lc. If gcc already passes -lc
     # to ld, don't add -lc before -lgcc.
     echo $ac_n "checking whether -lc should be explicitly linked in""... $ac_c" 1>&6
-echo "configure:4915: checking whether -lc should be explicitly linked in" >&5
+echo "configure:4916: checking whether -lc should be explicitly linked in" >&5
     if eval "test \"`echo '$''{'lt_cv_archive_cmds_need_lc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -4918,7 +4919,7 @@
   $rm conftest*
     echo 'static int dummy;' > conftest.$ac_ext
 
-    if { (eval echo configure:4922: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+    if { (eval echo configure:4923: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
       soname=conftest
       lib=conftest
       libobjs=conftest.$ac_objext
@@ -4931,7 +4932,7 @@
       libname=conftest
       save_allow_undefined_flag=$allow_undefined_flag
       allow_undefined_flag=
-      if { (eval echo configure:4935: \"$archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\") 1>&5; (eval $archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5; }
+      if { (eval echo configure:4936: \"$archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1\") 1>&5; (eval $archive_cmds 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) 2>&5; }
       then
 	lt_cv_archive_cmds_need_lc=no
       else
@@ -5517,12 +5518,12 @@
  
 
 echo $ac_n "checking for working const""... $ac_c" 1>&6
-echo "configure:5521: checking for working const" >&5
+echo "configure:5522: checking for working const" >&5
 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5526 "configure"
+#line 5527 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -5571,7 +5572,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:5575: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5576: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_const=yes
 else
@@ -5592,7 +5593,7 @@
 fi
 
 echo $ac_n "checking for inline""... $ac_c" 1>&6
-echo "configure:5596: checking for inline" >&5
+echo "configure:5597: checking for inline" >&5
 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -5599,7 +5600,7 @@
   ac_cv_c_inline=no
 for ac_kw in inline __inline__ __inline; do
   cat > conftest.$ac_ext <<EOF
-#line 5603 "configure"
+#line 5604 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -5606,7 +5607,7 @@
 } $ac_kw foo() {
 ; return 0; }
 EOF
-if { (eval echo configure:5610: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:5611: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_inline=$ac_kw; break
 else
@@ -5632,12 +5633,12 @@
 esac
 
 echo $ac_n "checking for size_t""... $ac_c" 1>&6
-echo "configure:5636: checking for size_t" >&5
+echo "configure:5637: checking for size_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5641 "configure"
+#line 5642 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -5669,17 +5670,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:5673: checking for $ac_hdr" >&5
+echo "configure:5674: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5678 "configure"
+#line 5679 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:5683: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5684: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -5720,106 +5721,7 @@
     ;;
 esac
 
-echo $ac_n "checking for boolean_t in sys/types.h""... $ac_c" 1>&6
-echo "configure:5725: checking for boolean_t in sys/types.h" >&5
-if eval "test \"`echo '$''{'ac_cv_c_boolean_t_sys_types_h'+set}'`\" = set"; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  cat > conftest.$ac_ext <<EOF
-#line 5730 "configure"
-#include "confdefs.h"
-#include <sys/types.h>
-int main() {
-boolean_t foo;
-; return 0; }
-EOF
-if { (eval echo configure:5737: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
-  rm -rf conftest*
-  ac_cv_c_boolean_t_sys_types_h=yes
-else
-  echo "configure: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_c_boolean_t_sys_types_h=no
-fi
-rm -f conftest*
-fi
 
-echo "$ac_t""$ac_cv_c_boolean_t_sys_types_h" 1>&6
-if test x"$ac_cv_c_boolean_t_sys_types_h" != x"no"; then
-    cat >> confdefs.h <<\EOF
-#define BOOLEAN_T_IN_SYS_TYPES_H 1
-EOF
-
-fi
-
-echo $ac_n "checking for boolean_t in pthread.h""... $ac_c" 1>&6
-echo "configure:5758: checking for boolean_t in pthread.h" >&5
-if eval "test \"`echo '$''{'ac_cv_c_boolean_t_pthread_h'+set}'`\" = set"; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  cat > conftest.$ac_ext <<EOF
-#line 5763 "configure"
-#include "confdefs.h"
-#include <pthread.h>
-int main() {
-boolean_t foo;
-; return 0; }
-EOF
-if { (eval echo configure:5770: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
-  rm -rf conftest*
-  ac_cv_c_boolean_t_pthread_h=yes
-else
-  echo "configure: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_c_boolean_t_pthread_h=no
-fi
-rm -f conftest*
-fi
-
-echo "$ac_t""$ac_cv_c_boolean_t_pthread_h" 1>&6
-if test x"$ac_cv_c_boolean_t_pthread_h" != x"no"; then
-    cat >> confdefs.h <<\EOF
-#define BOOLEAN_T_IN_PTHREAD_H 1
-EOF
-
-fi
-
-echo $ac_n "checking for boolean_t in cthreads.h""... $ac_c" 1>&6
-echo "configure:5791: checking for boolean_t in cthreads.h" >&5
-if eval "test \"`echo '$''{'ac_cv_c_boolean_t_cthreads_h'+set}'`\" = set"; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  cat > conftest.$ac_ext <<EOF
-#line 5796 "configure"
-#include "confdefs.h"
-#include <cthreads.h>
-int main() {
-boolean_t foo;
-; return 0; }
-EOF
-if { (eval echo configure:5803: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
-  rm -rf conftest*
-  ac_cv_c_boolean_t_cthreads_h=yes
-else
-  echo "configure: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_c_boolean_t_cthreads_h=no
-fi
-rm -f conftest*
-fi
-
-echo "$ac_t""$ac_cv_c_boolean_t_cthreads_h" 1>&6
-if test x"$ac_cv_c_boolean_t_cthreads_h" != x"no"; then
-    cat >> confdefs.h <<\EOF
-#define BOOLEAN_T_IN_CTHREADS_H 1
-EOF
-
-fi
-
-
 CAN_BUILD_LIBDVDCSS=0
 
 for ac_hdr in winioctl.h
@@ -5826,17 +5728,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:5830: checking for $ac_hdr" >&5
+echo "configure:5732: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5835 "configure"
+#line 5737 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:5840: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5742: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -5869,17 +5771,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:5873: checking for $ac_hdr" >&5
+echo "configure:5775: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5878 "configure"
+#line 5780 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:5883: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5785: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -5905,17 +5807,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:5909: checking for $ac_hdr" >&5
+echo "configure:5811: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5914 "configure"
+#line 5816 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:5919: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5821: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -5945,7 +5847,7 @@
   LINUX_DVD_STRUCT=0
   OPENBSD_DVD_STRUCT=0
         cat > conftest.$ac_ext <<EOF
-#line 5949 "configure"
+#line 5851 "configure"
 #include "confdefs.h"
 #include <sys/cdio.h>
 EOF
@@ -5958,7 +5860,7 @@
 EOF
 
     cat > conftest.$ac_ext <<EOF
-#line 5962 "configure"
+#line 5864 "configure"
 #include "confdefs.h"
 #include <sys/cdio.h>
 EOF
@@ -5978,7 +5880,7 @@
 rm -f conftest*
 
         cat > conftest.$ac_ext <<EOF
-#line 5982 "configure"
+#line 5884 "configure"
 #include "confdefs.h"
 #include <sys/dvdio.h>
 EOF
@@ -5991,7 +5893,7 @@
 EOF
 
     cat > conftest.$ac_ext <<EOF
-#line 5995 "configure"
+#line 5897 "configure"
 #include "confdefs.h"
 #include <sys/dvdio.h>
 EOF
@@ -6011,7 +5913,7 @@
 rm -f conftest*
 
         cat > conftest.$ac_ext <<EOF
-#line 6015 "configure"
+#line 5917 "configure"
 #include "confdefs.h"
 #include <linux/cdrom.h>
 EOF
@@ -6029,7 +5931,7 @@
 rm -f conftest*
 
         cat > conftest.$ac_ext <<EOF
-#line 6033 "configure"
+#line 5935 "configure"
 #include "confdefs.h"
 #include <dvd.h>
 EOF
@@ -6051,17 +5953,17 @@
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:6055: checking for $ac_hdr" >&5
+echo "configure:5957: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6060 "configure"
+#line 5962 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:6065: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5967: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -6086,6 +5988,7 @@
 #define DVD_STRUCT_IN_BSDI_DVDIOCTL_DVD_H 1
 EOF
 
+      EXTRA_SOURCES="${EXTRA_SOURCES} bsdi_ioctl.c"
       LINUX_DVD_STRUCT=1
     
 else
@@ -6099,17 +6002,17 @@
 
         ac_safe=`echo "sys/scsi/scsi_types.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/scsi/scsi_types.h""... $ac_c" 1>&6
-echo "configure:6103: checking for sys/scsi/scsi_types.h" >&5
+echo "configure:6006: checking for sys/scsi/scsi_types.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6108 "configure"
+#line 6011 "configure"
 #include "confdefs.h"
 #include <sys/scsi/scsi_types.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:6113: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:6016: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -6128,17 +6031,17 @@
   
     ac_safe=`echo "sys/scsi/impl/uscsi.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/scsi/impl/uscsi.h""... $ac_c" 1>&6
-echo "configure:6132: checking for sys/scsi/impl/uscsi.h" >&5
+echo "configure:6035: checking for sys/scsi/impl/uscsi.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6137 "configure"
+#line 6040 "configure"
 #include "confdefs.h"
 #include <sys/scsi/impl/uscsi.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:6142: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:6045: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -6171,17 +6074,17 @@
 
         ac_safe=`echo "sys/scsi.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/scsi.h""... $ac_c" 1>&6
-echo "configure:6175: checking for sys/scsi.h" >&5
+echo "configure:6078: checking for sys/scsi.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6180 "configure"
+#line 6083 "configure"
 #include "confdefs.h"
 #include <sys/scsi.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:6185: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:6088: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -6199,7 +6102,7 @@
   echo "$ac_t""yes" 1>&6
   
     cat > conftest.$ac_ext <<EOF
-#line 6203 "configure"
+#line 6106 "configure"
 #include "confdefs.h"
 #include <sys/scsi.h>
 EOF
@@ -6222,17 +6125,17 @@
 
         ac_safe=`echo "IOKit/storage/IODVDMediaBSDClient.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for IOKit/storage/IODVDMediaBSDClient.h""... $ac_c" 1>&6
-echo "configure:6226: checking for IOKit/storage/IODVDMediaBSDClient.h" >&5
+echo "configure:6129: checking for IOKit/storage/IODVDMediaBSDClient.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6231 "configure"
+#line 6134 "configure"
 #include "confdefs.h"
 #include <IOKit/storage/IODVDMediaBSDClient.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:6236: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:6139: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -6288,6 +6191,7 @@
 
 
 
+
 trap '' 1 2 15
 cat > confcache <<\EOF
 # This file is a shell script that caches the results of configure
@@ -6457,6 +6361,7 @@
 s%@STRIP@%$STRIP%g
 s%@LIBTOOL@%$LIBTOOL%g
 s%@EXTRA_LIB@%$EXTRA_LIB%g
+s%@EXTRA_SOURCES@%$EXTRA_SOURCES%g
 
 CEOF
 EOF
--- a/configure.in
+++ b/configure.in
@@ -30,31 +30,6 @@
     ;;
 esac
 
-dnl Check for boolean_t
-AC_CACHE_CHECK([for boolean_t in sys/types.h],
-    [ac_cv_c_boolean_t_sys_types_h],
-    [AC_TRY_COMPILE([#include <sys/types.h>], [boolean_t foo;],
-     ac_cv_c_boolean_t_sys_types_h=yes, ac_cv_c_boolean_t_sys_types_h=no)])
-if test x"$ac_cv_c_boolean_t_sys_types_h" != x"no"; then
-    AC_DEFINE(BOOLEAN_T_IN_SYS_TYPES_H, 1, Define if <sys/types.h> defines boolean_t.)
-fi
-
-AC_CACHE_CHECK([for boolean_t in pthread.h],
-    [ac_cv_c_boolean_t_pthread_h],
-    [AC_TRY_COMPILE([#include <pthread.h>], [boolean_t foo;],
-     ac_cv_c_boolean_t_pthread_h=yes, ac_cv_c_boolean_t_pthread_h=no)])
-if test x"$ac_cv_c_boolean_t_pthread_h" != x"no"; then
-    AC_DEFINE(BOOLEAN_T_IN_PTHREAD_H, 1, Define if <pthread.h> defines boolean_t.)
-fi
-
-AC_CACHE_CHECK([for boolean_t in cthreads.h],
-    [ac_cv_c_boolean_t_cthreads_h],
-    [AC_TRY_COMPILE([#include <cthreads.h>], [boolean_t foo;],
-     ac_cv_c_boolean_t_cthreads_h=yes, ac_cv_c_boolean_t_cthreads_h=no)])
-if test x"$ac_cv_c_boolean_t_cthreads_h" != x"no"; then
-    AC_DEFINE(BOOLEAN_T_IN_CTHREADS_H, 1, Define if <cthreads.h> defines boolean_t.)
-fi
-
 dnl
 dnl  libdvdcss: check for DVD ioctls
 dnl
@@ -115,6 +90,7 @@
     AC_CHECK_HEADERS(/sys/dev/scsi/scsi_ioctl.h,[
       AC_DEFINE(DVD_STRUCT_IN_BSDI_DVDIOCTL_DVD_H, 1,
                 Define if <extras/BSDI_dvdioctl/dvd.h> defines DVD_STRUCT.)
+      EXTRA_SOURCES="${EXTRA_SOURCES} bsdi_ioctl.c"
       LINUX_DVD_STRUCT=1
     ])
   ])
@@ -161,6 +137,7 @@
 CFLAGS="-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DDVDCSS_DIST $CFLAGS"
 
 AC_SUBST(EXTRA_LIB)
+AC_SUBST(EXTRA_SOURCES)
 
 AC_OUTPUT([Makefile src/Makefile src/dvdcss/Makefile test/Makefile debian/Makefile])
 
--- a/debian/Makefile.in
+++ b/debian/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -69,6 +69,7 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_LIB = @EXTRA_LIB@
+EXTRA_SOURCES = @EXTRA_SOURCES@
 LIBTOOL = @LIBTOOL@
 LN_S = @LN_S@
 MAKEINFO = @MAKEINFO@
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,8 +1,13 @@
 SUBDIRS = dvdcss
 
 lib_LTLIBRARIES = libdvdcss.la
-libdvdcss_la_SOURCES = libdvdcss.c css.c ioctl.c bsdi_ioctl.c
-libdvdcss_la_LIBADD = @EXTRA_LIB@
+
+libdvdcss_la_SOURCES = libdvdcss.c device.c error.c css.c ioctl.c
+
+EXTRA_libdvdcss_la_SOURCES = bsdi_ioctl.c
+libdvdcss_la_DEPENDENCIES = @EXTRA_SOURCES@
+
+libdvdcss_la_LIBADD = @EXTRA_SOURCES@ @EXTRA_LIB@
 libdvdcss_la_LDFLAGS = -version-info 2:1:0
 
-noinst_HEADERS = csstables.h ioctl.h common.h css.h libdvdcss.h bsdi_dvd.h
+noinst_HEADERS = csstables.h ioctl.h device.h common.h css.h libdvdcss.h bsdi_dvd.h
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -69,6 +69,7 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_LIB = @EXTRA_LIB@
+EXTRA_SOURCES = @EXTRA_SOURCES@
 LIBTOOL = @LIBTOOL@
 LN_S = @LN_S@
 MAKEINFO = @MAKEINFO@
@@ -82,11 +83,16 @@
 SUBDIRS = dvdcss
 
 lib_LTLIBRARIES = libdvdcss.la
-libdvdcss_la_SOURCES = libdvdcss.c css.c ioctl.c bsdi_ioctl.c
-libdvdcss_la_LIBADD = @EXTRA_LIB@
+
+libdvdcss_la_SOURCES = libdvdcss.c device.c error.c css.c ioctl.c
+
+EXTRA_libdvdcss_la_SOURCES = bsdi_ioctl.c
+libdvdcss_la_DEPENDENCIES = @EXTRA_SOURCES@
+
+libdvdcss_la_LIBADD = @EXTRA_SOURCES@ @EXTRA_LIB@
 libdvdcss_la_LDFLAGS = -version-info 2:1:0
 
-noinst_HEADERS = csstables.h ioctl.h common.h css.h libdvdcss.h bsdi_dvd.h
+noinst_HEADERS = csstables.h ioctl.h device.h common.h css.h libdvdcss.h bsdi_dvd.h
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
 CONFIG_HEADER = config.h
 CONFIG_CLEAN_FILES = 
@@ -97,8 +103,7 @@
 CPPFLAGS = @CPPFLAGS@
 LDFLAGS = @LDFLAGS@
 LIBS = @LIBS@
-libdvdcss_la_DEPENDENCIES = 
-libdvdcss_la_OBJECTS =  libdvdcss.lo css.lo ioctl.lo bsdi_ioctl.lo
+libdvdcss_la_OBJECTS =  libdvdcss.lo device.lo error.lo css.lo ioctl.lo
 CFLAGS = @CFLAGS@
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -113,9 +118,9 @@
 
 TAR = tar
 GZIP_ENV = --best
-DEP_FILES =  .deps/bsdi_ioctl.P .deps/css.P .deps/ioctl.P \
-.deps/libdvdcss.P
-SOURCES = $(libdvdcss_la_SOURCES)
+DEP_FILES =  .deps/bsdi_ioctl.P .deps/css.P .deps/device.P .deps/error.P \
+.deps/ioctl.P .deps/libdvdcss.P
+SOURCES = $(libdvdcss_la_SOURCES) $(EXTRA_libdvdcss_la_SOURCES)
 OBJECTS = $(libdvdcss_la_OBJECTS)
 
 all: all-redirect
--- a/src/bsdi_ioctl.c
+++ b/src/bsdi_ioctl.c
@@ -1,7 +1,5 @@
 #include "config.h"
 
-#ifdef DVD_STRUCT_IN_BSDI_DVDIOCTL_DVD_H
-
 /*
  * Hacked version of the linux cdrom.c kernel module - everything except the
  * DVD handling ripped out and the rest rewritten to use raw SCSI commands
@@ -698,5 +696,3 @@
 	mh.block_length_lo = size & 0xff;
 	return(scsi_cmd(fd, &cgc));
 	}
-
-#endif
--- a/src/common.h
+++ b/src/common.h
@@ -3,7 +3,7 @@
  * Collection of useful common types and macros definitions
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: common.h,v 1.1 2001/12/22 00:08:13 sam Exp $
+ * $Id: common.h,v 1.2 2002/08/09 14:10:43 sam Exp $
  *
  * Authors: Samuel Hocevar <[email protected]>
  *          Vincent Seguin <[email protected]>
@@ -31,33 +31,10 @@
 /* Basic types definitions */
 typedef unsigned char           u8;
 typedef signed char             s8;
-typedef unsigned short          u16;
-typedef signed short            s16;
 typedef unsigned int            u32;
 typedef signed int              s32;
-#if defined( _MSC_VER )
-typedef unsigned __int64        u64;
-typedef signed __int64          s64;
-#else
-typedef unsigned long long      u64;
-typedef signed long long        s64;
-#endif
 
 typedef u8                  byte_t;
-
-/* Boolean type */
-#ifdef BOOLEAN_T_IN_SYS_TYPES_H
-#   include <sys/types.h>
-#elif defined(BOOLEAN_T_IN_PTHREAD_H)
-#   include <pthread.h>
-#elif defined(BOOLEAN_T_IN_CTHREADS_H)
-#   include <cthreads.h>
-#else
-typedef int                 boolean_t;
-#endif
-#ifdef SYS_GNU
-#   define _MACH_I386_BOOLEAN_H_
-#endif
 
 #if defined( WIN32 )
 
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -48,15 +48,6 @@
 /* Have a BeOS system. */
 #undef SYS_BEOS
 
-/* Define if <sys/types.h> defines boolean_t. */
-#undef BOOLEAN_T_IN_SYS_TYPES_H
-
-/* Define if <pthread.h> defines boolean_t. */
-#undef BOOLEAN_T_IN_PTHREAD_H
-
-/* Define if <cthreads.h> defines boolean_t. */
-#undef BOOLEAN_T_IN_CTHREADS_H
-
 /* Define if <sys/cdio.h> defines dvd_struct. */
 #undef DVD_STRUCT_IN_SYS_CDIO_H
 
--- a/src/css.c
+++ b/src/css.c
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * css.c: Functions for DVD authentication and unscrambling
+ * css.c: Functions for DVD authentication and descrambling
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: css.c,v 1.11 2002/07/16 22:47:40 sam Exp $
+ * $Id: css.c,v 1.12 2002/08/09 14:10:43 sam Exp $
  *
  * Author: St�phane Borel <[email protected]>
  *         H�kan Hjort <[email protected]>
@@ -46,32 +46,33 @@
 #include "libdvdcss.h"
 #include "csstables.h"
 #include "ioctl.h"
+#include "device.h"
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  CSSGetBusKey ( dvdcss_handle dvdcss );
-static int  CSSGetASF    ( dvdcss_handle dvdcss );
-static void CSSCryptKey  ( int i_key_type, int i_varient,
-                           u8 const *p_challenge, u8 *p_key );
-static void CSSDecryptKey( u8 invert, u8 const *p_key, u8 const *p_crypted, 
-                           u8 *p_result );
-static int  CSSDecryptDiscKey ( u8 const *p_struct_disckey,
-                                dvd_key_t p_disc_key );
-static void CSSDecryptTitleKey( dvd_key_t p_disc_key, dvd_key_t p_titlekey );
-static int  CSSDiscCrack ( dvdcss_handle dvdcss, u8 *p_disc_key );
-static int  CSSRecoverKey( int i_start, 
-                           u8 const *p_crypted, u8 const *p_decrypted, 
-                           u8 const *p_sector_seed, u8 *p_key );
-static int  CSSTitleCrack( dvdcss_handle dvdcss, int i_pos, int i_len, 
-                           dvd_key_t p_titlekey );
-static int  CSSAttackPattern( u8 const p_sec[0x800], int i_pos, u8 *p_key );
-static int  CSSAttackPadding( u8 const p_sec[0x800], int i_pos, u8 *p_key );
+static int  GetBusKey       ( dvdcss_handle );
+static int  GetASF          ( dvdcss_handle );
 
+static void CryptKey        ( int, int, u8 const *, u8 * );
+static void DecryptKey      ( u8, u8 const *, u8 const *, u8 * );
+
+static int  DecryptDiscKey  ( u8 const *, dvd_key_t );
+static int  CrackDiscKey    ( dvdcss_handle, u8 * );
+
+static void DecryptTitleKey ( dvd_key_t, dvd_key_t );
+static int  RecoverTitleKey ( int, u8 const *, u8 const *, u8 const *, u8 * );
+static int  CrackTitleKey   ( dvdcss_handle, int, int, dvd_key_t );
+
+static int  AttackPattern   ( u8 const[], int, u8 * );
+#if 0
+static int  AttackPadding   ( u8 const[], int, u8 * );
+#endif
+
 /*****************************************************************************
- * CSSTest : check if the disc is encrypted or not
+ * _dvdcss_test: check if the disc is encrypted or not
  *****************************************************************************/
-int CSSTest( dvdcss_handle dvdcss )
+int _dvdcss_test( dvdcss_handle dvdcss )
 {
     int i_ret, i_copyright;
 
@@ -97,7 +98,7 @@
 }
 
 /*****************************************************************************
- * CSSGetBusKey : Go through the CSS Authentication process
+ * GetBusKey : Go through the CSS Authentication process
  *****************************************************************************
  * It simulates the mutual authentication between logical unit and host,
  * and stops when a session key (called bus key) has been established.
@@ -106,7 +107,7 @@
  * that ASF=1 from the start and then later fail with a 'read of scrambled 
  * block without authentication' error.
  *****************************************************************************/
-static int CSSGetBusKey( dvdcss_handle dvdcss )
+static int GetBusKey( dvdcss_handle dvdcss )
 {
     u8        p_buffer[10];
     u8        p_challenge[2*KEY_SIZE];
@@ -113,8 +114,8 @@
     dvd_key_t p_key1;
     dvd_key_t p_key2;
     dvd_key_t p_key_check;
-    u8        i_varient = 0;
-    char      psz_warning[48];
+    u8        i_variant = 0;
+    char      psz_warning[80];
     int       i_ret = -1;
     int       i;
 
@@ -126,17 +127,16 @@
        an AGID, invalidate one (in sequence) and try again. */
     for( i = 0; i_ret == -1 && i < 4 ; ++i )
     {
-        _dvdcss_debug( dvdcss, "ioctl_ReportAgid failed" );
-        
-        sprintf( psz_warning, "invalidating AGID %d", i );
+        sprintf( psz_warning,
+                 "ioctl ReportAgid failed, invalidating AGID %d", i );
         _dvdcss_debug( dvdcss, psz_warning );
-        
+
         /* This is really _not good_, should be handled by the OS.
            Invalidating an AGID could make another process fail some
            where in it's authentication process. */
         dvdcss->css.i_agid = i;
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
-        
+
         _dvdcss_debug( dvdcss, "requesting AGID" );
         i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
     }
@@ -144,7 +144,7 @@
     /* Unable to authenticate without AGID */
     if( i_ret == -1 )
     {
-        _dvdcss_error( dvdcss, "ioctl_ReportAgid failed, fatal" );
+        _dvdcss_error( dvdcss, "ioctl ReportAgid failed, fatal" );
         return -1;
     }
 
@@ -164,7 +164,7 @@
     if( ioctl_SendChallenge( dvdcss->i_fd,
                              &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl_SendChallenge failed" );
+        _dvdcss_error( dvdcss, "ioctl SendChallenge failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -172,7 +172,7 @@
     /* Get key1 from LU */
     if( ioctl_ReportKey1( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0)
     {
-        _dvdcss_error( dvdcss, "ioctl_ReportKey1 failed" );
+        _dvdcss_error( dvdcss, "ioctl ReportKey1 failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -185,14 +185,14 @@
 
     for( i = 0 ; i < 32 ; ++i )
     {
-        CSSCryptKey( 0, i, p_challenge, p_key_check );
+        CryptKey( 0, i, p_challenge, p_key_check );
 
         if( memcmp( p_key_check, p_key1, KEY_SIZE ) == 0 )
         {
             snprintf( psz_warning, sizeof(psz_warning),
-                      "drive authentic, using variant %d", i );
+                      "drive authenticated, using variant %d", i );
             _dvdcss_debug( dvdcss, psz_warning );
-            i_varient = i;
+            i_variant = i;
             break;
         }
     }
@@ -208,7 +208,7 @@
     if( ioctl_ReportChallenge( dvdcss->i_fd, 
                                &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl_ReportKeyChallenge failed" );
+        _dvdcss_error( dvdcss, "ioctl ReportKeyChallenge failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -219,7 +219,7 @@
         p_challenge[i] = p_buffer[9-i];
     }
 
-    CSSCryptKey( 1, i_varient, p_challenge, p_key2 );
+    CryptKey( 1, i_variant, p_challenge, p_key2 );
 
     /* Get key2 from host */
     for( i = 0 ; i < KEY_SIZE ; ++i )
@@ -230,7 +230,7 @@
     /* Send key2 to LU */
     if( ioctl_SendKey2( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl_SendKey2 failed" );
+        _dvdcss_error( dvdcss, "ioctl SendKey2 failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -241,26 +241,109 @@
     memcpy( p_challenge, p_key1, KEY_SIZE );
     memcpy( p_challenge + KEY_SIZE, p_key2, KEY_SIZE );
 
-    CSSCryptKey( 2, i_varient, p_challenge, dvdcss->css.p_bus_key );
+    CryptKey( 2, i_variant, p_challenge, dvdcss->css.p_bus_key );
 
     return 0;
 }
 
 /*****************************************************************************
- * CSSPrintKey : debug function that dumps a key value 
+ * PrintKey : debug function that dumps a key value 
  *****************************************************************************/
-static void CSSPrintKey( dvdcss_handle dvdcss, u8 const *data )
+static void PrintKey( dvdcss_handle dvdcss, char *prefix, u8 const *data )
 {
     char psz_output[80];
 
-    sprintf( psz_output, "the key is %02x %02x %02x %02x %02x",
+    sprintf( psz_output, "%s%02x:%02x:%02x:%02x:%02x", prefix,
              data[0], data[1], data[2], data[3], data[4] );
     _dvdcss_debug( dvdcss, psz_output );
 }
 
 /*****************************************************************************
- * CSSGetDiscKey : get disc key.
+ * _dvdcss_title: crack or decrypt the current title key if needed
  *****************************************************************************
+ * This function should only be called by dvdcss_seek and should eventually
+ * not be external if possible.
+ *****************************************************************************/
+int _dvdcss_title ( dvdcss_handle dvdcss, int i_block )
+{
+    dvd_title_t *p_title;
+    dvd_title_t *p_newtitle;
+    dvd_key_t    p_title_key;
+    int          i_ret;
+
+    if( ! dvdcss->b_scrambled )
+    {
+        return 0;
+    }
+
+    /* Check if we've already cracked this key */
+    p_title = dvdcss->p_titles;
+    while( p_title != NULL
+            && p_title->p_next != NULL
+            && p_title->p_next->i_startlb <= i_block )
+    {
+        p_title = p_title->p_next;
+    }
+
+    if( p_title != NULL
+         && p_title->i_startlb == i_block )
+    {
+        /* We've already cracked this key, nothing to do */
+        memcpy( dvdcss->css.p_title_key, p_title->p_key, sizeof(dvd_key_t) );
+        return 0;
+    }
+
+    /* Crack or decrypt CSS title key for current VTS */
+    i_ret = _dvdcss_titlekey( dvdcss, i_block, p_title_key );
+
+    if( i_ret < 0 )
+    {
+        _dvdcss_error( dvdcss, "fatal error in vts css key" );
+        return i_ret;
+    }
+    else if( i_ret == 0 )
+    {
+        _dvdcss_debug( dvdcss, "unencrypted title" );
+        /* Still store this in the cache, so we don't need to check again. */
+    }
+
+    /* Find our spot in the list */
+    p_newtitle = NULL;
+    p_title = dvdcss->p_titles;
+    while( ( p_title != NULL ) && ( p_title->i_startlb < i_block ) )
+    {
+        p_newtitle = p_title;
+        p_title = p_title->p_next;
+    }
+
+    /* Save the found title */
+    p_title = p_newtitle;
+
+    /* Write in the new title and its key */
+    p_newtitle = malloc( sizeof( dvd_title_t ) );
+    p_newtitle->i_startlb = i_block;
+    memcpy( p_newtitle->p_key, p_title_key, KEY_SIZE );
+
+    /* Link it at the head of the (possibly empty) list */
+    if( p_title == NULL )
+    {
+        p_newtitle->p_next = dvdcss->p_titles;
+        dvdcss->p_titles = p_newtitle;
+    }
+    /* Link the new title inside the list */
+    else
+    {
+        p_newtitle->p_next = p_title->p_next;
+        p_title->p_next = p_newtitle;
+    }
+
+    memcpy( dvdcss->css.p_title_key, p_title_key, KEY_SIZE );
+    return 0;
+}
+
+/*****************************************************************************
+ * _dvdcss_disckey: get disc key.
+ *****************************************************************************
  * This function should only be called if DVD ioctls are present.
  * It will set dvdcss->i_method = DVDCSS_METHOD_TITLE if it fails to find 
  * a valid disc key.
@@ -268,13 +351,15 @@
  *  -disc key hash crack,
  *  -decryption with player keys if they are available.
  *****************************************************************************/
-int CSSGetDiscKey( dvdcss_handle dvdcss )
+int _dvdcss_disckey( dvdcss_handle dvdcss )
 {
     unsigned char p_buffer[2048];
     dvd_key_t p_disc_key;
     int i;
 
-    if( CSSGetBusKey( dvdcss ) < 0)
+    _dvdcss_debug( dvdcss, "retrieving disc key by all means" );
+
+    if( GetBusKey( dvdcss ) < 0)
     {
         return -1;
     }
@@ -282,15 +367,16 @@
     /* Get encrypted disc key */
     if( ioctl_ReadDiscKey( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl_ReadDiscKey failed" );
+        _dvdcss_error( dvdcss, "ioctl ReadDiscKey failed" );
         return -1;
     }
 
     /* This should have invaidated the AGID and got us ASF=1. */
-    if( CSSGetASF( dvdcss ) != 1 )
+    if( GetASF( dvdcss ) != 1 )
     {
         /* Region mismatch (or region not set) is the most likely source. */  
-        _dvdcss_error( dvdcss, "ASF not 1 after reading disc key" );
+        _dvdcss_error( dvdcss,
+                       "ASF not 1 after reading disc key (region mismatch?)" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -304,58 +390,68 @@
     switch( dvdcss->i_method )
     {
         case DVDCSS_METHOD_KEY:
+
             /* Decrypt disc key with player key. */
             _dvdcss_debug( dvdcss, "decrypting disc key with player keys" );
-            if( ! CSSDecryptDiscKey( p_buffer, p_disc_key ) )
+            if( ! DecryptDiscKey( p_buffer, p_disc_key ) )
             {
+                PrintKey( dvdcss, "decrypted disc key is ", p_disc_key );
                 break;
             }
-            _dvdcss_debug( dvdcss, "no valid player key" );
-            /* Fall through */
+            _dvdcss_debug( dvdcss, "failed to decrypt the disc key, "
+                                   "trying to crack it instead" );
 
+            /* Fallback */
+
         case DVDCSS_METHOD_DISC:
+
             /* Crack Disc key to be able to use it */
-            _dvdcss_debug( dvdcss, "cracking disc key from key hash" );
-            _dvdcss_debug( dvdcss, "building 64MB table ... this will take some time" );
+            _dvdcss_debug( dvdcss, "cracking disc key from key hash ..."
+                                   " this will take some time" );
             memcpy( p_disc_key, p_buffer, KEY_SIZE );
-            if( CSSDiscCrack( dvdcss, p_disc_key ) )
+            if( ! CrackDiscKey( dvdcss, p_disc_key ) )
             {
-                _dvdcss_debug( dvdcss, "failed cracking disc key" );
-                dvdcss->i_method = DVDCSS_METHOD_TITLE;
+                PrintKey( dvdcss, "cracked disc key is ", p_disc_key );
+                break;
             }
+            _dvdcss_debug( dvdcss, "failed to crack the disc key" );
+            dvdcss->i_method = DVDCSS_METHOD_TITLE;
             break;
 
         default:
-            _dvdcss_debug( dvdcss, "disc key won't be decrypted" );
+
+            _dvdcss_debug( dvdcss, "disc key needs not be decrypted" );
             memset( p_disc_key, 0, KEY_SIZE );
             break;
     }
 
     memcpy( dvdcss->css.p_disc_key, p_disc_key, KEY_SIZE );
-    CSSPrintKey( dvdcss, dvdcss->css.p_disc_key );
+
     return 0;
 }
 
 
 /*****************************************************************************
- * CSSGetTitleKey : get title key.
+ * _dvdcss_titlekey: get title key.
  *****************************************************************************/
-int CSSGetTitleKey( dvdcss_handle dvdcss, int i_pos, dvd_key_t p_title_key )
+int _dvdcss_titlekey( dvdcss_handle dvdcss, int i_pos, dvd_key_t p_title_key )
 {
     u8  p_key[KEY_SIZE];
     int i, i_ret = 0;
 
+    _dvdcss_debug( dvdcss, "retrieving title key by all means" );
+
     if( dvdcss->b_ioctls && ( dvdcss->i_method == DVDCSS_METHOD_KEY || 
-			      dvdcss->i_method == DVDCSS_METHOD_DISC ) )
+                              dvdcss->i_method == DVDCSS_METHOD_DISC ) )
     {
         /* We have a decrypted Disc key and the ioctls are available,
          * read the title key and decrypt it.
          */
 
-        _dvdcss_debug( dvdcss, "decrypting title key with disc key" );
+        _dvdcss_debug( dvdcss, "getting disc key the classic way" );
 
         /* We need to authenticate again every time to get a new session key */
-        if( CSSGetBusKey( dvdcss ) < 0 )
+        if( GetBusKey( dvdcss ) < 0 )
         {
             return -1;
         }
@@ -364,90 +460,96 @@
         if( ioctl_ReadTitleKey( dvdcss->i_fd, &dvdcss->css.i_agid,
                                 i_pos, p_key ) < 0 )
         {
-            _dvdcss_error( dvdcss, "ioctl_ReadTitleKey failed" );
+            _dvdcss_debug( dvdcss,
+                           "ioctl ReadTitleKey failed (region mismatch?)" );
             i_ret = -1;
         }
 
         /* Test ASF, it will be reset to 0 if we got a Region error */
-        switch( CSSGetASF( dvdcss ) )
+        switch( GetASF( dvdcss ) )
         {
             case -1:
                 /* An error getting the ASF status, something must be wrong. */
-                // ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
-                _dvdcss_debug( dvdcss, "lost ASF reqesting Title key" );
+                _dvdcss_debug( dvdcss, "lost ASF reqesting title key" );
+                ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
                 i_ret = -1;
-		break;
+                break;
 
             case 0:
                 /* This might either be a title that has no key, 
                  * or we encountered a region error. */
-                _dvdcss_debug( dvdcss, "lost ASF reqesting Title key" );
+                _dvdcss_debug( dvdcss, "lost ASF reqesting title key" );
                 break;
 
             case 1:
                 /* Drive status is ok. */
-		/* If the title key request failed, but we did not loose ASF,
-		 * we might stil have the AGID.  Other code assume that we
-		 * will not after this so invalidate it(?). */
-		if( i_ret < 0 )
-		{
-		  //ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
-		}
+                /* If the title key request failed, but we did not loose ASF,
+                 * we might stil have the AGID.  Other code assume that we
+                 * will not after this so invalidate it(?). */
+                if( i_ret < 0 )
+                {
+                    ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
+                }
                 break;
         }
-	
-	if( !( i_ret < 0 ) )
-	{
-	    /* Decrypt title key using the bus key */
-	    for( i = 0 ; i < KEY_SIZE ; i++ )
-	    {
-		p_key[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
-	    }
 
-	    /* If p_key is all zero then there realy wasn't any key pressent
-	     * even though we got to read it without an error. */
-	    if( !( p_key[0] | p_key[1] | p_key[2] | p_key[3] | p_key[4] ) )
-	    {
-		i_ret = 0;
-	    }
-	    else
-	    {
-		CSSDecryptTitleKey( dvdcss->css.p_disc_key, p_key );
-		i_ret = 1;
-	    }
+        if( !( i_ret < 0 ) )
+        {
+            /* Decrypt title key using the bus key */
+            for( i = 0 ; i < KEY_SIZE ; i++ )
+            {
+                p_key[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
+            }
 
-	    /* All went well either there wasn't a key or we have it now. */
-	    memcpy( p_title_key, p_key, KEY_SIZE );
-	    CSSPrintKey( dvdcss, p_title_key );
-	    
-	    return i_ret;
-	}
+            /* If p_key is all zero then there realy wasn't any key pressent
+             * even though we got to read it without an error. */
+            if( !( p_key[0] | p_key[1] | p_key[2] | p_key[3] | p_key[4] ) )
+            {
+                i_ret = 0;
+            }
+            else
+            {
+                DecryptTitleKey( dvdcss->css.p_disc_key, p_key );
+                i_ret = 1;
+            }
 
-	/* The title key request failed */
-	_dvdcss_debug( dvdcss, "Reverting to cracking the Title key" );
+            /* All went well either there wasn't a key or we have it now. */
+            memcpy( p_title_key, p_key, KEY_SIZE );
+            PrintKey( dvdcss, "title key is ", p_title_key );
 
-	/* FALL THROUGH */
+            return i_ret;
+        }
+
+        /* The title key request failed */
+        _dvdcss_debug( dvdcss, "reopening disc and cracking title key" );
+
+        /* Close and reopen everything */
+        _dvdcss_close( dvdcss );
+        _dvdcss_open( dvdcss );
+        _dvdcss_disckey( dvdcss );
+
+        /* Fallback */
     }
-    
+
     /* METHOD is TITLE, we can't use the ioctls or requesting the title key
      * failed above.  For these cases we try to crack the key instead. */
-    
+
     /* For now, the read limit is 9Gb / 2048 =  4718592 sectors. */
-    i_ret = CSSTitleCrack( dvdcss, i_pos, 4718592, p_key);
+    i_ret = CrackTitleKey( dvdcss, i_pos, 4718592, p_key );
 
     memcpy( p_title_key, p_key, KEY_SIZE );
-    CSSPrintKey( dvdcss, p_title_key );
+    PrintKey( dvdcss, "title key is ", p_title_key );
 
     return i_ret;
 }
 
 /*****************************************************************************
- * CSSDescrambleSector: does the actual descrambling of data
+ * _dvdcss_unscramble: does the actual descrambling of data
  *****************************************************************************
- * sec : sector to descramble
+ * sec : sector to unscramble
  * key : title key for this sector
  *****************************************************************************/
-int CSSDescrambleSector( dvd_key_t p_key, u8 *p_sec )
+int _dvdcss_unscramble( dvd_key_t p_key, u8 *p_sec )
 {
     unsigned int    i_t1, i_t2, i_t3, i_t4, i_t5, i_t6;
     u8             *p_end = p_sec + 0x800;
@@ -488,7 +590,7 @@
 /* Following functions are local */
 
 /*****************************************************************************
- * CSSGetASF : Get Authentication success flag
+ * GetASF : Get Authentication success flag
  *****************************************************************************
  * Returns :
  *  -1 on ioctl error,
@@ -495,7 +597,7 @@
  *  0 if the device needs to be authenticated,
  *  1 either.
  *****************************************************************************/
-static int CSSGetASF( dvdcss_handle dvdcss )
+static int GetASF( dvdcss_handle dvdcss )
 {
     int i_asf = 0;
 
@@ -508,11 +610,11 @@
 
     if( i_asf )
     {
-        _dvdcss_debug( dvdcss, "GetASF authenticated (ASF=1)" );
+        _dvdcss_debug( dvdcss, "GetASF authenticated, ASF=1" );
     }
     else
     {
-        _dvdcss_debug( dvdcss, "GetASF not authenticated (ASF=0)" );
+        _dvdcss_debug( dvdcss, "GetASF not authenticated, ASF=0" );
     }
 
     return i_asf;
@@ -519,14 +621,14 @@
 }
 
 /*****************************************************************************
- * CSSCryptKey : shuffles bits and unencrypt keys.
+ * CryptKey : shuffles bits and unencrypt keys.
  *****************************************************************************
- * Used during authentication and disc key negociation in CSSGetBusKey.
+ * Used during authentication and disc key negociation in GetBusKey.
  * i_key_type : 0->key1, 1->key2, 2->buskey.
- * i_varient : between 0 and 31.
+ * i_variant : between 0 and 31.
  *****************************************************************************/
-static void CSSCryptKey( int i_key_type, int i_varient,
-                         u8 const *p_challenge, u8 *p_key )
+static void CryptKey( int i_key_type, int i_variant,
+                      u8 const *p_challenge, u8 *p_key )
 {
     /* Permutation table for challenge */
     u8      pp_perm_challenge[3][10] =
@@ -534,8 +636,8 @@
               { 6, 1, 9, 3, 8, 5, 7, 4, 0, 2 },
               { 4, 0, 3, 5, 7, 2, 8, 6, 1, 9 } };
 
-    /* Permutation table for varient table for key2 and buskey */
-    u8      pp_perm_varient[2][32] =
+    /* Permutation table for variant table for key2 and buskey */
+    u8      pp_perm_variant[2][32] =
             { { 0x0a, 0x08, 0x0e, 0x0c, 0x0b, 0x09, 0x0f, 0x0d,
                 0x1a, 0x18, 0x1e, 0x1c, 0x1b, 0x19, 0x1f, 0x1d,
                 0x02, 0x00, 0x06, 0x04, 0x03, 0x01, 0x07, 0x05,
@@ -545,7 +647,7 @@
                 0x13, 0x1b, 0x17, 0x1f, 0x03, 0x0b, 0x07, 0x0f,
                 0x11, 0x19, 0x15, 0x1d, 0x01, 0x09, 0x05, 0x0d } };
 
-    u8      p_varients[32] =
+    u8      p_variants[32] =
             {   0xB7, 0x74, 0x85, 0xD0, 0xCC, 0xDB, 0xCA, 0x73,
                 0x03, 0xFE, 0x31, 0x03, 0x52, 0xE0, 0xB7, 0x42,
                 0x63, 0x16, 0xF2, 0x2A, 0x79, 0x52, 0xFF, 0x1B,
@@ -554,19 +656,11 @@
     /* The "secret" key */
     u8      p_secret[5] = { 0x55, 0xD6, 0xC4, 0xC5, 0x28 };
 
-    u8      p_bits[30];
-    u8      p_scratch[10];
-    u8      p_tmp1[5];
-    u8      p_tmp2[5];
+    u8      p_bits[30], p_scratch[10], p_tmp1[5], p_tmp2[5];
     u8      i_lfsr0_o;  /* 1 bit used */
     u8      i_lfsr1_o;  /* 1 bit used */
-    u32     i_lfsr0;
-    u32     i_lfsr1;
-    u8      i_css_varient;
-    u8      i_cse;
-    u8      i_index;
-    u8      i_combined;
-    u8      i_carry;
+    u32     i_lfsr0, i_lfsr1;
+    u8      i_css_variant, i_cse, i_index, i_combined, i_carry;
     u8      i_val = 0;
     int     i_term = 0;
     int     i_bit;
@@ -575,13 +669,13 @@
     for (i = 9; i >= 0; --i)
         p_scratch[i] = p_challenge[pp_perm_challenge[i_key_type][i]];
 
-    i_css_varient = ( i_key_type == 0 ) ? i_varient :
-                    pp_perm_varient[i_key_type-1][i_varient];
+    i_css_variant = ( i_key_type == 0 ) ? i_variant :
+                    pp_perm_variant[i_key_type-1][i_variant];
 
     /*
      * This encryption engine implements one of 32 variations
      * one the same theme depending upon the choice in the
-     * varient parameter (0 - 31).
+     * variant parameter (0 - 31).
      *
      * The algorithm itself manipulates a 40 bit input into
      * a 40 bit output.
@@ -622,7 +716,7 @@
      * are implemented in bit reversed order.
      *
      */
-    
+
     /* In order to ensure that the LFSR works we need to ensure that the
      * initial values are non-zero.  Thus when we initialise them from
      * the seed,  we ensure that a bit is set.
@@ -651,7 +745,7 @@
             i_carry = ( i_combined >> 1 ) & 1;
             i_val |= ( i_combined & 1 ) << i_bit;
         }
-    
+
         p_bits[--i_index] = i_val;
     } while( i_index > 0 );
 
@@ -659,7 +753,7 @@
      * select one of 32 different variations on the
      * algorithm.
      */
-    i_cse = p_varients[i_css_varient] ^ p_crypt_tab2[i_css_varient];
+    i_cse = p_variants[i_css_variant] ^ p_crypt_tab2[i_css_variant];
 
     /* Now the actual blocks doing the encryption.  Each
      * of these works on 40 bits at a time and are quite
@@ -726,11 +820,11 @@
 }
 
 /*****************************************************************************
- * CSSDecryptKey: decrypt p_crypted with p_key.
+ * DecryptKey: decrypt p_crypted with p_key.
  *****************************************************************************
  * Used to decrypt the disc key, with a player key, after requesting it 
- * in CSSGetDiscKey and to decrypt title keys, with a disc key, requested 
- * in CSSGetTitleKey.
+ * in _dvdcss_disckey and to decrypt title keys, with a disc key, requested 
+ * in _dvdcss_titlekey.
  * The player keys and the resulting disc key are only used as KEKs 
  * (key encryption keys).
  * Decryption is slightly dependant on the type of key:
@@ -737,8 +831,8 @@
  *  -for disc key, invert is 0x00,
  *  -for title key, invert if 0xff. 
  *****************************************************************************/
-static void CSSDecryptKey( u8 invert, u8 const *p_key, 
-                           u8 const *p_crypted, u8 *p_result )
+static void DecryptKey( u8 invert, u8 const *p_key, 
+                        u8 const *p_crypted, u8 *p_result )
 {
     unsigned int    i_lfsr1_lo;
     unsigned int    i_lfsr1_hi;
@@ -793,43 +887,8 @@
     return;
 }
 
-static const dvd_key_t player_keys[] = 
-{
-    { 0x01, 0xaf, 0xe3, 0x12, 0x80 },
-    { 0x12, 0x11, 0xca, 0x04, 0x3b },
-    { 0x14, 0x0c, 0x9e, 0xd0, 0x09 },
-    { 0x14, 0x71, 0x35, 0xba, 0xe2 },
-    { 0x1a, 0xa4, 0x33, 0x21, 0xa6 },
-    { 0x26, 0xec, 0xc4, 0xa7, 0x4e },
-    { 0x2c, 0xb2, 0xc1, 0x09, 0xee },
-    { 0x2f, 0x25, 0x9e, 0x96, 0xdd },
-    { 0x33, 0x2f, 0x49, 0x6c, 0xe0 },
-    { 0x35, 0x5b, 0xc1, 0x31, 0x0f },
-    { 0x36, 0x67, 0xb2, 0xe3, 0x85 },
-    { 0x39, 0x3d, 0xf1, 0xf1, 0xbd },
-    { 0x3b, 0x31, 0x34, 0x0d, 0x91 },
-    { 0x45, 0xed, 0x28, 0xeb, 0xd3 },
-    { 0x48, 0xb7, 0x6c, 0xce, 0x69 },
-    { 0x4b, 0x65, 0x0d, 0xc1, 0xee },
-    { 0x4c, 0xbb, 0xf5, 0x5b, 0x23 },
-    { 0x51, 0x67, 0x67, 0xc5, 0xe0 },
-    { 0x53, 0x94, 0xe1, 0x75, 0xbf },
-    { 0x57, 0x2c, 0x8b, 0x31, 0xae },
-    { 0x63, 0xdb, 0x4c, 0x5b, 0x4a },
-    { 0x7b, 0x1e, 0x5e, 0x2b, 0x57 },
-    { 0x85, 0xf3, 0x85, 0xa0, 0xe0 },
-    { 0xab, 0x1e, 0xe7, 0x7b, 0x72 },
-    { 0xab, 0x36, 0xe3, 0xeb, 0x76 },
-    { 0xb1, 0xb8, 0xf9, 0x38, 0x03 },
-    { 0xb8, 0x5d, 0xd8, 0x53, 0xbd },
-    { 0xbf, 0x92, 0xc3, 0xb0, 0xe2 },
-    { 0xcf, 0x1a, 0xb2, 0xf8, 0x0a },
-    { 0xec, 0xa0, 0xcf, 0xb3, 0xff },
-    { 0xfc, 0x95, 0xa9, 0x87, 0x35 }
-};
-
 /*****************************************************************************
- * CSSDecryptDiscKey
+ * DecryptDiscKey
  *****************************************************************************
  * Decryption of the disc key with player keys if they are available.
  * Try to decrypt the disc key from every position with every player key.
@@ -836,12 +895,46 @@
  * p_struct_disckey: the 2048 byte DVD_STRUCT_DISCKEY data
  * p_disc_key: result, the 5 byte disc key
  *****************************************************************************/
-static int CSSDecryptDiscKey( u8 const *p_struct_disckey, 
-                              dvd_key_t p_disc_key )
+static int DecryptDiscKey( u8 const *p_struct_disckey, dvd_key_t p_disc_key )
 {
     u8 p_verify[KEY_SIZE];
     int i, n = 0;
 
+    static const dvd_key_t player_keys[] = 
+    {
+        { 0x01, 0xaf, 0xe3, 0x12, 0x80 },
+        { 0x12, 0x11, 0xca, 0x04, 0x3b },
+        { 0x14, 0x0c, 0x9e, 0xd0, 0x09 },
+        { 0x14, 0x71, 0x35, 0xba, 0xe2 },
+        { 0x1a, 0xa4, 0x33, 0x21, 0xa6 },
+        { 0x26, 0xec, 0xc4, 0xa7, 0x4e },
+        { 0x2c, 0xb2, 0xc1, 0x09, 0xee },
+        { 0x2f, 0x25, 0x9e, 0x96, 0xdd },
+        { 0x33, 0x2f, 0x49, 0x6c, 0xe0 },
+        { 0x35, 0x5b, 0xc1, 0x31, 0x0f },
+        { 0x36, 0x67, 0xb2, 0xe3, 0x85 },
+        { 0x39, 0x3d, 0xf1, 0xf1, 0xbd },
+        { 0x3b, 0x31, 0x34, 0x0d, 0x91 },
+        { 0x45, 0xed, 0x28, 0xeb, 0xd3 },
+        { 0x48, 0xb7, 0x6c, 0xce, 0x69 },
+        { 0x4b, 0x65, 0x0d, 0xc1, 0xee },
+        { 0x4c, 0xbb, 0xf5, 0x5b, 0x23 },
+        { 0x51, 0x67, 0x67, 0xc5, 0xe0 },
+        { 0x53, 0x94, 0xe1, 0x75, 0xbf },
+        { 0x57, 0x2c, 0x8b, 0x31, 0xae },
+        { 0x63, 0xdb, 0x4c, 0x5b, 0x4a },
+        { 0x7b, 0x1e, 0x5e, 0x2b, 0x57 },
+        { 0x85, 0xf3, 0x85, 0xa0, 0xe0 },
+        { 0xab, 0x1e, 0xe7, 0x7b, 0x72 },
+        { 0xab, 0x36, 0xe3, 0xeb, 0x76 },
+        { 0xb1, 0xb8, 0xf9, 0x38, 0x03 },
+        { 0xb8, 0x5d, 0xd8, 0x53, 0xbd },
+        { 0xbf, 0x92, 0xc3, 0xb0, 0xe2 },
+        { 0xcf, 0x1a, 0xb2, 0xf8, 0x0a },
+        { 0xec, 0xa0, 0xcf, 0xb3, 0xff },
+        { 0xfc, 0x95, 0xa9, 0x87, 0x35 }
+    };
+
     /* Decrypt disc key with player keys from csskeys.h */
     while( n < sizeof(player_keys) / sizeof(dvd_key_t) )
     {
@@ -848,13 +941,13 @@
         for( i = 1; i < 409; i++ )
         {
             /* Check if player key n is the right key for position i. */
-            CSSDecryptKey( 0, player_keys[n], p_struct_disckey + 5 * i,
-                           p_disc_key );
+            DecryptKey( 0, player_keys[n], p_struct_disckey + 5 * i,
+                        p_disc_key );
 
             /* The first part in the struct_disckey block is the 
              * 'disc key' encrypted with it self.  Using this we 
              * can check if we decrypted the correct key. */
-            CSSDecryptKey( 0, p_disc_key, p_struct_disckey, p_verify );
+            DecryptKey( 0, p_disc_key, p_struct_disckey, p_verify );
 
             /* If the position / player key pair worked then return. */
             if( memcmp( p_disc_key, p_verify, 5 ) == 0 )
@@ -864,7 +957,7 @@
         }
         n++;
     }
-    
+
     /* Have tried all combinations of positions and keys, 
      * and we still didn't succeed. */
     return -1;
@@ -871,19 +964,19 @@
 }
 
 /*****************************************************************************
- * CSSDecryptTitleKey
+ * DecryptTitleKey
  *****************************************************************************
  * Decrypt the title key using the disc key.
  * p_disc_key: result, the 5 byte disc key
  * p_titlekey: the encrypted title key, gets overwritten by the decrypted key
  *****************************************************************************/
-static void CSSDecryptTitleKey( dvd_key_t p_disc_key, dvd_key_t p_titlekey )
+static void DecryptTitleKey( dvd_key_t p_disc_key, dvd_key_t p_titlekey )
 {
-    CSSDecryptKey( 0xff, p_disc_key, p_titlekey, p_titlekey );
+    DecryptKey( 0xff, p_disc_key, p_titlekey, p_titlekey );
 }
 
 /*****************************************************************************
- * CSSDiscCrack: brute force disc key
+ * CrackDiscKey: brute force disc key
  * CSS hash reversal function designed by Frank Stevenson
  *****************************************************************************
  * This function uses a big amount of memory to crack the disc key from the   
@@ -898,12 +991,12 @@
 {
     unsigned char key[KEY_SIZE];
 
-    CSSDecryptKey( 0, ckey, hash, key);
+    DecryptKey( 0, ckey, hash, key );
 
     return memcmp( key, ckey, KEY_SIZE );
 }
 
-static int CSSDiscCrack( dvdcss_handle dvdcss, u8 *p_disc_key )
+static int CrackDiscKey( dvdcss_handle dvdcss, u8 *p_disc_key )
 {
     unsigned char B[5] = { 0,0,0,0,0 }; /* Second Stage of mangle cipher */
     unsigned char C[5] = { 0,0,0,0,0 }; /* Output Stage of mangle cipher
@@ -924,11 +1017,13 @@
     unsigned int*  BigTable;    /* LFSR2 startstate indexed by 
                                  * 1,2,5 output byte */
 
+    _dvdcss_debug( dvdcss, "cracking disc key" );
+
     /*
      * Prepare tables for hash reversal
      */
 
-    
+
     /* initialize lookup tables for k[1] */
     K1table = malloc( 65536 * K1TABLEWIDTH );
     memset( K1table, 0 , 65536 * K1TABLEWIDTH );
@@ -1092,15 +1187,15 @@
 }
 
 /*****************************************************************************
- * CSSRecoverKey : (title) key recovery from chiper and plain text
+ * RecoverTitleKey: (title) key recovery from cipher and plain text
  * Function designed by Frank Stevenson
  *****************************************************************************
- * Called from CSSAttack* which are inturn called by CSSTitleCrack.  Given
+ * Called from Attack* which are in turn called by CrackTitleKey.  Given
  * a guessed(?) plain text and the chiper text.  Returns -1 on failure.
  *****************************************************************************/
-static int CSSRecoverKey( int i_start,
-                          u8 const *p_crypted, u8 const *p_decrypted,
-                          u8 const *p_sector_seed, u8 *p_key )
+static int RecoverTitleKey( int i_start, u8 const *p_crypted,
+                            u8 const *p_decrypted,
+                            u8 const *p_sector_seed, u8 *p_key )
 {
     u8 p_buffer[10];
     unsigned int i_t1, i_t2, i_t3, i_t4, i_t5, i_t6;
@@ -1228,7 +1323,7 @@
  * The the copyrigth protection bits are located at 0x14 (bits 0x20 and 0x10).
  * The data of the PES packet begins at 0x15 (if there isn't any PTS/DTS)
  * or at 0x?? if there are both PTS and DTS's.
- * The seed value used with the descrambler key is the 5 bytes at 0x54-0x58.
+ * The seed value used with the unscrambling key is the 5 bytes at 0x54-0x58.
  * The scrabled part of a sector begins at 0x80. 
  *****************************************************************************/
 
@@ -1236,14 +1331,14 @@
 static int i_tries = 0, i_success = 0;
 
 /*****************************************************************************
- * CSSTitleCrack : try to crack title key from the contents of a VOB.
+ * CrackTitleKey: try to crack title key from the contents of a VOB.
  *****************************************************************************
- * This function is called by CSSGetTitleKey to find a title key, if we've
+ * This function is called by _dvdcss_titlekey to find a title key, if we've
  * chosen to crack title key instead of decrypting it with the disc key.
  * The DVD should have been opened and be in an authenticated state.
  * i_pos is the starting sector, i_len is the maximum number of sectors to read
  *****************************************************************************/
-static int CSSTitleCrack( dvdcss_handle dvdcss, int i_pos, int i_len, 
+static int CrackTitleKey( dvdcss_handle dvdcss, int i_pos, int i_len, 
                           dvd_key_t p_titlekey )
 {
     u8       p_buf[0x800];
@@ -1251,21 +1346,32 @@
     int      i_reads = 0;
     int      i_encrypted = 0;
     int      b_stop_scanning = 0;
-    int      i_blocks_read;
+    int      i_ret;
 
+    _dvdcss_debug( dvdcss, "cracking title key" );
+
     i_tries = 0;
     i_success = 0;
 
     do
     {
-        i_pos = _dvdcss_seek( dvdcss, i_pos );
-        i_blocks_read = dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS );
-        
+        i_ret = _dvdcss_seek( dvdcss, i_pos );
+
+        if( i_ret != i_pos )
+        {
+            _dvdcss_error( dvdcss, "seek failed" );
+        }
+
+        i_ret = dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS );
+ 
         /* Either we are at the end of the physical device or the auth
-         * have faild / where not done and we got a read error. */
-        if( !i_blocks_read )
+         * have failed / were not done and we got a read error. */
+        if( i_ret <= 0 )
         {
-            _dvdcss_debug( dvdcss, "read returned 0 (end of device?)" );
+            if( i_ret == 0 )
+            {
+                _dvdcss_debug( dvdcss, "read returned 0 (end of device?)" );
+            }
             break;
         }
 
@@ -1289,12 +1395,12 @@
         {
             i_encrypted++;
 
-            if( CSSAttackPattern(p_buf, i_reads, p_titlekey) > 0 )
+            if( AttackPattern(p_buf, i_reads, p_titlekey) > 0 )
             {
                 b_stop_scanning = 1;
             }
 #if 0
-            if( CSSAttackPadding(p_buf, i_reads, p_titlekey) > 0 )
+            if( AttackPadding(p_buf, i_reads, p_titlekey) > 0 )
             {
                 b_stop_scanning = 1;
             }
@@ -1301,13 +1407,15 @@
 #endif
         }
 
-        i_pos += i_blocks_read;
-        i_len -= i_blocks_read;
-        i_reads += i_blocks_read;
+        i_pos++;
+        i_len--;
+        i_reads++;
 
         /* Emit a progress indication now and then. */
         if( !( i_reads & 0xfff ) ) 
-          _dvdcss_debug( dvdcss, "still working..." );
+        {
+            _dvdcss_debug( dvdcss, "still cracking..." );
+        }
 
         /* Stop after 2000 blocks if we haven't seen any encrypted blocks. */
         if( i_reads >= 2000 && i_encrypted == 0 ) break;
@@ -1350,12 +1458,12 @@
  * Then it guesses that the plain text for first encrypted bytes are
  * a contiuation of that pattern.
  *****************************************************************************/
-static int CSSAttackPattern( u8 const p_sec[0x800], int i_pos, u8 *p_key )
+static int AttackPattern( u8 const p_sec[0x800], int i_pos, u8 *p_key )
 {
     unsigned int i_best_plen = 0;
     unsigned int i_best_p = 0;
     unsigned int i, j;
-    
+
     /* For all cycle length from 2 to 48 */
     for( i = 2 ; i < 0x30 ; i++ )
     {
@@ -1372,7 +1480,7 @@
             }
         }
     }
-    
+
     /* We need at most 10 plain text bytes?, so a make sure that we
      * have at least 20 repeated bytes and that they have cycled at
      * least one time.  */
@@ -1379,18 +1487,17 @@
     if( ( i_best_plen > 3 ) && ( i_best_plen / i_best_p >= 2) )
     {
         int res;
-        
+
         i_tries++;
         memset( p_key, 0, KEY_SIZE );
-        res = CSSRecoverKey( 0,  &p_sec[0x80],
-                             &p_sec[ 0x80 - 
-                                     ( i_best_plen / i_best_p) * i_best_p ],
-                             &p_sec[0x54] /* key_seed */, p_key );
+        res = RecoverTitleKey( 0,  &p_sec[0x80],
+                      &p_sec[ 0x80 - (i_best_plen / i_best_p) * i_best_p ],
+                      &p_sec[0x54] /* key_seed */, p_key );
         i_success += ( res >= 0 );
-#if 0        
+#if 0
         if( res >= 0 )
         {
-            fprintf( stderr, "key is %02x %02x %02x %02x %02x ",
+            fprintf( stderr, "key is %02x:%02x:%02x:%02x:%02x ",
                      p_key[0], p_key[1], p_key[2], p_key[3], p_key[4] );
             fprintf( stderr, "at block %5d pattern len %3d period %3d %s\n", 
                      i_pos, i_best_plen, i_best_p, (res>=0?"y":"n") );
@@ -1398,7 +1505,7 @@
 #endif
         return ( res >= 0 );
     }
-    
+
     return 0;
 }
 
@@ -1416,16 +1523,16 @@
  * Padding stream. This looks like 0x00 00 01 be xx xx ff ff ...
  * where xx xx is the length of the padding stream.
  *****************************************************************************/
-static int CSSAttackPadding( u8 const p_sec[0x800], int i_pos, u8 *p_key )
+static int AttackPadding( u8 const p_sec[0x800], int i_pos, u8 *p_key )
 {
     unsigned int i_pes_length;
-    //static int i_tries = 0, i_success = 0;
+    /*static int i_tries = 0, i_success = 0;*/
 
     i_pes_length = (p_sec[0x12]<<8) | p_sec[0x13];
-    
+
     /* Coverd by the test below but usfull for debuging. */
     if( i_pes_length == 0x800 - 0x14 ) return 0;
-    
+
     /* There must be room for at least 4? bytes of padding stream, 
      * and it must be encrypted.
      * sector size - pack/pes header - padding startcode - padding length */
@@ -1434,7 +1541,7 @@
           p_sec[0x14 + i_pes_length + 1] == 0x00 &&
           p_sec[0x14 + i_pes_length + 2] == 0x01 ) )
     { 
-      fprintf( stderr, "plain %d %02x %02x %02x %02x (type %02x sub %02x)\n", 
+      fprintf( stderr, "plain %d %02x:%02x:%02x:%02x (type %02x sub %02x)\n", 
                0x800 - 0x14 - 4 - 2 - i_pes_length,
                p_sec[0x14 + i_pes_length + 0],
                p_sec[0x14 + i_pes_length + 1],
@@ -1443,7 +1550,7 @@
                p_sec[0x11], p_sec[0x17 + p_sec[0x16]]);
       return 0;
     }
-    
+
     /* If we are here we know that there is a where in the pack a
        encrypted PES header is (startcode + lenght). It's never more 
        than  two packets in the pack, so we 'know' the length. The 
@@ -1450,7 +1557,7 @@
        plaintext at offset (0x14 + i_pes_length) will then be 
        00 00 01 e0/bd/be xx xx, in the case of be the following bytes 
        are also known. */
-    
+
     /* An encrypted SPU PES packet with another encrypted PES packet following.
        Normaly if the following was a padding stream that would be in plain
        text. So it will be another SPU PES packet. */
@@ -1460,7 +1567,7 @@
     {
         i_tries++;
     }
-    
+
     /* A Video PES packet with another encrypted PES packet following.
      * No reason execpt for time stamps to break the data into two packets.
      * So it's likely that the following PES packet is a padding stream. */
@@ -1471,13 +1578,13 @@
    
     if( 1 )
     {
-        //fprintf( stderr, "key is %02x %02x %02x %02x %02x ",
-        //           p_key[0], p_key[1], p_key[2], p_key[3], p_key[4] );
+        /*fprintf( stderr, "key is %02x:%02x:%02x:%02x:%02x ",
+                   p_key[0], p_key[1], p_key[2], p_key[3], p_key[4] );*/
         fprintf( stderr, "at block %5d padding len %4d "
                  "type %02x sub %02x\n",  i_pos, i_pes_length, 
                  p_sec[0x11], p_sec[0x17 + p_sec[0x16]]);
     }
-    
+
     return 0;
 }
 #endif
--- a/src/css.h
+++ b/src/css.h
@@ -2,7 +2,7 @@
  * css.h: Structures for DVD authentication and unscrambling
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: css.h,v 1.5 2002/07/16 22:47:40 sam Exp $
+ * $Id: css.h,v 1.6 2002/08/09 14:10:43 sam Exp $
  *
  * Author: St�phane Borel <[email protected]>
  *
@@ -48,8 +48,9 @@
 /*****************************************************************************
  * Prototypes in css.c
  *****************************************************************************/
-int   CSSTest             ( dvdcss_handle );
-int   CSSGetDiscKey       ( dvdcss_handle );
-int   CSSGetTitleKey      ( dvdcss_handle, int , dvd_key_t );
-int   CSSDescrambleSector ( u8 *, u8 * );
+int   _dvdcss_test        ( dvdcss_handle );
+int   _dvdcss_title       ( dvdcss_handle, int );
+int   _dvdcss_disckey     ( dvdcss_handle );
+int   _dvdcss_titlekey    ( dvdcss_handle, int , dvd_key_t );
+int   _dvdcss_unscramble  ( u8 *, u8 * );
 
--- /dev/null
+++ b/src/device.c
@@ -1,0 +1,668 @@
+/*****************************************************************************
+ * device.h: DVD device access
+ *****************************************************************************
+ * Copyright (C) 1998-2002 VideoLAN
+ * $Id: device.c,v 1.1 2002/08/09 14:10:43 sam Exp $
+ *
+ * Authors: St�phane Borel <[email protected]>
+ *          Samuel Hocevar <[email protected]>
+ *          H�kan Hjort <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>
+#endif
+
+#if defined( WIN32 )
+#   include <io.h>                                                 /* read() */
+#else
+#   include <sys/uio.h>                                      /* struct iovec */
+#endif
+
+#include "dvdcss/dvdcss.h"
+
+#include "common.h"
+#include "css.h"
+#include "libdvdcss.h"
+#include "ioctl.h"
+#include "device.h"
+
+/*****************************************************************************
+ * readv_*: readv() replacements for iovec-impaired C libraries
+ *****************************************************************************/
+#if defined( WIN32 )
+static inline int readv( int i_fd, struct iovec * p_iovec, int i_count )
+{
+    int i_index, i_len, i_total = 0;
+    unsigned char *p_base;
+    int i_bytes;
+
+    for( i_index = i_count; i_index; i_index-- )
+    {
+        i_len  = p_iovec->iov_len;
+        p_base = p_iovec->iov_base;
+
+        /* Loop is unrolled one time to spare the (i_bytes <= 0) test */
+
+        if( i_len > 0 )
+        {
+            i_bytes = read( i_fd, p_base, i_len );
+
+            if( i_bytes < 0 )
+            {
+                /* One of the reads failed, too bad.
+                   We won't even bother returning the reads that went ok,
+                   and as in the posix spec the file postition is left
+                   unspecified after a failure */
+                return -1;
+            }
+
+            i_total += i_bytes;
+
+            if( i_bytes != i_len )
+            {
+                /* we reached the end of the file or a signal interrupted
+                   the read */
+                return i_total;
+            }
+        }
+
+        p_iovec++;
+    }
+
+    return i_total;
+}
+#endif /* WIN32 */
+
+int _dvdcss_use_ioctls( dvdcss_handle dvdcss )
+{
+#if defined( WIN32 )
+    /* Some one need to implement this for Windows */
+    if( WIN2K )
+    {
+	return 1;	
+    }
+    else
+    {
+	return 1;	
+    }
+#else
+    struct stat fileinfo;
+    int ret;
+
+    ret = fstat( dvdcss->i_fd, &fileinfo );
+    if( ret < 0 )
+    {
+	return 1;  /* What to do?  Be conservative and try to use the ioctls */
+    }
+    
+    /* Complete this list and check that we test for the right things 
+     * (I've assumed for all OSs that 'r', (raw) device, are char devices
+     *  and those that don't contain/use an 'r' in the name are block devices)
+     *
+     * Linux    needs a block device
+     * Solaris  needs a char device
+     * Darwin   needs a char device 
+     * OpenBSD  needs a char device
+     * NetBSD   needs a char device
+     * FreeBSD  can use either the block or the char device
+     * BSD/OS   can use either the block or the char device
+     */
+    
+    /* Check if this is a block/char device */
+    if( S_ISBLK( fileinfo.st_mode ) || 
+	S_ISCHR( fileinfo.st_mode ) )
+    {
+	return 1;
+    }
+    else
+    {
+	return 0;
+    }
+#endif
+}
+
+int _dvdcss_open ( dvdcss_handle dvdcss )
+{
+    char *psz_device = dvdcss->psz_device;
+
+#if defined( WIN32 )
+    if( WIN2K )
+    {
+        char psz_dvd[7];
+        _snprintf( psz_dvd, 7, "\\\\.\\%c:", psz_device[0] );
+
+        /* To have access to ioctls, we need read and write access to the
+         * device. This is only allowed if you have administrator priviledges
+         * so we allow for a fallback method where ioctls are not available but
+         * we at least have read access to the device.
+         * (See Microsoft Q241374: Read and Write Access Required for SCSI
+         * Pass Through Requests) */
+        (HANDLE) dvdcss->i_fd =
+                CreateFile( psz_dvd, GENERIC_READ | GENERIC_WRITE,
+                                FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                NULL, OPEN_EXISTING,
+                                FILE_FLAG_RANDOM_ACCESS, NULL );
+
+        if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
+            (HANDLE) dvdcss->i_fd =
+                    CreateFile( psz_dvd, GENERIC_READ, FILE_SHARE_READ,
+                                    NULL, OPEN_EXISTING,
+                                    FILE_FLAG_RANDOM_ACCESS, NULL );
+
+        if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
+        {
+            _dvdcss_error( dvdcss, "failed opening device" );
+            return -1;
+        }
+    }
+    else
+    {
+        dvdcss->i_fd = _win32_dvdcss_aopen( psz_device[0], dvdcss );
+        if( dvdcss->i_fd == -1 )
+        {
+            _dvdcss_error( dvdcss, "failed opening device" );
+            return -1;
+        }
+    }
+
+    /* initialise readv temporary buffer */
+    dvdcss->p_readv_buffer   = NULL;
+    dvdcss->i_readv_buf_size = 0;
+
+#else
+    dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, 0 );
+
+    if( dvdcss->i_fd == -1 )
+    {
+        _dvdcss_error( dvdcss, "failed opening device" );
+        return -1;
+    }
+
+#endif
+
+    return 0;
+}
+
+#ifndef WIN32
+int _dvdcss_raw_open ( dvdcss_handle dvdcss, char *psz_device )
+{
+    dvdcss->i_raw_fd = open( psz_device, 0 );
+
+    if( dvdcss->i_raw_fd == -1 )
+    {
+        _dvdcss_error( dvdcss, "failed opening raw device, continuing" );
+        return -1;
+    }
+    else
+    {
+        dvdcss->i_read_fd = dvdcss->i_raw_fd;
+    }
+
+    return 0;
+}
+#endif
+
+int _dvdcss_close ( dvdcss_handle dvdcss )
+{
+#if defined( WIN32 )
+    if( WIN2K )
+    {
+        CloseHandle( (HANDLE) dvdcss->i_fd );
+    }
+    else
+    {
+        _win32_dvdcss_aclose( dvdcss->i_fd );
+    }
+
+    /* Free readv temporary buffer */
+    if( dvdcss->p_readv_buffer )
+    {
+        free( dvdcss->p_readv_buffer );
+        dvdcss->p_readv_buffer   = NULL;
+        dvdcss->i_readv_buf_size = 0;
+    }
+
+#else
+    close( dvdcss->i_fd );
+
+    if( dvdcss->i_raw_fd >= 0 )
+    {
+        close( dvdcss->i_raw_fd );
+        dvdcss->i_raw_fd = -1;
+    }
+
+#endif
+
+    return 0;
+}
+
+int _dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks )
+{
+#if defined( WIN32 )
+    dvdcss->i_seekpos = i_blocks;
+
+    if( WIN2K )
+    {
+        LARGE_INTEGER li_read;
+
+#ifndef INVALID_SET_FILE_POINTER
+#define INVALID_SET_FILE_POINTER ((DWORD)-1)
+#endif
+
+        li_read.QuadPart = (LONGLONG)i_blocks * DVDCSS_BLOCK_SIZE;
+
+        li_read.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd,
+                                          li_read.LowPart,
+                                          &li_read.HighPart, FILE_BEGIN );
+        if( (li_read.LowPart == INVALID_SET_FILE_POINTER)
+            && GetLastError() != NO_ERROR)
+        {
+            li_read.QuadPart = -DVDCSS_BLOCK_SIZE;
+        }
+
+        li_read.QuadPart /= DVDCSS_BLOCK_SIZE;
+        return (int)li_read.QuadPart;
+    }
+    else
+    {
+        return ( _win32_dvdcss_aseek( dvdcss->i_fd, i_blocks, SEEK_SET ) );
+    }
+#else
+    off_t   i_read;
+
+    dvdcss->i_seekpos = i_blocks;
+
+    i_read = lseek( dvdcss->i_read_fd,
+                    (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET );
+
+    if( i_read < 0 )
+    {
+        _dvdcss_error( dvdcss, "seek error" );
+    }
+
+    return i_read / DVDCSS_BLOCK_SIZE;
+#endif
+
+}
+
+int _dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer, int i_blocks )
+{
+#if defined( WIN32 ) 
+    if( WIN2K )
+    {
+        int i_bytes;
+
+        if( !ReadFile( (HANDLE) dvdcss->i_fd, p_buffer,
+                  i_blocks * DVDCSS_BLOCK_SIZE,
+                  (LPDWORD)&i_bytes, NULL ) )
+        {
+            return -1;
+        }
+        return i_bytes / DVDCSS_BLOCK_SIZE;
+    }
+    else
+    {
+        return _win32_dvdcss_aread( dvdcss->i_fd, p_buffer, i_blocks );
+    }
+
+#else
+    int i_ret;
+    /* TODO: partial reads are wrong,i.e 2200/2048 = 1 
+     * but the location has advanced 2200 bytes (lseek possition that is) */
+    i_ret = read( dvdcss->i_read_fd, p_buffer,
+                  (off_t)i_blocks * DVDCSS_BLOCK_SIZE );
+    if( i_ret < 0 )
+    {
+        _dvdcss_error( dvdcss, "read error" );
+        return i_ret;
+    }
+
+    return i_ret / DVDCSS_BLOCK_SIZE;
+#endif
+
+}
+
+int _dvdcss_readv ( dvdcss_handle dvdcss, struct iovec *p_iovec, int i_blocks )
+{
+    int i_read;
+
+#if defined( WIN32 )
+    /* Check the size of the readv temp buffer, just in case we need to
+     * realloc something bigger */
+    if( dvdcss->i_readv_buf_size < i_blocks * DVDCSS_BLOCK_SIZE )
+    {
+        dvdcss->i_readv_buf_size = i_blocks * DVDCSS_BLOCK_SIZE;
+
+        if( dvdcss->p_readv_buffer ) free( dvdcss->p_readv_buffer );
+
+        /* Allocate a buffer which will be used as a temporary storage
+         * for readv */
+        dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
+        if( !dvdcss->p_readv_buffer )
+        {
+            _dvdcss_error( dvdcss, " failed (readv)" );
+            return -1;
+        }
+    }
+
+    i_read = _win32_dvdcss_readv( dvdcss->i_fd, p_iovec, i_blocks,
+                                  dvdcss->p_readv_buffer );
+    return i_read;
+
+#else
+    i_read = readv( dvdcss->i_read_fd, p_iovec, i_blocks );
+    return i_read / DVDCSS_BLOCK_SIZE;
+
+#endif
+}
+
+
+#if defined( WIN32 )
+
+/*****************************************************************************
+ * _win32_dvdcss_readv: vectored read using ReadFile for Win2K and
+ *                      _win32_dvdcss_aread for win9x
+ *****************************************************************************/
+int _win32_dvdcss_readv( int i_fd, struct iovec *p_iovec,
+                         int i_num_buffers, char *p_tmp_buffer )
+{
+    int i_index;
+    int i_blocks, i_blocks_total = 0;
+
+    for( i_index = i_num_buffers; i_index; i_index-- )
+    {
+        i_blocks_total += p_iovec[i_index-1].iov_len; 
+    }
+
+    if( i_blocks_total <= 0 ) return 0;
+
+    i_blocks_total /= DVDCSS_BLOCK_SIZE;
+
+    if( WIN2K )
+    {
+        unsigned long int i_bytes;
+        if( !ReadFile( (HANDLE)i_fd, p_tmp_buffer,
+                       i_blocks_total * DVDCSS_BLOCK_SIZE, &i_bytes, NULL ) )
+        {
+            return -1;
+            /* The read failed... too bad.
+               As in the posix spec the file postition is left
+               unspecified after a failure */
+        }
+        i_blocks = i_bytes / DVDCSS_BLOCK_SIZE;
+    }
+    else /* Win9x */
+    {
+        i_blocks = _win32_dvdcss_aread( i_fd, p_tmp_buffer, i_blocks_total );
+        if( i_blocks < 0 )
+        {
+            return -1;  /* idem */
+        }
+    }
+
+    /* We just have to copy the content of the temp buffer into the iovecs */
+    i_index = 0;
+    i_blocks_total = i_blocks;
+    while( i_blocks_total > 0 )
+    {
+        memcpy( p_iovec[i_index].iov_base,
+                &p_tmp_buffer[(i_blocks - i_blocks_total) * DVDCSS_BLOCK_SIZE],
+                p_iovec[i_index].iov_len );
+        /* if we read less blocks than asked, we'll just end up copying
+           garbage, this isn't an issue as we return the number of
+           blocks actually read */
+        i_blocks_total -= ( p_iovec[i_index].iov_len / DVDCSS_BLOCK_SIZE );
+        i_index++;
+    } 
+
+    return i_blocks;
+}
+
+/*****************************************************************************
+ * _win32_dvdcss_aopen: open dvd drive (load aspi and init w32_aspidev
+ *                      structure)
+ *****************************************************************************/
+int _win32_dvdcss_aopen( char c_drive, dvdcss_handle dvdcss )
+{
+    HMODULE hASPI;
+    DWORD dwSupportInfo;
+    struct w32_aspidev *fd;
+    int i, j, i_hostadapters;
+    long (*lpGetSupport)( void );
+    long (*lpSendCommand)( void* );
+     
+    hASPI = LoadLibrary( "wnaspi32.dll" );
+    if( hASPI == NULL )
+    {
+        _dvdcss_error( dvdcss, "unable to load wnaspi32.dll" );
+        return -1;
+    }
+
+    (FARPROC) lpGetSupport = GetProcAddress( hASPI, "GetASPI32SupportInfo" );
+    (FARPROC) lpSendCommand = GetProcAddress( hASPI, "SendASPI32Command" );
+ 
+    if(lpGetSupport == NULL || lpSendCommand == NULL )
+    {
+        _dvdcss_debug( dvdcss, "unable to get aspi function pointers" );
+        FreeLibrary( hASPI );
+        return -1;
+    }
+
+    dwSupportInfo = lpGetSupport();
+
+    if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS )
+    {
+        _dvdcss_debug( dvdcss, "no host adapters found (aspi)" );
+        FreeLibrary( hASPI );
+        return -1;
+    }
+
+    if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP )
+    {
+        _dvdcss_error( dvdcss, "unable to initalize aspi layer" );
+        FreeLibrary( hASPI );
+        return -1;
+    }
+
+    i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) );
+    if( i_hostadapters == 0 )
+    {
+        FreeLibrary( hASPI );
+        return -1;
+    }
+
+    fd = malloc( sizeof( struct w32_aspidev ) );
+    if( fd == NULL )
+    {
+        FreeLibrary( hASPI );
+        return -1;
+    }
+
+    fd->i_blocks = 0;
+    fd->hASPI = (long) hASPI;
+    fd->lpSendCommand = lpSendCommand;
+
+    c_drive = c_drive > 'Z' ? c_drive - 'a' : c_drive - 'A';
+
+    for( i = 0; i < i_hostadapters; i++ )
+    {
+        for( j = 0; j < 15; j++ )
+        {
+            struct SRB_GetDiskInfo srbDiskInfo;
+
+            srbDiskInfo.SRB_Cmd         = SC_GET_DISK_INFO;
+            srbDiskInfo.SRB_HaId        = i;
+            srbDiskInfo.SRB_Flags       = 0;
+            srbDiskInfo.SRB_Hdr_Rsvd    = 0;
+            srbDiskInfo.SRB_Target      = j;
+            srbDiskInfo.SRB_Lun         = 0;
+
+            lpSendCommand( (void*) &srbDiskInfo );
+
+            if( (srbDiskInfo.SRB_Status == SS_COMP) &&
+                (srbDiskInfo.SRB_Int13HDriveInfo == c_drive) )
+            {
+                fd->i_sid = MAKEWORD( i, j );
+                return (int) fd;
+            }
+        }
+    }
+
+    free( (void*) fd );
+    FreeLibrary( hASPI );
+    _dvdcss_debug( dvdcss, "unable to get haid and target (aspi)" );
+    return( -1 );        
+}
+
+/*****************************************************************************
+ * _win32_dvdcss_aclose: close dvd drive (unload aspi and free w32_aspidev
+ *                       structure)
+ *****************************************************************************/
+int _win32_dvdcss_aclose( int i_fd )
+{
+    struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
+
+    FreeLibrary( (HMODULE) fd->hASPI );
+    free( (void*) i_fd );
+
+    return 0;
+}
+
+/*****************************************************************************
+ * _win32_dvdcss_aseek: aspi version of _dvdcss_seek
+ * 
+ * returns the number of blocks read.
+ *****************************************************************************/
+int _win32_dvdcss_aseek( int i_fd, int i_blocks, int i_method )
+{
+    int i_old_blocks;
+    char sz_buf[ DVDCSS_BLOCK_SIZE ];
+    struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
+    
+    i_old_blocks = fd->i_blocks;
+    fd->i_blocks = i_blocks;
+
+    if( _win32_dvdcss_aread( i_fd, sz_buf, 1 ) == -1 )
+    {
+        fd->i_blocks = i_old_blocks;
+        return -1;
+    }
+
+    (fd->i_blocks)--;
+
+    return fd->i_blocks;
+}
+
+/*****************************************************************************
+ * _win32_dvdcss_aread: aspi version of _dvdcss_read
+ *
+ * returns the number of blocks read.
+ *****************************************************************************/
+int _win32_dvdcss_aread( int i_fd, void *p_data, int i_blocks )
+{
+    HANDLE hEvent;
+    struct SRB_ExecSCSICmd ssc;
+    struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
+
+    /* Create the transfer completion event */
+    hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
+    if( hEvent == NULL )
+    {
+        return -1;
+    }
+
+    memset( &ssc, 0, sizeof( ssc ) );
+
+    ssc.SRB_Cmd         = SC_EXEC_SCSI_CMD;
+    ssc.SRB_Flags       = SRB_DIR_IN | SRB_EVENT_NOTIFY;
+    ssc.SRB_HaId        = LOBYTE( fd->i_sid );
+    ssc.SRB_Target      = HIBYTE( fd->i_sid );
+    ssc.SRB_SenseLen    = SENSE_LEN;
+    
+    ssc.SRB_PostProc = (LPVOID) hEvent;
+    ssc.SRB_BufPointer  = p_data;
+    ssc.SRB_CDBLen      = 12;
+    
+    ssc.CDBByte[0]      = 0xA8; /* RAW */
+    ssc.CDBByte[2]      = (UCHAR) (fd->i_blocks >> 24);
+    ssc.CDBByte[3]      = (UCHAR) (fd->i_blocks >> 16) & 0xff;
+    ssc.CDBByte[4]      = (UCHAR) (fd->i_blocks >> 8) & 0xff;
+    ssc.CDBByte[5]      = (UCHAR) (fd->i_blocks) & 0xff;
+    
+    /* We have to break down the reads into 64kb pieces (ASPI restriction) */
+    if( i_blocks > 32 )
+    {
+        ssc.SRB_BufLen = 32 * DVDCSS_BLOCK_SIZE;
+        ssc.CDBByte[9] = 32;
+        fd->i_blocks  += 32;
+
+        /* Initiate transfer */  
+        ResetEvent( hEvent );
+        fd->lpSendCommand( (void*) &ssc );
+
+        /* transfer the next 64kb (_win32_dvdcss_aread is called recursively)
+         * We need to check the status of the read on return */
+        if( _win32_dvdcss_aread( i_fd, (u8*) p_data + 32 * DVDCSS_BLOCK_SIZE,
+                                 i_blocks - 32) < 0 )
+        {
+            return -1;
+        }
+    }
+    else
+    {
+        /* This is the last transfer */
+        ssc.SRB_BufLen   = i_blocks * DVDCSS_BLOCK_SIZE;
+        ssc.CDBByte[9]   = (UCHAR) i_blocks;
+        fd->i_blocks += i_blocks;
+
+        /* Initiate transfer */  
+        ResetEvent( hEvent );
+        fd->lpSendCommand( (void*) &ssc );
+
+    }
+
+    /* If the command has still not been processed, wait until it's finished */
+    if( ssc.SRB_Status == SS_PENDING )
+    {
+        WaitForSingleObject( hEvent, INFINITE );
+    }
+    CloseHandle( hEvent );
+
+    /* check that the transfer went as planned */
+    if( ssc.SRB_Status != SS_COMP )
+    {
+      return -1;
+    }
+
+    return i_blocks;
+}
+
+#endif
+
--- /dev/null
+++ b/src/device.h
@@ -1,0 +1,68 @@
+/*****************************************************************************
+ * device.h: DVD device access
+ *****************************************************************************
+ * Copyright (C) 1998-2002 VideoLAN
+ * $Id: device.h,v 1.1 2002/08/09 14:10:43 sam Exp $
+ *
+ * Authors: St�phane Borel <[email protected]>
+ *          Samuel Hocevar <[email protected]>
+ *          H�kan Hjort <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * iovec structure: vectored data entry
+ *****************************************************************************/
+#if defined( WIN32 )
+#   include <io.h>                                                 /* read() */
+#else
+#   include <sys/uio.h>                                      /* struct iovec */
+#endif
+
+#if defined( WIN32 )
+struct iovec
+{
+    void *iov_base;     /* Pointer to data. */
+    size_t iov_len;     /* Length of data.  */
+};
+#endif
+
+/*****************************************************************************
+ * Device reading prototypes
+ *****************************************************************************/
+int _dvdcss_use_ioctls ( dvdcss_handle );
+int _dvdcss_open       ( dvdcss_handle );
+int _dvdcss_close      ( dvdcss_handle );
+int _dvdcss_readv      ( dvdcss_handle, struct iovec *, int );
+
+/*****************************************************************************
+ * Device reading prototypes, win32 specific
+ *****************************************************************************/
+#ifdef WIN32
+int _win32_dvdcss_readv  ( int, struct iovec *, int, char * );
+int _win32_dvdcss_aopen  ( char, dvdcss_handle );
+int _win32_dvdcss_aclose ( int );
+int _win32_dvdcss_aseek  ( int, int, int );
+int _win32_dvdcss_aread  ( int, void *, int );
+#endif
+
+/*****************************************************************************
+ * Device reading prototypes, raw-device specific
+ *****************************************************************************/
+#ifndef WIN32
+int _dvdcss_raw_open     ( dvdcss_handle, char * );
+#endif
+
--- a/src/dvdcss/Makefile.in
+++ b/src/dvdcss/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -68,6 +68,7 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_LIB = @EXTRA_LIB@
+EXTRA_SOURCES = @EXTRA_SOURCES@
 LIBTOOL = @LIBTOOL@
 LN_S = @LN_S@
 MAKEINFO = @MAKEINFO@
--- /dev/null
+++ b/src/error.c
@@ -1,0 +1,57 @@
+/*****************************************************************************
+ * error.c: error management functions
+ *****************************************************************************
+ * Copyright (C) 1998-2002 VideoLAN
+ * $Id: error.c,v 1.1 2002/08/09 14:10:43 sam Exp $
+ *
+ * Author: Samuel Hocevar <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include "dvdcss/dvdcss.h"
+
+#include "common.h"
+#include "css.h"
+#include "libdvdcss.h"
+
+/*****************************************************************************
+ * Error messages
+ *****************************************************************************/
+void _dvdcss_error( dvdcss_handle dvdcss, char *psz_string )
+{
+    if( dvdcss->b_errors )
+    {
+        fprintf( stderr, "libdvdcss error: %s\n", psz_string );
+    }
+
+    dvdcss->psz_error = psz_string;
+}
+
+/*****************************************************************************
+ * Debug messages
+ *****************************************************************************/
+void _dvdcss_debug( dvdcss_handle dvdcss, char *psz_string )
+{
+    if( dvdcss->b_debug )
+    {
+        fprintf( stderr, "libdvdcss debug: %s\n", psz_string );
+    }
+}
+
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -2,7 +2,7 @@
  * libdvdcss.c: DVD reading library.
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.c,v 1.13 2002/07/16 22:47:40 sam Exp $
+ * $Id: libdvdcss.c,v 1.14 2002/08/09 14:10:43 sam Exp $
  *
  * Authors: St�phane Borel <[email protected]>
  *          Samuel Hocevar <[email protected]>
@@ -39,12 +39,6 @@
 #   include <unistd.h>
 #endif
 
-#if defined( WIN32 )
-#   include <io.h>                                                 /* read() */
-#else
-#   include <sys/uio.h>                                      /* struct iovec */
-#endif
-
 #include "dvdcss/dvdcss.h"
 
 #include "common.h"
@@ -51,6 +45,7 @@
 #include "css.h"
 #include "libdvdcss.h"
 #include "ioctl.h"
+#include "device.h"
 
 /*****************************************************************************
  * dvdcss_interface_?: the current libdvdcss version and interface version
@@ -58,87 +53,6 @@
 char * dvdcss_interface_2 = VERSION;
 
 /*****************************************************************************
- * iovec structure: vectored data entry
- *****************************************************************************/
-#if defined( WIN32 )
-struct iovec
-{
-    void *iov_base;     /* Pointer to data. */
-    size_t iov_len;     /* Length of data.  */
-};
-#endif
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int _dvdcss_use_ioctls ( dvdcss_handle dvdcss );
-static int _dvdcss_open  ( dvdcss_handle, char *psz_target );
-static int _dvdcss_close ( dvdcss_handle );
-static int _dvdcss_readv ( dvdcss_handle, struct iovec *p_iovec, int i_blocks );
-
-/*****************************************************************************
- * Local prototypes, win32 specific
- *****************************************************************************/
-#if defined( WIN32 )
-static int _win32_dvdcss_readv  ( int i_fd, struct iovec *p_iovec,
-                                  int i_num_buffers, char *p_tmp_buffer );
-static int _win32_dvdcss_aopen  ( char c_drive, dvdcss_handle dvdcss );
-static int _win32_dvdcss_aclose ( int i_fd );
-static int _win32_dvdcss_aseek  ( int i_fd, int i_blocks, int i_method );
-static int _win32_dvdcss_aread  ( int i_fd, void *p_data, int i_blocks );
-#else
-static int _dvdcss_raw_open     ( dvdcss_handle, char *psz_target );
-#endif
-
-/*****************************************************************************
- * readv_*: readv() replacements for iovec-impaired C libraries
- *****************************************************************************/
-#if defined( WIN32 )
-static inline int readv( int i_fd, struct iovec *p_iovec, int i_count )
-{
-    int i_index, i_len, i_total = 0;
-    unsigned char *p_base;
-    int i_bytes;
-
-    for( i_index = i_count; i_index; i_index-- )
-    {
-
-        i_len  = p_iovec->iov_len;
-        p_base = p_iovec->iov_base;
-
-        /* Loop is unrolled one time to spare the (i_bytes <= 0) test */
-
-        if( i_len > 0 )
-        {
-            i_bytes = read( i_fd, p_base, i_len );
-
-            if( i_bytes < 0 )
-            {
-                /* One of the reads failed, too bad.
-                   We won't even bother returning the reads that went ok,
-                   and as in the posix spec the file postition is left
-                   unspecified after a failure */
-                return -1;
-            }
-
-            i_total += i_bytes;
-
-            if( i_bytes != i_len )
-            {
-                /* we reached the end of the file or a signal interrupted
-                   the read */
-                return i_total;
-            }
-        }
-
-        p_iovec++;
-    }
-
-    return i_total;
-}
-#endif /* WIN32 */
-
-/*****************************************************************************
  * dvdcss_open: initialize library, open a DVD device, crack CSS key
  *****************************************************************************/
 extern dvdcss_handle dvdcss_open ( char *psz_target )
@@ -153,7 +67,9 @@
 
     dvdcss_handle dvdcss;
 
-    /* Allocate the library structure */
+    /*
+     *  Allocate the library structure
+     */
     dvdcss = malloc( sizeof( struct dvdcss_s ) );
     if( dvdcss == NULL )
     {
@@ -160,17 +76,38 @@
         return NULL;
     }
 
-    /* Initialize structure with default values */
+    /*
+     *  Initialize structure with default values
+     */
 #ifndef WIN32
     dvdcss->i_raw_fd = -1;
 #endif
     dvdcss->p_titles = NULL;
+    dvdcss->psz_device = (char *)strdup( psz_target );
     dvdcss->psz_error = "no error";
     dvdcss->i_method = DVDCSS_METHOD_KEY;
     dvdcss->b_debug = 0;
-    dvdcss->b_errors = 1;
+    dvdcss->b_errors = 0;
 
-    /* Find method from DVDCSS_METHOD environment variable */
+    /*
+     *  Find verbosity from DVDCSS_VERBOSE environment variable
+     */
+    if( psz_verbose != NULL )
+    {
+        switch( atoi( psz_verbose ) )
+        {
+        case 2:
+            dvdcss->b_debug = 1;
+        case 1:
+            dvdcss->b_errors = 1;
+        case 0:
+            break;
+        }
+    }
+
+    /*
+     *  Find method from DVDCSS_METHOD environment variable
+     */
     if( psz_method != NULL )
     {
         if( !strncmp( psz_method, "key", 4 ) )
@@ -189,66 +126,53 @@
         {
             _dvdcss_error( dvdcss, "unknown decrypt method, please choose "
                                    "from 'title', 'key' or 'disc'" );
+            free( dvdcss->psz_device );
             free( dvdcss );
             return NULL;
         }
     }
 
-    /* Find verbosity from DVDCSS_VERBOSE environment variable */
-    if( psz_verbose != NULL )
-    {
-        switch( atoi( psz_verbose ) )
-        {
-        case 0:
-            dvdcss->b_errors = 0;
-            break;
-        case 1:
-            break;
-        case 2:
-            dvdcss->b_debug = 1;
-            break;
-        default:
-            _dvdcss_error( dvdcss, "unknown verbose level, please choose "
-                                   "from '0', '1' or '2'" );
-            free( dvdcss );
-            return NULL;
-            break;
-        }
-    }
-
-    /* Open device */
-    i_ret = _dvdcss_open( dvdcss, psz_target );
+    /*
+     *  Open device
+     */
+    i_ret = _dvdcss_open( dvdcss );
     if( i_ret < 0 )
     {
+        free( dvdcss->psz_device );
         free( dvdcss );
         return NULL;
     }
     
-    dvdcss->b_encrypted = 1; /* Assume the worst */
+    dvdcss->b_scrambled = 1; /* Assume the worst */
     dvdcss->b_ioctls = _dvdcss_use_ioctls( dvdcss );
 
     if( dvdcss->b_ioctls )
     {
-        i_ret = CSSTest( dvdcss );
+        i_ret = _dvdcss_test( dvdcss );
 	if( i_ret < 0 )
 	{
 	    /* Disable the CSS ioctls and hope that it works? */
+            _dvdcss_debug( dvdcss,
+                           "could not check whether the disc was scrambled" );
 	    dvdcss->b_ioctls = 0;
 	}
 	else
 	{
-	    dvdcss->b_encrypted = i_ret;
+            _dvdcss_debug( dvdcss, i_ret ? "disc is scrambled"
+                                         : "disc is unscrambled" );
+	    dvdcss->b_scrambled = i_ret;
 	}
     }
 
     /* If disc is CSS protected and the ioctls work, authenticate the drive */
-    if( dvdcss->b_encrypted && dvdcss->b_ioctls )
+    if( dvdcss->b_scrambled && dvdcss->b_ioctls )
     {
-        i_ret = CSSGetDiscKey( dvdcss );
+        i_ret = _dvdcss_disckey( dvdcss );
 
         if( i_ret < 0 )
         {
             _dvdcss_close( dvdcss );
+            free( dvdcss->psz_device );
             free( dvdcss );
             return NULL;
         }
@@ -283,7 +207,7 @@
        || ( i_flags & DVDCSS_SEEK_KEY ) )
     {
         /* check the title key */
-        if( dvdcss_title( dvdcss, i_blocks ) ) 
+        if( _dvdcss_title( dvdcss, i_blocks ) ) 
         {
             return -1;
         }
@@ -300,82 +224,15 @@
  *****************************************************************************/
 extern int dvdcss_title ( dvdcss_handle dvdcss, int i_block )
 {
-    dvd_title_t *p_title;
-    dvd_title_t *p_newtitle;
-    dvd_key_t    p_title_key;
-    int          i_ret;
-
-    if( ! dvdcss->b_encrypted )
+    fprintf( stderr, "WARNING: dvdcss_title() is DEPRECATED\n" );
+    if( ! dvdcss->b_scrambled )
     {
         return 0;
     }
 
-    /* Check if we've already cracked this key */
-    p_title = dvdcss->p_titles;
-    while( p_title != NULL
-            && p_title->p_next != NULL
-            && p_title->p_next->i_startlb <= i_block )
-    {
-        p_title = p_title->p_next;
-    }
-
-    if( p_title != NULL
-         && p_title->i_startlb == i_block )
-    {
-        /* We've already cracked this key, nothing to do */
-        memcpy( dvdcss->css.p_title_key, p_title->p_key, sizeof(dvd_key_t) );
-        return 0;
-    }
-
-    /* Crack or decrypt CSS title key for current VTS */
-    i_ret = CSSGetTitleKey( dvdcss, i_block, p_title_key );
-
-    if( i_ret < 0 )
-    {
-        _dvdcss_error( dvdcss, "fatal error in vts css key" );
-        return i_ret;
-    }
-    else if( i_ret == 0 )
-    {
-        _dvdcss_debug( dvdcss, "unencrypted title" );
-        /* Still store this in the cache, so we don't need to check again. */
-    }
-
-    /* Find our spot in the list */
-    p_newtitle = NULL;
-    p_title = dvdcss->p_titles;
-    while( ( p_title != NULL ) && ( p_title->i_startlb < i_block ) )
-    {
-        p_newtitle = p_title;
-        p_title = p_title->p_next;
-    }
-
-    /* Save the found title */
-    p_title = p_newtitle;
-
-    /* Write in the new title and its key */
-    p_newtitle = malloc( sizeof( dvd_title_t ) );
-    p_newtitle->i_startlb = i_block;
-    memcpy( p_newtitle->p_key, p_title_key, KEY_SIZE );
-
-    /* Link it at the head of the (possibly empty) list */
-    if( p_title == NULL )
-    {
-        p_newtitle->p_next = dvdcss->p_titles;
-        dvdcss->p_titles = p_newtitle;
-    }
-    /* Link the new title inside the list */
-    else
-    {
-        p_newtitle->p_next = p_title->p_next;
-        p_title->p_next = p_newtitle;
-    }
-
-    memcpy( dvdcss->css.p_title_key, p_title_key, KEY_SIZE );
-    return 0;
+    return _dvdcss_title( dvdcss, i_block );
 }
 
-#define Pkey dvdcss->css.p_title_key
 /*****************************************************************************
  * dvdcss_read: read data from the device, decrypt if requested
  *****************************************************************************/
@@ -388,13 +245,13 @@
     i_ret = _dvdcss_read( dvdcss, p_buffer, i_blocks );
 
     if( i_ret <= 0
-         || !dvdcss->b_encrypted
+         || !dvdcss->b_scrambled
          || !(i_flags & DVDCSS_READ_DECRYPT) )
     {
         return i_ret;
     }
 
-    if( !( Pkey[0] | Pkey[1] | Pkey[2] | Pkey[3] | Pkey[4] ) ) 
+    if( ! memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) )
     {
         /* For what we believe is an unencrypted title, 
 	 * check that there are no encrypted blocks */
@@ -407,7 +264,7 @@
                 /* or fail completely? return 0; */
 		break;
             }
-            (u8*)p_buffer += DVDCSS_BLOCK_SIZE;
+            p_buffer = (void *) ((u8 *)p_buffer + DVDCSS_BLOCK_SIZE);
         }
     }
     else 
@@ -415,9 +272,9 @@
         /* Decrypt the blocks we managed to read */
         for( i_index = i_ret; i_index; i_index-- )
 	{
-	    CSSDescrambleSector( dvdcss->css.p_title_key, p_buffer );
+	    _dvdcss_unscramble( dvdcss->css.p_title_key, p_buffer );
 	    ((u8*)p_buffer)[0x14] &= 0x8f;
-	    (u8*)p_buffer += DVDCSS_BLOCK_SIZE;
+            p_buffer = (void *) ((u8 *)p_buffer + DVDCSS_BLOCK_SIZE);
 	}
     }
     
@@ -427,28 +284,27 @@
 /*****************************************************************************
  * dvdcss_readv: read data to an iovec structure, decrypt if requested
  *****************************************************************************/
-extern int dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
+extern int dvdcss_readv ( dvdcss_handle dvdcss, void *_p_iovec,
                                                 int i_blocks,
                                                 int i_flags )
 {
-#define P_IOVEC ((struct iovec*)p_iovec)
+    struct iovec *p_iovec = (struct iovec *)_p_iovec;
     int i_ret, i_index;
     void *iov_base;
     size_t iov_len;
 
-    i_ret = _dvdcss_readv( dvdcss, P_IOVEC, i_blocks );
+    i_ret = _dvdcss_readv( dvdcss, p_iovec, i_blocks );
 
     if( i_ret <= 0
-         || !dvdcss->b_encrypted
+         || !dvdcss->b_scrambled
          || !(i_flags & DVDCSS_READ_DECRYPT) )
     {
         return i_ret;
     }
 
-
     /* Initialize loop for decryption */
-    iov_base = P_IOVEC->iov_base;
-    iov_len = P_IOVEC->iov_len;
+    iov_base = p_iovec->iov_base;
+    iov_len = p_iovec->iov_len;
 
     /* Decrypt the blocks we managed to read */
     for( i_index = i_ret; i_index; i_index-- )
@@ -461,22 +317,20 @@
 
         while( iov_len == 0 )
         {
-            P_IOVEC++;
-            iov_base = P_IOVEC->iov_base;
-            iov_len = P_IOVEC->iov_len;
+            p_iovec++;
+            iov_base = p_iovec->iov_base;
+            iov_len = p_iovec->iov_len;
         }
 
-        CSSDescrambleSector( dvdcss->css.p_title_key, iov_base );
+        _dvdcss_unscramble( dvdcss->css.p_title_key, iov_base );
         ((u8*)iov_base)[0x14] &= 0x8f;
 
-        (u8*)iov_base += DVDCSS_BLOCK_SIZE;
-        (u8*)iov_len -= DVDCSS_BLOCK_SIZE;
+        iov_base = (void *) ((u8*)iov_base + DVDCSS_BLOCK_SIZE);
+        iov_len -= DVDCSS_BLOCK_SIZE;
     }
 
     return i_ret;
-#undef P_IOVEC
 }
-#undef Pkey
 
 /*****************************************************************************
  * dvdcss_close: close the DVD device and clean up the library
@@ -502,565 +356,9 @@
         return i_ret;
     }
 
+    free( dvdcss->psz_device );
     free( dvdcss );
 
     return 0;
 }
-
-/* Following functions are local */
-
-static int _dvdcss_use_ioctls( dvdcss_handle dvdcss )
-{
-#if defined( WIN32 )
-    /* Some one need to implement this for Windows */
-    if( WIN2K )
-    {
-	return 1;	
-    }
-    else
-    {
-	return 1;	
-    }
-#else
-    struct stat fileinfo;
-    int ret;
-
-    ret = fstat( dvdcss->i_fd, &fileinfo );
-    if( ret < 0 )
-    {
-	return 1;  /* What to do?  Be conservative and try to use the ioctsl */
-    }
-    
-    /* Complete this list and check that we test for the right things 
-     * (I've assumed for all OSs that 'r', (raw) device, are char devices
-     *  and those that don't contain/use an 'r' in the name are block devices)
-     *
-     * Linux    needs a block device
-     * Solaris  needs a char device
-     * Darwin   needs a char device 
-     * OpenBSD  needs a char device
-     * NetBSD   needs a char device
-     * FreeBSD  can use either the block or the char device
-     * BSD/OS   can use either the block or the char device
-     */
-    
-    /* Check if this is a block/char device */
-    if( S_ISBLK( fileinfo.st_mode ) || 
-	S_ISCHR( fileinfo.st_mode ) )
-    {
-	return 1;
-    }
-    else
-    {
-	return 0;
-    }
-#endif
-}
-
-static int _dvdcss_open ( dvdcss_handle dvdcss, char *psz_target )
-{
-#if defined( WIN32 )
-    if( WIN2K )
-    {
-        char psz_dvd[7];
-        _snprintf( psz_dvd, 7, "\\\\.\\%c:", psz_target[0] );
-
-        /* To have access to ioctls, we need read and write access to the
-         * device. This is only allowed if you have administrator priviledges
-         * so we allow for a fallback method where ioctls are not available but
-         * we at least have read access to the device.
-         * (See Microsoft Q241374: Read and Write Access Required for SCSI
-         * Pass Through Requests) */
-        (HANDLE) dvdcss->i_fd =
-                CreateFile( psz_dvd, GENERIC_READ | GENERIC_WRITE,
-                                FILE_SHARE_READ | FILE_SHARE_WRITE,
-                                NULL, OPEN_EXISTING,
-                                FILE_FLAG_RANDOM_ACCESS, NULL );
-
-        if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
-            (HANDLE) dvdcss->i_fd =
-                    CreateFile( psz_dvd, GENERIC_READ, FILE_SHARE_READ,
-                                    NULL, OPEN_EXISTING,
-                                    FILE_FLAG_RANDOM_ACCESS, NULL );
-
-        if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
-        {
-            _dvdcss_error( dvdcss, "failed opening device" );
-            return -1;
-        }
-    }
-    else
-    {
-        dvdcss->i_fd = _win32_dvdcss_aopen( psz_target[0], dvdcss );
-        if( dvdcss->i_fd == -1 )
-        {
-            _dvdcss_error( dvdcss, "failed opening device" );
-            return -1;
-        }
-    }
-
-    /* initialise readv temporary buffer */
-    dvdcss->p_readv_buffer   = NULL;
-    dvdcss->i_readv_buf_size = 0;
-
-#else
-    dvdcss->i_fd = dvdcss->i_read_fd = open( psz_target, 0 );
-
-    if( dvdcss->i_fd == -1 )
-    {
-        _dvdcss_error( dvdcss, "failed opening device" );
-        return -1;
-    }
-
-#endif
-
-    return 0;
-}
-
-#ifndef WIN32
-static int _dvdcss_raw_open ( dvdcss_handle dvdcss, char *psz_target )
-{
-    dvdcss->i_raw_fd = open( psz_target, 0 );
-
-    if( dvdcss->i_raw_fd == -1 )
-    {
-        _dvdcss_error( dvdcss, "failed opening raw device, continuing" );
-        return -1;
-    }
-    else
-    {
-        dvdcss->i_read_fd = dvdcss->i_raw_fd;
-    }
-
-    return 0;
-}
-#endif
-
-static int _dvdcss_close ( dvdcss_handle dvdcss )
-{
-#if defined( WIN32 )
-    if( WIN2K )
-    {
-        CloseHandle( (HANDLE) dvdcss->i_fd );
-    }
-    else
-    {
-        _win32_dvdcss_aclose( dvdcss->i_fd );
-    }
-
-    /* Free readv temporary buffer */
-    if( dvdcss->p_readv_buffer )
-    {
-        free( dvdcss->p_readv_buffer );
-        dvdcss->p_readv_buffer   = NULL;
-        dvdcss->i_readv_buf_size = 0;
-    }
-
-#else
-    close( dvdcss->i_fd );
-
-    if( dvdcss->i_raw_fd >= 0 )
-    {
-        close( dvdcss->i_raw_fd );
-        dvdcss->i_raw_fd = -1;
-    }
-
-#endif
-
-    return 0;
-}
-
-int _dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks )
-{
-#if defined( WIN32 )
-    dvdcss->i_seekpos = i_blocks;
-
-    if( WIN2K )
-    {
-        LARGE_INTEGER li_read;
-
-#ifndef INVALID_SET_FILE_POINTER
-#define INVALID_SET_FILE_POINTER ((DWORD)-1)
-#endif
-
-        li_read.QuadPart = (LONGLONG)i_blocks * DVDCSS_BLOCK_SIZE;
-
-        li_read.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd,
-                                          li_read.LowPart,
-                                          &li_read.HighPart, FILE_BEGIN );
-        if( (li_read.LowPart == INVALID_SET_FILE_POINTER)
-            && GetLastError() != NO_ERROR)
-        {
-            li_read.QuadPart = -DVDCSS_BLOCK_SIZE;
-        }
-
-        li_read.QuadPart /= DVDCSS_BLOCK_SIZE;
-        return (int)li_read.QuadPart;
-    }
-    else
-    {
-        return ( _win32_dvdcss_aseek( dvdcss->i_fd, i_blocks, SEEK_SET ) );
-    }
-#else
-    off_t   i_read;
-
-    dvdcss->i_seekpos = i_blocks;
-
-    i_read = lseek( dvdcss->i_read_fd,
-                    (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET );
-
-    return i_read / DVDCSS_BLOCK_SIZE;
-#endif
-
-}
-
-int _dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer, int i_blocks )
-{
-#if defined( WIN32 ) 
-    if( WIN2K )
-    {
-        int i_bytes;
-
-        if( !ReadFile( (HANDLE) dvdcss->i_fd, p_buffer,
-                  i_blocks * DVDCSS_BLOCK_SIZE,
-                  (LPDWORD)&i_bytes, NULL ) )
-        {
-            return -1;
-        }
-        return i_bytes / DVDCSS_BLOCK_SIZE;
-    }
-    else
-    {
-        return _win32_dvdcss_aread( dvdcss->i_fd, p_buffer, i_blocks );
-    }
-
-#else
-    int i_bytes;
-    /* TODO: !!! errors are mangled and disarded (-1/2048 = 0)
-     * and partial reads are wrong,i.e 2200/2048 = 1 
-     * but the location has advanced 2200 bytes (lseek possition that is) */
-    i_bytes = read( dvdcss->i_read_fd, p_buffer,
-                    (size_t)i_blocks * DVDCSS_BLOCK_SIZE );
-    return i_bytes / DVDCSS_BLOCK_SIZE;
-#endif
-
-}
-
-static int _dvdcss_readv ( dvdcss_handle dvdcss, struct iovec *p_iovec,
-                           int i_blocks )
-{
-    int i_read;
-
-#if defined( WIN32 )
-    /* Check the size of the readv temp buffer, just in case we need to
-     * realloc something bigger */
-    if( dvdcss->i_readv_buf_size < i_blocks * DVDCSS_BLOCK_SIZE )
-    {
-        dvdcss->i_readv_buf_size = i_blocks * DVDCSS_BLOCK_SIZE;
-
-        if( dvdcss->p_readv_buffer ) free( dvdcss->p_readv_buffer );
-
-        /* Allocate a buffer which will be used as a temporary storage
-         * for readv */
-        dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
-        if( !dvdcss->p_readv_buffer )
-        {
-            _dvdcss_error( dvdcss, " failed (readv)" );
-            return -1;
-        }
-    }
-
-    i_read = _win32_dvdcss_readv( dvdcss->i_fd, p_iovec, i_blocks,
-                                  dvdcss->p_readv_buffer );
-    return i_read;
-
-#else
-    i_read = readv( dvdcss->i_read_fd, p_iovec, i_blocks );
-    return i_read / DVDCSS_BLOCK_SIZE;
-
-#endif
-}
-
-
-#if defined( WIN32 )
-
-/*****************************************************************************
- * _win32_dvdcss_readv: vectored read using ReadFile for Win2K and
- *                      _win32_dvdcss_aread for win9x
- *****************************************************************************/
-static int _win32_dvdcss_readv( int i_fd, struct iovec *p_iovec,
-                                int i_num_buffers, char *p_tmp_buffer )
-{
-    int i_index;
-    int i_blocks, i_blocks_total = 0;
-
-    for( i_index = i_num_buffers; i_index; i_index-- )
-    {
-        i_blocks_total += p_iovec[i_index-1].iov_len; 
-    }
-
-    if( i_blocks_total <= 0 ) return 0;
-
-    i_blocks_total /= DVDCSS_BLOCK_SIZE;
-
-    if( WIN2K )
-    {
-        unsigned long int i_bytes;
-        if( !ReadFile( (HANDLE)i_fd, p_tmp_buffer,
-                       i_blocks_total * DVDCSS_BLOCK_SIZE, &i_bytes, NULL ) )
-        {
-            return -1;
-            /* The read failed... too bad.
-               As in the posix spec the file postition is left
-               unspecified after a failure */
-        }
-        i_blocks = i_bytes / DVDCSS_BLOCK_SIZE;
-    }
-    else /* Win9x */
-    {
-        i_blocks = _win32_dvdcss_aread( i_fd, p_tmp_buffer, i_blocks_total );
-        if( i_blocks < 0 )
-        {
-            return -1;  /* idem */
-        }
-    }
-
-    /* We just have to copy the content of the temp buffer into the iovecs */
-    i_index = 0;
-    i_blocks_total = i_blocks;
-    while( i_blocks_total > 0 )
-    {
-        memcpy( p_iovec[i_index].iov_base,
-                &p_tmp_buffer[(i_blocks - i_blocks_total) * DVDCSS_BLOCK_SIZE],
-                p_iovec[i_index].iov_len );
-        /* if we read less blocks than asked, we'll just end up copying
-           garbage, this isn't an issue as we return the number of
-           blocks actually read */
-        i_blocks_total -= ( p_iovec[i_index].iov_len / DVDCSS_BLOCK_SIZE );
-        i_index++;
-    } 
-
-    return i_blocks;
-}
-
-/*****************************************************************************
- * _win32_dvdcss_aopen: open dvd drive (load aspi and init w32_aspidev
- *                      structure)
- *****************************************************************************/
-static int _win32_dvdcss_aopen( char c_drive, dvdcss_handle dvdcss )
-{
-    HMODULE hASPI;
-    DWORD dwSupportInfo;
-    struct w32_aspidev *fd;
-    int i, j, i_hostadapters;
-    long (*lpGetSupport)( void );
-    long (*lpSendCommand)( void* );
-     
-    hASPI = LoadLibrary( "wnaspi32.dll" );
-    if( hASPI == NULL )
-    {
-        _dvdcss_error( dvdcss, "unable to load wnaspi32.dll" );
-        return -1;
-    }
-
-    (FARPROC) lpGetSupport = GetProcAddress( hASPI, "GetASPI32SupportInfo" );
-    (FARPROC) lpSendCommand = GetProcAddress( hASPI, "SendASPI32Command" );
- 
-    if(lpGetSupport == NULL || lpSendCommand == NULL )
-    {
-        _dvdcss_debug( dvdcss, "unable to get aspi function pointers" );
-        FreeLibrary( hASPI );
-        return -1;
-    }
-
-    dwSupportInfo = lpGetSupport();
-
-    if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS )
-    {
-        _dvdcss_debug( dvdcss, "no host adapters found (aspi)" );
-        FreeLibrary( hASPI );
-        return -1;
-    }
-
-    if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP )
-    {
-        _dvdcss_error( dvdcss, "unable to initalize aspi layer" );
-        FreeLibrary( hASPI );
-        return -1;
-    }
-
-    i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) );
-    if( i_hostadapters == 0 )
-    {
-        FreeLibrary( hASPI );
-        return -1;
-    }
-
-    fd = malloc( sizeof( struct w32_aspidev ) );
-    if( fd == NULL )
-    {
-        FreeLibrary( hASPI );
-        return -1;
-    }
-
-    fd->i_blocks = 0;
-    fd->hASPI = (long) hASPI;
-    fd->lpSendCommand = lpSendCommand;
-
-    c_drive = c_drive > 'Z' ? c_drive - 'a' : c_drive - 'A';
-
-    for( i = 0; i < i_hostadapters; i++ )
-    {
-        for( j = 0; j < 15; j++ )
-        {
-            struct SRB_GetDiskInfo srbDiskInfo;
-
-            srbDiskInfo.SRB_Cmd         = SC_GET_DISK_INFO;
-            srbDiskInfo.SRB_HaId        = i;
-            srbDiskInfo.SRB_Flags       = 0;
-            srbDiskInfo.SRB_Hdr_Rsvd    = 0;
-            srbDiskInfo.SRB_Target      = j;
-            srbDiskInfo.SRB_Lun         = 0;
-
-            lpSendCommand( (void*) &srbDiskInfo );
-
-            if( (srbDiskInfo.SRB_Status == SS_COMP) &&
-                (srbDiskInfo.SRB_Int13HDriveInfo == c_drive) )
-            {
-                fd->i_sid = MAKEWORD( i, j );
-                return (int) fd;
-            }
-        }
-    }
-
-    free( (void*) fd );
-    FreeLibrary( hASPI );
-    _dvdcss_debug( dvdcss, "unable to get haid and target (aspi)" );
-    return( -1 );        
-}
-
-/*****************************************************************************
- * _win32_dvdcss_aclose: close dvd drive (unload aspi and free w32_aspidev
- *                       structure)
- *****************************************************************************/
-static int _win32_dvdcss_aclose( int i_fd )
-{
-    struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
-
-    FreeLibrary( (HMODULE) fd->hASPI );
-    free( (void*) i_fd );
-
-    return 0;
-}
-
-/*****************************************************************************
- * _win32_dvdcss_aseek: aspi version of _dvdcss_seek
- * 
- * returns the number of blocks read.
- *****************************************************************************/
-static int _win32_dvdcss_aseek( int i_fd, int i_blocks, int i_method )
-{
-    int i_old_blocks;
-    char sz_buf[ DVDCSS_BLOCK_SIZE ];
-    struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
-    
-    i_old_blocks = fd->i_blocks;
-    fd->i_blocks = i_blocks;
-
-    if( _win32_dvdcss_aread( i_fd, sz_buf, 1 ) == -1 )
-    {
-        fd->i_blocks = i_old_blocks;
-        return -1;
-    }
-
-    (fd->i_blocks)--;
-
-    return fd->i_blocks;
-}
-
-/*****************************************************************************
- * _win32_dvdcss_aread: aspi version of _dvdcss_read
- *
- * returns the number of blocks read.
- *****************************************************************************/
-static int _win32_dvdcss_aread( int i_fd, void *p_data, int i_blocks )
-{
-    HANDLE hEvent;
-    struct SRB_ExecSCSICmd ssc;
-    struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
-
-    /* Create the transfer completion event */
-    hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
-    if( hEvent == NULL )
-    {
-        return -1;
-    }
-
-    memset( &ssc, 0, sizeof( ssc ) );
-
-    ssc.SRB_Cmd         = SC_EXEC_SCSI_CMD;
-    ssc.SRB_Flags       = SRB_DIR_IN | SRB_EVENT_NOTIFY;
-    ssc.SRB_HaId        = LOBYTE( fd->i_sid );
-    ssc.SRB_Target      = HIBYTE( fd->i_sid );
-    ssc.SRB_SenseLen    = SENSE_LEN;
-    
-    ssc.SRB_PostProc = (LPVOID) hEvent;
-    ssc.SRB_BufPointer  = p_data;
-    ssc.SRB_CDBLen      = 12;
-    
-    ssc.CDBByte[0]      = 0xA8; /* RAW */
-    ssc.CDBByte[2]      = (UCHAR) (fd->i_blocks >> 24);
-    ssc.CDBByte[3]      = (UCHAR) (fd->i_blocks >> 16) & 0xff;
-    ssc.CDBByte[4]      = (UCHAR) (fd->i_blocks >> 8) & 0xff;
-    ssc.CDBByte[5]      = (UCHAR) (fd->i_blocks) & 0xff;
-    
-    /* We have to break down the reads into 64kb pieces (ASPI restriction) */
-    if( i_blocks > 32 )
-    {
-        ssc.SRB_BufLen = 32 * DVDCSS_BLOCK_SIZE;
-        ssc.CDBByte[9] = 32;
-        fd->i_blocks  += 32;
-
-        /* Initiate transfer */  
-        ResetEvent( hEvent );
-        fd->lpSendCommand( (void*) &ssc );
-
-        /* transfer the next 64kb (_win32_dvdcss_aread is called recursively)
-         * We need to check the status of the read on return */
-        if( _win32_dvdcss_aread( i_fd, (u8*) p_data + 32 * DVDCSS_BLOCK_SIZE,
-                                 i_blocks - 32) < 0 )
-        {
-            return -1;
-        }
-    }
-    else
-    {
-        /* This is the last transfer */
-        ssc.SRB_BufLen   = i_blocks * DVDCSS_BLOCK_SIZE;
-        ssc.CDBByte[9]   = (UCHAR) i_blocks;
-        fd->i_blocks += i_blocks;
-
-        /* Initiate transfer */  
-        ResetEvent( hEvent );
-        fd->lpSendCommand( (void*) &ssc );
-
-    }
-
-    /* If the command has still not been processed, wait until it's finished */
-    if( ssc.SRB_Status == SS_PENDING )
-    {
-        WaitForSingleObject( hEvent, INFINITE );
-    }
-    CloseHandle( hEvent );
-
-    /* check that the transfer went as planned */
-    if( ssc.SRB_Status != SS_COMP )
-    {
-      return -1;
-    }
-
-    return i_blocks;
-}
-
-#endif
 
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -2,7 +2,7 @@
  * private.h: private DVD reading library data
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.h,v 1.2 2002/04/04 14:21:25 sam Exp $
+ * $Id: libdvdcss.h,v 1.3 2002/08/09 14:10:43 sam Exp $
  *
  * Authors: St�phane Borel <[email protected]>
  *          Samuel Hocevar <[email protected]>
@@ -28,28 +28,31 @@
 struct dvdcss_s
 {
     /* File descriptor */
-    int i_fd;
-    int i_seekpos;
+    char * psz_device;
+    int    i_fd;
+    int    i_seekpos;
 
     /* Decryption stuff */
     int          i_method;
     css_t        css;
-    boolean_t    b_ioctls;
-    boolean_t    b_encrypted;
+    int          b_ioctls;
+    int          b_scrambled;
     dvd_title_t *p_titles;
 
     /* Error management */
-    char     *psz_error;
-    boolean_t b_errors;
-    boolean_t b_debug;
+    char * psz_error;
+    int    b_errors;
+    int    b_debug;
 
-#if defined( WIN32 )
-    char *p_readv_buffer;
-    int  i_readv_buf_size;
-#else
-    int i_raw_fd;
-    int i_read_fd;
+#ifdef WIN32
+    char * p_readv_buffer;
+    int    i_readv_buf_size;
 #endif
+
+#ifndef WIN32
+    int    i_raw_fd;
+    int    i_read_fd;
+#endif
 };
 
 /*****************************************************************************
@@ -62,36 +65,9 @@
 /*****************************************************************************
  * Functions used across the library
  *****************************************************************************/
-int _dvdcss_seek  ( dvdcss_handle, int i_blocks );
-int _dvdcss_read  ( dvdcss_handle, void *p_buffer, int i_blocks );
+int  _dvdcss_seek  ( dvdcss_handle, int );
+int  _dvdcss_read  ( dvdcss_handle, void *, int );
 
-/*****************************************************************************
- * Error management
- *****************************************************************************/
-#if defined( _WIN32 ) && defined( _MSC_VER )
-#   define DVDCSS_ERROR( x ) fprintf( stderr, "libdvdcss error: %s\n", x );
-#   define DVDCSS_DEBUG( x ) fprintf( stderr, "libdvdcss debug: %s\n", x );
-#else
-#   define DVDCSS_ERROR( x... ) fprintf( stderr, "libdvdcss error: %s\n", ##x );
-#   define DVDCSS_DEBUG( x... ) fprintf( stderr, "libdvdcss debug: %s\n", ##x );
-#endif
-
-static inline void _dvdcss_error( dvdcss_handle dvdcss, char *psz_string )
-{
-    if( dvdcss->b_errors )
-    {
-        DVDCSS_ERROR( psz_string );
-    }
-
-    dvdcss->psz_error = psz_string;
-}
-
-static inline void _dvdcss_debug( dvdcss_handle dvdcss, char *psz_string )
-{
-    if( dvdcss->b_debug )
-    {
-        DVDCSS_DEBUG( psz_string );
-    }
-}
-
+void _dvdcss_error ( dvdcss_handle, char * );
+void _dvdcss_debug ( dvdcss_handle, char * );
 
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
 
 # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
@@ -69,6 +69,7 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_LIB = @EXTRA_LIB@
+EXTRA_SOURCES = @EXTRA_SOURCES@
 LIBTOOL = @LIBTOOL@
 LN_S = @LN_S@
 MAKEINFO = @MAKEINFO@
--- a/test/csstest.c
+++ b/test/csstest.c
@@ -1,10 +1,12 @@
 /* csstest.c - test program for libdvdcss
  * 
  * Samuel Hocevar <[email protected]> - June 2001
- * Updated on Nov 13th 2001 for libdvdcss version 1.0.0
+ *   Updated on Nov 13th 2001 for libdvdcss version 1.0.0
+ *   Additional error checks on Aug 9th 2002
  *
  * This piece of code is public domain */
 
+#include <stdio.h>
 #include <stdlib.h>
 
 #include <dvdcss/dvdcss.h>
@@ -13,7 +15,7 @@
 #define IsSectorScrambled(buf) (((unsigned char*)(buf))[0x14] & 0x30)
 
 /* Print parts of a 2048 bytes buffer */
-void dumpsector( unsigned char * );
+static void dumpsector( unsigned char * );
 
 int main( int i_argc, char *ppsz_argv[] )
 {
@@ -20,6 +22,7 @@
     dvdcss_handle dvdcss;
     unsigned char p_buffer[ DVDCSS_BLOCK_SIZE ];
     unsigned int  i_sector;
+    int           i_ret;
 
     /* Print version number */
     printf( "cool, I found libdvdcss version %s\n", dvdcss_interface_2 );
@@ -42,14 +45,25 @@
         return -1;
     }
 
-    /* Set the file descriptor at sector i_sector */
-    dvdcss_seek( dvdcss, i_sector, DVDCSS_NOFLAGS );
+    /* Set the file descriptor at sector i_sector and read one sector */
+    i_ret = dvdcss_seek( dvdcss, i_sector, DVDCSS_NOFLAGS );
+    if( i_ret != i_sector )
+    {
+        printf( "seek failed (%s)\n", dvdcss_error( dvdcss ) );
+        dvdcss_close( dvdcss );
+        return i_ret;
+    }
 
-    /* Read one sector */
-    dvdcss_read( dvdcss, p_buffer, 1, DVDCSS_NOFLAGS );
+    i_ret = dvdcss_read( dvdcss, p_buffer, 1, DVDCSS_NOFLAGS );
+    if( i_ret != 1 )
+    {
+        printf( "read failed (%s)\n", dvdcss_error( dvdcss ) );
+        dvdcss_close( dvdcss );
+        return i_ret;
+    }
 
     /* Print the sector */
-    printf( "requested sector:\n" );
+    printf( "requested sector: " );
     dumpsector( p_buffer );
 
     /* Check if sector was encrypted */
@@ -57,13 +71,25 @@
     {
         /* Set the file descriptor position to the previous location */
         /* ... and get the appropriate key for this sector */
-        dvdcss_seek( dvdcss, i_sector, DVDCSS_SEEK_KEY );
+        i_ret = dvdcss_seek( dvdcss, i_sector, DVDCSS_SEEK_KEY );
+        if( i_ret != i_sector )
+        {
+            printf( "seek failed (%s)\n", dvdcss_error( dvdcss ) );
+            dvdcss_close( dvdcss );
+            return i_ret;
+        }
 
         /* Read sector again, and decrypt it on the fly */
-        dvdcss_read( dvdcss, p_buffer, 1, DVDCSS_READ_DECRYPT );
+        i_ret = dvdcss_read( dvdcss, p_buffer, 1, DVDCSS_READ_DECRYPT );
+        if( i_ret != 1 )
+        {
+            printf( "read failed (%s)\n", dvdcss_error( dvdcss ) );
+            dvdcss_close( dvdcss );
+            return i_ret;
+        }
 
         /* Print the decrypted sector */
-        printf( "unscrambled sector:\n" );
+        printf( "unscrambled sector: " );
         dumpsector( p_buffer );
     }
     else
@@ -78,14 +104,14 @@
 }
 
 /* Print parts of a 2048 bytes buffer */
-void dumpsector( unsigned char *p_buffer )
+static void dumpsector( unsigned char *p_buffer )
 {
-    int i_amount = 10;
+    int i_amount = 4;
     for( ; i_amount ; i_amount--, p_buffer++ ) printf( "%.2x", *p_buffer );
-    printf( " ... " );
-    i_amount = 25;
+    printf( "..." );
+    i_amount = 22;
     p_buffer += 200;
     for( ; i_amount ; i_amount--, p_buffer++ ) printf( "%.2x", *p_buffer );
-    printf( " ...\n" );
+    printf( "...\n" );
 }