mmap.c (f838bad1b3be8ca0c785ee0e0c570dfda74cf377) mmap.c (18d1dbf1d401e8f9d74cf1cf799fdb19cff150c6)
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

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

148 rc = ecryptfs_read_xattr_region(
149 page_virt, page->mapping->host);
150 set_header_info(page_virt, crypt_stat);
151 }
152 kunmap_atomic(page_virt, KM_USER0);
153 flush_dcache_page(page);
154 if (rc) {
155 printk(KERN_ERR "%s: Error reading xattr "
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

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

148 rc = ecryptfs_read_xattr_region(
149 page_virt, page->mapping->host);
150 set_header_info(page_virt, crypt_stat);
151 }
152 kunmap_atomic(page_virt, KM_USER0);
153 flush_dcache_page(page);
154 if (rc) {
155 printk(KERN_ERR "%s: Error reading xattr "
156 "region; rc = [%d]\n", __FUNCTION__, rc);
156 "region; rc = [%d]\n", __func__, rc);
157 goto out;
158 }
159 } else {
160 /* This is an encrypted data extent */
161 loff_t lower_offset =
162 ((view_extent_num * crypt_stat->extent_size)
163 - crypt_stat->num_header_bytes_at_front);
164
165 rc = ecryptfs_read_lower_page_segment(
166 page, (lower_offset >> PAGE_CACHE_SHIFT),
167 (lower_offset & ~PAGE_CACHE_MASK),
168 crypt_stat->extent_size, page->mapping->host);
169 if (rc) {
170 printk(KERN_ERR "%s: Error attempting to read "
171 "extent at offset [%lld] in the lower "
157 goto out;
158 }
159 } else {
160 /* This is an encrypted data extent */
161 loff_t lower_offset =
162 ((view_extent_num * crypt_stat->extent_size)
163 - crypt_stat->num_header_bytes_at_front);
164
165 rc = ecryptfs_read_lower_page_segment(
166 page, (lower_offset >> PAGE_CACHE_SHIFT),
167 (lower_offset & ~PAGE_CACHE_MASK),
168 crypt_stat->extent_size, page->mapping->host);
169 if (rc) {
170 printk(KERN_ERR "%s: Error attempting to read "
171 "extent at offset [%lld] in the lower "
172 "file; rc = [%d]\n", __FUNCTION__,
172 "file; rc = [%d]\n", __func__,
173 lower_offset, rc);
174 goto out;
175 }
176 }
177 extent_num_in_page++;
178 }
179out:
180 return rc;

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

207 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
208 rc = ecryptfs_copy_up_encrypted_with_header(page,
209 crypt_stat);
210 if (rc) {
211 printk(KERN_ERR "%s: Error attempting to copy "
212 "the encrypted content from the lower "
213 "file whilst inserting the metadata "
214 "from the xattr into the header; rc = "
173 lower_offset, rc);
174 goto out;
175 }
176 }
177 extent_num_in_page++;
178 }
179out:
180 return rc;

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

207 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
208 rc = ecryptfs_copy_up_encrypted_with_header(page,
209 crypt_stat);
210 if (rc) {
211 printk(KERN_ERR "%s: Error attempting to copy "
212 "the encrypted content from the lower "
213 "file whilst inserting the metadata "
214 "from the xattr into the header; rc = "
215 "[%d]\n", __FUNCTION__, rc);
215 "[%d]\n", __func__, rc);
216 goto out;
217 }
218
219 } else {
220 rc = ecryptfs_read_lower_page_segment(
221 page, page->index, 0, PAGE_CACHE_SIZE,
222 page->mapping->host);
223 if (rc) {

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

288 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
289 || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
290 rc = ecryptfs_read_lower_page_segment(
291 page, page->index, 0, PAGE_CACHE_SIZE,
292 page->mapping->host);
293 if (rc) {
294 printk(KERN_ERR "%s: Error attemping to read "
295 "lower page segment; rc = [%d]\n",
216 goto out;
217 }
218
219 } else {
220 rc = ecryptfs_read_lower_page_segment(
221 page, page->index, 0, PAGE_CACHE_SIZE,
222 page->mapping->host);
223 if (rc) {

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

288 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
289 || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
290 rc = ecryptfs_read_lower_page_segment(
291 page, page->index, 0, PAGE_CACHE_SIZE,
292 page->mapping->host);
293 if (rc) {
294 printk(KERN_ERR "%s: Error attemping to read "
295 "lower page segment; rc = [%d]\n",
296 __FUNCTION__, rc);
296 __func__, rc);
297 ClearPageUptodate(page);
298 goto out;
299 } else
300 SetPageUptodate(page);
301 } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) {
302 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
303 rc = ecryptfs_copy_up_encrypted_with_header(
304 page, crypt_stat);
305 if (rc) {
306 printk(KERN_ERR "%s: Error attempting "
307 "to copy the encrypted content "
308 "from the lower file whilst "
309 "inserting the metadata from "
310 "the xattr into the header; rc "
297 ClearPageUptodate(page);
298 goto out;
299 } else
300 SetPageUptodate(page);
301 } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) {
302 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
303 rc = ecryptfs_copy_up_encrypted_with_header(
304 page, crypt_stat);
305 if (rc) {
306 printk(KERN_ERR "%s: Error attempting "
307 "to copy the encrypted content "
308 "from the lower file whilst "
309 "inserting the metadata from "
310 "the xattr into the header; rc "
311 "= [%d]\n", __FUNCTION__, rc);
311 "= [%d]\n", __func__, rc);
312 ClearPageUptodate(page);
313 goto out;
314 }
315 SetPageUptodate(page);
316 } else {
317 rc = ecryptfs_read_lower_page_segment(
318 page, page->index, 0, PAGE_CACHE_SIZE,
319 page->mapping->host);
320 if (rc) {
321 printk(KERN_ERR "%s: Error reading "
322 "page; rc = [%d]\n",
312 ClearPageUptodate(page);
313 goto out;
314 }
315 SetPageUptodate(page);
316 } else {
317 rc = ecryptfs_read_lower_page_segment(
318 page, page->index, 0, PAGE_CACHE_SIZE,
319 page->mapping->host);
320 if (rc) {
321 printk(KERN_ERR "%s: Error reading "
322 "page; rc = [%d]\n",
323 __FUNCTION__, rc);
323 __func__, rc);
324 ClearPageUptodate(page);
325 goto out;
326 }
327 SetPageUptodate(page);
328 }
329 } else {
330 rc = ecryptfs_decrypt_page(page);
331 if (rc) {
332 printk(KERN_ERR "%s: Error decrypting page "
333 "at index [%ld]; rc = [%d]\n",
324 ClearPageUptodate(page);
325 goto out;
326 }
327 SetPageUptodate(page);
328 }
329 } else {
330 rc = ecryptfs_decrypt_page(page);
331 if (rc) {
332 printk(KERN_ERR "%s: Error decrypting page "
333 "at index [%ld]; rc = [%d]\n",
334 __FUNCTION__, page->index, rc);
334 __func__, page->index, rc);
335 ClearPageUptodate(page);
336 goto out;
337 }
338 SetPageUptodate(page);
339 }
340 }
341 prev_page_end_size = ((loff_t)page->index << PAGE_CACHE_SHIFT);
342 /* If creating a page or more of holes, zero them out via truncate.
343 * Note, this will increase i_size. */
344 if (page->index != 0) {
345 if (prev_page_end_size > i_size_read(page->mapping->host)) {
346 rc = ecryptfs_truncate(file->f_path.dentry,
347 prev_page_end_size);
348 if (rc) {
349 printk(KERN_ERR "%s: Error on attempt to "
350 "truncate to (higher) offset [%lld];"
335 ClearPageUptodate(page);
336 goto out;
337 }
338 SetPageUptodate(page);
339 }
340 }
341 prev_page_end_size = ((loff_t)page->index << PAGE_CACHE_SHIFT);
342 /* If creating a page or more of holes, zero them out via truncate.
343 * Note, this will increase i_size. */
344 if (page->index != 0) {
345 if (prev_page_end_size > i_size_read(page->mapping->host)) {
346 rc = ecryptfs_truncate(file->f_path.dentry,
347 prev_page_end_size);
348 if (rc) {
349 printk(KERN_ERR "%s: Error on attempt to "
350 "truncate to (higher) offset [%lld];"
351 " rc = [%d]\n", __FUNCTION__,
351 " rc = [%d]\n", __func__,
352 prev_page_end_size, rc);
353 goto out;
354 }
355 }
356 }
357 /* Writing to a new page, and creating a small hole from start
358 * of page? Zero it out. */
359 if ((i_size_read(page->mapping->host) == prev_page_end_size)

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

384 file_size = (u64)i_size_read(ecryptfs_inode);
385 file_size = cpu_to_be64(file_size);
386 memcpy(file_size_virt, &file_size, sizeof(u64));
387 rc = ecryptfs_write_lower(ecryptfs_inode, file_size_virt, 0,
388 sizeof(u64));
389 kfree(file_size_virt);
390 if (rc)
391 printk(KERN_ERR "%s: Error writing file size to header; "
352 prev_page_end_size, rc);
353 goto out;
354 }
355 }
356 }
357 /* Writing to a new page, and creating a small hole from start
358 * of page? Zero it out. */
359 if ((i_size_read(page->mapping->host) == prev_page_end_size)

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

384 file_size = (u64)i_size_read(ecryptfs_inode);
385 file_size = cpu_to_be64(file_size);
386 memcpy(file_size_virt, &file_size, sizeof(u64));
387 rc = ecryptfs_write_lower(ecryptfs_inode, file_size_virt, 0,
388 sizeof(u64));
389 kfree(file_size_virt);
390 if (rc)
391 printk(KERN_ERR "%s: Error writing file size to header; "
392 "rc = [%d]\n", __FUNCTION__, rc);
392 "rc = [%d]\n", __func__, rc);
393out:
394 return rc;
395}
396
397struct kmem_cache *ecryptfs_xattr_cache;
398
399static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
400{

--- 129 unchanged lines hidden ---
393out:
394 return rc;
395}
396
397struct kmem_cache *ecryptfs_xattr_cache;
398
399static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
400{

--- 129 unchanged lines hidden ---