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