diff options
| author | Tyler Hicks <tyhicks@linux.vnet.ibm.com> | 2011-05-23 22:18:20 -0400 |
|---|---|---|
| committer | Tyler Hicks <tyhicks@linux.vnet.ibm.com> | 2011-05-29 13:49:53 -0400 |
| commit | c4f790736ca8d7d86883c5aee2ba1caa15cd8da3 (patch) | |
| tree | 827e371fb2aff1e9290fbd90ca436d069aaa356d | |
| parent | 139f37f5e14cd883eee2a8a36289f544b5390a44 (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>
| -rw-r--r-- | fs/ecryptfs/ecryptfs_kernel.h | 9 | ||||
| -rw-r--r-- | fs/ecryptfs/inode.c | 104 | ||||
| -rw-r--r-- | fs/ecryptfs/main.c | 69 | ||||
| -rw-r--r-- | fs/ecryptfs/super.c | 16 |
4 files changed, 91 insertions, 107 deletions
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index e70282775e2c..37224b5fb12a 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h | |||
| @@ -625,10 +625,8 @@ struct ecryptfs_open_req { | |||
| 625 | struct list_head kthread_ctl_list; | 625 | struct list_head kthread_ctl_list; |
| 626 | }; | 626 | }; |
| 627 | 627 | ||
| 628 | #define ECRYPTFS_INTERPOSE_FLAG_D_ADD 0x00000001 | 628 | struct inode *ecryptfs_get_inode(struct inode *lower_inode, |
| 629 | int ecryptfs_interpose(struct dentry *hidden_dentry, | 629 | struct super_block *sb); |
| 630 | struct dentry *this_dentry, struct super_block *sb, | ||
| 631 | u32 flags); | ||
| 632 | void ecryptfs_i_size_init(const char *page_virt, struct inode *inode); | 630 | void ecryptfs_i_size_init(const char *page_virt, struct inode *inode); |
| 633 | int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | 631 | int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, |
| 634 | struct dentry *lower_dentry, | 632 | struct dentry *lower_dentry, |
| @@ -679,9 +677,6 @@ int | |||
| 679 | ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, | 677 | ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, |
| 680 | unsigned char *src, struct dentry *ecryptfs_dentry); | 678 | unsigned char *src, struct dentry *ecryptfs_dentry); |
| 681 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length); | 679 | 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); | ||
| 685 | ssize_t | 680 | ssize_t |
| 686 | ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, | 681 | ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, |
| 687 | void *value, size_t size); | 682 | void *value, size_t size); |
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 | ||
| 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 | |||
| 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 | ||
| 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 | |||
| 1097 | const struct inode_operations ecryptfs_symlink_iops = { | 1171 | const 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, |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index 89b93389af8e..7c697abab396 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
| @@ -168,75 +168,6 @@ void ecryptfs_put_lower_file(struct inode *inode) | |||
| 168 | } | 168 | } |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 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 | |||
| 240 | enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, | 171 | enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, |
| 241 | ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher, | 172 | ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher, |
| 242 | ecryptfs_opt_ecryptfs_key_bytes, | 173 | ecryptfs_opt_ecryptfs_key_bytes, |
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c index 245b517bf1b6..dbd52d40df4c 100644 --- a/fs/ecryptfs/super.c +++ b/fs/ecryptfs/super.c | |||
| @@ -93,22 +93,6 @@ static void ecryptfs_destroy_inode(struct inode *inode) | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | /** | 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 | |||
| 111 | /** | ||
| 112 | * ecryptfs_statfs | 96 | * ecryptfs_statfs |
| 113 | * @sb: The ecryptfs super block | 97 | * @sb: The ecryptfs super block |
| 114 | * @buf: The struct kstatfs to fill in with stats | 98 | * @buf: The struct kstatfs to fill in with stats |
