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$
   20  */
   21 
   22 #include <sys/param.h>
   23 #include <sys/systm.h>
   24 #include <sys/buf.h>
   25 #include <sys/conf.h>
   26 #include <sys/proc.h>
   27 #include <sys/uio.h>
   28 
   29 #include <vm/vm.h>
   30 #include <vm/vm_extern.h>
   31 
   32 static void
   33 physwakeup(struct buf *bp)
   34 {
   35         wakeup((caddr_t) bp);
   36 }
   37 
   38 int
   39 physio(dev_t dev, struct uio *uio, int ioflag)
   40 {
   41         int i;
   42         int error;
   43         int spl;
   44         int chk_blockno;
   45         caddr_t sa;
   46         off_t blockno;
   47         u_int iolen;
   48         struct buf *bp;
   49 
   50         /* Keep the process UPAGES from being swapped. XXX: why ? */
   51         PHOLD(curproc);
   52 
   53         bp = getpbuf(NULL);
   54         sa = bp->b_data;
   55         error = 0;
   56 
   57         /* XXX: sanity check */
   58         if(dev->si_iosize_max < PAGE_SIZE) {
   59                 printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
   60                     devtoname(dev), dev->si_iosize_max);
   61                 dev->si_iosize_max = DFLTPHYS;
   62         }
   63 
   64         /* Don't check block number overflow for D_MEM */
   65         if ((devsw(dev)->d_flags & D_TYPEMASK) == D_MEM)
   66                 chk_blockno = 0;
   67         else
   68                 chk_blockno = 1;
   69 
   70         for (i = 0; i < uio->uio_iovcnt; i++) {
   71                 while (uio->uio_iov[i].iov_len) {
   72                         if (uio->uio_rw == UIO_READ)
   73                                 bp->b_flags = B_PHYS | B_CALL | B_READ;
   74                         else 
   75                                 bp->b_flags = B_PHYS | B_CALL | B_WRITE;
   76                         bp->b_dev = dev;
   77                         bp->b_iodone = physwakeup;
   78                         bp->b_data = uio->uio_iov[i].iov_base;
   79                         bp->b_bcount = uio->uio_iov[i].iov_len;
   80                         bp->b_offset = uio->uio_offset;
   81                         bp->b_saveaddr = sa;
   82 
   83                         /* Don't exceed drivers iosize limit */
   84                         if (bp->b_bcount > dev->si_iosize_max)
   85                                 bp->b_bcount = dev->si_iosize_max;
   86 
   87                         /* 
   88                          * Make sure the pbuf can map the request
   89                          * XXX: The pbuf has kvasize = MAXPHYS so a request
   90                          * XXX: larger than MAXPHYS - PAGE_SIZE must be
   91                          * XXX: page aligned or it will be fragmented.
   92                          */
   93                         iolen = ((vm_offset_t) bp->b_data) & PAGE_MASK;
   94                         if ((bp->b_bcount + iolen) > bp->b_kvasize) {
   95                                 bp->b_bcount = bp->b_kvasize;
   96                                 if (iolen != 0)
   97                                         bp->b_bcount -= PAGE_SIZE;
   98                         }
   99                         bp->b_bufsize = bp->b_bcount;
  100 
  101                         blockno = bp->b_offset >> DEV_BSHIFT;
  102                         if (chk_blockno && (daddr_t)blockno != blockno) {
  103                                 error = EINVAL; /* blockno overflow */
  104                                 goto doerror;
  105                         }
  106                         bp->b_blkno = blockno;
  107 
  108                         if (uio->uio_segflg == UIO_USERSPACE)
  109                                 if (vmapbuf(bp) < 0) {
  110                                         error = EFAULT;
  111                                         goto doerror;
  112                                 }
  113 
  114                         BUF_STRATEGY(bp, 0);
  115                         spl = splbio();
  116                         while ((bp->b_flags & B_DONE) == 0)
  117                                 tsleep((caddr_t)bp, PRIBIO, "physstr", 0);
  118                         splx(spl);
  119 
  120                         if (uio->uio_segflg == UIO_USERSPACE)
  121                                 vunmapbuf(bp);
  122                         iolen = bp->b_bcount - bp->b_resid;
  123                         if (iolen == 0 && !(bp->b_flags & B_ERROR))
  124                                 goto doerror;   /* EOF */
  125                         uio->uio_iov[i].iov_len -= iolen;
  126                         uio->uio_iov[i].iov_base += iolen;
  127                         uio->uio_resid -= iolen;
  128                         uio->uio_offset += iolen;
  129                         if( bp->b_flags & B_ERROR) {
  130                                 error = bp->b_error;
  131                                 goto doerror;
  132                         }
  133                 }
  134         }
  135 doerror:
  136         relpbuf(bp, NULL);
  137         PRELE(curproc);
  138         return (error);
  139 }

Cache object: fed4a71dd50582fc9b49fa487eeda7f7


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