2017-11-26 02:00:33 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2002-05-14 04:32:02 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999, 2002 Kenneth D. Merry.
|
1998-09-15 06:16:46 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 21:13:43 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-15 06:16:46 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
2017-12-06 23:24:11 +00:00
|
|
|
#include <assert.h>
|
1998-09-15 06:16:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-10-30 15:46:50 +00:00
|
|
|
#include <stdint.h>
|
1998-09-15 06:16:46 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <cam/cam.h>
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
#include <cam/cam_ccb.h>
|
|
|
|
#include <cam/scsi/scsi_pass.h>
|
|
|
|
#include "camlib.h"
|
|
|
|
|
|
|
|
|
2010-10-11 09:27:37 +00:00
|
|
|
static const char *nonrewind_devs[] = {
|
|
|
|
"sa"
|
1998-09-15 06:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
char cam_errbuf[CAM_ERRBUF_SIZE];
|
|
|
|
|
|
|
|
static struct cam_device *cam_real_open_device(const char *path, int flags,
|
|
|
|
struct cam_device *device,
|
|
|
|
const char *given_path,
|
|
|
|
const char *given_dev_name,
|
|
|
|
int given_unit_number);
|
|
|
|
static struct cam_device *cam_lookup_pass(const char *dev_name, int unit,
|
|
|
|
int flags, const char *given_path,
|
|
|
|
struct cam_device *device);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a ccb to a passthrough device.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
cam_send_ccb(struct cam_device *device, union ccb *ccb)
|
|
|
|
{
|
|
|
|
return(ioctl(device->fd, CAMIOCOMMAND, ccb));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Malloc a CCB, zero out the header and set its path, target and lun ids.
|
|
|
|
*/
|
|
|
|
union ccb *
|
|
|
|
cam_getccb(struct cam_device *dev)
|
|
|
|
{
|
|
|
|
union ccb *ccb;
|
|
|
|
|
|
|
|
ccb = (union ccb *)malloc(sizeof(union ccb));
|
|
|
|
if (ccb != NULL) {
|
|
|
|
bzero(&ccb->ccb_h, sizeof(struct ccb_hdr));
|
|
|
|
ccb->ccb_h.path_id = dev->path_id;
|
|
|
|
ccb->ccb_h.target_id = dev->target_id;
|
|
|
|
ccb->ccb_h.target_lun = dev->target_lun;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a CCB.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cam_freeccb(union ccb *ccb)
|
|
|
|
{
|
2005-07-13 10:40:07 +00:00
|
|
|
free(ccb);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a device name or path passed in by the user, and attempt to figure
|
|
|
|
* out the device name and unit number. Some possible device name formats are:
|
2010-10-11 09:27:37 +00:00
|
|
|
* /dev/foo0
|
1998-09-15 06:16:46 +00:00
|
|
|
* foo0
|
2010-10-11 09:27:37 +00:00
|
|
|
* nfoo0
|
2016-04-14 21:10:53 +00:00
|
|
|
*
|
2010-10-11 09:27:37 +00:00
|
|
|
* Some peripheral drivers create separate device nodes with 'n' prefix for
|
|
|
|
* non-rewind operations. Currently only sa(4) tape driver has this feature.
|
|
|
|
* We extract pure peripheral name as device name for this special case.
|
|
|
|
*
|
1998-09-15 06:16:46 +00:00
|
|
|
* Input parameters: device name/path, length of devname string
|
|
|
|
* Output: device name, unit number
|
|
|
|
* Return values: returns 0 for success, -1 for failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
|
|
|
|
{
|
|
|
|
char *tmpstr, *tmpstr2;
|
|
|
|
char *newpath;
|
|
|
|
int unit_offset;
|
2010-10-11 09:27:37 +00:00
|
|
|
int i;
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
if (path == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: device pathname was NULL", __func__);
|
1999-06-15 20:03:01 +00:00
|
|
|
return(-1);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can be rather destructive to the path string. Make a copy of
|
|
|
|
* it so we don't hose the user's string.
|
|
|
|
*/
|
|
|
|
newpath = (char *)strdup(path);
|
2017-12-06 23:24:11 +00:00
|
|
|
if (newpath == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
1998-09-15 06:16:46 +00:00
|
|
|
tmpstr = newpath;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see whether we have an absolute pathname.
|
|
|
|
*/
|
|
|
|
if (*tmpstr == '/') {
|
|
|
|
tmpstr2 = tmpstr;
|
2012-01-03 18:51:58 +00:00
|
|
|
tmpstr = strrchr(tmpstr2, '/');
|
2017-12-06 23:24:11 +00:00
|
|
|
/* We know that tmpstr2 contains a '/', so strrchr can't fail */
|
|
|
|
assert(tmpstr != NULL && *tmpstr != '\0');
|
|
|
|
tmpstr++;
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*tmpstr == '\0') {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: no text after slash", __func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
free(newpath);
|
1999-06-15 20:03:01 +00:00
|
|
|
return(-1);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see whether the user has given us a nonrewound tape
|
|
|
|
* device.
|
|
|
|
*/
|
2010-10-11 09:27:37 +00:00
|
|
|
if (*tmpstr == 'n' || *tmpstr == 'e') {
|
|
|
|
for (i = 0; i < sizeof(nonrewind_devs)/sizeof(char *); i++) {
|
|
|
|
int len = strlen(nonrewind_devs[i]);
|
|
|
|
if (strncmp(tmpstr + 1, nonrewind_devs[i], len) == 0) {
|
|
|
|
if (isdigit(tmpstr[len + 1])) {
|
|
|
|
tmpstr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-11 21:34:35 +00:00
|
|
|
* We should now have just a device name and unit number.
|
|
|
|
* That means that there must be at least 2 characters.
|
|
|
|
* If we only have 1, we don't have a valid device name.
|
1998-09-15 06:16:46 +00:00
|
|
|
*/
|
|
|
|
if (strlen(tmpstr) < 2) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: must have both device name and unit number",
|
2017-03-28 22:32:11 +00:00
|
|
|
__func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
free(newpath);
|
1999-06-15 20:03:01 +00:00
|
|
|
return(-1);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the first character of the string is a digit, then the user
|
|
|
|
* has probably given us all numbers. Point out the error.
|
|
|
|
*/
|
|
|
|
if (isdigit(*tmpstr)) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: device name cannot begin with a number",
|
2017-03-28 22:32:11 +00:00
|
|
|
__func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
free(newpath);
|
1999-06-15 20:03:01 +00:00
|
|
|
return(-1);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, if the last character of the string isn't a
|
2016-04-14 21:10:53 +00:00
|
|
|
* number, we know the user either didn't give us a device number,
|
1998-09-15 06:16:46 +00:00
|
|
|
* or he gave us a device name/number format we don't recognize.
|
|
|
|
*/
|
|
|
|
if (!isdigit(tmpstr[strlen(tmpstr) - 1])) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: unable to find device unit number", __func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
free(newpath);
|
1999-06-15 20:03:01 +00:00
|
|
|
return(-1);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to figure out where the device name ends and the unit
|
|
|
|
* number begins. As long as unit_offset is at least 1 less than
|
|
|
|
* the length of the string, we can still potentially have a device
|
|
|
|
* name at the front of the string. When we get to something that
|
|
|
|
* isn't a digit, we've hit the device name. Because of the check
|
|
|
|
* above, we know that this cannot happen when unit_offset == 1.
|
|
|
|
* Therefore it is okay to decrement unit_offset -- it won't cause
|
|
|
|
* us to go past the end of the character array.
|
|
|
|
*/
|
|
|
|
for (unit_offset = 1;
|
|
|
|
(unit_offset < (strlen(tmpstr)))
|
|
|
|
&& (isdigit(tmpstr[strlen(tmpstr) - unit_offset])); unit_offset++);
|
|
|
|
|
|
|
|
unit_offset--;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab the unit number.
|
|
|
|
*/
|
|
|
|
*unit = atoi(&tmpstr[strlen(tmpstr) - unit_offset]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put a null in place of the first number of the unit number so
|
|
|
|
* that all we have left is the device name.
|
|
|
|
*/
|
|
|
|
tmpstr[strlen(tmpstr) - unit_offset] = '\0';
|
|
|
|
|
2010-10-11 09:27:37 +00:00
|
|
|
strlcpy(dev_name, tmpstr, devnamelen);
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
/* Clean up allocated memory */
|
|
|
|
free(newpath);
|
|
|
|
|
1999-06-15 20:03:01 +00:00
|
|
|
return(0);
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Backwards compatible wrapper for the real open routine. This translates
|
|
|
|
* a pathname into a device name and unit number for use with the real open
|
|
|
|
* routine.
|
|
|
|
*/
|
|
|
|
struct cam_device *
|
|
|
|
cam_open_device(const char *path, int flags)
|
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
char dev_name[DEV_IDLEN + 1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cam_get_device() has already put an error message in cam_errbuf,
|
|
|
|
* so we don't need to.
|
|
|
|
*/
|
2002-05-14 04:32:02 +00:00
|
|
|
if (cam_get_device(path, dev_name, sizeof(dev_name), &unit) == -1)
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
return(cam_lookup_pass(dev_name, unit, flags, path, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the passthrough device for a given bus, target and lun, if the
|
|
|
|
* passthrough device exists.
|
|
|
|
*/
|
|
|
|
struct cam_device *
|
|
|
|
cam_open_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun,
|
|
|
|
int flags, struct cam_device *device)
|
|
|
|
{
|
|
|
|
union ccb ccb;
|
|
|
|
struct periph_match_pattern *match_pat;
|
|
|
|
int fd, bufsize;
|
|
|
|
|
|
|
|
if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: couldn't open %s\n%s: %s", __func__, XPT_DEVICE,
|
|
|
|
__func__, strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(&ccb, sizeof(union ccb));
|
|
|
|
ccb.ccb_h.func_code = XPT_DEV_MATCH;
|
2008-10-27 21:46:58 +00:00
|
|
|
ccb.ccb_h.path_id = CAM_XPT_PATH_ID;
|
|
|
|
ccb.ccb_h.target_id = CAM_TARGET_WILDCARD;
|
|
|
|
ccb.ccb_h.target_lun = CAM_LUN_WILDCARD;
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
/* Setup the result buffer */
|
|
|
|
bufsize = sizeof(struct dev_match_result);
|
|
|
|
ccb.cdm.match_buf_len = bufsize;
|
|
|
|
ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
|
|
|
|
if (ccb.cdm.matches == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: couldn't malloc match buffer", __func__);
|
1999-09-12 19:40:20 +00:00
|
|
|
close(fd);
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
ccb.cdm.num_matches = 0;
|
|
|
|
|
|
|
|
/* Setup the pattern buffer */
|
|
|
|
ccb.cdm.num_patterns = 1;
|
|
|
|
ccb.cdm.pattern_buf_len = sizeof(struct dev_match_pattern);
|
|
|
|
ccb.cdm.patterns = (struct dev_match_pattern *)malloc(
|
|
|
|
sizeof(struct dev_match_pattern));
|
|
|
|
if (ccb.cdm.patterns == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: couldn't malloc pattern buffer", __func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
free(ccb.cdm.matches);
|
2017-03-20 16:30:02 +00:00
|
|
|
ccb.cdm.matches = NULL;
|
1999-09-12 19:40:20 +00:00
|
|
|
close(fd);
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
ccb.cdm.patterns[0].type = DEV_MATCH_PERIPH;
|
2016-04-14 21:10:53 +00:00
|
|
|
match_pat = &ccb.cdm.patterns[0].pattern.periph_pattern;
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We're looking for the passthrough device associated with this
|
|
|
|
* particular bus/target/lun.
|
|
|
|
*/
|
|
|
|
sprintf(match_pat->periph_name, "pass");
|
|
|
|
match_pat->path_id = path_id;
|
|
|
|
match_pat->target_id = target_id;
|
|
|
|
match_pat->target_lun = target_lun;
|
|
|
|
/* Now set the flags to indicate what we're looking for. */
|
|
|
|
match_pat->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_TARGET |
|
|
|
|
PERIPH_MATCH_LUN | PERIPH_MATCH_NAME;
|
|
|
|
|
|
|
|
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: CAMIOCOMMAND ioctl failed\n"
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: %s", __func__, __func__, strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
goto btl_bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for an outright error.
|
|
|
|
*/
|
|
|
|
if ((ccb.ccb_h.status != CAM_REQ_CMP)
|
|
|
|
|| ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
|
|
|
|
&& (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: CAM error %#x, CDM error %d "
|
2017-03-28 22:32:11 +00:00
|
|
|
"returned from XPT_DEV_MATCH ccb", __func__,
|
2017-03-28 08:24:16 +00:00
|
|
|
ccb.ccb_h.status, ccb.cdm.status);
|
1998-09-15 06:16:46 +00:00
|
|
|
goto btl_bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ccb.cdm.status == CAM_DEV_MATCH_MORE) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: CDM reported more than one"
|
|
|
|
" passthrough device at %d:%d:%jx!!\n",
|
2017-03-28 22:32:11 +00:00
|
|
|
__func__, path_id, target_id, (uintmax_t)target_lun);
|
1998-09-15 06:16:46 +00:00
|
|
|
goto btl_bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ccb.cdm.num_matches == 0) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: no passthrough device found at"
|
2017-03-28 22:32:11 +00:00
|
|
|
" %d:%d:%jx", __func__, path_id, target_id,
|
2017-03-28 08:24:16 +00:00
|
|
|
(uintmax_t)target_lun);
|
1998-09-15 06:16:46 +00:00
|
|
|
goto btl_bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(ccb.cdm.matches[0].type) {
|
|
|
|
case DEV_MATCH_PERIPH: {
|
|
|
|
int pass_unit;
|
|
|
|
char dev_path[256];
|
|
|
|
struct periph_match_result *periph_result;
|
|
|
|
|
|
|
|
periph_result = &ccb.cdm.matches[0].result.periph_result;
|
|
|
|
pass_unit = periph_result->unit_number;
|
|
|
|
free(ccb.cdm.matches);
|
2017-03-20 16:30:02 +00:00
|
|
|
ccb.cdm.matches = NULL;
|
1998-09-15 06:16:46 +00:00
|
|
|
free(ccb.cdm.patterns);
|
2017-03-20 16:30:02 +00:00
|
|
|
ccb.cdm.patterns = NULL;
|
1999-09-12 19:40:20 +00:00
|
|
|
close(fd);
|
1998-09-15 06:16:46 +00:00
|
|
|
sprintf(dev_path, "/dev/pass%d", pass_unit);
|
|
|
|
return(cam_real_open_device(dev_path, flags, device, NULL,
|
|
|
|
NULL, 0));
|
|
|
|
break; /* NOTREACHED */
|
|
|
|
}
|
|
|
|
default:
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: asked for a peripheral match, but"
|
2017-03-28 22:32:11 +00:00
|
|
|
" got a bus or device match", __func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
goto btl_bailout;
|
|
|
|
break; /* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
btl_bailout:
|
|
|
|
free(ccb.cdm.matches);
|
2017-03-20 16:30:02 +00:00
|
|
|
ccb.cdm.matches = NULL;
|
1998-09-15 06:16:46 +00:00
|
|
|
free(ccb.cdm.patterns);
|
2017-03-20 16:30:02 +00:00
|
|
|
ccb.cdm.patterns = NULL;
|
1999-09-12 19:40:20 +00:00
|
|
|
close(fd);
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cam_device *
|
|
|
|
cam_open_spec_device(const char *dev_name, int unit, int flags,
|
|
|
|
struct cam_device *device)
|
|
|
|
{
|
|
|
|
return(cam_lookup_pass(dev_name, unit, flags, NULL, device));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cam_device *
|
|
|
|
cam_open_pass(const char *path, int flags, struct cam_device *device)
|
|
|
|
{
|
|
|
|
return(cam_real_open_device(path, flags, device, path, NULL, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cam_device *
|
|
|
|
cam_lookup_pass(const char *dev_name, int unit, int flags,
|
|
|
|
const char *given_path, struct cam_device *device)
|
|
|
|
{
|
2006-04-30 07:08:43 +00:00
|
|
|
int fd;
|
1998-09-15 06:16:46 +00:00
|
|
|
union ccb ccb;
|
|
|
|
char dev_path[256];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The flags argument above only applies to the actual passthrough
|
|
|
|
* device open, not our open of the given device to find the
|
|
|
|
* passthrough device.
|
|
|
|
*/
|
|
|
|
if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: couldn't open %s\n%s: %s", __func__, XPT_DEVICE,
|
|
|
|
__func__, strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This isn't strictly necessary for the GETPASSTHRU ioctl. */
|
|
|
|
ccb.ccb_h.func_code = XPT_GDEVLIST;
|
|
|
|
|
|
|
|
/* These two are necessary for the GETPASSTHRU ioctl to work. */
|
2002-05-14 04:32:02 +00:00
|
|
|
strlcpy(ccb.cgdl.periph_name, dev_name, sizeof(ccb.cgdl.periph_name));
|
1998-09-15 06:16:46 +00:00
|
|
|
ccb.cgdl.unit_number = unit;
|
|
|
|
|
|
|
|
/*
|
2016-04-14 21:10:53 +00:00
|
|
|
* Attempt to get the passthrough device. This ioctl will fail if
|
1998-10-12 21:54:13 +00:00
|
|
|
* the device name is null, if the device doesn't exist, or if the
|
|
|
|
* passthrough driver isn't in the kernel.
|
1998-09-15 06:16:46 +00:00
|
|
|
*/
|
2006-04-30 07:08:43 +00:00
|
|
|
if (ioctl(fd, CAMGETPASSTHRU, &ccb) == -1) {
|
1998-10-12 21:54:13 +00:00
|
|
|
char tmpstr[256];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get ENOENT from the transport layer version of
|
|
|
|
* the CAMGETPASSTHRU ioctl, it means one of two things:
|
|
|
|
* either the device name/unit number passed in doesn't
|
|
|
|
* exist, or the passthrough driver isn't in the kernel.
|
|
|
|
*/
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
snprintf(tmpstr, sizeof(tmpstr),
|
|
|
|
"\n%s: either the pass driver isn't in "
|
|
|
|
"your kernel\n%s: or %s%d doesn't exist",
|
2017-03-28 22:32:11 +00:00
|
|
|
__func__, __func__, dev_name, unit);
|
1998-10-12 21:54:13 +00:00
|
|
|
}
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: CAMGETPASSTHRU ioctl failed\n"
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: %s%s", __func__, __func__, strerror(errno),
|
2017-03-28 08:24:16 +00:00
|
|
|
(errno == ENOENT) ? tmpstr : "");
|
1998-10-12 21:54:13 +00:00
|
|
|
|
2006-04-30 07:08:43 +00:00
|
|
|
close(fd);
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2006-04-30 07:08:43 +00:00
|
|
|
close(fd);
|
|
|
|
|
1998-09-15 06:16:46 +00:00
|
|
|
/*
|
|
|
|
* If the ioctl returned the right status, but we got an error back
|
|
|
|
* in the ccb, that means that the kernel found the device the user
|
|
|
|
* passed in, but was unable to find the passthrough device for
|
|
|
|
* the device the user gave us.
|
|
|
|
*/
|
|
|
|
if (ccb.cgdl.status == CAM_GDEVLIST_ERROR) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: device %s%d does not exist!",
|
2017-03-28 22:32:11 +00:00
|
|
|
__func__, dev_name, unit);
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(dev_path, "/dev/%s%d", ccb.cgdl.periph_name,
|
|
|
|
ccb.cgdl.unit_number);
|
|
|
|
|
|
|
|
return(cam_real_open_device(dev_path, flags, device, NULL,
|
|
|
|
dev_name, unit));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a given device. The path argument isn't strictly necessary, but it
|
|
|
|
* is copied into the cam_device structure as a convenience to the user.
|
|
|
|
*/
|
|
|
|
static struct cam_device *
|
|
|
|
cam_real_open_device(const char *path, int flags, struct cam_device *device,
|
|
|
|
const char *given_path, const char *given_dev_name,
|
|
|
|
int given_unit_number)
|
|
|
|
{
|
|
|
|
union ccb ccb;
|
2001-07-04 07:43:10 +00:00
|
|
|
int fd = -1, malloced_device = 0;
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* See if the user wants us to malloc a device for him.
|
|
|
|
*/
|
|
|
|
if (device == NULL) {
|
|
|
|
if ((device = (struct cam_device *)malloc(
|
|
|
|
sizeof(struct cam_device))) == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: device structure malloc"
|
2017-03-28 22:32:11 +00:00
|
|
|
" failed\n%s: %s", __func__, __func__,
|
2017-03-28 08:24:16 +00:00
|
|
|
strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2001-07-04 07:43:10 +00:00
|
|
|
device->fd = -1;
|
1998-09-15 06:16:46 +00:00
|
|
|
malloced_device = 1;
|
2016-04-14 21:10:53 +00:00
|
|
|
}
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user passed in a path, save it for him.
|
|
|
|
*/
|
|
|
|
if (given_path != NULL)
|
2002-05-14 04:32:02 +00:00
|
|
|
strlcpy(device->device_path, given_path,
|
|
|
|
sizeof(device->device_path));
|
1998-09-15 06:16:46 +00:00
|
|
|
else
|
|
|
|
device->device_path[0] = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user passed in a device name and unit number pair, save
|
|
|
|
* those as well.
|
|
|
|
*/
|
|
|
|
if (given_dev_name != NULL)
|
2002-05-14 04:32:02 +00:00
|
|
|
strlcpy(device->given_dev_name, given_dev_name,
|
|
|
|
sizeof(device->given_dev_name));
|
1998-09-15 06:16:46 +00:00
|
|
|
else
|
|
|
|
device->given_dev_name[0] = '\0';
|
|
|
|
device->given_unit_number = given_unit_number;
|
|
|
|
|
|
|
|
if ((fd = open(path, flags)) < 0) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: couldn't open passthrough device %s\n"
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: %s", __func__, path, __func__,
|
2017-03-28 08:24:16 +00:00
|
|
|
strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
goto crod_bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->fd = fd;
|
|
|
|
|
|
|
|
bzero(&ccb, sizeof(union ccb));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlike the transport layer version of the GETPASSTHRU ioctl,
|
|
|
|
* we don't have to set any fields.
|
|
|
|
*/
|
|
|
|
ccb.ccb_h.func_code = XPT_GDEVLIST;
|
2016-04-14 21:10:53 +00:00
|
|
|
|
1998-09-15 06:16:46 +00:00
|
|
|
/*
|
|
|
|
* We're only doing this to get some information on the device in
|
|
|
|
* question. Otherwise, we'd have to pass in yet another
|
|
|
|
* parameter: the passthrough driver unit number.
|
|
|
|
*/
|
|
|
|
if (ioctl(fd, CAMGETPASSTHRU, &ccb) == -1) {
|
1998-10-12 21:54:13 +00:00
|
|
|
/*
|
|
|
|
* At this point we know the passthrough device must exist
|
|
|
|
* because we just opened it above. The only way this
|
|
|
|
* ioctl can fail is if the ccb size is wrong.
|
|
|
|
*/
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: CAMGETPASSTHRU ioctl failed\n"
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: %s", __func__, __func__, strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
goto crod_bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the ioctl returned the right status, but we got an error back
|
|
|
|
* in the ccb, that means that the kernel found the device the user
|
|
|
|
* passed in, but was unable to find the passthrough device for
|
|
|
|
* the device the user gave us.
|
|
|
|
*/
|
|
|
|
if (ccb.cgdl.status == CAM_GDEVLIST_ERROR) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: passthrough device does not exist!", __func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
goto crod_bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->dev_unit_num = ccb.cgdl.unit_number;
|
2002-05-14 04:32:02 +00:00
|
|
|
strlcpy(device->device_name, ccb.cgdl.periph_name,
|
|
|
|
sizeof(device->device_name));
|
1998-09-15 06:16:46 +00:00
|
|
|
device->path_id = ccb.ccb_h.path_id;
|
|
|
|
device->target_id = ccb.ccb_h.target_id;
|
|
|
|
device->target_lun = ccb.ccb_h.target_lun;
|
|
|
|
|
|
|
|
ccb.ccb_h.func_code = XPT_PATH_INQ;
|
|
|
|
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: Path Inquiry CCB failed\n"
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: %s", __func__, __func__, strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
goto crod_bailout;
|
|
|
|
}
|
2002-05-14 04:32:02 +00:00
|
|
|
strlcpy(device->sim_name, ccb.cpi.dev_name, sizeof(device->sim_name));
|
1998-09-15 06:16:46 +00:00
|
|
|
device->sim_unit_number = ccb.cpi.unit_number;
|
|
|
|
device->bus_id = ccb.cpi.bus_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It doesn't really matter what is in the payload for a getdev
|
|
|
|
* CCB, the kernel doesn't look at it.
|
|
|
|
*/
|
|
|
|
ccb.ccb_h.func_code = XPT_GDEV_TYPE;
|
|
|
|
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: Get Device Type CCB failed\n"
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: %s", __func__, __func__, strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
goto crod_bailout;
|
|
|
|
}
|
2000-01-16 20:15:43 +00:00
|
|
|
device->pd_type = SID_TYPE(&ccb.cgd.inq_data);
|
2016-04-14 21:10:53 +00:00
|
|
|
bcopy(&ccb.cgd.inq_data, &device->inq_data,
|
1998-09-15 06:16:46 +00:00
|
|
|
sizeof(struct scsi_inquiry_data));
|
|
|
|
device->serial_num_len = ccb.cgd.serial_num_len;
|
|
|
|
bcopy(&ccb.cgd.serial_num, &device->serial_num, device->serial_num_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero the payload, the kernel does look at the flags.
|
|
|
|
*/
|
Fix multiple Coverity Out-of-bounds access false postive issues in CAM
The currently used idiom for clearing the part of a ccb after its
header generates one or two Coverity errors for each time it is
used. All instances generate an Out-of-bounds access (ARRAY_VS_SINGLETON)
error because of the treatment of the header as a two element array,
with a pointer to the non-existent second element being passed as
the starting address to bzero(). Some instances also alsp generate
Out-of-bounds access (OVERRUN) errors, probably because the space
being cleared is larger than the sizeofstruct ccb_hdr).
In addition, this idiom is difficult for humans to understand and
it is error prone. The user has to chose the proper struct ccb_*
type (which does not appear in the surrounding code) for the sizeof()
in the length calculation. I found several instances where the
length was incorrect, which could cause either an actual out of
bounds write, or incompletely clear the ccb.
A better way is to write the code to clear the ccb itself starting
at sizeof(ccb_hdr) bytes from the start of the ccb, and calculate
the length based on the specific type of struct ccb_* being cleared
as specified by the union ccb member being used. The latter can
normally be seen in the nearby code. This is friendlier for Coverity
and other static analysis tools because they will see that the
intent is to clear the trailing part of the ccb.
Wrap all of the boilerplate code in a convenient macro that only
requires a pointer to the desired union ccb member (or a pointer
to the union ccb itself) as an argument.
Reported by: Coverity
CID: 1007578, 1008684, 1009724, 1009773, 1011304, 1011306
CID: 1011307, 1011308, 1011309, 1011310, 1011311, 1011312
CID: 1011313, 1011314, 1011315, 1011316, 1011317, 1011318
CID: 1011319, 1011320, 1011321, 1011322, 1011324, 1011325
CID: 1011326, 1011327, 1011328, 1011329, 1011330, 1011374
CID: 1011390, 1011391, 1011392, 1011393, 1011394, 1011395
CID: 1011396, 1011397, 1011398, 1011399, 1011400, 1011401
CID: 1011402, 1011403, 1011404, 1011405, 1011406, 1011408
CID: 1011409, 1011410, 1011411, 1011412, 1011413, 1011414
CID: 1017461, 1018387, 1086860, 1086874, 1194257, 1229897
CID: 1229968, 1306229, 1306234, 1331282, 1331283, 1331294
CID: 1331295, 1331535, 1331536, 1331539, 1331540, 1341623
CID: 1341624, 1341637, 1341638, 1355264, 1355324
Reviewed by: scottl, ken, delphij, imp
MFH: 1 month
Differential Revision: https://reviews.freebsd.org/D6496
2016-05-24 00:57:11 +00:00
|
|
|
CCB_CLEAR_ALL_EXCEPT_HDR(&ccb.cts);
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get transfer settings for this device.
|
|
|
|
*/
|
|
|
|
ccb.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
|
|
|
|
|
2006-11-02 00:54:38 +00:00
|
|
|
ccb.cts.type = CTS_TYPE_CURRENT_SETTINGS;
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 08:24:16 +00:00
|
|
|
"%s: Get Transfer Settings CCB failed\n"
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: %s", __func__, __func__, strerror(errno));
|
1998-09-15 06:16:46 +00:00
|
|
|
goto crod_bailout;
|
|
|
|
}
|
2013-06-03 21:52:19 +00:00
|
|
|
if (ccb.cts.transport == XPORT_SPI) {
|
2006-11-02 00:54:38 +00:00
|
|
|
struct ccb_trans_settings_spi *spi =
|
|
|
|
&ccb.cts.xport_specific.spi;
|
|
|
|
device->sync_period = spi->sync_period;
|
|
|
|
device->sync_offset = spi->sync_offset;
|
|
|
|
device->bus_width = spi->bus_width;
|
|
|
|
} else {
|
|
|
|
device->sync_period = 0;
|
|
|
|
device->sync_offset = 0;
|
|
|
|
device->bus_width = 0;
|
|
|
|
}
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
return(device);
|
|
|
|
|
|
|
|
crod_bailout:
|
|
|
|
|
2001-07-04 07:43:10 +00:00
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
|
1998-09-15 06:16:46 +00:00
|
|
|
if (malloced_device)
|
|
|
|
free(device);
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cam_close_device(struct cam_device *dev)
|
|
|
|
{
|
|
|
|
if (dev == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cam_close_spec_device(dev);
|
|
|
|
|
2005-07-13 10:40:07 +00:00
|
|
|
free(dev);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cam_close_spec_device(struct cam_device *dev)
|
|
|
|
{
|
|
|
|
if (dev == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-10-17 09:07:53 +00:00
|
|
|
if (dev->fd >= 0) {
|
1998-09-15 06:16:46 +00:00
|
|
|
close(dev->fd);
|
2015-10-17 09:07:53 +00:00
|
|
|
dev->fd = -1;
|
|
|
|
}
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
cam_path_string(struct cam_device *dev, char *str, int len)
|
|
|
|
{
|
|
|
|
if (dev == NULL) {
|
|
|
|
snprintf(str, len, "No path");
|
|
|
|
return(str);
|
|
|
|
}
|
|
|
|
|
2013-10-30 14:13:15 +00:00
|
|
|
snprintf(str, len, "(%s%d:%s%d:%d:%d:%jx): ",
|
1998-09-15 06:16:46 +00:00
|
|
|
(dev->device_name[0] != '\0') ? dev->device_name : "pass",
|
|
|
|
dev->dev_unit_num,
|
|
|
|
(dev->sim_name[0] != '\0') ? dev->sim_name : "unknown",
|
|
|
|
dev->sim_unit_number,
|
|
|
|
dev->bus_id,
|
|
|
|
dev->target_id,
|
2013-10-30 14:13:15 +00:00
|
|
|
(uintmax_t)dev->target_lun);
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
return(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Malloc/duplicate a CAM device structure.
|
|
|
|
*/
|
|
|
|
struct cam_device *
|
|
|
|
cam_device_dup(struct cam_device *device)
|
|
|
|
{
|
|
|
|
struct cam_device *newdev;
|
|
|
|
|
|
|
|
if (device == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: device is NULL", __func__);
|
2017-03-28 08:24:16 +00:00
|
|
|
return (NULL);
|
1998-09-15 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newdev = malloc(sizeof(struct cam_device));
|
2005-07-13 10:40:07 +00:00
|
|
|
if (newdev == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: couldn't malloc CAM device structure", __func__);
|
2017-03-28 08:24:16 +00:00
|
|
|
return (NULL);
|
2005-07-13 10:40:07 +00:00
|
|
|
}
|
1998-09-15 06:16:46 +00:00
|
|
|
|
|
|
|
bcopy(device, newdev, sizeof(struct cam_device));
|
|
|
|
|
|
|
|
return(newdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a CAM device structure.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cam_device_copy(struct cam_device *src, struct cam_device *dst)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (src == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: source device struct was NULL", __func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst == NULL) {
|
2017-03-29 08:38:31 +00:00
|
|
|
snprintf(cam_errbuf, nitems(cam_errbuf),
|
2017-03-28 22:32:11 +00:00
|
|
|
"%s: destination device struct was NULL", __func__);
|
1998-09-15 06:16:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy(src, dst, sizeof(struct cam_device));
|
|
|
|
|
|
|
|
}
|