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 void *ext4_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
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 if (!ext4_encrypted_inode(inode
))
39 return page_follow_link_light(dentry
, nd
);
41 ctx
= ext4_get_fname_crypto_ctx(inode
, inode
->i_sb
->s_blocksize
);
45 if (ext4_inode_is_fast_symlink(inode
)) {
46 caddr
= (char *) EXT4_I(inode
)->i_data
;
47 max_size
= sizeof(EXT4_I(inode
)->i_data
);
49 cpage
= read_mapping_page(inode
->i_mapping
, 0, NULL
);
51 ext4_put_fname_crypto_ctx(&ctx
);
58 /* Symlink is encrypted */
59 sd
= (struct ext4_encrypted_symlink_data
*)caddr
;
60 cstr
.name
= sd
->encrypted_path
;
61 cstr
.len
= le32_to_cpu(sd
->len
);
63 sizeof(struct ext4_encrypted_symlink_data
) - 1) >
65 /* Symlink data on the disk is corrupted */
69 plen
= (cstr
.len
< EXT4_FNAME_CRYPTO_DIGEST_SIZE
*2) ?
70 EXT4_FNAME_CRYPTO_DIGEST_SIZE
*2 : cstr
.len
;
71 paddr
= kmalloc(plen
+ 1, GFP_NOFS
);
77 res
= _ext4_fname_disk_to_usr(ctx
, NULL
, &cstr
, &pstr
);
80 /* Null-terminate the name */
83 nd_set_link(nd
, paddr
);
84 ext4_put_fname_crypto_ctx(&ctx
);
87 page_cache_release(cpage
);
91 ext4_put_fname_crypto_ctx(&ctx
);
94 page_cache_release(cpage
);
100 static void ext4_put_link(struct dentry
*dentry
, struct nameidata
*nd
,
103 struct page
*page
= cookie
;
106 kfree(nd_get_link(nd
));
109 page_cache_release(page
);
114 static void *ext4_follow_fast_link(struct dentry
*dentry
, struct nameidata
*nd
)
116 struct ext4_inode_info
*ei
= EXT4_I(d_inode(dentry
));
117 nd_set_link(nd
, (char *) ei
->i_data
);
121 const struct inode_operations ext4_symlink_inode_operations
= {
122 .readlink
= generic_readlink
,
123 #ifdef CONFIG_EXT4_FS_ENCRYPTION
124 .follow_link
= ext4_follow_link
,
125 .put_link
= ext4_put_link
,
127 .follow_link
= page_follow_link_light
,
128 .put_link
= page_put_link
,
130 .setattr
= ext4_setattr
,
131 .setxattr
= generic_setxattr
,
132 .getxattr
= generic_getxattr
,
133 .listxattr
= ext4_listxattr
,
134 .removexattr
= generic_removexattr
,
137 const struct inode_operations ext4_fast_symlink_inode_operations
= {
138 .readlink
= generic_readlink
,
139 .follow_link
= ext4_follow_fast_link
,
140 .setattr
= ext4_setattr
,
141 .setxattr
= generic_setxattr
,
142 .getxattr
= generic_getxattr
,
143 .listxattr
= ext4_listxattr
,
144 .removexattr
= generic_removexattr
,