From owner-svn-src-stable@FreeBSD.ORG Sun Sep 26 16:52:06 2010 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 23FD91065672; Sun, 26 Sep 2010 16:52:06 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id ECB2F8FC15; Sun, 26 Sep 2010 16:52:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o8QGq5Jr097974; Sun, 26 Sep 2010 16:52:05 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8QGq5i9097972; Sun, 26 Sep 2010 16:52:05 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201009261652.o8QGq5i9097972@svn.freebsd.org> From: Jaakko Heinonen Date: Sun, 26 Sep 2010 16:52:05 +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: r213186 - 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: Sun, 26 Sep 2010 16:52:06 -0000 Author: jh Date: Sun Sep 26 16:52:05 2010 New Revision: 213186 URL: http://svn.freebsd.org/changeset/base/213186 Log: MFC r211873: Don't attempt to write label with GEOM_BSD based method if the class is not available. This improves error reporting when bsdlabel(8) is unable to open a device for writing. If GEOM_BSD was unavailable, only a rather obscure error message "Class not found" was printed. PR: bin/58390 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 Sun Sep 26 14:20:09 2010 (r213185) +++ stable/8/sbin/bsdlabel/bsdlabel.c Sun Sep 26 16:52:05 2010 (r213186) @@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$"); #include "pathnames.h" static void makelabel(const char *, struct disklabel *); +static int geom_bsd_available(void); static int writelabel(void); static int readlabel(int flag); static void display(FILE *, const struct disklabel *); @@ -379,10 +380,33 @@ readboot(void) } static int +geom_bsd_available(void) +{ + struct gclass *class; + struct gmesh mesh; + int error; + + error = geom_gettree(&mesh); + if (error != 0) + errc(1, error, "Cannot get GEOM tree"); + + LIST_FOREACH(class, &mesh.lg_class, lg_class) { + if (strcmp(class->lg_name, "BSD") == 0) { + geom_deletetree(&mesh); + return (1); + } + } + + geom_deletetree(&mesh); + + return (0); +} + +static int writelabel(void) { uint64_t *p, sum; - int i, fd; + int i, fd, serrno; struct gctl_req *grq; char const *errstr; struct disklabel *lp = &lab; @@ -416,6 +440,13 @@ writelabel(void) if (is_file) { warn("cannot open file %s for writing label", specname); return(1); + } else + serrno = errno; + + /* Give up if GEOM_BSD is not available. */ + if (geom_bsd_available() == 0) { + warnc(serrno, "%s", specname); + return (1); } grq = gctl_get_handle();