fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
f645cd15cd9c30aa3b568ad85bd8a63996112c4bMilan Jurik * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/param.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <assert.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/impl/uscsi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/commands.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/impl/commands.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/sense.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/mode.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/status.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/inquiry.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/adapters/scsi_vhci.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/byteorder.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "common.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "errorcodes.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_MODE_SENSE_LEN 0xffff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAXLEN 1000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define RETRY_PATHLIST 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define BYTES_PER_LINE 16
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCMD_UNKNOWN 0xff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_VHCI "/devices/scsi_vhci/"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SLASH "/"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEV_PREFIX "/devices/"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEV_PREFIX_STRLEN strlen(DEV_PREFIX)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DEVICES_DIR "/devices"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern char *dtype[]; /* from adm.c */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int rand_r(unsigned int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int cleanup_dotdot_path(char *path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int wait_random_time(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *scsi_find_command_name(int cmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void scsi_printerr(struct uscsi_cmd *ucmd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_extended_sense *rq, int rqlen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char msg_string[], char *err_string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void string_dump(char *hdr, uchar_t *src, int nbytes, int format,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char msg_string[]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int issue_uscsi_cmd(int file, struct uscsi_cmd *command, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewait_random_time(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik time_t timeval;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct tm *tmbuf = NULL;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct timeval tval;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik unsigned int seed;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int random;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik pid_t pid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the system time and use "system seconds"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as 'seed' to generate a random number. Then,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait between 1/10 - 1/2 seconds before retry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the current process id and ex-or it with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the seed so that the random number is always
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * different even in case of multiple processes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * generate a random number at the same time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((timeval = time(NULL)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tmbuf = localtime(&timeval)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1); /* L_LOCALTIME_ERROR */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pid = getpid();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get a random number. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte seed = (unsigned int) tmbuf->tm_sec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte seed ^= pid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte random = rand_r(&seed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte random = ((random % 500) + 100) * MILLISEC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tval.tv_sec = random / MICROSEC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tval.tv_usec = random % MICROSEC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (select(0, NULL, NULL, NULL, &tval) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1); /* L_SELECT_ERROR */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Special string dump for error message
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestring_dump(char *hdr, uchar_t *src, int nbytes, int format, char msg_string[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char s[256];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte assert(format == HEX_ONLY || format == HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(s, hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = s; *p; p++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p = ' ';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = hdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nbytes > 0) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) sprintf(&msg_string[strlen(msg_string)], "%s", p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = MIN(nbytes, BYTES_PER_LINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "%02x ", src[i] & 0xff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (format == HEX_ASCII) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = BYTES_PER_LINE-n; i > 0; i--) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "%c", isprint(src[i]) ? src[i] : '.');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)], "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nbytes -= n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte src += n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return a pointer to a string telling us the name of the command.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortescsi_find_command_name(int cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /*
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * Names of commands. Must have SCMD_UNKNOWN at end of list.
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct scsi_command_name {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int command;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik char *name;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } scsi_command_names[29];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik register struct scsi_command_name *c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[0].command = SCMD_TEST_UNIT_READY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[0].name = MSGSTR(61, "Test Unit Ready");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[1].command = SCMD_FORMAT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[1].name = MSGSTR(110, "Format");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[2].command = SCMD_REASSIGN_BLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[2].name = MSGSTR(77, "Reassign Block");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[3].command = SCMD_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[3].name = MSGSTR(27, "Read");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[4].command = SCMD_WRITE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[4].name = MSGSTR(54, "Write");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[5].command = SCMD_READ_G1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[5].name = MSGSTR(79, "Read(10 Byte)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[6].command = SCMD_WRITE_G1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[6].name = MSGSTR(51, "Write(10 Byte)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[7].command = SCMD_MODE_SELECT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[7].name = MSGSTR(97, "Mode Select");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[8].command = SCMD_MODE_SENSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[8].name = MSGSTR(95, "Mode Sense");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[9].command = SCMD_REASSIGN_BLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[9].name = MSGSTR(77, "Reassign Block");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[10].command = SCMD_REQUEST_SENSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[10].name = MSGSTR(74, "Request Sense");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[11].command = SCMD_READ_DEFECT_LIST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[11].name = MSGSTR(80, "Read Defect List");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[12].command = SCMD_INQUIRY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[12].name = MSGSTR(102, "Inquiry");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[13].command = SCMD_WRITE_BUFFER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[13].name = MSGSTR(53, "Write Buffer");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[14].command = SCMD_READ_BUFFER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[14].name = MSGSTR(82, "Read Buffer");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[15].command = SCMD_START_STOP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[15].name = MSGSTR(67, "Start/Stop");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[16].command = SCMD_RESERVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[16].name = MSGSTR(72, "Reserve");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[17].command = SCMD_RELEASE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[17].name = MSGSTR(75, "Release");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[18].command = SCMD_MODE_SENSE_G1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[18].name = MSGSTR(94, "Mode Sense(10 Byte)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[19].command = SCMD_MODE_SELECT_G1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[19].name = MSGSTR(96, "Mode Select(10 Byte)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[20].command = SCMD_READ_CAPACITY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[20].name = MSGSTR(81, "Read Capacity");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[21].command = SCMD_SYNC_CACHE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[21].name = MSGSTR(64, "Synchronize Cache");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[22].command = SCMD_READ_DEFECT_LIST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[22].name = MSGSTR(80, "Read Defect List");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[23].command = SCMD_GDIAG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[23].name = MSGSTR(108, "Get Diagnostic");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[24].command = SCMD_SDIAG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[24].name = MSGSTR(69, "Set Diagnostic");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[25].command = SCMD_PERS_RESERV_IN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[25].name = MSGSTR(10500, "Persistent Reserve In");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[26].command = SCMD_PERS_RESERV_OUT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[26].name = MSGSTR(10501, "Persistent Reserve out");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[27].command = SCMD_LOG_SENSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[27].name = MSGSTR(10502, "Log Sense");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[28].command = SCMD_UNKNOWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_command_names[28].name = MSGSTR(25, "Unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (c = scsi_command_names; c->command != SCMD_UNKNOWN; c++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (c->command == cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (c->name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Function to create error message containing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * scsi request sense information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortescsi_printerr(struct uscsi_cmd *ucmd, struct scsi_extended_sense *rq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rqlen, char msg_string[], char *err_string)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int blkno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (rq->es_key) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_NO_SENSE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(91, "No sense error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_RECOVERABLE_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(76, "Recoverable error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_NOT_READY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(10503,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "Device Not ready. Error: Random Retry Failed: %s\n."),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik err_string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_MEDIUM_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(99, "Medium error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_HARDWARE_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(106, "Hardware error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_ILLEGAL_REQUEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(103, "Illegal request"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_UNIT_ATTENTION:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(10504,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "Unit attention."
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "Error: Random Retry Failed.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_WRITE_PROTECT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(52, "Write protect error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_BLANK_CHECK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(131, "Blank check error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_VENDOR_UNIQUE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(58, "Vendor unique error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_COPY_ABORTED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(123, "Copy aborted error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_ABORTED_COMMAND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(10505,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "Aborted command. Error: Random Retry Failed.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_EQUAL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(117, "Equal error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_VOLUME_OVERFLOW:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(57, "Volume overflow"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_MISCOMPARE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(98, "Miscompare error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_RESERVED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(10506,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "Reserved value found"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(msg_string, MSGSTR(59, "Unknown error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(10507, " during: %s"),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik scsi_find_command_name(ucmd->uscsi_cdb[0]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rq->es_valid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte blkno = (rq->es_info_1 << 24) | (rq->es_info_2 << 16) |
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (rq->es_info_3 << 8) | rq->es_info_4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(49, ": block %d (0x%x)"), blkno, blkno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)], "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rq->es_add_len >= 6) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(&msg_string[strlen(msg_string)],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(132, " Additional sense: 0x%x "
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "ASC Qualifier: 0x%x\n"),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik rq->es_add_code, rq->es_qual_code);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /*
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * rq->es_add_info[ADD_SENSE_CODE],
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * rq->es_add_info[ADD_SENSE_QUAL_CODE]);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rq->es_key == KEY_ILLEGAL_REQUEST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string_dump(MSGSTR(47, " cmd: "), (uchar_t *)ucmd,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik sizeof (struct uscsi_cmd), HEX_ONLY, msg_string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string_dump(MSGSTR(48, " cdb: "),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (uchar_t *)ucmd->uscsi_cdb,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik ucmd->uscsi_cdblen, HEX_ONLY, msg_string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string_dump(MSGSTR(43, " sense: "),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (uchar_t *)rq, 8 + rq->es_add_len, HEX_ONLY, msg_string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rqlen = rqlen; /* not used */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Execute a command and determine the result.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteissue_uscsi_cmd(int file, struct uscsi_cmd *command, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct scsi_extended_sense *rqbuf;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int status, i, retry_cnt = 0, err;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik char errorMsg[MAXLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set function flags for driver.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set Automatic request sense enable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_flags = USCSI_RQENABLE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_flags |= flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* intialize error message array */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errorMsg[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* print command for debug */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_S_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_cdb == NULL) ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (flag & USCSI_RESET) ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (flag & USCSI_RESET_ALL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & USCSI_RESET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" Issuing a SCSI Reset.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & USCSI_RESET_ALL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" Issuing a SCSI Reset All.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" Issuing the following "
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "SCSI command: %s\n",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik scsi_find_command_name(command->uscsi_cdb[0]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" fd=0x%x cdb=", file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < (int)command->uscsi_cdblen; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("%x ", *(command->uscsi_cdb + i));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("\n\tlen=0x%x bufaddr=0x%x buflen=0x%x"
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " flags=0x%x\n",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik command->uscsi_cdblen,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik command->uscsi_bufaddr,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik command->uscsi_buflen, command->uscsi_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_buflen > 0) &&
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik ((flag & USCSI_READ) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) dump_hex_data(" Buffer data: ",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (uchar_t *)command->uscsi_bufaddr,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MIN(command->uscsi_buflen, 512), HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fflush(stdout);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Default command timeout in case command left it 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (command->uscsi_timeout == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte command->uscsi_timeout = 60;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Issue command - finally */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = ioctl(file, USCSICMD, command);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == 0 && command->uscsi_status == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_S_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_buflen > 0) &&
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (flag & USCSI_READ)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) dump_hex_data("\tData read:",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (uchar_t *)command->uscsi_bufaddr,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MIN(command->uscsi_buflen, 512), HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status != 0) && (command->uscsi_status == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((getenv("_LUX_S_DEBUG") != NULL) ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (getenv("_LUX_ER_DEBUG") != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("Unexpected USCSICMD ioctl error: %s\n",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just a SCSI error, create error message
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retry once for Unit Attention,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Not Ready, and Aborted Command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((command->uscsi_rqbuf != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((char)command->uscsi_rqlen - (char)command->uscsi_rqresid) > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rqbuf = (struct scsi_extended_sense *)command->uscsi_rqbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (rqbuf->es_key) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_NOT_READY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF("Note: Device Not Ready."
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_UNIT_ATTENTION:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF(" cmd():"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " UNIT_ATTENTION: Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_ABORTED_COMMAND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ER_DPRINTF("Note: Command is aborted."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((getenv("_LUX_S_DEBUG") != NULL) ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (getenv("_LUX_ER_DEBUG") != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_printerr(command,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (struct scsi_extended_sense *)command->uscsi_rqbuf,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (command->uscsi_rqlen - command->uscsi_rqresid),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik errorMsg, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retry 5 times in case of BUSY, and only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * once for Reservation-conflict, Command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Termination and Queue Full. Wait for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * random amount of time (between 1/10 - 1/2 secs.)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * between each retry. This random wait is to avoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the multiple threads being executed at the same time
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and also the constraint in Photon IB, where the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * command queue has a depth of one command.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch ((uchar_t)command->uscsi_status & STATUS_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF(" cmd(): No. of retries %d."
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " STATUS_BUSY: Retrying...\n",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik retry_cnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_RESERVATION_CONFLICT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF(" cmd():"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " RESERVATION_CONFLICT:"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_TERMINATED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF("Note: Command Terminated."
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STATUS_QFULL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry_cnt++ < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte R_DPRINTF("Note: Command Queue is full."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Retrying...\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((err = wait_random_time()) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((getenv("_LUX_S_DEBUG") != NULL) ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (getenv("_LUX_ER_DEBUG") != NULL)) &&
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (errorMsg[0] != '\0')) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " %s\n", errorMsg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_SCSI_ERROR | command->uscsi_status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MODE SENSE USCSI command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pc = page control field
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * page_code = Pages to return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortescsi_mode_sense_cmd(int fd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *buf_ptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int buf_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t pc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t page_code)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct uscsi_cmd ucmd;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /* 10 byte Mode Select cmd */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik union scsi_cdb cdb = {SCMD_MODE_SENSE_G1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct scsi_extended_sense sense;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int status;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik static int uscsi_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd < 0) || (buf_ptr == NULL) || (buf_len < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1); /* L_INVALID_ARG */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset(buf_ptr, 0, buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&ucmd, 0, sizeof (ucmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Just for me - a sanity check */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((page_code > MODEPAGE_ALLPAGES) || (pc > 3) ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (buf_len > MAX_MODE_SENSE_LEN)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1); /* L_ILLEGAL_MODE_SENSE_PAGE */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb.g1_addr3 = (pc << 6) + page_code;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb.g1_count1 = buf_len>>8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb.g1_count0 = buf_len & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (caddr_t)&cdb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = (caddr_t)buf_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = buf_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqbuf = (caddr_t)&sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = 120;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = issue_uscsi_cmd(fd, &ucmd, USCSI_READ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Bytes actually transfered */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uscsi_count = buf_len - ucmd.uscsi_resid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte S_DPRINTF(" Number of bytes read on "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Mode Sense 0x%x\n", uscsi_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_D_DEBUG") != NULL) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) dump_hex_data(" Mode Sense data: ", buf_ptr,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik uscsi_count, HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortescsi_release(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct uscsi_cmd ucmd;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik union scsi_cdb cdb = {SCMD_RELEASE, 0, 0, 0, 0, 0};
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct scsi_extended_sense sense;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int fd, status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" scsi_release: Release: Path %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(path, O_NDELAY | O_RDONLY)) == -1)
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&ucmd, 0, sizeof (ucmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (caddr_t)&cdb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqbuf = (caddr_t)&sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = 60;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = (issue_uscsi_cmd(fd, &ucmd, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortescsi_reserve(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct uscsi_cmd ucmd;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik union scsi_cdb cdb = {SCMD_RESERVE, 0, 0, 0, 0, 0};
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct scsi_extended_sense sense;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int fd, status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF(" scsi_reserve: Reserve: Path %s\n", path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(path, O_NDELAY | O_RDONLY)) == -1)
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&ucmd, 0, sizeof (ucmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (caddr_t)&cdb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqbuf = (caddr_t)&sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_rqlen = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = 60;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = (issue_uscsi_cmd(fd, &ucmd, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print out fabric dev dtype
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_fabric_dtype_prop(uchar_t *hba_port_wwn, uchar_t *port_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t dtype_prop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dtype_prop & DTYPE_MASK) < 0x10) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " 0x%-2x (%s)\n",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (dtype_prop & DTYPE_MASK),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik dtype[(dtype_prop & DTYPE_MASK)]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((dtype_prop & DTYPE_MASK) < 0x1f) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2096, " 0x%-2x (Reserved)\n"),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (dtype_prop & DTYPE_MASK));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if this is the HBA */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwnConversion(hba_port_wwn) != wwnConversion(port_wwn)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(2097,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " 0x%-2x (Unknown Type)\n"),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (dtype_prop & DTYPE_MASK));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* MATCH */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(2241,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " 0x%-2x (Unknown Type,Host Bus Adapter)\n"),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (dtype_prop & DTYPE_MASK));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_inq_data(char *arg_path, char *path, L_inquiry inq, uchar_t *serial,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t serial_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik char **p;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik uchar_t *v_parm;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int scsi_3, length;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik char byte_number[MAXNAMELEN];
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik static char *scsi_inquiry_labels_2[21];
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik static char *scsi_inquiry_labels_3[22];
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik#define MAX_ANSI_VERSION 6
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik static char *ansi_version[MAX_ANSI_VERSION];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Intialize scsi_inquiry_labels_2 with i18n strings
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[0] = MSGSTR(138, "Vendor: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[1] = MSGSTR(149, "Product: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[2] = MSGSTR(139, "Revision: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[3] = MSGSTR(143, "Firmware Revision ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[4] = MSGSTR(144, "Serial Number ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[5] = MSGSTR(140, "Device type: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[6] = MSGSTR(145, "Removable media: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[7] = MSGSTR(146, "ISO version: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[8] = MSGSTR(147, "ECMA version: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[9] = MSGSTR(148, "ANSI version: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[10] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2168, "Async event notification: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[11] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2169, "Terminate i/o process msg: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[12] = MSGSTR(150, "Response data format: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[13] = MSGSTR(151, "Additional length: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[14] = MSGSTR(152, "Relative addressing: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[15] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2170, "32 bit transfers: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[16] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2171, "16 bit transfers: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[17] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2172, "Synchronous transfers: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[18] = MSGSTR(153, "Linked commands: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[19] = MSGSTR(154, "Command queueing: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_2[20] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2173, "Soft reset option: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Intialize scsi_inquiry_labels_3 with i18n strings
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[0] = MSGSTR(138, "Vendor: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[1] = MSGSTR(149, "Product: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[2] = MSGSTR(139, "Revision: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[3] = MSGSTR(143, "Firmware Revision ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[4] = MSGSTR(144, "Serial Number ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[5] = MSGSTR(140, "Device type: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[6] = MSGSTR(145, "Removable media: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[7] = MSGSTR(2174, "Medium Changer Element: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[8] = MSGSTR(146, "ISO version: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[9] = MSGSTR(147, "ECMA version: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[10] = MSGSTR(148, "ANSI version: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[11] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2175, "Async event reporting: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[12] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2176, "Terminate task: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[13] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2177, "Normal ACA Supported: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[14] = MSGSTR(150, "Response data format: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[15] = MSGSTR(151, "Additional length: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[16] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2178, "Cmd received on port: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[17] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2179, "SIP Bits: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[18] = MSGSTR(152, "Relative addressing: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[19] = MSGSTR(153, "Linked commands: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[20] =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2180, "Transfer Disable: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inquiry_labels_3[21] = MSGSTR(154, "Command queueing: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Intialize scsi_inquiry_labels_3 with i18n strings
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ansi_version[0] = MSGSTR(2181,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " (Device might or might not comply to an ANSI version)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ansi_version[1] = MSGSTR(2182,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " (This code is reserved for historical uses)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ansi_version[2] = MSGSTR(2183,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " (Device complies to ANSI X3.131-1994 (SCSI-2))");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ansi_version[3] = MSGSTR(2184,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " (Device complies to ANSI INCITS 301-1997 (SPC))");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik ansi_version[4] = MSGSTR(2226,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " (Device complies to ANSI INCITS 351-2001 (SPC-2))");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik ansi_version[5] = MSGSTR(2227,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " (Device complies to ANSI INCITS 408-2005 (SPC-3))");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /* print inquiry information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, MSGSTR(2185, "\nINQUIRY:\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * arg_path is the path sent to luxadm by the user. if arg_path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is a /devices path, then we do not need to print out physical
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * path info
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (strcmp(arg_path, path) != 0 &&
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik strstr(arg_path, "/devices/") == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(5, "Physical Path:"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n %s\n", path);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_ansi < 3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = scsi_inquiry_labels_2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_3 = 0;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = scsi_inquiry_labels_3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_3 = 1;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_len < 11) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p += 1;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_chars(inq.inq_vid, sizeof (inq.inq_vid), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_len < 27) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p += 1;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_chars(inq.inq_pid, sizeof (inq.inq_pid), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_len < 31) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p += 1;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_chars(inq.inq_revision, sizeof (inq.inq_revision), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_len < 39) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p += 2;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If Pluto then print
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * firmware rev & serial #.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr((char *)inq.inq_pid, "SSA") != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_chars(inq.inq_firmware_rev,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik sizeof (inq.inq_firmware_rev), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_chars(serial, serial_len, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((inq.inq_dtype & DTYPE_MASK) != DTYPE_ESI) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_chars(serial, serial_len, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if we miss both the above if's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p += 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s0x%x (", *p++, (inq.inq_dtype & DTYPE_MASK));
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if ((inq.inq_dtype & DTYPE_MASK) < 0x10) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", dtype[inq.inq_dtype & DTYPE_MASK]);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else if ((inq.inq_dtype & DTYPE_MASK) < 0x1f) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(71, "Reserved"));
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(2186, "Unknown device"));
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, ")\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s", *p++);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_rmb != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(45, "no"));
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (scsi_3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (inq.inq_mchngr != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(45, "no"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s%d\n", *p++, inq.inq_iso);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s%d\n", *p++, inq.inq_ecma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s%d", *p++, inq.inq_ansi);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_ansi < MAX_ANSI_VERSION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", ansi_version[inq.inq_ansi]);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else
f645cd15cd9c30aa3b568ad85bd8a63996112c4bMilan Jurik (void) fprintf(stdout, " (%s)", MSGSTR(71, "Reserved"));
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_aenc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p++;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (scsi_3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (inq.inq_normaca != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(45, "no"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_trmiop) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p++;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s%d\n", *p++, inq.inq_rdf);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s0x%x\n", *p++, inq.inq_len);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (scsi_3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (inq.inq_dual_p) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (inq.inq_port != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(2187,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "%sa\n"), *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(2188,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "%sb\n"), *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (scsi_3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (inq.inq_SIP_1 || inq.ui.inq_3.inq_SIP_2 ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik inq.ui.inq_3.inq_SIP_3) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, "%s%d, %d, %d\n", *p,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik inq.inq_SIP_1, inq.ui.inq_3.inq_SIP_2,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik inq.ui.inq_3.inq_SIP_3);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.ui.inq_2.inq_2_reladdr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (!scsi_3) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.ui.inq_2.inq_wbus32) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.ui.inq_2.inq_wbus16) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.ui.inq_2.inq_sync) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.ui.inq_2.inq_linked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (scsi_3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (inq.ui.inq_3.inq_trandis != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(45, "no"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.ui.inq_2.inq_cmdque) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (!scsi_3) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.ui.inq_2.inq_sftre) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(40, "yes"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /*
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * Now print the vendor-specific data.
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik v_parm = inq.inq_ven_specific_1;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (inq.inq_len >= 32) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte length = inq.inq_len - 31;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr((char *)inq.inq_pid, "SSA") != 0) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) fprintf(stdout, MSGSTR(2189,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "Number of Ports, Targets: %d,%d\n"),
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik inq.inq_ssa_ports, inq.inq_ssa_tgts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v_parm += 20;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte length -= 20;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((strstr((char *)inq.inq_pid, "SUN") != 0) ||
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (strncmp((char *)inq.inq_vid, "SUN ",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik sizeof (inq.inq_vid)) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v_parm += 16;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte length -= 16;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do hex Dump of rest of the data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (length > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2190,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " VENDOR-SPECIFIC PARAMETERS\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MSGSTR(2191,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "Byte# Hex Value "
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik " ASCII\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(byte_number,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik "%d ", inq.inq_len - length + 5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dump_hex_data(byte_number, v_parm,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MIN(length, inq.inq_res3 - v_parm), HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Skip reserved bytes 56-95.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte length -= (inq.inq_box_name - v_parm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (length > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(byte_number, "%d ",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik inq.inq_len - length + 5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dump_hex_data(byte_number, inq.inq_box_name,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MIN(length, sizeof (inq.inq_box_name) +
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik sizeof (inq.inq_avu)), HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (getenv("_LUX_D_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dump_hex_data("\nComplete Inquiry: ",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (uchar_t *)&inq,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik MIN(inq.inq_len + 5, sizeof (inq)), HEX_ASCII);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Internal routine to clean up ../'s in paths.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns 0 if no "../" are left.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wouldn't it be nice if there was a standard system library
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * routine to do this...?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecleanup_dotdot_path(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char holder[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *dotdot;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *previous_slash;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Find the first "/../" in the string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dotdot = strstr(path, "/../");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dotdot == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the [0] character is '/' and "../" immediatly
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * follows it, then we can strip the ../
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /../../foo/bar == /foo/bar
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dotdot == path) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(holder, &path[3]); /* strip "/.." */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(path, holder);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now look for the LAST "/" before the "/../"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as this is the parent dir we can get rid of.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We do this by temporarily truncating the string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * at the '/' just before "../" using the dotdot pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dotdot = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte previous_slash = strrchr(path, '/');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (previous_slash == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hmm, somethings wrong. path looks something
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * like "foo/../bar/" so we can't really deal with it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now truncate the path just after the previous '/'
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and slam everything after the "../" back on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(previous_slash+1) = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(path, dotdot+4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* We may have more "../"s */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Follow symbolic links from the logical device name to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the /devfs physical device name. To be complete, we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle the case of multiple links. This function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * either returns NULL (no links, or some other error),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or the physical device name, alloc'ed on the heap.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: If the path is relative, it will be forced into
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an absolute path by pre-pending the pwd to it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_slash_devices_from_osDevName(char *osDevName, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat stbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char source[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char scratch[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char pwd[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *tmp, *phys_path;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t is_lstat_failed = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return NULL if path is NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (osDevName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(source, osDevName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First make sure the path is absolute. If not, make it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If it's already an absolute path, we have no need
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to determine the cwd, so the program should still
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * function within security-by-obscurity directories.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (source[0] != '/') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp = getcwd(pwd, MAXPATHLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Handle special case of "./foo/bar"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (source[0] == '.' && source[1] == '/') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(scratch, source+2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* no "./" so just take everything */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(scratch, source);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(source, pwd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(source, "/");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(source, scratch);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clean up any "../"s that are in the path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik while (cleanup_dotdot_path(source))
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * source is now an absolute path to the link we're
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * concerned with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag == NOT_IGNORE_DANGLING_LINK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In order not to ingore dangling links, check
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the lstat. If lstat succeeds, return the path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from readlink.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: osDevName input with /devices path from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a dangling /dev link doesn't pass lstat so
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL is returned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (stat(source, &stbuf) == -1) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (!is_lstat_failed &&
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik strstr(source, "/devices")) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /*
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * lstat succeeded previously and source
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * contains "/devices" then it is
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * dangling node.
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik phys_path = (char *)calloc(1,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik strlen(source) + 1);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (phys_path != NULL) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) strncpy(phys_path,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik source, strlen(source) + 1);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (phys_path);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else if (is_lstat_failed) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /* check lstat result. */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (lstat(source, &stbuf) == -1) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (NULL);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /* and continue */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik is_lstat_failed = B_FALSE;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik } else {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /*
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * With algorithm that resolves a link
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * and then issues readlink(), should
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * not be reached here.
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (NULL);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (lstat(source, &stbuf) == -1) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /*
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * when stat succeeds it is not
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * a dangling node so it is not
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik * a special case.
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (NULL);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (flag == STANDARD_DEVNAME_HANDLING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See if there's a real file out there. If not,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we have a dangling link and we ignore it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (stat(source, &stbuf) == -1) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (NULL);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (lstat(source, &stbuf) == -1) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (NULL);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik /* invalid flag */
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the file is not a link, we're done one
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * way or the other. If there were links,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return the full pathname of the resulting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: All of our temp's are on the stack,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so we have to copy the final result to the heap.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!S_ISLNK(stbuf.st_mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte phys_path = (char *)calloc(1, strlen(source) + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (phys_path != NULL) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) strncpy(phys_path, source,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik strlen(source) + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (phys_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnt = readlink(source, scratch, sizeof (scratch));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cnt < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * scratch is on the heap, and for some reason readlink
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * doesn't always terminate things properly so we have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to make certain we're properly terminated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scratch[cnt] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now check to see if the link is relative. If so,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then we have to append it to the directory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which the source was in. (This is non trivial)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scratch[0] != '/') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp = strrchr(source, '/');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmp == NULL) { /* Whoa! Something's hosed! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte O_DPRINTF("Internal error... corrupt path.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now strip off just the directory path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(tmp+1) = '\0'; /* Keeping the last '/' */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* and append the new link */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(source, scratch);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: At this point, source should have "../"s
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but we'll clean it up in the next pass through
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the loop.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* It's an absolute link so no worries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(source, scratch);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Never reach here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input - Space for client_path, phci_path and paddr fields of ioc structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to be allocated by the caller of this routine.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_scsi_vhci_pathinfo(char *dev_path, sv_iocdata_t *ioc, int *path_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *physical_path, *physical_path_s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int initial_path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int current_path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *delimiter;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int malloc_error = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int prop_buf_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pathlist_retry_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik if (strncmp(dev_path, SCSI_VHCI, strlen(SCSI_VHCI)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((physical_path = get_slash_devices_from_osDevName(
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik dev_path, STANDARD_DEVNAME_HANDLING)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(physical_path, SCSI_VHCI,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik strlen(SCSI_VHCI)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((physical_path = calloc(1, MAXPATHLEN)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(physical_path, dev_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte physical_path_s = physical_path;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* move beyond "/devices" prefix */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte physical_path += DEV_PREFIX_STRLEN-1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove :c,raw suffix */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delimiter = strrchr(physical_path, ':');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if we didn't find the ':' fine, else truncate */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (delimiter != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *delimiter = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We'll call ioctl SCSI_VHCI_GET_CLIENT_MULTIPATH_INFO
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * at least twice. The first time will get the path count
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and the size of the ioctl propoerty buffer. The second
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * time will get the path_info for each path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It's possible that additional paths are added while this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * code is running. If the path count increases between the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2 ioctl's above, then we'll retry (and assume all is well).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(ioc->client, physical_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioc->buf_elem = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioc->ret_elem = (uint_t *)&(initial_path_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioc->ret_buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free physical path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(physical_path_s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 0 buf_size asks driver to return actual size needed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open the ioctl file descriptor */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open("/devices/scsi_vhci:devctl", O_RDWR)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_OPEN_PATH_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval = ioctl(fd, SCSI_VHCI_GET_CLIENT_MULTIPATH_INFO, ioc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retval != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (L_SCSI_VHCI_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prop_buf_size = SV_PROP_MAX_BUF_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (pathlist_retry_count <= RETRY_PATHLIST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioc->buf_elem = initial_path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Make driver put actual # paths in variable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioc->ret_elem = (uint_t *)&(current_path_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate space for array of path_info structures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate enough space for # paths from get_pathcount
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioc->ret_buf = (sv_path_info_t *)
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik calloc(initial_path_count, sizeof (sv_path_info_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioc->ret_buf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate space for path properties returned by driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte malloc_error = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < initial_path_count; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioc->ret_buf[i].ret_prop.buf_size = prop_buf_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ioc->ret_buf[i].ret_prop.buf =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (caddr_t)malloc(prop_buf_size)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte malloc_error = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ioc->ret_buf[i].ret_prop.ret_buf_size =
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (uint_t *)malloc(sizeof (uint_t))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte malloc_error = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (malloc_error == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < initial_path_count; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ioc->ret_buf[i].ret_prop.buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ioc->ret_buf[i].ret_prop.ret_buf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ioc->ret_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval = ioctl(fd, SCSI_VHCI_GET_CLIENT_MULTIPATH_INFO, ioc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retval != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < initial_path_count; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ioc->ret_buf[i].ret_prop.buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ioc->ret_buf[i].ret_prop.ret_buf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ioc->ret_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_SCSI_VHCI_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_path_count < current_path_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* then a new path was added */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathlist_retry_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte initial_path_count = current_path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we are done with ioctl's, lose the fd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Compare the length num elements from the ioctl response
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and the caller's request - use smaller value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pathlist_p->path_count now has count returned from ioctl.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ioc.buf_elem has the value the caller provided.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_path_count < current_path_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* More paths exist than we allocated space for */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *path_count = initial_path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *path_count = current_path_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_mode_page(char *path, uchar_t **pg_buf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik struct mode_header_g1 *mode_header_ptr;
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik int status, size, fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* open controller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(path, O_NDELAY | O_RDWR)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1); /* L_OPEN_PATH_FAIL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Read the first part of the page to get the page size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = 20;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*pg_buf = (uchar_t *)calloc(1, size)) == NULL) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) close(fd);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* read page */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status = scsi_mode_sense_cmd(fd, *pg_buf, size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, MODEPAGE_ALLPAGES)) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) close(fd);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) free(*pg_buf);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now get the size for all pages */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode_header_ptr = (struct mode_header_g1 *)(void *)*pg_buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = ntohs(mode_header_ptr->length) +
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik sizeof (mode_header_ptr->length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(*pg_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*pg_buf = (uchar_t *)calloc(1, size)) == NULL) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) close(fd);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (L_MALLOC_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* read all pages */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status = scsi_mode_sense_cmd(fd, *pg_buf, size,
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik 0, MODEPAGE_ALLPAGES)) {
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) close(fd);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik (void) free(*pg_buf);
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Dump a structure in hexadecimal.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedump_hex_data(char *hdr, uchar_t *src, int nbytes, int format)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char s[256];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte assert(format == HEX_ONLY || format == HEX_ASCII);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(s, hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = s; *p; p++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p = ' ';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = hdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nbytes > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%s", p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = MIN(nbytes, BYTES_PER_LINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%02x ", src[i] & 0xff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (format == HEX_ASCII) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = BYTES_PER_LINE-n; i > 0; i--) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "%c",
fc23152c0568d631ad6c47a2537542c6c8fab02cMilan Jurik isprint(src[i]) ? src[i] : '.');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nbytes -= n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte src += n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}