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