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.
7 * Copyright (C) 1997-2003 Erez Zadok
8 * Copyright (C) 2001-2003 Stony Brook University
9 * Copyright (C) 2004-2007 International Business Machines Corp.
10 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #include <linux/pagemap.h>
29 #include <linux/writeback.h>
30 #include <linux/page-flags.h>
31 #include <linux/mount.h>
32 #include <linux/file.h>
33 #include <linux/crypto.h>
34 #include <linux/scatterlist.h>
35 #include "ecryptfs_kernel.h"
37 struct kmem_cache *ecryptfs_lower_page_cache;
42 * Get one page from cache or lower f/s, return error otherwise.
44 * Returns unlocked and up-to-date page (if ok), with increased
47 static struct page *ecryptfs_get1page(struct file *file, int index)
49 struct dentry *dentry;
51 struct address_space *mapping;
53 dentry = file->f_path.dentry;
54 inode = dentry->d_inode;
55 mapping = inode->i_mapping;
56 return read_mapping_page(mapping, index, (void *)file);
60 int write_zeros(struct file *file, pgoff_t index, int start, int num_zeros);
64 * @file: The ecryptfs file
65 * @new_length: The new length of the data in the underlying file;
66 * everything between the prior end of the file and the
67 * new end of the file will be filled with zero's.
68 * new_length must be greater than current length
70 * Function for handling lseek-ing past the end of the file.
72 * This function does not support shrinking, only growing a file.
74 * Returns zero on success; non-zero otherwise.
76 int ecryptfs_fill_zeros(struct file *file, loff_t new_length)
79 struct dentry *dentry = file->f_path.dentry;
80 struct inode *inode = dentry->d_inode;
81 pgoff_t old_end_page_index = 0;
82 pgoff_t index = old_end_page_index;
83 int old_end_pos_in_page = -1;
84 pgoff_t new_end_page_index;
85 int new_end_pos_in_page;
86 loff_t cur_length = i_size_read(inode);
88 if (cur_length != 0) {
89 index = old_end_page_index =
90 ((cur_length - 1) >> PAGE_CACHE_SHIFT);
91 old_end_pos_in_page = ((cur_length - 1) & ~PAGE_CACHE_MASK);
93 new_end_page_index = ((new_length - 1) >> PAGE_CACHE_SHIFT);
94 new_end_pos_in_page = ((new_length - 1) & ~PAGE_CACHE_MASK);
95 ecryptfs_printk(KERN_DEBUG, "old_end_page_index = [0x%.16x]; "
96 "old_end_pos_in_page = [%d]; "
97 "new_end_page_index = [0x%.16x]; "
98 "new_end_pos_in_page = [%d]\n",
99 old_end_page_index, old_end_pos_in_page,
100 new_end_page_index, new_end_pos_in_page);
101 if (old_end_page_index == new_end_page_index) {
102 /* Start and end are in the same page; we just need to
103 * set a portion of the existing page to zero's */
104 rc = write_zeros(file, index, (old_end_pos_in_page + 1),
105 (new_end_pos_in_page - old_end_pos_in_page));
107 ecryptfs_printk(KERN_ERR, "write_zeros(file=[%p], "
109 "old_end_pos_in_page=[d], "
110 "(PAGE_CACHE_SIZE - new_end_pos_in_page"
112 ")=[d]) returned [%d]\n", file, index,
115 (PAGE_CACHE_SIZE - new_end_pos_in_page),
119 /* Fill the remainder of the previous last page with zeros */
120 rc = write_zeros(file, index, (old_end_pos_in_page + 1),
121 ((PAGE_CACHE_SIZE - 1) - old_end_pos_in_page));
123 ecryptfs_printk(KERN_ERR, "write_zeros(file=[%p], "
124 "index=[0x%.16x], old_end_pos_in_page=[d], "
125 "(PAGE_CACHE_SIZE - old_end_pos_in_page)=[d]) "
126 "returned [%d]\n", file, index,
128 (PAGE_CACHE_SIZE - old_end_pos_in_page), rc);
132 while (index < new_end_page_index) {
133 /* Fill all intermediate pages with zeros */
134 rc = write_zeros(file, index, 0, PAGE_CACHE_SIZE);
136 ecryptfs_printk(KERN_ERR, "write_zeros(file=[%p], "
138 "old_end_pos_in_page=[d], "
139 "(PAGE_CACHE_SIZE - new_end_pos_in_page"
141 ")=[d]) returned [%d]\n", file, index,
144 (PAGE_CACHE_SIZE - new_end_pos_in_page),
150 /* Fill the portion at the beginning of the last new page with
152 rc = write_zeros(file, index, 0, (new_end_pos_in_page + 1));
154 ecryptfs_printk(KERN_ERR, "write_zeros(file="
155 "[%p], index=[0x%.16x], 0, "
156 "new_end_pos_in_page=[%d]"
157 "returned [%d]\n", file, index,
158 new_end_pos_in_page, rc);
167 * @page: Page that is locked before this call is made
169 * Returns zero on success; non-zero otherwise
171 static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
173 struct ecryptfs_page_crypt_context ctx;
177 ctx.mode = ECRYPTFS_WRITEPAGE_MODE;
179 rc = ecryptfs_encrypt_page(&ctx);
181 ecryptfs_printk(KERN_WARNING, "Error encrypting "
182 "page (upper index [0x%.16x])\n", page->index);
183 ClearPageUptodate(page);
186 SetPageUptodate(page);
193 * Reads the data from the lower file file at index lower_page_index
194 * and copies that data into page.
196 * @param page Page to fill
197 * @param lower_page_index Index of the page in the lower file to get
199 int ecryptfs_do_readpage(struct file *file, struct page *page,
200 pgoff_t lower_page_index)
203 struct dentry *dentry;
204 struct file *lower_file;
205 struct dentry *lower_dentry;
207 struct inode *lower_inode;
209 struct page *lower_page = NULL;
210 char *lower_page_data;
211 const struct address_space_operations *lower_a_ops;
213 dentry = file->f_path.dentry;
214 lower_file = ecryptfs_file_to_lower(file);
215 lower_dentry = ecryptfs_dentry_to_lower(dentry);
216 inode = dentry->d_inode;
217 lower_inode = ecryptfs_inode_to_lower(inode);
218 lower_a_ops = lower_inode->i_mapping->a_ops;
219 lower_page = read_cache_page(lower_inode->i_mapping, lower_page_index,
220 (filler_t *)lower_a_ops->readpage,
222 if (IS_ERR(lower_page)) {
223 rc = PTR_ERR(lower_page);
225 ecryptfs_printk(KERN_ERR, "Error reading from page cache\n");
228 page_data = kmap_atomic(page, KM_USER0);
229 lower_page_data = kmap_atomic(lower_page, KM_USER1);
230 memcpy(page_data, lower_page_data, PAGE_CACHE_SIZE);
231 kunmap_atomic(lower_page_data, KM_USER1);
232 kunmap_atomic(page_data, KM_USER0);
233 flush_dcache_page(page);
236 if (likely(lower_page))
237 page_cache_release(lower_page);
239 SetPageUptodate(page);
241 ClearPageUptodate(page);
246 * Octets 0-7: Unencrypted file size (big-endian)
247 * Octets 8-15: eCryptfs special marker
248 * Octets 16-19: Flags
249 * Octet 16: File format version number (between 0 and 255)
250 * Octets 17-18: Reserved
251 * Octet 19: Bit 1 (lsb): Reserved
254 * Octets 20-23: Header extent size (big-endian)
255 * Octets 24-25: Number of header extents at front of file
257 * Octet 26: Begin RFC 2440 authentication token packet set
259 static void set_header_info(char *page_virt,
260 struct ecryptfs_crypt_stat *crypt_stat)
263 int save_num_header_extents_at_front =
264 crypt_stat->num_header_extents_at_front;
266 crypt_stat->num_header_extents_at_front = 1;
267 ecryptfs_write_header_metadata(page_virt + 20, crypt_stat, &written);
268 crypt_stat->num_header_extents_at_front =
269 save_num_header_extents_at_front;
274 * @file: This is an ecryptfs file
275 * @page: ecryptfs associated page to stick the read data into
277 * Read in a page, decrypting if necessary.
279 * Returns zero on success; non-zero on error.
281 static int ecryptfs_readpage(struct file *file, struct page *page)
284 struct ecryptfs_crypt_stat *crypt_stat;
286 BUG_ON(!(file && file->f_path.dentry && file->f_path.dentry->d_inode));
287 crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)
290 || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
291 || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
292 ecryptfs_printk(KERN_DEBUG,
293 "Passing through unencrypted page\n");
294 rc = ecryptfs_do_readpage(file, page, page->index);
296 ecryptfs_printk(KERN_ERR, "Error reading page; rc = "
300 } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) {
301 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
302 int num_pages_in_header_region =
303 (crypt_stat->header_extent_size
306 if (page->index < num_pages_in_header_region) {
309 page_virt = kmap_atomic(page, KM_USER0);
310 memset(page_virt, 0, PAGE_CACHE_SIZE);
311 if (page->index == 0) {
312 rc = ecryptfs_read_xattr_region(
313 page_virt, file->f_path.dentry);
314 set_header_info(page_virt, crypt_stat);
316 kunmap_atomic(page_virt, KM_USER0);
317 flush_dcache_page(page);
319 printk(KERN_ERR "Error reading xattr "
324 rc = ecryptfs_do_readpage(
327 - num_pages_in_header_region));
329 printk(KERN_ERR "Error reading page; "
335 rc = ecryptfs_do_readpage(file, page, page->index);
337 printk(KERN_ERR "Error reading page; rc = "
343 rc = ecryptfs_decrypt_page(file, page);
345 ecryptfs_printk(KERN_ERR, "Error decrypting page; "
350 SetPageUptodate(page);
353 ClearPageUptodate(page);
354 ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16x]\n",
361 * Called with lower inode mutex held.
363 static int fill_zeros_to_end_of_page(struct page *page, unsigned int to)
365 struct inode *inode = page->mapping->host;
366 int end_byte_in_page;
368 if ((i_size_read(inode) / PAGE_CACHE_SIZE) != page->index)
370 end_byte_in_page = i_size_read(inode) % PAGE_CACHE_SIZE;
371 if (to > end_byte_in_page)
372 end_byte_in_page = to;
373 zero_user_page(page, end_byte_in_page,
374 PAGE_CACHE_SIZE - end_byte_in_page, KM_USER0);
380 * eCryptfs does not currently support holes. When writing after a
381 * seek past the end of the file, eCryptfs fills in 0's through to the
382 * current location. The code to fill in the 0's to all the
383 * intermediate pages calls ecryptfs_prepare_write_no_truncate().
386 ecryptfs_prepare_write_no_truncate(struct file *file, struct page *page,
387 unsigned from, unsigned to)
391 if (from == 0 && to == PAGE_CACHE_SIZE)
392 goto out; /* If we are writing a full page, it will be
394 if (!PageUptodate(page))
395 rc = ecryptfs_do_readpage(file, page, page->index);
400 static int ecryptfs_prepare_write(struct file *file, struct page *page,
401 unsigned from, unsigned to)
406 if (from == 0 && to == PAGE_CACHE_SIZE)
407 goto out; /* If we are writing a full page, it will be
409 if (!PageUptodate(page))
410 rc = ecryptfs_do_readpage(file, page, page->index);
411 pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
412 if (pos > i_size_read(page->mapping->host)) {
413 rc = ecryptfs_truncate(file->f_path.dentry, pos);
415 printk(KERN_ERR "Error on attempt to "
416 "truncate to (higher) offset [%lld];"
417 " rc = [%d]\n", pos, rc);
425 int ecryptfs_writepage_and_release_lower_page(struct page *lower_page,
426 struct inode *lower_inode,
427 struct writeback_control *wbc)
431 rc = lower_inode->i_mapping->a_ops->writepage(lower_page, wbc);
433 ecryptfs_printk(KERN_ERR, "Error calling lower writepage(); "
437 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME;
438 page_cache_release(lower_page);
444 void ecryptfs_release_lower_page(struct page *lower_page, int page_locked)
447 unlock_page(lower_page);
448 page_cache_release(lower_page);
452 * ecryptfs_write_inode_size_to_header
454 * Writes the lower file size to the first 8 bytes of the header.
456 * Returns zero on success; non-zero on error.
458 static int ecryptfs_write_inode_size_to_header(struct file *lower_file,
459 struct inode *lower_inode,
463 struct page *header_page;
465 const struct address_space_operations *lower_a_ops;
469 header_page = grab_cache_page(lower_inode->i_mapping, 0);
471 ecryptfs_printk(KERN_ERR, "grab_cache_page for "
472 "lower_page_index 0 failed\n");
476 lower_a_ops = lower_inode->i_mapping->a_ops;
477 rc = lower_a_ops->prepare_write(lower_file, header_page, 0, 8);
479 if (rc == AOP_TRUNCATED_PAGE) {
480 ecryptfs_release_lower_page(header_page, 0);
483 ecryptfs_release_lower_page(header_page, 1);
486 file_size = (u64)i_size_read(inode);
487 ecryptfs_printk(KERN_DEBUG, "Writing size: [0x%.16x]\n", file_size);
488 file_size = cpu_to_be64(file_size);
489 header_virt = kmap_atomic(header_page, KM_USER0);
490 memcpy(header_virt, &file_size, sizeof(u64));
491 kunmap_atomic(header_virt, KM_USER0);
492 flush_dcache_page(header_page);
493 rc = lower_a_ops->commit_write(lower_file, header_page, 0, 8);
495 ecryptfs_printk(KERN_ERR, "Error commiting header page "
497 if (rc == AOP_TRUNCATED_PAGE) {
498 ecryptfs_release_lower_page(header_page, 0);
501 ecryptfs_release_lower_page(header_page, 1);
502 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME;
503 mark_inode_dirty_sync(inode);
508 static int ecryptfs_write_inode_size_to_xattr(struct inode *lower_inode,
510 struct dentry *ecryptfs_dentry,
511 int lower_i_mutex_held)
515 struct dentry *lower_dentry;
519 xattr_virt = kmem_cache_alloc(ecryptfs_xattr_cache, GFP_KERNEL);
521 printk(KERN_ERR "Out of memory whilst attempting to write "
522 "inode size to xattr\n");
526 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
527 if (!lower_dentry->d_inode->i_op->getxattr ||
528 !lower_dentry->d_inode->i_op->setxattr) {
530 "No support for setting xattr in lower filesystem\n");
532 kmem_cache_free(ecryptfs_xattr_cache, xattr_virt);
535 if (!lower_i_mutex_held)
536 mutex_lock(&lower_dentry->d_inode->i_mutex);
537 size = lower_dentry->d_inode->i_op->getxattr(lower_dentry,
541 if (!lower_i_mutex_held)
542 mutex_unlock(&lower_dentry->d_inode->i_mutex);
545 file_size = (u64)i_size_read(inode);
546 file_size = cpu_to_be64(file_size);
547 memcpy(xattr_virt, &file_size, sizeof(u64));
548 if (!lower_i_mutex_held)
549 mutex_lock(&lower_dentry->d_inode->i_mutex);
550 rc = lower_dentry->d_inode->i_op->setxattr(lower_dentry,
552 xattr_virt, size, 0);
553 if (!lower_i_mutex_held)
554 mutex_unlock(&lower_dentry->d_inode->i_mutex);
556 printk(KERN_ERR "Error whilst attempting to write inode size "
557 "to lower file xattr; rc = [%d]\n", rc);
558 kmem_cache_free(ecryptfs_xattr_cache, xattr_virt);
564 ecryptfs_write_inode_size_to_metadata(struct file *lower_file,
565 struct inode *lower_inode,
567 struct dentry *ecryptfs_dentry,
568 int lower_i_mutex_held)
570 struct ecryptfs_crypt_stat *crypt_stat;
572 crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
573 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
574 return ecryptfs_write_inode_size_to_xattr(lower_inode, inode,
578 return ecryptfs_write_inode_size_to_header(lower_file,
583 int ecryptfs_get_lower_page(struct page **lower_page, struct inode *lower_inode,
584 struct file *lower_file,
585 unsigned long lower_page_index, int byte_offset,
591 *lower_page = grab_cache_page(lower_inode->i_mapping, lower_page_index);
592 if (!(*lower_page)) {
594 ecryptfs_printk(KERN_ERR, "Error attempting to grab "
595 "lower page with index [0x%.16x]\n",
599 rc = lower_inode->i_mapping->a_ops->prepare_write(lower_file,
604 if (rc == AOP_TRUNCATED_PAGE) {
605 ecryptfs_release_lower_page(*lower_page, 0);
608 ecryptfs_printk(KERN_ERR, "prepare_write for "
609 "lower_page_index = [0x%.16x] failed; rc = "
610 "[%d]\n", lower_page_index, rc);
611 ecryptfs_release_lower_page(*lower_page, 1);
612 (*lower_page) = NULL;
620 * ecryptfs_commit_lower_page
622 * Returns zero on success; non-zero on error
625 ecryptfs_commit_lower_page(struct page *lower_page, struct inode *lower_inode,
626 struct file *lower_file, int byte_offset,
632 rc = lower_inode->i_mapping->a_ops->commit_write(
633 lower_file, lower_page, byte_offset, region_size);
634 if (rc == AOP_TRUNCATED_PAGE)
637 ecryptfs_printk(KERN_ERR,
638 "Error committing write; rc = [%d]\n", rc);
641 ecryptfs_release_lower_page(lower_page, page_locked);
646 * ecryptfs_copy_page_to_lower
648 * Used for plaintext pass-through; no page index interpolation
651 int ecryptfs_copy_page_to_lower(struct page *page, struct inode *lower_inode,
652 struct file *lower_file)
655 struct page *lower_page;
657 rc = ecryptfs_get_lower_page(&lower_page, lower_inode, lower_file,
658 page->index, 0, PAGE_CACHE_SIZE);
660 ecryptfs_printk(KERN_ERR, "Error attempting to get page "
661 "at index [0x%.16x]\n", page->index);
665 memcpy((char *)page_address(lower_page), page_address(page),
667 rc = ecryptfs_commit_lower_page(lower_page, lower_inode, lower_file,
670 ecryptfs_printk(KERN_ERR, "Error attempting to commit page "
671 "at index [0x%.16x]\n", page->index);
676 struct kmem_cache *ecryptfs_xattr_cache;
679 * ecryptfs_commit_write
680 * @file: The eCryptfs file object
681 * @page: The eCryptfs page
682 * @from: Ignored (we rotate the page IV on each write)
685 * This is where we encrypt the data and pass the encrypted data to
686 * the lower filesystem. In OpenPGP-compatible mode, we operate on
687 * entire underlying packets.
689 static int ecryptfs_commit_write(struct file *file, struct page *page,
690 unsigned from, unsigned to)
692 struct ecryptfs_page_crypt_context ctx;
695 struct inode *lower_inode;
696 struct file *lower_file;
697 struct ecryptfs_crypt_stat *crypt_stat;
700 inode = page->mapping->host;
701 lower_inode = ecryptfs_inode_to_lower(inode);
702 lower_file = ecryptfs_file_to_lower(file);
703 mutex_lock(&lower_inode->i_mutex);
704 crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)
706 if (crypt_stat->flags & ECRYPTFS_NEW_FILE) {
707 ecryptfs_printk(KERN_DEBUG, "ECRYPTFS_NEW_FILE flag set in "
708 "crypt_stat at memory location [%p]\n", crypt_stat);
709 crypt_stat->flags &= ~(ECRYPTFS_NEW_FILE);
711 ecryptfs_printk(KERN_DEBUG, "Not a new file\n");
712 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
713 "(page w/ index = [0x%.16x], to = [%d])\n", page->index,
715 rc = fill_zeros_to_end_of_page(page, to);
717 ecryptfs_printk(KERN_WARNING, "Error attempting to fill "
718 "zeros in page with index = [0x%.16x]\n",
723 ctx.mode = ECRYPTFS_PREPARE_COMMIT_MODE;
724 ctx.param.lower_file = lower_file;
725 rc = ecryptfs_encrypt_page(&ctx);
727 ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper "
728 "index [0x%.16x])\n", page->index);
731 inode->i_blocks = lower_inode->i_blocks;
732 pos = (page->index << PAGE_CACHE_SHIFT) + to;
733 if (pos > i_size_read(inode)) {
734 i_size_write(inode, pos);
735 ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
736 "[0x%.16x]\n", i_size_read(inode));
738 rc = ecryptfs_write_inode_size_to_metadata(lower_file, lower_inode,
739 inode, file->f_dentry,
740 ECRYPTFS_LOWER_I_MUTEX_HELD);
742 printk(KERN_ERR "Error writing inode size to metadata; "
744 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME;
745 mark_inode_dirty_sync(inode);
748 ClearPageUptodate(page);
750 SetPageUptodate(page);
751 mutex_unlock(&lower_inode->i_mutex);
757 * @file: The ecryptfs file
758 * @index: The index in which we are writing
759 * @start: The position after the last block of data
760 * @num_zeros: The number of zeros to write
762 * Write a specified number of zero's to a page.
764 * (start + num_zeros) must be less than or equal to PAGE_CACHE_SIZE
767 int write_zeros(struct file *file, pgoff_t index, int start, int num_zeros)
770 struct page *tmp_page;
772 tmp_page = ecryptfs_get1page(file, index);
773 if (IS_ERR(tmp_page)) {
774 ecryptfs_printk(KERN_ERR, "Error getting page at index "
775 "[0x%.16x]\n", index);
776 rc = PTR_ERR(tmp_page);
779 if ((rc = ecryptfs_prepare_write_no_truncate(file, tmp_page, start,
780 (start + num_zeros)))) {
781 ecryptfs_printk(KERN_ERR, "Error preparing to write zero's "
782 "to page at index [0x%.16x]\n",
784 page_cache_release(tmp_page);
787 zero_user_page(tmp_page, start, num_zeros, KM_USER0);
788 rc = ecryptfs_commit_write(file, tmp_page, start, start + num_zeros);
790 ecryptfs_printk(KERN_ERR, "Error attempting to write zero's "
791 "to remainder of page at index [0x%.16x]\n",
793 page_cache_release(tmp_page);
797 page_cache_release(tmp_page);
802 static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block)
806 struct inode *lower_inode;
808 inode = (struct inode *)mapping->host;
809 lower_inode = ecryptfs_inode_to_lower(inode);
810 if (lower_inode->i_mapping->a_ops->bmap)
811 rc = lower_inode->i_mapping->a_ops->bmap(lower_inode->i_mapping,
816 static void ecryptfs_sync_page(struct page *page)
819 struct inode *lower_inode;
820 struct page *lower_page;
822 inode = page->mapping->host;
823 lower_inode = ecryptfs_inode_to_lower(inode);
824 /* NOTE: Recently swapped with grab_cache_page(), since
825 * sync_page() just makes sure that pending I/O gets done. */
826 lower_page = find_lock_page(lower_inode->i_mapping, page->index);
828 ecryptfs_printk(KERN_DEBUG, "find_lock_page failed\n");
831 lower_page->mapping->a_ops->sync_page(lower_page);
832 ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16x]\n",
834 unlock_page(lower_page);
835 page_cache_release(lower_page);
838 struct address_space_operations ecryptfs_aops = {
839 .writepage = ecryptfs_writepage,
840 .readpage = ecryptfs_readpage,
841 .prepare_write = ecryptfs_prepare_write,
842 .commit_write = ecryptfs_commit_write,
843 .bmap = ecryptfs_bmap,
844 .sync_page = ecryptfs_sync_page,