Add m_mbuftouio() helper function to copy(out) an arbitrary
long mbuf chain into an arbitrary large uio in a single step. It is a functional mirror image of m_uiotombuf(). This function is supposed to be used instead of hand rolled code with the same purpose and to concentrate it into one place for potential further optimization or hardware assistance.
This commit is contained in:
parent
0622974ab2
commit
bc05b2f6fa
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=194667
@ -1769,6 +1769,34 @@ m_uiotombuf(struct uio *uio, int how, int len, int align, int flags)
|
||||
return (m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy an mbuf chain into a uio limited by len if set.
|
||||
*/
|
||||
int
|
||||
m_mbuftouio(struct uio *uio, struct mbuf *m, int len)
|
||||
{
|
||||
int error, length, total;
|
||||
int progress = 0;
|
||||
|
||||
if (len > 0)
|
||||
total = min(uio->uio_resid, len);
|
||||
else
|
||||
total = uio->uio_resid;
|
||||
|
||||
/* Fill the uio with data from the mbufs. */
|
||||
for (; m != NULL; m = m->m_next) {
|
||||
length = min(m->m_len, total - progress);
|
||||
|
||||
error = uiomove(mtod(m, void *), length, uio);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
progress += length;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the m_data pointer of a newly-allocated mbuf
|
||||
* to place an object of the specified size at the
|
||||
|
@ -813,6 +813,7 @@ void m_freem(struct mbuf *);
|
||||
struct mbuf *m_getm2(struct mbuf *, int, int, short, int);
|
||||
struct mbuf *m_getptr(struct mbuf *, int, int *);
|
||||
u_int m_length(struct mbuf *, struct mbuf **);
|
||||
int m_mbuftouio(struct uio *, struct mbuf *, int);
|
||||
void m_move_pkthdr(struct mbuf *, struct mbuf *);
|
||||
struct mbuf *m_prepend(struct mbuf *, int, int);
|
||||
void m_print(const struct mbuf *, int);
|
||||
|
Loading…
Reference in New Issue
Block a user