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