]> Devi Nivas Git - cs3210-lab1.git/commitdiff
don't let dirty blocks be evicted from cache!
authorRobert Morris <rtm@csail.mit.edu>
Fri, 14 Oct 2011 14:23:23 +0000 (10:23 -0400)
committerRobert Morris <rtm@csail.mit.edu>
Fri, 14 Oct 2011 14:23:23 +0000 (10:23 -0400)
bio.c
file.c
log.c
sysfile.c

diff --git a/bio.c b/bio.c
index 88b0964de12298ee9366b46c93c74cd8ccb380ae..de1d0f297290f5a6e12192c17c47800011d4e290 100644 (file)
--- a/bio.c
+++ b/bio.c
@@ -79,9 +79,9 @@ bget(uint dev, uint sector)
     }
   }
 
-  // Not cached; recycle some existing buffer.
+  // Not cached; recycle some non-busy and clean buffer.
   for(b = bcache.head.prev; b != &bcache.head; b = b->prev){
-    if((b->flags & B_BUSY) == 0){
+    if((b->flags & B_BUSY) == 0 && (b->flags & B_DIRTY) == 0){
       b->dev = dev;
       b->sector = sector;
       b->flags = B_BUSY;
diff --git a/file.c b/file.c
index 3fd2cbe9c3a3087d81a56de6b31c9bd300bf8f52..53c5af242fb798ff683daba7de0479c420efed74 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,3 +1,7 @@
+//
+// File descriptors
+//
+
 #include "types.h"
 #include "defs.h"
 #include "param.h"
@@ -87,7 +91,7 @@ filestat(struct file *f, struct stat *st)
   return -1;
 }
 
-// Read from file f.  Addr is kernel address.
+// Read from file f.
 int
 fileread(struct file *f, char *addr, int n)
 {
@@ -108,7 +112,7 @@ fileread(struct file *f, char *addr, int n)
 }
 
 //PAGEBREAK!
-// Write to file f.  Addr is kernel address.
+// Write to file f.
 int
 filewrite(struct file *f, char *addr, int n)
 {
diff --git a/log.c b/log.c
index 5b827debfc62968bc00221c626e9920f05747026..1814edc404a388fdfd27a6f24aad6211b14501ed 100644 (file)
--- a/log.c
+++ b/log.c
@@ -177,6 +177,7 @@ log_write(struct buf *b)
   brelse(lbuf);
   if (i == log.lh.n)
     log.lh.n++;
+  b->flags |= B_DIRTY; // XXX prevent eviction
 }
 
 //PAGEBREAK!
index 9de3d86c7a766b7d92b756c2300d918066ed9322..e6d08e842d2f6a5d199ae952ead41aec61882dfd 100644 (file)
--- a/sysfile.c
+++ b/sysfile.c
@@ -1,3 +1,9 @@
+//
+// File-system system calls.
+// Mostly argument checking, since we don't trust
+// user code, and calls into file.c and fs.c.
+//
+
 #include "types.h"
 #include "defs.h"
 #include "param.h"