summaryrefslogtreecommitdiffstats
path: root/usr.sbin/fdcontrol
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>2001-12-15 19:09:04 +0000
committerjoerg <joerg@FreeBSD.org>2001-12-15 19:09:04 +0000
commitb2bcdd0ab8129dadaba668862099bdcf62c0a673 (patch)
treec968cf76f6441af16366647eb2faba327bc6777e /usr.sbin/fdcontrol
parent994cab589b53047338727cf60ea42223f294cc51 (diff)
downloadFreeBSD-src-b2bcdd0ab8129dadaba668862099bdcf62c0a673.zip
FreeBSD-src-b2bcdd0ab8129dadaba668862099bdcf62c0a673.tar.gz
Long promised major enhancement set for the floppy disk driver:
. The main device node now supports automatic density selection for commonly used media densities. So you can stuff your 1.44 MB and 720 KB media into your drive and just access /dev/fd0, no questions asked. It's all that easy, isn't it? :) . Device density handling has been completely overhauled. The old way of hardwired kernel density knowledge is no longer there. Instead, the kernel now implements 16 subdevices per drive. The first subdevice uses automatic density selection, while the remaining 15 devices are freely programmable. They can be assigned an arbitrary name of the form /dev/fd[:digit]+.[:digit:]{1,4}, where the second number is meant to either implement device names that are mnemonic for their raw capacity (as it used to be), or they can alternatively be created as "anonymous" devices like fd0.1 through fd0.15, depending on the taste of the administrator. After creating a subdevice, it is initialized to the maximal native density of the respective drive type, so it needs to be customized for other densities by using fdcontrol(8). Pseudo-partition devices (fd0a through fd0h) are still supported as symlinks. . The old hack to use flags 0x1 to always assume drive 0 were there is no longer supported; this is now supposed to be done by wiring the devices down from the loader via device flags. On IA32 architectures, the first two drives are looked up in the CMOS configuration records though. On PCMCIA (i. e., the Y-E Data controller of the Toshiba Libretto), a single drive is always assumed. . Other specialities like disabling the FIFO and not probing the drive at boot-time are selected by per-controller or per-drive flags, too. . Unit attentions (media has been changed) are supposed to be detected now; density autoselection only occurs after a unit attention. (Can be turned off by a per-drive flag, this will cause each Fdopen() to perform the autoselection.) . FM floppies can be handled now (on controllers that actually support it -- not all do these days). . Fdopen() can be told to avoid density selection by setting O_NONBLOCK; this leaves the descriptor in a half-opened state where only a few ioctls are accepted. This is necessary to run fdformat on a device that uses automatic density selection (since you cannot autoselect on an unformatted medium, obviously). . Just differentiate between a plain old NE765 and the enhanced chips, but don't try more; the existing code was wrong and only misdetected the chips anyway. BUGS and TODOs: . All documentation update still needs to be done. . Formatting not-so-standard format yields unpredictable results; i have yet to figure out why this happens. "Standard" formats like 720 and 1440 KB do work, however. . rc scripts are needed to setup device nodes with nonstandard densities (like the old /dev/fdN.MMM we used to have). . Obtaining device flags from the kernel environment doesn't work yet, thus currently only drives that are present in (IA32) CMOS are really detected. Someone who knows the odds and ends about device flags is needed here, i can't figure out what i'm doing wrong. . 2.88 MB still needs to be done.
Diffstat (limited to 'usr.sbin/fdcontrol')
-rw-r--r--usr.sbin/fdcontrol/Makefile4
-rw-r--r--usr.sbin/fdcontrol/fdcontrol.c206
2 files changed, 124 insertions, 86 deletions
diff --git a/usr.sbin/fdcontrol/Makefile b/usr.sbin/fdcontrol/Makefile
index ec411d7a..38f9a1e 100644
--- a/usr.sbin/fdcontrol/Makefile
+++ b/usr.sbin/fdcontrol/Makefile
@@ -1,8 +1,12 @@
# $FreeBSD$
+.PATH: ${.CURDIR}/../fdread
+
PROG= fdcontrol
+SRCS= fdcontrol.c fdutil.c
MAN= fdcontrol.8
WARNS?= 2
+CFLAGS+= -I${.CURDIR}/../fdread
.include <bsd.prog.mk>
diff --git a/usr.sbin/fdcontrol/fdcontrol.c b/usr.sbin/fdcontrol/fdcontrol.c
index e120059..9d447a5 100644
--- a/usr.sbin/fdcontrol/fdcontrol.c
+++ b/usr.sbin/fdcontrol/fdcontrol.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1994 by Joerg Wunsch, Dresden
+ * Copyright (C) 1994, 2001 by Joerg Wunsch, Dresden
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,110 +36,144 @@ static const char rcsid[] =
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
-static int getnumber(void);
-static void usage(void);
+#include "fdutil.h"
-static int
-getnumber(void)
-{
- int i;
- char b[80];
- fgets(b, 80, stdin);
- if(b[0] == '\n') return -1;
+static int debug = -1, format, verbose, show = 1, showfmt;
+static char *fmtstring;
- sscanf(b, " %i", &i);
- return i;
-}
+static void showdev(enum fd_drivetype, const char *);
+static void usage(void);
static void
usage(void)
{
- fprintf(stderr, "usage: fdcontrol [-d 0|1] | [-s] device-node\n");
- exit(2);
+ errx(EX_USAGE,
+ "usage: fdcontrol [-F] [-d dbg] [-f fmt] [-s fmtstr] [-v] device");
}
+void
+showdev(enum fd_drivetype type, const char *fname)
+{
+ const char *name, *descr;
-#define ask(name, fmt) \
-printf(#name "? [" fmt "]: ", ft.name); fflush(stdout); \
-if((i = getnumber()) != -1) ft.name = i
+ getname(type, &name, &descr);
+ if (verbose)
+ printf("%s: %s drive (%s)\n", fname, name, descr);
+ else
+ printf("%s\n", name);
+}
int
main(int argc, char **argv)
{
- struct fd_type ft;
- int fd, i;
- int debug = -1, settype = 1;
-
- while((i = getopt(argc, argv, "d:s")) != -1)
- switch(i)
- {
- case 'd':
- debug = atoi(optarg);
- settype = 0;
- break;
-
- case 's':
- debug = -1;
- settype = 1;
- break;
-
- case '?':
- default:
- usage();
- }
-
- argc -= optind;
- argv += optind;
-
- if(argc != 1)
- usage();
-
- if((fd = open(argv[0], 0)) < 0)
- {
- warn("open(floppy)");
- return 1;
- }
-
- if(debug != -1)
- {
- if(ioctl(fd, FD_DEBUG, &debug) < 0)
- {
- warn("ioctl(FD_DEBUG)");
- return 1;
+ enum fd_drivetype type;
+ struct fd_type ft, newft, *fdtp;
+ const char *name, *descr;
+ int fd, i, mode;
+
+ while((i = getopt(argc, argv, "d:Ff:s:v")) != -1)
+ switch(i) {
+ case 'd':
+ if (strcmp(optarg, "0") == 0)
+ debug = 0;
+ else if (strcmp(optarg, "1") == 0)
+ debug = 1;
+ else
+ usage();
+ show = 0;
+ break;
+
+ case 'F':
+ showfmt = 1;
+ show = 0;
+ break;
+
+ case 'f':
+ if (getnum(optarg, &format)) {
+ fprintf(stderr,
+ "Bad argument %s to -f option; must be numeric\n",
+ optarg);
+ usage();
+ }
+ show = 0;
+ break;
+
+ case 's':
+ fmtstring = optarg;
+ show = 0;
+ break;
+
+ case 'v':
+ verbose++;
+ break;
+
+ default:
+ usage();
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if(argc != 1)
+ usage();
+
+ if (show || showfmt)
+ mode = O_RDONLY | O_NONBLOCK;
+ else
+ mode = O_RDWR;
+
+ if((fd = open(argv[0], mode)) < 0)
+ err(EX_UNAVAILABLE, "open(%s)", argv[0]);
+
+ if (ioctl(fd, FD_GDTYPE, &type) == -1)
+ err(EX_OSERR, "ioctl(FD_GDTYPE)");
+ if (ioctl(fd, FD_GTYPE, &ft) == -1)
+ err(EX_OSERR, "ioctl(FD_GTYPE)");
+
+ if (show) {
+ showdev(type, argv[0]);
+ return (0);
}
- return 0;
- }
-
- if(settype)
- {
- if(ioctl(fd, FD_GTYPE, &ft) < 0)
- {
- warn("ioctl(FD_GTYPE)");
- return 1;
+
+ if (format) {
+ getname(type, &name, &descr);
+ fdtp = get_fmt(format, type);
+ if (fdtp == 0)
+ errx(EX_USAGE,
+ "unknown format %d KB for drive type %s",
+ format, name);
+ ft = *fdtp;
+ }
+
+ if (fmtstring) {
+ parse_fmt(fmtstring, type, ft, &newft);
+ ft = newft;
+ }
+
+ if (showfmt) {
+ if (verbose)
+ printf("%s: %d KB media type, fmt = ",
+ argv[0], ft.size / 2);
+ print_fmt(ft);
+ return (0);
+ }
+
+ if (format || fmtstring) {
+ if (ioctl(fd, FD_STYPE, &ft) == -1)
+ err(EX_OSERR, "ioctl(FD_STYPE)");
+ return (0);
}
- ask(sectrac, "%d");
- ask(secsize, "%d");
- ask(datalen, "0x%x");
- ask(gap, "0x%x");
- ask(tracks, "%d");
- ask(size, "%d");
- ask(steptrac, "%d");
- ask(trans, "%d");
- ask(heads, "%d");
- ask(f_gap, "0x%x");
- ask(f_inter, "%d");
-
- if(ioctl(fd, FD_STYPE, &ft) < 0)
- {
- warn("ioctl(FD_STYPE)");
- return 1;
+ if (debug != -1) {
+ if (ioctl(fd, FD_DEBUG, &debug) == -1)
+ err(EX_OSERR, "ioctl(FD_DEBUG)");
+ return (0);
}
- return 0;
- }
- return 0;
+ return 0;
}
OpenPOWER on IntegriCloud