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