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