xref: /original-bsd/old/rxformat/rxformat.c (revision 2c12987e)
1 /*
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 char copyright[] =
10 "@(#) Copyright (c) 1983 The Regents of the University of California.\n\
11  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)rxformat.c	5.5 (Berkeley) 06/01/90";
16 #endif /* not lint */
17 
18 #include <sys/file.h>
19 #include <vaxuba/rxreg.h>
20 #include <stdio.h>
21 #include <errno.h>
22 #include "pathnames.h"
23 
24 char devname[] = _PATH_DEVNAME;
25 
26 /*
27  * Format RX02 floppy disks.
28  */
29 
30 main(argc, argv)
31 	int argc;
32 	char *argv[];
33 {
34 	int fd, idens = 0, filarg = 1;
35 	int i, c;
36 
37 	if (argc < 2 || argc > 3)
38 		usage();
39 	if (argc == 3) {
40 		if (strncmp(argv[1],"-d",2) != 0)
41 			usage();
42 		idens++;
43 		filarg++;
44 	}
45 	devname[8] = argv[filarg][7];
46 	if ((fd = open(devname, O_RDWR)) < 0) {
47 		perror(devname);
48 		exit(1);
49 	}
50 	if (isatty(fileno(stdin))) {
51 		printf("Format %s to %s density (y/n)? ",
52 			argv[filarg], idens ? "double" : "single");
53 		i = c = getchar();
54 		while (c != '\n' && c != EOF)
55 			c = getchar();
56 		if (i != 'y')
57 			exit(0);
58 	} else
59 		printf("Formatting %s to %s density\n",
60 			argv[filarg], idens ? "double" : "single");
61 	/*
62 	 * Change the ioctl command when dkio.h has
63 	 * been finished.
64 	 */
65 	if (ioctl(fd, RXIOC_FORMAT, &idens) == 0)
66 		exit(0);
67 	else {
68 		perror(devname);
69 		exit(1);
70 	}
71 }
72 
73 usage()
74 {
75 	fprintf(stderr, "usage: rxformat [-d] /dev/rx?\n");
76 	exit(1);
77 }
78