2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 1994, 2001 by Joerg Wunsch, Dresden
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
22 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/fdcio.h>
46 static int 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;
80 while((i = getopt(argc, argv, "aFf:s:v")) != -1)
92 if (!strcmp(optarg, "auto")) {
94 } else if (getnum(optarg, &format)) {
96 "Bad argument %s to -f option; must be numeric\n",
122 if((fd = open(argv[0], O_RDONLY | O_NONBLOCK)) < 0)
123 err(EX_UNAVAILABLE, "open(%s)", argv[0]);
125 if (ioctl(fd, FD_GDTYPE, &type) == -1)
126 err(EX_OSERR, "ioctl(FD_GDTYPE)");
127 if (ioctl(fd, FD_GTYPE, &ft) == -1)
128 err(EX_OSERR, "ioctl(FD_GTYPE)");
131 showdev(type, argv[0]);
136 memset(&newft, 0, sizeof newft);
141 getname(type, &name, &descr);
142 fdtp = get_fmt(format, type);
145 "unknown format %d KB for drive type %s",
151 parse_fmt(fmtstring, type, ft, &newft);
159 printf("%s: %d KB media type\n", argv[0],
160 (128 << ft.secsize) * ft.size / 1024);
161 printf("\tFormat:\t\t");
163 if (ft.datalen != 0xff &&
164 ft.datalen != (128 << ft.secsize))
165 printf("\tData length:\t%d\n", ft.datalen);
166 printf("\tSector size:\t%d\n", 128 << ft.secsize);
167 printf("\tSectors/track:\t%d\n", ft.sectrac);
168 printf("\tHeads/cylinder:\t%d\n", ft.heads);
169 printf("\tCylinders/disk:\t%d\n", ft.tracks);
171 case 0: printf("\tTransfer rate:\t500 kbps\n"); break;
172 case 1: printf("\tTransfer rate:\t300 kbps\n"); break;
173 case 2: printf("\tTransfer rate:\t250 kbps\n"); break;
174 case 3: printf("\tTransfer rate:\t1 Mbps\n"); break;
176 printf("\tSector gap:\t%d\n", ft.gap);
177 printf("\tFormat gap:\t%d\n", ft.f_gap);
178 printf("\tInterleave:\t%d\n", ft.f_inter);
179 printf("\tSide offset:\t%d\n", ft.offset_side2);
180 printf("\tFlags\t\t<");
182 if (ft.flags & FL_MFM) {
186 if (ft.flags & FL_2STEP) {
187 printf("%s2STEP", s);
190 if (ft.flags & FL_PERPND) {
191 printf("%sPERPENDICULAR", s);
194 if (ft.flags & FL_AUTO) {
205 if (format || fmtstring) {
206 if (ioctl(fd, FD_STYPE, &ft) == -1)
207 err(EX_OSERR, "ioctl(FD_STYPE)");