fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 485
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 485
6 #
7 # Regression test for:
8 #    349fa7d6e193 ("ext4: prevent right-shifting extents beyond EXT_MAX_BLOCKS")
9 #    7d83fb14258b ("xfs: prevent creating negative-sized file via INSERT_RANGE")
10 #
11 . ./common/preamble
12 _begin_fstest auto quick insert
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         cd /
18         rm -f $testfile
19 }
20
21 # Import common functions.
22 . ./common/filter
23
24 # real QA test starts here
25 _supported_fs generic
26 _require_test
27 _require_math
28 _require_xfs_io_command "falloc" "-k"
29 _require_xfs_io_command "finsert"
30 _require_xfs_io_command "truncate"
31
32 block_size=$(_get_file_block_size $TEST_DIR)
33 max_file_size=$(_get_max_file_size)
34 max_blocks=$((max_file_size / block_size))
35 testfile=$TEST_DIR/testfile.$seq
36
37 echo "# With KEEP_SIZE"
38 rm -f "$testfile"
39
40 # Add an extent at the beginning of the file.  With ext4, this is needed to
41 # reproduce the bug where the extents appear out of order later.
42 $XFS_IO_PROG -f -c "falloc 0 $((2 * block_size))" "$testfile"
43
44 # Add an extent just below s_maxbytes, without changing i_size (i.e. with -k).
45 # The out-of-order extents bug can't be reproduced if i_size is changed, because
46 # then the range insertion fails due to the new i_size being > s_maxbytes.
47 $XFS_IO_PROG -c "falloc -k $(( (max_blocks - 1) * $block_size )) $block_size" \
48         "$testfile"
49
50 # Insert an extent at the beginning of the file.  With the ext4 bug, this caused
51 # the logical block number of the extent just below s_maxbytes to wrap around,
52 # causing the extents to get out of order, causing corruption detected by
53 # e2fsck.  With the fix, the range insertion fails with EINVAL.  Though, with
54 # xfs and f2fs the insertion succeeds, resulting in extents beyond s_maxbytes,
55 # but there is no wraparound -- which is arguably okay.  So we allow either
56 # behavior and just rely on fsck detecting if something went wrong.
57 $XFS_IO_PROG -c "finsert 0 $((2 * block_size))" "$testfile" &>>$seqres.full
58
59 # Also do the same test, but with changing i_size (i.e. without -k).  The
60 # insertion should fail with EFBIG.  This exposed an XFS bug where i_size + len
61 # underwent signed overflow, resulting in a negative-sized file.
62 echo "# Without KEEP_SIZE"
63 rm -f "$testfile"
64 $XFS_IO_PROG -f -c "falloc 0 $((2 * block_size))" "$testfile"
65 $XFS_IO_PROG -c "falloc $(( (max_blocks - 1) * $block_size )) $block_size" \
66         "$testfile"
67 $XFS_IO_PROG -c "finsert 0 $((2 * block_size))" "$testfile"
68
69 status=0
70 exit