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