xref: /linux/fs/ecryptfs/read_write.c (revision 48c1e44aceca577aa35be509714bd9ec4b4c3837)
1da0102a1SMichael Halcrow /**
2da0102a1SMichael Halcrow  * eCryptfs: Linux filesystem encryption layer
3da0102a1SMichael Halcrow  *
4da0102a1SMichael Halcrow  * Copyright (C) 2007 International Business Machines Corp.
5da0102a1SMichael Halcrow  *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
6da0102a1SMichael Halcrow  *
7da0102a1SMichael Halcrow  * This program is free software; you can redistribute it and/or
8da0102a1SMichael Halcrow  * modify it under the terms of the GNU General Public License as
9da0102a1SMichael Halcrow  * published by the Free Software Foundation; either version 2 of the
10da0102a1SMichael Halcrow  * License, or (at your option) any later version.
11da0102a1SMichael Halcrow  *
12da0102a1SMichael Halcrow  * This program is distributed in the hope that it will be useful, but
13da0102a1SMichael Halcrow  * WITHOUT ANY WARRANTY; without even the implied warranty of
14da0102a1SMichael Halcrow  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15da0102a1SMichael Halcrow  * General Public License for more details.
16da0102a1SMichael Halcrow  *
17da0102a1SMichael Halcrow  * You should have received a copy of the GNU General Public License
18da0102a1SMichael Halcrow  * along with this program; if not, write to the Free Software
19da0102a1SMichael Halcrow  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20da0102a1SMichael Halcrow  * 02111-1307, USA.
21da0102a1SMichael Halcrow  */
22da0102a1SMichael Halcrow 
23da0102a1SMichael Halcrow #include <linux/fs.h>
24da0102a1SMichael Halcrow #include <linux/pagemap.h>
25da0102a1SMichael Halcrow #include "ecryptfs_kernel.h"
26da0102a1SMichael Halcrow 
27da0102a1SMichael Halcrow /**
28da0102a1SMichael Halcrow  * ecryptfs_write_lower
29da0102a1SMichael Halcrow  * @ecryptfs_inode: The eCryptfs inode
30da0102a1SMichael Halcrow  * @data: Data to write
31da0102a1SMichael Halcrow  * @offset: Byte offset in the lower file to which to write the data
32da0102a1SMichael Halcrow  * @size: Number of bytes from @data to write at @offset in the lower
33da0102a1SMichael Halcrow  *        file
34da0102a1SMichael Halcrow  *
35da0102a1SMichael Halcrow  * Write data to the lower file.
36da0102a1SMichael Halcrow  *
3796a7b9c2STyler Hicks  * Returns bytes written on success; less than zero on error
38da0102a1SMichael Halcrow  */
39da0102a1SMichael Halcrow int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
40da0102a1SMichael Halcrow 			 loff_t offset, size_t size)
41da0102a1SMichael Halcrow {
42da0102a1SMichael Halcrow 	struct ecryptfs_inode_info *inode_info;
43da0102a1SMichael Halcrow 	mm_segment_t fs_save;
4496a7b9c2STyler Hicks 	ssize_t rc;
45da0102a1SMichael Halcrow 
46da0102a1SMichael Halcrow 	inode_info = ecryptfs_inode_to_private(ecryptfs_inode);
47da0102a1SMichael Halcrow 	mutex_lock(&inode_info->lower_file_mutex);
48da0102a1SMichael Halcrow 	BUG_ON(!inode_info->lower_file);
49da0102a1SMichael Halcrow 	inode_info->lower_file->f_pos = offset;
50da0102a1SMichael Halcrow 	fs_save = get_fs();
51da0102a1SMichael Halcrow 	set_fs(get_ds());
5296a7b9c2STyler Hicks 	rc = vfs_write(inode_info->lower_file, data, size,
53da0102a1SMichael Halcrow 		       &inode_info->lower_file->f_pos);
54da0102a1SMichael Halcrow 	set_fs(fs_save);
55da0102a1SMichael Halcrow 	mutex_unlock(&inode_info->lower_file_mutex);
56da0102a1SMichael Halcrow 	mark_inode_dirty_sync(ecryptfs_inode);
57da0102a1SMichael Halcrow 	return rc;
58da0102a1SMichael Halcrow }
59da0102a1SMichael Halcrow 
60da0102a1SMichael Halcrow /**
61da0102a1SMichael Halcrow  * ecryptfs_write_lower_page_segment
62da0102a1SMichael Halcrow  * @ecryptfs_inode: The eCryptfs inode
63da0102a1SMichael Halcrow  * @page_for_lower: The page containing the data to be written to the
64da0102a1SMichael Halcrow  *                  lower file
65da0102a1SMichael Halcrow  * @offset_in_page: The offset in the @page_for_lower from which to
66da0102a1SMichael Halcrow  *                  start writing the data
67da0102a1SMichael Halcrow  * @size: The amount of data from @page_for_lower to write to the
68da0102a1SMichael Halcrow  *        lower file
69da0102a1SMichael Halcrow  *
70da0102a1SMichael Halcrow  * Determines the byte offset in the file for the given page and
71da0102a1SMichael Halcrow  * offset within the page, maps the page, and makes the call to write
72da0102a1SMichael Halcrow  * the contents of @page_for_lower to the lower inode.
73da0102a1SMichael Halcrow  *
74da0102a1SMichael Halcrow  * Returns zero on success; non-zero otherwise
75da0102a1SMichael Halcrow  */
76da0102a1SMichael Halcrow int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
77da0102a1SMichael Halcrow 				      struct page *page_for_lower,
78da0102a1SMichael Halcrow 				      size_t offset_in_page, size_t size)
79da0102a1SMichael Halcrow {
80da0102a1SMichael Halcrow 	char *virt;
81da0102a1SMichael Halcrow 	loff_t offset;
82da0102a1SMichael Halcrow 	int rc;
83da0102a1SMichael Halcrow 
848a146a2bSMichael Halcrow 	offset = ((((loff_t)page_for_lower->index) << PAGE_CACHE_SHIFT)
85d6a13c17SMichael Halcrow 		  + offset_in_page);
86da0102a1SMichael Halcrow 	virt = kmap(page_for_lower);
87da0102a1SMichael Halcrow 	rc = ecryptfs_write_lower(ecryptfs_inode, virt, offset, size);
8896a7b9c2STyler Hicks 	if (rc > 0)
8996a7b9c2STyler Hicks 		rc = 0;
90da0102a1SMichael Halcrow 	kunmap(page_for_lower);
91da0102a1SMichael Halcrow 	return rc;
92da0102a1SMichael Halcrow }
93da0102a1SMichael Halcrow 
94da0102a1SMichael Halcrow /**
95da0102a1SMichael Halcrow  * ecryptfs_write
96*48c1e44aSAl Viro  * @ecryptfs_inode: The eCryptfs file into which to write
97da0102a1SMichael Halcrow  * @data: Virtual address where data to write is located
98da0102a1SMichael Halcrow  * @offset: Offset in the eCryptfs file at which to begin writing the
99da0102a1SMichael Halcrow  *          data from @data
100da0102a1SMichael Halcrow  * @size: The number of bytes to write from @data
101da0102a1SMichael Halcrow  *
102da0102a1SMichael Halcrow  * Write an arbitrary amount of data to an arbitrary location in the
103da0102a1SMichael Halcrow  * eCryptfs inode page cache. This is done on a page-by-page, and then
104da0102a1SMichael Halcrow  * by an extent-by-extent, basis; individual extents are encrypted and
105da0102a1SMichael Halcrow  * written to the lower page cache (via VFS writes). This function
106da0102a1SMichael Halcrow  * takes care of all the address translation to locations in the lower
107da0102a1SMichael Halcrow  * filesystem; it also handles truncate events, writing out zeros
108da0102a1SMichael Halcrow  * where necessary.
109da0102a1SMichael Halcrow  *
110da0102a1SMichael Halcrow  * Returns zero on success; non-zero otherwise
111da0102a1SMichael Halcrow  */
112*48c1e44aSAl Viro int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
113da0102a1SMichael Halcrow 		   size_t size)
114da0102a1SMichael Halcrow {
115da0102a1SMichael Halcrow 	struct page *ecryptfs_page;
11613a791b4STyler Hicks 	struct ecryptfs_crypt_stat *crypt_stat;
117da0102a1SMichael Halcrow 	char *ecryptfs_page_virt;
11813a791b4STyler Hicks 	loff_t ecryptfs_file_size = i_size_read(ecryptfs_inode);
119da0102a1SMichael Halcrow 	loff_t data_offset = 0;
120da0102a1SMichael Halcrow 	loff_t pos;
121da0102a1SMichael Halcrow 	int rc = 0;
122da0102a1SMichael Halcrow 
12313a791b4STyler Hicks 	crypt_stat = &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
1247a3f595cSEric Sandeen 	/*
1257a3f595cSEric Sandeen 	 * if we are writing beyond current size, then start pos
1267a3f595cSEric Sandeen 	 * at the current size - we'll fill in zeros from there.
1277a3f595cSEric Sandeen 	 */
128da0102a1SMichael Halcrow 	if (offset > ecryptfs_file_size)
129da0102a1SMichael Halcrow 		pos = ecryptfs_file_size;
130da0102a1SMichael Halcrow 	else
131da0102a1SMichael Halcrow 		pos = offset;
132da0102a1SMichael Halcrow 	while (pos < (offset + size)) {
133da0102a1SMichael Halcrow 		pgoff_t ecryptfs_page_idx = (pos >> PAGE_CACHE_SHIFT);
134da0102a1SMichael Halcrow 		size_t start_offset_in_page = (pos & ~PAGE_CACHE_MASK);
135da0102a1SMichael Halcrow 		size_t num_bytes = (PAGE_CACHE_SIZE - start_offset_in_page);
136da0102a1SMichael Halcrow 		size_t total_remaining_bytes = ((offset + size) - pos);
137da0102a1SMichael Halcrow 
138da0102a1SMichael Halcrow 		if (num_bytes > total_remaining_bytes)
139da0102a1SMichael Halcrow 			num_bytes = total_remaining_bytes;
140da0102a1SMichael Halcrow 		if (pos < offset) {
1417a3f595cSEric Sandeen 			/* remaining zeros to write, up to destination offset */
142da0102a1SMichael Halcrow 			size_t total_remaining_zeros = (offset - pos);
143da0102a1SMichael Halcrow 
144da0102a1SMichael Halcrow 			if (num_bytes > total_remaining_zeros)
145da0102a1SMichael Halcrow 				num_bytes = total_remaining_zeros;
146da0102a1SMichael Halcrow 		}
14702bd9799SAl Viro 		ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_inode,
148da0102a1SMichael Halcrow 							 ecryptfs_page_idx);
149da0102a1SMichael Halcrow 		if (IS_ERR(ecryptfs_page)) {
150da0102a1SMichael Halcrow 			rc = PTR_ERR(ecryptfs_page);
151da0102a1SMichael Halcrow 			printk(KERN_ERR "%s: Error getting page at "
152da0102a1SMichael Halcrow 			       "index [%ld] from eCryptfs inode "
15318d1dbf1SHarvey Harrison 			       "mapping; rc = [%d]\n", __func__,
154da0102a1SMichael Halcrow 			       ecryptfs_page_idx, rc);
155da0102a1SMichael Halcrow 			goto out;
156da0102a1SMichael Halcrow 		}
157da0102a1SMichael Halcrow 		ecryptfs_page_virt = kmap_atomic(ecryptfs_page, KM_USER0);
1587a3f595cSEric Sandeen 
1597a3f595cSEric Sandeen 		/*
1607a3f595cSEric Sandeen 		 * pos: where we're now writing, offset: where the request was
1617a3f595cSEric Sandeen 		 * If current pos is before request, we are filling zeros
1627a3f595cSEric Sandeen 		 * If we are at or beyond request, we are writing the *data*
1637a3f595cSEric Sandeen 		 * If we're in a fresh page beyond eof, zero it in either case
1647a3f595cSEric Sandeen 		 */
1657a3f595cSEric Sandeen 		if (pos < offset || !start_offset_in_page) {
1667a3f595cSEric Sandeen 			/* We are extending past the previous end of the file.
1677a3f595cSEric Sandeen 			 * Fill in zero values to the end of the page */
1687a3f595cSEric Sandeen 			memset(((char *)ecryptfs_page_virt
1697a3f595cSEric Sandeen 				+ start_offset_in_page), 0,
1707a3f595cSEric Sandeen 				PAGE_CACHE_SIZE - start_offset_in_page);
1717a3f595cSEric Sandeen 		}
1727a3f595cSEric Sandeen 
1737a3f595cSEric Sandeen 		/* pos >= offset, we are now writing the data request */
174da0102a1SMichael Halcrow 		if (pos >= offset) {
175da0102a1SMichael Halcrow 			memcpy(((char *)ecryptfs_page_virt
176da0102a1SMichael Halcrow 				+ start_offset_in_page),
177da0102a1SMichael Halcrow 			       (data + data_offset), num_bytes);
178da0102a1SMichael Halcrow 			data_offset += num_bytes;
179da0102a1SMichael Halcrow 		}
180da0102a1SMichael Halcrow 		kunmap_atomic(ecryptfs_page_virt, KM_USER0);
181da0102a1SMichael Halcrow 		flush_dcache_page(ecryptfs_page);
18216a72c45SMichael Halcrow 		SetPageUptodate(ecryptfs_page);
18316a72c45SMichael Halcrow 		unlock_page(ecryptfs_page);
18413a791b4STyler Hicks 		if (crypt_stat->flags & ECRYPTFS_ENCRYPTED)
1850216f7f7SMichael Halcrow 			rc = ecryptfs_encrypt_page(ecryptfs_page);
18613a791b4STyler Hicks 		else
18713a791b4STyler Hicks 			rc = ecryptfs_write_lower_page_segment(ecryptfs_inode,
18813a791b4STyler Hicks 						ecryptfs_page,
18913a791b4STyler Hicks 						start_offset_in_page,
19013a791b4STyler Hicks 						data_offset);
19116a72c45SMichael Halcrow 		page_cache_release(ecryptfs_page);
192da0102a1SMichael Halcrow 		if (rc) {
193da0102a1SMichael Halcrow 			printk(KERN_ERR "%s: Error encrypting "
19418d1dbf1SHarvey Harrison 			       "page; rc = [%d]\n", __func__, rc);
195da0102a1SMichael Halcrow 			goto out;
196da0102a1SMichael Halcrow 		}
197da0102a1SMichael Halcrow 		pos += num_bytes;
198da0102a1SMichael Halcrow 	}
199da0102a1SMichael Halcrow 	if ((offset + size) > ecryptfs_file_size) {
20013a791b4STyler Hicks 		i_size_write(ecryptfs_inode, (offset + size));
20113a791b4STyler Hicks 		if (crypt_stat->flags & ECRYPTFS_ENCRYPTED) {
2020216f7f7SMichael Halcrow 			rc = ecryptfs_write_inode_size_to_metadata(
20313a791b4STyler Hicks 								ecryptfs_inode);
204da0102a1SMichael Halcrow 			if (rc) {
205da0102a1SMichael Halcrow 				printk(KERN_ERR	"Problem with "
206da0102a1SMichael Halcrow 				       "ecryptfs_write_inode_size_to_metadata; "
207da0102a1SMichael Halcrow 				       "rc = [%d]\n", rc);
208da0102a1SMichael Halcrow 				goto out;
209da0102a1SMichael Halcrow 			}
210da0102a1SMichael Halcrow 		}
21113a791b4STyler Hicks 	}
212da0102a1SMichael Halcrow out:
213da0102a1SMichael Halcrow 	return rc;
214da0102a1SMichael Halcrow }
215da0102a1SMichael Halcrow 
216da0102a1SMichael Halcrow /**
217da0102a1SMichael Halcrow  * ecryptfs_read_lower
218da0102a1SMichael Halcrow  * @data: The read data is stored here by this function
219da0102a1SMichael Halcrow  * @offset: Byte offset in the lower file from which to read the data
220da0102a1SMichael Halcrow  * @size: Number of bytes to read from @offset of the lower file and
221da0102a1SMichael Halcrow  *        store into @data
222da0102a1SMichael Halcrow  * @ecryptfs_inode: The eCryptfs inode
223da0102a1SMichael Halcrow  *
224da0102a1SMichael Halcrow  * Read @size bytes of data at byte offset @offset from the lower
225da0102a1SMichael Halcrow  * inode into memory location @data.
226da0102a1SMichael Halcrow  *
22796a7b9c2STyler Hicks  * Returns bytes read on success; 0 on EOF; less than zero on error
228da0102a1SMichael Halcrow  */
229da0102a1SMichael Halcrow int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
230da0102a1SMichael Halcrow 			struct inode *ecryptfs_inode)
231da0102a1SMichael Halcrow {
232da0102a1SMichael Halcrow 	struct ecryptfs_inode_info *inode_info =
233da0102a1SMichael Halcrow 		ecryptfs_inode_to_private(ecryptfs_inode);
234da0102a1SMichael Halcrow 	mm_segment_t fs_save;
23596a7b9c2STyler Hicks 	ssize_t rc;
236da0102a1SMichael Halcrow 
237da0102a1SMichael Halcrow 	mutex_lock(&inode_info->lower_file_mutex);
238da0102a1SMichael Halcrow 	BUG_ON(!inode_info->lower_file);
239da0102a1SMichael Halcrow 	inode_info->lower_file->f_pos = offset;
240da0102a1SMichael Halcrow 	fs_save = get_fs();
241da0102a1SMichael Halcrow 	set_fs(get_ds());
24296a7b9c2STyler Hicks 	rc = vfs_read(inode_info->lower_file, data, size,
243da0102a1SMichael Halcrow 		      &inode_info->lower_file->f_pos);
244da0102a1SMichael Halcrow 	set_fs(fs_save);
245da0102a1SMichael Halcrow 	mutex_unlock(&inode_info->lower_file_mutex);
246da0102a1SMichael Halcrow 	return rc;
247da0102a1SMichael Halcrow }
248da0102a1SMichael Halcrow 
249da0102a1SMichael Halcrow /**
250da0102a1SMichael Halcrow  * ecryptfs_read_lower_page_segment
251da0102a1SMichael Halcrow  * @page_for_ecryptfs: The page into which data for eCryptfs will be
252da0102a1SMichael Halcrow  *                     written
253da0102a1SMichael Halcrow  * @offset_in_page: Offset in @page_for_ecryptfs from which to start
254da0102a1SMichael Halcrow  *                  writing
255da0102a1SMichael Halcrow  * @size: The number of bytes to write into @page_for_ecryptfs
256da0102a1SMichael Halcrow  * @ecryptfs_inode: The eCryptfs inode
257da0102a1SMichael Halcrow  *
258da0102a1SMichael Halcrow  * Determines the byte offset in the file for the given page and
259da0102a1SMichael Halcrow  * offset within the page, maps the page, and makes the call to read
260da0102a1SMichael Halcrow  * the contents of @page_for_ecryptfs from the lower inode.
261da0102a1SMichael Halcrow  *
262da0102a1SMichael Halcrow  * Returns zero on success; non-zero otherwise
263da0102a1SMichael Halcrow  */
264da0102a1SMichael Halcrow int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
265da0102a1SMichael Halcrow 				     pgoff_t page_index,
266da0102a1SMichael Halcrow 				     size_t offset_in_page, size_t size,
267da0102a1SMichael Halcrow 				     struct inode *ecryptfs_inode)
268da0102a1SMichael Halcrow {
269da0102a1SMichael Halcrow 	char *virt;
270da0102a1SMichael Halcrow 	loff_t offset;
271da0102a1SMichael Halcrow 	int rc;
272da0102a1SMichael Halcrow 
273d6a13c17SMichael Halcrow 	offset = ((((loff_t)page_index) << PAGE_CACHE_SHIFT) + offset_in_page);
274da0102a1SMichael Halcrow 	virt = kmap(page_for_ecryptfs);
275da0102a1SMichael Halcrow 	rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode);
27696a7b9c2STyler Hicks 	if (rc > 0)
27796a7b9c2STyler Hicks 		rc = 0;
278da0102a1SMichael Halcrow 	kunmap(page_for_ecryptfs);
27916a72c45SMichael Halcrow 	flush_dcache_page(page_for_ecryptfs);
280da0102a1SMichael Halcrow 	return rc;
281da0102a1SMichael Halcrow }
282da0102a1SMichael Halcrow 
2837896b631SAdrian Bunk #if 0
284da0102a1SMichael Halcrow /**
285da0102a1SMichael Halcrow  * ecryptfs_read
286da0102a1SMichael Halcrow  * @data: The virtual address into which to write the data read (and
287da0102a1SMichael Halcrow  *        possibly decrypted) from the lower file
288da0102a1SMichael Halcrow  * @offset: The offset in the decrypted view of the file from which to
289da0102a1SMichael Halcrow  *          read into @data
290da0102a1SMichael Halcrow  * @size: The number of bytes to read into @data
291da0102a1SMichael Halcrow  * @ecryptfs_file: The eCryptfs file from which to read
292da0102a1SMichael Halcrow  *
293da0102a1SMichael Halcrow  * Read an arbitrary amount of data from an arbitrary location in the
294da0102a1SMichael Halcrow  * eCryptfs page cache. This is done on an extent-by-extent basis;
295da0102a1SMichael Halcrow  * individual extents are decrypted and read from the lower page
296da0102a1SMichael Halcrow  * cache (via VFS reads). This function takes care of all the
297da0102a1SMichael Halcrow  * address translation to locations in the lower filesystem.
298da0102a1SMichael Halcrow  *
299da0102a1SMichael Halcrow  * Returns zero on success; non-zero otherwise
300da0102a1SMichael Halcrow  */
301da0102a1SMichael Halcrow int ecryptfs_read(char *data, loff_t offset, size_t size,
302da0102a1SMichael Halcrow 		  struct file *ecryptfs_file)
303da0102a1SMichael Halcrow {
30402bd9799SAl Viro 	struct inode *ecryptfs_inode = ecryptfs_file->f_dentry->d_inode;
305da0102a1SMichael Halcrow 	struct page *ecryptfs_page;
306da0102a1SMichael Halcrow 	char *ecryptfs_page_virt;
30702bd9799SAl Viro 	loff_t ecryptfs_file_size = i_size_read(ecryptfs_inode);
308da0102a1SMichael Halcrow 	loff_t data_offset = 0;
309da0102a1SMichael Halcrow 	loff_t pos;
310da0102a1SMichael Halcrow 	int rc = 0;
311da0102a1SMichael Halcrow 
312da0102a1SMichael Halcrow 	if ((offset + size) > ecryptfs_file_size) {
313da0102a1SMichael Halcrow 		rc = -EINVAL;
314da0102a1SMichael Halcrow 		printk(KERN_ERR "%s: Attempt to read data past the end of the "
315da0102a1SMichael Halcrow 			"file; offset = [%lld]; size = [%td]; "
316da0102a1SMichael Halcrow 		       "ecryptfs_file_size = [%lld]\n",
31718d1dbf1SHarvey Harrison 		       __func__, offset, size, ecryptfs_file_size);
318da0102a1SMichael Halcrow 		goto out;
319da0102a1SMichael Halcrow 	}
320da0102a1SMichael Halcrow 	pos = offset;
321da0102a1SMichael Halcrow 	while (pos < (offset + size)) {
322da0102a1SMichael Halcrow 		pgoff_t ecryptfs_page_idx = (pos >> PAGE_CACHE_SHIFT);
323da0102a1SMichael Halcrow 		size_t start_offset_in_page = (pos & ~PAGE_CACHE_MASK);
324da0102a1SMichael Halcrow 		size_t num_bytes = (PAGE_CACHE_SIZE - start_offset_in_page);
325da0102a1SMichael Halcrow 		size_t total_remaining_bytes = ((offset + size) - pos);
326da0102a1SMichael Halcrow 
327da0102a1SMichael Halcrow 		if (num_bytes > total_remaining_bytes)
328da0102a1SMichael Halcrow 			num_bytes = total_remaining_bytes;
32902bd9799SAl Viro 		ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_inode,
330da0102a1SMichael Halcrow 							 ecryptfs_page_idx);
331da0102a1SMichael Halcrow 		if (IS_ERR(ecryptfs_page)) {
332da0102a1SMichael Halcrow 			rc = PTR_ERR(ecryptfs_page);
333da0102a1SMichael Halcrow 			printk(KERN_ERR "%s: Error getting page at "
334da0102a1SMichael Halcrow 			       "index [%ld] from eCryptfs inode "
33518d1dbf1SHarvey Harrison 			       "mapping; rc = [%d]\n", __func__,
336da0102a1SMichael Halcrow 			       ecryptfs_page_idx, rc);
337da0102a1SMichael Halcrow 			goto out;
338da0102a1SMichael Halcrow 		}
339da0102a1SMichael Halcrow 		ecryptfs_page_virt = kmap_atomic(ecryptfs_page, KM_USER0);
340da0102a1SMichael Halcrow 		memcpy((data + data_offset),
341da0102a1SMichael Halcrow 		       ((char *)ecryptfs_page_virt + start_offset_in_page),
342da0102a1SMichael Halcrow 		       num_bytes);
343da0102a1SMichael Halcrow 		kunmap_atomic(ecryptfs_page_virt, KM_USER0);
34416a72c45SMichael Halcrow 		flush_dcache_page(ecryptfs_page);
34516a72c45SMichael Halcrow 		SetPageUptodate(ecryptfs_page);
34616a72c45SMichael Halcrow 		unlock_page(ecryptfs_page);
347da0102a1SMichael Halcrow 		page_cache_release(ecryptfs_page);
348da0102a1SMichael Halcrow 		pos += num_bytes;
349da0102a1SMichael Halcrow 		data_offset += num_bytes;
350da0102a1SMichael Halcrow 	}
351da0102a1SMichael Halcrow out:
352da0102a1SMichael Halcrow 	return rc;
353da0102a1SMichael Halcrow }
3547896b631SAdrian Bunk #endif  /*  0  */
355