The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/kern_physio.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1994 John S. Dyson
    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 immediately at the beginning of the file, without modification,
   10  *    this list of conditions, and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 3. Absolutely no warranty of function or purpose is made by the author
   15  *    John S. Dyson.
   16  * 4. Modifications may be freely made to this file if the above conditions
   17  *    are met.
   18  *
   19  * $FreeBSD: releng/5.0/sys/kern/kern_physio.c 104908 2002-10-11 14:58:34Z mike $
   20  */
   21 
   22 #include <sys/param.h>
   23 #include <sys/systm.h>
   24 #include <sys/bio.h>
   25 #include <sys/buf.h>
   26 #include <sys/conf.h>
   27 #include <sys/proc.h>
   28 #include <sys/uio.h>
   29 
   30 #include <vm/vm.h>
   31 #include <vm/vm_extern.h>
   32 
   33 static void
   34 physwakeup(struct buf *bp)
   35 {
   36         wakeup(bp);
   37 }
   38 
   39 int
   40 physio(dev_t dev, struct uio *uio, int ioflag)
   41 {
   42         int i;
   43         int error;
   44         int spl;
   45         caddr_t sa;
   46         u_int iolen;
   47         struct buf *bp;
   48 
   49         /* Keep the process UPAGES from being swapped. XXX: why ? */
   50         PHOLD(curproc);
   51 
   52         bp = getpbuf(NULL);
   53         sa = bp->b_data;
   54         error = bp->b_error = 0;
   55 
   56         /* XXX: sanity check */
   57         if(dev->si_iosize_max < PAGE_SIZE) {
   58                 printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
   59                     devtoname(dev), dev->si_iosize_max);
   60                 dev->si_iosize_max = DFLTPHYS;
   61         }
   62 
   63         for (i = 0; i < uio->uio_iovcnt; i++) {
   64                 while (uio->uio_iov[i].iov_len) {
   65                         bp->b_flags = B_PHYS;
   66                         if (uio->uio_rw == UIO_READ)
   67                                 bp->b_iocmd = BIO_READ;
   68                         else 
   69                                 bp->b_iocmd = BIO_WRITE;
   70                         bp->b_dev = dev;
   71                         bp->b_iodone = physwakeup;
   72                         bp->b_data = uio->uio_iov[i].iov_base;
   73                         bp->b_bcount = uio->uio_iov[i].iov_len;
   74                         bp->b_offset = uio->uio_offset;
   75                         bp->b_saveaddr = sa;
   76 
   77                         /* Don't exceed drivers iosize limit */
   78                         if (bp->b_bcount > dev->si_iosize_max)
   79                                 bp->b_bcount = dev->si_iosize_max;
   80 
   81                         /* 
   82                          * Make sure the pbuf can map the request
   83                          * XXX: The pbuf has kvasize = MAXPHYS so a request
   84                          * XXX: larger than MAXPHYS - PAGE_SIZE must be
   85                          * XXX: page aligned or it will be fragmented.
   86                          */
   87                         iolen = ((vm_offset_t) bp->b_data) & PAGE_MASK;
   88                         if ((bp->b_bcount + iolen) > bp->b_kvasize) {
   89                                 bp->b_bcount = bp->b_kvasize;
   90                                 if (iolen != 0)
   91                                         bp->b_bcount -= PAGE_SIZE;
   92                         }
   93                         bp->b_bufsize = bp->b_bcount;
   94 
   95                         bp->b_blkno = btodb(bp->b_offset);
   96 
   97                         if (uio->uio_segflg == UIO_USERSPACE) {
   98                                 if (!useracc(bp->b_data, bp->b_bufsize,
   99                                     bp->b_iocmd == BIO_READ ?
  100                                     VM_PROT_WRITE : VM_PROT_READ)) {
  101                                         error = EFAULT;
  102                                         goto doerror;
  103                                 }
  104                                 vmapbuf(bp);
  105                         }
  106 
  107                         DEV_STRATEGY(bp, 0);
  108                         spl = splbio();
  109                         while ((bp->b_flags & B_DONE) == 0)
  110                                 tsleep(bp, PRIBIO, "physstr", 0);
  111                         splx(spl);
  112 
  113                         if (uio->uio_segflg == UIO_USERSPACE)
  114                                 vunmapbuf(bp);
  115                         iolen = bp->b_bcount - bp->b_resid;
  116                         if (iolen == 0 && !(bp->b_ioflags & BIO_ERROR))
  117                                 goto doerror;   /* EOF */
  118                         uio->uio_iov[i].iov_len -= iolen;
  119                         uio->uio_iov[i].iov_base =
  120                             (char *)uio->uio_iov[i].iov_base + iolen;
  121                         uio->uio_resid -= iolen;
  122                         uio->uio_offset += iolen;
  123                         if( bp->b_ioflags & BIO_ERROR) {
  124                                 error = bp->b_error;
  125                                 goto doerror;
  126                         }
  127                 }
  128         }
  129 doerror:
  130         relpbuf(bp, NULL);
  131         PRELE(curproc);
  132         return (error);
  133 }

Cache object: 0b578b5f667f44becb0fe82b0969b56b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.