xref: /freebsd/contrib/pjdfstest/tests/chflags/00.t (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/chflags/00.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="chflags changes flags"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require chflags
11
12case "${os}:${fs}" in
13FreeBSD:UFS)
14	allflags="UF_NODUMP,UF_IMMUTABLE,UF_APPEND,UF_NOUNLINK,UF_OPAQUE,SF_ARCHIVED,SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK"
15	userflags="UF_NODUMP,UF_IMMUTABLE,UF_APPEND,UF_NOUNLINK,UF_OPAQUE"
16	systemflags="SF_ARCHIVED,SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK"
17
18	echo "1..742"
19	;;
20FreeBSD:ZFS)
21	allflags="UF_NODUMP,SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK"
22	userflags="UF_NODUMP"
23	systemflags="SF_IMMUTABLE,SF_APPEND,SF_NOUNLINK"
24
25	echo "1..482"
26	;;
27*)
28	quick_exit
29	;;
30esac
31
32n0=`namegen`
33n1=`namegen`
34n2=`namegen`
35
36expect 0 mkdir ${n2} 0755
37cdir=`pwd`
38cd ${n2}
39
40for type in regular dir fifo block char socket; do
41	create_file ${type} ${n0}
42	expect none stat ${n0} flags
43	expect 0 chflags ${n0} ${allflags}
44	expect ${allflags} stat ${n0} flags
45	expect 0 chflags ${n0} ${userflags}
46	expect ${userflags} stat ${n0} flags
47	expect 0 chflags ${n0} ${systemflags}
48	expect ${systemflags} stat ${n0} flags
49	expect 0 chflags ${n0} none
50	expect none stat ${n0} flags
51	if [ "${type}" = "dir" ]; then
52		expect 0 rmdir ${n0}
53	else
54		expect 0 unlink ${n0}
55	fi
56
57	create_file ${type} ${n0}
58	expect none stat ${n0} flags
59	expect 0 lchflags ${n0} ${allflags}
60	expect ${allflags} stat ${n0} flags
61	expect 0 lchflags ${n0} ${userflags}
62	expect ${userflags} stat ${n0} flags
63	expect 0 lchflags ${n0} ${systemflags}
64	expect ${systemflags} stat ${n0} flags
65	expect 0 lchflags ${n0} none
66	expect none stat ${n0} flags
67	if [ "${type}" = "dir" ]; then
68		expect 0 rmdir ${n0}
69	else
70		expect 0 unlink ${n0}
71	fi
72done
73
74expect 0 create ${n0} 0644
75expect 0 symlink ${n0} ${n1}
76expect none stat ${n1} flags
77expect none lstat ${n1} flags
78expect 0 chflags ${n1} ${allflags}
79expect ${allflags} stat ${n1} flags
80expect none lstat ${n1} flags
81expect 0 chflags ${n1} ${userflags}
82expect ${userflags} stat ${n1} flags
83expect none lstat ${n1} flags
84expect 0 chflags ${n1} ${systemflags}
85expect ${systemflags} stat ${n1} flags
86expect none lstat ${n1} flags
87expect 0 chflags ${n1} none
88expect none stat ${n1} flags
89expect none lstat ${n1} flags
90expect 0 unlink ${n1}
91expect 0 unlink ${n0}
92
93expect 0 create ${n0} 0644
94expect 0 symlink ${n0} ${n1}
95expect none stat ${n1} flags
96expect none lstat ${n1} flags
97expect 0 lchflags ${n1} ${allflags}
98expect ${allflags} lstat ${n1} flags
99expect none stat ${n1} flags
100expect 0 lchflags ${n1} ${userflags}
101expect ${userflags} lstat ${n1} flags
102expect none stat ${n1} flags
103expect 0 lchflags ${n1} ${systemflags}
104expect ${systemflags} lstat ${n1} flags
105expect none stat ${n1} flags
106expect 0 lchflags ${n1} none
107expect none lstat ${n1} flags
108expect none stat ${n1} flags
109expect 0 unlink ${n1}
110expect 0 unlink ${n0}
111
112# successful chflags(2) updates ctime.
113for type in regular dir fifo block char socket symlink; do
114	if [ "${type}" != "symlink" ]; then
115		create_file ${type} ${n0}
116		for flag in `echo ${allflags},none | tr ',' ' '`; do
117			ctime1=`${fstest} stat ${n0} ctime`
118			sleep 1
119			expect 0 chflags ${n0} ${flag}
120			ctime2=`${fstest} stat ${n0} ctime`
121			test_check $ctime1 -lt $ctime2
122		done
123		if [ "${type}" = "dir" ]; then
124			expect 0 rmdir ${n0}
125		else
126			expect 0 unlink ${n0}
127		fi
128	fi
129
130	create_file ${type} ${n0}
131	for flag in `echo ${allflags},none | tr ',' ' '`; do
132		ctime1=`${fstest} lstat ${n0} ctime`
133		sleep 1
134		expect 0 lchflags ${n0} ${flag}
135		ctime2=`${fstest} lstat ${n0} ctime`
136		test_check $ctime1 -lt $ctime2
137	done
138	if [ "${type}" = "dir" ]; then
139		expect 0 rmdir ${n0}
140	else
141		expect 0 unlink ${n0}
142	fi
143done
144
145# unsuccessful chflags(2) does not update ctime.
146for type in regular dir fifo block char socket symlink; do
147	if [ "${type}" != "symlink" ]; then
148		create_file ${type} ${n0}
149		for flag in `echo ${allflags},none | tr ',' ' '`; do
150			ctime1=`${fstest} stat ${n0} ctime`
151			sleep 1
152			expect EPERM -u 65534 chflags ${n0} ${flag}
153			ctime2=`${fstest} stat ${n0} ctime`
154			test_check $ctime1 -eq $ctime2
155		done
156		if [ "${type}" = "dir" ]; then
157			expect 0 rmdir ${n0}
158		else
159			expect 0 unlink ${n0}
160		fi
161	fi
162
163	create_file ${type} ${n0}
164	for flag in `echo ${allflags},none | tr ',' ' '`; do
165		ctime1=`${fstest} lstat ${n0} ctime`
166		sleep 1
167		expect EPERM -u 65534 lchflags ${n0} ${flag}
168		ctime2=`${fstest} lstat ${n0} ctime`
169		test_check $ctime1 -eq $ctime2
170	done
171	if [ "${type}" = "dir" ]; then
172		expect 0 rmdir ${n0}
173	else
174		expect 0 unlink ${n0}
175	fi
176done
177
178cd ${cdir}
179expect 0 rmdir ${n2}
180