This source file includes following definitions.
- sysv_file_read
- sysv_file_write
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <asm/segment.h>
17
18 #include <linux/kernel.h>
19 #include <linux/fs.h>
20 #include <linux/sysv_fs.h>
21 #include <linux/errno.h>
22 #include <linux/fcntl.h>
23 #include <linux/stat.h>
24 #include <linux/string.h>
25 #include <linux/locks.h>
26
27 #define NBUF 32
28
29 #define MIN(a,b) (((a)<(b))?(a):(b))
30 #define MAX(a,b) (((a)>(b))?(a):(b))
31
32 #include <linux/fs.h>
33 #include <linux/sysv_fs.h>
34
35 static int sysv_file_write(struct inode *, struct file *, char *, int);
36
37
38
39
40
41 static struct file_operations sysv_file_operations = {
42 NULL,
43 sysv_file_read,
44 sysv_file_write,
45 NULL,
46 NULL,
47 NULL,
48 sysv_mmap,
49 NULL,
50 NULL,
51 sysv_sync_file
52 };
53
54 static struct file_operations sysv_file_operations_with_bmap = {
55 NULL,
56 sysv_file_read,
57 sysv_file_write,
58 NULL,
59 NULL,
60 NULL,
61 generic_mmap,
62 NULL,
63 NULL,
64 sysv_sync_file
65 };
66
67 struct inode_operations sysv_file_inode_operations = {
68 &sysv_file_operations,
69 NULL,
70 NULL,
71 NULL,
72 NULL,
73 NULL,
74 NULL,
75 NULL,
76 NULL,
77 NULL,
78 NULL,
79 NULL,
80 NULL,
81 sysv_truncate,
82 NULL
83 };
84
85 struct inode_operations sysv_file_inode_operations_with_bmap = {
86 &sysv_file_operations_with_bmap,
87 NULL,
88 NULL,
89 NULL,
90 NULL,
91 NULL,
92 NULL,
93 NULL,
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 sysv_bmap,
99 sysv_truncate,
100 NULL
101 };
102
103 struct sysv_buffer {
104 struct buffer_head * bh;
105 char * bh_data;
106 };
107
108 int sysv_file_read(struct inode * inode, struct file * filp, char * buf, int count)
109 {
110 struct super_block * sb = inode->i_sb;
111 int read,left,chars;
112 unsigned int block;
113 int blocks, offset;
114 int bhrequest, bhreqi, uptodate;
115 struct sysv_buffer * bhb, * bhe;
116 struct buffer_head * bhreq[NBUF];
117 struct sysv_buffer buflist[NBUF];
118 unsigned int size;
119
120 if (!inode) {
121 printk("sysv_file_read: inode = NULL\n");
122 return -EINVAL;
123 }
124 if (!S_ISREG(inode->i_mode)) {
125 printk("sysv_file_read: mode = %07o\n",inode->i_mode);
126 return -EINVAL;
127 }
128 offset = filp->f_pos;
129 size = inode->i_size;
130 if (offset > size)
131 left = 0;
132 else
133 left = size - offset;
134 if (left > count)
135 left = count;
136 if (left <= 0)
137 return 0;
138 read = 0;
139 block = offset >> sb->sv_block_size_bits;
140 offset &= sb->sv_block_size_1;
141 size = (size + sb->sv_block_size_1) >> sb->sv_block_size_bits;
142 blocks = (left + offset + sb->sv_block_size_1) >> sb->sv_block_size_bits;
143 bhb = bhe = buflist;
144 if (filp->f_reada) {
145 blocks += read_ahead[MAJOR(inode->i_dev)] >> (sb->sv_block_size_bits - 9);
146 if (block + blocks > size)
147 blocks = size - block;
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 do {
165 bhrequest = 0;
166 uptodate = 1;
167 while (blocks) {
168 --blocks;
169 bhb->bh = sysv_getblk(inode, block++, 0, &bhb->bh_data);
170 if (bhb->bh && !bhb->bh->b_uptodate) {
171 uptodate = 0;
172 if (sb->sv_block_size_ratio_bits > 0)
173 for (bhreqi = 0; bhreqi < bhrequest; bhreqi++)
174 if (bhreq[bhreqi] == bhb->bh)
175 goto notreq;
176 bhreq[bhrequest++] = bhb->bh;
177 notreq: ;
178 }
179
180 if (++bhb == &buflist[NBUF])
181 bhb = buflist;
182
183
184
185 if (uptodate)
186 break;
187 if (bhb == bhe)
188 break;
189 }
190
191
192 if (bhrequest)
193 ll_rw_block(READ, bhrequest, bhreq);
194
195 do {
196 if (bhe->bh) {
197 wait_on_buffer(bhe->bh);
198 if (!bhe->bh->b_uptodate) {
199 brelse(bhe->bh);
200 if (++bhe == &buflist[NBUF])
201 bhe = buflist;
202 left = 0;
203 break;
204 }
205 }
206 if (left < sb->sv_block_size - offset)
207 chars = left;
208 else
209 chars = sb->sv_block_size - offset;
210 filp->f_pos += chars;
211 left -= chars;
212 read += chars;
213 if (bhe->bh) {
214 memcpy_tofs(buf,offset+bhe->bh_data,chars);
215 brelse(bhe->bh);
216 buf += chars;
217 } else {
218 while (chars-- > 0)
219 put_fs_byte(0,buf++);
220 }
221 offset = 0;
222 if (++bhe == &buflist[NBUF])
223 bhe = buflist;
224 } while (left > 0 && bhe != bhb && (!bhe->bh || !bhe->bh->b_lock));
225 } while (left > 0);
226
227
228 while (bhe != bhb) {
229 brelse(bhe->bh);
230 if (++bhe == &buflist[NBUF])
231 bhe = buflist;
232 };
233 if (!read)
234 return -EIO;
235 filp->f_reada = 1;
236 if (!IS_RDONLY(inode))
237 inode->i_atime = CURRENT_TIME;
238 return read;
239 }
240
241 static int sysv_file_write(struct inode * inode, struct file * filp, char * buf, int count)
242 {
243 struct super_block * sb = inode->i_sb;
244 off_t pos;
245 int written,c;
246 struct buffer_head * bh;
247 char * bh_data;
248 char * p;
249
250 if (!inode) {
251 printk("sysv_file_write: inode = NULL\n");
252 return -EINVAL;
253 }
254 if (!S_ISREG(inode->i_mode)) {
255 printk("sysv_file_write: mode = %07o\n",inode->i_mode);
256 return -EINVAL;
257 }
258
259
260
261
262
263
264
265 if (sb->sv_block_size_ratio_bits > 0)
266 coh_lock_inode(inode);
267 if (filp->f_flags & O_APPEND)
268 pos = inode->i_size;
269 else
270 pos = filp->f_pos;
271 written = 0;
272 while (written<count) {
273 bh = sysv_getblk (inode, pos >> sb->sv_block_size_bits, 1, &bh_data);
274 if (!bh) {
275 if (!written)
276 written = -ENOSPC;
277 break;
278 }
279 c = sb->sv_block_size - (pos & sb->sv_block_size_1);
280 if (c > count-written)
281 c = count-written;
282 if (c != BLOCK_SIZE && !bh->b_uptodate) {
283 ll_rw_block(READ, 1, &bh);
284 wait_on_buffer(bh);
285 if (!bh->b_uptodate) {
286 brelse(bh);
287 if (!written)
288 written = -EIO;
289 break;
290 }
291 }
292
293 p = (pos & sb->sv_block_size_1) + bh_data;
294 pos += c;
295 if (pos > inode->i_size) {
296 inode->i_size = pos;
297 inode->i_dirt = 1;
298 }
299 written += c;
300 memcpy_fromfs(p,buf,c);
301 buf += c;
302 bh->b_uptodate = 1;
303 mark_buffer_dirty(bh, 0);
304 brelse(bh);
305 }
306 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
307 filp->f_pos = pos;
308 inode->i_dirt = 1;
309 if (sb->sv_block_size_ratio_bits > 0)
310 coh_unlock_inode(inode);
311 return written;
312 }