| 1 |
blade |
2 |
/* @(#)scsi_scan.c 1.19 04/04/16 Copyright 1997-2004 J. Schilling */
|
| 2 |
|
|
#ifndef lint
|
| 3 |
|
|
static char sccsid[] =
|
| 4 |
|
|
"@(#)scsi_scan.c 1.19 04/04/16 Copyright 1997-2004 J. Schilling";
|
| 5 |
|
|
#endif
|
| 6 |
|
|
/*
|
| 7 |
|
|
* Scan SCSI Bus.
|
| 8 |
|
|
* Stolen from sformat. Need a more general form to
|
| 9 |
|
|
* re-use it in sformat too.
|
| 10 |
|
|
*
|
| 11 |
|
|
* Copyright (c) 1997-2004 J. Schilling
|
| 12 |
|
|
*/
|
| 13 |
|
|
/*
|
| 14 |
|
|
* This program is free software; you can redistribute it and/or modify
|
| 15 |
|
|
* it under the terms of the GNU General Public License version 2
|
| 16 |
|
|
* as published by the Free Software Foundation.
|
| 17 |
|
|
*
|
| 18 |
|
|
* This program is distributed in the hope that it will be useful,
|
| 19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
* GNU General Public License for more details.
|
| 22 |
|
|
*
|
| 23 |
|
|
* You should have received a copy of the GNU General Public License along with
|
| 24 |
|
|
* this program; see the file COPYING. If not, write to the Free Software
|
| 25 |
|
|
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 26 |
|
|
*/
|
| 27 |
|
|
|
| 28 |
|
|
#include <mconfig.h>
|
| 29 |
|
|
#include <stdio.h>
|
| 30 |
|
|
#include <stdxlib.h>
|
| 31 |
|
|
#include <standard.h>
|
| 32 |
|
|
#include <btorder.h>
|
| 33 |
|
|
#include <errno.h>
|
| 34 |
|
|
#include <schily.h>
|
| 35 |
|
|
|
| 36 |
|
|
#include <scg/scgcmd.h>
|
| 37 |
|
|
#include <scg/scsidefs.h>
|
| 38 |
|
|
#include <scg/scsireg.h>
|
| 39 |
|
|
#include <scg/scsitransp.h>
|
| 40 |
|
|
|
| 41 |
|
|
#include "scsi_scan.h"
|
| 42 |
|
|
#include "cdrecord.h"
|
| 43 |
|
|
|
| 44 |
|
|
LOCAL void print_product __PR((FILE *f, struct scsi_inquiry *ip));
|
| 45 |
|
|
EXPORT int select_target __PR((SCSI *scgp, FILE *f));
|
| 46 |
|
|
LOCAL int select_unit __PR((SCSI *scgp, FILE *f));
|
| 47 |
|
|
|
| 48 |
|
|
LOCAL void
|
| 49 |
|
|
print_product(f, ip)
|
| 50 |
|
|
FILE *f;
|
| 51 |
|
|
struct scsi_inquiry *ip;
|
| 52 |
|
|
{
|
| 53 |
|
|
fprintf(f, "'%.8s' ", ip->vendor_info);
|
| 54 |
|
|
fprintf(f, "'%.16s' ", ip->prod_ident);
|
| 55 |
|
|
fprintf(f, "'%.4s' ", ip->prod_revision);
|
| 56 |
|
|
if (ip->add_len < 31) {
|
| 57 |
|
|
fprintf(f, "NON CCS ");
|
| 58 |
|
|
}
|
| 59 |
|
|
scg_fprintdev(f, ip);
|
| 60 |
|
|
}
|
| 61 |
|
|
|
| 62 |
|
|
EXPORT int
|
| 63 |
|
|
select_target(scgp, f)
|
| 64 |
|
|
SCSI *scgp;
|
| 65 |
|
|
FILE *f;
|
| 66 |
|
|
{
|
| 67 |
|
|
int initiator;
|
| 68 |
|
|
#ifdef FMT
|
| 69 |
|
|
int cscsibus = scg_scsibus(scgp);
|
| 70 |
|
|
int ctarget = scg_target(scgp);
|
| 71 |
|
|
int clun = scg_lun(scgp);
|
| 72 |
|
|
#endif
|
| 73 |
|
|
int n;
|
| 74 |
|
|
int low = -1;
|
| 75 |
|
|
int high = -1;
|
| 76 |
|
|
int amt = 0;
|
| 77 |
|
|
int bus;
|
| 78 |
|
|
int tgt;
|
| 79 |
|
|
int lun = 0;
|
| 80 |
|
|
BOOL have_tgt;
|
| 81 |
|
|
|
| 82 |
|
|
scgp->silent++;
|
| 83 |
|
|
|
| 84 |
|
|
for (bus = 0; bus < 256; bus++) {
|
| 85 |
|
|
scg_settarget(scgp, bus, 0, 0);
|
| 86 |
|
|
|
| 87 |
|
|
if (!scg_havebus(scgp, bus))
|
| 88 |
|
|
continue;
|
| 89 |
|
|
|
| 90 |
|
|
initiator = scg_initiator_id(scgp);
|
| 91 |
|
|
fprintf(f, "scsibus%d:\n", bus);
|
| 92 |
|
|
|
| 93 |
|
|
for (tgt = 0; tgt < 16; tgt++) {
|
| 94 |
|
|
n = bus*100 + tgt;
|
| 95 |
|
|
|
| 96 |
|
|
scg_settarget(scgp, bus, tgt, lun);
|
| 97 |
|
|
have_tgt = unit_ready(scgp) || scgp->scmd->error != SCG_FATAL;
|
| 98 |
|
|
|
| 99 |
|
|
if (!have_tgt && tgt > 7) {
|
| 100 |
|
|
if (scgp->scmd->ux_errno == EINVAL)
|
| 101 |
|
|
break;
|
| 102 |
|
|
continue;
|
| 103 |
|
|
}
|
| 104 |
|
|
|
| 105 |
|
|
#ifdef FMT
|
| 106 |
|
|
if (print_disknames(bus, tgt, -1) < 8)
|
| 107 |
|
|
fprintf(f, "\t");
|
| 108 |
|
|
else
|
| 109 |
|
|
fprintf(f, " ");
|
| 110 |
|
|
#else
|
| 111 |
|
|
fprintf(f, "\t");
|
| 112 |
|
|
#endif
|
| 113 |
|
|
if (fprintf(f, "%d,%d,%d", bus, tgt, lun) < 8)
|
| 114 |
|
|
fprintf(f, "\t");
|
| 115 |
|
|
else
|
| 116 |
|
|
fprintf(f, " ");
|
| 117 |
|
|
fprintf(f, "%3d) ", n);
|
| 118 |
|
|
if (tgt == initiator) {
|
| 119 |
|
|
fprintf(f, "HOST ADAPTOR\n");
|
| 120 |
|
|
continue;
|
| 121 |
|
|
}
|
| 122 |
|
|
if (!have_tgt) {
|
| 123 |
|
|
/*
|
| 124 |
|
|
* Hack: fd -> -2 means no access
|
| 125 |
|
|
*/
|
| 126 |
|
|
fprintf(f, "%c\n", scgp->fd == -2 ? '?':'*');
|
| 127 |
|
|
continue;
|
| 128 |
|
|
}
|
| 129 |
|
|
amt++;
|
| 130 |
|
|
if (low < 0)
|
| 131 |
|
|
low = n;
|
| 132 |
|
|
high = n;
|
| 133 |
|
|
|
| 134 |
|
|
getdev(scgp, FALSE);
|
| 135 |
|
|
print_product(f, scgp->inq);
|
| 136 |
|
|
}
|
| 137 |
|
|
}
|
| 138 |
|
|
scgp->silent--;
|
| 139 |
|
|
|
| 140 |
|
|
if (low < 0) {
|
| 141 |
|
|
errmsgno(EX_BAD, "No target found.\n");
|
| 142 |
|
|
return (0);
|
| 143 |
|
|
}
|
| 144 |
|
|
n = -1;
|
| 145 |
|
|
#ifdef FMT
|
| 146 |
|
|
getint("Select target", &n, low, high);
|
| 147 |
|
|
bus = n/100;
|
| 148 |
|
|
tgt = n%100;
|
| 149 |
|
|
scg_settarget(scgp, bus, tgt, lun);
|
| 150 |
|
|
return (select_unit(scgp));
|
| 151 |
|
|
|
| 152 |
|
|
scg_settarget(scgp, cscsibus, ctarget, clun);
|
| 153 |
|
|
#endif
|
| 154 |
|
|
return (amt);
|
| 155 |
|
|
}
|
| 156 |
|
|
|
| 157 |
|
|
LOCAL int
|
| 158 |
|
|
select_unit(scgp, f)
|
| 159 |
|
|
SCSI *scgp;
|
| 160 |
|
|
FILE *f;
|
| 161 |
|
|
{
|
| 162 |
|
|
int initiator;
|
| 163 |
|
|
int clun = scg_lun(scgp);
|
| 164 |
|
|
int low = -1;
|
| 165 |
|
|
int high = -1;
|
| 166 |
|
|
int lun;
|
| 167 |
|
|
|
| 168 |
|
|
scgp->silent++;
|
| 169 |
|
|
|
| 170 |
|
|
fprintf(f, "scsibus%d target %d:\n", scg_scsibus(scgp), scg_target(scgp));
|
| 171 |
|
|
|
| 172 |
|
|
initiator = scg_initiator_id(scgp);
|
| 173 |
|
|
for (lun = 0; lun < 8; lun++) {
|
| 174 |
|
|
|
| 175 |
|
|
#ifdef FMT
|
| 176 |
|
|
if (print_disknames(scg_scsibus(scgp), scg_target(scgp), lun) < 8)
|
| 177 |
|
|
fprintf(f, "\t");
|
| 178 |
|
|
else
|
| 179 |
|
|
fprintf(f, " ");
|
| 180 |
|
|
#else
|
| 181 |
|
|
fprintf(f, "\t");
|
| 182 |
|
|
#endif
|
| 183 |
|
|
if (fprintf(f, "%d,%d,%d", scg_scsibus(scgp), scg_target(scgp), lun) < 8)
|
| 184 |
|
|
fprintf(f, "\t");
|
| 185 |
|
|
else
|
| 186 |
|
|
fprintf(f, " ");
|
| 187 |
|
|
fprintf(f, "%3d) ", lun);
|
| 188 |
|
|
if (scg_target(scgp) == initiator) {
|
| 189 |
|
|
fprintf(f, "HOST ADAPTOR\n");
|
| 190 |
|
|
continue;
|
| 191 |
|
|
}
|
| 192 |
|
|
scg_settarget(scgp, scg_scsibus(scgp), scg_target(scgp), lun);
|
| 193 |
|
|
if (!unit_ready(scgp) && scgp->scmd->error == SCG_FATAL) {
|
| 194 |
|
|
fprintf(f, "*\n");
|
| 195 |
|
|
continue;
|
| 196 |
|
|
}
|
| 197 |
|
|
if (unit_ready(scgp)) {
|
| 198 |
|
|
/* non extended sense illegal lun */
|
| 199 |
|
|
if (scgp->scmd->sense.code == 0x25) {
|
| 200 |
|
|
fprintf(f, "BAD UNIT\n");
|
| 201 |
|
|
continue;
|
| 202 |
|
|
}
|
| 203 |
|
|
}
|
| 204 |
|
|
if (low < 0)
|
| 205 |
|
|
low = lun;
|
| 206 |
|
|
high = lun;
|
| 207 |
|
|
|
| 208 |
|
|
getdev(scgp, FALSE);
|
| 209 |
|
|
print_product(f, scgp->inq);
|
| 210 |
|
|
}
|
| 211 |
|
|
scgp->silent--;
|
| 212 |
|
|
|
| 213 |
|
|
if (low < 0) {
|
| 214 |
|
|
errmsgno(EX_BAD, "No lun found.\n");
|
| 215 |
|
|
return (0);
|
| 216 |
|
|
}
|
| 217 |
|
|
lun = -1;
|
| 218 |
|
|
#ifdef FMT
|
| 219 |
|
|
getint("Select lun", &lun, low, high);
|
| 220 |
|
|
scg_settarget(scgp, scg_scsibus(scgp), scg_target(scgp), lun);
|
| 221 |
|
|
format_one(scgp);
|
| 222 |
|
|
return (1);
|
| 223 |
|
|
#endif
|
| 224 |
|
|
|
| 225 |
|
|
scg_settarget(scgp, scg_scsibus(scgp), scg_target(scgp), clun);
|
| 226 |
|
|
return (1);
|
| 227 |
|
|
}
|