Search
lxdream.org :: lxdream/src/gdrom/linux.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/linux.c
changeset 342:850502f0e8de
prev259:7c6881790cc2
next353:b8569afb53fc
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/linux.c Fri Dec 29 00:24:43 2006 +0000
1.2 +++ b/src/gdrom/linux.c Wed Jan 31 10:58:42 2007 +0000
1.3 @@ -1,7 +1,7 @@
1.4 /**
1.5 - * $Id: linux.c,v 1.2 2006-12-29 00:24:43 nkeynes Exp $
1.6 + * $Id: linux.c,v 1.3 2007-01-31 10:58:42 nkeynes Exp $
1.7 *
1.8 - * Linux cd-rom device driver
1.9 + * Linux cd-rom device driver.
1.10 *
1.11 * Copyright (c) 2005 Nathan Keynes.
1.12 *
1.13 @@ -29,7 +29,7 @@
1.14
1.15 #define MAXTOCENTRIES 600 /* This is a fairly generous overestimate really */
1.16 #define MAXTOCSIZE 4 + (MAXTOCENTRIES*11)
1.17 -#define MAX_SECTORS_PER_CALL 32
1.18 +#define MAX_SECTORS_PER_CALL 1
1.19
1.20 #define MSFTOLBA( m,s,f ) (f + (s*CD_FRAMES) + (m*CD_FRAMES*CD_SECS))
1.21
1.22 @@ -48,11 +48,10 @@
1.23
1.24 static gboolean linux_image_is_valid( FILE *f );
1.25 static gdrom_disc_t linux_open_device( const gchar *filename, FILE *f );
1.26 -static gdrom_error_t linux_read_disc_toc( gdrom_disc_t disc );
1.27 -static gdrom_error_t linux_read_sectors( gdrom_disc_t disc, uint32_t sector,
1.28 - uint32_t sector_count, int mode, char *buf,
1.29 - uint32_t *length );
1.30 -static gdrom_error_t linux_send_command( int fd, char *cmd, char *buffer, size_t buflen,
1.31 +static gdrom_error_t linux_read_disc_toc( gdrom_image_t disc );
1.32 +static gdrom_error_t linux_read_sector( gdrom_disc_t disc, uint32_t sector,
1.33 + int mode, char *buf, uint32_t *length );
1.34 +static gdrom_error_t linux_send_command( int fd, char *cmd, char *buffer, size_t *buflen,
1.35 int direction );
1.36
1.37
1.38 @@ -90,9 +89,9 @@
1.39 return NULL;
1.40 }
1.41
1.42 - gdrom_error_t status = linux_read_disc_toc( disc );
1.43 + gdrom_error_t status = linux_read_disc_toc( (gdrom_image_t)disc );
1.44 if( status != 0 ) {
1.45 - free(disc);
1.46 + disc->close(disc);
1.47 if( status == 0xFFFF ) {
1.48 ERROR("Unable to load disc table of contents (%s)", strerror(errno));
1.49 } else {
1.50 @@ -101,24 +100,25 @@
1.51 }
1.52 return NULL;
1.53 }
1.54 - disc->read_sectors = linux_read_sectors;
1.55 - disc->disc_type = IDE_DISC_CDROM;
1.56 + disc->read_sector = linux_read_sector;
1.57 + ((gdrom_image_t)disc)->disc_type = IDE_DISC_CDROM;
1.58 return disc;
1.59 }
1.60
1.61 /**
1.62 * Read the full table of contents into the disc from the device.
1.63 */
1.64 -static gdrom_error_t linux_read_disc_toc( gdrom_disc_t disc )
1.65 +static gdrom_error_t linux_read_disc_toc( gdrom_image_t disc )
1.66 {
1.67 int fd = fileno(disc->file);
1.68 unsigned char buf[MAXTOCSIZE];
1.69 + int buflen = sizeof(buf);
1.70 char cmd[12] = { 0x43, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1.71
1.72 cmd[7] = (sizeof(buf))>>8;
1.73 cmd[8] = (sizeof(buf))&0xFF;
1.74 memset( buf, 0, sizeof(buf) );
1.75 - gdrom_error_t status = linux_send_command( fd, cmd, buf, sizeof(buf), CGC_DATA_READ );
1.76 + gdrom_error_t status = linux_send_command( fd, cmd, buf, &buflen, CGC_DATA_READ );
1.77 if( status != 0 ) {
1.78 return status;
1.79 }
1.80 @@ -172,66 +172,31 @@
1.81 return 0;
1.82 }
1.83
1.84 -static gdrom_error_t linux_read_sectors_ioctl( gdrom_disc_t disc, uint32_t sector,
1.85 - uint32_t sector_count, int mode, char *buf,
1.86 - uint32_t *length )
1.87 +static gdrom_error_t linux_read_sector( gdrom_disc_t disc, uint32_t sector,
1.88 + int mode, char *buf, uint32_t *length )
1.89 {
1.90 - int fd = fileno(disc->file);
1.91 - int call;
1.92 - struct cdrom_read read;
1.93 - read.cdread_lba = LBATOMSF(sector);
1.94 - read.cdread_bufaddr = buf;
1.95 - switch(mode) {
1.96 - case GDROM_MODE1:
1.97 - call = CDROMREADMODE1;
1.98 - read.cdread_buflen = sector_count * 2048;
1.99 - break;
1.100 - case GDROM_MODE2:
1.101 - call = CDROMREADMODE2;
1.102 - read.cdread_buflen = sector_count * 2336;
1.103 - break;
1.104 - default:
1.105 - return PKT_ERR_BADREADMODE;
1.106 - }
1.107 -
1.108 - if( ioctl( fd, call, &read ) == -1 ) {
1.109 - ERROR( "Error reading disc (%s)", strerror(errno) );
1.110 - return PKT_ERR_BADREAD;
1.111 - }
1.112 - *length = read.cdread_buflen;
1.113 - return PKT_ERR_OK;
1.114 -}
1.115 -
1.116 -static gdrom_error_t linux_read_sectors( gdrom_disc_t disc, uint32_t sector,
1.117 - uint32_t sector_count, int mode, char *buf,
1.118 - uint32_t *length )
1.119 -{
1.120 - int fd = fileno(disc->file);
1.121 + gdrom_image_t image = (gdrom_image_t)disc;
1.122 + int fd = fileno(image->file);
1.123 uint32_t real_sector = sector - CD_MSF_OFFSET;
1.124 - uint32_t sector_size = 2048;
1.125 - int buflen = sector_count * sector_size;
1.126 + uint32_t sector_size = MAX_SECTOR_SIZE;
1.127 int i;
1.128 char cmd[12] = { 0xBE, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1.129
1.130 - for( i=0; i<sector_count; i += MAX_SECTORS_PER_CALL ) {
1.131 - int count = MIN(MAX_SECTORS_PER_CALL, sector_count);
1.132 - cmd[2] = (real_sector >> 24) & 0xFF;
1.133 - cmd[3] = (real_sector >> 16) & 0xFF;
1.134 - cmd[4] = (real_sector >> 8) & 0xFF;
1.135 - cmd[5] = real_sector & 0xFF;
1.136 - cmd[6] = (count >> 16) & 0xFF;
1.137 - cmd[7] = (count >> 8) & 0xFF;
1.138 - cmd[8] = count & 0xFF;
1.139 - cmd[9] = 0x10;
1.140 + cmd[1] = (mode & 0x0E) << 1;
1.141 + cmd[2] = (real_sector >> 24) & 0xFF;
1.142 + cmd[3] = (real_sector >> 16) & 0xFF;
1.143 + cmd[4] = (real_sector >> 8) & 0xFF;
1.144 + cmd[5] = real_sector & 0xFF;
1.145 + cmd[6] = 0;
1.146 + cmd[7] = 0;
1.147 + cmd[8] = 1;
1.148 + cmd[9] = 0x10;
1.149
1.150 - gdrom_error_t status = linux_send_command( fd, cmd, buf, count * sector_size, CGC_DATA_READ );
1.151 - if( status != 0 ) {
1.152 - return status;
1.153 - }
1.154 - real_sector += count;
1.155 - buf += count * sector_size;
1.156 + gdrom_error_t status = linux_send_command( fd, cmd, buf, &sector_size, CGC_DATA_READ );
1.157 + if( status != 0 ) {
1.158 + return status;
1.159 }
1.160 - *length = buflen;
1.161 + *length = 2048;
1.162 return 0;
1.163 }
1.164
1.165 @@ -240,7 +205,7 @@
1.166 * @return 0 on success, -1 on an operating system error, or a sense error
1.167 * code on a device error.
1.168 */
1.169 -static gdrom_error_t linux_send_command( int fd, char *cmd, char *buffer, size_t buflen,
1.170 +static gdrom_error_t linux_send_command( int fd, char *cmd, char *buffer, size_t *buflen,
1.171 int direction )
1.172 {
1.173 struct request_sense sense;
1.174 @@ -250,7 +215,7 @@
1.175 memset( &sense, 0, sizeof(sense) );
1.176 memcpy( cgc.cmd, cmd, 12 );
1.177 cgc.buffer = buffer;
1.178 - cgc.buflen = buflen;
1.179 + cgc.buflen = *buflen;
1.180 cgc.sense = &sense;
1.181 cgc.data_direction = direction;
1.182
1.183 @@ -258,9 +223,11 @@
1.184 if( sense.sense_key == 0 ) {
1.185 return -1;
1.186 } else {
1.187 + /* TODO: Map newer codes back to the ones used by the gd-rom. */
1.188 return sense.sense_key | (sense.asc<<8);
1.189 }
1.190 } else {
1.191 + *buflen = cgc.buflen;
1.192 return 0;
1.193 }
1.194 }
.