168
|
1 /*
|
|
2 * Copyright (C) 2001, 2002, 2003 Billy Biggs <vektor@dumbterm.net>,
|
|
3 * Håkan Hjort <d95hjort@dtek.chalmers.se>,
|
|
4 * Björn Englund <d4bjorn@dtek.chalmers.se>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or (at
|
|
9 * your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
|
19 */
|
|
20
|
|
21 #include "config.h"
|
|
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>
|
|
31 #include <unistd.h>
|
|
32 #include <limits.h>
|
|
33 #include <dirent.h>
|
|
34
|
|
35 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__)|| defined(__DARWIN__)
|
|
36 #define SYS_BSD 1
|
|
37 #endif
|
|
38
|
|
39 #if defined(__sun)
|
|
40 #include <sys/mnttab.h>
|
|
41 #elif defined(SYS_BSD)
|
|
42 #include <fstab.h>
|
|
43 #elif defined(__linux__)
|
|
44 #include <mntent.h>
|
|
45 #endif
|
|
46
|
|
47 #include "dvd_udf.h"
|
|
48 #include "dvd_input.h"
|
|
49 #include "dvd_reader.h"
|
|
50 #include "md5.h"
|
|
51
|
|
52 #define DEFAULT_UDF_CACHE_LEVEL 1
|
|
53
|
176
|
54 /**/
|
|
55 #define WIN32_CSS 0
|
|
56 /**/
|
|
57
|
168
|
58 struct dvd_reader_s {
|
|
59 /* Basic information. */
|
|
60 int isImageFile;
|
|
61
|
|
62 /* Hack for keeping track of the css status.
|
|
63 * 0: no css, 1: perhaps (need init of keys), 2: have done init */
|
|
64 int css_state;
|
|
65 int css_title; /* Last title that we have called dvdinpute_title for. */
|
|
66
|
|
67 /* Information required for an image file. */
|
|
68 dvd_input_t dev;
|
|
69
|
|
70 /* Information required for a directory path drive. */
|
|
71 char *path_root;
|
|
72
|
|
73 /* Filesystem cache */
|
|
74 int udfcache_level; /* 0 - turned off, 1 - on */
|
|
75 void *udfcache;
|
|
76 };
|
|
77
|
|
78 struct dvd_file_s {
|
|
79 /* Basic information. */
|
|
80 dvd_reader_t *dvd;
|
|
81
|
|
82 /* Hack for selecting the right css title. */
|
|
83 int css_title;
|
|
84
|
|
85 /* Information required for an image file. */
|
|
86 uint32_t lb_start;
|
|
87 uint32_t seek_pos;
|
|
88
|
|
89 /* Information required for a directory path drive. */
|
|
90 size_t title_sizes[ 9 ];
|
|
91 dvd_input_t title_devs[ 9 ];
|
|
92
|
|
93 /* Calculated at open-time, size in blocks. */
|
|
94 ssize_t filesize;
|
|
95 };
|
|
96
|
|
97 /**
|
|
98 * Set the level of caching on udf
|
|
99 * level = 0 (no caching)
|
|
100 * level = 1 (caching filesystem info)
|
|
101 */
|
|
102 int DVDUDFCacheLevel(dvd_reader_t *device, int level)
|
|
103 {
|
|
104 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
|
|
105
|
|
106 if(level > 0) {
|
|
107 level = 1;
|
|
108 } else if(level < 0) {
|
|
109 return dev->udfcache_level;
|
|
110 }
|
|
111
|
|
112 dev->udfcache_level = level;
|
|
113
|
|
114 return level;
|
|
115 }
|
|
116
|
|
117 void *GetUDFCacheHandle(dvd_reader_t *device)
|
|
118 {
|
|
119 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
|
|
120
|
|
121 return dev->udfcache;
|
|
122 }
|
|
123
|
|
124 void SetUDFCacheHandle(dvd_reader_t *device, void *cache)
|
|
125 {
|
|
126 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
|
|
127
|
|
128 dev->udfcache = cache;
|
|
129 }
|
|
130
|
|
131
|
|
132
|
|
133 /* Loop over all titles and call dvdcss_title to crack the keys. */
|
|
134 static int initAllCSSKeys( dvd_reader_t *dvd )
|
|
135 {
|
|
136 struct timeval all_s, all_e;
|
|
137 struct timeval t_s, t_e;
|
|
138 char filename[ MAX_UDF_FILE_NAME_LEN ];
|
|
139 uint32_t start, len;
|
|
140 int title;
|
|
141
|
|
142 char *nokeys_str = getenv("DVDREAD_NOKEYS");
|
|
143 if(nokeys_str != NULL)
|
|
144 return 0;
|
|
145
|
|
146 fprintf( stderr, "\n" );
|
|
147 fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" );
|
|
148 fprintf( stderr, "libdvdread: This can take a _long_ time, "
|
|
149 "please be patient\n\n" );
|
|
150
|
|
151 gettimeofday(&all_s, NULL);
|
|
152
|
|
153 for( title = 0; title < 100; title++ ) {
|
|
154 gettimeofday( &t_s, NULL );
|
|
155 if( title == 0 ) {
|
|
156 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
|
|
157 } else {
|
|
158 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 0 );
|
|
159 }
|
|
160 start = UDFFindFile( dvd, filename, &len );
|
|
161 if( start != 0 && len != 0 ) {
|
|
162 /* Perform CSS key cracking for this title. */
|
|
163 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
|
|
164 filename, start );
|
|
165 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
|
|
166 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start);
|
|
167 }
|
|
168 gettimeofday( &t_e, NULL );
|
|
169 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
|
|
170 (long int) t_e.tv_sec - t_s.tv_sec );
|
|
171 }
|
|
172
|
|
173 if( title == 0 ) continue;
|
|
174
|
|
175 gettimeofday( &t_s, NULL );
|
|
176 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 );
|
|
177 start = UDFFindFile( dvd, filename, &len );
|
|
178 if( start == 0 || len == 0 ) break;
|
|
179
|
|
180 /* Perform CSS key cracking for this title. */
|
|
181 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
|
|
182 filename, start );
|
|
183 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
|
|
184 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start);
|
|
185 }
|
|
186 gettimeofday( &t_e, NULL );
|
|
187 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
|
|
188 (long int) t_e.tv_sec - t_s.tv_sec );
|
|
189 }
|
|
190 title--;
|
|
191
|
|
192 fprintf( stderr, "libdvdread: Found %d VTS's\n", title );
|
|
193 gettimeofday(&all_e, NULL);
|
|
194 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
|
|
195 (long int) all_e.tv_sec - all_s.tv_sec );
|
|
196
|
|
197 return 0;
|
|
198 }
|
|
199
|
|
200
|
|
201
|
|
202 /**
|
|
203 * Open a DVD image or block device file.
|
|
204 */
|
|
205 static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css )
|
|
206 {
|
|
207 dvd_reader_t *dvd;
|
|
208 dvd_input_t dev;
|
|
209
|
|
210 dev = dvdinput_open( location );
|
|
211 if( !dev ) {
|
|
212 fprintf( stderr, "libdvdread: Can't open %s for reading\n", location );
|
|
213 return 0;
|
|
214 }
|
|
215
|
|
216 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
|
|
217 if( !dvd ) return 0;
|
|
218 dvd->isImageFile = 1;
|
|
219 dvd->dev = dev;
|
|
220 dvd->path_root = 0;
|
|
221
|
|
222 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
|
|
223 dvd->udfcache = NULL;
|
|
224
|
|
225 if( have_css ) {
|
|
226 /* Only if DVDCSS_METHOD = title, a bit if it's disc or if
|
|
227 * DVDCSS_METHOD = key but region missmatch. Unfortunaly we
|
|
228 * don't have that information. */
|
|
229
|
|
230 dvd->css_state = 1; /* Need key init. */
|
|
231 }
|
|
232 dvd->css_title = 0;
|
|
233
|
|
234 return dvd;
|
|
235 }
|
|
236
|
|
237 static dvd_reader_t *DVDOpenPath( const char *path_root )
|
|
238 {
|
|
239 dvd_reader_t *dvd;
|
|
240
|
|
241 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
|
|
242 if( !dvd ) return 0;
|
|
243 dvd->isImageFile = 0;
|
|
244 dvd->dev = 0;
|
|
245 dvd->path_root = strdup( path_root );
|
|
246
|
|
247 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
|
|
248 dvd->udfcache = NULL;
|
|
249
|
|
250 dvd->css_state = 0; /* Only used in the UDF path */
|
|
251 dvd->css_title = 0; /* Only matters in the UDF path */
|
|
252
|
|
253 return dvd;
|
|
254 }
|
|
255
|
|
256 #if defined(__sun)
|
|
257 /* /dev/rdsk/c0t6d0s0 (link to /devices/...)
|
|
258 /vol/dev/rdsk/c0t6d0/??
|
|
259 /vol/rdsk/<name> */
|
|
260 static char *sun_block2char( const char *path )
|
|
261 {
|
|
262 char *new_path;
|
|
263
|
|
264 /* Must contain "/dsk/" */
|
|
265 if( !strstr( path, "/dsk/" ) ) return (char *) strdup( path );
|
|
266
|
|
267 /* Replace "/dsk/" with "/rdsk/" */
|
|
268 new_path = malloc( strlen(path) + 2 );
|
|
269 strcpy( new_path, path );
|
|
270 strcpy( strstr( new_path, "/dsk/" ), "" );
|
|
271 strcat( new_path, "/rdsk/" );
|
|
272 strcat( new_path, strstr( path, "/dsk/" ) + strlen( "/dsk/" ) );
|
|
273
|
|
274 return new_path;
|
|
275 }
|
|
276 #endif
|
|
277
|
|
278 #if defined(SYS_BSD)
|
|
279 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recomended to _not_ use r
|
|
280 OpenBSD /dev/rcd0c, it needs to be the raw device
|
|
281 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others
|
|
282 Darwin /dev/rdisk0, it needs to be the raw device
|
|
283 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do) */
|
|
284 static char *bsd_block2char( const char *path )
|
|
285 {
|
|
286 char *new_path;
|
|
287
|
|
288 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
|
|
289 if( !strncmp( path, "/dev/", 5 ) || strncmp( path, "/dev/r", 6 ) )
|
|
290 return (char *) strdup( path );
|
|
291
|
|
292 /* Replace "/dev/" with "/dev/r" */
|
|
293 new_path = malloc( strlen(path) + 2 );
|
|
294 strcpy( new_path, "/dev/r" );
|
|
295 strcat( new_path, path + strlen( "/dev/" ) );
|
|
296
|
|
297 return new_path;
|
|
298 }
|
|
299 #endif
|
|
300
|
|
301 dvd_reader_t *DVDOpen( const char *path )
|
|
302 {
|
176
|
303 #ifndef _MSC_VER
|
168
|
304 struct stat fileinfo;
|
176
|
305 int ret;
|
|
306 #endif /* _MSC_VER */
|
|
307
|
|
308 int have_css;
|
|
309
|
168
|
310 char *dev_name = 0;
|
|
311
|
|
312 if( path == NULL )
|
|
313 return 0;
|
|
314
|
176
|
315 #ifdef _MSC_VER
|
|
316
|
|
317 /* Try to open libdvdcss or fall back to standard functions */
|
|
318 have_css = dvdinput_setup();
|
|
319
|
|
320 return DVDOpenImageFile( path, have_css );
|
|
321
|
|
322 #else
|
|
323
|
183
|
324 /* Try to open libdvdcss or fall back to standard functions */
|
|
325 have_css = dvdinput_setup();
|
|
326
|
168
|
327 ret = stat( path, &fileinfo );
|
|
328 if( ret < 0 ) {
|
183
|
329
|
|
330 /* maybe "host:port" url? try opening it with acCeSS library */
|
|
331 if( strchr(path,':') ) {
|
|
332 return DVDOpenImageFile( path, have_css );
|
|
333 }
|
|
334
|
168
|
335 /* If we can't stat the file, give up */
|
|
336 fprintf( stderr, "libdvdread: Can't stat %s\n", path );
|
|
337 perror("");
|
|
338 return 0;
|
|
339 }
|
|
340
|
|
341 /* First check if this is a block/char device or a file*/
|
|
342 if( S_ISBLK( fileinfo.st_mode ) ||
|
|
343 S_ISCHR( fileinfo.st_mode ) ||
|
|
344 S_ISREG( fileinfo.st_mode ) ) {
|
|
345
|
|
346 /**
|
|
347 * Block devices and regular files are assumed to be DVD-Video images.
|
|
348 */
|
|
349 #if defined(__sun)
|
|
350 return DVDOpenImageFile( sun_block2char( path ), have_css );
|
|
351 #elif defined(SYS_BSD)
|
|
352 return DVDOpenImageFile( bsd_block2char( path ), have_css );
|
|
353 #else
|
|
354 return DVDOpenImageFile( path, have_css );
|
|
355 #endif
|
|
356
|
|
357 } else if( S_ISDIR( fileinfo.st_mode ) ) {
|
|
358 dvd_reader_t *auth_drive = 0;
|
|
359 char *path_copy;
|
|
360 #if defined(SYS_BSD)
|
|
361 struct fstab* fe;
|
|
362 #elif defined(__sun) || defined(__linux__)
|
|
363 FILE *mntfile;
|
|
364 #endif
|
|
365
|
|
366 /* XXX: We should scream real loud here. */
|
|
367 if( !(path_copy = strdup( path ) ) ) return 0;
|
|
368
|
|
369 /* Resolve any symlinks and get the absolut dir name. */
|
|
370 {
|
|
371 char *new_path;
|
|
372 int cdir = open( ".", O_RDONLY );
|
|
373
|
|
374 if( cdir >= 0 ) {
|
|
375 chdir( path_copy );
|
|
376 new_path = getcwd( NULL, PATH_MAX );
|
|
377 fchdir( cdir );
|
|
378 close( cdir );
|
|
379 if( new_path ) {
|
|
380 free( path_copy );
|
|
381 path_copy = new_path;
|
|
382 }
|
|
383 }
|
|
384 }
|
|
385
|
|
386 /**
|
|
387 * If we're being asked to open a directory, check if that directory
|
|
388 * is the mountpoint for a DVD-ROM which we can use instead.
|
|
389 */
|
|
390
|
|
391 if( strlen( path_copy ) > 1 ) {
|
|
392 if( path_copy[ strlen( path_copy ) - 1 ] == '/' )
|
|
393 path_copy[ strlen( path_copy ) - 1 ] = '\0';
|
|
394 }
|
|
395
|
|
396 if( strlen( path_copy ) > 9 ) {
|
|
397 if( !strcasecmp( &(path_copy[ strlen( path_copy ) - 9 ]),
|
|
398 "/video_ts" ) ) {
|
|
399 path_copy[ strlen( path_copy ) - 9 ] = '\0';
|
|
400 }
|
|
401 }
|
|
402
|
|
403 #if defined(SYS_BSD)
|
|
404 if( ( fe = getfsfile( path_copy ) ) ) {
|
|
405 dev_name = bsd_block2char( fe->fs_spec );
|
|
406 fprintf( stderr,
|
|
407 "libdvdread: Attempting to use device %s"
|
|
408 " mounted on %s for CSS authentication\n",
|
|
409 dev_name,
|
|
410 fe->fs_file );
|
|
411 auth_drive = DVDOpenImageFile( dev_name, have_css );
|
|
412 }
|
|
413 #elif defined(__sun)
|
|
414 mntfile = fopen( MNTTAB, "r" );
|
|
415 if( mntfile ) {
|
|
416 struct mnttab mp;
|
|
417 int res;
|
|
418
|
|
419 while( ( res = getmntent( mntfile, &mp ) ) != -1 ) {
|
|
420 if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) {
|
|
421 dev_name = sun_block2char( mp.mnt_special );
|
|
422 fprintf( stderr,
|
|
423 "libdvdread: Attempting to use device %s"
|
|
424 " mounted on %s for CSS authentication\n",
|
|
425 dev_name,
|
|
426 mp.mnt_mountp );
|
|
427 auth_drive = DVDOpenImageFile( dev_name, have_css );
|
|
428 break;
|
|
429 }
|
|
430 }
|
|
431 fclose( mntfile );
|
|
432 }
|
|
433 #elif defined(__linux__)
|
|
434 mntfile = fopen( MOUNTED, "r" );
|
|
435 if( mntfile ) {
|
|
436 struct mntent *me;
|
|
437
|
|
438 while( ( me = getmntent( mntfile ) ) ) {
|
|
439 if( !strcmp( me->mnt_dir, path_copy ) ) {
|
|
440 fprintf( stderr,
|
|
441 "libdvdread: Attempting to use device %s"
|
|
442 " mounted on %s for CSS authentication\n",
|
|
443 me->mnt_fsname,
|
|
444 me->mnt_dir );
|
|
445 auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css );
|
|
446 dev_name = strdup(me->mnt_fsname);
|
|
447 break;
|
|
448 }
|
|
449 }
|
|
450 fclose( mntfile );
|
|
451 }
|
|
452 #endif
|
|
453 if( !dev_name ) {
|
|
454 fprintf( stderr, "libdvdread: Couldn't find device name.\n" );
|
|
455 } else if( !auth_drive ) {
|
|
456 fprintf( stderr, "libdvdread: Device %s inaccessible, "
|
|
457 "CSS authentication not available.\n", dev_name );
|
|
458 }
|
|
459
|
|
460 free( dev_name );
|
|
461 free( path_copy );
|
|
462
|
|
463 /**
|
|
464 * If we've opened a drive, just use that.
|
|
465 */
|
|
466 if( auth_drive ) return auth_drive;
|
|
467
|
|
468 /**
|
|
469 * Otherwise, we now try to open the directory tree instead.
|
|
470 */
|
|
471 return DVDOpenPath( path );
|
|
472 }
|
176
|
473 #endif /* _MSC_VER */
|
168
|
474
|
|
475 /* If it's none of the above, screw it. */
|
|
476 fprintf( stderr, "libdvdread: Could not open %s\n", path );
|
|
477 return 0;
|
|
478 }
|
|
479
|
|
480 void DVDClose( dvd_reader_t *dvd )
|
|
481 {
|
|
482 if( dvd ) {
|
|
483 if( dvd->dev ) dvdinput_close( dvd->dev );
|
|
484 if( dvd->path_root ) free( dvd->path_root );
|
|
485 if( dvd->udfcache ) FreeUDFCache( dvd->udfcache );
|
|
486 free( dvd );
|
|
487 }
|
|
488 }
|
|
489
|
|
490 /**
|
|
491 * Open an unencrypted file on a DVD image file.
|
|
492 */
|
|
493 static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename )
|
|
494 {
|
|
495 uint32_t start, len;
|
|
496 dvd_file_t *dvd_file;
|
|
497
|
|
498 start = UDFFindFile( dvd, filename, &len );
|
|
499 if( !start ) return 0;
|
|
500
|
|
501 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
|
|
502 if( !dvd_file ) return 0;
|
|
503 dvd_file->dvd = dvd;
|
|
504 dvd_file->lb_start = start;
|
|
505 dvd_file->seek_pos = 0;
|
|
506 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
|
|
507 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
|
|
508 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
|
|
509
|
|
510 return dvd_file;
|
|
511 }
|
|
512
|
|
513 /**
|
|
514 * Searches for <file> in directory <path>, ignoring case.
|
|
515 * Returns 0 and full filename in <filename>.
|
|
516 * or -1 on file not found.
|
|
517 * or -2 on path not found.
|
|
518 */
|
|
519 static int findDirFile( const char *path, const char *file, char *filename )
|
|
520 {
|
|
521 DIR *dir;
|
|
522 struct dirent *ent;
|
|
523
|
|
524 dir = opendir( path );
|
|
525 if( !dir ) return -2;
|
|
526
|
|
527 while( ( ent = readdir( dir ) ) != NULL ) {
|
|
528 if( !strcasecmp( ent->d_name, file ) ) {
|
|
529 sprintf( filename, "%s%s%s", path,
|
|
530 ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
|
|
531 ent->d_name );
|
|
532 return 0;
|
|
533 }
|
|
534 }
|
|
535
|
|
536 return -1;
|
|
537 }
|
|
538
|
|
539 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
|
|
540 {
|
|
541 char video_path[ PATH_MAX + 1 ];
|
|
542 const char *nodirfile;
|
|
543 int ret;
|
|
544
|
|
545 /* Strip off the directory for our search */
|
|
546 if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) {
|
|
547 nodirfile = &(file[ 10 ]);
|
|
548 } else {
|
|
549 nodirfile = file;
|
|
550 }
|
|
551
|
|
552 ret = findDirFile( dvd->path_root, nodirfile, filename );
|
|
553 if( ret < 0 ) {
|
|
554 /* Try also with adding the path, just in case. */
|
|
555 sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root );
|
|
556 ret = findDirFile( video_path, nodirfile, filename );
|
|
557 if( ret < 0 ) {
|
|
558 /* Try with the path, but in lower case. */
|
|
559 sprintf( video_path, "%s/video_ts/", dvd->path_root );
|
|
560 ret = findDirFile( video_path, nodirfile, filename );
|
|
561 if( ret < 0 ) {
|
|
562 return 0;
|
|
563 }
|
|
564 }
|
|
565 }
|
|
566
|
|
567 return 1;
|
|
568 }
|
|
569
|
|
570 /**
|
|
571 * Open an unencrypted file from a DVD directory tree.
|
|
572 */
|
|
573 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
|
|
574 {
|
|
575 char full_path[ PATH_MAX + 1 ];
|
|
576 dvd_file_t *dvd_file;
|
|
577 struct stat fileinfo;
|
|
578 dvd_input_t dev;
|
|
579
|
|
580 /* Get the full path of the file. */
|
|
581 if( !findDVDFile( dvd, filename, full_path ) ) return 0;
|
|
582
|
|
583 dev = dvdinput_open( full_path );
|
|
584 if( !dev ) return 0;
|
|
585
|
|
586 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
|
|
587 if( !dvd_file ) return 0;
|
|
588 dvd_file->dvd = dvd;
|
|
589 dvd_file->lb_start = 0;
|
|
590 dvd_file->seek_pos = 0;
|
|
591 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
|
|
592 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
|
|
593 dvd_file->filesize = 0;
|
|
594
|
|
595 if( stat( full_path, &fileinfo ) < 0 ) {
|
|
596 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
|
|
597 free( dvd_file );
|
|
598 return 0;
|
|
599 }
|
|
600 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
|
|
601 dvd_file->title_devs[ 0 ] = dev;
|
|
602 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
|
|
603
|
|
604 return dvd_file;
|
|
605 }
|
|
606
|
|
607 static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu )
|
|
608 {
|
|
609 char filename[ MAX_UDF_FILE_NAME_LEN ];
|
|
610 uint32_t start, len;
|
|
611 dvd_file_t *dvd_file;
|
|
612
|
|
613 if( title == 0 ) {
|
|
614 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
|
|
615 } else {
|
|
616 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
|
|
617 }
|
|
618 start = UDFFindFile( dvd, filename, &len );
|
|
619 if( start == 0 ) return 0;
|
|
620
|
|
621 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
|
|
622 if( !dvd_file ) return 0;
|
|
623 dvd_file->dvd = dvd;
|
|
624 /*Hack*/ dvd_file->css_title = title << 1 | menu;
|
|
625 dvd_file->lb_start = start;
|
|
626 dvd_file->seek_pos = 0;
|
|
627 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
|
|
628 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
|
|
629 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
|
|
630
|
|
631 /* Calculate the complete file size for every file in the VOBS */
|
|
632 if( !menu ) {
|
|
633 int cur;
|
|
634
|
|
635 for( cur = 2; cur < 10; cur++ ) {
|
|
636 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
|
|
637 if( !UDFFindFile( dvd, filename, &len ) ) break;
|
|
638 dvd_file->filesize += len / DVD_VIDEO_LB_LEN;
|
|
639 }
|
|
640 }
|
|
641
|
|
642 if( dvd->css_state == 1 /* Need key init */ ) {
|
|
643 initAllCSSKeys( dvd );
|
|
644 dvd->css_state = 2;
|
|
645 }
|
|
646 /*
|
|
647 if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) {
|
|
648 fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n",
|
|
649 filename );
|
|
650 }
|
|
651 */
|
|
652
|
|
653 return dvd_file;
|
|
654 }
|
|
655
|
|
656 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
|
|
657 {
|
|
658 char filename[ MAX_UDF_FILE_NAME_LEN ];
|
|
659 char full_path[ PATH_MAX + 1 ];
|
|
660 struct stat fileinfo;
|
|
661 dvd_file_t *dvd_file;
|
|
662 int i;
|
|
663
|
|
664 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
|
|
665 if( !dvd_file ) return 0;
|
|
666 dvd_file->dvd = dvd;
|
|
667 /*Hack*/ dvd_file->css_title = title << 1 | menu;
|
|
668 dvd_file->lb_start = 0;
|
|
669 dvd_file->seek_pos = 0;
|
|
670 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
|
|
671 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
|
|
672 dvd_file->filesize = 0;
|
|
673
|
|
674 if( menu ) {
|
|
675 dvd_input_t dev;
|
|
676
|
|
677 if( title == 0 ) {
|
|
678 sprintf( filename, "VIDEO_TS.VOB" );
|
|
679 } else {
|
|
680 sprintf( filename, "VTS_%02i_0.VOB", title );
|
|
681 }
|
|
682 if( !findDVDFile( dvd, filename, full_path ) ) {
|
|
683 free( dvd_file );
|
|
684 return 0;
|
|
685 }
|
|
686
|
|
687 dev = dvdinput_open( full_path );
|
|
688 if( dev == NULL ) {
|
|
689 free( dvd_file );
|
|
690 return 0;
|
|
691 }
|
|
692
|
|
693 if( stat( full_path, &fileinfo ) < 0 ) {
|
|
694 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
|
|
695 free( dvd_file );
|
|
696 return 0;
|
|
697 }
|
|
698 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
|
|
699 dvd_file->title_devs[ 0 ] = dev;
|
|
700 dvdinput_title( dvd_file->title_devs[0], 0);
|
|
701 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
|
|
702
|
|
703 } else {
|
|
704 for( i = 0; i < 9; ++i ) {
|
|
705
|
|
706 sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 );
|
|
707 if( !findDVDFile( dvd, filename, full_path ) ) {
|
|
708 break;
|
|
709 }
|
|
710
|
|
711 if( stat( full_path, &fileinfo ) < 0 ) {
|
|
712 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
|
|
713 break;
|
|
714 }
|
|
715
|
|
716 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
|
|
717 dvd_file->title_devs[ i ] = dvdinput_open( full_path );
|
|
718 dvdinput_title( dvd_file->title_devs[ i ], 0 );
|
|
719 dvd_file->filesize += dvd_file->title_sizes[ i ];
|
|
720 }
|
|
721 if( !dvd_file->title_devs[ 0 ] ) {
|
|
722 free( dvd_file );
|
|
723 return 0;
|
|
724 }
|
|
725 }
|
|
726
|
|
727 return dvd_file;
|
|
728 }
|
|
729
|
|
730 dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum,
|
|
731 dvd_read_domain_t domain )
|
|
732 {
|
|
733 char filename[ MAX_UDF_FILE_NAME_LEN ];
|
|
734
|
|
735 /* Check arguments. */
|
|
736 if( dvd == NULL || titlenum < 0 )
|
|
737 return NULL;
|
|
738
|
|
739 switch( domain ) {
|
|
740 case DVD_READ_INFO_FILE:
|
|
741 if( titlenum == 0 ) {
|
|
742 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
|
|
743 } else {
|
|
744 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
|
|
745 }
|
|
746 break;
|
|
747 case DVD_READ_INFO_BACKUP_FILE:
|
|
748 if( titlenum == 0 ) {
|
|
749 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
|
|
750 } else {
|
|
751 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
|
|
752 }
|
|
753 break;
|
|
754 case DVD_READ_MENU_VOBS:
|
|
755 if( dvd->isImageFile ) {
|
|
756 return DVDOpenVOBUDF( dvd, titlenum, 1 );
|
|
757 } else {
|
|
758 return DVDOpenVOBPath( dvd, titlenum, 1 );
|
|
759 }
|
|
760 break;
|
|
761 case DVD_READ_TITLE_VOBS:
|
|
762 if( titlenum == 0 ) return 0;
|
|
763 if( dvd->isImageFile ) {
|
|
764 return DVDOpenVOBUDF( dvd, titlenum, 0 );
|
|
765 } else {
|
|
766 return DVDOpenVOBPath( dvd, titlenum, 0 );
|
|
767 }
|
|
768 break;
|
|
769 default:
|
|
770 fprintf( stderr, "libdvdread: Invalid domain for file open.\n" );
|
|
771 return NULL;
|
|
772 }
|
|
773
|
|
774 if( dvd->isImageFile ) {
|
|
775 return DVDOpenFileUDF( dvd, filename );
|
|
776 } else {
|
|
777 return DVDOpenFilePath( dvd, filename );
|
|
778 }
|
|
779 }
|
|
780
|
|
781 void DVDCloseFile( dvd_file_t *dvd_file )
|
|
782 {
|
|
783 int i;
|
|
784
|
|
785 if( dvd_file ) {
|
|
786 if( dvd_file->dvd->isImageFile ) {
|
|
787 ;
|
|
788 } else {
|
|
789 for( i = 0; i < 9; ++i ) {
|
|
790 if( dvd_file->title_devs[ i ] ) {
|
|
791 dvdinput_close( dvd_file->title_devs[i] );
|
|
792 }
|
|
793 }
|
|
794 }
|
|
795
|
|
796 free( dvd_file );
|
|
797 dvd_file = 0;
|
|
798 }
|
|
799 }
|
|
800
|
|
801 /* Internal, but used from dvd_udf.c */
|
|
802 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
|
|
803 size_t block_count, unsigned char *data,
|
|
804 int encrypted )
|
|
805 {
|
|
806 int ret;
|
|
807 if( !device->dev ) {
|
|
808 fprintf( stderr, "libdvdread: Fatal error in block read.\n" );
|
|
809 return 0;
|
|
810 }
|
|
811
|
|
812 ret = dvdinput_seek( device->dev, (int) lb_number );
|
|
813 if( ret != (int) lb_number ) {
|
|
814 fprintf( stderr, "libdvdread: Can't seek to block %u\n", lb_number );
|
|
815 return 0;
|
|
816 }
|
|
817
|
|
818 ret = dvdinput_read( device->dev, (char *) data,
|
|
819 (int) block_count, encrypted );
|
|
820 return ret;
|
|
821 }
|
|
822
|
|
823 /* This is using a single input and starting from 'dvd_file->lb_start' offset.
|
|
824 *
|
|
825 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
|
|
826 * into the buffer located at 'data' and if 'encrypted' is set
|
|
827 * descramble the data if it's encrypted. Returning either an
|
|
828 * negative error or the number of blocks read. */
|
|
829 static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset,
|
|
830 size_t block_count, unsigned char *data,
|
|
831 int encrypted )
|
|
832 {
|
|
833 return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset,
|
|
834 block_count, data, encrypted );
|
|
835 }
|
|
836
|
|
837 /* This is using possibly several inputs and starting from an offset of '0'.
|
|
838 *
|
|
839 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
|
|
840 * into the buffer located at 'data' and if 'encrypted' is set
|
|
841 * descramble the data if it's encrypted. Returning either an
|
|
842 * negative error or the number of blocks read. */
|
|
843 static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset,
|
|
844 size_t block_count, unsigned char *data,
|
|
845 int encrypted )
|
|
846 {
|
|
847 int i;
|
|
848 int ret, ret2, off;
|
|
849
|
|
850 ret = 0;
|
|
851 ret2 = 0;
|
|
852 for( i = 0; i < 9; ++i ) {
|
|
853 if( !dvd_file->title_sizes[ i ] ) return 0; /* Past end of file */
|
|
854
|
|
855 if( offset < dvd_file->title_sizes[ i ] ) {
|
|
856 if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) {
|
|
857 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
|
|
858 if( off < 0 || off != (int)offset ) {
|
|
859 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
|
|
860 offset );
|
|
861 return off < 0 ? off : 0;
|
|
862 }
|
|
863 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
|
|
864 (int)block_count, encrypted );
|
|
865 break;
|
|
866 } else {
|
|
867 size_t part1_size = dvd_file->title_sizes[ i ] - offset;
|
|
868 /* FIXME: Really needs to be a while loop.
|
|
869 * (This is only true if you try and read >1GB at a time) */
|
|
870
|
|
871 /* Read part 1 */
|
|
872 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
|
|
873 if( off < 0 || off != (int)offset ) {
|
|
874 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
|
|
875 offset );
|
|
876 return off < 0 ? off : 0;
|
|
877 }
|
|
878 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
|
|
879 (int)part1_size, encrypted );
|
|
880 if( ret < 0 ) return ret;
|
|
881 /* FIXME: This is wrong if i is the last file in the set.
|
|
882 * also error from this read will not show in ret. */
|
|
883
|
|
884 /* Does the next part exist? If not then return now. */
|
|
885 if( !dvd_file->title_devs[ i + 1 ] ) return ret;
|
|
886
|
|
887 /* Read part 2 */
|
|
888 off = dvdinput_seek( dvd_file->title_devs[ i + 1 ], 0 );
|
|
889 if( off < 0 || off != 0 ) {
|
|
890 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
|
|
891 0 );
|
|
892 return off < 0 ? off : 0;
|
|
893 }
|
|
894 ret2 = dvdinput_read( dvd_file->title_devs[ i + 1 ],
|
|
895 data + ( part1_size
|
|
896 * (int64_t)DVD_VIDEO_LB_LEN ),
|
|
897 (int)(block_count - part1_size),
|
|
898 encrypted );
|
|
899 if( ret2 < 0 ) return ret2;
|
|
900 break;
|
|
901 }
|
|
902 } else {
|
|
903 offset -= dvd_file->title_sizes[ i ];
|
|
904 }
|
|
905 }
|
|
906
|
|
907 return ret + ret2;
|
|
908 }
|
|
909
|
|
910 /* This is broken reading more than 2Gb at a time is ssize_t is 32-bit. */
|
|
911 ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset,
|
|
912 size_t block_count, unsigned char *data )
|
|
913 {
|
|
914 int ret;
|
|
915 /* Check arguments. */
|
|
916 if( dvd_file == NULL || offset < 0 || data == NULL )
|
|
917 return -1;
|
|
918
|
|
919 /* Hack, and it will still fail for multiple opens in a threaded app ! */
|
|
920 if( dvd_file->dvd->css_title != dvd_file->css_title ) {
|
|
921 dvd_file->dvd->css_title = dvd_file->css_title;
|
|
922 if( dvd_file->dvd->isImageFile ) {
|
|
923 dvdinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start );
|
|
924 }
|
|
925 /* Here each vobu has it's own dvdcss handle, so no need to update
|
|
926 else {
|
|
927 dvdinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start );
|
|
928 }*/
|
|
929 }
|
|
930
|
|
931 if( dvd_file->dvd->isImageFile ) {
|
|
932 ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset,
|
|
933 block_count, data, DVDINPUT_READ_DECRYPT );
|
|
934 } else {
|
|
935 ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset,
|
|
936 block_count, data, DVDINPUT_READ_DECRYPT );
|
|
937 }
|
|
938
|
|
939 return (ssize_t)ret;
|
|
940 }
|
|
941
|
|
942 int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset )
|
|
943 {
|
|
944 /* Check arguments. */
|
|
945 if( dvd_file == NULL || offset < 0 )
|
|
946 return -1;
|
|
947
|
|
948 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
|
|
949 return -1;
|
|
950 }
|
|
951 dvd_file->seek_pos = (uint32_t) offset;
|
|
952 return offset;
|
|
953 }
|
|
954
|
|
955 ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
|
|
956 {
|
183
|
957 unsigned char *secbuf_base, *secbuf;
|
168
|
958 unsigned int numsec, seek_sector, seek_byte;
|
|
959 int ret;
|
|
960
|
|
961 /* Check arguments. */
|
|
962 if( dvd_file == NULL || data == NULL )
|
|
963 return -1;
|
|
964
|
|
965 seek_sector = dvd_file->seek_pos / DVD_VIDEO_LB_LEN;
|
|
966 seek_byte = dvd_file->seek_pos % DVD_VIDEO_LB_LEN;
|
|
967
|
|
968 numsec = ( ( seek_byte + byte_size ) / DVD_VIDEO_LB_LEN ) +
|
|
969 ( ( ( seek_byte + byte_size ) % DVD_VIDEO_LB_LEN ) ? 1 : 0 );
|
|
970
|
183
|
971 secbuf_base = (unsigned char *) malloc( numsec * DVD_VIDEO_LB_LEN + 2048 );
|
|
972 secbuf = (unsigned char *)(((int)secbuf_base & ~2047) + 2048);
|
|
973 if( !secbuf_base ) {
|
168
|
974 fprintf( stderr, "libdvdread: Can't allocate memory "
|
|
975 "for file read!\n" );
|
|
976 return 0;
|
|
977 }
|
|
978
|
|
979 if( dvd_file->dvd->isImageFile ) {
|
|
980 ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector,
|
|
981 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
|
|
982 } else {
|
|
983 ret = DVDReadBlocksPath( dvd_file, seek_sector,
|
|
984 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
|
|
985 }
|
|
986
|
|
987 if( ret != (int) numsec ) {
|
183
|
988 free( secbuf_base );
|
168
|
989 return ret < 0 ? ret : 0;
|
|
990 }
|
|
991
|
|
992 memcpy( data, &(secbuf[ seek_byte ]), byte_size );
|
183
|
993 free( secbuf_base );
|
168
|
994
|
|
995 dvd_file->seek_pos += byte_size;
|
|
996 return byte_size;
|
|
997 }
|
|
998
|
|
999 ssize_t DVDFileSize( dvd_file_t *dvd_file )
|
|
1000 {
|
|
1001 /* Check arguments. */
|
|
1002 if( dvd_file == NULL )
|
|
1003 return -1;
|
|
1004
|
|
1005 return dvd_file->filesize;
|
|
1006 }
|
|
1007
|
|
1008 int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
|
|
1009 {
|
|
1010 struct md5_ctx ctx;
|
|
1011 int title;
|
|
1012
|
|
1013 /* Check arguments. */
|
|
1014 if( dvd == NULL || discid == NULL )
|
|
1015 return 0;
|
|
1016
|
|
1017 /* Go through the first 10 IFO:s, in order,
|
|
1018 * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO */
|
|
1019 md5_init_ctx( &ctx );
|
|
1020 for( title = 0; title < 10; title++ ) {
|
|
1021 dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
|
|
1022 if( dvd_file != NULL ) {
|
|
1023 ssize_t bytes_read;
|
|
1024 size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
|
183
|
1025 char *buffer_base = malloc( file_size + 2048 );
|
|
1026 char *buffer = (unsigned char *)(((int)buffer_base & ~2047) + 2048);
|
168
|
1027
|
183
|
1028 if( buffer_base == NULL ) {
|
168
|
1029 fprintf( stderr, "libdvdread: DVDDiscId, failed to "
|
|
1030 "allocate memory for file read!\n" );
|
|
1031 return -1;
|
|
1032 }
|
|
1033 bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
|
|
1034 if( bytes_read != file_size ) {
|
|
1035 fprintf( stderr, "libdvdread: DVDDiscId read returned %d bytes"
|
|
1036 ", wanted %d\n", bytes_read, file_size );
|
|
1037 DVDCloseFile( dvd_file );
|
183
|
1038 free( buffer_base );
|
168
|
1039 return -1;
|
|
1040 }
|
|
1041
|
|
1042 md5_process_bytes( buffer, file_size, &ctx );
|
|
1043
|
|
1044 DVDCloseFile( dvd_file );
|
183
|
1045 free( buffer_base );
|
168
|
1046 }
|
|
1047 }
|
|
1048 md5_finish_ctx( &ctx, discid );
|
|
1049
|
|
1050 return 0;
|
|
1051 }
|
|
1052
|
|
1053
|
|
1054 int DVDISOVolumeInfo( dvd_reader_t *dvd,
|
|
1055 char *volid, unsigned int volid_size,
|
|
1056 unsigned char *volsetid, unsigned int volsetid_size )
|
|
1057 {
|
183
|
1058 unsigned char *buffer, *buffer_base;
|
168
|
1059 int ret;
|
|
1060
|
|
1061 /* Check arguments. */
|
|
1062 if( dvd == NULL )
|
|
1063 return 0;
|
|
1064
|
|
1065 if( dvd->dev == NULL ) {
|
|
1066 /* No block access, so no ISO... */
|
|
1067 return -1;
|
|
1068 }
|
|
1069
|
183
|
1070 buffer_base = malloc( DVD_VIDEO_LB_LEN + 2048 );
|
|
1071 buffer = (unsigned char *)(((int)buffer_base & ~2047) + 2048);
|
|
1072
|
|
1073 if( buffer_base == NULL ) {
|
168
|
1074 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
|
|
1075 "allocate memory for file read!\n" );
|
|
1076 return -1;
|
|
1077 }
|
|
1078
|
|
1079 ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 );
|
|
1080 if( ret != 1 ) {
|
|
1081 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
|
|
1082 "read ISO9660 Primary Volume Descriptor!\n" );
|
183
|
1083 free( buffer_base );
|
168
|
1084 return -1;
|
|
1085 }
|
|
1086
|
|
1087 if( (volid != NULL) && (volid_size > 0) ) {
|
|
1088 unsigned int n;
|
|
1089 for(n = 0; n < 32; n++) {
|
|
1090 if(buffer[40+n] == 0x20) {
|
|
1091 break;
|
|
1092 }
|
|
1093 }
|
|
1094
|
|
1095 if(volid_size > n+1) {
|
|
1096 volid_size = n+1;
|
|
1097 }
|
|
1098
|
|
1099 memcpy(volid, &buffer[40], volid_size-1);
|
|
1100 volid[volid_size-1] = '\0';
|
|
1101 }
|
|
1102
|
|
1103 if( (volsetid != NULL) && (volsetid_size > 0) ) {
|
|
1104 if(volsetid_size > 128) {
|
|
1105 volsetid_size = 128;
|
|
1106 }
|
|
1107 memcpy(volsetid, &buffer[190], volsetid_size);
|
|
1108 }
|
183
|
1109 free( buffer_base );
|
168
|
1110 return 0;
|
|
1111 }
|
|
1112
|
|
1113
|
|
1114 int DVDUDFVolumeInfo( dvd_reader_t *dvd,
|
|
1115 char *volid, unsigned int volid_size,
|
|
1116 unsigned char *volsetid, unsigned int volsetid_size )
|
|
1117 {
|
|
1118 int ret;
|
|
1119 /* Check arguments. */
|
|
1120 if( dvd == NULL )
|
|
1121 return -1;
|
|
1122
|
|
1123 if( dvd->dev == NULL ) {
|
|
1124 /* No block access, so no UDF VolumeSet Identifier */
|
|
1125 return -1;
|
|
1126 }
|
|
1127
|
|
1128 if( (volid != NULL) && (volid_size > 0) ) {
|
|
1129 ret = UDFGetVolumeIdentifier(dvd, volid, volid_size);
|
|
1130 if(!ret) {
|
|
1131 return -1;
|
|
1132 }
|
|
1133 }
|
|
1134 if( (volsetid != NULL) && (volsetid_size > 0) ) {
|
|
1135 ret = UDFGetVolumeSetIdentifier(dvd, volsetid, volsetid_size);
|
|
1136 if(!ret) {
|
|
1137 return -1;
|
|
1138 }
|
|
1139 }
|
|
1140
|
|
1141 return 0;
|
|
1142 }
|