- Add QNX4 file system.
[davej-history.git] / fs / qnx4 / fsync.c
blob8e7df05129761f7bc93b5ea107d21e56d9bec94c
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/errno.h>
14 #include <linux/sched.h>
15 #include <linux/stat.h>
16 #include <linux/fcntl.h>
17 #include <linux/locks.h>
19 #include <linux/fs.h>
20 #include <linux/qnx4_fs.h>
22 #include <asm/segment.h>
23 #include <asm/system.h>
25 #define blocksize QNX4_BLOCK_SIZE
28 * The functions for qnx4 fs file synchronization.
31 #ifdef CONFIG_QNX4FS_RW
33 static int sync_block(struct inode *inode, unsigned short *block, int wait)
35 struct buffer_head *bh;
36 unsigned short tmp;
38 if (!*block)
39 return 0;
40 tmp = *block;
41 bh = get_hash_table(inode->i_dev, *block, blocksize);
42 if (!bh)
43 return 0;
44 if (*block != tmp) {
45 brelse(bh);
46 return 1;
48 if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
49 brelse(bh);
50 return -1;
52 if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh)) {
53 brelse(bh);
54 return 0;
56 ll_rw_block(WRITE, 1, &bh);
57 bh->b_count--;
58 return 0;
61 static int sync_iblock(struct inode *inode, unsigned short *iblock,
62 struct buffer_head **bh, int wait)
64 int rc;
65 unsigned short tmp;
67 *bh = NULL;
68 tmp = *iblock;
69 if (!tmp)
70 return 0;
71 rc = sync_block(inode, iblock, wait);
72 if (rc)
73 return rc;
74 *bh = bread(inode->i_dev, tmp, blocksize);
75 if (tmp != *iblock) {
76 brelse(*bh);
77 *bh = NULL;
78 return 1;
80 if (!*bh)
81 return -1;
82 return 0;
85 static int sync_direct(struct inode *inode, int wait)
87 int i;
88 int rc, err = 0;
90 for (i = 0; i < 7; i++) {
91 rc = sync_block(inode,
92 (unsigned short *) inode->u.qnx4_i.i_first_xtnt.xtnt_blk + i, wait);
93 if (rc > 0)
94 break;
95 if (rc)
96 err = rc;
98 return err;
101 static int sync_indirect(struct inode *inode, unsigned short *iblock, int wait)
103 int i;
104 struct buffer_head *ind_bh;
105 int rc, err = 0;
107 rc = sync_iblock(inode, iblock, &ind_bh, wait);
108 if (rc || !ind_bh)
109 return rc;
111 for (i = 0; i < 512; i++) {
112 rc = sync_block(inode,
113 ((unsigned short *) ind_bh->b_data) + i,
114 wait);
115 if (rc > 0)
116 break;
117 if (rc)
118 err = rc;
120 brelse(ind_bh);
121 return err;
124 static int sync_dindirect(struct inode *inode, unsigned short *diblock,
125 int wait)
127 int i;
128 struct buffer_head *dind_bh;
129 int rc, err = 0;
131 rc = sync_iblock(inode, diblock, &dind_bh, wait);
132 if (rc || !dind_bh)
133 return rc;
135 for (i = 0; i < 512; i++) {
136 rc = sync_indirect(inode,
137 ((unsigned short *) dind_bh->b_data) + i,
138 wait);
139 if (rc > 0)
140 break;
141 if (rc)
142 err = rc;
144 brelse(dind_bh);
145 return err;
148 int qnx4_sync_file(struct file *file, struct dentry *dentry)
150 struct inode *inode = dentry->d_inode;
151 int wait, err = 0;
153 (void) file;
154 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
155 S_ISLNK(inode->i_mode)))
156 return -EINVAL;
158 for (wait = 0; wait <= 1; wait++) {
159 err |= sync_direct(inode, wait);
161 err |= qnx4_sync_inode(inode);
162 return (err < 0) ? -EIO : 0;
165 #endif