fstests: add _require_hardlinks for all necessary tests
[xfstests-dev.git] / tests / generic / 002
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 002
6 #
7 # simple inode link count test for a regular file
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 # get standard environment, filters and checks
14 . ./common/rc
15 . ./common/filter
16
17 tmp=/tmp/$$
18 here=`pwd`
19 status=0        # success is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24     rm -f $tmp.*
25 }
26
27 # real QA test starts here
28 _supported_fs generic
29 _supported_os Linux
30 _require_test
31 _require_hardlinks
32
33 rm -f $seqres.full
34
35 echo "Silence is goodness ..."
36
37 # ensure target directory exists
38 mkdir `dirname $TEST_DIR/$tmp` 2>/dev/null
39
40 touch $TEST_DIR/$tmp.1
41 for l in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
42 do
43     ln $TEST_DIR/$tmp.1 $TEST_DIR/$tmp.$l
44     x=`$here/src/lstat64 $TEST_DIR/$tmp.1 | sed -n -e '/ Links: /s/.*Links: *//p'`
45     if [ "$l" -ne $x ]
46     then
47         echo "Arrgh, created link #$l and lstat64 looks like ..."
48         $here/src/lstat64 $TEST_DIR/$tmp.1
49         status=1
50     fi
51 done
52
53 for l in 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
54 do
55     x=`$here/src/lstat64 $TEST_DIR/$tmp.1 | sed -n -e '/ Links: /s/.*Links: *//p'`
56     if [ "$l" -ne $x ]
57     then
58         echo "Arrgh, about to remove link #$l and lstat64 looks like ..."
59         $here/src/lstat64 $TEST_DIR/$tmp.1
60         status=1
61     fi
62     rm -f $TEST_DIR/$tmp.$l
63 done
64
65 # success, all done
66 exit