Index: head/etc/mtree/BSD.tests.dist
===================================================================
--- head/etc/mtree/BSD.tests.dist	(revision 286963)
+++ head/etc/mtree/BSD.tests.dist	(revision 286964)
@@ -1,588 +1,590 @@
 # $FreeBSD$
 #
 # Please see the file src/etc/mtree/README before making changes to this file.
 #
 
 /set type=dir uname=root gname=wheel mode=0755
 .
     bin
         cat
         ..
         chown
         ..
         date
         ..
         expr
         ..
         mv
         ..
         pax
         ..
         pkill
         ..
         sh
             builtins
             ..
             errors
             ..
             execution
             ..
             expansion
             ..
             parameters
             ..
             parser
             ..
             set-e
             ..
         ..
         sleep
         ..
         test
         ..
     ..
     cddl
         lib
         ..
         sbin
         ..
         usr.bin
         ..
         usr.sbin
             dtrace
                 common
                     aggs
                     ..
                     arithmetic
                     ..
                     arrays
                     ..
                     assocs
                     ..
                     begin
                     ..
                     bitfields
                     ..
                     buffering
                     ..
                     builtinvar
                     ..
                     cg
                     ..
                     clauses
                     ..
                     cpc
                     ..
                     decls
                     ..
                     drops
                     ..
                     dtraceUtil
                     ..
                     end
                     ..
                     enum
                     ..
                     error
                     ..
                     exit
                     ..
                     fbtprovider
                     ..
                     funcs
                     ..
                     grammar
                     ..
                     include
                     ..
                     inline
                     ..
                     io
                     ..
                     ip
                     ..
                     java_api
                     ..
                     json
                     ..
                     lexer
                     ..
                     llquantize
                     ..
                     mdb
                     ..
                     mib
                     ..
                     misc
                     ..
                     multiaggs
                     ..
                     offsetof
                     ..
                     operators
                     ..
                     pid
                     ..
                     plockstat
                     ..
                     pointers
                     ..
                     pragma
                     ..
                     predicates
                     ..
                     preprocessor
                     ..
                     print
                     ..
                     printa
                     ..
                     printf
                     ..
                     privs
                     ..
                     probes
                     ..
                     proc
                     ..
                     profile-n
                     ..
                     providers
                     ..
                     raise
                     ..
                     rates
                     ..
                     safety
                     ..
                     scalars
                     ..
                     sched
                     ..
                     scripting
                     ..
                     sdt
                     ..
                     sizeof
                     ..
                     speculation
                     ..
                     stability
                     ..
                     stack
                     ..
                     stackdepth
                     ..
                     stop
                     ..
                     strlen
                     ..
                     strtoll
                     ..
                     struct
                     ..
                     syscall
                     ..
                     sysevent
                     ..
                     tick-n
                     ..
                     trace
                     ..
                     tracemem
                     ..
                     translators
                     ..
                     typedef
                     ..
                     types
                     ..
                     uctf
                     ..
                     union
                     ..
                     usdt
                     ..
                     ustack
                     ..
                     vars
                     ..
                     version
                     ..
                 ..
             ..
         ..
     ..
     etc
         rc.d
         ..
     ..
     games
     ..
     gnu
         lib
         ..
         usr.bin
             diff
             ..
         ..
     ..
     lib
         atf
             libatf-c
                 detail
                 ..
             ..
             libatf-c++
                 detail
                 ..
             ..
             test-programs
             ..
         ..
         libc
             c063
             ..
             db
             ..
             gen
                 execve
                 ..
                 posix_spawn
                 ..
             ..
             hash
                 data
                 ..
             ..
             inet
             ..
             locale
             ..
             net
                 getaddrinfo
                     data
                     ..
                 ..
             ..
             regex
                 data
                 ..
             ..
             ssp
             ..
             stdio
             ..
             stdlib
             ..
             string
             ..
             sys
             ..
             time
             ..
             tls
                 dso
                 ..
             ..
             termios
             ..
             ttyio
             ..
         ..
         libcrypt
         ..
         libmp
         ..
         libnv
         ..
         libpam
         ..
         libproc
         ..
         librt
         ..
         libthr
             dlopen
             ..
         ..
         libutil
         ..
         msun
         ..
     ..
     libexec
         atf
             atf-check
             ..
             atf-sh
             ..
         ..
         rtld-elf
         ..
     ..
     sbin
         dhclient
         ..
         devd
         ..
         growfs
         ..
         ifconfig
         ..
         mdconfig
         ..
     ..
     secure
         lib
         ..
         libexec
         ..
         usr.bin
         ..
         usr.sbin
         ..
     ..
     share
         examples
             tests
                 atf
                 ..
                 plain
                 ..
             ..
         ..
     ..
     sys
         aio
         ..
         fifo
         ..
         file
         ..
         kern
             execve
             ..
         ..
         kqueue
         ..
         mqueue
         ..
         netinet
         ..
         opencrypto
         ..
         pjdfstest
             chflags
             ..
             chmod
             ..
             chown
             ..
             ftruncate
             ..
             granular
             ..
             link
             ..
             mkdir
             ..
             mkfifo
             ..
             mknod
             ..
             open
             ..
             rename
             ..
             rmdir
             ..
             symlink
             ..
             truncate
             ..
             unlink
             ..
         ..
         vm
         ..
     ..
     usr.bin
         apply
         ..
         basename
         ..
         bmake
             archives
                 fmt_44bsd
                 ..
                 fmt_44bsd_mod
                 ..
                 fmt_oldbsd
                 ..
             ..
             basic
                 t0
                 ..
                 t1
                 ..
                 t2
                 ..
                 t3
                 ..
             ..
             execution
                 ellipsis
                 ..
                 empty
                 ..
                 joberr
                 ..
                 plus
                 ..
             ..
             shell
                 builtin
                 ..
                 meta
                 ..
                 path
                 ..
                 path_select
                 ..
                 replace
                 ..
                 select
                 ..
             ..
             suffixes
                 basic
                 ..
                 src_wild1
                 ..
                 src_wild2
                 ..
             ..
             syntax
                 directive-t0
                 ..
                 enl
                 ..
                 funny-targets
                 ..
                 semi
                 ..
             ..
             sysmk
                 t0
                     2
                         1
                         ..
                     ..
                     mk
                     ..
                 ..
                 t1
                     2
                         1
                         ..
                     ..
                     mk
                     ..
                 ..
                 t2
                     2
                         1
                         ..
                     ..
                     mk
                     ..
                 ..
             ..
             variables
                 modifier_M
                 ..
                 modifier_t
                 ..
                 opt_V
                 ..
                 t0
                 ..
             ..
         ..
         calendar
         ..
         cmp
         ..
         col
         ..
         comm
         ..
         cut
         ..
         dirname
         ..
         file2c
         ..
         grep
         ..
         gzip
         ..
         ident
         ..
         join
         ..
         jot
         ..
         lastcomm
         ..
         m4
         ..
         mkimg
         ..
         ncal
         ..
         opensm
         ..
         printf
         ..
         sed
             regress.multitest.out
             ..
         ..
         soelim
         ..
         timeout
         ..
         tr
         ..
         truncate
         ..
         units
         ..
         uudecode
         ..
         uuencode
         ..
         xargs
         ..
         yacc
             yacc
             ..
         ..
     ..
     usr.sbin
         etcupdate
         ..
+        fstyp
+        ..
         newsyslog
         ..
         nmtree
         ..
         pw
         ..
         sa
         ..
     ..
 ..
 
 # vim: set expandtab ts=4 sw=4:
Index: head/usr.sbin/fstyp/Makefile
===================================================================
--- head/usr.sbin/fstyp/Makefile	(revision 286963)
+++ head/usr.sbin/fstyp/Makefile	(revision 286964)
@@ -1,41 +1,47 @@
 # $FreeBSD$
 
 .include <src.opts.mk>
 
 PROG=	fstyp
 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?=	0
 
+.include <src.opts.mk>
+
+.if ${MK_TESTS} != "no"
+SUBDIR+=	tests
+.endif
+
 .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
 
 CFLAGS+=-I${.CURDIR}/../../sys
 
 DPADD=   ${LIBGEOM} ${LIBMD}
 LDADD=   -lgeom -lmd
 
 .if ${MK_ZFS} != "no"
 DPADD += ${LIBNVPAIR} ${LIBZFS}
 LDADD += -lnvpair -lzfs
 .endif
 
 .include <bsd.prog.mk>
Index: head/usr.sbin/fstyp/tests/Makefile
===================================================================
--- head/usr.sbin/fstyp/tests/Makefile	(nonexistent)
+++ head/usr.sbin/fstyp/tests/Makefile	(revision 286964)
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+TESTSDIR=	${TESTSBASE}/usr.sbin/fstyp
+
+ATF_TESTS_SH=	fstyp_test
+
+FILES=	ext2.img.bz2
+FILES+=	ext3.img.bz2
+FILES+=	ext4.img.bz2
+FILES+=	ext4_with_label.img.bz2
+FILES+=	ntfs.img.bz2
+FILES+=	ntfs_with_label.img.bz2
+FILESDIR=	${TESTSDIR}
+
+.include <bsd.test.mk>

Property changes on: head/usr.sbin/fstyp/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: head/usr.sbin/fstyp/tests/ext2.img.bz2
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-bzip2

Property changes on: head/usr.sbin/fstyp/tests/ext2.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Index: head/usr.sbin/fstyp/tests/ext3.img.bz2
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-bzip2

Property changes on: head/usr.sbin/fstyp/tests/ext3.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Index: head/usr.sbin/fstyp/tests/ext4.img.bz2
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-bzip2

Property changes on: head/usr.sbin/fstyp/tests/ext4.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Index: head/usr.sbin/fstyp/tests/ext4_with_label.img.bz2
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-bzip2

Property changes on: head/usr.sbin/fstyp/tests/ext4_with_label.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Index: head/usr.sbin/fstyp/tests/fstyp_test.sh
===================================================================
--- head/usr.sbin/fstyp/tests/fstyp_test.sh	(nonexistent)
+++ head/usr.sbin/fstyp/tests/fstyp_test.sh	(revision 286964)
@@ -0,0 +1,234 @@
+# $FreeBSD$
+
+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 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 cd9660
+	atf_add_test_case cd9660_label
+	atf_add_test_case dir
+	atf_add_test_case empty
+	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
+}

Property changes on: head/usr.sbin/fstyp/tests/fstyp_test.sh
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: head/usr.sbin/fstyp/tests/ntfs.img.bz2
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-bzip2

Property changes on: head/usr.sbin/fstyp/tests/ntfs.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Index: head/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-bzip2

Property changes on: head/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property