FreeBSD/usr.sbin/camdd/camdd.c
/*
 * Fetch all completed commands from the pass(4) device.
 *
 * Returns the number of commands received, or -1 if any of the commands
 * completed with an error.  Returns 0 if no commands are available.
 */
Fetch all completed commands from the pass(4) device.
Returns the number of commands received, or -1 if any of the commands
completed with an error.  Returns 0 if no commands are available.
Fetch all completed commands from the pass ( 4 ) device . Returns the number of commands received or - 1 if any of the commands completed with an error . Returns 0 if no commands are available .
int
camdd_pass_fetch(struct camdd_dev *dev)
{
	struct camdd_dev_pass *pass_dev = &dev->dev_spec.pass;
	union ccb ccb;
	int retval = 0, num_fetched = 0, error_count = 0;
	pthread_mutex_unlock(&dev->mutex);
	while ((retval = ioctl(pass_dev->dev->fd, CAMIOGET, &ccb)) != -1) {
		struct camdd_buf *buf;
		struct camdd_buf_data *data;
		cam_status ccb_status;
		union ccb *buf_ccb;
		buf = ccb.ccb_h.ccb_buf;
		data = &buf->buf_type_spec.data;
		buf_ccb = &data->ccb;
		num_fetched++;
		bcopy(&ccb, buf_ccb, sizeof(ccb));
		pthread_mutex_lock(&dev->mutex);
		STAILQ_REMOVE(&dev->active_queue, buf, camdd_buf, links);
		dev->cur_active_io--;
		ccb_status = ccb.ccb_h.status & CAM_STATUS_MASK;
		if (ccb_status != CAM_REQ_CMP) {
			cam_error_print(pass_dev->dev, &ccb, CAM_ESF_ALL,
					CAM_EPF_ALL, stderr);
		}
		data->resid = ccb.csio.resid;
		dev->bytes_transferred += (ccb.csio.dxfer_len - ccb.csio.resid);
		if (buf->status == CAMDD_STATUS_NONE)
			buf->status = camdd_ccb_status(&ccb);
		if (buf->status == CAMDD_STATUS_ERROR)
			error_count++;
		else if (buf->status == CAMDD_STATUS_EOF) {
			dev->flags |= CAMDD_DEV_FLAG_EOF;
		}
		camdd_complete_buf(dev, buf, &error_count);
		pthread_mutex_unlock(&dev->mutex);
	}
	pthread_mutex_lock(&dev->mutex);
	if (error_count > 0)
		return (-1);
	else
		return (num_fetched);
}
int camdd_pass_fetch ( struct camdd_dev * dev ) { struct camdd_dev_pass * pass_dev = & dev -> dev_spec . pass ; union ccb ccb ; int retval = 0 , num_fetched = 0 , error_count = 0 ; pthread_mutex_unlock ( & dev -> mutex ) ; while ( ( retval = ioctl ( pass_dev -> dev -> fd , CAMIOGET , & ccb ) ) != -1 ) { struct camdd_buf * buf ; struct camdd_buf_data * data ; cam_status ccb_status ; union ccb * buf_ccb ; buf = ccb . ccb_h . ccb_buf ; data = & buf -> buf_type_spec . data ; buf_ccb = & data -> ccb ; num_fetched ++ ; bcopy ( & ccb , buf_ccb , sizeof ( ccb ) ) ; pthread_mutex_lock ( & dev -> mutex ) ; STAILQ_REMOVE ( & dev -> active_queue , buf , camdd_buf , links ) ; dev -> cur_active_io -- ; ccb_status = ccb . ccb_h . status & CAM_STATUS_MASK ; if ( ccb_status != CAM_REQ_CMP ) { cam_error_print ( pass_dev -> dev , & ccb , CAM_ESF_ALL , CAM_EPF_ALL , stderr ) ; } data -> resid = ccb . csio . resid ; dev -> bytes_transferred += ( ccb . csio . dxfer_len - ccb . csio . resid ) ; if ( buf -> status == CAMDD_STATUS_NONE ) buf -> status = camdd_ccb_status ( & ccb ) ; if ( buf -> status == CAMDD_STATUS_ERROR ) error_count ++ ; else if ( buf -> status == CAMDD_STATUS_EOF ) { dev -> flags |= CAMDD_DEV_FLAG_EOF ; } camdd_complete_buf ( dev , buf , & error_count ) ; pthread_mutex_unlock ( & dev -> mutex ) ; } pthread_mutex_lock ( & dev -> mutex ) ; if ( error_count > 0 ) return ( -1 ) ; else return ( num_fetched ) ; }
Fetch all completed commands from the pass(4) device.
Fetch all completed commands from the pass ( 4 ) device .
/*
	 * XXX KDM we don't distinguish between EFAULT and ENOENT.
	 */ /*
		 * Copy the CCB back out so we get status, sense data, etc.
		 */ /*
		 * We're now done, so take this off the active queue.
		 */ /*
			 * Once we queue this buffer to our partner thread,
			 * he will know that we've hit EOF.
			 */ /*
		 * Unlock in preparation for the ioctl call.
		 */