xref: /freebsd/contrib/pjdfstest/tests/unlink/00.t (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/00.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="unlink removes regular files, symbolic links, fifos and sockets"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10echo "1..112"
11
12n0=`namegen`
13n1=`namegen`
14n2=`namegen`
15
16expect 0 mkdir ${n2} 0755
17cdir=`pwd`
18cd ${n2}
19
20expect 0 create ${n0} 0644
21expect regular lstat ${n0} type
22expect 0 unlink ${n0}
23expect ENOENT lstat ${n0} type
24
25expect 0 symlink ${n1} ${n0}
26expect symlink lstat ${n0} type
27expect 0 unlink ${n0}
28expect ENOENT lstat ${n0} type
29
30expect 0 mkfifo ${n0} 0644
31expect fifo lstat ${n0} type
32expect 0 unlink ${n0}
33expect ENOENT lstat ${n0} type
34
35expect 0 mknod ${n0} b 0644 1 2
36expect block lstat ${n0} type
37expect 0 unlink ${n0}
38expect ENOENT lstat ${n0} type
39
40expect 0 mknod ${n0} c 0644 1 2
41expect char lstat ${n0} type
42expect 0 unlink ${n0}
43expect ENOENT lstat ${n0} type
44
45expect 0 bind ${n0}
46expect socket lstat ${n0} type
47expect 0 unlink ${n0}
48expect ENOENT lstat ${n0} type
49
50# successful unlink(2) updates ctime.
51expect 0 create ${n0} 0644
52expect 0 link ${n0} ${n1}
53ctime1=`${fstest} stat ${n0} ctime`
54sleep 1
55expect 0 unlink ${n1}
56ctime2=`${fstest} stat ${n0} ctime`
57test_check $ctime1 -lt $ctime2
58expect 0 unlink ${n0}
59
60expect 0 mkfifo ${n0} 0644
61expect 0 link ${n0} ${n1}
62ctime1=`${fstest} stat ${n0} ctime`
63sleep 1
64expect 0 unlink ${n1}
65ctime2=`${fstest} stat ${n0} ctime`
66test_check $ctime1 -lt $ctime2
67expect 0 unlink ${n0}
68
69expect 0 mknod ${n0} b 0644 1 2
70expect 0 link ${n0} ${n1}
71ctime1=`${fstest} stat ${n0} ctime`
72sleep 1
73expect 0 unlink ${n1}
74ctime2=`${fstest} stat ${n0} ctime`
75test_check $ctime1 -lt $ctime2
76expect 0 unlink ${n0}
77
78expect 0 mknod ${n0} c 0644 1 2
79expect 0 link ${n0} ${n1}
80ctime1=`${fstest} stat ${n0} ctime`
81sleep 1
82expect 0 unlink ${n1}
83ctime2=`${fstest} stat ${n0} ctime`
84test_check $ctime1 -lt $ctime2
85expect 0 unlink ${n0}
86
87expect 0 bind ${n0}
88expect 0 link ${n0} ${n1}
89ctime1=`${fstest} stat ${n0} ctime`
90sleep 1
91expect 0 unlink ${n1}
92ctime2=`${fstest} stat ${n0} ctime`
93test_check $ctime1 -lt $ctime2
94expect 0 unlink ${n0}
95
96# unsuccessful unlink(2) does not update ctime.
97expect 0 create ${n0} 0644
98ctime1=`${fstest} stat ${n0} ctime`
99sleep 1
100expect EACCES -u 65534 unlink ${n0}
101ctime2=`${fstest} stat ${n0} ctime`
102test_check $ctime1 -eq $ctime2
103expect 0 unlink ${n0}
104
105expect 0 mkfifo ${n0} 0644
106ctime1=`${fstest} stat ${n0} ctime`
107sleep 1
108expect EACCES -u 65534 unlink ${n0}
109ctime2=`${fstest} stat ${n0} ctime`
110test_check $ctime1 -eq $ctime2
111expect 0 unlink ${n0}
112
113expect 0 mknod ${n0} b 0644 1 2
114ctime1=`${fstest} stat ${n0} ctime`
115sleep 1
116expect EACCES -u 65534 unlink ${n0}
117ctime2=`${fstest} stat ${n0} ctime`
118test_check $ctime1 -eq $ctime2
119expect 0 unlink ${n0}
120
121expect 0 mknod ${n0} c 0644 1 2
122ctime1=`${fstest} stat ${n0} ctime`
123sleep 1
124expect EACCES -u 65534 unlink ${n0}
125ctime2=`${fstest} stat ${n0} ctime`
126test_check $ctime1 -eq $ctime2
127expect 0 unlink ${n0}
128
129expect 0 bind ${n0}
130ctime1=`${fstest} stat ${n0} ctime`
131sleep 1
132expect EACCES -u 65534 unlink ${n0}
133ctime2=`${fstest} stat ${n0} ctime`
134test_check $ctime1 -eq $ctime2
135expect 0 unlink ${n0}
136
137expect 0 mkdir ${n0} 0755
138expect 0 create ${n0}/${n1} 0644
139time=`${fstest} stat ${n0} ctime`
140sleep 1
141expect 0 unlink ${n0}/${n1}
142mtime=`${fstest} stat ${n0} mtime`
143test_check $time -lt $mtime
144ctime=`${fstest} stat ${n0} ctime`
145test_check $time -lt $ctime
146expect 0 rmdir ${n0}
147
148expect 0 mkdir ${n0} 0755
149expect 0 mkfifo ${n0}/${n1} 0644
150time=`${fstest} stat ${n0} ctime`
151sleep 1
152expect 0 unlink ${n0}/${n1}
153mtime=`${fstest} stat ${n0} mtime`
154test_check $time -lt $mtime
155ctime=`${fstest} stat ${n0} ctime`
156test_check $time -lt $ctime
157expect 0 rmdir ${n0}
158
159expect 0 mkdir ${n0} 0755
160expect 0 mknod ${n0}/${n1} b 0644 1 2
161time=`${fstest} stat ${n0} ctime`
162sleep 1
163expect 0 unlink ${n0}/${n1}
164mtime=`${fstest} stat ${n0} mtime`
165test_check $time -lt $mtime
166ctime=`${fstest} stat ${n0} ctime`
167test_check $time -lt $ctime
168expect 0 rmdir ${n0}
169
170expect 0 mkdir ${n0} 0755
171expect 0 mknod ${n0}/${n1} c 0644 1 2
172time=`${fstest} stat ${n0} ctime`
173sleep 1
174expect 0 unlink ${n0}/${n1}
175mtime=`${fstest} stat ${n0} mtime`
176test_check $time -lt $mtime
177ctime=`${fstest} stat ${n0} ctime`
178test_check $time -lt $ctime
179expect 0 rmdir ${n0}
180
181expect 0 mkdir ${n0} 0755
182expect 0 bind ${n0}/${n1}
183time=`${fstest} stat ${n0} ctime`
184sleep 1
185expect 0 unlink ${n0}/${n1}
186mtime=`${fstest} stat ${n0} mtime`
187test_check $time -lt $mtime
188ctime=`${fstest} stat ${n0} ctime`
189test_check $time -lt $ctime
190expect 0 rmdir ${n0}
191
192expect 0 mkdir ${n0} 0755
193expect 0 symlink test ${n0}/${n1}
194time=`${fstest} stat ${n0} ctime`
195sleep 1
196expect 0 unlink ${n0}/${n1}
197mtime=`${fstest} stat ${n0} mtime`
198test_check $time -lt $mtime
199ctime=`${fstest} stat ${n0} ctime`
200test_check $time -lt $ctime
201expect 0 rmdir ${n0}
202
203expect 0 create ${n0} 0644
204expect 0 link ${n0} ${n1}
205time=`${fstest} stat ${n0} ctime`
206sleep 1
207expect 0 unlink ${n1}
208ctime=`${fstest} stat ${n0} ctime`
209test_check $time -lt $ctime
210expect 0 unlink ${n0}
211
212cd ${cdir}
213expect 0 rmdir ${n2}
214