Index: usr.sbin/fstyp/Makefile =================================================================== --- usr.sbin/fstyp/Makefile +++ usr.sbin/fstyp/Makefile @@ -1,9 +1,26 @@ # $FreeBSD$ 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 zfs.c MAN= fstyp.8 WARNS= 6 +IGNORE_PRAGMA= YES + +CFLAGS+= -DNEED_SOLARIS_BOOLEAN +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}/../../cddl/contrib/opensolaris/head + +DPADD= ${LIBGEOM} ${LIBMD} ${LIBNVPAIR} ${LIBZFS} +LDADD= -lgeom -lmd -lnvpair -lzfs + +CFLAGS+=-I${.CURDIR}/../../sys + .include Index: usr.sbin/fstyp/fstyp.h =================================================================== --- usr.sbin/fstyp/fstyp.h +++ usr.sbin/fstyp/fstyp.h @@ -39,8 +39,10 @@ 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); +int fstyp_zfs(FILE *fp, char *label, size_t size); #endif /* !FSTYP_H */ Index: usr.sbin/fstyp/fstyp.c =================================================================== --- usr.sbin/fstyp/fstyp.c +++ usr.sbin/fstyp/fstyp.c @@ -57,9 +57,11 @@ } fstypes[] = { { "cd9660", &fstyp_cd9660 }, { "ext2fs", &fstyp_ext2fs }, + { "geli", &fstyp_geli }, { "msdosfs", &fstyp_msdosfs }, { "ntfs", &fstyp_ntfs }, { "ufs", &fstyp_ufs }, + { "zfs", &fstyp_zfs }, { NULL, NULL } }; Index: usr.sbin/fstyp/geli.c =================================================================== --- /dev/null +++ usr.sbin/fstyp/geli.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2015 Allan Jude + * 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "fstyp.h" + +int +fstyp_geli(FILE *fp, char *label __unused, size_t labelsize __unused) +{ + int error; + off_t mediasize; + u_int sectorsize; + ssize_t bread = 0; + struct g_eli_metadata md; + u_char *buf; + + error = ioctl(fileno(fp), DIOCGMEDIASIZE, &mediasize); + if (error) + return (1); + error = ioctl(fileno(fp), DIOCGSECTORSIZE, §orsize); + if (error) + return (1); + buf = malloc(sectorsize); + bread = pread(fileno(fp), buf, sectorsize, mediasize - sectorsize); + if (bread < 1) + goto gelierr; + if (bread) { + 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); +} Index: usr.sbin/fstyp/zfs.c =================================================================== --- /dev/null +++ usr.sbin/fstyp/zfs.c @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2015 Allan Jude + * 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "fstyp.h" + +int +fstyp_zfs(FILE *fp, char *label, size_t labelsize) +{ + 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; + + if (pread(fileno(fp), &zpool_label, sizeof(zpool_label), 0) != sizeof(zpool_label)) { + return (1); + } + + if (nvlist_unpack(buf, buflen, &config, 0) != 0) { + return (1); + } else { + if (nvlist_lookup_string(config, "name", &zpool_name) != 0) { + return (1); + } + strlcpy(label, zpool_name, labelsize); + nvlist_free(config); + return (0); + } + return (1); +}