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