xref: /freebsd/contrib/netbsd-tests/fs/h_funcs.subr (revision 6955543a8897fd94bf62db1099798f68e323001a)
157718be8SEnji Cooper#!/bin/sh
257718be8SEnji Cooper#
357718be8SEnji Cooper# $NetBSD: h_funcs.subr,v 1.3 2010/06/23 11:19:17 pooka Exp $
457718be8SEnji Cooper#
557718be8SEnji Cooper# Copyright (c) 2007 The NetBSD Foundation, Inc.
657718be8SEnji Cooper# All rights reserved.
757718be8SEnji Cooper#
857718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
957718be8SEnji Cooper# modification, are permitted provided that the following conditions
1057718be8SEnji Cooper# are met:
1157718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright
1257718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer.
1357718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
1457718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
1557718be8SEnji Cooper#    documentation and/or other materials provided with the distribution.
1657718be8SEnji Cooper#
1757718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1857718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1957718be8SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2057718be8SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2157718be8SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2257718be8SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2357718be8SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2457718be8SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2557718be8SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2657718be8SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2757718be8SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
2857718be8SEnji Cooper#
2957718be8SEnji Cooper
3057718be8SEnji Cooper#
3157718be8SEnji Cooper# require_fs name
3257718be8SEnji Cooper#
3357718be8SEnji Cooper#	Checks that the given file system is built into the kernel and
3457718be8SEnji Cooper#	that its corresponding mount(8) utility is available.  Otherwise
3557718be8SEnji Cooper#	skips the test.
3657718be8SEnji Cooper#
3757718be8SEnji Cooperrequire_fs() {
3857718be8SEnji Cooper	local name
3957718be8SEnji Cooper	local autoload
4057718be8SEnji Cooper	name="${1}"
4157718be8SEnji Cooper
4257718be8SEnji Cooper	atf_require_prog mount
4357718be8SEnji Cooper	atf_require_prog mount_${name}
4457718be8SEnji Cooper	atf_require_prog umount
4557718be8SEnji Cooper
4661e13648SEnji Cooper	# Begin FreeBSD
4761e13648SEnji Cooper	if true; then
48*6955543aSMitchell Horne		if kldstat -qm ${name} || kldload -n ${name}; then
4961e13648SEnji Cooper			found=yes
5061e13648SEnji Cooper		else
5161e13648SEnji Cooper			found=no
5261e13648SEnji Cooper		fi
5361e13648SEnji Cooper	else
5461e13648SEnji Cooper	# End FreeBSD
5546e1f071SAlan Somers	# if we have autoloadable modules, just assume the file system
5646e1f071SAlan Somers	atf_require_prog sysctl
5757718be8SEnji Cooper	autoload=$(sysctl -n kern.module.autoload)
5857718be8SEnji Cooper	[ "${autoload}" = "1" ] && return 0
5957718be8SEnji Cooper
6057718be8SEnji Cooper	set -- $(sysctl -n vfs.generic.fstypes)
6157718be8SEnji Cooper	found=no
6257718be8SEnji Cooper	while [ ${#} -gt 1 ];  do
6357718be8SEnji Cooper		if [ ${1} = ${name} ]; then
6457718be8SEnji Cooper			found=yes
6557718be8SEnji Cooper			break
6657718be8SEnji Cooper		fi
6757718be8SEnji Cooper		shift
6857718be8SEnji Cooper	done
6961e13648SEnji Cooper	# Begin FreeBSD
7061e13648SEnji Cooper	fi
7161e13648SEnji Cooper	# End FreeBSD
7257718be8SEnji Cooper	[ ${found} = yes ] || \
7357718be8SEnji Cooper		atf_skip "The kernel does not include support the " \
7457718be8SEnji Cooper		         "\`${name}' file system"
7557718be8SEnji Cooper}
76