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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/fdcio.h>
44 static int format, verbose, show = 1, showfmt;
45 static char *fmtstring;
47 static void showdev(enum fd_drivetype, const char *);
48 static void usage(void);
54 "usage: fdcontrol [-F] [-d dbg] [-f fmt] [-s fmtstr] [-v] device");
58 showdev(enum fd_drivetype type, const char *fname)
60 const char *name, *descr;
62 getname(type, &name, &descr);
64 printf("%s: %s drive (%s)\n", fname, name, descr);
70 main(int argc, char **argv)
72 enum fd_drivetype type;
73 struct fd_type ft, newft, *fdtp;
74 const char *name, *descr;
75 int fd, i, mode, autofmt;
78 while((i = getopt(argc, argv, "aFf:s:v")) != -1)
89 if (!strcmp(optarg, "auto")) {
91 } else if (getnum(optarg, &format)) {
93 "Bad argument %s to -f option; must be numeric\n",
120 mode = O_RDONLY | O_NONBLOCK;
124 if((fd = open(argv[0], mode)) < 0)
125 err(EX_UNAVAILABLE, "open(%s)", argv[0]);
127 if (ioctl(fd, FD_GDTYPE, &type) == -1)
128 err(EX_OSERR, "ioctl(FD_GDTYPE)");
129 if (ioctl(fd, FD_GTYPE, &ft) == -1)
130 err(EX_OSERR, "ioctl(FD_GTYPE)");
133 showdev(type, argv[0]);
138 memset(&newft, 0, sizeof newft);
143 getname(type, &name, &descr);
144 fdtp = get_fmt(format, type);
147 "unknown format %d KB for drive type %s",
153 parse_fmt(fmtstring, type, ft, &newft);
161 printf("%s: %d KB media type\n", argv[0],
162 (128 << ft.secsize) * ft.size / 1024);
163 printf("\tFormat:\t\t");
165 if (ft.datalen != 0xff &&
166 ft.datalen != (128 << ft.secsize))
167 printf("\tData length:\t%d\n", ft.datalen);
168 printf("\tSector size:\t%d\n", 128 << ft.secsize);
169 printf("\tSectors/track:\t%d\n", ft.sectrac);
170 printf("\tHeads/cylinder:\t%d\n", ft.heads);
171 printf("\tCylinders/disk:\t%d\n", ft.tracks);
173 case 0: printf("\tTransfer rate:\t500 kbps\n"); break;
174 case 1: printf("\tTransfer rate:\t300 kbps\n"); break;
175 case 2: printf("\tTransfer rate:\t250 kbps\n"); break;
176 case 3: printf("\tTransfer rate:\t1 Mbps\n"); break;
178 printf("\tSector gap:\t%d\n", ft.gap);
179 printf("\tFormat gap:\t%d\n", ft.f_gap);
180 printf("\tInterleave:\t%d\n", ft.f_inter);
181 printf("\tSide offset:\t%d\n", ft.offset_side2);
182 printf("\tFlags\t\t<");
184 if (ft.flags & FL_MFM) {
188 if (ft.flags & FL_2STEP) {
189 printf("%s2STEP", s);
192 if (ft.flags & FL_PERPND) {
193 printf("%sPERPENDICULAR", s);
196 if (ft.flags & FL_AUTO) {
207 if (format || fmtstring) {
208 if (ioctl(fd, FD_STYPE, &ft) == -1)
209 err(EX_OSERR, "ioctl(FD_STYPE)");