xfstests: change test case file mode to 0755
[xfstests-dev.git] / tests / generic / 306
1 #! /bin/bash
2 # FS QA Test No. 306
3 #
4 # Test RW open of a device on a RO fs
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35     umount $BINDFILE
36     cd /
37     rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45
46 # Modify as appropriate.
47 _supported_fs generic
48 _supported_os Linux
49 _require_scratch
50
51 DEVNULL=$SCRATCH_MNT/devnull
52 DEVZERO=$SCRATCH_MNT/devzero
53 SYMLINK=$SCRATCH_MNT/symlink
54 BINDFILE=$SCRATCH_MNT/bindfile
55 TARGET=$TEST_DIR/target
56
57 rm -f $seqres.full
58 _scratch_mkfs > $seqres.full 2>&1
59 _scratch_mount
60
61 rm -f $DEVNULL $DEVZERO
62
63 mknod $DEVNULL c 1 3 || _fail "Could not create devnull device"
64 mknod $DEVZERO c 1 5 || _fail "Could not create devzero device"
65 touch $BINDFILE || _fail "Could not create bind mount file"
66 touch $TARGET || _fail "Could not create symlink target"
67 ln -s $TARGET $SYMLINK
68
69 _scratch_unmount || _fail "Could not unmount scratch device"
70 _scratch_mount -o ro || _fail "Could not mount scratch readonly"
71
72 # We should be able to read & write to/from these devices even on an RO fs
73 echo "== try to create new file"
74 touch $SCRATCH_MNT/this_should_fail 2>&1 | _filter_scratch
75 echo "== pwrite to null device"
76 $XFS_IO_PROG -c "pwrite 0 512" $DEVNULL | _filter_xfs_io
77 echo "== pread from zero device"
78 $XFS_IO_PROG -c "pread 0 512" $DEVZERO | _filter_xfs_io
79
80 echo "== truncating write to null device"
81 echo foo > $DEVNULL 2>&1 | _filter_scratch
82 echo "== appending write to null device"
83 echo foo >> $DEVNULL 2>&1 | _filter_scratch
84
85 echo "== writing to symlink from ro fs to rw fs"
86 # Various combinations of O_CREAT & O_TRUNC
87 $XFS_IO_PROG -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
88 $XFS_IO_PROG -f -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
89 $XFS_IO_PROG -t -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
90
91 echo "== write to bind-mounted rw file on ro fs"
92 mount --bind $TARGET $BINDFILE
93 # with and without -f (adds O_CREAT)
94 $XFS_IO_PROG -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
95 $XFS_IO_PROG -f -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
96 $XFS_IO_PROG -t -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
97
98 # success, all done
99 status=0
100 exit