17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*4a634bb8Sga159272 * Common Development and Distribution License (the "License").
6*4a634bb8Sga159272 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*4a634bb8Sga159272 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate *
257c478bd9Sstevel@tonic-gate * Simple nfs V4 ops
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <rpc/types.h>
317c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
337c478bd9Sstevel@tonic-gate #include "clnt.h"
347c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
357c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <sys/promif.h>
387c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
397c478bd9Sstevel@tonic-gate #include "nfs_inet.h"
407c478bd9Sstevel@tonic-gate #include <sys/stat.h>
417c478bd9Sstevel@tonic-gate #include <sys/bootvfs.h>
427c478bd9Sstevel@tonic-gate #include <sys/bootdebug.h>
437c478bd9Sstevel@tonic-gate #include <sys/salib.h>
447c478bd9Sstevel@tonic-gate #include <sys/sacache.h>
457c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
467c478bd9Sstevel@tonic-gate #include "brpc.h"
477c478bd9Sstevel@tonic-gate #include <rpcsvc/nfs4_prot.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #define dprintf if (boothowto & RB_DEBUG) printf
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static struct timeval zero_timeout = {0, 0}; /* default */
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate * NFS Version 4 specific functions
557c478bd9Sstevel@tonic-gate */
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate ssize_t
nfs4read(struct nfs_file * filep,char * buf,size_t size)587c478bd9Sstevel@tonic-gate nfs4read(struct nfs_file *filep, char *buf, size_t size)
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate enum clnt_stat status;
617c478bd9Sstevel@tonic-gate read4arg_t readargs;
627c478bd9Sstevel@tonic-gate read4res_t readres;
637c478bd9Sstevel@tonic-gate char *buf_offset;
647c478bd9Sstevel@tonic-gate uint_t count = 0;
657c478bd9Sstevel@tonic-gate uint_t readcnt = 0;
667c478bd9Sstevel@tonic-gate bool_t done = FALSE;
677c478bd9Sstevel@tonic-gate struct timeval timeout;
687c478bd9Sstevel@tonic-gate int framing_errs = 0;
697c478bd9Sstevel@tonic-gate static uint_t pos;
707c478bd9Sstevel@tonic-gate static char ind[] = "|/-\\";
717c478bd9Sstevel@tonic-gate static int blks_read;
727c478bd9Sstevel@tonic-gate utf8string str;
737c478bd9Sstevel@tonic-gate char tagname[] = "inetboot read";
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate bzero(&readres, sizeof (readres));
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate str.utf8string_len = sizeof (tagname) - 1;
787c478bd9Sstevel@tonic-gate str.utf8string_val = tagname;
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate * read
827c478bd9Sstevel@tonic-gate */
837c478bd9Sstevel@tonic-gate buf_offset = buf;
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate if (nfs_readsize == 0)
867c478bd9Sstevel@tonic-gate nfs_readsize = READ4_SIZE;
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate if (size < nfs_readsize)
897c478bd9Sstevel@tonic-gate readargs.r_count = size;
907c478bd9Sstevel@tonic-gate else
917c478bd9Sstevel@tonic-gate readargs.r_count = nfs_readsize;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate if (filep->fh.fh4.len > 0)
947c478bd9Sstevel@tonic-gate compound_init(&readargs.r_arg, &str, 0, 2, &filep->fh.fh4);
957c478bd9Sstevel@tonic-gate else
967c478bd9Sstevel@tonic-gate compound_init(&readargs.r_arg, &str, 0, 2, NULL);
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate readargs.r_opread = OP_READ;
997c478bd9Sstevel@tonic-gate /*
1007c478bd9Sstevel@tonic-gate * zero out the stateid field
1017c478bd9Sstevel@tonic-gate */
1027c478bd9Sstevel@tonic-gate bzero(&readargs.r_stateid, sizeof (readargs.r_stateid));
1037c478bd9Sstevel@tonic-gate readargs.r_offset = filep->offset;
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate do {
1067c478bd9Sstevel@tonic-gate readres.r_data_val = buf_offset;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate if ((count + readargs.r_count) > size)
1097c478bd9Sstevel@tonic-gate readargs.r_count = size - count;
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate timeout.tv_sec = NFS_REXMIT_MIN;
1127c478bd9Sstevel@tonic-gate timeout.tv_usec = 0;
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate do {
1157c478bd9Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC4_COMPOUND,
1167c478bd9Sstevel@tonic-gate xdr_read4_args, (caddr_t)&readargs,
1177c478bd9Sstevel@tonic-gate xdr_read4_res, (caddr_t)&readres,
1187c478bd9Sstevel@tonic-gate timeout);
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate if (status == RPC_TIMEDOUT) {
1217c478bd9Sstevel@tonic-gate dprintf("NFS read(%d) timed out. Retrying...\n", readargs.r_count);
1227c478bd9Sstevel@tonic-gate if (errno == ETIMEDOUT)
1237c478bd9Sstevel@tonic-gate framing_errs++;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate if (framing_errs > NFS_MAX_FERRS &&
1267c478bd9Sstevel@tonic-gate readargs.r_count > NFS_READ_DECR) {
1277c478bd9Sstevel@tonic-gate readargs.r_count /= 2;
1287c478bd9Sstevel@tonic-gate nfs_readsize /= 2;
1297c478bd9Sstevel@tonic-gate dprintf("NFS read size now %d.\n",
1307c478bd9Sstevel@tonic-gate nfs_readsize);
1317c478bd9Sstevel@tonic-gate timeout.tv_sec = NFS_REXMIT_MIN;
1327c478bd9Sstevel@tonic-gate framing_errs = 0;
1337c478bd9Sstevel@tonic-gate } else {
1347c478bd9Sstevel@tonic-gate if (timeout.tv_sec < NFS_REXMIT_MAX)
1357c478bd9Sstevel@tonic-gate timeout.tv_sec++;
1367c478bd9Sstevel@tonic-gate else
1377c478bd9Sstevel@tonic-gate timeout.tv_sec = 0;
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate } while (status == RPC_TIMEDOUT);
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate if (status != RPC_SUCCESS)
1437c478bd9Sstevel@tonic-gate return (-1);
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate if (readres.r_status != NFS4_OK) {
1467c478bd9Sstevel@tonic-gate nfs4_error(readres.r_status);
1477c478bd9Sstevel@tonic-gate return (-1);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate readcnt = readres.r_data_len;
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate if (readres.r_eof == TRUE)
1537c478bd9Sstevel@tonic-gate done = TRUE;
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate if (readcnt < readargs.r_count) {
1567c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
1577c478bd9Sstevel@tonic-gate if ((boothowto & DBFLAGS) == DBFLAGS)
158*4a634bb8Sga159272 printf("nfs4read: partial read %d instead "
159*4a634bb8Sga159272 "of %d\n", readcnt, readargs.count);
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate done = TRUE;
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate count += readcnt;
1657c478bd9Sstevel@tonic-gate filep->offset += readcnt;
1667c478bd9Sstevel@tonic-gate buf_offset += readcnt;
1677c478bd9Sstevel@tonic-gate readargs.r_offset += readcnt;
1687c478bd9Sstevel@tonic-gate if ((blks_read++ & 0x3) == 0)
1697c478bd9Sstevel@tonic-gate printf("%c\b", ind[pos++ & 3]);
1707c478bd9Sstevel@tonic-gate } while (count < size && !done);
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate return (count);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate static vtype_t nf4_to_vt[] = {
1777c478bd9Sstevel@tonic-gate VBAD, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO
1787c478bd9Sstevel@tonic-gate };
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate int
nfs4getattr(struct nfs_file * nfp,struct vattr * vap)1817c478bd9Sstevel@tonic-gate nfs4getattr(struct nfs_file *nfp, struct vattr *vap)
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate enum clnt_stat status;
1847c478bd9Sstevel@tonic-gate attr4_bitmap1_t bitmap1;
1857c478bd9Sstevel@tonic-gate attr4_bitmap2_t bitmap2;
1867c478bd9Sstevel@tonic-gate getattr4arg_t getattrargs;
1877c478bd9Sstevel@tonic-gate getattr4res_t getattrres;
1887c478bd9Sstevel@tonic-gate b_fattr4_t *bfattr4;
1897c478bd9Sstevel@tonic-gate utf8string str;
1907c478bd9Sstevel@tonic-gate char tagname[] = "inetboot getattr";
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate bzero(&getattrres, sizeof (getattrres));
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate * Putfh
1957c478bd9Sstevel@tonic-gate */
1967c478bd9Sstevel@tonic-gate str.utf8string_len = sizeof (tagname) - 1;
1977c478bd9Sstevel@tonic-gate str.utf8string_val = tagname;
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate if (nfp->fh.fh4.len > 0)
2007c478bd9Sstevel@tonic-gate compound_init(&getattrargs.ga_arg, &str, 0, 2, &nfp->fh.fh4);
2017c478bd9Sstevel@tonic-gate else
2027c478bd9Sstevel@tonic-gate compound_init(&getattrargs.ga_arg, &str, 0, 2, NULL);
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * getattr
2067c478bd9Sstevel@tonic-gate */
2077c478bd9Sstevel@tonic-gate getattrargs.ga_opgetattr = OP_GETATTR;
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate * Set up the attribute bitmap. We pretty much need everything
2107c478bd9Sstevel@tonic-gate * except for the filehandle and supported attrs.
2117c478bd9Sstevel@tonic-gate */
2127c478bd9Sstevel@tonic-gate bitmap1.word = 0;
2137c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_type = 1;
2147c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_size = 1;
2157c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_fileid = 1;
2167c478bd9Sstevel@tonic-gate bitmap2.word = 0;
2177c478bd9Sstevel@tonic-gate bitmap2.bm_fattr4_mode = 1;
2187c478bd9Sstevel@tonic-gate bitmap2.bm_fattr4_time_access = 1;
2197c478bd9Sstevel@tonic-gate bitmap2.bm_fattr4_time_metadata = 1;
2207c478bd9Sstevel@tonic-gate bitmap2.bm_fattr4_time_modify = 1;
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate getattrargs.ga_attr_req.b_bitmap_len = NFS4_MAX_BITWORDS;
2237c478bd9Sstevel@tonic-gate getattrargs.ga_attr_req.b_bitmap_val[0] = bitmap1.word;
2247c478bd9Sstevel@tonic-gate getattrargs.ga_attr_req.b_bitmap_val[1] = bitmap2.word;
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC4_COMPOUND, xdr_getattr4_args,
2277c478bd9Sstevel@tonic-gate (caddr_t)&getattrargs, xdr_getattr4_res,
2287c478bd9Sstevel@tonic-gate (caddr_t)&getattrres, zero_timeout);
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate if (status != RPC_SUCCESS) {
2317c478bd9Sstevel@tonic-gate dprintf("nfs4getattr: RPC error %d\n", status);
2327c478bd9Sstevel@tonic-gate return (-1);
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate if (getattrres.gr_attr_status != NFS4_OK) {
2367c478bd9Sstevel@tonic-gate nfs4_error(getattrres.gr_attr_status);
2377c478bd9Sstevel@tonic-gate return (getattrres.gr_attr_status);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate bfattr4 = &getattrres.gr_attrs;
2417c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_TYPE) {
2427c478bd9Sstevel@tonic-gate if (bfattr4->b_fattr4_type < NF4REG ||
2437c478bd9Sstevel@tonic-gate bfattr4->b_fattr4_type > NF4FIFO)
2447c478bd9Sstevel@tonic-gate vap->va_type = VBAD;
2457c478bd9Sstevel@tonic-gate else
2467c478bd9Sstevel@tonic-gate vap->va_type = nf4_to_vt[bfattr4->b_fattr4_type];
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_MODE)
2497c478bd9Sstevel@tonic-gate vap->va_mode = (mode_t)bfattr4->b_fattr4_mode;
2507c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_SIZE)
2517c478bd9Sstevel@tonic-gate vap->va_size = (u_offset_t)bfattr4->b_fattr4_size;
2527c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_NODEID)
2537c478bd9Sstevel@tonic-gate vap->va_nodeid = (uint64_t)bfattr4->b_fattr4_fileid;
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate * XXX - may need to do something more here.
2567c478bd9Sstevel@tonic-gate */
2577c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_ATIME) {
2587c478bd9Sstevel@tonic-gate vap->va_atime.tv_sec = bfattr4->b_fattr4_time_access.seconds;
2597c478bd9Sstevel@tonic-gate vap->va_atime.tv_nsec = bfattr4->b_fattr4_time_access.nseconds;
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_CTIME) {
2627c478bd9Sstevel@tonic-gate vap->va_ctime.tv_sec = bfattr4->b_fattr4_time_metadata.seconds;
2637c478bd9Sstevel@tonic-gate vap->va_ctime.tv_nsec =
2647c478bd9Sstevel@tonic-gate bfattr4->b_fattr4_time_metadata.nseconds;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_MTIME) {
2677c478bd9Sstevel@tonic-gate vap->va_mtime.tv_sec = bfattr4->b_fattr4_time_modify.seconds;
2687c478bd9Sstevel@tonic-gate vap->va_mtime.tv_nsec = bfattr4->b_fattr4_time_modify.nseconds;
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate return (NFS4_OK);
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate * Display nfs error messages.
2767c478bd9Sstevel@tonic-gate */
2777c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2787c478bd9Sstevel@tonic-gate void
nfs4_error(enum nfsstat4 status)2797c478bd9Sstevel@tonic-gate nfs4_error(enum nfsstat4 status)
2807c478bd9Sstevel@tonic-gate {
2817c478bd9Sstevel@tonic-gate if (!(boothowto & RB_DEBUG))
2827c478bd9Sstevel@tonic-gate return;
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate switch (status) {
2857c478bd9Sstevel@tonic-gate case NFS4_OK:
2867c478bd9Sstevel@tonic-gate printf("NFS: No error.\n");
2877c478bd9Sstevel@tonic-gate break;
2887c478bd9Sstevel@tonic-gate case NFS4ERR_PERM:
2897c478bd9Sstevel@tonic-gate printf("NFS: Not owner.\n");
2907c478bd9Sstevel@tonic-gate break;
2917c478bd9Sstevel@tonic-gate case NFS4ERR_NOENT:
2927c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
2937c478bd9Sstevel@tonic-gate printf("NFS: No such file or directory.\n");
2947c478bd9Sstevel@tonic-gate #endif /* NFS_OPS_DEBUG */
2957c478bd9Sstevel@tonic-gate break;
2967c478bd9Sstevel@tonic-gate case NFS4ERR_IO:
2977c478bd9Sstevel@tonic-gate printf("NFS: IO ERROR occurred on NFS server.\n");
2987c478bd9Sstevel@tonic-gate break;
2997c478bd9Sstevel@tonic-gate case NFS4ERR_NXIO:
3007c478bd9Sstevel@tonic-gate printf("NFS: No such device or address.\n");
3017c478bd9Sstevel@tonic-gate break;
3027c478bd9Sstevel@tonic-gate case NFS4ERR_ACCESS:
3037c478bd9Sstevel@tonic-gate printf("NFS: Permission denied.\n");
3047c478bd9Sstevel@tonic-gate break;
3057c478bd9Sstevel@tonic-gate case NFS4ERR_EXIST:
3067c478bd9Sstevel@tonic-gate printf("NFS: File exists.\n");
3077c478bd9Sstevel@tonic-gate break;
3087c478bd9Sstevel@tonic-gate case NFS4ERR_XDEV:
3097c478bd9Sstevel@tonic-gate printf("NFS: Cross device hard link.\n");
3107c478bd9Sstevel@tonic-gate break;
3117c478bd9Sstevel@tonic-gate case NFS4ERR_NOTDIR:
3127c478bd9Sstevel@tonic-gate printf("NFS: Not a directory.\n");
3137c478bd9Sstevel@tonic-gate break;
3147c478bd9Sstevel@tonic-gate case NFS4ERR_ISDIR:
3157c478bd9Sstevel@tonic-gate printf("NFS: Is a directory.\n");
3167c478bd9Sstevel@tonic-gate break;
3177c478bd9Sstevel@tonic-gate case NFS4ERR_INVAL:
3187c478bd9Sstevel@tonic-gate printf("NFS: Invalid argument.\n");
3197c478bd9Sstevel@tonic-gate break;
3207c478bd9Sstevel@tonic-gate case NFS4ERR_FBIG:
3217c478bd9Sstevel@tonic-gate printf("NFS: File too large.\n");
3227c478bd9Sstevel@tonic-gate break;
3237c478bd9Sstevel@tonic-gate case NFS4ERR_NOSPC:
3247c478bd9Sstevel@tonic-gate printf("NFS: No space left on device.\n");
3257c478bd9Sstevel@tonic-gate break;
3267c478bd9Sstevel@tonic-gate case NFS4ERR_ROFS:
3277c478bd9Sstevel@tonic-gate printf("NFS: Read-only filesystem.\n");
3287c478bd9Sstevel@tonic-gate break;
3297c478bd9Sstevel@tonic-gate case NFS4ERR_MLINK:
3307c478bd9Sstevel@tonic-gate printf("NFS: Too many hard links.\n");
3317c478bd9Sstevel@tonic-gate break;
3327c478bd9Sstevel@tonic-gate case NFS4ERR_NAMETOOLONG:
3337c478bd9Sstevel@tonic-gate printf("NFS: File name too long.\n");
3347c478bd9Sstevel@tonic-gate break;
3357c478bd9Sstevel@tonic-gate case NFS4ERR_NOTEMPTY:
3367c478bd9Sstevel@tonic-gate printf("NFS: Directory not empty.\n");
3377c478bd9Sstevel@tonic-gate break;
3387c478bd9Sstevel@tonic-gate case NFS4ERR_DQUOT:
3397c478bd9Sstevel@tonic-gate printf("NFS: Disk quota exceeded.\n");
3407c478bd9Sstevel@tonic-gate break;
3417c478bd9Sstevel@tonic-gate case NFS4ERR_STALE:
3427c478bd9Sstevel@tonic-gate printf("NFS: Stale file handle.\n");
3437c478bd9Sstevel@tonic-gate break;
3447c478bd9Sstevel@tonic-gate case NFS4ERR_BADHANDLE:
3457c478bd9Sstevel@tonic-gate printf("NFS: Illegal NFS file handle.\n");
3467c478bd9Sstevel@tonic-gate break;
3477c478bd9Sstevel@tonic-gate case NFS4ERR_BAD_COOKIE:
3487c478bd9Sstevel@tonic-gate printf("NFS: Stale Cookie.\n");
3497c478bd9Sstevel@tonic-gate break;
3507c478bd9Sstevel@tonic-gate case NFS4ERR_NOTSUPP:
3517c478bd9Sstevel@tonic-gate printf("NFS: Operation is not supported.\n");
3527c478bd9Sstevel@tonic-gate break;
3537c478bd9Sstevel@tonic-gate case NFS4ERR_TOOSMALL:
3547c478bd9Sstevel@tonic-gate printf("NFS: Buffer too small.\n");
3557c478bd9Sstevel@tonic-gate break;
3567c478bd9Sstevel@tonic-gate case NFS4ERR_SERVERFAULT:
3577c478bd9Sstevel@tonic-gate printf("NFS: Server fault.\n");
3587c478bd9Sstevel@tonic-gate break;
3597c478bd9Sstevel@tonic-gate case NFS4ERR_BADTYPE:
3607c478bd9Sstevel@tonic-gate printf("NFS: Unsupported object type.\n");
3617c478bd9Sstevel@tonic-gate break;
3627c478bd9Sstevel@tonic-gate case NFS4ERR_BAD_STATEID:
3637c478bd9Sstevel@tonic-gate printf("NFS: Bad stateid\n");
3647c478bd9Sstevel@tonic-gate break;
3657c478bd9Sstevel@tonic-gate case NFS4ERR_BAD_SEQID:
3667c478bd9Sstevel@tonic-gate printf("NFS: Bad seqid\n");
3677c478bd9Sstevel@tonic-gate break;
3687c478bd9Sstevel@tonic-gate default:
3697c478bd9Sstevel@tonic-gate printf("NFS: unknown error.\n");
3707c478bd9Sstevel@tonic-gate break;
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate * lookup one component. for multicomponent lookup use a driver like lookup().
3767c478bd9Sstevel@tonic-gate */
3777c478bd9Sstevel@tonic-gate struct nfs_file *
nfs4lookup(struct nfs_file * dir,char * name,int * nstat)3787c478bd9Sstevel@tonic-gate nfs4lookup(struct nfs_file *dir, char *name, int *nstat)
3797c478bd9Sstevel@tonic-gate {
3807c478bd9Sstevel@tonic-gate static struct nfs_file cd;
3817c478bd9Sstevel@tonic-gate attr4_bitmap1_t bitmap1;
3827c478bd9Sstevel@tonic-gate lookup4arg_t lookupargs;
3837c478bd9Sstevel@tonic-gate lookup4res_t lookupres;
3847c478bd9Sstevel@tonic-gate enum clnt_stat status;
3857c478bd9Sstevel@tonic-gate utf8string str;
3867c478bd9Sstevel@tonic-gate char tagname[] = "inetboot lookup";
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate * NFSv4 uses a special LOOKUPP op
3907c478bd9Sstevel@tonic-gate * for looking up the parent directory.
3917c478bd9Sstevel@tonic-gate */
3927c478bd9Sstevel@tonic-gate if (strcmp(name, "..") == 0)
3937c478bd9Sstevel@tonic-gate return (nfs4lookupp(dir, nstat, NULL));
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate *nstat = (int)NFS4_OK;
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate bzero(&lookupres, sizeof (lookupres));
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate /*
4007c478bd9Sstevel@tonic-gate * Check if we have a filehandle and initialize the compound
4017c478bd9Sstevel@tonic-gate * with putfh or putrootfh appropriately.
4027c478bd9Sstevel@tonic-gate */
4037c478bd9Sstevel@tonic-gate str.utf8string_len = sizeof (tagname) - 1;
4047c478bd9Sstevel@tonic-gate str.utf8string_val = tagname;
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate if (dir->fh.fh4.len > 0)
4077c478bd9Sstevel@tonic-gate compound_init(&lookupargs.la_arg, &str, 0, 3, &dir->fh.fh4);
4087c478bd9Sstevel@tonic-gate else
4097c478bd9Sstevel@tonic-gate compound_init(&lookupargs.la_arg, &str, 0, 3, NULL);
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate /*
4127c478bd9Sstevel@tonic-gate * lookup
4137c478bd9Sstevel@tonic-gate */
4147c478bd9Sstevel@tonic-gate lookupargs.la_oplookup = OP_LOOKUP;
4157c478bd9Sstevel@tonic-gate /*
4167c478bd9Sstevel@tonic-gate * convert the pathname from char * to utf8string
4177c478bd9Sstevel@tonic-gate */
4187c478bd9Sstevel@tonic-gate lookupargs.la_pathname.utf8string_len = strlen(name);
4197c478bd9Sstevel@tonic-gate lookupargs.la_pathname.utf8string_val =
4207c478bd9Sstevel@tonic-gate bkmem_alloc(lookupargs.la_pathname.utf8string_len);
4217c478bd9Sstevel@tonic-gate if (lookupargs.la_pathname.utf8string_val == NULL) {
4227c478bd9Sstevel@tonic-gate dprintf("nfs4lookup: bkmem_alloc failed\n");
4237c478bd9Sstevel@tonic-gate return (NULL);
4247c478bd9Sstevel@tonic-gate }
4257c478bd9Sstevel@tonic-gate bcopy(name, lookupargs.la_pathname.utf8string_val,
4267c478bd9Sstevel@tonic-gate lookupargs.la_pathname.utf8string_len);
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate /*
4297c478bd9Sstevel@tonic-gate * Setup the attr bitmap. All we need is the type and filehandle info
4307c478bd9Sstevel@tonic-gate */
4317c478bd9Sstevel@tonic-gate lookupargs.la_opgetattr = OP_GETATTR;
4327c478bd9Sstevel@tonic-gate bitmap1.word = 0;
4337c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_type = 1;
4347c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_filehandle = 1;
4357c478bd9Sstevel@tonic-gate lookupargs.la_attr_req.b_bitmap_len = 1;
4367c478bd9Sstevel@tonic-gate lookupargs.la_attr_req.b_bitmap_val[0] = bitmap1.word;
4377c478bd9Sstevel@tonic-gate lookupargs.la_attr_req.b_bitmap_val[1] = 0;
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC4_COMPOUND, xdr_lookup4_args,
4407c478bd9Sstevel@tonic-gate (caddr_t)&lookupargs, xdr_lookup4_res,
4417c478bd9Sstevel@tonic-gate (caddr_t)&lookupres, zero_timeout);
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate if (status != RPC_SUCCESS) {
4447c478bd9Sstevel@tonic-gate dprintf("nfs4lookup: RPC error. status %d\n", status);
4457c478bd9Sstevel@tonic-gate return (NULL);
4467c478bd9Sstevel@tonic-gate }
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate if (lookupres.lr_lookup_status != NFS4_OK) {
4497c478bd9Sstevel@tonic-gate #ifdef DEBUG
4507c478bd9Sstevel@tonic-gate dprintf("nfs4lookup: lookup status = %d\n",
4517c478bd9Sstevel@tonic-gate lookupres.lr_lookup_status);
4527c478bd9Sstevel@tonic-gate #endif
4537c478bd9Sstevel@tonic-gate nfs4_error(lookupres.lr_lookup_status);
4547c478bd9Sstevel@tonic-gate *nstat = (int)lookupres.lr_lookup_status;
4557c478bd9Sstevel@tonic-gate if (lookupargs.la_pathname.utf8string_val != NULL)
4567c478bd9Sstevel@tonic-gate bkmem_free(lookupargs.la_pathname.utf8string_val,
4577c478bd9Sstevel@tonic-gate lookupargs.la_pathname.utf8string_len);
4587c478bd9Sstevel@tonic-gate return (NULL);
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate if (lookupres.lr_attr_status != NFS4_OK) {
4627c478bd9Sstevel@tonic-gate #ifdef DEBUG
4637c478bd9Sstevel@tonic-gate dprintf("nfs4lookup: getattr status = %d\n",
4647c478bd9Sstevel@tonic-gate lookupres.lr_attr_status);
4657c478bd9Sstevel@tonic-gate #endif
4667c478bd9Sstevel@tonic-gate nfs4_error(lookupres.lr_attr_status);
4677c478bd9Sstevel@tonic-gate *nstat = (int)lookupres.lr_attr_status;
4687c478bd9Sstevel@tonic-gate if (lookupargs.la_pathname.utf8string_val != NULL)
4697c478bd9Sstevel@tonic-gate bkmem_free(lookupargs.la_pathname.utf8string_val,
4707c478bd9Sstevel@tonic-gate lookupargs.la_pathname.utf8string_len);
4717c478bd9Sstevel@tonic-gate return (NULL);
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate /*
4757c478bd9Sstevel@tonic-gate * We have all the information we need to update the file pointer
4767c478bd9Sstevel@tonic-gate */
4777c478bd9Sstevel@tonic-gate bzero((caddr_t)&cd, sizeof (struct nfs_file));
4787c478bd9Sstevel@tonic-gate cd.version = NFS_V4;
4797c478bd9Sstevel@tonic-gate cd.ftype.type4 = lookupres.lr_attrs.b_fattr4_type;
4807c478bd9Sstevel@tonic-gate cd.fh.fh4.len = lookupres.lr_attrs.b_fattr4_filehandle.len;
4817c478bd9Sstevel@tonic-gate bcopy(lookupres.lr_attrs.b_fattr4_filehandle.data, cd.fh.fh4.data,
4827c478bd9Sstevel@tonic-gate cd.fh.fh4.len);
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate /*
4857c478bd9Sstevel@tonic-gate * Free the arg string
4867c478bd9Sstevel@tonic-gate */
4877c478bd9Sstevel@tonic-gate if (lookupargs.la_pathname.utf8string_val != NULL)
4887c478bd9Sstevel@tonic-gate bkmem_free(lookupargs.la_pathname.utf8string_val,
4897c478bd9Sstevel@tonic-gate lookupargs.la_pathname.utf8string_len);
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate return (&cd);
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate /*
4957c478bd9Sstevel@tonic-gate * lookup parent directory.
4967c478bd9Sstevel@tonic-gate */
4977c478bd9Sstevel@tonic-gate struct nfs_file *
nfs4lookupp(struct nfs_file * dir,int * nstat,uint64_t * fileid)4987c478bd9Sstevel@tonic-gate nfs4lookupp(struct nfs_file *dir, int *nstat, uint64_t *fileid)
4997c478bd9Sstevel@tonic-gate {
5007c478bd9Sstevel@tonic-gate static struct nfs_file cd;
5017c478bd9Sstevel@tonic-gate attr4_bitmap1_t bitmap1;
5027c478bd9Sstevel@tonic-gate lookupp4arg_t lookuppargs;
5037c478bd9Sstevel@tonic-gate lookup4res_t lookupres;
5047c478bd9Sstevel@tonic-gate enum clnt_stat status;
5057c478bd9Sstevel@tonic-gate utf8string str;
5067c478bd9Sstevel@tonic-gate char tagname[] = "inetboot lookupp";
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate *nstat = (int)NFS4_OK;
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate bzero(&lookupres, sizeof (lookupres));
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate /*
5137c478bd9Sstevel@tonic-gate * Check if we have a filehandle and initialize the compound
5147c478bd9Sstevel@tonic-gate * with putfh or putrootfh appropriately.
5157c478bd9Sstevel@tonic-gate */
5167c478bd9Sstevel@tonic-gate str.utf8string_len = sizeof (tagname) - 1;
5177c478bd9Sstevel@tonic-gate str.utf8string_val = tagname;
5187c478bd9Sstevel@tonic-gate
5197c478bd9Sstevel@tonic-gate if (dir->fh.fh4.len > 0)
5207c478bd9Sstevel@tonic-gate compound_init(&lookuppargs.la_arg, &str, 0, 3, &dir->fh.fh4);
5217c478bd9Sstevel@tonic-gate else
5227c478bd9Sstevel@tonic-gate compound_init(&lookuppargs.la_arg, &str, 0, 3, NULL);
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate /*
5257c478bd9Sstevel@tonic-gate * lookupp
5267c478bd9Sstevel@tonic-gate */
5277c478bd9Sstevel@tonic-gate lookuppargs.la_oplookupp = OP_LOOKUPP;
5287c478bd9Sstevel@tonic-gate /*
5297c478bd9Sstevel@tonic-gate * Setup the attr bitmap. Normally, all we need is the type and
5307c478bd9Sstevel@tonic-gate * filehandle info, but getdents might require the fileid of the
5317c478bd9Sstevel@tonic-gate * parent.
5327c478bd9Sstevel@tonic-gate */
5337c478bd9Sstevel@tonic-gate lookuppargs.la_opgetattr = OP_GETATTR;
5347c478bd9Sstevel@tonic-gate bitmap1.word = 0;
5357c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_type = 1;
5367c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_filehandle = 1;
5377c478bd9Sstevel@tonic-gate if (fileid != NULL)
5387c478bd9Sstevel@tonic-gate bitmap1.bm_fattr4_fileid = 1;
5397c478bd9Sstevel@tonic-gate lookuppargs.la_attr_req.b_bitmap_len = 1;
5407c478bd9Sstevel@tonic-gate lookuppargs.la_attr_req.b_bitmap_val[0] = bitmap1.word;
5417c478bd9Sstevel@tonic-gate lookuppargs.la_attr_req.b_bitmap_val[1] = 0;
5427c478bd9Sstevel@tonic-gate
5437c478bd9Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC4_COMPOUND, xdr_lookupp4_args,
5447c478bd9Sstevel@tonic-gate (caddr_t)&lookuppargs, xdr_lookup4_res,
5457c478bd9Sstevel@tonic-gate (caddr_t)&lookupres, zero_timeout);
5467c478bd9Sstevel@tonic-gate
5477c478bd9Sstevel@tonic-gate if (status != RPC_SUCCESS) {
5487c478bd9Sstevel@tonic-gate dprintf("nfs4lookupp: RPC error. status %d\n", status);
5497c478bd9Sstevel@tonic-gate return (NULL);
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate if (lookupres.lr_lookup_status != NFS4_OK) {
5537c478bd9Sstevel@tonic-gate #ifdef DEBUG
5547c478bd9Sstevel@tonic-gate dprintf("nfs4lookupp: lookupp status = %d\n",
5557c478bd9Sstevel@tonic-gate lookupres.lr_lookup_status);
5567c478bd9Sstevel@tonic-gate #endif
5577c478bd9Sstevel@tonic-gate nfs4_error(lookupres.lr_lookup_status);
5587c478bd9Sstevel@tonic-gate *nstat = (int)lookupres.lr_lookup_status;
5597c478bd9Sstevel@tonic-gate return (NULL);
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate if (lookupres.lr_attr_status != NFS4_OK) {
5637c478bd9Sstevel@tonic-gate #ifdef DEBUG
5647c478bd9Sstevel@tonic-gate dprintf("nfs4lookupp: getattr status = %d\n",
5657c478bd9Sstevel@tonic-gate lookupres.lr_attr_status);
5667c478bd9Sstevel@tonic-gate #endif
5677c478bd9Sstevel@tonic-gate nfs4_error(lookupres.lr_attr_status);
5687c478bd9Sstevel@tonic-gate *nstat = (int)lookupres.lr_attr_status;
5697c478bd9Sstevel@tonic-gate return (NULL);
5707c478bd9Sstevel@tonic-gate }
5717c478bd9Sstevel@tonic-gate
5727c478bd9Sstevel@tonic-gate /*
5737c478bd9Sstevel@tonic-gate * We have all the information we need to update the file pointer
5747c478bd9Sstevel@tonic-gate */
5757c478bd9Sstevel@tonic-gate bzero((caddr_t)&cd, sizeof (struct nfs_file));
5767c478bd9Sstevel@tonic-gate cd.version = NFS_V4;
5777c478bd9Sstevel@tonic-gate cd.ftype.type4 = lookupres.lr_attrs.b_fattr4_type;
5787c478bd9Sstevel@tonic-gate cd.fh.fh4.len = lookupres.lr_attrs.b_fattr4_filehandle.len;
5797c478bd9Sstevel@tonic-gate bcopy(lookupres.lr_attrs.b_fattr4_filehandle.data, cd.fh.fh4.data,
5807c478bd9Sstevel@tonic-gate cd.fh.fh4.len);
5817c478bd9Sstevel@tonic-gate
5827c478bd9Sstevel@tonic-gate /*
5837c478bd9Sstevel@tonic-gate * Fill in the fileid if the user passed in one
5847c478bd9Sstevel@tonic-gate */
5857c478bd9Sstevel@tonic-gate if (fileid != NULL)
5867c478bd9Sstevel@tonic-gate *fileid = lookupres.lr_attrs.b_fattr4_fileid;
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate return (&cd);
5897c478bd9Sstevel@tonic-gate }
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate /*
5927c478bd9Sstevel@tonic-gate * Gets symbolic link into pathname.
5937c478bd9Sstevel@tonic-gate */
5947c478bd9Sstevel@tonic-gate int
nfs4getsymlink(struct nfs_file * cfile,char ** path)5957c478bd9Sstevel@tonic-gate nfs4getsymlink(struct nfs_file *cfile, char **path)
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate enum clnt_stat status;
5987c478bd9Sstevel@tonic-gate readlink4arg_t readlinkargs;
5997c478bd9Sstevel@tonic-gate readlink4res_t readlinkres;
6007c478bd9Sstevel@tonic-gate static char symlink_path[NFS_MAXPATHLEN];
6017c478bd9Sstevel@tonic-gate int spathlen;
6027c478bd9Sstevel@tonic-gate utf8string str;
6037c478bd9Sstevel@tonic-gate char tagname[] = "inetboot getsymlink";
6047c478bd9Sstevel@tonic-gate int error = NFS4_OK;
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate bzero(&readlinkres, sizeof (readlinkres));
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate /*
6097c478bd9Sstevel@tonic-gate * readlink
6107c478bd9Sstevel@tonic-gate */
6117c478bd9Sstevel@tonic-gate str.utf8string_len = sizeof (tagname) - 1;
6127c478bd9Sstevel@tonic-gate str.utf8string_val = tagname;
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate if (cfile->fh.fh4.len > 0)
6157c478bd9Sstevel@tonic-gate compound_init(&readlinkargs.rl_arg, &str, 0, 2,
6167c478bd9Sstevel@tonic-gate &cfile->fh.fh4);
6177c478bd9Sstevel@tonic-gate else
6187c478bd9Sstevel@tonic-gate compound_init(&readlinkargs.rl_arg, &str, 0, 2, NULL);
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate readlinkargs.rl_opreadlink = OP_READLINK;
6217c478bd9Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC4_COMPOUND, xdr_readlink4_args,
6227c478bd9Sstevel@tonic-gate (caddr_t)&readlinkargs, xdr_readlink4_res,
6237c478bd9Sstevel@tonic-gate (caddr_t)&readlinkres, zero_timeout);
6247c478bd9Sstevel@tonic-gate
6257c478bd9Sstevel@tonic-gate if (status != RPC_SUCCESS) {
6267c478bd9Sstevel@tonic-gate dprintf("nfs4getsymlink: RPC readlink error %d\n", status);
6277c478bd9Sstevel@tonic-gate error = -1;
6287c478bd9Sstevel@tonic-gate goto out;
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate if (readlinkres.rl_status != NFS4_OK) {
6327c478bd9Sstevel@tonic-gate nfs4_error(readlinkres.rl_status);
6337c478bd9Sstevel@tonic-gate error = readlinkres.rl_status;
6347c478bd9Sstevel@tonic-gate goto out;
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate /*
6387c478bd9Sstevel@tonic-gate * Convert the utf8string to a normal character string
6397c478bd9Sstevel@tonic-gate */
6407c478bd9Sstevel@tonic-gate spathlen = readlinkres.rl_link.utf8string_len;
6417c478bd9Sstevel@tonic-gate if (spathlen <= 0 || readlinkres.rl_link.utf8string_val == NULL) {
6427c478bd9Sstevel@tonic-gate *path = NULL;
6437c478bd9Sstevel@tonic-gate error = readlinkres.rl_status;
6447c478bd9Sstevel@tonic-gate goto out;
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate bcopy(readlinkres.rl_link.utf8string_val, symlink_path, spathlen);
6487c478bd9Sstevel@tonic-gate symlink_path[spathlen] = '\0';
6497c478bd9Sstevel@tonic-gate *path = symlink_path;
6507c478bd9Sstevel@tonic-gate
6517c478bd9Sstevel@tonic-gate out:
6527c478bd9Sstevel@tonic-gate /*
6537c478bd9Sstevel@tonic-gate * Free the results
6547c478bd9Sstevel@tonic-gate */
6557c478bd9Sstevel@tonic-gate if (readlinkres.rl_link.utf8string_val != NULL)
6567c478bd9Sstevel@tonic-gate bkmem_free(readlinkres.rl_link.utf8string_val, spathlen);
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate return (error);
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate /*
6627c478bd9Sstevel@tonic-gate * Should just forget about the tag, but will leave in support for the time
6637c478bd9Sstevel@tonic-gate * being.
6647c478bd9Sstevel@tonic-gate */
6657c478bd9Sstevel@tonic-gate void
compound_init(b_compound_t * cp,utf8string * str,uint_t mvers,uint_t arglen,struct nfs_bfh4 * pfh)6667c478bd9Sstevel@tonic-gate compound_init(b_compound_t *cp, utf8string *str, uint_t mvers, uint_t arglen,
6677c478bd9Sstevel@tonic-gate struct nfs_bfh4 *pfh)
6687c478bd9Sstevel@tonic-gate {
6697c478bd9Sstevel@tonic-gate if (str == NULL || str->utf8string_len == 0) {
6707c478bd9Sstevel@tonic-gate cp->ca_tag.utf8string_len = 0;
6717c478bd9Sstevel@tonic-gate cp->ca_tag.utf8string_val = NULL;
6727c478bd9Sstevel@tonic-gate } else {
6737c478bd9Sstevel@tonic-gate cp->ca_tag.utf8string_len = str->utf8string_len;
6747c478bd9Sstevel@tonic-gate cp->ca_tag.utf8string_val = str->utf8string_val;
6757c478bd9Sstevel@tonic-gate }
6767c478bd9Sstevel@tonic-gate cp->ca_minorversion = mvers;
6777c478bd9Sstevel@tonic-gate cp->ca_argarray_len = arglen;
6787c478bd9Sstevel@tonic-gate if (pfh == NULL) {
6797c478bd9Sstevel@tonic-gate cp->ca_isputrootfh = TRUE;
6807c478bd9Sstevel@tonic-gate cp->ca_opputfh.pf_opnum = OP_PUTROOTFH;
6817c478bd9Sstevel@tonic-gate } else {
6827c478bd9Sstevel@tonic-gate cp->ca_isputrootfh = FALSE;
6837c478bd9Sstevel@tonic-gate cp->ca_opputfh.pf_opnum = OP_PUTFH;
6847c478bd9Sstevel@tonic-gate cp->ca_opputfh.pf_filehandle.len = pfh->len;
6857c478bd9Sstevel@tonic-gate bcopy(pfh->data, cp->ca_opputfh.pf_filehandle.data, pfh->len);
6867c478bd9Sstevel@tonic-gate }
6877c478bd9Sstevel@tonic-gate }
688