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 _begin_fstest auto quick rw
12 # Override the default cleanup function.
20 # Import common functions.
23 # real QA test starts here
25 # Modify as appropriate.
32 DEVNULL=$SCRATCH_MNT/devnull
33 DEVZERO=$SCRATCH_MNT/devzero
34 SYMLINK=$SCRATCH_MNT/symlink
35 BINDFILE=$SCRATCH_MNT/bindfile
36 TARGET=$TEST_DIR/target
38 _scratch_mkfs > $seqres.full 2>&1
41 rm -f $DEVNULL $DEVZERO
43 mknod $DEVNULL c 1 3 || _fail "Could not create devnull device"
44 mknod $DEVZERO c 1 5 || _fail "Could not create devzero device"
45 touch $BINDFILE || _fail "Could not create bind mount file"
46 touch $TARGET || _fail "Could not create symlink target"
47 ln -s $TARGET $SYMLINK
49 _scratch_remount ro || _fail "Could not remount scratch readonly"
51 # We should be able to read & write to/from these devices even on an RO fs
52 echo "== try to create new file"
53 touch $SCRATCH_MNT/this_should_fail 2>&1 | _filter_scratch
54 echo "== pwrite to null device"
55 $XFS_IO_PROG -c "pwrite 0 512" $DEVNULL | _filter_xfs_io
56 echo "== pread from zero device"
57 $XFS_IO_PROG -c "pread 0 512" $DEVZERO | _filter_xfs_io
59 echo "== truncating write to null device"
60 echo foo > $DEVNULL 2>&1 | _filter_scratch
61 echo "== appending write to null device"
62 echo foo >> $DEVNULL 2>&1 | _filter_scratch
64 echo "== writing to symlink from ro fs to rw fs"
65 # Various combinations of O_CREAT & O_TRUNC
66 $XFS_IO_PROG -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
67 $XFS_IO_PROG -f -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
68 $XFS_IO_PROG -t -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
70 echo "== write to bind-mounted rw file on ro fs"
71 mount --bind $TARGET $BINDFILE
72 # with and without -f (adds O_CREAT)
73 $XFS_IO_PROG -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
74 $XFS_IO_PROG -f -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
75 $XFS_IO_PROG -t -c "pwrite 0 512" $BINDFILE | _filter_xfs_io