get rid of extraneous header files
[unix-history] / usr / src / sys / vm / vm_swap.c
index 6cabd25..4543dae 100644 (file)
@@ -1,4 +1,10 @@
-/*     vm_swap.c       6.5     85/05/22        */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)vm_swap.c   7.4 (Berkeley) %G%
+ */
 
 #include "param.h"
 #include "systm.h"
 
 #include "param.h"
 #include "systm.h"
 #include "map.h"
 #include "uio.h"
 #include "file.h"
 #include "map.h"
 #include "uio.h"
 #include "file.h"
+#include "stat.h"
+#include "stat.h"
 
 
-struct buf rswbuf;
 /*
  * Indirect driver for multi-controller paging.
  */
 swstrategy(bp)
        register struct buf *bp;
 {
 /*
  * Indirect driver for multi-controller paging.
  */
 swstrategy(bp)
        register struct buf *bp;
 {
-       int sz, off, seg;
-       dev_t dev;
+       int sz, off, seg, index;
+       register struct swdevt *sp;
 
 #ifdef GENERIC
        /*
 
 #ifdef GENERIC
        /*
@@ -35,42 +42,31 @@ swstrategy(bp)
        sz = howmany(bp->b_bcount, DEV_BSIZE);
        if (bp->b_blkno+sz > nswap) {
                bp->b_flags |= B_ERROR;
        sz = howmany(bp->b_bcount, DEV_BSIZE);
        if (bp->b_blkno+sz > nswap) {
                bp->b_flags |= B_ERROR;
-               iodone(bp);
+               biodone(bp);
                return;
        }
        if (nswdev > 1) {
                off = bp->b_blkno % dmmax;
                if (off+sz > dmmax) {
                        bp->b_flags |= B_ERROR;
                return;
        }
        if (nswdev > 1) {
                off = bp->b_blkno % dmmax;
                if (off+sz > dmmax) {
                        bp->b_flags |= B_ERROR;
-                       iodone(bp);
+                       biodone(bp);
                        return;
                }
                seg = bp->b_blkno / dmmax;
                        return;
                }
                seg = bp->b_blkno / dmmax;
-               dev = swdevt[seg % nswdev].sw_dev;
+               index = seg % nswdev;
                seg /= nswdev;
                bp->b_blkno = seg*dmmax + off;
        } else
                seg /= nswdev;
                bp->b_blkno = seg*dmmax + off;
        } else
-               dev = swdevt[0].sw_dev;
-       bp->b_dev = dev;
-       if (dev == 0)
+               index = 0;
+       sp = &swdevt[index];
+#ifdef SECSIZE
+       bp->b_blkno <<= sp->sw_bshift;
+       bp->b_blksize = sp->sw_blksize;
+#endif SECSIZE
+       bp->b_dev = sp->sw_dev;
+       if (bp->b_dev == 0)
                panic("swstrategy");
                panic("swstrategy");
-       (*bdevsw[major(dev)].d_strategy)(bp);
-}
-
-swread(dev, uio)
-       dev_t dev;
-       struct uio *uio;
-{
-
-       return (physio(swstrategy, &rswbuf, dev, B_READ, minphys, uio));
-}
-
-swwrite(dev, uio)
-       dev_t dev;
-       struct uio *uio;
-{
-
-       return (physio(swstrategy, &rswbuf, dev, B_WRITE, minphys, uio));
+       (*bdevsw[major(bp->b_dev)].d_strategy)(bp);
 }
 
 /*
 }
 
 /*
@@ -88,7 +84,7 @@ swapon()
        register struct swdevt *sp;
        register struct nameidata *ndp = &u.u_nd;
 
        register struct swdevt *sp;
        register struct nameidata *ndp = &u.u_nd;
 
-       if (!suser())
+       if (u.u_error = suser(u.u_cred, &u.u_acflag))
                return;
        ndp->ni_nameiop = LOOKUP | FOLLOW;
        ndp->ni_segflg = UIO_USERSPACE;
                return;
        ndp->ni_nameiop = LOOKUP | FOLLOW;
        ndp->ni_segflg = UIO_USERSPACE;
@@ -113,12 +109,16 @@ swapon()
                                u.u_error = EBUSY;
                                return;
                        }
                                u.u_error = EBUSY;
                                return;
                        }
-                       swfree(sp - swdevt);
+                       u.u_error = swfree(sp - swdevt);
                        return;
                }
        u.u_error = EINVAL;
 }
 
                        return;
                }
        u.u_error = EINVAL;
 }
 
+#ifdef SECSIZE
+long   argdbsize;              /* XXX */
+
+#endif SECSIZE
 /*
  * 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
@@ -128,16 +128,22 @@ swapon()
 swfree(index)
        int index;
 {
 swfree(index)
        int index;
 {
+       register struct swdevt *sp;
+       register struct swdevt *sp;
        register swblk_t vsbase;
        register long blk;
        dev_t dev;
        register swblk_t dvbase;
        register int nblks;
        register swblk_t vsbase;
        register long blk;
        dev_t dev;
        register swblk_t dvbase;
        register int nblks;
+       int error;
+       int error;
 
 
-       dev = swdevt[index].sw_dev;
-       (*bdevsw[major(dev)].d_open)(dev, FREAD|FWRITE);
-       swdevt[index].sw_freed = 1;
-       nblks = swdevt[index].sw_nblks;
+       sp = &swdevt[index];
+       dev = sp->sw_dev;
+       if (error = (*bdevsw[major(dev)].d_open)(dev, FREAD|FWRITE, S_IFBLK))
+               return (error);
+       sp->sw_freed = 1;
+       nblks = sp->sw_nblks;
        for (dvbase = 0; dvbase < nblks; dvbase += dmmax) {
                blk = nblks - dvbase;
                if ((vsbase = index*dmmax + dvbase*nswdev) >= nswap)
        for (dvbase = 0; dvbase < nblks; dvbase += dmmax) {
                blk = nblks - dvbase;
                if ((vsbase = index*dmmax + dvbase*nswdev) >= nswap)
@@ -150,16 +156,39 @@ swfree(index)
                         * but need some space for argmap so use 1/2 this
                         * hunk which needs special treatment anyways.
                         */
                         * but need some space for argmap so use 1/2 this
                         * hunk which needs special treatment anyways.
                         */
-                       argdev = swdevt[0].sw_dev;
+                       argdev = sp->sw_dev;
+#ifdef SECSIZE
+                       argdbsize = sp->sw_blksize;
+                       rminit(argmap,
+                          ((blk / 2) * DEV_BSIZE - CLBYTES) / argdbsize,
+                          CLBYTES / argdbsize, "argmap", ARGMAPSIZE);
+#else SECSIZE
                        rminit(argmap, (long)(blk/2-ctod(CLSIZE)),
                            (long)ctod(CLSIZE), "argmap", ARGMAPSIZE);
                        rminit(argmap, (long)(blk/2-ctod(CLSIZE)),
                            (long)ctod(CLSIZE), "argmap", ARGMAPSIZE);
+#endif SECSIZE
                        /*
                         * First of all chunks... initialize the swapmap
                         * the second half of the hunk.
                         */
                        rminit(swapmap, (long)blk/2, (long)blk/2,
                            "swap", nswapmap);
                        /*
                         * First of all chunks... initialize the swapmap
                         * the second half of the hunk.
                         */
                        rminit(swapmap, (long)blk/2, (long)blk/2,
                            "swap", nswapmap);
+               } else if (dvbase == 0) {
+                       /*
+                        * Don't use the first cluster of the device
+                        * in case it starts with a label or boot block.
+                        */
+                       rmfree(swapmap, blk - ctod(CLSIZE),
+                           vsbase + ctod(CLSIZE));
+               } else if (dvbase == 0) {
+                       /*
+                        * Don't use the first cluster of the device
+                        * in case it starts with a label or boot block.
+                        */
+                       rmfree(swapmap, blk - ctod(CLSIZE),
+                           vsbase + ctod(CLSIZE));
                } else
                        rmfree(swapmap, blk, vsbase);
        }
                } else
                        rmfree(swapmap, blk, vsbase);
        }
+       return (0);
+       return (0);
 }
 }