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# linktest.sh <number of symlinks> <number of hardlinks> 7# Author: Ngie Cooper <yaneurabeya@gmail.com> 8 9TST_NEEDS_TMPDIR=1 10TST_POS_ARGS=2 11TST_TESTFUNC=do_test 12 13. tst_test.sh 14 15if [ $# -ne 2 ]; then 16 tst_res TBROK "usage: $0 {softlink count} {hardlink count}" 17 exit 1 18fi 19 20validate_parameter() 21{ 22 if ! tst_is_int "$2"; then 23 tst_brk TBROK "$1 must be integer" 24 fi 25 26 if [ "$2" -lt 0 ]; then 27 tst_brk TBROK "$1 must be >= 0" 28 fi 29} 30 31validate_parameter "softlink count" $1 32validate_parameter "hardlink count" $2 33 34soft_links=$1 35hard_links=$2 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 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 if [ $lerrors -eq 0 ]; then 58 rtype=TPASS 59 fi 60 61 tst_res $rtype "$prefix_msg link 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