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