X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3903760236c30e3b5ace7a4eefac3a269d68957c..eb6b6ca394357805f2bdba989abae309f718b4d8:/bsd/nfs/xdr_subs.h diff --git a/bsd/nfs/xdr_subs.h b/bsd/nfs/xdr_subs.h index 77590a33b..36e4dc929 100644 --- a/bsd/nfs/xdr_subs.h +++ b/bsd/nfs/xdr_subs.h @@ -2,7 +2,7 @@ * Copyright (c) 2000-2011 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in @@ -11,10 +11,10 @@ * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. - * + * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -22,7 +22,7 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ @@ -82,14 +82,14 @@ * but we cannot count on their alignment anyway. */ -#define fxdr_unsigned(t, v) ((t)ntohl((uint32_t)(v))) -#define txdr_unsigned(v) (htonl((uint32_t)(v))) +#define fxdr_unsigned(t, v) ((t)ntohl((uint32_t)(v))) +#define txdr_unsigned(v) (htonl((uint32_t)(v))) -#define fxdr_hyper(f, t) { \ +#define fxdr_hyper(f, t) { \ ((uint32_t *)(t))[_QUAD_HIGHWORD] = ntohl(((uint32_t *)(f))[0]); \ ((uint32_t *)(t))[_QUAD_LOWWORD] = ntohl(((uint32_t *)(f))[1]); \ } -#define txdr_hyper(f, t) { \ +#define txdr_hyper(f, t) { \ ((uint32_t *)(t))[0] = htonl(((uint32_t *)(f))[_QUAD_HIGHWORD]); \ ((uint32_t *)(t))[1] = htonl(((uint32_t *)(f))[_QUAD_LOWWORD]); \ } @@ -100,28 +100,31 @@ * * generalized functionality for managing the building/dissecting of XDR data */ -typedef enum xdrbuf_type { XDRBUF_BUFFER=1 } xdrbuf_type; +typedef enum xdrbuf_type { + XDRBUF_NONE = 0, + XDRBUF_BUFFER = 1, +} xdrbuf_type; struct xdrbuf { union { struct { - char * xbb_base; /* base address of buffer */ - uint32_t xbb_size; /* size of buffer */ - uint32_t xbb_len; /* length of data in buffer */ + char * xbb_base; /* base address of buffer */ + uint32_t xbb_size; /* size of buffer */ + uint32_t xbb_len; /* length of data in buffer */ } xb_buffer; } xb_u; - char * xb_ptr; /* pointer to current position */ - size_t xb_left; /* bytes remaining in current buffer */ - size_t xb_growsize; /* bytes to allocate when growing */ - xdrbuf_type xb_type; /* type of xdr buffer */ - uint32_t xb_flags; /* XB_* (see below) */ + char * xb_ptr; /* pointer to current position */ + size_t xb_left; /* bytes remaining in current buffer */ + size_t xb_growsize; /* bytes to allocate when growing */ + xdrbuf_type xb_type; /* type of xdr buffer */ + uint32_t xb_flags; /* XB_* (see below) */ }; -#define XB_CLEANUP 0x0001 /* needs cleanup */ +#define XB_CLEANUP 0x0001 /* needs cleanup */ -#define XDRWORD 4 /* the basic XDR building block is a 4 byte (32 bit) word */ -#define xdr_rndup(a) (((a)+3)&(~0x3)) /* round up to XDRWORD size */ -#define xdr_pad(a) (xdr_rndup(a) - (a)) /* calculate round up padding */ +#define XDRWORD 4 /* the basic XDR building block is a 4 byte (32 bit) word */ +#define xdr_rndup(a) (((a)+3)&(~0x3)) /* round up to XDRWORD size */ +#define xdr_pad(a) (xdr_rndup(a) - (a)) /* calculate round up padding */ void xb_init(struct xdrbuf *, xdrbuf_type); void xb_init_buffer(struct xdrbuf *, char *, size_t); @@ -163,8 +166,9 @@ xb_init_buffer(struct xdrbuf *xbp, char *buf, size_t buflen) xbp->xb_growsize = 512; xbp->xb_ptr = buf; xbp->xb_left = buflen; - if (buf) /* when using an existing buffer, xb code should skip cleanup */ + if (buf) { /* when using an existing buffer, xb code should skip cleanup */ xbp->xb_flags &= ~XB_CLEANUP; + } } /* @@ -173,7 +177,7 @@ xb_init_buffer(struct xdrbuf *xbp, char *buf, size_t buflen) char * xb_buffer_base(struct xdrbuf *xbp) { - return (xbp->xb_u.xb_buffer.xbb_base); + return xbp->xb_u.xb_buffer.xbb_base; } /* @@ -182,12 +186,16 @@ xb_buffer_base(struct xdrbuf *xbp) void xb_cleanup(struct xdrbuf *xbp) { - if (!(xbp->xb_flags & XB_CLEANUP)) + if (!(xbp->xb_flags & XB_CLEANUP)) { return; + } switch (xbp->xb_type) { case XDRBUF_BUFFER: - if (xbp->xb_u.xb_buffer.xbb_base) + if (xbp->xb_u.xb_buffer.xbb_base) { xb_free(xbp->xb_u.xb_buffer.xbb_base); + } + break; + default: break; } xbp->xb_flags &= ~XB_CLEANUP; @@ -204,6 +212,8 @@ xb_set_cur_buf_len(struct xdrbuf *xbp) case XDRBUF_BUFFER: xbp->xb_u.xb_buffer.xbb_len = xbp->xb_ptr - xbp->xb_u.xb_buffer.xbb_base; break; + default: + break; } } @@ -216,8 +226,9 @@ xb_advance(struct xdrbuf *xbp, uint32_t len) uint32_t tlen; while (len) { - if (xbp->xb_left <= 0) - return (EBADRPC); + if (xbp->xb_left <= 0) { + return EBADRPC; + } tlen = MIN(xbp->xb_left, len); if (tlen) { xbp->xb_ptr += tlen; @@ -225,7 +236,7 @@ xb_advance(struct xdrbuf *xbp, uint32_t len) len -= tlen; } } - return (0); + return 0; } /* @@ -240,9 +251,11 @@ xb_offset(struct xdrbuf *xbp) case XDRBUF_BUFFER: offset = xbp->xb_ptr - xbp->xb_u.xb_buffer.xbb_base; break; + default: + break; } - return (offset); + return offset; } /* @@ -251,15 +264,16 @@ xb_offset(struct xdrbuf *xbp) int xb_seek(struct xdrbuf *xbp, uint32_t offset) { - switch (xbp->xb_type) { case XDRBUF_BUFFER: xbp->xb_ptr = xbp->xb_u.xb_buffer.xbb_base + offset; xbp->xb_left = xbp->xb_u.xb_buffer.xbb_len - offset; break; + default: + break; } - return (0); + return 0; } /* @@ -275,7 +289,7 @@ xb_malloc(size_t size) #else buf = malloc(size); #endif - return (buf); + return buf; } /* * free a chunk of memory allocated with xb_malloc() @@ -304,11 +318,13 @@ xb_grow(struct xdrbuf *xbp) oldsize = xbp->xb_u.xb_buffer.xbb_size; oldbuf = xbp->xb_u.xb_buffer.xbb_base; newsize = oldsize + xbp->xb_growsize; - if (newsize < oldsize) - return (ENOMEM); + if (newsize < oldsize) { + return ENOMEM; + } newbuf = xb_malloc(newsize); - if (newbuf == NULL) - return (ENOMEM); + if (newbuf == NULL) { + return ENOMEM; + } if (oldbuf != NULL) { bcopy(oldbuf, newbuf, oldsize); xb_free(oldbuf); @@ -318,9 +334,11 @@ xb_grow(struct xdrbuf *xbp) xbp->xb_ptr = newbuf + oldsize; xbp->xb_left = xbp->xb_growsize; break; + default: + break; } - return (0); + return 0; } /* @@ -340,16 +358,19 @@ xb_add_bytes(struct xdrbuf *xbp, const char *buf, uint32_t count, int nopad) while (len) { if (xbp->xb_left <= 0) { /* need more space */ - if ((error = xb_grow(xbp))) - return (error); - if (xbp->xb_left <= 0) - return (ENOMEM); + if ((error = xb_grow(xbp))) { + return error; + } + if (xbp->xb_left <= 0) { + return ENOMEM; + } } tlen = MIN(xbp->xb_left, len); if (tlen) { if (count) { - if (tlen > count) + if (tlen > count) { tlen = count; + } bcopy(buf, xbp->xb_ptr, tlen); } else { bzero(xbp->xb_ptr, tlen); @@ -363,7 +384,7 @@ xb_add_bytes(struct xdrbuf *xbp, const char *buf, uint32_t count, int nopad) } } } - return (0); + return 0; } /* @@ -380,13 +401,15 @@ xb_get_bytes(struct xdrbuf *xbp, char *buf, uint32_t count, int nopad) /* copy in "count" bytes and zero out any pad bytes */ while (len) { - if (xbp->xb_left <= 0) - return (ENOMEM); + if (xbp->xb_left <= 0) { + return ENOMEM; + } tlen = MIN(xbp->xb_left, len); if (tlen) { if (count) { - if (tlen > count) + if (tlen > count) { tlen = count; + } bcopy(xbp->xb_ptr, buf, tlen); } xbp->xb_ptr += tlen; @@ -398,7 +421,7 @@ xb_get_bytes(struct xdrbuf *xbp, char *buf, uint32_t count, int nopad) } } } - return (0); + return 0; } #endif /* _NFS_XDR_SUBS_FUNCS_ */ @@ -411,53 +434,53 @@ xb_get_bytes(struct xdrbuf *xbp, char *buf, uint32_t count, int nopad) /* finalize the data that has been added to the buffer */ #define xb_build_done(E, XB) \ do { \ - if (E) break; \ - xb_set_cur_buf_len(XB); \ + if (E) break; \ + xb_set_cur_buf_len(XB); \ } while (0) /* add a 32-bit value */ #define xb_add_32(E, XB, VAL) \ do { \ - uint32_t __tmp; \ - if (E) break; \ - __tmp = txdr_unsigned(VAL); \ - (E) = xb_add_bytes((XB), (void*)&__tmp, XDRWORD, 0); \ + uint32_t __tmp; \ + if (E) break; \ + __tmp = txdr_unsigned(VAL); \ + (E) = xb_add_bytes((XB), (void*)&__tmp, XDRWORD, 0); \ } while (0) /* add a 64-bit value */ #define xb_add_64(E, XB, VAL) \ do { \ - uint64_t __tmp1, __tmp2; \ - if (E) break; \ - __tmp1 = (VAL); \ - txdr_hyper(&__tmp1, &__tmp2); \ - (E) = xb_add_bytes((XB), (char*)&__tmp2, 2 * XDRWORD, 0); \ + uint64_t __tmp1, __tmp2; \ + if (E) break; \ + __tmp1 = (VAL); \ + txdr_hyper(&__tmp1, &__tmp2); \ + (E) = xb_add_bytes((XB), (char*)&__tmp2, 2 * XDRWORD, 0); \ } while (0) /* add an array of XDR words */ #define xb_add_word_array(E, XB, A, LEN) \ do { \ - uint32_t __i; \ - xb_add_32((E), (XB), (LEN)); \ - for (__i=0; __i < (uint32_t)(LEN); __i++) \ - xb_add_32((E), (XB), (A)[__i]); \ + uint32_t __i; \ + xb_add_32((E), (XB), (LEN)); \ + for (__i=0; __i < (uint32_t)(LEN); __i++) \ + xb_add_32((E), (XB), (A)[__i]); \ } while (0) -#define xb_add_bitmap(E, XB, B, LEN) xb_add_word_array((E), (XB), (B), (LEN)) +#define xb_add_bitmap(E, XB, B, LEN) xb_add_word_array((E), (XB), (B), (LEN)) /* add a file handle */ #define xb_add_fh(E, XB, FHP, FHLEN) \ do { \ - xb_add_32((E), (XB), (FHLEN)); \ - if (E) break; \ - (E) = xb_add_bytes((XB), (char*)(FHP), (FHLEN), 0); \ + xb_add_32((E), (XB), (FHLEN)); \ + if (E) break; \ + (E) = xb_add_bytes((XB), (char*)(FHP), (FHLEN), 0); \ } while (0) /* add a string */ #define xb_add_string(E, XB, S, LEN) \ do { \ - xb_add_32((E), (XB), (LEN)); \ - if (E) break; \ - (E) = xb_add_bytes((XB), (const char*)(S), (LEN), 0); \ + xb_add_32((E), (XB), (LEN)); \ + if (E) break; \ + (E) = xb_add_bytes((XB), (const char*)(S), (LEN), 0); \ } while (0) @@ -468,46 +491,46 @@ xb_get_bytes(struct xdrbuf *xbp, char *buf, uint32_t count, int nopad) /* skip past data in the buffer */ #define xb_skip(E, XB, LEN) \ do { \ - if (E) break; \ - (E) = xb_advance((XB), (LEN)); \ + if (E) break; \ + (E) = xb_advance((XB), (LEN)); \ } while (0) /* get a 32-bit value */ #define xb_get_32(E, XB, LVAL) \ do { \ - uint32_t __tmp; \ - if (E) break; \ - (E) = xb_get_bytes((XB), (char*)&__tmp, XDRWORD, 0); \ - if (E) break; \ - (LVAL) = fxdr_unsigned(uint32_t, __tmp); \ + uint32_t __tmp; \ + if (E) break; \ + (E) = xb_get_bytes((XB), (char*)&__tmp, XDRWORD, 0); \ + if (E) break; \ + (LVAL) = fxdr_unsigned(uint32_t, __tmp); \ } while (0) /* get a 64-bit value */ #define xb_get_64(E, XB, LVAL) \ do { \ - uint64_t __tmp; \ - if (E) break; \ - (E) = xb_get_bytes((XB), (char*)&__tmp, 2 * XDRWORD, 0); \ - if (E) break; \ - fxdr_hyper(&__tmp, &(LVAL)); \ + uint64_t __tmp; \ + if (E) break; \ + (E) = xb_get_bytes((XB), (char*)&__tmp, 2 * XDRWORD, 0); \ + if (E) break; \ + fxdr_hyper(&__tmp, &(LVAL)); \ } while (0) /* get an array of XDR words (of a given expected/maximum length) */ #define xb_get_word_array(E, XB, A, LEN) \ do { \ - uint32_t __len = 0, __i; \ - xb_get_32((E), (XB), __len); \ - if (E) break; \ - for (__i=0; __i < MIN(__len, (uint32_t)(LEN)); __i++) \ - xb_get_32((E), (XB), (A)[__i]); \ - if (E) break; \ - for (; __i < __len; __i++) \ - xb_skip((E), (XB), XDRWORD); \ - for (; __i < (uint32_t)(LEN); __i++) \ - (A)[__i] = 0; \ - (LEN) = __len; \ + uint32_t __len = 0, __i; \ + xb_get_32((E), (XB), __len); \ + if (E) break; \ + for (__i=0; __i < MIN(__len, (uint32_t)(LEN)); __i++) \ + xb_get_32((E), (XB), (A)[__i]); \ + if (E) break; \ + for (; __i < __len; __i++) \ + xb_skip((E), (XB), XDRWORD); \ + for (; __i < (uint32_t)(LEN); __i++) \ + (A)[__i] = 0; \ + (LEN) = __len; \ } while (0) -#define xb_get_bitmap(E, XB, B, LEN) xb_get_word_array((E), (XB), (B), (LEN)) +#define xb_get_bitmap(E, XB, B, LEN) xb_get_word_array((E), (XB), (B), (LEN)) #endif /* __APPLE_API_PRIVATE */ #endif /* _NFS_XDR_SUBS_H_ */