From eugen@grosbein.pp.ru  Sun Nov  6 14:04:02 2011
Return-Path: <eugen@grosbein.pp.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 16690106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  6 Nov 2011 14:04:02 +0000 (UTC)
	(envelope-from eugen@grosbein.pp.ru)
Received: from grosbein.pp.ru (grosbein.pp.ru [89.189.172.146])
	by mx1.freebsd.org (Postfix) with ESMTP id 5BDB88FC0C
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  6 Nov 2011 14:04:00 +0000 (UTC)
Received: from grosbein.pp.ru (localhost [127.0.0.1])
	by grosbein.pp.ru (8.14.5/8.14.5) with ESMTP id pA6DpaOp003937
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 6 Nov 2011 20:51:36 +0700 (NOVT)
	(envelope-from eugen@grosbein.pp.ru)
Received: (from eugen@localhost)
	by grosbein.pp.ru (8.14.5/8.14.5/Submit) id pA6DpaZn003936;
	Sun, 6 Nov 2011 20:51:36 +0700 (NOVT)
	(envelope-from eugen)
Message-Id: <201111061351.pA6DpaZn003936@grosbein.pp.ru>
Date: Sun, 6 Nov 2011 20:51:36 +0700 (NOVT)
From: Eugene Grosbein <egrosbein@rdtc.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: bsdlabel destroys partitions with indexes over 8
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         162332
>Category:       bin
>Synopsis:       bsdlabel destroys partitions with indexes over 8
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 06 14:10:05 UTC 2011
>Closed-Date:    Wed Nov 16 16:59:05 UTC 2011
>Last-Modified:  Wed Nov 16 16:59:05 UTC 2011
>Originator:     Eugene Grosbein
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
RDTC JSC
>Environment:
System: FreeBSD grosbein.pp.ru 8.2-STABLE FreeBSD 8.2-STABLE #13: Sat Oct 22 20:07:08 NOVT 2011 root@grosbein.pp.ru:/usr/local/obj/usr/local/src/sys/DADV amd64

>Description:
	GEOM now support upto 20 partitions within single BSD label.
	To raise default limit (8) one have to create label as such:

gpart create -s BSD -n 20 ad0s1

	But, "bsdlabel -e ad0s1" silently lowers limit down to 8
	and destroys partitions numbered 9 (i) and more even
	if one exits an editor without saving the label.


>How-To-Repeat:
	
	1. Create BSD label with command mentioned above:

gpart create -s BSD -n 20 ad0s1

	2. Use gpart to create 9 partitions within a slice:

gpart add -t freebsd-ufs -s 1G ad0s1
...
gpart add -t freebsd-ufs -s 1G ad0s1

	3. Use "gpart show" to make sure they are all created
	4. Use "bsdlabel -e ad0s1", don't change anything and exit your editor.
	5. Use "gpart show" to see that partition 9 has disappeared.
	6. "gpart add" not refuses to recreate partition 9 as limit is 8 now.

>Fix:

Unknown.
Silent partition deletion in not acceptable, as well as changing of limit.
>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/162332: commit references a PR
Date: Sun,  6 Nov 2011 18:59:57 +0000 (UTC)

 Author: ae
 Date: Sun Nov  6 18:59:42 2011
 New Revision: 227248
 URL: http://svn.freebsd.org/changeset/base/227248
 
 Log:
   bsdlabel(8) could automatically fill many of disklabel's deprecated
   fields, but user could specify some of those fields when edits disklabel
   with `bsdlabel -e`. But without -A flag these fields might be
   overwritten with default values from the virgin disklabel.
   So, don't overwrite such fields if they are not zero. Also add checks
   to prevent creating disklabel with less than DEFPARTITIONS and more
   than MAXPARTITIONS partitions.
   
   PR:		bin/162332
   Tested by:	Eugene Grosbein
   MFC after:	1 week
 
 Modified:
   head/sbin/bsdlabel/bsdlabel.c
 
 Modified: head/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- head/sbin/bsdlabel/bsdlabel.c	Sun Nov  6 18:50:39 2011	(r227247)
 +++ head/sbin/bsdlabel/bsdlabel.c	Sun Nov  6 18:59:42 2011	(r227248)
 @@ -836,6 +836,11 @@ getasciilabel(FILE *f, struct disklabel 
  				    "line %d: bad # of partitions\n", lineno);
  				lp->d_npartitions = MAXPARTITIONS;
  				errors++;
 +			} else if (v < DEFPARTITIONS) {
 +				fprintf(stderr,
 +				    "line %d: bad # of partitions\n", lineno);
 +				lp->d_npartitions = DEFPARTITIONS;
 +				errors++;
  			} else
  				lp->d_npartitions = v;
  			continue;
 @@ -1149,23 +1154,42 @@ checklabel(struct disklabel *lp)
  			errors++;
  		} else if (lp->d_bbsize % lp->d_secsize)
  			warnx("boot block size %% sector-size != 0");
 -		if (lp->d_npartitions > MAXPARTITIONS)
 +		if (lp->d_npartitions > MAXPARTITIONS) {
  			warnx("number of partitions (%lu) > MAXPARTITIONS (%d)",
  			    (u_long)lp->d_npartitions, MAXPARTITIONS);
 +			errors++;
 +		}
 +		if (lp->d_npartitions < DEFPARTITIONS) {
 +			warnx("number of partitions (%lu) < DEFPARTITIONS (%d)",
 +			    (u_long)lp->d_npartitions, DEFPARTITIONS);
 +			errors++;
 +		}
  	} else {
  		struct disklabel *vl;
  
  		vl = getvirginlabel();
 -		lp->d_secsize = vl->d_secsize;
 -		lp->d_nsectors = vl->d_nsectors;
 -		lp->d_ntracks = vl->d_ntracks;
 -		lp->d_ncylinders = vl->d_ncylinders;
 -		lp->d_rpm = vl->d_rpm;
 -		lp->d_interleave = vl->d_interleave;
 -		lp->d_secpercyl = vl->d_secpercyl;
 -		lp->d_secperunit = vl->d_secperunit;
 -		lp->d_bbsize = vl->d_bbsize;
 -		lp->d_npartitions = vl->d_npartitions;
 +		if (lp->d_secsize == 0)
 +			lp->d_secsize = vl->d_secsize;
 +		if (lp->d_nsectors == 0)
 +			lp->d_nsectors = vl->d_nsectors;
 +		if (lp->d_ntracks == 0)
 +			lp->d_ntracks = vl->d_ntracks;
 +		if (lp->d_ncylinders == 0)
 +			lp->d_ncylinders = vl->d_ncylinders;
 +		if (lp->d_rpm == 0)
 +			lp->d_rpm = vl->d_rpm;
 +		if (lp->d_interleave == 0)
 +			lp->d_interleave = vl->d_interleave;
 +		if (lp->d_secpercyl == 0)
 +			lp->d_secpercyl = vl->d_secpercyl;
 +		if (lp->d_secperunit == 0)
 +			lp->d_secperunit = vl->d_secperunit;
 +		if (lp->d_bbsize == 0)
 +			lp->d_bbsize = vl->d_bbsize;
 +		if (lp->d_npartitions == 0 ||
 +		    lp->d_npartitions < DEFPARTITIONS ||
 +		    lp->d_npartitions > MAXPARTITIONS)
 +			lp->d_npartitions = vl->d_npartitions;
  	}
  
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: ae 
State-Changed-When: Sun Nov 6 19:06:01 UTC 2011 
State-Changed-Why:  
Patched in head/. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/162332: commit references a PR
Date: Wed, 16 Nov 2011 15:32:41 +0000 (UTC)

 Author: ae
 Date: Wed Nov 16 15:32:32 2011
 New Revision: 227556
 URL: http://svn.freebsd.org/changeset/base/227556
 
 Log:
   MFC r227231:
     To be in sync with GEOM_PART_BSD limit the maximum number of supported
     partitions to 20.
   
   MFC r227248:
     bsdlabel(8) could automatically fill many of disklabel's deprecated
     fields, but user could specify some of those fields when edits disklabel
     with `bsdlabel -e`. But without -A flag these fields might be
     overwritten with default values from the virgin disklabel.
     So, don't overwrite such fields if they are not zero. Also add checks
     to prevent creating disklabel with less than DEFPARTITIONS and more
     than MAXPARTITIONS partitions.
   
     PR:		bin/162332
     Tested by:	Eugene Grosbein
   
   MFC r227262:
     Remove unneeded checks.
   
   MFC r227270:
     Add recommendation to use gpart(8) when user tries write disklabel
     or bootcode to already opened provider.
   
   MFC r227296:
     Fix multi-line comment formatting.
   
   Approved by:	re (kib)
 
 Modified:
   stable/9/sbin/bsdlabel/bsdlabel.c
 Directory Properties:
   stable/9/sbin/bsdlabel/   (props changed)
 
 Modified: stable/9/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- stable/9/sbin/bsdlabel/bsdlabel.c	Wed Nov 16 15:25:12 2011	(r227555)
 +++ stable/9/sbin/bsdlabel/bsdlabel.c	Wed Nov 16 15:32:32 2011	(r227556)
 @@ -63,7 +63,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/disk.h>
  #define DKTYPENAMES
  #define FSTYPENAMES
 -#define MAXPARTITIONS	26
 +#define MAXPARTITIONS	20
  #include <sys/disklabel.h>
  
  #include <unistd.h>
 @@ -80,7 +80,7 @@ __FBSDID("$FreeBSD$");
  #include "pathnames.h"
  
  static void	makelabel(const char *, struct disklabel *);
 -static int	geom_bsd_available(void);
 +static int	geom_class_available(const char *);
  static int	writelabel(void);
  static int	readlabel(int flag);
  static void	display(FILE *, const struct disklabel *);
 @@ -355,7 +355,7 @@ readboot(void)
  }
  
  static int
 -geom_bsd_available(void)
 +geom_class_available(const char *name)
  {
  	struct gclass *class;
  	struct gmesh mesh;
 @@ -366,7 +366,7 @@ geom_bsd_available(void)
  		errc(1, error, "Cannot get GEOM tree");
  
  	LIST_FOREACH(class, &mesh.lg_class, lg_class) {
 -		if (strcmp(class->lg_name, "BSD") == 0) {
 +		if (strcmp(class->lg_name, name) == 0) {
  			geom_deletetree(&mesh);
  			return (1);
  		}
 @@ -411,8 +411,20 @@ writelabel(void)
  		} else
  			serrno = errno;
  
 +		if (geom_class_available("PART") != 0) {
 +			/*
 +			 * Since we weren't able open provider for
 +			 * writing, then recommend user to use gpart(8).
 +			 */
 +			warnc(serrno,
 +			    "cannot open provider %s for writing label",
 +			    specname);
 +			warnx("Try to use gpart(8).");
 +			return (1);
 +		}
 +
  		/* Give up if GEOM_BSD is not available. */
 -		if (geom_bsd_available() == 0) {
 +		if (geom_class_available("BSD") == 0) {
  			warnc(serrno, "%s", specname);
  			return (1);
  		}
 @@ -831,11 +843,16 @@ getasciilabel(FILE *f, struct disklabel 
  			continue;
  		}
  		if (sscanf(cp, "%lu partitions", &v) == 1) {
 -			if (v == 0 || v > MAXPARTITIONS) {
 +			if (v > MAXPARTITIONS) {
  				fprintf(stderr,
  				    "line %d: bad # of partitions\n", lineno);
  				lp->d_npartitions = MAXPARTITIONS;
  				errors++;
 +			} else if (v < DEFPARTITIONS) {
 +				fprintf(stderr,
 +				    "line %d: bad # of partitions\n", lineno);
 +				lp->d_npartitions = DEFPARTITIONS;
 +				errors++;
  			} else
  				lp->d_npartitions = v;
  			continue;
 @@ -1149,23 +1166,41 @@ checklabel(struct disklabel *lp)
  			errors++;
  		} else if (lp->d_bbsize % lp->d_secsize)
  			warnx("boot block size %% sector-size != 0");
 -		if (lp->d_npartitions > MAXPARTITIONS)
 +		if (lp->d_npartitions > MAXPARTITIONS) {
  			warnx("number of partitions (%lu) > MAXPARTITIONS (%d)",
  			    (u_long)lp->d_npartitions, MAXPARTITIONS);
 +			errors++;
 +		}
 +		if (lp->d_npartitions < DEFPARTITIONS) {
 +			warnx("number of partitions (%lu) < DEFPARTITIONS (%d)",
 +			    (u_long)lp->d_npartitions, DEFPARTITIONS);
 +			errors++;
 +		}
  	} else {
  		struct disklabel *vl;
  
  		vl = getvirginlabel();
 -		lp->d_secsize = vl->d_secsize;
 -		lp->d_nsectors = vl->d_nsectors;
 -		lp->d_ntracks = vl->d_ntracks;
 -		lp->d_ncylinders = vl->d_ncylinders;
 -		lp->d_rpm = vl->d_rpm;
 -		lp->d_interleave = vl->d_interleave;
 -		lp->d_secpercyl = vl->d_secpercyl;
 -		lp->d_secperunit = vl->d_secperunit;
 -		lp->d_bbsize = vl->d_bbsize;
 -		lp->d_npartitions = vl->d_npartitions;
 +		if (lp->d_secsize == 0)
 +			lp->d_secsize = vl->d_secsize;
 +		if (lp->d_nsectors == 0)
 +			lp->d_nsectors = vl->d_nsectors;
 +		if (lp->d_ntracks == 0)
 +			lp->d_ntracks = vl->d_ntracks;
 +		if (lp->d_ncylinders == 0)
 +			lp->d_ncylinders = vl->d_ncylinders;
 +		if (lp->d_rpm == 0)
 +			lp->d_rpm = vl->d_rpm;
 +		if (lp->d_interleave == 0)
 +			lp->d_interleave = vl->d_interleave;
 +		if (lp->d_secpercyl == 0)
 +			lp->d_secpercyl = vl->d_secpercyl;
 +		if (lp->d_secperunit == 0)
 +			lp->d_secperunit = vl->d_secperunit;
 +		if (lp->d_bbsize == 0)
 +			lp->d_bbsize = vl->d_bbsize;
 +		if (lp->d_npartitions < DEFPARTITIONS ||
 +		    lp->d_npartitions > MAXPARTITIONS)
 +			lp->d_npartitions = vl->d_npartitions;
  	}
  
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/162332: commit references a PR
Date: Wed, 16 Nov 2011 15:33:05 +0000 (UTC)

 Author: ae
 Date: Wed Nov 16 15:32:52 2011
 New Revision: 227557
 URL: http://svn.freebsd.org/changeset/base/227557
 
 Log:
   MFC r227231:
     To be in sync with GEOM_PART_BSD limit the maximum number of supported
     partitions to 20.
   
   MFC r227248:
     bsdlabel(8) could automatically fill many of disklabel's deprecated
     fields, but user could specify some of those fields when edits disklabel
     with `bsdlabel -e`. But without -A flag these fields might be
     overwritten with default values from the virgin disklabel.
     So, don't overwrite such fields if they are not zero. Also add checks
     to prevent creating disklabel with less than DEFPARTITIONS and more
     than MAXPARTITIONS partitions.
   
     PR:           bin/162332
     Tested by:    Eugene Grosbein
   
   MFC r227262:
     Remove unneeded checks.
   
   MFC r227270:
     Add recommendation to use gpart(8) when user tries write disklabel
     or bootcode to already opened provider.
   
   MFC r227296:
     Fix multi-line comment formatting.
   
   Approved by:    re (kib)
 
 Modified:
   releng/9.0/sbin/bsdlabel/bsdlabel.c
 Directory Properties:
   releng/9.0/sbin/bsdlabel/   (props changed)
 
 Modified: releng/9.0/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- releng/9.0/sbin/bsdlabel/bsdlabel.c	Wed Nov 16 15:32:32 2011	(r227556)
 +++ releng/9.0/sbin/bsdlabel/bsdlabel.c	Wed Nov 16 15:32:52 2011	(r227557)
 @@ -63,7 +63,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/disk.h>
  #define DKTYPENAMES
  #define FSTYPENAMES
 -#define MAXPARTITIONS	26
 +#define MAXPARTITIONS	20
  #include <sys/disklabel.h>
  
  #include <unistd.h>
 @@ -80,7 +80,7 @@ __FBSDID("$FreeBSD$");
  #include "pathnames.h"
  
  static void	makelabel(const char *, struct disklabel *);
 -static int	geom_bsd_available(void);
 +static int	geom_class_available(const char *);
  static int	writelabel(void);
  static int	readlabel(int flag);
  static void	display(FILE *, const struct disklabel *);
 @@ -355,7 +355,7 @@ readboot(void)
  }
  
  static int
 -geom_bsd_available(void)
 +geom_class_available(const char *name)
  {
  	struct gclass *class;
  	struct gmesh mesh;
 @@ -366,7 +366,7 @@ geom_bsd_available(void)
  		errc(1, error, "Cannot get GEOM tree");
  
  	LIST_FOREACH(class, &mesh.lg_class, lg_class) {
 -		if (strcmp(class->lg_name, "BSD") == 0) {
 +		if (strcmp(class->lg_name, name) == 0) {
  			geom_deletetree(&mesh);
  			return (1);
  		}
 @@ -411,8 +411,20 @@ writelabel(void)
  		} else
  			serrno = errno;
  
 +		if (geom_class_available("PART") != 0) {
 +			/*
 +			 * Since we weren't able open provider for
 +			 * writing, then recommend user to use gpart(8).
 +			 */
 +			warnc(serrno,
 +			    "cannot open provider %s for writing label",
 +			    specname);
 +			warnx("Try to use gpart(8).");
 +			return (1);
 +		}
 +
  		/* Give up if GEOM_BSD is not available. */
 -		if (geom_bsd_available() == 0) {
 +		if (geom_class_available("BSD") == 0) {
  			warnc(serrno, "%s", specname);
  			return (1);
  		}
 @@ -831,11 +843,16 @@ getasciilabel(FILE *f, struct disklabel 
  			continue;
  		}
  		if (sscanf(cp, "%lu partitions", &v) == 1) {
 -			if (v == 0 || v > MAXPARTITIONS) {
 +			if (v > MAXPARTITIONS) {
  				fprintf(stderr,
  				    "line %d: bad # of partitions\n", lineno);
  				lp->d_npartitions = MAXPARTITIONS;
  				errors++;
 +			} else if (v < DEFPARTITIONS) {
 +				fprintf(stderr,
 +				    "line %d: bad # of partitions\n", lineno);
 +				lp->d_npartitions = DEFPARTITIONS;
 +				errors++;
  			} else
  				lp->d_npartitions = v;
  			continue;
 @@ -1149,23 +1166,41 @@ checklabel(struct disklabel *lp)
  			errors++;
  		} else if (lp->d_bbsize % lp->d_secsize)
  			warnx("boot block size %% sector-size != 0");
 -		if (lp->d_npartitions > MAXPARTITIONS)
 +		if (lp->d_npartitions > MAXPARTITIONS) {
  			warnx("number of partitions (%lu) > MAXPARTITIONS (%d)",
  			    (u_long)lp->d_npartitions, MAXPARTITIONS);
 +			errors++;
 +		}
 +		if (lp->d_npartitions < DEFPARTITIONS) {
 +			warnx("number of partitions (%lu) < DEFPARTITIONS (%d)",
 +			    (u_long)lp->d_npartitions, DEFPARTITIONS);
 +			errors++;
 +		}
  	} else {
  		struct disklabel *vl;
  
  		vl = getvirginlabel();
 -		lp->d_secsize = vl->d_secsize;
 -		lp->d_nsectors = vl->d_nsectors;
 -		lp->d_ntracks = vl->d_ntracks;
 -		lp->d_ncylinders = vl->d_ncylinders;
 -		lp->d_rpm = vl->d_rpm;
 -		lp->d_interleave = vl->d_interleave;
 -		lp->d_secpercyl = vl->d_secpercyl;
 -		lp->d_secperunit = vl->d_secperunit;
 -		lp->d_bbsize = vl->d_bbsize;
 -		lp->d_npartitions = vl->d_npartitions;
 +		if (lp->d_secsize == 0)
 +			lp->d_secsize = vl->d_secsize;
 +		if (lp->d_nsectors == 0)
 +			lp->d_nsectors = vl->d_nsectors;
 +		if (lp->d_ntracks == 0)
 +			lp->d_ntracks = vl->d_ntracks;
 +		if (lp->d_ncylinders == 0)
 +			lp->d_ncylinders = vl->d_ncylinders;
 +		if (lp->d_rpm == 0)
 +			lp->d_rpm = vl->d_rpm;
 +		if (lp->d_interleave == 0)
 +			lp->d_interleave = vl->d_interleave;
 +		if (lp->d_secpercyl == 0)
 +			lp->d_secpercyl = vl->d_secpercyl;
 +		if (lp->d_secperunit == 0)
 +			lp->d_secperunit = vl->d_secperunit;
 +		if (lp->d_bbsize == 0)
 +			lp->d_bbsize = vl->d_bbsize;
 +		if (lp->d_npartitions < DEFPARTITIONS ||
 +		    lp->d_npartitions > MAXPARTITIONS)
 +			lp->d_npartitions = vl->d_npartitions;
  	}
  
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/162332: commit references a PR
Date: Wed, 16 Nov 2011 16:24:46 +0000 (UTC)

 Author: ae
 Date: Wed Nov 16 16:24:36 2011
 New Revision: 227564
 URL: http://svn.freebsd.org/changeset/base/227564
 
 Log:
   MFC r227231:
     To be in sync with GEOM_PART_BSD limit the maximum number of supported
     partitions to 20.
   
   MFC r227248:
     bsdlabel(8) could automatically fill many of disklabel's deprecated
     fields, but user could specify some of those fields when edits disklabel
     with `bsdlabel -e`. But without -A flag these fields might be
     overwritten with default values from the virgin disklabel.
     So, don't overwrite such fields if they are not zero. Also add checks
     to prevent creating disklabel with less than DEFPARTITIONS and more
     than MAXPARTITIONS partitions.
   
     PR:		bin/162332
     Tested by:	Eugene Grosbein
   
   MFC r227262:
     Remove unneeded checks.
   
   MFC r227270:
     Add recommendation to use gpart(8) when user tries write disklabel
     or bootcode to already opened provider.
   
   M2C r227296:
     Fix multi-line comment formatting.
 
 Modified:
   stable/8/sbin/bsdlabel/bsdlabel.c
 Directory Properties:
   stable/8/sbin/bsdlabel/   (props changed)
 
 Modified: stable/8/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- stable/8/sbin/bsdlabel/bsdlabel.c	Wed Nov 16 16:15:31 2011	(r227563)
 +++ stable/8/sbin/bsdlabel/bsdlabel.c	Wed Nov 16 16:24:36 2011	(r227564)
 @@ -63,7 +63,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/disk.h>
  #define DKTYPENAMES
  #define FSTYPENAMES
 -#define MAXPARTITIONS	26
 +#define MAXPARTITIONS	20
  #include <sys/disklabel.h>
  
  #include <unistd.h>
 @@ -80,7 +80,7 @@ __FBSDID("$FreeBSD$");
  #include "pathnames.h"
  
  static void	makelabel(const char *, struct disklabel *);
 -static int	geom_bsd_available(void);
 +static int	geom_class_available(const char *);
  static int	writelabel(void);
  static int	readlabel(int flag);
  static void	display(FILE *, const struct disklabel *);
 @@ -354,7 +354,7 @@ readboot(void)
  }
  
  static int
 -geom_bsd_available(void)
 +geom_class_available(const char *name)
  {
  	struct gclass *class;
  	struct gmesh mesh;
 @@ -365,7 +365,7 @@ geom_bsd_available(void)
  		errc(1, error, "Cannot get GEOM tree");
  
  	LIST_FOREACH(class, &mesh.lg_class, lg_class) {
 -		if (strcmp(class->lg_name, "BSD") == 0) {
 +		if (strcmp(class->lg_name, name) == 0) {
  			geom_deletetree(&mesh);
  			return (1);
  		}
 @@ -410,8 +410,20 @@ writelabel(void)
  		} else
  			serrno = errno;
  
 +		if (geom_class_available("PART") != 0) {
 +			/*
 +			 * Since we weren't able open provider for
 +			 * writing, then recommend user to use gpart(8).
 +			 */
 +			warnc(serrno,
 +			    "cannot open provider %s for writing label",
 +			    specname);
 +			warnx("Try to use gpart(8).");
 +			return (1);
 +		}
 +
  		/* Give up if GEOM_BSD is not available. */
 -		if (geom_bsd_available() == 0) {
 +		if (geom_class_available("BSD") == 0) {
  			warnc(serrno, "%s", specname);
  			return (1);
  		}
 @@ -824,11 +836,16 @@ getasciilabel(FILE *f, struct disklabel 
  			continue;
  		}
  		if (sscanf(cp, "%lu partitions", &v) == 1) {
 -			if (v == 0 || v > MAXPARTITIONS) {
 +			if (v > MAXPARTITIONS) {
  				fprintf(stderr,
  				    "line %d: bad # of partitions\n", lineno);
  				lp->d_npartitions = MAXPARTITIONS;
  				errors++;
 +			} else if (v < DEFPARTITIONS) {
 +				fprintf(stderr,
 +				    "line %d: bad # of partitions\n", lineno);
 +				lp->d_npartitions = DEFPARTITIONS;
 +				errors++;
  			} else
  				lp->d_npartitions = v;
  			continue;
 @@ -1142,23 +1159,41 @@ checklabel(struct disklabel *lp)
  			errors++;
  		} else if (lp->d_bbsize % lp->d_secsize)
  			warnx("boot block size %% sector-size != 0");
 -		if (lp->d_npartitions > MAXPARTITIONS)
 +		if (lp->d_npartitions > MAXPARTITIONS) {
  			warnx("number of partitions (%lu) > MAXPARTITIONS (%d)",
  			    (u_long)lp->d_npartitions, MAXPARTITIONS);
 +			errors++;
 +		}
 +		if (lp->d_npartitions < DEFPARTITIONS) {
 +			warnx("number of partitions (%lu) < DEFPARTITIONS (%d)",
 +			    (u_long)lp->d_npartitions, DEFPARTITIONS);
 +			errors++;
 +		}
  	} else {
  		struct disklabel *vl;
  
  		vl = getvirginlabel();
 -		lp->d_secsize = vl->d_secsize;
 -		lp->d_nsectors = vl->d_nsectors;
 -		lp->d_ntracks = vl->d_ntracks;
 -		lp->d_ncylinders = vl->d_ncylinders;
 -		lp->d_rpm = vl->d_rpm;
 -		lp->d_interleave = vl->d_interleave;
 -		lp->d_secpercyl = vl->d_secpercyl;
 -		lp->d_secperunit = vl->d_secperunit;
 -		lp->d_bbsize = vl->d_bbsize;
 -		lp->d_npartitions = vl->d_npartitions;
 +		if (lp->d_secsize == 0)
 +			lp->d_secsize = vl->d_secsize;
 +		if (lp->d_nsectors == 0)
 +			lp->d_nsectors = vl->d_nsectors;
 +		if (lp->d_ntracks == 0)
 +			lp->d_ntracks = vl->d_ntracks;
 +		if (lp->d_ncylinders == 0)
 +			lp->d_ncylinders = vl->d_ncylinders;
 +		if (lp->d_rpm == 0)
 +			lp->d_rpm = vl->d_rpm;
 +		if (lp->d_interleave == 0)
 +			lp->d_interleave = vl->d_interleave;
 +		if (lp->d_secpercyl == 0)
 +			lp->d_secpercyl = vl->d_secpercyl;
 +		if (lp->d_secperunit == 0)
 +			lp->d_secperunit = vl->d_secperunit;
 +		if (lp->d_bbsize == 0)
 +			lp->d_bbsize = vl->d_bbsize;
 +		if (lp->d_npartitions < DEFPARTITIONS ||
 +		    lp->d_npartitions > MAXPARTITIONS)
 +			lp->d_npartitions = vl->d_npartitions;
  	}
  
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: ae 
State-Changed-When: Wed Nov 16 16:58:09 UTC 2011 
State-Changed-Why:  
Merged to stable/9, releng/9.0 and stable/8. Thanks! 

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