Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Jan 2012 09:14:51 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r230569 - stable/8/sys/geom/part
Message-ID:  <201201260914.q0Q9Epj9073973@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Thu Jan 26 09:14:51 2012
New Revision: 230569
URL: http://svn.freebsd.org/changeset/base/230569

Log:
  MFC r216132 (by ivoras):
    Add a note about the magic number 20. Actually, 22.75 entries fit in
    a 512 byte sector but when choosing magic numbers, 20 looks nicer.
  
  MFC r223332:
    Change the way how we update bootcode for BSD scheme.
    Since the only parameter that we check is size of bootcode, then
    allow only two sizes: size of boot1 and size of /boot/boot.
    This partially protects users from losing ability to boot if incorrect
    bootcode is specified.

Modified:
  stable/8/sys/geom/part/g_part_bsd.c
Directory Properties:
  stable/8/sys/   (props changed)

Modified: stable/8/sys/geom/part/g_part_bsd.c
==============================================================================
--- stable/8/sys/geom/part/g_part_bsd.c	Thu Jan 26 08:51:23 2012	(r230568)
+++ stable/8/sys/geom/part/g_part_bsd.c	Thu Jan 26 09:14:51 2012	(r230569)
@@ -45,6 +45,11 @@ __FBSDID("$FreeBSD$");
 
 #include "g_part_if.h"
 
+#define	BOOT1_SIZE	512
+#define	LABEL_SIZE	512
+#define	BOOT2_OFF	(BOOT1_SIZE + LABEL_SIZE)
+#define	BOOT2_SIZE	(BBSIZE - BOOT2_OFF)
+
 struct g_part_bsd_table {
 	struct g_part_table	base;
 	u_char			*bbarea;
@@ -99,7 +104,7 @@ static struct g_part_scheme g_part_bsd_s
 	sizeof(struct g_part_bsd_table),
 	.gps_entrysz = sizeof(struct g_part_bsd_entry),
 	.gps_minent = 8,
-	.gps_maxent = 20,
+	.gps_maxent = 20,	/* Only 22 entries fit in 512 byte sectors */
 	.gps_bootcodesz = BBSIZE,
 };
 G_PART_SCHEME_DECLARE(g_part_bsd);
@@ -167,22 +172,16 @@ g_part_bsd_bootcode(struct g_part_table 
 {
 	struct g_part_bsd_table *table;
 	const u_char *codeptr;
-	size_t hdsz, tlsz;
-	size_t codesz, tlofs;
 
-	hdsz = 512;
-	tlofs = hdsz + 148 + basetable->gpt_entries * 16;
-	tlsz = BBSIZE - tlofs;
+	if (gpp->gpp_codesize != BOOT1_SIZE && gpp->gpp_codesize != BBSIZE)
+		return (ENODEV);
+
 	table = (struct g_part_bsd_table *)basetable;
-	bzero(table->bbarea, hdsz);
-	bzero(table->bbarea + tlofs, tlsz);
 	codeptr = gpp->gpp_codeptr;
-	codesz = MIN(hdsz, gpp->gpp_codesize);
-	if (codesz > 0)
-		bcopy(codeptr, table->bbarea, codesz);
-	codesz = MIN(tlsz, gpp->gpp_codesize - tlofs);
-	if (codesz > 0)
-		bcopy(codeptr + tlofs, table->bbarea + tlofs, codesz);
+	bcopy(codeptr, table->bbarea, BOOT1_SIZE);
+	if (gpp->gpp_codesize == BBSIZE)
+		bcopy(codeptr + BOOT2_OFF, table->bbarea + BOOT2_OFF,
+		    BOOT2_SIZE);
 	return (0);
 }
 



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