disk scheduling
mkdir
-more than one directory content block
sh arguments
sh redirection
indirect blocks
is there a create/create race for same file name?
resulting in two entries w/ same name in directory?
-namei
- return just inode
- return offset in dir where found, w/ dir locked, for unlink
- return dir locked, for mknod
-
-is the offset alone useful? how do I read/write it?
-
test: one process unlinks a file while another links to it
test: simultaneous create of same file
test: one process opens a file while another deletes it
-oy, mkfs wants dir size to be last written entry, but i
- want it to be nblocks*512
- maybe fix kernel code to handle former
+wdir should use writei, to avoid special-case block allocation
+ also readi
+ is dir locked? probably
if (b >= size)
panic("balloc: out of blocks\n");
- cprintf ("balloc: allocate block %d\n", b);
bp->data[bi/8] |= 0x1 << (bi % 8);
bwrite (bp, BBLOCK(b, ninodes)); // mark it allocated on disk
brelse(bp);
int ninodes;
uchar m;
- cprintf ("bfree: free block %d\n", b);
bp = bread(dev, 1);
sb = (struct superblock *) bp->data;
ninodes = sb->ninodes;
struct inode *
iget(uint dev, uint inum)
{
- struct inode *ip, *nip = 0;
+ struct inode *ip, *nip;
struct dinode *dip;
struct buf *bp;
acquire(&inode_table_lock);
loop:
+ nip = 0;
for(ip = &inode[0]; ip < &inode[NINODE]; ip++){
if(ip->count > 0 && ip->dev == dev && ip->inum == inum){
if(ip->busy){
brelse(bp);
}
- if (inum >= ninodes) {
+ if (inum >= ninodes)
panic ("ialloc: no inodes left\n");
- }
- cprintf ("ialloc: %d\n", inum);
dip->type = type;
bwrite (bp, IBLOCK(inum)); // mark it allocated on the disk
brelse(bp);
static void
ifree(struct inode *ip)
{
- cprintf("ifree: %d\n", ip->inum);
ip->type = 0;
iupdate(ip);
}
void
iunlock(struct inode *ip)
{
- if(ip->busy != 1)
+ if(ip->busy != 1 || ip->count < 1)
panic("iunlock");
acquire(&inode_table_lock);
if(ip->count < 1 || ip->busy != 1)
panic("iput");
- if ((ip->count <= 1) && (ip->nlink <= 0))
+ if ((ip->count == 1) && (ip->nlink == 0))
iunlink(ip);
acquire(&inode_table_lock);
{
struct inode *ip, *dp;
- cprintf("mknod: %s %d %d %d\n", cp, type, major, minor);
-
if ((dp = namei(cp, NAMEI_CREATE, 0)) == 0)
return 0;
{
struct inode *ip, *dp;
struct dirent de;
- uint off, inum, cc;
+ uint off, inum, dev;
- cprintf("unlink(%s)\n", cp);
-
- if ((dp = namei(cp, NAMEI_DELETE, &off)) == 0) {
- cprintf("unlink(%s) it doesn't exist\n", cp);
+ if ((dp = namei(cp, NAMEI_DELETE, &off)) == 0)
return -1;
- }
- if((cc = readi(dp, (char*)&de, off, sizeof(de))) != sizeof(de) ||
- de.inum == 0){
- cprintf("off %d dp->size %d cc %d de.inum %d",
- off, dp->size, cc, de.inum);
+ dev = dp->dev;
+
+ if(readi(dp, (char*)&de, off, sizeof(de)) != sizeof(de) || de.inum == 0)
panic("unlink no entry");
- }
+
inum = de.inum;
- cprintf("dinum %d off %d de %s/%d\n",
- dp->inum, off, de.name, de.inum);
memset(&de, 0, sizeof(de));
if(writei(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
iupdate(dp);
iput(dp);
- ip = iget(dp->dev, inum);
- if(ip == 0)
- panic("unlink no inode");
+ ip = iget(dev, inum);
ip->nlink--;
{
struct inode *ip, *dp;
- cprintf("link(%s, %s)\n", name1, name2);
-
- if ((ip = namei(name1, NAMEI_LOOKUP, 0)) == 0){
- cprintf(" failed %s does not exist\n", name1);
+ if ((ip = namei(name1, NAMEI_LOOKUP, 0)) == 0)
return -1;
- }
if(ip->type == T_DIR){
- cprintf(" failed %s is a dir\n", name1);
iput(ip);
return -1;
}
iunlock(ip);
if ((dp = namei(name2, NAMEI_CREATE, 0)) == 0) {
- cprintf(" failed %s exists\n", name2);
idecref(ip);
return -1;
}
if(dp->dev != ip->dev){
- cprintf(" cross-device link\n");
idecref(ip);
iput(dp);
return -1;
iput(dp);
iput(ip);
- cprintf(" succeeded\n");
-
return 0;
}
id = ioapic_read(io, IOAPIC_ID) >> APIC_ID_SHIFT;
if (id != ioapic_id)
panic ("ioapic_init: id isn't equal to ioapic_id\n");
- cprintf ("ioapic VER: 0x%x id %d nintr %d\n", l, id, nintr);
for (i = 0; i < nintr; i++) {
// active-hi and edge-triggered for ISA interrupts
// Assume that pin 0 on the first I/O APIC is an ExtINT pin.
h &= ~IOART_DEST;
h |= (cpunum << APIC_ID_SHIFT);
ioapic_write(io, IOAPIC_REDTBL_HI(irq), h);
- cprintf("cpu%d: intr %d: lo 0x%x hi 0x%x\n", cpu(), irq, l, h);
}