From owner-svn-src-all@FreeBSD.ORG Thu Jan 26 09:14:52 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D0001065673; Thu, 26 Jan 2012 09:14:52 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0D2428FC08; Thu, 26 Jan 2012 09:14:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0Q9Ep09073975; Thu, 26 Jan 2012 09:14:51 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0Q9Epj9073973; Thu, 26 Jan 2012 09:14:51 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201201260914.q0Q9Epj9073973@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 26 Jan 2012 09:14:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r230569 - stable/8/sys/geom/part X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jan 2012 09:14:52 -0000 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); }