Subject: Re: m_copy - doesn't copy if M_EXT is set.
To: None <tls@rek.tjls.com>
From: None <itojun@iijlab.net>
List: tech-net
Date: 10/09/1999 17:48:14
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <16988.939458867.1@coconut.itojun.org>
Content-Transfer-Encoding: 7bit

>> OpenBSD will pick it up, sooner or later (:-), and we can probably get
>> it into FreeBSD as well...leaving BSDI, who seem to do their own thing
>> anyway.
>Of course, we've already been told what name Darwin is using for this -- I
>suggest we follow their example and call it m_dup(), or at least provide
>a compatibility macro.

	This does not raise any compatibility problems.  Let me know
	if you like it or not.

itojun



------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <16988.939458867.2@coconut.itojun.org>
Content-Transfer-Encoding: 7bit

Index: kern/uipc_mbuf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/uipc_mbuf.c,v
retrieving revision 1.43
diff -c -r1.43 uipc_mbuf.c
*** uipc_mbuf.c	1999/08/05 02:24:29	1.43
--- uipc_mbuf.c	1999/10/09 08:43:08
***************
*** 105,110 ****
--- 105,111 ----
  
  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";
***************
*** 401,406 ****
--- 402,426 ----
  	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;
  	struct mbuf *top;
***************
*** 440,448 ****
  		}
  		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);
  		} else
  			memcpy(mtod(n, caddr_t), mtod(m, caddr_t)+off,
  			    (unsigned)n->m_len);
--- 460,474 ----
  		}
  		n->m_len = min(len, m->m_len - off);
  		if (m->m_flags & M_EXT) {
! 			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);
Index: sys/mbuf.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/mbuf.h,v
retrieving revision 1.46
diff -c -r1.46 mbuf.h
*** mbuf.h	1999/08/05 04:00:03	1.46
--- mbuf.h	1999/10/09 08:43:10
***************
*** 534,539 ****
--- 534,540 ----
  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));

------- =_aaaaaaaaaa0--