2 * Copyright (C) 1994, 2001 by Joerg Wunsch, Dresden
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
24 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 static const char rcsid[] =
33 #include <sys/fdcio.h>
46 static int debug = -1, format, verbose, show = 1, showfmt;
47 static char *fmtstring;
49 static void showdev(enum fd_drivetype, const char *);
50 static void usage(void);
56 "usage: fdcontrol [-F] [-d dbg] [-f fmt] [-s fmtstr] [-v] device");
60 showdev(enum fd_drivetype type, const char *fname)
62 const char *name, *descr;
64 getname(type, &name, &descr);
66 printf("%s: %s drive (%s)\n", fname, name, descr);
72 main(int argc, char **argv)
74 enum fd_drivetype type;
75 struct fd_type ft, newft, *fdtp;
76 const char *name, *descr;
79 while((i = getopt(argc, argv, "d:Ff:s:v")) != -1)
82 if (strcmp(optarg, "0") == 0)
84 else if (strcmp(optarg, "1") == 0)
97 if (getnum(optarg, &format)) {
99 "Bad argument %s to -f option; must be numeric\n",
126 mode = O_RDONLY | O_NONBLOCK;
130 if((fd = open(argv[0], mode)) < 0)
131 err(EX_UNAVAILABLE, "open(%s)", argv[0]);
133 if (ioctl(fd, FD_GDTYPE, &type) == -1)
134 err(EX_OSERR, "ioctl(FD_GDTYPE)");
135 if (ioctl(fd, FD_GTYPE, &ft) == -1)
136 err(EX_OSERR, "ioctl(FD_GTYPE)");
139 showdev(type, argv[0]);
144 getname(type, &name, &descr);
145 fdtp = get_fmt(format, type);
148 "unknown format %d KB for drive type %s",
154 parse_fmt(fmtstring, type, ft, &newft);
160 printf("%s: %d KB media type, fmt = ",
161 argv[0], ft.size / 2);
166 if (format || fmtstring) {
167 if (ioctl(fd, FD_STYPE, &ft) == -1)
168 err(EX_OSERR, "ioctl(FD_STYPE)");
173 if (ioctl(fd, FD_DEBUG, &debug) == -1)
174 err(EX_OSERR, "ioctl(FD_DEBUG)");