xref: /freebsd-src/tools/regression/tmpfs/t_setattr (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1*f8c94cecSXin LI#!/bin/sh
2*f8c94cecSXin LI#
3*f8c94cecSXin LI# $NetBSD: t_setattr,v 1.6 2006/11/09 16:20:06 jmmv 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 setattr vnode operation works, using several commands
37*f8c94cecSXin LI# that require this function.
38*f8c94cecSXin LI#
39*f8c94cecSXin LI
40*f8c94cecSXin LItest_run() {
41*f8c94cecSXin LI	test_mount
42*f8c94cecSXin LI
43*f8c94cecSXin LI	test_name "File owner can be changed on its own"
44*f8c94cecSXin LI	mkdir own || die
45*f8c94cecSXin LI	eval $(stat -s own | sed -e 's|st_|ost_|g')
46*f8c94cecSXin LI	chown 1234 own || die
47*f8c94cecSXin LI	eval $(stat -s own)
48*f8c94cecSXin LI	[ ${st_uid} -eq 1234 ] || die
49*f8c94cecSXin LI	[ ${st_gid} -eq ${ost_gid} ] || die
50*f8c94cecSXin LI
51*f8c94cecSXin LI	mkdir ownq || die
52*f8c94cecSXin LI	echo 'chown 1234 ownq' | kqueue_monitor 1 ownq || die
53*f8c94cecSXin LI	test_name "Changing a file's owner raises NOTE_ATTRIB on it"
54*f8c94cecSXin LI	kqueue_check ownq NOTE_ATTRIB || die
55*f8c94cecSXin LI
56*f8c94cecSXin LI	test_name "File group can be changed on its own"
57*f8c94cecSXin LI	mkdir grp || die
58*f8c94cecSXin LI	eval $(stat -s grp | sed -e 's|st_|ost_|g')
59*f8c94cecSXin LI	chgrp 5678 grp || die
60*f8c94cecSXin LI	eval $(stat -s grp)
61*f8c94cecSXin LI	[ ${st_uid} -eq ${ost_uid} ] || die
62*f8c94cecSXin LI	[ ${st_gid} -eq 5678 ] || die
63*f8c94cecSXin LI
64*f8c94cecSXin LI	mkdir grpq || die
65*f8c94cecSXin LI	echo 'chgrp 1234 grpq' | kqueue_monitor 1 grpq || die
66*f8c94cecSXin LI	test_name "Changing a file's group raises NOTE_ATTRIB on it"
67*f8c94cecSXin LI	kqueue_check grpq NOTE_ATTRIB || die
68*f8c94cecSXin LI
69*f8c94cecSXin LI	test_name "File owner and group can be changed at once"
70*f8c94cecSXin LI	mkdir owngrp || die
71*f8c94cecSXin LI	chown 1234:5678 owngrp || die
72*f8c94cecSXin LI	eval $(stat -s owngrp)
73*f8c94cecSXin LI	[ ${st_uid} -eq 1234 ] || die
74*f8c94cecSXin LI	[ ${st_gid} -eq 5678 ] || die
75*f8c94cecSXin LI
76*f8c94cecSXin LI	mkdir owngrpp || die
77*f8c94cecSXin LI	echo 'chown 1234:5678 owngrpp' | kqueue_monitor 1 owngrpp || die
78*f8c94cecSXin LI	test_name "Changing a file's owner and group raises NOTE_ATTRIB on it"
79*f8c94cecSXin LI	kqueue_check owngrpp NOTE_ATTRIB || die
80*f8c94cecSXin LI
81*f8c94cecSXin LI	test_name "File mode can be changed"
82*f8c94cecSXin LI	mkdir mode || die
83*f8c94cecSXin LI	chmod 0000 mode || die
84*f8c94cecSXin LI	eval $(stat -s mode)
85*f8c94cecSXin LI	[ ${st_mode} -eq 40000 ] || die
86*f8c94cecSXin LI
87*f8c94cecSXin LI	mkdir modeq || die
88*f8c94cecSXin LI	echo 'chmod 0000 modeq' | kqueue_monitor 1 modeq || die
89*f8c94cecSXin LI	test_name "Updating a file's mode raises NOTE_ATTRIB on it"
90*f8c94cecSXin LI	kqueue_check modeq NOTE_ATTRIB || die
91*f8c94cecSXin LI
92*f8c94cecSXin LI	test_name "File times can be changed"
93*f8c94cecSXin LI	mkdir times || die
94*f8c94cecSXin LI	TZ=GMT touch -t 200501010101 times || die
95*f8c94cecSXin LI	eval $(stat -s times)
96*f8c94cecSXin LI	[ ${st_atime} = ${st_mtime} ] || die
97*f8c94cecSXin LI	[ ${st_atime} = 1104541260 ] || die
98*f8c94cecSXin LI
99*f8c94cecSXin LI	mkdir timesq || die
100*f8c94cecSXin LI	echo 'touch timesq' | kqueue_monitor 1 timesq || die
101*f8c94cecSXin LI	test_name "Updating a file's times raises NOTE_ATTRIB on it"
102*f8c94cecSXin LI	kqueue_check timesq NOTE_ATTRIB || die
103*f8c94cecSXin LI
104*f8c94cecSXin LI	test_unmount
105*f8c94cecSXin LI}
106*f8c94cecSXin LI
107*f8c94cecSXin LI. ${SUBRDIR}/h_funcs.subr
108