Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 1 | /** |
| 2 | * eCryptfs: Linux filesystem encryption layer |
| 3 | * |
| 4 | * Copyright (C) 1997-2004 Erez Zadok |
| 5 | * Copyright (C) 2001-2004 Stony Brook University |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 6 | * Copyright (C) 2004-2007 International Business Machines Corp. |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 7 | * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com> |
| 8 | * Michael C. Thompsion <mcthomps@us.ibm.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of the |
| 13 | * License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 23 | * 02111-1307, USA. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/file.h> |
| 27 | #include <linux/vmalloc.h> |
| 28 | #include <linux/pagemap.h> |
| 29 | #include <linux/dcache.h> |
| 30 | #include <linux/namei.h> |
| 31 | #include <linux/mount.h> |
| 32 | #include <linux/crypto.h> |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 33 | #include <linux/fs_stack.h> |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 34 | #include "ecryptfs_kernel.h" |
| 35 | |
| 36 | static struct dentry *lock_parent(struct dentry *dentry) |
| 37 | { |
| 38 | struct dentry *dir; |
| 39 | |
| 40 | dir = dget(dentry->d_parent); |
Peter Zijlstra | 908e0a8 | 2007-03-07 20:41:30 -0800 | [diff] [blame] | 41 | mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 42 | return dir; |
| 43 | } |
| 44 | |
| 45 | static void unlock_parent(struct dentry *dentry) |
| 46 | { |
| 47 | mutex_unlock(&(dentry->d_parent->d_inode->i_mutex)); |
| 48 | dput(dentry->d_parent); |
| 49 | } |
| 50 | |
| 51 | static void unlock_dir(struct dentry *dir) |
| 52 | { |
| 53 | mutex_unlock(&dir->d_inode->i_mutex); |
| 54 | dput(dir); |
| 55 | } |
| 56 | |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 57 | /** |
| 58 | * ecryptfs_create_underlying_file |
| 59 | * @lower_dir_inode: inode of the parent in the lower fs of the new file |
| 60 | * @lower_dentry: New file's dentry in the lower fs |
| 61 | * @ecryptfs_dentry: New file's dentry in ecryptfs |
| 62 | * @mode: The mode of the new file |
| 63 | * @nd: nameidata of ecryptfs' parent's dentry & vfsmount |
| 64 | * |
| 65 | * Creates the file in the lower file system. |
| 66 | * |
| 67 | * Returns zero on success; non-zero on error condition |
| 68 | */ |
| 69 | static int |
| 70 | ecryptfs_create_underlying_file(struct inode *lower_dir_inode, |
| 71 | struct dentry *dentry, int mode, |
| 72 | struct nameidata *nd) |
| 73 | { |
| 74 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 75 | struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); |
| 76 | struct dentry *dentry_save; |
| 77 | struct vfsmount *vfsmount_save; |
| 78 | int rc; |
| 79 | |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 80 | dentry_save = nd->path.dentry; |
| 81 | vfsmount_save = nd->path.mnt; |
| 82 | nd->path.dentry = lower_dentry; |
| 83 | nd->path.mnt = lower_mnt; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 84 | rc = vfs_create(lower_dir_inode, lower_dentry, mode, nd); |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 85 | nd->path.dentry = dentry_save; |
| 86 | nd->path.mnt = vfsmount_save; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 87 | return rc; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * ecryptfs_do_create |
| 92 | * @directory_inode: inode of the new file's dentry's parent in ecryptfs |
| 93 | * @ecryptfs_dentry: New file's dentry in ecryptfs |
| 94 | * @mode: The mode of the new file |
| 95 | * @nd: nameidata of ecryptfs' parent's dentry & vfsmount |
| 96 | * |
| 97 | * Creates the underlying file and the eCryptfs inode which will link to |
| 98 | * it. It will also update the eCryptfs directory inode to mimic the |
| 99 | * stat of the lower directory inode. |
| 100 | * |
| 101 | * Returns zero on success; non-zero on error condition |
| 102 | */ |
| 103 | static int |
| 104 | ecryptfs_do_create(struct inode *directory_inode, |
| 105 | struct dentry *ecryptfs_dentry, int mode, |
| 106 | struct nameidata *nd) |
| 107 | { |
| 108 | int rc; |
| 109 | struct dentry *lower_dentry; |
| 110 | struct dentry *lower_dir_dentry; |
| 111 | |
| 112 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); |
| 113 | lower_dir_dentry = lock_parent(lower_dentry); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame^] | 114 | if (IS_ERR(lower_dir_dentry)) { |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 115 | ecryptfs_printk(KERN_ERR, "Error locking directory of " |
| 116 | "dentry\n"); |
| 117 | rc = PTR_ERR(lower_dir_dentry); |
| 118 | goto out; |
| 119 | } |
| 120 | rc = ecryptfs_create_underlying_file(lower_dir_dentry->d_inode, |
| 121 | ecryptfs_dentry, mode, nd); |
Michael Halcrow | 4981e08 | 2007-10-16 01:28:09 -0700 | [diff] [blame] | 122 | if (rc) { |
Michael Halcrow | caeeeec | 2008-01-08 15:33:02 -0800 | [diff] [blame] | 123 | printk(KERN_ERR "%s: Failure to create dentry in lower fs; " |
Harvey Harrison | 18d1dbf | 2008-04-29 00:59:48 -0700 | [diff] [blame] | 124 | "rc = [%d]\n", __func__, rc); |
Michael Halcrow | caeeeec | 2008-01-08 15:33:02 -0800 | [diff] [blame] | 125 | goto out_lock; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 126 | } |
| 127 | rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, |
| 128 | directory_inode->i_sb, 0); |
| 129 | if (rc) { |
| 130 | ecryptfs_printk(KERN_ERR, "Failure in ecryptfs_interpose\n"); |
| 131 | goto out_lock; |
| 132 | } |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 133 | fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode); |
| 134 | fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 135 | out_lock: |
| 136 | unlock_dir(lower_dir_dentry); |
| 137 | out: |
| 138 | return rc; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * grow_file |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 143 | * @ecryptfs_dentry: the eCryptfs dentry |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 144 | * |
| 145 | * This is the code which will grow the file to its correct size. |
| 146 | */ |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 147 | static int grow_file(struct dentry *ecryptfs_dentry) |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 148 | { |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 149 | struct inode *ecryptfs_inode = ecryptfs_dentry->d_inode; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 150 | struct file fake_file; |
| 151 | struct ecryptfs_file_info tmp_file_info; |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 152 | char zero_virt[] = { 0x00 }; |
| 153 | int rc = 0; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 154 | |
| 155 | memset(&fake_file, 0, sizeof(fake_file)); |
Josef "Jeff" Sipek | bd243a4 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 156 | fake_file.f_path.dentry = ecryptfs_dentry; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 157 | memset(&tmp_file_info, 0, sizeof(tmp_file_info)); |
| 158 | ecryptfs_set_file_private(&fake_file, &tmp_file_info); |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 159 | ecryptfs_set_file_lower( |
| 160 | &fake_file, |
| 161 | ecryptfs_inode_to_private(ecryptfs_inode)->lower_file); |
| 162 | rc = ecryptfs_write(&fake_file, zero_virt, 0, 1); |
| 163 | i_size_write(ecryptfs_inode, 0); |
| 164 | rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode); |
| 165 | ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat.flags |= |
| 166 | ECRYPTFS_NEW_FILE; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 167 | return rc; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * ecryptfs_initialize_file |
| 172 | * |
| 173 | * Cause the file to be changed from a basic empty file to an ecryptfs |
| 174 | * file with a header and first data page. |
| 175 | * |
| 176 | * Returns zero on success |
| 177 | */ |
| 178 | static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) |
| 179 | { |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 180 | struct ecryptfs_crypt_stat *crypt_stat = |
| 181 | &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 182 | int rc = 0; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 183 | |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 184 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { |
| 185 | ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); |
Michael Halcrow | e2bd99e | 2007-02-12 00:53:49 -0800 | [diff] [blame] | 186 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 187 | goto out; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 188 | } |
Michael Halcrow | e2bd99e | 2007-02-12 00:53:49 -0800 | [diff] [blame] | 189 | crypt_stat->flags |= ECRYPTFS_NEW_FILE; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 190 | ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n"); |
| 191 | rc = ecryptfs_new_file_context(ecryptfs_dentry); |
| 192 | if (rc) { |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 193 | ecryptfs_printk(KERN_ERR, "Error creating new file " |
| 194 | "context; rc = [%d]\n", rc); |
| 195 | goto out; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 196 | } |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 197 | rc = ecryptfs_write_metadata(ecryptfs_dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 198 | if (rc) { |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 199 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); |
| 200 | goto out; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 201 | } |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 202 | rc = grow_file(ecryptfs_dentry); |
Michael Halcrow | 5dda699 | 2007-10-16 01:28:06 -0700 | [diff] [blame] | 203 | if (rc) |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 204 | printk(KERN_ERR "Error growing file; rc = [%d]\n", rc); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 205 | out: |
| 206 | return rc; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * ecryptfs_create |
| 211 | * @dir: The inode of the directory in which to create the file. |
| 212 | * @dentry: The eCryptfs dentry |
| 213 | * @mode: The mode of the new file. |
| 214 | * @nd: nameidata |
| 215 | * |
| 216 | * Creates a new file. |
| 217 | * |
| 218 | * Returns zero on success; non-zero on error condition |
| 219 | */ |
| 220 | static int |
| 221 | ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry, |
| 222 | int mode, struct nameidata *nd) |
| 223 | { |
| 224 | int rc; |
| 225 | |
Michael Halcrow | 4981e08 | 2007-10-16 01:28:09 -0700 | [diff] [blame] | 226 | /* ecryptfs_do_create() calls ecryptfs_interpose(), which opens |
| 227 | * the crypt_stat->lower_file (persistent file) */ |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 228 | rc = ecryptfs_do_create(directory_inode, ecryptfs_dentry, mode, nd); |
| 229 | if (unlikely(rc)) { |
| 230 | ecryptfs_printk(KERN_WARNING, "Failed to create file in" |
| 231 | "lower filesystem\n"); |
| 232 | goto out; |
| 233 | } |
| 234 | /* At this point, a file exists on "disk"; we need to make sure |
| 235 | * that this on disk file is prepared to be an ecryptfs file */ |
| 236 | rc = ecryptfs_initialize_file(ecryptfs_dentry); |
| 237 | out: |
| 238 | return rc; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * ecryptfs_lookup |
| 243 | * @dir: inode |
| 244 | * @dentry: The dentry |
| 245 | * @nd: nameidata, may be NULL |
| 246 | * |
| 247 | * Find a file on disk. If the file does not exist, then we'll add it to the |
| 248 | * dentry cache and continue on to read it from the disk. |
| 249 | */ |
| 250 | static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, |
| 251 | struct nameidata *nd) |
| 252 | { |
| 253 | int rc = 0; |
| 254 | struct dentry *lower_dir_dentry; |
| 255 | struct dentry *lower_dentry; |
| 256 | struct vfsmount *lower_mnt; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 257 | char *encoded_name; |
Mika Kukkonen | c381bfc | 2007-07-17 04:04:53 -0700 | [diff] [blame] | 258 | int encoded_namelen; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 259 | struct ecryptfs_crypt_stat *crypt_stat = NULL; |
Michael Halcrow | e77a56d | 2007-02-12 00:53:47 -0800 | [diff] [blame] | 260 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 261 | char *page_virt = NULL; |
| 262 | struct inode *lower_inode; |
| 263 | u64 file_size; |
| 264 | |
| 265 | lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent); |
| 266 | dentry->d_op = &ecryptfs_dops; |
| 267 | if ((dentry->d_name.len == 1 && !strcmp(dentry->d_name.name, ".")) |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 268 | || (dentry->d_name.len == 2 |
| 269 | && !strcmp(dentry->d_name.name, ".."))) { |
| 270 | d_drop(dentry); |
| 271 | goto out; |
| 272 | } |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 273 | encoded_namelen = ecryptfs_encode_filename(crypt_stat, |
| 274 | dentry->d_name.name, |
| 275 | dentry->d_name.len, |
| 276 | &encoded_name); |
| 277 | if (encoded_namelen < 0) { |
| 278 | rc = encoded_namelen; |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 279 | d_drop(dentry); |
| 280 | goto out; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 281 | } |
| 282 | ecryptfs_printk(KERN_DEBUG, "encoded_name = [%s]; encoded_namelen " |
| 283 | "= [%d]\n", encoded_name, encoded_namelen); |
| 284 | lower_dentry = lookup_one_len(encoded_name, lower_dir_dentry, |
| 285 | encoded_namelen - 1); |
| 286 | kfree(encoded_name); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 287 | if (IS_ERR(lower_dentry)) { |
| 288 | ecryptfs_printk(KERN_ERR, "ERR from lower_dentry\n"); |
| 289 | rc = PTR_ERR(lower_dentry); |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 290 | d_drop(dentry); |
| 291 | goto out; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 292 | } |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 293 | lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 294 | ecryptfs_printk(KERN_DEBUG, "lower_dentry = [%p]; lower_dentry->" |
| 295 | "d_name.name = [%s]\n", lower_dentry, |
| 296 | lower_dentry->d_name.name); |
| 297 | lower_inode = lower_dentry->d_inode; |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 298 | fsstack_copy_attr_atime(dir, lower_dir_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 299 | BUG_ON(!atomic_read(&lower_dentry->d_count)); |
| 300 | ecryptfs_set_dentry_private(dentry, |
| 301 | kmem_cache_alloc(ecryptfs_dentry_info_cache, |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 302 | GFP_KERNEL)); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 303 | if (!ecryptfs_dentry_to_private(dentry)) { |
| 304 | rc = -ENOMEM; |
| 305 | ecryptfs_printk(KERN_ERR, "Out of memory whilst attempting " |
| 306 | "to allocate ecryptfs_dentry_info struct\n"); |
| 307 | goto out_dput; |
| 308 | } |
| 309 | ecryptfs_set_dentry_lower(dentry, lower_dentry); |
| 310 | ecryptfs_set_dentry_lower_mnt(dentry, lower_mnt); |
| 311 | if (!lower_dentry->d_inode) { |
| 312 | /* We want to add because we couldn't find in lower */ |
| 313 | d_add(dentry, NULL); |
| 314 | goto out; |
| 315 | } |
| 316 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 1); |
| 317 | if (rc) { |
| 318 | ecryptfs_printk(KERN_ERR, "Error interposing\n"); |
| 319 | goto out_dput; |
| 320 | } |
| 321 | if (S_ISDIR(lower_inode->i_mode)) { |
| 322 | ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n"); |
| 323 | goto out; |
| 324 | } |
| 325 | if (S_ISLNK(lower_inode->i_mode)) { |
| 326 | ecryptfs_printk(KERN_DEBUG, "Is a symlink; returning\n"); |
| 327 | goto out; |
| 328 | } |
Ryusuke Konishi | 202a21d | 2007-08-10 13:00:51 -0700 | [diff] [blame] | 329 | if (special_file(lower_inode->i_mode)) { |
| 330 | ecryptfs_printk(KERN_DEBUG, "Is a special file; returning\n"); |
| 331 | goto out; |
| 332 | } |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 333 | if (!nd) { |
| 334 | ecryptfs_printk(KERN_DEBUG, "We have a NULL nd, just leave" |
| 335 | "as we *think* we are about to unlink\n"); |
| 336 | goto out; |
| 337 | } |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 338 | /* Released in this function */ |
Robert P. J. Day | c376222 | 2007-02-10 01:45:03 -0800 | [diff] [blame] | 339 | page_virt = kmem_cache_zalloc(ecryptfs_header_cache_2, |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 340 | GFP_USER); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 341 | if (!page_virt) { |
| 342 | rc = -ENOMEM; |
| 343 | ecryptfs_printk(KERN_ERR, |
| 344 | "Cannot ecryptfs_kmalloc a page\n"); |
| 345 | goto out_dput; |
| 346 | } |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 347 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
Michael Halcrow | e2bd99e | 2007-02-12 00:53:49 -0800 | [diff] [blame] | 348 | if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 349 | ecryptfs_set_default_sizes(crypt_stat); |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 350 | rc = ecryptfs_read_and_validate_header_region(page_virt, |
| 351 | dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 352 | if (rc) { |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 353 | rc = ecryptfs_read_and_validate_xattr_region(page_virt, dentry); |
| 354 | if (rc) { |
| 355 | printk(KERN_DEBUG "Valid metadata not found in header " |
| 356 | "region or xattr region; treating file as " |
| 357 | "unencrypted\n"); |
| 358 | rc = 0; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 359 | kmem_cache_free(ecryptfs_header_cache_2, page_virt); |
| 360 | goto out; |
| 361 | } |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 362 | crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 363 | } |
Michael Halcrow | e77a56d | 2007-02-12 00:53:47 -0800 | [diff] [blame] | 364 | mount_crypt_stat = &ecryptfs_superblock_to_private( |
| 365 | dentry->d_sb)->mount_crypt_stat; |
| 366 | if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) { |
| 367 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) |
Michael Halcrow | cc11bef | 2008-02-06 01:38:32 -0800 | [diff] [blame] | 368 | file_size = (crypt_stat->num_header_bytes_at_front |
Michael Halcrow | e77a56d | 2007-02-12 00:53:47 -0800 | [diff] [blame] | 369 | + i_size_read(lower_dentry->d_inode)); |
| 370 | else |
| 371 | file_size = i_size_read(lower_dentry->d_inode); |
| 372 | } else { |
| 373 | memcpy(&file_size, page_virt, sizeof(file_size)); |
| 374 | file_size = be64_to_cpu(file_size); |
| 375 | } |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 376 | i_size_write(dentry->d_inode, (loff_t)file_size); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 377 | kmem_cache_free(ecryptfs_header_cache_2, page_virt); |
| 378 | goto out; |
| 379 | |
| 380 | out_dput: |
| 381 | dput(lower_dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 382 | d_drop(dentry); |
| 383 | out: |
| 384 | return ERR_PTR(rc); |
| 385 | } |
| 386 | |
| 387 | static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir, |
| 388 | struct dentry *new_dentry) |
| 389 | { |
| 390 | struct dentry *lower_old_dentry; |
| 391 | struct dentry *lower_new_dentry; |
| 392 | struct dentry *lower_dir_dentry; |
| 393 | u64 file_size_save; |
| 394 | int rc; |
| 395 | |
| 396 | file_size_save = i_size_read(old_dentry->d_inode); |
| 397 | lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); |
| 398 | lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); |
| 399 | dget(lower_old_dentry); |
| 400 | dget(lower_new_dentry); |
| 401 | lower_dir_dentry = lock_parent(lower_new_dentry); |
| 402 | rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode, |
| 403 | lower_new_dentry); |
| 404 | if (rc || !lower_new_dentry->d_inode) |
| 405 | goto out_lock; |
| 406 | rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0); |
| 407 | if (rc) |
| 408 | goto out_lock; |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 409 | fsstack_copy_attr_times(dir, lower_new_dentry->d_inode); |
| 410 | fsstack_copy_inode_size(dir, lower_new_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 411 | old_dentry->d_inode->i_nlink = |
| 412 | ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink; |
| 413 | i_size_write(new_dentry->d_inode, file_size_save); |
| 414 | out_lock: |
| 415 | unlock_dir(lower_dir_dentry); |
| 416 | dput(lower_new_dentry); |
| 417 | dput(lower_old_dentry); |
Michael Halcrow | ae56fb1 | 2006-11-16 01:19:30 -0800 | [diff] [blame] | 418 | d_drop(lower_old_dentry); |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 419 | d_drop(new_dentry); |
| 420 | d_drop(old_dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 421 | return rc; |
| 422 | } |
| 423 | |
| 424 | static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry) |
| 425 | { |
| 426 | int rc = 0; |
| 427 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 428 | struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir); |
| 429 | |
| 430 | lock_parent(lower_dentry); |
| 431 | rc = vfs_unlink(lower_dir_inode, lower_dentry); |
| 432 | if (rc) { |
Michael Halcrow | ae56fb1 | 2006-11-16 01:19:30 -0800 | [diff] [blame] | 433 | printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 434 | goto out_unlock; |
| 435 | } |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 436 | fsstack_copy_attr_times(dir, lower_dir_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 437 | dentry->d_inode->i_nlink = |
| 438 | ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink; |
| 439 | dentry->d_inode->i_ctime = dir->i_ctime; |
Michael Halcrow | caeeeec | 2008-01-08 15:33:02 -0800 | [diff] [blame] | 440 | d_drop(dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 441 | out_unlock: |
| 442 | unlock_parent(lower_dentry); |
| 443 | return rc; |
| 444 | } |
| 445 | |
| 446 | static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry, |
| 447 | const char *symname) |
| 448 | { |
| 449 | int rc; |
| 450 | struct dentry *lower_dentry; |
| 451 | struct dentry *lower_dir_dentry; |
| 452 | umode_t mode; |
| 453 | char *encoded_symname; |
Mika Kukkonen | c381bfc | 2007-07-17 04:04:53 -0700 | [diff] [blame] | 454 | int encoded_symlen; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 455 | struct ecryptfs_crypt_stat *crypt_stat = NULL; |
| 456 | |
| 457 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 458 | dget(lower_dentry); |
| 459 | lower_dir_dentry = lock_parent(lower_dentry); |
| 460 | mode = S_IALLUGO; |
| 461 | encoded_symlen = ecryptfs_encode_filename(crypt_stat, symname, |
| 462 | strlen(symname), |
| 463 | &encoded_symname); |
| 464 | if (encoded_symlen < 0) { |
| 465 | rc = encoded_symlen; |
| 466 | goto out_lock; |
| 467 | } |
| 468 | rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry, |
| 469 | encoded_symname, mode); |
| 470 | kfree(encoded_symname); |
| 471 | if (rc || !lower_dentry->d_inode) |
| 472 | goto out_lock; |
| 473 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); |
| 474 | if (rc) |
| 475 | goto out_lock; |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 476 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); |
| 477 | fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 478 | out_lock: |
| 479 | unlock_dir(lower_dir_dentry); |
| 480 | dput(lower_dentry); |
| 481 | if (!dentry->d_inode) |
| 482 | d_drop(dentry); |
| 483 | return rc; |
| 484 | } |
| 485 | |
| 486 | static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
| 487 | { |
| 488 | int rc; |
| 489 | struct dentry *lower_dentry; |
| 490 | struct dentry *lower_dir_dentry; |
| 491 | |
| 492 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 493 | lower_dir_dentry = lock_parent(lower_dentry); |
| 494 | rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode); |
| 495 | if (rc || !lower_dentry->d_inode) |
| 496 | goto out; |
| 497 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); |
| 498 | if (rc) |
| 499 | goto out; |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 500 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); |
| 501 | fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 502 | dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; |
| 503 | out: |
| 504 | unlock_dir(lower_dir_dentry); |
| 505 | if (!dentry->d_inode) |
| 506 | d_drop(dentry); |
| 507 | return rc; |
| 508 | } |
| 509 | |
| 510 | static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry) |
| 511 | { |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 512 | struct dentry *lower_dentry; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 513 | struct dentry *lower_dir_dentry; |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 514 | int rc; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 515 | |
| 516 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 517 | dget(dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 518 | lower_dir_dentry = lock_parent(lower_dentry); |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 519 | dget(lower_dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 520 | rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry); |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 521 | dput(lower_dentry); |
| 522 | if (!rc) |
| 523 | d_delete(lower_dentry); |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 524 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 525 | dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; |
| 526 | unlock_dir(lower_dir_dentry); |
| 527 | if (!rc) |
| 528 | d_drop(dentry); |
Michael Halcrow | 45ec4aba | 2006-10-30 22:07:20 -0800 | [diff] [blame] | 529 | dput(dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 530 | return rc; |
| 531 | } |
| 532 | |
| 533 | static int |
| 534 | ecryptfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) |
| 535 | { |
| 536 | int rc; |
| 537 | struct dentry *lower_dentry; |
| 538 | struct dentry *lower_dir_dentry; |
| 539 | |
| 540 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 541 | lower_dir_dentry = lock_parent(lower_dentry); |
| 542 | rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev); |
| 543 | if (rc || !lower_dentry->d_inode) |
| 544 | goto out; |
| 545 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); |
| 546 | if (rc) |
| 547 | goto out; |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 548 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); |
| 549 | fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 550 | out: |
| 551 | unlock_dir(lower_dir_dentry); |
| 552 | if (!dentry->d_inode) |
| 553 | d_drop(dentry); |
| 554 | return rc; |
| 555 | } |
| 556 | |
| 557 | static int |
| 558 | ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 559 | struct inode *new_dir, struct dentry *new_dentry) |
| 560 | { |
| 561 | int rc; |
| 562 | struct dentry *lower_old_dentry; |
| 563 | struct dentry *lower_new_dentry; |
| 564 | struct dentry *lower_old_dir_dentry; |
| 565 | struct dentry *lower_new_dir_dentry; |
| 566 | |
| 567 | lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); |
| 568 | lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); |
| 569 | dget(lower_old_dentry); |
| 570 | dget(lower_new_dentry); |
| 571 | lower_old_dir_dentry = dget_parent(lower_old_dentry); |
| 572 | lower_new_dir_dentry = dget_parent(lower_new_dentry); |
| 573 | lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
| 574 | rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry, |
| 575 | lower_new_dir_dentry->d_inode, lower_new_dentry); |
| 576 | if (rc) |
| 577 | goto out_lock; |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 578 | fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 579 | if (new_dir != old_dir) |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 580 | fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 581 | out_lock: |
| 582 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
Michael Halcrow | a908308 | 2006-11-16 01:19:16 -0800 | [diff] [blame] | 583 | dput(lower_new_dentry->d_parent); |
| 584 | dput(lower_old_dentry->d_parent); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 585 | dput(lower_new_dentry); |
| 586 | dput(lower_old_dentry); |
| 587 | return rc; |
| 588 | } |
| 589 | |
| 590 | static int |
| 591 | ecryptfs_readlink(struct dentry *dentry, char __user * buf, int bufsiz) |
| 592 | { |
| 593 | int rc; |
| 594 | struct dentry *lower_dentry; |
| 595 | char *decoded_name; |
| 596 | char *lower_buf; |
| 597 | mm_segment_t old_fs; |
| 598 | struct ecryptfs_crypt_stat *crypt_stat; |
| 599 | |
| 600 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 601 | if (!lower_dentry->d_inode->i_op || |
| 602 | !lower_dentry->d_inode->i_op->readlink) { |
| 603 | rc = -EINVAL; |
| 604 | goto out; |
| 605 | } |
| 606 | /* Released in this function */ |
| 607 | lower_buf = kmalloc(bufsiz, GFP_KERNEL); |
| 608 | if (lower_buf == NULL) { |
| 609 | ecryptfs_printk(KERN_ERR, "Out of memory\n"); |
| 610 | rc = -ENOMEM; |
| 611 | goto out; |
| 612 | } |
| 613 | old_fs = get_fs(); |
| 614 | set_fs(get_ds()); |
| 615 | ecryptfs_printk(KERN_DEBUG, "Calling readlink w/ " |
| 616 | "lower_dentry->d_name.name = [%s]\n", |
| 617 | lower_dentry->d_name.name); |
| 618 | rc = lower_dentry->d_inode->i_op->readlink(lower_dentry, |
| 619 | (char __user *)lower_buf, |
| 620 | bufsiz); |
| 621 | set_fs(old_fs); |
| 622 | if (rc >= 0) { |
| 623 | crypt_stat = NULL; |
| 624 | rc = ecryptfs_decode_filename(crypt_stat, lower_buf, rc, |
| 625 | &decoded_name); |
| 626 | if (rc == -ENOMEM) |
| 627 | goto out_free_lower_buf; |
| 628 | if (rc > 0) { |
| 629 | ecryptfs_printk(KERN_DEBUG, "Copying [%d] bytes " |
| 630 | "to userspace: [%*s]\n", rc, |
| 631 | decoded_name); |
| 632 | if (copy_to_user(buf, decoded_name, rc)) |
| 633 | rc = -EFAULT; |
| 634 | } |
| 635 | kfree(decoded_name); |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 636 | fsstack_copy_attr_atime(dentry->d_inode, |
| 637 | lower_dentry->d_inode); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 638 | } |
| 639 | out_free_lower_buf: |
| 640 | kfree(lower_buf); |
| 641 | out: |
| 642 | return rc; |
| 643 | } |
| 644 | |
| 645 | static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 646 | { |
| 647 | char *buf; |
| 648 | int len = PAGE_SIZE, rc; |
| 649 | mm_segment_t old_fs; |
| 650 | |
| 651 | /* Released in ecryptfs_put_link(); only release here on error */ |
| 652 | buf = kmalloc(len, GFP_KERNEL); |
| 653 | if (!buf) { |
| 654 | rc = -ENOMEM; |
| 655 | goto out; |
| 656 | } |
| 657 | old_fs = get_fs(); |
| 658 | set_fs(get_ds()); |
| 659 | ecryptfs_printk(KERN_DEBUG, "Calling readlink w/ " |
| 660 | "dentry->d_name.name = [%s]\n", dentry->d_name.name); |
| 661 | rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len); |
| 662 | buf[rc] = '\0'; |
| 663 | set_fs(old_fs); |
| 664 | if (rc < 0) |
| 665 | goto out_free; |
| 666 | rc = 0; |
| 667 | nd_set_link(nd, buf); |
| 668 | goto out; |
| 669 | out_free: |
| 670 | kfree(buf); |
| 671 | out: |
| 672 | return ERR_PTR(rc); |
| 673 | } |
| 674 | |
| 675 | static void |
| 676 | ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr) |
| 677 | { |
| 678 | /* Free the char* */ |
| 679 | kfree(nd_get_link(nd)); |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * upper_size_to_lower_size |
| 684 | * @crypt_stat: Crypt_stat associated with file |
| 685 | * @upper_size: Size of the upper file |
| 686 | * |
Michael Halcrow | cc11bef | 2008-02-06 01:38:32 -0800 | [diff] [blame] | 687 | * Calculate the required size of the lower file based on the |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 688 | * specified size of the upper file. This calculation is based on the |
| 689 | * number of headers in the underlying file and the extent size. |
| 690 | * |
| 691 | * Returns Calculated size of the lower file. |
| 692 | */ |
| 693 | static loff_t |
| 694 | upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat, |
| 695 | loff_t upper_size) |
| 696 | { |
| 697 | loff_t lower_size; |
| 698 | |
Michael Halcrow | cc11bef | 2008-02-06 01:38:32 -0800 | [diff] [blame] | 699 | lower_size = crypt_stat->num_header_bytes_at_front; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 700 | if (upper_size != 0) { |
| 701 | loff_t num_extents; |
| 702 | |
| 703 | num_extents = upper_size >> crypt_stat->extent_shift; |
| 704 | if (upper_size & ~crypt_stat->extent_mask) |
| 705 | num_extents++; |
| 706 | lower_size += (num_extents * crypt_stat->extent_size); |
| 707 | } |
| 708 | return lower_size; |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * ecryptfs_truncate |
| 713 | * @dentry: The ecryptfs layer dentry |
| 714 | * @new_length: The length to expand the file to |
| 715 | * |
| 716 | * Function to handle truncations modifying the size of the file. Note |
| 717 | * that the file sizes are interpolated. When expanding, we are simply |
| 718 | * writing strings of 0's out. When truncating, we need to modify the |
| 719 | * underlying file size according to the page index interpolations. |
| 720 | * |
| 721 | * Returns zero on success; non-zero otherwise |
| 722 | */ |
| 723 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) |
| 724 | { |
| 725 | int rc = 0; |
| 726 | struct inode *inode = dentry->d_inode; |
| 727 | struct dentry *lower_dentry; |
Michael Halcrow | 2ed9255 | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 728 | struct file fake_ecryptfs_file; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 729 | struct ecryptfs_crypt_stat *crypt_stat; |
| 730 | loff_t i_size = i_size_read(inode); |
| 731 | loff_t lower_size_before_truncate; |
| 732 | loff_t lower_size_after_truncate; |
| 733 | |
| 734 | if (unlikely((new_length == i_size))) |
| 735 | goto out; |
| 736 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
| 737 | /* Set up a fake ecryptfs file, this is used to interface with |
| 738 | * the file in the underlying filesystem so that the |
| 739 | * truncation has an effect there as well. */ |
| 740 | memset(&fake_ecryptfs_file, 0, sizeof(fake_ecryptfs_file)); |
Josef "Jeff" Sipek | bd243a4 | 2006-12-08 02:36:48 -0800 | [diff] [blame] | 741 | fake_ecryptfs_file.f_path.dentry = dentry; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 742 | /* Released at out_free: label */ |
| 743 | ecryptfs_set_file_private(&fake_ecryptfs_file, |
| 744 | kmem_cache_alloc(ecryptfs_file_info_cache, |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 745 | GFP_KERNEL)); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 746 | if (unlikely(!ecryptfs_file_to_private(&fake_ecryptfs_file))) { |
| 747 | rc = -ENOMEM; |
| 748 | goto out; |
| 749 | } |
| 750 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
Michael Halcrow | 2ed9255 | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 751 | ecryptfs_set_file_lower( |
| 752 | &fake_ecryptfs_file, |
| 753 | ecryptfs_inode_to_private(dentry->d_inode)->lower_file); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 754 | /* Switch on growing or shrinking file */ |
| 755 | if (new_length > i_size) { |
Michael Halcrow | 2ed9255 | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 756 | char zero[] = { 0x00 }; |
Michael Halcrow | 240e2df | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 757 | |
Michael Halcrow | 2ed9255 | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 758 | /* Write a single 0 at the last position of the file; |
| 759 | * this triggers code that will fill in 0's throughout |
| 760 | * the intermediate portion of the previous end of the |
| 761 | * file and the new and of the file */ |
| 762 | rc = ecryptfs_write(&fake_ecryptfs_file, zero, |
| 763 | (new_length - 1), 1); |
| 764 | } else { /* new_length < i_size_read(inode) */ |
| 765 | /* We're chopping off all the pages down do the page |
| 766 | * in which new_length is located. Fill in the end of |
| 767 | * that page from (new_length & ~PAGE_CACHE_MASK) to |
| 768 | * PAGE_CACHE_SIZE with zeros. */ |
| 769 | size_t num_zeros = (PAGE_CACHE_SIZE |
| 770 | - (new_length & ~PAGE_CACHE_MASK)); |
| 771 | |
| 772 | if (num_zeros) { |
| 773 | char *zeros_virt; |
| 774 | |
| 775 | zeros_virt = kzalloc(num_zeros, GFP_KERNEL); |
| 776 | if (!zeros_virt) { |
| 777 | rc = -ENOMEM; |
| 778 | goto out_free; |
| 779 | } |
| 780 | rc = ecryptfs_write(&fake_ecryptfs_file, zeros_virt, |
| 781 | new_length, num_zeros); |
| 782 | kfree(zeros_virt); |
Michael Halcrow | 5dda699 | 2007-10-16 01:28:06 -0700 | [diff] [blame] | 783 | if (rc) { |
Michael Halcrow | 240e2df | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 784 | printk(KERN_ERR "Error attempting to zero out " |
| 785 | "the remainder of the end page on " |
| 786 | "reducing truncate; rc = [%d]\n", rc); |
Michael Halcrow | 2ed9255 | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 787 | goto out_free; |
Michael Halcrow | 240e2df | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 788 | } |
| 789 | } |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 790 | vmtruncate(inode, new_length); |
Michael Halcrow | 0216f7f | 2007-10-16 01:28:08 -0700 | [diff] [blame] | 791 | rc = ecryptfs_write_inode_size_to_metadata(inode); |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 792 | if (rc) { |
| 793 | printk(KERN_ERR "Problem with " |
| 794 | "ecryptfs_write_inode_size_to_metadata; " |
| 795 | "rc = [%d]\n", rc); |
Michael Halcrow | 2ed9255 | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 796 | goto out_free; |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 797 | } |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 798 | /* We are reducing the size of the ecryptfs file, and need to |
| 799 | * know if we need to reduce the size of the lower file. */ |
| 800 | lower_size_before_truncate = |
| 801 | upper_size_to_lower_size(crypt_stat, i_size); |
| 802 | lower_size_after_truncate = |
| 803 | upper_size_to_lower_size(crypt_stat, new_length); |
| 804 | if (lower_size_after_truncate < lower_size_before_truncate) |
| 805 | vmtruncate(lower_dentry->d_inode, |
| 806 | lower_size_after_truncate); |
| 807 | } |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 808 | out_free: |
| 809 | if (ecryptfs_file_to_private(&fake_ecryptfs_file)) |
| 810 | kmem_cache_free(ecryptfs_file_info_cache, |
| 811 | ecryptfs_file_to_private(&fake_ecryptfs_file)); |
| 812 | out: |
| 813 | return rc; |
| 814 | } |
| 815 | |
| 816 | static int |
| 817 | ecryptfs_permission(struct inode *inode, int mask, struct nameidata *nd) |
| 818 | { |
| 819 | int rc; |
| 820 | |
| 821 | if (nd) { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 822 | struct vfsmount *vfsmnt_save = nd->path.mnt; |
| 823 | struct dentry *dentry_save = nd->path.dentry; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 824 | |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 825 | nd->path.mnt = ecryptfs_dentry_to_lower_mnt(nd->path.dentry); |
| 826 | nd->path.dentry = ecryptfs_dentry_to_lower(nd->path.dentry); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 827 | rc = permission(ecryptfs_inode_to_lower(inode), mask, nd); |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 828 | nd->path.mnt = vfsmnt_save; |
| 829 | nd->path.dentry = dentry_save; |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 830 | } else |
| 831 | rc = permission(ecryptfs_inode_to_lower(inode), mask, NULL); |
| 832 | return rc; |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * ecryptfs_setattr |
| 837 | * @dentry: dentry handle to the inode to modify |
| 838 | * @ia: Structure with flags of what to change and values |
| 839 | * |
| 840 | * Updates the metadata of an inode. If the update is to the size |
| 841 | * i.e. truncation, then ecryptfs_truncate will handle the size modification |
| 842 | * of both the ecryptfs inode and the lower inode. |
| 843 | * |
| 844 | * All other metadata changes will be passed right to the lower filesystem, |
| 845 | * and we will just update our inode to look like the lower. |
| 846 | */ |
| 847 | static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) |
| 848 | { |
| 849 | int rc = 0; |
| 850 | struct dentry *lower_dentry; |
| 851 | struct inode *inode; |
| 852 | struct inode *lower_inode; |
| 853 | struct ecryptfs_crypt_stat *crypt_stat; |
| 854 | |
| 855 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 856 | if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)) |
| 857 | ecryptfs_init_crypt_stat(crypt_stat); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 858 | inode = dentry->d_inode; |
| 859 | lower_inode = ecryptfs_inode_to_lower(inode); |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 860 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 861 | mutex_lock(&crypt_stat->cs_mutex); |
| 862 | if (S_ISDIR(dentry->d_inode->i_mode)) |
| 863 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); |
Michael Halcrow | 64ee480 | 2007-07-19 01:47:54 -0700 | [diff] [blame] | 864 | else if (S_ISREG(dentry->d_inode->i_mode) |
| 865 | && (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED) |
| 866 | || !(crypt_stat->flags & ECRYPTFS_KEY_VALID))) { |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 867 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat; |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 868 | |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 869 | mount_crypt_stat = &ecryptfs_superblock_to_private( |
| 870 | dentry->d_sb)->mount_crypt_stat; |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 871 | rc = ecryptfs_read_metadata(dentry); |
Michael Halcrow | 5dda699 | 2007-10-16 01:28:06 -0700 | [diff] [blame] | 872 | if (rc) { |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 873 | if (!(mount_crypt_stat->flags |
| 874 | & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { |
| 875 | rc = -EIO; |
Michael Halcrow | 25bd817 | 2008-02-06 01:38:35 -0800 | [diff] [blame] | 876 | printk(KERN_WARNING "Either the lower file " |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 877 | "is not in a valid eCryptfs format, " |
Michael Halcrow | 25bd817 | 2008-02-06 01:38:35 -0800 | [diff] [blame] | 878 | "or the key could not be retrieved. " |
| 879 | "Plaintext passthrough mode is not " |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 880 | "enabled; returning -EIO\n"); |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 881 | mutex_unlock(&crypt_stat->cs_mutex); |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 882 | goto out; |
| 883 | } |
| 884 | rc = 0; |
| 885 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); |
| 886 | mutex_unlock(&crypt_stat->cs_mutex); |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 887 | goto out; |
| 888 | } |
Michael Halcrow | e10f281 | 2007-06-27 14:09:44 -0700 | [diff] [blame] | 889 | } |
| 890 | mutex_unlock(&crypt_stat->cs_mutex); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 891 | if (ia->ia_valid & ATTR_SIZE) { |
| 892 | ecryptfs_printk(KERN_DEBUG, |
| 893 | "ia->ia_valid = [0x%x] ATTR_SIZE" " = [0x%x]\n", |
| 894 | ia->ia_valid, ATTR_SIZE); |
| 895 | rc = ecryptfs_truncate(dentry, ia->ia_size); |
| 896 | /* ecryptfs_truncate handles resizing of the lower file */ |
| 897 | ia->ia_valid &= ~ATTR_SIZE; |
| 898 | ecryptfs_printk(KERN_DEBUG, "ia->ia_valid = [%x]\n", |
| 899 | ia->ia_valid); |
| 900 | if (rc < 0) |
| 901 | goto out; |
| 902 | } |
Jeff Layton | 1ac564e | 2007-10-18 03:05:17 -0700 | [diff] [blame] | 903 | |
| 904 | /* |
| 905 | * mode change is for clearing setuid/setgid bits. Allow lower fs |
| 906 | * to interpret this in its own way. |
| 907 | */ |
| 908 | if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
| 909 | ia->ia_valid &= ~ATTR_MODE; |
| 910 | |
Miklos Szeredi | 9c3580a | 2008-04-29 00:59:48 -0700 | [diff] [blame] | 911 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 912 | rc = notify_change(lower_dentry, ia); |
Miklos Szeredi | 9c3580a | 2008-04-29 00:59:48 -0700 | [diff] [blame] | 913 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 914 | out: |
Josef "Jeff" Sipek | 0cc72dc | 2006-12-08 02:36:31 -0800 | [diff] [blame] | 915 | fsstack_copy_attr_all(inode, lower_inode, NULL); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 916 | return rc; |
| 917 | } |
| 918 | |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 919 | int |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 920 | ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
| 921 | size_t size, int flags) |
| 922 | { |
| 923 | int rc = 0; |
| 924 | struct dentry *lower_dentry; |
| 925 | |
| 926 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 927 | if (!lower_dentry->d_inode->i_op->setxattr) { |
| 928 | rc = -ENOSYS; |
| 929 | goto out; |
| 930 | } |
| 931 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
| 932 | rc = lower_dentry->d_inode->i_op->setxattr(lower_dentry, name, value, |
| 933 | size, flags); |
| 934 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
| 935 | out: |
| 936 | return rc; |
| 937 | } |
| 938 | |
Michael Halcrow | dd2a3b7 | 2007-02-12 00:53:46 -0800 | [diff] [blame] | 939 | ssize_t |
Michael Halcrow | d7cdc5f | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 940 | ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, |
| 941 | void *value, size_t size) |
| 942 | { |
| 943 | int rc = 0; |
| 944 | |
| 945 | if (!lower_dentry->d_inode->i_op->getxattr) { |
| 946 | rc = -ENOSYS; |
| 947 | goto out; |
| 948 | } |
| 949 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
| 950 | rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value, |
| 951 | size); |
| 952 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
| 953 | out: |
| 954 | return rc; |
| 955 | } |
| 956 | |
Adrian Bunk | 7896b63 | 2008-02-06 01:38:32 -0800 | [diff] [blame] | 957 | static ssize_t |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 958 | ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value, |
| 959 | size_t size) |
| 960 | { |
Michael Halcrow | 2ed9255 | 2007-10-16 01:28:10 -0700 | [diff] [blame] | 961 | return ecryptfs_getxattr_lower(ecryptfs_dentry_to_lower(dentry), name, |
| 962 | value, size); |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | static ssize_t |
| 966 | ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size) |
| 967 | { |
| 968 | int rc = 0; |
| 969 | struct dentry *lower_dentry; |
| 970 | |
| 971 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 972 | if (!lower_dentry->d_inode->i_op->listxattr) { |
| 973 | rc = -ENOSYS; |
| 974 | goto out; |
| 975 | } |
| 976 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
| 977 | rc = lower_dentry->d_inode->i_op->listxattr(lower_dentry, list, size); |
| 978 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
| 979 | out: |
| 980 | return rc; |
| 981 | } |
| 982 | |
| 983 | static int ecryptfs_removexattr(struct dentry *dentry, const char *name) |
| 984 | { |
| 985 | int rc = 0; |
| 986 | struct dentry *lower_dentry; |
| 987 | |
| 988 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
| 989 | if (!lower_dentry->d_inode->i_op->removexattr) { |
| 990 | rc = -ENOSYS; |
| 991 | goto out; |
| 992 | } |
| 993 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
| 994 | rc = lower_dentry->d_inode->i_op->removexattr(lower_dentry, name); |
| 995 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
| 996 | out: |
| 997 | return rc; |
| 998 | } |
| 999 | |
| 1000 | int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode) |
| 1001 | { |
| 1002 | if ((ecryptfs_inode_to_lower(inode) |
| 1003 | == (struct inode *)candidate_lower_inode)) |
| 1004 | return 1; |
| 1005 | else |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
| 1009 | int ecryptfs_inode_set(struct inode *inode, void *lower_inode) |
| 1010 | { |
| 1011 | ecryptfs_init_inode(inode, (struct inode *)lower_inode); |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1015 | const struct inode_operations ecryptfs_symlink_iops = { |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 1016 | .readlink = ecryptfs_readlink, |
| 1017 | .follow_link = ecryptfs_follow_link, |
| 1018 | .put_link = ecryptfs_put_link, |
| 1019 | .permission = ecryptfs_permission, |
| 1020 | .setattr = ecryptfs_setattr, |
| 1021 | .setxattr = ecryptfs_setxattr, |
| 1022 | .getxattr = ecryptfs_getxattr, |
| 1023 | .listxattr = ecryptfs_listxattr, |
| 1024 | .removexattr = ecryptfs_removexattr |
| 1025 | }; |
| 1026 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1027 | const struct inode_operations ecryptfs_dir_iops = { |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 1028 | .create = ecryptfs_create, |
| 1029 | .lookup = ecryptfs_lookup, |
| 1030 | .link = ecryptfs_link, |
| 1031 | .unlink = ecryptfs_unlink, |
| 1032 | .symlink = ecryptfs_symlink, |
| 1033 | .mkdir = ecryptfs_mkdir, |
| 1034 | .rmdir = ecryptfs_rmdir, |
| 1035 | .mknod = ecryptfs_mknod, |
| 1036 | .rename = ecryptfs_rename, |
| 1037 | .permission = ecryptfs_permission, |
| 1038 | .setattr = ecryptfs_setattr, |
| 1039 | .setxattr = ecryptfs_setxattr, |
| 1040 | .getxattr = ecryptfs_getxattr, |
| 1041 | .listxattr = ecryptfs_listxattr, |
| 1042 | .removexattr = ecryptfs_removexattr |
| 1043 | }; |
| 1044 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1045 | const struct inode_operations ecryptfs_main_iops = { |
Michael Halcrow | 237fead | 2006-10-04 02:16:22 -0700 | [diff] [blame] | 1046 | .permission = ecryptfs_permission, |
| 1047 | .setattr = ecryptfs_setattr, |
| 1048 | .setxattr = ecryptfs_setxattr, |
| 1049 | .getxattr = ecryptfs_getxattr, |
| 1050 | .listxattr = ecryptfs_listxattr, |
| 1051 | .removexattr = ecryptfs_removexattr |
| 1052 | }; |