add mbuf deep-copy fnudtion, m_dup().

NOTE: if you use m_dup(), your additional kernel code can become
incompatible with 4.xBSD or other *BSD.
This commit is contained in:
itojun 1999-10-27 14:23:26 +00:00
parent 9b2cad3aee
commit b7f47adef9
2 changed files with 32 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_mbuf.c,v 1.43 1999/08/05 02:24:29 thorpej Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.44 1999/10/27 14:23:27 itojun Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -105,6 +105,7 @@ int max_datalen;
void *mclpool_alloc __P((unsigned long, int, int));
void mclpool_release __P((void *, unsigned long, int));
static struct mbuf *m_copym0 __P((struct mbuf *, int, int, int, int));
const char *mclpool_warnmsg =
"WARNING: mclpool limit reached; increase NMBCLUSTERS";
@ -400,6 +401,25 @@ m_copym(m, off0, len, wait)
struct mbuf *m;
int off0, wait;
int len;
{
return m_copym0(m, off0, len, wait, 0); /* shallow copy on M_EXT */
}
struct mbuf *
m_dup(m, off0, len, wait)
struct mbuf *m;
int off0, wait;
int len;
{
return m_copym0(m, off0, len, wait, 1); /* deep copy */
}
static struct mbuf *
m_copym0(m, off0, len, wait, deep)
struct mbuf *m;
int off0, wait;
int len;
int deep; /* deep copy */
{
struct mbuf *n, **np;
int off = off0;
@ -440,9 +460,15 @@ m_copym(m, off0, len, wait)
}
n->m_len = min(len, m->m_len - off);
if (m->m_flags & M_EXT) {
n->m_data = m->m_data + off;
n->m_ext = m->m_ext;
MCLADDREFERENCE(m, n);
if (!deep) {
n->m_data = m->m_data + off;
n->m_ext = m->m_ext;
MCLADDREFERENCE(m, n);
} else {
MCLGET(n, wait);
memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off,
(unsigned)n->m_len);
}
} else
memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off,
(unsigned)n->m_len);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mbuf.h,v 1.46 1999/08/05 04:00:03 sommerfeld Exp $ */
/* $NetBSD: mbuf.h,v 1.47 1999/10/27 14:23:26 itojun Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999 The NetBSD Foundation, Inc.
@ -534,6 +534,7 @@ struct mbuf *m_copym __P((struct mbuf *, int, int, int));
struct mbuf *m_copypacket __P((struct mbuf *, int));
struct mbuf *m_devget __P((char *, int, int, struct ifnet *,
void (*copy)(const void *, void *, size_t)));
struct mbuf *m_dup __P((struct mbuf *, int, int, int));
struct mbuf *m_free __P((struct mbuf *));
struct mbuf *m_get __P((int, int));
struct mbuf *m_getclr __P((int, int));