From nobody@FreeBSD.org  Thu Dec  8 03:05:27 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B4B2016A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  8 Dec 2005 03:05:27 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6CE6443D7F
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  8 Dec 2005 03:05:27 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jB835RU8021979
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 8 Dec 2005 03:05:27 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jB835QdN021978;
	Thu, 8 Dec 2005 03:05:26 GMT
	(envelope-from nobody)
Message-Id: <200512080305.jB835QdN021978@www.freebsd.org>
Date: Thu, 8 Dec 2005 03:05:26 GMT
From: Chris Pressey <cpressey@catseye.mine.nu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: fdisk(8) incapable of altering in-core geometry
X-Send-Pr-Version: www-2.3

>Number:         90093
>Category:       bin
>Synopsis:       fdisk(8) incapable of altering in-core geometry
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-geom
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 08 03:10:02 GMT 2005
>Closed-Date:    
>Last-Modified:  Sun Jul 27 19:10:06 UTC 2008
>Originator:     Chris Pressey
>Release:        7.0-CURRENT
>Organization:
Cat's Eye Technologies
>Environment:
FreeBSD catbus.biscuit.boo 7.0-CURRENT FreeBSD 7.0-CURRENT #2: Sat Dec 3 09:14:05 PST 2005 catseye@catbus.biscuit.boo:/usr/obj/usr/home/work/freebsd/src/sys/BIRDLAND i386
>Description:
The fdisk(8) utility, when called to update the MBR of a disk, asks you whether you want to change "our idea of that the BIOS thinks" (i.e. the in-core value) of the geometry of that disk.  However, it never actually succeeds in doing that.

This behaviour has been independently observed (also on recent -CURRENT) by Andrew Turner (FreeBSD SoC BSD Installer project.)

The bug was first suspected due to consistent failure of the BSD Installer tool, which calls /sbin/fdisk to change the geometry of the user's disk.  The same failure is seen in FreeBSD 6.x, indicating that the same bug is in all likelihood present in 6.x as well.  Anecdotal evidence from a different source suggests it may be in 5.x as well, but this is less certain.

>How-To-Repeat:
- As root, run "fdisk -u ad1" (or on whatever disk you like)
- Tell fdisk(8) "yes, I'd like to change our idea of what the BIOS thinks (of the geometry of this disk)"
- Give fdisk(8) any new geometry values you like
- Be happy with this choice
- Choose to write the new partition table
- Get a "GEOM not found" error (optional)
- Run "fdisk ad1" again and observe that the geometry hasn't changed.

>Fix:
Problem is probably in the GEOM layer, or in how fdisk(8) talks to the GEOM layer, but is not precisely known.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-geom 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Fri Dec 9 07:03:25 GMT 2005 
Responsible-Changed-Why:  
This is GEOM-related 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90093 

From: "Scott Ullrich" <sullrich@gmail.com>
To: bug-followup@FreeBSD.org, cpressey@catseye.mine.nu
Cc:  
Subject: Re: bin/90093: fdisk(8) incapable of altering in-core geometry
Date: Sun, 21 May 2006 18:43:17 -0400

 Hello, this patch seems to fix the problems outlined in this pr.  I am
 not sure if this is the "correct" fix but it does ineed work.  This
 patch was given to me by Olavi Kumpulainen <olavi@ipunplugged.com> and
 he asked me to follow up to the PR if it worked.  I've also sent this
 patch to 2 other parties with the same problems and they reported that
 this fixed their issues as well.
 
 --- fdisk.c=09Wed Oct  5 03:16:39 2005
 +++ fdisk-patched.c=09Tue May 16 14:36:51 2006
 @@ -750,6 +750,7 @@
  =09char fbuf[BUFSIZ];
  =09int i, fdw;
 
 +=09close(fd);=09/* Give the GEOM layer exclusive access to the disk */
  =09grq =3D gctl_get_handle();
  =09gctl_ro_param(grq, "verb", -1, "write MBR");
  =09gctl_ro_param(grq, "class", -1, "MBR");
 @@ -760,13 +761,15 @@
  =09=09q++;
  =09gctl_ro_param(grq, "geom", -1, q);
  =09gctl_ro_param(grq, "data", secsize, buf);
 -=09q =3D gctl_issue(grq);
 +=09q =3D gctl_issue(grq);
  =09if (q =3D=3D NULL) {
  =09=09gctl_free(grq);
 +=09=09open_disk(u_flag);
  =09=09return(0);
  =09}
  =09warnx("%s", q);
  =09gctl_free(grq);
 +=09open_disk(u_flag);
  =09
  =09error =3D pwrite(fd, buf, secsize, (sector * 512));
  =09if (error =3D=3D secsize)

From: "Scott Ullrich" <sullrich@gmail.com>
To: bug-followup@FreeBSD.org, cpressey@catseye.mine.nu
Cc:  
Subject: Re: bin/90093: fdisk(8) incapable of altering in-core geometry
Date: Sat, 3 Jun 2006 17:36:34 -0400

 Sorry for the previous mungled patch.
 
 I'll provide a link to our CVS repo which has the patch:
 
 http://cvs.pfsense.com/cgi-bin/cvsweb.cgi/tools/patches/fdisk.c.diff?rev=1.1;content-type=text%2Fplain
 
 And in case the above gets mungled:
 
 http://tinyurl.com/nthtc

From: "Scott Ullrich" <sullrich@gmail.com>
To: bug-followup@FreeBSD.org, cpressey@catseye.mine.nu
Cc:  
Subject: Re: bin/90093: fdisk(8) incapable of altering in-core geometry
Date: Mon, 14 Apr 2008 13:07:11 -0400

 Here is an updated patch for this issue:
 http://cvs.pfsense.org/cgi-bin/cvsweb.cgi/tools/patches/RELENG_7_0/fdisk.c.diff
 
 or the tiny version:
 
 http://tinyurl.com/5gp6eu

From: Ulf Lilleengen <lulf@freebsd.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/90093: fdisk(8) incapable of altering in-core geometry
Date: Sun, 27 Jul 2008 21:06:30 +0200

 AFAICT, the fdisk code skips to using pwrite to write the MBR if the MBR GEOM
 class fails (which it will do if an MBR does not exist), and should update
 the MBR info correctly anyway. I was however unsuccessful altering the
 geometry even with this patch. But the warning printed when geom_mbr fails is
 a bit confusing, since the write request might be successful anyway, so we
 should either just quell the warning, or make using geom_mbr work.
 
 -- 
 Ulf Lilleengen
>Unformatted:
