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
35 * $FreeBSD: src/usr.sbin/wormcontrol/wormcontrol.c,v 1.11 1999/10/01 14:12:46 peter Exp $
36 * $DragonFly: src/usr.sbin/wormcontrol/Attic/wormcontrol.c,v 1.2 2003/06/17 04:30:04 dillon Exp $
47 #include <sys/ioctl.h>
48 #include <sys/wormio.h>
53 fprintf(stderr,"usage: wormcontrol [-f device] command [args]\n");
57 #define eq(a, b) (strcmp(a, b) == 0)
60 main(int argc, char **argv)
64 const char *devname = "/dev/rworm0";
66 while ((c = getopt(argc, argv, "f:")) != -1)
83 if ((fd = open(devname, O_RDONLY | O_NONBLOCK, 0)) == -1)
84 err(EX_NOINPUT, "open(%s)", devname);
86 if (eq(argv[0], "prepdisk")) {
87 struct wormio_prepare_disk d;
90 for (i = 1; i < argc; i++) {
91 if (eq(argv[i], "dummy"))
93 else if (eq(argv[i], "single"))
95 else if (eq(argv[i], "double"))
97 else if (eq(argv[i], "quad"))
99 else if (eq(argv[i], "max"))
103 "wrong param for \"prepdisk\": %s",
107 errx(EX_USAGE, "missing speed parameter");
108 if (ioctl(fd, WORMIOCPREPDISK, &d) == -1)
109 err(EX_IOERR, "ioctl(WORMIOCPREPDISK)");
111 else if (eq(argv[0], "track")) {
112 struct wormio_prepare_track t;
113 bzero(&t, sizeof (t));
116 for (i = 1; i < argc; i++) {
117 if (eq(argv[i], "audio"))
119 else if (eq(argv[i], "data")) {
121 t.track_type = BLOCK_MODE_1;
122 } else if (eq(argv[i], "preemp"))
126 "wrong param for \"track\": %s",
130 errx(EX_USAGE, "missing track type parameter");
131 if (t.audio == 0 && t.preemp == 1)
132 errx(EX_USAGE, "\"preemp\" attempted on data track");
133 if (ioctl(fd, WORMIOCPREPTRACK, &t) == -1)
134 err(EX_IOERR, "ioctl(WORMIOCPREPTRACK)");
136 else if (eq(argv[0], "fixate")) {
137 struct wormio_fixation f;
140 for (i = 1; i < argc; i++) {
141 if (eq(argv[i], "onp"))
143 else if (argv[i][0] >= '0' && argv[i][0] <= '4' &&
145 f.toc_type = argv[i][0] - '0';
148 "wrong param for \"fixate\": %s",
151 if (f.toc_type == -1)
152 errx(EX_USAGE, "missing TOC type parameter");
153 if (ioctl(fd, WORMIOCFIXATION, &f) == -1)
154 err(EX_IOERR, "ioctl(WORMIOFIXATION)");
156 else if (eq(argv[0], "blank")) {
157 if (ioctl(fd, CDRIOCBLANK) == -1)
158 err(EX_IOERR, "ioctl(CDRIOCBLANK)");
160 else if (eq(argv[0], "nextwriteable")) {
162 if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) == -1)
163 err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)");
164 printf("%d\n", addr);
167 errx(EX_USAGE, "unknown command: %s", argv[0]);