FreeBSD/sys/cam/ctl/ctl.c
/*
 * We support the SYNCHRONIZE CACHE command (10 and 16 byte versions), but
 * we don't really do anything with the LBA and length fields if the user
 * passes them in.  Instead we'll just flush out the cache for the entire
 * LUN.
 */
We support the SYNCHRONIZE CACHE command (10 and 16 byte versions), but
we don't really do anything with the LBA and length fields if the user
passes them in.  Instead we'll just flush out the cache for the entire
LUN.
We support the SYNCHRONIZE CACHE command ( 10 and 16 byte versions ) but we don ' t really do anything with the LBA and length fields if the user passes them in . Instead we ' ll just flush out the cache for the entire LUN .
int
ctl_sync_cache(struct ctl_scsiio *ctsio)
{
	struct ctl_lun *lun;
	struct ctl_softc *softc;
	struct ctl_lba_len_flags *lbalen;
	uint64_t starting_lba;
	uint32_t block_count;
	int retval;
	uint8_t byte2;
	CTL_DEBUG_PRINT(("ctl_sync_cache\n"));
	lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
	softc = lun->ctl_softc;
	retval = 0;
	switch (ctsio->cdb[0]) {
	case SYNCHRONIZE_CACHE: {
		struct scsi_sync_cache *cdb;
		cdb = (struct scsi_sync_cache *)ctsio->cdb;
		starting_lba = scsi_4btoul(cdb->begin_lba);
		block_count = scsi_2btoul(cdb->lb_count);
		byte2 = cdb->byte2;
		break;
	}
	case SYNCHRONIZE_CACHE_16: {
		struct scsi_sync_cache_16 *cdb;
		cdb = (struct scsi_sync_cache_16 *)ctsio->cdb;
		starting_lba = scsi_8btou64(cdb->begin_lba);
		block_count = scsi_4btoul(cdb->lb_count);
		byte2 = cdb->byte2;
		break;
	}
	default:
		ctl_set_invalid_opcode(ctsio);
		ctl_done((union ctl_io *)ctsio);
		goto bailout;
		break; 
	}
	if ((starting_lba + block_count) > (lun->be_lun->maxlba + 1)) {
		ctl_set_lba_out_of_range(ctsio);
		ctl_done((union ctl_io *)ctsio);
		goto bailout;
	}
	lbalen = (struct ctl_lba_len_flags *)&ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN];
	lbalen->lba = starting_lba;
	lbalen->len = block_count;
	lbalen->flags = byte2;
	retval = lun->backend->config_write((union ctl_io *)ctsio);
bailout:
	return (retval);
}
int ctl_sync_cache ( struct ctl_scsiio * ctsio ) { struct ctl_lun * lun ; struct ctl_softc * softc ; struct ctl_lba_len_flags * lbalen ; uint64_t starting_lba ; uint32_t block_count ; int retval ; uint8_t byte2 ; CTL_DEBUG_PRINT ( ( " \n " ) ) ; lun = ( struct ctl_lun * ) ctsio -> io_hdr . ctl_private [ CTL_PRIV_LUN ] . ptr ; softc = lun -> ctl_softc ; retval = 0 ; switch ( ctsio -> cdb [ 0 ] ) { case SYNCHRONIZE_CACHE : { struct scsi_sync_cache * cdb ; cdb = ( struct scsi_sync_cache * ) ctsio -> cdb ; starting_lba = scsi_4btoul ( cdb -> begin_lba ) ; block_count = scsi_2btoul ( cdb -> lb_count ) ; byte2 = cdb -> byte2 ; break ; } case SYNCHRONIZE_CACHE_16 : { struct scsi_sync_cache_16 * cdb ; cdb = ( struct scsi_sync_cache_16 * ) ctsio -> cdb ; starting_lba = scsi_8btou64 ( cdb -> begin_lba ) ; block_count = scsi_4btoul ( cdb -> lb_count ) ; byte2 = cdb -> byte2 ; break ; } default : ctl_set_invalid_opcode ( ctsio ) ; ctl_done ( ( union ctl_io * ) ctsio ) ; goto bailout ; break ; } if ( ( starting_lba + block_count ) > ( lun -> be_lun -> maxlba + 1 ) ) { ctl_set_lba_out_of_range ( ctsio ) ; ctl_done ( ( union ctl_io * ) ctsio ) ; goto bailout ; } lbalen = ( struct ctl_lba_len_flags * ) & ctsio -> io_hdr . ctl_private [ CTL_PRIV_LBA_LEN ] ; lbalen -> lba = starting_lba ; lbalen -> len = block_count ; lbalen -> flags = byte2 ; retval = lun -> backend -> config_write ( ( union ctl_io * ) ctsio ) ; bailout : return ( retval ) ; }
We support the SYNCHRONIZE CACHE command (10 and 16 byte versions), but
 we don't really do anything with the LBA and length fields if the user
 passes them in.
We support the SYNCHRONIZE CACHE command ( 10 and 16 byte versions ) but we don ' t really do anything with the LBA and length fields if the user passes them in .
/* NOTREACHED */ /*
	 * We check the LBA and length, but don't do anything with them.
	 * A SYNCHRONIZE CACHE will cause the entire cache for this lun to
	 * get flushed.  This check will just help satisfy anyone who wants
	 * to see an error for an out of range LBA.
	 */