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

FreeBSD/Linux Kernel Cross Reference
sys/opencrypto/crmbuf.c

Version: -  FREEBSD  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  cheribsd  -  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  -  FREEBSD-LIBC  -  FREEBSD8-LIBC  -  FREEBSD7-LIBC  -  FREEBSD6-LIBC  -  GLIBC27 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2002 Somebody. All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  * 3. All advertising materials mentioning features or use of this software
   13  *    must display the following acknowledgement:
   14  *      This product includes software developed by the University of
   15  *      California, Berkeley and its contributors.
   16  * 4. Neither the name of the University nor the names of its contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  *
   32  * $FreeBSD: src/sys/opencrypto/crmbuf.c,v 1.1 2002/10/04 20:31:22 sam Exp $
   33  */
   34 
   35 #include "opt_param.h"
   36 #include <sys/param.h>
   37 #include <sys/systm.h>
   38 #include <sys/mbuf.h>
   39 #include <sys/kernel.h>
   40 
   41 /*
   42  * Miscellaneous mbuf routines that belong in uipc_mbuf.c but
   43  * are kept private to the crypto support for now.
   44  */
   45 extern  int m_apply(struct mbuf *m, int off, int len,
   46                     int (*f)(caddr_t, caddr_t, unsigned int), caddr_t fstate);
   47 extern  struct mbuf * m_getptr(struct mbuf *m, int loc, int *off);
   48 
   49 /*
   50  * Apply function f to the data in an mbuf chain starting "off" bytes from the
   51  * beginning, continuing for "len" bytes.
   52  */
   53 int
   54 m_apply(struct mbuf *m, int off, int len, int (*f)(caddr_t, caddr_t, unsigned int), caddr_t fstate)
   55 {
   56         int rval;
   57         unsigned int count;
   58 
   59         if (len < 0)
   60                 panic("m_apply: len %d < 0", len);
   61         if (off < 0)
   62                 panic("m_apply: off %d < 0", off);
   63         while (off > 0) {
   64                 if (m == NULL)
   65                         panic("m_apply: null mbuf in skip");
   66                 if (off < m->m_len)
   67                         break;
   68                 off -= m->m_len;
   69                 m = m->m_next;
   70         }
   71         while (len > 0) {
   72                 if (m == NULL)
   73                         panic("m_apply: null mbuf");
   74                 count = min(m->m_len - off, len);
   75 
   76                 rval = f(fstate, mtod(m, caddr_t) + off, count);
   77                 if (rval)
   78                         return (rval);
   79 
   80                 len -= count;
   81                 off = 0;
   82                 m = m->m_next;
   83         }
   84 
   85         return (0);
   86 }
   87 
   88 /*
   89  * Return a pointer to mbuf/offset of location in mbuf chain.
   90  */
   91 struct mbuf *
   92 m_getptr(struct mbuf *m, int loc, int *off)
   93 {
   94         while (loc >= 0) {
   95                 /* Normal end of search */
   96                 if (m->m_len > loc) {
   97                         *off = loc;
   98                         return (m);
   99                 }
  100                 else {
  101                         loc -= m->m_len;
  102 
  103                         if (m->m_next == NULL) {
  104                                 if (loc == 0) {
  105                                         /* Point at the end of valid data */
  106                                         *off = m->m_len;
  107                                         return (m);
  108                                 }
  109                                 else
  110                                         return (NULL);
  111                         }
  112                         else
  113                                 m = m->m_next;
  114                 }
  115         }
  116 
  117         return (NULL);
  118 }

Cache object: 6b6ec6333f1aaeacc7ecf9d3043f9927


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