summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorallanjude <allanjude@FreeBSD.org>2015-06-19 05:09:02 +0000
committerallanjude <allanjude@FreeBSD.org>2015-06-19 05:09:02 +0000
commit82671124eea59e64041ba4e91e97f61d7ee1b320 (patch)
tree0eb73c14c847aea32611eb467d3c6f672b12bdbd /usr.sbin
parentf898f863602366d9c7156dec7b0d1c4afc257f6b (diff)
downloadFreeBSD-src-82671124eea59e64041ba4e91e97f61d7ee1b320.zip
FreeBSD-src-82671124eea59e64041ba4e91e97f61d7ee1b320.tar.gz
Add the ability to detect ZFS and GELI encrypted file systems to fstyp(8)
Functionality is hidden behind the -u flag to avoid confusing automounters PR: 200823 Reviewed by: asomers, eadler, wblock (man page) Approved by: trasz MFC after: 10 days Relnotes: yes Sponsored by: ScaleEngine Inc. Differential Revision: https://reviews.freebsd.org/D2045
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/fstyp/Makefile34
-rw-r--r--usr.sbin/fstyp/fstyp.848
-rw-r--r--usr.sbin/fstyp/fstyp.c28
-rw-r--r--usr.sbin/fstyp/fstyp.h4
-rw-r--r--usr.sbin/fstyp/geli.c76
-rw-r--r--usr.sbin/fstyp/zfs.c73
6 files changed, 244 insertions, 19 deletions
diff --git a/usr.sbin/fstyp/Makefile b/usr.sbin/fstyp/Makefile
index d0b14d1..d1de06e 100644
--- a/usr.sbin/fstyp/Makefile
+++ b/usr.sbin/fstyp/Makefile
@@ -1,9 +1,41 @@
# $FreeBSD$
+.include <src.opts.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_CDDL} != "no"
+SRCS += zfs.c
+.endif
+
MAN= fstyp.8
WARNS= 6
+.if ${MK_CDDL} != "no"
+IGNORE_PRAGMA= YES
+
+CFLAGS+= -DNEED_SOLARIS_BOOLEAN -DHAVE_CDDL
+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
+
+CFLAGS+=-I${.CURDIR}/../../sys
+
+DPADD= ${LIBGEOM} ${LIBMD}
+LDADD= -lgeom -lmd
+
+.if ${MK_CDDL} != "no"
+DPADD += ${LIBNVPAIR} ${LIBZFS}
+LDADD += -lnvpair -lzfs
+.endif
+
.include <bsd.prog.mk>
diff --git a/usr.sbin/fstyp/fstyp.8 b/usr.sbin/fstyp/fstyp.8
index 5223f81..981a8d3 100644
--- a/usr.sbin/fstyp/fstyp.8
+++ b/usr.sbin/fstyp/fstyp.8
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 14, 2015
+.Dd June 15, 2015
.Dt FSTYP 8
.Os
.Sh NAME
@@ -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
diff --git a/usr.sbin/fstyp/fstyp.c b/usr.sbin/fstyp/fstyp.c
index 1a699eb..95218ca 100644
--- a/usr.sbin/fstyp/fstyp.c
+++ b/usr.sbin/fstyp/fstyp.c
@@ -55,13 +55,18 @@ typedef int (*fstyp_function)(FILE *, char *, size_t);
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_CDDL
+ { "zfs", &fstyp_zfs, true },
+#endif
+ { NULL, NULL, NULL }
};
void *
@@ -124,7 +129,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 +158,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 +172,9 @@ main(int argc, char **argv)
case 's':
ignore_type = true;
break;
+ case 'u':
+ show_unmountable = true;
+ break;
default:
usage();
}
@@ -193,6 +201,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;
diff --git a/usr.sbin/fstyp/fstyp.h b/usr.sbin/fstyp/fstyp.h
index d4fd54f..ca778ba 100644
--- a/usr.sbin/fstyp/fstyp.h
+++ b/usr.sbin/fstyp/fstyp.h
@@ -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_CDDL
+int fstyp_zfs(FILE *fp, char *label, size_t size);
+#endif
#endif /* !FSTYP_H */
diff --git a/usr.sbin/fstyp/geli.c b/usr.sbin/fstyp/geli.c
new file mode 100644
index 0000000..1c15ca6
--- /dev/null
+++ b/usr.sbin/fstyp/geli.c
@@ -0,0 +1,76 @@
+/*-
+ * 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:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__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>
+
+#include "fstyp.h"
+
+int
+fstyp_geli(FILE *fp, char *label __unused, size_t labelsize __unused)
+{
+ int error;
+ off_t mediasize;
+ u_int sectorsize;
+ struct g_eli_metadata md;
+ u_char *buf;
+
+ error = ioctl(fileno(fp), DIOCGMEDIASIZE, &mediasize);
+ if (error != 0)
+ return (1);
+ error = ioctl(fileno(fp), DIOCGSECTORSIZE, &sectorsize);
+ if (error != 0)
+ return (1);
+ buf = (u_char *)read_buf(fp, mediasize - sectorsize, sectorsize);
+ if (buf == NULL)
+ goto gelierr;
+ error = eli_metadata_decode(buf, &md);
+ if (error)
+ goto gelierr;
+
+ if (strncmp(md.md_magic, "GEOM::ELI", 9) == 0) {
+ free(buf);
+ return (0);
+ }
+
+gelierr:
+ free(buf);
+
+ return (1);
+}
diff --git a/usr.sbin/fstyp/zfs.c b/usr.sbin/fstyp/zfs.c
new file mode 100644
index 0000000..9d91db6
--- /dev/null
+++ b/usr.sbin/fstyp/zfs.c
@@ -0,0 +1,73 @@
+/*-
+ * 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:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <libnvpair.h>
+#include <sys/vdev_impl.h>
+
+#include "fstyp.h"
+
+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;
+ char *zpool_name = NULL;
+ size_t buflen = sizeof (zpool_label.vl_vdev_phys.vp_nvlist);
+ nvlist_t *config = NULL;
+
+ zpool_ptr = (vdev_label_t *)read_buf(fp, 0, sizeof(zpool_label));
+ if (zpool_ptr == 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:
+ nvlist_free(config);
+ free(zpool_ptr);
+
+ return (1);
+}
OpenPOWER on IntegriCloud