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