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