Lines Matching +full:page +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Copyright (C) 1997-2003 Erez Zadok
9 * Copyright (C) 2001-2003 Stony Brook University
10 * Copyright (C) 2004-2007 International Business Machines Corp.
16 #include <linux/page-flags.h>
28 * Get one page from cache or lower f/s, return error otherwise.
30 * Returns locked and up-to-date page (if ok), with increased
33 struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index) in ecryptfs_get_locked_page()
35 struct page *page = read_mapping_page(inode->i_mapping, index, NULL); in ecryptfs_get_locked_page() local
36 if (!IS_ERR(page)) in ecryptfs_get_locked_page()
37 lock_page(page); in ecryptfs_get_locked_page()
38 return page; in ecryptfs_get_locked_page()
43 * @page: Page that is locked before this call is made
44 * @wbc: Write-back control structure
46 * Returns zero on success; non-zero otherwise
49 * the lower filesystem. In OpenPGP-compatible mode, we operate on
52 static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc) in ecryptfs_writepage() argument
56 rc = ecryptfs_encrypt_page(page); in ecryptfs_writepage()
59 "page (upper index [0x%.16lx])\n", page->index); in ecryptfs_writepage()
60 ClearPageUptodate(page); in ecryptfs_writepage()
63 SetPageUptodate(page); in ecryptfs_writepage()
65 unlock_page(page); in ecryptfs_writepage()
72 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { in strip_xattr_flag()
75 crypt_stat->flags &= ~ECRYPTFS_METADATA_IN_XATTR; in strip_xattr_flag()
78 crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; in strip_xattr_flag()
84 * Octets 0-7: Unencrypted file size (big-endian)
85 * Octets 8-15: eCryptfs special marker
86 * Octets 16-19: Flags
88 * Octets 17-18: Reserved
91 * Bits 3-8: Reserved
92 * Octets 20-23: Header extent size (big-endian)
93 * Octets 24-25: Number of header extents at front of file
94 * (big-endian)
100 * @page: Sort of a ``virtual'' representation of the encrypted lower
109 ecryptfs_copy_up_encrypted_with_header(struct page *page, in ecryptfs_copy_up_encrypted_with_header() argument
114 / crypt_stat->extent_size); in ecryptfs_copy_up_encrypted_with_header()
118 loff_t view_extent_num = ((((loff_t)page->index) in ecryptfs_copy_up_encrypted_with_header()
122 (crypt_stat->metadata_size / crypt_stat->extent_size); in ecryptfs_copy_up_encrypted_with_header()
128 page_virt = kmap_atomic(page); in ecryptfs_copy_up_encrypted_with_header()
135 page_virt, page->mapping->host); in ecryptfs_copy_up_encrypted_with_header()
142 flush_dcache_page(page); in ecryptfs_copy_up_encrypted_with_header()
151 ((view_extent_num * crypt_stat->extent_size) in ecryptfs_copy_up_encrypted_with_header()
152 - crypt_stat->metadata_size); in ecryptfs_copy_up_encrypted_with_header()
155 page, (lower_offset >> PAGE_SHIFT), in ecryptfs_copy_up_encrypted_with_header()
157 crypt_stat->extent_size, page->mapping->host); in ecryptfs_copy_up_encrypted_with_header()
179 * Returns zero on success; non-zero on error.
183 struct page *page = &folio->page; in ecryptfs_read_folio() local
185 &ecryptfs_inode_to_private(page->mapping->host)->crypt_stat; in ecryptfs_read_folio()
188 if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { in ecryptfs_read_folio()
189 rc = ecryptfs_read_lower_page_segment(page, page->index, 0, in ecryptfs_read_folio()
191 page->mapping->host); in ecryptfs_read_folio()
192 } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) { in ecryptfs_read_folio()
193 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { in ecryptfs_read_folio()
194 rc = ecryptfs_copy_up_encrypted_with_header(page, in ecryptfs_read_folio()
207 page, page->index, 0, PAGE_SIZE, in ecryptfs_read_folio()
208 page->mapping->host); in ecryptfs_read_folio()
210 printk(KERN_ERR "Error reading page; rc = " in ecryptfs_read_folio()
216 rc = ecryptfs_decrypt_page(page); in ecryptfs_read_folio()
218 ecryptfs_printk(KERN_ERR, "Error decrypting page; " in ecryptfs_read_folio()
225 ClearPageUptodate(page); in ecryptfs_read_folio()
227 SetPageUptodate(page); in ecryptfs_read_folio()
228 ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16lx]\n", in ecryptfs_read_folio()
229 page->index); in ecryptfs_read_folio()
230 unlock_page(page); in ecryptfs_read_folio()
237 static int fill_zeros_to_end_of_page(struct page *page, unsigned int to) in fill_zeros_to_end_of_page() argument
239 struct inode *inode = page->mapping->host; in fill_zeros_to_end_of_page()
242 if ((i_size_read(inode) / PAGE_SIZE) != page->index) in fill_zeros_to_end_of_page()
247 zero_user_segment(page, end_byte_in_page, PAGE_SIZE); in fill_zeros_to_end_of_page()
259 * @pagep: Pointer to return the page
264 * Returns zero on success; non-zero otherwise
269 struct page **pagep, void **fsdata) in ecryptfs_write_begin()
272 struct page *page; in ecryptfs_write_begin() local
276 page = grab_cache_page_write_begin(mapping, index); in ecryptfs_write_begin()
277 if (!page) in ecryptfs_write_begin()
278 return -ENOMEM; in ecryptfs_write_begin()
279 *pagep = page; in ecryptfs_write_begin()
282 if (!PageUptodate(page)) { in ecryptfs_write_begin()
284 &ecryptfs_inode_to_private(mapping->host)->crypt_stat; in ecryptfs_write_begin()
286 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { in ecryptfs_write_begin()
288 page, index, 0, PAGE_SIZE, mapping->host); in ecryptfs_write_begin()
291 "lower page segment; rc = [%d]\n", in ecryptfs_write_begin()
293 ClearPageUptodate(page); in ecryptfs_write_begin()
296 SetPageUptodate(page); in ecryptfs_write_begin()
297 } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) { in ecryptfs_write_begin()
298 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { in ecryptfs_write_begin()
300 page, crypt_stat); in ecryptfs_write_begin()
308 ClearPageUptodate(page); in ecryptfs_write_begin()
311 SetPageUptodate(page); in ecryptfs_write_begin()
314 page, index, 0, PAGE_SIZE, in ecryptfs_write_begin()
315 mapping->host); in ecryptfs_write_begin()
318 "page; rc = [%d]\n", in ecryptfs_write_begin()
320 ClearPageUptodate(page); in ecryptfs_write_begin()
323 SetPageUptodate(page); in ecryptfs_write_begin()
327 >= i_size_read(page->mapping->host)) { in ecryptfs_write_begin()
328 zero_user(page, 0, PAGE_SIZE); in ecryptfs_write_begin()
329 SetPageUptodate(page); in ecryptfs_write_begin()
331 rc = ecryptfs_decrypt_page(page); in ecryptfs_write_begin()
334 "page at index [%ld]; " in ecryptfs_write_begin()
336 __func__, page->index, rc); in ecryptfs_write_begin()
337 ClearPageUptodate(page); in ecryptfs_write_begin()
340 SetPageUptodate(page); in ecryptfs_write_begin()
344 /* If creating a page or more of holes, zero them out via truncate. in ecryptfs_write_begin()
347 if (prev_page_end_size > i_size_read(page->mapping->host)) { in ecryptfs_write_begin()
348 rc = ecryptfs_truncate(file->f_path.dentry, in ecryptfs_write_begin()
359 /* Writing to a new page, and creating a small hole from start in ecryptfs_write_begin()
360 * of page? Zero it out. */ in ecryptfs_write_begin()
361 if ((i_size_read(mapping->host) == prev_page_end_size) in ecryptfs_write_begin()
363 zero_user(page, 0, PAGE_SIZE); in ecryptfs_write_begin()
366 unlock_page(page); in ecryptfs_write_begin()
367 put_page(page); in ecryptfs_write_begin()
376 * Writes the lower file size to the first 8 bytes of the header.
378 * Returns zero on success; non-zero on error.
387 rc = -ENOMEM; in ecryptfs_write_inode_size_to_header()
395 printk(KERN_ERR "%s: Error writing file size to header; " in ecryptfs_write_inode_size_to_header()
407 ssize_t size; in ecryptfs_write_inode_size_to_xattr() local
410 ecryptfs_inode_to_private(ecryptfs_inode)->lower_file->f_path.dentry; in ecryptfs_write_inode_size_to_xattr()
414 if (!(lower_inode->i_opflags & IOP_XATTR)) { in ecryptfs_write_inode_size_to_xattr()
417 rc = -ENOSYS; in ecryptfs_write_inode_size_to_xattr()
422 rc = -ENOMEM; in ecryptfs_write_inode_size_to_xattr()
426 size = __vfs_getxattr(lower_dentry, lower_inode, ECRYPTFS_XATTR_NAME, in ecryptfs_write_inode_size_to_xattr()
428 if (size < 0) in ecryptfs_write_inode_size_to_xattr()
429 size = 8; in ecryptfs_write_inode_size_to_xattr()
432 ECRYPTFS_XATTR_NAME, xattr_virt, size, 0); in ecryptfs_write_inode_size_to_xattr()
435 printk(KERN_ERR "Error whilst attempting to write inode size " in ecryptfs_write_inode_size_to_xattr()
446 crypt_stat = &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; in ecryptfs_write_inode_size_to_metadata()
447 BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); in ecryptfs_write_inode_size_to_metadata()
448 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) in ecryptfs_write_inode_size_to_metadata()
461 * @page: The eCryptfs page
467 struct page *page, void *fsdata) in ecryptfs_write_end() argument
470 unsigned from = pos & (PAGE_SIZE - 1); in ecryptfs_write_end()
472 struct inode *ecryptfs_inode = mapping->host; in ecryptfs_write_end()
474 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; in ecryptfs_write_end()
478 "(page w/ index = [0x%.16lx], to = [%d])\n", index, to); in ecryptfs_write_end()
479 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { in ecryptfs_write_end()
480 rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0, in ecryptfs_write_end()
489 if (!PageUptodate(page)) { in ecryptfs_write_end()
494 SetPageUptodate(page); in ecryptfs_write_end()
496 /* Fills in zeros if 'to' goes beyond inode size */ in ecryptfs_write_end()
497 rc = fill_zeros_to_end_of_page(page, to); in ecryptfs_write_end()
500 "zeros in page with index = [0x%.16lx]\n", index); in ecryptfs_write_end()
503 rc = ecryptfs_encrypt_page(page); in ecryptfs_write_end()
505 ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper " in ecryptfs_write_end()
511 ecryptfs_printk(KERN_DEBUG, "Expanded file size to " in ecryptfs_write_end()
517 printk(KERN_ERR "Error writing inode size to metadata; " in ecryptfs_write_end()
522 unlock_page(page); in ecryptfs_write_end()
523 put_page(page); in ecryptfs_write_end()
529 struct inode *lower_inode = ecryptfs_inode_to_lower(mapping->host); in ecryptfs_bmap()
544 * address_space_operations without the ->dirty_folio method was