xref: /linux/fs/ecryptfs/file.c (revision ac7576f4b1da8c9c6bc1ae026c2b9e86ae617ba5)
1237fead6SMichael Halcrow /**
2237fead6SMichael Halcrow  * eCryptfs: Linux filesystem encryption layer
3237fead6SMichael Halcrow  *
4237fead6SMichael Halcrow  * Copyright (C) 1997-2004 Erez Zadok
5237fead6SMichael Halcrow  * Copyright (C) 2001-2004 Stony Brook University
6dd2a3b7aSMichael Halcrow  * Copyright (C) 2004-2007 International Business Machines Corp.
7237fead6SMichael Halcrow  *   Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com>
8237fead6SMichael Halcrow  *   		Michael C. Thompson <mcthomps@us.ibm.com>
9237fead6SMichael Halcrow  *
10237fead6SMichael Halcrow  * This program is free software; you can redistribute it and/or
11237fead6SMichael Halcrow  * modify it under the terms of the GNU General Public License as
12237fead6SMichael Halcrow  * published by the Free Software Foundation; either version 2 of the
13237fead6SMichael Halcrow  * License, or (at your option) any later version.
14237fead6SMichael Halcrow  *
15237fead6SMichael Halcrow  * This program is distributed in the hope that it will be useful, but
16237fead6SMichael Halcrow  * WITHOUT ANY WARRANTY; without even the implied warranty of
17237fead6SMichael Halcrow  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18237fead6SMichael Halcrow  * General Public License for more details.
19237fead6SMichael Halcrow  *
20237fead6SMichael Halcrow  * You should have received a copy of the GNU General Public License
21237fead6SMichael Halcrow  * along with this program; if not, write to the Free Software
22237fead6SMichael Halcrow  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23237fead6SMichael Halcrow  * 02111-1307, USA.
24237fead6SMichael Halcrow  */
25237fead6SMichael Halcrow 
26237fead6SMichael Halcrow #include <linux/file.h>
27237fead6SMichael Halcrow #include <linux/poll.h>
285a0e3ad6STejun Heo #include <linux/slab.h>
29237fead6SMichael Halcrow #include <linux/mount.h>
30237fead6SMichael Halcrow #include <linux/pagemap.h>
31237fead6SMichael Halcrow #include <linux/security.h>
32237fead6SMichael Halcrow #include <linux/compat.h>
330cc72dc7SJosef "Jeff" Sipek #include <linux/fs_stack.h>
34a27bb332SKent Overstreet #include <linux/aio.h>
35237fead6SMichael Halcrow #include "ecryptfs_kernel.h"
36237fead6SMichael Halcrow 
37237fead6SMichael Halcrow /**
38237fead6SMichael Halcrow  * ecryptfs_read_update_atime
39237fead6SMichael Halcrow  *
40237fead6SMichael Halcrow  * generic_file_read updates the atime of upper layer inode.  But, it
41237fead6SMichael Halcrow  * doesn't give us a chance to update the atime of the lower layer
42237fead6SMichael Halcrow  * inode.  This function is a wrapper to generic_file_read.  It
43237fead6SMichael Halcrow  * updates the atime of the lower level inode if generic_file_read
44237fead6SMichael Halcrow  * returns without any errors. This is to be used only for file reads.
45237fead6SMichael Halcrow  * The function to be used for directory reads is ecryptfs_read.
46237fead6SMichael Halcrow  */
47237fead6SMichael Halcrow static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
4802797829SAl Viro 				struct iov_iter *to)
49237fead6SMichael Halcrow {
5038a708d7SEdward Shishkin 	ssize_t rc;
51cc18ec3cSMatthew Wilcox 	struct path *path;
52237fead6SMichael Halcrow 	struct file *file = iocb->ki_filp;
53237fead6SMichael Halcrow 
5402797829SAl Viro 	rc = generic_file_read_iter(iocb, to);
55237fead6SMichael Halcrow 	/*
56237fead6SMichael Halcrow 	 * Even though this is a async interface, we need to wait
57237fead6SMichael Halcrow 	 * for IO to finish to update atime
58237fead6SMichael Halcrow 	 */
59237fead6SMichael Halcrow 	if (-EIOCBQUEUED == rc)
60237fead6SMichael Halcrow 		rc = wait_on_sync_kiocb(iocb);
61237fead6SMichael Halcrow 	if (rc >= 0) {
62cc18ec3cSMatthew Wilcox 		path = ecryptfs_dentry_to_lower_path(file->f_path.dentry);
63cc18ec3cSMatthew Wilcox 		touch_atime(path);
64237fead6SMichael Halcrow 	}
65237fead6SMichael Halcrow 	return rc;
66237fead6SMichael Halcrow }
67237fead6SMichael Halcrow 
68237fead6SMichael Halcrow struct ecryptfs_getdents_callback {
695c0ba4e0SAl Viro 	struct dir_context ctx;
702de5f059SAl Viro 	struct dir_context *caller;
710747fdb2SAl Viro 	struct super_block *sb;
72237fead6SMichael Halcrow 	int filldir_called;
73237fead6SMichael Halcrow 	int entries_written;
74237fead6SMichael Halcrow };
75237fead6SMichael Halcrow 
767d6c7045SMichael Halcrow /* Inspired by generic filldir in fs/readdir.c */
77237fead6SMichael Halcrow static int
78*ac7576f4SMiklos Szeredi ecryptfs_filldir(struct dir_context *ctx, const char *lower_name,
79*ac7576f4SMiklos Szeredi 		 int lower_namelen, loff_t offset, u64 ino, unsigned int d_type)
80237fead6SMichael Halcrow {
81237fead6SMichael Halcrow 	struct ecryptfs_getdents_callback *buf =
82*ac7576f4SMiklos Szeredi 		container_of(ctx, struct ecryptfs_getdents_callback, ctx);
83a8f12864SMichael Halcrow 	size_t name_size;
84addd65adSMichael Halcrow 	char *name;
85237fead6SMichael Halcrow 	int rc;
86237fead6SMichael Halcrow 
87237fead6SMichael Halcrow 	buf->filldir_called++;
88addd65adSMichael Halcrow 	rc = ecryptfs_decode_and_decrypt_filename(&name, &name_size,
890747fdb2SAl Viro 						  buf->sb, lower_name,
90addd65adSMichael Halcrow 						  lower_namelen);
91addd65adSMichael Halcrow 	if (rc) {
92addd65adSMichael Halcrow 		printk(KERN_ERR "%s: Error attempting to decode and decrypt "
93addd65adSMichael Halcrow 		       "filename [%s]; rc = [%d]\n", __func__, lower_name,
94addd65adSMichael Halcrow 		       rc);
95237fead6SMichael Halcrow 		goto out;
96237fead6SMichael Halcrow 	}
972de5f059SAl Viro 	buf->caller->pos = buf->ctx.pos;
982de5f059SAl Viro 	rc = !dir_emit(buf->caller, name, name_size, ino, d_type);
99addd65adSMichael Halcrow 	kfree(name);
1002de5f059SAl Viro 	if (!rc)
101237fead6SMichael Halcrow 		buf->entries_written++;
102237fead6SMichael Halcrow out:
103237fead6SMichael Halcrow 	return rc;
104237fead6SMichael Halcrow }
105237fead6SMichael Halcrow 
106237fead6SMichael Halcrow /**
107237fead6SMichael Halcrow  * ecryptfs_readdir
108addd65adSMichael Halcrow  * @file: The eCryptfs directory file
1092de5f059SAl Viro  * @ctx: The actor to feed the entries to
110237fead6SMichael Halcrow  */
1112de5f059SAl Viro static int ecryptfs_readdir(struct file *file, struct dir_context *ctx)
112237fead6SMichael Halcrow {
113237fead6SMichael Halcrow 	int rc;
114237fead6SMichael Halcrow 	struct file *lower_file;
1150747fdb2SAl Viro 	struct inode *inode = file_inode(file);
1162de5f059SAl Viro 	struct ecryptfs_getdents_callback buf = {
1172de5f059SAl Viro 		.ctx.actor = ecryptfs_filldir,
1182de5f059SAl Viro 		.caller = ctx,
1190747fdb2SAl Viro 		.sb = inode->i_sb,
1202de5f059SAl Viro 	};
121237fead6SMichael Halcrow 	lower_file = ecryptfs_file_to_lower(file);
1222de5f059SAl Viro 	lower_file->f_pos = ctx->pos;
1235c0ba4e0SAl Viro 	rc = iterate_dir(lower_file, &buf.ctx);
1242de5f059SAl Viro 	ctx->pos = buf.ctx.pos;
1257d6c7045SMichael Halcrow 	if (rc < 0)
1267d6c7045SMichael Halcrow 		goto out;
1277d6c7045SMichael Halcrow 	if (buf.filldir_called && !buf.entries_written)
1287d6c7045SMichael Halcrow 		goto out;
129237fead6SMichael Halcrow 	if (rc >= 0)
1307d6c7045SMichael Halcrow 		fsstack_copy_attr_atime(inode,
131496ad9aaSAl Viro 					file_inode(lower_file));
1327d6c7045SMichael Halcrow out:
133237fead6SMichael Halcrow 	return rc;
134237fead6SMichael Halcrow }
135237fead6SMichael Halcrow 
136237fead6SMichael Halcrow struct kmem_cache *ecryptfs_file_info_cache;
137237fead6SMichael Halcrow 
138e3ccaa97STyler Hicks static int read_or_initialize_metadata(struct dentry *dentry)
139e3ccaa97STyler Hicks {
140e3ccaa97STyler Hicks 	struct inode *inode = dentry->d_inode;
141e3ccaa97STyler Hicks 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
142e3ccaa97STyler Hicks 	struct ecryptfs_crypt_stat *crypt_stat;
143e3ccaa97STyler Hicks 	int rc;
144e3ccaa97STyler Hicks 
145e3ccaa97STyler Hicks 	crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
146e3ccaa97STyler Hicks 	mount_crypt_stat = &ecryptfs_superblock_to_private(
147e3ccaa97STyler Hicks 						inode->i_sb)->mount_crypt_stat;
148e3ccaa97STyler Hicks 	mutex_lock(&crypt_stat->cs_mutex);
149e3ccaa97STyler Hicks 
150e3ccaa97STyler Hicks 	if (crypt_stat->flags & ECRYPTFS_POLICY_APPLIED &&
151e3ccaa97STyler Hicks 	    crypt_stat->flags & ECRYPTFS_KEY_VALID) {
152e3ccaa97STyler Hicks 		rc = 0;
153e3ccaa97STyler Hicks 		goto out;
154e3ccaa97STyler Hicks 	}
155e3ccaa97STyler Hicks 
156e3ccaa97STyler Hicks 	rc = ecryptfs_read_metadata(dentry);
157e3ccaa97STyler Hicks 	if (!rc)
158e3ccaa97STyler Hicks 		goto out;
159e3ccaa97STyler Hicks 
160e3ccaa97STyler Hicks 	if (mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED) {
161e3ccaa97STyler Hicks 		crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
162e3ccaa97STyler Hicks 				       | ECRYPTFS_ENCRYPTED);
163e3ccaa97STyler Hicks 		rc = 0;
164e3ccaa97STyler Hicks 		goto out;
165e3ccaa97STyler Hicks 	}
166e3ccaa97STyler Hicks 
167e3ccaa97STyler Hicks 	if (!(mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED) &&
168e3ccaa97STyler Hicks 	    !i_size_read(ecryptfs_inode_to_lower(inode))) {
169e3ccaa97STyler Hicks 		rc = ecryptfs_initialize_file(dentry, inode);
170e3ccaa97STyler Hicks 		if (!rc)
171e3ccaa97STyler Hicks 			goto out;
172e3ccaa97STyler Hicks 	}
173e3ccaa97STyler Hicks 
174e3ccaa97STyler Hicks 	rc = -EIO;
175e3ccaa97STyler Hicks out:
176e3ccaa97STyler Hicks 	mutex_unlock(&crypt_stat->cs_mutex);
177e3ccaa97STyler Hicks 	return rc;
178e3ccaa97STyler Hicks }
179e3ccaa97STyler Hicks 
180237fead6SMichael Halcrow /**
181237fead6SMichael Halcrow  * ecryptfs_open
182237fead6SMichael Halcrow  * @inode: inode speciying file to open
183237fead6SMichael Halcrow  * @file: Structure to return filled in
184237fead6SMichael Halcrow  *
185237fead6SMichael Halcrow  * Opens the file specified by inode.
186237fead6SMichael Halcrow  *
187237fead6SMichael Halcrow  * Returns zero on success; non-zero otherwise
188237fead6SMichael Halcrow  */
189237fead6SMichael Halcrow static int ecryptfs_open(struct inode *inode, struct file *file)
190237fead6SMichael Halcrow {
191237fead6SMichael Halcrow 	int rc = 0;
192237fead6SMichael Halcrow 	struct ecryptfs_crypt_stat *crypt_stat = NULL;
193237fead6SMichael Halcrow 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
194bd243a4bSJosef "Jeff" Sipek 	struct dentry *ecryptfs_dentry = file->f_path.dentry;
195237fead6SMichael Halcrow 	/* Private value of ecryptfs_dentry allocated in
196237fead6SMichael Halcrow 	 * ecryptfs_lookup() */
197237fead6SMichael Halcrow 	struct ecryptfs_file_info *file_info;
198237fead6SMichael Halcrow 
199e77a56ddSMichael Halcrow 	mount_crypt_stat = &ecryptfs_superblock_to_private(
200e77a56ddSMichael Halcrow 		ecryptfs_dentry->d_sb)->mount_crypt_stat;
201e77a56ddSMichael Halcrow 	if ((mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
202e77a56ddSMichael Halcrow 	    && ((file->f_flags & O_WRONLY) || (file->f_flags & O_RDWR)
203e77a56ddSMichael Halcrow 		|| (file->f_flags & O_CREAT) || (file->f_flags & O_TRUNC)
204e77a56ddSMichael Halcrow 		|| (file->f_flags & O_APPEND))) {
205e77a56ddSMichael Halcrow 		printk(KERN_WARNING "Mount has encrypted view enabled; "
206e77a56ddSMichael Halcrow 		       "files may only be read\n");
207e77a56ddSMichael Halcrow 		rc = -EPERM;
208e77a56ddSMichael Halcrow 		goto out;
209e77a56ddSMichael Halcrow 	}
210237fead6SMichael Halcrow 	/* Released in ecryptfs_release or end of function if failure */
211c3762229SRobert P. J. Day 	file_info = kmem_cache_zalloc(ecryptfs_file_info_cache, GFP_KERNEL);
212237fead6SMichael Halcrow 	ecryptfs_set_file_private(file, file_info);
213237fead6SMichael Halcrow 	if (!file_info) {
214237fead6SMichael Halcrow 		ecryptfs_printk(KERN_ERR,
215237fead6SMichael Halcrow 				"Error attempting to allocate memory\n");
216237fead6SMichael Halcrow 		rc = -ENOMEM;
217237fead6SMichael Halcrow 		goto out;
218237fead6SMichael Halcrow 	}
219237fead6SMichael Halcrow 	crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
220237fead6SMichael Halcrow 	mutex_lock(&crypt_stat->cs_mutex);
221e2bd99ecSMichael Halcrow 	if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) {
222237fead6SMichael Halcrow 		ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n");
223237fead6SMichael Halcrow 		/* Policy code enabled in future release */
2242ed92554SMichael Halcrow 		crypt_stat->flags |= (ECRYPTFS_POLICY_APPLIED
2252ed92554SMichael Halcrow 				      | ECRYPTFS_ENCRYPTED);
226237fead6SMichael Halcrow 	}
227237fead6SMichael Halcrow 	mutex_unlock(&crypt_stat->cs_mutex);
2283b06b3ebSTyler Hicks 	rc = ecryptfs_get_lower_file(ecryptfs_dentry, inode);
22972b55fffSMichael Halcrow 	if (rc) {
23072b55fffSMichael Halcrow 		printk(KERN_ERR "%s: Error attempting to initialize "
231332ab16fSTyler Hicks 			"the lower file for the dentry with name "
2329e78d14aSDavid Howells 			"[%pd]; rc = [%d]\n", __func__,
2339e78d14aSDavid Howells 			ecryptfs_dentry, rc);
234ceeab929SJulia Lawall 		goto out_free;
23572b55fffSMichael Halcrow 	}
2360abe1169SRoberto Sassu 	if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE)
2370abe1169SRoberto Sassu 	    == O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) {
238e27759d7SErez Zadok 		rc = -EPERM;
239332ab16fSTyler Hicks 		printk(KERN_WARNING "%s: Lower file is RO; eCryptfs "
240e27759d7SErez Zadok 		       "file must hence be opened RO\n", __func__);
241332ab16fSTyler Hicks 		goto out_put;
242e27759d7SErez Zadok 	}
2432ed92554SMichael Halcrow 	ecryptfs_set_file_lower(
2442ed92554SMichael Halcrow 		file, ecryptfs_inode_to_private(inode)->lower_file);
245237fead6SMichael Halcrow 	if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
246237fead6SMichael Halcrow 		ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
2472f9b12a3SMichael Halcrow 		mutex_lock(&crypt_stat->cs_mutex);
248e2bd99ecSMichael Halcrow 		crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
2492f9b12a3SMichael Halcrow 		mutex_unlock(&crypt_stat->cs_mutex);
250237fead6SMichael Halcrow 		rc = 0;
251237fead6SMichael Halcrow 		goto out;
252237fead6SMichael Halcrow 	}
253e3ccaa97STyler Hicks 	rc = read_or_initialize_metadata(ecryptfs_dentry);
254e3ccaa97STyler Hicks 	if (rc)
255332ab16fSTyler Hicks 		goto out_put;
256888d57bbSJoe Perches 	ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = "
257888d57bbSJoe Perches 			"[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino,
258888d57bbSJoe Perches 			(unsigned long long)i_size_read(inode));
259237fead6SMichael Halcrow 	goto out;
260332ab16fSTyler Hicks out_put:
261332ab16fSTyler Hicks 	ecryptfs_put_lower_file(inode);
2622ed92554SMichael Halcrow out_free:
263237fead6SMichael Halcrow 	kmem_cache_free(ecryptfs_file_info_cache,
264237fead6SMichael Halcrow 			ecryptfs_file_to_private(file));
265237fead6SMichael Halcrow out:
266237fead6SMichael Halcrow 	return rc;
267237fead6SMichael Halcrow }
268237fead6SMichael Halcrow 
269237fead6SMichael Halcrow static int ecryptfs_flush(struct file *file, fl_owner_t td)
270237fead6SMichael Halcrow {
27164e6651dSTyler Hicks 	struct file *lower_file = ecryptfs_file_to_lower(file);
27264e6651dSTyler Hicks 
27372c2d531SAl Viro 	if (lower_file->f_op->flush) {
27464e6651dSTyler Hicks 		filemap_write_and_wait(file->f_mapping);
27564e6651dSTyler Hicks 		return lower_file->f_op->flush(lower_file, td);
27664e6651dSTyler Hicks 	}
27764e6651dSTyler Hicks 
27864e6651dSTyler Hicks 	return 0;
279237fead6SMichael Halcrow }
280237fead6SMichael Halcrow 
281237fead6SMichael Halcrow static int ecryptfs_release(struct inode *inode, struct file *file)
282237fead6SMichael Halcrow {
283332ab16fSTyler Hicks 	ecryptfs_put_lower_file(inode);
2842ed92554SMichael Halcrow 	kmem_cache_free(ecryptfs_file_info_cache,
2852ed92554SMichael Halcrow 			ecryptfs_file_to_private(file));
2862ed92554SMichael Halcrow 	return 0;
287237fead6SMichael Halcrow }
288237fead6SMichael Halcrow 
289237fead6SMichael Halcrow static int
29002c24a82SJosef Bacik ecryptfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
291237fead6SMichael Halcrow {
292bc5abcf7STyler Hicks 	int rc;
293bc5abcf7STyler Hicks 
294bc5abcf7STyler Hicks 	rc = filemap_write_and_wait(file->f_mapping);
295bc5abcf7STyler Hicks 	if (rc)
296bc5abcf7STyler Hicks 		return rc;
297bc5abcf7STyler Hicks 
298821f7494STyler Hicks 	return vfs_fsync(ecryptfs_file_to_lower(file), datasync);
299237fead6SMichael Halcrow }
300237fead6SMichael Halcrow 
301237fead6SMichael Halcrow static int ecryptfs_fasync(int fd, struct file *file, int flag)
302237fead6SMichael Halcrow {
303237fead6SMichael Halcrow 	int rc = 0;
304237fead6SMichael Halcrow 	struct file *lower_file = NULL;
305237fead6SMichael Halcrow 
306237fead6SMichael Halcrow 	lower_file = ecryptfs_file_to_lower(file);
30772c2d531SAl Viro 	if (lower_file->f_op->fasync)
308237fead6SMichael Halcrow 		rc = lower_file->f_op->fasync(fd, lower_file, flag);
309237fead6SMichael Halcrow 	return rc;
310237fead6SMichael Halcrow }
311237fead6SMichael Halcrow 
312c43f7b8fSTyler Hicks static long
313c43f7b8fSTyler Hicks ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
314c43f7b8fSTyler Hicks {
3152000f5beSTyler Hicks 	struct file *lower_file = ecryptfs_file_to_lower(file);
316c43f7b8fSTyler Hicks 	long rc = -ENOTTY;
317c43f7b8fSTyler Hicks 
318bdd35366SAl Viro 	if (lower_file->f_op->unlocked_ioctl)
319c43f7b8fSTyler Hicks 		rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
320c43f7b8fSTyler Hicks 	return rc;
321c43f7b8fSTyler Hicks }
322c43f7b8fSTyler Hicks 
323c43f7b8fSTyler Hicks #ifdef CONFIG_COMPAT
324c43f7b8fSTyler Hicks static long
325c43f7b8fSTyler Hicks ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
326c43f7b8fSTyler Hicks {
3272000f5beSTyler Hicks 	struct file *lower_file = ecryptfs_file_to_lower(file);
328c43f7b8fSTyler Hicks 	long rc = -ENOIOCTLCMD;
329c43f7b8fSTyler Hicks 
330c2e3f5d5SAl Viro 	if (lower_file->f_op->compat_ioctl)
331c43f7b8fSTyler Hicks 		rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
332c43f7b8fSTyler Hicks 	return rc;
333c43f7b8fSTyler Hicks }
334c43f7b8fSTyler Hicks #endif
335237fead6SMichael Halcrow 
336237fead6SMichael Halcrow const struct file_operations ecryptfs_dir_fops = {
3372de5f059SAl Viro 	.iterate = ecryptfs_readdir,
338323ef68fSAndy Whitcroft 	.read = generic_read_dir,
339c43f7b8fSTyler Hicks 	.unlocked_ioctl = ecryptfs_unlocked_ioctl,
340c43f7b8fSTyler Hicks #ifdef CONFIG_COMPAT
341c43f7b8fSTyler Hicks 	.compat_ioctl = ecryptfs_compat_ioctl,
342c43f7b8fSTyler Hicks #endif
343237fead6SMichael Halcrow 	.open = ecryptfs_open,
344237fead6SMichael Halcrow 	.flush = ecryptfs_flush,
345237fead6SMichael Halcrow 	.release = ecryptfs_release,
346237fead6SMichael Halcrow 	.fsync = ecryptfs_fsync,
347237fead6SMichael Halcrow 	.fasync = ecryptfs_fasync,
348e9f6a99cSMichael Halcrow 	.splice_read = generic_file_splice_read,
3496038f373SArnd Bergmann 	.llseek = default_llseek,
350237fead6SMichael Halcrow };
351237fead6SMichael Halcrow 
352237fead6SMichael Halcrow const struct file_operations ecryptfs_main_fops = {
35353a2731fSMichael Halcrow 	.llseek = generic_file_llseek,
35402797829SAl Viro 	.read = new_sync_read,
35502797829SAl Viro 	.read_iter = ecryptfs_read_update_atime,
3568174202bSAl Viro 	.write = new_sync_write,
3578174202bSAl Viro 	.write_iter = generic_file_write_iter,
3582de5f059SAl Viro 	.iterate = ecryptfs_readdir,
359c43f7b8fSTyler Hicks 	.unlocked_ioctl = ecryptfs_unlocked_ioctl,
360c43f7b8fSTyler Hicks #ifdef CONFIG_COMPAT
361c43f7b8fSTyler Hicks 	.compat_ioctl = ecryptfs_compat_ioctl,
362c43f7b8fSTyler Hicks #endif
363821f7494STyler Hicks 	.mmap = generic_file_mmap,
364237fead6SMichael Halcrow 	.open = ecryptfs_open,
365237fead6SMichael Halcrow 	.flush = ecryptfs_flush,
366237fead6SMichael Halcrow 	.release = ecryptfs_release,
367237fead6SMichael Halcrow 	.fsync = ecryptfs_fsync,
368237fead6SMichael Halcrow 	.fasync = ecryptfs_fasync,
369e9f6a99cSMichael Halcrow 	.splice_read = generic_file_splice_read,
370237fead6SMichael Halcrow };
371