2 * linux/net/sunrpc/xdr.c
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
9 #include <linux/types.h>
10 #include <linux/socket.h>
11 #include <linux/string.h>
12 #include <linux/kernel.h>
13 #include <linux/pagemap.h>
14 #include <linux/errno.h>
16 #include <linux/net.h>
18 #include <linux/sunrpc/xdr.h>
19 #include <linux/sunrpc/msg_prot.h>
22 * XDR functions for basic NFS types
25 xdr_encode_netobj(u32 *p, const struct xdr_netobj *obj)
27 unsigned int quadlen = XDR_QUADLEN(obj->len);
29 p[quadlen] = 0; /* zero trailing bytes */
30 *p++ = htonl(obj->len);
31 memcpy(p, obj->data, obj->len);
32 return p + XDR_QUADLEN(obj->len);
36 xdr_decode_netobj_fixed(u32 *p, void *obj, unsigned int len)
38 if (ntohl(*p++) != len)
41 return p + XDR_QUADLEN(len);
45 xdr_decode_netobj(u32 *p, struct xdr_netobj *obj)
49 if ((len = ntohl(*p++)) > XDR_MAX_NETOBJ)
53 return p + XDR_QUADLEN(len);
57 * xdr_encode_opaque_fixed - Encode fixed length opaque data
58 * @p - pointer to current position in XDR buffer.
59 * @ptr - pointer to data to encode (or NULL)
60 * @nbytes - size of data.
62 * Copy the array of data of length nbytes at ptr to the XDR buffer
63 * at position p, then align to the next 32-bit boundary by padding
64 * with zero bytes (see RFC1832).
65 * Note: if ptr is NULL, only the padding is performed.
67 * Returns the updated current XDR buffer position
70 u32 *xdr_encode_opaque_fixed(u32 *p, const void *ptr, unsigned int nbytes)
72 if (likely(nbytes != 0)) {
73 unsigned int quadlen = XDR_QUADLEN(nbytes);
74 unsigned int padding = (quadlen << 2) - nbytes;
77 memcpy(p, ptr, nbytes);
79 memset((char *)p + nbytes, 0, padding);
84 EXPORT_SYMBOL(xdr_encode_opaque_fixed);
87 * xdr_encode_opaque - Encode variable length opaque data
88 * @p - pointer to current position in XDR buffer.
89 * @ptr - pointer to data to encode (or NULL)
90 * @nbytes - size of data.
92 * Returns the updated current XDR buffer position
94 u32 *xdr_encode_opaque(u32 *p, const void *ptr, unsigned int nbytes)
97 return xdr_encode_opaque_fixed(p, ptr, nbytes);
99 EXPORT_SYMBOL(xdr_encode_opaque);
102 xdr_encode_string(u32 *p, const char *string)
104 return xdr_encode_array(p, string, strlen(string));
108 xdr_decode_string(u32 *p, char **sp, int *lenp, int maxlen)
113 if ((len = ntohl(*p++)) > maxlen)
117 if ((len % 4) != 0) {
120 string = (char *) (p - 1);
121 memmove(string, p, len);
125 return p + XDR_QUADLEN(len);
129 xdr_decode_string_inplace(u32 *p, char **sp, int *lenp, int maxlen)
133 if ((len = ntohl(*p++)) > maxlen)
137 return p + XDR_QUADLEN(len);
141 xdr_encode_pages(struct xdr_buf *xdr, struct page **pages, unsigned int base,
144 struct kvec *tail = xdr->tail;
148 xdr->page_base = base;
151 p = (u32 *)xdr->head[0].iov_base + XDR_QUADLEN(xdr->head[0].iov_len);
156 unsigned int pad = 4 - (len & 3);
159 tail->iov_base = (char *)p + (len & 3);
168 xdr_inline_pages(struct xdr_buf *xdr, unsigned int offset,
169 struct page **pages, unsigned int base, unsigned int len)
171 struct kvec *head = xdr->head;
172 struct kvec *tail = xdr->tail;
173 char *buf = (char *)head->iov_base;
174 unsigned int buflen = head->iov_len;
176 head->iov_len = offset;
179 xdr->page_base = base;
182 tail->iov_base = buf + offset;
183 tail->iov_len = buflen - offset;
189 * Realign the kvec if the server missed out some reply elements
190 * (such as post-op attributes,...)
191 * Note: This is a simple implementation that assumes that
192 * len <= iov->iov_len !!!
193 * The RPC header (assumed to be the 1st element in the iov array)
196 void xdr_shift_iovec(struct kvec *iov, int nr, size_t len)
200 for (pvec = iov + nr - 1; nr > 1; nr--, pvec--) {
201 struct kvec *svec = pvec - 1;
203 if (len > pvec->iov_len) {
204 printk(KERN_DEBUG "RPC: Urk! Large shift of short iovec.\n");
207 memmove((char *)pvec->iov_base + len, pvec->iov_base,
208 pvec->iov_len - len);
210 if (len > svec->iov_len) {
211 printk(KERN_DEBUG "RPC: Urk! Large shift of short iovec.\n");
214 memcpy(pvec->iov_base,
215 (char *)svec->iov_base + svec->iov_len - len, len);
220 * Map a struct xdr_buf into an kvec array.
222 int xdr_kmap(struct kvec *iov_base, struct xdr_buf *xdr, size_t base)
224 struct kvec *iov = iov_base;
225 struct page **ppage = xdr->pages;
226 unsigned int len, pglen = xdr->page_len;
228 len = xdr->head[0].iov_len;
230 iov->iov_len = len - base;
231 iov->iov_base = (char *)xdr->head[0].iov_base + base;
243 if (base || xdr->page_base) {
245 base += xdr->page_base;
246 ppage += base >> PAGE_CACHE_SHIFT;
247 base &= ~PAGE_CACHE_MASK;
250 len = PAGE_CACHE_SIZE;
251 iov->iov_base = kmap(*ppage);
253 iov->iov_base += base;
262 } while ((pglen -= len) != 0);
264 if (xdr->tail[0].iov_len) {
265 iov->iov_len = xdr->tail[0].iov_len - base;
266 iov->iov_base = (char *)xdr->tail[0].iov_base + base;
269 return (iov - iov_base);
272 void xdr_kunmap(struct xdr_buf *xdr, size_t base)
274 struct page **ppage = xdr->pages;
275 unsigned int pglen = xdr->page_len;
279 if (base > xdr->head[0].iov_len)
280 base -= xdr->head[0].iov_len;
286 if (base || xdr->page_base) {
288 base += xdr->page_base;
289 ppage += base >> PAGE_CACHE_SHIFT;
290 /* Note: The offset means that the length of the first
291 * page is really (PAGE_CACHE_SIZE - (base & ~PAGE_CACHE_MASK)).
292 * In order to avoid an extra test inside the loop,
293 * we bump pglen here, and just subtract PAGE_CACHE_SIZE... */
294 pglen += base & ~PAGE_CACHE_MASK;
297 flush_dcache_page(*ppage);
299 if (pglen <= PAGE_CACHE_SIZE)
301 pglen -= PAGE_CACHE_SIZE;
307 xdr_partial_copy_from_skb(struct xdr_buf *xdr, unsigned int base,
309 skb_read_actor_t copy_actor)
311 struct page **ppage = xdr->pages;
312 unsigned int len, pglen = xdr->page_len;
315 len = xdr->head[0].iov_len;
318 ret = copy_actor(desc, (char *)xdr->head[0].iov_base + base, len);
319 if (ret != len || !desc->count)
331 if (base || xdr->page_base) {
333 base += xdr->page_base;
334 ppage += base >> PAGE_CACHE_SHIFT;
335 base &= ~PAGE_CACHE_MASK;
340 len = PAGE_CACHE_SIZE;
341 kaddr = kmap_atomic(*ppage, KM_SKB_SUNRPC_DATA);
346 ret = copy_actor(desc, kaddr + base, len);
351 ret = copy_actor(desc, kaddr, len);
353 flush_dcache_page(*ppage);
354 kunmap_atomic(kaddr, KM_SKB_SUNRPC_DATA);
355 if (ret != len || !desc->count)
358 } while ((pglen -= len) != 0);
360 len = xdr->tail[0].iov_len;
362 copy_actor(desc, (char *)xdr->tail[0].iov_base + base, len - base);
367 xdr_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen,
368 struct xdr_buf *xdr, unsigned int base, int msgflags)
370 struct page **ppage = xdr->pages;
371 unsigned int len, pglen = xdr->page_len;
373 ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
375 len = xdr->head[0].iov_len;
376 if (base < len || (addr != NULL && base == 0)) {
378 .iov_base = xdr->head[0].iov_base + base,
379 .iov_len = len - base,
381 struct msghdr msg = {
383 .msg_namelen = addrlen,
384 .msg_flags = msgflags,
387 msg.msg_flags |= MSG_MORE;
389 if (iov.iov_len != 0)
390 err = kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len);
392 err = kernel_sendmsg(sock, &msg, NULL, 0, 0);
397 if (err != iov.iov_len)
409 if (base || xdr->page_base) {
411 base += xdr->page_base;
412 ppage += base >> PAGE_CACHE_SHIFT;
413 base &= ~PAGE_CACHE_MASK;
416 sendpage = sock->ops->sendpage ? : sock_no_sendpage;
418 int flags = msgflags;
420 len = PAGE_CACHE_SIZE;
426 if (pglen != len || xdr->tail[0].iov_len != 0)
429 /* Hmm... We might be dealing with highmem pages */
430 if (PageHighMem(*ppage))
431 sendpage = sock_no_sendpage;
432 err = sendpage(sock, *ppage, base, len, flags);
441 } while ((pglen -= len) != 0);
443 len = xdr->tail[0].iov_len;
446 .iov_base = xdr->tail[0].iov_base + base,
447 .iov_len = len - base,
449 struct msghdr msg = {
450 .msg_flags = msgflags,
452 err = kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len);
464 * Helper routines for doing 'memmove' like operations on a struct xdr_buf
466 * _shift_data_right_pages
467 * @pages: vector of pages containing both the source and dest memory area.
468 * @pgto_base: page vector address of destination
469 * @pgfrom_base: page vector address of source
470 * @len: number of bytes to copy
472 * Note: the addresses pgto_base and pgfrom_base are both calculated in
474 * if a memory area starts at byte 'base' in page 'pages[i]',
475 * then its address is given as (i << PAGE_CACHE_SHIFT) + base
476 * Also note: pgfrom_base must be < pgto_base, but the memory areas
477 * they point to may overlap.
480 _shift_data_right_pages(struct page **pages, size_t pgto_base,
481 size_t pgfrom_base, size_t len)
483 struct page **pgfrom, **pgto;
487 BUG_ON(pgto_base <= pgfrom_base);
492 pgto = pages + (pgto_base >> PAGE_CACHE_SHIFT);
493 pgfrom = pages + (pgfrom_base >> PAGE_CACHE_SHIFT);
495 pgto_base &= ~PAGE_CACHE_MASK;
496 pgfrom_base &= ~PAGE_CACHE_MASK;
499 /* Are any pointers crossing a page boundary? */
500 if (pgto_base == 0) {
501 pgto_base = PAGE_CACHE_SIZE;
504 if (pgfrom_base == 0) {
505 pgfrom_base = PAGE_CACHE_SIZE;
510 if (copy > pgto_base)
512 if (copy > pgfrom_base)
517 vto = kmap_atomic(*pgto, KM_USER0);
518 vfrom = kmap_atomic(*pgfrom, KM_USER1);
519 memmove(vto + pgto_base, vfrom + pgfrom_base, copy);
520 kunmap_atomic(vfrom, KM_USER1);
521 kunmap_atomic(vto, KM_USER0);
523 } while ((len -= copy) != 0);
528 * @pages: array of pages
529 * @pgbase: page vector address of destination
530 * @p: pointer to source data
533 * Copies data from an arbitrary memory location into an array of pages
534 * The copy is assumed to be non-overlapping.
537 _copy_to_pages(struct page **pages, size_t pgbase, const char *p, size_t len)
543 pgto = pages + (pgbase >> PAGE_CACHE_SHIFT);
544 pgbase &= ~PAGE_CACHE_MASK;
547 copy = PAGE_CACHE_SIZE - pgbase;
551 vto = kmap_atomic(*pgto, KM_USER0);
552 memcpy(vto + pgbase, p, copy);
553 kunmap_atomic(vto, KM_USER0);
556 if (pgbase == PAGE_CACHE_SIZE) {
562 } while ((len -= copy) != 0);
567 * @p: pointer to destination
568 * @pages: array of pages
569 * @pgbase: offset of source data
572 * Copies data into an arbitrary memory location from an array of pages
573 * The copy is assumed to be non-overlapping.
576 _copy_from_pages(char *p, struct page **pages, size_t pgbase, size_t len)
578 struct page **pgfrom;
582 pgfrom = pages + (pgbase >> PAGE_CACHE_SHIFT);
583 pgbase &= ~PAGE_CACHE_MASK;
586 copy = PAGE_CACHE_SIZE - pgbase;
590 vfrom = kmap_atomic(*pgfrom, KM_USER0);
591 memcpy(p, vfrom + pgbase, copy);
592 kunmap_atomic(vfrom, KM_USER0);
595 if (pgbase == PAGE_CACHE_SIZE) {
601 } while ((len -= copy) != 0);
607 * @len: bytes to remove from buf->head[0]
609 * Shrinks XDR buffer's header kvec buf->head[0] by
610 * 'len' bytes. The extra data is not lost, but is instead
611 * moved into the inlined pages and/or the tail.
614 xdr_shrink_bufhead(struct xdr_buf *buf, size_t len)
616 struct kvec *head, *tail;
618 unsigned int pglen = buf->page_len;
622 BUG_ON (len > head->iov_len);
624 /* Shift the tail first */
625 if (tail->iov_len != 0) {
626 if (tail->iov_len > len) {
627 copy = tail->iov_len - len;
628 memmove((char *)tail->iov_base + len,
629 tail->iov_base, copy);
631 /* Copy from the inlined pages into the tail */
636 if (offs >= tail->iov_len)
638 else if (copy > tail->iov_len - offs)
639 copy = tail->iov_len - offs;
641 _copy_from_pages((char *)tail->iov_base + offs,
643 buf->page_base + pglen + offs - len,
645 /* Do we also need to copy data from the head into the tail ? */
647 offs = copy = len - pglen;
648 if (copy > tail->iov_len)
649 copy = tail->iov_len;
650 memcpy(tail->iov_base,
651 (char *)head->iov_base +
652 head->iov_len - offs,
656 /* Now handle pages */
659 _shift_data_right_pages(buf->pages,
660 buf->page_base + len,
666 _copy_to_pages(buf->pages, buf->page_base,
667 (char *)head->iov_base + head->iov_len - len,
670 head->iov_len -= len;
672 /* Have we truncated the message? */
673 if (buf->len > buf->buflen)
674 buf->len = buf->buflen;
680 * @len: bytes to remove from buf->pages
682 * Shrinks XDR buffer's page array buf->pages by
683 * 'len' bytes. The extra data is not lost, but is instead
684 * moved into the tail.
687 xdr_shrink_pagelen(struct xdr_buf *buf, size_t len)
692 unsigned int pglen = buf->page_len;
695 BUG_ON (len > pglen);
697 /* Shift the tail first */
698 if (tail->iov_len != 0) {
699 p = (char *)tail->iov_base + len;
700 if (tail->iov_len > len) {
701 copy = tail->iov_len - len;
702 memmove(p, tail->iov_base, copy);
705 /* Copy from the inlined pages into the tail */
707 if (copy > tail->iov_len)
708 copy = tail->iov_len;
709 _copy_from_pages((char *)tail->iov_base,
710 buf->pages, buf->page_base + pglen - len,
713 buf->page_len -= len;
715 /* Have we truncated the message? */
716 if (buf->len > buf->buflen)
717 buf->len = buf->buflen;
721 xdr_shift_buf(struct xdr_buf *buf, size_t len)
723 xdr_shrink_bufhead(buf, len);
727 * xdr_init_encode - Initialize a struct xdr_stream for sending data.
728 * @xdr: pointer to xdr_stream struct
729 * @buf: pointer to XDR buffer in which to encode data
730 * @p: current pointer inside XDR buffer
732 * Note: at the moment the RPC client only passes the length of our
733 * scratch buffer in the xdr_buf's header kvec. Previously this
734 * meant we needed to call xdr_adjust_iovec() after encoding the
735 * data. With the new scheme, the xdr_stream manages the details
736 * of the buffer length, and takes care of adjusting the kvec
739 void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, uint32_t *p)
741 struct kvec *iov = buf->head;
745 xdr->end = (uint32_t *)((char *)iov->iov_base + iov->iov_len);
746 buf->len = iov->iov_len = (char *)p - (char *)iov->iov_base;
749 EXPORT_SYMBOL(xdr_init_encode);
752 * xdr_reserve_space - Reserve buffer space for sending
753 * @xdr: pointer to xdr_stream
754 * @nbytes: number of bytes to reserve
756 * Checks that we have enough buffer space to encode 'nbytes' more
757 * bytes of data. If so, update the total xdr_buf length, and
758 * adjust the length of the current kvec.
760 uint32_t * xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes)
762 uint32_t *p = xdr->p;
765 /* align nbytes on the next 32-bit boundary */
768 q = p + (nbytes >> 2);
769 if (unlikely(q > xdr->end || q < p))
772 xdr->iov->iov_len += nbytes;
773 xdr->buf->len += nbytes;
776 EXPORT_SYMBOL(xdr_reserve_space);
779 * xdr_write_pages - Insert a list of pages into an XDR buffer for sending
780 * @xdr: pointer to xdr_stream
781 * @pages: list of pages
782 * @base: offset of first byte
783 * @len: length of data in bytes
786 void xdr_write_pages(struct xdr_stream *xdr, struct page **pages, unsigned int base,
789 struct xdr_buf *buf = xdr->buf;
790 struct kvec *iov = buf->tail;
792 buf->page_base = base;
795 iov->iov_base = (char *)xdr->p;
800 unsigned int pad = 4 - (len & 3);
802 BUG_ON(xdr->p >= xdr->end);
803 iov->iov_base = (char *)xdr->p + (len & 3);
811 EXPORT_SYMBOL(xdr_write_pages);
814 * xdr_init_decode - Initialize an xdr_stream for decoding data.
815 * @xdr: pointer to xdr_stream struct
816 * @buf: pointer to XDR buffer from which to decode data
817 * @p: current pointer inside XDR buffer
819 void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, uint32_t *p)
821 struct kvec *iov = buf->head;
822 unsigned int len = iov->iov_len;
829 xdr->end = (uint32_t *)((char *)iov->iov_base + len);
831 EXPORT_SYMBOL(xdr_init_decode);
834 * xdr_inline_decode - Retrieve non-page XDR data to decode
835 * @xdr: pointer to xdr_stream struct
836 * @nbytes: number of bytes of data to decode
838 * Check if the input buffer is long enough to enable us to decode
839 * 'nbytes' more bytes of data starting at the current position.
840 * If so return the current pointer, then update the current
843 uint32_t * xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes)
845 uint32_t *p = xdr->p;
846 uint32_t *q = p + XDR_QUADLEN(nbytes);
848 if (unlikely(q > xdr->end || q < p))
853 EXPORT_SYMBOL(xdr_inline_decode);
856 * xdr_read_pages - Ensure page-based XDR data to decode is aligned at current pointer position
857 * @xdr: pointer to xdr_stream struct
858 * @len: number of bytes of page data
860 * Moves data beyond the current pointer position from the XDR head[] buffer
861 * into the page list. Any data that lies beyond current position + "len"
862 * bytes is moved into the XDR tail[]. The current pointer is then
863 * repositioned at the beginning of the XDR tail.
865 void xdr_read_pages(struct xdr_stream *xdr, unsigned int len)
867 struct xdr_buf *buf = xdr->buf;
873 /* Realign pages to current pointer position */
875 shift = iov->iov_len + (char *)iov->iov_base - (char *)xdr->p;
877 xdr_shrink_bufhead(buf, shift);
879 /* Truncate page data and move it into the tail */
880 if (buf->page_len > len)
881 xdr_shrink_pagelen(buf, buf->page_len - len);
882 padding = (XDR_QUADLEN(len) << 2) - len;
883 xdr->iov = iov = buf->tail;
884 /* Compute remaining message length. */
886 shift = buf->buflen - buf->len;
892 * Position current pointer at beginning of tail, and
893 * set remaining message length.
895 xdr->p = (uint32_t *)((char *)iov->iov_base + padding);
896 xdr->end = (uint32_t *)((char *)iov->iov_base + end);
898 EXPORT_SYMBOL(xdr_read_pages);
900 static struct kvec empty_iov = {.iov_base = NULL, .iov_len = 0};
903 xdr_buf_from_iov(struct kvec *iov, struct xdr_buf *buf)
906 buf->tail[0] = empty_iov;
908 buf->buflen = buf->len = iov->iov_len;
911 /* Sets subiov to the intersection of iov with the buffer of length len
912 * starting base bytes after iov. Indicates empty intersection by setting
913 * length of subiov to zero. Decrements len by length of subiov, sets base
914 * to zero (or decrements it by length of iov if subiov is empty). */
916 iov_subsegment(struct kvec *iov, struct kvec *subiov, int *base, int *len)
918 if (*base > iov->iov_len) {
919 subiov->iov_base = NULL;
921 *base -= iov->iov_len;
923 subiov->iov_base = iov->iov_base + *base;
924 subiov->iov_len = min(*len, (int)iov->iov_len - *base);
927 *len -= subiov->iov_len;
930 /* Sets subbuf to the portion of buf of length len beginning base bytes
931 * from the start of buf. Returns -1 if base of length are out of bounds. */
933 xdr_buf_subsegment(struct xdr_buf *buf, struct xdr_buf *subbuf,
938 subbuf->buflen = subbuf->len = len;
939 iov_subsegment(buf->head, subbuf->head, &base, &len);
941 if (base < buf->page_len) {
942 i = (base + buf->page_base) >> PAGE_CACHE_SHIFT;
943 subbuf->pages = &buf->pages[i];
944 subbuf->page_base = (base + buf->page_base) & ~PAGE_CACHE_MASK;
945 subbuf->page_len = min((int)buf->page_len - base, len);
946 len -= subbuf->page_len;
949 base -= buf->page_len;
950 subbuf->page_len = 0;
953 iov_subsegment(buf->tail, subbuf->tail, &base, &len);
959 /* obj is assumed to point to allocated memory of size at least len: */
961 read_bytes_from_xdr_buf(struct xdr_buf *buf, int base, void *obj, int len)
963 struct xdr_buf subbuf;
967 status = xdr_buf_subsegment(buf, &subbuf, base, len);
970 this_len = min(len, (int)subbuf.head[0].iov_len);
971 memcpy(obj, subbuf.head[0].iov_base, this_len);
974 this_len = min(len, (int)subbuf.page_len);
976 _copy_from_pages(obj, subbuf.pages, subbuf.page_base, this_len);
979 this_len = min(len, (int)subbuf.tail[0].iov_len);
980 memcpy(obj, subbuf.tail[0].iov_base, this_len);
986 read_u32_from_xdr_buf(struct xdr_buf *buf, int base, u32 *obj)
991 status = read_bytes_from_xdr_buf(buf, base, &raw, sizeof(*obj));
998 /* If the netobj starting offset bytes from the start of xdr_buf is contained
999 * entirely in the head or the tail, set object to point to it; otherwise
1000 * try to find space for it at the end of the tail, copy it there, and
1001 * set obj to point to it. */
1003 xdr_buf_read_netobj(struct xdr_buf *buf, struct xdr_netobj *obj, int offset)
1005 u32 tail_offset = buf->head[0].iov_len + buf->page_len;
1008 if (read_u32_from_xdr_buf(buf, offset, &obj->len))
1010 obj_end_offset = offset + 4 + obj->len;
1012 if (obj_end_offset <= buf->head[0].iov_len) {
1013 /* The obj is contained entirely in the head: */
1014 obj->data = buf->head[0].iov_base + offset + 4;
1015 } else if (offset + 4 >= tail_offset) {
1016 if (obj_end_offset - tail_offset
1017 > buf->tail[0].iov_len)
1019 /* The obj is contained entirely in the tail: */
1020 obj->data = buf->tail[0].iov_base
1021 + offset - tail_offset + 4;
1023 /* use end of tail as storage for obj:
1024 * (We don't copy to the beginning because then we'd have
1025 * to worry about doing a potentially overlapping copy.
1026 * This assumes the object is at most half the length of the
1028 if (obj->len > buf->tail[0].iov_len)
1030 obj->data = buf->tail[0].iov_base + buf->tail[0].iov_len -
1032 if (read_bytes_from_xdr_buf(buf, offset + 4,
1033 obj->data, obj->len))