From owner-svn-src-stable@FreeBSD.ORG Wed Nov 16 16:24:36 2011 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DD9961065670; Wed, 16 Nov 2011 16:24:36 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CC9A78FC17; Wed, 16 Nov 2011 16:24:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pAGGOavm056898; Wed, 16 Nov 2011 16:24:36 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pAGGOa0n056896; Wed, 16 Nov 2011 16:24:36 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201111161624.pAGGOa0n056896@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Nov 2011 16:24:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r227564 - stable/8/sbin/bsdlabel X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Nov 2011 16:24:37 -0000 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 #define DKTYPENAMES #define FSTYPENAMES -#define MAXPARTITIONS 26 +#define MAXPARTITIONS 20 #include #include @@ -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; }