5 # 349fa7d6e193 ("ext4: prevent right-shifting extents beyond EXT_MAX_BLOCKS")
6 # 7d83fb14258b ("xfs: prevent creating negative-sized file via INSERT_RANGE")
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2018 Google, Inc. All Rights Reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
29 status=1 # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
42 # remove previous $seqres.full before test
45 # real QA test starts here
50 _require_xfs_io_command "falloc" "-k"
51 _require_xfs_io_command "finsert"
52 _require_xfs_io_command "truncate"
54 # Get the maximum size of a file in $TEST_DIR (s_maxbytes). On ext4 this will
55 # be UINT32_MAX * block_size, but other filesystems may allow up to LLONG_MAX.
58 local testfile=$TEST_DIR/maxfilesize.$seq
60 local r=9223372036854775807 # LLONG_MAX
64 # Use _math() to avoid signed integer overflow.
65 local m=$(_math "($l + $r + 1) / 2")
66 if $XFS_IO_PROG -f -c "truncate $m" $testfile \
67 |& grep -q 'File too large'
77 block_size=$(_get_file_block_size $TEST_DIR)
78 max_file_size=$(get_max_file_size)
79 max_blocks=$((max_file_size / block_size))
80 testfile=$TEST_DIR/testfile.$seq
82 echo "# With KEEP_SIZE"
85 # Add an extent at the beginning of the file. With ext4, this is needed to
86 # reproduce the bug where the extents appear out of order later.
87 $XFS_IO_PROG -f -c "falloc 0 $((2 * block_size))" "$testfile"
89 # Add an extent just below s_maxbytes, without changing i_size (i.e. with -k).
90 # The out-of-order extents bug can't be reproduced if i_size is changed, because
91 # then the range insertion fails due to the new i_size being > s_maxbytes.
92 $XFS_IO_PROG -c "falloc -k $(( (max_blocks - 1) * $block_size )) $block_size" \
95 # Insert an extent at the beginning of the file. With the ext4 bug, this caused
96 # the logical block number of the extent just below s_maxbytes to wrap around,
97 # causing the extents to get out of order, causing corruption detected by
98 # e2fsck. With the fix, the range insertion fails with EINVAL. Though, with
99 # xfs and f2fs the insertion succeeds, resulting in extents beyond s_maxbytes,
100 # but there is no wraparound -- which is arguably okay. So we allow either
101 # behavior and just rely on fsck detecting if something went wrong.
102 $XFS_IO_PROG -c "finsert 0 $((2 * block_size))" "$testfile" &>>$seqres.full
104 # Also do the same test, but with changing i_size (i.e. without -k). The
105 # insertion should fail with EFBIG. This exposed an XFS bug where i_size + len
106 # underwent signed overflow, resulting in a negative-sized file.
107 echo "# Without KEEP_SIZE"
109 $XFS_IO_PROG -f -c "falloc 0 $((2 * block_size))" "$testfile"
110 $XFS_IO_PROG -c "falloc $(( (max_blocks - 1) * $block_size )) $block_size" \
112 $XFS_IO_PROG -c "finsert 0 $((2 * block_size))" "$testfile"