4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <libdiskstatus.h>
40 dprintf(const char *fmt
, ...)
48 (void) vprintf(fmt
, ap
);
53 ddump(const char *label
, const void *data
, size_t length
)
57 #define LINEBUFLEN 128
58 char linebuf
[LINEBUFLEN
];
61 const char *start
= data
;
67 dprintf("%s\n", label
);
72 for (byte_count
= 0; byte_count
< length
; byte_count
+= i
) {
74 (void) snprintf(linep
, bufleft
, "0x%08x ", byte_count
);
80 * Inner loop processes 16 bytes at a time, or less
81 * if we have less than 16 bytes to go
83 for (i
= 0; (i
< 16) && ((byte_count
+ i
) < length
); i
++) {
84 (void) snprintf(linep
, bufleft
, "%02X", (unsigned int)
85 (unsigned char) start
[byte_count
+ i
]);
103 * If i is less than 16, then we had less than 16 bytes
104 * written to the output. We need to fixup the alignment
105 * to allow the "text" output to be aligned
108 int numspaces
= (16 - i
) * 3;
109 while (numspaces
-- > 0) {
124 for (i
= 0; (i
< 16) && ((byte_count
+ i
) < length
); i
++) {
125 int subscript
= byte_count
+ i
;
126 char ch
= (isprint(start
[subscript
]) ?
127 start
[subscript
] : '.');
136 linebuf
[LINEBUFLEN
- bufleft
] = 0;
138 dprintf("%s\n", linebuf
);
141 bufleft
= LINEBUFLEN
;
147 disk_status_errmsg(int error
)
151 return ("memory allocation failure");
153 return ("failed to open device");
154 case EDS_NO_TRANSPORT
:
155 return ("no supported communication protocol");
156 case EDS_NOT_SUPPORTED
:
157 return ("disk status information not supported");
158 case EDS_NOT_SIMULATOR
:
159 return ("not a valid simulator file");
161 return ("I/O error from device");
163 return ("unknown error");
168 ds_set_errno(disk_status_t
*dsp
, int error
)
170 dsp
->ds_error
= error
;