/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by John Kohl.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* fdformat: format a floppy diskette, using interface provided in
* <sys/fdio.h>
*/
#include <sys/cdefs.h>
int
main(int argc, char *argv[])
{
char *fdbuf = NULL, *trackbuf = NULL;
int errcnt = 0;
int verify = 1;
int ch;
long tmplong;
int tmpint;
char *tmpcharp;
int parmmask = 0;
struct fdformat_parms parms, fetchparms;
struct fdformat_cmd cmd;
const char *filename = _PATH_FLOPPY_DEV;
int fd;
int trk, cyl;
while ((ch = getopt(argc, argv, "f:t:nB:C:S:T:P:G:F:X:I:")) != -1)
switch (ch) {
case 't': /* disk type */
switch (cgetent(&fdbuf, fdb_array, optarg)) {
case 0:
break;
case 1:
case -3:
errx(1, "tc= loop or missing entry entry in "
_PATH_FLOPPYTAB " for type %s", optarg);
break;
case -1:
errx(1, "Unknown floppy disk type %s", optarg);
break;
default:
err(1, "Problem accessing " _PATH_FLOPPYTAB);
break;
}
getparm(nbps, NBPS);
getparm(ncyl, NCYL);
getparm(nspt, NSPT);
getparm(ntrk, NTRK);
getparm(stepspercyl, STEPSPERCYL);
getparm(gaplen, GAPLEN);
getparm(fillbyte, FILLBYTE);
getparm(xfer_rate, XFER_RATE);
getparm(interleave, INTERLEAVE);
break;
case 'f': /* device name */
filename = optarg;
break;
case 'n': /* no verify */
verify = 0;
break;
case 'B':
numarg(nbps, NBPS, <=);
break;
case 'C':
numarg(ncyl, NCYL, <=);
break;
case 'S':
numarg(nspt, NSPT, <=);
break;
case 'T':
numarg(ntrk, NTRK, <=);
break;
case 'P':
numarg(stepspercyl, STEPSPERCYL, <=);
break;
case 'G':
numarg(gaplen, GAPLEN, <=);
break;
case 'F':
numarg(fillbyte, FILLBYTE, <);
break;
case 'X':
numarg(xfer_rate, XFER_RATE, <=);
break;
case 'I':
numarg(interleave, INTERLEAVE, <=);
break;
case '?':
default:
usage();
}
if (optind < argc)
usage();
fd = open(filename, O_RDWR);
if (fd == -1)
err(1, "Cannot open %s", filename);
if (ioctl(fd, FDIOCGETFORMAT, &fetchparms) == -1) {
if (errno == ENOTTY)
err(1, "Device `%s' does not support floppy formatting",
filename);
else
err(1, "Cannot fetch current floppy"
" formatting parameters");
}