vfs: Remove {get,set,remove}xattr inode operations
[cascardo/linux.git] / fs / ext4 / symlink.c
1 /*
2  *  linux/fs/ext4/symlink.c
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  *
17  *  ext4 symlink handling code
18  */
19
20 #include <linux/fs.h>
21 #include <linux/namei.h>
22 #include "ext4.h"
23 #include "xattr.h"
24
25 static const char *ext4_encrypted_get_link(struct dentry *dentry,
26                                            struct inode *inode,
27                                            struct delayed_call *done)
28 {
29         struct page *cpage = NULL;
30         char *caddr, *paddr = NULL;
31         struct fscrypt_str cstr, pstr;
32         struct fscrypt_symlink_data *sd;
33         loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
34         int res;
35         u32 max_size = inode->i_sb->s_blocksize;
36
37         if (!dentry)
38                 return ERR_PTR(-ECHILD);
39
40         res = fscrypt_get_encryption_info(inode);
41         if (res)
42                 return ERR_PTR(res);
43
44         if (ext4_inode_is_fast_symlink(inode)) {
45                 caddr = (char *) EXT4_I(inode)->i_data;
46                 max_size = sizeof(EXT4_I(inode)->i_data);
47         } else {
48                 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
49                 if (IS_ERR(cpage))
50                         return ERR_CAST(cpage);
51                 caddr = page_address(cpage);
52                 caddr[size] = 0;
53         }
54
55         /* Symlink is encrypted */
56         sd = (struct fscrypt_symlink_data *)caddr;
57         cstr.name = sd->encrypted_path;
58         cstr.len  = le16_to_cpu(sd->len);
59         if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
60                 /* Symlink data on the disk is corrupted */
61                 res = -EFSCORRUPTED;
62                 goto errout;
63         }
64
65         res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
66         if (res)
67                 goto errout;
68
69         res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
70         if (res < 0)
71                 goto errout;
72
73         paddr = pstr.name;
74
75         /* Null-terminate the name */
76         if (res <= pstr.len)
77                 paddr[res] = '\0';
78         if (cpage)
79                 put_page(cpage);
80         set_delayed_call(done, kfree_link, paddr);
81         return paddr;
82 errout:
83         if (cpage)
84                 put_page(cpage);
85         kfree(paddr);
86         return ERR_PTR(res);
87 }
88
89 const struct inode_operations ext4_encrypted_symlink_inode_operations = {
90         .readlink       = generic_readlink,
91         .get_link       = ext4_encrypted_get_link,
92         .setattr        = ext4_setattr,
93         .listxattr      = ext4_listxattr,
94 };
95
96 const struct inode_operations ext4_symlink_inode_operations = {
97         .readlink       = generic_readlink,
98         .get_link       = page_get_link,
99         .setattr        = ext4_setattr,
100         .listxattr      = ext4_listxattr,
101 };
102
103 const struct inode_operations ext4_fast_symlink_inode_operations = {
104         .readlink       = generic_readlink,
105         .get_link       = simple_get_link,
106         .setattr        = ext4_setattr,
107         .listxattr      = ext4_listxattr,
108 };