]> hydra-www.ietfng.org Git - xv6-public/commitdiff
Make runoff happier about line lengths, nits.
authorPeter H. Froehlich <peter.hans.froehlich@gmail.com>
Sat, 3 Oct 2015 06:01:07 +0000 (02:01 -0400)
committerPeter H. Froehlich <peter.hans.froehlich@gmail.com>
Sat, 3 Oct 2015 06:01:07 +0000 (02:01 -0400)
bootmain.c
fs.c
fs.h
ide.c
uart.c

index 2af246224cf0ce94218dc2a0353bf57a8f8a9440..6c6f080f91e518453f614d253c23e03388ce794c 100644 (file)
@@ -46,11 +46,18 @@ bootmain(void)
   entry();
 }
 
+static int
+diskready(void)
+{
+  uchar status = inb(IDE_DATA_PRIMARY+IDE_REG_STATUS);
+  return (status & (IDE_BSY|IDE_DRDY)) == IDE_DRDY;
+}
+
 void
 waitdisk(void)
 {
   // Wait for disk ready.
-  while((inb(IDE_DATA_PRIMARY+IDE_REG_STATUS) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
+  while(!diskready())
     ;
 }
 
@@ -64,7 +71,8 @@ readsect(void *dst, uint offset)
   outb(IDE_DATA_PRIMARY+IDE_REG_LBA0, offset & 0xff);
   outb(IDE_DATA_PRIMARY+IDE_REG_LBA1, (offset >> 8) & 0xff);
   outb(IDE_DATA_PRIMARY+IDE_REG_LBA2, (offset >> 16) & 0xff);
-  outb(IDE_DATA_PRIMARY+IDE_REG_DISK, ((offset >> 24) & 0x0f) | IDE_DISK_LBA);
+  outb(IDE_DATA_PRIMARY+IDE_REG_DISK,
+    ((offset >> 24) & 0x0f) | IDE_DISK_LBA);
   outb(IDE_DATA_PRIMARY+IDE_REG_COMMAND, IDE_CMD_READ);
 
   // Read data.
diff --git a/fs.c b/fs.c
index 025b326c4d91e027df472a8d668cdd549a806aa7..f8d7929d103bec762fe2a106ec5d300382f8b2fe 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -5,7 +5,7 @@
 //   + Directories: inode with special contents (list of other inodes!)
 //   + Names: paths like /usr/rtm/xv6/fs.c for convenient naming.
 //
-// This file contains the low-level file system manipulation 
+// This file contains the low-level file system manipulation
 // routines.  The (higher-level) system call implementations
 // are in sysfile.c.
 
 
 #define min(a, b) ((a) < (b) ? (a) : (b))
 static void itrunc(struct inode*);
-struct superblock sb;   // there should be one per dev, but we run with one dev
+
+// there should be one per dev, but we run with one dev
+struct superblock sb;
 
 // Read the super block.
 void
 readsb(int dev, struct superblock *sb)
 {
   struct buf *bp;
-  
+
   bp = bread(dev, 1);
   memmove(sb, bp->data, sizeof(*sb));
   brelse(bp);
@@ -40,14 +42,14 @@ static void
 bzero(int dev, int bno)
 {
   struct buf *bp;
-  
+
   bp = bread(dev, bno);
   memset(bp->data, 0, BSIZE);
   log_write(bp);
   brelse(bp);
 }
 
-// Blocks. 
+// Blocks.
 
 // Allocate a zeroed disk block.
 static uint
@@ -164,8 +166,10 @@ iinit(int dev)
 {
   initlock(&icache.lock, "icache");
   readsb(dev, &sb);
-  cprintf("sb: size %d nblocks %d ninodes %d nlog %d logstart %d inodestart %d bmap start %d\n", sb.size,
-          sb.nblocks, sb.ninodes, sb.nlog, sb.logstart, sb.inodestart, sb.bmapstart);
+  cprintf(
+    "sb: size %d nblocks %d ninodes %d nlog %d logstart %d "
+    "inodestart %d bmap start %d\n", sb.size, sb.nblocks, sb.ninodes,
+    sb.nlog, sb.logstart, sb.inodestart, sb.bmapstart);
 }
 
 static struct inode* iget(uint dev, uint inum);
@@ -348,7 +352,7 @@ iunlockput(struct inode *ip)
 //
 // The content (data) associated with each inode is stored
 // in blocks on the disk. The first NDIRECT block numbers
-// are listed in ip->addrs[].  The next NINDIRECT blocks are 
+// are listed in ip->addrs[].  The next NINDIRECT blocks are
 // listed in block ip->addrs[NDIRECT].
 
 // Return the disk block address of the nth block in inode ip.
@@ -401,7 +405,7 @@ itrunc(struct inode *ip)
       ip->addrs[i] = 0;
     }
   }
-  
+
   if(ip->addrs[NDIRECT]){
     bp = bread(ip->dev, ip->addrs[NDIRECT]);
     a = (uint*)bp->data;
@@ -554,7 +558,7 @@ dirlink(struct inode *dp, char *name, uint inum)
   de.inum = inum;
   if(writei(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
     panic("dirlink");
-  
+
   return 0;
 }
 
diff --git a/fs.h b/fs.h
index e1d7d09c3a32c61df0152383fb855b84cec5d1d1..5a72406b0904d4c346f0a7d072dd99e0d4c711c3 100644 (file)
--- a/fs.h
+++ b/fs.h
@@ -1,15 +1,15 @@
-// On-disk file system format. 
+// On-disk file system format.
 // Both the kernel and user programs use this header file.
 
-
 #define ROOTINO 1  // root i-number
 #define BSIZE 512  // block size
 
 // Disk layout:
-// [ boot block | super block | log | inode blocks | free bit map | data blocks ]
+// [ boot block | super block | log | inode blocks | free bit map
+//   | data blocks ]
 //
-// mkfs computes the super block and builds an initial file system. The super describes
-// the disk layout:
+// mkfs computes the super block and builds an initial file system.
+// The super describes the disk layout:
 struct superblock {
   uint size;         // Size of file system image (blocks)
   uint nblocks;      // Number of data blocks
diff --git a/ide.c b/ide.c
index e32ed0e98d034ca1734f89708a9fc51671dd814e..b713433c17f0c94f02dd62eb86f0467225f24b5c 100644 (file)
--- a/ide.c
+++ b/ide.c
@@ -23,13 +23,20 @@ static struct buf *idequeue;
 static int havedisk1;
 static void idestart(struct buf*);
 
+static int
+diskready(int *status)
+{
+  *status = inb(IDE_DATA_PRIMARY+IDE_REG_STATUS);
+  return (*status & (IDE_BSY|IDE_DRDY)) == IDE_DRDY;
+}
+
 // Wait for IDE disk to become ready.
 static int
 idewait(int checkerr)
 {
   int r;
 
-  while(((r = inb(IDE_DATA_PRIMARY+IDE_REG_STATUS)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
+  while(!diskready(&r))
     ;
   if(checkerr && (r & (IDE_DF|IDE_ERR)) != 0)
     return -1;
@@ -74,11 +81,12 @@ idestart(struct buf *b)
 
   idewait(0);
   outb(IDE_CTRL_PRIMARY+IDE_REG_CTRL, 0);  // generate interrupt
-  outb(IDE_DATA_PRIMARY+IDE_REG_SECTORS, sector_per_block);  // number of sectors
+  outb(IDE_DATA_PRIMARY+IDE_REG_SECTORS, sector_per_block);
   outb(IDE_DATA_PRIMARY+IDE_REG_LBA0, sector & 0xff);
   outb(IDE_DATA_PRIMARY+IDE_REG_LBA1, (sector >> 8) & 0xff);
   outb(IDE_DATA_PRIMARY+IDE_REG_LBA2, (sector >> 16) & 0xff);
-  outb(IDE_DATA_PRIMARY+IDE_REG_DISK, IDE_DISK_LBA | ((b->dev&1)<<4) | ((sector>>24)&0x0f));
+  outb(IDE_DATA_PRIMARY+IDE_REG_DISK,
+    IDE_DISK_LBA | ((b->dev&1)<<4) | ((sector>>24)&0x0f));
   if(b->flags & B_DIRTY){
     outb(IDE_DATA_PRIMARY+IDE_REG_COMMAND, IDE_CMD_WRITE);
     outsl(IDE_DATA_PRIMARY+IDE_REG_DATA, b->data, BSIZE/4);
diff --git a/uart.c b/uart.c
index d88a85988112ed578f8706d3bc96838edf0cc391..e54b48bdb8389cd7348832c7ec7acc6a89739f3c 100644 (file)
--- a/uart.c
+++ b/uart.c
@@ -43,6 +43,18 @@ uartinit(void)
     uartputc(*p);
 }
 
+static int
+cantransmit(void)
+{
+  return inb(COM1+UART_LINE_STATUS) & UART_TRANSMIT_READY;
+}
+
+static int
+hasreceived(void)
+{
+  return inb(COM1+UART_LINE_STATUS) & UART_RECEIVE_READY;
+}
+
 void
 uartputc(int c)
 {
@@ -50,7 +62,7 @@ uartputc(int c)
 
   if(!uart)
     return;
-  for(i = 0; i < 128 && !(inb(COM1+UART_LINE_STATUS) & UART_TRANSMIT_READY); i++)
+  for(i = 0; i < 128 && !cantransmit(); i++)
     microdelay(10);
   outb(COM1+UART_TRANSMIT_BUFFER, c);
 }
@@ -60,7 +72,7 @@ uartgetc(void)
 {
   if(!uart)
     return -1;
-  if(!(inb(COM1+UART_LINE_STATUS) & UART_RECEIVE_READY))
+  if(!hasreceived())
     return -1;
   return inb(COM1+UART_RECEIVE_BUFFER);
 }