SCpnt->cmd_len = rq->cmd_len; 
static int sr_init_command(struct scsi_cmnd * SCpnt){	int block=0, this_count, s_size, timeout = SR_TIMEOUT;	struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);	SCSI_LOG_HLQUEUE(1, printk("Doing sr request, dev = %s, block = %d\n",				cd->disk->disk_name, block));	if (!cd->device || !scsi_device_online(cd->device)) {		SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n",					SCpnt->request->nr_sectors));		SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));		return 0;	}	if (cd->device->changed) {		/*		 * quietly refuse to do anything to a changed disc until the		 * changed bit has been reset		 */		return 0;	}	/*	 * these are already setup, just copy cdb basically	 */	if (SCpnt->request->flags & REQ_BLOCK_PC) {		struct request *rq = SCpnt->request;		if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))			return 0;		memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));		if (!rq->data_len)			SCpnt->sc_data_direction = DMA_NONE;		else if (rq_data_dir(rq) == WRITE)			SCpnt->sc_data_direction = DMA_TO_DEVICE;		else			SCpnt->sc_data_direction = DMA_FROM_DEVICE;		this_count = rq->data_len;		if (rq->timeout)			timeout = rq->timeout;		SCpnt->transfersize = rq->data_len;		goto queue;	}	if (!(SCpnt->request->flags & REQ_CMD)) {		blk_dump_rq_flags(SCpnt->request, "sr unsup command");		return 0;	}	/*	 * we do lazy blocksize switching (when reading XA sectors,	 * see CDROMREADMODE2 ioctl) 	 */	s_size = cd->device->sector_size;	if (s_size > 2048) {		if (!in_interrupt())			sr_set_blocklength(cd, 2048);		else			printk("sr: can't switch blocksize: in interrupt\n");	}	if (s_size != 512 && s_size != 1024 && s_size != 2048) {		printk("sr: bad sector size %d\n", s_size);		return 0;	}	if (rq_data_dir(SCpnt->request) == WRITE) {		if (!cd->device->writeable)			return 0;		SCpnt->cmnd[0] = WRITE_10;		SCpnt->sc_data_direction = DMA_TO_DEVICE; 	 	cd->cdi.media_written = 1;	} else if (rq_data_dir(SCpnt->request) == READ) {		SCpnt->cmnd[0] = READ_10;		SCpnt->sc_data_direction = DMA_FROM_DEVICE;	} else {		blk_dump_rq_flags(SCpnt->request, "Unknown sr command");		return 0;	}	{		struct scatterlist *sg = SCpnt->request_buffer;		int i, size = 0;		for (i = 0; i < SCpnt->use_sg; i++)			size += sg[i].length;		if (size != SCpnt->request_bufflen && SCpnt->use_sg) {			printk(KERN_ERR "sr: mismatch count %d, bytes %d\n",					size, SCpnt->request_bufflen);			if (SCpnt->request_bufflen > size)				SCpnt->request_bufflen = SCpnt->bufflen = size;		}	}	/*	 * request doesn't start on hw block boundary, add scatter pads	 */	if (((unsigned int)SCpnt->request->sector % (s_size >> 9)) ||	    (SCpnt->request_bufflen % s_size)) {		printk("sr: unaligned transfer\n");		return 0;	}	this_count = (SCpnt->request_bufflen >> 9) / (s_size >> 9);	SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",				cd->cdi.name,				(rq_data_dir(SCpnt->request) == WRITE) ?					"writing" : "reading",				this_count, SCpnt->request->nr_sectors));	SCpnt->cmnd[1] = 0;	block = (unsigned int)SCpnt->request->sector / (s_size >> 9);	if (this_count > 0xffff) {		this_count = 0xffff;		SCpnt->request_bufflen = SCpnt->bufflen =				this_count * s_size;	}	SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;	SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;	SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;	SCpnt->cmnd[5] = (unsigned char) block & 0xff;	SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;	SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;	SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;	/*	 * We shouldn't disconnect in the middle of a sector, so with a dumb	 * host adapter, it's safe to assume that we can at least transfer	 * this many bytes between each connect / disconnect.	 */	SCpnt->transfersize = cd->device->sector_size;	SCpnt->underflow = this_count << 9;queue:	SCpnt->allowed = MAX_RETRIES;	SCpnt->timeout_per_command = timeout;	/*	 * This is the completion routine we use.  This is matched in terms	 * of capability to this function.	 */	SCpnt->done = rw_intr;	/*	 * This indicates that the command is ready from our end to be	 * queued.	 */	return 1;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/186d330e682210100c671355580a8592e4a21692/sr.c/buggy/drivers/scsi/sr.c