xref: /freebsd/usr.sbin/fdcontrol/fdcontrol.c (revision e627b39baccd1ec9129690167cf5e6d860509655)
1 /*
2  * Copyright (C) 1994 by Joerg Wunsch, Dresden
3  * All rights reserved.
4  *
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.
13  *
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.
26  */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <machine/ioctl_fd.h>
31 #include <sys/file.h>
32 
33 int
34 getnumber(void)
35 {
36   int i;
37   char b[80];
38 
39   fgets(b, 80, stdin);
40   if(b[0] == '\n') return -1;
41 
42   sscanf(b, " %i", &i);
43   return i;
44 }
45 
46 void
47 usage(void)
48 {
49   fprintf(stderr, "usage: fdcontrol [-d 0|1] | [-s] device-node\n");
50   exit(2);
51 }
52 
53 
54 #define ask(name, fmt) \
55 printf(#name "? [" fmt "]: ", ft.name); fflush(stdout);   \
56 if((i = getnumber()) != -1) ft.name = i
57 
58 int
59 main(int argc, char **argv)
60 {
61   struct fd_type ft;
62   int fd, i;
63   int debug = -1, settype = 1;
64 
65   while((i = getopt(argc, argv, "d:s")) != EOF)
66     switch(i)
67       {
68       case 'd':
69 	debug = atoi(optarg);
70 	settype = 0;
71 	break;
72 
73       case 's':
74 	debug = -1;
75 	settype = 1;
76 	break;
77 
78       case '?':
79       default:
80 	usage();
81       }
82 
83   argc -= optind;
84   argv += optind;
85 
86   if(argc != 1)
87     usage();
88 
89   if((fd = open(argv[0], 0)) < 0)
90     {
91       perror("open(floppy)");
92       return 1;
93     }
94 
95   if(debug != -1)
96     {
97       if(ioctl(fd, FD_DEBUG, &debug) < 0)
98 	{
99 	  perror("ioctl(FD_DEBUG)");
100 	  return 1;
101 	}
102       return 0;
103     }
104 
105   if(settype)
106     {
107       if(ioctl(fd, FD_GTYPE, &ft) < 0)
108 	{
109 	  perror("ioctl(FD_GTYPE)");
110 	  return 1;
111 	}
112 
113       ask(sectrac, "%d");
114       ask(secsize, "%d");
115       ask(datalen, "0x%x");
116       ask(gap, "0x%x");
117       ask(tracks, "%d");
118       ask(size, "%d");
119       ask(steptrac, "%d");
120       ask(trans, "%d");
121       ask(heads, "%d");
122       ask(f_gap, "0x%x");
123       ask(f_inter, "%d");
124 
125       if(ioctl(fd, FD_STYPE, &ft) < 0)
126 	{
127 	  perror("ioctl(FD_STYPE)");
128 	  return 1;
129 	}
130       return 0;
131     }
132 
133 }
134 
135 
136 
137