f2fs: switch to fscrypt ->symlink() helper functions
Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
Родитель
6a9269c838
Коммит
393c038f5c
|
@ -496,28 +496,17 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
||||||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
size_t len = strlen(symname);
|
size_t len = strlen(symname);
|
||||||
struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1);
|
struct fscrypt_str disk_link;
|
||||||
struct fscrypt_symlink_data *sd = NULL;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (unlikely(f2fs_cp_error(sbi)))
|
if (unlikely(f2fs_cp_error(sbi)))
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
if (f2fs_encrypted_inode(dir)) {
|
err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
|
||||||
err = fscrypt_get_encryption_info(dir);
|
&disk_link);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (!fscrypt_has_encryption_key(dir))
|
|
||||||
return -ENOKEY;
|
|
||||||
|
|
||||||
disk_link.len = (fscrypt_fname_encrypted_size(dir, len) +
|
|
||||||
sizeof(struct fscrypt_symlink_data));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (disk_link.len > dir->i_sb->s_blocksize)
|
|
||||||
return -ENAMETOOLONG;
|
|
||||||
|
|
||||||
err = dquot_initialize(dir);
|
err = dquot_initialize(dir);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -526,7 +515,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
||||||
if (IS_ERR(inode))
|
if (IS_ERR(inode))
|
||||||
return PTR_ERR(inode);
|
return PTR_ERR(inode);
|
||||||
|
|
||||||
if (f2fs_encrypted_inode(inode))
|
if (IS_ENCRYPTED(inode))
|
||||||
inode->i_op = &f2fs_encrypted_symlink_inode_operations;
|
inode->i_op = &f2fs_encrypted_symlink_inode_operations;
|
||||||
else
|
else
|
||||||
inode->i_op = &f2fs_symlink_inode_operations;
|
inode->i_op = &f2fs_symlink_inode_operations;
|
||||||
|
@ -536,39 +525,14 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
||||||
f2fs_lock_op(sbi);
|
f2fs_lock_op(sbi);
|
||||||
err = f2fs_add_link(dentry, inode);
|
err = f2fs_add_link(dentry, inode);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out_handle_failed_inode;
|
||||||
f2fs_unlock_op(sbi);
|
f2fs_unlock_op(sbi);
|
||||||
alloc_nid_done(sbi, inode->i_ino);
|
alloc_nid_done(sbi, inode->i_ino);
|
||||||
|
|
||||||
if (f2fs_encrypted_inode(inode)) {
|
err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link);
|
||||||
struct qstr istr = QSTR_INIT(symname, len);
|
|
||||||
struct fscrypt_str ostr;
|
|
||||||
|
|
||||||
sd = kzalloc(disk_link.len, GFP_NOFS);
|
|
||||||
if (!sd) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = fscrypt_get_encryption_info(inode);
|
|
||||||
if (err)
|
if (err)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
|
||||||
if (!fscrypt_has_encryption_key(inode)) {
|
|
||||||
err = -ENOKEY;
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ostr.name = sd->encrypted_path;
|
|
||||||
ostr.len = disk_link.len;
|
|
||||||
err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
|
|
||||||
if (err)
|
|
||||||
goto err_out;
|
|
||||||
|
|
||||||
sd->len = cpu_to_le16(ostr.len);
|
|
||||||
disk_link.name = (char *)sd;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = page_symlink(inode, disk_link.name, disk_link.len);
|
err = page_symlink(inode, disk_link.name, disk_link.len);
|
||||||
|
|
||||||
err_out:
|
err_out:
|
||||||
|
@ -594,12 +558,14 @@ err_out:
|
||||||
f2fs_unlink(dir, dentry);
|
f2fs_unlink(dir, dentry);
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(sd);
|
|
||||||
|
|
||||||
f2fs_balance_fs(sbi, true);
|
f2fs_balance_fs(sbi, true);
|
||||||
return err;
|
goto out_free_encrypted_link;
|
||||||
out:
|
|
||||||
|
out_handle_failed_inode:
|
||||||
handle_failed_inode(inode);
|
handle_failed_inode(inode);
|
||||||
|
out_free_encrypted_link:
|
||||||
|
if (disk_link.name != (unsigned char *)symname)
|
||||||
|
kfree(disk_link.name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче