2 * linux/fs/ext4/symlink.c
4 * Only fast symlinks left here - the rest is done by generic code. AV, 1999
6 * Copyright (C) 1992, 1993, 1994, 1995
7 * Remy Card (card@masi.ibp.fr)
8 * Laboratoire MASI - Institut Blaise Pascal
9 * Universite Pierre et Marie Curie (Paris VI)
13 * linux/fs/minix/symlink.c
15 * Copyright (C) 1991, 1992 Linus Torvalds
17 * ext4 symlink handling code
21 #include <linux/namei.h>
25 #ifdef CONFIG_EXT4_FS_ENCRYPTION
26 static const char *ext4_follow_link(struct dentry *dentry, void **cookie)
28 struct page *cpage = NULL;
29 char *caddr, *paddr = NULL;
30 struct ext4_str cstr, pstr;
31 struct inode *inode = d_inode(dentry);
32 struct ext4_fname_crypto_ctx *ctx = NULL;
33 struct ext4_encrypted_symlink_data *sd;
34 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
36 u32 plen, max_size = inode->i_sb->s_blocksize;
38 ctx = ext4_get_fname_crypto_ctx(inode, inode->i_sb->s_blocksize);
42 if (ext4_inode_is_fast_symlink(inode)) {
43 caddr = (char *) EXT4_I(inode)->i_data;
44 max_size = sizeof(EXT4_I(inode)->i_data);
46 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
48 ext4_put_fname_crypto_ctx(&ctx);
49 return ERR_CAST(cpage);
55 /* Symlink is encrypted */
56 sd = (struct ext4_encrypted_symlink_data *)caddr;
57 cstr.name = sd->encrypted_path;
58 cstr.len = le32_to_cpu(sd->len);
60 sizeof(struct ext4_encrypted_symlink_data) - 1) >
62 /* Symlink data on the disk is corrupted */
66 plen = (cstr.len < EXT4_FNAME_CRYPTO_DIGEST_SIZE*2) ?
67 EXT4_FNAME_CRYPTO_DIGEST_SIZE*2 : cstr.len;
68 paddr = kmalloc(plen + 1, GFP_NOFS);
74 res = _ext4_fname_disk_to_usr(ctx, NULL, &cstr, &pstr);
77 /* Null-terminate the name */
80 ext4_put_fname_crypto_ctx(&ctx);
83 page_cache_release(cpage);
85 return *cookie = paddr;
87 ext4_put_fname_crypto_ctx(&ctx);
90 page_cache_release(cpage);
96 const struct inode_operations ext4_encrypted_symlink_inode_operations = {
97 .readlink = generic_readlink,
98 .follow_link = ext4_follow_link,
99 .put_link = kfree_put_link,
100 .setattr = ext4_setattr,
101 .setxattr = generic_setxattr,
102 .getxattr = generic_getxattr,
103 .listxattr = ext4_listxattr,
104 .removexattr = generic_removexattr,
108 const struct inode_operations ext4_symlink_inode_operations = {
109 .readlink = generic_readlink,
110 .follow_link = page_follow_link_light,
111 .put_link = page_put_link,
112 .setattr = ext4_setattr,
113 .setxattr = generic_setxattr,
114 .getxattr = generic_getxattr,
115 .listxattr = ext4_listxattr,
116 .removexattr = generic_removexattr,
119 const struct inode_operations ext4_fast_symlink_inode_operations = {
120 .readlink = generic_readlink,
121 .follow_link = simple_follow_link,
122 .setattr = ext4_setattr,
123 .setxattr = generic_setxattr,
124 .getxattr = generic_getxattr,
125 .listxattr = ext4_listxattr,
126 .removexattr = generic_removexattr,