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