xref: /freebsd/contrib/pjdfstest/tests/rename/06.t (revision eda14cbc264d6969b02f2b1994cef11148e914f1)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/06.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="rename returns EPERM if the file pointed at by the 'from' argument has its immutable, undeletable or append-only flag set"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags
11
12case "${os}:${fs}" in
13FreeBSD:ZFS)
14	flags="SF_IMMUTABLE SF_NOUNLINK SF_APPEND"
15	echo "1..195"
16	;;
17FreeBSD:UFS)
18	flags="SF_IMMUTABLE SF_NOUNLINK SF_APPEND UF_IMMUTABLE UF_NOUNLINK UF_APPEND"
19	echo "1..351"
20	;;
21*)
22	quick_exit
23esac
24
25n0=`namegen`
26n1=`namegen`
27
28for type in regular dir fifo block char socket symlink; do
29	if [ "${type}" != "symlink" ]; then
30		create_file ${type} ${n0}
31		for flag in ${flags}; do
32			expect 0 chflags ${n0} ${flag}
33			expect ${flag} stat ${n0} flags
34			[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
35			expect EPERM rename ${n0} ${n1}
36			[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
37			expect ENOENT rename ${n1} ${n0}
38		done
39		expect 0 chflags ${n0} none
40		if [ "${type}" = "dir" ]; then
41			expect 0 rmdir ${n0}
42		else
43			expect 0 unlink ${n0}
44		fi
45	fi
46
47	create_file ${type} ${n0}
48	for flag in ${flags}; do
49		expect 0 lchflags ${n0} ${flag}
50		expect ${flag} lstat ${n0} flags
51		[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
52		expect EPERM rename ${n0} ${n1}
53		[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
54		expect ENOENT rename ${n1} ${n0}
55	done
56	expect 0 lchflags ${n0} none
57	if [ "${type}" = "dir" ]; then
58		expect 0 rmdir ${n0}
59	else
60		expect 0 unlink ${n0}
61	fi
62done
63