xref: /freebsd/contrib/pjdfstest/tests/link/13.t (revision 5bf5ca772c6de2d53344a78cf461447cc322ccea)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/link/13.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="link returns EPERM if the parent directory of the destination file has its immutable flag set"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags
11
12case "${os}:${fs}" in
13FreeBSD:ZFS)
14	echo "1..29"
15	;;
16FreeBSD:UFS)
17	echo "1..49"
18	;;
19*)
20	quick_exit
21esac
22
23n0=`namegen`
24n1=`namegen`
25n2=`namegen`
26
27expect 0 mkdir ${n0} 0755
28
29expect 0 create ${n0}/${n1} 0644
30expect 1 stat ${n0}/${n1} nlink
31expect 0 link ${n0}/${n1} ${n0}/${n2}
32expect 2 stat ${n0}/${n1} nlink
33expect 0 unlink ${n0}/${n2}
34expect 1 stat ${n0}/${n1} nlink
35
36expect 0 chflags ${n0} SF_IMMUTABLE
37expect EPERM link ${n0}/${n1} ${n0}/${n2}
38expect 1 stat ${n0}/${n1} nlink
39expect 0 chflags ${n0} none
40expect 0 link ${n0}/${n1} ${n0}/${n2}
41expect 2 stat ${n0}/${n1} nlink
42expect 0 unlink ${n0}/${n2}
43expect 1 stat ${n0}/${n1} nlink
44
45expect 0 chflags ${n0} SF_NOUNLINK
46expect 0 link ${n0}/${n1} ${n0}/${n2}
47expect 2 stat ${n0}/${n1} nlink
48expect 0 chflags ${n0} none
49expect 0 unlink ${n0}/${n2}
50expect 1 stat ${n0}/${n1} nlink
51
52expect 0 chflags ${n0} SF_APPEND
53expect 0 link ${n0}/${n1} ${n0}/${n2}
54expect 2 stat ${n0}/${n1} nlink
55expect 0 chflags ${n0} none
56expect 0 unlink ${n0}/${n2}
57expect 1 stat ${n0}/${n1} nlink
58
59case "${os}:${fs}" in
60FreeBSD:UFS)
61	expect 0 chflags ${n0} UF_IMMUTABLE
62	expect EPERM link ${n0}/${n1} ${n0}/${n2}
63	expect 1 stat ${n0}/${n1} nlink
64	expect 0 chflags ${n0} none
65	expect 0 link ${n0}/${n1} ${n0}/${n2}
66	expect 2 stat ${n0}/${n1} nlink
67	expect 0 unlink ${n0}/${n2}
68	expect 1 stat ${n0}/${n1} nlink
69
70	expect 0 chflags ${n0} UF_NOUNLINK
71	expect 0 link ${n0}/${n1} ${n0}/${n2}
72	expect 2 stat ${n0}/${n1} nlink
73	expect 0 chflags ${n0} none
74	expect 0 unlink ${n0}/${n2}
75	expect 1 stat ${n0}/${n1} nlink
76
77	expect 0 chflags ${n0} UF_APPEND
78	expect 0 link ${n0}/${n1} ${n0}/${n2}
79	expect 2 stat ${n0}/${n1} nlink
80	expect 0 chflags ${n0} none
81	expect 0 unlink ${n0}/${n2}
82	expect 1 stat ${n0}/${n1} nlink
83	;;
84esac
85
86expect 0 unlink ${n0}/${n1}
87expect 0 rmdir ${n0}
88