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