blob: e1589f91706a2f18187b2229599e8a1ecc744e46 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/mm.h>
3#include <linux/fs.h>
4#include <linux/errno.h>
5#include <linux/string.h>
6#include <linux/blkdev.h>
7#include <linux/blkpg.h>
8#include <linux/cdrom.h>
9#include <linux/delay.h>
10#include <asm/io.h>
11#include <asm/uaccess.h>
12
13#include <scsi/scsi.h>
14#include <scsi/scsi_dbg.h>
15#include <scsi/scsi_device.h>
16#include <scsi/scsi_eh.h>
17#include <scsi/scsi_host.h>
18#include <scsi/scsi_ioctl.h>
James Bottomley820732b2005-06-12 22:21:29 -050019#include <scsi/scsi_cmnd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include "sr.h"
22
23#if 0
24#define DEBUG
25#endif
26
27/* The sr_is_xa() seems to trigger firmware bugs with some drives :-(
28 * It is off by default and can be turned on with this module parameter */
29static int xa_test = 0;
30
31module_param(xa_test, int, S_IRUGO | S_IWUSR);
32
Christoph Hellwiga09c6312006-01-11 14:28:06 +010033/* primitive to determine whether we need to have GFP_DMA set based on
34 * the status of the unchecked_isa_dma flag in the host structure */
35#define SR_GFP_DMA(cd) (((cd)->device->host->unchecked_isa_dma) ? GFP_DMA : 0)
36
37
38static int sr_read_tochdr(struct cdrom_device_info *cdi,
39 struct cdrom_tochdr *tochdr)
40{
41 struct scsi_cd *cd = cdi->handle;
42 struct packet_command cgc;
43 int result;
44 unsigned char *buffer;
45
46 buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
47 if (!buffer)
48 return -ENOMEM;
49
50 memset(&cgc, 0, sizeof(struct packet_command));
51 cgc.timeout = IOCTL_TIMEOUT;
52 cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
53 cgc.cmd[8] = 12; /* LSB of length */
54 cgc.buffer = buffer;
55 cgc.buflen = 12;
56 cgc.quiet = 1;
57 cgc.data_direction = DMA_FROM_DEVICE;
58
59 result = sr_do_ioctl(cd, &cgc);
60
61 tochdr->cdth_trk0 = buffer[2];
62 tochdr->cdth_trk1 = buffer[3];
63
64 kfree(buffer);
65 return result;
66}
67
68static int sr_read_tocentry(struct cdrom_device_info *cdi,
69 struct cdrom_tocentry *tocentry)
70{
71 struct scsi_cd *cd = cdi->handle;
72 struct packet_command cgc;
73 int result;
74 unsigned char *buffer;
75
76 buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
77 if (!buffer)
78 return -ENOMEM;
79
80 memset(&cgc, 0, sizeof(struct packet_command));
81 cgc.timeout = IOCTL_TIMEOUT;
82 cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
83 cgc.cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
84 cgc.cmd[6] = tocentry->cdte_track;
85 cgc.cmd[8] = 12; /* LSB of length */
86 cgc.buffer = buffer;
87 cgc.buflen = 12;
88 cgc.data_direction = DMA_FROM_DEVICE;
89
90 result = sr_do_ioctl(cd, &cgc);
91
92 tocentry->cdte_ctrl = buffer[5] & 0xf;
93 tocentry->cdte_adr = buffer[5] >> 4;
94 tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
95 if (tocentry->cdte_format == CDROM_MSF) {
96 tocentry->cdte_addr.msf.minute = buffer[9];
97 tocentry->cdte_addr.msf.second = buffer[10];
98 tocentry->cdte_addr.msf.frame = buffer[11];
99 } else
100 tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
101 + buffer[10]) << 8) + buffer[11];
102
103 kfree(buffer);
104 return result;
105}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107#define IOCTL_RETRIES 3
108
109/* ATAPI drives don't have a SCMD_PLAYAUDIO_TI command. When these drives
110 are emulating a SCSI device via the idescsi module, they need to have
111 CDROMPLAYTRKIND commands translated into CDROMPLAYMSF commands for them */
112
113static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti)
114{
115 struct cdrom_tocentry trk0_te, trk1_te;
116 struct cdrom_tochdr tochdr;
117 struct packet_command cgc;
118 int ntracks, ret;
119
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100120 ret = sr_read_tochdr(cdi, &tochdr);
121 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return ret;
123
124 ntracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
125
126 if (ti->cdti_trk1 == ntracks)
127 ti->cdti_trk1 = CDROM_LEADOUT;
128 else if (ti->cdti_trk1 != CDROM_LEADOUT)
129 ti->cdti_trk1 ++;
130
131 trk0_te.cdte_track = ti->cdti_trk0;
132 trk0_te.cdte_format = CDROM_MSF;
133 trk1_te.cdte_track = ti->cdti_trk1;
134 trk1_te.cdte_format = CDROM_MSF;
135
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100136 ret = sr_read_tocentry(cdi, &trk0_te);
137 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return ret;
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100139 ret = sr_read_tocentry(cdi, &trk1_te);
140 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return ret;
142
143 memset(&cgc, 0, sizeof(struct packet_command));
144 cgc.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
145 cgc.cmd[3] = trk0_te.cdte_addr.msf.minute;
146 cgc.cmd[4] = trk0_te.cdte_addr.msf.second;
147 cgc.cmd[5] = trk0_te.cdte_addr.msf.frame;
148 cgc.cmd[6] = trk1_te.cdte_addr.msf.minute;
149 cgc.cmd[7] = trk1_te.cdte_addr.msf.second;
150 cgc.cmd[8] = trk1_te.cdte_addr.msf.frame;
151 cgc.data_direction = DMA_NONE;
152 cgc.timeout = IOCTL_TIMEOUT;
153 return sr_do_ioctl(cdi->handle, &cgc);
154}
155
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100156static int sr_play_trkind(struct cdrom_device_info *cdi,
157 struct cdrom_ti *ti)
158
159{
160 struct scsi_cd *cd = cdi->handle;
161 struct packet_command cgc;
162 int result;
163
164 memset(&cgc, 0, sizeof(struct packet_command));
165 cgc.timeout = IOCTL_TIMEOUT;
166 cgc.cmd[0] = GPCMD_PLAYAUDIO_TI;
167 cgc.cmd[4] = ti->cdti_trk0;
168 cgc.cmd[5] = ti->cdti_ind0;
169 cgc.cmd[7] = ti->cdti_trk1;
170 cgc.cmd[8] = ti->cdti_ind1;
171 cgc.data_direction = DMA_NONE;
172
173 result = sr_do_ioctl(cd, &cgc);
174 if (result == -EDRIVE_CANT_DO_THIS)
175 result = sr_fake_playtrkind(cdi, ti);
176
177 return result;
178}
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* We do our own retries because we want to know what the specific
181 error code is. Normally the UNIT_ATTENTION code will automatically
182 clear after one error */
183
184int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
185{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 struct scsi_device *SDev;
James Bottomley820732b2005-06-12 22:21:29 -0500187 struct scsi_sense_hdr sshdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 int result, err = 0, retries = 0;
James Bottomley820732b2005-06-12 22:21:29 -0500189 struct request_sense *sense = cgc->sense;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 SDev = cd->device;
James Bottomley820732b2005-06-12 22:21:29 -0500192
193 if (!sense) {
Linus Torvaldsf716d832006-03-06 17:41:44 -0800194 sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
James Bottomley820732b2005-06-12 22:21:29 -0500195 if (!sense) {
196 err = -ENOMEM;
197 goto out;
198 }
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 retry:
202 if (!scsi_block_when_processing_errors(SDev)) {
203 err = -ENODEV;
James Bottomley820732b2005-06-12 22:21:29 -0500204 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
James Bottomley820732b2005-06-12 22:21:29 -0500207 memset(sense, 0, sizeof(*sense));
208 result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
209 cgc->buffer, cgc->buflen, (char *)sense,
210 cgc->timeout, IOCTL_RETRIES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
James Bottomley820732b2005-06-12 22:21:29 -0500212 scsi_normalize_sense((char *)sense, sizeof(*sense), &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 /* Minimal error checking. Ignore cases we know about, and report the rest. */
215 if (driver_byte(result) != 0) {
James Bottomley820732b2005-06-12 22:21:29 -0500216 switch (sshdr.sense_key) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 case UNIT_ATTENTION:
218 SDev->changed = 1;
219 if (!cgc->quiet)
220 printk(KERN_INFO "%s: disc change detected.\n", cd->cdi.name);
221 if (retries++ < 10)
222 goto retry;
223 err = -ENOMEDIUM;
224 break;
225 case NOT_READY: /* This happens if there is no disc in drive */
James Bottomley820732b2005-06-12 22:21:29 -0500226 if (sshdr.asc == 0x04 &&
227 sshdr.ascq == 0x01) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /* sense: Logical unit is in process of becoming ready */
229 if (!cgc->quiet)
230 printk(KERN_INFO "%s: CDROM not ready yet.\n", cd->cdi.name);
231 if (retries++ < 10) {
232 /* sleep 2 sec and try again */
233 ssleep(2);
234 goto retry;
235 } else {
236 /* 20 secs are enough? */
237 err = -ENOMEDIUM;
238 break;
239 }
240 }
241 if (!cgc->quiet)
242 printk(KERN_INFO "%s: CDROM not ready. Make sure there is a disc in the drive.\n", cd->cdi.name);
243#ifdef DEBUG
James Bottomley820732b2005-06-12 22:21:29 -0500244 scsi_print_sense_hdr("sr", &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#endif
246 err = -ENOMEDIUM;
247 break;
248 case ILLEGAL_REQUEST:
249 err = -EIO;
James Bottomley820732b2005-06-12 22:21:29 -0500250 if (sshdr.asc == 0x20 &&
251 sshdr.ascq == 0x00)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 /* sense: Invalid command operation code */
253 err = -EDRIVE_CANT_DO_THIS;
254#ifdef DEBUG
255 __scsi_print_command(cgc->cmd);
James Bottomley820732b2005-06-12 22:21:29 -0500256 scsi_print_sense_hdr("sr", &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#endif
258 break;
259 default:
260 printk(KERN_ERR "%s: CDROM (ioctl) error, command: ", cd->cdi.name);
261 __scsi_print_command(cgc->cmd);
James Bottomley820732b2005-06-12 22:21:29 -0500262 scsi_print_sense_hdr("sr", &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 err = -EIO;
264 }
265 }
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /* Wake up a process waiting for device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 out:
James Bottomley820732b2005-06-12 22:21:29 -0500269 if (!cgc->sense)
270 kfree(sense);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 cgc->stat = err;
272 return err;
273}
274
275/* ---------------------------------------------------------------------- */
276/* interface to cdrom.c */
277
278static int test_unit_ready(Scsi_CD *cd)
279{
280 struct packet_command cgc;
281
282 memset(&cgc, 0, sizeof(struct packet_command));
283 cgc.cmd[0] = GPCMD_TEST_UNIT_READY;
284 cgc.quiet = 1;
285 cgc.data_direction = DMA_NONE;
286 cgc.timeout = IOCTL_TIMEOUT;
287 return sr_do_ioctl(cd, &cgc);
288}
289
290int sr_tray_move(struct cdrom_device_info *cdi, int pos)
291{
292 Scsi_CD *cd = cdi->handle;
293 struct packet_command cgc;
294
295 memset(&cgc, 0, sizeof(struct packet_command));
296 cgc.cmd[0] = GPCMD_START_STOP_UNIT;
297 cgc.cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
298 cgc.data_direction = DMA_NONE;
299 cgc.timeout = IOCTL_TIMEOUT;
300 return sr_do_ioctl(cd, &cgc);
301}
302
303int sr_lock_door(struct cdrom_device_info *cdi, int lock)
304{
305 Scsi_CD *cd = cdi->handle;
306
307 return scsi_set_medium_removal(cd->device, lock ?
308 SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
309}
310
311int sr_drive_status(struct cdrom_device_info *cdi, int slot)
312{
313 if (CDSL_CURRENT != slot) {
314 /* we have no changer support */
315 return -EINVAL;
316 }
317 if (0 == test_unit_ready(cdi->handle))
318 return CDS_DISC_OK;
319
320 return CDS_TRAY_OPEN;
321}
322
323int sr_disk_status(struct cdrom_device_info *cdi)
324{
325 Scsi_CD *cd = cdi->handle;
326 struct cdrom_tochdr toc_h;
327 struct cdrom_tocentry toc_e;
328 int i, rc, have_datatracks = 0;
329
330 /* look for data tracks */
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100331 rc = sr_read_tochdr(cdi, &toc_h);
332 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return (rc == -ENOMEDIUM) ? CDS_NO_DISC : CDS_NO_INFO;
334
335 for (i = toc_h.cdth_trk0; i <= toc_h.cdth_trk1; i++) {
336 toc_e.cdte_track = i;
337 toc_e.cdte_format = CDROM_LBA;
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100338 if (sr_read_tocentry(cdi, &toc_e))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 return CDS_NO_INFO;
340 if (toc_e.cdte_ctrl & CDROM_DATA_TRACK) {
341 have_datatracks = 1;
342 break;
343 }
344 }
345 if (!have_datatracks)
346 return CDS_AUDIO;
347
348 if (cd->xa_flag)
349 return CDS_XA_2_1;
350 else
351 return CDS_DATA_1;
352}
353
354int sr_get_last_session(struct cdrom_device_info *cdi,
355 struct cdrom_multisession *ms_info)
356{
357 Scsi_CD *cd = cdi->handle;
358
359 ms_info->addr.lba = cd->ms_offset;
360 ms_info->xa_flag = cd->xa_flag || cd->ms_offset > 0;
361
362 return 0;
363}
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
366{
367 Scsi_CD *cd = cdi->handle;
368 struct packet_command cgc;
369 char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
370 int result;
371
Nate Dailey3a73e8c2005-04-21 16:14:05 -0400372 if (!buffer)
373 return -ENOMEM;
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 memset(&cgc, 0, sizeof(struct packet_command));
376 cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
377 cgc.cmd[2] = 0x40; /* I do want the subchannel info */
378 cgc.cmd[3] = 0x02; /* Give me medium catalog number info */
379 cgc.cmd[8] = 24;
380 cgc.buffer = buffer;
381 cgc.buflen = 24;
382 cgc.data_direction = DMA_FROM_DEVICE;
383 cgc.timeout = IOCTL_TIMEOUT;
384 result = sr_do_ioctl(cd, &cgc);
385
386 memcpy(mcn->medium_catalog_number, buffer + 9, 13);
387 mcn->medium_catalog_number[13] = 0;
388
389 kfree(buffer);
390 return result;
391}
392
393int sr_reset(struct cdrom_device_info *cdi)
394{
395 return 0;
396}
397
398int sr_select_speed(struct cdrom_device_info *cdi, int speed)
399{
400 Scsi_CD *cd = cdi->handle;
401 struct packet_command cgc;
402
403 if (speed == 0)
404 speed = 0xffff; /* set to max */
405 else
406 speed *= 177; /* Nx to kbyte/s */
407
408 memset(&cgc, 0, sizeof(struct packet_command));
409 cgc.cmd[0] = GPCMD_SET_SPEED; /* SET CD SPEED */
410 cgc.cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
411 cgc.cmd[3] = speed & 0xff; /* LSB */
412 cgc.data_direction = DMA_NONE;
413 cgc.timeout = IOCTL_TIMEOUT;
414
415 if (sr_do_ioctl(cd, &cgc))
416 return -EIO;
417 return 0;
418}
419
420/* ----------------------------------------------------------------------- */
421/* this is called by the generic cdrom driver. arg is a _kernel_ pointer, */
422/* because the generic cdrom driver does the user access stuff for us. */
423/* only cdromreadtochdr and cdromreadtocentry are left - for use with the */
424/* sr_disk_status interface for the generic cdrom driver. */
425
426int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
427{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 switch (cmd) {
429 case CDROMREADTOCHDR:
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100430 return sr_read_tochdr(cdi, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 case CDROMREADTOCENTRY:
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100432 return sr_read_tocentry(cdi, arg);
433 case CDROMPLAYTRKIND:
434 return sr_play_trkind(cdi, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 default:
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100436 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
440/* -----------------------------------------------------------------------
441 * a function to read all sorts of funny cdrom sectors using the READ_CD
442 * scsi-3 mmc command
443 *
444 * lba: linear block address
445 * format: 0 = data (anything)
446 * 1 = audio
447 * 2 = data (mode 1)
448 * 3 = data (mode 2)
449 * 4 = data (mode 2 form1)
450 * 5 = data (mode 2 form2)
451 * blksize: 2048 | 2336 | 2340 | 2352
452 */
453
454static int sr_read_cd(Scsi_CD *cd, unsigned char *dest, int lba, int format, int blksize)
455{
456 struct packet_command cgc;
457
458#ifdef DEBUG
459 printk("%s: sr_read_cd lba=%d format=%d blksize=%d\n",
460 cd->cdi.name, lba, format, blksize);
461#endif
462
463 memset(&cgc, 0, sizeof(struct packet_command));
464 cgc.cmd[0] = GPCMD_READ_CD; /* READ_CD */
465 cgc.cmd[1] = ((format & 7) << 2);
466 cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
467 cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
468 cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
469 cgc.cmd[5] = (unsigned char) lba & 0xff;
470 cgc.cmd[8] = 1;
471 switch (blksize) {
472 case 2336:
473 cgc.cmd[9] = 0x58;
474 break;
475 case 2340:
476 cgc.cmd[9] = 0x78;
477 break;
478 case 2352:
479 cgc.cmd[9] = 0xf8;
480 break;
481 default:
482 cgc.cmd[9] = 0x10;
483 break;
484 }
485 cgc.buffer = dest;
486 cgc.buflen = blksize;
487 cgc.data_direction = DMA_FROM_DEVICE;
488 cgc.timeout = IOCTL_TIMEOUT;
489 return sr_do_ioctl(cd, &cgc);
490}
491
492/*
493 * read sectors with blocksizes other than 2048
494 */
495
496static int sr_read_sector(Scsi_CD *cd, int lba, int blksize, unsigned char *dest)
497{
498 struct packet_command cgc;
499 int rc;
500
501 /* we try the READ CD command first... */
502 if (cd->readcd_known) {
503 rc = sr_read_cd(cd, dest, lba, 0, blksize);
504 if (-EDRIVE_CANT_DO_THIS != rc)
505 return rc;
506 cd->readcd_known = 0;
507 printk("CDROM does'nt support READ CD (0xbe) command\n");
508 /* fall & retry the other way */
509 }
510 /* ... if this fails, we switch the blocksize using MODE SELECT */
511 if (blksize != cd->device->sector_size) {
512 if (0 != (rc = sr_set_blocklength(cd, blksize)))
513 return rc;
514 }
515#ifdef DEBUG
516 printk("%s: sr_read_sector lba=%d blksize=%d\n", cd->cdi.name, lba, blksize);
517#endif
518
519 memset(&cgc, 0, sizeof(struct packet_command));
520 cgc.cmd[0] = GPCMD_READ_10;
521 cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
522 cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
523 cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
524 cgc.cmd[5] = (unsigned char) lba & 0xff;
525 cgc.cmd[8] = 1;
526 cgc.buffer = dest;
527 cgc.buflen = blksize;
528 cgc.data_direction = DMA_FROM_DEVICE;
529 cgc.timeout = IOCTL_TIMEOUT;
530 rc = sr_do_ioctl(cd, &cgc);
531
532 return rc;
533}
534
535/*
536 * read a sector in raw mode to check the sector format
537 * ret: 1 == mode2 (XA), 0 == mode1, <0 == error
538 */
539
540int sr_is_xa(Scsi_CD *cd)
541{
542 unsigned char *raw_sector;
543 int is_xa;
544
545 if (!xa_test)
546 return 0;
547
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800548 raw_sector = kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (!raw_sector)
550 return -ENOMEM;
551 if (0 == sr_read_sector(cd, cd->ms_offset + 16,
552 CD_FRAMESIZE_RAW1, raw_sector)) {
553 is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
554 } else {
555 /* read a raw sector failed for some reason. */
556 is_xa = -1;
557 }
558 kfree(raw_sector);
559#ifdef DEBUG
560 printk("%s: sr_is_xa: %d\n", cd->cdi.name, is_xa);
561#endif
562 return is_xa;
563}