4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1991-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <sys/errno.h>
31 #include <sys/tiuser.h>
34 #include <rpc/types.h>
38 #include <rpc/rpc_msg.h>
41 #include "snoop_nfs.h"
44 #include <rpcsvc/nfs_prot.h>
46 static char *perms(int);
47 static char *filetype(int);
48 static char *sum_readdirres(void);
49 static void detail_readdirres(void);
50 static void detail_diroparg(void);
51 static void nfscall2(int);
52 static void nfsreply2(int);
53 static void detail_mode(int);
54 static void detail_sattr(void);
55 static void interpret_nfs2(int, int, int, int, int, char *, int);
57 extern jmp_buf xdr_err
;
59 static char *procnames_short
[] = {
67 "WRITECACHE2", /* 7 */
80 static char *procnames_long
[] = {
81 "Null procedure", /* 0 */
82 "Get file attributes", /* 1 */
83 "Set file attributes", /* 2 */
84 "Get root filehandle", /* 3 */
85 "Look up file name", /* 4 */
86 "Read from symbolic link", /* 5 */
87 "Read from file", /* 6 */
88 "Write to cache", /* 7 */
89 "Write to file", /* 8 */
90 "Create file", /* 9 */
91 "Remove file", /* 10 */
94 "Make symbolic link", /* 13 */
95 "Make directory", /* 14 */
96 "Remove directory", /* 15 */
97 "Read from directory", /* 16 */
98 "Get filesystem attributes", /* 17 */
105 interpret_nfs(flags
, type
, xid
, vers
, proc
, data
, len
)
106 int flags
, type
, xid
, vers
, proc
;
112 interpret_nfs2(flags
, type
, xid
, vers
, proc
, data
, len
);
117 interpret_nfs3(flags
, type
, xid
, vers
, proc
, data
, len
);
122 interpret_nfs4(flags
, type
, xid
, vers
, proc
, data
, len
);
128 interpret_nfs2(flags
, type
, xid
, vers
, proc
, data
, len
)
129 int flags
, type
, xid
, vers
, proc
;
134 char buff
[NFS_MAXPATHLEN
+ 1];
138 if (proc
< 0 || proc
> MAXPROC
)
142 line
= get_sum_line();
147 procnames_short
[proc
]);
148 line
+= strlen(line
);
150 case NFSPROC_GETATTR
:
151 case NFSPROC_READLINK
:
153 case NFSPROC_SETATTR
:
154 (void) sprintf(line
, sum_nfsfh());
162 (void) sprintf(line
, "%s %s",
164 getxdr_string(buff
, NFS_MAXNAMLEN
));
168 (void) getxdr_long(); /* beginoff */
170 (void) getxdr_long(); /* totalcount */
172 (void) sprintf(line
, "%s at %d for %d",
177 (void) sprintf(line
, "%s %s",
179 getxdr_string(buff
, NFS_MAXNAMLEN
));
180 line
+= strlen(line
);
182 (void) sprintf(line
, " to%s %s",
184 getxdr_string(buff
, NFS_MAXNAMLEN
));
188 (void) sprintf(line
, "%s", fh
);
189 line
+= strlen(line
);
191 (void) sprintf(line
, " to%s %s",
193 getxdr_string(buff
, NFS_MAXNAMLEN
));
195 case NFSPROC_SYMLINK
:
197 (void) sprintf(line
, "%s %s",
199 getxdr_string(buff
, NFS_MAXNAMLEN
));
200 line
+= strlen(line
);
201 (void) sprintf(line
, " to %s",
202 getxdr_string(buff
, NFS_MAXPATHLEN
));
204 case NFSPROC_READDIR
:
206 (void) sprintf(line
, "%s Cookie=%lu",
207 fh
, getxdr_u_long());
213 (void) sprintf(line
, "%s at %d for %d",
220 check_retransmit(line
, (ulong_t
)xid
);
222 (void) sprintf(line
, "NFS R %s ",
223 procnames_short
[proc
]);
224 line
+= strlen(line
);
229 if (sum_nfsstat(line
) == 0) {
230 line
+= strlen(line
);
231 (void) sprintf(line
, sum_nfsfh());
234 case NFSPROC_READLINK
:
235 if (sum_nfsstat(line
) == 0) {
236 line
+= strlen(line
);
237 (void) sprintf(line
, " (Path=%s)",
242 case NFSPROC_GETATTR
:
243 case NFSPROC_SYMLINK
:
245 case NFSPROC_SETATTR
:
251 (void) sum_nfsstat(line
);
253 case NFSPROC_READDIR
:
254 if (sum_nfsstat(line
) == 0) {
255 line
+= strlen(line
);
256 (void) strcat(line
, sum_readdirres());
260 if (sum_nfsstat(line
) == 0) {
261 line
+= strlen(line
);
262 xdr_skip(68); /* fattrs */
263 (void) sprintf(line
, " (%ld bytes)",
273 if (flags
& F_DTAIL
) {
274 show_header("NFS: ", "Sun NFS", len
);
276 (void) sprintf(get_line(0, 0), "Proc = %d (%s)",
277 proc
, procnames_long
[proc
]);
287 * Print out version 2 NFS call packets
294 case NFSPROC_GETATTR
:
295 case NFSPROC_READLINK
:
299 case NFSPROC_SETATTR
:
315 (void) getxdr_long(); /* begoff */
316 (void) showxdr_long("Offset = %d");
317 (void) getxdr_long(); /* totalcount */
318 (void) showxdr_long("(%d bytes(s) of data)");
328 case NFSPROC_SYMLINK
:
330 (void) showxdr_string(NFS_MAXPATHLEN
, "Path = %s");
333 case NFSPROC_READDIR
:
335 (void) showxdr_u_long("Cookie = %lu");
336 (void) showxdr_long("Count = %d");
340 (void) showxdr_long("Offset = %d");
341 (void) showxdr_long("Count = %d");
349 * Print out version 2 NFS reply packets
356 case NFSPROC_GETATTR
:
357 case NFSPROC_SETATTR
:
360 if (detail_nfsstat() == 0) {
368 if (detail_nfsstat() == 0) {
373 case NFSPROC_READLINK
:
375 if (detail_nfsstat() == 0) {
376 (void) showxdr_string(NFS_MAXPATHLEN
, "Path = %s");
381 if (detail_nfsstat() == 0) {
383 (void) showxdr_long("(%d byte(s) of data)");
389 case NFSPROC_SYMLINK
:
394 case NFSPROC_READDIR
:
396 if (detail_nfsstat() == 0)
401 if (detail_nfsstat() == 0) {
402 (void) showxdr_long("Transfer size = %d");
403 (void) showxdr_long("Block size = %d");
404 (void) showxdr_long("Total blocks = %d");
405 (void) showxdr_long("Free blocks = %d");
406 (void) showxdr_long("Available blocks = %d");
418 (void) showxdr_string(NFS_MAXPATHLEN
, "File name = %s");
422 * V2 NFS protocol was implicitly linked with SunOS errnos.
423 * Some of the errno values changed in SVr4.
424 * Need to map errno value so that SVr4 snoop will interpret
432 case NFS_OK
: return ("OK");
433 case NFSERR_PERM
: return ("Not owner");
434 case NFSERR_NOENT
: return ("No such file or directory");
435 case NFSERR_IO
: return ("I/O error");
436 case NFSERR_NXIO
: return ("No such device or address");
437 case NFSERR_ACCES
: return ("Permission denied");
438 case NFSERR_EXIST
: return ("File exists");
439 case NFSERR_XDEV
: return ("Cross-device link");
440 case NFSERR_NODEV
: return ("No such device");
441 case NFSERR_NOTDIR
: return ("Not a directory");
442 case NFSERR_ISDIR
: return ("Is a directory");
443 case NFSERR_INVAL
: return ("Invalid argument");
444 case NFSERR_FBIG
: return ("File too large");
445 case NFSERR_NOSPC
: return ("No space left on device");
446 case NFSERR_ROFS
: return ("Read-only file system");
447 case NFSERR_OPNOTSUPP
: return ("Operation not supported");
448 case NFSERR_NAMETOOLONG
: return ("File name too long");
449 case NFSERR_NOTEMPTY
: return ("Directory not empty");
450 case NFSERR_DQUOT
: return ("Disc quota exceeded");
451 case NFSERR_STALE
: return ("Stale NFS file handle");
452 case NFSERR_REMOTE
: return ("Object is remote");
453 case NFSERR_WFLUSH
: return ("write cache flushed");
454 default: return ("(unknown error)");
465 status
= getxdr_long();
466 (void) strcpy(line
, statusmsg(status
));
477 status
= getxdr_long();
478 (void) sprintf(get_line(pos
, getxdr_pos()),
480 status
, statusmsg(status
));
482 return ((int)status
);
493 for (a
= b
= c
= d
= 0, i
= 0; i
< len
; i
+= 4) {
507 static char buff
[16];
509 fh
= sum_filehandle(NFS_FHSIZE
);
510 (void) sprintf(buff
, " FH=%08X", fh
);
521 fh
= sum_filehandle(NFS_FHSIZE
);
523 (void) sprintf(get_line(0, 0), "File handle = [%08X]", fh
);
524 (void) showxdr_hex(NFS_FHSIZE
, " %s");
533 switch (mode
& S_IFMT
) {
534 case S_IFDIR
: str
= "Directory"; break;
535 case S_IFCHR
: str
= "Character"; break;
536 case S_IFBLK
: str
= "Block"; break;
537 case S_IFREG
: str
= "Regular file"; break;
538 case S_IFLNK
: str
= "Link"; break;
539 case S_IFSOCK
: str
= "Socket"; break;
540 case S_IFIFO
: str
= "Fifo"; break;
541 default: str
= "?"; break;
544 (void) sprintf(get_line(0, 0), "Mode = 0%o", mode
);
545 (void) sprintf(get_line(0, 0), " Type = %s", str
);
546 (void) sprintf(get_line(0, 0),
547 " Setuid = %d, Setgid = %d, Sticky = %d",
548 (mode
& S_ISUID
) != 0,
549 (mode
& S_ISGID
) != 0,
550 (mode
& S_ISVTX
) != 0);
551 (void) sprintf(get_line(0, 0), " Owner's permissions = %s",
552 perms(mode
>> 6 & 0x7));
553 (void) sprintf(get_line(0, 0), " Group's permissions = %s",
554 perms(mode
>> 3 & 0x7));
555 (void) sprintf(get_line(0, 0), " Other's permissions = %s",
562 int fltype
, mode
, nlinks
, uid
, gid
, size
, blksz
;
563 int rdev
, blocks
, fsid
, fileid
;
565 fltype
= getxdr_long();
566 mode
= getxdr_long();
567 nlinks
= getxdr_long();
570 size
= getxdr_long();
571 blksz
= getxdr_long();
572 rdev
= getxdr_long();
573 blocks
= getxdr_long();
574 fsid
= getxdr_long();
575 fileid
= getxdr_long();
577 (void) sprintf(get_line(0, 0),
578 "File type = %d (%s)",
579 fltype
, filetype(fltype
));
581 (void) sprintf(get_line(0, 0),
582 "Link count = %d, UID = %d, GID = %d, Rdev = 0x%x",
583 nlinks
, uid
, gid
, rdev
);
584 (void) sprintf(get_line(0, 0),
585 "File size = %d, Block size = %d, No. of blocks = %d",
586 size
, blksz
, blocks
);
587 (void) sprintf(get_line(0, 0),
588 "File system id = %d, File id = %d",
590 (void) showxdr_date("Access time = %s");
591 (void) showxdr_date("Modification time = %s");
592 (void) showxdr_date("Inode change time = %s");
600 mode
= getxdr_long();
602 (void) showxdr_long("UID = %d");
603 (void) showxdr_long("GID = %d");
604 (void) showxdr_long("Size = %d");
605 (void) showxdr_date("Access time = %s");
606 (void) showxdr_date("Modification time = %s");
614 case NFREG
: return ("Regular File");
615 case NFDIR
: return ("Directory");
616 case NFBLK
: return ("Block special");
617 case NFCHR
: return ("Character special");
618 case NFLNK
: return ("Symbolic Link");
619 default: return ("?");
629 buff
[0] = n
& 4 ? 'r' : '-';
630 buff
[1] = n
& 2 ? 'w' : '-';
631 buff
[2] = n
& 1 ? 'x' : '-';
639 static char buff
[NFS_MAXNAMLEN
+ 1];
642 if (setjmp(xdr_err
)) {
643 (void) sprintf(buff
, " %d+ entries (incomplete)", entries
);
646 while (getxdr_long()) {
648 (void) getxdr_long(); /* fileid */
649 (void) getxdr_string(buff
, NFS_MAXNAMLEN
); /* name */
650 (void) getxdr_u_long(); /* cookie */
653 (void) sprintf(buff
, " %d entries (%s)",
655 getxdr_long() ? "No more" : "More");
662 ulong_t fileid
, cookie
;
665 char buff
[NFS_MAXNAMLEN
+ 1];
667 (void) sprintf(get_line(0, 0), " File id Cookie Name");
669 if (setjmp(xdr_err
)) {
670 (void) sprintf(get_line(0, 0),
671 " %d+ entries. (Frame is incomplete)",
675 while (getxdr_long()) {
677 fileid
= getxdr_long();
678 name
= (char *)getxdr_string(buff
, NFS_MAXNAMLEN
);
679 cookie
= getxdr_u_long();
680 (void) sprintf(get_line(0, 0),
682 fileid
, cookie
, name
);
685 (void) sprintf(get_line(0, 0), " %d entries", entries
);
686 (void) showxdr_long("EOF = %d");
693 xdr_skip(17 * 4); /* XDR sizeof nfsfattr */