aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/inode.c
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>2011-05-23 22:18:20 -0400
committerTyler Hicks <tyhicks@linux.vnet.ibm.com>2011-05-29 13:49:53 -0400
commitc4f790736ca8d7d86883c5aee2ba1caa15cd8da3 (patch)
tree827e371fb2aff1e9290fbd90ca436d069aaa356d /fs/ecryptfs/inode.c
parent139f37f5e14cd883eee2a8a36289f544b5390a44 (diff)
eCryptfs: Consolidate inode functions into inode.c
These functions should live in inode.c since their focus is on inodes and they're primarily used by functions in inode.c. Also does a simple cleanup of ecryptfs_inode_test() and rolls ecryptfs_init_inode() into ecryptfs_inode_set(). Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com> Tested-by: David <david@unsolicited.net>
Diffstat (limited to 'fs/ecryptfs/inode.c')
-rw-r--r--fs/ecryptfs/inode.c104
1 files changed, 89 insertions, 15 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 94ab3c06317a..704a8c8fe19a 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -51,6 +51,95 @@ static void unlock_dir(struct dentry *dir)
51 dput(dir); 51 dput(dir);
52} 52}
53 53
54static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
55{
56 if (ecryptfs_inode_to_lower(inode) == (struct inode *)lower_inode)
57 return 1;
58 return 0;
59}
60
61static int ecryptfs_inode_set(struct inode *inode, void *lower_inode)
62{
63 ecryptfs_set_inode_lower(inode, (struct inode *)lower_inode);
64 inode->i_ino = ((struct inode *)lower_inode)->i_ino;
65 inode->i_version++;
66 inode->i_op = &ecryptfs_main_iops;
67 inode->i_fop = &ecryptfs_main_fops;
68 inode->i_mapping->a_ops = &ecryptfs_aops;
69 return 0;
70}
71
72struct inode *ecryptfs_get_inode(struct inode *lower_inode,
73 struct super_block *sb)
74{
75 struct inode *inode;
76 int rc = 0;
77
78 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
79 rc = -EXDEV;
80 goto out;
81 }
82 if (!igrab(lower_inode)) {
83 rc = -ESTALE;
84 goto out;
85 }
86 inode = iget5_locked(sb, (unsigned long)lower_inode,
87 ecryptfs_inode_test, ecryptfs_inode_set,
88 lower_inode);
89 if (!inode) {
90 rc = -EACCES;
91 iput(lower_inode);
92 goto out;
93 }
94 if (inode->i_state & I_NEW)
95 unlock_new_inode(inode);
96 else
97 iput(lower_inode);
98 if (S_ISLNK(lower_inode->i_mode))
99 inode->i_op = &ecryptfs_symlink_iops;
100 else if (S_ISDIR(lower_inode->i_mode))
101 inode->i_op = &ecryptfs_dir_iops;
102 if (S_ISDIR(lower_inode->i_mode))
103 inode->i_fop = &ecryptfs_dir_fops;
104 if (special_file(lower_inode->i_mode))
105 init_special_inode(inode, lower_inode->i_mode,
106 lower_inode->i_rdev);
107 fsstack_copy_attr_all(inode, lower_inode);
108 /* This size will be overwritten for real files w/ headers and
109 * other metadata */
110 fsstack_copy_inode_size(inode, lower_inode);
111 return inode;
112out:
113 return ERR_PTR(rc);
114}
115
116#define ECRYPTFS_INTERPOSE_FLAG_D_ADD 0x00000001
117/**
118 * ecryptfs_interpose
119 * @lower_dentry: Existing dentry in the lower filesystem
120 * @dentry: ecryptfs' dentry
121 * @sb: ecryptfs's super_block
122 * @flags: flags to govern behavior of interpose procedure
123 *
124 * Interposes upper and lower dentries.
125 *
126 * Returns zero on success; non-zero otherwise
127 */
128static int ecryptfs_interpose(struct dentry *lower_dentry,
129 struct dentry *dentry, struct super_block *sb,
130 u32 flags)
131{
132 struct inode *lower_inode = lower_dentry->d_inode;
133 struct inode *inode = ecryptfs_get_inode(lower_inode, sb);
134 if (IS_ERR(inode))
135 return PTR_ERR(inode);
136 if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
137 d_add(dentry, inode);
138 else
139 d_instantiate(dentry, inode);
140 return 0;
141}
142
54/** 143/**
55 * ecryptfs_create_underlying_file 144 * ecryptfs_create_underlying_file
56 * @lower_dir_inode: inode of the parent in the lower fs of the new file 145 * @lower_dir_inode: inode of the parent in the lower fs of the new file
@@ -1079,21 +1168,6 @@ out:
1079 return rc; 1168 return rc;
1080} 1169}
1081 1170
1082int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode)
1083{
1084 if ((ecryptfs_inode_to_lower(inode)
1085 == (struct inode *)candidate_lower_inode))
1086 return 1;
1087 else
1088 return 0;
1089}
1090
1091int ecryptfs_inode_set(struct inode *inode, void *lower_inode)
1092{
1093 ecryptfs_init_inode(inode, (struct inode *)lower_inode);
1094 return 0;
1095}
1096
1097const struct inode_operations ecryptfs_symlink_iops = { 1171const struct inode_operations ecryptfs_symlink_iops = {
1098 .readlink = ecryptfs_readlink, 1172 .readlink = ecryptfs_readlink,
1099 .follow_link = ecryptfs_follow_link, 1173 .follow_link = ecryptfs_follow_link,