]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/ext4/symlink.c
x86/cpufeatures: Disentangle MSR_SPEC_CTRL enumeration from IBRS
[mirror_ubuntu-artful-kernel.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 33 int res;
a7550b30 34 u32 max_size = inode->i_sb->s_blocksize;
f348c252 35
6b255391
AV
36 if (!dentry)
37 return ERR_PTR(-ECHILD);
38
a7550b30 39 res = fscrypt_get_encryption_info(inode);
b7236e21
TT
40 if (res)
41 return ERR_PTR(res);
f348c252
TT
42
43 if (ext4_inode_is_fast_symlink(inode)) {
9ec3a646
LT
44 caddr = (char *) EXT4_I(inode)->i_data;
45 max_size = sizeof(EXT4_I(inode)->i_data);
f348c252
TT
46 } else {
47 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
b7236e21 48 if (IS_ERR(cpage))
680baacb 49 return ERR_CAST(cpage);
21fc61c7 50 caddr = page_address(cpage);
f348c252
TT
51 }
52
53 /* Symlink is encrypted */
a7550b30 54 sd = (struct fscrypt_symlink_data *)caddr;
f348c252 55 cstr.name = sd->encrypted_path;
5a1c7f47 56 cstr.len = le16_to_cpu(sd->len);
a7550b30 57 if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
f348c252 58 /* Symlink data on the disk is corrupted */
6a797d27 59 res = -EFSCORRUPTED;
f348c252
TT
60 goto errout;
61 }
a7550b30
JK
62
63 res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
64 if (res)
f348c252 65 goto errout;
dcce7a46 66 paddr = pstr.name;
a7550b30
JK
67
68 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
ef1eb3aa 69 if (res)
f348c252 70 goto errout;
a7550b30 71
f348c252 72 /* Null-terminate the name */
ef1eb3aa 73 paddr[pstr.len] = '\0';
21fc61c7 74 if (cpage)
09cbfeaf 75 put_page(cpage);
fceef393
AV
76 set_delayed_call(done, kfree_link, paddr);
77 return paddr;
f348c252 78errout:
21fc61c7 79 if (cpage)
09cbfeaf 80 put_page(cpage);
f348c252
TT
81 kfree(paddr);
82 return ERR_PTR(res);
83}
84
a7a67e8a 85const struct inode_operations ext4_encrypted_symlink_inode_operations = {
6b255391 86 .get_link = ext4_encrypted_get_link,
a7a67e8a 87 .setattr = ext4_setattr,
99652ea5 88 .getattr = ext4_getattr,
a7a67e8a 89 .listxattr = ext4_listxattr,
a7a67e8a 90};
f348c252 91
754661f1 92const struct inode_operations ext4_symlink_inode_operations = {
6b255391 93 .get_link = page_get_link,
256a4535 94 .setattr = ext4_setattr,
99652ea5 95 .getattr = ext4_getattr,
617ba13b 96 .listxattr = ext4_listxattr,
ac27a0ec
DK
97};
98
754661f1 99const struct inode_operations ext4_fast_symlink_inode_operations = {
6b255391 100 .get_link = simple_get_link,
256a4535 101 .setattr = ext4_setattr,
99652ea5 102 .getattr = ext4_getattr,
617ba13b 103 .listxattr = ext4_listxattr,
ac27a0ec 104};