Search
lxdream.org :: lxdream/src/drivers/cd_linux.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/cd_linux.c
changeset 736:a02d1475ccfd
prev720:b5594d1ac80a
next767:53dc977f8f25
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 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/drivers/cd_linux.c Sat Jul 05 11:57:36 2008 +0000
1.2 +++ b/src/drivers/cd_linux.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -51,13 +51,13 @@
1.4 static gdrom_disc_t linux_open_device( const gchar *filename, FILE *f );
1.5 static gdrom_error_t linux_read_disc_toc( gdrom_image_t disc );
1.6 static gdrom_error_t linux_read_sector( gdrom_disc_t disc, uint32_t sector,
1.7 - int mode, unsigned char *buf, uint32_t *length );
1.8 + int mode, unsigned char *buf, uint32_t *length );
1.9 static gdrom_error_t linux_send_command( int fd, char *cmd, unsigned char *buffer, size_t *buflen,
1.10 - int direction );
1.11 + int direction );
1.12 static int linux_drive_status( gdrom_disc_t disc );
1.13
1.14 struct gdrom_image_class cdrom_device_class = { "Linux", NULL,
1.15 - linux_image_is_valid, linux_open_device };
1.16 + linux_image_is_valid, linux_open_device };
1.17 GList *cdrom_get_native_devices(void)
1.18 {
1.19 GList *list = NULL;
1.20 @@ -65,19 +65,19 @@
1.21 struct stat st;
1.22 setfsent();
1.23 while( (ent = getfsent()) != NULL ) {
1.24 - if( (stat(ent->fs_spec, &st) != -1) &&
1.25 - S_ISBLK(st.st_mode) ) {
1.26 - /* Got a valid block device - is it a CDROM? */
1.27 - int fd = open(ent->fs_spec, O_RDONLY|O_NONBLOCK);
1.28 - if( fd == -1 )
1.29 - continue;
1.30 - int caps = ioctl(fd, CDROM_GET_CAPABILITY);
1.31 - if( caps != -1 ) {
1.32 - /* Appears to support CDROM functions */
1.33 - list = g_list_append( list, gdrom_device_new(ent->fs_spec, ent->fs_spec));
1.34 - }
1.35 - close(fd);
1.36 - }
1.37 + if( (stat(ent->fs_spec, &st) != -1) &&
1.38 + S_ISBLK(st.st_mode) ) {
1.39 + /* Got a valid block device - is it a CDROM? */
1.40 + int fd = open(ent->fs_spec, O_RDONLY|O_NONBLOCK);
1.41 + if( fd == -1 )
1.42 + continue;
1.43 + int caps = ioctl(fd, CDROM_GET_CAPABILITY);
1.44 + if( caps != -1 ) {
1.45 + /* Appears to support CDROM functions */
1.46 + list = g_list_append( list, gdrom_device_new(ent->fs_spec, ent->fs_spec));
1.47 + }
1.48 + close(fd);
1.49 + }
1.50 }
1.51 return list;
1.52 }
1.53 @@ -93,15 +93,15 @@
1.54 struct cdrom_tochdr tochdr;
1.55
1.56 if( fstat(fileno(f), &st) == -1 ) {
1.57 - return FALSE; /* can't stat device? */
1.58 + return FALSE; /* can't stat device? */
1.59 }
1.60 if( !S_ISBLK(st.st_mode) ) {
1.61 - return FALSE; /* Not a block device */
1.62 + return FALSE; /* Not a block device */
1.63 }
1.64
1.65 if( ioctl(fileno(f), CDROMREADTOCHDR, &tochdr) == -1 ) {
1.66 - /* Quick check that this is really a CD */
1.67 - return FALSE;
1.68 + /* Quick check that this is really a CD */
1.69 + return FALSE;
1.70 }
1.71
1.72 return TRUE;
1.73 @@ -113,20 +113,20 @@
1.74
1.75 disc = gdrom_image_new(filename, f);
1.76 if( disc == NULL ) {
1.77 - ERROR("Unable to allocate memory!");
1.78 - return NULL;
1.79 + ERROR("Unable to allocate memory!");
1.80 + return NULL;
1.81 }
1.82
1.83 gdrom_error_t status = linux_read_disc_toc( (gdrom_image_t)disc );
1.84 if( status != 0 ) {
1.85 - gdrom_image_destroy_no_close(disc);
1.86 - if( status == 0xFFFF ) {
1.87 - ERROR("Unable to load disc table of contents (%s)", strerror(errno));
1.88 - } else {
1.89 - ERROR("Unable to load disc table of contents (sense %d,%d)",
1.90 - status &0xFF, status >> 8 );
1.91 - }
1.92 - return NULL;
1.93 + gdrom_image_destroy_no_close(disc);
1.94 + if( status == 0xFFFF ) {
1.95 + ERROR("Unable to load disc table of contents (%s)", strerror(errno));
1.96 + } else {
1.97 + ERROR("Unable to load disc table of contents (sense %d,%d)",
1.98 + status &0xFF, status >> 8 );
1.99 + }
1.100 + return NULL;
1.101 }
1.102 disc->read_sector = linux_read_sector;
1.103 disc->drive_status = linux_drive_status;
1.104 @@ -138,13 +138,13 @@
1.105 int fd = fileno(((gdrom_image_t)disc)->file);
1.106 int status = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
1.107 if( status == CDS_DISC_OK ) {
1.108 - status = ioctl(fd, CDROM_MEDIA_CHANGED, CDSL_CURRENT);
1.109 - if( status != 0 ) {
1.110 - linux_read_disc_toc( (gdrom_image_t)disc);
1.111 - }
1.112 - return ((gdrom_image_t)disc)->disc_type | IDE_DISC_READY;
1.113 + status = ioctl(fd, CDROM_MEDIA_CHANGED, CDSL_CURRENT);
1.114 + if( status != 0 ) {
1.115 + linux_read_disc_toc( (gdrom_image_t)disc);
1.116 + }
1.117 + return ((gdrom_image_t)disc)->disc_type | IDE_DISC_READY;
1.118 } else {
1.119 - return IDE_DISC_NONE;
1.120 + return IDE_DISC_NONE;
1.121 }
1.122 }
1.123 /**
1.124 @@ -156,7 +156,7 @@
1.125 unsigned char buf[MAXTOCSIZE];
1.126 size_t buflen = sizeof(buf);
1.127 char cmd[12] = { 0x43, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1.128 -
1.129 +
1.130 cmd[7] = (sizeof(buf))>>8;
1.131 cmd[8] = (sizeof(buf))&0xFF;
1.132 memset( buf, 0, sizeof(buf) );
1.133 @@ -168,7 +168,7 @@
1.134 return 0;
1.135 }
1.136
1.137 - gdrom_error_t linux_play_audio( gdrom_disc_t disc, uint32_t lba, uint32_t endlba )
1.138 +gdrom_error_t linux_play_audio( gdrom_disc_t disc, uint32_t lba, uint32_t endlba )
1.139 {
1.140 int fd = fileno( ((gdrom_image_t)disc)->file );
1.141 uint32_t real_sector = lba - CD_MSF_OFFSET;
1.142 @@ -183,7 +183,7 @@
1.143 cmd[7] = (length >> 16) & 0xFF;
1.144 cmd[8] = (length >> 8) & 0xFF;
1.145 cmd[9] = length & 0xFF;
1.146 -
1.147 +
1.148 return linux_send_command( fd, cmd, NULL, &buflen, CGC_DATA_NONE );
1.149 }
1.150
1.151 @@ -196,16 +196,16 @@
1.152 }
1.153
1.154 static gdrom_error_t linux_read_sector( gdrom_disc_t disc, uint32_t sector,
1.155 - int mode, unsigned char *buf, uint32_t *length )
1.156 + int mode, unsigned char *buf, uint32_t *length )
1.157 {
1.158 gdrom_image_t image = (gdrom_image_t)disc;
1.159 int fd = fileno(image->file);
1.160 uint32_t real_sector = sector - CD_MSF_OFFSET;
1.161 uint32_t sector_size = MAX_SECTOR_SIZE;
1.162 char cmd[12];
1.163 -
1.164 +
1.165 mmc_make_read_cd_cmd( cmd, real_sector, mode );
1.166 -
1.167 +
1.168 gdrom_error_t status = linux_send_command( fd, cmd, buf, &sector_size, CGC_DATA_READ );
1.169 if( status != 0 ) {
1.170 return status;
1.171 @@ -220,7 +220,7 @@
1.172 * code on a device error.
1.173 */
1.174 static gdrom_error_t linux_send_command( int fd, char *cmd, unsigned char *buffer, size_t *buflen,
1.175 - int direction )
1.176 + int direction )
1.177 {
1.178 struct request_sense sense;
1.179 struct cdrom_generic_command cgc;
1.180 @@ -232,16 +232,16 @@
1.181 cgc.buflen = *buflen;
1.182 cgc.sense = &sense;
1.183 cgc.data_direction = direction;
1.184 -
1.185 +
1.186 if( ioctl(fd, CDROM_SEND_PACKET, &cgc) < 0 ) {
1.187 - if( sense.sense_key == 0 ) {
1.188 - return -1;
1.189 - } else {
1.190 - /* TODO: Map newer codes back to the ones used by the gd-rom. */
1.191 - return sense.sense_key | (sense.asc<<8);
1.192 - }
1.193 + if( sense.sense_key == 0 ) {
1.194 + return -1;
1.195 + } else {
1.196 + /* TODO: Map newer codes back to the ones used by the gd-rom. */
1.197 + return sense.sense_key | (sense.asc<<8);
1.198 + }
1.199 } else {
1.200 - *buflen = cgc.buflen;
1.201 - return 0;
1.202 + *buflen = cgc.buflen;
1.203 + return 0;
1.204 }
1.205 }
.