[PATCH 4/11] sunrpc-xdr-words

From: Andreas Gruenbacher
Date: Mon Apr 26 2004 - 05:40:12 EST


Encode 32-bit words in xdr_buf's

Andreas Gruenbacher <agruen@xxxxxxx>, SUSE Labs

Index: linux-2.6.6-rc2/include/linux/sunrpc/xdr.h
===================================================================
--- linux-2.6.6-rc2.orig/include/linux/sunrpc/xdr.h 2004-04-20 23:30:31.000000000 +0200
+++ linux-2.6.6-rc2/include/linux/sunrpc/xdr.h 2004-04-24 22:07:00.013155968 +0200
@@ -153,6 +153,9 @@
extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, int, int);
extern int xdr_buf_read_netobj(struct xdr_buf *, struct xdr_netobj *, int);
extern int read_bytes_from_xdr_buf(struct xdr_buf *buf, int base, void *obj, int len);
+extern int read_u32_from_xdr_buf(struct xdr_buf *, int, u32 *);
+extern int write_bytes_to_xdr_buf(struct xdr_buf *, int, void *, int);
+extern int write_u32_to_xdr_buf(struct xdr_buf *, int, u32);

/*
* Helper structure for copying from an sk_buff.
Index: linux-2.6.6-rc2/net/sunrpc/sunrpc_syms.c
===================================================================
--- linux-2.6.6-rc2.orig/net/sunrpc/sunrpc_syms.c 2004-04-20 23:30:00.000000000 +0200
+++ linux-2.6.6-rc2/net/sunrpc/sunrpc_syms.c 2004-04-24 22:07:00.010156424 +0200
@@ -132,6 +132,9 @@
EXPORT_SYMBOL(xdr_buf_subsegment);
EXPORT_SYMBOL(xdr_buf_read_netobj);
EXPORT_SYMBOL(read_bytes_from_xdr_buf);
+EXPORT_SYMBOL(read_u32_from_xdr_buf);
+EXPORT_SYMBOL(write_bytes_to_xdr_buf);
+EXPORT_SYMBOL(write_u32_to_xdr_buf);

/* Debugging symbols */
#ifdef RPC_DEBUG
Index: linux-2.6.6-rc2/net/sunrpc/xdr.c
===================================================================
--- linux-2.6.6-rc2.orig/net/sunrpc/xdr.c 2004-04-20 23:29:43.000000000 +0200
+++ linux-2.6.6-rc2/net/sunrpc/xdr.c 2004-04-24 22:08:19.476075768 +0200
@@ -990,7 +990,7 @@
return status;
}

-static int
+int
read_u32_from_xdr_buf(struct xdr_buf *buf, int base, u32 *obj)
{
u32 raw;
@@ -1003,6 +1003,41 @@
return 0;
}

+/* obj is assumed to point to allocated memory of size at least len: */
+int
+write_bytes_to_xdr_buf(struct xdr_buf *buf, int base, void *obj, int len)
+{
+ struct xdr_buf subbuf;
+ int this_len;
+ int status;
+
+ status = xdr_buf_subsegment(buf, &subbuf, base, len);
+ if (status)
+ goto out;
+ this_len = min(len, (int)subbuf.head[0].iov_len);
+ memcpy(subbuf.head[0].iov_base, obj, this_len);
+ len -= this_len;
+ obj += this_len;
+ this_len = min(len, (int)subbuf.page_len);
+ if (this_len)
+ _copy_to_pages(subbuf.pages, subbuf.page_base, obj, this_len);
+ len -= this_len;
+ obj += this_len;
+ this_len = min(len, (int)subbuf.tail[0].iov_len);
+ memcpy(subbuf.tail[0].iov_base, obj, this_len);
+out:
+ return status;
+}
+
+int
+write_u32_to_xdr_buf(struct xdr_buf *buf, int base, u32 obj)
+{
+ int status;
+
+ obj = htonl(obj);
+ return write_bytes_to_xdr_buf(buf, base, &obj, sizeof(obj));
+}
+
/* If the netobj starting offset bytes from the start of xdr_buf is contained
* entirely in the head or the tail, set object to point to it; otherwise
* try to find space for it at the end of the tail, copy it there, and


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/