2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <ctype.h>
2N/A#include <libdiskstatus.h>
2N/A#include <stdarg.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A
2N/A#include "ds_impl.h"
2N/A
2N/Aboolean_t ds_debug;
2N/A
2N/A/*PRINTFLIKE1*/
2N/Avoid
2N/Adprintf(const char *fmt, ...)
2N/A{
2N/A va_list ap;
2N/A
2N/A if (!ds_debug)
2N/A return;
2N/A
2N/A va_start(ap, fmt);
2N/A (void) vprintf(fmt, ap);
2N/A va_end(ap);
2N/A}
2N/A
2N/Avoid
2N/Addump(const char *label, const void *data, size_t length)
2N/A{
2N/A int byte_count;
2N/A int i;
2N/A#define LINEBUFLEN 128
2N/A char linebuf[LINEBUFLEN];
2N/A char *linep;
2N/A int bufleft, len;
2N/A const char *start = data;
2N/A
2N/A if (!ds_debug)
2N/A return;
2N/A
2N/A if (label != NULL)
2N/A dprintf("%s\n", label);
2N/A
2N/A linep = linebuf;
2N/A bufleft = LINEBUFLEN;
2N/A
2N/A for (byte_count = 0; byte_count < length; byte_count += i) {
2N/A
2N/A (void) snprintf(linep, bufleft, "0x%08x ", byte_count);
2N/A len = strlen(linep);
2N/A bufleft -= len;
2N/A linep += len;
2N/A
2N/A /*
2N/A * Inner loop processes 16 bytes at a time, or less
2N/A * if we have less than 16 bytes to go
2N/A */
2N/A for (i = 0; (i < 16) && ((byte_count + i) < length); i++) {
2N/A (void) snprintf(linep, bufleft, "%02X", (unsigned int)
2N/A (unsigned char) start[byte_count + i]);
2N/A
2N/A len = strlen(linep);
2N/A bufleft -= len;
2N/A linep += len;
2N/A
2N/A if (bufleft >= 2) {
2N/A if (i == 7)
2N/A *linep = '-';
2N/A else
2N/A *linep = ' ';
2N/A
2N/A --bufleft;
2N/A ++linep;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * If i is less than 16, then we had less than 16 bytes
2N/A * written to the output. We need to fixup the alignment
2N/A * to allow the "text" output to be aligned
2N/A */
2N/A if (i < 16) {
2N/A int numspaces = (16 - i) * 3;
2N/A while (numspaces-- > 0) {
2N/A if (bufleft >= 2) {
2N/A *linep = ' ';
2N/A --bufleft;
2N/A linep++;
2N/A }
2N/A }
2N/A }
2N/A
2N/A if (bufleft >= 2) {
2N/A *linep = ' ';
2N/A --bufleft;
2N/A ++linep;
2N/A }
2N/A
2N/A for (i = 0; (i < 16) && ((byte_count + i) < length); i++) {
2N/A int subscript = byte_count + i;
2N/A char ch = (isprint(start[subscript]) ?
2N/A start[subscript] : '.');
2N/A
2N/A if (bufleft >= 2) {
2N/A *linep = ch;
2N/A --bufleft;
2N/A ++linep;
2N/A }
2N/A }
2N/A
2N/A linebuf[LINEBUFLEN - bufleft] = 0;
2N/A
2N/A dprintf("%s\n", linebuf);
2N/A
2N/A linep = linebuf;
2N/A bufleft = LINEBUFLEN;
2N/A }
2N/A
2N/A}
2N/A
2N/Aconst char *
2N/Adisk_status_errmsg(int error)
2N/A{
2N/A switch (error) {
2N/A case EDS_NOMEM:
2N/A return ("memory allocation failure");
2N/A case EDS_CANT_OPEN:
2N/A return ("failed to open device");
2N/A case EDS_NO_TRANSPORT:
2N/A return ("no supported communication protocol");
2N/A case EDS_NOT_SUPPORTED:
2N/A return ("disk status information not supported");
2N/A case EDS_NOT_SIMULATOR:
2N/A return ("not a valid simulator file");
2N/A case EDS_IO:
2N/A return ("I/O error from device");
2N/A default:
2N/A return ("unknown error");
2N/A }
2N/A}
2N/A
2N/Aint
2N/Ads_set_errno(disk_status_t *dsp, int error)
2N/A{
2N/A dsp->ds_error = error;
2N/A return (-1);
2N/A}