This source file includes following definitions.
- revalidate_inode
- nfs_file_read
- nfs_file_mmap
- nfs_fsync
- do_read_nfs
- nfs_readpage
- nfs_file_write
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/fcntl.h>
23 #include <linux/stat.h>
24 #include <linux/mm.h>
25 #include <linux/nfs_fs.h>
26 #include <linux/malloc.h>
27 #include <linux/pagemap.h>
28
29 #include <asm/segment.h>
30 #include <asm/system.h>
31
32 static int nfs_file_mmap(struct inode *, struct file *, struct vm_area_struct *);
33 static int nfs_file_read(struct inode *, struct file *, char *, int);
34 static int nfs_file_write(struct inode *, struct file *, const char *, int);
35 static int nfs_fsync(struct inode *, struct file *);
36 static int nfs_readpage(struct inode * inode, struct page * page);
37
38 static struct file_operations nfs_file_operations = {
39 NULL,
40 nfs_file_read,
41 nfs_file_write,
42 NULL,
43 NULL,
44 NULL,
45 nfs_file_mmap,
46 NULL,
47 NULL,
48 nfs_fsync,
49 };
50
51 struct inode_operations nfs_file_inode_operations = {
52 &nfs_file_operations,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 NULL,
61 NULL,
62 NULL,
63 NULL,
64 nfs_readpage,
65 NULL,
66 NULL,
67 NULL
68 };
69
70 static inline void revalidate_inode(struct nfs_server * server, struct inode * inode)
71 {
72 struct nfs_fattr fattr;
73
74 if (jiffies - NFS_READTIME(inode) < server->acregmax)
75 return;
76
77 NFS_READTIME(inode) = jiffies;
78 if (nfs_proc_getattr(server, NFS_FH(inode), &fattr) == 0) {
79 nfs_refresh_inode(inode, &fattr);
80 if (fattr.mtime.seconds == NFS_OLDMTIME(inode))
81 return;
82 NFS_OLDMTIME(inode) = fattr.mtime.seconds;
83 }
84 invalidate_inode_pages(inode);
85 }
86
87
88 static int nfs_file_read(struct inode * inode, struct file * file,
89 char * buf, int count)
90 {
91 revalidate_inode(NFS_SERVER(inode), inode);
92 return generic_file_read(inode, file, buf, count);
93 }
94
95 static int nfs_file_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
96 {
97 revalidate_inode(NFS_SERVER(inode), inode);
98 return generic_file_mmap(inode, file, vma);
99 }
100
101 static int nfs_fsync(struct inode *inode, struct file *file)
102 {
103 return 0;
104 }
105
106 static inline void do_read_nfs(struct inode * inode, char * buf, unsigned long pos)
107 {
108 int refresh = 0;
109 int count = PAGE_SIZE;
110 int rsize = NFS_SERVER(inode)->rsize;
111 struct nfs_fattr fattr;
112
113 do {
114 int result;
115
116 if (count < rsize)
117 rsize = count;
118 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode),
119 pos, rsize, buf, &fattr);
120 if (result < 0)
121 break;
122 refresh = 1;
123 count -= result;
124 pos += result;
125 buf += result;
126 if (result < rsize)
127 break;
128 } while (count);
129
130 memset(buf, 0, count);
131 if (refresh)
132 nfs_refresh_inode(inode, &fattr);
133 }
134
135 static int nfs_readpage(struct inode * inode, struct page * page)
136 {
137 unsigned long address;
138
139 address = page_address(page);
140 page->count++;
141 wait_on_page(page);
142 if (page->uptodate) {
143 free_page(address);
144 return 0;
145 }
146 page->locked = 1;
147 do_read_nfs(inode, (char *) address, page->offset);
148 page->locked = 0;
149 page->uptodate = 1;
150 wake_up(&page->wait);
151 free_page(address);
152 return 0;
153 }
154
155 static int nfs_file_write(struct inode *inode, struct file *file, const char *buf,
156 int count)
157 {
158 int result, hunk, i, n, pos;
159 struct nfs_fattr fattr;
160
161 if (!inode) {
162 printk("nfs_file_write: inode = NULL\n");
163 return -EINVAL;
164 }
165 if (!S_ISREG(inode->i_mode)) {
166 printk("nfs_file_write: write to non-file, mode %07o\n",
167 inode->i_mode);
168 return -EINVAL;
169 }
170 if (count <= 0)
171 return 0;
172
173 pos = file->f_pos;
174 if (file->f_flags & O_APPEND)
175 pos = inode->i_size;
176 n = NFS_SERVER(inode)->wsize;
177 for (i = 0; i < count; i += n) {
178 hunk = count - i;
179 if (hunk >= n)
180 hunk = n;
181 result = nfs_proc_write(inode,
182 pos, hunk, buf, &fattr);
183 if (result < 0)
184 return result;
185 pos += hunk;
186 buf += hunk;
187 if (hunk < n) {
188 i += hunk;
189 break;
190 }
191 }
192 file->f_pos = pos;
193 nfs_refresh_inode(inode, &fattr);
194 return i;
195 }
196