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-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
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 
   20 #include <sys/cdefs.h>
   21 __FBSDID("$FreeBSD: releng/8.4/sys/kern/kern_physio.c 216102 2010-12-02 00:49:02Z kib $");
   22 
   23 #include <sys/param.h>
   24 #include <sys/systm.h>
   25 #include <sys/bio.h>
   26 #include <sys/buf.h>
   27 #include <sys/conf.h>
   28 #include <sys/proc.h>
   29 #include <sys/uio.h>
   30 
   31 #include <vm/vm.h>
   32 #include <vm/vm_extern.h>
   33 
   34 int
   35 physio(struct cdev *dev, struct uio *uio, int ioflag)
   36 {
   37         int i;
   38         int error;
   39         caddr_t sa;
   40         u_int iolen;
   41         struct buf *bp;
   42 
   43         /* Keep the process UPAGES from being swapped. XXX: why ? */
   44         PHOLD(curproc);
   45 
   46         bp = getpbuf(NULL);
   47         sa = bp->b_data;
   48         error = 0;
   49 
   50         /* XXX: sanity check */
   51         if(dev->si_iosize_max < PAGE_SIZE) {
   52                 printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
   53                     devtoname(dev), dev->si_iosize_max);
   54                 dev->si_iosize_max = DFLTPHYS;
   55         }
   56 
   57         for (i = 0; i < uio->uio_iovcnt; i++) {
   58                 while (uio->uio_iov[i].iov_len) {
   59                         bp->b_flags = 0;
   60                         if (uio->uio_rw == UIO_READ) {
   61                                 bp->b_iocmd = BIO_READ;
   62                                 curthread->td_ru.ru_inblock++;
   63                         } else {
   64                                 bp->b_iocmd = BIO_WRITE;
   65                                 curthread->td_ru.ru_oublock++;
   66                         }
   67                         bp->b_iodone = bdone;
   68                         bp->b_data = uio->uio_iov[i].iov_base;
   69                         bp->b_bcount = uio->uio_iov[i].iov_len;
   70                         bp->b_offset = uio->uio_offset;
   71                         bp->b_iooffset = uio->uio_offset;
   72                         bp->b_saveaddr = sa;
   73 
   74                         /* Don't exceed drivers iosize limit */
   75                         if (bp->b_bcount > dev->si_iosize_max)
   76                                 bp->b_bcount = dev->si_iosize_max;
   77 
   78                         /* 
   79                          * Make sure the pbuf can map the request
   80                          * XXX: The pbuf has kvasize = MAXPHYS so a request
   81                          * XXX: larger than MAXPHYS - PAGE_SIZE must be
   82                          * XXX: page aligned or it will be fragmented.
   83                          */
   84                         iolen = ((vm_offset_t) bp->b_data) & PAGE_MASK;
   85                         if ((bp->b_bcount + iolen) > bp->b_kvasize) {
   86                                 bp->b_bcount = bp->b_kvasize;
   87                                 if (iolen != 0)
   88                                         bp->b_bcount -= PAGE_SIZE;
   89                         }
   90                         bp->b_bufsize = bp->b_bcount;
   91 
   92                         bp->b_blkno = btodb(bp->b_offset);
   93 
   94                         if (uio->uio_segflg == UIO_USERSPACE)
   95                                 if (vmapbuf(bp) < 0) {
   96                                         error = EFAULT;
   97                                         goto doerror;
   98                                 }
   99 
  100                         dev_strategy(dev, bp);
  101                         if (uio->uio_rw == UIO_READ)
  102                                 bwait(bp, PRIBIO, "physrd");
  103                         else
  104                                 bwait(bp, PRIBIO, "physwr");
  105 
  106                         if (uio->uio_segflg == UIO_USERSPACE)
  107                                 vunmapbuf(bp);
  108                         iolen = bp->b_bcount - bp->b_resid;
  109                         if (iolen == 0 && !(bp->b_ioflags & BIO_ERROR))
  110                                 goto doerror;   /* EOF */
  111                         uio->uio_iov[i].iov_len -= iolen;
  112                         uio->uio_iov[i].iov_base =
  113                             (char *)uio->uio_iov[i].iov_base + iolen;
  114                         uio->uio_resid -= iolen;
  115                         uio->uio_offset += iolen;
  116                         if( bp->b_ioflags & BIO_ERROR) {
  117                                 error = bp->b_error;
  118                                 goto doerror;
  119                         }
  120                 }
  121         }
  122 doerror:
  123         relpbuf(bp, NULL);
  124         PRELE(curproc);
  125         return (error);
  126 }

Cache object: fdec5f308cf79eea4a5e9634fa5613fa


[ 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.