From owner-freebsd-bugs Wed Nov 1 10:40:02 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id KAA24506 for bugs-outgoing; Wed, 1 Nov 1995 10:40:02 -0800 Received: (from gnats@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id KAA24500 ; Wed, 1 Nov 1995 10:40:01 -0800 Resent-Date: Wed, 1 Nov 1995 10:40:01 -0800 Resent-Message-Id: <199511011840.KAA24500@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, ah@alvman.RoBIN.de Received: from flinx.RoBIN.de (root@flinx.RoBIN.de [193.174.7.25]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id KAA24423 for ; Wed, 1 Nov 1995 10:33:12 -0800 Received: (from uucp@localhost) by flinx.RoBIN.de (8.6.9/8.6.9) with UUCP id VAA24321 for FreeBSD-gnats-submit@freebsd.org; Wed, 1 Nov 1995 21:00:02 +0100 Received: (from ah@localhost) by alvman.RoBIN.de (8.6.11/8.6.9) id SAA04612; Fri, 27 Oct 1995 18:35:04 +0100 Message-Id: <199510271735.SAA04612@alvman.RoBIN.de> Date: Fri, 27 Oct 1995 18:35:04 +0100 From: Andreas Haakh Reply-To: ah@alvman.RoBIN.de To: FreeBSD-gnats-submit@freebsd.org, ah@alvman.RoBIN.de X-Send-Pr-Version: 3.2 Subject: misc/808: fdformat - patch to add DOS-filsystem Sender: owner-bugs@freebsd.org Precedence: bulk >Number: 808 >Category: misc >Synopsis: fdformat did not create DOS-filesystem >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Nov 1 10:40:00 PST 1995 >Last-Modified: >Originator: Andreas Haakh >Organization: not at all... >Release: FreeBSD 2.0.5-RELEASE i386 >Environment: irrelevant >Description: fdformat just did a raw format on floppies. You could not mount_msdos them. >How-To-Repeat: obvious >Fix: I added an option (-D) to write a dos-filesystem to the floppies. The changes are based on msdosfs and mformat (mtools). Files included from /sys/msdosfs/ should be moved to /usr/include/... The context-diffs are included and change the following files relative to /usr/src/ : sys/msdosfs/bootsect.h (a bug - has probably no influence on msdosfs) usr.sbin/fdformat/fdformat.c usr.sbin/fdformat/fdformat.1 //////////////////////START OF PATCH//////////////////////////////////////// *** sys/msdosfs/bootsect.h.orig Fri Oct 27 12:56:37 1995 --- sys/msdosfs/bootsect.h Fri Oct 27 12:56:19 1995 *************** *** 28,32 **** char bsBPB[19]; /* BIOS parameter block */ char bsDriveNumber; /* drive number (0x80) */ ! char bsBootCode[474]; /* pad so structure is 512 bytes long */ u_short bsBootSectSig; #define BOOTSIG 0xaa55 --- 28,32 ---- char bsBPB[19]; /* BIOS parameter block */ char bsDriveNumber; /* drive number (0x80) */ ! char bsBootCode[479]; /* pad so structure is 512 bytes long */ u_short bsBootSectSig; #define BOOTSIG 0xaa55 *** usr.sbin/fdformat/fdformat.c.orig Tue May 30 05:47:39 1995 --- usr.sbin/fdformat/fdformat.c Fri Oct 27 18:10:59 1995 *************** *** 37,40 **** --- 37,44 ---- * Andrew A. Chernov, ache@astral.msk.su * Thu Jan 27 00:47:24 MSK 1994 + * + * Added creation of DOS filesystem + * Andreas Haakh, ah@alman.RoBIN.de + * Fri Oct 27 18:10:59 1995 */ *************** *** 48,51 **** --- 52,57 ---- #include #include + #include "/sys/msdosfs/bootsect.h" /* for DOS filesystem */ + #include "/sys/msdosfs/bpb.h" static void *************** *** 139,146 **** } static void usage (void) { ! printf("Usage:\n\tfdformat [-q] [-n | -v] [-f #] [-c #] [-s #] [-h #]\n"); printf("\t\t [-r #] [-g #] [-i #] [-S #] [-F #] [-t #] devname\n"); printf("Options:\n"); --- 145,355 ---- } + static int + write_FAT(int fd, struct fd_type *fdt) { + + int i, Media, SecPerClust, RootDirBlks, FATsecs; + struct bootsector33 bs33; + struct byte_bpb33 *b33; + + + b33 = (struct byte_bpb33 *) bs33.bsBPB; + + if (sizeof(bs33) != 512) { + fprintf(stderr,"Check definition of struct bootsector33!\n"); + fprintf(stderr,"Sizof (struct bootsector33) != 512.\n"); + exit (3); + } + + + /* The following code is heavily borrowed from msdosfs + * and mformat from mtools. + * + * I have no documentation about the FAT. So I just rely + * on those two sources :-)) + * + * This function returns the number of written boot, FAT + * and root-dir blocks. + */ + + switch(fdt->size/2) { /* size in KBytes */ + int FatGuess, NumClus; + case 160: + Media = 0xfe; + SecPerClust = 1; + RootDirBlks = 4; + FATsecs = 1; + break; + case 180: + Media = 0xfc; + SecPerClust = 1; + RootDirBlks = 4; + FATsecs = 2; + break; + case 320: + Media = 0xff; + SecPerClust = 2; + RootDirBlks = 7; + FATsecs = 1; + break; + case 360: + Media = 0xfd; + SecPerClust = 2; + RootDirBlks = 7; + FATsecs = 2; + break; + case 720: + Media = 0xf9; + SecPerClust = 2; + RootDirBlks = 7; + FATsecs = 3; + break; + case 1200: + Media = 0xf9; + SecPerClust = 1; + RootDirBlks = 14; + FATsecs = 7; + break; + case 1440: + Media = 0xf0; + SecPerClust = 1; + RootDirBlks = 14; + FATsecs = 9; + break; + case 800: + case 820: + case 1480: + default: /* non standard format */ + Media = 0xf0; + if (fdt->heads == 1) { + SecPerClust = 1; + RootDirBlks = 4; + }else { + if (fdt->size > 2000) { + SecPerClust = 1; + RootDirBlks = 14; + } else { + SecPerClust = 2; + RootDirBlks = 7; + } + } + /* fat length. 341 is the number of 12 bit fat entries + * per sector */ + FatGuess = ((fdt->size / SecPerClust) / 341.0) + 0.95; + NumClus = (fdt->size - RootDirBlks - 2 * FatGuess - 1) + / SecPerClust; + FATsecs = (NumClus / 341.) + 1; + break; + } + + /* Set up the boot sector */ + + bs33.bsJump[0] = 0xeb; + bs33.bsJump[1] = 0x44; + bs33.bsJump[2] = 0x90; + strncpy(bs33.bsOemName,"4.4BSD ",8); + + putushort(b33->bpbBytesPerSec, 512); + b33->bpbSecPerClust = SecPerClust; + putushort(b33->bpbResSectors,1); + b33->bpbFATs = 2; + putushort(b33->bpbRootDirEnts, RootDirBlks * 16); + putushort(b33->bpbSectors, fdt->size); + b33->bpbMedia = Media; + putushort(b33->bpbFATsecs, FATsecs); + putushort(b33->bpbSecPerTrack, fdt->sectrac); + putushort(b33->bpbHeads, fdt->heads); + putushort(b33->bpbHiddenSecs, 0); + + bs33.bsDriveNumber = 0x00; + /* clear the bootcode */ + memset(bs33.bsBootCode, 0, sizeof bs33.bsBootCode); + bs33.bsBootSectSig = BOOTSIG; + + + #ifdef TEST_DOS_FAT + printf("jmp: %02x%02x%02x\n",bs33.bsJump[0], + bs33.bsJump[1], bs33.bsJump[2]); + printf("OEM: %s\n",bs33.bsOemName); + printf("Drv: %04x\n", bs33.bsDriveNumber); + printf("Sig: %04x\n", bs33.bsBootSectSig); + + printf("Bytes/sector = %4d\n", getushort(b33->bpbBytesPerSec)); + printf("Sectors/cluster = %4d\n", b33->bpbSecPerClust); + printf("Reserved sectors = %4d\n", getushort(b33->bpbResSectors)); + printf("Sectors/track = %4d\n", getushort(b33->bpbSecPerTrack)); + printf("Number of FATs = %4d\n", b33->bpbFATs); + printf("Root dir entries = %4d\n", getushort(b33->bpbRootDirEnts)); + printf("Total # of secs = %4d\n", getushort(b33->bpbSectors)); + printf("Media descriptor = %4d %c\n", b33->bpbMedia, b33->bpbMedia); + printf("Sectors/FAT = %4d\n", getushort(b33->bpbFATsecs)); + printf("Number of heads = %4d\n", getushort(b33->bpbHeads)); + printf("Hidden sectors = %4d\n", getushort(b33->bpbHiddenSecs)); + #endif + + /* write bootsector to disk */ + lseek(fd, (off_t) 0, SEEK_SET); + if (512 != write(fd, &bs33, 512) ) { + perror("Error writing DOS-block0.\n"); + exit (3); + } + + + /* + * now we use bs33 for FAT and root directory + */ + memset(&bs33, 0, (size_t) 512); + + /* first FAT first block */ + bs33.bsJump[0] = Media; + bs33.bsJump[1] = 0xff; + bs33.bsJump[2] = 0xff; + if (512 != write(fd, &bs33, 512) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + /* first FAT remaining blocks */ + bs33.bsJump[0] = 0x00; + bs33.bsJump[1] = 0x00; + bs33.bsJump[2] = 0x00; + for (i = 1; i < FATsecs; i++) + if (512 != write(fd, &bs33, 512) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + /* second FAT first block */ + bs33.bsJump[0] = Media; + bs33.bsJump[1] = 0xff; + bs33.bsJump[2] = 0xff; + if (512 != write(fd, &bs33, 512) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + /* second FAT remaining blocks */ + bs33.bsJump[0] = 0x00; + bs33.bsJump[1] = 0x00; + bs33.bsJump[2] = 0x00; + for (i = 1; i < FATsecs; i++) + if (512 != write(fd, &bs33, 512) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + /* the root directory */ + for (i = 0; i < RootDirBlks; i++) + if (512 != write(fd, &bs33, 512) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + return (1 + 2 * FATsecs + RootDirBlks); + } + static void usage (void) { ! printf("Usage:\n\tfdformat [-q] [-n | -v] [-D] [-f #] [-c #] [-s #] [-h #]\n"); printf("\t\t [-r #] [-g #] [-i #] [-S #] [-F #] [-t #] devname\n"); printf("Options:\n"); *************** *** 161,164 **** --- 370,374 ---- printf("\t-F #\tspecify fill byte\n"); printf("\t-t #\tnumber of steps per track\n"); + printf("\t-D #\twrite a DOS filsystem on floppy\n"); exit(2); } *************** *** 189,198 **** 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; struct fd_type fdt; ! while((c = getopt(argc, argv, "f:c:s:h:r:g:S:F:t:i:qvn")) != -1) switch(c) { case 'f': /* format in kilobytes */ --- 399,408 ---- 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, dosfat = 0; int fd, c, track, error, tracks_per_dot, bytes_per_track, errs; const char *devname, *suffix; struct fd_type fdt; ! while((c = getopt(argc, argv, "f:c:s:h:r:g:S:F:t:i:qvnD")) != -1) switch(c) { case 'f': /* format in kilobytes */ *************** *** 243,246 **** --- 453,459 ---- verify = 0; break; + case 'D': + dosfat = 1; + break; case 'v': *************** *** 309,312 **** --- 522,526 ---- if (verify_only) { + dosfat = 0; if(!quiet) printf("Verify %dK floppy `%s'.\n", *************** *** 361,366 **** } } ! if(!quiet) printf(" done.\n"); return errs; --- 575,585 ---- } } ! if(!quiet) { printf(" done.\n"); + if (dosfat) + printf("Creating DOS filesystem.\n"); + } + if (dosfat) + write_FAT(fd, &fdt); return errs; *** usr.sbin/fdformat/fdformat.1.orig Fri Oct 28 18:07:32 1994 --- usr.sbin/fdformat/fdformat.1 Fri Oct 27 16:17:19 1995 *************** *** 34,37 **** --- 34,38 ---- .Bq Fl v .Bq Fl n + .Bq Fl D .Bq Fl f Ar capacity .Bq Fl c Ar cyls *************** *** 81,84 **** --- 82,87 ---- .It Fl v Don't format, verify only. + .It Fl D + write a DOS filesystem on floppy after formatting. .It Fl c Ar cyls .It Fl s Ar secs *************** *** 116,120 **** 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 SEE ALSO .Xr fdc 4 . --- 119,124 ---- 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). An exit status ! of 3 indicates an error writing the DOS filsystem. .Sh SEE ALSO .Xr fdc 4 . *************** *** 131,133 **** .if n Joerg Wunsch, .if t J\(:org Wunsch, ! Dresden, with changes by Serge Vakulenko and Andrew A. Chernov, Moscow. --- 135,138 ---- .if n Joerg Wunsch, .if t J\(:org Wunsch, ! Dresden, with changes by Serge Vakulenko, Andrew A. Chernov, Moscow and ! Andreas Haakh, Darmstadt. //////////////////////END OF PATCH//////////////////////////////////////// -- Andreas Haakh \ ah@alvman.RoBIN.de Kirschberg 12 b \ +49 6155 62615 64347 Griesheim \_________________________________________ >Audit-Trail: >Unformatted: