From bf53b5e2fbb35e73d8a47dc5675a2217f247d604 Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 10 Feb 1994 01:15:01 +0000 Subject: [PATCH] Add interleave > 1 support by Poul-Henning Kamp. Chack valid range of sectors per track. --- usr.sbin/fdformat/fdformat.1 | 2 -- usr.sbin/fdformat/fdformat.c | 25 +++++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/usr.sbin/fdformat/fdformat.1 b/usr.sbin/fdformat/fdformat.1 index fce0f7e9bac2..b395c9e153f0 100644 --- a/usr.sbin/fdformat/fdformat.1 +++ b/usr.sbin/fdformat/fdformat.1 @@ -111,8 +111,6 @@ An exit status of 0 is returned upon successful operation. Exit status 1 is returned on any errors during floppy formatting, and an exit status of 2 reflects invalid arguments given to the program (along with an appropriate information written to diagnostic output). -.Sh BUGS -The only valid interleave factor value is 1. .Sh SEE ALSO .Xr fd 4 . .Sh HISTORY diff --git a/usr.sbin/fdformat/fdformat.c b/usr.sbin/fdformat/fdformat.c index f29013d80ff3..dc8fba87ff04 100644 --- a/usr.sbin/fdformat/fdformat.c +++ b/usr.sbin/fdformat/fdformat.c @@ -51,10 +51,18 @@ static void format_track(int fd, int cyl, int secs, int head, int rate, - int gaplen, int secsize, int fill) + int gaplen, int secsize, int fill,int interleave) { struct fd_formb f; - register int i; + register int i,j; + int il[FD_MAX_NSEC]; + + memset(il,0,sizeof il); + for(j = 0, i = 1; i <= secs; i++) { + while(il[(j%secs)+1]) j++; + il[(j%secs)+1] = i; + j += interleave; + } f.format_version = FD_FORMAT_VERSION; f.head = head; @@ -68,7 +76,7 @@ format_track(int fd, int cyl, int secs, int head, int rate, for(i = 0; i < secs; i++) { f.fd_formb_cylno(i) = cyl; f.fd_formb_headno(i) = head; - f.fd_formb_secno(i) = i + 1; + f.fd_formb_secno(i) = il[i+1]; f.fd_formb_secsize(i) = secsize; } if(ioctl(fd, FD_FORM, (caddr_t)&f) < 0) { @@ -274,15 +282,15 @@ main(int argc, char **argv) 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); + exit(2); + } 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; - if (fdt.f_inter != 1) { - fprintf(stderr, "fdformat: can't format with interleave != 1 yet\n"); - exit(2); - } bytes_per_track = fdt.sectrac * (1<