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