Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Mar 2009 20:38:57 +0000 (UTC)
From:      Ivan Voras <ivoras@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r190423 - head/sys/geom/label
Message-ID:  <200903252038.n2PKcvee087615@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ivoras
Date: Wed Mar 25 20:38:57 2009
New Revision: 190423
URL: http://svn.freebsd.org/changeset/base/190423

Log:
  Create GEOM labels from UFS IDs, e.g. /dev/ufsid/49c97b1faa2adc43. UFS IDs
  are always present and can be used to identify file systems (useful if
  hardware devices move often).
  
  Actually-by:	pjd
  Approved by:	gnn (mentor)

Modified:
  head/sys/geom/label/g_label.c
  head/sys/geom/label/g_label.h
  head/sys/geom/label/g_label_ufs.c

Modified: head/sys/geom/label/g_label.c
==============================================================================
--- head/sys/geom/label/g_label.c	Wed Mar 25 20:15:48 2009	(r190422)
+++ head/sys/geom/label/g_label.c	Wed Mar 25 20:38:57 2009	(r190423)
@@ -77,7 +77,8 @@ struct g_class g_label_class = {
  * 6. Add your file system to manual page sbin/geom/class/label/glabel.8.
  */
 const struct g_label_desc *g_labels[] = {
-	&g_label_ufs,
+	&g_label_ufs_id,
+	&g_label_ufs_volume,
 	&g_label_iso9660,
 	&g_label_msdosfs,
 	&g_label_ext2fs,

Modified: head/sys/geom/label/g_label.h
==============================================================================
--- head/sys/geom/label/g_label.h	Wed Mar 25 20:15:48 2009	(r190422)
+++ head/sys/geom/label/g_label.h	Wed Mar 25 20:38:57 2009	(r190423)
@@ -64,7 +64,8 @@ struct g_label_desc {
 };
 
 /* Supported labels. */
-extern const struct g_label_desc g_label_ufs;
+extern const struct g_label_desc g_label_ufs_id;
+extern const struct g_label_desc g_label_ufs_volume;
 extern const struct g_label_desc g_label_iso9660;
 extern const struct g_label_desc g_label_msdosfs;
 extern const struct g_label_desc g_label_ext2fs;

Modified: head/sys/geom/label/g_label_ufs.c
==============================================================================
--- head/sys/geom/label/g_label_ufs.c	Wed Mar 25 20:15:48 2009	(r190422)
+++ head/sys/geom/label/g_label_ufs.c	Wed Mar 25 20:38:57 2009	(r190423)
@@ -39,12 +39,16 @@ __FBSDID("$FreeBSD$");
 #include <geom/geom.h>
 #include <geom/label/g_label.h>
 
-#define G_LABEL_UFS_DIR	"ufs"
+#define G_LABEL_UFS_VOLUME_DIR	"ufs"
+#define G_LABEL_UFS_ID_DIR	"ufsid"
+
+#define	G_LABEL_UFS_VOLUME	0
+#define	G_LABEL_UFS_ID		1
 
 static const int superblocks[] = SBLOCKSEARCH;
 
 static void
-g_label_ufs_taste(struct g_consumer *cp, char *label, size_t size)
+g_label_ufs_taste_common(struct g_consumer *cp, char *label, size_t size, int what)
 {
 	struct g_provider *pp;
 	int sb, superblock;
@@ -96,18 +100,50 @@ g_label_ufs_taste(struct g_consumer *cp,
 		}
 		G_LABEL_DEBUG(1, "%s file system detected on %s.",
 		    fs->fs_magic == FS_UFS1_MAGIC ? "UFS1" : "UFS2", pp->name);
-		/* Check for volume label */
-		if (fs->fs_volname[0] == '\0') {
-			g_free(fs);
-			continue;
+		switch (what) {
+		case G_LABEL_UFS_VOLUME:
+			/* Check for volume label */
+			if (fs->fs_volname[0] == '\0') {
+				g_free(fs);
+				continue;
+			}
+			strlcpy(label, fs->fs_volname, size);
+			break;
+		case G_LABEL_UFS_ID:
+			if (fs->fs_id[0] == 0 && fs->fs_id[1] == 0) {
+				g_free(fs);
+				continue;
+			}
+			snprintf(label, size, "%08x%08x", fs->fs_id[0],
+			    fs->fs_id[1]);
+			break;
 		}
-		strlcpy(label, fs->fs_volname, size);
 		g_free(fs);
 		break;
 	}
 }
 
-const struct g_label_desc g_label_ufs = {
-	.ld_taste = g_label_ufs_taste,
-	.ld_dir = G_LABEL_UFS_DIR
+static void
+g_label_ufs_volume_taste(struct g_consumer *cp, char *label, size_t size)
+{
+
+	g_label_ufs_taste_common(cp, label, size, G_LABEL_UFS_VOLUME);
+}
+
+static void
+g_label_ufs_id_taste(struct g_consumer *cp, char *label, size_t size)
+{
+
+	g_label_ufs_taste_common(cp, label, size, G_LABEL_UFS_ID);
+}
+
+
+const struct g_label_desc g_label_ufs_volume = {
+	.ld_taste = g_label_ufs_volume_taste,
+	.ld_dir = G_LABEL_UFS_VOLUME_DIR
+};
+
+const struct g_label_desc g_label_ufs_id = {
+	.ld_taste = g_label_ufs_id_taste,
+	.ld_dir = G_LABEL_UFS_ID_DIR
 };



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