comparison dvdread/dvd_reader.c @ 24055:98ba5d5bfe2d

Sync libdvdread with version 0.9.6.
author diego
date Thu, 16 Aug 2007 06:57:43 +0000
parents 1542693b2a30
children eb9f3e3723d1
comparison
equal deleted inserted replaced
24054:6e218aef8e05 24055:98ba5d5bfe2d
411 } 411 }
412 #endif 412 #endif
413 413
414 #if defined(SYS_BSD) 414 #if defined(SYS_BSD)
415 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recomended to _not_ use r 415 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recomended to _not_ use r
416 update: FreeBSD and DragonFly no longer uses the prefix so don't add it.
417
416 OpenBSD /dev/rcd0c, it needs to be the raw device 418 OpenBSD /dev/rcd0c, it needs to be the raw device
417 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others 419 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others
418 Darwin /dev/rdisk0, it needs to be the raw device 420 Darwin /dev/rdisk0, it needs to be the raw device
419 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do) */ 421 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do)
422
423 returns a string allocated with strdup which should be free()'d when
424 no longer used.
425 */
420 static char *bsd_block2char( const char *path ) 426 static char *bsd_block2char( const char *path )
421 #if defined(__FreeBSD__) 427 {
422 { 428 #if defined(__FreeBSD__) || defined(__DragonFly__)
423 return (char *) strdup( path ); 429 return (char *) strdup( path );
424 }
425 #else 430 #else
426 {
427 char *new_path; 431 char *new_path;
428 432
429 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */ 433 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
430 if( strncmp( path, "/dev/", 5 ) || !strncmp( path, "/dev/r", 6 ) ) 434 if( strncmp( path, "/dev/", 5 ) || !strncmp( path, "/dev/r", 6 ) )
431 return (char *) strdup( path ); 435 return (char *) strdup( path );
434 new_path = malloc( strlen(path) + 2 ); 438 new_path = malloc( strlen(path) + 2 );
435 strcpy( new_path, "/dev/r" ); 439 strcpy( new_path, "/dev/r" );
436 strcat( new_path, path + strlen( "/dev/" ) ); 440 strcat( new_path, path + strlen( "/dev/" ) );
437 441
438 return new_path; 442 return new_path;
439 } 443 #endif /* __FreeBSD__ || __DragonFly__ */
440 #endif /* __FreeBSD__ */ 444 }
441 #endif 445 #endif
442 446
443 447
444 dvd_reader_t *DVDOpen( const char *path ) 448 dvd_reader_t *DVDOpen( const char *path )
445 { 449 {
484 488
485 /* First check if this is a block/char device or a file*/ 489 /* First check if this is a block/char device or a file*/
486 if( S_ISBLK( fileinfo.st_mode ) || 490 if( S_ISBLK( fileinfo.st_mode ) ||
487 S_ISCHR( fileinfo.st_mode ) || 491 S_ISCHR( fileinfo.st_mode ) ||
488 S_ISREG( fileinfo.st_mode ) ) { 492 S_ISREG( fileinfo.st_mode ) ) {
489
490 /** 493 /**
491 * Block devices and regular files are assumed to be DVD-Video images. 494 * Block devices and regular files are assumed to be DVD-Video images.
492 */ 495 */
496 dvd_reader_t *dvd = NULL;
493 #if defined(__sun) 497 #if defined(__sun)
494 return DVDOpenImageFile( sun_block2char( path ), have_css ); 498 dev_name = sun_block2char( path );
495 #elif defined(SYS_BSD) 499 #elif defined(SYS_BSD)
496 return DVDOpenImageFile( bsd_block2char( path ), have_css ); 500 dev_name = bsd_block2char( path );
497 #else 501 #else
498 return DVDOpenImageFile( path, have_css ); 502 dev_name = strdup( path );
499 #endif 503 #endif
500 504 dvd = DVDOpenImageFile( dev_name, have_css );
505 free( dev_name );
506
507 return dvd;
501 } else if( S_ISDIR( fileinfo.st_mode ) ) { 508 } else if( S_ISDIR( fileinfo.st_mode ) ) {
502 dvd_reader_t *auth_drive = 0; 509 dvd_reader_t *auth_drive = 0;
503 char *path_copy; 510 char *path_copy;
504 #if defined(SYS_BSD) 511 #if defined(SYS_BSD)
505 struct fstab* fe; 512 struct fstab* fe;
1016 } 1023 }
1017 1024
1018 free( dvd_file ); 1025 free( dvd_file );
1019 dvd_file = 0; 1026 dvd_file = 0;
1020 } 1027 }
1028 }
1029
1030 static int DVDFileStatVOBUDF(dvd_reader_t *dvd, int title,
1031 int menu, dvd_stat_t *statbuf)
1032 {
1033 char filename[ MAX_UDF_FILE_NAME_LEN ];
1034 uint32_t size;
1035 off_t tot_size;
1036 off_t parts_size[9];
1037 int nr_parts = 0;
1038 int n;
1039
1040 if( title == 0 ) {
1041 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
1042 } else {
1043 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
1044 }
1045 if(!UDFFindFile( dvd, filename, &size )) {
1046 return -1;
1047 }
1048 tot_size = size;
1049 nr_parts = 1;
1050 parts_size[0] = size;
1051
1052 if( !menu ) {
1053 int cur;
1054
1055 for( cur = 2; cur < 10; cur++ ) {
1056 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
1057 if( !UDFFindFile( dvd, filename, &size ) ) {
1058 break;
1059 }
1060 parts_size[nr_parts] = size;
1061 tot_size += size;
1062 nr_parts++;
1063 }
1064 }
1065
1066 statbuf->size = tot_size;
1067 statbuf->nr_parts = nr_parts;
1068 for(n = 0; n < nr_parts; n++) {
1069 statbuf->parts_size[n] = parts_size[n];
1070 }
1071 return 0;
1072 }
1073
1074
1075 static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
1076 int menu, dvd_stat_t *statbuf )
1077 {
1078 char filename[ MAX_UDF_FILE_NAME_LEN ];
1079 char full_path[ PATH_MAX + 1 ];
1080 struct stat fileinfo;
1081 off_t tot_size;
1082 off_t parts_size[9];
1083 int nr_parts = 0;
1084 int n;
1085
1086
1087
1088 if( title == 0 ) {
1089 sprintf( filename, "VIDEO_TS.VOB" );
1090 } else {
1091 sprintf( filename, "VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
1092 }
1093 if( !findDVDFile( dvd, filename, full_path ) ) {
1094 return -1;
1095 }
1096
1097 if( stat( full_path, &fileinfo ) < 0 ) {
1098 if(dvd->verbose >= 1) {
1099 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
1100 }
1101 return -1;
1102 }
1103
1104
1105 tot_size = fileinfo.st_size;
1106 nr_parts = 1;
1107 parts_size[0] = fileinfo.st_size;
1108
1109 if( !menu ) {
1110 int cur;
1111
1112 for( cur = 2; cur < 10; cur++ ) {
1113
1114 sprintf( filename, "VTS_%02d_%d.VOB", title, cur );
1115 if( !findDVDFile( dvd, filename, full_path ) ) {
1116 break;
1117 }
1118
1119 if( stat( full_path, &fileinfo ) < 0 ) {
1120 if(dvd->verbose >= 1) {
1121 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
1122 }
1123 break;
1124 }
1125
1126 parts_size[nr_parts] = fileinfo.st_size;
1127 tot_size += parts_size[nr_parts];
1128 nr_parts++;
1129 }
1130 }
1131
1132 statbuf->size = tot_size;
1133 statbuf->nr_parts = nr_parts;
1134 for(n = 0; n < nr_parts; n++) {
1135 statbuf->parts_size[n] = parts_size[n];
1136 }
1137 return 0;
1138 }
1139
1140
1141 int DVDFileStat(dvd_reader_t *dvd, int titlenum,
1142 dvd_read_domain_t domain, dvd_stat_t *statbuf)
1143 {
1144 char filename[ MAX_UDF_FILE_NAME_LEN ];
1145 char full_path[ PATH_MAX + 1 ];
1146 struct stat fileinfo;
1147 uint32_t size;
1148
1149 /* Check arguments. */
1150 if( dvd == NULL || titlenum < 0 ) {
1151 errno = EINVAL;
1152 return -1;
1153 }
1154
1155 switch( domain ) {
1156 case DVD_READ_INFO_FILE:
1157 if( titlenum == 0 ) {
1158 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
1159 } else {
1160 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
1161 }
1162 break;
1163 case DVD_READ_INFO_BACKUP_FILE:
1164 if( titlenum == 0 ) {
1165 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
1166 } else {
1167 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
1168 }
1169 break;
1170 case DVD_READ_MENU_VOBS:
1171 if( dvd->isImageFile ) {
1172 return DVDFileStatVOBUDF( dvd, titlenum, 1, statbuf );
1173 } else {
1174 return DVDFileStatVOBPath( dvd, titlenum, 1, statbuf );
1175 }
1176 break;
1177 case DVD_READ_TITLE_VOBS:
1178 if( titlenum == 0 ) {
1179 return -1;
1180 }
1181 if( dvd->isImageFile ) {
1182 return DVDFileStatVOBUDF( dvd, titlenum, 0, statbuf );
1183 } else {
1184 return DVDFileStatVOBPath( dvd, titlenum, 0, statbuf );
1185 }
1186 break;
1187 default:
1188 if(dvd->verbose >= 1) {
1189 fprintf( stderr, "libdvdread: Invalid domain for file stat.\n" );
1190 }
1191 errno = EINVAL;
1192 return -1;
1193 }
1194
1195 if( dvd->isImageFile ) {
1196 if( UDFFindFile( dvd, filename, &size ) ) {
1197 statbuf->size = size;
1198 statbuf->nr_parts = 1;
1199 statbuf->parts_size[0] = size;
1200 return 0;
1201 }
1202 } else {
1203 if( findDVDFile( dvd, filename, full_path ) ) {
1204 if( stat( full_path, &fileinfo ) < 0 ) {
1205 if(dvd->verbose >= 1) {
1206 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
1207 }
1208 } else {
1209 statbuf->size = fileinfo.st_size;
1210 statbuf->nr_parts = 1;
1211 statbuf->parts_size[0] = statbuf->size;
1212 return 0;
1213 }
1214 }
1215 }
1216 return -1;
1021 } 1217 }
1022 1218
1023 /** 1219 /**
1024 * Internal, but used from dvd_udf.c 1220 * Internal, but used from dvd_udf.c
1025 * 1221 *