11 /*===========================================================================*
13 *===========================================================================*/
14 bit_t
count_free_bits(sp
, map
)
15 struct super_block
*sp
; /* the filesystem to allocate from */
16 int map
; /* IMAP (inode map) or ZMAP (zone map) */
18 /* Allocate a bit from a bit map and return its bit number. */
19 block_t start_block
; /* first bit block */
21 bit_t map_bits
; /* how many bits are there in the bit map? */
22 short bit_blocks
; /* how many blocks are there in the bit map? */
23 bit_t origin
; /* number of bit to start searching at */
24 unsigned word
, bcount
;
26 bitchunk_t
*wptr
, *wlim
, k
;
33 start_block
= START_BLOCK
;
34 map_bits
= (bit_t
) (sp
->s_ninodes
+ 1);
35 bit_blocks
= sp
->s_imap_blocks
;
36 origin
= sp
->s_isearch
;
38 start_block
= START_BLOCK
+ sp
->s_imap_blocks
;
39 map_bits
= (bit_t
) (sp
->s_zones
- (sp
->s_firstdatazone
- 1));
40 bit_blocks
= sp
->s_zmap_blocks
;
41 origin
= sp
->s_zsearch
;
44 /* Figure out where to start the bit search (depends on 'origin'). */
45 if (origin
>= map_bits
) origin
= 0; /* for robustness */
48 /* Locate the starting place. */
49 block
= (block_t
) (origin
/ FS_BITS_PER_BLOCK(sp
->s_block_size
));
50 word
= (origin
% FS_BITS_PER_BLOCK(sp
->s_block_size
)) / FS_BITCHUNK_BITS
;
52 /* Iterate over all blocks plus one, because we start in the middle. */
55 bp
= get_block(sp
->s_dev
, start_block
+ block
, NORMAL
);
57 wlim
= &bp
->b_bitmap
[FS_BITMAP_CHUNKS(sp
->s_block_size
)];
59 /* Iterate over the words in block. */
60 for (wptr
= &bp
->b_bitmap
[word
]; wptr
< wlim
; wptr
++) {
62 /* Does this word contain a free bit? */
63 if (*wptr
== (bitchunk_t
) ~0) continue;
65 k
= (bitchunk_t
) conv4(sp
->s_native
, (int) *wptr
);
67 for (i
= 0; i
< 8*sizeof(k
); ++i
) {
68 /* Bit number from the start of the bit map. */
69 b
= ((bit_t
) block
* FS_BITS_PER_BLOCK(sp
->s_block_size
))
70 + (wptr
- &bp
->b_bitmap
[0]) * FS_BITCHUNK_BITS
73 /* Don't count bits beyond the end of the map. */
77 if ((k
& (1 << i
)) == 0) {
82 if (b
>= map_bits
) break;
84 put_block(bp
, MAP_BLOCK
);
87 } while (--bcount
> 0);
88 return free_bits
; /* no bit could be allocated */
92 /*===========================================================================*
94 *===========================================================================*/
95 void blockstats(u32_t
*blocks
, u32_t
*free
, u32_t
*used
)
97 struct super_block
*sp
;
100 sp
= get_super(fs_dev
);
104 scale
= sp
->s_log_zone_size
;
106 *blocks
= sp
->s_zones
<< scale
;
107 *free
= count_free_bits(sp
, ZMAP
) << scale
;
108 *used
= *blocks
- *free
;