From nobody@FreeBSD.org  Tue Oct  7 13:58:12 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id BB7841065694
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  7 Oct 2008 13:58:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id AA50F8FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  7 Oct 2008 13:58:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id m97DwCC2056092
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 7 Oct 2008 13:58:12 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id m97DwCSF056091;
	Tue, 7 Oct 2008 13:58:12 GMT
	(envelope-from nobody)
Message-Id: <200810071358.m97DwCSF056091@www.freebsd.org>
Date: Tue, 7 Oct 2008 13:58:12 GMT
From: Alexey Shuvaev <shuvaev@physik.uni-wuerzburg.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: gpart auto-padding gptboot
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         127922
>Category:       bin
>Synopsis:       [patch] gpart(8): restore auto-padding gptboot
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    marcel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 07 14:00:14 UTC 2008
>Closed-Date:    Sat Nov 22 16:59:26 UTC 2008
>Last-Modified:  Sat Nov 22 16:59:26 UTC 2008
>Originator:     Alexey Shuvaev
>Release:        8.0-CURRENT
>Organization:
University of Wuerzburg
>Environment:
FreeBSD wep4035.physik.uni-wuerzburg.de 8.0-CURRENT FreeBSD 8.0-CURRENT #0: Wed Oct  1 16:59:10 CEST 2008     root@wep4035.physik.uni-wuerzburg.de:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
This is about gpart's "bootcode" verb
(namely -b bootcode -i part_index part of the verb).
The code is taken from gpt(8) utility (removed from current).
It adds automatic padding of gptboot bootcode to the nearest sector boundary.
Otherwise gptboot is truncated and is unable to boot.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- sbin/geom/class/part/geom_part.c.orig	2008-08-08 18:14:25.000000000 +0200
+++ sbin/geom/class/part/geom_part.c	2008-09-20 04:13:15.000000000 +0200
@@ -386,6 +386,8 @@
 	struct ggeom *gp;
 	struct gprovider *pp;
 	const char *s;
+	char *buf;
+	off_t bsize;
 	int error, fd;
 
 	s = gctl_get_ascii(req, "class");
@@ -421,7 +423,17 @@
 			errx(EXIT_FAILURE, "%s: not enough space", dsf);
 		if (lseek(fd, 0, SEEK_SET) != 0)
 			err(EXIT_FAILURE, "%s", dsf);
-		if (write(fd, code, size) != size)
+
+		/*
+		 * When writing to a disk device, the write must be
+		 * sector aligned and not write to any partial sectors,
+		 * so round up the buffer size to the next sector and zero it.
+		 */
+		bsize = (size + pp->lg_sectorsize - 1) /
+		    pp->lg_sectorsize * pp->lg_sectorsize;
+		buf = calloc(1, bsize);
+		bcopy(code, buf, size);
+		if (write(fd, buf, bsize) != bsize)
 			err(EXIT_FAILURE, "%s", dsf);
 		close(fd);
 	} else


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->marcel 
Responsible-Changed-By: remko 
Responsible-Changed-When: Tue Oct 7 19:54:39 UTC 2008 
Responsible-Changed-Why:  
Hi Marcel, can you have a look at this gpart thingy please? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=127922 
State-Changed-From-To: open->closed 
State-Changed-By: marcel 
State-Changed-When: Sat Nov 22 16:56:59 UTC 2008 
State-Changed-Why:  
Fix committed to -CURRENT and Xin Li has approval for MFC. 
It will be in 7.1-RELEASE. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=127922 
>Unformatted:
