2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook. All Rights Reserved.
7 # Test invalid swap files.
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
24 # get standard environment, filters and checks
28 # remove previous $seqres.full before test
32 _require_scratch_swapfile
33 _require_test_program mkswap
34 _require_test_program swapon
36 _scratch_mkfs >> $seqres.full 2>&1
39 echo "File with holes"
40 # We can't use _format_swapfile because we're using our custom mkswap and
42 touch "$SCRATCH_MNT/swap"
43 $CHATTR_PROG +C "$SCRATCH_MNT/swap" >> $seqres.full 2>&1
44 chmod 0600 "$SCRATCH_MNT/swap"
45 $XFS_IO_PROG -c "truncate $(($(get_page_size) * 10))" "$SCRATCH_MNT/swap"
46 "$here/src/mkswap" "$SCRATCH_MNT/swap"
47 "$here/src/swapon" "$SCRATCH_MNT/swap"
48 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
50 echo "Empty swap file (only swap header)"
51 rm -f "$SCRATCH_MNT/swap"
52 touch "$SCRATCH_MNT/swap"
53 $CHATTR_PROG +C "$SCRATCH_MNT/swap" >> $seqres.full 2>&1
54 chmod 0600 "$SCRATCH_MNT/swap"
55 _pwrite_byte 0x61 0 $(get_page_size) "$SCRATCH_MNT/swap" >> $seqres.full
56 "$here/src/mkswap" "$SCRATCH_MNT/swap"
57 "$here/src/swapon" "$SCRATCH_MNT/swap"
58 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1