From nobody@FreeBSD.org  Thu Jun  9 07:29:23 2011
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 75344106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  9 Jun 2011 07:29:23 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 65A848FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  9 Jun 2011 07:29:23 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p597TNKA065011
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 9 Jun 2011 07:29:23 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p597TN2F065010;
	Thu, 9 Jun 2011 07:29:23 GMT
	(envelope-from nobody)
Message-Id: <201106090729.p597TN2F065010@red.freebsd.org>
Date: Thu, 9 Jun 2011 07:29:23 GMT
From: Eir Nym <eirnym@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [GEOM] gpart 'add' command must preserve gap for schemes
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         157724
>Category:       kern
>Synopsis:       [geom] gpart(8) 'add' command must preserve gap for schemes
>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 Jun 09 07:30:11 UTC 2011
>Closed-Date:    
>Last-Modified:  Tue Jun 28 05:10:06 UTC 2011
>Originator:     Eir Nym
>Release:        FreeBSD-CURRENT r222277
>Organization:
Private Person
>Environment:
>Description:
Any GEOM scheme has reserved space at the beginning. And this space must be preserved by gpart 'add' command.
>How-To-Repeat:
Short example with BSD scheme (same with MBR, GPT and others):
#gpart create -s MBR ada0
#gpart add -t freebsd -s 999 ada0
#gpart create -s BSD ada0
#gpart show ada0s1
=> 0 999 ada0s1 BSD
   0 999 - free -
#gpart add -t freebsd-ufs ada0s1
#gpart show ada0s1
=> 0 999 ada0s1 BSD
   0 999 freebsd-ufs

/// This partition scheme is currently invalid. ///
#gpart delete -i 1 ada0s1
#gpart destroy ada0s1
#bsdlabel -w ada0s1
#gpart show ada0s1
=> 0 999 ada0s1 BSD
   0 16  -free-
   16 983 !0
/// This partition scheme is currently valid ///
>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-geom 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Jun 9 21:18:57 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

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

From: "Andrey V. Elsukov" <ae@FreeBSD.org>
To: bug-followup@FreeBSD.org, eirnym@gmail.com
Cc: Marcel Moolenaar <marcel@FreeBSD.org>
Subject: Re: kern/157724: [geom] gpart(8) 'add' command must preserve gap
 for schemes
Date: Mon, 27 Jun 2011 15:38:08 +0400

 Hi, Eir Nym
 
 I am partially agree with you. geom_part_bsd does not protects
 metadata from overwriting. And it is bad for users which are not
 aware about this. Also it is easy to wipe metadata now, when
 first partition of BSD scheme should not always have UFS file
 system.
 
 -- 
 WBR, Andrey V. Elsukov

From: Marcel Moolenaar <marcel@xcllnt.net>
To: "Andrey V. Elsukov" <ae@FreeBSD.org>
Cc: bug-followup@FreeBSD.org, eirnym@gmail.com,
        Marcel Moolenaar <marcel@FreeBSD.org>
Subject: Re: kern/157724: [geom] gpart(8) 'add' command must preserve gap for schemes
Date: Mon, 27 Jun 2011 09:39:11 -0700

 On Jun 27, 2011, at 4:38 AM, Andrey V. Elsukov wrote:
 
 > Hi, Eir Nym
 > 
 > I am partially agree with you. geom_part_bsd does not protects
 > metadata from overwriting. And it is bad for users which are not
 > aware about this. Also it is easy to wipe metadata now, when
 > first partition of BSD scheme should not always have UFS file
 > system.
 
 There isn't a lot we can do about it. This is one of those
 historical mistakes that you can't fix without breaking with
 30+ years of history. It's not worth the hassle IMO...
 
 -- 
 Marcel Moolenaar
 marcel@xcllnt.net
 
 

From: "Andrey V. Elsukov" <ae@FreeBSD.org>
To: Marcel Moolenaar <marcel@xcllnt.net>
Cc: bug-followup@FreeBSD.org, eirnym@gmail.com, 
 Marcel Moolenaar <marcel@FreeBSD.org>
Subject: Re: kern/157724: [geom] gpart(8) 'add' command must preserve gap
 for schemes
Date: Mon, 27 Jun 2011 21:40:41 +0400

 This is a multi-part message in MIME format.
 --------------020406000309010000060206
 Content-Type: text/plain; charset=KOI8-R
 Content-Transfer-Encoding: 7bit
 
 On 27.06.2011 20:39, Marcel Moolenaar wrote:
 >> I am partially agree with you. geom_part_bsd does not protects
 >> metadata from overwriting. And it is bad for users which are not
 >> aware about this. Also it is easy to wipe metadata now, when
 >> first partition of BSD scheme should not always have UFS file
 >> system.
 > 
 > There isn't a lot we can do about it. This is one of those
 > historical mistakes that you can't fix without breaking with
 > 30+ years of history. It's not worth the hassle IMO...
 
 Hi, Marcel
 
 I think we can just set gpt_first = 16 in g_part_bsd_create for new
 tables and for existing tables also set gpt_first = 16 if all partitions
 don not use this space. Something like this (untested):
 
 -- 
 WBR, Andrey V. Elsukov
 
 --------------020406000309010000060206
 Content-Type: text/plain;
  name="g_part_bsd.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="g_part_bsd.diff"
 
 Index: head/sys/geom/part/g_part_bsd.c
 ===================================================================
 --- head/sys/geom/part/g_part_bsd.c	(revision 223600)
 +++ head/sys/geom/part/g_part_bsd.c	(working copy)
 @@ -225,12 +225,12 @@ g_part_bsd_create(struct g_part_table *basetable,
  	le16enc(ptr + 138, basetable->gpt_entries);	/* d_npartitions */
  	le32enc(ptr + 140, BBSIZE);			/* d_bbsize */
  
 -	basetable->gpt_first = 0;
 +	basetable->gpt_first = BBSIZE / pp->sectorsize;
  	basetable->gpt_last = msize - 1;
  	basetable->gpt_isleaf = 1;
  
  	baseentry = g_part_new_entry(basetable, RAW_PART + 1,
 -	    basetable->gpt_first, basetable->gpt_last);
 +	    0, basetable->gpt_last);
  	baseentry->gpe_internal = 1;
  	entry = (struct g_part_bsd_entry *)baseentry;
  	entry->part.p_size = basetable->gpt_last + 1;
 @@ -437,7 +437,11 @@ g_part_bsd_read(struct g_part_table *basetable, st
  		entry->part = part;
  		if (index == RAW_PART)
  			baseentry->gpe_internal = 1;
 +		else if (baseentry->gpe_start < BBSIZE / pp->sectorsize)
 +			error = 1;
  	}
 +	if (error == 0)
 +		basetable->gpt_first = BBSIZE / pp->sectorsize;
  
  	return (0);
  
 
 --------------020406000309010000060206--

From: Marcel Moolenaar <marcel@xcllnt.net>
To: "Andrey V. Elsukov" <ae@FreeBSD.org>
Cc: bug-followup@FreeBSD.org, eirnym@gmail.com,
        Marcel Moolenaar <marcel@FreeBSD.org>
Subject: Re: kern/157724: [geom] gpart(8) 'add' command must preserve gap for schemes
Date: Mon, 27 Jun 2011 11:01:33 -0700

 On Jun 27, 2011, at 10:40 AM, Andrey V. Elsukov wrote:
 
 > On 27.06.2011 20:39, Marcel Moolenaar wrote:
 >>> I am partially agree with you. geom_part_bsd does not protects
 >>> metadata from overwriting. And it is bad for users which are not
 >>> aware about this. Also it is easy to wipe metadata now, when
 >>> first partition of BSD scheme should not always have UFS file
 >>> system.
 >> 
 >> There isn't a lot we can do about it. This is one of those
 >> historical mistakes that you can't fix without breaking with
 >> 30+ years of history. It's not worth the hassle IMO...
 > 
 > Hi, Marcel
 > 
 > I think we can just set gpt_first = 16 in g_part_bsd_create for new
 > tables and for existing tables also set gpt_first = 16 if all partitions
 > don not use this space. Something like this (untested):
 
 You may want to look at /etc/disktab. Are you willing to
 change all entries and deal with the consequences? :-)
 
 -- 
 Marcel Moolenaar
 marcel@xcllnt.net
 
 

From: Eir Nym <eirnym@gmail.com>
To: Marcel Moolenaar <marcel@xcllnt.net>
Cc: "Andrey V. Elsukov" <ae@freebsd.org>, bug-followup@freebsd.org, 
	Marcel Moolenaar <marcel@freebsd.org>
Subject: Re: kern/157724: [geom] gpart(8) 'add' command must preserve gap for schemes
Date: Tue, 28 Jun 2011 05:06:06 +0000

 On 27 June 2011 18:01, Marcel Moolenaar <marcel@xcllnt.net> wrote:
 >
 > On Jun 27, 2011, at 10:40 AM, Andrey V. Elsukov wrote:
 >
 >> On 27.06.2011 20:39, Marcel Moolenaar wrote:
 >>>> I am partially agree with you. geom_part_bsd does not protects
 >>>> metadata from overwriting. And it is bad for users which are not
 >>>> aware about this. Also it is easy to wipe metadata now, when
 >>>> first partition of BSD scheme should not always have UFS file
 >>>> system.
 >>>
 >>> There isn't a lot we can do about it. This is one of those
 >>> historical mistakes that you can't fix without breaking with
 >>> 30+ years of history. It's not worth the hassle IMO...
 >>
 >> Hi, Marcel
 >>
 >> I think we can just set gpt_first = 16 in g_part_bsd_create for new
 >> tables and for existing tables also set gpt_first = 16 if all partitions
 >> don not use this space. Something like this (untested):
 >
 > You may want to look at /etc/disktab. Are you willing to
 > change all entries and deal with the consequences? :-)
 >
 
 according [1] and bsdlabel(8), we can preserve 0 if we use ZFS (this
 filesystem have space for boot code), and 8k for UFS (this filesystem
 have no space for boot code).
 
 So if we install UFS without boot, can we preserve no gap?
 
 [1]: [http://wiki.freebsd.org/RootOnZFS/ZFSBootPartition]
 -- Eir Nym
 
 > --
 > Marcel Moolenaar
 > marcel@xcllnt.net
 >
 >
>Unformatted:
