3 * interface business GmbH
4 * Tolkewitzer Strasse 49
10 * Written by Joerg Wunsch <joerg_wunsch@interface-business.de>
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY
23 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
37 static const char rcsid[] =
38 "$FreeBSD: src/usr.sbin/wormcontrol/wormcontrol.c,v 1.11 1999/10/01 14:12:46 peter Exp $";
49 #include <sys/ioctl.h>
50 #include <sys/wormio.h>
55 fprintf(stderr,"usage: wormcontrol [-f device] command [args]\n");
59 #define eq(a, b) (strcmp(a, b) == 0)
62 main(int argc, char **argv)
66 const char *devname = "/dev/rworm0";
68 while ((c = getopt(argc, argv, "f:")) != -1)
85 if ((fd = open(devname, O_RDONLY | O_NONBLOCK, 0)) == -1)
86 err(EX_NOINPUT, "open(%s)", devname);
88 if (eq(argv[0], "prepdisk")) {
89 struct wormio_prepare_disk d;
92 for (i = 1; i < argc; i++) {
93 if (eq(argv[i], "dummy"))
95 else if (eq(argv[i], "single"))
97 else if (eq(argv[i], "double"))
99 else if (eq(argv[i], "quad"))
101 else if (eq(argv[i], "max"))
105 "wrong param for \"prepdisk\": %s",
109 errx(EX_USAGE, "missing speed parameter");
110 if (ioctl(fd, WORMIOCPREPDISK, &d) == -1)
111 err(EX_IOERR, "ioctl(WORMIOCPREPDISK)");
113 else if (eq(argv[0], "track")) {
114 struct wormio_prepare_track t;
115 bzero(&t, sizeof (t));
118 for (i = 1; i < argc; i++) {
119 if (eq(argv[i], "audio"))
121 else if (eq(argv[i], "data")) {
123 t.track_type = BLOCK_MODE_1;
124 } else if (eq(argv[i], "preemp"))
128 "wrong param for \"track\": %s",
132 errx(EX_USAGE, "missing track type parameter");
133 if (t.audio == 0 && t.preemp == 1)
134 errx(EX_USAGE, "\"preemp\" attempted on data track");
135 if (ioctl(fd, WORMIOCPREPTRACK, &t) == -1)
136 err(EX_IOERR, "ioctl(WORMIOCPREPTRACK)");
138 else if (eq(argv[0], "fixate")) {
139 struct wormio_fixation f;
142 for (i = 1; i < argc; i++) {
143 if (eq(argv[i], "onp"))
145 else if (argv[i][0] >= '0' && argv[i][0] <= '4' &&
147 f.toc_type = argv[i][0] - '0';
150 "wrong param for \"fixate\": %s",
153 if (f.toc_type == -1)
154 errx(EX_USAGE, "missing TOC type parameter");
155 if (ioctl(fd, WORMIOCFIXATION, &f) == -1)
156 err(EX_IOERR, "ioctl(WORMIOFIXATION)");
158 else if (eq(argv[0], "blank")) {
159 if (ioctl(fd, CDRIOCBLANK) == -1)
160 err(EX_IOERR, "ioctl(CDRIOCBLANK)");
162 else if (eq(argv[0], "nextwriteable")) {
164 if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) == -1)
165 err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)");
166 printf("%d\n", addr);
169 errx(EX_USAGE, "unknown command: %s", argv[0]);