This source file includes following definitions.
- nfs_file_read
- nfs_file_write
1
2
3
4
5
6
7
8
9 #include <asm/segment.h>
10 #include <asm/system.h>
11
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/fcntl.h>
16 #include <linux/stat.h>
17 #include <linux/mm.h>
18 #include <linux/nfs_fs.h>
19
20 static int nfs_file_read(struct inode *, struct file *, char *, int);
21 static int nfs_file_write(struct inode *, struct file *, char *, int);
22
23 static struct file_operations nfs_file_operations = {
24 NULL,
25 nfs_file_read,
26 nfs_file_write,
27 NULL,
28 NULL,
29 NULL,
30 NULL,
31 NULL,
32 NULL,
33 NULL
34 };
35
36 struct inode_operations nfs_file_inode_operations = {
37 &nfs_file_operations,
38 NULL,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL
51 };
52
53 static int nfs_file_read(struct inode *inode, struct file *file, char *buf,
54 int count)
55 {
56 int result;
57 int hunk;
58 int i;
59 int n;
60 struct nfs_fattr fattr;
61 char *data;
62 off_t pos;
63
64 if (!inode) {
65 printk("nfs_file_read: inode = NULL\n");
66 return -EINVAL;
67 }
68 if (!S_ISREG(inode->i_mode)) {
69 printk("nfs_file_read: read from non-file, mode %07o\n",
70 inode->i_mode);
71 return -EINVAL;
72 }
73 pos = file->f_pos;
74 if (file->f_pos + count > inode->i_size)
75 count = inode->i_size - pos;
76 if (count <= 0)
77 return 0;
78 n = NFS_SERVER(inode)->rsize;
79 data = (char *) kmalloc(n, GFP_KERNEL);
80 for (i = 0; i < count; i += n) {
81 hunk = count - i;
82 if (hunk > n)
83 hunk = n;
84 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode),
85 pos, hunk, data, &fattr);
86 if (result < 0) {
87 kfree_s(data, n);
88 return result;
89 }
90 memcpy_tofs(buf, data, result);
91 pos += result;
92 buf += result;
93 if (result < n) {
94 i += result;
95 break;
96 }
97 }
98 file->f_pos = pos;
99 kfree_s(data, n);
100 nfs_refresh_inode(inode, &fattr);
101 return i;
102 }
103
104 static int nfs_file_write(struct inode *inode, struct file *file, char *buf,
105 int count)
106 {
107 int result;
108 int hunk;
109 int i;
110 int n;
111 struct nfs_fattr fattr;
112 char *data;
113 int pos;
114
115 if (!inode) {
116 printk("nfs_file_write: inode = NULL\n");
117 return -EINVAL;
118 }
119 if (!S_ISREG(inode->i_mode)) {
120 printk("nfs_file_write: write to non-file, mode %07o\n",
121 inode->i_mode);
122 return -EINVAL;
123 }
124 if (count <= 0)
125 return 0;
126 pos = file->f_pos;
127 if (file->f_flags & O_APPEND)
128 pos = inode->i_size;
129 n = NFS_SERVER(inode)->wsize;
130 data = (char *) kmalloc(n, GFP_KERNEL);
131 for (i = 0; i < count; i += n) {
132 hunk = count - i;
133 if (hunk >= n)
134 hunk = n;
135 memcpy_fromfs(data, buf, hunk);
136 result = nfs_proc_write(NFS_SERVER(inode), NFS_FH(inode),
137 pos, hunk, data, &fattr);
138 if (result < 0) {
139 kfree_s(data, n);
140 return result;
141 }
142 pos += hunk;
143 buf += hunk;
144 if (hunk < n) {
145 i += hunk;
146 break;
147 }
148 }
149 file->f_pos = pos;
150 kfree_s(data, n);
151 nfs_refresh_inode(inode, &fattr);
152 return i;
153 }
154