Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Aug 2010 11:08:11 +0000 (UTC)
From:      Jaakko Heinonen <jh@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r211873 - head/sbin/bsdlabel
Message-ID:  <201008271108.o7RB8Bhv075962@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jh
Date: Fri Aug 27 11:08:11 2010
New Revision: 211873
URL: http://svn.freebsd.org/changeset/base/211873

Log:
  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
  Reviewed by:	ae
  Discussed with:	marcel
  MFC after:	1 month

Modified:
  head/sbin/bsdlabel/bsdlabel.c

Modified: head/sbin/bsdlabel/bsdlabel.c
==============================================================================
--- head/sbin/bsdlabel/bsdlabel.c	Fri Aug 27 10:47:17 2010	(r211872)
+++ head/sbin/bsdlabel/bsdlabel.c	Fri Aug 27 11:08:11 2010	(r211873)
@@ -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();



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008271108.o7RB8Bhv075962>