Repository navigation
Expand file tree
/
Copy pathsuper.c
More file actions
75 lines (59 loc) · 2.19 KB
/
Copy pathsuper.c
File metadata and controls
75 lines (59 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
8F20
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* This file manages the super block table and the related data structures,
* namely, the bit maps that keep track of which zones and which inodes are
* allocated and which are free. When a new inode or zone is needed, the
* appropriate bit map is searched for a free entry.
*
* The entry points into this file are
* alloc_bit: somebody wants to allocate a zone or inode; find one
* free_bit: indicate that a zone or inode is available for allocation
*/
#include "fs.h"
#include "buf.h"
#include "inode.h"
#include "const.h"
/*===========================================================================*
* alloc_bit *
*===========================================================================*/
bit_t alloc_bit(void)
{
/* Allocate a bit from a bit map and return its bit number. */
bitchunk_t *wptr, *wlim;
bit_t b;
unsigned int i, bcount;
bcount = FS_BITMAP_CHUNKS(PFS_NR_INODES); /* Inode map has this many chunks. */
wlim = &inodemap[bcount]; /* Point to last chunk in inodemap. */
for (wptr = &inodemap[0]; wptr < wlim; wptr++) {
/* Does this word contain a free bit? */
if (*wptr == (bitchunk_t) ~0) continue; /* No. Go to next word */
/* Find and allocate the free bit. */
for (i = 0; (*wptr & (1 << i)) != 0; ++i) {}
/* Get inode number */
b = (bit_t) ((wptr - &inodemap[0]) * FS_BITCHUNK_BITS + i);
/* Don't allocate bits beyond end of map. */
if (b >= PFS_NR_INODES) break;
/* Allocate and return bit number. */
*wptr |= 1 << i;
/* Mark server 'busy' */
busy++;
return(b);
}
return(NO_BIT); /* no bit could be allocated */
}
/*===========================================================================*
* free_bit *
*===========================================================================*/
void free_bit(bit_returned)
bit_t bit_returned; /* number of bit to insert into the inode map*/
{
bitchunk_t *k, mask;
bit_t bit;
unsigned word;
/* Get word offset and bit within offset */
word = (unsigned) (bit_returned / (bit_t) FS_BITCHUNK_BITS);
bit = bit_returned % (bit_t) FS_BITCHUNK_BITS;
/* Unset bit */
k = &inodemap[word];
mask = (unsigned) 1 << bit;
*k &= ~mask;
busy--; /* One inode less in use. */
}