From owner-p4-projects Wed Dec 4 13:45:41 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 96B6C37B404; Wed, 4 Dec 2002 13:45:35 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2EBD537B401 for ; Wed, 4 Dec 2002 13:45:35 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id C1DBF43E4A for ; Wed, 4 Dec 2002 13:45:34 -0800 (PST) (envelope-from green@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id gB4LfImV010278 for ; Wed, 4 Dec 2002 13:41:18 -0800 (PST) (envelope-from green@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id gB4LfH0K010260 for perforce@freebsd.org; Wed, 4 Dec 2002 13:41:17 -0800 (PST) Date: Wed, 4 Dec 2002 13:41:17 -0800 (PST) Message-Id: <200212042141.gB4LfH0K010260@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to green@freebsd.org using -f From: Brian Feldman Subject: PERFORCE change 21932 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://perforce.freebsd.org/chv.cgi?CH=21932 Change 21932 by green@green_laptop_2 on 2002/12/04 13:41:09 Modify disklabel(8) to accept modification of disklabel::d_bbsize, called "boot block size" in the text description. Following this, correct 'disklabel -B' so that it doesn't try to modify the disklabel sector directly when it writes a boot block; in fact, it shouldn't need to modify it at all, but as of now it still updates it via DIOCWDINFO. That and -r mode should be removed, really. Point is, I can get disklabel(8) to now install the UFS2 boot2 correctly and boot from UFS2! Affected files ... .. //depot/projects/trustedbsd/mac/sbin/disklabel/disklabel.c#15 edit Differences ... ==== //depot/projects/trustedbsd/mac/sbin/disklabel/disklabel.c#15 (text+ko) ==== @@ -97,6 +97,12 @@ #ifndef BBSIZE #define BBSIZE 8192 /* size of boot area, with label */ #endif +/* + * Define an upper boundary for the boot blocks. + */ +#ifndef MAXBBSIZE +#define MAXBBSIZE 262144 /* max size of boot area, with label */ +#endif /* FIX! These are too low, but are traditional */ #define DEFAULT_NEWFS_BLOCK 8192U @@ -142,7 +148,7 @@ char namebuf[BBSIZE], *np = namebuf; struct disklabel lab; -char bootarea[BBSIZE]; +char bootarea[MAXBBSIZE]; char blank[] = ""; char unknown[] = "unknown"; @@ -233,7 +239,6 @@ argv += optind; #if NUMBOOT > 0 if (installboot) { - rflag++; if (op == UNSPEC) op = WRITEBOOT; } else { @@ -345,6 +350,7 @@ tlab = *lp; if (argc == 2) makelabel(argv[1], 0, &lab); + lab.d_bbsize = lp->d_bbsize; lp = makebootarea(bootarea, &lab, f); *lp = tlab; if (checklabel(lp) == 0) @@ -404,7 +410,7 @@ lp->d_magic2 = DISKMAGIC; lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - if (rflag) { + if (rflag || op == WRITEBOOT) { /* * First set the kernel disk label, * then write a label to the raw disk. @@ -413,7 +419,7 @@ * may prevent us from changing the current (in-core) * label. */ - if (ioctl(f, DIOCSDINFO, lp) < 0 && + if (op != WRITEBOOT && ioctl(f, DIOCSDINFO, lp) < 0 && errno != ENODEV && errno != ENOTTY) { l_perror("ioctl DIOCSDINFO"); return (1); @@ -467,15 +473,41 @@ cksum ^= *sp1++; sl->sl_cksum = cksum; #endif - /* - * write enable label sector before write (if necessary), - * disable after writing. - */ - flag = 1; - (void)ioctl(f, DIOCWLABEL, &flag); - if (write(f, boot, lp->d_bbsize) != (int)lp->d_bbsize) { - warn("write"); - return (1); + if (op != WRITEBOOT) { + /* + * write enable label sector before write (if + * necessary), disable after writing. + */ + flag = 1; + (void)ioctl(f, DIOCWLABEL, &flag); + if (write(f, boot, lp->d_bbsize) != (int)lp->d_bbsize) { + warn("write"); + return (1); + } + } else { + /* + * Write out all of the boot area except + * for the sector reserved for the disklabel + * itself; that part is written only by + * the kernel, and we can't get it right. + */ + ssize_t labelareabegin, labelareaend; + + labelareabegin = (LABELSECTOR * lp->d_secsize) + + LABELOFFSET; + labelareaend = labelareabegin + lp->d_secsize; + if (write(f, boot, labelareabegin) != + labelareabegin) { + warn("write"); + return (1); + } + (void)lseek(f, (off_t)labelareaend, SEEK_SET); + if (write(f, boot + labelareaend, + lp->d_bbsize - labelareaend) != + lp->d_bbsize - labelareaend) { + warn("write"); + return (1); + } } #if NUMBOOT > 0 /* @@ -486,8 +518,13 @@ return(1); } #endif - flag = 0; - (void) ioctl(f, DIOCWLABEL, &flag); + if (op != WRITEBOOT) { + flag = 0; + (void) ioctl(f, DIOCWLABEL, &flag); + } else if (ioctl(f, DIOCWDINFO, lp) < 0) { + l_perror("ioctl DIOCWDINFO"); + return (1); + } } else if (ioctl(f, DIOCWDINFO, lp) < 0) { l_perror("ioctl DIOCWDINFO"); return (1); @@ -581,10 +618,10 @@ #endif /* XXX */ - if (dp->d_secsize == 0) { + if (dp->d_secsize == 0) dp->d_secsize = DEV_BSIZE; + if (dp->d_bbsize == 0) dp->d_bbsize = BBSIZE; - } lp = (struct disklabel *) (boot + (LABELSECTOR * dp->d_secsize) + LABELOFFSET); bzero((char *)lp, sizeof *lp); @@ -596,7 +633,7 @@ */ if (!installboot) { if (rflag) { - if (read(f, boot, BBSIZE) < BBSIZE) + if (read(f, boot, lp->d_bbsize) < lp->d_bbsize) err(4, "%s", specname); bzero((char *)lp, sizeof *lp); } @@ -754,6 +791,7 @@ fprintf(f, "sectors/cylinder: %lu\n", (u_long)lp->d_secpercyl); fprintf(f, "cylinders: %lu\n", (u_long)lp->d_ncylinders); fprintf(f, "sectors/unit: %lu\n", (u_long)lp->d_secperunit); + fprintf(f, "boot block size: %u\n", lp->d_bbsize); fprintf(f, "rpm: %u\n", lp->d_rpm); fprintf(f, "interleave: %u\n", lp->d_interleave); fprintf(f, "trackskew: %u\n", lp->d_trackskew); @@ -1092,6 +1130,16 @@ lp->d_secperunit = v; continue; } + if (streq(cp, "boot block size")) { + v = strtoul(tp, NULL, 10); + if (v == 0 || v > UINT_MAX) { + fprintf(stderr, "line %d: %s: bad %s\n", + lineno, tp, cp); + errors++; + } else + lp->d_bbsize = v; + continue; + } if (streq(cp, "rpm")) { v = strtoul(tp, NULL, 10); if (v == 0 || v > USHRT_MAX) { @@ -1625,10 +1673,10 @@ loclab.d_secpercyl = loclab.d_ntracks * loclab.d_nsectors; loclab.d_ncylinders = loclab.d_secperunit / loclab.d_secpercyl; loclab.d_npartitions = MAXPARTITIONS; + loclab.d_bbsize = BBSIZE; /* Various (unneeded) compat stuff */ loclab.d_rpm = 3600; - loclab.d_bbsize = BBSIZE; loclab.d_interleave = 1;; strncpy(loclab.d_typename, "amnesiac", sizeof(loclab.d_typename)); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message