Linux 2.2.0
[davej-history.git] / fs / qnx4 / fsync.c
blob826ee8a093ea504585407d14f77ddd60e3df33e6
1 /*
2 * QNX4 file system, Linux implementation.
3 *
4 * Version : 0.1
5 *
6 * Using parts of the xiafs filesystem.
7 *
8 * History :
9 *
10 * 24-03-1998 by Richard Frowijn : first release.
13 #include <linux/config.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/stat.h>
17 #include <linux/fcntl.h>
18 #include <linux/locks.h>
20 #include <linux/fs.h>
21 #include <linux/qnx4_fs.h>
23 #include <asm/segment.h>
24 #include <asm/system.h>
26 #define blocksize QNX4_BLOCK_SIZE
29 * The functions for qnx4 fs file synchronization.
32 #ifdef CONFIG_QNX4FS_RW
34 static int sync_block(struct inode *inode, unsigned short *block, int wait)
36 struct buffer_head *bh;
37 unsigned short tmp;
39 if (!*block)
40 return 0;
41 tmp = *block;
42 bh = get_hash_table(inode->i_dev, *block, blocksize);
43 if (!bh)
44 return 0;
45 if (*block != tmp) {
46 brelse(bh);
47 return 1;
49 if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
50 brelse(bh);
51 return -1;
53 if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh)) {
54 brelse(bh);
55 return 0;
57 ll_rw_block(WRITE, 1, &bh);
58 bh->b_count--;
59 return 0;
62 static int sync_iblock(struct inode *inode, unsigned short *iblock,
63 struct buffer_head **bh, int wait)
65 int rc;
66 unsigned short tmp;
68 *bh = NULL;
69 tmp = *iblock;
70 if (!tmp)
71 return 0;
72 rc = sync_block(inode, iblock, wait);
73 if (rc)
74 return rc;
75 *bh = bread(inode->i_dev, tmp, blocksize);
76 if (tmp != *iblock) {
77 brelse(*bh);
78 *bh = NULL;
79 return 1;
81 if (!*bh)
82 return -1;
83 return 0;
86 static int sync_direct(struct inode *inode, int wait)
88 int i;
89 int rc, err = 0;
91 for (i = 0; i < 7; i++) {
92 rc = sync_block(inode,
93 (unsigned short *) inode->u.qnx4_i.i_first_xtnt.xtnt_blk + i, wait);
94 if (rc > 0)
95 break;
96 if (rc)
97 err = rc;
99 return err;
102 static int sync_indirect(struct inode *inode, unsigned short *iblock, int wait)
104 int i;
105 struct buffer_head *ind_bh;
106 int rc, err = 0;
108 rc = sync_iblock(inode, iblock, &ind_bh, wait);
109 if (rc || !ind_bh)
110 return rc;
112 for (i = 0; i < 512; i++) {
113 rc = sync_block(inode,
114 ((unsigned short *) ind_bh->b_data) + i,
115 wait);
116 if (rc > 0)
117 break;
118 if (rc)
119 err = rc;
121 brelse(ind_bh);
122 return err;
125 static int sync_dindirect(struct inode *inode, unsigned short *diblock,
126 int wait)
128 int i;
129 struct buffer_head *dind_bh;
130 int rc, err = 0;
132 rc = sync_iblock(inode, diblock, &dind_bh, wait);
133 if (rc || !dind_bh)
134 return rc;
136 for (i = 0; i < 512; i++) {
137 rc = sync_indirect(inode,
138 ((unsigned short *) dind_bh->b_data) + i,
139 wait);
140 if (rc > 0)
141 break;
142 if (rc)
143 err = rc;
145 brelse(dind_bh);
146 return err;
149 int qnx4_sync_file(struct file *file, struct dentry *dentry)
151 struct inode *inode = dentry->d_inode;
152 int wait, err = 0;
154 (void) file;
155 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
156 S_ISLNK(inode->i_mode)))
157 return -EINVAL;
159 for (wait = 0; wait <= 1; wait++) {
160 err |= sync_direct(inode, wait);
162 err |= qnx4_sync_inode(inode);
163 return (err < 0) ? -EIO : 0;
166 #endif