aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ecryptfs/inode.c')
-rw-r--r--fs/ecryptfs/inode.c85
1 files changed, 24 insertions, 61 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index dfcc68484f47..11f5e5076aef 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -30,6 +30,7 @@
30#include <linux/namei.h> 30#include <linux/namei.h>
31#include <linux/mount.h> 31#include <linux/mount.h>
32#include <linux/crypto.h> 32#include <linux/crypto.h>
33#include <linux/fs_stack.h>
33#include "ecryptfs_kernel.h" 34#include "ecryptfs_kernel.h"
34 35
35static struct dentry *lock_parent(struct dentry *dentry) 36static struct dentry *lock_parent(struct dentry *dentry)
@@ -53,48 +54,6 @@ static void unlock_dir(struct dentry *dir)
53 dput(dir); 54 dput(dir);
54} 55}
55 56
56void ecryptfs_copy_inode_size(struct inode *dst, const struct inode *src)
57{
58 i_size_write(dst, i_size_read((struct inode *)src));
59 dst->i_blocks = src->i_blocks;
60}
61
62void ecryptfs_copy_attr_atime(struct inode *dest, const struct inode *src)
63{
64 dest->i_atime = src->i_atime;
65}
66
67static void ecryptfs_copy_attr_times(struct inode *dest,
68 const struct inode *src)
69{
70 dest->i_atime = src->i_atime;
71 dest->i_mtime = src->i_mtime;
72 dest->i_ctime = src->i_ctime;
73}
74
75static void ecryptfs_copy_attr_timesizes(struct inode *dest,
76 const struct inode *src)
77{
78 dest->i_atime = src->i_atime;
79 dest->i_mtime = src->i_mtime;
80 dest->i_ctime = src->i_ctime;
81 ecryptfs_copy_inode_size(dest, src);
82}
83
84void ecryptfs_copy_attr_all(struct inode *dest, const struct inode *src)
85{
86 dest->i_mode = src->i_mode;
87 dest->i_nlink = src->i_nlink;
88 dest->i_uid = src->i_uid;
89 dest->i_gid = src->i_gid;
90 dest->i_rdev = src->i_rdev;
91 dest->i_atime = src->i_atime;
92 dest->i_mtime = src->i_mtime;
93 dest->i_ctime = src->i_ctime;
94 dest->i_blkbits = src->i_blkbits;
95 dest->i_flags = src->i_flags;
96}
97
98/** 57/**
99 * ecryptfs_create_underlying_file 58 * ecryptfs_create_underlying_file
100 * @lower_dir_inode: inode of the parent in the lower fs of the new file 59 * @lower_dir_inode: inode of the parent in the lower fs of the new file
@@ -171,8 +130,8 @@ ecryptfs_do_create(struct inode *directory_inode,
171 ecryptfs_printk(KERN_ERR, "Failure in ecryptfs_interpose\n"); 130 ecryptfs_printk(KERN_ERR, "Failure in ecryptfs_interpose\n");
172 goto out_lock; 131 goto out_lock;
173 } 132 }
174 ecryptfs_copy_attr_timesizes(directory_inode, 133 fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode);
175 lower_dir_dentry->d_inode); 134 fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
176out_lock: 135out_lock:
177 unlock_dir(lower_dir_dentry); 136 unlock_dir(lower_dir_dentry);
178out: 137out:
@@ -196,7 +155,7 @@ static int grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file,
196 struct ecryptfs_file_info tmp_file_info; 155 struct ecryptfs_file_info tmp_file_info;
197 156
198 memset(&fake_file, 0, sizeof(fake_file)); 157 memset(&fake_file, 0, sizeof(fake_file));
199 fake_file.f_dentry = ecryptfs_dentry; 158 fake_file.f_path.dentry = ecryptfs_dentry;
200 memset(&tmp_file_info, 0, sizeof(tmp_file_info)); 159 memset(&tmp_file_info, 0, sizeof(tmp_file_info));
201 ecryptfs_set_file_private(&fake_file, &tmp_file_info); 160 ecryptfs_set_file_private(&fake_file, &tmp_file_info);
202 ecryptfs_set_file_lower(&fake_file, lower_file); 161 ecryptfs_set_file_lower(&fake_file, lower_file);
@@ -365,11 +324,11 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
365 "d_name.name = [%s]\n", lower_dentry, 324 "d_name.name = [%s]\n", lower_dentry,
366 lower_dentry->d_name.name); 325 lower_dentry->d_name.name);
367 lower_inode = lower_dentry->d_inode; 326 lower_inode = lower_dentry->d_inode;
368 ecryptfs_copy_attr_atime(dir, lower_dir_dentry->d_inode); 327 fsstack_copy_attr_atime(dir, lower_dir_dentry->d_inode);
369 BUG_ON(!atomic_read(&lower_dentry->d_count)); 328 BUG_ON(!atomic_read(&lower_dentry->d_count));
370 ecryptfs_set_dentry_private(dentry, 329 ecryptfs_set_dentry_private(dentry,
371 kmem_cache_alloc(ecryptfs_dentry_info_cache, 330 kmem_cache_alloc(ecryptfs_dentry_info_cache,
372 SLAB_KERNEL)); 331 GFP_KERNEL));
373 if (!ecryptfs_dentry_to_private(dentry)) { 332 if (!ecryptfs_dentry_to_private(dentry)) {
374 rc = -ENOMEM; 333 rc = -ENOMEM;
375 ecryptfs_printk(KERN_ERR, "Out of memory whilst attempting " 334 ecryptfs_printk(KERN_ERR, "Out of memory whilst attempting "
@@ -404,7 +363,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
404 /* Released in this function */ 363 /* Released in this function */
405 page_virt = 364 page_virt =
406 (char *)kmem_cache_alloc(ecryptfs_header_cache_2, 365 (char *)kmem_cache_alloc(ecryptfs_header_cache_2,
407 SLAB_USER); 366 GFP_USER);
408 if (!page_virt) { 367 if (!page_virt) {
409 rc = -ENOMEM; 368 rc = -ENOMEM;
410 ecryptfs_printk(KERN_ERR, 369 ecryptfs_printk(KERN_ERR,
@@ -462,7 +421,8 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
462 rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0); 421 rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
463 if (rc) 422 if (rc)
464 goto out_lock; 423 goto out_lock;
465 ecryptfs_copy_attr_timesizes(dir, lower_new_dentry->d_inode); 424 fsstack_copy_attr_times(dir, lower_new_dentry->d_inode);
425 fsstack_copy_inode_size(dir, lower_new_dentry->d_inode);
466 old_dentry->d_inode->i_nlink = 426 old_dentry->d_inode->i_nlink =
467 ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink; 427 ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink;
468 i_size_write(new_dentry->d_inode, file_size_save); 428 i_size_write(new_dentry->d_inode, file_size_save);
@@ -488,7 +448,7 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
488 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc); 448 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
489 goto out_unlock; 449 goto out_unlock;
490 } 450 }
491 ecryptfs_copy_attr_times(dir, lower_dir_inode); 451 fsstack_copy_attr_times(dir, lower_dir_inode);
492 dentry->d_inode->i_nlink = 452 dentry->d_inode->i_nlink =
493 ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink; 453 ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink;
494 dentry->d_inode->i_ctime = dir->i_ctime; 454 dentry->d_inode->i_ctime = dir->i_ctime;
@@ -527,7 +487,8 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
527 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); 487 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
528 if (rc) 488 if (rc)
529 goto out_lock; 489 goto out_lock;
530 ecryptfs_copy_attr_timesizes(dir, lower_dir_dentry->d_inode); 490 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
491 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
531out_lock: 492out_lock:
532 unlock_dir(lower_dir_dentry); 493 unlock_dir(lower_dir_dentry);
533 dput(lower_dentry); 494 dput(lower_dentry);
@@ -550,7 +511,8 @@ static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
550 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); 511 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
551 if (rc) 512 if (rc)
552 goto out; 513 goto out;
553 ecryptfs_copy_attr_timesizes(dir, lower_dir_dentry->d_inode); 514 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
515 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
554 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; 516 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink;
555out: 517out:
556 unlock_dir(lower_dir_dentry); 518 unlock_dir(lower_dir_dentry);
@@ -573,7 +535,7 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
573 dput(lower_dentry); 535 dput(lower_dentry);
574 if (!rc) 536 if (!rc)
575 d_delete(lower_dentry); 537 d_delete(lower_dentry);
576 ecryptfs_copy_attr_times(dir, lower_dir_dentry->d_inode); 538 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
577 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; 539 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink;
578 unlock_dir(lower_dir_dentry); 540 unlock_dir(lower_dir_dentry);
579 if (!rc) 541 if (!rc)
@@ -597,7 +559,8 @@ ecryptfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
597 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); 559 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
598 if (rc) 560 if (rc)
599 goto out; 561 goto out;
600 ecryptfs_copy_attr_timesizes(dir, lower_dir_dentry->d_inode); 562 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
563 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
601out: 564out:
602 unlock_dir(lower_dir_dentry); 565 unlock_dir(lower_dir_dentry);
603 if (!dentry->d_inode) 566 if (!dentry->d_inode)
@@ -626,9 +589,9 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
626 lower_new_dir_dentry->d_inode, lower_new_dentry); 589 lower_new_dir_dentry->d_inode, lower_new_dentry);
627 if (rc) 590 if (rc)
628 goto out_lock; 591 goto out_lock;
629 ecryptfs_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); 592 fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL);
630 if (new_dir != old_dir) 593 if (new_dir != old_dir)
631 ecryptfs_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); 594 fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL);
632out_lock: 595out_lock:
633 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); 596 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
634 dput(lower_new_dentry->d_parent); 597 dput(lower_new_dentry->d_parent);
@@ -684,8 +647,8 @@ ecryptfs_readlink(struct dentry *dentry, char __user * buf, int bufsiz)
684 rc = -EFAULT; 647 rc = -EFAULT;
685 } 648 }
686 kfree(decoded_name); 649 kfree(decoded_name);
687 ecryptfs_copy_attr_atime(dentry->d_inode, 650 fsstack_copy_attr_atime(dentry->d_inode,
688 lower_dentry->d_inode); 651 lower_dentry->d_inode);
689 } 652 }
690out_free_lower_buf: 653out_free_lower_buf:
691 kfree(lower_buf); 654 kfree(lower_buf);
@@ -791,11 +754,11 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
791 * the file in the underlying filesystem so that the 754 * the file in the underlying filesystem so that the
792 * truncation has an effect there as well. */ 755 * truncation has an effect there as well. */
793 memset(&fake_ecryptfs_file, 0, sizeof(fake_ecryptfs_file)); 756 memset(&fake_ecryptfs_file, 0, sizeof(fake_ecryptfs_file));
794 fake_ecryptfs_file.f_dentry = dentry; 757 fake_ecryptfs_file.f_path.dentry = dentry;
795 /* Released at out_free: label */ 758 /* Released at out_free: label */
796 ecryptfs_set_file_private(&fake_ecryptfs_file, 759 ecryptfs_set_file_private(&fake_ecryptfs_file,
797 kmem_cache_alloc(ecryptfs_file_info_cache, 760 kmem_cache_alloc(ecryptfs_file_info_cache,
798 SLAB_KERNEL)); 761 GFP_KERNEL));
799 if (unlikely(!ecryptfs_file_to_private(&fake_ecryptfs_file))) { 762 if (unlikely(!ecryptfs_file_to_private(&fake_ecryptfs_file))) {
800 rc = -ENOMEM; 763 rc = -ENOMEM;
801 goto out; 764 goto out;
@@ -915,7 +878,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
915 } 878 }
916 rc = notify_change(lower_dentry, ia); 879 rc = notify_change(lower_dentry, ia);
917out: 880out:
918 ecryptfs_copy_attr_all(inode, lower_inode); 881 fsstack_copy_attr_all(inode, lower_inode, NULL);
919 return rc; 882 return rc;
920} 883}
921 884