1 /* This file manages the super block table and the related data structures,
2 * namely, the bit maps that keep track of which zones and which inodes are
3 * allocated and which are free. When a new inode or zone is needed, the
4 * appropriate bit map is searched for a free entry.
6 * The entry points into this file are
7 * alloc_bit: somebody wants to allocate a zone or inode; find one
8 * free_bit: indicate that a zone or inode is available for allocation
17 /*===========================================================================*
19 *===========================================================================*/
22 /* Allocate a bit from a bit map and return its bit number. */
23 bitchunk_t
*wptr
, *wlim
;
25 unsigned int i
, bcount
;
27 bcount
= FS_BITMAP_CHUNKS(NR_INODES
); /* Inode map has this many chunks. */
28 wlim
= &inodemap
[bcount
]; /* Point to last chunk in inodemap. */
30 for (wptr
= &inodemap
[0]; wptr
< wlim
; wptr
++) {
31 /* Does this word contain a free bit? */
32 if (*wptr
== (bitchunk_t
) ~0) continue; /* No. Go to next word */
34 /* Find and allocate the free bit. */
35 for (i
= 0; (*wptr
& (1 << i
)) != 0; ++i
) {}
37 /* Get inode number */
38 b
= (bit_t
) ((wptr
- &inodemap
[0]) * FS_BITCHUNK_BITS
+ i
);
40 /* Don't allocate bits beyond end of map. */
41 if (b
>= NR_INODES
) break;
43 /* Allocate and return bit number. */
46 /* Mark server 'busy' */
51 return(NO_BIT
); /* no bit could be allocated */
55 /*===========================================================================*
57 *===========================================================================*/
58 void free_bit(bit_returned
)
59 bit_t bit_returned
; /* number of bit to insert into the inode map*/
65 /* Get word offset and bit within offset */
66 word
= (unsigned) (bit_returned
/ (bit_t
) FS_BITCHUNK_BITS
);
67 bit
= bit_returned
% (bit_t
) FS_BITCHUNK_BITS
;
71 mask
= (unsigned) 1 << bit
;
74 busy
--; /* One inode less in use. */