1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * Simple nfs ops - open, close, read, and lseek.
27*0Sstevel@tonic-gate  */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #include <rpc/types.h>
32*0Sstevel@tonic-gate #include <rpc/auth.h>
33*0Sstevel@tonic-gate #include <sys/t_lock.h>
34*0Sstevel@tonic-gate #include "clnt.h"
35*0Sstevel@tonic-gate #include <sys/fcntl.h>
36*0Sstevel@tonic-gate #include <sys/vfs.h>
37*0Sstevel@tonic-gate #include <errno.h>
38*0Sstevel@tonic-gate #include <sys/promif.h>
39*0Sstevel@tonic-gate #include <rpc/xdr.h>
40*0Sstevel@tonic-gate #include "nfs_inet.h"
41*0Sstevel@tonic-gate #include <sys/stat.h>
42*0Sstevel@tonic-gate #include <sys/bootvfs.h>
43*0Sstevel@tonic-gate #include <sys/bootdebug.h>
44*0Sstevel@tonic-gate #include <sys/salib.h>
45*0Sstevel@tonic-gate #include <sys/sacache.h>
46*0Sstevel@tonic-gate #include <rpc/rpc.h>
47*0Sstevel@tonic-gate #include "brpc.h"
48*0Sstevel@tonic-gate #include <rpcsvc/nfs_prot.h>
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #define	dprintf	if (boothowto & RB_DEBUG) printf
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate static struct timeval zero_timeout = {0, 0};	/* default */
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate  * NFS Version 2 specific functions
56*0Sstevel@tonic-gate  */
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate ssize_t
59*0Sstevel@tonic-gate nfsread(struct nfs_file *filep, char *buf, size_t size)
60*0Sstevel@tonic-gate {
61*0Sstevel@tonic-gate 	readargs		read_args;
62*0Sstevel@tonic-gate 	readres			read_res;
63*0Sstevel@tonic-gate 	enum clnt_stat		read_stat;
64*0Sstevel@tonic-gate 	uint_t			readcnt = 0;	/* # bytes read by nfs */
65*0Sstevel@tonic-gate 	uint_t			count = 0;	/* # bytes transferred to buf */
66*0Sstevel@tonic-gate 	int			done = FALSE;	/* last block has come in */
67*0Sstevel@tonic-gate 	int			framing_errs = 0;	/* stack errors */
68*0Sstevel@tonic-gate 	char			*buf_offset;	/* current buffer offset */
69*0Sstevel@tonic-gate 	struct timeval		timeout;
70*0Sstevel@tonic-gate #ifndef i386
71*0Sstevel@tonic-gate 	static uint_t		pos;		/* progress indicator counter */
72*0Sstevel@tonic-gate 	static char		ind[] = "|/-\\";	/* progress indicator */
73*0Sstevel@tonic-gate 	static int		blks_read;
74*0Sstevel@tonic-gate #endif
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	read_args.file = filep->fh.fh2;		/* structure copy */
77*0Sstevel@tonic-gate 	read_args.offset = filep->offset;
78*0Sstevel@tonic-gate 	buf_offset = buf;
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 	/* Optimize for reads of less than one block size */
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate 	if (nfs_readsize == 0)
83*0Sstevel@tonic-gate 		nfs_readsize = READ_SIZE;
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate 	if (size < nfs_readsize)
86*0Sstevel@tonic-gate 		read_args.count = size;
87*0Sstevel@tonic-gate 	else
88*0Sstevel@tonic-gate 		read_args.count = nfs_readsize;
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	do {
91*0Sstevel@tonic-gate 		/* use the user's buffer to stuff the data into. */
92*0Sstevel@tonic-gate 		read_res.readres_u.reply.data.data_val = buf_offset;
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate 		/*
95*0Sstevel@tonic-gate 		 * Handle the case where the file does not end
96*0Sstevel@tonic-gate 		 * on a block boundary.
97*0Sstevel@tonic-gate 		 */
98*0Sstevel@tonic-gate 		if ((count + read_args.count) > size)
99*0Sstevel@tonic-gate 			read_args.count = size - count;
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate 		timeout.tv_sec = NFS_REXMIT_MIN; /* Total wait for call */
102*0Sstevel@tonic-gate 		timeout.tv_usec = 0;
103*0Sstevel@tonic-gate 		do {
104*0Sstevel@tonic-gate 			read_stat = CLNT_CALL(root_CLIENT, NFSPROC_READ,
105*0Sstevel@tonic-gate 			    xdr_readargs, (caddr_t)&read_args,
106*0Sstevel@tonic-gate 			    xdr_readres, (caddr_t)&read_res, timeout);
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 			if (read_stat == RPC_TIMEDOUT) {
109*0Sstevel@tonic-gate 				dprintf("NFS read(%d) timed out. Retrying...\n",
110*0Sstevel@tonic-gate 				    read_args.count);
111*0Sstevel@tonic-gate 				/*
112*0Sstevel@tonic-gate 				 * If the remote is there and trying to respond,
113*0Sstevel@tonic-gate 				 * but our stack is having trouble reassembling
114*0Sstevel@tonic-gate 				 * the reply, reduce the read size in an
115*0Sstevel@tonic-gate 				 * attempt to compensate. Reset the
116*0Sstevel@tonic-gate 				 * transmission and reply wait timers.
117*0Sstevel@tonic-gate 				 */
118*0Sstevel@tonic-gate 				if (errno == ETIMEDOUT)
119*0Sstevel@tonic-gate 					framing_errs++;
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate 				if (framing_errs > NFS_MAX_FERRS &&
122*0Sstevel@tonic-gate 				    read_args.count > NFS_READ_DECR) {
123*0Sstevel@tonic-gate 					read_args.count -= NFS_READ_DECR;
124*0Sstevel@tonic-gate 					nfs_readsize -= NFS_READ_DECR;
125*0Sstevel@tonic-gate 					dprintf("NFS Read size now %d.\n",
126*0Sstevel@tonic-gate 					    nfs_readsize);
127*0Sstevel@tonic-gate 					timeout.tv_sec = NFS_REXMIT_MIN;
128*0Sstevel@tonic-gate 					framing_errs = 0;
129*0Sstevel@tonic-gate 				} else {
130*0Sstevel@tonic-gate 					if (timeout.tv_sec < NFS_REXMIT_MAX)
131*0Sstevel@tonic-gate 						timeout.tv_sec++;
132*0Sstevel@tonic-gate 					else
133*0Sstevel@tonic-gate 						timeout.tv_sec = 0;
134*0Sstevel@tonic-gate 							/* default RPC */
135*0Sstevel@tonic-gate 				}
136*0Sstevel@tonic-gate 			}
137*0Sstevel@tonic-gate 		} while (read_stat == RPC_TIMEDOUT);
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate 		if (read_stat != RPC_SUCCESS)
140*0Sstevel@tonic-gate 			return (-1);
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate 		readcnt = read_res.readres_u.reply.data.data_len;
143*0Sstevel@tonic-gate 		/*
144*0Sstevel@tonic-gate 		 * Handle the case where the file is simply empty, and
145*0Sstevel@tonic-gate 		 * nothing could be read.
146*0Sstevel@tonic-gate 		 */
147*0Sstevel@tonic-gate 		if (readcnt == 0)
148*0Sstevel@tonic-gate 			break; /* eof */
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate 		/*
151*0Sstevel@tonic-gate 		 * Handle the case where the file is smaller than
152*0Sstevel@tonic-gate 		 * the size of the read request, thus the request
153*0Sstevel@tonic-gate 		 * couldn't be completely filled.
154*0Sstevel@tonic-gate 		 */
155*0Sstevel@tonic-gate 		if (readcnt < read_args.count) {
156*0Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
157*0Sstevel@tonic-gate 			if ((boothowto & DBFLAGS) == DBFLAGS)
158*0Sstevel@tonic-gate 				printf("nfsread(): partial read %d"
159*0Sstevel@tonic-gate 					" instead of %d\n",
160*0Sstevel@tonic-gate 					readcnt, read_args.count);
161*0Sstevel@tonic-gate #endif
162*0Sstevel@tonic-gate 			done = TRUE; /* update the counts and exit */
163*0Sstevel@tonic-gate 		}
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate 		/* update various offsets */
166*0Sstevel@tonic-gate 		count += readcnt;
167*0Sstevel@tonic-gate 		filep->offset += readcnt;
168*0Sstevel@tonic-gate 		buf_offset += readcnt;
169*0Sstevel@tonic-gate 		read_args.offset += readcnt;
170*0Sstevel@tonic-gate #ifndef i386
171*0Sstevel@tonic-gate 		/*
172*0Sstevel@tonic-gate 		 * round and round she goes (though not on every block..
173*0Sstevel@tonic-gate 		 * - OBP's take a fair bit of time to actually print stuff)
174*0Sstevel@tonic-gate 		 */
175*0Sstevel@tonic-gate 		if ((blks_read++ & 0x3) == 0)
176*0Sstevel@tonic-gate 			printf("%c\b", ind[pos++ & 3]);
177*0Sstevel@tonic-gate #endif
178*0Sstevel@tonic-gate 	} while (count < size && !done);
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate 	return (count);
181*0Sstevel@tonic-gate }
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate static vtype_t nf_to_vt[] = {
184*0Sstevel@tonic-gate 	VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK
185*0Sstevel@tonic-gate };
186*0Sstevel@tonic-gate 
187*0Sstevel@tonic-gate int
188*0Sstevel@tonic-gate nfsgetattr(struct nfs_file *nfp, struct vattr *vap)
189*0Sstevel@tonic-gate {
190*0Sstevel@tonic-gate 	enum clnt_stat getattr_stat;
191*0Sstevel@tonic-gate 	attrstat getattr_res;
192*0Sstevel@tonic-gate 	fattr *na;
193*0Sstevel@tonic-gate 	struct timeval timeout = {0, 0};	/* default */
194*0Sstevel@tonic-gate 
195*0Sstevel@tonic-gate 	getattr_stat = CLNT_CALL(root_CLIENT, NFSPROC_GETATTR,
196*0Sstevel@tonic-gate 			    xdr_nfs_fh, (caddr_t)&(nfp->fh.fh2),
197*0Sstevel@tonic-gate 			    xdr_attrstat, (caddr_t)&getattr_res, timeout);
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 	if (getattr_stat != RPC_SUCCESS) {
200*0Sstevel@tonic-gate 		dprintf("nfs_getattr: RPC error %d\n", getattr_stat);
201*0Sstevel@tonic-gate 		return (-1);
202*0Sstevel@tonic-gate 	}
203*0Sstevel@tonic-gate 	if (getattr_res.status != NFS_OK) {
204*0Sstevel@tonic-gate 		nfs_error(getattr_res.status);
205*0Sstevel@tonic-gate 		return (getattr_res.status);
206*0Sstevel@tonic-gate 	}
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate 	/* adapted from nattr_to_vattr() in nfs_client.c */
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate 	na = &getattr_res.attrstat_u.attributes;
211*0Sstevel@tonic-gate 	if (vap->va_mask & AT_TYPE) {
212*0Sstevel@tonic-gate 		if (na->type < NFNON || na->type > NFSOCK)
213*0Sstevel@tonic-gate 			vap->va_type = VBAD;
214*0Sstevel@tonic-gate 		else
215*0Sstevel@tonic-gate 			vap->va_type = nf_to_vt[na->type];
216*0Sstevel@tonic-gate 	}
217*0Sstevel@tonic-gate 	if (vap->va_mask & AT_MODE)
218*0Sstevel@tonic-gate 		vap->va_mode = na->mode;
219*0Sstevel@tonic-gate 	if (vap->va_mask & AT_SIZE)
220*0Sstevel@tonic-gate 		vap->va_size = na->size;
221*0Sstevel@tonic-gate 	if (vap->va_mask & AT_NODEID)
222*0Sstevel@tonic-gate 		vap->va_nodeid = na->fileid;
223*0Sstevel@tonic-gate 	if (vap->va_mask & AT_ATIME) {
224*0Sstevel@tonic-gate 		vap->va_atime.tv_sec  = na->atime.seconds;
225*0Sstevel@tonic-gate 		vap->va_atime.tv_nsec = na->atime.useconds * 1000;
226*0Sstevel@tonic-gate 	}
227*0Sstevel@tonic-gate 	if (vap->va_mask & AT_CTIME) {
228*0Sstevel@tonic-gate 		vap->va_ctime.tv_sec  = na->ctime.seconds;
229*0Sstevel@tonic-gate 		vap->va_ctime.tv_nsec = na->ctime.useconds * 1000;
230*0Sstevel@tonic-gate 	}
231*0Sstevel@tonic-gate 	if (vap->va_mask & AT_MTIME) {
232*0Sstevel@tonic-gate 		vap->va_mtime.tv_sec  = na->mtime.seconds;
233*0Sstevel@tonic-gate 		vap->va_mtime.tv_nsec = na->mtime.useconds * 1000;
234*0Sstevel@tonic-gate 	}
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
237*0Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
238*0Sstevel@tonic-gate 		printf("nfs_getattr(): done.\n");
239*0Sstevel@tonic-gate #endif
240*0Sstevel@tonic-gate 	return (getattr_res.status);
241*0Sstevel@tonic-gate }
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate /*
244*0Sstevel@tonic-gate  * Display nfs error messages.
245*0Sstevel@tonic-gate  */
246*0Sstevel@tonic-gate /*ARGSUSED*/
247*0Sstevel@tonic-gate void
248*0Sstevel@tonic-gate nfs_error(enum nfsstat status)
249*0Sstevel@tonic-gate {
250*0Sstevel@tonic-gate 	if (!(boothowto & RB_DEBUG))
251*0Sstevel@tonic-gate 		return;
252*0Sstevel@tonic-gate 
253*0Sstevel@tonic-gate 	switch (status) {
254*0Sstevel@tonic-gate 	case NFSERR_PERM:
255*0Sstevel@tonic-gate 		printf("NFS: Not owner.\n");
256*0Sstevel@tonic-gate 		break;
257*0Sstevel@tonic-gate 	case NFSERR_NOENT:
258*0Sstevel@tonic-gate #ifdef	NFS_OPS_DEBUG
259*0Sstevel@tonic-gate 		printf("NFS: No such file or directory.\n");
260*0Sstevel@tonic-gate #endif	/* NFS_OPS_DEBUG */
261*0Sstevel@tonic-gate 		break;
262*0Sstevel@tonic-gate 	case NFSERR_IO:
263*0Sstevel@tonic-gate 		printf("NFS: IO ERROR occurred on NFS server.\n");
264*0Sstevel@tonic-gate 		break;
265*0Sstevel@tonic-gate 	case NFSERR_NXIO:
266*0Sstevel@tonic-gate 		printf("NFS: No such device or address.\n");
267*0Sstevel@tonic-gate 		break;
268*0Sstevel@tonic-gate 	case NFSERR_ACCES:
269*0Sstevel@tonic-gate 		printf("NFS: Permission denied.\n");
270*0Sstevel@tonic-gate 		break;
271*0Sstevel@tonic-gate 	case NFSERR_EXIST:
272*0Sstevel@tonic-gate 		printf("NFS: File exists.\n");
273*0Sstevel@tonic-gate 		break;
274*0Sstevel@tonic-gate 	case NFSERR_NODEV:
275*0Sstevel@tonic-gate 		printf("NFS: No such device.\n");
276*0Sstevel@tonic-gate 		break;
277*0Sstevel@tonic-gate 	case NFSERR_NOTDIR:
278*0Sstevel@tonic-gate 		printf("NFS: Not a directory.\n");
279*0Sstevel@tonic-gate 		break;
280*0Sstevel@tonic-gate 	case NFSERR_ISDIR:
281*0Sstevel@tonic-gate 		printf("NFS: Is a directory.\n");
282*0Sstevel@tonic-gate 		break;
283*0Sstevel@tonic-gate 	case NFSERR_FBIG:
284*0Sstevel@tonic-gate 		printf("NFS: File too large.\n");
285*0Sstevel@tonic-gate 		break;
286*0Sstevel@tonic-gate 	case NFSERR_NOSPC:
287*0Sstevel@tonic-gate 		printf("NFS: No space left on device.\n");
288*0Sstevel@tonic-gate 		break;
289*0Sstevel@tonic-gate 	case NFSERR_ROFS:
290*0Sstevel@tonic-gate 		printf("NFS: Read-only filesystem.\n");
291*0Sstevel@tonic-gate 		break;
292*0Sstevel@tonic-gate 	case NFSERR_NAMETOOLONG:
293*0Sstevel@tonic-gate 		printf("NFS: File name too long.\n");
294*0Sstevel@tonic-gate 		break;
295*0Sstevel@tonic-gate 	case NFSERR_NOTEMPTY:
296*0Sstevel@tonic-gate 		printf("NFS: Directory not empty.\n");
297*0Sstevel@tonic-gate 		break;
298*0Sstevel@tonic-gate 	case NFSERR_DQUOT:
299*0Sstevel@tonic-gate 		printf("NFS: Disk quota exceeded.\n");
300*0Sstevel@tonic-gate 		break;
301*0Sstevel@tonic-gate 	case NFSERR_STALE:
302*0Sstevel@tonic-gate 		printf("NFS: Stale file handle.\n");
303*0Sstevel@tonic-gate 		break;
304*0Sstevel@tonic-gate 	case NFSERR_WFLUSH:
305*0Sstevel@tonic-gate 		printf("NFS: server's write cache has been flushed.\n");
306*0Sstevel@tonic-gate 		break;
307*0Sstevel@tonic-gate 	default:
308*0Sstevel@tonic-gate 		printf("NFS: unknown error.\n");
309*0Sstevel@tonic-gate 		break;
310*0Sstevel@tonic-gate 	}
311*0Sstevel@tonic-gate }
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate struct nfs_file *
314*0Sstevel@tonic-gate nfslookup(struct nfs_file *dir, char *name, int *nstat)
315*0Sstevel@tonic-gate {
316*0Sstevel@tonic-gate 	static struct nfs_file cd;
317*0Sstevel@tonic-gate 	diropargs dirop;
318*0Sstevel@tonic-gate 	diropres res_lookup;
319*0Sstevel@tonic-gate 	enum clnt_stat status;
320*0Sstevel@tonic-gate 
321*0Sstevel@tonic-gate 	*nstat = (int)NFS_OK;
322*0Sstevel@tonic-gate 
323*0Sstevel@tonic-gate 	bcopy(&dir->fh.fh2, &dirop.dir, NFS_FHSIZE);
324*0Sstevel@tonic-gate 	dirop.name = name;
325*0Sstevel@tonic-gate 
326*0Sstevel@tonic-gate 	status = CLNT_CALL(root_CLIENT, NFSPROC_LOOKUP, xdr_diropargs,
327*0Sstevel@tonic-gate 			(caddr_t)&dirop, xdr_diropres, (caddr_t)&res_lookup,
328*0Sstevel@tonic-gate 			zero_timeout);
329*0Sstevel@tonic-gate 	if (status != RPC_SUCCESS) {
330*0Sstevel@tonic-gate 		dprintf("lookup: RPC error.\n");
331*0Sstevel@tonic-gate 		return (NULL);
332*0Sstevel@tonic-gate 	}
333*0Sstevel@tonic-gate 	if (res_lookup.status != NFS_OK) {
334*0Sstevel@tonic-gate 		nfs_error(res_lookup.status);
335*0Sstevel@tonic-gate 		*nstat = (int)res_lookup.status;
336*0Sstevel@tonic-gate 		return (NULL);
337*0Sstevel@tonic-gate 	}
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	bzero((caddr_t)&cd, sizeof (struct nfs_file));
340*0Sstevel@tonic-gate 	cd.version = NFS_VERSION;
341*0Sstevel@tonic-gate 	cd.ftype.type2 = res_lookup.diropres_u.diropres.attributes.type;
342*0Sstevel@tonic-gate 	bcopy(&res_lookup.diropres_u.diropres.file, &cd.fh.fh2, NFS_FHSIZE);
343*0Sstevel@tonic-gate 	return (&cd);
344*0Sstevel@tonic-gate }
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate /*
347*0Sstevel@tonic-gate  * Gets symbolic link into pathname.
348*0Sstevel@tonic-gate  */
349*0Sstevel@tonic-gate int
350*0Sstevel@tonic-gate nfsgetsymlink(struct nfs_file *cfile, char **path)
351*0Sstevel@tonic-gate {
352*0Sstevel@tonic-gate 	enum clnt_stat status;
353*0Sstevel@tonic-gate 	struct readlinkres linkres;
354*0Sstevel@tonic-gate 	static char symlink_path[NFS_MAXPATHLEN];
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate 	/*
357*0Sstevel@tonic-gate 	 * linkres needs a zeroed buffer to place path data into:
358*0Sstevel@tonic-gate 	 */
359*0Sstevel@tonic-gate 	bzero(symlink_path, NFS_MAXPATHLEN);
360*0Sstevel@tonic-gate 	linkres.readlinkres_u.data = &symlink_path[0];
361*0Sstevel@tonic-gate 
362*0Sstevel@tonic-gate 	status = CLNT_CALL(root_CLIENT, NFSPROC_READLINK,
363*0Sstevel@tonic-gate 		    xdr_nfs_fh, (caddr_t)&cfile->fh.fh2,
364*0Sstevel@tonic-gate 		    xdr_readlinkres, (caddr_t)&linkres, zero_timeout);
365*0Sstevel@tonic-gate 	if (status != RPC_SUCCESS) {
366*0Sstevel@tonic-gate 		dprintf("nfsgetsymlink: RPC call failed.\n");
367*0Sstevel@tonic-gate 		return (-1);
368*0Sstevel@tonic-gate 	}
369*0Sstevel@tonic-gate 	if (linkres.status != NFS_OK) {
370*0Sstevel@tonic-gate 		nfs_error(linkres.status);
371*0Sstevel@tonic-gate 		return (linkres.status);
372*0Sstevel@tonic-gate 	}
373*0Sstevel@tonic-gate 
374*0Sstevel@tonic-gate 	*path = linkres.readlinkres_u.data;
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 	return (NFS_OK);
377*0Sstevel@tonic-gate }
378