Merge tag 'vfio-v4.8-rc1' of git://github.com/awilliam/linux-vfio
[deliverable/linux.git] / fs / ext4 / symlink.c
CommitLineData
ac27a0ec 1/*
617ba13b 2 * linux/fs/ext4/symlink.c
ac27a0ec
DK
3 *
4 * Only fast symlinks left here - the rest is done by generic code. AV, 1999
5 *
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)
10 *
11 * from
12 *
13 * linux/fs/minix/symlink.c
14 *
15 * Copyright (C) 1991, 1992 Linus Torvalds
16 *
617ba13b 17 * ext4 symlink handling code
ac27a0ec
DK
18 */
19
20#include <linux/fs.h>
ac27a0ec 21#include <linux/namei.h>
3dcf5451 22#include "ext4.h"
ac27a0ec
DK
23#include "xattr.h"
24
6b255391 25static const char *ext4_encrypted_get_link(struct dentry *dentry,
fceef393
AV
26 struct inode *inode,
27 struct delayed_call *done)
f348c252
TT
28{
29 struct page *cpage = NULL;
30 char *caddr, *paddr = NULL;
a7550b30
JK
31 struct fscrypt_str cstr, pstr;
32 struct fscrypt_symlink_data *sd;
f348c252
TT
33 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
34 int res;
a7550b30 35 u32 max_size = inode->i_sb->s_blocksize;
f348c252 36
6b255391
AV
37 if (!dentry)
38 return ERR_PTR(-ECHILD);
39
a7550b30 40 res = fscrypt_get_encryption_info(inode);
b7236e21
TT
41 if (res)
42 return ERR_PTR(res);
f348c252
TT
43
44 if (ext4_inode_is_fast_symlink(inode)) {
9ec3a646
LT
45 caddr = (char *) EXT4_I(inode)->i_data;
46 max_size = sizeof(EXT4_I(inode)->i_data);
f348c252
TT
47 } else {
48 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
b7236e21 49 if (IS_ERR(cpage))
680baacb 50 return ERR_CAST(cpage);
21fc61c7 51 caddr = page_address(cpage);
f348c252
TT
52 caddr[size] = 0;
53 }
54
55 /* Symlink is encrypted */
a7550b30 56 sd = (struct fscrypt_symlink_data *)caddr;
f348c252 57 cstr.name = sd->encrypted_path;
5a1c7f47 58 cstr.len = le16_to_cpu(sd->len);
a7550b30 59 if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
f348c252 60 /* Symlink data on the disk is corrupted */
6a797d27 61 res = -EFSCORRUPTED;
f348c252
TT
62 goto errout;
63 }
a7550b30
JK
64
65 res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
66 if (res)
f348c252 67 goto errout;
a7550b30
JK
68
69 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
f348c252
TT
70 if (res < 0)
71 goto errout;
a7550b30
JK
72
73 paddr = pstr.name;
74
f348c252 75 /* Null-terminate the name */
a7550b30 76 if (res <= pstr.len)
f348c252 77 paddr[res] = '\0';
21fc61c7 78 if (cpage)
09cbfeaf 79 put_page(cpage);
fceef393
AV
80 set_delayed_call(done, kfree_link, paddr);
81 return paddr;
f348c252 82errout:
21fc61c7 83 if (cpage)
09cbfeaf 84 put_page(cpage);
f348c252
TT
85 kfree(paddr);
86 return ERR_PTR(res);
87}
88
a7a67e8a
AV
89const struct inode_operations ext4_encrypted_symlink_inode_operations = {
90 .readlink = generic_readlink,
6b255391 91 .get_link = ext4_encrypted_get_link,
a7a67e8a
AV
92 .setattr = ext4_setattr,
93 .setxattr = generic_setxattr,
94 .getxattr = generic_getxattr,
95 .listxattr = ext4_listxattr,
96 .removexattr = generic_removexattr,
97};
f348c252 98
754661f1 99const struct inode_operations ext4_symlink_inode_operations = {
ac27a0ec 100 .readlink = generic_readlink,
6b255391 101 .get_link = page_get_link,
256a4535 102 .setattr = ext4_setattr,
ac27a0ec
DK
103 .setxattr = generic_setxattr,
104 .getxattr = generic_getxattr,
617ba13b 105 .listxattr = ext4_listxattr,
ac27a0ec 106 .removexattr = generic_removexattr,
ac27a0ec
DK
107};
108
754661f1 109const struct inode_operations ext4_fast_symlink_inode_operations = {
ac27a0ec 110 .readlink = generic_readlink,
6b255391 111 .get_link = simple_get_link,
256a4535 112 .setattr = ext4_setattr,
ac27a0ec
DK
113 .setxattr = generic_setxattr,
114 .getxattr = generic_getxattr,
617ba13b 115 .listxattr = ext4_listxattr,
ac27a0ec 116 .removexattr = generic_removexattr,
ac27a0ec 117};
This page took 0.604623 seconds and 5 git commands to generate.