xref: /titanic_53/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_nfs.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1991-2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
32*7c478bd9Sstevel@tonic-gate #include <setjmp.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <rpc/types.h>
35*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
36*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
37*7c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
38*7c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
39*7c478bd9Sstevel@tonic-gate #include <string.h>
40*7c478bd9Sstevel@tonic-gate #include "snoop.h"
41*7c478bd9Sstevel@tonic-gate #include "snoop_nfs.h"
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
44*7c478bd9Sstevel@tonic-gate #include <rpcsvc/nfs_prot.h>
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate static char *perms(int);
47*7c478bd9Sstevel@tonic-gate static char *filetype(int);
48*7c478bd9Sstevel@tonic-gate static char *sum_readdirres(void);
49*7c478bd9Sstevel@tonic-gate static void detail_readdirres(void);
50*7c478bd9Sstevel@tonic-gate static void detail_diroparg(void);
51*7c478bd9Sstevel@tonic-gate static void nfscall2(int);
52*7c478bd9Sstevel@tonic-gate static void nfsreply2(int);
53*7c478bd9Sstevel@tonic-gate static void detail_mode(int);
54*7c478bd9Sstevel@tonic-gate static void detail_sattr(void);
55*7c478bd9Sstevel@tonic-gate static void interpret_nfs2(int, int, int, int, int, char *, int);
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate extern jmp_buf xdr_err;
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate static char *procnames_short[] = {
60*7c478bd9Sstevel@tonic-gate 	"NULL2",	/*  0 */
61*7c478bd9Sstevel@tonic-gate 	"GETATTR2",	/*  1 */
62*7c478bd9Sstevel@tonic-gate 	"SETATTR2",	/*  2 */
63*7c478bd9Sstevel@tonic-gate 	"ROOT2",	/*  3 */
64*7c478bd9Sstevel@tonic-gate 	"LOOKUP2",	/*  4 */
65*7c478bd9Sstevel@tonic-gate 	"READLINK2",	/*  5 */
66*7c478bd9Sstevel@tonic-gate 	"READ2",	/*  6 */
67*7c478bd9Sstevel@tonic-gate 	"WRITECACHE2",	/*  7 */
68*7c478bd9Sstevel@tonic-gate 	"WRITE2",	/*  8 */
69*7c478bd9Sstevel@tonic-gate 	"CREATE2",	/*  9 */
70*7c478bd9Sstevel@tonic-gate 	"REMOVE2",	/* 10 */
71*7c478bd9Sstevel@tonic-gate 	"RENAME2",	/* 11 */
72*7c478bd9Sstevel@tonic-gate 	"LINK2",	/* 12 */
73*7c478bd9Sstevel@tonic-gate 	"SYMLINK2",	/* 13 */
74*7c478bd9Sstevel@tonic-gate 	"MKDIR2",	/* 14 */
75*7c478bd9Sstevel@tonic-gate 	"RMDIR2",	/* 15 */
76*7c478bd9Sstevel@tonic-gate 	"READDIR2",	/* 16 */
77*7c478bd9Sstevel@tonic-gate 	"STATFS2",	/* 17 */
78*7c478bd9Sstevel@tonic-gate };
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate static char *procnames_long[] = {
81*7c478bd9Sstevel@tonic-gate 	"Null procedure",		/*  0 */
82*7c478bd9Sstevel@tonic-gate 	"Get file attributes",		/*  1 */
83*7c478bd9Sstevel@tonic-gate 	"Set file attributes",		/*  2 */
84*7c478bd9Sstevel@tonic-gate 	"Get root filehandle",		/*  3 */
85*7c478bd9Sstevel@tonic-gate 	"Look up file name",		/*  4 */
86*7c478bd9Sstevel@tonic-gate 	"Read from symbolic link",	/*  5 */
87*7c478bd9Sstevel@tonic-gate 	"Read from file",		/*  6 */
88*7c478bd9Sstevel@tonic-gate 	"Write to cache",		/*  7 */
89*7c478bd9Sstevel@tonic-gate 	"Write to file",		/*  8 */
90*7c478bd9Sstevel@tonic-gate 	"Create file",			/*  9 */
91*7c478bd9Sstevel@tonic-gate 	"Remove file",			/* 10 */
92*7c478bd9Sstevel@tonic-gate 	"Rename",			/* 11 */
93*7c478bd9Sstevel@tonic-gate 	"Link",				/* 12 */
94*7c478bd9Sstevel@tonic-gate 	"Make symbolic link",		/* 13 */
95*7c478bd9Sstevel@tonic-gate 	"Make directory",		/* 14 */
96*7c478bd9Sstevel@tonic-gate 	"Remove directory",		/* 15 */
97*7c478bd9Sstevel@tonic-gate 	"Read from directory",		/* 16 */
98*7c478bd9Sstevel@tonic-gate 	"Get filesystem attributes",	/* 17 */
99*7c478bd9Sstevel@tonic-gate };
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate #define	MAXPROC	17
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
104*7c478bd9Sstevel@tonic-gate void
interpret_nfs(flags,type,xid,vers,proc,data,len)105*7c478bd9Sstevel@tonic-gate interpret_nfs(flags, type, xid, vers, proc, data, len)
106*7c478bd9Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
107*7c478bd9Sstevel@tonic-gate 	char *data;
108*7c478bd9Sstevel@tonic-gate 	int len;
109*7c478bd9Sstevel@tonic-gate {
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	if (vers == 2) {
112*7c478bd9Sstevel@tonic-gate 		interpret_nfs2(flags, type, xid, vers, proc, data, len);
113*7c478bd9Sstevel@tonic-gate 		return;
114*7c478bd9Sstevel@tonic-gate 	}
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	if (vers == 3) {
117*7c478bd9Sstevel@tonic-gate 		interpret_nfs3(flags, type, xid, vers, proc, data, len);
118*7c478bd9Sstevel@tonic-gate 		return;
119*7c478bd9Sstevel@tonic-gate 	}
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	if (vers == 4) {
122*7c478bd9Sstevel@tonic-gate 		interpret_nfs4(flags, type, xid, vers, proc, data, len);
123*7c478bd9Sstevel@tonic-gate 		return;
124*7c478bd9Sstevel@tonic-gate 	}
125*7c478bd9Sstevel@tonic-gate }
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate static void
interpret_nfs2(flags,type,xid,vers,proc,data,len)128*7c478bd9Sstevel@tonic-gate interpret_nfs2(flags, type, xid, vers, proc, data, len)
129*7c478bd9Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
130*7c478bd9Sstevel@tonic-gate 	char *data;
131*7c478bd9Sstevel@tonic-gate 	int len;
132*7c478bd9Sstevel@tonic-gate {
133*7c478bd9Sstevel@tonic-gate 	char *line;
134*7c478bd9Sstevel@tonic-gate 	char buff[NFS_MAXPATHLEN + 1];
135*7c478bd9Sstevel@tonic-gate 	int off, sz;
136*7c478bd9Sstevel@tonic-gate 	char *fh;
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	if (proc < 0 || proc > MAXPROC)
139*7c478bd9Sstevel@tonic-gate 		return;
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
142*7c478bd9Sstevel@tonic-gate 		line = get_sum_line();
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 		if (type == CALL) {
145*7c478bd9Sstevel@tonic-gate 			(void) sprintf(line,
146*7c478bd9Sstevel@tonic-gate 				"NFS C %s",
147*7c478bd9Sstevel@tonic-gate 				procnames_short[proc]);
148*7c478bd9Sstevel@tonic-gate 			line += strlen(line);
149*7c478bd9Sstevel@tonic-gate 			switch (proc) {
150*7c478bd9Sstevel@tonic-gate 			case NFSPROC_GETATTR:
151*7c478bd9Sstevel@tonic-gate 			case NFSPROC_READLINK:
152*7c478bd9Sstevel@tonic-gate 			case NFSPROC_STATFS:
153*7c478bd9Sstevel@tonic-gate 			case NFSPROC_SETATTR:
154*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, sum_nfsfh());
155*7c478bd9Sstevel@tonic-gate 				break;
156*7c478bd9Sstevel@tonic-gate 			case NFSPROC_LOOKUP:
157*7c478bd9Sstevel@tonic-gate 			case NFSPROC_REMOVE:
158*7c478bd9Sstevel@tonic-gate 			case NFSPROC_RMDIR:
159*7c478bd9Sstevel@tonic-gate 			case NFSPROC_CREATE:
160*7c478bd9Sstevel@tonic-gate 			case NFSPROC_MKDIR:
161*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
162*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s %s",
163*7c478bd9Sstevel@tonic-gate 					fh,
164*7c478bd9Sstevel@tonic-gate 					getxdr_string(buff, NFS_MAXNAMLEN));
165*7c478bd9Sstevel@tonic-gate 				break;
166*7c478bd9Sstevel@tonic-gate 			case NFSPROC_WRITE:
167*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
168*7c478bd9Sstevel@tonic-gate 				(void) getxdr_long();	/* beginoff */
169*7c478bd9Sstevel@tonic-gate 				off = getxdr_long();
170*7c478bd9Sstevel@tonic-gate 				(void) getxdr_long();	/* totalcount */
171*7c478bd9Sstevel@tonic-gate 				sz  = getxdr_long();
172*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s at %d for %d",
173*7c478bd9Sstevel@tonic-gate 					fh, off, sz);
174*7c478bd9Sstevel@tonic-gate 				break;
175*7c478bd9Sstevel@tonic-gate 			case NFSPROC_RENAME:
176*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
177*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s %s",
178*7c478bd9Sstevel@tonic-gate 					fh,
179*7c478bd9Sstevel@tonic-gate 					getxdr_string(buff, NFS_MAXNAMLEN));
180*7c478bd9Sstevel@tonic-gate 				line += strlen(line);
181*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
182*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, " to%s %s",
183*7c478bd9Sstevel@tonic-gate 					fh,
184*7c478bd9Sstevel@tonic-gate 					getxdr_string(buff, NFS_MAXNAMLEN));
185*7c478bd9Sstevel@tonic-gate 				break;
186*7c478bd9Sstevel@tonic-gate 			case NFSPROC_LINK:
187*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
188*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s", fh);
189*7c478bd9Sstevel@tonic-gate 				line += strlen(line);
190*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
191*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, " to%s %s",
192*7c478bd9Sstevel@tonic-gate 					fh,
193*7c478bd9Sstevel@tonic-gate 					getxdr_string(buff, NFS_MAXNAMLEN));
194*7c478bd9Sstevel@tonic-gate 				break;
195*7c478bd9Sstevel@tonic-gate 			case NFSPROC_SYMLINK:
196*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
197*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s %s",
198*7c478bd9Sstevel@tonic-gate 					fh,
199*7c478bd9Sstevel@tonic-gate 					getxdr_string(buff, NFS_MAXNAMLEN));
200*7c478bd9Sstevel@tonic-gate 				line += strlen(line);
201*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, " to %s",
202*7c478bd9Sstevel@tonic-gate 					getxdr_string(buff, NFS_MAXPATHLEN));
203*7c478bd9Sstevel@tonic-gate 				break;
204*7c478bd9Sstevel@tonic-gate 			case NFSPROC_READDIR:
205*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
206*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s Cookie=%lu",
207*7c478bd9Sstevel@tonic-gate 					fh, getxdr_u_long());
208*7c478bd9Sstevel@tonic-gate 				break;
209*7c478bd9Sstevel@tonic-gate 			case NFSPROC_READ:
210*7c478bd9Sstevel@tonic-gate 				fh = sum_nfsfh();
211*7c478bd9Sstevel@tonic-gate 				off = getxdr_long();
212*7c478bd9Sstevel@tonic-gate 				sz  = getxdr_long();
213*7c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s at %d for %d",
214*7c478bd9Sstevel@tonic-gate 					fh, off, sz);
215*7c478bd9Sstevel@tonic-gate 				break;
216*7c478bd9Sstevel@tonic-gate 			default:
217*7c478bd9Sstevel@tonic-gate 				break;
218*7c478bd9Sstevel@tonic-gate 			}
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate 			check_retransmit(line, (ulong_t)xid);
221*7c478bd9Sstevel@tonic-gate 		} else {
222*7c478bd9Sstevel@tonic-gate 			(void) sprintf(line, "NFS R %s ",
223*7c478bd9Sstevel@tonic-gate 				procnames_short[proc]);
224*7c478bd9Sstevel@tonic-gate 			line += strlen(line);
225*7c478bd9Sstevel@tonic-gate 			switch (proc) {
226*7c478bd9Sstevel@tonic-gate 			case NFSPROC_CREATE:
227*7c478bd9Sstevel@tonic-gate 			case NFSPROC_MKDIR:
228*7c478bd9Sstevel@tonic-gate 			case NFSPROC_LOOKUP:
229*7c478bd9Sstevel@tonic-gate 				if (sum_nfsstat(line) == 0) {
230*7c478bd9Sstevel@tonic-gate 					line += strlen(line);
231*7c478bd9Sstevel@tonic-gate 					(void) sprintf(line, sum_nfsfh());
232*7c478bd9Sstevel@tonic-gate 				}
233*7c478bd9Sstevel@tonic-gate 				break;
234*7c478bd9Sstevel@tonic-gate 			case NFSPROC_READLINK:
235*7c478bd9Sstevel@tonic-gate 				if (sum_nfsstat(line) == 0) {
236*7c478bd9Sstevel@tonic-gate 					line += strlen(line);
237*7c478bd9Sstevel@tonic-gate 					(void) sprintf(line, " (Path=%s)",
238*7c478bd9Sstevel@tonic-gate 						getxdr_string(buff,
239*7c478bd9Sstevel@tonic-gate 							NFS_MAXPATHLEN));
240*7c478bd9Sstevel@tonic-gate 				}
241*7c478bd9Sstevel@tonic-gate 				break;
242*7c478bd9Sstevel@tonic-gate 			case NFSPROC_GETATTR:
243*7c478bd9Sstevel@tonic-gate 			case NFSPROC_SYMLINK:
244*7c478bd9Sstevel@tonic-gate 			case NFSPROC_STATFS:
245*7c478bd9Sstevel@tonic-gate 			case NFSPROC_SETATTR:
246*7c478bd9Sstevel@tonic-gate 			case NFSPROC_REMOVE:
247*7c478bd9Sstevel@tonic-gate 			case NFSPROC_RMDIR:
248*7c478bd9Sstevel@tonic-gate 			case NFSPROC_WRITE:
249*7c478bd9Sstevel@tonic-gate 			case NFSPROC_RENAME:
250*7c478bd9Sstevel@tonic-gate 			case NFSPROC_LINK:
251*7c478bd9Sstevel@tonic-gate 				(void) sum_nfsstat(line);
252*7c478bd9Sstevel@tonic-gate 				break;
253*7c478bd9Sstevel@tonic-gate 			case NFSPROC_READDIR:
254*7c478bd9Sstevel@tonic-gate 				if (sum_nfsstat(line) == 0) {
255*7c478bd9Sstevel@tonic-gate 					line += strlen(line);
256*7c478bd9Sstevel@tonic-gate 					(void) strcat(line, sum_readdirres());
257*7c478bd9Sstevel@tonic-gate 				}
258*7c478bd9Sstevel@tonic-gate 				break;
259*7c478bd9Sstevel@tonic-gate 			case NFSPROC_READ:
260*7c478bd9Sstevel@tonic-gate 				if (sum_nfsstat(line) == 0) {
261*7c478bd9Sstevel@tonic-gate 					line += strlen(line);
262*7c478bd9Sstevel@tonic-gate 					xdr_skip(68); /* fattrs */
263*7c478bd9Sstevel@tonic-gate 					(void) sprintf(line, " (%ld bytes)",
264*7c478bd9Sstevel@tonic-gate 						getxdr_long());
265*7c478bd9Sstevel@tonic-gate 				}
266*7c478bd9Sstevel@tonic-gate 				break;
267*7c478bd9Sstevel@tonic-gate 			default:
268*7c478bd9Sstevel@tonic-gate 				break;
269*7c478bd9Sstevel@tonic-gate 			}
270*7c478bd9Sstevel@tonic-gate 		}
271*7c478bd9Sstevel@tonic-gate 	}
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
274*7c478bd9Sstevel@tonic-gate 		show_header("NFS:  ", "Sun NFS", len);
275*7c478bd9Sstevel@tonic-gate 		show_space();
276*7c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0), "Proc = %d (%s)",
277*7c478bd9Sstevel@tonic-gate 			proc, procnames_long[proc]);
278*7c478bd9Sstevel@tonic-gate 		if (type == CALL)
279*7c478bd9Sstevel@tonic-gate 			nfscall2(proc);
280*7c478bd9Sstevel@tonic-gate 		else
281*7c478bd9Sstevel@tonic-gate 			nfsreply2(proc);
282*7c478bd9Sstevel@tonic-gate 		show_trailer();
283*7c478bd9Sstevel@tonic-gate 	}
284*7c478bd9Sstevel@tonic-gate }
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate /*
287*7c478bd9Sstevel@tonic-gate  *  Print out version 2 NFS call packets
288*7c478bd9Sstevel@tonic-gate  */
289*7c478bd9Sstevel@tonic-gate static void
nfscall2(proc)290*7c478bd9Sstevel@tonic-gate nfscall2(proc)
291*7c478bd9Sstevel@tonic-gate 	int proc;
292*7c478bd9Sstevel@tonic-gate {
293*7c478bd9Sstevel@tonic-gate 	switch (proc) {
294*7c478bd9Sstevel@tonic-gate 	case NFSPROC_GETATTR:
295*7c478bd9Sstevel@tonic-gate 	case NFSPROC_READLINK:
296*7c478bd9Sstevel@tonic-gate 	case NFSPROC_STATFS:
297*7c478bd9Sstevel@tonic-gate 		detail_nfsfh();
298*7c478bd9Sstevel@tonic-gate 		break;
299*7c478bd9Sstevel@tonic-gate 	case NFSPROC_SETATTR:
300*7c478bd9Sstevel@tonic-gate 		detail_nfsfh();
301*7c478bd9Sstevel@tonic-gate 		detail_sattr();
302*7c478bd9Sstevel@tonic-gate 		break;
303*7c478bd9Sstevel@tonic-gate 	case NFSPROC_LOOKUP:
304*7c478bd9Sstevel@tonic-gate 	case NFSPROC_REMOVE:
305*7c478bd9Sstevel@tonic-gate 	case NFSPROC_RMDIR:
306*7c478bd9Sstevel@tonic-gate 		detail_diroparg();
307*7c478bd9Sstevel@tonic-gate 		break;
308*7c478bd9Sstevel@tonic-gate 	case NFSPROC_MKDIR:
309*7c478bd9Sstevel@tonic-gate 	case NFSPROC_CREATE:
310*7c478bd9Sstevel@tonic-gate 		detail_diroparg();
311*7c478bd9Sstevel@tonic-gate 		detail_sattr();
312*7c478bd9Sstevel@tonic-gate 		break;
313*7c478bd9Sstevel@tonic-gate 	case NFSPROC_WRITE:
314*7c478bd9Sstevel@tonic-gate 		detail_nfsfh();
315*7c478bd9Sstevel@tonic-gate 		(void) getxdr_long();	/* begoff */
316*7c478bd9Sstevel@tonic-gate 		(void) showxdr_long("Offset = %d");
317*7c478bd9Sstevel@tonic-gate 		(void) getxdr_long();	/* totalcount */
318*7c478bd9Sstevel@tonic-gate 		(void) showxdr_long("(%d bytes(s) of data)");
319*7c478bd9Sstevel@tonic-gate 		break;
320*7c478bd9Sstevel@tonic-gate 	case NFSPROC_RENAME:
321*7c478bd9Sstevel@tonic-gate 		detail_diroparg();
322*7c478bd9Sstevel@tonic-gate 		detail_diroparg();
323*7c478bd9Sstevel@tonic-gate 		break;
324*7c478bd9Sstevel@tonic-gate 	case NFSPROC_LINK:
325*7c478bd9Sstevel@tonic-gate 		detail_nfsfh();
326*7c478bd9Sstevel@tonic-gate 		detail_diroparg();
327*7c478bd9Sstevel@tonic-gate 		break;
328*7c478bd9Sstevel@tonic-gate 	case NFSPROC_SYMLINK:
329*7c478bd9Sstevel@tonic-gate 		detail_diroparg();
330*7c478bd9Sstevel@tonic-gate 		(void) showxdr_string(NFS_MAXPATHLEN, "Path = %s");
331*7c478bd9Sstevel@tonic-gate 		detail_sattr();
332*7c478bd9Sstevel@tonic-gate 		break;
333*7c478bd9Sstevel@tonic-gate 	case NFSPROC_READDIR:
334*7c478bd9Sstevel@tonic-gate 		detail_nfsfh();
335*7c478bd9Sstevel@tonic-gate 		(void) showxdr_u_long("Cookie = %lu");
336*7c478bd9Sstevel@tonic-gate 		(void) showxdr_long("Count = %d");
337*7c478bd9Sstevel@tonic-gate 		break;
338*7c478bd9Sstevel@tonic-gate 	case NFSPROC_READ:
339*7c478bd9Sstevel@tonic-gate 		detail_nfsfh();
340*7c478bd9Sstevel@tonic-gate 		(void) showxdr_long("Offset = %d");
341*7c478bd9Sstevel@tonic-gate 		(void) showxdr_long("Count = %d");
342*7c478bd9Sstevel@tonic-gate 		break;
343*7c478bd9Sstevel@tonic-gate 	default:
344*7c478bd9Sstevel@tonic-gate 		break;
345*7c478bd9Sstevel@tonic-gate 	}
346*7c478bd9Sstevel@tonic-gate }
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate /*
349*7c478bd9Sstevel@tonic-gate  *  Print out version 2 NFS reply packets
350*7c478bd9Sstevel@tonic-gate  */
351*7c478bd9Sstevel@tonic-gate static void
nfsreply2(proc)352*7c478bd9Sstevel@tonic-gate nfsreply2(proc)
353*7c478bd9Sstevel@tonic-gate 	int proc;
354*7c478bd9Sstevel@tonic-gate {
355*7c478bd9Sstevel@tonic-gate 	switch (proc) {
356*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_GETATTR:
357*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_SETATTR:
358*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_WRITE:
359*7c478bd9Sstevel@tonic-gate 		/* attrstat */
360*7c478bd9Sstevel@tonic-gate 		if (detail_nfsstat() == 0) {
361*7c478bd9Sstevel@tonic-gate 			detail_fattr();
362*7c478bd9Sstevel@tonic-gate 		}
363*7c478bd9Sstevel@tonic-gate 		break;
364*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_LOOKUP:
365*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_CREATE:
366*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_MKDIR:
367*7c478bd9Sstevel@tonic-gate 		/* diropres */
368*7c478bd9Sstevel@tonic-gate 		if (detail_nfsstat() == 0) {
369*7c478bd9Sstevel@tonic-gate 			detail_nfsfh();
370*7c478bd9Sstevel@tonic-gate 			detail_fattr();
371*7c478bd9Sstevel@tonic-gate 		}
372*7c478bd9Sstevel@tonic-gate 		break;
373*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_READLINK:
374*7c478bd9Sstevel@tonic-gate 		/* readlinkres */
375*7c478bd9Sstevel@tonic-gate 		if (detail_nfsstat() == 0) {
376*7c478bd9Sstevel@tonic-gate 			(void) showxdr_string(NFS_MAXPATHLEN, "Path = %s");
377*7c478bd9Sstevel@tonic-gate 		}
378*7c478bd9Sstevel@tonic-gate 		break;
379*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_READ:
380*7c478bd9Sstevel@tonic-gate 		/* readres */
381*7c478bd9Sstevel@tonic-gate 		if (detail_nfsstat() == 0) {
382*7c478bd9Sstevel@tonic-gate 			detail_fattr();
383*7c478bd9Sstevel@tonic-gate 			(void) showxdr_long("(%d byte(s) of data)");
384*7c478bd9Sstevel@tonic-gate 		}
385*7c478bd9Sstevel@tonic-gate 		break;
386*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_REMOVE:
387*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_RENAME:
388*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_LINK:
389*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_SYMLINK:
390*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_RMDIR:
391*7c478bd9Sstevel@tonic-gate 		/* stat */
392*7c478bd9Sstevel@tonic-gate 		detail_nfsstat();
393*7c478bd9Sstevel@tonic-gate 		break;
394*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_READDIR:
395*7c478bd9Sstevel@tonic-gate 		/* readdirres */
396*7c478bd9Sstevel@tonic-gate 		if (detail_nfsstat() == 0)
397*7c478bd9Sstevel@tonic-gate 			detail_readdirres();
398*7c478bd9Sstevel@tonic-gate 		break;
399*7c478bd9Sstevel@tonic-gate 	    case NFSPROC_STATFS:
400*7c478bd9Sstevel@tonic-gate 		/* statfsres */
401*7c478bd9Sstevel@tonic-gate 		if (detail_nfsstat() == 0) {
402*7c478bd9Sstevel@tonic-gate 			(void) showxdr_long("Transfer size = %d");
403*7c478bd9Sstevel@tonic-gate 			(void) showxdr_long("Block size = %d");
404*7c478bd9Sstevel@tonic-gate 			(void) showxdr_long("Total blocks = %d");
405*7c478bd9Sstevel@tonic-gate 			(void) showxdr_long("Free blocks = %d");
406*7c478bd9Sstevel@tonic-gate 			(void) showxdr_long("Available blocks = %d");
407*7c478bd9Sstevel@tonic-gate 		}
408*7c478bd9Sstevel@tonic-gate 		break;
409*7c478bd9Sstevel@tonic-gate 	    default:
410*7c478bd9Sstevel@tonic-gate 		break;
411*7c478bd9Sstevel@tonic-gate 	}
412*7c478bd9Sstevel@tonic-gate }
413*7c478bd9Sstevel@tonic-gate 
414*7c478bd9Sstevel@tonic-gate static void
detail_diroparg()415*7c478bd9Sstevel@tonic-gate detail_diroparg()
416*7c478bd9Sstevel@tonic-gate {
417*7c478bd9Sstevel@tonic-gate 	detail_nfsfh();
418*7c478bd9Sstevel@tonic-gate 	(void) showxdr_string(NFS_MAXPATHLEN, "File name = %s");
419*7c478bd9Sstevel@tonic-gate }
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate /*
422*7c478bd9Sstevel@tonic-gate  * V2 NFS protocol was implicitly linked with SunOS errnos.
423*7c478bd9Sstevel@tonic-gate  * Some of the errno values changed in SVr4.
424*7c478bd9Sstevel@tonic-gate  * Need to map errno value so that SVr4 snoop will interpret
425*7c478bd9Sstevel@tonic-gate  * them correctly.
426*7c478bd9Sstevel@tonic-gate  */
427*7c478bd9Sstevel@tonic-gate static char *
statusmsg(status)428*7c478bd9Sstevel@tonic-gate statusmsg(status)
429*7c478bd9Sstevel@tonic-gate 	ulong_t status;
430*7c478bd9Sstevel@tonic-gate {
431*7c478bd9Sstevel@tonic-gate 	switch (status) {
432*7c478bd9Sstevel@tonic-gate 	case NFS_OK: return ("OK");
433*7c478bd9Sstevel@tonic-gate 	case NFSERR_PERM: return ("Not owner");
434*7c478bd9Sstevel@tonic-gate 	case NFSERR_NOENT: return ("No such file or directory");
435*7c478bd9Sstevel@tonic-gate 	case NFSERR_IO: return ("I/O error");
436*7c478bd9Sstevel@tonic-gate 	case NFSERR_NXIO: return ("No such device or address");
437*7c478bd9Sstevel@tonic-gate 	case NFSERR_ACCES: return ("Permission denied");
438*7c478bd9Sstevel@tonic-gate 	case NFSERR_EXIST: return ("File exists");
439*7c478bd9Sstevel@tonic-gate 	case NFSERR_XDEV: return ("Cross-device link");
440*7c478bd9Sstevel@tonic-gate 	case NFSERR_NODEV: return ("No such device");
441*7c478bd9Sstevel@tonic-gate 	case NFSERR_NOTDIR: return ("Not a directory");
442*7c478bd9Sstevel@tonic-gate 	case NFSERR_ISDIR: return ("Is a directory");
443*7c478bd9Sstevel@tonic-gate 	case NFSERR_INVAL: return ("Invalid argument");
444*7c478bd9Sstevel@tonic-gate 	case NFSERR_FBIG: return ("File too large");
445*7c478bd9Sstevel@tonic-gate 	case NFSERR_NOSPC: return ("No space left on device");
446*7c478bd9Sstevel@tonic-gate 	case NFSERR_ROFS: return ("Read-only file system");
447*7c478bd9Sstevel@tonic-gate 	case NFSERR_OPNOTSUPP: return ("Operation not supported");
448*7c478bd9Sstevel@tonic-gate 	case NFSERR_NAMETOOLONG: return ("File name too long");
449*7c478bd9Sstevel@tonic-gate 	case NFSERR_NOTEMPTY: return ("Directory not empty");
450*7c478bd9Sstevel@tonic-gate 	case NFSERR_DQUOT: return ("Disc quota exceeded");
451*7c478bd9Sstevel@tonic-gate 	case NFSERR_STALE: return ("Stale NFS file handle");
452*7c478bd9Sstevel@tonic-gate 	case NFSERR_REMOTE: return ("Object is remote");
453*7c478bd9Sstevel@tonic-gate 	case NFSERR_WFLUSH: return ("write cache flushed");
454*7c478bd9Sstevel@tonic-gate 	default: return ("(unknown error)");
455*7c478bd9Sstevel@tonic-gate 	}
456*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
457*7c478bd9Sstevel@tonic-gate }
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate int
sum_nfsstat(line)460*7c478bd9Sstevel@tonic-gate sum_nfsstat(line)
461*7c478bd9Sstevel@tonic-gate 	char *line;
462*7c478bd9Sstevel@tonic-gate {
463*7c478bd9Sstevel@tonic-gate 	ulong_t status;
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate 	status = getxdr_long();
466*7c478bd9Sstevel@tonic-gate 	(void) strcpy(line, statusmsg(status));
467*7c478bd9Sstevel@tonic-gate 	return (status);
468*7c478bd9Sstevel@tonic-gate }
469*7c478bd9Sstevel@tonic-gate 
470*7c478bd9Sstevel@tonic-gate int
detail_nfsstat()471*7c478bd9Sstevel@tonic-gate detail_nfsstat()
472*7c478bd9Sstevel@tonic-gate {
473*7c478bd9Sstevel@tonic-gate 	ulong_t status;
474*7c478bd9Sstevel@tonic-gate 	int pos;
475*7c478bd9Sstevel@tonic-gate 
476*7c478bd9Sstevel@tonic-gate 	pos = getxdr_pos();
477*7c478bd9Sstevel@tonic-gate 	status = getxdr_long();
478*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(pos, getxdr_pos()),
479*7c478bd9Sstevel@tonic-gate 		"Status = %lu (%s)",
480*7c478bd9Sstevel@tonic-gate 		status, statusmsg(status));
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate 	return ((int)status);
483*7c478bd9Sstevel@tonic-gate }
484*7c478bd9Sstevel@tonic-gate 
485*7c478bd9Sstevel@tonic-gate int
sum_filehandle(len)486*7c478bd9Sstevel@tonic-gate sum_filehandle(len)
487*7c478bd9Sstevel@tonic-gate 	int len;
488*7c478bd9Sstevel@tonic-gate {
489*7c478bd9Sstevel@tonic-gate 	int i, l;
490*7c478bd9Sstevel@tonic-gate 	int fh = 0;
491*7c478bd9Sstevel@tonic-gate 
492*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < len; i += 4) {
493*7c478bd9Sstevel@tonic-gate 		l = getxdr_long();
494*7c478bd9Sstevel@tonic-gate 		fh ^= (l >> 16) ^ l;
495*7c478bd9Sstevel@tonic-gate 	}
496*7c478bd9Sstevel@tonic-gate 
497*7c478bd9Sstevel@tonic-gate 	return (fh);
498*7c478bd9Sstevel@tonic-gate }
499*7c478bd9Sstevel@tonic-gate 
500*7c478bd9Sstevel@tonic-gate char *
sum_nfsfh()501*7c478bd9Sstevel@tonic-gate sum_nfsfh()
502*7c478bd9Sstevel@tonic-gate {
503*7c478bd9Sstevel@tonic-gate 	int fh;
504*7c478bd9Sstevel@tonic-gate 	static char buff[16];
505*7c478bd9Sstevel@tonic-gate 
506*7c478bd9Sstevel@tonic-gate 	fh = sum_filehandle(NFS_FHSIZE);
507*7c478bd9Sstevel@tonic-gate 	(void) sprintf(buff, " FH=%04X", fh & 0xFFFF);
508*7c478bd9Sstevel@tonic-gate 	return (buff);
509*7c478bd9Sstevel@tonic-gate }
510*7c478bd9Sstevel@tonic-gate 
511*7c478bd9Sstevel@tonic-gate void
detail_nfsfh()512*7c478bd9Sstevel@tonic-gate detail_nfsfh()
513*7c478bd9Sstevel@tonic-gate {
514*7c478bd9Sstevel@tonic-gate 	int pos;
515*7c478bd9Sstevel@tonic-gate 	int fh;
516*7c478bd9Sstevel@tonic-gate 
517*7c478bd9Sstevel@tonic-gate 	pos = getxdr_pos();
518*7c478bd9Sstevel@tonic-gate 	fh = sum_filehandle(NFS_FHSIZE);
519*7c478bd9Sstevel@tonic-gate 	setxdr_pos(pos);
520*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "File handle = [%04X]", fh & 0xFFFF);
521*7c478bd9Sstevel@tonic-gate 	(void) showxdr_hex(NFS_FHSIZE, " %s");
522*7c478bd9Sstevel@tonic-gate }
523*7c478bd9Sstevel@tonic-gate 
524*7c478bd9Sstevel@tonic-gate static void
detail_mode(mode)525*7c478bd9Sstevel@tonic-gate detail_mode(mode)
526*7c478bd9Sstevel@tonic-gate 	int mode;
527*7c478bd9Sstevel@tonic-gate {
528*7c478bd9Sstevel@tonic-gate 	char *str;
529*7c478bd9Sstevel@tonic-gate 
530*7c478bd9Sstevel@tonic-gate 	switch (mode & S_IFMT) {
531*7c478bd9Sstevel@tonic-gate 	case S_IFDIR: str = "Directory";	break;
532*7c478bd9Sstevel@tonic-gate 	case S_IFCHR: str = "Character";	break;
533*7c478bd9Sstevel@tonic-gate 	case S_IFBLK: str = "Block";		break;
534*7c478bd9Sstevel@tonic-gate 	case S_IFREG: str = "Regular file";	break;
535*7c478bd9Sstevel@tonic-gate 	case S_IFLNK: str = "Link";		break;
536*7c478bd9Sstevel@tonic-gate 	case S_IFSOCK: str = "Socket";		break;
537*7c478bd9Sstevel@tonic-gate 	case S_IFIFO: str = "Fifo";		break;
538*7c478bd9Sstevel@tonic-gate 	default: str = "?";			break;
539*7c478bd9Sstevel@tonic-gate 	}
540*7c478bd9Sstevel@tonic-gate 
541*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "Mode = 0%o", mode);
542*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " Type = %s", str);
543*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
544*7c478bd9Sstevel@tonic-gate 		" Setuid = %d, Setgid = %d, Sticky = %d",
545*7c478bd9Sstevel@tonic-gate 		(mode & S_ISUID) != 0,
546*7c478bd9Sstevel@tonic-gate 		(mode & S_ISGID) != 0,
547*7c478bd9Sstevel@tonic-gate 		(mode & S_ISVTX) != 0);
548*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " Owner's permissions = %s",
549*7c478bd9Sstevel@tonic-gate 		perms(mode >> 6 & 0x7));
550*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " Group's permissions = %s",
551*7c478bd9Sstevel@tonic-gate 		perms(mode >> 3 & 0x7));
552*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " Other's permissions = %s",
553*7c478bd9Sstevel@tonic-gate 		perms(mode & 0x7));
554*7c478bd9Sstevel@tonic-gate }
555*7c478bd9Sstevel@tonic-gate 
556*7c478bd9Sstevel@tonic-gate void
detail_fattr()557*7c478bd9Sstevel@tonic-gate detail_fattr()
558*7c478bd9Sstevel@tonic-gate {
559*7c478bd9Sstevel@tonic-gate 	int fltype, mode, nlinks, uid, gid, size, blksz;
560*7c478bd9Sstevel@tonic-gate 	int rdev, blocks, fsid, fileid;
561*7c478bd9Sstevel@tonic-gate 
562*7c478bd9Sstevel@tonic-gate 	fltype = getxdr_long();
563*7c478bd9Sstevel@tonic-gate 	mode = getxdr_long();
564*7c478bd9Sstevel@tonic-gate 	nlinks = getxdr_long();
565*7c478bd9Sstevel@tonic-gate 	uid = getxdr_long();
566*7c478bd9Sstevel@tonic-gate 	gid = getxdr_long();
567*7c478bd9Sstevel@tonic-gate 	size = getxdr_long();
568*7c478bd9Sstevel@tonic-gate 	blksz = getxdr_long();
569*7c478bd9Sstevel@tonic-gate 	rdev = getxdr_long();
570*7c478bd9Sstevel@tonic-gate 	blocks = getxdr_long();
571*7c478bd9Sstevel@tonic-gate 	fsid = getxdr_long();
572*7c478bd9Sstevel@tonic-gate 	fileid = getxdr_long();
573*7c478bd9Sstevel@tonic-gate 
574*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
575*7c478bd9Sstevel@tonic-gate 		"File type = %d (%s)",
576*7c478bd9Sstevel@tonic-gate 		fltype, filetype(fltype));
577*7c478bd9Sstevel@tonic-gate 	detail_mode(mode);
578*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
579*7c478bd9Sstevel@tonic-gate 		"Link count = %d, UID = %d, GID = %d, Rdev = 0x%x",
580*7c478bd9Sstevel@tonic-gate 		nlinks, uid, gid, rdev);
581*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
582*7c478bd9Sstevel@tonic-gate 		"File size = %d, Block size = %d, No. of blocks = %d",
583*7c478bd9Sstevel@tonic-gate 		size, blksz, blocks);
584*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
585*7c478bd9Sstevel@tonic-gate 		"File system id = %d, File id = %d",
586*7c478bd9Sstevel@tonic-gate 		fsid, fileid);
587*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Access time       = %s");
588*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Modification time = %s");
589*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Inode change time = %s");
590*7c478bd9Sstevel@tonic-gate }
591*7c478bd9Sstevel@tonic-gate 
592*7c478bd9Sstevel@tonic-gate static void
detail_sattr()593*7c478bd9Sstevel@tonic-gate detail_sattr()
594*7c478bd9Sstevel@tonic-gate {
595*7c478bd9Sstevel@tonic-gate 	int mode;
596*7c478bd9Sstevel@tonic-gate 
597*7c478bd9Sstevel@tonic-gate 	mode = getxdr_long();
598*7c478bd9Sstevel@tonic-gate 	detail_mode(mode);
599*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("UID = %d");
600*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("GID = %d");
601*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Size = %d");
602*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Access time       = %s");
603*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Modification time = %s");
604*7c478bd9Sstevel@tonic-gate }
605*7c478bd9Sstevel@tonic-gate 
606*7c478bd9Sstevel@tonic-gate static char *
filetype(n)607*7c478bd9Sstevel@tonic-gate filetype(n)
608*7c478bd9Sstevel@tonic-gate 	int n;
609*7c478bd9Sstevel@tonic-gate {
610*7c478bd9Sstevel@tonic-gate 	switch (n) {
611*7c478bd9Sstevel@tonic-gate 	    case NFREG: return ("Regular File");
612*7c478bd9Sstevel@tonic-gate 	    case NFDIR: return ("Directory");
613*7c478bd9Sstevel@tonic-gate 	    case NFBLK: return ("Block special");
614*7c478bd9Sstevel@tonic-gate 	    case NFCHR: return ("Character special");
615*7c478bd9Sstevel@tonic-gate 	    case NFLNK: return ("Symbolic Link");
616*7c478bd9Sstevel@tonic-gate 	    default:	return ("?");
617*7c478bd9Sstevel@tonic-gate 	}
618*7c478bd9Sstevel@tonic-gate }
619*7c478bd9Sstevel@tonic-gate 
620*7c478bd9Sstevel@tonic-gate static char *
perms(n)621*7c478bd9Sstevel@tonic-gate perms(n)
622*7c478bd9Sstevel@tonic-gate 	int n;
623*7c478bd9Sstevel@tonic-gate {
624*7c478bd9Sstevel@tonic-gate 	static char buff[4];
625*7c478bd9Sstevel@tonic-gate 
626*7c478bd9Sstevel@tonic-gate 	buff[0] = n & 4 ? 'r' : '-';
627*7c478bd9Sstevel@tonic-gate 	buff[1] = n & 2 ? 'w' : '-';
628*7c478bd9Sstevel@tonic-gate 	buff[2] = n & 1 ? 'x' : '-';
629*7c478bd9Sstevel@tonic-gate 	buff[3] = '\0';
630*7c478bd9Sstevel@tonic-gate 	return (buff);
631*7c478bd9Sstevel@tonic-gate }
632*7c478bd9Sstevel@tonic-gate 
633*7c478bd9Sstevel@tonic-gate static char *
sum_readdirres()634*7c478bd9Sstevel@tonic-gate sum_readdirres()
635*7c478bd9Sstevel@tonic-gate {
636*7c478bd9Sstevel@tonic-gate 	static char buff[NFS_MAXNAMLEN + 1];
637*7c478bd9Sstevel@tonic-gate 	int entries = 0;
638*7c478bd9Sstevel@tonic-gate 
639*7c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
640*7c478bd9Sstevel@tonic-gate 		(void) sprintf(buff, " %d+ entries (incomplete)", entries);
641*7c478bd9Sstevel@tonic-gate 		return (buff);
642*7c478bd9Sstevel@tonic-gate 	}
643*7c478bd9Sstevel@tonic-gate 	while (getxdr_long()) {
644*7c478bd9Sstevel@tonic-gate 		entries++;
645*7c478bd9Sstevel@tonic-gate 		(void) getxdr_long();			/* fileid */
646*7c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, NFS_MAXNAMLEN); /* name */
647*7c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();			/* cookie */
648*7c478bd9Sstevel@tonic-gate 	}
649*7c478bd9Sstevel@tonic-gate 
650*7c478bd9Sstevel@tonic-gate 	(void) sprintf(buff, " %d entries (%s)",
651*7c478bd9Sstevel@tonic-gate 		entries,
652*7c478bd9Sstevel@tonic-gate 		getxdr_long() ? "No more" : "More");
653*7c478bd9Sstevel@tonic-gate 	return (buff);
654*7c478bd9Sstevel@tonic-gate }
655*7c478bd9Sstevel@tonic-gate 
656*7c478bd9Sstevel@tonic-gate static void
detail_readdirres()657*7c478bd9Sstevel@tonic-gate detail_readdirres()
658*7c478bd9Sstevel@tonic-gate {
659*7c478bd9Sstevel@tonic-gate 	ulong_t fileid, cookie;
660*7c478bd9Sstevel@tonic-gate 	int entries = 0;
661*7c478bd9Sstevel@tonic-gate 	char *name;
662*7c478bd9Sstevel@tonic-gate 	char buff[NFS_MAXNAMLEN + 1];
663*7c478bd9Sstevel@tonic-gate 
664*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " File id  Cookie Name");
665*7c478bd9Sstevel@tonic-gate 
666*7c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
667*7c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
668*7c478bd9Sstevel@tonic-gate 			"  %d+ entries. (Frame is incomplete)",
669*7c478bd9Sstevel@tonic-gate 			entries);
670*7c478bd9Sstevel@tonic-gate 		return;
671*7c478bd9Sstevel@tonic-gate 	}
672*7c478bd9Sstevel@tonic-gate 	while (getxdr_long()) {
673*7c478bd9Sstevel@tonic-gate 		entries++;
674*7c478bd9Sstevel@tonic-gate 		fileid = getxdr_long();
675*7c478bd9Sstevel@tonic-gate 		name = (char *)getxdr_string(buff, NFS_MAXNAMLEN);
676*7c478bd9Sstevel@tonic-gate 		cookie = getxdr_u_long();
677*7c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
678*7c478bd9Sstevel@tonic-gate 			" %7lu %7lu %s",
679*7c478bd9Sstevel@tonic-gate 			fileid, cookie, name);
680*7c478bd9Sstevel@tonic-gate 	}
681*7c478bd9Sstevel@tonic-gate 
682*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "  %d entries", entries);
683*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("EOF = %d");
684*7c478bd9Sstevel@tonic-gate }
685*7c478bd9Sstevel@tonic-gate 
686*7c478bd9Sstevel@tonic-gate void
skip_fattr()687*7c478bd9Sstevel@tonic-gate skip_fattr()
688*7c478bd9Sstevel@tonic-gate {
689*7c478bd9Sstevel@tonic-gate 
690*7c478bd9Sstevel@tonic-gate 	xdr_skip(17 * 4);	/* XDR sizeof nfsfattr */
691*7c478bd9Sstevel@tonic-gate }
692