drop NADDRS and INDIRECT; too many names
This commit is contained in:
parent
030a47736f
commit
ba6cd8a685
4 changed files with 13 additions and 15 deletions
12
fs.c
12
fs.c
|
@ -335,10 +335,10 @@ bmap(struct inode *ip, uint bn, int alloc)
|
||||||
|
|
||||||
if(bn < NINDIRECT){
|
if(bn < NINDIRECT){
|
||||||
// Load indirect block, allocating if necessary.
|
// Load indirect block, allocating if necessary.
|
||||||
if((addr = ip->addrs[INDIRECT]) == 0){
|
if((addr = ip->addrs[NDIRECT]) == 0){
|
||||||
if(!alloc)
|
if(!alloc)
|
||||||
return -1;
|
return -1;
|
||||||
ip->addrs[INDIRECT] = addr = balloc(ip->dev);
|
ip->addrs[NDIRECT] = addr = balloc(ip->dev);
|
||||||
}
|
}
|
||||||
bp = bread(ip->dev, addr);
|
bp = bread(ip->dev, addr);
|
||||||
a = (uint*)bp->data;
|
a = (uint*)bp->data;
|
||||||
|
@ -375,16 +375,16 @@ itrunc(struct inode *ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ip->addrs[INDIRECT]){
|
if(ip->addrs[NDIRECT]){
|
||||||
bp = bread(ip->dev, ip->addrs[INDIRECT]);
|
bp = bread(ip->dev, ip->addrs[NDIRECT]);
|
||||||
a = (uint*)bp->data;
|
a = (uint*)bp->data;
|
||||||
for(j = 0; j < NINDIRECT; j++){
|
for(j = 0; j < NINDIRECT; j++){
|
||||||
if(a[j])
|
if(a[j])
|
||||||
bfree(ip->dev, a[j]);
|
bfree(ip->dev, a[j]);
|
||||||
}
|
}
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
bfree(ip->dev, ip->addrs[INDIRECT]);
|
bfree(ip->dev, ip->addrs[NDIRECT]);
|
||||||
ip->addrs[INDIRECT] = 0;
|
ip->addrs[NDIRECT] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip->size = 0;
|
ip->size = 0;
|
||||||
|
|
4
fs.h
4
fs.h
|
@ -15,9 +15,7 @@ struct superblock {
|
||||||
uint ninodes; // Number of inodes.
|
uint ninodes; // Number of inodes.
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NADDRS (NDIRECT+1)
|
|
||||||
#define NDIRECT 12
|
#define NDIRECT 12
|
||||||
#define INDIRECT 12
|
|
||||||
#define NINDIRECT (BSIZE / sizeof(uint))
|
#define NINDIRECT (BSIZE / sizeof(uint))
|
||||||
#define MAXFILE (NDIRECT + NINDIRECT)
|
#define MAXFILE (NDIRECT + NINDIRECT)
|
||||||
|
|
||||||
|
@ -28,7 +26,7 @@ struct dinode {
|
||||||
short minor; // Minor device number (T_DEV only)
|
short minor; // Minor device number (T_DEV only)
|
||||||
short nlink; // Number of links to inode in file system
|
short nlink; // Number of links to inode in file system
|
||||||
uint size; // Size of file (bytes)
|
uint size; // Size of file (bytes)
|
||||||
uint addrs[NADDRS]; // Data block addresses
|
uint addrs[NDIRECT+1]; // Data block addresses
|
||||||
};
|
};
|
||||||
|
|
||||||
// Inodes per block.
|
// Inodes per block.
|
||||||
|
|
2
fsvar.h
2
fsvar.h
|
@ -11,7 +11,7 @@ struct inode {
|
||||||
short minor;
|
short minor;
|
||||||
short nlink;
|
short nlink;
|
||||||
uint size;
|
uint size;
|
||||||
uint addrs[NADDRS];
|
uint addrs[NDIRECT+1];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define I_BUSY 0x1
|
#define I_BUSY 0x1
|
||||||
|
|
8
mkfs.c
8
mkfs.c
|
@ -259,17 +259,17 @@ iappend(uint inum, void *xp, int n)
|
||||||
}
|
}
|
||||||
x = xint(din.addrs[fbn]);
|
x = xint(din.addrs[fbn]);
|
||||||
} else {
|
} else {
|
||||||
if(xint(din.addrs[INDIRECT]) == 0) {
|
if(xint(din.addrs[NDIRECT]) == 0) {
|
||||||
// printf("allocate indirect block\n");
|
// printf("allocate indirect block\n");
|
||||||
din.addrs[INDIRECT] = xint(freeblock++);
|
din.addrs[NDIRECT] = xint(freeblock++);
|
||||||
usedblocks++;
|
usedblocks++;
|
||||||
}
|
}
|
||||||
// printf("read indirect block\n");
|
// printf("read indirect block\n");
|
||||||
rsect(xint(din.addrs[INDIRECT]), (char*) indirect);
|
rsect(xint(din.addrs[NDIRECT]), (char*) indirect);
|
||||||
if(indirect[fbn - NDIRECT] == 0) {
|
if(indirect[fbn - NDIRECT] == 0) {
|
||||||
indirect[fbn - NDIRECT] = xint(freeblock++);
|
indirect[fbn - NDIRECT] = xint(freeblock++);
|
||||||
usedblocks++;
|
usedblocks++;
|
||||||
wsect(xint(din.addrs[INDIRECT]), (char*) indirect);
|
wsect(xint(din.addrs[NDIRECT]), (char*) indirect);
|
||||||
}
|
}
|
||||||
x = xint(indirect[fbn-NDIRECT]);
|
x = xint(indirect[fbn-NDIRECT]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue