1 /* Blue Sky: File Systems in the Cloud
3 * Copyright (C) 2010 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
9 /* Common RPC code shared between the BlueSky server and test client code. */
11 #include "mount_prot.h"
12 #include "nfs3_prot.h"
15 #include <rpc/pmap_clnt.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <netinet/ip.h>
25 /* Routines for XDR-encoding to a growable string. */
26 static bool_t xdr_string_putlong(XDR *xdrs, const long *lp)
28 GString *str = (GString *)xdrs->x_private;
29 uint32_t data = htonl(*lp);
30 g_string_set_size(str, str->len + 4);
31 memcpy(str->str + str->len - 4, &data, 4);
35 static bool_t xdr_string_putbytes(XDR *xdrs, const char *addr, u_int len)
37 GString *str = (GString *)xdrs->x_private;
38 g_string_set_size(str, str->len + len);
39 memcpy(str->str + str->len - len, addr, len);
43 static u_int xdr_string_getpos(const XDR *xdrs)
45 GString *str = (GString *)xdrs->x_private;
49 static bool_t xdr_string_putint32(XDR *xdrs, const int32_t *ip)
51 GString *str = (GString *)xdrs->x_private;
52 uint32_t data = htonl(*ip);
53 g_string_set_size(str, str->len + 4);
54 memcpy(str->str + str->len - 4, &data, 4);
58 static int32_t *xdr_string_inline(XDR *xdrs, u_int len)
60 GString *str = (GString *)xdrs->x_private;
61 g_string_set_size(str, str->len + len);
62 return (int32_t *)(str->str + str->len - len);
65 static void xdr_string_destroy(XDR *xdrs)
69 static struct xdr_ops xdr_string_ops = {
70 .x_putlong = xdr_string_putlong,
71 .x_putbytes = xdr_string_putbytes,
72 .x_getpostn = xdr_string_getpos,
73 .x_putint32 = xdr_string_putint32,
74 .x_inline = xdr_string_inline,
75 .x_destroy = xdr_string_destroy,
78 void xdr_string_create(XDR *xdrs, GString *string, enum xdr_op op)
81 xdrs->x_ops = &xdr_string_ops;
82 xdrs->x_private = (char *)string;