new common.punch file for exercising various hole punch functions,
[xfstests-dev.git] / 103
1 #! /bin/sh
2 # FS QA Test No. 103
3 #
4 # Exercise the XFS nosymlinks inode flag
5 #
6 #-----------------------------------------------------------------------
7 #  Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
8 #-----------------------------------------------------------------------
9 #
10 # creator
11 owner=nathans@sgi.com
12
13 seq=`basename $0`
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
20
21 # get standard environment, filters and checks
22 . ./common.rc
23 . ./common.filter
24
25 _create_scratch()
26 {
27         echo "*** mkfs"
28         if ! _scratch_mkfs_xfs >$tmp.out 2>&1
29         then
30                 cat $tmp.out
31                 echo "failed to mkfs $SCRATCH_DEV"
32                 exit 1
33         fi
34
35         echo "*** mount"
36         if ! _scratch_mount 2>/dev/null
37         then
38                 echo "failed to mount $SCRATCH_DEV"
39                 exit 1
40         fi
41 }
42
43 _filter_scratch()
44 {
45         sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
46 }
47
48 _filter_ln()
49 {
50     sed -e "s,SCRATCH_MNT/nosymlink/target - Operation not permitted,ln: creating symbolic link \`SCRATCH_MNT/nosymlink/target\' to \`SCRATCH_MNT/nosymlink/source\': Operation not permitted,g"
51 }
52
53 _filter_noymlinks_flag()
54 {
55         _test_inode_flag nosymlinks $SCRATCH_MNT/nosymlink
56         if [ $? -eq 0 ]; then
57                 echo "--n-- SCRATCH_MNT/nosymlink"
58         else
59                 echo "----- SCRATCH_MNT/nosymlink"
60         fi
61 }
62
63 # real QA test starts here
64 _supported_os Linux IRIX
65 _supported_fs xfs
66 _require_command /usr/sbin/xfs_io
67 _require_scratch
68
69 _create_scratch
70
71
72 echo "*** testing nosymlinks directories"
73 mkdir $SCRATCH_MNT/nosymlink
74 echo "*** setting nosymlinks bit"
75 $XFS_IO_PROG -r -c 'chattr +n' $SCRATCH_MNT/nosymlink
76 _filter_noymlinks_flag
77
78 touch $SCRATCH_MNT/nosymlink/source
79 ln -s $SCRATCH_MNT/nosymlink/source $SCRATCH_MNT/nosymlink/target 2>&1 \
80         | _filter_scratch | _filter_ln
81 ln $SCRATCH_MNT/nosymlink/source $SCRATCH_MNT/nosymlink/hardlinksareok
82
83 echo "*** 1st listing..."
84 find $SCRATCH_MNT | _filter_scratch
85
86 echo "*** clearing nosymlinks bit"
87 $XFS_IO_PROG -r -c 'chattr -n' $SCRATCH_MNT/nosymlink
88 _filter_noymlinks_flag
89
90 ln -s $SCRATCH_MNT/nosymlink/source $SCRATCH_MNT/nosymlink/target
91 ln $SCRATCH_MNT/nosymlink/source $SCRATCH_MNT/nosymlink/hardlinksareok2
92
93 echo "*** 2nd listing..."
94 find $SCRATCH_MNT | _filter_scratch
95
96 echo "*** finished testing nosymlinks directories"
97
98 status=0
99 exit