Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add two new mbuf routines:
details: https://anonhg.NetBSD.org/src/rev/b20d68922c37
branches: trunk
changeset: 545617:b20d68922c37
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat Apr 12 02:49:25 2003 +0000
description:
Add two new mbuf routines:
* m_apply(), which applies a function to each mbuf in chain
starting at a specified offset, for a specified length.
* m_getptr(), which returns a pointer to the mbuf, as well as
the offset into that mbuf, corresponding to an offset from
the beginning of an mbuf chain.
>From OpenBSD, cleaned up slightly by me.
diffstat:
sys/kern/uipc_mbuf.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++-
sys/sys/mbuf.h | 9 ++++--
2 files changed, 75 insertions(+), 5 deletions(-)
diffs (116 lines):
diff -r 8e7793fd1dee -r b20d68922c37 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c Sat Apr 12 02:15:22 2003 +0000
+++ b/sys/kern/uipc_mbuf.c Sat Apr 12 02:49:25 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbuf.c,v 1.65 2003/04/09 18:38:03 thorpej Exp $ */
+/* $NetBSD: uipc_mbuf.c,v 1.66 2003/04/12 02:49:25 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.65 2003/04/09 18:38:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.66 2003/04/12 02:49:25 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1022,3 +1022,70 @@
out: if (((m = m0)->m_flags & M_PKTHDR) && (m->m_pkthdr.len < totlen))
m->m_pkthdr.len = totlen;
}
+
+/*
+ * Apply function f to the data in an mbuf chain starting "off" bytes from the
+ * beginning, continuing for "len" bytes.
+ */
+int
+m_apply(struct mbuf *m, int off, int len,
+ int (*f)(void *, caddr_t, unsigned int), void *arg)
+{
+ unsigned int count;
+ int rval;
+
+ KASSERT(len >= 0);
+ KASSERT(off >= 0);
+
+ while (off > 0) {
+ KASSERT(m != NULL);
+ if (off < m->m_len)
+ break;
+ off -= m->m_len;
+ m = m->m_next;
+ }
+ while (len > 0) {
+ KASSERT(m != NULL);
+ count = min(m->m_len - off, len);
+
+ rval = (*f)(arg, mtod(m, caddr_t) + off, count);
+ if (rval)
+ return (rval);
+
+ len -= count;
+ off = 0;
+ m = m->m_next;
+ }
+
+ return (0);
+}
+
+/*
+ * Return a pointer to mbuf/offset of location in mbuf chain.
+ */
+struct mbuf *
+m_getptr(struct mbuf *m, int loc, int *off)
+{
+
+ while (loc >= 0) {
+ /* Normal end of search */
+ if (m->m_len > loc) {
+ *off = loc;
+ return (m);
+ } else {
+ loc -= m->m_len;
+
+ if (m->m_next == NULL) {
+ if (loc == 0) {
+ /* Point at the end of valid data */
+ *off = m->m_len;
+ return (m);
+ } else
+ return (NULL);
+ } else
+ m = m->m_next;
+ }
+ }
+
+ return (NULL);
+}
diff -r 8e7793fd1dee -r b20d68922c37 sys/sys/mbuf.h
--- a/sys/sys/mbuf.h Sat Apr 12 02:15:22 2003 +0000
+++ b/sys/sys/mbuf.h Sat Apr 12 02:49:25 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.h,v 1.80 2003/04/09 18:38:01 thorpej Exp $ */
+/* $NetBSD: mbuf.h,v 1.81 2003/04/12 02:49:25 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2001 The NetBSD Foundation, Inc.
@@ -807,12 +807,15 @@
struct mbuf *m_get(int, int);
struct mbuf *m_getclr(int, int);
struct mbuf *m_gethdr(int, int);
-struct mbuf *m_prepend(struct mbuf *,int,int);
+struct mbuf *m_prepend(struct mbuf *,int, int);
struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
struct mbuf *m_pullup(struct mbuf *, int);
struct mbuf *m_copyup(struct mbuf *, int, int);
-struct mbuf *m_split(struct mbuf *,int,int);
+struct mbuf *m_split(struct mbuf *,int, int);
+struct mbuf *m_getptr(struct mbuf *, int, int *);
void m_adj(struct mbuf *, int);
+int m_apply(struct mbuf *, int, int,
+ int (*)(void *, caddr_t, unsigned int), void *);
void m_cat(struct mbuf *,struct mbuf *);
#ifdef MBUFTRACE
void m_claim(struct mbuf *, struct mowner *);
Home |
Main Index |
Thread Index |
Old Index