Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / devices / disk.c
index a3f26cfd8a4a2d5d7ade593e07db6d2c73111af7..0a131740b00711bc94af611330518d9e919b18f5 100644 (file)
@@ -109,7 +109,7 @@ disk_init (void)
       int dev_no;
 
       /* Initialize channel. */
-      snprintf (c->name, sizeof c->name, "hd%zd", chan_no);
+      snprintf (c->name, sizeof c->name, "hd%zu", chan_no);
       switch (chan_no) 
         {
         case 0:
@@ -123,9 +123,9 @@ disk_init (void)
         default:
           NOT_REACHED ();
         }
-      lock_init (&c->lock, c->name);
+      lock_init (&c->lock);
       c->expecting_interrupt = false;
-      sema_init (&c->completion_wait, 0, c->name);
+      sema_init (&c->completion_wait, 0);
  
       /* Initialize devices. */
       for (dev_no = 0; dev_no < 2; dev_no++)
@@ -142,7 +142,7 @@ disk_init (void)
         }
 
       /* Register interrupt handler. */
-      intr_register (c->irq, 0, INTR_OFF, interrupt_handler, c->name);
+      intr_register_ext (c->irq, interrupt_handler, c->name);
 
       /* Reset hardware. */
       reset_channel (c);
@@ -179,7 +179,14 @@ disk_print_stats (void)
 }
 
 /* Returns the disk numbered DEV_NO--either 0 or 1 for master or
-   slave, respectively--within the channel numbered CHAN_NO. */
+   slave, respectively--within the channel numbered CHAN_NO.
+
+   Pintos uses disks this way:
+        0:0 - operating system kernel
+        0:1 - file system
+        1:0 - scratch
+        1:1 - swap
+*/
 struct disk *
 disk_get (int chan_no, int dev_no) 
 {
@@ -285,12 +292,12 @@ reset_channel (struct channel *c)
   /* Issue soft reset sequence, which selects device 0 as a side effect.
      Also enable interrupts. */
   outb (reg_ctl (c), 0);
-  timer_sleep (timer_us2ticks (10));
+  timer_usleep (10);
   outb (reg_ctl (c), CTL_SRST);
-  timer_sleep (timer_us2ticks (10));
+  timer_usleep (10);
   outb (reg_ctl (c), 0);
 
-  timer_sleep (timer_ms2ticks (150));
+  timer_msleep (150);
 
   /* Wait for device 0 to clear BSY. */
   if (present[0]) 
@@ -309,7 +316,7 @@ reset_channel (struct channel *c)
         {
           if (inb (reg_nsect (c)) == 1 && inb (reg_lbal (c)) == 1)
             break;
-          timer_sleep (timer_ms2ticks (10));
+          timer_msleep (10);
         }
       wait_while_busy (&c->devices[1]);
     }
@@ -475,7 +482,7 @@ wait_until_idle (const struct disk *d)
     {
       if ((inb (reg_status (d->channel)) & (STA_BSY | STA_DRQ)) == 0)
         return;
-      timer_sleep (timer_us2ticks (10));
+      timer_usleep (10);
     }
 
   printf ("%s: idle timeout\n", d->name);
@@ -501,7 +508,7 @@ wait_while_busy (const struct disk *d)
             printf ("ok\n");
           return (inb (reg_alt_status (c)) & STA_DRQ) != 0;
         }
-      timer_sleep (timer_ms2ticks (10));
+      timer_msleep (10);
     }
 
   printf ("failed\n");
@@ -518,7 +525,7 @@ select_device (const struct disk *d)
     dev |= DEV_DEV;
   outb (reg_device (c), dev);
   inb (reg_alt_status (c));
-  timer_sleep (timer_ns2ticks (400));
+  timer_nsleep (400);
 }
 
 /* Select disk D in its channel, as select_device(), but wait for