blob: e21f64675a808caa33659bbdb46f2ba44ca8690c [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
Daniel Campellod1d080c2015-07-20 16:27:37 -070051static ssize_t sdcardfs_direct_IO(struct kiocb *iocb,
52 struct iov_iter *iter, loff_t pos)
Daniel Campello35c9e242015-07-20 16:23:50 -070053{
54 /*
55 * This function returns zero on purpose in order to support direct IO.
56 * __dentry_open checks a_ops->direct_IO and returns EINVAL if it is null.
57 *
58 * However, this function won't be called by certain file operations
59 * including generic fs functions. * reads and writes are delivered to
60 * the lower file systems and the direct IOs will be handled by them.
61 *
62 * NOTE: exceptionally, on the recent kernels (since Linux 3.8.x),
63 * swap_writepage invokes this function directly.
64 */
65 printk(KERN_INFO "%s, operation is not supported\n", __func__);
66 return 0;
67}
68
69/*
70 * XXX: the default address_space_ops for sdcardfs is empty. We cannot set
71 * our inode->i_mapping->a_ops to NULL because too many code paths expect
72 * the a_ops vector to be non-NULL.
73 */
74const struct address_space_operations sdcardfs_aops = {
75 /* empty on purpose */
76 .direct_IO = sdcardfs_direct_IO,
77};
78
79const struct vm_operations_struct sdcardfs_vm_ops = {
80 .fault = sdcardfs_fault,
81};