/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <rpc/xdr.h>
#include <rpcsvc/nfs4_prot.h>
#include <nfs/nfs4.h>
#include "../../../cmd/fs.d/nfs/lib/ref_subr.h"
char *
xdr2path(char *xdrpath, int size)
{
XDR xdrs;
pathname4 pathname;
char *buf, *path;
int i;
uint_t len;
xdrmem_create(&xdrs, xdrpath, size, XDR_DECODE);
bzero(&pathname, sizeof (pathname4));
if (!xdr_pathname4(&xdrs, &pathname))
return (NULL);
buf = calloc(size, 1);
for (i = 0; i < pathname.pathname4_len; i++) {
path = utf8_to_str(&pathname.pathname4_val[i], &len, NULL);
if (path == NULL)
continue;
(void) strcat(buf, "/");
(void) strcat(buf, path);
free(path);
}
xdr_free(xdr_pathname4, (char *)&pathname);
xdr_destroy(&xdrs);
return (buf);
}
int
path2xdr(char *path, char **xdrbuf)
{
XDR xdrs;
pathname4 pathname;
char *buf;
int size;
(void) make_pathname4(path, &pathname);
size = xdr_sizeof(xdr_pathname4, &pathname);
buf = malloc(size);
if (buf == NULL)
return (0);
xdrmem_create(&xdrs, buf, size, XDR_ENCODE);
if (!xdr_pathname4(&xdrs, &pathname))
return (0);
*xdrbuf = buf;
xdr_destroy(&xdrs);
return (size);
}