2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Red Hat, Inc. All Rights Reserved.
7 # Test RW open of a device on a RO fs
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
29 # real QA test starts here
31 # Modify as appropriate.
37 DEVNULL=$SCRATCH_MNT/devnull
38 DEVZERO=$SCRATCH_MNT/devzero
39 SYMLINK=$SCRATCH_MNT/symlink
40 BINDFILE=$SCRATCH_MNT/bindfile
41 TARGET=$TEST_DIR/target
44 _scratch_mkfs > $seqres.full 2>&1
47 rm -f $DEVNULL $DEVZERO
49 mknod $DEVNULL c 1 3 || _fail "Could not create devnull device"
50 mknod $DEVZERO c 1 5 || _fail "Could not create devzero device"
51 touch $BINDFILE || _fail "Could not create bind mount file"
52 touch $TARGET || _fail "Could not create symlink target"
53 ln -s $TARGET $SYMLINK
55 _scratch_remount ro || _fail "Could not remount scratch readonly"
57 # We should be able to read & write to/from these devices even on an RO fs
58 echo "== try to create new file"
59 touch $SCRATCH_MNT/this_should_fail 2>&1 | _filter_scratch
60 echo "== pwrite to null device"
61 $XFS_IO_PROG -c "pwrite 0 512" $DEVNULL | _filter_xfs_io
62 echo "== pread from zero device"
63 $XFS_IO_PROG -c "pread 0 512" $DEVZERO | _filter_xfs_io
65 echo "== truncating write to null device"
66 echo foo > $DEVNULL 2>&1 | _filter_scratch
67 echo "== appending write to null device"
68 echo foo >> $DEVNULL 2>&1 | _filter_scratch
70 echo "== writing to symlink from ro fs to rw fs"
71 # Various combinations of O_CREAT & O_TRUNC
72 $XFS_IO_PROG -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
73 $XFS_IO_PROG -f -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
74 $XFS_IO_PROG -t -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
76 echo "== write to bind-mounted rw file on ro fs"
77 mount --bind $TARGET $BINDFILE
78 # with and without -f (adds O_CREAT)
79 $XFS_IO_PROG -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
80 $XFS_IO_PROG -f -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
81 $XFS_IO_PROG -t -c "pwrite 0 512" $BINDFILE | _filter_xfs_io