summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2003-04-23 01:36:53 +0000
committerJason Wright <jason@cvs.openbsd.org>2003-04-23 01:36:53 +0000
commit5bd65e491cdcb6238a2b4d8d63f0e648a36e6ebf (patch)
tree83874a5963c2852deea97cc296a203a5f0ad4436 /sys/kern
parente44d7024f11c55dda9eb57072b1256b410065539 (diff)
Move m_copyback() to uipc_mbuf where it makes some kinda sense; ok dhartmei
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/uipc_mbuf.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index d3294797913..757e57380a9 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.59 2003/02/12 14:41:07 jason Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.60 2003/04/23 01:36:52 jason Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -426,6 +426,60 @@ m_copydata(m, off, len, cp)
}
/*
+ * Copy data from a buffer back into the indicated mbuf chain,
+ * starting "off" bytes from the beginning, extending the mbuf
+ * chain if necessary. The mbuf needs to be properly initialized
+ * including the setting of m_len.
+ */
+void
+m_copyback(m0, off, len, cp)
+ struct mbuf *m0;
+ register int off;
+ register int len;
+ caddr_t cp;
+{
+ register int mlen;
+ register struct mbuf *m = m0, *n;
+ int totlen = 0;
+
+ if (m0 == 0)
+ return;
+ while (off > (mlen = m->m_len)) {
+ off -= mlen;
+ totlen += mlen;
+ if (m->m_next == 0) {
+ n = m_getclr(M_DONTWAIT, m->m_type);
+ if (n == 0)
+ goto out;
+ n->m_len = min(MLEN, len + off);
+ m->m_next = n;
+ }
+ m = m->m_next;
+ }
+ while (len > 0) {
+ mlen = min (m->m_len - off, len);
+ bcopy(cp, off + mtod(m, caddr_t), (unsigned)mlen);
+ cp += mlen;
+ len -= mlen;
+ mlen += off;
+ off = 0;
+ totlen += mlen;
+ if (len == 0)
+ break;
+ if (m->m_next == 0) {
+ n = m_get(M_DONTWAIT, m->m_type);
+ if (n == 0)
+ break;
+ n->m_len = min(MLEN, len);
+ m->m_next = n;
+ }
+ m = m->m_next;
+ }
+out: if (((m = m0)->m_flags & M_PKTHDR) && (m->m_pkthdr.len < totlen))
+ m->m_pkthdr.len = totlen;
+}
+
+/*
* Concatenate mbuf chain n to m.
* Both chains must be of the same type (e.g. MT_DATA).
* Any m_pkthdr is not updated.