phunix/minix/fs/pfs/super.c
David van Moolenbroek f859061eaf PFS: use libfsdriver
In order to avoid creating libfsdriver exceptions, two changes to VFS
are necessary:

- the returned position field for reads/writes is no longer abused to
  return the new pipe size; VFS is perfectly capable of updating the
  size itself;
- during system startup, PFS is now sent a mount request, just like all
  other file systems.

In proper "two steps forward, one step back" fashion, the latter point
has the consequence that PFS can no longer drop its privileges at
startup.  This is probably best resolved with a more general solution
for all boot image system services.  The upside is that PFS no longer
needs to be linked with libc.

Change-Id: I92e2410cdb0d93d0e6107bae10bc08efc2dbb8b3
2014-09-18 12:46:28 +00:00

73 lines
2.1 KiB
C

/* 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"
/*===========================================================================*
* 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. */
}