Fixed extern declaration from pointer to array
[minix.git] / servers / pfs / super.c
blob845af9f43c1ea532855753e2b82a6b89a7f2c9fe
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
9 */
11 #include "fs.h"
12 #include <string.h>
13 #include <minix/com.h>
14 #include <minix/u64.h>
15 #include "buf.h"
16 #include "inode.h"
17 #include "const.h"
20 /*===========================================================================*
21 * alloc_bit *
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;
27 bit_t b;
28 int i, bcount;
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. */
47 *wptr |= 1 << i;
49 /* Mark server 'busy' */
50 busy++;
51 return(b);
54 return(NO_BIT); /* no bit could be allocated */
58 /*===========================================================================*
59 * free_bit *
60 *===========================================================================*/
61 PUBLIC void free_bit(bit_returned)
62 bit_t bit_returned; /* number of bit to insert into the inode map*/
64 bitchunk_t *k, mask;
65 bit_t bit;
66 unsigned word;
68 /* Get word offset and bit within offset */
69 word = bit_returned / FS_BITCHUNK_BITS;
70 bit = bit_returned % FS_BITCHUNK_BITS;
72 /* Unset bit */
73 k = &inodemap[word];
74 mask = 1 << bit;
75 *k &= ~mask;
77 busy--; /* One inode less in use. */