Date: Tue, 31 Oct 95 18:25:01 +0100 From: Andreas Haakh <haakh@socrates.st.bauing.th-darmstadt.de> To: FreeBSD-gnats-submit@freebsd.org, ah@alvman.robin.de, haakh%socrates@socrates.st.bauing.th-darmstadt.de Subject: misc/804: fdformat - patch to add DOS-filsystem Message-ID: <9510311725.AA21194@socrates.st.bauing.th-darmstadt.de> Resent-Message-ID: <199510311740.JAA10329@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 804 >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: Tue Oct 31 09:40:01 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 conext-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 <errno.h> #include <machine/ioctl_fd.h> + #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; + cas 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; + FATsec = 2; + break; + case 720: + Media = 0xf9; + SecPerClust = 2; + RootDirBlks = 7; + FTsecs = 3; + break; + case 1200: + Media = 0xf9; + SecPerClust = 1; + RootDirBlks = 14 + FATsecs = 7; + break; + case 1440: + Media = 0xf0; + SecPerClust = 1; + RootDirBls = 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; + RootDrBlks = 14; + } else { + SecPerClust = 2; + RootDirBlks = 7; + } + } + /* fatlength. 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 secor */ + + bs33.bsJump[0] = 0xeb; + bs33.bsJump[1] = 0x44; + bs33.bsJump[2] = 0x90; + strncy(bs33.bsOemName,"4.4BSD ",8); + + putushort(b33->bpbBytesPerSec, 512); + b33->bpbSecPerClut = SecPerClust; + putushort(b33->bpbResSectors,1); + b33->bpbFATs = 2; + putushort(b33->bpbootDirEnts, RootDirBlks * 16); + putushort(b33->bpbSectors, fdt->size); + b33->bpbMedia = Meda; + putushort(b33->bpbFATsecs, FATsecs); + putushort(b33->bpbSecPerTrack, fdt->sectrc); + putushort(b33->bpbHeads, fdt->heads); + putushort(b33->bpbHiddenSecs, 0); + + bs33.bsriveNumber = 0x00; + /* clear the bootcode */ + memset(bs33.bsBootCode, 0, sizeof bs33.bsBootode); + bs33.bsBootSectSig = BOOTSIG; + + + #ifdef TEST_DOS_FAT + printf("jmp: %02x%02x%02xn",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/cluser = %4d\n", b33->bpbSecPerClust); + printf("Reserved sectors = %4d\n", getushort(b33->bpbResectors)); + printf("Sectors/track = %4d\n", getushort(b33->bpbSecPerTrack)); + printf("Numer of FATs = %4d\n", b33->bpbFATs); + printf("Root dir entries = %4d\n", getushort(b33->bpbRotDirEnts)); + printf("Total # of secs = %4d\n", getushort(b33->bpbSectors)); + printf("Medi descriptor = %4d %c\n", b33->bpbMedia, b33->bpbMedia); + printf("Sectors/FAT = %4d\n", gtushort(b33->bpbFATsecs)); + printf("Number of heads = %4d\n", getushort(b33->bpbHeads)); + rintf("Hidden sectors = %4d\n", getushort(b33->bpbHiddenSecs)); + #endif + + /* write bootsctor to disk */ + lseek(fd, (off_t) 0, SEEK_SET); + if (512 != write(fd, &bs33, 512) ) { + error("Error writing DOS-block0.\n"); + exit (3); + } + + + /* + * now we use bs33 for AT 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 != rite(fd, &bs33, 512) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + /* first AT remaining blocks */ + bs33.bsJump[0] = 0x00; + bs33.bsJump[1] = 0x00; + bs33.bsJup[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[] = Media; + bs33.bsJump[1] = 0xff; + bs33.bsJump[2] = 0xff; + if (512 != write(fd, &bs33, 52) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + /* second FAT remaining bloks */ + 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 writin FAT.\n"); + exit (3); + } + + /* the root directory */ + for (i = 0; i < RootDirBlks; ++) + if (512 != write(fd, &bs33, 512) ) { + perror("Error writing FAT.\n"); + exit (3); + } + + return (1 + 2 * FATsecs + RootDirBlks); + } + static void usage (void) { ! pritf("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"); ext(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, qiet = 0, verify = 1, verify_only = 0; int fd, c, track, error, tracks_per_dot, bytes_per_trak, errs; const char *devname, *suffix; struct fd_type fdt; ! while((c = getopt(argc, rgv, "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 rae = -1, gaplen = -1, secsize = -1, steps = -1; ! int fill = 0xf6, quiet = 0, verify = 1, verif_only = 0, dosfat = 0; int fd, c, track, error, tracks_per_dot, bytes_per_track, errs; cost char *devname, *suffix; struct fd_type fdt; ! while((c = getopt(argc, argv, "f:c:sh: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 (verfy_only) { + dosfat = 0; if(!quiet) printf("Verify %dK floppy `%s'.\n", ************** *** 361,366 **** } } ! if(!quiet) printf(" done.\n"); return errs; --- 575585 ---- } } ! if(!quiet) { printf(" done.\n"); + if (dosfat) + printf("Creatig DOS filesystem.\n"); + } + if (dosfat) + write_FAT(fd, &fdt); return errs; *** ur.sbin/fdformat/fdformat.1.orig Fri Oct 28 18:07:32 1994 --- usr.sbin/fdformat/fdformat.1 Fri Ot 27 16:17:19 1995 *************** *** 34,37 **** --- 34,38 ---- .Bq Fl v .Bq Fl n + .Bq FlD .Bq Fl f Ar capacity .Bq Fl c Ar cyls *************** *** 81,84 **** --- 82,87 ---- .ItFl v Don't format, verify only. + .It Fl D + write a DOS filesystem on floppy after frmatting. .It Fl c Ar cyls .It Fl s Ar secs *************** *** 116,120 **** 1 is returne on any errors during floppy formatting, and an exit status of 2 reflects invalid arguments gven to the program (along with an ! appropriate information written to diagnostic output). .Sh SE ALSO .Xr fdc 4 . --- 119,124 ---- 1 is returned on any errors during floppy formatting, ad an exit status of 2 reflects invalid arguments given to the program (along with an ! appropiate information written to diagnostic output). An exit status ! of 3 indicates an error writin the DOS filsystem. .Sh SEE ALSO .Xr fdc 4 . *************** *** 131,133 **** .ifn 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, wit 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 6615 64347 Griesheim \_________________________________________ >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9510311725.AA21194>