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