adds a couple print_vmcb()s for the write CR0 -> shutdown bug
[freebsd-src/fkvm-freebsd.git] / sbin / camcontrol / util.c
blob67f4e4f0cd157c379d233d9c96e15c2da5155b38
1 /*
2 * Written By Julian ELischer
3 * Copyright julian Elischer 1993.
4 * Permission is granted to use or redistribute this file in any way as long
5 * as this notice remains. Julian Elischer does not guarantee that this file
6 * is totally correct for any given task and users of this file must
7 * accept responsibility for any damage that occurs from the application of this
8 * file.
10 * (julian@tfs.com julian@dialix.oz.au)
12 * User SCSI hooks added by Peter Dufault:
14 * Copyright (c) 1994 HD Associates
15 * (contact: dufault@hda.com)
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. The name of HD Associates
27 * may not be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
43 * Taken from the original scsi(8) program.
44 * from: scsi.c,v 1.17 1998/01/12 07:57:57 charnier Exp $";
46 #include <sys/cdefs.h>
47 __FBSDID("$FreeBSD$");
49 #include <sys/stdint.h>
50 #include <sys/types.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <string.h>
56 #include <camlib.h>
57 #include "camcontrol.h"
59 int verbose;
61 /* iget: Integer argument callback
63 int
64 iget(void *hook, char *name)
66 struct get_hook *h = (struct get_hook *)hook;
67 int arg;
69 if (h->got >= h->argc)
71 fprintf(stderr, "Expecting an integer argument.\n");
72 usage(0);
73 exit(1);
75 arg = strtol(h->argv[h->got], 0, 0);
76 h->got++;
78 if (verbose && name && *name)
79 printf("%s: %d\n", name, arg);
81 return arg;
84 /* cget: char * argument callback
86 char *
87 cget(void *hook, char *name)
89 struct get_hook *h = (struct get_hook *)hook;
90 char *arg;
92 if (h->got >= h->argc)
94 fprintf(stderr, "Expecting a character pointer argument.\n");
95 usage(0);
96 exit(1);
98 arg = h->argv[h->got];
99 h->got++;
101 if (verbose && name)
102 printf("cget: %s: %s", name, arg);
104 return arg;
107 /* arg_put: "put argument" callback
109 void
110 arg_put(void *hook __unused, int letter, void *arg, int count, char *name)
112 if (verbose && name && *name)
113 printf("%s: ", name);
115 switch(letter)
117 case 'i':
118 case 'b':
119 printf("%jd ", (intmax_t)(intptr_t)arg);
120 break;
122 case 'c':
123 case 'z':
125 char *p;
127 p = malloc(count + 1);
128 if (p == NULL) {
129 fprintf(stderr, "can't malloc memory for p\n");
130 exit(1);
133 bzero(p, count +1);
134 strncpy(p, (char *)arg, count);
135 if (letter == 'z')
137 int i;
138 for (i = count - 1; i >= 0; i--)
139 if (p[i] == ' ')
140 p[i] = 0;
141 else
142 break;
144 printf("%s ", p);
146 free(p);
149 break;
151 default:
152 printf("Unknown format letter: '%c'\n", letter);
154 if (verbose)
155 putchar('\n');