#! /bin/sh
# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
# Copyright (c) International Business Machines  Corp., 2001
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# PURPOSE: Tests NFS copy of various filesizes, file consistency
#          between copies and preservation of write/nowrite permissions.
#
# Ported by: Robbie Williamson (robbiew@us.ibm.com)

TCID="nfs02"
TST_TOTAL=3
TST_CLEANUP="nfs_cleanup"

. nfs_lib.sh
. test_net.sh

do_test1()
{
	tst_resm TINFO "do_test1 $TC"
	ROD cp $LTP_DATAFILES/ascii.jmb .
	tst_resm TINFO "compare both ascii.jmbs"
	ROD diff $LTP_DATAFILES/ascii.jmb ascii.jmb

	tst_resm TPASS "test1 passed"
}

do_test2()
{
	tst_resm TINFO "do_test2, copy data files"
	local files="ascii.sm ascii.med ascii.lg"

	for f in $files; do
		tst_resm TINFO "copy '$f' file"
		ROD cp $LTP_DATAFILES/$f .
		ROD cp $f ${f}cp
		ROD diff $LTP_DATAFILES/$f ${f}cp
	done

	tst_resm TPASS "test2 passed"
}

do_test3()
{
	tst_resm TINFO "do_test3, test permissions"
	ROD chmod a-wx ascii.sm
	ROD ls -l ascii.sm | grep -q "r--"
	ROD chmod a+w ascii.sm
	tst_resm TPASS "test3 passed"
}

LTP_DATAFILES="$LTPROOT/testcases/bin/datafiles"

nfs_setup

do_test1
do_test2
do_test3

tst_exit
