Index: sys/kern/libmchain/subr_mchain.c =================================================================== RCS file: /mnt/share/dragonfly-cvs/src/sys/kern/libmchain/subr_mchain.c,v retrieving revision 1.4 diff -u -r1.4 subr_mchain.c --- sys/kern/libmchain/subr_mchain.c 7 Jun 2005 19:06:08 -0000 1.4 +++ sys/kern/libmchain/subr_mchain.c 21 Jan 2006 11:45:03 -0000 @@ -10,9 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Boris Popov. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -37,8 +34,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -47,11 +44,11 @@ MODULE_VERSION(libmchain, 1); -#define MBERROR(format, args...) printf("%s(%d): "format, __func__ , \ - __LINE__ ,## args) +#define MBERROR(format, ...) printf("%s(%d): "format, __func__ , \ + __LINE__ , ## __VA_ARGS__) -#define MBPANIC(format, args...) printf("%s(%d): "format, __func__ , \ - __LINE__ ,## args) +#define MBPANIC(format, ...) printf("%s(%d): "format, __func__ , \ + __LINE__ , ## __VA_ARGS__) /* * Various helper functions @@ -157,42 +154,42 @@ int mb_put_uint16be(struct mbchain *mbp, u_int16_t x) { - x = htobes(x); + x = htobe16(x); return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM); } int mb_put_uint16le(struct mbchain *mbp, u_int16_t x) { - x = htoles(x); + x = htole16(x); return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM); } int mb_put_uint32be(struct mbchain *mbp, u_int32_t x) { - x = htobel(x); + x = htobe32(x); return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM); } int mb_put_uint32le(struct mbchain *mbp, u_int32_t x) { - x = htolel(x); + x = htole32(x); return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM); } int mb_put_int64be(struct mbchain *mbp, int64_t x) { - x = htobeq(x); + x = htobe64(x); return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM); } int mb_put_int64le(struct mbchain *mbp, int64_t x) { - x = htoleq(x); + x = htole64(x); return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM); } @@ -203,6 +200,7 @@ caddr_t dst; c_caddr_t src; int cplen, error, mleft, count; + size_t srclen, dstlen; m = mbp->mb_cur; mleft = mbp->mb_mleft; @@ -219,10 +217,13 @@ continue; } cplen = mleft > size ? size : mleft; + srclen = dstlen = cplen; dst = mtod(m, caddr_t) + m->m_len; switch (type) { case MB_MCUSTOM: - error = mbp->mb_copy(mbp, source, dst, cplen); + srclen = size; + dstlen = mleft; + error = mbp->mb_copy(mbp, source, dst, &srclen, &dstlen); if (error) return error; break; @@ -242,11 +243,11 @@ bzero(dst, cplen); break; } - size -= cplen; - source += cplen; - m->m_len += cplen; - mleft -= cplen; - mbp->mb_count += cplen; + size -= srclen; + source += srclen; + m->m_len += dstlen; + mleft -= dstlen; + mbp->mb_count += dstlen; } mbp->mb_cur = m; mbp->mb_mleft = mleft; @@ -295,7 +296,8 @@ return error; uiop->uio_offset += left; uiop->uio_resid -= left; - uiop->uio_iov->iov_base += left; + uiop->uio_iov->iov_base = + (char *)uiop->uio_iov->iov_base + left; uiop->uio_iov->iov_len -= left; size -= left; } @@ -393,7 +395,8 @@ u_int16_t v; int error = md_get_uint16(mdp, &v); - *x = letohs(v); + if (x != NULL) + *x = le16toh(v); return error; } @@ -402,7 +405,8 @@ u_int16_t v; int error = md_get_uint16(mdp, &v); - *x = betohs(v); + if (x != NULL) + *x = be16toh(v); return error; } @@ -419,7 +423,8 @@ int error; error = md_get_uint32(mdp, &v); - *x = betohl(v); + if (x != NULL) + *x = be32toh(v); return error; } @@ -430,7 +435,8 @@ int error; error = md_get_uint32(mdp, &v); - *x = letohl(v); + if (x != NULL) + *x = le32toh(v); return error; } @@ -447,7 +453,8 @@ int error; error = md_get_int64(mdp, &v); - *x = betohq(v); + if (x != NULL) + *x = be64toh(v); return error; } @@ -458,7 +465,8 @@ int error; error = md_get_int64(mdp, &v); - *x = letohq(v); + if (x != NULL) + *x = le64toh(v); return error; } @@ -546,7 +554,8 @@ return error; uiop->uio_offset += left; uiop->uio_resid -= left; - uiop->uio_iov->iov_base += left; + uiop->uio_iov->iov_base = + (char *)uiop->uio_iov->iov_base + left; uiop->uio_iov->iov_len -= left; size -= left; } Index: sys/sys/mchain.h =================================================================== RCS file: /mnt/share/dragonfly-cvs/src/sys/sys/mchain.h,v retrieving revision 1.3 diff -u -r1.3 mchain.h --- sys/sys/mchain.h 23 Sep 2004 16:11:47 -0000 1.3 +++ sys/sys/mchain.h 20 Jan 2006 17:32:41 -0000 @@ -35,67 +35,22 @@ #ifndef _SYS_MCHAIN_H_ #define _SYS_MCHAIN_H_ -#include - -/* - * This macros probably belongs to the endian.h - */ -#if _BYTE_ORDER == _LITTLE_ENDIAN - -#define htoles(x) ((u_int16_t)(x)) -#define letohs(x) ((u_int16_t)(x)) -#define htolel(x) ((u_int32_t)(x)) -#define letohl(x) ((u_int32_t)(x)) -#define htoleq(x) ((int64_t)(x)) -#define letohq(x) ((int64_t)(x)) - -#define htobes(x) (htons(x)) -#define betohs(x) (ntohs(x)) -#define htobel(x) (htonl(x)) -#define betohl(x) (ntohl(x)) - -static __inline int64_t -htobeq(int64_t x) -{ - return (int64_t)htonl((u_int32_t)(x >> 32)) | - (int64_t)htonl((u_int32_t)(x & 0xffffffff)) << 32; -} - -static __inline int64_t -betohq(int64_t x) -{ - return (int64_t)ntohl((u_int32_t)(x >> 32)) | - (int64_t)ntohl((u_int32_t)(x & 0xffffffff)) << 32; -} - -#else /* (BYTE_ORDER == LITTLE_ENDIAN) */ - -#error "Macros for Big-Endians are incomplete" - -/* -#define htoles(x) ((u_int16_t)(x)) -#define letohs(x) ((u_int16_t)(x)) -#define htolel(x) ((u_int32_t)(x)) -#define letohl(x) ((u_int32_t)(x)) -*/ -#endif /* (BYTE_ORDER == LITTLE_ENDIAN) */ - - #ifdef _KERNEL /* * Type of copy for mb_{put|get}_mem() */ #define MB_MSYSTEM 0 /* use bcopy() */ -#define MB_MUSER 1 /* use copyin()/copyout() */ -#define MB_MINLINE 2 /* use an inline copy loop */ +#define MB_MUSER 1 /* use copyin()/copyout() */ +#define MB_MINLINE 2 /* use an inline copy loop */ #define MB_MZERO 3 /* bzero(), mb_put_mem only */ #define MB_MCUSTOM 4 /* use an user defined function */ struct mbuf; struct mbchain; -typedef int mb_copy_t(struct mbchain *mbp, c_caddr_t src, caddr_t dst, int len); +typedef int mb_copy_t(struct mbchain *mbp, c_caddr_t src, caddr_t dst, + size_t *srclen, size_t *dstlen); struct mbchain { struct mbuf * mb_top; /* head of mbufs chain */