2 * QNX4 file system, Linux implementation.
6 * Using parts of the xiafs filesystem.
10 * 28-05-1998 by Richard Frowijn : first release.
11 * 20-06-1998 by Frank Denis : basic optimisations.
12 * 25-06-1998 by Frank Denis : qnx4_is_free, qnx4_set_bitmap, qnx4_bmap .
13 * 28-06-1998 by Frank Denis : qnx4_free_inode (to be fixed) .
16 #include <linux/config.h>
17 #include <linux/sched.h>
18 #include <linux/qnx4_fs.h>
19 #include <linux/stat.h>
20 #include <linux/kernel.h>
21 #include <linux/string.h>
23 #include <asm/bitops.h>
25 int qnx4_new_block(struct super_block
*sb
)
30 void count_bits(const register char *bmPart
, register int size
,
36 if (size
> QNX4_BLOCK_SIZE
) {
37 size
= QNX4_BLOCK_SIZE
;
62 unsigned long qnx4_count_free_blocks(struct super_block
*sb
)
64 int start
= sb
->u
.qnx4_sb
.BitMap
->di_first_xtnt
.xtnt_blk
- 1;
68 int size
= sb
->u
.qnx4_sb
.BitMap
->di_size
;
69 struct buffer_head
*bh
;
71 while (total
< size
) {
72 if ((bh
= bread(sb
->s_dev
, start
+ offset
, QNX4_BLOCK_SIZE
)) == NULL
) {
73 printk("qnx4: I/O error in counting free blocks\n");
76 count_bits(bh
->b_data
, size
- total
, &total_free
);
78 total
+= QNX4_BLOCK_SIZE
;
84 unsigned long qnx4_count_free_inodes(struct super_block
*sb
)
86 return qnx4_count_free_blocks(sb
) * QNX4_INODES_PER_BLOCK
; /* FIXME */
89 #ifdef CONFIG_QNX4FS_RW
91 int qnx4_is_free(struct super_block
*sb
, long block
)
93 int start
= sb
->u
.qnx4_sb
.BitMap
->di_first_xtnt
.xtnt_blk
- 1;
94 int size
= sb
->u
.qnx4_sb
.BitMap
->di_size
;
95 struct buffer_head
*bh
;
99 start
+= block
/ (QNX4_BLOCK_SIZE
* 8);
100 QNX4DEBUG(("qnx4: is_free requesting block [%lu], bitmap in block [%lu]\n",
101 (unsigned long) block
, (unsigned long) start
));
102 (void) size
; /* CHECKME */
103 bh
= bread(sb
->s_dev
, start
, QNX4_BLOCK_SIZE
);
107 g
= bh
->b_data
+ (block
% QNX4_BLOCK_SIZE
);
108 if (((*g
) & (1 << (block
% 8))) == 0) {
109 QNX4DEBUG(("qnx4: is_free -> block is free\n"));
112 QNX4DEBUG(("qnx4: is_free -> block is busy\n"));
120 int qnx4_set_bitmap(struct super_block
*sb
, long block
, int busy
)
122 int start
= sb
->u
.qnx4_sb
.BitMap
->di_first_xtnt
.xtnt_blk
- 1;
123 int size
= sb
->u
.qnx4_sb
.BitMap
->di_size
;
124 struct buffer_head
*bh
;
127 start
+= block
/ (QNX4_BLOCK_SIZE
* 8);
128 QNX4DEBUG(("qnx4: set_bitmap requesting block [%lu], bitmap in block [%lu]\n",
129 (unsigned long) block
, (unsigned long) start
));
130 (void) size
; /* CHECKME */
131 bh
= bread(sb
->s_dev
, start
, QNX4_BLOCK_SIZE
);
135 g
= bh
->b_data
+ (block
% QNX4_BLOCK_SIZE
);
137 (*g
) &= ~(1 << (block
% 8));
139 (*g
) |= (1 << (block
% 8));
141 mark_buffer_dirty(bh
, 1);
147 static void qnx4_clear_inode(struct inode
*inode
)
149 struct qnx4_inode_info
*qnx4_ino
= &inode
->u
.qnx4_i
;
151 memset(qnx4_ino
->i_reserved
, 0, sizeof qnx4_ino
->i_reserved
);
152 qnx4_ino
->i_size
= 0;
153 qnx4_ino
->i_num_xtnts
= 0;
154 qnx4_ino
->i_mode
= 0;
155 qnx4_ino
->i_status
= 0;
158 void qnx4_free_inode(struct inode
*inode
)
164 printk("free_inode: inode has no device\n");
167 if (inode
->i_count
> 1) {
168 printk("free_inode: inode has count=%d\n", inode
->i_count
);
171 if (inode
->i_nlink
) {
172 printk("free_inode: inode has nlink=%d\n", inode
->i_nlink
);
176 printk("free_inode: inode on nonexistent device\n");
179 if (inode
->i_ino
< 1) {
180 printk("free_inode: inode 0 or nonexistent inode\n");
183 qnx4_clear_inode(inode
);