make dirlookup and dirlink more similar
This commit is contained in:
parent
cd3d739e6f
commit
327cc21fba
2 changed files with 66 additions and 18 deletions
23
fs.c
23
fs.c
|
@ -469,30 +469,25 @@ struct inode*
|
||||||
dirlookup(struct inode *dp, char *name, uint *poff)
|
dirlookup(struct inode *dp, char *name, uint *poff)
|
||||||
{
|
{
|
||||||
uint off, inum;
|
uint off, inum;
|
||||||
struct buf *bp;
|
struct dirent de;
|
||||||
struct dirent *de;
|
|
||||||
|
|
||||||
if(dp->type != T_DIR)
|
if(dp->type != T_DIR)
|
||||||
panic("dirlookup not DIR");
|
panic("dirlookup not DIR");
|
||||||
|
|
||||||
for(off = 0; off < dp->size; off += BSIZE){
|
for(off = 0; off < dp->size; off += sizeof(de)){
|
||||||
bp = bread(dp->dev, bmap(dp, off / BSIZE));
|
if(readi(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
|
||||||
for(de = (struct dirent*)bp->data;
|
panic("dirlink read");
|
||||||
de < (struct dirent*)(bp->data + BSIZE);
|
if(de.inum == 0)
|
||||||
de++){
|
|
||||||
if(de->inum == 0)
|
|
||||||
continue;
|
continue;
|
||||||
if(namecmp(name, de->name) == 0){
|
if(namecmp(name, de.name) == 0){
|
||||||
// entry matches path element
|
// entry matches path element
|
||||||
if(poff)
|
if(poff)
|
||||||
*poff = off + (uchar*)de - bp->data;
|
*poff = off;
|
||||||
inum = de->inum;
|
inum = de.inum;
|
||||||
brelse(bp);
|
|
||||||
return iget(dp->dev, inum);
|
return iget(dp->dev, inum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
brelse(bp);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
53
usertests.c
53
usertests.c
|
@ -1529,6 +1529,59 @@ bigargtest(void)
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// what happens when the file system runs out of blocks?
|
||||||
|
// answer: balloc panics, so this test is not useful.
|
||||||
|
void
|
||||||
|
fsfull()
|
||||||
|
{
|
||||||
|
int nfiles;
|
||||||
|
int fsblocks = 0;
|
||||||
|
|
||||||
|
printf(1, "fsfull test\n");
|
||||||
|
|
||||||
|
for(nfiles = 0; ; nfiles++){
|
||||||
|
char name[64];
|
||||||
|
name[0] = 'f';
|
||||||
|
name[1] = '0' + nfiles / 1000;
|
||||||
|
name[2] = '0' + (nfiles % 1000) / 100;
|
||||||
|
name[3] = '0' + (nfiles % 100) / 10;
|
||||||
|
name[4] = '0' + (nfiles % 10);
|
||||||
|
name[5] = '\0';
|
||||||
|
printf(1, "writing %s\n", name);
|
||||||
|
int fd = open(name, O_CREATE|O_RDWR);
|
||||||
|
if(fd < 0){
|
||||||
|
printf(1, "open %s failed\n", name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int total = 0;
|
||||||
|
while(1){
|
||||||
|
int cc = write(fd, buf, 512);
|
||||||
|
if(cc < 512)
|
||||||
|
break;
|
||||||
|
total += cc;
|
||||||
|
fsblocks++;
|
||||||
|
}
|
||||||
|
printf(1, "wrote %d bytes\n", total);
|
||||||
|
close(fd);
|
||||||
|
if(total == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(nfiles >= 0){
|
||||||
|
char name[64];
|
||||||
|
name[0] = 'f';
|
||||||
|
name[1] = '0' + nfiles / 1000;
|
||||||
|
name[2] = '0' + (nfiles % 1000) / 100;
|
||||||
|
name[3] = '0' + (nfiles % 100) / 10;
|
||||||
|
name[4] = '0' + (nfiles % 10);
|
||||||
|
name[5] = '\0';
|
||||||
|
unlink(name);
|
||||||
|
nfiles--;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(1, "fsfull test finished\n");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue