2 * SPDX-License-Identifier: BSD-3-Clause
4 * Written By Julian ELischer
5 * Copyright julian Elischer 1993.
6 * Permission is granted to use or redistribute this file in any way as long
7 * as this notice remains. Julian Elischer does not guarantee that this file
8 * is totally correct for any given task and users of this file must
9 * accept responsibility for any damage that occurs from the application of this
12 * (julian@tfs.com julian@dialix.oz.au)
14 * User SCSI hooks added by Peter Dufault:
16 * Copyright (c) 1994 HD Associates
17 * (contact: dufault@hda.com)
18 * All rights reserved.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * 3. The name of HD Associates
29 * may not be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * Taken from the original scsi(8) program.
46 * from: scsi.c,v 1.17 1998/01/12 07:57:57 charnier Exp $";
48 #include <sys/cdefs.h>
49 #include <sys/stdint.h>
50 #include <sys/types.h>
57 #include "camcontrol.h"
61 /* iget: Integer argument callback
64 iget(void *hook, char *name)
66 struct get_hook *h = (struct get_hook *)hook;
69 if (h->got >= h->argc)
71 fprintf(stderr, "Expecting an integer argument.\n");
75 arg = strtol(h->argv[h->got], 0, 0);
78 if (verbose && name && *name)
79 printf("%s: %d\n", name, arg);
84 /* cget: char * argument callback
87 cget(void *hook, char *name)
89 struct get_hook *h = (struct get_hook *)hook;
92 if (h->got >= h->argc)
94 fprintf(stderr, "Expecting a character pointer argument.\n");
98 arg = h->argv[h->got];
102 printf("cget: %s: %s", name, arg);
107 /* arg_put: "put argument" callback
110 arg_put(void *hook __unused, int letter, void *arg, int count, char *name)
112 if (verbose && name && *name)
113 printf("%s: ", name);
119 printf("%jd ", (intmax_t)(intptr_t)arg);
127 p = calloc(1, count + 1);
129 fprintf(stderr, "can't malloc memory for p\n");
133 strlcpy(p, (char *)arg, count + 1);
137 for (i = count - 1; i >= 0; i--)
151 printf("Unknown format letter: '%c'\n", letter);
158 * Get confirmation from user
164 get_confirmation(void)
170 fprintf(stdout, "Are you SURE you want to do this? (yes/no) ");
171 if (fgets(str, sizeof(str), stdin) != NULL) {
172 if (strncasecmp(str, "yes", 3) == 0)
174 else if (strncasecmp(str, "no", 2) == 0)
178 "Please answer \"yes\" or \"no\"\n");
181 } while (response == -1);