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