LCOV - code coverage report
Current view: top level - drivers/scsi - sr_ioctl.c (source / functions) Hit Total Coverage
Test: landlock.info Lines: 0 289 0.0 %
Date: 2021-04-22 12:43:58 Functions: 0 17 0.0 %

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

Generated by: LCOV version 1.14