1 /* $NetBSD: rawwrite.c,v 1.10 2009/03/18 10:22:26 cegger Exp $ */
4 * Copyright (c) 1995 Leo Weppelman.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #define SECT_SIZE 512 /* Sector size */
37 #define NSECT_DD 18 /* Sectors per cylinder 720Kb */
38 #define NSECT_HD 36 /* Sectors per cylinder 1.44Mb */
39 #define NTRK 80 /* Number of tracks */
41 static void help
PROTO((void));
42 static void usage
PROTO((void));
43 static void brwrite
PROTO((char *, int, int));
45 char buf
[NSECT_HD
* SECT_SIZE
];
46 int h_flag
= 0; /* Show help */
47 int v_flag
= 0; /* Verbose (a dot for each track copied) */
48 int V_flag
= 0; /* Show version */
51 const char version
[] = "$Revision: 1.11 $";
54 main(int argc
, char *argv
[])
69 while ((ch
= getopt(argc
, argv
, "hHvVwo:")) != -1) {
78 redirect_output(optarg
);
97 eprintf("%s\r\n", version
);
102 infile
= argv
[optind
];
104 if ((fd
= open(infile
, O_RDONLY
)) < 0)
105 fatal(-1, "Cannot open '%s'\n", infile
);
107 for (i
= 0; i
< NTRK
; i
++) {
108 n
= read(fd
, buf
, nsect
* SECT_SIZE
);
110 eprintf("Only %d tracks in input file\r\n", i
);
114 fatal(-1, "\n\rRead error on '%s'\n", infile
);
115 if (n
!= (nsect
* SECT_SIZE
))
116 fatal(-1, "\n\rUnexpected short-read on '%s'\n", infile
);
122 brwrite(buf
, i
, nsect
);
131 brwrite(char *buf
, int trk
, int spt
)
134 * These need to be static with my version of osbind.h :-(
136 static u_char trbuf
[NSECT_HD
* SECT_SIZE
* 2];
137 static u_int sideno
= 0;
139 for (sideno
= 0; sideno
< 2; sideno
++) {
140 if (Flopfmt(trbuf
, 0, 0, spt
/2, trk
, sideno
, 1,
142 fatal(-1, "Format error");
143 if (Flopwr(buf
, 0, 0, 1, trk
, sideno
, spt
/2))
144 fatal(-1, "Write error");
145 buf
+= (spt
/2) * SECT_SIZE
;
151 eprintf("Usage: %s [-hvVw] [-o <log-file>] <infile>\r\n", progname
);
159 write a raw floppy-image to disk\r
161 Usage: %s [-hvVw] [-o <log-file>] <infile>\r
163 Description of options:\r
165 \t-h What you're getting right now.\r
166 \t-H Write high density floppies.\r
167 \t-o Write output to both <output file> and stdout.\r
168 \t-v Show a '.' for each track written.\r
169 \t-V Print program version.\r
170 \t-w Wait for a keypress before exiting.\r