Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Oct 2008 13:58:12 GMT
From:      Alexey Shuvaev <shuvaev@physik.uni-wuerzburg.de>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/127922: gpart auto-padding gptboot
Message-ID:  <200810071358.m97DwCSF056091@www.freebsd.org>
Resent-Message-ID: <200810071400.m97E0EpO003442@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         127922
>Category:       bin
>Synopsis:       gpart auto-padding gptboot
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 07 14:00:14 UTC 2008
>Closed-Date:
>Last-Modified:
>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 trancated 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:
>Unformatted:



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