-/* $OpenBSD: uipc_mbuf.c,v 1.279 2021/03/06 09:20:49 jsg Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.280 2022/01/18 12:38:21 bluhm Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
head = M_DATABUF(m0);
if (m0->m_len == 0) {
- m0->m_data = head;
-
while (m->m_len == 0) {
m = m_free(m);
if (m == NULL)
tail = head + M_SIZE(m0);
head += adj;
- if (len <= tail - head) {
- /* there's enough space in the first mbuf */
-
- if (len > tail - mtod(m0, caddr_t)) {
+ if (!M_READONLY(m0) && len <= tail - head) {
+ /* we can copy everything into the first mbuf */
+ if (m0->m_len == 0) {
+ m0->m_data = head;
+ } else if (len > tail - mtod(m0, caddr_t)) {
/* need to memmove to make space at the end */
memmove(head, mtod(m0, caddr_t), m0->m_len);
m0->m_data = head;
len -= m0->m_len;
} else {
- /* the first mbuf is too small so make a new one */
+ /* the first mbuf is too small or read-only, make a new one */
space = adj + len;
if (space > MAXMCLBYTES)