diff options
Diffstat (limited to 'fs/ecryptfs/inode.c')
-rw-r--r-- | fs/ecryptfs/inode.c | 101 |
1 files changed, 45 insertions, 56 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index c746b5d8a336..a29dc31965fa 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -153,37 +153,30 @@ out: | |||
153 | 153 | ||
154 | /** | 154 | /** |
155 | * grow_file | 155 | * grow_file |
156 | * @ecryptfs_dentry: the ecryptfs dentry | 156 | * @ecryptfs_dentry: the eCryptfs dentry |
157 | * @lower_file: The lower file | ||
158 | * @inode: The ecryptfs inode | ||
159 | * @lower_inode: The lower inode | ||
160 | * | 157 | * |
161 | * This is the code which will grow the file to its correct size. | 158 | * This is the code which will grow the file to its correct size. |
162 | */ | 159 | */ |
163 | static int grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file, | 160 | static int grow_file(struct dentry *ecryptfs_dentry) |
164 | struct inode *inode, struct inode *lower_inode) | ||
165 | { | 161 | { |
166 | int rc = 0; | 162 | struct inode *ecryptfs_inode = ecryptfs_dentry->d_inode; |
167 | struct file fake_file; | 163 | struct file fake_file; |
168 | struct ecryptfs_file_info tmp_file_info; | 164 | struct ecryptfs_file_info tmp_file_info; |
165 | char zero_virt[] = { 0x00 }; | ||
166 | int rc = 0; | ||
169 | 167 | ||
170 | memset(&fake_file, 0, sizeof(fake_file)); | 168 | memset(&fake_file, 0, sizeof(fake_file)); |
171 | fake_file.f_path.dentry = ecryptfs_dentry; | 169 | fake_file.f_path.dentry = ecryptfs_dentry; |
172 | memset(&tmp_file_info, 0, sizeof(tmp_file_info)); | 170 | memset(&tmp_file_info, 0, sizeof(tmp_file_info)); |
173 | ecryptfs_set_file_private(&fake_file, &tmp_file_info); | 171 | ecryptfs_set_file_private(&fake_file, &tmp_file_info); |
174 | ecryptfs_set_file_lower(&fake_file, lower_file); | 172 | ecryptfs_set_file_lower( |
175 | rc = ecryptfs_fill_zeros(&fake_file, 1); | 173 | &fake_file, |
176 | if (rc) { | 174 | ecryptfs_inode_to_private(ecryptfs_inode)->lower_file); |
177 | ecryptfs_inode_to_private(inode)->crypt_stat.flags |= | 175 | rc = ecryptfs_write(&fake_file, zero_virt, 0, 1); |
178 | ECRYPTFS_SECURITY_WARNING; | 176 | i_size_write(ecryptfs_inode, 0); |
179 | ecryptfs_printk(KERN_WARNING, "Error attempting to fill zeros " | 177 | rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode); |
180 | "in file; rc = [%d]\n", rc); | 178 | ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat.flags |= |
181 | goto out; | 179 | ECRYPTFS_NEW_FILE; |
182 | } | ||
183 | i_size_write(inode, 0); | ||
184 | rc = ecryptfs_write_inode_size_to_metadata(inode); | ||
185 | ecryptfs_inode_to_private(inode)->crypt_stat.flags |= ECRYPTFS_NEW_FILE; | ||
186 | out: | ||
187 | return rc; | 180 | return rc; |
188 | } | 181 | } |
189 | 182 | ||
@@ -197,53 +190,31 @@ out: | |||
197 | */ | 190 | */ |
198 | static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) | 191 | static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) |
199 | { | 192 | { |
193 | struct ecryptfs_crypt_stat *crypt_stat = | ||
194 | &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat; | ||
200 | int rc = 0; | 195 | int rc = 0; |
201 | int lower_flags; | ||
202 | struct ecryptfs_crypt_stat *crypt_stat; | ||
203 | struct dentry *lower_dentry; | ||
204 | struct file *lower_file; | ||
205 | struct inode *inode, *lower_inode; | ||
206 | struct vfsmount *lower_mnt; | ||
207 | 196 | ||
208 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); | ||
209 | ecryptfs_printk(KERN_DEBUG, "lower_dentry->d_name.name = [%s]\n", | ||
210 | lower_dentry->d_name.name); | ||
211 | inode = ecryptfs_dentry->d_inode; | ||
212 | crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat; | ||
213 | lower_flags = ((O_CREAT | O_TRUNC) & O_ACCMODE) | O_RDWR; | ||
214 | lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry); | ||
215 | /* Corresponding fput() at end of this function */ | ||
216 | rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, | ||
217 | lower_flags); | ||
218 | if (rc) { | ||
219 | ecryptfs_printk(KERN_ERR, | ||
220 | "Error opening dentry; rc = [%i]\n", rc); | ||
221 | goto out; | ||
222 | } | ||
223 | lower_inode = lower_dentry->d_inode; | ||
224 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { | 197 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { |
225 | ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); | 198 | ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); |
226 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); | 199 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); |
227 | goto out_fput; | 200 | goto out; |
228 | } | 201 | } |
229 | crypt_stat->flags |= ECRYPTFS_NEW_FILE; | 202 | crypt_stat->flags |= ECRYPTFS_NEW_FILE; |
230 | ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n"); | 203 | ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n"); |
231 | rc = ecryptfs_new_file_context(ecryptfs_dentry); | 204 | rc = ecryptfs_new_file_context(ecryptfs_dentry); |
232 | if (rc) { | 205 | if (rc) { |
233 | ecryptfs_printk(KERN_DEBUG, "Error creating new file " | 206 | ecryptfs_printk(KERN_ERR, "Error creating new file " |
234 | "context\n"); | 207 | "context; rc = [%d]\n", rc); |
235 | goto out_fput; | 208 | goto out; |
236 | } | 209 | } |
237 | rc = ecryptfs_write_metadata(ecryptfs_dentry, lower_file); | 210 | rc = ecryptfs_write_metadata(ecryptfs_dentry); |
238 | if (rc) { | 211 | if (rc) { |
239 | ecryptfs_printk(KERN_DEBUG, "Error writing headers\n"); | 212 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); |
240 | goto out_fput; | 213 | goto out; |
241 | } | 214 | } |
242 | rc = grow_file(ecryptfs_dentry, lower_file, inode, lower_inode); | 215 | rc = grow_file(ecryptfs_dentry); |
243 | out_fput: | ||
244 | rc = ecryptfs_close_lower_file(lower_file); | ||
245 | if (rc) | 216 | if (rc) |
246 | printk(KERN_ERR "Error closing lower_file\n"); | 217 | printk(KERN_ERR "Error growing file; rc = [%d]\n", rc); |
247 | out: | 218 | out: |
248 | return rc; | 219 | return rc; |
249 | } | 220 | } |
@@ -389,8 +360,8 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, | |||
389 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; | 360 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
390 | if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) | 361 | if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) |
391 | ecryptfs_set_default_sizes(crypt_stat); | 362 | ecryptfs_set_default_sizes(crypt_stat); |
392 | rc = ecryptfs_read_and_validate_header_region(page_virt, lower_dentry, | 363 | rc = ecryptfs_read_and_validate_header_region(page_virt, |
393 | nd->mnt); | 364 | dentry->d_inode); |
394 | if (rc) { | 365 | if (rc) { |
395 | rc = ecryptfs_read_and_validate_xattr_region(page_virt, dentry); | 366 | rc = ecryptfs_read_and_validate_xattr_region(page_virt, dentry); |
396 | if (rc) { | 367 | if (rc) { |
@@ -941,7 +912,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
941 | } | 912 | } |
942 | mount_crypt_stat = &ecryptfs_superblock_to_private( | 913 | mount_crypt_stat = &ecryptfs_superblock_to_private( |
943 | dentry->d_sb)->mount_crypt_stat; | 914 | dentry->d_sb)->mount_crypt_stat; |
944 | rc = ecryptfs_read_metadata(dentry, lower_file); | 915 | rc = ecryptfs_read_metadata(dentry); |
945 | if (rc) { | 916 | if (rc) { |
946 | if (!(mount_crypt_stat->flags | 917 | if (!(mount_crypt_stat->flags |
947 | & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { | 918 | & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { |
@@ -1003,6 +974,24 @@ out: | |||
1003 | } | 974 | } |
1004 | 975 | ||
1005 | ssize_t | 976 | ssize_t |
977 | ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, | ||
978 | void *value, size_t size) | ||
979 | { | ||
980 | int rc = 0; | ||
981 | |||
982 | if (!lower_dentry->d_inode->i_op->getxattr) { | ||
983 | rc = -ENOSYS; | ||
984 | goto out; | ||
985 | } | ||
986 | mutex_lock(&lower_dentry->d_inode->i_mutex); | ||
987 | rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value, | ||
988 | size); | ||
989 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | ||
990 | out: | ||
991 | return rc; | ||
992 | } | ||
993 | |||
994 | ssize_t | ||
1006 | ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value, | 995 | ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value, |
1007 | size_t size) | 996 | size_t size) |
1008 | { | 997 | { |