mmap.c (681e4a5e13c1c8315694eb4f44e0cdd84c9082d2) mmap.c (821f7494a77627fb1ab539591c57b22cdca702d6)
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

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

61 * This is where we encrypt the data and pass the encrypted data to
62 * the lower filesystem. In OpenPGP-compatible mode, we operate on
63 * entire underlying packets.
64 */
65static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
66{
67 int rc;
68
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

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

61 * This is where we encrypt the data and pass the encrypted data to
62 * the lower filesystem. In OpenPGP-compatible mode, we operate on
63 * entire underlying packets.
64 */
65static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
66{
67 int rc;
68
69 /*
70 * Refuse to write the page out if we are called from reclaim context
71 * since our writepage() path may potentially allocate memory when
72 * calling into the lower fs vfs_write() which may in turn invoke
73 * us again.
74 */
75 if (current->flags & PF_MEMALLOC) {
76 redirty_page_for_writepage(wbc, page);
77 rc = 0;
78 goto out;
79 }
80
81 rc = ecryptfs_encrypt_page(page);
82 if (rc) {
83 ecryptfs_printk(KERN_WARNING, "Error encrypting "
84 "page (upper index [0x%.16lx])\n", page->index);
85 ClearPageUptodate(page);
86 goto out;
87 }
88 SetPageUptodate(page);

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

493{
494 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
495 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
496 unsigned to = from + copied;
497 struct inode *ecryptfs_inode = mapping->host;
498 struct ecryptfs_crypt_stat *crypt_stat =
499 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
500 int rc;
69 rc = ecryptfs_encrypt_page(page);
70 if (rc) {
71 ecryptfs_printk(KERN_WARNING, "Error encrypting "
72 "page (upper index [0x%.16lx])\n", page->index);
73 ClearPageUptodate(page);
74 goto out;
75 }
76 SetPageUptodate(page);

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

481{
482 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
483 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
484 unsigned to = from + copied;
485 struct inode *ecryptfs_inode = mapping->host;
486 struct ecryptfs_crypt_stat *crypt_stat =
487 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
488 int rc;
501 int need_unlock_page = 1;
502
503 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
504 "(page w/ index = [0x%.16lx], to = [%d])\n", index, to);
505 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
506 rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0,
507 to);
508 if (!rc) {
509 rc = copied;

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

514 }
515 /* Fills in zeros if 'to' goes beyond inode size */
516 rc = fill_zeros_to_end_of_page(page, to);
517 if (rc) {
518 ecryptfs_printk(KERN_WARNING, "Error attempting to fill "
519 "zeros in page with index = [0x%.16lx]\n", index);
520 goto out;
521 }
489
490 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
491 "(page w/ index = [0x%.16lx], to = [%d])\n", index, to);
492 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
493 rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0,
494 to);
495 if (!rc) {
496 rc = copied;

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

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

--- 17 unchanged lines hidden ---
529 page_cache_release(page);
530 return rc;
531}
532
533static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block)
534{
535 int rc = 0;
536 struct inode *inode;

--- 17 unchanged lines hidden ---