mmap.c (fed8859b3ab94274c986cbdf7d27130e0545f02c) mmap.c (57db4e8d73ef2b5e94a3f412108dff2576670a8a)
1/**
2 * eCryptfs: Linux filesystem encryption layer
3 * This is where eCryptfs coordinates the symmetric encryption and
4 * decryption of the file data as it passes between the lower
5 * encrypted file and the upper decrypted file.
6 *
7 * Copyright (C) 1997-2003 Erez Zadok
8 * Copyright (C) 2001-2003 Stony Brook University

--- 48 unchanged lines hidden (view full) ---

57 * @page: Page that is locked before this call is made
58 *
59 * Returns zero on success; non-zero otherwise
60 */
61static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
62{
63 int rc;
64
1/**
2 * eCryptfs: Linux filesystem encryption layer
3 * This is where eCryptfs coordinates the symmetric encryption and
4 * decryption of the file data as it passes between the lower
5 * encrypted file and the upper decrypted file.
6 *
7 * Copyright (C) 1997-2003 Erez Zadok
8 * Copyright (C) 2001-2003 Stony Brook University

--- 48 unchanged lines hidden (view full) ---

57 * @page: Page that is locked before this call is made
58 *
59 * Returns zero on success; non-zero otherwise
60 */
61static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
62{
63 int rc;
64
65 /*
66 * Refuse to write the page out if we are called from reclaim context
67 * since our writepage() path may potentially allocate memory when
68 * calling into the lower fs vfs_write() which may in turn invoke
69 * us again.
70 */
71 if (current->flags & PF_MEMALLOC) {
72 redirty_page_for_writepage(wbc, page);
73 rc = 0;
74 goto out;
75 }
76
65 rc = ecryptfs_encrypt_page(page);
66 if (rc) {
67 ecryptfs_printk(KERN_WARNING, "Error encrypting "
68 "page (upper index [0x%.16lx])\n", page->index);
69 ClearPageUptodate(page);
70 goto out;
71 }
72 SetPageUptodate(page);
77 rc = ecryptfs_encrypt_page(page);
78 if (rc) {
79 ecryptfs_printk(KERN_WARNING, "Error encrypting "
80 "page (upper index [0x%.16lx])\n", page->index);
81 ClearPageUptodate(page);
82 goto out;
83 }
84 SetPageUptodate(page);
73 unlock_page(page);
74out:
85out:
86 unlock_page(page);
75 return rc;
76}
77
78static void strip_xattr_flag(char *page_virt,
79 struct ecryptfs_crypt_stat *crypt_stat)
80{
81 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
82 size_t written;

--- 393 unchanged lines hidden (view full) ---

476{
477 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
478 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
479 unsigned to = from + copied;
480 struct inode *ecryptfs_inode = mapping->host;
481 struct ecryptfs_crypt_stat *crypt_stat =
482 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
483 int rc;
87 return rc;
88}
89
90static void strip_xattr_flag(char *page_virt,
91 struct ecryptfs_crypt_stat *crypt_stat)
92{
93 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
94 size_t written;

--- 393 unchanged lines hidden (view full) ---

488{
489 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
490 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
491 unsigned to = from + copied;
492 struct inode *ecryptfs_inode = mapping->host;
493 struct ecryptfs_crypt_stat *crypt_stat =
494 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
495 int rc;
496 int need_unlock_page = 1;
484
485 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
486 "(page w/ index = [0x%.16lx], to = [%d])\n", index, to);
487 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
488 rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0,
489 to);
490 if (!rc) {
491 rc = copied;

--- 4 unchanged lines hidden (view full) ---

496 }
497 /* Fills in zeros if 'to' goes beyond inode size */
498 rc = fill_zeros_to_end_of_page(page, to);
499 if (rc) {
500 ecryptfs_printk(KERN_WARNING, "Error attempting to fill "
501 "zeros in page with index = [0x%.16lx]\n", index);
502 goto out;
503 }
497
498 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
499 "(page w/ index = [0x%.16lx], to = [%d])\n", index, to);
500 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
501 rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0,
502 to);
503 if (!rc) {
504 rc = copied;

--- 4 unchanged lines hidden (view full) ---

509 }
510 /* Fills in zeros if 'to' goes beyond inode size */
511 rc = fill_zeros_to_end_of_page(page, to);
512 if (rc) {
513 ecryptfs_printk(KERN_WARNING, "Error attempting to fill "
514 "zeros in page with index = [0x%.16lx]\n", index);
515 goto out;
516 }
504 rc = ecryptfs_encrypt_page(page);
505 if (rc) {
506 ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper "
507 "index [0x%.16lx])\n", index);
508 goto out;
509 }
517 set_page_dirty(page);
518 unlock_page(page);
519 need_unlock_page = 0;
510 if (pos + copied > i_size_read(ecryptfs_inode)) {
511 i_size_write(ecryptfs_inode, pos + copied);
512 ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
513 "[0x%.16llx]\n",
514 (unsigned long long)i_size_read(ecryptfs_inode));
520 if (pos + copied > i_size_read(ecryptfs_inode)) {
521 i_size_write(ecryptfs_inode, pos + copied);
522 ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
523 "[0x%.16llx]\n",
524 (unsigned long long)i_size_read(ecryptfs_inode));
525 balance_dirty_pages_ratelimited(mapping);
526 rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
527 if (rc) {
528 printk(KERN_ERR "Error writing inode size to metadata; "
529 "rc = [%d]\n", rc);
530 goto out;
531 }
515 }
532 }
516 rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
517 if (rc)
518 printk(KERN_ERR "Error writing inode size to metadata; "
519 "rc = [%d]\n", rc);
520 else
521 rc = copied;
533 rc = copied;
522out:
534out:
523 unlock_page(page);
535 if (need_unlock_page)
536 unlock_page(page);
524 page_cache_release(page);
525 return rc;
526}
527
528static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block)
529{
530 int rc = 0;
531 struct inode *inode;

--- 17 unchanged lines hidden ---
537 page_cache_release(page);
538 return rc;
539}
540
541static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block)
542{
543 int rc = 0;
544 struct inode *inode;

--- 17 unchanged lines hidden ---