-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmap.c
105 lines (93 loc) · 3.08 KB
/
mmap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright (c) 1998-2015 Erez Zadok
* Copyright (c) 2009 Shrikar Archak
* Copyright (c) 2003-2015 Stony Brook University
* Copyright (c) 2003-2015 The Research Foundation of SUNY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/*
* CSE-506 : Operating Systems HW2
* Author : Meng-Chieh Yang
* ID : 110452591
* Date : 11/1/16
*
* mmap.c:
* - modify function name
*
*/
#include "trfs.h"
static int trfs_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 = TRFS_F(file)->lower_vm_ops;
BUG_ON(!lower_vm_ops);
lower_file = trfs_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 trfs_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 trfs_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 = TRFS_F(file)->lower_vm_ops;
BUG_ON(!lower_vm_ops);
if (!lower_vm_ops->page_mkwrite)
goto out;
lower_file = trfs_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 trfs_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 trfs_direct_IO(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 trfs_aops = {
.direct_IO = trfs_direct_IO,
};
const struct vm_operations_struct trfs_vm_ops = {
.fault = trfs_fault,
.page_mkwrite = trfs_page_mkwrite,
};