summaryrefslogtreecommitdiffstats
path: root/usr.sbin/fdwrite
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-09-18 06:35:51 +0000
committercharnier <charnier@FreeBSD.org>1997-09-18 06:35:51 +0000
commitce8df1cd4a99de80e927c5b1489abd07df57d0dd (patch)
tree6187876358257ea34b38431a0933b935265602fb /usr.sbin/fdwrite
parent9beb19603d8adaf028ce0cacfd477aa39a4b1cc9 (diff)
downloadFreeBSD-src-ce8df1cd4a99de80e927c5b1489abd07df57d0dd.zip
FreeBSD-src-ce8df1cd4a99de80e927c5b1489abd07df57d0dd.tar.gz
Use err(3). Document -y flag. Remove unused -s flag from getopt string.
Diffstat (limited to 'usr.sbin/fdwrite')
-rw-r--r--usr.sbin/fdwrite/fdwrite.116
-rw-r--r--usr.sbin/fdwrite/fdwrite.c69
2 files changed, 33 insertions, 52 deletions
diff --git a/usr.sbin/fdwrite/fdwrite.1 b/usr.sbin/fdwrite/fdwrite.1
index d445eed..53cb70e 100644
--- a/usr.sbin/fdwrite/fdwrite.1
+++ b/usr.sbin/fdwrite/fdwrite.1
@@ -6,7 +6,7 @@
.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
.\" ----------------------------------------------------------------------------
.\"
-.\" $Id: fdwrite.1,v 1.4 1997/02/22 16:05:48 peter Exp $
+.\" $Id: fdwrite.1,v 1.5 1997/05/19 16:33:27 eivind Exp $
.\"
.\"
.Dd September 16, 1993
@@ -17,9 +17,10 @@
.Nd format and write floppy disks
.Sh SYNOPSIS
.Nm fdwrite
-.Bq Fl v
-.Bq Fl f Ar inputfile
-.Bq Fl d Ar device
+.Op Fl v
+.Op Fl y
+.Op Fl f Ar inputfile
+.Op Fl d Ar device
.Sh DESCRIPTION
.Nm Fdwrite
formats and writes one and more floppy disks.
@@ -40,7 +41,7 @@ This continues until the program is interrupted or EOF is encountered on the
The options are as follows:
.Bl -tag -width 10n -offset indent
.It Fl v
-toggles verbosity on stdout.
+Toggle verbosity on stdout.
Default is ``on''.
After
.Ar device
@@ -49,6 +50,9 @@ During operation progress will be reported with the number of tracks
remaining on the current floppy disk, and the letters I, Z, F, W,
R and C, which indicates completion of Input, Zero-fill, Format
Write, Read and Compare of current track respectively.
+.It Fl y
+Don't ask for presence of a floppy disk in the drive. This non-interactive flag
+is useful for shell scripts.
.It Fl f Ar inputfile
Input file to read. If none is given, stdin is assumed.
.It Fl d Ar device
@@ -92,7 +96,7 @@ Some of the code was taken from
.Xr fdformat 1 .
.Sh AUTHOR
The program has been contributed by
-Poul-Henning Kamp <phk@login.dknet.dk>
+.An Poul-Henning Kamp Aq phk@login.dknet.dk
.Sh BUGS
Diagnostics are less than complete at present.
diff --git a/usr.sbin/fdwrite/fdwrite.c b/usr.sbin/fdwrite/fdwrite.c
index 908bb86..e0c176b 100644
--- a/usr.sbin/fdwrite/fdwrite.c
+++ b/usr.sbin/fdwrite/fdwrite.c
@@ -6,18 +6,18 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id$
+ * $Id: fdwrite.c,v 1.6 1997/02/22 16:05:49 peter Exp $
*
*/
+#include <ctype.h>
+#include <err.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <strings.h>
-#include <ctype.h>
+#include <unistd.h>
-#include <errno.h>
#include <machine/ioctl_fd.h>
int
@@ -54,9 +54,9 @@ format_track(int fd, int cyl, int secs, int head, int rate,
}
static void
-usage ()
+usage()
{
- printf("Usage:\n\tfdwrite [-v] [-y] [-f inputfile] [-d device]\n");
+ fprintf(stderr, "usage: fdwrite [-v] [-y] [-f inputfile] [-d device]\n");
exit(2);
}
@@ -71,7 +71,7 @@ main(int argc, char **argv)
FILE *tty;
setbuf(stdout,0);
- while((c = getopt(argc, argv, "d:s:f:vy")) != -1)
+ while((c = getopt(argc, argv, "d:f:vy")) != -1)
switch(c) {
case 'd': /* Which drive */
device = optarg;
@@ -81,10 +81,8 @@ main(int argc, char **argv)
if (inputfd >= 0)
close(inputfd);
inputfd = open(optarg,O_RDONLY);
- if (inputfd < 0) {
- perror(optarg);
- exit(1);
- }
+ if (inputfd < 0)
+ err(1, "%s", optarg);
break;
case 'v': /* Toggle verbosity */
@@ -109,10 +107,8 @@ main(int argc, char **argv)
usage();
tty = fopen("/dev/tty","r+");
- if(!tty) {
- perror("/dev/tty");
- exit(1);
- }
+ if(!tty)
+ err(1, "/dev/tty");
setbuf(tty,0);
for(j=1;j > 0;) {
@@ -127,24 +123,20 @@ main(int argc, char **argv)
}
}
- if((fd = open(device, O_RDWR)) < 0) {
- perror(device);
- exit(1);
- }
+ if((fd = open(device, O_RDWR)) < 0)
+ err(1, "%s", device);
- if(ioctl(fd, FD_GTYPE, &fdt) < 0) {
- fprintf(stderr, "fdformat: not a floppy disk: %s\n", device);
- exit(1);
- }
+ if(ioctl(fd, FD_GTYPE, &fdt) < 0)
+ errx(1, "not a floppy disk: %s", device);
bpt = fdt.sectrac * (1<<fdt.secsize) * 128;
if(!trackbuf) {
trackbuf = malloc(bpt);
- if(!trackbuf) { perror("malloc"); exit(1); }
+ if(!trackbuf) errx(1, "malloc");
}
if(!vrfybuf) {
vrfybuf = malloc(bpt);
- if(!vrfybuf) { perror("malloc"); exit(1); }
+ if(!vrfybuf) errx(1, "malloc");
}
if(fdn == 1) {
@@ -172,30 +164,15 @@ main(int argc, char **argv)
fdt.f_inter);
if(verbose) putc('F',stdout);
- if (lseek (fd, (long) track*bpt, 0) < 0) {
- perror("lseek");
- exit (1);
- }
- if (write (fd, trackbuf, bpt) != bpt) {
- perror("write");
- exit (1);
- }
+ if (lseek (fd, (long) track*bpt, 0) < 0) err(1, "lseek");
+ if (write (fd, trackbuf, bpt) != bpt) err(1, "write");
if(verbose) putc('W',stdout);
- if (lseek (fd, (long) track*bpt, 0) < 0) {
- perror("lseek");
- exit (1);
- }
- if (read (fd, vrfybuf, bpt) != bpt) {
- perror("read");
- exit (1);
- }
+ if (lseek (fd, (long) track*bpt, 0) < 0) err(1, "lseek");
+ if (read (fd, vrfybuf, bpt) != bpt) err(1, "read");
if(verbose) putc('R',stdout);
- if (memcmp(trackbuf,vrfybuf,bpt)) {
- perror("compare");
- exit (1);
- }
+ if (memcmp(trackbuf,vrfybuf,bpt)) err(1, "compare");
if(verbose) putc('C',stdout);
memset(trackbuf,0,bpt);
OpenPOWER on IntegriCloud