This commit is contained in:
kaashoek 2006-08-07 01:38:46 +00:00
parent 8ec6530fee
commit 104207726b
4 changed files with 33 additions and 8 deletions

13
bio.c
View file

@ -50,6 +50,19 @@ bread(uint dev, uint sector)
return b;
}
void
bwrite(uint dev, 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);
sleep (c, &ide_lock);
ide_finish(c);
release(&ide_lock);
}
void
brelse(struct buf *b)
{

2
defs.h
View file

@ -96,7 +96,9 @@ int ide_finish(void *);
// bio.c
struct buf;
struct buf *getblk(void);
struct buf *bread(uint, uint);
void bwrite(uint, struct buf *, uint);
void brelse(struct buf *);
// fs.c

18
ide.c
View file

@ -101,7 +101,10 @@ ide_start_request (void)
outb(0x1F5, (r->secno >> 16) & 0xFF);
outb(0x1F6, 0xE0 | ((r->diskno&1)<<4) | ((r->secno>>24)&0x0F));
if (r->read) outb(0x1F7, 0x20); // read
else outb(0x1F7, 0x30); // write
else {
outb(0x1F7, 0x30); // write
outsl(0x1F0, r->addr, 512/4);
}
}
}
@ -113,7 +116,7 @@ ide_start_rw(int diskno, uint secno, void *addr, uint nsecs, int read)
if(!holding(&ide_lock))
panic("ide_start_read: not holding ide_lock");
if(nsecs > 256)
if(nsecs > 1)
panic("ide_start_read: nsecs too large");
while ((head + 1) % NREQUEST == tail)
@ -136,7 +139,7 @@ ide_start_rw(int diskno, uint secno, void *addr, uint nsecs, int read)
int
ide_finish(void *c)
{
int r = 0;
int r;
struct ide_request *req = (struct ide_request *) c;
if(c != &request[tail])
@ -144,11 +147,10 @@ ide_finish(void *c)
if(!holding(&ide_lock))
panic("ide_start_read: not holding ide_lock");
for (; req->nsecs > 0; req->nsecs--, req->addr += 512) {
if ((r = ide_wait_ready(1)) < 0)
break;
if (req->read) insl(0x1F0, req->addr, 512/4);
else outsl(0x1F0, req->addr, 512/4);
if (req->read) {
if ((r = ide_wait_ready(1)) >= 0)
insl(0x1F0, req->addr, 512/4);
}
if ((head + 1) % NREQUEST == tail) {

View file

@ -426,6 +426,14 @@ sys_block(void)
brelse(b);
}
#if 0
cprintf("overwrite fs.img!\n");
b = getblk();
memset (b->data, 'f', 10);
bwrite(1, b, 0);
cprintf("write is done\n");
#endif
ip = iget(1, 1);
cprintf("iget 1: %d %d %d %d %d %d %d %d\n",
ip->dev, ip->inum, ip->count, ip->busy,