Search
lxdream.org :: lxdream/src/gdrom/cdi.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/cdi.c
changeset 736:a02d1475ccfd
prev678:35eb00945316
next759:f16975739abc
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/gdrom/cdi.c Thu May 29 11:00:26 2008 +0000
1.2 +++ b/src/gdrom/cdi.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -33,10 +33,10 @@
1.4 static gdrom_disc_t cdi_image_open( const gchar *filename, FILE *f );
1.5
1.6 struct gdrom_image_class cdi_image_class = { "DiscJuggler", "cdi",
1.7 - cdi_image_is_valid, cdi_image_open };
1.8 + cdi_image_is_valid, cdi_image_open };
1.9
1.10 static const char TRACK_START_MARKER[20] = { 0,0,1,0,0,0,255,255,255,255,
1.11 - 0,0,1,0,0,0,255,255,255,255 };
1.12 + 0,0,1,0,0,0,255,255,255,255 };
1.13 static const char EXT_MARKER[9] = {0,255,255,255,255,255,255,255,255 };
1.14
1.15 struct cdi_trailer {
1.16 @@ -66,10 +66,10 @@
1.17 len = ftell(f)+8;
1.18 fread( &trail, sizeof(trail), 1, f );
1.19 if( trail.header_offset >= len ||
1.20 - trail.header_offset == 0 )
1.21 - return FALSE;
1.22 + trail.header_offset == 0 )
1.23 + return FALSE;
1.24 return trail.cdi_version == CDI_V2_ID || trail.cdi_version == CDI_V3_ID ||
1.25 - trail.cdi_version == CDI_V35_ID;
1.26 + trail.cdi_version == CDI_V35_ID;
1.27 }
1.28
1.29 gdrom_disc_t cdi_image_open( const gchar *filename, FILE *f )
1.30 @@ -89,119 +89,119 @@
1.31 len = ftell(f)+8;
1.32 fread( &trail, sizeof(trail), 1, f );
1.33 if( trail.header_offset >= len ||
1.34 - trail.header_offset == 0 )
1.35 - return NULL;
1.36 -
1.37 + trail.header_offset == 0 )
1.38 + return NULL;
1.39 +
1.40 if( trail.cdi_version != CDI_V2_ID && trail.cdi_version != CDI_V3_ID &&
1.41 - trail.cdi_version != CDI_V35_ID ) {
1.42 - return NULL;
1.43 + trail.cdi_version != CDI_V35_ID ) {
1.44 + return NULL;
1.45 }
1.46
1.47 if( trail.cdi_version == CDI_V35_ID ) {
1.48 - fseek( f, -trail.header_offset, SEEK_END );
1.49 + fseek( f, -trail.header_offset, SEEK_END );
1.50 } else {
1.51 - fseek( f, trail.header_offset, SEEK_SET );
1.52 + fseek( f, trail.header_offset, SEEK_SET );
1.53 }
1.54 fread( &session_count, sizeof(session_count), 1, f );
1.55 -
1.56 +
1.57 disc = gdrom_image_new(filename, f);
1.58 if( disc == NULL ) {
1.59 - ERROR("Unable to allocate memory!");
1.60 - return NULL;
1.61 + ERROR("Unable to allocate memory!");
1.62 + return NULL;
1.63 }
1.64 image = (gdrom_image_t)disc;
1.65
1.66 for( i=0; i< session_count; i++ ) {
1.67 - fread( &track_count, sizeof(track_count), 1, f );
1.68 - if( track_count + total_tracks > 99 ) {
1.69 - ERROR( "Invalid number of tracks, bad cdi image\n" );
1.70 - gdrom_image_destroy_no_close(disc);
1.71 - return NULL;
1.72 - }
1.73 + fread( &track_count, sizeof(track_count), 1, f );
1.74 + if( track_count + total_tracks > 99 ) {
1.75 + ERROR( "Invalid number of tracks, bad cdi image\n" );
1.76 + gdrom_image_destroy_no_close(disc);
1.77 + return NULL;
1.78 + }
1.79 for( j=0; j<track_count; j++ ) {
1.80 struct cdi_track_data trk;
1.81 uint32_t new_fmt = 0;
1.82 - uint8_t fnamelen = 0;
1.83 + uint8_t fnamelen = 0;
1.84 fread( &new_fmt, sizeof(new_fmt), 1, f );
1.85 if( new_fmt != 0 ) { /* Additional data 3.00.780+ ?? */
1.86 - fseek( f, 8, SEEK_CUR ); /* Skip */
1.87 + fseek( f, 8, SEEK_CUR ); /* Skip */
1.88 }
1.89 fread( marker, 20, 1, f );
1.90 if( memcmp( marker, TRACK_START_MARKER, 20) != 0 ) {
1.91 - ERROR( "Track start marker not found, error reading cdi image\n" );
1.92 - gdrom_image_destroy_no_close(disc);
1.93 - return NULL;
1.94 - }
1.95 - fseek( f, 4, SEEK_CUR );
1.96 + ERROR( "Track start marker not found, error reading cdi image\n" );
1.97 + gdrom_image_destroy_no_close(disc);
1.98 + return NULL;
1.99 + }
1.100 + fseek( f, 4, SEEK_CUR );
1.101 fread( &fnamelen, 1, 1, f );
1.102 fseek( f, (int)fnamelen, SEEK_CUR ); /* skip over the filename */
1.103 - fseek( f, 19, SEEK_CUR );
1.104 - fread( &new_fmt, sizeof(new_fmt), 1, f );
1.105 - if( new_fmt == 0x80000000 ) {
1.106 - fseek( f, 10, SEEK_CUR );
1.107 - } else {
1.108 - fseek( f, 2, SEEK_CUR );
1.109 - }
1.110 + fseek( f, 19, SEEK_CUR );
1.111 + fread( &new_fmt, sizeof(new_fmt), 1, f );
1.112 + if( new_fmt == 0x80000000 ) {
1.113 + fseek( f, 10, SEEK_CUR );
1.114 + } else {
1.115 + fseek( f, 2, SEEK_CUR );
1.116 + }
1.117 fread( &trk, sizeof(trk), 1, f );
1.118 - image->track[total_tracks].session = i;
1.119 - image->track[total_tracks].lba = trk.start_lba + 150;
1.120 - image->track[total_tracks].sector_count = trk.length;
1.121 - switch( trk.mode ) {
1.122 - case 0:
1.123 - image->track[total_tracks].mode = GDROM_CDDA;
1.124 - image->track[total_tracks].sector_size = 2352;
1.125 - image->track[total_tracks].flags = 0x01;
1.126 - if( trk.sector_size != 2 ) {
1.127 - ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.128 - gdrom_image_destroy_no_close(disc);
1.129 - return NULL;
1.130 - }
1.131 - break;
1.132 - case 1:
1.133 - image->track[total_tracks].mode = GDROM_MODE1;
1.134 - image->track[total_tracks].sector_size = 2048;
1.135 - image->track[total_tracks].flags = 0x41;
1.136 - if( trk.sector_size != 0 ) {
1.137 - ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.138 - gdrom_image_destroy_no_close(disc);
1.139 - return NULL;
1.140 - }
1.141 - break;
1.142 - case 2:
1.143 - image->track[total_tracks].flags = 0x41;
1.144 - switch( trk.sector_size ) {
1.145 - case 0:
1.146 - image->track[total_tracks].mode = GDROM_MODE2_FORM1;
1.147 - image->track[total_tracks].sector_size = 2048;
1.148 - break;
1.149 - case 1:
1.150 - image->track[total_tracks].mode = GDROM_SEMIRAW_MODE2;
1.151 - image->track[total_tracks].sector_size = 2336;
1.152 - break;
1.153 - case 2:
1.154 - default:
1.155 - ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.156 - gdrom_image_destroy_no_close(disc);
1.157 - return NULL;
1.158 - }
1.159 - break;
1.160 - default:
1.161 - ERROR( "Unsupported track mode %d", trk.mode );
1.162 - gdrom_image_destroy_no_close(disc);
1.163 - return NULL;
1.164 - }
1.165 - image->track[total_tracks].offset = posn +
1.166 - trk.pregap_length * image->track[total_tracks].sector_size ;
1.167 - posn += trk.total_length * image->track[total_tracks].sector_size;
1.168 - total_tracks++;
1.169 - fread( marker, 1, 9, f );
1.170 - if( memcmp( marker, EXT_MARKER, 9 ) == 0 ) {
1.171 - fseek( f, 79, SEEK_CUR );
1.172 - } else {
1.173 - fseek( f, -9, SEEK_CUR );
1.174 - }
1.175 - }
1.176 - fseek( f, 12, SEEK_CUR );
1.177 + image->track[total_tracks].session = i;
1.178 + image->track[total_tracks].lba = trk.start_lba + 150;
1.179 + image->track[total_tracks].sector_count = trk.length;
1.180 + switch( trk.mode ) {
1.181 + case 0:
1.182 + image->track[total_tracks].mode = GDROM_CDDA;
1.183 + image->track[total_tracks].sector_size = 2352;
1.184 + image->track[total_tracks].flags = 0x01;
1.185 + if( trk.sector_size != 2 ) {
1.186 + ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.187 + gdrom_image_destroy_no_close(disc);
1.188 + return NULL;
1.189 + }
1.190 + break;
1.191 + case 1:
1.192 + image->track[total_tracks].mode = GDROM_MODE1;
1.193 + image->track[total_tracks].sector_size = 2048;
1.194 + image->track[total_tracks].flags = 0x41;
1.195 + if( trk.sector_size != 0 ) {
1.196 + ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.197 + gdrom_image_destroy_no_close(disc);
1.198 + return NULL;
1.199 + }
1.200 + break;
1.201 + case 2:
1.202 + image->track[total_tracks].flags = 0x41;
1.203 + switch( trk.sector_size ) {
1.204 + case 0:
1.205 + image->track[total_tracks].mode = GDROM_MODE2_FORM1;
1.206 + image->track[total_tracks].sector_size = 2048;
1.207 + break;
1.208 + case 1:
1.209 + image->track[total_tracks].mode = GDROM_SEMIRAW_MODE2;
1.210 + image->track[total_tracks].sector_size = 2336;
1.211 + break;
1.212 + case 2:
1.213 + default:
1.214 + ERROR( "Invalid combination of mode %d with size %d", trk.mode, trk.sector_size );
1.215 + gdrom_image_destroy_no_close(disc);
1.216 + return NULL;
1.217 + }
1.218 + break;
1.219 + default:
1.220 + ERROR( "Unsupported track mode %d", trk.mode );
1.221 + gdrom_image_destroy_no_close(disc);
1.222 + return NULL;
1.223 + }
1.224 + image->track[total_tracks].offset = posn +
1.225 + trk.pregap_length * image->track[total_tracks].sector_size ;
1.226 + posn += trk.total_length * image->track[total_tracks].sector_size;
1.227 + total_tracks++;
1.228 + fread( marker, 1, 9, f );
1.229 + if( memcmp( marker, EXT_MARKER, 9 ) == 0 ) {
1.230 + fseek( f, 79, SEEK_CUR );
1.231 + } else {
1.232 + fseek( f, -9, SEEK_CUR );
1.233 + }
1.234 + }
1.235 + fseek( f, 12, SEEK_CUR );
1.236 }
1.237 image->track_count = total_tracks;
1.238 return disc;
.