BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / kern / kern_physio.c
index 7ed76dd..bf6dc96 100644 (file)
@@ -2,14 +2,39 @@
  * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)kern_physio.c       7.17 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     from: @(#)kern_physio.c 7.20 (Berkeley) 5/11/91
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "buf.h"
 #include "conf.h"
 #include "proc.h"
 #include "buf.h"
 #include "conf.h"
 #include "proc.h"
 #include "vnode.h"
 #include "specdev.h"
 
 #include "vnode.h"
 #include "specdev.h"
 
+#ifdef HPUXCOMPAT
+#include "user.h"
+#endif
+
 /*
 /*
- * Raw I/O. The arguments are
- *     The strategy routine for the device
- *     A buffer, which will either be a special buffer header owned
- *         exclusively by the device for this purpose, or NULL,
- *         indicating that we should use a swap buffer
- *     The device number
- *     Read/write flag
- * Essentially all the work is computing physical addresses and
- * validating them.
- * If the user has the proper access privilidges, the process is
+ * This routine does raw device I/O for a user process.
+ *
+ * If the user has the proper access privileges, the process is
  * marked 'delayed unlock' and the pages involved in the I/O are
  * marked 'delayed unlock' and the pages involved in the I/O are
- * faulted and locked. After the completion of the I/O, the above pages
+ * faulted and locked. After the completion of the I/O, the pages
  * are unlocked.
  */
 physio(strat, bp, dev, rw, mincnt, uio)
  * are unlocked.
  */
 physio(strat, bp, dev, rw, mincnt, uio)
@@ -42,141 +64,33 @@ physio(strat, bp, dev, rw, mincnt, uio)
        u_int (*mincnt)();
        struct uio *uio;
 {
        u_int (*mincnt)();
        struct uio *uio;
 {
-       register struct iovec *iov;
-       register int requested, done;
-       register struct proc *p = curproc;
-       char *a;
-       int s, allocbuf = 0, error = 0;
-       struct buf *getswbuf();
-#ifdef SECSIZE
-       int bsize;
-       struct partinfo dpart;
-#endif SECSIZE
 
 
-#ifdef SECSIZE
-       if ((unsigned)major(dev) < nchrdev &&
-           (*cdevsw[major(dev)].d_ioctl)(dev, DIOCGPART, (caddr_t)&dpart,
-           FREAD) == 0)
-               bsize = dpart.disklab->d_secsize;
-       else
-               bsize = DEV_BSIZE;
-#endif SECSIZE
-       for (;;) {
-               if (uio->uio_iovcnt == 0)
-                       return (0);
-               iov = uio->uio_iov;
-               if (useracc(iov->iov_base, (u_int)iov->iov_len,
-                   rw==B_READ? B_WRITE : B_READ) == NULL)
-                       return (EFAULT);
-               s = splbio();
-               while (bp->b_flags&B_BUSY) {
-                       bp->b_flags |= B_WANTED;
-                       sleep((caddr_t)bp, PRIBIO+1);
-               }
-               if (!allocbuf) {        /* only if sharing caller's buffer */
-                       s = splbio();
-                       while (bp->b_flags&B_BUSY) {
-                               bp->b_flags |= B_WANTED;
-                               sleep((caddr_t)bp, PRIBIO+1);
-                       }
-                       splx(s);
-               }
-               bp->b_error = 0;
-               bp->b_proc = u.u_procp;
-#ifdef SECSIZE
-               bp->b_blksize = bsize;
-#endif SECSIZE
-               bp->b_un.b_addr = iov->iov_base;
-               while (iov->iov_len > 0) {
-                       bp->b_flags = B_BUSY | B_PHYS | rw;
-                       bp->b_dev = dev;
-#ifdef SECSIZE
-                       bp->b_blkno = uio->uio_offset / bsize;
-#else SECSIZE
-                       bp->b_blkno = btodb(uio->uio_offset);
-#endif SECSIZE
-                       bp->b_bcount = iov->iov_len;
-                       (*mincnt)(bp);
-                       c = bp->b_bcount;
-                       u.u_procp->p_flag |= SPHYSIO;
-                       vslock(a = bp->b_un.b_addr, c);
-                       physstrat(bp, strat, PRIBIO);
-                       (void) splbio();
-                       vsunlock(a, c, rw);
-                       u.u_procp->p_flag &= ~SPHYSIO;
-                       if (bp->b_flags&B_WANTED)
-                               wakeup((caddr_t)bp);
-                       splx(s);
-                       c -= bp->b_resid;
-                       bp->b_un.b_addr += c;
-                       iov->iov_len -= c;
-                       uio->uio_resid -= c;
-                       uio->uio_offset += c;
-                       /* temp kludge for tape drives */
-                       if (bp->b_resid || (bp->b_flags&B_ERROR))
-                               break;
-               }
-               bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS);
-               error = geterror(bp);
-               if (bp->b_resid || error)
-                       return (error);
-               uio->uio_iov++;
-               uio->uio_iovcnt--;
-       }
-#if defined(hp300)
-       DCIU();
-#endif
-       if (allocbuf)
-               freeswbuf(bp);
-       return (error);
+       /*
+        * Body deleted.
+        */
+       return (EIO);
 }
 
 }
 
+/*
+ * Calculate the maximum size of I/O request that can be requested
+ * in a single operation. This limit is necessary to prevent a single
+ * process from being able to lock more than a fixed amount of memory
+ * in the kernel.
+ */
 u_int
 minphys(bp)
        struct buf *bp;
 {
 u_int
 minphys(bp)
        struct buf *bp;
 {
-       if (bp->b_bcount > MAXPHYS)
-               bp->b_bcount = MAXPHYS;
-}
-
-static
-struct buf *
-getswbuf(prio)
-       int prio;
-{
-       int s;
-       struct buf *bp;
-
-       s = splbio();
-       while (bswlist.av_forw == NULL) {
-               bswlist.b_flags |= B_WANTED;
-               sleep((caddr_t)&bswlist, prio);
-       }
-       bp = bswlist.av_forw;
-       bswlist.av_forw = bp->av_forw;
-       splx(s);
-       return (bp);
-}
-
-static
-freeswbuf(bp)
-       struct buf *bp;
-{
-       int s;
 
 
-       s = splbio();
-       bp->av_forw = bswlist.av_forw;
-       bswlist.av_forw = bp;
-       if (bp->b_vp)
-               brelvp(bp);
-       if (bswlist.b_flags & B_WANTED) {
-               bswlist.b_flags &= ~B_WANTED;
-               wakeup((caddr_t)&bswlist);
-               wakeup((caddr_t)pageproc);
-       }
-       splx(s);
+       /*
+        * Body deleted.
+        */
+       return;
 }
 
 }
 
+/*
+ * Do a read on a device for a user process.
+ */
 rawread(dev, uio)
        dev_t dev;
        struct uio *uio;
 rawread(dev, uio)
        dev_t dev;
        struct uio *uio;
@@ -185,6 +99,9 @@ rawread(dev, uio)
            dev, B_READ, minphys, uio));
 }
 
            dev, B_READ, minphys, uio));
 }
 
+/*
+ * Do a write on a device for a user process.
+ */
 rawwrite(dev, uio)
        dev_t dev;
        struct uio *uio;
 rawwrite(dev, uio)
        dev_t dev;
        struct uio *uio;