it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
if (ll_sbi_has_encrypt(ll_i2sbi(dir)) && IS_ENCRYPTED(dir)) {
- /* we know that we are going to create a regular file because
+ /* in case of create, this is going to be a regular file because
* we set S_IFREG bit on it->it_create_mode above
*/
rc = llcrypt_get_encryption_info(dir);
if (rc)
GOTO(out_release, rc);
- if (!llcrypt_has_encryption_key(dir))
- GOTO(out_release, rc = -ENOKEY);
- encrypt = true;
- rc = 0;
+ if (open_flags & O_CREAT) {
+ if (!llcrypt_has_encryption_key(dir))
+ GOTO(out_release, rc = -ENOKEY);
+ encrypt = true;
+ }
}
OBD_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE2, cfs_fail_val);
cp $testfile $tmpfile
$RUNAS dd if=/dev/urandom of=$testfile2 bs=127 count=1 conv=fsync ||
error "write to encrypted file $testfile2 failed"
+ $RUNAS mkdir $testdir/subdir || error "mkdir subdir failed"
+ $RUNAS touch $testdir/subdir/subfile || error "mkdir subdir failed"
$RUNAS fscrypt lock --verbose $testdir ||
error "fscrypt lock $testdir failed (1)"
+ $RUNAS ls -R $testdir || error "ls -R $testdir failed"
+ local filecount=$($RUNAS find $testdir -type f | wc -l)
+ [ $filecount -eq 3 ] || error "found $filecount files"
+
$RUNAS hexdump -C $testfile &&
error "reading $testfile should have failed without key"
+ $RUNAS touch ${testfile}.nokey &&
+ error "touch ${testfile}.nokey should have failed without key"
+
echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
error "fscrypt unlock $testdir failed (1)"