xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_link.sh (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1# $NetBSD: t_link.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
2#
3# Copyright (c) 2005, 2006, 2007, 2008 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#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28#
29# Verifies that the link operation works.
30#
31
32atf_test_case basic
33basic_head() {
34	atf_set "descr" "Verifies that the link operation works on files" \
35	                "at the top directory"
36	atf_set "require.user" "root"
37}
38basic_body() {
39	test_mount
40
41	atf_check -s eq:0 -o empty -e empty touch a
42	atf_check -s eq:0 -o empty -e empty touch z
43	eval $(stat -s a | sed -e 's|st_|sta_|g')
44	eval $(stat -s z | sed -e 's|st_|stz_|g')
45	test ${sta_ino} != ${stz_ino} || \
46	    atf_fail "Node numbers are not different"
47	test ${sta_nlink} -eq 1 || atf_fail "Number of links is incorrect"
48	atf_check -s eq:0 -o empty -e empty ln a b
49
50	echo "Checking if link count is correct after links are created"
51	eval $(stat -s a | sed -e 's|st_|sta_|g')
52	eval $(stat -s b | sed -e 's|st_|stb_|g')
53	test ${sta_ino} = ${stb_ino} || atf_fail "Node number changed"
54	test ${sta_nlink} -eq 2 || atf_fail "Link count is incorrect"
55	test ${stb_nlink} -eq 2 || atf_fail "Link count is incorrect"
56
57	echo "Checking if link count is correct after links are deleted"
58	atf_check -s eq:0 -o empty -e empty rm a
59	eval $(stat -s b | sed -e 's|st_|stb_|g')
60	test ${stb_nlink} -eq 1 || atf_fail "Link count is incorrect"
61	atf_check -s eq:0 -o empty -e empty rm b
62
63	test_unmount
64}
65
66atf_test_case subdirs
67subdirs_head() {
68	atf_set "descr" "Verifies that the link operation works if used" \
69	                "in subdirectories"
70	atf_set "require.user" "root"
71}
72subdirs_body() {
73	test_mount
74
75	atf_check -s eq:0 -o empty -e empty touch a
76	atf_check -s eq:0 -o empty -e empty mkdir c
77	atf_check -s eq:0 -o empty -e empty ln a c/b
78
79	echo "Checking if link count is correct after links are created"
80	eval $(stat -s a | sed -e 's|st_|sta_|g')
81	eval $(stat -s c/b | sed -e 's|st_|stb_|g')
82	test ${sta_ino} = ${stb_ino} || atf_fail "Node number changed"
83	test ${sta_nlink} -eq 2 || atf_fail "Link count is incorrect"
84	test ${stb_nlink} -eq 2 || atf_fail "Link count is incorrect"
85
86	echo "Checking if link count is correct after links are deleted"
87	atf_check -s eq:0 -o empty -e empty rm a
88	eval $(stat -s c/b | sed -e 's|st_|stb_|g')
89	test ${stb_nlink} -eq 1 || atf_fail "Link count is incorrect"
90	atf_check -s eq:0 -o empty -e empty rm c/b
91	atf_check -s eq:0 -o empty -e empty rmdir c
92
93	test_unmount
94}
95
96atf_test_case kqueue
97kqueue_head() {
98	atf_set "descr" "Verifies that creating a link raises the correct" \
99	                "kqueue events"
100	atf_set "require.user" "root"
101}
102kqueue_body() {
103	test_mount
104
105	atf_check -s eq:0 -o empty -e empty mkdir dir
106	atf_check -s eq:0 -o empty -e empty touch dir/a
107	echo 'ln dir/a dir/b' | kqueue_monitor 2 dir dir/a
108	kqueue_check dir/a NOTE_LINK
109	kqueue_check dir NOTE_WRITE
110
111	echo 'rm dir/a' | kqueue_monitor 2 dir dir/b
112	# XXX According to the (short) kqueue(2) documentation, the following
113	# should raise a NOTE_LINK but FFS raises a NOTE_DELETE...
114	kqueue_check dir/b NOTE_LINK
115	kqueue_check dir NOTE_WRITE
116	atf_check -s eq:0 -o empty -e empty rm dir/b
117	atf_check -s eq:0 -o empty -e empty rmdir dir
118
119	test_unmount
120}
121
122atf_init_test_cases() {
123	. $(atf_get_srcdir)/../h_funcs.subr
124	. $(atf_get_srcdir)/h_funcs.subr
125
126	atf_add_test_case basic
127	atf_add_test_case subdirs
128	atf_add_test_case kqueue
129}
130