1f8c94cecSXin LI#!/bin/sh 2f8c94cecSXin LI# 3f8c94cecSXin LI# $NetBSD: t_setattr,v 1.6 2006/11/09 16:20:06 jmmv Exp $ 4f8c94cecSXin LI# 5f8c94cecSXin LI# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. 6f8c94cecSXin LI# All rights reserved. 7f8c94cecSXin LI# 8f8c94cecSXin LI# This code is derived from software contributed to The NetBSD Foundation 9f8c94cecSXin LI# by Julio M. Merino Vidal, developed as part of Google's Summer of Code 10f8c94cecSXin LI# 2005 program. 11f8c94cecSXin LI# 12f8c94cecSXin LI# Redistribution and use in source and binary forms, with or without 13f8c94cecSXin LI# modification, are permitted provided that the following conditions 14f8c94cecSXin LI# are met: 15f8c94cecSXin LI# 1. Redistributions of source code must retain the above copyright 16f8c94cecSXin LI# notice, this list of conditions and the following disclaimer. 17f8c94cecSXin LI# 2. Redistributions in binary form must reproduce the above copyright 18f8c94cecSXin LI# notice, this list of conditions and the following disclaimer in the 19f8c94cecSXin LI# documentation and/or other materials provided with the distribution. 20f8c94cecSXin LI# 3. All advertising materials mentioning features or use of this software 21f8c94cecSXin LI# must display the following acknowledgement: 22f8c94cecSXin LI# This product includes software developed by the NetBSD 23f8c94cecSXin LI# Foundation, Inc. and its contributors. 24f8c94cecSXin LI# 4. Neither the name of The NetBSD Foundation nor the names of its 25f8c94cecSXin LI# contributors may be used to endorse or promote products derived 26f8c94cecSXin LI# from this software without specific prior written permission. 27f8c94cecSXin LI# 28f8c94cecSXin LI# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29f8c94cecSXin LI# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30f8c94cecSXin LI# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31f8c94cecSXin LI# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32f8c94cecSXin LI# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33f8c94cecSXin LI# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34f8c94cecSXin LI# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35f8c94cecSXin LI# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36f8c94cecSXin LI# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37f8c94cecSXin LI# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38f8c94cecSXin LI# POSSIBILITY OF SUCH DAMAGE. 39f8c94cecSXin LI# 40f8c94cecSXin LI# $FreeBSD$ 41f8c94cecSXin LI# 42f8c94cecSXin LI 43f8c94cecSXin LI# 44f8c94cecSXin LI# Verifies that the setattr vnode operation works, using several commands 45f8c94cecSXin LI# that require this function. 46f8c94cecSXin LI# 47f8c94cecSXin LI 48f8c94cecSXin LItest_run() { 49f8c94cecSXin LI test_mount 50f8c94cecSXin LI 51f8c94cecSXin LI test_name "File owner can be changed on its own" 52f8c94cecSXin LI mkdir own || die 53f8c94cecSXin LI eval $(stat -s own | sed -e 's|st_|ost_|g') 54f8c94cecSXin LI chown 1234 own || die 55f8c94cecSXin LI eval $(stat -s own) 56f8c94cecSXin LI [ ${st_uid} -eq 1234 ] || die 57f8c94cecSXin LI [ ${st_gid} -eq ${ost_gid} ] || die 58f8c94cecSXin LI 59f8c94cecSXin LI mkdir ownq || die 60f8c94cecSXin LI echo 'chown 1234 ownq' | kqueue_monitor 1 ownq || die 61f8c94cecSXin LI test_name "Changing a file's owner raises NOTE_ATTRIB on it" 62f8c94cecSXin LI kqueue_check ownq NOTE_ATTRIB || die 63f8c94cecSXin LI 64f8c94cecSXin LI test_name "File group can be changed on its own" 65f8c94cecSXin LI mkdir grp || die 66f8c94cecSXin LI eval $(stat -s grp | sed -e 's|st_|ost_|g') 67f8c94cecSXin LI chgrp 5678 grp || die 68f8c94cecSXin LI eval $(stat -s grp) 69f8c94cecSXin LI [ ${st_uid} -eq ${ost_uid} ] || die 70f8c94cecSXin LI [ ${st_gid} -eq 5678 ] || die 71f8c94cecSXin LI 72f8c94cecSXin LI mkdir grpq || die 73f8c94cecSXin LI echo 'chgrp 1234 grpq' | kqueue_monitor 1 grpq || die 74f8c94cecSXin LI test_name "Changing a file's group raises NOTE_ATTRIB on it" 75f8c94cecSXin LI kqueue_check grpq NOTE_ATTRIB || die 76f8c94cecSXin LI 77f8c94cecSXin LI test_name "File owner and group can be changed at once" 78f8c94cecSXin LI mkdir owngrp || die 79f8c94cecSXin LI chown 1234:5678 owngrp || die 80f8c94cecSXin LI eval $(stat -s owngrp) 81f8c94cecSXin LI [ ${st_uid} -eq 1234 ] || die 82f8c94cecSXin LI [ ${st_gid} -eq 5678 ] || die 83f8c94cecSXin LI 84f8c94cecSXin LI mkdir owngrpp || die 85f8c94cecSXin LI echo 'chown 1234:5678 owngrpp' | kqueue_monitor 1 owngrpp || die 86f8c94cecSXin LI test_name "Changing a file's owner and group raises NOTE_ATTRIB on it" 87f8c94cecSXin LI kqueue_check owngrpp NOTE_ATTRIB || die 88f8c94cecSXin LI 89f8c94cecSXin LI test_name "File mode can be changed" 90f8c94cecSXin LI mkdir mode || die 91f8c94cecSXin LI chmod 0000 mode || die 92f8c94cecSXin LI eval $(stat -s mode) 93f8c94cecSXin LI [ ${st_mode} -eq 40000 ] || die 94f8c94cecSXin LI 95f8c94cecSXin LI mkdir modeq || die 96f8c94cecSXin LI echo 'chmod 0000 modeq' | kqueue_monitor 1 modeq || die 97f8c94cecSXin LI test_name "Updating a file's mode raises NOTE_ATTRIB on it" 98f8c94cecSXin LI kqueue_check modeq NOTE_ATTRIB || die 99f8c94cecSXin LI 100f8c94cecSXin LI test_name "File times can be changed" 101f8c94cecSXin LI mkdir times || die 102f8c94cecSXin LI TZ=GMT touch -t 200501010101 times || die 103f8c94cecSXin LI eval $(stat -s times) 104f8c94cecSXin LI [ ${st_atime} = ${st_mtime} ] || die 105f8c94cecSXin LI [ ${st_atime} = 1104541260 ] || die 106f8c94cecSXin LI 107f8c94cecSXin LI mkdir timesq || die 108f8c94cecSXin LI echo 'touch timesq' | kqueue_monitor 1 timesq || die 109f8c94cecSXin LI test_name "Updating a file's times raises NOTE_ATTRIB on it" 110f8c94cecSXin LI kqueue_check timesq NOTE_ATTRIB || die 111f8c94cecSXin LI 112f8c94cecSXin LI test_unmount 113f8c94cecSXin LI} 114f8c94cecSXin LI 115f8c94cecSXin LI. ${SUBRDIR}/h_funcs.subr 116