Lab 8 File System: Large Files
Increase the maximum size of an xv6 file.
Last updated
#define FSSIZE 200000 // size of file system in blocks#define NDIRECT 11
#define NINDIRECT (BSIZE / sizeof(uint))
#define NDOUBLY_INDIRECT NINDIRECT*NINDIRECT
#define MAXFILE (NDIRECT + NINDIRECT + NDOUBLY_INDIRECT) bn -= NINDIRECT;
if(bn < NDOUBLY_INDIRECT){
// Load double indirect block, allocating if necessary.
if((addr = ip->addrs[NDIRECT + 1]) == 0)
ip->addrs[NDIRECT + 1] = addr = balloc(ip->dev);
bp = bread(ip->dev, addr);
a = (uint*)bp->data;
// load 2nd layer block.
uint double_index = bn / NINDIRECT;
if((addr = a[double_index]) == 0){
a[double_index] = addr = balloc(ip->dev);
log_write(bp);
}
brelse(bp);
// now find disk block.
bp = bread(ip->dev, addr);
a = (uint*)bp->data;
uint pos = bn % NINDIRECT;
if ((addr = a[pos]) == 0) {
a[pos] = addr = balloc(ip->dev);
log_write(bp);
}