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