Search
lxdream.org :: lxdream/src/gdrom/cdi.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/cdi.c
changeset 342:850502f0e8de
prev236:581a9f8bf6a6
next347:e686be8b10df
author nkeynes
date Wed Jan 31 10:58:42 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Refactor gdrom module to be more conducive to real device support
file annotate diff log raw
1.1 --- a/src/gdrom/cdi.c Thu Dec 14 11:58:18 2006 +0000
1.2 +++ b/src/gdrom/cdi.c Wed Jan 31 10:58:42 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: cdi.c,v 1.4 2006-12-14 11:58:18 nkeynes Exp $
1.6 + * $Id: cdi.c,v 1.5 2007-01-31 10:58:42 nkeynes Exp $
1.7 *
1.8 * CDI CD-image file support
1.9 *
1.10 @@ -74,6 +74,7 @@
1.11 gdrom_disc_t cdi_image_open( const gchar *filename, FILE *f )
1.12 {
1.13 gdrom_disc_t disc = NULL;
1.14 + gdrom_image_t image;
1.15 int fd = -1, i,j, tmp;
1.16 uint16_t session_count;
1.17 uint16_t track_count;
1.18 @@ -100,6 +101,12 @@
1.19 fread( &session_count, sizeof(session_count), 1, f );
1.20
1.21 disc = gdrom_image_new(f);
1.22 + if( disc == NULL ) {
1.23 + fclose(f);
1.24 + ERROR("Unable to allocate memory!");
1.25 + return NULL;
1.26 + }
1.27 + image = (gdrom_image_t)disc;
1.28
1.29 for( i=0; i< session_count; i++ ) {
1.30 fread( &track_count, sizeof(track_count), 1, f );
1.31 @@ -114,63 +121,63 @@
1.32 fread( marker, 20, 1, f );
1.33 if( memcmp( marker, track_start_marker, 20) != 0 ) {
1.34 ERROR( "Track start marker not found, error reading cdi image\n" );
1.35 - free(disc);
1.36 + disc->close(disc);
1.37 return NULL;
1.38 }
1.39 fseek( f, 4, SEEK_CUR );
1.40 fread( &fnamelen, 1, 1, f );
1.41 fseek( f, (int)fnamelen, SEEK_CUR ); /* skip over the filename */
1.42 fread( &trk, sizeof(trk), 1, f );
1.43 - disc->track[total_tracks].session = i;
1.44 - disc->track[total_tracks].lba = trk.start_lba + 150;
1.45 - disc->track[total_tracks].sector_count = trk.length;
1.46 + image->track[total_tracks].session = i;
1.47 + image->track[total_tracks].lba = trk.start_lba + 150;
1.48 + image->track[total_tracks].sector_count = trk.length;
1.49 switch( trk.mode ) {
1.50 case 0:
1.51 - disc->track[total_tracks].mode = GDROM_CDDA;
1.52 - disc->track[total_tracks].sector_size = 2352;
1.53 - disc->track[total_tracks].flags = 0x01;
1.54 + image->track[total_tracks].mode = GDROM_CDDA;
1.55 + image->track[total_tracks].sector_size = 2352;
1.56 + image->track[total_tracks].flags = 0x01;
1.57 if( trk.sector_size != 2 ) {
1.58 ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.59 - free(disc);
1.60 + disc->close(disc);
1.61 return NULL;
1.62 }
1.63 break;
1.64 case 1:
1.65 - disc->track[total_tracks].mode = GDROM_MODE1;
1.66 - disc->track[total_tracks].sector_size = 2048;
1.67 - disc->track[total_tracks].flags = 0x41;
1.68 + image->track[total_tracks].mode = GDROM_MODE1;
1.69 + image->track[total_tracks].sector_size = 2048;
1.70 + image->track[total_tracks].flags = 0x41;
1.71 if( trk.sector_size != 0 ) {
1.72 ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.73 - free(disc);
1.74 + disc->close(disc);
1.75 return NULL;
1.76 }
1.77 break;
1.78 case 2:
1.79 - disc->track[total_tracks].flags = 0x41;
1.80 + image->track[total_tracks].flags = 0x41;
1.81 switch( trk.sector_size ) {
1.82 case 0:
1.83 - disc->track[total_tracks].mode = GDROM_MODE2_XA1;
1.84 - disc->track[total_tracks].sector_size = 2048;
1.85 + image->track[total_tracks].mode = GDROM_MODE2_XA1;
1.86 + image->track[total_tracks].sector_size = 2048;
1.87 break;
1.88 case 1:
1.89 - disc->track[total_tracks].mode = GDROM_MODE2;
1.90 - disc->track[total_tracks].sector_size = 2336;
1.91 + image->track[total_tracks].mode = GDROM_MODE2;
1.92 + image->track[total_tracks].sector_size = 2336;
1.93 break;
1.94 case 2:
1.95 default:
1.96 ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.97 - free(disc);
1.98 + disc->close(disc);
1.99 return NULL;
1.100 }
1.101 break;
1.102 default:
1.103 ERROR( "Unsupported track mode %d", trk.mode );
1.104 - free(disc);
1.105 + disc->close(disc);
1.106 return NULL;
1.107 }
1.108 - disc->track[total_tracks].offset = posn +
1.109 - trk.pregap_length * disc->track[total_tracks].sector_size ;
1.110 - posn += trk.total_length * disc->track[total_tracks].sector_size;
1.111 + image->track[total_tracks].offset = posn +
1.112 + trk.pregap_length * image->track[total_tracks].sector_size ;
1.113 + posn += trk.total_length * image->track[total_tracks].sector_size;
1.114 total_tracks++;
1.115 lseek( fd, 12, SEEK_CUR );
1.116 if( new_fmt ) {
1.117 @@ -180,8 +187,7 @@
1.118 }
1.119 }
1.120 }
1.121 - disc->track_count = total_tracks;
1.122 - disc->file = f;
1.123 - disc->filename = filename;
1.124 + image->track_count = total_tracks;
1.125 + image->filename = filename;
1.126 return disc;
1.127 }
.