summaryrefslogtreecommitdiff
path: root/ide.c
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-27 14:09:30 +0000
committerrsc <rsc>2007-08-27 14:09:30 +0000
commitd003d232fc34d92426aed61af13d3815355c1db8 (patch)
tree2bdaa3d76a6c0869b186721fd1be9c4f0630dd7f /ide.c
parentefc12b8e616ed3394468c1802da8e1f39e387cd3 (diff)
downloadxv6-labs-d003d232fc34d92426aed61af13d3815355c1db8.tar.gz
xv6-labs-d003d232fc34d92426aed61af13d3815355c1db8.tar.bz2
xv6-labs-d003d232fc34d92426aed61af13d3815355c1db8.zip
Another attempt at the bio.c comment.
Rename B_WRITE to B_DIRTY and then let ide.c maintain the B_VALID and B_DIRTY flags.
Diffstat (limited to 'ide.c')
-rw-r--r--ide.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ide.c b/ide.c
index 83bffcf..092b8ce 100644
--- a/ide.c
+++ b/ide.c
@@ -78,7 +78,7 @@ ide_start_request(struct buf *b)
outb(0x1f4, (b->sector >> 8) & 0xff);
outb(0x1f5, (b->sector >> 16) & 0xff);
outb(0x1f6, 0xE0 | ((b->dev&1)<<4) | ((b->sector>>24)&0x0f));
- if(b->flags & B_WRITE){
+ if(b->flags & B_DIRTY){
outb(0x1f7, IDE_CMD_WRITE);
outsl(0x1f0, b->data, 512/4);
}else{
@@ -100,11 +100,12 @@ ide_intr(void)
}
// Read data if needed.
- if((b->flags & B_WRITE) == 0 && ide_wait_ready(1) >= 0)
+ if(!(b->flags & B_DIRTY) && ide_wait_ready(1) >= 0)
insl(0x1f0, b->data, 512/4);
// Wake process waiting for this buf.
- b->done = 1;
+ b->flags |= B_VALID;
+ b->flags &= ~B_DIRTY;
wakeup(b);
// Start disk on next buf in queue.
@@ -115,7 +116,9 @@ ide_intr(void)
}
//PAGEBREAK!
-// Queue a disk operation and wait for it to finish.
+// Sync buf with disk.
+// If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
+// Else if B_VALID is not set, read buf from disk, set B_VALID.
void
ide_rw(struct buf *b)
{
@@ -123,13 +126,14 @@ ide_rw(struct buf *b)
if(!(b->flags & B_BUSY))
panic("ide_rw: buf not busy");
+ if((b->flags & (B_VALID|B_DIRTY)) == B_VALID)
+ panic("ide_rw: nothing to do");
if(b->dev != 0 && !disk_1_present)
panic("ide disk 1 not present");
acquire(&ide_lock);
// Append b to ide_queue.
- b->done = 0;
b->qnext = 0;
for(pp=&ide_queue; *pp; pp=&(*pp)->qnext)
;
@@ -140,7 +144,8 @@ ide_rw(struct buf *b)
ide_start_request(b);
// Wait for request to finish.
- while(!b->done)
+ while((b->flags & (B_VALID|B_DIRTY)) != B_VALID)
sleep(b, &ide_lock);
+
release(&ide_lock);
}