1166065Spjd#!/bin/sh
2166065Spjd# $FreeBSD: releng/10.3/tools/regression/pjdfstest/tests/rename/08.t 211186 2010-08-11 17:34:58Z pjd $
3166065Spjd
4166065Spjddesc="rename returns EPERM if the parent directory of the file pointed at by the 'to' argument has its immutable flag set"
5166065Spjd
6166065Spjddir=`dirname $0`
7166065Spjd. ${dir}/../misc.sh
8166065Spjd
9166065Spjdrequire chflags
10166065Spjd
11210984Spjdcase "${os}:${fs}" in
12210984SpjdFreeBSD:ZFS)
13210984Spjd	flags1="SF_IMMUTABLE"
14210984Spjd	flags2="SF_NOUNLINK SF_APPEND"
15211186Spjd	echo "1..128"
16210984Spjd	;;
17210984SpjdFreeBSD:UFS)
18210984Spjd	flags1="SF_IMMUTABLE UF_IMMUTABLE"
19210984Spjd	flags2="SF_NOUNLINK SF_APPEND UF_NOUNLINK UF_APPEND"
20211186Spjd	echo "1..219"
21210984Spjd	;;
22210984Spjd*)
23210984Spjd	quick_exit
24210984Spjdesac
25166065Spjd
26166065Spjdn0=`namegen`
27166065Spjdn1=`namegen`
28166065Spjdn2=`namegen`
29166065Spjd
30166065Spjdexpect 0 mkdir ${n0} 0755
31166065Spjd
32211186Spjdfor type in regular dir fifo block char socket symlink; do
33211186Spjd	create_file ${type} ${n1}
34211186Spjd	for flag in ${flags1}; do
35211186Spjd		expect 0 chflags ${n0} ${flag}
36211186Spjd		expect ${flag} stat ${n0} flags
37211186Spjd		expect EPERM rename ${n1} ${n0}/${n2}
38211186Spjd	done
39166065Spjd	expect 0 chflags ${n0} none
40211186Spjd	if [ "${type}" = "dir" ]; then
41211186Spjd		expect 0 rmdir ${n1}
42211186Spjd	else
43211186Spjd		expect 0 unlink ${n1}
44211186Spjd	fi
45166065Spjddone
46166065Spjd
47211186Spjdfor type in regular dir fifo block char socket symlink; do
48211186Spjd	create_file ${type} ${n1}
49211186Spjd	for flag in ${flags2}; do
50211186Spjd		expect 0 chflags ${n0} ${flag}
51211186Spjd		expect ${flag} stat ${n0} flags
52211186Spjd		expect 0 rename ${n1} ${n0}/${n2}
53211186Spjd		expect 0 chflags ${n0} none
54211186Spjd		expect 0 rename ${n0}/${n2} ${n1}
55211186Spjd	done
56211186Spjd	if [ "${type}" = "dir" ]; then
57211186Spjd		expect 0 rmdir ${n1}
58211186Spjd	else
59211186Spjd		expect 0 unlink ${n1}
60211186Spjd	fi
61166065Spjddone
62166065Spjd
63166065Spjdexpect 0 rmdir ${n0}
64