annotate libdvdread/dvd_reader.c @ 28223:6080184bef59

Do not run mkdir in a subshell.
author diego
date Mon, 05 Jan 2009 00:08:23 +0000
parents 48c1ae64255b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27466
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1 /* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
2 /*
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
3 * Copyright (C) 2001, 2002, 2003 Billy Biggs <vektor@dumbterm.net>,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
4 * Håkan Hjort <d95hjort@dtek.chalmers.se>,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
5 * Björn Englund <d4bjorn@dtek.chalmers.se>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
6 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
7 * Modified for use with MPlayer, changes contained in libdvdread_changes.diff.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
8 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
9 * $Id$
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
10 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or (at
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
14 * your option) any later version.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
15 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful, but
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
19 * General Public License for more details.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
20 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
24 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
25
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
26 #include "config.h"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
27
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
28 #include <sys/types.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
29 #include <sys/stat.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
30 #include <sys/time.h> /* For the timing of dvdcss_title crack. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
31 #include <fcntl.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
32 #include <stdlib.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
33 #include <stdio.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
34 #include <errno.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
35 #include <string.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
36 #include <unistd.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
37 #include <limits.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
38 #include <dirent.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
39
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
40 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__DARWIN__) || defined(__DragonFly__)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
41 #define SYS_BSD 1
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
42 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
43
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
44 #if defined(__sun)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
45 #include <sys/mnttab.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
46 #elif defined(hpux)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
47 #include </usr/conf/h/mnttab.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
48 #elif defined(SYS_BSD)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
49 #include <fstab.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
50 #elif defined(__linux__) || defined(__CYGWIN__)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
51 #include <mntent.h>
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
52 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
53
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
54 #include "dvd_reader.h"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
55 #include "dvd_input.h"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
56 #include "dvd_udf.h"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
57 #include "md5.h"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
58
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
59 #include "dvdread_internal.h"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
60
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
61 #define DEFAULT_UDF_CACHE_LEVEL 0
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
62
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
63 struct dvd_reader_s {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
64 /* Basic information. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
65 int isImageFile;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
66
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
67 /* Hack for keeping track of the css status.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
68 * 0: no css, 1: perhaps (need init of keys), 2: have done init */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
69 int css_state;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
70 int css_title; /* Last title that we have called dvdinpute_title for. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
71
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
72 /* Information required for an image file. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
73 dvd_input_t dev;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
74
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
75 /* Information required for a directory path drive. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
76 char *path_root;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
77
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
78 /* Filesystem cache */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
79 int udfcache_level; /* 0 - turned off, 1 - on */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
80 void *udfcache;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
81
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
82 /* block aligned malloc */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
83 void *align;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
84
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
85 /* error message verbosity level */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
86 int verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
87 };
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
88
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
89 struct dvd_file_s {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
90 /* Basic information. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
91 dvd_reader_t *dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
92
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
93 /* Hack for selecting the right css title. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
94 int css_title;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
95
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
96 /* Information required for an image file. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
97 uint32_t lb_start;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
98 uint32_t seek_pos;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
99
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
100 /* Information required for a directory path drive. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
101 size_t title_sizes[ 9 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
102 dvd_input_t title_devs[ 9 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
103
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
104 /* Calculated at open-time, size in blocks. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
105 ssize_t filesize;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
106 };
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
107
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
108
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
109 #define DVDREAD_VERBOSE_DEFAULT 0
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
110
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
111 int get_verbose(void)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
112 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
113 char *dvdread_verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
114 int verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
115
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
116 dvdread_verbose = getenv("DVDREAD_VERBOSE");
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
117 if(dvdread_verbose) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
118 verbose = (int)strtol(dvdread_verbose, NULL, 0);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
119 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
120 verbose = DVDREAD_VERBOSE_DEFAULT;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
121 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
122 return verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
123 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
124
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
125 int dvdread_verbose(dvd_reader_t *dvd)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
126 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
127 return dvd->verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
128 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
129
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
130 dvd_reader_t *device_of_file(dvd_file_t *file)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
131 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
132 return file->dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
133 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
134
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
135 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
136 * Returns the compiled version. (DVDREAD_VERSION as an int)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
137 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
138 int DVDVersion(void)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
139 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
140 return DVDREAD_VERSION;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
141 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
142
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
143
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
144 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
145 * Set the level of caching on udf
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
146 * level = 0 (no caching)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
147 * level = 1 (caching filesystem info)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
148 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
149 int DVDUDFCacheLevel(dvd_reader_t *device, int level)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
150 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
151 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
152
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
153 if(level > 0) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
154 level = 1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
155 } else if(level < 0) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
156 return dev->udfcache_level;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
157 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
158
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
159 dev->udfcache_level = level;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
160
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
161 return level;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
162 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
163
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
164 void *GetUDFCacheHandle(dvd_reader_t *device)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
165 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
166 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
167
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
168 return dev->udfcache;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
169 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
170
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
171 void SetUDFCacheHandle(dvd_reader_t *device, void *cache)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
172 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
173 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
174
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
175 dev->udfcache = cache;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
176 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
177
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
178 void *GetAlignHandle(dvd_reader_t *device)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
179 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
180 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
181
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
182 return dev->align;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
183 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
184
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
185 void SetAlignHandle(dvd_reader_t *device, void *align)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
186 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
187 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
188
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
189 dev->align = align;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
190 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
191
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
192
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
193 /* Loop over all titles and call dvdcss_title to crack the keys. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
194 static int initAllCSSKeys( dvd_reader_t *dvd )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
195 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
196 struct timeval all_s, all_e;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
197 struct timeval t_s, t_e;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
198 char filename[ MAX_UDF_FILE_NAME_LEN ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
199 uint32_t start, len;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
200 int title;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
201
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
202 char *nokeys_str = getenv("DVDREAD_NOKEYS");
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
203 if(nokeys_str != NULL)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
204 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
205
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
206 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
207 fprintf( stderr, "\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
208 fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
209 fprintf( stderr, "libdvdread: This can take a _long_ time, "
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
210 "please be patient\n\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
211 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
212 gettimeofday(&all_s, NULL);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
213
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
214 for( title = 0; title < 100; title++ ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
215 gettimeofday( &t_s, NULL );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
216 if( title == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
217 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
218 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
219 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
220 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
221 start = UDFFindFile( dvd, filename, &len );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
222 if( start != 0 && len != 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
223 /* Perform CSS key cracking for this title. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
224 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
225 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
226 filename, start );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
227 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
228 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
229 if(dvd->verbose >= 0) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
230 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
231 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
232 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
233 gettimeofday( &t_e, NULL );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
234 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
235 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
236 (long int) t_e.tv_sec - t_s.tv_sec );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
237 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
238 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
239
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
240 if( title == 0 ) continue;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
241
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
242 gettimeofday( &t_s, NULL );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
243 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
244 start = UDFFindFile( dvd, filename, &len );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
245 if( start == 0 || len == 0 ) break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
246
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
247 /* Perform CSS key cracking for this title. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
248 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
249 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
250 filename, start );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
251 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
252 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
253 if(dvd->verbose >= 0) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
254 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
255 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
256 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
257 gettimeofday( &t_e, NULL );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
258 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
259 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
260 (long int) t_e.tv_sec - t_s.tv_sec );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
261 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
262 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
263 title--;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
264
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
265 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
266 fprintf( stderr, "libdvdread: Found %d VTS's\n", title );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
267 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
268 gettimeofday(&all_e, NULL);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
269 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
270 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
271 (long int) all_e.tv_sec - all_s.tv_sec );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
272 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
273 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
274 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
275
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
276
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
277
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
278 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
279 * Open a DVD image or block device file.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
280 * Checks if the root directory in the udf image file can be found.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
281 * If not it assumes this isn't a valid udf image and returns NULL
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
282 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
283 static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
284 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
285 dvd_reader_t *dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
286 dvd_input_t dev;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
287 int verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
288
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
289 verbose = get_verbose();
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
290
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
291 dev = dvdinput_open( location );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
292 if( !dev ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
293 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
294 fprintf( stderr, "libdvdread: Can't open '%s' for reading: %s\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
295 location, strerror(errno));
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
296 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
297 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
298 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
299
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
300 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
301 if( !dvd ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
302 int tmp_errno = errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
303 dvdinput_close(dev);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
304 errno = tmp_errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
305 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
306 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
307 dvd->verbose = verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
308 dvd->isImageFile = 1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
309 dvd->dev = dev;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
310 dvd->path_root = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
311
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
312 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
313 dvd->udfcache = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
314
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
315 dvd->align = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
316
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
317 if( have_css ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
318 /* Only if DVDCSS_METHOD = title, a bit if it's disc or if
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
319 * DVDCSS_METHOD = key but region missmatch. Unfortunaly we
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
320 * don't have that information. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
321
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
322 dvd->css_state = 1; /* Need key init. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
323 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
324 dvd->css_title = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
325
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
326 /* sanity check, is it a valid UDF image, can we find the root dir */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
327 if(!UDFFindFile(dvd, "/", NULL)) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
328 dvdinput_close(dvd->dev);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
329 if(dvd->udfcache) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
330 FreeUDFCache(dvd, dvd->udfcache);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
331 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
332 if(dvd->align) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
333 if(dvd->verbose >= 0) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
334 fprintf(stderr, "libdvdread: DVDOpenImageFile(): Memory leak in align functions 1\n");
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
335 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
336 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
337 free(dvd);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
338 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
339 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
340 return dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
341 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
342
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
343 static dvd_reader_t *DVDOpenPath( const char *path_root )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
344 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
345 dvd_reader_t *dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
346
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
347 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
348 if( !dvd ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
349 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
350 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
351 dvd->verbose = get_verbose();
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
352 dvd->isImageFile = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
353 dvd->dev = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
354 dvd->path_root = strdup( path_root );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
355 if(!dvd->path_root) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
356 free(dvd);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
357 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
358 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
359 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
360 dvd->udfcache = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
361
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
362 dvd->align = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
363
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
364 dvd->css_state = 0; /* Only used in the UDF path */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
365 dvd->css_title = 0; /* Only matters in the UDF path */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
366
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
367 return dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
368 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
369
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
370 #if defined(__sun)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
371 /* /dev/rdsk/c0t6d0s0 (link to /devices/...)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
372 /vol/dev/rdsk/c0t6d0/??
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
373 /vol/rdsk/<name> */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
374 static char *sun_block2char( const char *path )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
375 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
376 char *new_path;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
377
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
378 /* Must contain "/dsk/" */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
379 if( !strstr( path, "/dsk/" ) ) return (char *) strdup( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
380
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
381 /* Replace "/dsk/" with "/rdsk/" */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
382 new_path = malloc( strlen(path) + 2 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
383 strcpy( new_path, path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
384 strcpy( strstr( new_path, "/dsk/" ), "" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
385 strcat( new_path, "/rdsk/" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
386 strcat( new_path, strstr( path, "/dsk/" ) + strlen( "/dsk/" ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
387
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
388 return new_path;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
389 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
390 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
391
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
392 #if defined(SYS_BSD)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
393 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recomended to _not_ use r
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
394 update: FreeBSD and DragonFly no longer uses the prefix so don't add it.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
395
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
396 OpenBSD /dev/rcd0c, it needs to be the raw device
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
397 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
398 Darwin /dev/rdisk0, it needs to be the raw device
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
399 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
400
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
401 returns a string allocated with strdup which should be free()'d when
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
402 no longer used.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
403 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
404 static char *bsd_block2char( const char *path )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
405 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
406 #if defined(__FreeBSD__) || defined(__DragonFly__)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
407 return (char *) strdup( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
408 #else
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
409 char *new_path;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
410
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
411 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
412 if( strncmp( path, "/dev/", 5 ) || !strncmp( path, "/dev/r", 6 ) )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
413 return (char *) strdup( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
414
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
415 /* Replace "/dev/" with "/dev/r" */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
416 new_path = malloc( strlen(path) + 2 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
417 strcpy( new_path, "/dev/r" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
418 strcat( new_path, path + strlen( "/dev/" ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
419
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
420 return new_path;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
421 #endif /* __FreeBSD__ || __DragonFly__ */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
422 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
423 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
424
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
425
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
426 dvd_reader_t *DVDOpen( const char *path )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
427 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
428 struct stat fileinfo;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
429 int ret, have_css;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
430 char *dev_name = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
431 int internal_errno = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
432 int verbose;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
433
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
434 if( path == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
435 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
436 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
437 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
438
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
439 verbose = get_verbose();
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
440
27727
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27466
diff changeset
441 #if defined(__CYGWIN__) || defined(__MINGW32__)
27466
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
442 /* Stat doesn't work on devices under mingwin/cygwin. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
443 if( path[0] && path[1] == ':' && path[2] == '\0' )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
444 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
445 /* Don't try to stat the file */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
446 fileinfo.st_mode = S_IFBLK;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
447 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
448 else
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
449 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
450 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
451 ret = stat( path, &fileinfo );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
452 if( ret < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
453 int tmp_errno = errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
454 /* If we can't stat the file, give up */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
455 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
456 fprintf( stderr, "libdvdread: Can't stat '%s': %s\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
457 path, strerror(errno));
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
458 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
459 errno = tmp_errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
460 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
461 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
462 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
463
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
464 /* Try to open libdvdcss or fall back to standard functions */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
465 have_css = dvdinput_setup();
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
466
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
467 /* First check if this is a block/char device or a file*/
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
468 if( S_ISBLK( fileinfo.st_mode ) ||
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
469 S_ISCHR( fileinfo.st_mode ) ||
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
470 S_ISREG( fileinfo.st_mode ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
471 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
472 * Block devices and regular files are assumed to be DVD-Video images.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
473 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
474 dvd_reader_t *dvd = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
475 #if defined(__sun)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
476 dev_name = sun_block2char( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
477 #elif defined(SYS_BSD)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
478 dev_name = bsd_block2char( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
479 #else
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
480 dev_name = strdup( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
481 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
482 dvd = DVDOpenImageFile( dev_name, have_css );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
483 free( dev_name );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
484
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
485 return dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
486 } else if( S_ISDIR( fileinfo.st_mode ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
487 dvd_reader_t *auth_drive = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
488 char *path_copy;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
489 #if defined(SYS_BSD)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
490 struct fstab* fe;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
491 #elif defined(__sun) || defined(__linux__) || defined(__CYGWIN__)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
492 FILE *mntfile;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
493 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
494
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
495 /* XXX: We should scream real loud here. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
496 if( !(path_copy = strdup( path ) ) ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
497
27727
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27466
diff changeset
498 /* don't have fchdir, and getcwd( NULL, ... ) is strange */
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27466
diff changeset
499 #if !(defined(__CYGWIN__) || defined(__MINGW32__))
27466
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
500 /* Resolve any symlinks and get the absolut dir name. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
501 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
502 char *new_path;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
503 char *current_path;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
504
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
505 current_path = malloc(PATH_MAX);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
506 if(current_path) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
507 if(!getcwd(current_path, PATH_MAX)) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
508 free(current_path);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
509 current_path = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
510 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
511 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
512 if(current_path) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
513 chdir( path_copy );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
514 new_path = malloc(PATH_MAX);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
515 if(new_path) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
516 if(!getcwd(new_path, PATH_MAX )) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
517 free(new_path);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
518 new_path = NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
519 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
520 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
521
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
522 chdir(current_path);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
523 free(current_path);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
524 if( new_path ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
525 free( path_copy );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
526 path_copy = new_path;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
527 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
528 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
529 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
530 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
531
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
532 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
533 * If we're being asked to open a directory, check if that directory
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
534 * is the mountpoint for a DVD-ROM which we can use instead.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
535 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
536
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
537 if( strlen( path_copy ) > 1 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
538 if( path_copy[ strlen( path_copy ) - 1 ] == '/' ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
539 path_copy[ strlen( path_copy ) - 1 ] = '\0';
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
540 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
541 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
542
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
543 if( strlen( path_copy ) >= 9 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
544 if( !strcasecmp( &(path_copy[ strlen( path_copy ) - 9 ]),
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
545 "/video_ts" ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
546 path_copy[ strlen( path_copy ) - 9 ] = '\0';
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
547 if(path_copy[0] == '\0') {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
548 path_copy[0] = '/';
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
549 path_copy[1] = '\0';
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
550 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
551 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
552 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
553
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
554 #if defined(SYS_BSD)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
555 if( ( fe = getfsfile( path_copy ) ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
556 dev_name = bsd_block2char( fe->fs_spec );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
557 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
558 fprintf( stderr,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
559 "libdvdread: Attempting to use device %s"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
560 " mounted on %s%s\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
561 dev_name,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
562 fe->fs_file,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
563 have_css ? " for CSS authentication" : "");
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
564 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
565 auth_drive = DVDOpenImageFile( dev_name, have_css );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
566 if(!auth_drive) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
567 internal_errno = errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
568 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
569 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
570 #elif defined(__sun)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
571 mntfile = fopen( MNTTAB, "r" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
572 if( mntfile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
573 struct mnttab mp;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
574 int res;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
575
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
576 while( ( res = getmntent( mntfile, &mp ) ) != -1 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
577 if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
578 dev_name = sun_block2char( mp.mnt_special );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
579 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
580 fprintf( stderr,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
581 "libdvdread: Attempting to use device %s"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
582 " mounted on %s%s\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
583 dev_name,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
584 mp.mnt_mountp,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
585 have_css ? " for CSS authentication" : "");
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
586 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
587 auth_drive = DVDOpenImageFile( dev_name, have_css );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
588 if(!auth_drive) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
589 internal_errno = errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
590 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
591 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
592 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
593 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
594 fclose( mntfile );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
595 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
596 #elif defined(__linux__) || defined(__CYGWIN__)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
597 mntfile = fopen( MOUNTED, "r" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
598 if( mntfile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
599 struct mntent *me;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
600
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
601 while( ( me = getmntent( mntfile ) ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
602 if( !strcmp( me->mnt_dir, path_copy ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
603 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
604 fprintf( stderr,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
605 "libdvdread: Attempting to use device %s"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
606 " mounted on %s%s\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
607 me->mnt_fsname,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
608 me->mnt_dir,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
609 have_css ? " for CSS authentication" : "");
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
610 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
611 auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
612 if(!auth_drive) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
613 internal_errno = errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
614 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
615 dev_name = strdup(me->mnt_fsname);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
616 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
617 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
618 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
619 fclose( mntfile );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
620 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
621 #elif defined(__MINGW32__)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
622 dev_name = strdup(path);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
623 auth_drive = DVDOpenImageFile( path, have_css );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
624 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
625 if( !dev_name ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
626 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
627 fprintf( stderr, "libdvdread: Couldn't find device name.\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
628 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
629 } else if( !auth_drive ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
630 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
631 fprintf( stderr, "libdvdread: Device %s inaccessible%s: %s\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
632 dev_name,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
633 have_css ? ", CSS authentication not available" : "",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
634 strerror(internal_errno));
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
635 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
636 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
637
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
638 free( dev_name );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
639 free( path_copy );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
640
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
641 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
642 * If we've opened a drive, just use that.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
643 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
644 if( auth_drive ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
645 return auth_drive;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
646 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
647 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
648 * Otherwise, we now try to open the directory tree instead.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
649 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
650 return DVDOpenPath( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
651 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
652
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
653 /* If it's none of the above, screw it. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
654 if(verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
655 fprintf( stderr, "libdvdread: Could not open %s\n", path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
656 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
657 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
658 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
659
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
660 void DVDClose( dvd_reader_t *dvd )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
661 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
662 if( dvd ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
663 if( dvd->dev ) dvdinput_close( dvd->dev );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
664 if( dvd->path_root ) free( dvd->path_root );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
665 if( dvd->udfcache ) FreeUDFCache( dvd, dvd->udfcache );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
666 if(dvd->align) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
667 if(dvd->verbose >= 0) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
668 fprintf(stderr, "libdvdread: DVDClose(): Memory leak in align functions\n");
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
669 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
670 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
671
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
672 free( dvd );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
673 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
674 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
675
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
676 void DVDInit(void)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
677 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
678 dvdinput_setup();
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
679 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
680
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
681 void DVDFinish(void)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
682 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
683 dvdinput_free();
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
684 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
685
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
686 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
687 * Open an unencrypted file on a DVD image file.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
688 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
689 static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
690 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
691 uint32_t start, len;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
692 dvd_file_t *dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
693
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
694 start = UDFFindFile( dvd, filename, &len );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
695 if( !start ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
696
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
697 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
698 if( !dvd_file ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
699 dvd_file->dvd = dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
700 dvd_file->lb_start = start;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
701 dvd_file->seek_pos = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
702 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
703 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
704 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
705
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
706 return dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
707 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
708
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
709 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
710 * Searches for <file> in directory <path>, ignoring case.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
711 * Returns 0 and full filename in <filename>.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
712 * or -1 on file not found.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
713 * or -2 on path not found.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
714 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
715 static int findDirFile( const char *path, const char *file, char *filename )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
716 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
717 DIR *dir;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
718 struct dirent *ent;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
719
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
720 dir = opendir( path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
721 if( !dir ) return -2;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
722
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
723 while( ( ent = readdir( dir ) ) != NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
724 if( !strcasecmp( ent->d_name, file ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
725 sprintf( filename, "%s%s%s", path,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
726 ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
727 ent->d_name );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
728 closedir(dir);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
729 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
730 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
731 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
732 closedir(dir);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
733 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
734 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
735
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
736 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
737 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
738 char video_path[ PATH_MAX + 1 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
739 const char *nodirfile;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
740 int ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
741
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
742 /* Strip off the directory for our search */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
743 if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
744 nodirfile = &(file[ 10 ]);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
745 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
746 nodirfile = file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
747 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
748
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
749 ret = findDirFile( dvd->path_root, nodirfile, filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
750 if( ret < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
751 /* Try also with adding the path, just in case. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
752 sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
753 ret = findDirFile( video_path, nodirfile, filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
754 if( ret < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
755 /* Try with the path, but in lower case. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
756 sprintf( video_path, "%s/video_ts/", dvd->path_root );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
757 ret = findDirFile( video_path, nodirfile, filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
758 if( ret < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
759 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
760 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
761 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
762 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
763
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
764 return 1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
765 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
766
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
767 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
768 * Open an unencrypted file from a DVD directory tree.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
769 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
770 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
771 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
772 char full_path[ PATH_MAX + 1 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
773 dvd_file_t *dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
774 struct stat fileinfo;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
775 dvd_input_t dev;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
776
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
777 /* Get the full path of the file. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
778 if( !findDVDFile( dvd, filename, full_path ) ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
779
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
780 dev = dvdinput_open( full_path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
781 if( !dev ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
782
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
783 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
784 if( !dvd_file ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
785 dvd_file->dvd = dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
786 dvd_file->lb_start = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
787 dvd_file->seek_pos = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
788 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
789 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
790 dvd_file->filesize = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
791
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
792 if( stat( full_path, &fileinfo ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
793 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
794 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
795 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
796 free( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
797 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
798 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
799 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
800 dvd_file->title_devs[ 0 ] = dev;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
801 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
802
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
803 return dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
804 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
805
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
806 static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
807 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
808 char filename[ MAX_UDF_FILE_NAME_LEN ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
809 uint32_t start, len;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
810 dvd_file_t *dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
811
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
812 if( title == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
813 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
814 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
815 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
816 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
817 start = UDFFindFile( dvd, filename, &len );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
818 if( start == 0 ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
819
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
820 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
821 if( !dvd_file ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
822 dvd_file->dvd = dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
823 /*Hack*/ dvd_file->css_title = title << 1 | menu;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
824 dvd_file->lb_start = start;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
825 dvd_file->seek_pos = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
826 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
827 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
828 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
829
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
830 /* Calculate the complete file size for every file in the VOBS */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
831 if( !menu ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
832 int cur;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
833
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
834 for( cur = 2; cur < 10; cur++ ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
835 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
836 if( !UDFFindFile( dvd, filename, &len ) ) break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
837 dvd_file->filesize += len / DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
838 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
839 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
840
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
841 if( dvd->css_state == 1 /* Need key init */ ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
842 // initAllCSSKeys( dvd );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
843 // dvd->css_state = 2;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
844 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
845 /*
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
846 if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
847 fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
848 filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
849 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
850 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
851
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
852 return dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
853 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
854
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
855 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
856 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
857 char filename[ MAX_UDF_FILE_NAME_LEN ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
858 char full_path[ PATH_MAX + 1 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
859 struct stat fileinfo;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
860 dvd_file_t *dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
861 int i;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
862
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
863 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
864 if( !dvd_file ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
865 dvd_file->dvd = dvd;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
866 /*Hack*/ dvd_file->css_title = title << 1 | menu;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
867 dvd_file->lb_start = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
868 dvd_file->seek_pos = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
869 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
870 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
871 dvd_file->filesize = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
872
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
873 if( menu ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
874 dvd_input_t dev;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
875
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
876 if( title == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
877 sprintf( filename, "VIDEO_TS.VOB" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
878 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
879 sprintf( filename, "VTS_%02i_0.VOB", title );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
880 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
881 if( !findDVDFile( dvd, filename, full_path ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
882 free( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
883 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
884 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
885
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
886 dev = dvdinput_open( full_path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
887 if( dev == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
888 free( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
889 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
890 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
891
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
892 if( stat( full_path, &fileinfo ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
893 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
894 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
895 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
896 free( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
897 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
898 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
899 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
900 dvd_file->title_devs[ 0 ] = dev;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
901 dvdinput_title( dvd_file->title_devs[0], 0);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
902 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
903
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
904 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
905 for( i = 0; i < 9; ++i ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
906
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
907 sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
908 if( !findDVDFile( dvd, filename, full_path ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
909 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
910 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
911
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
912 if( stat( full_path, &fileinfo ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
913 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
914 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
915 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
916 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
917 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
918
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
919 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
920 dvd_file->title_devs[ i ] = dvdinput_open( full_path );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
921 dvdinput_title( dvd_file->title_devs[ i ], 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
922 dvd_file->filesize += dvd_file->title_sizes[ i ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
923 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
924 if( !dvd_file->title_devs[ 0 ] ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
925 free( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
926 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
927 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
928 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
929
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
930 return dvd_file;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
931 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
932
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
933 dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
934 dvd_read_domain_t domain )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
935 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
936 char filename[ MAX_UDF_FILE_NAME_LEN ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
937
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
938 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
939 if( dvd == NULL || titlenum < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
940 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
941 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
942 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
943
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
944 switch( domain ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
945 case DVD_READ_INFO_FILE:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
946 if( titlenum == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
947 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
948 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
949 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
950 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
951 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
952 case DVD_READ_INFO_BACKUP_FILE:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
953 if( titlenum == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
954 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
955 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
956 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
957 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
958 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
959 case DVD_READ_MENU_VOBS:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
960 if( dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
961 return DVDOpenVOBUDF( dvd, titlenum, 1 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
962 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
963 return DVDOpenVOBPath( dvd, titlenum, 1 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
964 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
965 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
966 case DVD_READ_TITLE_VOBS:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
967 if( titlenum == 0 ) return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
968 if( dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
969 return DVDOpenVOBUDF( dvd, titlenum, 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
970 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
971 return DVDOpenVOBPath( dvd, titlenum, 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
972 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
973 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
974 default:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
975 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
976 fprintf( stderr, "libdvdread: Invalid domain for file open.\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
977 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
978 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
979 return NULL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
980 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
981
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
982 if( dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
983 return DVDOpenFileUDF( dvd, filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
984 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
985 return DVDOpenFilePath( dvd, filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
986 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
987 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
988
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
989 void DVDCloseFile( dvd_file_t *dvd_file )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
990 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
991 int i;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
992
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
993 if( dvd_file ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
994 if( dvd_file->dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
995 ;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
996 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
997 for( i = 0; i < 9; ++i ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
998 if( dvd_file->title_devs[ i ] ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
999 dvdinput_close( dvd_file->title_devs[i] );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1000 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1001 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1002 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1003
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1004 free( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1005 dvd_file = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1006 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1007 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1008
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1009 static int DVDFileStatVOBUDF(dvd_reader_t *dvd, int title,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1010 int menu, dvd_stat_t *statbuf)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1011 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1012 char filename[ MAX_UDF_FILE_NAME_LEN ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1013 uint32_t size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1014 off_t tot_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1015 off_t parts_size[9];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1016 int nr_parts = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1017 int n;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1018
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1019 if( title == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1020 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1021 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1022 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1023 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1024 if(!UDFFindFile( dvd, filename, &size )) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1025 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1026 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1027 tot_size = size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1028 nr_parts = 1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1029 parts_size[0] = size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1030
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1031 if( !menu ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1032 int cur;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1033
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1034 for( cur = 2; cur < 10; cur++ ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1035 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1036 if( !UDFFindFile( dvd, filename, &size ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1037 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1038 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1039 parts_size[nr_parts] = size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1040 tot_size += size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1041 nr_parts++;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1042 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1043 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1044
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1045 statbuf->size = tot_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1046 statbuf->nr_parts = nr_parts;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1047 for(n = 0; n < nr_parts; n++) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1048 statbuf->parts_size[n] = parts_size[n];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1049 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1050 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1051 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1052
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1053
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1054 static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1055 int menu, dvd_stat_t *statbuf )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1056 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1057 char filename[ MAX_UDF_FILE_NAME_LEN ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1058 char full_path[ PATH_MAX + 1 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1059 struct stat fileinfo;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1060 off_t tot_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1061 off_t parts_size[9];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1062 int nr_parts = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1063 int n;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1064
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1065
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1066
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1067 if( title == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1068 sprintf( filename, "VIDEO_TS.VOB" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1069 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1070 sprintf( filename, "VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1071 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1072 if( !findDVDFile( dvd, filename, full_path ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1073 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1074 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1075
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1076 if( stat( full_path, &fileinfo ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1077 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1078 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1079 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1080 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1081 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1082
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1083
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1084 tot_size = fileinfo.st_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1085 nr_parts = 1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1086 parts_size[0] = fileinfo.st_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1087
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1088 if( !menu ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1089 int cur;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1090
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1091 for( cur = 2; cur < 10; cur++ ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1092
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1093 sprintf( filename, "VTS_%02d_%d.VOB", title, cur );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1094 if( !findDVDFile( dvd, filename, full_path ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1095 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1096 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1097
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1098 if( stat( full_path, &fileinfo ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1099 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1100 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1101 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1102 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1103 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1104
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1105 parts_size[nr_parts] = fileinfo.st_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1106 tot_size += parts_size[nr_parts];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1107 nr_parts++;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1108 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1109 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1110
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1111 statbuf->size = tot_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1112 statbuf->nr_parts = nr_parts;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1113 for(n = 0; n < nr_parts; n++) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1114 statbuf->parts_size[n] = parts_size[n];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1115 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1116 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1117 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1118
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1119
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1120 int DVDFileStat(dvd_reader_t *dvd, int titlenum,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1121 dvd_read_domain_t domain, dvd_stat_t *statbuf)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1122 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1123 char filename[ MAX_UDF_FILE_NAME_LEN ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1124 char full_path[ PATH_MAX + 1 ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1125 struct stat fileinfo;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1126 uint32_t size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1127
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1128 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1129 if( dvd == NULL || titlenum < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1130 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1131 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1132 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1133
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1134 switch( domain ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1135 case DVD_READ_INFO_FILE:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1136 if( titlenum == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1137 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1138 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1139 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1140 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1141 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1142 case DVD_READ_INFO_BACKUP_FILE:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1143 if( titlenum == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1144 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1145 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1146 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1147 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1148 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1149 case DVD_READ_MENU_VOBS:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1150 if( dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1151 return DVDFileStatVOBUDF( dvd, titlenum, 1, statbuf );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1152 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1153 return DVDFileStatVOBPath( dvd, titlenum, 1, statbuf );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1154 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1155 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1156 case DVD_READ_TITLE_VOBS:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1157 if( titlenum == 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1158 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1159 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1160 if( dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1161 return DVDFileStatVOBUDF( dvd, titlenum, 0, statbuf );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1162 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1163 return DVDFileStatVOBPath( dvd, titlenum, 0, statbuf );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1164 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1165 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1166 default:
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1167 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1168 fprintf( stderr, "libdvdread: Invalid domain for file stat.\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1169 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1170 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1171 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1172 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1173
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1174 if( dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1175 if( UDFFindFile( dvd, filename, &size ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1176 statbuf->size = size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1177 statbuf->nr_parts = 1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1178 statbuf->parts_size[0] = size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1179 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1180 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1181 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1182 if( findDVDFile( dvd, filename, full_path ) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1183 if( stat( full_path, &fileinfo ) < 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1184 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1185 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1186 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1187 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1188 statbuf->size = fileinfo.st_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1189 statbuf->nr_parts = 1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1190 statbuf->parts_size[0] = statbuf->size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1191 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1192 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1193 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1194 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1195 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1196 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1197
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1198 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1199 * Internal, but used from dvd_udf.c
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1200 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1201 * @param device A read handle.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1202 * @param lb_number Logical block number to start read from.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1203 * @param block_count Number of logical blocks to read.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1204 * @param data Pointer to buffer where read data should be stored.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1205 * This buffer must be large enough to hold lb_number*2048 bytes.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1206 * The pointer must be aligned to the logical block size when
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1207 * reading from a raw/O_DIRECT device.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1208 * @param encrypted 0 if no decryption shall be performed,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1209 * 1 if decryption shall be performed
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1210 * @param return Returns number of blocks read on success, negative on error
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1211 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1212 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1213 size_t block_count, unsigned char *data,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1214 int encrypted )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1215 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1216 int ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1217
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1218 if( !device->dev ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1219 if(device->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1220 fprintf( stderr, "libdvdread: Fatal error in block read.\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1221 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1222 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1223 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1224
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1225 ret = dvdinput_seek( device->dev, (int) lb_number );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1226 if( ret != (int) lb_number ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1227 if(device->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1228 fprintf( stderr,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1229 "libdvdread: UDFReadBlocksRaw: Can't seek to block %u\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1230 lb_number );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1231 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1232 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1233 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1234
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1235 return dvdinput_read( device->dev, (char *) data,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1236 (int) block_count, encrypted );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1237 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1238
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1239 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1240 * This is using a single input and starting from 'dvd_file->lb_start' offset.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1241 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1242 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1243 * into the buffer located at 'data' and if 'encrypted' is set
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1244 * descramble the data if it's encrypted. Returning either an
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1245 * negative error or the number of blocks read.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1246 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1247 * @param data Pointer to buffer where read data should be placed.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1248 * This buffer must be large enough to hold block_count*2048 bytes.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1249 * The pointer must be aligned to 2048 bytes when reading from
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1250 * a raw/O_DIRECT device.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1251 * @return Returns the number of blocks read on success or a negative error.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1252 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1253 static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1254 size_t block_count, unsigned char *data,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1255 int encrypted )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1256 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1257 return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1258 block_count, data, encrypted );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1259 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1260
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1261 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1262 * This is using possibly several inputs and starting from an offset of '0'.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1263 * data must be aligned to logical block size (2048 bytes) of the device
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1264 * for raw/O_DIRECT devices to work
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1265 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1266 * into the buffer located at 'data' and if 'encrypted' is set
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1267 * descramble the data if it's encrypted. Returning either an
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1268 * negative error or the number of blocks read.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1269 *
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1270 * @param dvd_file A file read handle.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1271 * @param offset Block offset from start of file.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1272 * @return Returns number of blocks read on success, negative on error.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1273 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1274 static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1275 size_t block_count, unsigned char *data,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1276 int encrypted )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1277 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1278 int i;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1279 int ret, ret2, off;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1280
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1281 ret = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1282 ret2 = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1283 for( i = 0; i < 9; ++i ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1284 if( !dvd_file->title_sizes[ i ] ) return 0; /* Past end of file */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1285
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1286 if( offset < dvd_file->title_sizes[ i ] ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1287 if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1288 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1289 if( off < 0 || off != (int)offset ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1290 if(dvd_file->dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1291 fprintf( stderr, "libdvdread: DVDReadBlocksPath1: Can't seek to block %d\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1292 offset );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1293 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1294 return off < 0 ? off : 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1295 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1296 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1297 (int)block_count, encrypted );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1298 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1299 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1300 size_t part1_size = dvd_file->title_sizes[ i ] - offset;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1301 /* FIXME: Really needs to be a while loop.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1302 * (This is only true if you try and read >1GB at a time) */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1303
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1304 /* Read part 1 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1305 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1306 if( off < 0 || off != (int)offset ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1307 if(dvd_file->dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1308 fprintf( stderr, "libdvdread: DVDReadBlocksPath2: Can't seek to block %d\n",
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1309 offset );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1310 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1311 return off < 0 ? off : 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1312 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1313 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1314 (int)part1_size, encrypted );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1315 if( ret < 0 ) return ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1316 /* FIXME: This is wrong if i is the last file in the set.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1317 * also error from this read will not show in ret. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1318
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1319 /* Does the next part exist? If not then return now. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1320 if( !dvd_file->title_devs[ i + 1 ] ) return ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1321
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1322 /* Read part 2 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1323 off = dvdinput_seek( dvd_file->title_devs[ i + 1 ], 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1324 if( off < 0 || off != 0 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1325 if(dvd_file->dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1326 fprintf( stderr, "libdvdread: DVDReadBlocksPath3: Can't seek to block %d\n", 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1327 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1328 return off < 0 ? off : 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1329 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1330 ret2 = dvdinput_read( dvd_file->title_devs[ i + 1 ],
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1331 data + ( part1_size
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1332 * (int64_t)DVD_VIDEO_LB_LEN ),
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1333 (int)(block_count - part1_size),
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1334 encrypted );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1335 if( ret2 < 0 ) return ret2;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1336 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1337 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1338 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1339 offset -= dvd_file->title_sizes[ i ];
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1340 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1341 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1342
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1343 return ret + ret2;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1344 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1345
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1346 /**
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1347 * This is broken reading more than 2Gb at a time if ssize_t is 32-bit.
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1348 */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1349 ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1350 size_t block_count, unsigned char *data )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1351 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1352 int ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1353
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1354 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1355 if( dvd_file == NULL || offset < 0 || data == NULL )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1356 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1357
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1358 /* Hack, and it will still fail for multiple opens in a threaded app ! */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1359 if( dvd_file->dvd->css_title != dvd_file->css_title ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1360 dvd_file->dvd->css_title = dvd_file->css_title;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1361 if( dvd_file->dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1362 dvdinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1363 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1364 /* Here each vobu has it's own dvdcss handle, so no need to update
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1365 else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1366 dvdinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1367 }*/
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1368 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1369
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1370 if( dvd_file->dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1371 ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1372 block_count, data, DVDINPUT_READ_DECRYPT );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1373 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1374 ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1375 block_count, data, DVDINPUT_READ_DECRYPT );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1376 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1377
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1378 return (ssize_t)ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1379 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1380
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1381 int DVDFileSeek( dvd_file_t *dvd_file, int offset )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1382 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1383 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1384 if( dvd_file == NULL || offset < 0 )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1385 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1386
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1387 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1388 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1389 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1390 dvd_file->seek_pos = (uint32_t) offset;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1391 return offset;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1392 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1393
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1394 #ifndef HAVE_UINTPTR_T
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1395 #warning "Assuming that (unsigned long) can hold (void *)"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1396 typedef unsigned long uintptr_t;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1397 #endif
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1398
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1399 #define DVD_ALIGN(ptr) (void *)((((uintptr_t)(ptr)) + (DVD_VIDEO_LB_LEN-1)) \
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1400 / DVD_VIDEO_LB_LEN * DVD_VIDEO_LB_LEN)
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1401
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1402 ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1403 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1404 unsigned char *secbuf_start;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1405 unsigned char *secbuf; //must be aligned to 2048-bytes for raw/O_DIRECT
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1406 unsigned int numsec, seek_sector, seek_byte;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1407 int ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1408
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1409 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1410 if( dvd_file == NULL || data == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1411 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1412 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1413 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1414 seek_sector = dvd_file->seek_pos / DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1415 seek_byte = dvd_file->seek_pos % DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1416
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1417 numsec = ( ( seek_byte + byte_size ) / DVD_VIDEO_LB_LEN ) +
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1418 ( ( ( seek_byte + byte_size ) % DVD_VIDEO_LB_LEN ) ? 1 : 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1419
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1420 /* must align to 2048 bytes if we are reading from raw/O_DIRECT */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1421 secbuf_start = (unsigned char *) malloc( (numsec+1) * DVD_VIDEO_LB_LEN );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1422 if( !secbuf_start ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1423 /* errno will be set to ENOMEM by malloc */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1424 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1425 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1426
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1427 secbuf = DVD_ALIGN(secbuf_start);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1428
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1429 if( dvd_file->dvd->isImageFile ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1430 ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1431 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1432 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1433 ret = DVDReadBlocksPath( dvd_file, seek_sector,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1434 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1435 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1436
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1437 if( ret != (int) numsec ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1438 free( secbuf_start );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1439 return ret < 0 ? ret : 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1440 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1441
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1442 memcpy( data, &(secbuf[ seek_byte ]), byte_size );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1443 free( secbuf_start );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1444
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1445 dvd_file->seek_pos += byte_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1446 return byte_size;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1447 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1448
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1449 ssize_t DVDFileSize( dvd_file_t *dvd_file )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1450 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1451 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1452 if( dvd_file == NULL )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1453 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1454
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1455 return dvd_file->filesize;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1456 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1457
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1458 int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1459 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1460 struct md5_ctx ctx;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1461 int title;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1462 int nr_of_files = 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1463 int tmp_errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1464 int nofiles_errno = ENOENT;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1465 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1466 if( dvd == NULL || discid == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1467 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1468 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1469 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1470 /* Go through the first 10 IFO:s, in order,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1471 * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1472 md5_init_ctx( &ctx );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1473 for( title = 0; title < 10; title++ ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1474 dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1475 if( dvd_file != NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1476 ssize_t bytes_read;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1477 size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1478 char *buffer = malloc( file_size );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1479
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1480 nr_of_files++;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1481
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1482 if( buffer == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1483 /* errno will be set to ENOMEM by malloc */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1484 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1485 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1486
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1487 bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1488 if( bytes_read != file_size ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1489 tmp_errno = errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1490 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1491 fprintf( stderr, "libdvdread: DVDDiscId read returned %d bytes"
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1492 ", wanted %d\n", (int)bytes_read, (int)file_size );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1493 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1494 free(buffer);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1495 DVDCloseFile( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1496 errno = tmp_errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1497 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1498 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1499
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1500 md5_process_bytes( buffer, file_size, &ctx );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1501
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1502 DVDCloseFile( dvd_file );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1503 free( buffer );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1504 } else {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1505 if(errno != ENOENT) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1506 nofiles_errno = errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1507 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1508 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1509 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1510 md5_finish_ctx( &ctx, discid );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1511 if(nr_of_files == 0) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1512 errno = nofiles_errno;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1513 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1514 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1515 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1516 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1517
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1518
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1519 int DVDISOVolumeInfo( dvd_reader_t *dvd,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1520 char *volid, unsigned int volid_size,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1521 unsigned char *volsetid, unsigned int volsetid_size )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1522 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1523 unsigned char *buffer; /* must be aligned to 2048 for raw/O_DIRECT */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1524 unsigned char *buffer_start;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1525 int ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1526
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1527 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1528 if( dvd == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1529 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1530 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1531 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1532
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1533 if( dvd->dev == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1534 /* No block access, so no ISO... */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1535 errno = EINVAL;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1536 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1537 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1538
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1539 buffer_start = malloc( 2 * DVD_VIDEO_LB_LEN );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1540 if( buffer_start == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1541 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1542 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1543
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1544 buffer = DVD_ALIGN(buffer_start);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1545
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1546 ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1547 if( ret != 1 ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1548 if(dvd->verbose >= 1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1549 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1550 "read ISO9660 Primary Volume Descriptor!\n" );
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1551 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1552 free(buffer_start);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1553 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1554 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1555
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1556 if( (volid != NULL) && (volid_size > 0) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1557 unsigned int n;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1558 for(n = 0; n < 32; n++) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1559 if(buffer[40+n] == 0x20) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1560 break;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1561 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1562 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1563
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1564 if(volid_size > n+1) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1565 volid_size = n+1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1566 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1567
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1568 memcpy(volid, &buffer[40], volid_size-1);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1569 volid[volid_size-1] = '\0';
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1570 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1571
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1572 if( (volsetid != NULL) && (volsetid_size > 0) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1573 if(volsetid_size > 128) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1574 volsetid_size = 128;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1575 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1576 memcpy(volsetid, &buffer[190], volsetid_size);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1577 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1578 free(buffer_start);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1579
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1580 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1581 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1582
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1583
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1584 int DVDUDFVolumeInfo( dvd_reader_t *dvd,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1585 char *volid, unsigned int volid_size,
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1586 unsigned char *volsetid, unsigned int volsetid_size )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1587 {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1588 int ret;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1589 /* Check arguments. */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1590 if( dvd == NULL )
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1591 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1592
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1593 if( dvd->dev == NULL ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1594 /* No block access, so no UDF VolumeSet Identifier */
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1595 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1596 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1597
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1598 if( (volid != NULL) && (volid_size > 0) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1599 ret = UDFGetVolumeIdentifier(dvd, volid, volid_size);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1600 if(!ret) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1601 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1602 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1603 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1604 if( (volsetid != NULL) && (volsetid_size > 0) ) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1605 ret = UDFGetVolumeSetIdentifier(dvd, volsetid, volsetid_size);
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1606 if(!ret) {
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1607 return -1;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1608 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1609 }
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1610
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1611 return 0;
ea01824701a5 Rename internal libdvdread fork from dvdread to libdvdread
rathann
parents:
diff changeset
1612 }