Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jan 2016 16:38:09 +0000 (UTC)
From:      Allan Jude <allanjude@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r293776 - stable/10/usr.sbin/fstyp
Message-ID:  <201601121638.u0CGc9cJ076217@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: allanjude
Date: Tue Jan 12 16:38:09 2016
New Revision: 293776
URL: https://svnweb.freebsd.org/changeset/base/293776

Log:
  MFC: r284589
    Add the ability to detect ZFS and GELI encrypted file systems to fstyp(8)
  
  MFC: r284644
    Fix GCC Warnings
  
  MFC: r284728
    Only build ZFS support in absense of WITHOUT_ZFS
  
  MFC: r285426
    Remove excess copyrights
  
  MFC: r286569
    Use GELI sentinel constant
  
  MFC: r287937
    Eliminate unneeded copying of vdev data, goto, etc. and add a note
    that checksum of vdev label should be checked (which is not done
    currently).
  
    No functional change.
  
    While I'm there, raise WARNS to 2.
  
  MFC: r292757
    Fix order of includes in usr.sbin/fstyp/zfs.c
  
  MFC: r292829
    Eliminate unneeded includes.

Added:
  stable/10/usr.sbin/fstyp/geli.c
     - copied, changed from r284589, head/usr.sbin/fstyp/geli.c
  stable/10/usr.sbin/fstyp/zfs.c
     - copied, changed from r284589, head/usr.sbin/fstyp/zfs.c
Modified:
  stable/10/usr.sbin/fstyp/Makefile
  stable/10/usr.sbin/fstyp/fstyp.8
  stable/10/usr.sbin/fstyp/fstyp.c
  stable/10/usr.sbin/fstyp/fstyp.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/fstyp/Makefile
==============================================================================
--- stable/10/usr.sbin/fstyp/Makefile	Tue Jan 12 16:31:07 2016	(r293775)
+++ stable/10/usr.sbin/fstyp/Makefile	Tue Jan 12 16:38:09 2016	(r293776)
@@ -3,13 +3,43 @@
 .include <bsd.own.mk>
 
 PROG=	fstyp
-SRCS=	fstyp.c ext2fs.c cd9660.c msdosfs.c ntfs.c ufs.c
+SRCS=	cd9660.c ext2fs.c fstyp.c geli.c msdosfs.c ntfs.c ufs.c
+
+.if ${MK_ZFS} != "no"
+SRCS +=	zfs.c
+.endif
+
 MAN=	fstyp.8
 
-WARNS=	6
+WARNS?=	2
 
 .if ${MK_TESTS} != "no"
 SUBDIR+=	tests
 .endif
 
+CFLAGS+=-I${.CURDIR}/../../sys
+
+.if ${MK_ZFS} != "no"
+IGNORE_PRAGMA=  YES
+
+CFLAGS+= -DNEED_SOLARIS_BOOLEAN -DHAVE_ZFS
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/compat/opensolaris
+CFLAGS+= -I${.CURDIR}/../../cddl/compat/opensolaris/include
+CFLAGS+= -I${.CURDIR}/../../cddl/compat/opensolaris/lib/libumem
+CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libnvpair
+CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libzpool/common
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common/fs/zfs
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common/sys
+CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/head
+.endif
+
+DPADD=   ${LIBGEOM} ${LIBMD}
+LDADD=   -lgeom -lmd
+
+.if ${MK_ZFS} != "no"
+DPADD += ${LIBNVPAIR} ${LIBZFS}
+LDADD += -lnvpair -lzfs
+.endif
+
 .include <bsd.prog.mk>

Modified: stable/10/usr.sbin/fstyp/fstyp.8
==============================================================================
--- stable/10/usr.sbin/fstyp/fstyp.8	Tue Jan 12 16:31:07 2016	(r293775)
+++ stable/10/usr.sbin/fstyp/fstyp.8	Tue Jan 12 16:38:09 2016	(r293776)
@@ -37,20 +37,42 @@
 .Nm
 .Op Fl l
 .Op Fl s
+.Op Fl u
 .Ar special
 .Sh DESCRIPTION
 The
 .Nm
 utility is used to determine the filesystem type on a given device.
 It can recognize ISO-9660, Ext2, FAT, NTFS, and UFS filesystems.
+When the
+.Fl u
+flag is specified,
+.Nm
+also recognizes certain additional metadata formats that cannot be
+handled using
+.Xr mount 8 ,
+such as ZFS pools and
+.Xr geli 8
+providers.
+.Pp
 The filesystem name is printed to the standard output
-as, respectively,
-.Li cd9660 ,
-.Li ext2fs ,
-.Li msdosfs ,
-.Li ntfs ,
-or
-.Li ufs .
+as, respectively:
+.Bl -item -offset indent -compact
+.It
+cd9660
+.It
+ext2fs
+.It
+geli
+.It
+msdosfs
+.It
+ntfs
+.It
+ufs
+.It
+zfs
+.El
 .Pp
 Because
 .Nm
@@ -73,6 +95,9 @@ By default,
 only works on regular files and disk-like device nodes.
 Trying to read other file types might have unexpected consequences or hang
 indefinitely.
+.It Fl u
+Include filesystems and devices that cannot be mounted directly by
+.Xr mount 8 .
 .El
 .Sh EXIT STATUS
 The
@@ -82,8 +107,11 @@ type is not recognized.
 .Sh SEE ALSO
 .Xr file 1 ,
 .Xr capsicum 4 ,
+.Xr autofs 8 ,
+.Xr geli 8 ,
 .Xr glabel 8 ,
-.Xr mount 8
+.Xr mount 8 ,
+.Xr zpool 8
 .Sh HISTORY
 The
 .Nm
@@ -95,3 +123,5 @@ The
 utility was developed by
 .An Edward Tomasz Napierala Aq Mt trasz@FreeBSD.org
 under sponsorship from the FreeBSD Foundation.
+ZFS and GELI support was added by
+.An Allan Jude Aq Mt allanjude@FreeBSD.org

Modified: stable/10/usr.sbin/fstyp/fstyp.c
==============================================================================
--- stable/10/usr.sbin/fstyp/fstyp.c	Tue Jan 12 16:31:07 2016	(r293775)
+++ stable/10/usr.sbin/fstyp/fstyp.c	Tue Jan 12 16:38:09 2016	(r293776)
@@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <stdbool.h>
 #include <stddef.h>
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -55,13 +54,18 @@ typedef int (*fstyp_function)(FILE *, ch
 static struct {
 	const char	*name;
 	fstyp_function	function;
+	bool		unmountable;
 } fstypes[] = {
-	{ "cd9660", &fstyp_cd9660 },
-	{ "ext2fs", &fstyp_ext2fs },
-	{ "msdosfs", &fstyp_msdosfs },
-	{ "ntfs", &fstyp_ntfs },
-	{ "ufs", &fstyp_ufs },
-	{ NULL, NULL }
+	{ "cd9660", &fstyp_cd9660, false },
+	{ "ext2fs", &fstyp_ext2fs, false },
+	{ "geli", &fstyp_geli, true },
+	{ "msdosfs", &fstyp_msdosfs, false },
+	{ "ntfs", &fstyp_ntfs, false },
+	{ "ufs", &fstyp_ufs, false },
+#ifdef HAVE_ZFS
+	{ "zfs", &fstyp_zfs, true },
+#endif
+	{ NULL, NULL, NULL }
 };
 
 void *
@@ -124,7 +128,7 @@ static void
 usage(void)
 {
 
-	fprintf(stderr, "usage: fstyp [-l][-s] special\n");
+	fprintf(stderr, "usage: fstyp [-l] [-s] [-u] special\n");
 	exit(1);
 }
 
@@ -153,13 +157,13 @@ int
 main(int argc, char **argv)
 {
 	int ch, error, i, nbytes;
-	bool ignore_type = false, show_label = false;
+	bool ignore_type = false, show_label = false, show_unmountable = false;
 	char label[LABEL_LEN + 1], strvised[LABEL_LEN * 4 + 1];
 	char *path;
 	FILE *fp;
 	fstyp_function fstyp_f;
 
-	while ((ch = getopt(argc, argv, "ls")) != -1) {
+	while ((ch = getopt(argc, argv, "lsu")) != -1) {
 		switch (ch) {
 		case 'l':
 			show_label = true;
@@ -167,6 +171,9 @@ main(int argc, char **argv)
 		case 's':
 			ignore_type = true;
 			break;
+		case 'u':
+			show_unmountable = true;
+			break;
 		default:
 			usage();
 		}
@@ -193,6 +200,8 @@ main(int argc, char **argv)
 	memset(label, '\0', sizeof(label));
 
 	for (i = 0;; i++) {
+		if (show_unmountable == false && fstypes[i].unmountable == true)
+			continue;
 		fstyp_f = fstypes[i].function;
 		if (fstyp_f == NULL)
 			break;

Modified: stable/10/usr.sbin/fstyp/fstyp.h
==============================================================================
--- stable/10/usr.sbin/fstyp/fstyp.h	Tue Jan 12 16:31:07 2016	(r293775)
+++ stable/10/usr.sbin/fstyp/fstyp.h	Tue Jan 12 16:38:09 2016	(r293776)
@@ -40,8 +40,12 @@ void	rtrim(char *label, size_t size);
 
 int	fstyp_cd9660(FILE *fp, char *label, size_t size);
 int	fstyp_ext2fs(FILE *fp, char *label, size_t size);
+int	fstyp_geli(FILE *fp, char *label, size_t size);
 int	fstyp_msdosfs(FILE *fp, char *label, size_t size);
 int	fstyp_ntfs(FILE *fp, char *label, size_t size);
 int	fstyp_ufs(FILE *fp, char *label, size_t size);
+#ifdef HAVE_ZFS
+int	fstyp_zfs(FILE *fp, char *label, size_t size);
+#endif
 
 #endif /* !FSTYP_H */

Copied and modified: stable/10/usr.sbin/fstyp/geli.c (from r284589, head/usr.sbin/fstyp/geli.c)
==============================================================================
--- head/usr.sbin/fstyp/geli.c	Fri Jun 19 05:09:02 2015	(r284589, copy source)
+++ stable/10/usr.sbin/fstyp/geli.c	Tue Jan 12 16:38:09 2016	(r293776)
@@ -2,9 +2,6 @@
  * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org>
  * All rights reserved.
  *
- * This software was developed by Edward Tomasz Napierala under sponsorship
- * from the FreeBSD Foundation.
- *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -32,11 +29,9 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/disk.h>
 #include <sys/types.h>
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 
 #include <geom/eli/g_eli.h>
 
@@ -64,7 +59,7 @@ fstyp_geli(FILE *fp, char *label __unuse
 	if (error)
 		goto gelierr;
 
-	if (strncmp(md.md_magic, "GEOM::ELI", 9) == 0) {
+	if (strcmp(md.md_magic, G_ELI_MAGIC) == 0) {
 		free(buf);
 		return (0);
 	}

Copied and modified: stable/10/usr.sbin/fstyp/zfs.c (from r284589, head/usr.sbin/fstyp/zfs.c)
==============================================================================
--- head/usr.sbin/fstyp/zfs.c	Fri Jun 19 05:09:02 2015	(r284589, copy source)
+++ stable/10/usr.sbin/fstyp/zfs.c	Tue Jan 12 16:38:09 2016	(r293776)
@@ -1,10 +1,8 @@
 /*-
  * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org>
+ * Copyright (c) 2015 Xin LI <delphij@FreeBSD.org>
  * All rights reserved.
  *
- * This software was developed by Edward Tomasz Napierala under sponsorship
- * from the FreeBSD Foundation.
- *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -31,6 +29,9 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
+#include <cddl/compat/opensolaris/sys/types.h>
+#include <sys/time.h>
+#include <cddl/compat/opensolaris/sys/time.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -45,29 +46,33 @@ __FBSDID("$FreeBSD$");
 int
 fstyp_zfs(FILE *fp, char *label, size_t labelsize)
 {
-	vdev_label_t *zpool_ptr = NULL;
-	vdev_label_t zpool_label;
-	char *buf = zpool_label.vl_vdev_phys.vp_nvlist;
+	vdev_label_t *vdev_label = NULL;
+	vdev_phys_t *vdev_phys;
 	char *zpool_name = NULL;
-	size_t buflen = sizeof (zpool_label.vl_vdev_phys.vp_nvlist);
 	nvlist_t *config = NULL;
+	int err = 0;
 
-	zpool_ptr = (vdev_label_t *)read_buf(fp, 0, sizeof(zpool_label));
-	if (zpool_ptr == NULL)
+	/*
+	 * Read in the first ZFS vdev label ("L0"), located at the beginning
+	 * of the vdev and extract the pool name from it.
+	 *
+	 * TODO: the checksum of label should be validated.
+	 */
+	vdev_label = (vdev_label_t *)read_buf(fp, 0, sizeof(*vdev_label));
+	if (vdev_label == NULL)
 		return (1);
-	zpool_label = *zpool_ptr;
-	if (nvlist_unpack(buf, buflen, &config, 0) != 0)
-		goto zfserr;
-	if (nvlist_lookup_string(config, "name", &zpool_name) != 0)
-		goto zfserr;
-	strlcpy(label, zpool_name, labelsize);
-	nvlist_free(config);
-	free(zpool_ptr);
-	return (0);
 
-zfserr:
+	vdev_phys = &(vdev_label->vl_vdev_phys);
+
+	if ((nvlist_unpack(vdev_phys->vp_nvlist, sizeof(vdev_phys->vp_nvlist),
+	    &config, 0)) == 0 &&
+	    (nvlist_lookup_string(config, "name", &zpool_name) == 0)) {
+		strlcpy(label, zpool_name, labelsize);
+	} else
+		err = 1;
+
 	nvlist_free(config);
-	free(zpool_ptr);
+	free(vdev_label);
 
-	return (1);
+	return (err);
 }



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