10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6747Sga159272 * Common Development and Distribution License (the "License").
6*6747Sga159272 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*6747Sga159272 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate *
250Sstevel@tonic-gate * Simple nfs V3 ops
260Sstevel@tonic-gate */
270Sstevel@tonic-gate
280Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
290Sstevel@tonic-gate
300Sstevel@tonic-gate #include <rpc/types.h>
310Sstevel@tonic-gate #include <rpc/auth.h>
320Sstevel@tonic-gate #include <sys/t_lock.h>
330Sstevel@tonic-gate #include "clnt.h"
340Sstevel@tonic-gate #include <sys/fcntl.h>
350Sstevel@tonic-gate #include <sys/vfs.h>
360Sstevel@tonic-gate #include <errno.h>
370Sstevel@tonic-gate #include <sys/promif.h>
380Sstevel@tonic-gate #include <rpc/xdr.h>
390Sstevel@tonic-gate #include "nfs_inet.h"
400Sstevel@tonic-gate #include <sys/stat.h>
410Sstevel@tonic-gate #include <sys/bootvfs.h>
420Sstevel@tonic-gate #include <sys/bootdebug.h>
430Sstevel@tonic-gate #include <sys/salib.h>
440Sstevel@tonic-gate #include <sys/sacache.h>
450Sstevel@tonic-gate #include <rpc/rpc.h>
460Sstevel@tonic-gate #include "brpc.h"
470Sstevel@tonic-gate #include <rpcsvc/nfs_prot.h>
480Sstevel@tonic-gate
490Sstevel@tonic-gate #define dprintf if (boothowto & RB_DEBUG) printf
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate * NFS Version 3 specific functions
530Sstevel@tonic-gate */
540Sstevel@tonic-gate
550Sstevel@tonic-gate ssize_t
nfs3read(struct nfs_file * filep,char * buf,size_t size)560Sstevel@tonic-gate nfs3read(struct nfs_file *filep, char *buf, size_t size)
570Sstevel@tonic-gate {
580Sstevel@tonic-gate READ3args read_args;
590Sstevel@tonic-gate READ3res read_res;
600Sstevel@tonic-gate enum clnt_stat read_stat;
610Sstevel@tonic-gate uint_t readcnt = 0; /* # bytes read by nfs */
620Sstevel@tonic-gate uint_t count = 0; /* # bytes transferred to buf */
630Sstevel@tonic-gate int done = FALSE; /* last block has come in */
640Sstevel@tonic-gate int framing_errs = 0; /* stack errors */
650Sstevel@tonic-gate char *buf_offset; /* current buffer offset */
660Sstevel@tonic-gate struct timeval timeout;
670Sstevel@tonic-gate static uint_t pos; /* progress indicator counter */
680Sstevel@tonic-gate static char ind[] = "|/-\\"; /* progress indicator */
690Sstevel@tonic-gate static int blks_read;
700Sstevel@tonic-gate
710Sstevel@tonic-gate read_args.file.data.data_len = filep->fh.fh3.len;
720Sstevel@tonic-gate read_args.file.data.data_val = filep->fh.fh3.data;
730Sstevel@tonic-gate read_args.offset = filep->offset;
740Sstevel@tonic-gate
750Sstevel@tonic-gate bzero(&read_res, sizeof (read_res));
760Sstevel@tonic-gate
770Sstevel@tonic-gate buf_offset = buf;
780Sstevel@tonic-gate
790Sstevel@tonic-gate /* Optimize for reads of less than one block size */
800Sstevel@tonic-gate
810Sstevel@tonic-gate if (nfs_readsize == 0)
820Sstevel@tonic-gate nfs_readsize = READ3_SIZE;
830Sstevel@tonic-gate
840Sstevel@tonic-gate if (size < nfs_readsize)
850Sstevel@tonic-gate read_args.count = size;
860Sstevel@tonic-gate else
870Sstevel@tonic-gate read_args.count = nfs_readsize;
880Sstevel@tonic-gate
890Sstevel@tonic-gate do {
900Sstevel@tonic-gate /* use the user's buffer to stuff the data into. */
910Sstevel@tonic-gate read_res.READ3res_u.resok.data.data_val = buf_offset;
920Sstevel@tonic-gate
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate * Handle the case where the file does not end
950Sstevel@tonic-gate * on a block boundary.
960Sstevel@tonic-gate */
970Sstevel@tonic-gate if ((count + read_args.count) > size)
980Sstevel@tonic-gate read_args.count = size - count;
990Sstevel@tonic-gate
1000Sstevel@tonic-gate timeout.tv_sec = NFS_REXMIT_MIN; /* Total wait for call */
1010Sstevel@tonic-gate timeout.tv_usec = 0;
1020Sstevel@tonic-gate do {
1030Sstevel@tonic-gate read_stat = CLNT_CALL(root_CLIENT, NFSPROC3_READ,
1040Sstevel@tonic-gate xdr_READ3args, (caddr_t)&read_args,
1050Sstevel@tonic-gate xdr_READ3res, (caddr_t)&read_res, timeout);
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate if (read_stat == RPC_TIMEDOUT) {
1080Sstevel@tonic-gate dprintf("NFS read(%d) timed out. Retrying...\n",
1090Sstevel@tonic-gate read_args.count);
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate * If the remote is there and trying to respond,
1120Sstevel@tonic-gate * but our stack is having trouble reassembling
1130Sstevel@tonic-gate * the reply, reduce the read size in an
1140Sstevel@tonic-gate * attempt to compensate. Reset the
1150Sstevel@tonic-gate * transmission and reply wait timers.
1160Sstevel@tonic-gate */
1170Sstevel@tonic-gate if (errno == ETIMEDOUT)
1180Sstevel@tonic-gate framing_errs++;
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate if (framing_errs > NFS_MAX_FERRS &&
1210Sstevel@tonic-gate read_args.count > NFS_READ_DECR) {
1220Sstevel@tonic-gate read_args.count /= 2;
1230Sstevel@tonic-gate nfs_readsize /= 2;
1240Sstevel@tonic-gate dprintf("NFS Read size now %d.\n",
1250Sstevel@tonic-gate nfs_readsize);
1260Sstevel@tonic-gate timeout.tv_sec = NFS_REXMIT_MIN;
1270Sstevel@tonic-gate framing_errs = 0;
1280Sstevel@tonic-gate } else {
1290Sstevel@tonic-gate if (timeout.tv_sec < NFS_REXMIT_MAX)
1300Sstevel@tonic-gate timeout.tv_sec++;
1310Sstevel@tonic-gate else
1320Sstevel@tonic-gate timeout.tv_sec = 0;
1330Sstevel@tonic-gate /* default RPC */
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate } while (read_stat == RPC_TIMEDOUT);
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate if (read_stat != RPC_SUCCESS)
1390Sstevel@tonic-gate return (-1);
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate if (read_res.status != NFS3_OK)
1420Sstevel@tonic-gate return (-1);
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate readcnt = read_res.READ3res_u.resok.data.data_len;
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate * If we are at EOF, update counts and exit
1470Sstevel@tonic-gate */
1480Sstevel@tonic-gate if (read_res.READ3res_u.resok.eof == TRUE)
1490Sstevel@tonic-gate done = TRUE;
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate * Handle the case where the file is smaller than
1530Sstevel@tonic-gate * the size of the read request, thus the request
1540Sstevel@tonic-gate * couldn't be completely filled.
1550Sstevel@tonic-gate */
1560Sstevel@tonic-gate if (readcnt < read_args.count) {
1570Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
1580Sstevel@tonic-gate if ((boothowto & DBFLAGS) == DBFLAGS)
1590Sstevel@tonic-gate printf("nfs3read(): partial read %d"
160*6747Sga159272 " instead of %d\n",
161*6747Sga159272 readcnt, read_args.count);
1620Sstevel@tonic-gate #endif
1630Sstevel@tonic-gate done = TRUE; /* update the counts and exit */
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate /* update various offsets */
1670Sstevel@tonic-gate count += readcnt;
1680Sstevel@tonic-gate filep->offset += readcnt;
1690Sstevel@tonic-gate buf_offset += readcnt;
1700Sstevel@tonic-gate read_args.offset += readcnt;
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate * round and round she goes (though not on every block..
1730Sstevel@tonic-gate * - OBP's take a fair bit of time to actually print stuff)
1740Sstevel@tonic-gate */
1750Sstevel@tonic-gate if ((blks_read++ & 0x3) == 0)
1760Sstevel@tonic-gate printf("%c\b", ind[pos++ & 3]);
1770Sstevel@tonic-gate } while (count < size && !done);
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate return (count);
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate
1820Sstevel@tonic-gate int
nfs3getattr(struct nfs_file * nfp,struct vattr * vap)1830Sstevel@tonic-gate nfs3getattr(struct nfs_file *nfp, struct vattr *vap)
1840Sstevel@tonic-gate {
1850Sstevel@tonic-gate enum clnt_stat getattr_stat;
1860Sstevel@tonic-gate GETATTR3args getattr_args;
1870Sstevel@tonic-gate GETATTR3res getattr_res;
1880Sstevel@tonic-gate fattr3 *na;
1890Sstevel@tonic-gate struct timeval timeout = {0, 0}; /* default */
1900Sstevel@tonic-gate vtype_t nf3_to_vt[] =
1910Sstevel@tonic-gate { VBAD, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO };
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate bzero(&getattr_args, sizeof (getattr_args));
1950Sstevel@tonic-gate getattr_args.object.data.data_len = nfp->fh.fh3.len;
1960Sstevel@tonic-gate getattr_args.object.data.data_val = nfp->fh.fh3.data;
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate bzero(&getattr_res, sizeof (getattr_res));
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate getattr_stat = CLNT_CALL(root_CLIENT, NFSPROC3_GETATTR,
201*6747Sga159272 xdr_GETATTR3args, (caddr_t)&getattr_args,
202*6747Sga159272 xdr_GETATTR3res, (caddr_t)&getattr_res, timeout);
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate if (getattr_stat != RPC_SUCCESS) {
2050Sstevel@tonic-gate dprintf("nfs_getattr: RPC error %d\n", getattr_stat);
2060Sstevel@tonic-gate return (-1);
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate if (getattr_res.status != NFS3_OK) {
2090Sstevel@tonic-gate nfs3_error(getattr_res.status);
2100Sstevel@tonic-gate return (getattr_res.status);
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate na = &getattr_res.GETATTR3res_u.resok.obj_attributes;
2140Sstevel@tonic-gate if (vap->va_mask & AT_TYPE) {
2150Sstevel@tonic-gate if (na->type < NF3REG || na->type > NF3FIFO)
2160Sstevel@tonic-gate vap->va_type = VBAD;
2170Sstevel@tonic-gate else
2180Sstevel@tonic-gate vap->va_type = nf3_to_vt[na->type];
2190Sstevel@tonic-gate }
2200Sstevel@tonic-gate if (vap->va_mask & AT_MODE)
2210Sstevel@tonic-gate vap->va_mode = (mode_t)na->mode;
2220Sstevel@tonic-gate if (vap->va_mask & AT_SIZE)
2230Sstevel@tonic-gate vap->va_size = (u_offset_t)na->size;
2240Sstevel@tonic-gate if (vap->va_mask & AT_NODEID)
2250Sstevel@tonic-gate vap->va_nodeid = (u_longlong_t)na->fileid;
2260Sstevel@tonic-gate if (vap->va_mask & AT_ATIME) {
2270Sstevel@tonic-gate vap->va_atime.tv_sec = na->atime.seconds;
2280Sstevel@tonic-gate vap->va_atime.tv_nsec = na->atime.nseconds;
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate if (vap->va_mask & AT_CTIME) {
2310Sstevel@tonic-gate vap->va_ctime.tv_sec = na->ctime.seconds;
2320Sstevel@tonic-gate vap->va_ctime.tv_nsec = na->ctime.nseconds;
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate if (vap->va_mask & AT_MTIME) {
2350Sstevel@tonic-gate vap->va_mtime.tv_sec = na->mtime.seconds;
2360Sstevel@tonic-gate vap->va_mtime.tv_nsec = na->mtime.nseconds;
2370Sstevel@tonic-gate }
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate return (NFS3_OK);
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate * Display nfs error messages.
2440Sstevel@tonic-gate */
2450Sstevel@tonic-gate /*ARGSUSED*/
2460Sstevel@tonic-gate void
nfs3_error(enum nfsstat3 status)2470Sstevel@tonic-gate nfs3_error(enum nfsstat3 status)
2480Sstevel@tonic-gate {
2490Sstevel@tonic-gate if (!(boothowto & RB_DEBUG))
2500Sstevel@tonic-gate return;
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate switch (status) {
2530Sstevel@tonic-gate case NFS3_OK:
2540Sstevel@tonic-gate printf("NFS: No error.\n");
2550Sstevel@tonic-gate break;
2560Sstevel@tonic-gate case NFS3ERR_PERM:
2570Sstevel@tonic-gate printf("NFS: Not owner.\n");
2580Sstevel@tonic-gate break;
2590Sstevel@tonic-gate case NFS3ERR_NOENT:
2600Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
2610Sstevel@tonic-gate printf("NFS: No such file or directory.\n");
2620Sstevel@tonic-gate #endif /* NFS_OPS_DEBUG */
2630Sstevel@tonic-gate break;
2640Sstevel@tonic-gate case NFS3ERR_IO:
2650Sstevel@tonic-gate printf("NFS: IO ERROR occurred on NFS server.\n");
2660Sstevel@tonic-gate break;
2670Sstevel@tonic-gate case NFS3ERR_NXIO:
2680Sstevel@tonic-gate printf("NFS: No such device or address.\n");
2690Sstevel@tonic-gate break;
2700Sstevel@tonic-gate case NFS3ERR_ACCES:
2710Sstevel@tonic-gate printf("NFS: Permission denied.\n");
2720Sstevel@tonic-gate break;
2730Sstevel@tonic-gate case NFS3ERR_EXIST:
2740Sstevel@tonic-gate printf("NFS: File exists.\n");
2750Sstevel@tonic-gate break;
2760Sstevel@tonic-gate case NFS3ERR_XDEV:
2770Sstevel@tonic-gate printf("NFS: Cross device hard link.\n");
2780Sstevel@tonic-gate break;
2790Sstevel@tonic-gate case NFS3ERR_NODEV:
2800Sstevel@tonic-gate printf("NFS: No such device.\n");
2810Sstevel@tonic-gate break;
2820Sstevel@tonic-gate case NFS3ERR_NOTDIR:
2830Sstevel@tonic-gate printf("NFS: Not a directory.\n");
2840Sstevel@tonic-gate break;
2850Sstevel@tonic-gate case NFS3ERR_ISDIR:
2860Sstevel@tonic-gate printf("NFS: Is a directory.\n");
2870Sstevel@tonic-gate break;
2880Sstevel@tonic-gate case NFS3ERR_INVAL:
2890Sstevel@tonic-gate printf("NFS: Invalid argument.\n");
2900Sstevel@tonic-gate break;
2910Sstevel@tonic-gate case NFS3ERR_FBIG:
2920Sstevel@tonic-gate printf("NFS: File too large.\n");
2930Sstevel@tonic-gate break;
2940Sstevel@tonic-gate case NFS3ERR_NOSPC:
2950Sstevel@tonic-gate printf("NFS: No space left on device.\n");
2960Sstevel@tonic-gate break;
2970Sstevel@tonic-gate case NFS3ERR_ROFS:
2980Sstevel@tonic-gate printf("NFS: Read-only filesystem.\n");
2990Sstevel@tonic-gate break;
3000Sstevel@tonic-gate case NFS3ERR_MLINK:
3010Sstevel@tonic-gate printf("NFS: Too many hard links.\n");
3020Sstevel@tonic-gate break;
3030Sstevel@tonic-gate case NFS3ERR_NAMETOOLONG:
3040Sstevel@tonic-gate printf("NFS: File name too long.\n");
3050Sstevel@tonic-gate break;
3060Sstevel@tonic-gate case NFS3ERR_NOTEMPTY:
3070Sstevel@tonic-gate printf("NFS: Directory not empty.\n");
3080Sstevel@tonic-gate break;
3090Sstevel@tonic-gate case NFS3ERR_DQUOT:
3100Sstevel@tonic-gate printf("NFS: Disk quota exceeded.\n");
3110Sstevel@tonic-gate break;
3120Sstevel@tonic-gate case NFS3ERR_STALE:
3130Sstevel@tonic-gate printf("NFS: Stale file handle.\n");
3140Sstevel@tonic-gate break;
3150Sstevel@tonic-gate case NFS3ERR_REMOTE:
3160Sstevel@tonic-gate printf("NFS: Remote file in path.\n");
3170Sstevel@tonic-gate break;
3180Sstevel@tonic-gate case NFS3ERR_BADHANDLE:
3190Sstevel@tonic-gate printf("NFS: Illegal NFS file handle.\n");
3200Sstevel@tonic-gate break;
3210Sstevel@tonic-gate case NFS3ERR_NOT_SYNC:
3220Sstevel@tonic-gate printf("NFS: Synchronization mismatch.\n");
3230Sstevel@tonic-gate break;
3240Sstevel@tonic-gate case NFS3ERR_BAD_COOKIE:
3250Sstevel@tonic-gate printf("NFS: Stale Cookie.\n");
3260Sstevel@tonic-gate break;
3270Sstevel@tonic-gate case NFS3ERR_NOTSUPP:
3280Sstevel@tonic-gate printf("NFS: Operation is not supported.\n");
3290Sstevel@tonic-gate break;
3300Sstevel@tonic-gate case NFS3ERR_TOOSMALL:
3310Sstevel@tonic-gate printf("NFS: Buffer too small.\n");
3320Sstevel@tonic-gate break;
3330Sstevel@tonic-gate case NFS3ERR_SERVERFAULT:
3340Sstevel@tonic-gate printf("NFS: Server fault.\n");
3350Sstevel@tonic-gate break;
3360Sstevel@tonic-gate case NFS3ERR_BADTYPE:
3370Sstevel@tonic-gate printf("NFS: Unsupported object type.\n");
3380Sstevel@tonic-gate break;
3390Sstevel@tonic-gate case NFS3ERR_JUKEBOX:
3400Sstevel@tonic-gate printf("NFS: Resource temporarily unavailable.\n");
3410Sstevel@tonic-gate break;
3420Sstevel@tonic-gate default:
3430Sstevel@tonic-gate printf("NFS: unknown error.\n");
3440Sstevel@tonic-gate break;
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate }
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate struct nfs_file *
nfs3lookup(struct nfs_file * dir,char * name,int * nstat)3490Sstevel@tonic-gate nfs3lookup(struct nfs_file *dir, char *name, int *nstat)
3500Sstevel@tonic-gate {
3510Sstevel@tonic-gate struct timeval zero_timeout = {0, 0}; /* default */
3520Sstevel@tonic-gate static struct nfs_file cd;
3530Sstevel@tonic-gate LOOKUP3args dirop;
3540Sstevel@tonic-gate LOOKUP3res res_lookup;
3550Sstevel@tonic-gate enum clnt_stat status;
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate *nstat = (int)NFS3_OK;
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate bzero((caddr_t)&dirop, sizeof (LOOKUP3args));
3600Sstevel@tonic-gate bzero((caddr_t)&res_lookup, sizeof (LOOKUP3res));
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate dirop.what.dir.data.data_len = dir->fh.fh3.len;
3630Sstevel@tonic-gate dirop.what.dir.data.data_val = dir->fh.fh3.data;
3640Sstevel@tonic-gate dirop.what.name = name;
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC3_LOOKUP, xdr_LOOKUP3args,
367*6747Sga159272 (caddr_t)&dirop, xdr_LOOKUP3res, (caddr_t)&res_lookup,
368*6747Sga159272 zero_timeout);
3690Sstevel@tonic-gate if (status != RPC_SUCCESS) {
3700Sstevel@tonic-gate dprintf("lookup: RPC error.\n");
3710Sstevel@tonic-gate return (NULL);
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate if (res_lookup.status != NFS3_OK) {
3740Sstevel@tonic-gate nfs3_error(res_lookup.status);
3750Sstevel@tonic-gate *nstat = (int)res_lookup.status;
3760Sstevel@tonic-gate (void) CLNT_FREERES(root_CLIENT,
377*6747Sga159272 xdr_LOOKUP3res, (caddr_t)&res_lookup);
3780Sstevel@tonic-gate return (NULL);
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate bzero((caddr_t)&cd, sizeof (struct nfs_file));
3820Sstevel@tonic-gate cd.version = NFS_V3;
3830Sstevel@tonic-gate /*
3840Sstevel@tonic-gate * Server must supply post_op_attr's
3850Sstevel@tonic-gate */
3860Sstevel@tonic-gate if (res_lookup.LOOKUP3res_u.resok.obj_attributes.attributes_follow ==
387*6747Sga159272 FALSE) {
3880Sstevel@tonic-gate printf("nfs3lookup: server fails to return post_op_attr\n");
3890Sstevel@tonic-gate (void) CLNT_FREERES(root_CLIENT,
390*6747Sga159272 xdr_LOOKUP3res, (caddr_t)&res_lookup);
3910Sstevel@tonic-gate return (NULL);
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate
394*6747Sga159272 cd.ftype.type3 = res_lookup.LOOKUP3res_u.resok.obj_attributes
395*6747Sga159272 .post_op_attr_u.attributes.type;
3960Sstevel@tonic-gate cd.fh.fh3.len = res_lookup.LOOKUP3res_u.resok.object.data.data_len;
3970Sstevel@tonic-gate bcopy(res_lookup.LOOKUP3res_u.resok.object.data.data_val,
398*6747Sga159272 cd.fh.fh3.data, cd.fh.fh3.len);
3990Sstevel@tonic-gate (void) CLNT_FREERES(root_CLIENT, xdr_LOOKUP3res, (caddr_t)&res_lookup);
4000Sstevel@tonic-gate return (&cd);
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate /*
4040Sstevel@tonic-gate * Gets symbolic link into pathname.
4050Sstevel@tonic-gate */
4060Sstevel@tonic-gate int
nfs3getsymlink(struct nfs_file * cfile,char ** path)4070Sstevel@tonic-gate nfs3getsymlink(struct nfs_file *cfile, char **path)
4080Sstevel@tonic-gate {
4090Sstevel@tonic-gate struct timeval zero_timeout = {0, 0}; /* default */
4100Sstevel@tonic-gate enum clnt_stat status;
4110Sstevel@tonic-gate struct READLINK3res linkres;
4120Sstevel@tonic-gate struct READLINK3args linkargs;
4130Sstevel@tonic-gate static char symlink_path[NFS_MAXPATHLEN];
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate bzero(&linkargs, sizeof (linkargs));
4160Sstevel@tonic-gate linkargs.symlink.data.data_len = cfile->fh.fh3.len;
4170Sstevel@tonic-gate linkargs.symlink.data.data_val = cfile->fh.fh3.data;
4180Sstevel@tonic-gate
4190Sstevel@tonic-gate /*
4200Sstevel@tonic-gate * linkres needs a zeroed buffer to place path data into:
4210Sstevel@tonic-gate */
4220Sstevel@tonic-gate bzero(&linkres, sizeof (linkres));
4230Sstevel@tonic-gate bzero(symlink_path, NFS_MAXPATHLEN);
4240Sstevel@tonic-gate linkres.READLINK3res_u.resok.data = symlink_path;
4250Sstevel@tonic-gate
4260Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC3_READLINK,
427*6747Sga159272 xdr_READLINK3args, (caddr_t)&linkargs,
428*6747Sga159272 xdr_READLINK3res, (caddr_t)&linkres, zero_timeout);
4290Sstevel@tonic-gate if (status != RPC_SUCCESS) {
4300Sstevel@tonic-gate dprintf("nfs3getsymlink: RPC call failed.\n");
4310Sstevel@tonic-gate return (-1);
4320Sstevel@tonic-gate }
4330Sstevel@tonic-gate if (linkres.status != NFS3_OK) {
4340Sstevel@tonic-gate nfs3_error(linkres.status);
4350Sstevel@tonic-gate return (linkres.status);
4360Sstevel@tonic-gate }
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate *path = symlink_path;
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate return (NFS3_OK);
4410Sstevel@tonic-gate }
442