summaryrefslogtreecommitdiff
path: root/fs.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2015-06-27 12:39:13 -0400
committerFrans Kaashoek <[email protected]>2015-06-27 12:39:13 -0400
commit8320d61be5613fb2875be859695752b1487fda20 (patch)
treef0a800145225ffcd97f805be47e5b41764504898 /fs.c
parentde4af193c87b3a7fa8762ccaeb81a6addf168799 (diff)
downloadxv6-labs-8320d61be5613fb2875be859695752b1487fda20.tar.gz
xv6-labs-8320d61be5613fb2875be859695752b1487fda20.tar.bz2
xv6-labs-8320d61be5613fb2875be859695752b1487fda20.zip
Pick up where i left off in april:
- move log into metadata part of disk, so that marking that the log's blocks are in use falls out for free - superblock describes the whole disk (sizes and offets) - sizes and offsets are computed in one place (mkfs) and the rest of the code refers to the superblock for these values, instead of recomputing them.
Diffstat (limited to 'fs.c')
-rw-r--r--fs.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/fs.c b/fs.c
index 286252d..025b326 100644
--- a/fs.c
+++ b/fs.c
@@ -22,6 +22,7 @@
#define min(a, b) ((a) < (b) ? (a) : (b))
static void itrunc(struct inode*);
+struct superblock sb; // there should be one per dev, but we run with one dev
// Read the super block.
void
@@ -54,12 +55,10 @@ balloc(uint dev)
{
int b, bi, m;
struct buf *bp;
- struct superblock sb;
bp = 0;
- readsb(dev, &sb);
for(b = 0; b < sb.size; b += BPB){
- bp = bread(dev, BBLOCK(b, sb.ninodes));
+ bp = bread(dev, BBLOCK(b, sb));
for(bi = 0; bi < BPB && b + bi < sb.size; bi++){
m = 1 << (bi % 8);
if((bp->data[bi/8] & m) == 0){ // Is block free?
@@ -80,11 +79,10 @@ static void
bfree(int dev, uint b)
{
struct buf *bp;
- struct superblock sb;
int bi, m;
readsb(dev, &sb);
- bp = bread(dev, BBLOCK(b, sb.ninodes));
+ bp = bread(dev, BBLOCK(b, sb));
bi = b % BPB;
m = 1 << (bi % 8);
if((bp->data[bi/8] & m) == 0)
@@ -101,8 +99,8 @@ bfree(int dev, uint b)
// its size, the number of links referring to it, and the
// list of blocks holding the file's content.
//
-// The inodes are laid out sequentially on disk immediately after
-// the superblock. Each inode has a number, indicating its
+// The inodes are laid out sequentially on disk at
+// sb.startinode. Each inode has a number, indicating its
// position on the disk.
//
// The kernel keeps a cache of in-use inodes in memory
@@ -162,9 +160,12 @@ struct {
} icache;
void
-iinit(void)
+iinit(int dev)
{
initlock(&icache.lock, "icache");
+ readsb(dev, &sb);
+ cprintf("sb: size %d nblocks %d ninodes %d nlog %d logstart %d inodestart %d bmap start %d\n", sb.size,
+ sb.nblocks, sb.ninodes, sb.nlog, sb.logstart, sb.inodestart, sb.bmapstart);
}
static struct inode* iget(uint dev, uint inum);
@@ -178,12 +179,9 @@ ialloc(uint dev, short type)
int inum;
struct buf *bp;
struct dinode *dip;
- struct superblock sb;
-
- readsb(dev, &sb);
for(inum = 1; inum < sb.ninodes; inum++){
- bp = bread(dev, IBLOCK(inum));
+ bp = bread(dev, IBLOCK(inum, sb));
dip = (struct dinode*)bp->data + inum%IPB;
if(dip->type == 0){ // a free inode
memset(dip, 0, sizeof(*dip));
@@ -204,7 +202,7 @@ iupdate(struct inode *ip)
struct buf *bp;
struct dinode *dip;
- bp = bread(ip->dev, IBLOCK(ip->inum));
+ bp = bread(ip->dev, IBLOCK(ip->inum, sb));
dip = (struct dinode*)bp->data + ip->inum%IPB;
dip->type = ip->type;
dip->major = ip->major;
@@ -281,7 +279,7 @@ ilock(struct inode *ip)
release(&icache.lock);
if(!(ip->flags & I_VALID)){
- bp = bread(ip->dev, IBLOCK(ip->inum));
+ bp = bread(ip->dev, IBLOCK(ip->inum, sb));
dip = (struct dinode*)bp->data + ip->inum%IPB;
ip->type = dip->type;
ip->major = dip->major;