Search
lxdream.org :: lxdream/src/gdrom/nrg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/nrg.c
changeset 342:850502f0e8de
prev168:203a72138e16
next422:61a0598e07ff
author nkeynes
date Wed Jan 31 10:58:42 2007 +0000 (15 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/nrg.c Mon Jun 26 10:30:42 2006 +0000
1.2 +++ b/src/gdrom/nrg.c Wed Jan 31 10:58:42 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: nrg.c,v 1.3 2006-06-26 10:30:42 nkeynes Exp $
1.6 + * $Id: nrg.c,v 1.4 2007-01-31 10:58:42 nkeynes Exp $
1.7 *
1.8 * Nero (NRG) CD file format. File information stolen shamelessly from
1.9 * libcdio.
1.10 @@ -156,6 +156,7 @@
1.11 struct nrg_chunk chunk;
1.12 struct nrg_daoi *dao;
1.13 gdrom_disc_t disc;
1.14 + gdrom_image_t image;
1.15 gboolean end = FALSE;
1.16 int session_id = 0;
1.17 int session_track_id = 0;
1.18 @@ -178,9 +179,11 @@
1.19
1.20 disc = gdrom_image_new(f);
1.21 if( disc == NULL ) {
1.22 + fclose(f);
1.23 ERROR("Unable to allocate memory!");
1.24 return NULL;
1.25 }
1.26 + image = (gdrom_image_t)disc;
1.27
1.28 do {
1.29 fread( &chunk, sizeof(chunk), 1, f );
1.30 @@ -198,36 +201,36 @@
1.31 if( cue->track == 0 )
1.32 continue; /* Track 0. Leadin? always 0? */
1.33 if( cue->track == 0xAA ) { /* end of disc */
1.34 - disc->track[track_id-1].sector_count =
1.35 - msf_to_lba( cue->addr ) - disc->track[track_id-1].lba;
1.36 + image->track[track_id-1].sector_count =
1.37 + msf_to_lba( cue->addr ) - image->track[track_id-1].lba;
1.38 } else {
1.39 track = cue_track_id + bcd_to_uint8(cue->track) - 1;
1.40 if( (cue->control & 0x01) == 0 ) {
1.41 /* Pre-gap address. */
1.42 if( track != 0 ) {
1.43 - disc->track[track-1].sector_count =
1.44 - msf_to_lba( cue->addr ) - disc->track[track-1].lba;
1.45 + image->track[track-1].sector_count =
1.46 + msf_to_lba( cue->addr ) - image->track[track-1].lba;
1.47 }
1.48 } else { /* Track-start address */
1.49 - disc->track[track].lba = msf_to_lba( cue->addr );
1.50 - disc->track[track].flags = cue->type;
1.51 + image->track[track].lba = msf_to_lba( cue->addr );
1.52 + image->track[track].flags = cue->type;
1.53 }
1.54 }
1.55 }
1.56 break;
1.57 case DAOI_ID:
1.58 dao = (struct nrg_daoi *)data;
1.59 - memcpy( disc->mcn, dao->mcn, 13 );
1.60 - disc->mcn[13] = '\0';
1.61 + memcpy( image->mcn, dao->mcn, 13 );
1.62 + image->mcn[13] = '\0';
1.63 assert( dao->track_count * 30 + 22 == chunk.length );
1.64 assert( dao->track_count == cue_track_count );
1.65 for( i=0; i<dao->track_count; i++ ) {
1.66 - disc->track[cue_track_id].sector_size = ntohl(dao->track[i].sector_size);
1.67 - disc->track[cue_track_id].offset = ntohl(dao->track[i].offset);
1.68 - disc->track[cue_track_id].mode = nrg_track_mode( dao->track[i].mode );
1.69 - assert( disc->track[cue_track_id].sector_count ==
1.70 - (ntohl(dao->track[i].end) - ntohl(dao->track[i].offset))/
1.71 - ntohl(dao->track[i].sector_size) );
1.72 + image->track[cue_track_id].sector_size = ntohl(dao->track[i].sector_size);
1.73 + image->track[cue_track_id].offset = ntohl(dao->track[i].offset);
1.74 + image->track[cue_track_id].mode = nrg_track_mode( dao->track[i].mode );
1.75 + image->track[cue_track_id].sector_count =
1.76 + (ntohl(dao->track[i].end) - ntohl(dao->track[i].offset))/
1.77 + ntohl(dao->track[i].sector_size);
1.78 cue_track_id++;
1.79 }
1.80 break;
1.81 @@ -235,26 +238,26 @@
1.82 /* Data is a single 32-bit number representing number of tracks in session */
1.83 i = ntohl( *(uint32_t *)data );
1.84 while( i-- > 0 )
1.85 - disc->track[session_track_id++].session = session_id;
1.86 + image->track[session_track_id++].session = session_id;
1.87 session_id++;
1.88 break;
1.89 case ETNF_ID:
1.90 for( i=0; i < chunk.length; i+= 0x14 ) {
1.91 struct nrg_etnf *etnf = (struct nrg_etnf *)(data+i);
1.92 - disc->track[track_id].offset = ntohl(etnf->offset);
1.93 - disc->track[track_id].lba = ntohl(etnf->lba) + (i+1)*GDROM_PREGAP;
1.94 - disc->track[track_id].mode = nrg_track_mode( ntohl(etnf->mode) );
1.95 - if( disc->track[track_id].mode == -1 ) {
1.96 + image->track[track_id].offset = ntohl(etnf->offset);
1.97 + image->track[track_id].lba = ntohl(etnf->lba) + (i+1)*GDROM_PREGAP;
1.98 + image->track[track_id].mode = nrg_track_mode( ntohl(etnf->mode) );
1.99 + if( image->track[track_id].mode == -1 ) {
1.100 disc->close(disc);
1.101 return NULL;
1.102 }
1.103 - if( disc->track[track_id].mode == GDROM_CDDA )
1.104 - disc->track[track_id].flags = 0x01;
1.105 + if( image->track[track_id].mode == GDROM_CDDA )
1.106 + image->track[track_id].flags = 0x01;
1.107 else
1.108 - disc->track[track_id].flags = 0x01 | TRACK_DATA;
1.109 - disc->track[track_id].sector_size = GDROM_SECTOR_SIZE(disc->track[track_id].mode);
1.110 - disc->track[track_id].sector_count = ntohl(etnf->length) /
1.111 - disc->track[track_id].sector_size;
1.112 + image->track[track_id].flags = 0x01 | TRACK_DATA;
1.113 + image->track[track_id].sector_size = GDROM_SECTOR_SIZE(image->track[track_id].mode);
1.114 + image->track[track_id].sector_count = ntohl(etnf->length) /
1.115 + image->track[track_id].sector_size;
1.116 track_id++;
1.117 }
1.118 break;
1.119 @@ -263,12 +266,9 @@
1.120 break;
1.121 }
1.122 } while( !end );
1.123 - disc->track_count = track_id;
1.124 + image->track_count = track_id;
1.125 return disc;
1.126 }
1.127
1.128 -gboolean nrg_read_sectors( struct gdrom_disc *disc, uint32_t lba, uint32_t count, char *buf )
1.129 -{
1.130 - return FALSE;
1.131 -}
1.132
1.133 +
.