This source file includes following definitions.
- minix_file_read
- minix_file_write
1
2
3
4
5
6
7 #include <errno.h>
8 #include <fcntl.h>
9
10 #include <linux/sched.h>
11 #include <linux/minix_fs.h>
12 #include <linux/kernel.h>
13 #include <asm/segment.h>
14
15 #define MIN(a,b) (((a)<(b))?(a):(b))
16 #define MAX(a,b) (((a)>(b))?(a):(b))
17
18 int minix_file_read(struct inode * inode, struct file * filp, char * buf, int count)
19 {
20 int read,left,chars,nr;
21 struct buffer_head * bh;
22
23 if (filp->f_pos > inode->i_size)
24 left = 0;
25 else
26 left = inode->i_size - filp->f_pos;
27 if (left > count)
28 left = count;
29 read = 0;
30 while (left > 0) {
31 if (nr = bmap(inode,(filp->f_pos)>>BLOCK_SIZE_BITS)) {
32 if (!(bh=bread(inode->i_dev,nr)))
33 return read?read:-EIO;
34 } else
35 bh = NULL;
36 nr = filp->f_pos & (BLOCK_SIZE-1);
37 chars = MIN( BLOCK_SIZE-nr , left );
38 filp->f_pos += chars;
39 left -= chars;
40 read += chars;
41 if (bh) {
42 memcpy_tofs(buf,nr+bh->b_data,chars);
43 buf += chars;
44 brelse(bh);
45 } else {
46 while (chars-->0)
47 put_fs_byte(0,buf++);
48 }
49 }
50 inode->i_atime = CURRENT_TIME;
51 return read;
52 }
53
54 int minix_file_write(struct inode * inode, struct file * filp, char * buf, int count)
55 {
56 off_t pos;
57 int written,block,c;
58 struct buffer_head * bh;
59 char * p;
60
61
62
63
64
65 if (filp->f_flags & O_APPEND)
66 pos = inode->i_size;
67 else
68 pos = filp->f_pos;
69 written = 0;
70 while (written<count) {
71 if (!(block = minix_create_block(inode,pos/BLOCK_SIZE))) {
72 if (!written)
73 written = -ENOSPC;
74 break;
75 }
76 if (!(bh=bread(inode->i_dev,block))) {
77 if (!written)
78 written = -EIO;
79 break;
80 }
81 c = pos % BLOCK_SIZE;
82 p = c + bh->b_data;
83 c = BLOCK_SIZE-c;
84 if (c > count-written)
85 c = count-written;
86 pos += c;
87 if (pos > inode->i_size) {
88 inode->i_size = pos;
89 inode->i_dirt = 1;
90 }
91 written += c;
92 memcpy_fromfs(p,buf,c);
93 buf += c;
94 bh->b_dirt = 1;
95 brelse(bh);
96 }
97 inode->i_mtime = CURRENT_TIME;
98 if (!(filp->f_flags & O_APPEND)) {
99 filp->f_pos = pos;
100 inode->i_ctime = CURRENT_TIME;
101 inode->i_dirt = 1;
102 }
103 return written;
104 }