1 // SPDX-License-Identifier: GPL-2.0
3 * linux/fs/ext4/symlink.c
5 * Only fast symlinks left here - the rest is done by generic code. AV, 1999
7 * Copyright (C) 1992, 1993, 1994, 1995
9 * Laboratoire MASI - Institut Blaise Pascal
10 * Universite Pierre et Marie Curie (Paris VI)
14 * linux/fs/minix/symlink.c
16 * Copyright (C) 1991, 1992 Linus Torvalds
18 * ext4 symlink handling code
22 #include <linux/namei.h>
26 static const char *ext4_encrypted_get_link(struct dentry *dentry,
28 struct delayed_call *done)
30 struct buffer_head *bh = NULL;
32 unsigned int max_size;
36 return ERR_PTR(-ECHILD);
38 if (ext4_inode_is_fast_symlink(inode)) {
39 caddr = EXT4_I(inode)->i_data;
40 max_size = sizeof(EXT4_I(inode)->i_data);
42 bh = ext4_bread(NULL, inode, 0, 0);
46 EXT4_ERROR_INODE(inode, "bad symlink.");
47 return ERR_PTR(-EFSCORRUPTED);
50 max_size = inode->i_sb->s_blocksize;
53 paddr = fscrypt_get_symlink(inode, caddr, max_size, done);
58 static int ext4_encrypted_symlink_getattr(struct user_namespace *mnt_userns,
59 const struct path *path,
60 struct kstat *stat, u32 request_mask,
61 unsigned int query_flags)
63 ext4_getattr(mnt_userns, path, stat, request_mask, query_flags);
65 return fscrypt_symlink_getattr(path, stat);
68 static void ext4_free_link(void *bh)
73 static const char *ext4_get_link(struct dentry *dentry, struct inode *inode,
74 struct delayed_call *callback)
76 struct buffer_head *bh;
79 bh = ext4_getblk(NULL, inode, 0, EXT4_GET_BLOCKS_CACHED_NOWAIT);
82 if (!bh || !ext4_buffer_uptodate(bh))
83 return ERR_PTR(-ECHILD);
85 bh = ext4_bread(NULL, inode, 0, 0);
89 EXT4_ERROR_INODE(inode, "bad symlink.");
90 return ERR_PTR(-EFSCORRUPTED);
94 set_delayed_call(callback, ext4_free_link, bh);
95 nd_terminate_link(bh->b_data, inode->i_size,
96 inode->i_sb->s_blocksize - 1);
100 const struct inode_operations ext4_encrypted_symlink_inode_operations = {
101 .get_link = ext4_encrypted_get_link,
102 .setattr = ext4_setattr,
103 .getattr = ext4_encrypted_symlink_getattr,
104 .listxattr = ext4_listxattr,
107 const struct inode_operations ext4_symlink_inode_operations = {
108 .get_link = ext4_get_link,
109 .setattr = ext4_setattr,
110 .getattr = ext4_getattr,
111 .listxattr = ext4_listxattr,
114 const struct inode_operations ext4_fast_symlink_inode_operations = {
115 .get_link = simple_get_link,
116 .setattr = ext4_setattr,
117 .getattr = ext4_getattr,
118 .listxattr = ext4_listxattr,