vm, kernel, top: report memory usage of vm, kernel
[minix.git] / servers / pfs / super.c
blob958fa2a6b149e525d0a7ec2423150ff9291eabe6
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 "buf.h"
13 #include "inode.h"
14 #include "const.h"
17 /*===========================================================================*
18 * alloc_bit *
19 *===========================================================================*/
20 bit_t alloc_bit(void)
22 /* Allocate a bit from a bit map and return its bit number. */
23 bitchunk_t *wptr, *wlim;
24 bit_t b;
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. */
44 *wptr |= 1 << i;
46 /* Mark server 'busy' */
47 busy++;
48 return(b);
51 return(NO_BIT); /* no bit could be allocated */
55 /*===========================================================================*
56 * free_bit *
57 *===========================================================================*/
58 void free_bit(bit_returned)
59 bit_t bit_returned; /* number of bit to insert into the inode map*/
61 bitchunk_t *k, mask;
62 bit_t bit;
63 unsigned word;
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;
69 /* Unset bit */
70 k = &inodemap[word];
71 mask = (unsigned) 1 << bit;
72 *k &= ~mask;
74 busy--; /* One inode less in use. */