Skip to content

Commit c4f7907

Browse files
author
Tyler Hicks
committed
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>
1 parent 139f37f commit c4f7907

File tree

4 files changed

+91
-107
lines changed

4 files changed

+91
-107
lines changed

fs/ecryptfs/ecryptfs_kernel.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,8 @@ struct ecryptfs_open_req {
625625
struct list_head kthread_ctl_list;
626626
};
627627

628-
#define ECRYPTFS_INTERPOSE_FLAG_D_ADD 0x00000001
629-
int ecryptfs_interpose(struct dentry *hidden_dentry,
630-
struct dentry *this_dentry, struct super_block *sb,
631-
u32 flags);
628+
struct inode *ecryptfs_get_inode(struct inode *lower_inode,
629+
struct super_block *sb);
632630
void ecryptfs_i_size_init(const char *page_virt, struct inode *inode);
633631
int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
634632
struct dentry *lower_dentry,
@@ -679,9 +677,6 @@ int
679677
ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
680678
unsigned char *src, struct dentry *ecryptfs_dentry);
681679
int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
682-
int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode);
683-
int ecryptfs_inode_set(struct inode *inode, void *lower_inode);
684-
void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode);
685680
ssize_t
686681
ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
687682
void *value, size_t size);

fs/ecryptfs/inode.c

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,95 @@ static void unlock_dir(struct dentry *dir)
5151
dput(dir);
5252
}
5353

54+
static 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+
61+
static 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+
72+
struct 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;
112+
out:
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+
*/
128+
static 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+
54143
/**
55144
* ecryptfs_create_underlying_file
56145
* @lower_dir_inode: inode of the parent in the lower fs of the new file
@@ -1079,21 +1168,6 @@ static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
10791168
return rc;
10801169
}
10811170

1082-
int 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-
1091-
int ecryptfs_inode_set(struct inode *inode, void *lower_inode)
1092-
{
1093-
ecryptfs_init_inode(inode, (struct inode *)lower_inode);
1094-
return 0;
1095-
}
1096-
10971171
const struct inode_operations ecryptfs_symlink_iops = {
10981172
.readlink = ecryptfs_readlink,
10991173
.follow_link = ecryptfs_follow_link,

fs/ecryptfs/main.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -168,75 +168,6 @@ void ecryptfs_put_lower_file(struct inode *inode)
168168
}
169169
}
170170

171-
static struct inode *ecryptfs_get_inode(struct inode *lower_inode,
172-
struct super_block *sb)
173-
{
174-
struct inode *inode;
175-
int rc = 0;
176-
177-
if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
178-
rc = -EXDEV;
179-
goto out;
180-
}
181-
if (!igrab(lower_inode)) {
182-
rc = -ESTALE;
183-
goto out;
184-
}
185-
inode = iget5_locked(sb, (unsigned long)lower_inode,
186-
ecryptfs_inode_test, ecryptfs_inode_set,
187-
lower_inode);
188-
if (!inode) {
189-
rc = -EACCES;
190-
iput(lower_inode);
191-
goto out;
192-
}
193-
if (inode->i_state & I_NEW)
194-
unlock_new_inode(inode);
195-
else
196-
iput(lower_inode);
197-
if (S_ISLNK(lower_inode->i_mode))
198-
inode->i_op = &ecryptfs_symlink_iops;
199-
else if (S_ISDIR(lower_inode->i_mode))
200-
inode->i_op = &ecryptfs_dir_iops;
201-
if (S_ISDIR(lower_inode->i_mode))
202-
inode->i_fop = &ecryptfs_dir_fops;
203-
if (special_file(lower_inode->i_mode))
204-
init_special_inode(inode, lower_inode->i_mode,
205-
lower_inode->i_rdev);
206-
fsstack_copy_attr_all(inode, lower_inode);
207-
/* This size will be overwritten for real files w/ headers and
208-
* other metadata */
209-
fsstack_copy_inode_size(inode, lower_inode);
210-
return inode;
211-
out:
212-
return ERR_PTR(rc);
213-
}
214-
215-
/**
216-
* ecryptfs_interpose
217-
* @lower_dentry: Existing dentry in the lower filesystem
218-
* @dentry: ecryptfs' dentry
219-
* @sb: ecryptfs's super_block
220-
* @flags: flags to govern behavior of interpose procedure
221-
*
222-
* Interposes upper and lower dentries.
223-
*
224-
* Returns zero on success; non-zero otherwise
225-
*/
226-
int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
227-
struct super_block *sb, u32 flags)
228-
{
229-
struct inode *lower_inode = lower_dentry->d_inode;
230-
struct inode *inode = ecryptfs_get_inode(lower_inode, sb);
231-
if (IS_ERR(inode))
232-
return PTR_ERR(inode);
233-
if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
234-
d_add(dentry, inode);
235-
else
236-
d_instantiate(dentry, inode);
237-
return 0;
238-
}
239-
240171
enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
241172
ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
242173
ecryptfs_opt_ecryptfs_key_bytes,

fs/ecryptfs/super.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ static void ecryptfs_destroy_inode(struct inode *inode)
9292
call_rcu(&inode->i_rcu, ecryptfs_i_callback);
9393
}
9494

95-
/**
96-
* ecryptfs_init_inode
97-
* @inode: The ecryptfs inode
98-
*
99-
* Set up the ecryptfs inode.
100-
*/
101-
void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode)
102-
{
103-
ecryptfs_set_inode_lower(inode, lower_inode);
104-
inode->i_ino = lower_inode->i_ino;
105-
inode->i_version++;
106-
inode->i_op = &ecryptfs_main_iops;
107-
inode->i_fop = &ecryptfs_main_fops;
108-
inode->i_mapping->a_ops = &ecryptfs_aops;
109-
}
110-
11195
/**
11296
* ecryptfs_statfs
11397
* @sb: The ecryptfs super block

0 commit comments

Comments
 (0)