xref: /aosp_15_r20/external/ltp/testcases/kernel/fs/linktest/linktest.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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 <[email protected]>
7
8TST_NEEDS_TMPDIR=1
9TST_TESTFUNC=do_test
10TST_OPTS="a:s:"
11TST_PARSE_ARGS=parse_args
12TST_USAGE=usage
13
14hard_links=1000
15soft_links=1000
16
17usage()
18{
19	echo "Usage: linktest.sh {-a n} {-s n}"
20	echo "-a n    Hard link count"
21	echo "-s n    Soft link count"
22}
23
24parse_args()
25{
26	tst_is_int "$2" || tst_brk TBROK "-$1 must be integer ($2)"
27	[ "$2" -ge 0 ] || tst_brk TBROK "-$1 must be >= 0 ($2)"
28
29	case $1 in
30	a) hard_links=$2;;
31	s) soft_links=$2;;
32	esac
33}
34
35do_link()
36{
37	local prefix="$1"
38	local ln_opts="$2"
39	local limit="$3"
40	local prefix_msg="$4"
41
42	local lerrors=0
43	local i=0
44	local rtype="TFAIL"
45
46	tst_res TINFO "test $prefix_msg link, limit: $limit"
47
48	cd "${prefix}link.$$"
49	while [ $i -lt $limit ]; do
50		if ! ln $ln_opts "$PWD/${prefix}file" ${prefix}file${i}; then
51			lerrors=$((lerrors + 1))
52		fi
53		i=$((i + 1))
54	done
55	cd ..
56
57	[ $lerrors -eq 0 ] && rtype="TPASS"
58
59	tst_res $rtype "errors: $lerrors"
60}
61
62do_test()
63{
64	mkdir hlink.$$ slink.$$
65	touch hlink.$$/hfile slink.$$/sfile
66
67	do_link "s" "-s" $soft_links "symbolic"
68	do_link "h"   "" $hard_links "hard"
69
70	rm -rf hlink.$$ slink.$$
71}
72
73. tst_test.sh
74tst_run
75