aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/ecryptfs/crypto.c150
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h21
-rw-r--r--fs/ecryptfs/file.c28
-rw-r--r--fs/ecryptfs/main.c5
-rw-r--r--fs/ecryptfs/mmap.c336
5 files changed, 1 insertions, 539 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 9408ea484164..a9ca373c6107 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -353,119 +353,6 @@ out:
353 return rc; 353 return rc;
354} 354}
355 355
356static void
357ecryptfs_extent_to_lwr_pg_idx_and_offset(unsigned long *lower_page_idx,
358 int *byte_offset,
359 struct ecryptfs_crypt_stat *crypt_stat,
360 unsigned long extent_num)
361{
362 unsigned long lower_extent_num;
363 int extents_occupied_by_headers_at_front;
364 int bytes_occupied_by_headers_at_front;
365 int extent_offset;
366 int extents_per_page;
367
368 bytes_occupied_by_headers_at_front =
369 (crypt_stat->extent_size
370 * crypt_stat->num_header_extents_at_front);
371 extents_occupied_by_headers_at_front =
372 ( bytes_occupied_by_headers_at_front
373 / crypt_stat->extent_size );
374 lower_extent_num = extents_occupied_by_headers_at_front + extent_num;
375 extents_per_page = PAGE_CACHE_SIZE / crypt_stat->extent_size;
376 (*lower_page_idx) = lower_extent_num / extents_per_page;
377 extent_offset = lower_extent_num % extents_per_page;
378 (*byte_offset) = extent_offset * crypt_stat->extent_size;
379 ecryptfs_printk(KERN_DEBUG, " * crypt_stat->extent_size = "
380 "[%d]\n", crypt_stat->extent_size);
381 ecryptfs_printk(KERN_DEBUG, " * crypt_stat->"
382 "num_header_extents_at_front = [%d]\n",
383 crypt_stat->num_header_extents_at_front);
384 ecryptfs_printk(KERN_DEBUG, " * extents_occupied_by_headers_at_"
385 "front = [%d]\n", extents_occupied_by_headers_at_front);
386 ecryptfs_printk(KERN_DEBUG, " * lower_extent_num = [0x%.16x]\n",
387 lower_extent_num);
388 ecryptfs_printk(KERN_DEBUG, " * extents_per_page = [%d]\n",
389 extents_per_page);
390 ecryptfs_printk(KERN_DEBUG, " * (*lower_page_idx) = [0x%.16x]\n",
391 (*lower_page_idx));
392 ecryptfs_printk(KERN_DEBUG, " * extent_offset = [%d]\n",
393 extent_offset);
394 ecryptfs_printk(KERN_DEBUG, " * (*byte_offset) = [%d]\n",
395 (*byte_offset));
396}
397
398static int ecryptfs_write_out_page(struct ecryptfs_page_crypt_context *ctx,
399 struct page *lower_page,
400 struct inode *lower_inode,
401 int byte_offset_in_page, int bytes_to_write)
402{
403 int rc = 0;
404
405 if (ctx->mode == ECRYPTFS_PREPARE_COMMIT_MODE) {
406 rc = ecryptfs_commit_lower_page(lower_page, lower_inode,
407 ctx->param.lower_file,
408 byte_offset_in_page,
409 bytes_to_write);
410 if (rc) {
411 ecryptfs_printk(KERN_ERR, "Error calling lower "
412 "commit; rc = [%d]\n", rc);
413 goto out;
414 }
415 } else {
416 rc = ecryptfs_writepage_and_release_lower_page(lower_page,
417 lower_inode,
418 ctx->param.wbc);
419 if (rc) {
420 ecryptfs_printk(KERN_ERR, "Error calling lower "
421 "writepage(); rc = [%d]\n", rc);
422 goto out;
423 }
424 }
425out:
426 return rc;
427}
428
429static int ecryptfs_read_in_page(struct ecryptfs_page_crypt_context *ctx,
430 struct page **lower_page,
431 struct inode *lower_inode,
432 unsigned long lower_page_idx,
433 int byte_offset_in_page)
434{
435 int rc = 0;
436
437 if (ctx->mode == ECRYPTFS_PREPARE_COMMIT_MODE) {
438 /* TODO: Limit this to only the data extents that are
439 * needed */
440 rc = ecryptfs_get_lower_page(lower_page, lower_inode,
441 ctx->param.lower_file,
442 lower_page_idx,
443 byte_offset_in_page,
444 (PAGE_CACHE_SIZE
445 - byte_offset_in_page));
446 if (rc) {
447 ecryptfs_printk(
448 KERN_ERR, "Error attempting to grab, map, "
449 "and prepare_write lower page with index "
450 "[0x%.16x]; rc = [%d]\n", lower_page_idx, rc);
451 goto out;
452 }
453 } else {
454 *lower_page = grab_cache_page(lower_inode->i_mapping,
455 lower_page_idx);
456 if (!(*lower_page)) {
457 rc = -EINVAL;
458 ecryptfs_printk(
459 KERN_ERR, "Error attempting to grab and map "
460 "lower page with index [0x%.16x]; rc = [%d]\n",
461 lower_page_idx, rc);
462 goto out;
463 }
464 }
465out:
466 return rc;
467}
468
469/** 356/**
470 * ecryptfs_lower_offset_for_extent 357 * ecryptfs_lower_offset_for_extent
471 * 358 *
@@ -1306,43 +1193,6 @@ int ecryptfs_cipher_code_to_string(char *str, u16 cipher_code)
1306 return rc; 1193 return rc;
1307} 1194}
1308 1195
1309/**
1310 * ecryptfs_read_header_region
1311 * @data: The virtual address to write header region data into
1312 * @dentry: The lower dentry
1313 * @mnt: The lower VFS mount
1314 *
1315 * Returns zero on success; non-zero otherwise
1316 */
1317static int ecryptfs_read_header_region(char *data, struct dentry *dentry,
1318 struct vfsmount *mnt)
1319{
1320 struct file *lower_file;
1321 mm_segment_t oldfs;
1322 int rc;
1323
1324 rc = ecryptfs_open_lower_file(&lower_file, dentry, mnt, O_RDONLY);
1325 if (rc) {
1326 printk(KERN_ERR
1327 "Error opening lower_file to read header region\n");
1328 goto out;
1329 }
1330 lower_file->f_pos = 0;
1331 oldfs = get_fs();
1332 set_fs(get_ds());
1333 rc = lower_file->f_op->read(lower_file, (char __user *)data,
1334 ECRYPTFS_DEFAULT_EXTENT_SIZE, &lower_file->f_pos);
1335 set_fs(oldfs);
1336 rc = ecryptfs_close_lower_file(lower_file);
1337 if (rc) {
1338 printk(KERN_ERR "Error closing lower_file\n");
1339 goto out;
1340 }
1341 rc = 0;
1342out:
1343 return rc;
1344}
1345
1346int ecryptfs_read_and_validate_header_region(char *data, 1196int ecryptfs_read_and_validate_header_region(char *data,
1347 struct inode *ecryptfs_inode) 1197 struct inode *ecryptfs_inode)
1348{ 1198{
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 3e52b42fba06..bb92b74d66e9 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -552,22 +552,7 @@ void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat);
552void ecryptfs_destroy_mount_crypt_stat( 552void ecryptfs_destroy_mount_crypt_stat(
553 struct ecryptfs_mount_crypt_stat *mount_crypt_stat); 553 struct ecryptfs_mount_crypt_stat *mount_crypt_stat);
554int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat); 554int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat);
555int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptefs_inode); 555int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode);
556int ecryptfs_get_lower_page(struct page **lower_page, struct inode *lower_inode,
557 struct file *lower_file,
558 unsigned long lower_page_index, int byte_offset,
559 int region_bytes);
560int
561ecryptfs_commit_lower_page(struct page *lower_page, struct inode *lower_inode,
562 struct file *lower_file, int byte_offset,
563 int region_size);
564int ecryptfs_copy_page_to_lower(struct page *page, struct inode *lower_inode,
565 struct file *lower_file);
566int ecryptfs_do_readpage(struct file *file, struct page *page,
567 pgoff_t lower_page_index);
568int ecryptfs_writepage_and_release_lower_page(struct page *lower_page,
569 struct inode *lower_inode,
570 struct writeback_control *wbc);
571int ecryptfs_encrypt_page(struct page *page); 556int ecryptfs_encrypt_page(struct page *page);
572int ecryptfs_decrypt_page(struct page *page); 557int ecryptfs_decrypt_page(struct page *page);
573int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry); 558int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry);
@@ -591,10 +576,6 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length);
591int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode); 576int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode);
592int ecryptfs_inode_set(struct inode *inode, void *lower_inode); 577int ecryptfs_inode_set(struct inode *inode, void *lower_inode);
593void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode); 578void ecryptfs_init_inode(struct inode *inode, struct inode *lower_inode);
594int ecryptfs_open_lower_file(struct file **lower_file,
595 struct dentry *lower_dentry,
596 struct vfsmount *lower_mnt, int flags);
597int ecryptfs_close_lower_file(struct file *lower_file);
598ssize_t ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value, 579ssize_t ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
599 size_t size); 580 size_t size);
600ssize_t 581ssize_t
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 95be9a90c504..c98c4690a771 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -141,34 +141,6 @@ retry:
141 141
142struct kmem_cache *ecryptfs_file_info_cache; 142struct kmem_cache *ecryptfs_file_info_cache;
143 143
144int ecryptfs_open_lower_file(struct file **lower_file,
145 struct dentry *lower_dentry,
146 struct vfsmount *lower_mnt, int flags)
147{
148 int rc = 0;
149
150 flags |= O_LARGEFILE;
151 dget(lower_dentry);
152 mntget(lower_mnt);
153 *lower_file = dentry_open(lower_dentry, lower_mnt, flags);
154 if (IS_ERR(*lower_file)) {
155 printk(KERN_ERR "Error opening lower file for lower_dentry "
156 "[0x%p], lower_mnt [0x%p], and flags [0x%x]\n",
157 lower_dentry, lower_mnt, flags);
158 rc = PTR_ERR(*lower_file);
159 *lower_file = NULL;
160 goto out;
161 }
162out:
163 return rc;
164}
165
166int ecryptfs_close_lower_file(struct file *lower_file)
167{
168 fput(lower_file);
169 return 0;
170}
171
172/** 144/**
173 * ecryptfs_open 145 * ecryptfs_open
174 * @inode: inode speciying file to open 146 * @inode: inode speciying file to open
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index fb9d85b5c7b8..97e6801f722c 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -671,11 +671,6 @@ static struct ecryptfs_cache_info {
671 .size = PAGE_CACHE_SIZE, 671 .size = PAGE_CACHE_SIZE,
672 }, 672 },
673 { 673 {
674 .cache = &ecryptfs_lower_page_cache,
675 .name = "ecryptfs_lower_page_cache",
676 .size = PAGE_CACHE_SIZE,
677 },
678 {
679 .cache = &ecryptfs_key_record_cache, 674 .cache = &ecryptfs_key_record_cache,
680 .name = "ecryptfs_key_record_cache", 675 .name = "ecryptfs_key_record_cache",
681 .size = sizeof(struct ecryptfs_key_record), 676 .size = sizeof(struct ecryptfs_key_record),
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 6ae0afb238d1..4eb09c1753c6 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -57,113 +57,6 @@ struct page *ecryptfs_get1page(struct file *file, loff_t index)
57} 57}
58 58
59/** 59/**
60 * ecryptfs_fill_zeros
61 * @file: The ecryptfs file
62 * @new_length: The new length of the data in the underlying file;
63 * everything between the prior end of the file and the
64 * new end of the file will be filled with zero's.
65 * new_length must be greater than current length
66 *
67 * Function for handling lseek-ing past the end of the file.
68 *
69 * This function does not support shrinking, only growing a file.
70 *
71 * Returns zero on success; non-zero otherwise.
72 */
73int ecryptfs_fill_zeros(struct file *file, loff_t new_length)
74{
75 int rc = 0;
76 struct dentry *dentry = file->f_path.dentry;
77 struct inode *inode = dentry->d_inode;
78 pgoff_t old_end_page_index = 0;
79 pgoff_t index = old_end_page_index;
80 int old_end_pos_in_page = -1;
81 pgoff_t new_end_page_index;
82 int new_end_pos_in_page;
83 loff_t cur_length = i_size_read(inode);
84
85 if (cur_length != 0) {
86 index = old_end_page_index =
87 ((cur_length - 1) >> PAGE_CACHE_SHIFT);
88 old_end_pos_in_page = ((cur_length - 1) & ~PAGE_CACHE_MASK);
89 }
90 new_end_page_index = ((new_length - 1) >> PAGE_CACHE_SHIFT);
91 new_end_pos_in_page = ((new_length - 1) & ~PAGE_CACHE_MASK);
92 ecryptfs_printk(KERN_DEBUG, "old_end_page_index = [0x%.16x]; "
93 "old_end_pos_in_page = [%d]; "
94 "new_end_page_index = [0x%.16x]; "
95 "new_end_pos_in_page = [%d]\n",
96 old_end_page_index, old_end_pos_in_page,
97 new_end_page_index, new_end_pos_in_page);
98 if (old_end_page_index == new_end_page_index) {
99 /* Start and end are in the same page; we just need to
100 * set a portion of the existing page to zero's */
101 rc = ecryptfs_write_zeros(file, index,
102 (old_end_pos_in_page + 1),
103 (new_end_pos_in_page
104 - old_end_pos_in_page));
105 if (rc)
106 ecryptfs_printk(KERN_ERR, "ecryptfs_write_zeros("
107 "file=[%p], "
108 "index=[0x%.16x], "
109 "old_end_pos_in_page=[d], "
110 "(PAGE_CACHE_SIZE - new_end_pos_in_page"
111 "=[%d]"
112 ")=[d]) returned [%d]\n", file, index,
113 old_end_pos_in_page,
114 new_end_pos_in_page,
115 (PAGE_CACHE_SIZE - new_end_pos_in_page),
116 rc);
117 goto out;
118 }
119 /* Fill the remainder of the previous last page with zeros */
120 rc = ecryptfs_write_zeros(file, index, (old_end_pos_in_page + 1),
121 ((PAGE_CACHE_SIZE - 1) - old_end_pos_in_page));
122 if (rc) {
123 ecryptfs_printk(KERN_ERR, "ecryptfs_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,
127 old_end_pos_in_page,
128 (PAGE_CACHE_SIZE - old_end_pos_in_page), rc);
129 goto out;
130 }
131 index++;
132 while (index < new_end_page_index) {
133 /* Fill all intermediate pages with zeros */
134 rc = ecryptfs_write_zeros(file, index, 0, PAGE_CACHE_SIZE);
135 if (rc) {
136 ecryptfs_printk(KERN_ERR, "ecryptfs_write_zeros("
137 "file=[%p], "
138 "index=[0x%.16x], "
139 "old_end_pos_in_page=[d], "
140 "(PAGE_CACHE_SIZE - new_end_pos_in_page"
141 "=[%d]"
142 ")=[d]) returned [%d]\n", file, index,
143 old_end_pos_in_page,
144 new_end_pos_in_page,
145 (PAGE_CACHE_SIZE - new_end_pos_in_page),
146 rc);
147 goto out;
148 }
149 index++;
150 }
151 /* Fill the portion at the beginning of the last new page with
152 * zero's */
153 rc = ecryptfs_write_zeros(file, index, 0, (new_end_pos_in_page + 1));
154 if (rc) {
155 ecryptfs_printk(KERN_ERR, "ecryptfs_write_zeros(file="
156 "[%p], index=[0x%.16x], 0, "
157 "new_end_pos_in_page=[%d]"
158 "returned [%d]\n", file, index,
159 new_end_pos_in_page, rc);
160 goto out;
161 }
162out:
163 return rc;
164}
165
166/**
167 * ecryptfs_writepage 60 * ecryptfs_writepage
168 * @page: Page that is locked before this call is made 61 * @page: Page that is locked before this call is made
169 * 62 *
@@ -187,58 +80,6 @@ out:
187} 80}
188 81
189/** 82/**
190 * Reads the data from the lower file file at index lower_page_index
191 * and copies that data into page.
192 *
193 * @param page Page to fill
194 * @param lower_page_index Index of the page in the lower file to get
195 */
196int ecryptfs_do_readpage(struct file *file, struct page *page,
197 pgoff_t lower_page_index)
198{
199 int rc;
200 struct dentry *dentry;
201 struct file *lower_file;
202 struct dentry *lower_dentry;
203 struct inode *inode;
204 struct inode *lower_inode;
205 char *page_data;
206 struct page *lower_page = NULL;
207 char *lower_page_data;
208 const struct address_space_operations *lower_a_ops;
209
210 dentry = file->f_path.dentry;
211 lower_file = ecryptfs_file_to_lower(file);
212 lower_dentry = ecryptfs_dentry_to_lower(dentry);
213 inode = dentry->d_inode;
214 lower_inode = ecryptfs_inode_to_lower(inode);
215 lower_a_ops = lower_inode->i_mapping->a_ops;
216 lower_page = read_cache_page(lower_inode->i_mapping, lower_page_index,
217 (filler_t *)lower_a_ops->readpage,
218 (void *)lower_file);
219 if (IS_ERR(lower_page)) {
220 rc = PTR_ERR(lower_page);
221 lower_page = NULL;
222 ecryptfs_printk(KERN_ERR, "Error reading from page cache\n");
223 goto out;
224 }
225 page_data = kmap_atomic(page, KM_USER0);
226 lower_page_data = kmap_atomic(lower_page, KM_USER1);
227 memcpy(page_data, lower_page_data, PAGE_CACHE_SIZE);
228 kunmap_atomic(lower_page_data, KM_USER1);
229 kunmap_atomic(page_data, KM_USER0);
230 flush_dcache_page(page);
231 rc = 0;
232out:
233 if (likely(lower_page))
234 page_cache_release(lower_page);
235 if (rc == 0)
236 SetPageUptodate(page);
237 else
238 ClearPageUptodate(page);
239 return rc;
240}
241/**
242 * Header Extent: 83 * Header Extent:
243 * Octets 0-7: Unencrypted file size (big-endian) 84 * Octets 0-7: Unencrypted file size (big-endian)
244 * Octets 8-15: eCryptfs special marker 85 * Octets 8-15: eCryptfs special marker
@@ -416,27 +257,6 @@ out:
416 return 0; 257 return 0;
417} 258}
418 259
419/**
420 * eCryptfs does not currently support holes. When writing after a
421 * seek past the end of the file, eCryptfs fills in 0's through to the
422 * current location. The code to fill in the 0's to all the
423 * intermediate pages calls ecryptfs_prepare_write_no_truncate().
424 */
425static int
426ecryptfs_prepare_write_no_truncate(struct file *file, struct page *page,
427 unsigned from, unsigned to)
428{
429 int rc = 0;
430
431 if (from == 0 && to == PAGE_CACHE_SIZE)
432 goto out; /* If we are writing a full page, it will be
433 up to date. */
434 if (!PageUptodate(page))
435 rc = ecryptfs_do_readpage(file, page, page->index);
436out:
437 return rc;
438}
439
440static int ecryptfs_prepare_write(struct file *file, struct page *page, 260static int ecryptfs_prepare_write(struct file *file, struct page *page,
441 unsigned from, unsigned to) 261 unsigned from, unsigned to)
442{ 262{
@@ -470,30 +290,6 @@ out:
470 return rc; 290 return rc;
471} 291}
472 292
473int ecryptfs_writepage_and_release_lower_page(struct page *lower_page,
474 struct inode *lower_inode,
475 struct writeback_control *wbc)
476{
477 int rc = 0;
478
479 rc = lower_inode->i_mapping->a_ops->writepage(lower_page, wbc);
480 if (rc) {
481 ecryptfs_printk(KERN_ERR, "Error calling lower writepage(); "
482 "rc = [%d]\n", rc);
483 goto out;
484 }
485 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME;
486 page_cache_release(lower_page);
487out:
488 return rc;
489}
490
491static void ecryptfs_release_lower_page(struct page *lower_page)
492{
493 unlock_page(lower_page);
494 page_cache_release(lower_page);
495}
496
497/** 293/**
498 * ecryptfs_write_inode_size_to_header 294 * ecryptfs_write_inode_size_to_header
499 * 295 *
@@ -580,90 +376,6 @@ int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode)
580 return ecryptfs_write_inode_size_to_header(ecryptfs_inode); 376 return ecryptfs_write_inode_size_to_header(ecryptfs_inode);
581} 377}
582 378
583int 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,
586 int region_bytes)
587{
588 int rc = 0;
589
590 *lower_page = grab_cache_page(lower_inode->i_mapping, lower_page_index);
591 if (!(*lower_page)) {
592 rc = -EINVAL;
593 ecryptfs_printk(KERN_ERR, "Error attempting to grab "
594 "lower page with index [0x%.16x]\n",
595 lower_page_index);
596 goto out;
597 }
598 rc = lower_inode->i_mapping->a_ops->prepare_write(lower_file,
599 (*lower_page),
600 byte_offset,
601 region_bytes);
602 if (rc) {
603 ecryptfs_printk(KERN_ERR, "prepare_write for "
604 "lower_page_index = [0x%.16x] failed; rc = "
605 "[%d]\n", lower_page_index, rc);
606 ecryptfs_release_lower_page(*lower_page);
607 (*lower_page) = NULL;
608 }
609out:
610 return rc;
611}
612
613/**
614 * ecryptfs_commit_lower_page
615 *
616 * Returns zero on success; non-zero on error
617 */
618int
619ecryptfs_commit_lower_page(struct page *lower_page, struct inode *lower_inode,
620 struct file *lower_file, int byte_offset,
621 int region_size)
622{
623 int rc = 0;
624
625 rc = lower_inode->i_mapping->a_ops->commit_write(
626 lower_file, lower_page, byte_offset, region_size);
627 if (rc < 0) {
628 ecryptfs_printk(KERN_ERR,
629 "Error committing write; rc = [%d]\n", rc);
630 } else
631 rc = 0;
632 ecryptfs_release_lower_page(lower_page);
633 return rc;
634}
635
636/**
637 * ecryptfs_copy_page_to_lower
638 *
639 * Used for plaintext pass-through; no page index interpolation
640 * required.
641 */
642int ecryptfs_copy_page_to_lower(struct page *page, struct inode *lower_inode,
643 struct file *lower_file)
644{
645 int rc = 0;
646 struct page *lower_page;
647
648 rc = ecryptfs_get_lower_page(&lower_page, lower_inode, lower_file,
649 page->index, 0, PAGE_CACHE_SIZE);
650 if (rc) {
651 ecryptfs_printk(KERN_ERR, "Error attempting to get page "
652 "at index [0x%.16x]\n", page->index);
653 goto out;
654 }
655 /* TODO: aops */
656 memcpy((char *)page_address(lower_page), page_address(page),
657 PAGE_CACHE_SIZE);
658 rc = ecryptfs_commit_lower_page(lower_page, lower_inode, lower_file,
659 0, PAGE_CACHE_SIZE);
660 if (rc)
661 ecryptfs_printk(KERN_ERR, "Error attempting to commit page "
662 "at index [0x%.16x]\n", page->index);
663out:
664 return rc;
665}
666
667/** 379/**
668 * ecryptfs_commit_write 380 * ecryptfs_commit_write
669 * @file: The eCryptfs file object 381 * @file: The eCryptfs file object
@@ -721,54 +433,6 @@ out:
721 return rc; 433 return rc;
722} 434}
723 435
724/**
725 * ecryptfs_write_zeros
726 * @file: The ecryptfs file
727 * @index: The index in which we are writing
728 * @start: The position after the last block of data
729 * @num_zeros: The number of zeros to write
730 *
731 * Write a specified number of zero's to a page.
732 *
733 * (start + num_zeros) must be less than or equal to PAGE_CACHE_SIZE
734 */
735int
736ecryptfs_write_zeros(struct file *file, pgoff_t index, int start, int num_zeros)
737{
738 int rc = 0;
739 struct page *tmp_page;
740
741 tmp_page = ecryptfs_get1page(file, index);
742 if (IS_ERR(tmp_page)) {
743 ecryptfs_printk(KERN_ERR, "Error getting page at index "
744 "[0x%.16x]\n", index);
745 rc = PTR_ERR(tmp_page);
746 goto out;
747 }
748 rc = ecryptfs_prepare_write_no_truncate(file, tmp_page, start,
749 (start + num_zeros));
750 if (rc) {
751 ecryptfs_printk(KERN_ERR, "Error preparing to write zero's "
752 "to page at index [0x%.16x]\n",
753 index);
754 page_cache_release(tmp_page);
755 goto out;
756 }
757 zero_user_page(tmp_page, start, num_zeros, KM_USER0);
758 rc = ecryptfs_commit_write(file, tmp_page, start, start + num_zeros);
759 if (rc < 0) {
760 ecryptfs_printk(KERN_ERR, "Error attempting to write zero's "
761 "to remainder of page at index [0x%.16x]\n",
762 index);
763 page_cache_release(tmp_page);
764 goto out;
765 }
766 rc = 0;
767 page_cache_release(tmp_page);
768out:
769 return rc;
770}
771
772static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block) 436static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block)
773{ 437{
774 int rc = 0; 438 int rc = 0;