xref: /csrg-svn/old/rxformat/rxformat.c (revision 39889)
121177Sdist /*
2*39889Sbostic  * Copyright (c) 1983 The Regents of the University of California.
3*39889Sbostic  * All rights reserved.
4*39889Sbostic  *
5*39889Sbostic  * Redistribution and use in source and binary forms are permitted
6*39889Sbostic  * provided that the above copyright notice and this paragraph are
7*39889Sbostic  * duplicated in all such forms and that any documentation,
8*39889Sbostic  * advertising materials, and other materials related to such
9*39889Sbostic  * distribution and use acknowledge that the software was developed
10*39889Sbostic  * by the University of California, Berkeley.  The name of the
11*39889Sbostic  * University may not be used to endorse or promote products derived
12*39889Sbostic  * from this software without specific prior written permission.
13*39889Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*39889Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*39889Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1621177Sdist  */
1721177Sdist 
1814556Ssam #ifndef lint
1921177Sdist char copyright[] =
20*39889Sbostic "@(#) Copyright (c) 1983 The Regents of the University of California.\n\
2121177Sdist  All rights reserved.\n";
22*39889Sbostic #endif /* not lint */
2312077Shelge 
2421177Sdist #ifndef lint
25*39889Sbostic static char sccsid[] = "@(#)rxformat.c	5.4 (Berkeley) 01/05/90";
26*39889Sbostic #endif /* not lint */
2721177Sdist 
2837980Sbostic #include <sys/file.h>
2937980Sbostic #include <vaxuba/rxreg.h>
3012077Shelge #include <stdio.h>
3112077Shelge #include <errno.h>
32*39889Sbostic #include "pathnames.h"
3312077Shelge 
3437980Sbostic char devname[] = _PATH_DEVNAME;
3512333Shelge 
3612077Shelge /*
3712896Ssam  * Format RX02 floppy disks.
3812077Shelge  */
3912333Shelge 
4012077Shelge main(argc, argv)
4112077Shelge 	int argc;
4212077Shelge 	char *argv[];
4312077Shelge {
4412077Shelge 	int fd, idens = 0, filarg = 1;
4524446Sbloom 	int i, c;
4612077Shelge 
4724446Sbloom 	if (argc < 2 || argc > 3)
4812077Shelge 		usage();
4912077Shelge 	if (argc == 3) {
5012077Shelge 		if (strncmp(argv[1],"-d",2) != 0)
5112077Shelge 			usage();
5212077Shelge 		idens++;
5312333Shelge 		filarg++;
5412077Shelge 	}
5512333Shelge 	devname[8] = argv[filarg][7];
5624446Sbloom 	if ((fd = open(devname, O_RDWR)) < 0) {
5712333Shelge 		perror(devname);
5824446Sbloom 		exit(1);
5912077Shelge 	}
6024446Sbloom 	if (isatty(fileno(stdin))) {
6124446Sbloom 		printf("Format %s to %s density (y/n)? ",
6224446Sbloom 			argv[filarg], idens ? "double" : "single");
6324446Sbloom 		i = c = getchar();
6424446Sbloom 		while (c != '\n' && c != EOF)
6524446Sbloom 			c = getchar();
6624446Sbloom 		if (i != 'y')
6724446Sbloom 			exit(0);
6824446Sbloom 	} else
6924446Sbloom 		printf("Formatting %s to %s density\n",
7024446Sbloom 			argv[filarg], idens ? "double" : "single");
7112333Shelge 	/*
7212896Ssam 	 * Change the ioctl command when dkio.h has
7312896Ssam 	 * been finished.
7412333Shelge 	 */
7524446Sbloom 	if (ioctl(fd, RXIOC_FORMAT, &idens) == 0)
7624446Sbloom 		exit(0);
7724446Sbloom 	else {
7812333Shelge 		perror(devname);
7924446Sbloom 		exit(1);
8024446Sbloom 	}
8112077Shelge }
8212077Shelge 
8312077Shelge usage()
8412077Shelge {
8512077Shelge 	fprintf(stderr, "usage: rxformat [-d] /dev/rx?\n");
8624446Sbloom 	exit(1);
8712077Shelge }
88