diff --git a/usr.sbin/fstyp/Makefile b/usr.sbin/fstyp/Makefile
index 14b5d9dfd9c3..384e2f7dee60 100644
--- a/usr.sbin/fstyp/Makefile
+++ b/usr.sbin/fstyp/Makefile
@@ -1,55 +1,55 @@
 # $FreeBSD$
 
 .include <src.opts.mk>
 
 PROG=	fstyp
-SRCS=	apfs.c cd9660.c exfat.c ext2fs.c fstyp.c geli.c hammer.c	\
+SRCS=	apfs.c befs.c cd9660.c exfat.c ext2fs.c fstyp.c geli.c hammer.c	\
 	hammer2.c hfsplus.c msdosfs.c ntfs.c ufs.c
 
 .if ${MK_ZFS} != "no"
 SRCS +=	zfs.c
 .endif
 
 MAN=	fstyp.8
 
 WARNS?=	2
 
 .if ${MK_ICONV} == "yes"
 CFLAGS+=	-DWITH_ICONV
 .endif
 
 .include <bsd.endian.mk>
 
 .if ${TARGET_ENDIANNESS} == 1234
 HAS_TESTS=
 SUBDIR.${MK_TESTS}+= tests
 .endif
 
 .if ${MK_ZFS} != "no"
 IGNORE_PRAGMA=  YES
 
 CFLAGS+= -DHAVE_ZFS
 CFLAGS.zfs.c+= -DIN_BASE
 CFLAGS.zfs.c+= -I${SRCTOP}/sys/contrib/openzfs/include
 CFLAGS.zfs.c+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include
 CFLAGS.zfs.c+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
 CFLAGS.zfs.c+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
 CFLAGS.zfs.c+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
 CFLAGS.zfs.c+= -DHAVE_ISSETUGID
 CFLAGS.zfs.c+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
 .endif
 
 .for src in ${SRCS}
 .if ${src} != "zfs.c"
 CFLAGS.${src}+=-I${SRCTOP}/sys
 .endif
 .endfor
 
 
 LIBADD=	geom md ufs
 
 .if ${MK_ZFS} != "no"
 LIBADD+=nvpair zfs spl
 .endif
 
 .include <bsd.prog.mk>
diff --git a/usr.sbin/fstyp/befs.c b/usr.sbin/fstyp/befs.c
new file mode 100644
index 000000000000..352fe7d4c296
--- /dev/null
+++ b/usr.sbin/fstyp/befs.c
@@ -0,0 +1,70 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 Miguel Gocobachi
+ *
+ * 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 AUTHOR 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 AUTHOR 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 <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fstyp.h"
+
+#define B_OS_NAME_LENGTH	32
+#define BEFS_BLOCK_OFFSET	512
+#define BEFS_SUPER_BLOCK_MAGIC1	0x42465331
+
+struct disk_super_block {
+    char	name[B_OS_NAME_LENGTH];
+    int32_t	magic1;
+};
+
+int
+fstyp_befs(FILE *fp, char *label, size_t size)
+{
+	struct disk_super_block *volume;
+
+	volume = read_buf(fp, BEFS_BLOCK_OFFSET, sizeof(*volume));
+
+	if (volume == NULL) {
+		return (1);
+	}
+
+	if (volume->magic1 == BEFS_SUPER_BLOCK_MAGIC1) {
+		strlcpy(label, volume->name, size);
+		free(volume);
+
+		return (0);
+	}
+
+	free(volume);
+
+	return (1);
+}
diff --git a/usr.sbin/fstyp/fstyp.8 b/usr.sbin/fstyp/fstyp.8
index d587e331490f..22d41628d8d5 100644
--- a/usr.sbin/fstyp/fstyp.8
+++ b/usr.sbin/fstyp/fstyp.8
@@ -1,134 +1,136 @@
 .\" Copyright (c) 2014 The FreeBSD Foundation
 .\"
 .\" 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.
 .\"
 .\" $FreeBSD$
 .\"
 .Dd December 24, 2019
 .Dt FSTYP 8
 .Os
 .Sh NAME
 .Nm fstyp
 .Nd determine filesystem type
 .Sh SYNOPSIS
 .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, exFAT, Ext2, FAT, NTFS, and UFS filesystems.
+It can recognize BeFS (BeOS), ISO-9660, exFAT, 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
 .Xr geli 8
 providers, and
 ZFS pools.
 .Pp
 The filesystem name is printed to the standard output
 as, respectively:
 .Bl -item -offset indent -compact
 .It
+befs
+.It
 cd9660
 .It
 exfat
 .It
 ext2fs
 .It
 geli
 .It
 hammer
 .It
 hammer2
 .It
 msdosfs
 .It
 ntfs
 .It
 ufs
 .It
 zfs
 .El
 .Pp
 Because
 .Nm
 is built specifically to detect filesystem types, it differs from
 .Xr file 1
 in several ways.
 The output is machine-parsable, filesystem labels are supported,
 the utility runs sandboxed using
 .Xr capsicum 4 ,
 and does not try to recognize any file format other than filesystems.
 .Pp
 These options are available:
 .Bl -tag -width ".Fl l"
 .It Fl l
 In addition to filesystem type, print filesystem label if available.
 .It Fl s
 Ignore file type.
 By default,
 .Nm
 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
 .Nm
 utility exits 0 on success, and >0 if an error occurs or the filesystem
 type is not recognized.
 .Sh SEE ALSO
 .Xr file 1 ,
 .Xr capsicum 4 ,
 .Xr autofs 5 ,
 .Xr geli 8 ,
 .Xr glabel 8 ,
 .Xr mount 8 ,
 .Xr zpool 8
 .Sh HISTORY
 The
 .Nm
 command appeared in
 .Fx 10.2 .
 .Sh AUTHORS
 .An -nosplit
 The
 .Nm
 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 46b5d6100011..b39277914aed 100644
--- a/usr.sbin/fstyp/fstyp.c
+++ b/usr.sbin/fstyp/fstyp.c
@@ -1,268 +1,269 @@
 /*-
  * Copyright (c) 2014 The FreeBSD Foundation
  *
  * 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 AUTHOR 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 AUTHOR 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/capsicum.h>
 #include <sys/disk.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <capsicum_helpers.h>
 #include <err.h>
 #include <errno.h>
 #ifdef WITH_ICONV
 #include <iconv.h>
 #endif
 #include <locale.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <vis.h>
 
 #include "fstyp.h"
 
 #define	LABEL_LEN	256
 
 bool show_label = false;
 
 typedef int (*fstyp_function)(FILE *, char *, size_t);
 
 static struct {
 	const char	*name;
 	fstyp_function	function;
 	bool		unmountable;
 	char		*precache_encoding;
 } fstypes[] = {
 	{ "apfs", &fstyp_apfs, true, NULL },
+	{ "befs", &fstyp_befs, false, NULL },
 	{ "cd9660", &fstyp_cd9660, false, NULL },
 	{ "exfat", &fstyp_exfat, false, EXFAT_ENC },
 	{ "ext2fs", &fstyp_ext2fs, false, NULL },
 	{ "geli", &fstyp_geli, true, NULL },
 	{ "hammer", &fstyp_hammer, true, NULL },
 	{ "hammer2", &fstyp_hammer2, true, NULL },
 	{ "hfs+", &fstyp_hfsp, false, NULL },
 	{ "msdosfs", &fstyp_msdosfs, false, NULL },
 	{ "ntfs", &fstyp_ntfs, false, NTFS_ENC },
 	{ "ufs", &fstyp_ufs, false, NULL },
 #ifdef HAVE_ZFS
 	{ "zfs", &fstyp_zfs, true, NULL },
 #endif
 	{ NULL, NULL, NULL, NULL }
 };
 
 void *
 read_buf(FILE *fp, off_t off, size_t len)
 {
 	int error;
 	size_t nread;
 	void *buf;
 
 	error = fseek(fp, off, SEEK_SET);
 	if (error != 0) {
 		warn("cannot seek to %jd", (uintmax_t)off);
 		return (NULL);
 	}
 
 	buf = malloc(len);
 	if (buf == NULL) {
 		warn("cannot malloc %zd bytes of memory", len);
 		return (NULL);
 	}
 
 	nread = fread(buf, len, 1, fp);
 	if (nread != 1) {
 		free(buf);
 		if (feof(fp) == 0)
 			warn("fread");
 		return (NULL);
 	}
 
 	return (buf);
 }
 
 char *
 checked_strdup(const char *s)
 {
 	char *c;
 
 	c = strdup(s);
 	if (c == NULL)
 		err(1, "strdup");
 	return (c);
 }
 
 void
 rtrim(char *label, size_t size)
 {
 	ptrdiff_t i;
 
 	for (i = size - 1; i >= 0; i--) {
 		if (label[i] == '\0')
 			continue;
 		else if (label[i] == ' ')
 			label[i] = '\0';
 		else
 			break;
 	}
 }
 
 static void
 usage(void)
 {
 
 	fprintf(stderr, "usage: fstyp [-l] [-s] [-u] special\n");
 	exit(1);
 }
 
 static void
 type_check(const char *path, FILE *fp)
 {
 	int error, fd;
 	off_t mediasize;
 	struct stat sb;
 
 	fd = fileno(fp);
 
 	error = fstat(fd, &sb);
 	if (error != 0)
 		err(1, "%s: fstat", path);
 
 	if (S_ISREG(sb.st_mode))
 		return;
 
 	error = ioctl(fd, DIOCGMEDIASIZE, &mediasize);
 	if (error != 0)
 		errx(1, "%s: not a disk", path);
 }
 
 int
 main(int argc, char **argv)
 {
 	int ch, error, i, nbytes;
 	bool ignore_type = 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, "lsu")) != -1) {
 		switch (ch) {
 		case 'l':
 			show_label = true;
 			break;
 		case 's':
 			ignore_type = true;
 			break;
 		case 'u':
 			show_unmountable = true;
 			break;
 		default:
 			usage();
 		}
 	}
 
 	argc -= optind;
 	argv += optind;
 	if (argc != 1)
 		usage();
 
 	path = argv[0];
 
 	if (setlocale(LC_CTYPE, "") == NULL)
 		err(1, "setlocale");
 	caph_cache_catpages();
 
 #ifdef WITH_ICONV
 	/* Cache iconv conversion data before entering capability mode. */
 	if (show_label) {
 		for (i = 0; i < nitems(fstypes); i++) {
 			iconv_t cd;
 
 			if (fstypes[i].precache_encoding == NULL)
 				continue;
 			cd = iconv_open("", fstypes[i].precache_encoding);
 			if (cd == (iconv_t)-1)
 				err(1, "%s: iconv_open %s", fstypes[i].name,
 				    fstypes[i].precache_encoding);
 			/* Iconv keeps a small cache of unused encodings. */
 			iconv_close(cd);
 		}
 	}
 #endif
 
 	fp = fopen(path, "r");
 	if (fp == NULL)
 		err(1, "%s", path);
 
 	if (caph_enter() < 0)
 		err(1, "cap_enter");
 
 	if (ignore_type == false)
 		type_check(path, fp);
 
 	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;
 
 		error = fstyp_f(fp, label, sizeof(label));
 		if (error == 0)
 			break;
 	}
 
 	if (fstypes[i].name == NULL) {
 		warnx("%s: filesystem not recognized", path);
 		return (1);
 	}
 
 	if (show_label && label[0] != '\0') {
 		/*
 		 * XXX: I'd prefer VIS_HTTPSTYLE, but it unconditionally
 		 *      encodes spaces.
 		 */
 		nbytes = strsnvis(strvised, sizeof(strvised), label,
 		    VIS_GLOB | VIS_NL, "\"'$");
 		if (nbytes == -1)
 			err(1, "strsnvis");
 
 		printf("%s %s\n", fstypes[i].name, strvised);
 	} else {
 		printf("%s\n", fstypes[i].name);
 	}
 
 	return (0);
 }
diff --git a/usr.sbin/fstyp/fstyp.h b/usr.sbin/fstyp/fstyp.h
index 73861d7fdc0d..f11d66f5ffc2 100644
--- a/usr.sbin/fstyp/fstyp.h
+++ b/usr.sbin/fstyp/fstyp.h
@@ -1,67 +1,68 @@
 /*-
  * Copyright (c) 2014 The FreeBSD Foundation
  *
  * 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 AUTHOR 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 AUTHOR 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.
  *
  * $FreeBSD$
  */
 
 #ifndef FSTYP_H
 #define	FSTYP_H
 
 #include <stdbool.h>
 
 #define	MIN(a,b) (((a)<(b))?(a):(b))
 
 /* The spec doesn't seem to permit UTF-16 surrogates; definitely LE. */
 #define	EXFAT_ENC	"UCS-2LE"
 /*
  * NTFS itself is agnostic to encoding; it just stores 255 u16 wchars.  In
  * practice, UTF-16 seems expected for NTFS.  (Maybe also for exFAT.)
  */
 #define	NTFS_ENC	"UTF-16LE"
 
 extern bool	show_label;	/* -l flag */
 
 void	*read_buf(FILE *fp, off_t off, size_t len);
 char	*checked_strdup(const char *s);
 void	rtrim(char *label, size_t size);
 
 int	fstyp_apfs(FILE *fp, char *label, size_t size);
+int	fstyp_befs(FILE *fp, char *label, size_t size);
 int	fstyp_cd9660(FILE *fp, char *label, size_t size);
 int	fstyp_exfat(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_hammer(FILE *fp, char *label, size_t size);
 int	fstyp_hammer2(FILE *fp, char *label, size_t size);
 int	fstyp_hfsp(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 */
diff --git a/usr.sbin/fstyp/tests/Makefile b/usr.sbin/fstyp/tests/Makefile
index 9c4624af3a4c..c821bc9b45eb 100644
--- a/usr.sbin/fstyp/tests/Makefile
+++ b/usr.sbin/fstyp/tests/Makefile
@@ -1,15 +1,16 @@
 # $FreeBSD$
 
 PACKAGE=	tests
 
 ATF_TESTS_SH=	fstyp_test
 
+${PACKAGE}FILES+=	befs.img.bz2
 ${PACKAGE}FILES+=	dfr-01-xfat.img.bz2
 ${PACKAGE}FILES+=	ext2.img.bz2
 ${PACKAGE}FILES+=	ext3.img.bz2
 ${PACKAGE}FILES+=	ext4.img.bz2
 ${PACKAGE}FILES+=	ext4_with_label.img.bz2
 ${PACKAGE}FILES+=	ntfs.img.bz2
 ${PACKAGE}FILES+=	ntfs_with_label.img.bz2
 
 .include <bsd.test.mk>
diff --git a/usr.sbin/fstyp/tests/befs.img.bz2 b/usr.sbin/fstyp/tests/befs.img.bz2
new file mode 100644
index 000000000000..c2a6693216d5
Binary files /dev/null and b/usr.sbin/fstyp/tests/befs.img.bz2 differ
diff --git a/usr.sbin/fstyp/tests/fstyp_test.sh b/usr.sbin/fstyp/tests/fstyp_test.sh
index 8f76424f5f75..81a549629dd7 100755
--- a/usr.sbin/fstyp/tests/fstyp_test.sh
+++ b/usr.sbin/fstyp/tests/fstyp_test.sh
@@ -1,281 +1,292 @@
 #!/bin/sh
 #
 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
 #
 # Copyright (c) 2015 Alan Somers
 #
 # 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 AUTHOR 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 AUTHOR 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.
 
 # $FreeBSD$
 
+atf_test_case befs
+befs_head() {
+	atf_set "descr" "fstyp(8) can detect BeFS and label filesystem"
+}
+befs_body() {
+	bzcat $(atf_get_srcdir)/befs.img.bz2 > befs.img
+	atf_check -s exit:0 -o inline:"befs\n" fstyp befs.img
+	atf_check -s exit:0 -o inline:"befs BeFS\n" fstyp -l befs.img
+}
+
 atf_test_case cd9660
 cd9660_head() {
 	atf_set "descr" "fstyp(8) should detect cd9660 filesystems"
 }
 cd9660_body() {
 	atf_check -s exit:0 mkdir -p dir/emptydir	# makefs requires a nonempty directory
 	atf_check -s exit:0 -o ignore makefs -t cd9660 -Z -s 64m cd9660.img dir
 	atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
 	atf_check -s exit:0 -o inline:"cd9660\n" fstyp -l cd9660.img
 }
 
 atf_test_case cd9660_label
 cd9660_label_head() {
 	atf_set "descr" "fstyp(8) can read the label on a cd9660 filesystem"
 }
 cd9660_label_body() {
 	atf_check -s exit:0 mkdir -p dir/emptydir	# makefs requires a nonempty directory
 	atf_check -s exit:0 -o ignore makefs -t cd9660 -o label=Foo -Z -s 64m cd9660.img dir
 	atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
 	# Note: cd9660 labels are always upper case
 	atf_check -s exit:0 -o inline:"cd9660 FOO\n" fstyp -l cd9660.img
 }
 
 atf_test_case dir
 dir_head() {
 	atf_set "descr" "fstyp(8) should fail on a directory"
 }
 dir_body() {
 	atf_check -s exit:0 mkdir dir
 	atf_check -s exit:1 -e match:"not a disk" fstyp dir
 }
 
 atf_test_case exfat
 exfat_head() {
 	atf_set "descr" "fstyp(8) can detect exFAT filesystems"
 }
 exfat_body() {
 	bzcat $(atf_get_srcdir)/dfr-01-xfat.img.bz2 > exfat.img
 	atf_check -s exit:0 -o inline:"exfat\n" fstyp -u exfat.img
 }
 
 atf_test_case exfat_label
 exfat_label_head() {
 	atf_set "descr" "fstyp(8) can read exFAT labels"
 }
 exfat_label_body() {
 	bzcat $(atf_get_srcdir)/dfr-01-xfat.img.bz2 > exfat.img
 	atf_check -s exit:0 -o inline:"exfat exFat\n" fstyp -u -l exfat.img
 }
 
 atf_test_case empty
 empty_head() {
 	atf_set "descr" "fstyp(8) should fail on an empty file"
 }
 empty_body() {
 	atf_check -s exit:0 touch empty
 	atf_check -s exit:1 -e match:"filesystem not recognized" fstyp empty
 }
 
 atf_test_case ext2
 ext2_head() {
 	atf_set "descr" "fstyp(8) can detect ext2 filesystems"
 }
 ext2_body() {
 	bzcat $(atf_get_srcdir)/ext2.img.bz2 > ext2.img
 	atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext2.img
 	atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext2.img
 }
 
 atf_test_case ext3
 ext3_head() {
 	atf_set "descr" "fstyp(8) can detect ext3 filesystems"
 }
 ext3_body() {
 	bzcat $(atf_get_srcdir)/ext3.img.bz2 > ext3.img
 	atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext3.img
 	atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext3.img
 }
 
 atf_test_case ext4
 ext4_head() {
 	atf_set "descr" "fstyp(8) can detect ext4 filesystems"
 }
 ext4_body() {
 	bzcat $(atf_get_srcdir)/ext4.img.bz2 > ext4.img
 	atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext4.img
 	atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext4.img
 }
 
 atf_test_case ext4_label
 ext4_label_head() {
 	atf_set "descr" "fstyp(8) can read the label on an ext4 filesystem"
 }
 ext4_label_body() {
 	bzcat $(atf_get_srcdir)/ext4_with_label.img.bz2 > ext4_with_label.img
 	atf_check -s exit:0 -o inline:"ext2fs foo\n" fstyp -l ext4_with_label.img
 }
 
 atf_test_case fat12
 fat12_head() {
 	atf_set "descr" "fstyp(8) can detect FAT12 filesystems"
 }
 fat12_body() {
 	atf_check -s exit:0 truncate -s 64m msdos.img
 	atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 12 ./msdos.img
 	atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
 	atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
 }
 
 atf_test_case fat16
 fat16_head() {
 	atf_set "descr" "fstyp(8) can detect FAT16 filesystems"
 }
 fat16_body() {
 	atf_check -s exit:0 truncate -s 64m msdos.img
 	atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 16 ./msdos.img
 	atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
 	atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
 }
 
 atf_test_case fat32
 fat32_head() {
 	atf_set "descr" "fstyp(8) can detect FAT32 filesystems"
 }
 fat32_body() {
 	atf_check -s exit:0 truncate -s 64m msdos.img
 	atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -c 1 \
 		./msdos.img
 	atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
 	atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
 }
 
 atf_test_case fat32_label
 fat32_label_head() {
 	atf_set "descr" "fstyp(8) can read the label on an msdos filesystem"
 }
 fat32_label_body() {
 	atf_check -s exit:0 truncate -s 64m msdos.img
 	atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -L Foo -c 1 \
 		./msdos.img
 	atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
 	# Note: msdos labels are always upper case
 	atf_check -s exit:0 -o inline:"msdosfs FOO\n" fstyp -l msdos.img
 }
 
 atf_test_case ntfs
 ntfs_head() {
 	atf_set "descr" "fstyp(8) can detect ntfs filesystems"
 }
 ntfs_body() {
 	bzcat $(atf_get_srcdir)/ntfs.img.bz2 > ntfs.img
 	atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs.img
 	atf_check -s exit:0 -o inline:"ntfs\n" fstyp -l ntfs.img
 }
 
 atf_test_case ntfs_with_label
 ntfs_with_label_head() {
 	atf_set "descr" "fstyp(8) can read labels on ntfs filesystems"
 }
 ntfs_with_label_body() {
 	bzcat $(atf_get_srcdir)/ntfs_with_label.img.bz2 > ntfs_with_label.img
 	atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs_with_label.img
 	atf_check -s exit:0 -o inline:"ntfs Foo\n" fstyp -l ntfs_with_label.img
 }
 
 atf_test_case ufs1
 ufs1_head() {
 	atf_set "descr" "fstyp(8) should detect UFS version 1 filesystems"
 }
 ufs1_body() {
 	atf_check -s exit:0 mkdir dir
 	atf_check -s exit:0 -o ignore makefs -Z -s 64m ufs.img dir
 	atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
 	atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
 }
 
 atf_test_case ufs2
 ufs2_head() {
 	atf_set "descr" "fstyp(8) should detect UFS version 2 filesystems"
 }
 ufs2_body() {
 	atf_check -s exit:0 mkdir dir
 	atf_check -s exit:0 -o ignore makefs -o version=2 -Z -s 64m ufs.img dir
 	atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
 	atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
 }
 
 atf_test_case ufs2_label
 ufs2_label_head() {
 	atf_set "descr" "fstyp(8) can read the label on a UFS v2 filesystem"
 }
 ufs2_label_body() {
 	atf_check -s exit:0 mkdir dir
 	atf_check -s exit:0 -o ignore makefs -o version=2,label="foo" -Z -s 64m ufs.img dir
 	atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l ufs.img
 }
 
 atf_test_case ufs_on_device cleanup
 ufs_on_device_head() {
 	atf_set "descr" "fstyp(8) should work on device nodes"
 	atf_set "require.user" "root"
 }
 ufs_on_device_body() {
 	mdconfig -a -t swap -s 64m > mdname
 	md=$(cat mdname)
 	if [ -z "$md" ]; then
 		atf_fail "Failed to create md(4) device"
 	fi
 	atf_check -s exit:0 -o ignore newfs -L foo /dev/$md
 	atf_check -s exit:0 -o inline:"ufs\n" fstyp /dev/$md
 	atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l /dev/$md
 }
 ufs_on_device_cleanup() {
 	md=$(cat mdname)
 	if [ -n "$md" ]; then
 		mdconfig -d -u "$md"
 	fi
 }
 
 atf_test_case zeros
 zeros_head() {
 	atf_set "descr" "fstyp(8) should fail on a zero-filled file"
 }
 zeros_body() {
 	atf_check -s exit:0 truncate -s 256m zeros
 	atf_check -s exit:1 -e match:"filesystem not recognized" fstyp zeros
 }
 
 
 atf_init_test_cases() {
+	atf_add_test_case befs
 	atf_add_test_case cd9660
 	atf_add_test_case cd9660_label
 	atf_add_test_case dir
 	atf_add_test_case empty
 	atf_add_test_case exfat
 	atf_add_test_case exfat_label
 	atf_add_test_case ext2
 	atf_add_test_case ext3
 	atf_add_test_case ext4
 	atf_add_test_case ext4_label
 	atf_add_test_case fat12
 	atf_add_test_case fat16
 	atf_add_test_case fat32
 	atf_add_test_case fat32_label
 	atf_add_test_case ntfs
 	atf_add_test_case ntfs_with_label
 	atf_add_test_case ufs1
 	atf_add_test_case ufs2
 	atf_add_test_case ufs2_label
 	atf_add_test_case ufs_on_device
 	atf_add_test_case zeros
 }