xref: /csrg-svn/old/rxformat/rxformat.c (revision 39889)
1 /*
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 char copyright[] =
20 "@(#) Copyright (c) 1983 The Regents of the University of California.\n\
21  All rights reserved.\n";
22 #endif /* not lint */
23 
24 #ifndef lint
25 static char sccsid[] = "@(#)rxformat.c	5.4 (Berkeley) 01/05/90";
26 #endif /* not lint */
27 
28 #include <sys/file.h>
29 #include <vaxuba/rxreg.h>
30 #include <stdio.h>
31 #include <errno.h>
32 #include "pathnames.h"
33 
34 char devname[] = _PATH_DEVNAME;
35 
36 /*
37  * Format RX02 floppy disks.
38  */
39 
40 main(argc, argv)
41 	int argc;
42 	char *argv[];
43 {
44 	int fd, idens = 0, filarg = 1;
45 	int i, c;
46 
47 	if (argc < 2 || argc > 3)
48 		usage();
49 	if (argc == 3) {
50 		if (strncmp(argv[1],"-d",2) != 0)
51 			usage();
52 		idens++;
53 		filarg++;
54 	}
55 	devname[8] = argv[filarg][7];
56 	if ((fd = open(devname, O_RDWR)) < 0) {
57 		perror(devname);
58 		exit(1);
59 	}
60 	if (isatty(fileno(stdin))) {
61 		printf("Format %s to %s density (y/n)? ",
62 			argv[filarg], idens ? "double" : "single");
63 		i = c = getchar();
64 		while (c != '\n' && c != EOF)
65 			c = getchar();
66 		if (i != 'y')
67 			exit(0);
68 	} else
69 		printf("Formatting %s to %s density\n",
70 			argv[filarg], idens ? "double" : "single");
71 	/*
72 	 * Change the ioctl command when dkio.h has
73 	 * been finished.
74 	 */
75 	if (ioctl(fd, RXIOC_FORMAT, &idens) == 0)
76 		exit(0);
77 	else {
78 		perror(devname);
79 		exit(1);
80 	}
81 }
82 
83 usage()
84 {
85 	fprintf(stderr, "usage: rxformat [-d] /dev/rx?\n");
86 	exit(1);
87 }
88