err(1, devname);
err(1, "%s", devname);
main(argc, argv)	int argc;	char *argv[];{	int cyls = -1, secs = -1, heads = -1, intleave = -1;	int rate = -1, gaplen = -1, secsize = -1, steps = -1;	int fill = 0xf6, quiet = 0, verify = 1, verify_only = 0;	int fd, c, track, error, tracks_per_dot, bytes_per_track, errs;	char *devname;	struct fd_type fdt;	while((c = getopt(argc, argv, "c:s:h:r:g:S:F:t:i:qvn")) != -1)		switch (c) {		case 'c':       /* # of cyls */			cyls = atoi(optarg);			break;		case 's':       /* # of secs per track */			secs = atoi(optarg);			break;		case 'h':       /* # of heads */			heads = atoi(optarg);			break;		case 'r':       /* transfer rate, kilobyte/sec */			rate = atoi(optarg);			break;		case 'g':       /* length of GAP3 to format with */			gaplen = atoi(optarg);			break;		case 'S':       /* sector size shift factor (1 << S)*128 */			secsize = atoi(optarg);			break;		case 'F':       /* fill byte, C-like notation allowed */			fill = (int)strtol(optarg, (char **)0, 0);			break;		case 't':       /* steps per track */			steps = atoi(optarg);			break;		case 'i':       /* interleave factor */			intleave = atoi(optarg);			break;		case 'q':			quiet = 1;			break;		case 'n':			verify = 0;			break;		case 'v':			verify = 1;			verify_only = 1;			break;		case '?': default:			usage();		}	if (optind != argc - 1)		usage();	if ((fd = opendev(argv[optind], O_RDWR, OPENDEV_PART, &devname)) < 0)		err(1, devname);	if (ioctl(fd, FD_GTYPE, &fdt) < 0)		errx(1, "not a floppy disk: %s", devname);	switch (rate) {	case -1:		break;	case 250:		fdt.rate = FDC_250KBPS;		break;	case 300:		fdt.rate = FDC_300KBPS;		break;	case 500:		fdt.rate = FDC_500KBPS;		break;	default:		errx(1, "invalid transfer rate: %d", rate);	}	if (cyls >= 0)		fdt.tracks = cyls;	if (secs >= 0)		fdt.sectrac = secs;	if (fdt.sectrac > FD_MAX_NSEC)		errx(1, "too many sectors per track, max value is %d",			FD_MAX_NSEC);	if (heads >= 0)		fdt.heads = heads;	if (gaplen >= 0)		fdt.gap2 = gaplen;	if (secsize >= 0)		fdt.secsize = secsize;	if (steps >= 0)		fdt.step = steps;	bytes_per_track = fdt.sectrac * (1<<fdt.secsize) * 128;	tracks_per_dot = fdt.tracks * fdt.heads / 40;	if (verify_only) {		if (!quiet)			printf("Verify %dK floppy `%s'.\n",				fdt.tracks * fdt.heads * bytes_per_track / 1024,				devname);	}	else if (!quiet) {		printf("Format %dK floppy `%s'? (y/n): ",			fdt.tracks * fdt.heads * bytes_per_track / 1024,			devname);		if (!yes()) {			printf("Not confirmed.\n");			exit(0);		}	}	/*	 * Formatting.	 */	if (!quiet) {		printf("Processing ");		for (track = 0; track < fdt.tracks * fdt.heads; track++) {			if (!((track + 1) % tracks_per_dot))				putchar('-');		}		putchar('\r');		printf("Processing ");		fflush(stdout);	}	error = errs = 0;	for (track = 0; track < fdt.tracks * fdt.heads; track++) {		if (!verify_only) {			format_track(fd, track / fdt.heads, fdt.sectrac,				track % fdt.heads, fdt.rate, fdt.gap2,				     fdt.secsize, fill,				     intleave >= 0 ? intleave : 1);			if (!quiet && !((track + 1) % tracks_per_dot)) {				putchar('F');				fflush(stdout);			}		}		if (verify) {			if (verify_track(fd, track, bytes_per_track) < 0)				error = errs = 1;			if (!quiet && !((track + 1) % tracks_per_dot)) {				if (!verify_only)					putchar('\b');				if (error) {					putchar('E');					error = 0;				}				else					putchar('V');				fflush(stdout);			}		}	}	if (!quiet)		printf(" done.\n");	exit(errs);}