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 };
34
35 struct inode_operations nfs_file_inode_operations = {
36 &nfs_file_operations,
37 NULL,
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 };
51
52 static int nfs_file_read(struct inode *inode, struct file *file, char *buf,
53 int count)
54 {
55 int result;
56 int hunk;
57 int i;
58 int n;
59 struct nfs_fattr fattr;
60 char *data;
61 off_t pos;
62
63 if (!inode) {
64 printk("nfs_file_read: inode = NULL\n");
65 return -EINVAL;
66 }
67 if (!S_ISREG(inode->i_mode)) {
68 printk("nfs_file_read: read from non-file, mode %07o\n",
69 inode->i_mode);
70 return -EINVAL;
71 }
72 pos = file->f_pos;
73 if (file->f_pos + count > inode->i_size)
74 count = inode->i_size - pos;
75 if (count <= 0)
76 return 0;
77 n = NFS_SERVER(inode)->rsize;
78 data = (char *) kmalloc(n, GFP_KERNEL);
79 for (i = 0; i < count; i += n) {
80 hunk = count - i;
81 if (hunk > n)
82 hunk = n;
83 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode),
84 pos, hunk, data, &fattr);
85 if (result < 0) {
86 kfree_s(data, n);
87 return result;
88 }
89 memcpy_tofs(buf, data, result);
90 pos += result;
91 buf += result;
92 if (result < n) {
93 i += result;
94 break;
95 }
96 }
97 file->f_pos = pos;
98 kfree_s(data, n);
99 nfs_refresh_inode(inode, &fattr);
100 return i;
101 }
102
103 static int nfs_file_write(struct inode *inode, struct file *file, char *buf,
104 int count)
105 {
106 int result;
107 int hunk;
108 int i;
109 int n;
110 struct nfs_fattr fattr;
111 char *data;
112 int pos;
113
114 if (!inode) {
115 printk("nfs_file_write: inode = NULL\n");
116 return -EINVAL;
117 }
118 if (!S_ISREG(inode->i_mode)) {
119 printk("nfs_file_write: write to non-file, mode %07o\n",
120 inode->i_mode);
121 return -EINVAL;
122 }
123 if (count <= 0)
124 return 0;
125 pos = file->f_pos;
126 if (file->f_flags & O_APPEND)
127 pos = inode->i_size;
128 n = NFS_SERVER(inode)->wsize;
129 data = (char *) kmalloc(n, GFP_KERNEL);
130 for (i = 0; i < count; i += n) {
131 hunk = count - i;
132 if (hunk >= n)
133 hunk = n;
134 memcpy_fromfs(data, buf, hunk);
135 result = nfs_proc_write(NFS_SERVER(inode), NFS_FH(inode),
136 pos, hunk, data, &fattr);
137 if (result < 0) {
138 kfree_s(data, n);
139 return result;
140 }
141 pos += hunk;
142 buf += hunk;
143 if (hunk < n) {
144 i += hunk;
145 break;
146 }
147 }
148 file->f_pos = pos;
149 kfree_s(data, n);
150 nfs_refresh_inode(inode, &fattr);
151 return i;
152 }
153