This source file includes following definitions.
- revalidate_inode
- nfs_file_read
- nfs_file_mmap
- nfs_fsync
- 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
37 static struct file_operations nfs_file_operations = {
38 NULL,
39 nfs_file_read,
40 nfs_file_write,
41 NULL,
42 NULL,
43 NULL,
44 nfs_file_mmap,
45 NULL,
46 NULL,
47 nfs_fsync,
48 };
49
50 struct inode_operations nfs_file_inode_operations = {
51 &nfs_file_operations,
52 NULL,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 NULL,
61 NULL,
62 NULL,
63 nfs_readpage,
64 NULL,
65 NULL,
66 NULL
67 };
68
69 static inline void revalidate_inode(struct nfs_server * server, struct inode * inode)
70 {
71 struct nfs_fattr fattr;
72
73 if (jiffies - NFS_READTIME(inode) < server->acregmax)
74 return;
75
76 NFS_READTIME(inode) = jiffies;
77 if (nfs_proc_getattr(server, NFS_FH(inode), &fattr) == 0) {
78 nfs_refresh_inode(inode, &fattr);
79 if (fattr.mtime.seconds == NFS_OLDMTIME(inode))
80 return;
81 NFS_OLDMTIME(inode) = fattr.mtime.seconds;
82 }
83 invalidate_inode_pages(inode);
84 }
85
86
87 static int nfs_file_read(struct inode * inode, struct file * file,
88 char * buf, int count)
89 {
90 revalidate_inode(NFS_SERVER(inode), inode);
91 return generic_file_read(inode, file, buf, count);
92 }
93
94 static int nfs_file_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
95 {
96 revalidate_inode(NFS_SERVER(inode), inode);
97 return generic_file_mmap(inode, file, vma);
98 }
99
100 static int nfs_fsync(struct inode *inode, struct file *file)
101 {
102 return 0;
103 }
104
105 static int nfs_file_write(struct inode *inode, struct file *file, const char *buf,
106 int count)
107 {
108 int result, written, wsize;
109 struct nfs_fattr fattr;
110 unsigned long pos;
111
112 if (!inode) {
113 printk("nfs_file_write: inode = NULL\n");
114 return -EINVAL;
115 }
116 if (!S_ISREG(inode->i_mode)) {
117 printk("nfs_file_write: write to non-file, mode %07o\n",
118 inode->i_mode);
119 return -EINVAL;
120 }
121 if (count <= 0)
122 return 0;
123
124 pos = file->f_pos;
125 if (file->f_flags & O_APPEND)
126 pos = inode->i_size;
127 wsize = NFS_SERVER(inode)->wsize;
128 result = 0;
129 written = 0;
130 while (written < count) {
131 int hunk = count - written;
132 if (hunk >= wsize)
133 hunk = wsize;
134 result = nfs_proc_write(inode,
135 pos, hunk, buf, &fattr);
136 if (result < 0)
137 break;
138 pos += hunk;
139 buf += hunk;
140 written += hunk;
141 if (hunk < wsize)
142 break;
143 }
144 if (!written)
145 return result;
146 file->f_pos = pos;
147 if (pos > inode->i_size)
148 inode->i_size = pos;
149 nfs_refresh_inode(inode, &fattr);
150 return written;
151 }
152