• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) International Business Machines Corp., 2000
4# Copyright (c) Linux Test Project, 2012-2019
5# Regression test for max links per file
6# Author: Ngie Cooper <yaneurabeya@gmail.com>
7
8TST_NEEDS_TMPDIR=1
9TST_TESTFUNC=do_test
10TST_OPTS="a:s:"
11TST_PARSE_ARGS=parse_args
12TST_USAGE=usage
13
14. tst_test.sh
15
16hard_links=1000
17soft_links=1000
18
19usage()
20{
21	echo "Usage: linktest.sh {-a n} {-s n}"
22	echo "-a n    Hard link count"
23	echo "-s n    Soft link count"
24}
25
26parse_args()
27{
28	tst_is_int "$2" || tst_brk TBROK "-$1 must be integer ($2)"
29	[ "$2" -ge 0 ] || tst_brk TBROK "-$1 must be >= 0 ($2)"
30
31	case $1 in
32	a) hard_links=$2;;
33	s) soft_links=$2;;
34	esac
35}
36
37do_link()
38{
39	local prefix="$1"
40	local ln_opts="$2"
41	local limit="$3"
42	local prefix_msg="$4"
43
44	local lerrors=0
45	local i=0
46	local rtype="TFAIL"
47
48	tst_res TINFO "test $prefix_msg link, limit: $limit"
49
50	cd "${prefix}link.$$"
51	while [ $i -lt $limit ]; do
52		if ! ln $ln_opts "$PWD/${prefix}file" ${prefix}file${i}; then
53			lerrors=$((lerrors + 1))
54		fi
55		i=$((i + 1))
56	done
57	cd ..
58
59	[ $lerrors -eq 0 ] && rtype="TPASS"
60
61	tst_res $rtype "errors: $lerrors"
62}
63
64do_test()
65{
66	mkdir hlink.$$ slink.$$
67	touch hlink.$$/hfile slink.$$/sfile
68
69	do_link "s" "-s" $soft_links "symbolic"
70	do_link "h"   "" $hard_links "hard"
71
72	rm -rf hlink.$$ slink.$$
73}
74
75tst_run
76