Homework: bigger files for xv6
修改param.h
:
#define FSSIZE 20000 // size of file system in blocks
修改fs.h
:
#define NDIRECT 11
#define NINDIRECT (BSIZE / sizeof(uint))
#define NDINDIRECT (NINDIRECT * NINDIRECT)
#define MAXFILE (NDIRECT + NINDIRECT + NDINDIRECT)
struct dinode {
// -- 省略 --
uint addrs[NDIRECT+2];
};
修改file.h
:
struct inode {
// -- 省略 --
uint addrs[NDIRECT+2];
};
修改fs.c
:
static uint
bmap(struct inode *ip, uint bn)
{
uint addr, *a;
struct buf *bp;
if(bn < NDIRECT){
if((addr = ip->addrs[bn]) == 0)
ip->addrs[bn] = addr = balloc(ip->dev);
return addr;
}
bn -= NDIRECT;
if(bn < NINDIRECT){
// Load indirect block, allocating if necessary.
if((addr = ip->addrs[NDIRECT]) == 0)
ip->addrs[NDIRECT] = addr = balloc(ip->dev);
bp = bread(ip->dev, addr);
a = (uint*)bp->data;
if((addr = a[bn]) == 0){
a[bn] = addr = balloc(ip->dev);
log_write(bp);
}
brelse(bp);
return addr;
}
bn -= NINDIRECT;
if (bn < NDINDIRECT) {
uint bn1 = bn / NINDIRECT;
uint bn2 = bn % NINDIRECT;
struct buf *bp2;
if ((addr = ip->addrs[NDIRECT + 1]) == 0)
ip->addrs[NDIRECT + 1] = addr = balloc(ip->dev);
bp = bread(ip->dev, addr);
a = (uint *)bp->data;
if ((addr = a[bn1]) == 0) {
a[bn1] = addr = balloc(ip->dev);
log_write(bp);
}
bp2 = bread(ip->dev, addr);
a = (uint *)bp2->data;
if ((addr = a[bn2]) == 0) {
a[bn2] = addr = balloc(ip->dev);
log_write(bp2);
}
brelse(bp2);
brelse(bp);
return addr;
}
panic("bmap: out of range");
}
然后删除fs.img
文件,再make clean qemu
:
init: starting sh
$ big
.....................................................................................................................................................................
wrote 16523 sectors
done; ok
$