1166065Spjd#!/bin/sh
2166065Spjd# $FreeBSD$
3166065Spjd
4166065Spjddesc="rename returns EPERM if the file pointed at by the 'from' argument has its immutable, undeletable or append-only flag set"
5166065Spjd
6166065Spjddir=`dirname $0`
7166065Spjd. ${dir}/../misc.sh
8166065Spjd
9166065Spjdrequire chflags
10166065Spjd
11210984Spjdcase "${os}:${fs}" in
12210984SpjdFreeBSD:ZFS)
13210984Spjd	flags="SF_IMMUTABLE SF_NOUNLINK SF_APPEND"
14211186Spjd	echo "1..195"
15210984Spjd	;;
16210984SpjdFreeBSD:UFS)
17210984Spjd	flags="SF_IMMUTABLE SF_NOUNLINK SF_APPEND UF_IMMUTABLE UF_NOUNLINK UF_APPEND"
18211186Spjd	echo "1..351"
19210984Spjd	;;
20210984Spjd*)
21210984Spjd	quick_exit
22210984Spjdesac
23166065Spjd
24166065Spjdn0=`namegen`
25166065Spjdn1=`namegen`
26166065Spjd
27211186Spjdfor type in regular dir fifo block char socket symlink; do
28211186Spjd	if [ "${type}" != "symlink" ]; then
29211186Spjd		create_file ${type} ${n0}
30211186Spjd		for flag in ${flags}; do
31211186Spjd			expect 0 chflags ${n0} ${flag}
32211186Spjd			expect ${flag} stat ${n0} flags
33211186Spjd			[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
34211186Spjd			expect EPERM rename ${n0} ${n1}
35211186Spjd			[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
36211186Spjd			expect ENOENT rename ${n1} ${n0}
37211186Spjd		done
38211186Spjd		expect 0 chflags ${n0} none
39211186Spjd		if [ "${type}" = "dir" ]; then
40211186Spjd			expect 0 rmdir ${n0}
41211186Spjd		else
42211186Spjd			expect 0 unlink ${n0}
43211186Spjd		fi
44211186Spjd	fi
45166065Spjd
46211186Spjd	create_file ${type} ${n0}
47211186Spjd	for flag in ${flags}; do
48211186Spjd		expect 0 lchflags ${n0} ${flag}
49211186Spjd		expect ${flag} lstat ${n0} flags
50211186Spjd		[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
51211186Spjd		expect EPERM rename ${n0} ${n1}
52211186Spjd		[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
53211186Spjd		expect ENOENT rename ${n1} ${n0}
54211186Spjd	done
55211186Spjd	expect 0 lchflags ${n0} none
56211186Spjd	if [ "${type}" = "dir" ]; then
57211186Spjd		expect 0 rmdir ${n0}
58211186Spjd	else
59211186Spjd		expect 0 unlink ${n0}
60211186Spjd	fi
61166065Spjddone
62