xref: /freebsd-src/tools/regression/tmpfs/t_remove (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1*f8c94cecSXin LI#!/bin/sh
2*f8c94cecSXin LI#
3*f8c94cecSXin LI# $NetBSD: t_remove,v 1.7.2.1 2007/01/04 20:29:50 bouyer Exp $
4*f8c94cecSXin LI#
5*f8c94cecSXin LI# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
6*f8c94cecSXin LI# All rights reserved.
7*f8c94cecSXin LI#
8*f8c94cecSXin LI# This code is derived from software contributed to The NetBSD Foundation
9*f8c94cecSXin LI# by Julio M. Merino Vidal, developed as part of Google's Summer of Code
10*f8c94cecSXin LI# 2005 program.
11*f8c94cecSXin LI#
12*f8c94cecSXin LI# Redistribution and use in source and binary forms, with or without
13*f8c94cecSXin LI# modification, are permitted provided that the following conditions
14*f8c94cecSXin LI# are met:
15*f8c94cecSXin LI# 1. Redistributions of source code must retain the above copyright
16*f8c94cecSXin LI#    notice, this list of conditions and the following disclaimer.
17*f8c94cecSXin LI# 2. Redistributions in binary form must reproduce the above copyright
18*f8c94cecSXin LI#    notice, this list of conditions and the following disclaimer in the
19*f8c94cecSXin LI#    documentation and/or other materials provided with the distribution.
20*f8c94cecSXin LI#
21*f8c94cecSXin LI# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22*f8c94cecSXin LI# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23*f8c94cecSXin LI# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24*f8c94cecSXin LI# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25*f8c94cecSXin LI# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26*f8c94cecSXin LI# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27*f8c94cecSXin LI# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*f8c94cecSXin LI# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29*f8c94cecSXin LI# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30*f8c94cecSXin LI# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31*f8c94cecSXin LI# POSSIBILITY OF SUCH DAMAGE.
32*f8c94cecSXin LI#
33*f8c94cecSXin LI#
34*f8c94cecSXin LI
35*f8c94cecSXin LI#
36*f8c94cecSXin LI# Verifies that the remove operation works.
37*f8c94cecSXin LI#
38*f8c94cecSXin LI
39*f8c94cecSXin LItest_run() {
40*f8c94cecSXin LI	test_mount
41*f8c94cecSXin LI
42*f8c94cecSXin LI	test_name "Files can be removed"
43*f8c94cecSXin LI	test -f a && die
44*f8c94cecSXin LI	touch a || die
45*f8c94cecSXin LI	test -f a || die
46*f8c94cecSXin LI	rm a || die
47*f8c94cecSXin LI	test -f a && die
48*f8c94cecSXin LI
49*f8c94cecSXin LI	test_name "Files with uchg flags cannot be removed"
50*f8c94cecSXin LI	touch a || die
51*f8c94cecSXin LI	chflags uchg a || die
52*f8c94cecSXin LI	#Not valid case in FreeBSD
53*f8c94cecSXin LI	#rm -f a 2>/dev/null && die
54*f8c94cecSXin LI	chflags nouchg a || die
55*f8c94cecSXin LI	rm a || die
56*f8c94cecSXin LI	test -f a && die
57*f8c94cecSXin LI
58*f8c94cecSXin LI	test_name "The node . cannot be unlinked"
59*f8c94cecSXin LI	mkdir a || die
60*f8c94cecSXin LI	unlink a/. 2>/dev/null && die
61*f8c94cecSXin LI	rmdir a
62*f8c94cecSXin LI
63*f8c94cecSXin LI	mkdir dir || die
64*f8c94cecSXin LI	touch dir/a || die
65*f8c94cecSXin LI	echo 'rm dir/a' | kqueue_monitor 2 dir dir/a || die
66*f8c94cecSXin LI	test_name "Deleting a file raises NOTE_DELETE on it"
67*f8c94cecSXin LI	kqueue_check dir/a NOTE_DELETE || die
68*f8c94cecSXin LI	test_name "Deleting a file raises NOTE_WRITE on the parent directory"
69*f8c94cecSXin LI	kqueue_check dir NOTE_WRITE || die
70*f8c94cecSXin LI	rmdir dir || die
71*f8c94cecSXin LI
72*f8c94cecSXin LI	test_unmount
73*f8c94cecSXin LI}
74*f8c94cecSXin LI
75*f8c94cecSXin LI. ${SUBRDIR}/h_funcs.subr
76