unsigned int lba   = tf->flags & ATA_TFLAG_LBA; unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; 
static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd){	struct ata_taskfile *tf = &qc->tf;	struct ata_device *dev = qc->dev;	unsigned int lba   = tf->flags & ATA_TFLAG_LBA;	unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48;	u64 block;	u32 n_block;	tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;	tf->protocol = qc->dev->xfer_protocol;	if (scsicmd[0] == READ_10 || scsicmd[0] == READ_6 ||	    scsicmd[0] == READ_16) {		tf->command = qc->dev->read_cmd;	} else {		tf->command = qc->dev->write_cmd;		tf->flags |= ATA_TFLAG_WRITE;	}	/* Calculate the SCSI LBA and transfer length. */	switch (scsicmd[0]) {	case READ_10:	case WRITE_10:		scsi_10_lba_len(scsicmd, &block, &n_block);		break;	case READ_6:	case WRITE_6:		scsi_6_lba_len(scsicmd, &block, &n_block);		/* for 6-byte r/w commands, transfer length 0		 * means 256 blocks of data, not 0 block.		 */		if (!n_block)			n_block = 256;		break;	case READ_16:	case WRITE_16:		scsi_16_lba_len(scsicmd, &block, &n_block);		break;	default:		DPRINTK("no-byte command\n");		goto invalid_fld;	}	/* Check and compose ATA command */	if (!n_block)		/* For 10-byte and 16-byte SCSI R/W commands, transfer		 * length 0 means transfer 0 block of data.		 * However, for ATA R/W commands, sector count 0 means		 * 256 or 65536 sectors, not 0 sectors as in SCSI.		 */		goto nothing_to_do;	if (lba) {		if (lba48) {			/* The request -may- be too large for LBA48. */			if ((block >> 48) || (n_block > 65536))				goto out_of_range;			tf->hob_nsect = (n_block >> 8) & 0xff;			tf->hob_lbah = (block >> 40) & 0xff;			tf->hob_lbam = (block >> 32) & 0xff;			tf->hob_lbal = (block >> 24) & 0xff;		} else { 			/* LBA28 */			/* The request -may- be too large for LBA28. */			if ((block >> 28) || (n_block > 256))				goto out_of_range;			tf->device |= (block >> 24) & 0xf;		}		qc->nsect = n_block;		tf->nsect = n_block & 0xff;		tf->lbah = (block >> 16) & 0xff;		tf->lbam = (block >> 8) & 0xff;		tf->lbal = block & 0xff;		tf->device |= ATA_LBA;	} else { 		/* CHS */		u32 sect, head, cyl, track;		/* The request -may- be too large for CHS addressing. */		if ((block >> 28) || (n_block > 256))			goto out_of_range;		/* Convert LBA to CHS */		track = (u32)block / dev->sectors;		cyl   = track / dev->heads;		head  = track % dev->heads;		sect  = (u32)block % dev->sectors + 1;		DPRINTK("block %u track %u cyl %u head %u sect %u\n",			(u32)block, track, cyl, head, sect);		/* Check whether the converted CHS can fit. 		   Cylinder: 0-65535 		   Head: 0-15		   Sector: 1-255*/		if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))			goto out_of_range;		qc->nsect = n_block;		tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */		tf->lbal = sect;		tf->lbam = cyl;		tf->lbah = cyl >> 8;		tf->device |= head;	}	return 0;invalid_fld:	ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0);	/* "Invalid field in cbd" */	return 1;out_of_range:	ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0);	/* "Logical Block Address out of range" */	return 1;nothing_to_do:	qc->scsicmd->result = SAM_STAT_GOOD;	return 1;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/07506697d1c615924298406f2357810709c09bcd/libata-scsi.c/buggy/drivers/scsi/libata-scsi.c