xref: /netbsd-src/tests/fs/tmpfs/t_link.sh (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1# $NetBSD: t_link.sh,v 1.1 2007/11/12 15:18:23 jmmv Exp $
2#
3# Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14# 3. All advertising materials mentioning features or use of this software
15#    must display the following acknowledgement:
16#        This product includes software developed by the NetBSD
17#        Foundation, Inc. and its contributors.
18# 4. Neither the name of The NetBSD Foundation nor the names of its
19#    contributors may be used to endorse or promote products derived
20#    from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32# POSSIBILITY OF SUCH DAMAGE.
33#
34
35#
36# Verifies that the link operation works.
37#
38
39atf_test_case basic
40basic_head() {
41	atf_set "descr" "Verifies that the link operation works on files" \
42	                "at the top directory"
43	atf_set "require.user" "root"
44}
45basic_body() {
46	test_mount
47
48	atf_check 'touch a' 0 null null
49	atf_check 'touch z' 0 null null
50	eval $(stat -s a | sed -e 's|st_|sta_|g')
51	eval $(stat -s z | sed -e 's|st_|stz_|g')
52	test ${sta_ino} != ${stz_ino} || \
53	    atf_fail "Node numbers are not different"
54	test ${sta_nlink} -eq 1 || atf_fail "Number of links is incorrect"
55	atf_check 'ln a b' 0 null null
56
57	echo "Checking if link count is correct after links are created"
58	eval $(stat -s a | sed -e 's|st_|sta_|g')
59	eval $(stat -s b | sed -e 's|st_|stb_|g')
60	test ${sta_ino} = ${stb_ino} || atf_fail "Node number changed"
61	test ${sta_nlink} -eq 2 || atf_fail "Link count is incorrect"
62	test ${stb_nlink} -eq 2 || atf_fail "Link count is incorrect"
63
64	echo "Checking if link count is correct after links are deleted"
65	atf_check 'rm a' 0 null null
66	eval $(stat -s b | sed -e 's|st_|stb_|g')
67	test ${stb_nlink} -eq 1 || atf_fail "Link count is incorrect"
68	atf_check 'rm b' 0 null null
69
70	test_unmount
71}
72
73atf_test_case subdirs
74subdirs_head() {
75	atf_set "descr" "Verifies that the link operation works if used" \
76	                "in subdirectories"
77	atf_set "require.user" "root"
78}
79subdirs_body() {
80	test_mount
81
82	atf_check 'touch a' 0 null null
83	atf_check 'mkdir c' 0 null null
84	atf_check 'ln a c/b' 0 null null
85
86	echo "Checking if link count is correct after links are created"
87	eval $(stat -s a | sed -e 's|st_|sta_|g')
88	eval $(stat -s c/b | sed -e 's|st_|stb_|g')
89	test ${sta_ino} = ${stb_ino} || atf_fail "Node number changed"
90	test ${sta_nlink} -eq 2 || atf_fail "Link count is incorrect"
91	test ${stb_nlink} -eq 2 || atf_fail "Link count is incorrect"
92
93	echo "Checking if link count is correct after links are deleted"
94	atf_check 'rm a' 0 null null
95	eval $(stat -s c/b | sed -e 's|st_|stb_|g')
96	test ${stb_nlink} -eq 1 || atf_fail "Link count is incorrect"
97	atf_check 'rm c/b' 0 null null
98	atf_check 'rmdir c' 0 null null
99
100	test_unmount
101}
102
103atf_test_case kqueue
104kqueue_head() {
105	atf_set "descr" "Verifies that creating a link raises the correct" \
106	                "kqueue events"
107	atf_set "require.user" "root"
108}
109kqueue_body() {
110	test_mount
111
112	atf_check 'mkdir dir' 0 null null
113	atf_check 'touch dir/a' 0 null null
114	echo 'ln dir/a dir/b' | kqueue_monitor 2 dir dir/a
115	kqueue_check dir/a NOTE_LINK
116	kqueue_check dir NOTE_WRITE
117
118	echo 'rm dir/a' | kqueue_monitor 2 dir dir/b
119	# XXX According to the (short) kqueue(2) documentation, the following
120	# should raise a NOTE_LINK but FFS raises a NOTE_DELETE...
121	kqueue_check dir/b NOTE_LINK
122	kqueue_check dir NOTE_WRITE
123	atf_check 'rm dir/b' 0 null null
124	atf_check 'rmdir dir' 0 null null
125
126	test_unmount
127}
128
129atf_init_test_cases() {
130	. $(atf_get_srcdir)/../h_funcs.subr
131	. $(atf_get_srcdir)/h_funcs.subr
132
133	atf_add_test_case basic
134	atf_add_test_case subdirs
135	atf_add_test_case kqueue
136}
137