blob: ac5f3deae088e355de3bd88436477a4bc162b8bf [file] [log] [blame]
Daniel Campello35c9e242015-07-20 16:23:50 -07001/*
2 * fs/sdcardfs/mmap.c
3 *
4 * Copyright (c) 2013 Samsung Electronics Co. Ltd
5 * Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
6 * Sunghwan Yun, Sungjong Seo
7 *
8 * This program has been developed as a stackable file system based on
9 * the WrapFS which written by
10 *
11 * Copyright (c) 1998-2011 Erez Zadok
12 * Copyright (c) 2009 Shrikar Archak
13 * Copyright (c) 2003-2011 Stony Brook University
14 * Copyright (c) 2003-2011 The Research Foundation of SUNY
15 *
16 * This file is dual licensed. It may be redistributed and/or modified
17 * under the terms of the Apache 2.0 License OR version 2 of the GNU
18 * General Public License.
19 */
20
21#include "sdcardfs.h"
22
23static int sdcardfs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24{
25 int err;
26 struct file *file, *lower_file;
27 const struct vm_operations_struct *lower_vm_ops;
28 struct vm_area_struct lower_vma;
29
30 memcpy(&lower_vma, vma, sizeof(struct vm_area_struct));
31 file = lower_vma.vm_file;
32 lower_vm_ops = SDCARDFS_F(file)->lower_vm_ops;
33 BUG_ON(!lower_vm_ops);
34
35 lower_file = sdcardfs_lower_file(file);
36 /*
37 * XXX: vm_ops->fault may be called in parallel. Because we have to
38 * resort to temporarily changing the vma->vm_file to point to the
39 * lower file, a concurrent invocation of sdcardfs_fault could see a
40 * different value. In this workaround, we keep a different copy of
41 * the vma structure in our stack, so we never expose a different
42 * value of the vma->vm_file called to us, even temporarily. A
43 * better fix would be to change the calling semantics of ->fault to
44 * take an explicit file pointer.
45 */
46 lower_vma.vm_file = lower_file;
47 err = lower_vm_ops->fault(&lower_vma, vmf);
48 return err;
49}
50
Amit Pundir71f1b592016-06-07 16:30:56 +053051static ssize_t sdcardfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
Daniel Campello35c9e242015-07-20 16:23:50 -070052{
53 /*
54 * This function returns zero on purpose in order to support direct IO.
55 * __dentry_open checks a_ops->direct_IO and returns EINVAL if it is null.
56 *
57 * However, this function won't be called by certain file operations
58 * including generic fs functions. * reads and writes are delivered to
59 * the lower file systems and the direct IOs will be handled by them.
60 *
61 * NOTE: exceptionally, on the recent kernels (since Linux 3.8.x),
62 * swap_writepage invokes this function directly.
63 */
64 printk(KERN_INFO "%s, operation is not supported\n", __func__);
65 return 0;
66}
67
68/*
69 * XXX: the default address_space_ops for sdcardfs is empty. We cannot set
70 * our inode->i_mapping->a_ops to NULL because too many code paths expect
71 * the a_ops vector to be non-NULL.
72 */
73const struct address_space_operations sdcardfs_aops = {
74 /* empty on purpose */
75 .direct_IO = sdcardfs_direct_IO,
76};
77
78const struct vm_operations_struct sdcardfs_vm_ops = {
79 .fault = sdcardfs_fault,
80};