kbuild: enable use of code from a different dir
[pv_ops_mirror.git] / fs / qnx4 / fsync.c
blobaa3b19544beea6aeb93bf30ceb5c1229f068aacf
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/time.h>
15 #include <linux/stat.h>
16 #include <linux/fcntl.h>
17 #include <linux/smp_lock.h>
18 #include <linux/buffer_head.h>
20 #include <linux/fs.h>
21 #include <linux/qnx4_fs.h>
23 #include <asm/system.h>
26 * The functions for qnx4 fs file synchronization.
29 #ifdef CONFIG_QNX4FS_RW
31 static int sync_block(struct inode *inode, unsigned short *block, int wait)
33 struct buffer_head *bh;
34 unsigned short tmp;
36 if (!*block)
37 return 0;
38 tmp = *block;
39 bh = sb_find_get_block(inode->i_sb, *block);
40 if (!bh)
41 return 0;
42 if (*block != tmp) {
43 brelse(bh);
44 return 1;
46 if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
47 brelse(bh);
48 return -1;
50 if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh)) {
51 brelse(bh);
52 return 0;
54 ll_rw_block(WRITE, 1, &bh);
55 atomic_dec(&bh->b_count);
56 return 0;
59 #ifdef WTF
60 static int sync_iblock(struct inode *inode, unsigned short *iblock,
61 struct buffer_head **bh, int wait)
63 int rc;
64 unsigned short tmp;
66 *bh = NULL;
67 tmp = *iblock;
68 if (!tmp)
69 return 0;
70 rc = sync_block(inode, iblock, wait);
71 if (rc)
72 return rc;
73 *bh = sb_bread(inode->i_sb, tmp);
74 if (tmp != *iblock) {
75 brelse(*bh);
76 *bh = NULL;
77 return 1;
79 if (!*bh)
80 return -1;
81 return 0;
83 #endif
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 *) qnx4_raw_inode(inode)->di_first_xtnt.xtnt_blk + i, wait);
93 if (rc > 0)
94 break;
95 if (rc)
96 err = rc;
98 return err;
101 #ifdef WTF
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;
148 #endif
150 int qnx4_sync_file(struct file *file, struct dentry *dentry, int unused)
152 struct inode *inode = dentry->d_inode;
153 int wait, err = 0;
155 (void) file;
156 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
157 S_ISLNK(inode->i_mode)))
158 return -EINVAL;
160 lock_kernel();
161 for (wait = 0; wait <= 1; wait++) {
162 err |= sync_direct(inode, wait);
164 err |= qnx4_sync_inode(inode);
165 unlock_kernel();
166 return (err < 0) ? -EIO : 0;
169 #endif