Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Oct 1998 14:25:30 -0600 (MDT)
From:      "Kenneth D. Merry" <ken@plutotech.com>
To:        ken@panzer.plutotech.com (ken)
Cc:        asami@cs.berkeley.edu, scsi@FreeBSD.ORG
Subject:   Re: for i in disks
Message-ID:  <199810202025.OAA05317@panzer.plutotech.com>
In-Reply-To: <no.id> from ken at "Oct 20, 98 02:19:54 pm"

next in thread | previous in thread | raw e-mail | index | archive | help

--ELM908915130-5283-0_
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

I wrote...
> If you just want a listing of CAM-accessible disks, I've attached a program
> that will do that.  'camcontrol devlist' will also list all CAM devices.
> The attached program takes as arguments the peripheral names you're
> interested in.  e.g.:

I neglected to attach the program.  Here it is, and it's also available
here:

ftp://ftp.kdm.org/pub/FreeBSD/cam/devmatch.c

Ken
-- 
Kenneth Merry
ken@plutotech.com

--ELM908915130-5283-0_
Content-Type: text/plain
Content-Disposition: attachment; filename=devmatch.c
Content-Description: devmatch.c
Content-Transfer-Encoding: 7bit

/*
 * Copyright (c) 1998 Kenneth D. Merry.
 * 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. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. 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.
 *
 *	$Id$
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_pass.h>
#include <camlib.h>
#include <err.h>

int
main(int argc, char **argv)
{
	union ccb ccb;
	int bufsize, i, opt;
	struct periph_match_pattern *match_pat;
	int fd;
	
	if ((fd = open("/dev/xpt0", O_RDWR)) == -1)
		err(1, "couldn't open /dev/xpt0");

	bzero(&(&ccb.ccb_h)[1], sizeof(struct ccb_dev_match));

	ccb.ccb_h.func_code = XPT_DEV_MATCH;
	bufsize = sizeof(struct dev_match_result) * 100;
	ccb.cdm.match_buf_len = bufsize;
	ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
	ccb.cdm.num_matches = 0;

	if (argc == 1) {
		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));
		ccb.cdm.patterns[0].type = DEV_MATCH_PERIPH;
		match_pat = &ccb.cdm.patterns[0].pattern.periph_pattern;
		match_pat->flags = PERIPH_MATCH_ANY;
	} else {
		ccb.cdm.pattern_buf_len =
			sizeof(struct dev_match_pattern) * (argc - 1);
		ccb.cdm.patterns = (struct dev_match_pattern *)malloc(
			ccb.cdm.pattern_buf_len);

		for (i = 0; (i < 100) && (--argc > 0); i++) {
			ccb.cdm.num_patterns++;
			ccb.cdm.patterns[i].type = DEV_MATCH_PERIPH;
			match_pat = &ccb.cdm.patterns[i].pattern.periph_pattern;
			match_pat->flags = PERIPH_MATCH_NAME;
			snprintf(match_pat->periph_name, DEV_IDLEN, "%s",
				 argv[argc]);
		}
	}

	do {
		if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1)
			err(1, "error sending CAMIOCOMMAND ioctl");

		if ((ccb.ccb_h.status != CAM_REQ_CMP)
		 || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
		    && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
			fprintf(stderr, "got CAM error %#x, CDM error %d\n",
				ccb.ccb_h.status, ccb.cdm.status);
			exit(1);
		}

		for (i = 0; i < ccb.cdm.num_matches; i++) {
			switch(ccb.cdm.matches[i].type) {
			case DEV_MATCH_PERIPH: {
				struct periph_match_result *periph_result;

				periph_result =
				      &ccb.cdm.matches[i].result.periph_result;

				fprintf(stdout, "%s%d\n",
					periph_result->periph_name,
					periph_result->unit_number);
				break;
			}
			default:
				fprintf(stderr, "unknown match type %#x\n",
					ccb.cdm.matches[i].type);
				break;
			}
		}

		/* re-set the number of matches */
		ccb.cdm.num_matches = 0;

	} while ((ccb.ccb_h.status == CAM_REQ_CMP)
		&& (ccb.cdm.status == CAM_DEV_MATCH_MORE));

	close(fd);

	return(0);
}

--ELM908915130-5283-0_--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-scsi" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810202025.OAA05317>