This source file includes following definitions.
- minix_file_write
1
2
3
4
5
6
7
8
9 #include <linux/sched.h>
10 #include <linux/minix_fs.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/fcntl.h>
14 #include <linux/stat.h>
15 #include <linux/locks.h>
16
17 #include <asm/segment.h>
18 #include <asm/system.h>
19
20 #define NBUF 32
21
22 #define MIN(a,b) (((a)<(b))?(a):(b))
23 #define MAX(a,b) (((a)>(b))?(a):(b))
24
25 #include <linux/fs.h>
26 #include <linux/minix_fs.h>
27
28 static int minix_file_write(struct inode *, struct file *, const char *, int);
29
30
31
32
33
34 static struct file_operations minix_file_operations = {
35 NULL,
36 generic_file_read,
37 minix_file_write,
38 NULL,
39 NULL,
40 NULL,
41 generic_mmap,
42 NULL,
43 NULL,
44 minix_sync_file
45 };
46
47 struct inode_operations minix_file_inode_operations = {
48 &minix_file_operations,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 generic_readpage,
61 NULL,
62 minix_bmap,
63 minix_truncate,
64 NULL
65 };
66
67 static int minix_file_write(struct inode * inode, struct file * filp, const char * buf, int count)
68 {
69 off_t pos;
70 int written,c;
71 struct buffer_head * bh;
72 char * p;
73
74 if (!inode) {
75 printk("minix_file_write: inode = NULL\n");
76 return -EINVAL;
77 }
78 if (!S_ISREG(inode->i_mode)) {
79 printk("minix_file_write: mode = %07o\n",inode->i_mode);
80 return -EINVAL;
81 }
82 if (filp->f_flags & O_APPEND)
83 pos = inode->i_size;
84 else
85 pos = filp->f_pos;
86 written = 0;
87 while (written < count) {
88 bh = minix_getblk(inode,pos/BLOCK_SIZE,1);
89 if (!bh) {
90 if (!written)
91 written = -ENOSPC;
92 break;
93 }
94 c = BLOCK_SIZE - (pos % BLOCK_SIZE);
95 if (c > count-written)
96 c = count-written;
97 if (c != BLOCK_SIZE && !buffer_uptodate(bh)) {
98 ll_rw_block(READ, 1, &bh);
99 wait_on_buffer(bh);
100 if (!buffer_uptodate(bh)) {
101 brelse(bh);
102 if (!written)
103 written = -EIO;
104 break;
105 }
106 }
107 p = (pos % BLOCK_SIZE) + bh->b_data;
108 memcpy_fromfs(p,buf,c);
109 update_vm_cache(inode, pos, p, c);
110 mark_buffer_uptodate(bh, 1);
111 mark_buffer_dirty(bh, 0);
112 brelse(bh);
113 pos += c;
114 written += c;
115 buf += c;
116 }
117 if (pos > inode->i_size)
118 inode->i_size = pos;
119 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
120 filp->f_pos = pos;
121 inode->i_dirt = 1;
122 return written;
123 }