From owner-freebsd-scsi Tue Oct 20 13:26:05 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA28888 for freebsd-scsi-outgoing; Tue, 20 Oct 1998 13:26:05 -0700 (PDT) (envelope-from owner-freebsd-scsi@FreeBSD.ORG) Received: from panzer.plutotech.com (panzer.plutotech.com [206.168.67.125]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA28883 for ; Tue, 20 Oct 1998 13:26:03 -0700 (PDT) (envelope-from ken@panzer.plutotech.com) Received: (from ken@localhost) by panzer.plutotech.com (8.9.1/8.8.5) id OAA05317; Tue, 20 Oct 1998 14:25:30 -0600 (MDT) From: "Kenneth D. Merry" Message-Id: <199810202025.OAA05317@panzer.plutotech.com> Subject: Re: for i in disks In-Reply-To: from ken at "Oct 20, 98 02:19:54 pm" To: ken@panzer.plutotech.com (ken) Date: Tue, 20 Oct 1998 14:25:30 -0600 (MDT) Cc: asami@cs.berkeley.edu, scsi@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL28s (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM908915130-5283-0_ Content-Transfer-Encoding: 7bit Sender: owner-freebsd-scsi@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org --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 #include #include #include #include #include #include #include #include #include #include #include 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