Annotation of Net2/kern/kern__physio.c, revision 1.1.1.3

1.1       root        1: /*
                      2:  * Copyright (c) 1989, 1990, 1991, 1992 William F. Jolitz, TeleMuse
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. All advertising materials mentioning features or use of this software
                     14:  *    must display the following acknowledgement:
                     15:  *     This software is a component of "386BSD" developed by 
                     16:        William F. Jolitz, TeleMuse.
                     17:  * 4. Neither the name of the developer nor the name "386BSD"
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ 
                     22:  * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS 
                     23:  * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT. 
                     24:  * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT 
                     25:  * NOT MAKE USE THIS WORK.
                     26:  *
                     27:  * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
                     28:  * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN 
                     29:  * REFERENCES SUCH AS THE  "PORTING UNIX TO THE 386" SERIES 
                     30:  * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING 
                     31:  * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND 
                     32:  * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE 
                     33:  * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS 
                     34:  * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
                     35:  *
                     36:  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
                     37:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     38:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     39:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER BE LIABLE
                     40:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     41:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     42:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     43:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     44:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     45:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     46:  * SUCH DAMAGE.
                     47:  *
1.1.1.3 ! root       48:  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
        !            49:  * --------------------         -----   ----------------------
        !            50:  * CURRENT PATCH LEVEL:         2       00065
        !            51:  * --------------------         -----   ----------------------
        !            52:  *
        !            53:  * 09 Sep 92   Paul Kranenburg         Fixed read from /dev/drum
        !            54:  * 28 Nov 92   Mark Tinguely           Fixed small leak in physio()
1.1       root       55:  */
1.1.1.3 ! root       56: static char rcsid[] = "$Header: /cvsroot/src/sys/kern/Attic/kern__physio.c,v 1.2 1993/03/21 18:11:14 cgd Exp $";
1.1       root       57: 
                     58: #include "param.h"
                     59: #include "systm.h"
                     60: #include "buf.h"
                     61: #include "conf.h"
                     62: #include "proc.h"
                     63: #include "malloc.h"
                     64: #include "vnode.h"
1.1.1.2   root       65: #include "vm/vm.h"
1.1       root       66: #include "specdev.h"
                     67: 
                     68: static physio(int (*)(), int, int, int, caddr_t, int *, struct proc *);
                     69: 
                     70: /*
                     71:  * Driver interface to do "raw" I/O in the address space of a
                     72:  * user process directly for read and write operations..
                     73:  */
                     74: 
                     75: rawread(dev, uio)
                     76:        dev_t dev; struct uio *uio;
                     77: {
                     78:        return (uioapply(physio, cdevsw[major(dev)].d_strategy, dev, uio));
                     79: }
                     80: 
                     81: rawwrite(dev, uio)
                     82:        dev_t dev; struct uio *uio;
                     83: {
                     84:        return (uioapply(physio, cdevsw[major(dev)].d_strategy, dev, uio));
                     85: }
                     86: 
                     87: static physio(strat, dev, off, rw, base, len, p)
                     88:        int (*strat)(); 
                     89:        dev_t dev;
                     90:        int rw, off;
                     91:        caddr_t base;
                     92:        int *len;
                     93:        struct proc *p;
                     94: {
                     95:        register struct buf *bp;
1.1.1.2   root       96:        int amttodo = *len, error, amtdone;
                     97:        vm_prot_t ftype;
                     98:        static zero;
                     99:        caddr_t adr;
1.1       root      100: 
                    101:        rw = rw == UIO_READ ? B_READ : 0;
                    102: 
                    103:        /* create and build a buffer header for a transfer */
                    104:        bp = (struct buf *)malloc(sizeof(*bp), M_TEMP, M_NOWAIT);
1.1.1.3 ! root      105:        bzero((char *)bp, sizeof(*bp));                 /* 09 Sep 92*/
1.1       root      106:        bp->b_flags = B_BUSY | B_PHYS | rw;
                    107:        bp->b_proc = p;
                    108:        bp->b_dev = dev;
                    109:        bp->b_error = 0;
                    110:        bp->b_blkno = off/DEV_BSIZE;
1.1.1.2   root      111:        amtdone = 0;
1.1       root      112: 
                    113:        /* iteratively do I/O on as large a chunk as possible */
                    114:        do {
                    115:                bp->b_flags &= ~B_DONE;
                    116:                bp->b_un.b_addr = base;
1.1.1.2   root      117:                /* XXX limit */
                    118:                bp->b_bcount = min (256*1024, amttodo);
1.1       root      119: 
                    120:                /* first, check if accessible */
1.1.1.3 ! root      121:                if (rw == B_READ && !useracc(base, bp->b_bcount, B_WRITE)) {
        !           122:                        free(bp, M_TEMP);
1.1       root      123:                        return (EFAULT);
1.1.1.3 ! root      124:                }
        !           125:                if (rw == B_WRITE && !useracc(base, bp->b_bcount, B_READ)) {
        !           126:                        free(bp, M_TEMP);
1.1       root      127:                        return (EFAULT);
1.1.1.3 ! root      128:                }
1.1       root      129: 
1.1.1.2   root      130:                /* update referenced and dirty bits, handle copy objects */
                    131:                if (rw == B_READ)
                    132:                        ftype = VM_PROT_READ | VM_PROT_WRITE;
                    133:                else
                    134:                        ftype = VM_PROT_READ;
1.1.1.3 ! root      135: /* 09 Sep 92*/ for (adr = (caddr_t)trunc_page(base); adr < base + bp->b_bcount;
1.1.1.2   root      136:                        adr += NBPG) {
                    137:                        vm_fault(&curproc->p_vmspace->vm_map,
                    138:                                adr, ftype, FALSE);
                    139:                        *(int *) adr += zero;
                    140:                }
                    141: 
1.1       root      142:                /* lock in core */
                    143:                vslock (base, bp->b_bcount);
                    144: 
                    145:                /* perform transfer */
                    146:                physstrat(bp, strat, PRIBIO);
                    147: 
                    148:                /* unlock */
                    149:                vsunlock (base, bp->b_bcount, 0);
1.1.1.2   root      150:                amtdone = bp->b_bcount - bp->b_resid;
                    151:                amttodo -= amtdone;
                    152:                base += amtdone;
                    153:                bp->b_blkno += amtdone/DEV_BSIZE;
                    154:        } while (amttodo && (bp->b_flags & B_ERROR) == 0 && amtdone > 0);
1.1       root      155: 
                    156:        error = bp->b_error;
                    157:        free(bp, M_TEMP);
1.1.1.2   root      158:        *len = amttodo;
1.1       root      159:        return (error);
                    160: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.