• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3#   Copyright (c) International Business Machines  Corp., 2000
4#
5#   This program is free software;  you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation; either version 2 of the License, or
8#   (at your option) any later version.
9#
10#   This program is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13#   the GNU General Public License for more details.
14#
15#   You should have received a copy of the GNU General Public License
16#   along with this program;  if not, write to the Free Software
17#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20#
21#  FILE(s)     : linktest.sh README
22#  DESCRIPTION : Regression test for max links per file
23#  USE         : linktest.sh <number of symlinks> <number of hardlinks>
24#  AUTHOR      : Garrett Cooper (yanegomi@gmail.com)
25#  HISTORY     :
26#	A rewrite of testcases/kernel/fs/linktest.pl
27
28export TCID=linker01
29export TST_TOTAL=2
30export TST_COUNT=1
31
32if [ $# -ne 2 ]; then
33	tst_res TBROK "" "usage: $0 {softlink count} {hardlink count}"
34	exit 1
35fi
36
37# TMPDIR not specified.
38if [ "x$TMPDIR" = x -o ! -d "$TMPDIR" ] ; then
39
40	if ! TMPDIR=$(mktemp -d) ; then
41		tst_res TBROK "" 'Failed to create $TMPDIR'
42		exit 1
43	fi
44	# We created the directory, so we have the power to delete it as well.
45	trap "rm -Rf '$TMPDIR'" EXIT
46
47# Most likely runltp provided; don't delete $TMPDIR, but instead delete the
48# files under it belonging to this process.
49else
50	trap "rm -Rf '$TMPDIR/[hs]link.$$'" EXIT
51fi
52
53cd "$TMPDIR" || tst_res TBROK "" "Failed to cd to $TMPDIR"
54
55mkdir hlink.$$ slink.$$ && touch hlink.$$/hfile slink.$$/sfile
56
57do_link() {
58	pfix=$1
59	ln_opts=$2
60	limit=$3
61	prefix_msg=$4
62
63	lerrors=0
64
65	i=0
66
67	cd "${pfix}link.$$"
68	while [ $i -lt $limit ]; do
69		if ! ln ${ln_opts} "$PWD/${pfix}file" ${pfix}file${i}; then
70			: $(( lerrors += 1 ))
71		fi
72		: $(( i+= 1 ))
73	done
74	cd ..
75
76	if [ $lerrors -eq 0 ]; then
77		RTYPE=TPASS
78	else
79		RTYPE=TFAIL
80	fi
81
82	tst_res $RTYPE "" "$prefix_msg Link Errors: $lerrors"
83
84	: $(( TST_COUNT += 1 ))
85
86}
87
88do_link s "-s" ${1} "Symbolic"
89do_link h   "" ${2} "Hard"
90
91rm -Rf hlink.$$ slink.$$
92