Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Dec 2002 18:47:22 -0500
From:      "Brian F. Feldman" <green@FreeBSD.org>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/boot/i386/boot2 boot2.c 
Message-ID:  <200212172347.gBHNlNiP014104@green.bikeshed.org>
In-Reply-To: Your message of "Tue, 17 Dec 2002 16:28:42 MST." <20021217.162842.36665700.imp@bsdimp.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
"M. Warner Losh" <imp@bsdimp.com> wrote:
> In message: <200212172213.gBHMD7wd013565@green.bikeshed.org>
>             "Brian F. Feldman" <green@FreeBSD.org> writes:
> : Warner Losh <imp@FreeBSD.org> wrote:
> : > imp         2002/12/17 14:00:06 PST
> : > 
> : >   Modified files:
> : >     sys/boot/i386/boot2  boot2.c 
> : >   Log:
> : >   Reduce diffs with Peter's expanded diffs:
> : >   1) Put back the keyboard printing printf, at the cost of 58 bytes.
> : >   2) Minor tweak to getstr at no apparent cost.
> : 
> : Hmm, after all this work on boot2, I remain confused as to why noone else 
> : working on the boot blocks seems to have any trouble reinstalling them
> : to test.  Am I really the only one that had to fix disklabel.c so that it 
> : would install boot blocks instead of just dying on a post-GEOM system?
> : It seems strange that it's only a few people here that would be having that 
> : issue :)
> 
> I had to hack disklabel.c in unnatural ways to install to test.

Is this better?

==== //depot/vendor/freebsd/src/sbin/disklabel/disklabel.8#12 (text+ko) - //depot/projects/trustedbsd/mac/sbin/disklabel/disklabel.8#10 (text+ko) ==== content
@@ -535,6 +535,7 @@
 sectors/cylinder: 969
 cylinders: 1211
 sectors/unit: 1173930
+boot block size: 8192
 rpm: 3600
 interleave: 1
 trackskew: 0
@@ -576,6 +577,11 @@
 specifies that the drive can perform bad sector remapping.
 .It Nm sectors/unit
 describes the total size of the disk.  This value must be correct.
+.It Nm boot block size
+specifies the total length of the boot block allowable on the disk.
+This defaults to 8192, as it always has, but may be increased if there is
+more space available, with a UFS2 filesystem as the first partition or
+via other means.
 .It Nm the partition table
 This is the
 .Ux
@@ -818,6 +824,7 @@
 sectors/cylinder: 1008
 cylinders: 40633
 sectors/unit: 40959009
+boot block size: 8192
 rpm: 3600
 interleave: 1
 trackskew: 0
==== //depot/vendor/freebsd/src/sbin/disklabel/disklabel.c#26 (text+ko) - //depot/projects/trustedbsd/mac/sbin/disklabel/disklabel.c#15 (text+ko) ==== content
@@ -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));


-- 
Brian Fundakowski Feldman                           \'[ FreeBSD ]''''''''''\
  <> green@FreeBSD.org  <> bfeldman@tislabs.com      \  The Power to Serve! \
 Opinions expressed are my own.                       \,,,,,,,,,,,,,,,,,,,,,,\



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212172347.gBHNlNiP014104>