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
13 #include <minix/com.h>
14 #include <minix/u64.h>
20 /*===========================================================================*
22 *===========================================================================*/
23 PUBLIC bit_t
alloc_bit(void)
25 /* Allocate a bit from a bit map and return its bit number. */
26 bitchunk_t
*wptr
, *wlim
;
30 bcount
= FS_BITMAP_CHUNKS(NR_INODES
); /* Inode map has this many chunks. */
31 wlim
= &inodemap
[bcount
]; /* Point to last chunk in inodemap. */
33 for (wptr
= &inodemap
[0]; wptr
< wlim
; wptr
++) {
34 /* Does this word contain a free bit? */
35 if (*wptr
== (bitchunk_t
) ~0) continue; /* No. Go to next word */
37 /* Find and allocate the free bit. */
38 for (i
= 0; (*wptr
& (1 << i
)) != 0; ++i
) {}
40 /* Get inode number */
41 b
= (wptr
- &inodemap
[0]) * FS_BITCHUNK_BITS
+ i
;
43 /* Don't allocate bits beyond end of map. */
44 if (b
>= NR_INODES
) break;
46 /* Allocate and return bit number. */
49 /* Mark server 'busy' */
54 return(NO_BIT
); /* no bit could be allocated */
58 /*===========================================================================*
60 *===========================================================================*/
61 PUBLIC
void free_bit(bit_returned
)
62 bit_t bit_returned
; /* number of bit to insert into the inode map*/
68 /* Get word offset and bit within offset */
69 word
= bit_returned
/ FS_BITCHUNK_BITS
;
70 bit
= bit_returned
% FS_BITCHUNK_BITS
;
77 busy
--; /* One inode less in use. */