blob: 674c66f5d4945527ad81d5bc3a6db493261952a5 [file] [log] [blame]
/*
* fs/sdcardfs/mmap.c
*
* Copyright (c) 2013 Samsung Electronics Co. Ltd
* Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
* Sunghwan Yun, Sungjong Seo
*
* This program has been developed as a stackable file system based on
* the WrapFS which written by
*
* Copyright (c) 1998-2011 Erez Zadok
* Copyright (c) 2009 Shrikar Archak
* Copyright (c) 2003-2011 Stony Brook University
* Copyright (c) 2003-2011 The Research Foundation of SUNY
*
* This file is dual licensed. It may be redistributed and/or modified
* under the terms of the Apache 2.0 License OR version 2 of the GNU
* General Public License.
*/
#include "sdcardfs.h"
static int sdcardfs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
{
int err;
struct file *file, *lower_file;
const struct vm_operations_struct *lower_vm_ops;
struct vm_area_struct lower_vma;
memcpy(&lower_vma, vma, sizeof(struct vm_area_struct));
file = lower_vma.vm_file;
lower_vm_ops = SDCARDFS_F(file)->lower_vm_ops;
BUG_ON(!lower_vm_ops);
lower_file = sdcardfs_lower_file(file);
/*
* XXX: vm_ops->fault may be called in parallel. Because we have to
* resort to temporarily changing the vma->vm_file to point to the
* lower file, a concurrent invocation of sdcardfs_fault could see a
* different value. In this workaround, we keep a different copy of
* the vma structure in our stack, so we never expose a different
* value of the vma->vm_file called to us, even temporarily. A
* better fix would be to change the calling semantics of ->fault to
* take an explicit file pointer.
*/
lower_vma.vm_file = lower_file;
err = lower_vm_ops->fault(&lower_vma, vmf);
return err;
}
static int sdcardfs_page_mkwrite(struct vm_area_struct *vma,
struct vm_fault *vmf)
{
int err = 0;
struct file *file, *lower_file;
const struct vm_operations_struct *lower_vm_ops;
struct vm_area_struct lower_vma;
memcpy(&lower_vma, vma, sizeof(struct vm_area_struct));
file = lower_vma.vm_file;
lower_vm_ops = SDCARDFS_F(file)->lower_vm_ops;
BUG_ON(!lower_vm_ops);
if (!lower_vm_ops->page_mkwrite)
goto out;
lower_file = sdcardfs_lower_file(file);
/*
* XXX: vm_ops->page_mkwrite may be called in parallel.
* Because we have to resort to temporarily changing the
* vma->vm_file to point to the lower file, a concurrent
* invocation of sdcardfs_page_mkwrite could see a different
* value. In this workaround, we keep a different copy of the
* vma structure in our stack, so we never expose a different
* value of the vma->vm_file called to us, even temporarily.
* A better fix would be to change the calling semantics of
* ->page_mkwrite to take an explicit file pointer.
*/
lower_vma.vm_file = lower_file;
err = lower_vm_ops->page_mkwrite(&lower_vma, vmf);
out:
return err;
}
static ssize_t sdcardfs_direct_IO(int rw, struct kiocb *iocb,
struct iov_iter *iter, loff_t pos)
{
/*
* This function should never be called directly. We need it
* to exist, to get past a check in open_check_o_direct(),
* which is called from do_last().
*/
return -EINVAL;
}
const struct address_space_operations sdcardfs_aops = {
.direct_IO = sdcardfs_direct_IO,
};
const struct vm_operations_struct sdcardfs_vm_ops = {
.fault = sdcardfs_fault,
.page_mkwrite = sdcardfs_page_mkwrite,
};