2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc. All Rights Reserved.
7 # Regression test for 0d06863f903a ("ext4: don't BUG when truncating encrypted
8 # inodes on the orphan list").
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment and checks
29 # remove previous $seqres.full before test
32 # real QA test starts here
34 _require_scratch_encryption
35 _require_command "$KEYCTL_PROG" keyctl
40 # Create an encrypted file whose size is not a multiple of the filesystem block
41 # size, then add it to the orphan list.
43 # We create the encrypted file normally, rather than use debugfs to force the
44 # inode flags to ENCRYPT|EXTENTS as done in the example listed in the commit
45 # message of the kernel fix, because forcing the inode flags is incompatible
46 # with some MKFS_OPTIONS such as inline_data or ^extents.
48 # This choice does, however, have the disadvantage that this test won't detect
49 # the bug in as many situations, such as in kernels configured without
52 _scratch_mkfs_encrypted &>>$seqres.full
54 mkdir $SCRATCH_MNT/edir
55 keydesc=$(_generate_session_encryption_key)
56 _set_encpolicy $SCRATCH_MNT/edir $keydesc
57 echo foo > $SCRATCH_MNT/edir/file
58 inum=$(stat -c '%i' $SCRATCH_MNT/edir/file)
60 debugfs -w -R "set_super_value s_last_orphan $inum" $SCRATCH_DEV &>>$seqres.full
62 # Try to mount the filesystem. This would hit a BUG() in fs/ext4/inode.c.