4.2 distribution
[unix-history] / usr / src / sys / vm / vm_swap.c
index a0c70ee..e5fa696 100644 (file)
@@ -1,4 +1,4 @@
-/*     vm_swap.c       4.2     %G%     */
+/*     vm_swap.c       6.1     83/07/29        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -8,6 +8,9 @@
 #include "../h/user.h"
 #include "../h/inode.h"
 #include "../h/map.h"
 #include "../h/user.h"
 #include "../h/inode.h"
 #include "../h/map.h"
+#include "../h/uio.h"
+#include "../h/file.h"
+#include "../h/nami.h"
 
 struct buf rswbuf;
 /*
 
 struct buf rswbuf;
 /*
@@ -19,33 +22,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 +79,16 @@ 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;
+       };
        register struct inode *ip;
        dev_t dev;
        register struct swdevt *sp;
 
        register struct inode *ip;
        dev_t dev;
        register struct swdevt *sp;
 
-       ip = namei(uchar, 0);
+       ip = namei(uchar, LOOKUP, 1);
        if (ip == NULL)
                return;
        if ((ip->i_mode&IFMT) != IFBLK) {
        if (ip == NULL)
                return;
        if ((ip->i_mode&IFMT) != IFBLK) {
@@ -67,7 +96,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,29 +121,44 @@ 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
-                        * but need some space for argmap so use this
+                        * but need some space for argmap so use 1/2 this
                         * hunk which needs special treatment anyways.
                         */
                        argdev = swdevt[0].sw_dev;
                         * hunk which needs special treatment anyways.
                         */
                        argdev = swdevt[0].sw_dev;
-                       mfree(argmap, blk-CLSIZE, vsbase+CLSIZE);
+                       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.
+                        */
+                       rminit(swapmap, (long)blk/2, (long)blk/2,
+                           "swap", nswapmap);
                } else
                } else
-                       mfree(swapmap, blk, vsbase);
+                       rmfree(swapmap, blk, vsbase);
        }
 }
        }
 }