Change to includes. no more ../h
[unix-history] / usr / src / sys / vm / vm_swap.c
index 3a328d3..f3928ad 100644 (file)
@@ -1,13 +1,15 @@
-/*     vm_swap.c       4.4     81/03/09        */
+/*     vm_swap.c       6.3     84/08/29        */
 
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/buf.h"
-#include "../h/conf.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/inode.h"
-#include "../h/map.h"
+#include "param.h"
+#include "systm.h"
+#include "buf.h"
+#include "conf.h"
+#include "dir.h"
+#include "user.h"
+#include "inode.h"
+#include "map.h"
+#include "uio.h"
+#include "file.h"
 
 struct buf rswbuf;
 /*
 
 struct buf rswbuf;
 /*
@@ -19,33 +21,56 @@ swstrategy(bp)
        int sz, off, seg;
        dev_t dev;
 
        int sz, off, seg;
        dev_t dev;
 
-       sz = (bp->b_bcount+511)/512;
-       off = bp->b_blkno % DMMAX;
-       if (bp->b_blkno+sz > nswap || off+sz > DMMAX) {
+#ifdef GENERIC
+       /*
+        * A mini-root gets copied into the front of the swap
+        * and we run over top of the swap area just long
+        * enough for us to do a mkfs and restor of the real
+        * root (sure beats rewriting standalone restor).
+        */
+#define        MINIROOTSIZE    4096
+       if (rootdev == dumpdev)
+               bp->b_blkno += MINIROOTSIZE;
+#endif
+       sz = howmany(bp->b_bcount, DEV_BSIZE);
+       if (bp->b_blkno+sz > nswap) {
                bp->b_flags |= B_ERROR;
                iodone(bp);
                return;
        }
                bp->b_flags |= B_ERROR;
                iodone(bp);
                return;
        }
-       seg = bp->b_blkno / DMMAX;
-       dev = swdevt[seg % nswdev].sw_dev;
-       seg /= nswdev;
-       bp->b_blkno = seg*DMMAX + off;
+       if (nswdev > 1) {
+               off = bp->b_blkno % dmmax;
+               if (off+sz > dmmax) {
+                       bp->b_flags |= B_ERROR;
+                       iodone(bp);
+                       return;
+               }
+               seg = bp->b_blkno / dmmax;
+               dev = swdevt[seg % nswdev].sw_dev;
+               seg /= nswdev;
+               bp->b_blkno = seg*dmmax + off;
+       } else
+               dev = swdevt[0].sw_dev;
        bp->b_dev = dev;
        if (dev == 0)
                panic("swstrategy");
        (*bdevsw[major(dev)].d_strategy)(bp);
 }
 
        bp->b_dev = dev;
        if (dev == 0)
                panic("swstrategy");
        (*bdevsw[major(dev)].d_strategy)(bp);
 }
 
-swread(dev)
+swread(dev, uio)
+       dev_t dev;
+       struct uio *uio;
 {
 
 {
 
-       physio(swstrategy, &rswbuf, dev, B_READ, minphys);
+       return (physio(swstrategy, &rswbuf, dev, B_READ, minphys, uio));
 }
 
 }
 
-swwrite(dev)
+swwrite(dev, uio)
+       dev_t dev;
+       struct uio *uio;
 {
 
 {
 
-       physio(swstrategy, &rswbuf, dev, B_WRITE, minphys);
+       return (physio(swstrategy, &rswbuf, dev, B_WRITE, minphys, uio));
 }
 
 /*
 }
 
 /*
@@ -53,13 +78,20 @@ swwrite(dev)
  * which must be in the swdevsw.  Return EBUSY
  * if already swapping on this device.
  */
  * which must be in the swdevsw.  Return EBUSY
  * if already swapping on this device.
  */
-vswapon()
+swapon()
 {
 {
+       struct a {
+               char    *name;
+       } *uap = (struct a *)u.u_ap;
        register struct inode *ip;
        dev_t dev;
        register struct swdevt *sp;
        register struct inode *ip;
        dev_t dev;
        register struct swdevt *sp;
+       register struct nameidata *ndp = &u.u_nd;
 
 
-       ip = namei(uchar, 0);
+       ndp->ni_nameiop = LOOKUP | FOLLOW;
+       ndp->ni_segflg = UIO_USERSPACE;
+       ndp->ni_dirp = uap->name;
+       ip = namei(ndp);
        if (ip == NULL)
                return;
        if ((ip->i_mode&IFMT) != IFBLK) {
        if (ip == NULL)
                return;
        if ((ip->i_mode&IFMT) != IFBLK) {
@@ -67,7 +99,7 @@ vswapon()
                iput(ip);
                return;
        }
                iput(ip);
                return;
        }
-       dev = (dev_t)ip->i_un.i_rdev;
+       dev = (dev_t)ip->i_rdev;
        iput(ip);
        if (major(dev) >= nblkdev) {
                u.u_error = ENXIO;
        iput(ip);
        if (major(dev) >= nblkdev) {
                u.u_error = ENXIO;
@@ -92,20 +124,28 @@ vswapon()
 /*
  * Swfree(index) frees the index'th portion of the swap map.
  * Each of the nswdev devices provides 1/nswdev'th of the swap
 /*
  * Swfree(index) frees the index'th portion of the swap map.
  * Each of the nswdev devices provides 1/nswdev'th of the swap
- * space, which is laid out with blocks of DMMAX pages circularly
+ * space, which is laid out with blocks of dmmax pages circularly
  * among the devices.
  */
 swfree(index)
        int index;
 {
        register swblk_t vsbase;
  * among the devices.
  */
 swfree(index)
        int index;
 {
        register swblk_t vsbase;
-       register int blk;
+       register long blk;
+       dev_t dev;
+       register swblk_t dvbase;
+       register int nblks;
 
 
+       dev = swdevt[index].sw_dev;
+       (*bdevsw[major(dev)].d_open)(dev, FREAD|FWRITE);
        swdevt[index].sw_freed = 1;
        swdevt[index].sw_freed = 1;
-       for (vsbase = index*DMMAX; vsbase < nswap; vsbase += nswdev*DMMAX) {
-               blk = nswap - vsbase;
-               if (blk > DMMAX)
-                       blk = DMMAX;
+       nblks = swdevt[index].sw_nblks;
+       for (dvbase = 0; dvbase < nblks; dvbase += dmmax) {
+               blk = nblks - dvbase;
+               if ((vsbase = index*dmmax + dvbase*nswdev) >= nswap)
+                       panic("swfree");
+               if (blk > dmmax)
+                       blk = dmmax;
                if (vsbase == 0) {
                        /*
                         * Can't free a block starting at 0 in the swapmap
                if (vsbase == 0) {
                        /*
                         * Can't free a block starting at 0 in the swapmap
@@ -113,13 +153,14 @@ swfree(index)
                         * hunk which needs special treatment anyways.
                         */
                        argdev = swdevt[0].sw_dev;
                         * hunk which needs special treatment anyways.
                         */
                        argdev = swdevt[0].sw_dev;
-                       rminit(argmap, blk/2-CLSIZE, CLSIZE,
-                           "argmap", ARGMAPSIZE);
+                       rminit(argmap, (long)(blk/2-ctod(CLSIZE)),
+                           (long)ctod(CLSIZE), "argmap", ARGMAPSIZE);
                        /*
                         * First of all chunks... initialize the swapmap
                         * the second half of the hunk.
                         */
                        /*
                         * First of all chunks... initialize the swapmap
                         * the second half of the hunk.
                         */
-                       rminit(swapmap, blk/2, blk/2, "swap", nswapmap);
+                       rminit(swapmap, (long)blk/2, (long)blk/2,
+                           "swap", nswapmap);
                } else
                        rmfree(swapmap, blk, vsbase);
        }
                } else
                        rmfree(swapmap, blk, vsbase);
        }