xref: /freebsd/contrib/pjdfstest/tests/rename/07.t (revision f0cfa1b168014f56c02b83e5f28412cc5f78d117)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/rename/07.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 'from' argument has its immutable or append-only flag set"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags
11
12case "${os}:${fs}" in
13FreeBSD:ZFS)
14	flags1="SF_IMMUTABLE SF_APPEND"
15	flags2="SF_NOUNLINK"
16	echo "1..128"
17	;;
18FreeBSD:UFS)
19	flags1="SF_IMMUTABLE SF_APPEND UF_IMMUTABLE UF_APPEND"
20	flags2="SF_NOUNLINK UF_NOUNLINK"
21	echo "1..212"
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} ${n0}/${n1}
35	for flag in ${flags1}; do
36		expect 0 chflags ${n0} ${flag}
37		expect ${flag} stat ${n0} flags
38		[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
39		expect EPERM rename ${n0}/${n1} ${n2}
40		[ "${flag}" = "SF_APPEND" ] && todo FreeBSD:ZFS "Renaming a file protected by SF_APPEND should return EPERM."
41		expect ENOENT rename ${n2} ${n0}/${n1}
42	done
43	expect 0 chflags ${n0} none
44	if [ "${type}" = "dir" ]; then
45		expect 0 rmdir ${n0}/${n1}
46	else
47		expect 0 unlink ${n0}/${n1}
48	fi
49done
50
51for type in regular dir fifo block char socket symlink; do
52	create_file ${type} ${n0}/${n1}
53	for flag in ${flags2}; do
54		expect 0 chflags ${n0} ${flag}
55		expect ${flag} stat ${n0} flags
56		expect 0 rename ${n0}/${n1} ${n2}
57		expect 0 rename ${n2} ${n0}/${n1}
58	done
59	expect 0 chflags ${n0} none
60	if [ "${type}" = "dir" ]; then
61		expect 0 rmdir ${n0}/${n1}
62	else
63		expect 0 unlink ${n0}/${n1}
64	fi
65done
66
67expect 0 rmdir ${n0}
68