diff options
Diffstat (limited to 'fs/ecryptfs/inode.c')
-rw-r--r-- | fs/ecryptfs/inode.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index c92cc1c00aae..d755455e3bff 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -31,6 +31,7 @@ | |||
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 <linux/fs_stack.h> |
34 | #include <asm/unaligned.h> | ||
34 | #include "ecryptfs_kernel.h" | 35 | #include "ecryptfs_kernel.h" |
35 | 36 | ||
36 | static struct dentry *lock_parent(struct dentry *dentry) | 37 | static struct dentry *lock_parent(struct dentry *dentry) |
@@ -188,6 +189,16 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) | |||
188 | "context; rc = [%d]\n", rc); | 189 | "context; rc = [%d]\n", rc); |
189 | goto out; | 190 | goto out; |
190 | } | 191 | } |
192 | if (!ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->lower_file) { | ||
193 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | ||
194 | if (rc) { | ||
195 | printk(KERN_ERR "%s: Error attempting to initialize " | ||
196 | "the persistent file for the dentry with name " | ||
197 | "[%s]; rc = [%d]\n", __func__, | ||
198 | ecryptfs_dentry->d_name.name, rc); | ||
199 | goto out; | ||
200 | } | ||
201 | } | ||
191 | rc = ecryptfs_write_metadata(ecryptfs_dentry); | 202 | rc = ecryptfs_write_metadata(ecryptfs_dentry); |
192 | if (rc) { | 203 | if (rc) { |
193 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); | 204 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); |
@@ -307,10 +318,11 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, | |||
307 | d_add(dentry, NULL); | 318 | d_add(dentry, NULL); |
308 | goto out; | 319 | goto out; |
309 | } | 320 | } |
310 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 1); | 321 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, |
322 | ECRYPTFS_INTERPOSE_FLAG_D_ADD); | ||
311 | if (rc) { | 323 | if (rc) { |
312 | ecryptfs_printk(KERN_ERR, "Error interposing\n"); | 324 | ecryptfs_printk(KERN_ERR, "Error interposing\n"); |
313 | goto out_dput; | 325 | goto out; |
314 | } | 326 | } |
315 | if (S_ISDIR(lower_inode->i_mode)) { | 327 | if (S_ISDIR(lower_inode->i_mode)) { |
316 | ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n"); | 328 | ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n"); |
@@ -336,11 +348,21 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, | |||
336 | rc = -ENOMEM; | 348 | rc = -ENOMEM; |
337 | ecryptfs_printk(KERN_ERR, | 349 | ecryptfs_printk(KERN_ERR, |
338 | "Cannot ecryptfs_kmalloc a page\n"); | 350 | "Cannot ecryptfs_kmalloc a page\n"); |
339 | goto out_dput; | 351 | goto out; |
340 | } | 352 | } |
341 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; | 353 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
342 | if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) | 354 | if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) |
343 | ecryptfs_set_default_sizes(crypt_stat); | 355 | ecryptfs_set_default_sizes(crypt_stat); |
356 | if (!ecryptfs_inode_to_private(dentry->d_inode)->lower_file) { | ||
357 | rc = ecryptfs_init_persistent_file(dentry); | ||
358 | if (rc) { | ||
359 | printk(KERN_ERR "%s: Error attempting to initialize " | ||
360 | "the persistent file for the dentry with name " | ||
361 | "[%s]; rc = [%d]\n", __func__, | ||
362 | dentry->d_name.name, rc); | ||
363 | goto out; | ||
364 | } | ||
365 | } | ||
344 | rc = ecryptfs_read_and_validate_header_region(page_virt, | 366 | rc = ecryptfs_read_and_validate_header_region(page_virt, |
345 | dentry->d_inode); | 367 | dentry->d_inode); |
346 | if (rc) { | 368 | if (rc) { |
@@ -364,8 +386,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, | |||
364 | else | 386 | else |
365 | file_size = i_size_read(lower_dentry->d_inode); | 387 | file_size = i_size_read(lower_dentry->d_inode); |
366 | } else { | 388 | } else { |
367 | memcpy(&file_size, page_virt, sizeof(file_size)); | 389 | file_size = get_unaligned_be64(page_virt); |
368 | file_size = be64_to_cpu(file_size); | ||
369 | } | 390 | } |
370 | i_size_write(dentry->d_inode, (loff_t)file_size); | 391 | i_size_write(dentry->d_inode, (loff_t)file_size); |
371 | kmem_cache_free(ecryptfs_header_cache_2, page_virt); | 392 | kmem_cache_free(ecryptfs_header_cache_2, page_virt); |