Search
lxdream.org :: lxdream/src/gdrom/gdimage.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdimage.c
changeset 736:a02d1475ccfd
prev720:b5594d1ac80a
next759:f16975739abc
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (11 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/gdimage.c Sat Jul 05 11:57:36 2008 +0000
1.2 +++ b/src/gdrom/gdimage.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -17,6 +17,7 @@
1.4 */
1.5
1.6 #include <assert.h>
1.7 +#include <string.h>
1.8 #include <netinet/in.h>
1.9
1.10 #include "gdrom/gddriver.h"
1.11 @@ -26,7 +27,7 @@
1.12
1.13 static void gdrom_image_destroy( gdrom_disc_t disc );
1.14 static gdrom_error_t gdrom_image_read_sector( gdrom_disc_t disc, uint32_t lba, int mode,
1.15 - unsigned char *buf, uint32_t *readlength );
1.16 + unsigned char *buf, uint32_t *readlength );
1.17 static gdrom_error_t gdrom_image_read_toc( gdrom_disc_t disc, unsigned char *buf );
1.18 static gdrom_error_t gdrom_image_read_session( gdrom_disc_t disc, int session, unsigned char *buf );
1.19 static gdrom_error_t gdrom_image_read_position( gdrom_disc_t disc, uint32_t lba, unsigned char *buf );
1.20 @@ -67,18 +68,18 @@
1.21
1.22 gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f )
1.23 {
1.24 - gdrom_image_t image = (gdrom_image_t)calloc(sizeof(struct gdrom_image), 1);
1.25 + gdrom_image_t image = (gdrom_image_t)g_malloc0(sizeof(struct gdrom_image));
1.26 if( image == NULL ) {
1.27 - return NULL;
1.28 + return NULL;
1.29 }
1.30 image->disc_type = IDE_DISC_CDROMXA;
1.31 image->file = f;
1.32 gdrom_disc_t disc = (gdrom_disc_t)image;
1.33 gdrom_image_init(disc);
1.34 if( filename == NULL ) {
1.35 - disc->name = NULL;
1.36 + disc->name = NULL;
1.37 } else {
1.38 - disc->name = g_strdup(filename);
1.39 + disc->name = g_strdup(filename);
1.40 }
1.41
1.42 return disc;
1.43 @@ -90,19 +91,19 @@
1.44 FILE *lastfile = NULL;
1.45 gdrom_image_t img = (gdrom_image_t)disc;
1.46 if( img->file != NULL ) {
1.47 - fclose(img->file);
1.48 - img->file = NULL;
1.49 + fclose(img->file);
1.50 + img->file = NULL;
1.51 }
1.52 for( i=0; i<img->track_count; i++ ) {
1.53 - if( img->track[i].file != NULL && img->track[i].file != lastfile ) {
1.54 - lastfile = img->track[i].file;
1.55 - fclose(lastfile);
1.56 - img->track[i].file = NULL;
1.57 - }
1.58 + if( img->track[i].file != NULL && img->track[i].file != lastfile ) {
1.59 + lastfile = img->track[i].file;
1.60 + fclose(lastfile);
1.61 + img->track[i].file = NULL;
1.62 + }
1.63 }
1.64 if( disc->name != NULL ) {
1.65 - g_free( (gpointer)disc->name );
1.66 - disc->name = NULL;
1.67 + g_free( (gpointer)disc->name );
1.68 + disc->name = NULL;
1.69 }
1.70 free( disc );
1.71 }
1.72 @@ -113,18 +114,18 @@
1.73 FILE *lastfile = NULL;
1.74 gdrom_image_t img = (gdrom_image_t)disc;
1.75 if( img->file != NULL ) {
1.76 - img->file = NULL;
1.77 + img->file = NULL;
1.78 }
1.79 for( i=0; i<img->track_count; i++ ) {
1.80 - if( img->track[i].file != NULL && img->track[i].file != lastfile ) {
1.81 - lastfile = img->track[i].file;
1.82 - fclose(lastfile);
1.83 - img->track[i].file = NULL;
1.84 - }
1.85 + if( img->track[i].file != NULL && img->track[i].file != lastfile ) {
1.86 + lastfile = img->track[i].file;
1.87 + fclose(lastfile);
1.88 + img->track[i].file = NULL;
1.89 + }
1.90 }
1.91 if( disc->name != NULL ) {
1.92 - g_free( (gpointer)disc->name );
1.93 - disc->name = NULL;
1.94 + g_free( (gpointer)disc->name );
1.95 + disc->name = NULL;
1.96 }
1.97 free( disc );
1.98 }
1.99 @@ -133,10 +134,10 @@
1.100 {
1.101 int i;
1.102 for( i=0; i<image->track_count; i++ ) {
1.103 - if( image->track[i].lba <= lba &&
1.104 - lba < (image->track[i].lba + image->track[i].sector_count) ) {
1.105 - return i+1;
1.106 - }
1.107 + if( image->track[i].lba <= lba &&
1.108 + lba < (image->track[i].lba + image->track[i].sector_count) ) {
1.109 + return i+1;
1.110 + }
1.111 }
1.112 return -1;
1.113 }
1.114 @@ -148,22 +149,22 @@
1.115 static gboolean gdrom_read_block( unsigned char *buf, int file_offset, int length, FILE *f )
1.116 {
1.117 if( file_offset < 0 ) {
1.118 - int size = -file_offset;
1.119 - if( size >= length ) {
1.120 - memset( buf, 0, length );
1.121 - return TRUE;
1.122 - } else {
1.123 - memset( buf, 0, size );
1.124 - file_offset = 0;
1.125 - length -= size;
1.126 - }
1.127 + int size = -file_offset;
1.128 + if( size >= length ) {
1.129 + memset( buf, 0, length );
1.130 + return TRUE;
1.131 + } else {
1.132 + memset( buf, 0, size );
1.133 + file_offset = 0;
1.134 + length -= size;
1.135 + }
1.136 }
1.137 fseek( f, file_offset, SEEK_SET );
1.138 return fread( buf, length, 1, f ) == 1;
1.139 }
1.140
1.141 static void gdrom_build_sector_header( unsigned char *buf, uint32_t lba,
1.142 - gdrom_track_mode_t sector_mode )
1.143 + gdrom_track_mode_t sector_mode )
1.144 {
1.145 memcpy( buf, gdrom_default_sync, 12 );
1.146 cd_build_address( buf, sector_mode, lba );
1.147 @@ -179,19 +180,19 @@
1.148 {
1.149 switch( read_mode ) {
1.150 case READ_CD_MODE_ANY:
1.151 - return TRUE;
1.152 + return TRUE;
1.153 case READ_CD_MODE_CDDA:
1.154 - return track_mode == GDROM_CDDA;
1.155 + return track_mode == GDROM_CDDA;
1.156 case READ_CD_MODE_1:
1.157 - return track_mode == GDROM_MODE1 || track_mode == GDROM_MODE2_FORM1;
1.158 + return track_mode == GDROM_MODE1 || track_mode == GDROM_MODE2_FORM1;
1.159 case READ_CD_MODE_2_FORM_1:
1.160 - return track_mode == GDROM_MODE1 || track_mode == GDROM_MODE2_FORM1;
1.161 + return track_mode == GDROM_MODE1 || track_mode == GDROM_MODE2_FORM1;
1.162 case READ_CD_MODE_2_FORM_2:
1.163 - return track_mode == GDROM_MODE2_FORM2;
1.164 + return track_mode == GDROM_MODE2_FORM2;
1.165 case READ_CD_MODE_2:
1.166 - return track_mode == GDROM_MODE2_FORMLESS;
1.167 + return track_mode == GDROM_MODE2_FORMLESS;
1.168 default:
1.169 - return FALSE;
1.170 + return FALSE;
1.171 }
1.172 }
1.173
1.174 @@ -202,26 +203,26 @@
1.175 static void gdrom_get_read_bounds( int sector_mode, int read_mode, int *start, int *size )
1.176 {
1.177 if( READ_CD_RAW(read_mode) ) {
1.178 - // whole sector
1.179 - *start = 0;
1.180 - *size = 2352;
1.181 + // whole sector
1.182 + *start = 0;
1.183 + *size = 2352;
1.184 } else {
1.185 - *size = 0;
1.186 - if( READ_CD_DATA(read_mode) ) {
1.187 - *start = gdrom_data_offset[sector_mode];
1.188 - *size = gdrom_sector_size[sector_mode];
1.189 - }
1.190 + *size = 0;
1.191 + if( READ_CD_DATA(read_mode) ) {
1.192 + *start = gdrom_data_offset[sector_mode];
1.193 + *size = gdrom_sector_size[sector_mode];
1.194 + }
1.195
1.196 - if( READ_CD_SUBHEAD(read_mode) &&
1.197 - (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2) ) {
1.198 - *start = SECTOR_HEADER_SIZE;
1.199 - *size += SECTOR_SUBHEADER_SIZE;
1.200 - }
1.201 + if( READ_CD_SUBHEAD(read_mode) &&
1.202 + (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2) ) {
1.203 + *start = SECTOR_HEADER_SIZE;
1.204 + *size += SECTOR_SUBHEADER_SIZE;
1.205 + }
1.206
1.207 - if( READ_CD_HEADER(read_mode) ) {
1.208 - *size += SECTOR_HEADER_SIZE;
1.209 - *start = 0;
1.210 - }
1.211 + if( READ_CD_HEADER(read_mode) ) {
1.212 + *size += SECTOR_HEADER_SIZE;
1.213 + *start = 0;
1.214 + }
1.215
1.216 }
1.217 }
1.218 @@ -242,7 +243,7 @@
1.219 * data correction codes.
1.220 */
1.221 static gdrom_error_t gdrom_image_read_sector( gdrom_disc_t disc, uint32_t lba,
1.222 - int mode, unsigned char *buf, uint32_t *length )
1.223 + int mode, unsigned char *buf, uint32_t *length )
1.224 {
1.225 gdrom_image_t image = (gdrom_image_t)disc;
1.226 struct cdrom_sector_header secthead;
1.227 @@ -252,44 +253,44 @@
1.228
1.229 track_no = gdrom_image_get_track_by_lba( image, lba );
1.230 if( track_no == -1 ) {
1.231 - return PKT_ERR_BADREAD;
1.232 + return PKT_ERR_BADREAD;
1.233 }
1.234 struct gdrom_track *track = &image->track[track_no-1];
1.235 file_offset = track->offset + track->sector_size * (lba - track->lba);
1.236 read_len = track->sector_size;
1.237 if( track->file != NULL ) {
1.238 - f = track->file;
1.239 + f = track->file;
1.240 } else {
1.241 - f = image->file;
1.242 + f = image->file;
1.243 }
1.244
1.245 /* First figure out what the real sector mode is for raw/semiraw sectors */
1.246 int sector_mode;
1.247 switch( track->mode ) {
1.248 case GDROM_RAW_NONXA:
1.249 - gdrom_read_block( (unsigned char *)(&secthead), file_offset, sizeof(secthead), f );
1.250 - sector_mode = (secthead.mode == 1) ? GDROM_MODE1 : GDROM_MODE2_FORMLESS;
1.251 - break;
1.252 + gdrom_read_block( (unsigned char *)(&secthead), file_offset, sizeof(secthead), f );
1.253 + sector_mode = (secthead.mode == 1) ? GDROM_MODE1 : GDROM_MODE2_FORMLESS;
1.254 + break;
1.255 case GDROM_RAW_XA:
1.256 - gdrom_read_block( (unsigned char *)(&secthead), file_offset, sizeof(secthead), f );
1.257 - if( secthead.mode == 1 ) {
1.258 - sector_mode = GDROM_MODE1;
1.259 - } else {
1.260 - sector_mode = ((secthead.subhead[2] & 0x20) == 0 ) ? GDROM_MODE2_FORM1 : GDROM_MODE2_FORM2;
1.261 - }
1.262 - break;
1.263 + gdrom_read_block( (unsigned char *)(&secthead), file_offset, sizeof(secthead), f );
1.264 + if( secthead.mode == 1 ) {
1.265 + sector_mode = GDROM_MODE1;
1.266 + } else {
1.267 + sector_mode = ((secthead.subhead[2] & 0x20) == 0 ) ? GDROM_MODE2_FORM1 : GDROM_MODE2_FORM2;
1.268 + }
1.269 + break;
1.270 case GDROM_SEMIRAW_MODE2:
1.271 - gdrom_read_block( secthead.subhead, file_offset, 8, f );
1.272 - sector_mode = ((secthead.subhead[2] & 0x20) == 0 ) ? GDROM_MODE2_FORM1 : GDROM_MODE2_FORM2;
1.273 - break;
1.274 + gdrom_read_block( secthead.subhead, file_offset, 8, f );
1.275 + sector_mode = ((secthead.subhead[2] & 0x20) == 0 ) ? GDROM_MODE2_FORM1 : GDROM_MODE2_FORM2;
1.276 + break;
1.277 default:
1.278 - /* In the other cases, the track mode completely defines the sector mode */
1.279 - sector_mode = track->mode;
1.280 - break;
1.281 + /* In the other cases, the track mode completely defines the sector mode */
1.282 + sector_mode = track->mode;
1.283 + break;
1.284 }
1.285
1.286 if( !gdrom_is_compatible_read_mode(sector_mode, READ_CD_MODE(mode)) ) {
1.287 - return PKT_ERR_BADREADMODE;
1.288 + return PKT_ERR_BADREADMODE;
1.289 }
1.290
1.291 /* Ok, we've got a valid sector, check what parts of the sector we need to
1.292 @@ -298,70 +299,70 @@
1.293 int channels = READ_CD_CHANNELS(mode);
1.294
1.295 if( channels == 0 ) {
1.296 - // legal, if weird
1.297 - *length = 0;
1.298 - return PKT_ERR_OK;
1.299 + // legal, if weird
1.300 + *length = 0;
1.301 + return PKT_ERR_OK;
1.302 } else if( channels == 0xA0 &&
1.303 - (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2 )) {
1.304 - // caller requested a non-contiguous region
1.305 - return PKT_ERR_BADFIELD;
1.306 + (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2 )) {
1.307 + // caller requested a non-contiguous region
1.308 + return PKT_ERR_BADFIELD;
1.309 } else if( READ_CD_RAW(channels) ) {
1.310 - channels = 0xF0; // implies everything
1.311 + channels = 0xF0; // implies everything
1.312 }
1.313
1.314 read_len = 0;
1.315 int start, size;
1.316 switch( track->mode ) {
1.317 case GDROM_CDDA:
1.318 - // audio is nice and simple (assume perfect reads for now)
1.319 - *length = 2352;
1.320 - gdrom_read_block( buf, file_offset, track->sector_size, f );
1.321 - return PKT_ERR_OK;
1.322 + // audio is nice and simple (assume perfect reads for now)
1.323 + *length = 2352;
1.324 + gdrom_read_block( buf, file_offset, track->sector_size, f );
1.325 + return PKT_ERR_OK;
1.326 case GDROM_RAW_XA:
1.327 case GDROM_RAW_NONXA:
1.328 - gdrom_get_read_bounds( sector_mode, channels, &start, &size );
1.329 - gdrom_read_block( buf, file_offset+start, size, f );
1.330 - read_len = size;
1.331 - break;
1.332 + gdrom_get_read_bounds( sector_mode, channels, &start, &size );
1.333 + gdrom_read_block( buf, file_offset+start, size, f );
1.334 + read_len = size;
1.335 + break;
1.336 case GDROM_SEMIRAW_MODE2:
1.337 - gdrom_get_read_bounds( sector_mode, channels, &start, &size );
1.338 - if( READ_CD_HEADER(channels) ) {
1.339 - gdrom_build_sector_header( buf, lba, sector_mode );
1.340 - read_len += SECTOR_HEADER_SIZE;
1.341 - size -= SECTOR_HEADER_SIZE;
1.342 - } else {
1.343 - start -= SECTOR_HEADER_SIZE;
1.344 - }
1.345 - gdrom_read_block( buf + read_len, file_offset+start, size, f );
1.346 - read_len += size;
1.347 - break;
1.348 + gdrom_get_read_bounds( sector_mode, channels, &start, &size );
1.349 + if( READ_CD_HEADER(channels) ) {
1.350 + gdrom_build_sector_header( buf, lba, sector_mode );
1.351 + read_len += SECTOR_HEADER_SIZE;
1.352 + size -= SECTOR_HEADER_SIZE;
1.353 + } else {
1.354 + start -= SECTOR_HEADER_SIZE;
1.355 + }
1.356 + gdrom_read_block( buf + read_len, file_offset+start, size, f );
1.357 + read_len += size;
1.358 + break;
1.359 default: // Data track w/ data only in file
1.360 - if( READ_CD_RAW(channels) ) {
1.361 - gdrom_read_block( buf + gdrom_data_offset[track->mode], file_offset,
1.362 - track->sector_size, f );
1.363 - do_encode_L2( buf, sector_mode, lba );
1.364 - read_len = 2352;
1.365 - } else {
1.366 - if( READ_CD_HEADER(channels) ) {
1.367 - gdrom_build_sector_header( buf, lba, sector_mode );
1.368 - read_len += SECTOR_HEADER_SIZE;
1.369 - }
1.370 - if( READ_CD_SUBHEAD(channels) &&
1.371 - (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2) ) {
1.372 - if( sector_mode == GDROM_MODE2_FORM1 ) {
1.373 - *((uint32_t *)(buf+read_len)) = 0;
1.374 - *((uint32_t *)(buf+read_len+4)) = 0;
1.375 - } else {
1.376 - *((uint32_t *)(buf+read_len)) = 0x00200000;
1.377 - *((uint32_t *)(buf+read_len+4)) = 0x00200000;
1.378 - }
1.379 - read_len += 8;
1.380 - }
1.381 - if( READ_CD_DATA(channels) ) {
1.382 - gdrom_read_block( buf+read_len, file_offset, track->sector_size, f );
1.383 - read_len += track->sector_size;
1.384 - }
1.385 - }
1.386 + if( READ_CD_RAW(channels) ) {
1.387 + gdrom_read_block( buf + gdrom_data_offset[track->mode], file_offset,
1.388 + track->sector_size, f );
1.389 + do_encode_L2( buf, sector_mode, lba );
1.390 + read_len = 2352;
1.391 + } else {
1.392 + if( READ_CD_HEADER(channels) ) {
1.393 + gdrom_build_sector_header( buf, lba, sector_mode );
1.394 + read_len += SECTOR_HEADER_SIZE;
1.395 + }
1.396 + if( READ_CD_SUBHEAD(channels) &&
1.397 + (sector_mode == GDROM_MODE2_FORM1 || sector_mode == GDROM_MODE2_FORM2) ) {
1.398 + if( sector_mode == GDROM_MODE2_FORM1 ) {
1.399 + *((uint32_t *)(buf+read_len)) = 0;
1.400 + *((uint32_t *)(buf+read_len+4)) = 0;
1.401 + } else {
1.402 + *((uint32_t *)(buf+read_len)) = 0x00200000;
1.403 + *((uint32_t *)(buf+read_len+4)) = 0x00200000;
1.404 + }
1.405 + read_len += 8;
1.406 + }
1.407 + if( READ_CD_DATA(channels) ) {
1.408 + gdrom_read_block( buf+read_len, file_offset, track->sector_size, f );
1.409 + read_len += track->sector_size;
1.410 + }
1.411 + }
1.412 }
1.413 *length = read_len;
1.414 return PKT_ERR_OK;
1.415 @@ -374,14 +375,14 @@
1.416 int i;
1.417
1.418 for( i=0; i<image->track_count; i++ ) {
1.419 - toc->track[i] = htonl( image->track[i].lba ) | image->track[i].flags;
1.420 + toc->track[i] = htonl( image->track[i].lba ) | image->track[i].flags;
1.421 }
1.422 toc->first = 0x0100 | image->track[0].flags;
1.423 toc->last = (image->track_count<<8) | image->track[i-1].flags;
1.424 toc->leadout = htonl(image->track[i-1].lba + image->track[i-1].sector_count) |
1.425 - image->track[i-1].flags;
1.426 + image->track[i-1].flags;
1.427 for( ;i<99; i++ )
1.428 - toc->track[i] = 0xFFFFFFFF;
1.429 + toc->track[i] = 0xFFFFFFFF;
1.430 return PKT_ERR_OK;
1.431 }
1.432
1.433 @@ -395,23 +396,23 @@
1.434 buf[1] = 0;
1.435
1.436 if( session == 0 ) {
1.437 - buf[2] = last_track->session+1; /* last session */
1.438 - buf[3] = (end_of_disc >> 16) & 0xFF;
1.439 - buf[4] = (end_of_disc >> 8) & 0xFF;
1.440 - buf[5] = end_of_disc & 0xFF;
1.441 - return PKT_ERR_OK;
1.442 + buf[2] = last_track->session+1; /* last session */
1.443 + buf[3] = (end_of_disc >> 16) & 0xFF;
1.444 + buf[4] = (end_of_disc >> 8) & 0xFF;
1.445 + buf[5] = end_of_disc & 0xFF;
1.446 + return PKT_ERR_OK;
1.447 } else {
1.448 - session--;
1.449 - for( i=0; i<image->track_count; i++ ) {
1.450 - if( image->track[i].session == session ) {
1.451 - buf[2] = i+1; /* first track of session */
1.452 - buf[3] = (image->track[i].lba >> 16) & 0xFF;
1.453 - buf[4] = (image->track[i].lba >> 8) & 0xFF;
1.454 - buf[5] = image->track[i].lba & 0xFF;
1.455 - return PKT_ERR_OK;
1.456 - }
1.457 - }
1.458 - return PKT_ERR_BADFIELD; /* No such session */
1.459 + session--;
1.460 + for( i=0; i<image->track_count; i++ ) {
1.461 + if( image->track[i].session == session ) {
1.462 + buf[2] = i+1; /* first track of session */
1.463 + buf[3] = (image->track[i].lba >> 16) & 0xFF;
1.464 + buf[4] = (image->track[i].lba >> 8) & 0xFF;
1.465 + buf[5] = image->track[i].lba & 0xFF;
1.466 + return PKT_ERR_OK;
1.467 + }
1.468 + }
1.469 + return PKT_ERR_BADFIELD; /* No such session */
1.470 }
1.471 }
1.472
1.473 @@ -420,8 +421,8 @@
1.474 gdrom_image_t image = (gdrom_image_t)disc;
1.475 int track_no = gdrom_image_get_track_by_lba( image, lba );
1.476 if( track_no == -1 ) {
1.477 - track_no = 1;
1.478 - lba = 150;
1.479 + track_no = 1;
1.480 + lba = 150;
1.481 }
1.482 struct gdrom_track *track = &image->track[track_no-1];
1.483 uint32_t offset = lba - track->lba;
1.484 @@ -455,29 +456,29 @@
1.485 gboolean is_bootable = FALSE;
1.486
1.487 INFO( "Disc ID: %s, %d tracks in %d sessions", disc->mcn, disc->track_count,
1.488 - disc->track[disc->track_count-1].session + 1 );
1.489 + disc->track[disc->track_count-1].session + 1 );
1.490 if( last_session > 0 ) {
1.491 - /* Boot track is the first data track of the last session, provided that it
1.492 - * cannot be a single-session disc.
1.493 - */
1.494 - int boot_track = -1;
1.495 - for( i=disc->track_count-1; i>=0 && disc->track[i].session == last_session; i-- ) {
1.496 - if( disc->track[i].flags & TRACK_DATA ) {
1.497 - boot_track = i;
1.498 - }
1.499 - }
1.500 - if( boot_track != -1 ) {
1.501 - unsigned char boot_sector[MAX_SECTOR_SIZE];
1.502 - uint32_t length = sizeof(boot_sector);
1.503 - if( d->read_sector( d, disc->track[boot_track].lba, 0x28,
1.504 - boot_sector, &length ) == PKT_ERR_OK ) {
1.505 - bootstrap_dump(boot_sector, FALSE);
1.506 - is_bootable = TRUE;
1.507 - }
1.508 - }
1.509 + /* Boot track is the first data track of the last session, provided that it
1.510 + * cannot be a single-session disc.
1.511 + */
1.512 + int boot_track = -1;
1.513 + for( i=disc->track_count-1; i>=0 && disc->track[i].session == last_session; i-- ) {
1.514 + if( disc->track[i].flags & TRACK_DATA ) {
1.515 + boot_track = i;
1.516 + }
1.517 + }
1.518 + if( boot_track != -1 ) {
1.519 + unsigned char boot_sector[MAX_SECTOR_SIZE];
1.520 + uint32_t length = sizeof(boot_sector);
1.521 + if( d->read_sector( d, disc->track[boot_track].lba, 0x28,
1.522 + boot_sector, &length ) == PKT_ERR_OK ) {
1.523 + bootstrap_dump(boot_sector, FALSE);
1.524 + is_bootable = TRUE;
1.525 + }
1.526 + }
1.527 }
1.528 if( !is_bootable ) {
1.529 - WARN( "Disc does not appear to be bootable" );
1.530 + WARN( "Disc does not appear to be bootable" );
1.531 }
1.532 }
1.533
1.534 @@ -501,4 +502,3 @@
1.535 }
1.536 g_free( dev );
1.537 }
1.538 -
1.539 \ No newline at end of file
.