if (this_count > 0xff) this_count = 0xff;  
static int sd_init_command(struct scsi_cmnd * SCpnt){	unsigned int this_count, timeout;	struct gendisk *disk;	sector_t block;	struct scsi_device *sdp = SCpnt->device;	struct request *rq = SCpnt->request;	timeout = sdp->timeout;	/*	 * SG_IO from block layer already setup, just copy cdb basically	 */	if (blk_pc_request(rq)) {		if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))			return 0;		memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));		if (rq_data_dir(rq) == WRITE)			SCpnt->sc_data_direction = DMA_TO_DEVICE;		else if (rq->data_len)			SCpnt->sc_data_direction = DMA_FROM_DEVICE;		else			SCpnt->sc_data_direction = DMA_NONE;		this_count = rq->data_len;		if (rq->timeout)			timeout = rq->timeout;		SCpnt->transfersize = rq->data_len;		SCpnt->allowed = SD_PASSTHROUGH_RETRIES;		goto queue;	}	/*	 * we only do REQ_CMD and REQ_BLOCK_PC	 */	if (!blk_fs_request(rq))		return 0;	disk = rq->rq_disk;	block = rq->sector;	this_count = SCpnt->request_bufflen >> 9;	SCSI_LOG_HLQUEUE(1, printk("sd_init_command: disk=%s, block=%llu, "			    "count=%d\n", disk->disk_name,			 (unsigned long long)block, this_count));	if (!sdp || !scsi_device_online(sdp) || 	    block + rq->nr_sectors > get_capacity(disk)) {		SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n", 				 rq->nr_sectors));		SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));		return 0;	}	if (sdp->changed) {		/*		 * quietly refuse to do anything to a changed disc until 		 * the changed bit has been reset		 */		/* printk("SCSI disk has been changed. Prohibiting further I/O.\n"); */		return 0;	}	SCSI_LOG_HLQUEUE(2, printk("%s : block=%llu\n",				   disk->disk_name, (unsigned long long)block));	/*	 * If we have a 1K hardware sectorsize, prevent access to single	 * 512 byte sectors.  In theory we could handle this - in fact	 * the scsi cdrom driver must be able to handle this because	 * we typically use 1K blocksizes, and cdroms typically have	 * 2K hardware sectorsizes.  Of course, things are simpler	 * with the cdrom, since it is read-only.  For performance	 * reasons, the filesystems should be able to handle this	 * and not force the scsi disk driver to use bounce buffers	 * for this.	 */	if (sdp->sector_size == 1024) {		if ((block & 1) || (rq->nr_sectors & 1)) {			printk(KERN_ERR "sd: Bad block number requested");			return 0;		} else {			block = block >> 1;			this_count = this_count >> 1;		}	}	if (sdp->sector_size == 2048) {		if ((block & 3) || (rq->nr_sectors & 3)) {			printk(KERN_ERR "sd: Bad block number requested");			return 0;		} else {			block = block >> 2;			this_count = this_count >> 2;		}	}	if (sdp->sector_size == 4096) {		if ((block & 7) || (rq->nr_sectors & 7)) {			printk(KERN_ERR "sd: Bad block number requested");			return 0;		} else {			block = block >> 3;			this_count = this_count >> 3;		}	}	if (rq_data_dir(rq) == WRITE) {		if (!sdp->writeable) {			return 0;		}		SCpnt->cmnd[0] = WRITE_6;		SCpnt->sc_data_direction = DMA_TO_DEVICE;	} else if (rq_data_dir(rq) == READ) {		SCpnt->cmnd[0] = READ_6;		SCpnt->sc_data_direction = DMA_FROM_DEVICE;	} else {		printk(KERN_ERR "sd: Unknown command %lx\n", rq->flags);/* overkill 	panic("Unknown sd command %lx\n", rq->flags); */		return 0;	}	SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n", 		disk->disk_name, (rq_data_dir(rq) == WRITE) ? 		"writing" : "reading", this_count, rq->nr_sectors));	SCpnt->cmnd[1] = 0;		if (block > 0xffffffff) {		SCpnt->cmnd[0] += READ_16 - READ_6;		SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0;		SCpnt->cmnd[3] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0;		SCpnt->cmnd[4] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0;		SCpnt->cmnd[5] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0;		SCpnt->cmnd[6] = (unsigned char) (block >> 24) & 0xff;		SCpnt->cmnd[7] = (unsigned char) (block >> 16) & 0xff;		SCpnt->cmnd[8] = (unsigned char) (block >> 8) & 0xff;		SCpnt->cmnd[9] = (unsigned char) block & 0xff;		SCpnt->cmnd[10] = (unsigned char) (this_count >> 24) & 0xff;		SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff;		SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff;		SCpnt->cmnd[13] = (unsigned char) this_count & 0xff;		SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0;	} else if ((this_count > 0xff) || (block > 0x1fffff) ||		   SCpnt->device->use_10_for_rw) {		if (this_count > 0xffff)			this_count = 0xffff;		SCpnt->cmnd[0] += READ_10 - READ_6;		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;	} else {		if (this_count > 0xff)			this_count = 0xff;		SCpnt->cmnd[1] |= (unsigned char) ((block >> 16) & 0x1f);		SCpnt->cmnd[2] = (unsigned char) ((block >> 8) & 0xff);		SCpnt->cmnd[3] = (unsigned char) block & 0xff;		SCpnt->cmnd[4] = (unsigned char) this_count;		SCpnt->cmnd[5] = 0;	}	SCpnt->request_bufflen = SCpnt->bufflen =			this_count * sdp->sector_size;	/*	 * 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 = sdp->sector_size;	SCpnt->underflow = this_count << 9;	SCpnt->allowed = SD_MAX_RETRIES;queue:	SCpnt->timeout_per_command = timeout;	/*	 * This is the completion routine we use.  This is matched in terms	 * of capability to this function.	 */	SCpnt->done = sd_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/7fce2cf62e4bd9c24717009865ac00940cb664b8/sd.c/buggy/drivers/scsi/sd.c