--- a/src/drivers/cd_linux.c Sat Jul 05 11:57:36 2008 +0000 +++ b/src/drivers/cd_linux.c Mon Jul 14 07:44:42 2008 +0000 @@ -51,13 +51,13 @@ static gdrom_disc_t linux_open_device( const gchar *filename, FILE *f ); static gdrom_error_t linux_read_disc_toc( gdrom_image_t disc ); static gdrom_error_t linux_read_sector( gdrom_disc_t disc, uint32_t sector, - int mode, unsigned char *buf, uint32_t *length ); + int mode, unsigned char *buf, uint32_t *length ); static gdrom_error_t linux_send_command( int fd, char *cmd, unsigned char *buffer, size_t *buflen, - int direction ); + int direction ); static int linux_drive_status( gdrom_disc_t disc ); struct gdrom_image_class cdrom_device_class = { "Linux", NULL, - linux_image_is_valid, linux_open_device }; + linux_image_is_valid, linux_open_device }; GList *cdrom_get_native_devices(void) { GList *list = NULL; @@ -65,19 +65,19 @@ struct stat st; setfsent(); while( (ent = getfsent()) != NULL ) { - if( (stat(ent->fs_spec, &st) != -1) && - S_ISBLK(st.st_mode) ) { - /* Got a valid block device - is it a CDROM? */ - int fd = open(ent->fs_spec, O_RDONLY|O_NONBLOCK); - if( fd == -1 ) - continue; - int caps = ioctl(fd, CDROM_GET_CAPABILITY); - if( caps != -1 ) { - /* Appears to support CDROM functions */ - list = g_list_append( list, gdrom_device_new(ent->fs_spec, ent->fs_spec)); - } - close(fd); - } + if( (stat(ent->fs_spec, &st) != -1) && + S_ISBLK(st.st_mode) ) { + /* Got a valid block device - is it a CDROM? */ + int fd = open(ent->fs_spec, O_RDONLY|O_NONBLOCK); + if( fd == -1 ) + continue; + int caps = ioctl(fd, CDROM_GET_CAPABILITY); + if( caps != -1 ) { + /* Appears to support CDROM functions */ + list = g_list_append( list, gdrom_device_new(ent->fs_spec, ent->fs_spec)); + } + close(fd); + } } return list; } @@ -93,15 +93,15 @@ struct cdrom_tochdr tochdr; if( fstat(fileno(f), &st) == -1 ) { - return FALSE; /* can't stat device? */ + return FALSE; /* can't stat device? */ } if( !S_ISBLK(st.st_mode) ) { - return FALSE; /* Not a block device */ + return FALSE; /* Not a block device */ } if( ioctl(fileno(f), CDROMREADTOCHDR, &tochdr) == -1 ) { - /* Quick check that this is really a CD */ - return FALSE; + /* Quick check that this is really a CD */ + return FALSE; } return TRUE; @@ -113,20 +113,20 @@ disc = gdrom_image_new(filename, f); if( disc == NULL ) { - ERROR("Unable to allocate memory!"); - return NULL; + ERROR("Unable to allocate memory!"); + return NULL; } gdrom_error_t status = linux_read_disc_toc( (gdrom_image_t)disc ); if( status != 0 ) { - gdrom_image_destroy_no_close(disc); - if( status == 0xFFFF ) { - ERROR("Unable to load disc table of contents (%s)", strerror(errno)); - } else { - ERROR("Unable to load disc table of contents (sense %d,%d)", - status &0xFF, status >> 8 ); - } - return NULL; + gdrom_image_destroy_no_close(disc); + if( status == 0xFFFF ) { + ERROR("Unable to load disc table of contents (%s)", strerror(errno)); + } else { + ERROR("Unable to load disc table of contents (sense %d,%d)", + status &0xFF, status >> 8 ); + } + return NULL; } disc->read_sector = linux_read_sector; disc->drive_status = linux_drive_status; @@ -138,13 +138,13 @@ int fd = fileno(((gdrom_image_t)disc)->file); int status = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); if( status == CDS_DISC_OK ) { - status = ioctl(fd, CDROM_MEDIA_CHANGED, CDSL_CURRENT); - if( status != 0 ) { - linux_read_disc_toc( (gdrom_image_t)disc); - } - return ((gdrom_image_t)disc)->disc_type | IDE_DISC_READY; + status = ioctl(fd, CDROM_MEDIA_CHANGED, CDSL_CURRENT); + if( status != 0 ) { + linux_read_disc_toc( (gdrom_image_t)disc); + } + return ((gdrom_image_t)disc)->disc_type | IDE_DISC_READY; } else { - return IDE_DISC_NONE; + return IDE_DISC_NONE; } } /** @@ -156,7 +156,7 @@ unsigned char buf[MAXTOCSIZE]; size_t buflen = sizeof(buf); char cmd[12] = { 0x43, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - + cmd[7] = (sizeof(buf))>>8; cmd[8] = (sizeof(buf))&0xFF; memset( buf, 0, sizeof(buf) ); @@ -168,7 +168,7 @@ return 0; } - gdrom_error_t linux_play_audio( gdrom_disc_t disc, uint32_t lba, uint32_t endlba ) +gdrom_error_t linux_play_audio( gdrom_disc_t disc, uint32_t lba, uint32_t endlba ) { int fd = fileno( ((gdrom_image_t)disc)->file ); uint32_t real_sector = lba - CD_MSF_OFFSET; @@ -183,7 +183,7 @@ cmd[7] = (length >> 16) & 0xFF; cmd[8] = (length >> 8) & 0xFF; cmd[9] = length & 0xFF; - + return linux_send_command( fd, cmd, NULL, &buflen, CGC_DATA_NONE ); } @@ -196,16 +196,16 @@ } static gdrom_error_t linux_read_sector( gdrom_disc_t disc, uint32_t sector, - int mode, unsigned char *buf, uint32_t *length ) + int mode, unsigned char *buf, uint32_t *length ) { gdrom_image_t image = (gdrom_image_t)disc; int fd = fileno(image->file); uint32_t real_sector = sector - CD_MSF_OFFSET; uint32_t sector_size = MAX_SECTOR_SIZE; char cmd[12]; - + mmc_make_read_cd_cmd( cmd, real_sector, mode ); - + gdrom_error_t status = linux_send_command( fd, cmd, buf, §or_size, CGC_DATA_READ ); if( status != 0 ) { return status; @@ -220,7 +220,7 @@ * code on a device error. */ static gdrom_error_t linux_send_command( int fd, char *cmd, unsigned char *buffer, size_t *buflen, - int direction ) + int direction ) { struct request_sense sense; struct cdrom_generic_command cgc; @@ -232,16 +232,16 @@ cgc.buflen = *buflen; cgc.sense = &sense; cgc.data_direction = direction; - + if( ioctl(fd, CDROM_SEND_PACKET, &cgc) < 0 ) { - if( sense.sense_key == 0 ) { - return -1; - } else { - /* TODO: Map newer codes back to the ones used by the gd-rom. */ - return sense.sense_key | (sense.asc<<8); - } + if( sense.sense_key == 0 ) { + return -1; + } else { + /* TODO: Map newer codes back to the ones used by the gd-rom. */ + return sense.sense_key | (sense.asc<<8); + } } else { - *buflen = cgc.buflen; - return 0; + *buflen = cgc.buflen; + return 0; } }