1170809Sdelphij#!/bin/sh 2170809Sdelphij# 3170809Sdelphij# $NetBSD: t_link,v 1.5 2006/11/09 16:20:06 jmmv Exp $ 4170809Sdelphij# 5170809Sdelphij# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. 6170809Sdelphij# All rights reserved. 7170809Sdelphij# 8170809Sdelphij# This code is derived from software contributed to The NetBSD Foundation 9170809Sdelphij# by Julio M. Merino Vidal, developed as part of Google's Summer of Code 10170809Sdelphij# 2005 program. 11170809Sdelphij# 12170809Sdelphij# Redistribution and use in source and binary forms, with or without 13170809Sdelphij# modification, are permitted provided that the following conditions 14170809Sdelphij# are met: 15170809Sdelphij# 1. Redistributions of source code must retain the above copyright 16170809Sdelphij# notice, this list of conditions and the following disclaimer. 17170809Sdelphij# 2. Redistributions in binary form must reproduce the above copyright 18170809Sdelphij# notice, this list of conditions and the following disclaimer in the 19170809Sdelphij# documentation and/or other materials provided with the distribution. 20170809Sdelphij# 21170809Sdelphij# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22170809Sdelphij# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23170809Sdelphij# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24170809Sdelphij# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25170809Sdelphij# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26170809Sdelphij# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27170809Sdelphij# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28170809Sdelphij# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29170809Sdelphij# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30170809Sdelphij# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31170809Sdelphij# POSSIBILITY OF SUCH DAMAGE. 32170809Sdelphij# 33170809Sdelphij# $FreeBSD$ 34170809Sdelphij# 35170809Sdelphij 36170809Sdelphij# 37170809Sdelphij# Verifies that the link operation works. 38170809Sdelphij# 39170809Sdelphij 40170809Sdelphijtest_run() { 41170809Sdelphij test_mount 42170809Sdelphij 43170809Sdelphij test_name "Link operation works" 44170809Sdelphij touch a || die 45170809Sdelphij touch z || die 46170809Sdelphij eval $(stat -s a | sed -e 's|st_|sta_|g') 47170809Sdelphij eval $(stat -s z | sed -e 's|st_|stz_|g') 48170809Sdelphij test ${sta_ino} != ${stz_ino} || die 49170809Sdelphij test ${sta_nlink} -eq 1 || die 50170809Sdelphij ln a b || die 51170809Sdelphij test_name "Link count is correct after links are created" 52170809Sdelphij eval $(stat -s a | sed -e 's|st_|sta_|g') 53170809Sdelphij eval $(stat -s b | sed -e 's|st_|stb_|g') 54170809Sdelphij test ${sta_ino} = ${stb_ino} || die 55170809Sdelphij test ${sta_nlink} -eq 2 || die 56170809Sdelphij test ${stb_nlink} -eq 2 || die 57170809Sdelphij test_name "Link count is correct after links are deleted" 58170809Sdelphij rm a || die 59170809Sdelphij eval $(stat -s b | sed -e 's|st_|stb_|g') 60170809Sdelphij test ${stb_nlink} -eq 1 || die 61170809Sdelphij rm b || die 62170809Sdelphij 63170809Sdelphij test_name "Link operation works in subdirectories" 64170809Sdelphij touch a || die 65170809Sdelphij mkdir c || die 66170809Sdelphij ln a c/b || die 67170809Sdelphij test_name "Link count is correct after links are created" 68170809Sdelphij eval $(stat -s a | sed -e 's|st_|sta_|g') 69170809Sdelphij eval $(stat -s c/b | sed -e 's|st_|stb_|g') 70170809Sdelphij test ${sta_ino} = ${stb_ino} || die 71170809Sdelphij test ${sta_nlink} -eq 2 || die 72170809Sdelphij test ${stb_nlink} -eq 2 || die 73170809Sdelphij test_name "Link count is correct after links are deleted" 74170809Sdelphij rm a || die 75170809Sdelphij eval $(stat -s c/b | sed -e 's|st_|stb_|g') 76170809Sdelphij test ${stb_nlink} -eq 1 || die 77170809Sdelphij rm c/b || die 78170809Sdelphij rmdir c || die 79170809Sdelphij 80170809Sdelphij mkdir dir || die 81170809Sdelphij touch dir/a || die 82170809Sdelphij echo 'ln dir/a dir/b' | kqueue_monitor 2 dir dir/a || die 83170809Sdelphij test_name "Creating a link raises NOTE_LINK on the source file" 84170809Sdelphij kqueue_check dir/a NOTE_LINK || die 85170809Sdelphij test_name "Creating a link raises NOTE_WRITE on the parent directory" 86170809Sdelphij kqueue_check dir NOTE_WRITE || die 87170809Sdelphij 88170809Sdelphij echo 'rm dir/a' | kqueue_monitor 2 dir dir/b || die 89170809Sdelphij # XXX According to the (short) kqueue(2) documentation, the following 90170809Sdelphij # should raise a NOTE_LINK but FFS raises a NOTE_DELETE... 91170809Sdelphij test_name "Deleting a link raises NOTE_DELETE on one other link" 92170809Sdelphij kqueue_check dir/b NOTE_DELETE || die 93170809Sdelphij test_name "Deleting a link raises NOTE_WRITE on the parent directory" 94170809Sdelphij kqueue_check dir NOTE_WRITE || die 95170809Sdelphij rm dir/b || die 96170809Sdelphij rmdir dir || die 97170809Sdelphij 98170809Sdelphij test_unmount 99170809Sdelphij} 100170809Sdelphij 101170809Sdelphij. ${SUBRDIR}/h_funcs.subr 102