Fix vf_tcdump's compilation
[mplayer/kovensky.git] / libdvdread4 / dvd_reader.c
blobfd2b48607700c23e015ea9769f176e9d43432f2f
1 /*
2 * Copyright (C) 2001-2004 Billy Biggs <vektor@dumbterm.net>,
3 * Håkan Hjort <d95hjort@dtek.chalmers.se>,
4 * Björn Englund <d4bjorn@dtek.chalmers.se>
6 * This file is part of libdvdread.
8 * libdvdread is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * libdvdread is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with libdvdread; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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>
35 /* misc win32 helpers */
36 #ifdef WIN32
37 #ifndef HAVE_GETTIMEOFDAY
38 /* replacement gettimeofday implementation */
39 #include <sys/timeb.h>
40 static inline int _private_gettimeofday( struct timeval *tv, void *tz )
42 struct timeb t;
43 ftime( &t );
44 tv->tv_sec = t.time;
45 tv->tv_usec = t.millitm * 1000;
46 return 0;
48 #define gettimeofday(TV, TZ) _private_gettimeofday((TV), (TZ))
49 #endif
50 #include <io.h> /* read() */
51 #define lseek64 _lseeki64
52 #endif
54 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__APPLE__)
55 #define SYS_BSD 1
56 #endif
58 #if defined(__sun)
59 #include <sys/mnttab.h>
60 #elif defined(SYS_BSD)
61 #include <fstab.h>
62 #elif defined(__linux__)
63 #include <mntent.h>
64 #endif
66 #include "dvdread/dvd_udf.h"
67 #include "dvd_input.h"
68 #include "dvdread/dvd_reader.h"
69 #include "md5.h"
71 #define DEFAULT_UDF_CACHE_LEVEL 1
73 struct dvd_reader_s {
74 /* Basic information. */
75 int isImageFile;
77 /* Hack for keeping track of the css status.
78 * 0: no css, 1: perhaps (need init of keys), 2: have done init */
79 int css_state;
80 int css_title; /* Last title that we have called dvdinpute_title for. */
82 /* Information required for an image file. */
83 dvd_input_t dev;
85 /* Information required for a directory path drive. */
86 char *path_root;
88 /* Filesystem cache */
89 int udfcache_level; /* 0 - turned off, 1 - on */
90 void *udfcache;
93 #define TITLES_MAX 9
95 struct dvd_file_s {
96 /* Basic information. */
97 dvd_reader_t *dvd;
99 /* Hack for selecting the right css title. */
100 int css_title;
102 /* Information required for an image file. */
103 uint32_t lb_start;
104 uint32_t seek_pos;
106 /* Information required for a directory path drive. */
107 size_t title_sizes[ TITLES_MAX ];
108 dvd_input_t title_devs[ TITLES_MAX ];
110 /* Calculated at open-time, size in blocks. */
111 ssize_t filesize;
114 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
115 size_t block_count, unsigned char *data,
116 int encrypted );
119 * Set the level of caching on udf
120 * level = 0 (no caching)
121 * level = 1 (caching filesystem info)
123 int DVDUDFCacheLevel(dvd_reader_t *device, int level)
125 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
127 if(level > 0) {
128 level = 1;
129 } else if(level < 0) {
130 return dev->udfcache_level;
133 dev->udfcache_level = level;
135 return level;
138 void *GetUDFCacheHandle(dvd_reader_t *device)
140 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
142 return dev->udfcache;
145 void SetUDFCacheHandle(dvd_reader_t *device, void *cache)
147 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
149 dev->udfcache = cache;
154 /* Loop over all titles and call dvdcss_title to crack the keys. */
155 static int initAllCSSKeys( dvd_reader_t *dvd )
157 struct timeval all_s, all_e;
158 struct timeval t_s, t_e;
159 char filename[ MAX_UDF_FILE_NAME_LEN ];
160 uint32_t start, len;
161 int title;
163 char *nokeys_str = getenv("DVDREAD_NOKEYS");
164 if(nokeys_str != NULL)
165 return 0;
167 fprintf( stderr, "\n" );
168 fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" );
169 fprintf( stderr, "libdvdread: This can take a _long_ time, "
170 "please be patient\n\n" );
171 gettimeofday(&all_s, NULL);
173 for( title = 0; title < 100; title++ ) {
174 gettimeofday( &t_s, NULL );
175 if( title == 0 ) {
176 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
177 } else {
178 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 0 );
180 start = UDFFindFile( dvd, filename, &len );
181 if( start != 0 && len != 0 ) {
182 /* Perform CSS key cracking for this title. */
183 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
184 filename, start );
185 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
186 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start);
188 gettimeofday( &t_e, NULL );
189 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
190 (long int) t_e.tv_sec - t_s.tv_sec );
193 if( title == 0 ) continue;
195 gettimeofday( &t_s, NULL );
196 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 );
197 start = UDFFindFile( dvd, filename, &len );
198 if( start == 0 || len == 0 ) break;
200 /* Perform CSS key cracking for this title. */
201 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
202 filename, start );
203 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
204 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start);
206 gettimeofday( &t_e, NULL );
207 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
208 (long int) t_e.tv_sec - t_s.tv_sec );
210 title--;
212 fprintf( stderr, "libdvdread: Found %d VTS's\n", title );
213 gettimeofday(&all_e, NULL);
214 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
215 (long int) all_e.tv_sec - all_s.tv_sec );
217 return 0;
223 * Open a DVD image or block device file.
225 static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css )
227 dvd_reader_t *dvd;
228 dvd_input_t dev;
230 dev = dvdinput_open( location );
231 if( !dev ) {
232 fprintf( stderr, "libdvdread: Can't open %s for reading\n", location );
233 return NULL;
236 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
237 if( !dvd ) {
238 dvdinput_close(dev);
239 return NULL;
241 dvd->isImageFile = 1;
242 dvd->dev = dev;
243 dvd->path_root = NULL;
245 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
246 dvd->udfcache = NULL;
248 if( have_css ) {
249 /* Only if DVDCSS_METHOD = title, a bit if it's disc or if
250 * DVDCSS_METHOD = key but region mismatch. Unfortunately we
251 * don't have that information. */
253 dvd->css_state = 1; /* Need key init. */
255 dvd->css_title = 0;
257 return dvd;
260 static dvd_reader_t *DVDOpenPath( const char *path_root )
262 dvd_reader_t *dvd;
264 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
265 if( !dvd ) return NULL;
266 dvd->isImageFile = 0;
267 dvd->dev = 0;
268 dvd->path_root = strdup( path_root );
269 if(!dvd->path_root) {
270 free(dvd);
271 return 0;
273 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
274 dvd->udfcache = NULL;
276 dvd->css_state = 0; /* Only used in the UDF path */
277 dvd->css_title = 0; /* Only matters in the UDF path */
279 return dvd;
282 #if defined(__sun)
283 /* /dev/rdsk/c0t6d0s0 (link to /devices/...)
284 /vol/dev/rdsk/c0t6d0/??
285 /vol/rdsk/<name> */
286 static char *sun_block2char( const char *path )
288 char *new_path;
290 /* Must contain "/dsk/" */
291 if( !strstr( path, "/dsk/" ) ) return (char *) strdup( path );
293 /* Replace "/dsk/" with "/rdsk/" */
294 new_path = malloc( strlen(path) + 2 );
295 strcpy( new_path, path );
296 strcpy( strstr( new_path, "/dsk/" ), "" );
297 strcat( new_path, "/rdsk/" );
298 strcat( new_path, strstr( path, "/dsk/" ) + strlen( "/dsk/" ) );
300 return new_path;
302 #endif
304 #if defined(SYS_BSD)
305 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recommended to _not_ use r
306 update: FreeBSD and DragonFly no longer uses the prefix so don't add it.
307 OpenBSD /dev/rcd0c, it needs to be the raw device
308 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others
309 Darwin /dev/rdisk0, it needs to be the raw device
310 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do)
311 returns a string allocated with strdup. It should be freed when no longer
312 used. */
313 static char *bsd_block2char( const char *path )
315 #if defined(__FreeBSD__) || defined(__DragonFly__)
316 return (char *) strdup( path );
317 #else
318 char *new_path;
320 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
321 if( !strncmp( path, "/dev/", 5 ) || strncmp( path, "/dev/r", 6 ) )
322 return (char *) strdup( path );
324 /* Replace "/dev/" with "/dev/r" */
325 new_path = malloc( strlen(path) + 2 );
326 strcpy( new_path, "/dev/r" );
327 strcat( new_path, path + strlen( "/dev/" ) );
329 return new_path;
330 #endif /* __FreeBSD__ || __DragonFly__ */
332 #endif
335 dvd_reader_t *DVDOpen( const char *ppath )
337 struct stat fileinfo;
338 int ret, have_css, retval, cdir = -1;
339 dvd_reader_t *ret_val = NULL;
340 char *dev_name = NULL;
341 char *path = NULL, *new_path = NULL, *path_copy = NULL;
343 #ifdef _WIN32
344 int len;
345 #endif
347 if( ppath == NULL )
348 goto DVDOpen_error;
350 path = strdup(ppath);
351 if( path == NULL )
352 goto DVDOpen_error;
354 /* Try to open libdvdcss or fall back to standard functions */
355 have_css = dvdinput_setup();
357 #ifdef _WIN32
358 /* Strip off the trailing \ if it is not a drive */
359 len = strlen(path);
360 if ((len > 1) &&
361 (path[len - 1] == '\\') &&
362 (path[len - 2] != ':'))
364 path[len-1] = '\0';
366 #endif
368 ret = stat( path, &fileinfo );
370 if( ret < 0 ) {
372 /* maybe "host:port" url? try opening it with acCeSS library */
373 if( strchr(path,':') ) {
374 ret_val = DVDOpenImageFile( path, have_css );
375 free(path);
376 return ret_val;
379 /* If we can't stat the file, give up */
380 fprintf( stderr, "libdvdread: Can't stat %s\n", path );
381 perror("");
382 goto DVDOpen_error;
385 /* First check if this is a block/char device or a file*/
386 if( S_ISBLK( fileinfo.st_mode ) ||
387 S_ISCHR( fileinfo.st_mode ) ||
388 S_ISREG( fileinfo.st_mode ) ) {
391 * Block devices and regular files are assumed to be DVD-Video images.
393 dvd_reader_t *dvd = NULL;
394 #if defined(__sun)
395 dev_name = sun_block2char( path );
396 #elif defined(SYS_BSD)
397 dev_name = bsd_block2char( path );
398 #else
399 dev_name = strdup( path );
400 #endif
401 dvd = DVDOpenImageFile( dev_name, have_css );
402 free( dev_name );
403 free(path);
404 return dvd;
405 } else if( S_ISDIR( fileinfo.st_mode ) ) {
406 dvd_reader_t *auth_drive = 0;
407 #if defined(SYS_BSD)
408 struct fstab* fe;
409 #elif defined(__sun) || defined(__linux__)
410 FILE *mntfile;
411 #endif
413 /* XXX: We should scream real loud here. */
414 if( !(path_copy = strdup( path ) ) )
415 goto DVDOpen_error;
417 #ifndef WIN32 /* don't have fchdir, and getcwd( NULL, ... ) is strange */
418 /* Also WIN32 does not have symlinks, so we don't need this bit of code. */
420 /* Resolve any symlinks and get the absolute dir name. */
422 if( ( cdir = open( ".", O_RDONLY ) ) >= 0 ) {
423 if( chdir( path_copy ) == -1 ) {
424 goto DVDOpen_error;
426 new_path = malloc(PATH_MAX+1);
427 if(!new_path) {
428 goto DVDOpen_error;
430 if( getcwd( new_path, PATH_MAX ) == NULL ) {
431 goto DVDOpen_error;
433 retval = fchdir( cdir );
434 close( cdir );
435 cdir = -1;
436 if( retval == -1 ) {
437 goto DVDOpen_error;
439 path_copy = new_path;
440 new_path = NULL;
443 #endif
446 * If we're being asked to open a directory, check if that directory
447 * is the mount point for a DVD-ROM which we can use instead.
450 if( strlen( path_copy ) > 1 ) {
451 if( path_copy[ strlen( path_copy ) - 1 ] == '/' ) {
452 path_copy[ strlen( path_copy ) - 1 ] = '\0';
456 if( strlen( path_copy ) > TITLES_MAX ) {
457 if( !strcasecmp( &(path_copy[ strlen( path_copy ) - TITLES_MAX ]),
458 "/video_ts" ) ) {
459 path_copy[ strlen( path_copy ) - TITLES_MAX ] = '\0';
463 if(path_copy[0] == '\0') {
464 path_copy[0] = '/';
465 path_copy[1] = '\0';
468 #if defined(SYS_BSD)
469 if( ( fe = getfsfile( path_copy ) ) ) {
470 dev_name = bsd_block2char( fe->fs_spec );
471 fprintf( stderr,
472 "libdvdread: Attempting to use device %s"
473 " mounted on %s for CSS authentication\n",
474 dev_name,
475 fe->fs_file );
476 auth_drive = DVDOpenImageFile( dev_name, have_css );
478 #elif defined(__sun)
479 mntfile = fopen( MNTTAB, "r" );
480 if( mntfile ) {
481 struct mnttab mp;
482 int res;
484 while( ( res = getmntent( mntfile, &mp ) ) != -1 ) {
485 if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) {
486 dev_name = sun_block2char( mp.mnt_special );
487 fprintf( stderr,
488 "libdvdread: Attempting to use device %s"
489 " mounted on %s for CSS authentication\n",
490 dev_name,
491 mp.mnt_mountp );
492 auth_drive = DVDOpenImageFile( dev_name, have_css );
493 break;
496 fclose( mntfile );
498 #elif defined(__linux__)
499 mntfile = fopen( MOUNTED, "r" );
500 if( mntfile ) {
501 struct mntent *me;
503 while( ( me = getmntent( mntfile ) ) ) {
504 if( !strcmp( me->mnt_dir, path_copy ) ) {
505 fprintf( stderr,
506 "libdvdread: Attempting to use device %s"
507 " mounted on %s for CSS authentication\n",
508 me->mnt_fsname,
509 me->mnt_dir );
510 auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css );
511 dev_name = strdup(me->mnt_fsname);
512 break;
515 fclose( mntfile );
517 #elif defined(_WIN32) || defined(__OS2__)
518 auth_drive = DVDOpenImageFile( path, have_css );
519 #endif
521 #if !defined(_WIN32) && !defined(__OS2__)
522 if( !dev_name ) {
523 fprintf( stderr, "libdvdread: Couldn't find device name.\n" );
524 } else if( !auth_drive ) {
525 fprintf( stderr, "libdvdread: Device %s inaccessible, "
526 "CSS authentication not available.\n", dev_name );
528 #else
529 if( !auth_drive ) {
530 fprintf( stderr, "libdvdread: Device %s inaccessible, "
531 "CSS authentication not available.\n", dev_name );
533 #endif
535 free( dev_name );
536 dev_name = NULL;
537 free( path_copy );
538 path_copy = NULL;
541 * If we've opened a drive, just use that.
543 if( auth_drive ) {
544 free(path);
545 return auth_drive;
548 * Otherwise, we now try to open the directory tree instead.
550 ret_val = DVDOpenPath( path );
551 free( path );
552 return ret_val;
555 DVDOpen_error:
556 /* If it's none of the above, screw it. */
557 fprintf( stderr, "libdvdread: Could not open %s\n", path );
558 if( path != NULL )
559 free( path );
560 if ( path_copy != NULL )
561 free( path_copy );
562 if ( cdir >= 0 )
563 close( cdir );
564 if ( new_path != NULL )
565 free( new_path );
566 return NULL;
569 void DVDClose( dvd_reader_t *dvd )
571 if( dvd ) {
572 if( dvd->dev ) dvdinput_close( dvd->dev );
573 if( dvd->path_root ) free( dvd->path_root );
574 if( dvd->udfcache ) FreeUDFCache( dvd->udfcache );
575 free( dvd );
580 * Open an unencrypted file on a DVD image file.
582 static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename )
584 uint32_t start, len;
585 dvd_file_t *dvd_file;
587 start = UDFFindFile( dvd, filename, &len );
588 if( !start ) {
589 fprintf( stderr, "libdvdnav:DVDOpenFileUDF:UDFFindFile %s failed\n", filename );
590 return NULL;
593 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
594 if( !dvd_file ) {
595 fprintf( stderr, "libdvdnav:DVDOpenFileUDF:malloc failed\n" );
596 return NULL;
598 dvd_file->dvd = dvd;
599 dvd_file->lb_start = start;
600 dvd_file->seek_pos = 0;
601 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
602 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
603 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
605 return dvd_file;
609 * Searches for <file> in directory <path>, ignoring case.
610 * Returns 0 and full filename in <filename>.
611 * or -1 on file not found.
612 * or -2 on path not found.
614 static int findDirFile( const char *path, const char *file, char *filename )
616 DIR *dir;
617 struct dirent *ent;
619 dir = opendir( path );
620 if( !dir ) return -2;
622 while( ( ent = readdir( dir ) ) != NULL ) {
623 if( !strcasecmp( ent->d_name, file ) ) {
624 sprintf( filename, "%s%s%s", path,
625 ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
626 ent->d_name );
627 closedir(dir);
628 return 0;
631 closedir(dir);
632 return -1;
635 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
637 char video_path[ PATH_MAX + 1 ];
638 const char *nodirfile;
639 int ret;
641 /* Strip off the directory for our search */
642 if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) {
643 nodirfile = &(file[ 10 ]);
644 } else {
645 nodirfile = file;
648 ret = findDirFile( dvd->path_root, nodirfile, filename );
649 if( ret < 0 ) {
650 /* Try also with adding the path, just in case. */
651 sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root );
652 ret = findDirFile( video_path, nodirfile, filename );
653 if( ret < 0 ) {
654 /* Try with the path, but in lower case. */
655 sprintf( video_path, "%s/video_ts/", dvd->path_root );
656 ret = findDirFile( video_path, nodirfile, filename );
657 if( ret < 0 ) {
658 return 0;
663 return 1;
667 * Open an unencrypted file from a DVD directory tree.
669 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
671 char full_path[ PATH_MAX + 1 ];
672 dvd_file_t *dvd_file;
673 struct stat fileinfo;
674 dvd_input_t dev;
676 /* Get the full path of the file. */
677 if( !findDVDFile( dvd, filename, full_path ) ) {
678 fprintf( stderr, "libdvdnav:DVDOpenFilePath:findDVDFile %s failed\n", filename );
679 return NULL;
682 dev = dvdinput_open( full_path );
683 if( !dev ) {
684 fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvdinput_open %s failed\n", full_path );
685 return NULL;
688 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
689 if( !dvd_file ) {
690 fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvd_file malloc failed\n" );
691 dvdinput_close(dev);
692 return NULL;
694 dvd_file->dvd = dvd;
695 dvd_file->lb_start = 0;
696 dvd_file->seek_pos = 0;
697 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
698 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
699 dvd_file->filesize = 0;
701 if( stat( full_path, &fileinfo ) < 0 ) {
702 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
703 free( dvd_file );
704 return NULL;
706 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
707 dvd_file->title_devs[ 0 ] = dev;
708 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
710 return dvd_file;
713 static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu )
715 char filename[ MAX_UDF_FILE_NAME_LEN ];
716 uint32_t start, len;
717 dvd_file_t *dvd_file;
719 if( title == 0 ) {
720 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
721 } else {
722 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
724 start = UDFFindFile( dvd, filename, &len );
725 if( start == 0 ) return NULL;
727 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
728 if( !dvd_file ) return NULL;
729 dvd_file->dvd = dvd;
730 /*Hack*/ dvd_file->css_title = title << 1 | menu;
731 dvd_file->lb_start = start;
732 dvd_file->seek_pos = 0;
733 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
734 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
735 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
737 /* Calculate the complete file size for every file in the VOBS */
738 if( !menu ) {
739 int cur;
741 for( cur = 2; cur < 10; cur++ ) {
742 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
743 if( !UDFFindFile( dvd, filename, &len ) ) break;
744 dvd_file->filesize += len / DVD_VIDEO_LB_LEN;
748 if( dvd->css_state == 1 /* Need key init */ ) {
749 initAllCSSKeys( dvd );
750 dvd->css_state = 2;
753 if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) {
754 fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n",
755 filename );
759 return dvd_file;
762 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
764 char filename[ MAX_UDF_FILE_NAME_LEN ];
765 char full_path[ PATH_MAX + 1 ];
766 struct stat fileinfo;
767 dvd_file_t *dvd_file;
768 int i;
770 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
771 if( !dvd_file ) return NULL;
772 dvd_file->dvd = dvd;
773 /*Hack*/ dvd_file->css_title = title << 1 | menu;
774 dvd_file->lb_start = 0;
775 dvd_file->seek_pos = 0;
776 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
777 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
778 dvd_file->filesize = 0;
780 if( menu ) {
781 dvd_input_t dev;
783 if( title == 0 ) {
784 sprintf( filename, "VIDEO_TS.VOB" );
785 } else {
786 sprintf( filename, "VTS_%02i_0.VOB", title );
788 if( !findDVDFile( dvd, filename, full_path ) ) {
789 free( dvd_file );
790 return NULL;
793 dev = dvdinput_open( full_path );
794 if( dev == NULL ) {
795 free( dvd_file );
796 return NULL;
799 if( stat( full_path, &fileinfo ) < 0 ) {
800 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
801 dvdinput_close(dev);
802 free( dvd_file );
803 return NULL;
805 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
806 dvd_file->title_devs[ 0 ] = dev;
807 dvdinput_title( dvd_file->title_devs[0], 0);
808 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
810 } else {
811 for( i = 0; i < TITLES_MAX; ++i ) {
813 sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 );
814 if( !findDVDFile( dvd, filename, full_path ) ) {
815 break;
818 if( stat( full_path, &fileinfo ) < 0 ) {
819 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
820 break;
823 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
824 dvd_file->title_devs[ i ] = dvdinput_open( full_path );
825 dvdinput_title( dvd_file->title_devs[ i ], 0 );
826 dvd_file->filesize += dvd_file->title_sizes[ i ];
828 if( !dvd_file->title_devs[ 0 ] ) {
829 free( dvd_file );
830 return NULL;
834 return dvd_file;
837 dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum,
838 dvd_read_domain_t domain )
840 char filename[ MAX_UDF_FILE_NAME_LEN ];
842 /* Check arguments. */
843 if( dvd == NULL || titlenum < 0 )
844 return NULL;
846 switch( domain ) {
847 case DVD_READ_INFO_FILE:
848 if( titlenum == 0 ) {
849 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
850 } else {
851 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
853 break;
854 case DVD_READ_INFO_BACKUP_FILE:
855 if( titlenum == 0 ) {
856 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
857 } else {
858 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
860 break;
861 case DVD_READ_MENU_VOBS:
862 if( dvd->isImageFile ) {
863 return DVDOpenVOBUDF( dvd, titlenum, 1 );
864 } else {
865 return DVDOpenVOBPath( dvd, titlenum, 1 );
867 break;
868 case DVD_READ_TITLE_VOBS:
869 if( titlenum == 0 ) return 0;
870 if( dvd->isImageFile ) {
871 return DVDOpenVOBUDF( dvd, titlenum, 0 );
872 } else {
873 return DVDOpenVOBPath( dvd, titlenum, 0 );
875 break;
876 default:
877 fprintf( stderr, "libdvdread: Invalid domain for file open.\n" );
878 return NULL;
881 if( dvd->isImageFile ) {
882 return DVDOpenFileUDF( dvd, filename );
883 } else {
884 return DVDOpenFilePath( dvd, filename );
888 void DVDCloseFile( dvd_file_t *dvd_file )
890 int i;
892 if( dvd_file ) {
893 if( !dvd_file->dvd->isImageFile ) {
894 for( i = 0; i < TITLES_MAX; ++i ) {
895 if( dvd_file->title_devs[ i ] ) {
896 dvdinput_close( dvd_file->title_devs[i] );
901 free( dvd_file );
902 dvd_file = 0;
906 static int DVDFileStatVOBUDF( dvd_reader_t *dvd, int title,
907 int menu, dvd_stat_t *statbuf )
909 char filename[ MAX_UDF_FILE_NAME_LEN ];
910 uint32_t size;
911 off_t tot_size;
912 off_t parts_size[ 9 ];
913 int nr_parts = 0;
914 int n;
916 if( title == 0 )
917 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
918 else
919 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
921 if( !UDFFindFile( dvd, filename, &size ) )
922 return -1;
924 tot_size = size;
925 nr_parts = 1;
926 parts_size[ 0 ] = size;
928 if( !menu ) {
929 int cur;
931 for( cur = 2; cur < 10; cur++ ) {
932 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
933 if( !UDFFindFile( dvd, filename, &size ) )
934 break;
936 parts_size[ nr_parts ] = size;
937 tot_size += size;
938 nr_parts++;
942 statbuf->size = tot_size;
943 statbuf->nr_parts = nr_parts;
944 for( n = 0; n < nr_parts; n++ )
945 statbuf->parts_size[ n ] = parts_size[ n ];
947 return 0;
951 static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
952 int menu, dvd_stat_t *statbuf )
954 char filename[ MAX_UDF_FILE_NAME_LEN ];
955 char full_path[ PATH_MAX + 1 ];
956 struct stat fileinfo;
957 off_t tot_size;
958 off_t parts_size[ 9 ];
959 int nr_parts = 0;
960 int n;
962 if( title == 0 )
963 sprintf( filename, "VIDEO_TS.VOB" );
964 else
965 sprintf( filename, "VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
967 if( !findDVDFile( dvd, filename, full_path ) )
968 return -1;
970 if( stat( full_path, &fileinfo ) < 0 ) {
971 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
972 return -1;
975 tot_size = fileinfo.st_size;
976 nr_parts = 1;
977 parts_size[ 0 ] = fileinfo.st_size;
979 if( !menu ) {
980 int cur;
981 for( cur = 2; cur < 10; cur++ ) {
982 sprintf( filename, "VTS_%02d_%d.VOB", title, cur );
983 if( !findDVDFile( dvd, filename, full_path ) )
984 break;
986 if( stat( full_path, &fileinfo ) < 0 ) {
987 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
988 break;
991 parts_size[ nr_parts ] = fileinfo.st_size;
992 tot_size += parts_size[ nr_parts ];
993 nr_parts++;
997 statbuf->size = tot_size;
998 statbuf->nr_parts = nr_parts;
999 for( n = 0; n < nr_parts; n++ )
1000 statbuf->parts_size[ n ] = parts_size[ n ];
1002 return 0;
1006 int DVDFileStat( dvd_reader_t *dvd, int titlenum,
1007 dvd_read_domain_t domain, dvd_stat_t *statbuf )
1009 char filename[ MAX_UDF_FILE_NAME_LEN ];
1010 char full_path[ PATH_MAX + 1 ];
1011 struct stat fileinfo;
1012 uint32_t size;
1014 /* Check arguments. */
1015 if( dvd == NULL || titlenum < 0 ) {
1016 errno = EINVAL;
1017 return -1;
1020 switch( domain ) {
1021 case DVD_READ_INFO_FILE:
1022 if( titlenum == 0 )
1023 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
1024 else
1025 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
1027 break;
1028 case DVD_READ_INFO_BACKUP_FILE:
1029 if( titlenum == 0 )
1030 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
1031 else
1032 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
1034 break;
1035 case DVD_READ_MENU_VOBS:
1036 if( dvd->isImageFile )
1037 return DVDFileStatVOBUDF( dvd, titlenum, 1, statbuf );
1038 else
1039 return DVDFileStatVOBPath( dvd, titlenum, 1, statbuf );
1041 break;
1042 case DVD_READ_TITLE_VOBS:
1043 if( titlenum == 0 )
1044 return -1;
1046 if( dvd->isImageFile )
1047 return DVDFileStatVOBUDF( dvd, titlenum, 0, statbuf );
1048 else
1049 return DVDFileStatVOBPath( dvd, titlenum, 0, statbuf );
1051 break;
1052 default:
1053 fprintf( stderr, "libdvdread: Invalid domain for file stat.\n" );
1054 errno = EINVAL;
1055 return -1;
1058 if( dvd->isImageFile ) {
1059 if( UDFFindFile( dvd, filename, &size ) ) {
1060 statbuf->size = size;
1061 statbuf->nr_parts = 1;
1062 statbuf->parts_size[ 0 ] = size;
1063 return 0;
1065 } else {
1066 if( findDVDFile( dvd, filename, full_path ) ) {
1067 if( stat( full_path, &fileinfo ) < 0 )
1068 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
1069 else {
1070 statbuf->size = fileinfo.st_size;
1071 statbuf->nr_parts = 1;
1072 statbuf->parts_size[ 0 ] = statbuf->size;
1073 return 0;
1077 return -1;
1080 /* Internal, but used from dvd_udf.c */
1081 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
1082 size_t block_count, unsigned char *data,
1083 int encrypted )
1085 int ret;
1087 if( !device->dev ) {
1088 fprintf( stderr, "libdvdread: Fatal error in block read.\n" );
1089 return 0;
1092 ret = dvdinput_seek( device->dev, (int) lb_number );
1093 if( ret != (int) lb_number ) {
1094 fprintf( stderr, "libdvdread: Can't seek to block %u\n", lb_number );
1095 return 0;
1098 ret = dvdinput_read( device->dev, (char *) data,
1099 (int) block_count, encrypted );
1100 return ret;
1103 /* This is using a single input and starting from 'dvd_file->lb_start' offset.
1105 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
1106 * into the buffer located at 'data' and if 'encrypted' is set
1107 * descramble the data if it's encrypted. Returning either an
1108 * negative error or the number of blocks read. */
1109 static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset,
1110 size_t block_count, unsigned char *data,
1111 int encrypted )
1113 return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset,
1114 block_count, data, encrypted );
1117 /* This is using possibly several inputs and starting from an offset of '0'.
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 DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset,
1124 size_t block_count, unsigned char *data,
1125 int encrypted )
1127 int i;
1128 int ret, ret2, off;
1130 ret = 0;
1131 ret2 = 0;
1132 for( i = 0; i < TITLES_MAX; ++i ) {
1133 if( !dvd_file->title_sizes[ i ] ) return 0; /* Past end of file */
1135 if( offset < dvd_file->title_sizes[ i ] ) {
1136 if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) {
1137 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
1138 if( off < 0 || off != (int)offset ) {
1139 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
1140 offset );
1141 return off < 0 ? off : 0;
1143 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
1144 (int)block_count, encrypted );
1145 break;
1146 } else {
1147 size_t part1_size = dvd_file->title_sizes[ i ] - offset;
1148 /* FIXME: Really needs to be a while loop.
1149 * (This is only true if you try and read >1GB at a time) */
1151 /* Read part 1 */
1152 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
1153 if( off < 0 || off != (int)offset ) {
1154 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
1155 offset );
1156 return off < 0 ? off : 0;
1158 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
1159 (int)part1_size, encrypted );
1160 if( ret < 0 ) return ret;
1161 /* FIXME: This is wrong if i is the last file in the set.
1162 * also error from this read will not show in ret. */
1164 /* Does the next part exist? If not then return now. */
1165 if( i + 1 >= TITLES_MAX || !dvd_file->title_devs[ i + 1 ] )
1166 return ret;
1168 /* Read part 2 */
1169 off = dvdinput_seek( dvd_file->title_devs[ i + 1 ], 0 );
1170 if( off < 0 || off != 0 ) {
1171 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
1172 0 );
1173 return off < 0 ? off : 0;
1175 ret2 = dvdinput_read( dvd_file->title_devs[ i + 1 ],
1176 data + ( part1_size
1177 * (int64_t)DVD_VIDEO_LB_LEN ),
1178 (int)(block_count - part1_size),
1179 encrypted );
1180 if( ret2 < 0 ) return ret2;
1181 break;
1183 } else {
1184 offset -= dvd_file->title_sizes[ i ];
1188 return ret + ret2;
1191 /* This is broken reading more than 2Gb at a time is ssize_t is 32-bit. */
1192 ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset,
1193 size_t block_count, unsigned char *data )
1195 int ret;
1197 /* Check arguments. */
1198 if( dvd_file == NULL || offset < 0 || data == NULL )
1199 return -1;
1201 /* Hack, and it will still fail for multiple opens in a threaded app ! */
1202 if( dvd_file->dvd->css_title != dvd_file->css_title ) {
1203 dvd_file->dvd->css_title = dvd_file->css_title;
1204 if( dvd_file->dvd->isImageFile ) {
1205 dvdinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start );
1207 /* Here each vobu has it's own dvdcss handle, so no need to update
1208 else {
1209 dvdinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start );
1213 if( dvd_file->dvd->isImageFile ) {
1214 ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset,
1215 block_count, data, DVDINPUT_READ_DECRYPT );
1216 } else {
1217 ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset,
1218 block_count, data, DVDINPUT_READ_DECRYPT );
1221 return (ssize_t)ret;
1224 int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset )
1226 /* Check arguments. */
1227 if( dvd_file == NULL || offset < 0 )
1228 return -1;
1230 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
1231 return -1;
1233 dvd_file->seek_pos = (uint32_t) offset;
1234 return offset;
1237 int DVDFileSeekForce(dvd_file_t *dvd_file, int offset, int force_size)
1239 /* Check arguments. */
1240 if( dvd_file == NULL || offset <= 0 )
1241 return -1;
1243 if( dvd_file->dvd->isImageFile ) {
1244 if( force_size < 0 )
1245 force_size = (offset - 1) / DVD_VIDEO_LB_LEN + 1;
1246 if( dvd_file->filesize < force_size ) {
1247 dvd_file->filesize = force_size;
1248 fprintf(stderr, "libdvdread: Ignored size of file indicated in UDF.\n");
1252 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN )
1253 return -1;
1255 dvd_file->seek_pos = (uint32_t) offset;
1256 return offset;
1259 ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
1261 unsigned char *secbuf_base, *secbuf;
1262 unsigned int numsec, seek_sector, seek_byte;
1263 int ret;
1265 /* Check arguments. */
1266 if( dvd_file == NULL || data == NULL )
1267 return -1;
1269 seek_sector = dvd_file->seek_pos / DVD_VIDEO_LB_LEN;
1270 seek_byte = dvd_file->seek_pos % DVD_VIDEO_LB_LEN;
1272 numsec = ( ( seek_byte + byte_size ) / DVD_VIDEO_LB_LEN ) +
1273 ( ( ( seek_byte + byte_size ) % DVD_VIDEO_LB_LEN ) ? 1 : 0 );
1275 secbuf_base = (unsigned char *) malloc( numsec * DVD_VIDEO_LB_LEN + 2048 );
1276 secbuf = (unsigned char *)(((uintptr_t)secbuf_base & ~((uintptr_t)2047)) + 2048);
1277 if( !secbuf_base ) {
1278 fprintf( stderr, "libdvdread: Can't allocate memory "
1279 "for file read!\n" );
1280 return 0;
1283 if( dvd_file->dvd->isImageFile ) {
1284 ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector,
1285 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
1286 } else {
1287 ret = DVDReadBlocksPath( dvd_file, seek_sector,
1288 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
1291 if( ret != (int) numsec ) {
1292 free( secbuf_base );
1293 return ret < 0 ? ret : 0;
1296 memcpy( data, &(secbuf[ seek_byte ]), byte_size );
1297 free( secbuf_base );
1299 DVDFileSeekForce(dvd_file, dvd_file->seek_pos + byte_size, -1);
1300 return byte_size;
1303 ssize_t DVDFileSize( dvd_file_t *dvd_file )
1305 /* Check arguments. */
1306 if( dvd_file == NULL )
1307 return -1;
1309 return dvd_file->filesize;
1312 int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
1314 struct md5_ctx ctx;
1315 int title;
1316 int nr_of_files = 0;
1318 /* Check arguments. */
1319 if( dvd == NULL || discid == NULL )
1320 return 0;
1322 /* Go through the first 10 IFO:s, in order,
1323 * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO */
1324 md5_init_ctx( &ctx );
1325 for( title = 0; title < 10; title++ ) {
1326 dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
1327 if( dvd_file != NULL ) {
1328 ssize_t bytes_read;
1329 size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
1330 char *buffer_base = malloc( file_size + 2048 );
1331 char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
1333 if( buffer_base == NULL ) {
1334 DVDCloseFile( dvd_file );
1335 fprintf( stderr, "libdvdread: DVDDiscId, failed to "
1336 "allocate memory for file read!\n" );
1337 return -1;
1340 bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
1341 if( bytes_read != file_size ) {
1342 fprintf( stderr, "libdvdread: DVDDiscId read returned %zd bytes"
1343 ", wanted %zd\n", bytes_read, file_size );
1344 DVDCloseFile( dvd_file );
1345 free( buffer_base );
1346 return -1;
1349 md5_process_bytes( buffer, file_size, &ctx );
1351 DVDCloseFile( dvd_file );
1352 free( buffer_base );
1353 nr_of_files++;
1356 md5_finish_ctx( &ctx, discid );
1357 if(!nr_of_files)
1358 return -1;
1360 return 0;
1364 int DVDISOVolumeInfo( dvd_reader_t *dvd,
1365 char *volid, unsigned int volid_size,
1366 unsigned char *volsetid, unsigned int volsetid_size )
1368 unsigned char *buffer, *buffer_base;
1369 int ret;
1371 /* Check arguments. */
1372 if( dvd == NULL )
1373 return 0;
1375 if( dvd->dev == NULL ) {
1376 /* No block access, so no ISO... */
1377 return -1;
1380 buffer_base = malloc( DVD_VIDEO_LB_LEN + 2048 );
1381 buffer = (unsigned char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
1383 if( buffer_base == NULL ) {
1384 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
1385 "allocate memory for file read!\n" );
1386 return -1;
1389 ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 );
1390 if( ret != 1 ) {
1391 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
1392 "read ISO9660 Primary Volume Descriptor!\n" );
1393 free( buffer_base );
1394 return -1;
1397 if( (volid != NULL) && (volid_size > 0) ) {
1398 unsigned int n;
1399 for(n = 0; n < 32; n++) {
1400 if(buffer[40+n] == 0x20) {
1401 break;
1405 if(volid_size > n+1) {
1406 volid_size = n+1;
1409 memcpy(volid, &buffer[40], volid_size-1);
1410 volid[volid_size-1] = '\0';
1413 if( (volsetid != NULL) && (volsetid_size > 0) ) {
1414 if(volsetid_size > 128) {
1415 volsetid_size = 128;
1417 memcpy(volsetid, &buffer[190], volsetid_size);
1419 free( buffer_base );
1420 return 0;
1424 int DVDUDFVolumeInfo( dvd_reader_t *dvd,
1425 char *volid, unsigned int volid_size,
1426 unsigned char *volsetid, unsigned int volsetid_size )
1428 int ret;
1429 /* Check arguments. */
1430 if( dvd == NULL )
1431 return -1;
1433 if( dvd->dev == NULL ) {
1434 /* No block access, so no UDF VolumeSet Identifier */
1435 return -1;
1438 if( (volid != NULL) && (volid_size > 0) ) {
1439 ret = UDFGetVolumeIdentifier(dvd, volid, volid_size);
1440 if(!ret) {
1441 return -1;
1444 if( (volsetid != NULL) && (volsetid_size > 0) ) {
1445 ret = UDFGetVolumeSetIdentifier(dvd, volsetid, volsetid_size);
1446 if(!ret) {
1447 return -1;
1451 return 0;