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