Search
lxdream.org :: lxdream/src/drivers/cd_osx.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/cd_osx.c
changeset 782:1af8b5ce627c
prev739:46fa527d9fef
next786:8f6ece92500e
author nkeynes
date Tue Jul 29 06:35:28 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Workaround OS X's inability to handle CD reads of unknown size (ie where the read
request failed to specify an expected sector type) - read raw sectors and parse it
out by hand.
file annotate diff log raw
1.1 --- a/src/drivers/cd_osx.c Wed Jul 16 10:34:55 2008 +0000
1.2 +++ b/src/drivers/cd_osx.c Tue Jul 29 06:35:28 2008 +0000
1.3 @@ -153,52 +153,78 @@
1.4 return 0;
1.5 }
1.6
1.7 -static gdrom_error_t cdrom_osx_read_sector( gdrom_disc_t disc, uint32_t sector,
1.8 +static gdrom_error_t cdrom_osx_read_sector( gdrom_disc_t disc, uint32_t lba,
1.9 int mode, unsigned char *buf, uint32_t *length )
1.10 {
1.11 + gdrom_image_t image = (gdrom_image_t)disc;
1.12 + int real_lba = lba - 150;
1.13 + int sector_size;
1.14 + int direct_read = 1;
1.15 + char data[MAX_SECTOR_SIZE];
1.16 osx_cdrom_drive_t drive = OSX_DRIVE(disc);
1.17 +
1.18 int fh = osx_cdrom_get_media_handle(drive);
1.19 if( fh == -1 ) {
1.20 return PKT_ERR_NODISC;
1.21 } else {
1.22 dk_cd_read_t readcd;
1.23 + memset( &readcd, 0, sizeof(readcd) );
1.24 + readcd.buffer = buf;
1.25
1.26 - memset( &readcd, 0, sizeof(readcd) );
1.27 // This is complicated by needing to know the exact read size. Gah.
1.28 if( READ_CD_RAW(mode) ) {
1.29 - *length = 2352;
1.30 + sector_size = 2352;
1.31 readcd.sectorArea = 0xF8;
1.32 + } else if ( READ_CD_MODE(mode) == READ_CD_MODE_ANY ) {
1.33 + /* Sector could be anything - need to do a raw read and then parse
1.34 + * the requested data out ourselves
1.35 + */
1.36 + int track_no = gdrom_image_get_track_by_lba( image, lba );
1.37 + struct gdrom_track *track = &image->track[track_no-1];
1.38 +
1.39 + sector_size = 2352;
1.40 + if( track->mode == GDROM_CDDA ) {
1.41 + readcd.sectorArea = kCDSectorAreaUser;
1.42 + } else {
1.43 + readcd.sectorArea = 0xF8;
1.44 + readcd.buffer = data;
1.45 + direct_read = 0;
1.46 + }
1.47 } else {
1.48 // This is incomplete...
1.49 if( READ_CD_DATA(mode) ) {
1.50 readcd.sectorArea = kCDSectorAreaUser;
1.51 switch( READ_CD_MODE(mode) ) {
1.52 case READ_CD_MODE_CDDA:
1.53 - *length = 2352;
1.54 + sector_size = 2352;
1.55 break;
1.56 case READ_CD_MODE_1:
1.57 case READ_CD_MODE_2_FORM_1:
1.58 - *length = 2048;
1.59 + sector_size = 2048;
1.60 break;
1.61 case READ_CD_MODE_2:
1.62 - *length = 2336;
1.63 + sector_size = 2336;
1.64 break;
1.65 case READ_CD_MODE_2_FORM_2:
1.66 - *length = 2324;
1.67 + sector_size = 2324;
1.68 break;
1.69 }
1.70 }
1.71 }
1.72
1.73 - readcd.offset = *length * (sector - 150);
1.74 + readcd.offset = sector_size * real_lba;
1.75 readcd.sectorType = READ_CD_MODE(mode)>>1;
1.76 - readcd.bufferLength = *length;
1.77 - readcd.buffer = buf;
1.78 + readcd.bufferLength = sector_size;
1.79 if( ioctl( fh, DKIOCCDREAD, &readcd ) == -1 ) {
1.80 return -1;
1.81 + }
1.82 +
1.83 + if( direct_read ) {
1.84 + *length = sector_size;
1.85 } else {
1.86 - return 0;
1.87 + gdrom_extract_raw_data_sector( data, mode, buf, length );
1.88 }
1.89 + return 0;
1.90 }
1.91 }
1.92
.