zero out all of dirent.name when creating
don't increase length of directory
This commit is contained in:
parent
cd93074e5b
commit
05e975511b
4 changed files with 20 additions and 17 deletions
4
Notes
4
Notes
|
@ -363,5 +363,5 @@ more than one directory content block
|
|||
sh arguments
|
||||
sh redirection
|
||||
indirect blocks
|
||||
two bugs in unlink
|
||||
how come unlink xxx fails? iput problem?
|
||||
two bugs in unlink: don't just return if nlink > 0,
|
||||
and search for name, not inum
|
||||
|
|
4
bio.c
4
bio.c
|
@ -90,13 +90,13 @@ bread(uint dev, uint sector)
|
|||
}
|
||||
|
||||
void
|
||||
bwrite(uint dev, struct buf *b, uint sector)
|
||||
bwrite(struct buf *b, uint sector)
|
||||
{
|
||||
void *c;
|
||||
extern struct spinlock ide_lock;
|
||||
|
||||
acquire(&ide_lock);
|
||||
c = ide_start_rw(dev & 0xff, sector, b->data, 1, 0);
|
||||
c = ide_start_rw(b->dev & 0xff, sector, b->data, 1, 0);
|
||||
sleep (c, &ide_lock);
|
||||
ide_finish(c);
|
||||
b->flags |= B_VALID;
|
||||
|
|
2
defs.h
2
defs.h
|
@ -106,7 +106,7 @@ void binit(void);
|
|||
struct buf;
|
||||
struct buf * getblk(uint dev, uint sector);
|
||||
struct buf *bread(uint, uint);
|
||||
void bwrite(uint, struct buf *, uint);
|
||||
void bwrite(struct buf *, uint);
|
||||
void brelse(struct buf *);
|
||||
|
||||
// fs.c
|
||||
|
|
23
fs.c
23
fs.c
|
@ -56,7 +56,7 @@ balloc(uint dev)
|
|||
|
||||
cprintf ("balloc: allocate block %d\n", b);
|
||||
bp->data[bi/8] |= 0x1 << (bi % 8);
|
||||
bwrite (dev, bp, BBLOCK(b, ninodes)); // mark it allocated on disk
|
||||
bwrite (bp, BBLOCK(b, ninodes)); // mark it allocated on disk
|
||||
brelse(bp);
|
||||
return b;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ bfree(int dev, uint b)
|
|||
bi = b % BPB;
|
||||
m = ~(0x1 << (bi %8));
|
||||
bp->data[bi/8] &= m;
|
||||
bwrite (dev, bp, BBLOCK(b, ninodes)); // mark it free on disk
|
||||
bwrite (bp, BBLOCK(b, ninodes)); // mark it free on disk
|
||||
brelse(bp);
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ iupdate (struct inode *ip)
|
|||
dip->nlink = ip->nlink;
|
||||
dip->size = ip->size;
|
||||
memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
|
||||
bwrite (ip->dev, bp, IBLOCK(ip->inum)); // mark it allocated on the disk
|
||||
bwrite (bp, IBLOCK(ip->inum)); // mark it allocated on the disk
|
||||
brelse(bp);
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ ialloc(uint dev, short type)
|
|||
|
||||
cprintf ("ialloc: %d\n", inum);
|
||||
dip->type = type;
|
||||
bwrite (dev, bp, IBLOCK(inum)); // mark it allocated on the disk
|
||||
bwrite (bp, IBLOCK(inum)); // mark it allocated on the disk
|
||||
brelse(bp);
|
||||
ip = iget (dev, inum);
|
||||
return ip;
|
||||
|
@ -353,7 +353,7 @@ writei(struct inode *ip, char *addr, uint off, uint n)
|
|||
m = min(BSIZE - off % BSIZE, n-r);
|
||||
bp = bread(ip->dev, bmap(ip, off / BSIZE));
|
||||
memmove (bp->data + off % BSIZE, addr, m);
|
||||
bwrite (ip->dev, bp, bmap(ip, off/BSIZE));
|
||||
bwrite (bp, bmap(ip, off/BSIZE));
|
||||
brelse (bp);
|
||||
r += m;
|
||||
off += m;
|
||||
|
@ -484,12 +484,15 @@ mknod(char *cp, short type, short major, short minor)
|
|||
|
||||
found:
|
||||
ep->inum = ip->inum;
|
||||
for(i = 0; i < DIRSIZ && cp[i]; i++) ep->name[i] = cp[i];
|
||||
bwrite (dp->dev, bp, bmap(dp, off/BSIZE)); // write directory block
|
||||
for(i = 0; i < DIRSIZ && cp[i]; i++)
|
||||
ep->name[i] = cp[i];
|
||||
for( ; i < DIRSIZ; i++)
|
||||
ep->name[i] = '\0';
|
||||
bwrite (bp, bmap(dp, off/BSIZE)); // write directory block
|
||||
brelse(bp);
|
||||
dp->size += sizeof(struct dirent); // update directory inode
|
||||
iupdate (dp);
|
||||
|
||||
iput(dp);
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
|
@ -531,7 +534,7 @@ unlink(char *cp)
|
|||
|
||||
found:
|
||||
ep->inum = 0;
|
||||
bwrite (dp->dev, bp, bmap(dp, off/BSIZE)); // write directory block
|
||||
bwrite (bp, bmap(dp, off/BSIZE)); // write directory block
|
||||
brelse(bp);
|
||||
iupdate (dp);
|
||||
iput(dp);
|
||||
|
|
Loading…
Reference in a new issue