* Copyright (C) 1992-1993 by Joerg Wunsch, Dresden
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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 AUTHOR ``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 REGENTS 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
* Added FD_GTYPE ioctl, verifying, proportional indicators.
* Serge Vakulenko, vak@zebub.msk.su
* Sat Dec 18 17:45:47 MSK 1993
* Final adaptation, change format/verify logic, add separate
* format gap/interleave values
* Andrew A. Chernov, ache@astral.msk.su
* Thu Jan 27 00:47:24 MSK 1994
#include <machine/ioctl_fd.h>
#include <../i386/isa/fdreg.h> /* XXX should be in <machine> dir */
format_track(int fd
, int cyl
, int secs
, int head
, int rate
,
int gaplen
, int secsize
, int fill
,int interleave
)
for(j
= 0, i
= 1; i
<= secs
; i
++) {
while(il
[(j
%secs
)+1]) j
++;
f
.format_version
= FD_FORMAT_VERSION
;
f
.fd_formb_secshift
= secsize
;
f
.fd_formb_gaplen
= gaplen
;
f
.fd_formb_fillbyte
= fill
;
for(i
= 0; i
< secs
; i
++) {
f
.fd_formb_cylno(i
) = cyl
;
f
.fd_formb_headno(i
) = head
;
f
.fd_formb_secno(i
) = il
[i
+1];
f
.fd_formb_secsize(i
) = secsize
;
if(ioctl(fd
, FD_FORM
, (caddr_t
)&f
) < 0) {
perror("\nfdformat: ioctl(FD_FORM)");
verify_track(int fd
, int track
, int tracksize
)
fprintf (stderr
, "\nfdformat: out of memory\n");
if (lseek (fd
, (long) track
*tracksize
, 0) < 0)
if (read (fd
, buf
, tracksize
) != tracksize
)
makename(const char *arg
, const char *suffix
)
static char namebuff
[20]; /* big enough for "/dev/rfd0a"... */
if(*arg
== '\0') /* ??? */
if(*arg
== '/') /* do not convert absolute pathnames */
strcpy(namebuff
, "/dev/r");
strncat(namebuff
, arg
, 3);
strcat(namebuff
, suffix
);
printf("Usage:\n\tfdformat [-q] [-n | -v] [-f #] [-c #] [-s #] [-h #]\n");
printf("\t\t [-r #] [-g #] [-i #] [-S #] [-F #] [-t #] devname\n");
printf("\t-q\tsupress any normal output, don't ask for confirmation\n");
printf("\t-n\tdon't verify floppy after formatting\n");
printf("\t-v\tdon't format, verify only\n");
printf("\t-f #\tspecify desired floppy capacity, in kilobytes;\n");
printf("\t\tvalid choices are 360, 720, 800, 820, 1200, 1440, 1480, 1720\n");
printf("\tdevname\tthe full name of floppy device or in short form fd0, fd1\n");
printf("Obscure options:\n");
printf("\t-c #\tspecify number of cylinders, 40 or 80\n");
printf("\t-s #\tspecify number of sectors per track, 9, 10, 15 or 18\n");
printf("\t-h #\tspecify number of floppy heads, 1 or 2\n");
printf("\t-r #\tspecify data rate, 250, 300 or 500 kbps\n");
printf("\t-g #\tspecify gap length\n");
printf("\t-i #\tspecify interleave factor\n");
printf("\t-S #\tspecify sector size, 0=128, 1=256, 2=512 bytes\n");
printf("\t-F #\tspecify fill byte\n");
printf("\t-t #\tnumber of steps per track\n");
reply
[sizeof(reply
)-1] = 0;
if (! fgets (reply
, sizeof(reply
)-1, stdin
))
for (p
=reply
; *p
==' ' || *p
=='\t'; ++p
)
if (*p
=='n' || *p
=='N' || *p
=='\n' || *p
=='\r')
printf("Answer `yes' or `no': ");
main(int argc
, char **argv
)
int format
= -1, 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
;
const char *devname
, *suffix
;
while((c
= getopt(argc
, argv
, "f:c:s:h:r:g:S:F:t:i:qvn")) != -1)
case 'f': /* format in kilobytes */
case 'c': /* # of cyls */
case 's': /* # of secs per track */
case 'h': /* # of heads */
case 'r': /* transfer rate, kilobyte/sec */
case 'g': /* length of GAP3 to format with */
case 'S': /* sector size shift factor (1 << S)*128 */
case 'F': /* fill byte, C-like notation allowed */
fill
= (int)strtol(optarg
, (char **)0, 0);
case 't': /* steps per track */
case 'i': /* interleave factor */
fprintf(stderr
, "fdformat: bad floppy size: %dK\n", format
);
case -1: suffix
= ""; break;
case 360: suffix
= ".360"; break;
case 720: suffix
= ".720"; break;
case 800: suffix
= ".800"; break;
case 820: suffix
= ".820"; break;
case 1200: suffix
= ".1200"; break;
case 1440: suffix
= ".1440"; break;
case 1480: suffix
= ".1480"; break;
case 1720: suffix
= ".1720"; break;
devname
= makename(argv
[optind
], suffix
);
if((fd
= open(devname
, O_RDWR
)) < 0) {
if(ioctl(fd
, FD_GTYPE
, &fdt
) < 0) {
fprintf(stderr
, "fdformat: not a floppy disk: %s\n", devname
);
case 250: fdt
.trans
= FDC_250KBPS
; break;
case 300: fdt
.trans
= FDC_300KBPS
; break;
case 500: fdt
.trans
= FDC_500KBPS
; break;
fprintf(stderr
, "fdformat: invalid transfer rate: %d\n", rate
);
if (cyls
>= 0) fdt
.tracks
= cyls
;
if (secs
>= 0) fdt
.sectrac
= secs
;
if (fdt
.sectrac
> FD_MAX_NSEC
) {
fprintf(stderr
, "fdformat: too many sectors per track, max value is %d\n", FD_MAX_NSEC
);
if (heads
>= 0) fdt
.heads
= heads
;
if (gaplen
>= 0) fdt
.f_gap
= gaplen
;
if (secsize
>= 0) fdt
.secsize
= secsize
;
if (steps
>= 0) fdt
.steptrac
= steps
;
if (intleave
>= 0) fdt
.f_inter
= intleave
;
bytes_per_track
= fdt
.sectrac
* (1<<fdt
.secsize
) * 128;
tracks_per_dot
= fdt
.tracks
* fdt
.heads
/ 40;
printf("Verify %dK floppy `%s'.\n",
fdt
.tracks
* fdt
.heads
* bytes_per_track
/ 1024,
printf("Format %dK floppy `%s'? (y/n): ",
fdt
.tracks
* fdt
.heads
* bytes_per_track
/ 1024,
printf("Not confirmed.\n");
printf("Processing ----------------------------------------\r");
for (track
= 0; track
< fdt
.tracks
* fdt
.heads
; track
++) {
format_track(fd
, track
/ fdt
.heads
, fdt
.sectrac
,
track
% fdt
.heads
, fdt
.trans
, fdt
.f_gap
,
fdt
.secsize
, fill
, fdt
.f_inter
);
if(!quiet
&& !((track
+ 1) % tracks_per_dot
)) {
if (verify_track(fd
, track
, bytes_per_track
) < 0)
if(!quiet
&& !((track
+ 1) % tracks_per_dot
)) {