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; |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 26 | struct file *file; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 27 | const struct vm_operations_struct *lower_vm_ops; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 28 | |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 29 | file = (struct file *)vma->vm_private_data; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 30 | lower_vm_ops = SDCARDFS_F(file)->lower_vm_ops; |
| 31 | BUG_ON(!lower_vm_ops); |
| 32 | |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 33 | err = lower_vm_ops->fault(vma, vmf); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 34 | return err; |
| 35 | } |
| 36 | |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 37 | static void sdcardfs_vm_open(struct vm_area_struct *vma) |
| 38 | { |
| 39 | struct file *file = (struct file *)vma->vm_private_data; |
| 40 | |
| 41 | get_file(file); |
| 42 | } |
| 43 | |
| 44 | static void sdcardfs_vm_close(struct vm_area_struct *vma) |
| 45 | { |
| 46 | struct file *file = (struct file *)vma->vm_private_data; |
| 47 | |
| 48 | fput(file); |
| 49 | } |
| 50 | |
Daniel Rosenberg | 055fc87 | 2017-02-24 15:41:48 -0800 | [diff] [blame] | 51 | static int sdcardfs_page_mkwrite(struct vm_area_struct *vma, |
| 52 | struct vm_fault *vmf) |
| 53 | { |
| 54 | int err = 0; |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 55 | struct file *file; |
Daniel Rosenberg | 055fc87 | 2017-02-24 15:41:48 -0800 | [diff] [blame] | 56 | const struct vm_operations_struct *lower_vm_ops; |
Daniel Rosenberg | 055fc87 | 2017-02-24 15:41:48 -0800 | [diff] [blame] | 57 | |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 58 | file = (struct file *)vma->vm_private_data; |
Daniel Rosenberg | 055fc87 | 2017-02-24 15:41:48 -0800 | [diff] [blame] | 59 | lower_vm_ops = SDCARDFS_F(file)->lower_vm_ops; |
| 60 | BUG_ON(!lower_vm_ops); |
| 61 | if (!lower_vm_ops->page_mkwrite) |
| 62 | goto out; |
| 63 | |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 64 | err = lower_vm_ops->page_mkwrite(vma, vmf); |
Daniel Rosenberg | 055fc87 | 2017-02-24 15:41:48 -0800 | [diff] [blame] | 65 | out: |
| 66 | return err; |
| 67 | } |
| 68 | |
Amit Pundir | 71f1b59 | 2016-06-07 16:30:56 +0530 | [diff] [blame] | 69 | static ssize_t sdcardfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 70 | { |
| 71 | /* |
Daniel Rosenberg | 85626b4 | 2017-02-24 15:49:45 -0800 | [diff] [blame] | 72 | * This function should never be called directly. We need it |
| 73 | * to exist, to get past a check in open_check_o_direct(), |
| 74 | * which is called from do_last(). |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 75 | */ |
Daniel Rosenberg | 85626b4 | 2017-02-24 15:49:45 -0800 | [diff] [blame] | 76 | return -EINVAL; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 79 | const struct address_space_operations sdcardfs_aops = { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 80 | .direct_IO = sdcardfs_direct_IO, |
| 81 | }; |
| 82 | |
| 83 | const struct vm_operations_struct sdcardfs_vm_ops = { |
| 84 | .fault = sdcardfs_fault, |
Daniel Rosenberg | 055fc87 | 2017-02-24 15:41:48 -0800 | [diff] [blame] | 85 | .page_mkwrite = sdcardfs_page_mkwrite, |
Daniel Rosenberg | 2d82e2e | 2017-04-10 20:54:30 -0700 | [diff] [blame] | 86 | .open = sdcardfs_vm_open, |
| 87 | .close = sdcardfs_vm_close, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 88 | }; |