PERFORCE change 22148 for review

Brian Feldman green at freebsd.org
Wed Dec 11 00:16:34 GMT 2002


http://perforce.freebsd.org/chv.cgi?CH=22148

Change 22148 by green at green_laptop_2 on 2002/12/10 16:16:33

	This is initial libdisk(3)/sysinstall(8) support for making
	UFS2-only systems bootable, as well.  The installer will now
	make a judgement call and install the UFS[12] boot loader
	(/boot/boot2) if it decides it should.  It is conservative,
	and will install the UFS1-only boot loader (/boot/boot2-ufs1)
	in cases where the first partition on all FreeBSD slices on
	a disk is not UFS2.
	
	The related changes are in src/sys/boot and src/usr.sbin/disklabel,
	however, the changes to disklabel(8) are not strictly necessary
	to support this.

Affected files ...

.. //depot/projects/trustedbsd/mac/lib/libdisk/disk.c#20 edit
.. //depot/projects/trustedbsd/mac/lib/libdisk/libdisk.3#4 edit
.. //depot/projects/trustedbsd/mac/lib/libdisk/libdisk.h#12 edit
.. //depot/projects/trustedbsd/mac/lib/libdisk/write_disk.c#8 edit
.. //depot/projects/trustedbsd/mac/lib/libdisk/write_i386_disk.c#4 edit
.. //depot/projects/trustedbsd/mac/lib/libdisk/write_pc98_disk.c#5 edit
.. //depot/projects/trustedbsd/mac/usr.sbin/sysinstall/disks.c#12 edit
.. //depot/projects/trustedbsd/mac/usr.sbin/sysinstall/install.c#16 edit
.. //depot/projects/trustedbsd/mac/usr.sbin/sysinstall/label.c#13 edit

Differences ...

==== //depot/projects/trustedbsd/mac/lib/libdisk/disk.c#20 (text+ko) ====

@@ -169,6 +169,8 @@
 	d->sector_size = s;
 	len /= s;	/* media size in number of sectors. */
 
+	d->bbsize = BBSIZE;	/* default, insufficient for UFS2 */
+
 	if (Add_Chunk(d, 0, len, name, whole, 0, 0, "-"))
 		DPRINT(("Failed to add 'whole' chunk"));
 
@@ -527,39 +529,60 @@
 }
 
 int
+Set_Boot_Block_Size(struct disk *d, size_t boot_block_size)
+{
+
+	d->bbsize = boot_block_size;
+	return 0;
+}
+
+int
 Set_Boot_Blocks(struct disk *d, const u_char *b1, const u_char *b2)
 {
+
+#if defined(__alpha__)
+	return (Set_Large_Boot_Blocks(d, b1, 15 * 512, NULL, 0));
+#elif defined(__sparc64__)
+	return (Set_Large_Boot_Blocks(d, b1, 16 * 512, NULL, 0));
+#else
+	return (Set_Large_Boot_Blocks(d, b1, 512, b2, 15 * 512));
+#endif
+}
+
+int
+Set_Large_Boot_Blocks(struct disk *d, const u_char *b1, size_t b1size,
+    const u_char *b2, size_t b2size)
+{
+	/*
+	 * Make sure all of the 0-2 boot blocks will fit inside the
+	 * boot block size reserved.
+	 */
+	if (b1size + b2size > d->bbsize)
+		return -1;
 #if defined(__i386__)
 	if (d->boot1)
 		free(d->boot1);
-	d->boot1 = malloc(512);
+	d->boot1 = malloc(b1size);
 	if (!d->boot1)
 		return -1;
-	memcpy(d->boot1, b1, 512);
+	memcpy(d->boot1, b1, b1size);
 	if (d->boot2)
 		free(d->boot2);
-	d->boot2 = malloc(15 * 512);
+	d->boot2 = malloc(b2size);
 	if (!d->boot2)
 		return -1;
-	memcpy(d->boot2, b2, 15 * 512);
-#elif defined(__alpha__)
+	memcpy(d->boot2, b2, b2size);
+#elif defined(__alpha__) || defined(__sparc64__)
 	if (d->boot1)
 		free(d->boot1);
-	d->boot1 = malloc(15 * 512);
+	d->boot1 = malloc(b1size);
 	if (!d->boot1)
 		return -1;
-	memcpy(d->boot1, b1, 15 * 512);
-#elif defined(__sparc64__)
-	if (d->boot1 != NULL)
-		free(d->boot1);
-	d->boot1 = malloc(16 * 512);
-	if (d->boot1 == NULL)
-		return (-1);
-	memcpy(d->boot1, b1, 16 * 512);
+	memcpy(d->boot1, b1, b1size);
 #elif defined(__ia64__)
 	/* nothing */
 #else
-/* Should be: #error "Set_Boot_Blocks: unknown arch"; */
+/* Should be: #error "Set_Large_Boot_Blocks: unknown arch"; */
 #endif
 	return 0;
 }

==== //depot/projects/trustedbsd/mac/lib/libdisk/libdisk.3#4 (text+ko) ====

@@ -44,6 +44,7 @@
 .Nm Disk_Names ,
 .Nm Set_Boot_Mgr ,
 .Nm Set_Boot_Blocks ,
+.Nm Set_Large_Boot_Blocks ,
 .Nm Write_Disk ,
 .Nm Cyl_Aligned ,
 .Nm Next_Cyl_Aligned ,
@@ -91,6 +92,8 @@
 .Ft int
 .Fn Set_Boot_Blocks "struct disk *d" "const u_char *boot1" "const u_char *boot2"
 .Ft int
+.Fn Set_Large_Boot_Blocks "struct disk *d" "const u_char *boot1" "size_t boot1size" "const u_char *boot2" "size_t boot2size"
+.Ft int
 .Fn Write_Disk "struct disk *d"
 .Ft int
 .Fn Cyl_Aligned "struct disk *d" "u_long offset"
@@ -254,7 +257,9 @@
 is called.
 .Pp
 .Fn Set_Boot_Blocks
-sets the boot-blocks for use on this disk.  Gets written when
+and
+.Fn Set_Large_Boot_Blocks
+set the boot-blocks for use on this disk.  Gets written when
 .Fn Write_Disk
 is called.
 .Pp

==== //depot/projects/trustedbsd/mac/lib/libdisk/libdisk.h#12 (text+ko) ====

@@ -91,6 +91,7 @@
 #endif
 	struct chunk	*chunks;
 	u_long		sector_size; /* media sector size, a power of 2 */
+	u_int		bbsize; /* boot block size for disklabel */
 };
 
 struct chunk {
@@ -166,6 +167,9 @@
 Set_Bios_Geom(struct disk *, u_long, u_long, u_long);
 /* Set the geometry the bios uses. */
 
+int
+Set_Boot_Block_Size(struct disk *, const size_t);
+
 void
 Sanitize_Bios_Geom(struct disk *);
 /* Set the bios geometry to something sane */
@@ -228,6 +232,9 @@
 
 int
 Set_Boot_Blocks(struct disk *, const u_char *, const u_char *);
+int
+Set_Large_Boot_Blocks(struct disk *, const u_char *, size_t, const u_char *,
+	size_t);
 /*
  * Use these boot-blocks on this disk.  Gets written when Write_Disk()
  * is called. Returns nonzero upon failure.

==== //depot/projects/trustedbsd/mac/lib/libdisk/write_disk.c#8 (text+ko) ====

@@ -45,7 +45,7 @@
 		dl->d_partitions[j].p_fstype = c2->subtype;
 	}
 
-	dl->d_bbsize = BBSIZE;
+	dl->d_bbsize = new->bbsize;
 	/*
 	 * Add in defaults for superblock size, interleave, and rpms
 	 */

==== //depot/projects/trustedbsd/mac/lib/libdisk/write_i386_disk.c#4 (text+ko) ====

@@ -34,9 +34,12 @@
 	struct disklabel *dl;
 	int i;
 	void *p;
-	u_char buf[BBSIZE];
+	u_char *buf;
 
-	for (i = 0; i < BBSIZE/512; i++) {
+	buf = malloc(new->bbsize);
+	if (buf == NULL)
+		return -1;
+	for (i = 0; i < new->bbsize / 512; i++) {
 		p = read_block(fd, i + c1->offset, 512);
 		memcpy(buf + 512 * i, p, 512);
 		free(p);
@@ -45,14 +48,15 @@
 		memcpy(buf, new->boot1, 512);
 
 	if (new->boot2)
-		memcpy(buf + 512, new->boot2, BBSIZE - 512);
+		memcpy(buf + 512, new->boot2, new->bbsize - 512);
 
 	dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
 	Fill_Disklabel(dl, new, old, c1);
 
-	for (i = 0; i < BBSIZE / 512; i++)
+	for (i = 0; i < new->bbsize / 512; i++)
 		write_block(fd, i + c1->offset, buf + 512 * i, 512);
 
+	free(buf);
 	return 0;
 }
 

==== //depot/projects/trustedbsd/mac/lib/libdisk/write_pc98_disk.c#5 (text+ko) ====

@@ -36,9 +36,11 @@
 	struct disklabel *dl;
 	int i;
 	void *p;
-	u_char buf[BBSIZE];
+ 	u_char *buf;
 
-	for (i = 0; i < BBSIZE / 512; i++) {
+ 	if (buf == NULL)
+ 		return -1;
+ 	for (i = 0; i < new->bbsize / 512; i++) {
 		p = read_block(fd, i + c1->offset, 512);
 		memcpy(buf + 512 * i, p, 512);
 		free(p);
@@ -47,14 +49,15 @@
 		memcpy(buf, new->boot1, 512);
 
 	if (new->boot2)
-		memcpy(buf + 512, new->boot2, BBSIZE - 512);
+		memcpy(buf + 512, new->boot2, new->bbsize - 512);
 
 	dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
 	Fill_Disklabel(dl, new, old, c1);
 
-	for (i = 0; i < BBSIZE / 512; i++)
+	for (i = 0; i < new->bbsize / 512; i++)
 		write_block(fd, i + c1->offset, buf + 512 * i, 512);
 
+	free(buf);
 	return 0;
 }
 

==== //depot/projects/trustedbsd/mac/usr.sbin/sysinstall/disks.c#12 (text+ko) ====

@@ -845,6 +845,12 @@
 diskPartitionWrite(dialogMenuItem *self)
 {
     Device **devs;
+#ifdef __i386__
+    size_t boot1size, boot2size;
+    Chunk *slice;
+    PartInfo *pi;
+    int bigbb, nonbigbb;
+#endif
     int i;
 
     if (!variable_cmp(DISK_PARTITIONED, "written"))
@@ -867,7 +873,60 @@
 	if (!devs[i]->enabled)
 	    continue;
 
-#if defined(__i386__) || defined(__ia64__)
+#ifdef __i386__
+	/*
+	 * For i386, use "big" boot blocks if the first partition in
+	 * every FreeBSD slice is UFS2 and therefore has 64KB of space
+	 * available rather than UFS1's mere 8KB.  We could be more
+	 * intelligent here and move forward uncreated non-UFS2
+	 * partitions to accomodate, and check that already-created
+	 * slice aren't actually created with an offset from the
+	 * beginning of their slice in the first place.
+	 */
+	nonbigbb = bigbb = 0;
+	for (slice = d->chunks->part; slice; slice = slice->next) {
+	    if (slice->type != freebsd)
+		continue;
+	    if (slice->part->type == unused)
+		continue;	/* just an empty FreeBSD slice */
+	    if (slice->part->subtype != FS_BSDFFS) {
+		nonbigbb = 1;	/* assume non-UFS2 means non-64KB */
+		continue;
+	    }
+	    pi = slice->part->private_data;
+	    if (pi == NULL || pi->newfs_type != NEWFS_UFS ||
+	      !pi->newfs_data.newfs_ufs.ufs2) {
+		nonbigbb = 1;	/* assume non-UFS2 means non-64KB */
+		continue;
+	    }
+	    bigbb = 1;
+	}
+	if (bigbb && nonbigbb)
+	    msgConfirm("Warning: Some FreeBSD slices on this disk preclude the "
+		       "installation of UFS2-capable boot blocks.  You will need "
+		       "to manually use disklabel(8) on these slices to install "
+		       "the correct boot blocks.");
+	/*
+	 * Boot blocks may switch back and forth if the installer is
+	 * writing out labels on multiple disks.
+	 */
+	free(boot1);
+	free(boot2);
+	if (!nonbigbb && bigbb) {
+	    boot1 = bootalloc("boot1", &boot1size);
+	    boot2 = bootalloc("boot2", &boot2size);
+	    Set_Boot_Block_Size(d, 0x10000);
+	    if (Set_Large_Boot_Blocks(d, boot1, boot1size, boot2,
+	      boot2size)) {
+	        msgConfirm("ERROR: Unable to use boot blocks on disk %s!", d->name);
+	        return DITEM_FAILURE;
+	    }
+	} else {
+	    boot1 = bootalloc("boot1", &boot1size);
+	    boot2 = bootalloc("boot2-ufs1", &boot2size);
+	    Set_Boot_Blocks(d, boot1, boot2);
+	}
+#elif defined(__ia64__)
 	if (!boot1) boot1 = bootalloc("boot1", NULL);
 	if (!boot2) boot2 = bootalloc("boot2", NULL);
 	Set_Boot_Blocks(d, boot1, boot2);

==== //depot/projects/trustedbsd/mac/usr.sbin/sysinstall/install.c#16 (text+ko) ====


==== //depot/projects/trustedbsd/mac/usr.sbin/sysinstall/label.c#13 (text+ko) ====

@@ -864,7 +864,7 @@
 
 		if ((pi != NULL) &&
 		    (pi->newfs_type == NEWFS_UFS)) {
-#ifdef __i386__
+#ifdef norootufs2
 			if (label_chunk_info[here].c->flags & CHUNK_IS_ROOT)
 				msg = MSG_NOT_APPLICABLE;
 			else
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list