fdcontrol(8): Staticize and bump WARNS to 6.
[dragonfly.git] / usr.sbin / fdcontrol / fdcontrol.c
blob7c0bb796612bf352379ac302e916ebca42a45e43
1 /*
2 * Copyright (C) 1994 by Joerg Wunsch, Dresden
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
25 * DAMAGE.
27 * $FreeBSD: src/usr.sbin/fdcontrol/fdcontrol.c,v 1.6 1999/08/28 01:16:13 peter Exp $
30 #include <err.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <machine/ioctl_fd.h>
35 #include <sys/file.h>
37 static int
38 getnumber(void)
40 int i;
41 char b[80];
43 fgets(b, 80, stdin);
44 if(b[0] == '\n') return -1;
46 sscanf(b, " %i", &i);
47 return i;
50 static void
51 usage(void)
53 fprintf(stderr, "usage: fdcontrol [-d 0|1] | [-s] device-node\n");
54 exit(2);
58 #define ask(name, fmt) \
59 printf(#name "? [" fmt "]: ", ft.name); fflush(stdout); \
60 if((i = getnumber()) != -1) ft.name = i
62 int
63 main(int argc, char **argv)
65 struct fd_type ft;
66 int fd, i;
67 int debug = -1, settype = 1;
69 while((i = getopt(argc, argv, "d:s")) != -1)
70 switch(i)
72 case 'd':
73 debug = atoi(optarg);
74 settype = 0;
75 break;
77 case 's':
78 debug = -1;
79 settype = 1;
80 break;
82 case '?':
83 default:
84 usage();
87 argc -= optind;
88 argv += optind;
90 if(argc != 1)
91 usage();
93 if((fd = open(argv[0], 0)) < 0)
95 warn("open(floppy)");
96 return 1;
99 if(debug != -1)
101 if(ioctl(fd, FD_DEBUG, &debug) < 0)
103 warn("ioctl(FD_DEBUG)");
104 return 1;
106 return 0;
109 if(settype)
111 if(ioctl(fd, FD_GTYPE, &ft) < 0)
113 warn("ioctl(FD_GTYPE)");
114 return 1;
117 ask(sectrac, "%d");
118 ask(secsize, "%d");
119 ask(datalen, "0x%x");
120 ask(gap, "0x%x");
121 ask(tracks, "%d");
122 ask(size, "%d");
123 ask(steptrac, "%d");
124 ask(trans, "%d");
125 ask(heads, "%d");
126 ask(f_gap, "0x%x");
127 ask(f_inter, "%d");
129 if(ioctl(fd, FD_STYPE, &ft) < 0)
131 warn("ioctl(FD_STYPE)");
132 return 1;
134 return 0;
137 return 0;