]>
The Tcpdump Group git mirrors - tcpdump/blob - print-nfs.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.70 2000-01-28 00:04:19 fenner Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <netinet/if_ether.h>
43 #include <netinet/in_systm.h>
44 #include <netinet/ip.h>
53 #include "interface.h"
54 #include "addrtoname.h"
59 static void nfs_printfh(const u_int32_t
*, const u_int
);
60 static void xid_map_enter(const struct rpc_msg
*, const struct ip
*);
61 static int32_t xid_map_find(const struct rpc_msg
*, const struct ip
*,
62 u_int32_t
*, u_int32_t
*);
63 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
64 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
65 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
66 static int print_int64(const u_int32_t
*dp
, int how
);
69 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
71 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
100 static struct tok nfsv3_writemodes
[] = {
107 static struct tok type2str
[] = {
119 * Print out a 64-bit integer. This appears to be different on each system,
120 * try to make the best of it. The integer stored as 2 consecutive XDR
121 * encoded 32-bit integers, to which a pointer is passed.
123 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
124 * integer datatype and can print it.
131 static int print_int64(const u_int32_t
*dp
, int how
)
136 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
139 printf(INT64_FORMAT
, res
);
142 printf(U_INT64_FORMAT
, res
);
145 printf(HEX_INT64_FORMAT
, res
);
155 printf ("0x%x%08x", dp
[0], dp
[1]);
164 static const u_int32_t
*
165 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
168 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
170 sa3
->sa_mode
= ntohl(*dp
++);
174 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
176 sa3
->sa_uid
= ntohl(*dp
++);
180 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
182 sa3
->sa_gid
= ntohl(*dp
++);
186 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
188 sa3
->sa_size
= ntohl(*dp
++);
192 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
194 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
195 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
199 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
201 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
202 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
210 static int nfserr
; /* true if we error rather than trunc */
213 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
216 printf(" mode %o", sa3
->sa_mode
);
218 printf(" uid %u", sa3
->sa_uid
);
220 printf(" gid %u", sa3
->sa_gid
);
222 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
223 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
224 sa3
->sa_atime
.nfsv3_nsec
);
225 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
226 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
227 sa3
->sa_mtime
.nfsv3_nsec
);
232 nfsreply_print(register const u_char
*bp
, u_int length
,
233 register const u_char
*bp2
)
235 register const struct rpc_msg
*rp
;
236 register const struct ip
*ip
;
237 u_int32_t proc
, vers
;
239 nfserr
= 0; /* assume no error */
240 rp
= (const struct rpc_msg
*)bp
;
241 ip
= (const struct ip
*)bp2
;
244 (void)printf("%s.nfs > %s.%u: reply %s %d",
245 ipaddr_string(&ip
->ip_src
),
246 ipaddr_string(&ip
->ip_dst
),
247 (u_int32_t
)ntohl(rp
->rm_xid
),
248 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
252 (void)printf("%s.%u > %s.%u: reply %s %d",
253 ipaddr_string(&ip
->ip_src
),
255 ipaddr_string(&ip
->ip_dst
),
256 (u_int32_t
)ntohl(rp
->rm_xid
),
257 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
261 if (xid_map_find(rp
, ip
, &proc
, &vers
) >= 0)
262 interp_reply(rp
, proc
, vers
, length
);
266 * Return a pointer to the first file handle in the packet.
267 * If the packet was truncated, return 0.
269 static const u_int32_t
*
270 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
272 register const u_int32_t
*dp
;
276 * find the start of the req data (if we captured it)
278 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
282 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
286 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
296 * Print out an NFS file handle and return a pointer to following word.
297 * If packet was truncated, return 0.
299 static const u_int32_t
*
300 parsefh(register const u_int32_t
*dp
, int v3
)
306 len
= (int)ntohl(*dp
) / 4;
311 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
312 nfs_printfh(dp
, len
);
320 * Print out a file name and return pointer to 32-bit word past it.
321 * If packet was truncated, return 0.
323 static const u_int32_t
*
324 parsefn(register const u_int32_t
*dp
)
326 register u_int32_t len
;
327 register const u_char
*cp
;
329 /* Bail if we don't have the string length */
332 /* Fetch string length; convert to host order */
336 TCHECK2(*dp
, ((len
+ 3) & ~3));
339 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
340 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
341 /* XXX seems like we should be checking the length */
343 (void) fn_printn(cp
, len
, NULL
);
352 * Print out file handle and file name.
353 * Return pointer to 32-bit word past file name.
354 * If packet was truncated (or there was some other error), return 0.
356 static const u_int32_t
*
357 parsefhn(register const u_int32_t
*dp
, int v3
)
359 dp
= parsefh(dp
, v3
);
363 return (parsefn(dp
));
367 nfsreq_print(register const u_char
*bp
, u_int length
,
368 register const u_char
*bp2
)
370 register const struct rpc_msg
*rp
;
371 register const struct ip
*ip
;
372 register const u_int32_t
*dp
;
376 struct nfsv3_sattr sa3
;
378 nfserr
= 0; /* assume no error */
379 rp
= (const struct rpc_msg
*)bp
;
380 ip
= (const struct ip
*)bp2
;
382 (void)printf("%s.%u > %s.nfs: %d",
383 ipaddr_string(&ip
->ip_src
),
384 (u_int32_t
)ntohl(rp
->rm_xid
),
385 ipaddr_string(&ip
->ip_dst
),
388 (void)printf("%s.%u > %s.%u: %d",
389 ipaddr_string(&ip
->ip_src
),
390 (u_int32_t
)ntohl(rp
->rm_xid
),
391 ipaddr_string(&ip
->ip_dst
),
395 xid_map_enter(rp
, ip
); /* record proc number for later on */
397 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
398 proc
= ntohl(rp
->rm_call
.cb_proc
);
400 if (!v3
&& proc
< NFS_NPROCS
)
401 proc
= nfsv3_procid
[proc
];
411 case NFSPROC_GETATTR
:
413 if ((dp
= parsereq(rp
, length
)) != NULL
&&
414 parsefh(dp
, v3
) != NULL
)
418 case NFSPROC_SETATTR
:
420 if ((dp
= parsereq(rp
, length
)) != NULL
&&
421 parsefh(dp
, v3
) != NULL
)
427 if ((dp
= parsereq(rp
, length
)) != NULL
&&
428 parsefhn(dp
, v3
) != NULL
)
434 if ((dp
= parsereq(rp
, length
)) != NULL
&&
435 (dp
= parsefh(dp
, v3
)) != NULL
) {
437 printf(" %04x", ntohl(dp
[0]));
442 case NFSPROC_READLINK
:
444 if ((dp
= parsereq(rp
, length
)) != NULL
&&
445 parsefh(dp
, v3
) != NULL
)
451 if ((dp
= parsereq(rp
, length
)) != NULL
&&
452 (dp
= parsefh(dp
, v3
)) != NULL
) {
455 printf(" %u bytes @ ",
456 (u_int32_t
) ntohl(dp
[2]));
457 print_int64(dp
, UNSIGNED
);
460 printf(" %u bytes @ %u",
461 (u_int32_t
)ntohl(dp
[1]),
462 (u_int32_t
)ntohl(dp
[0]));
470 if ((dp
= parsereq(rp
, length
)) != NULL
&&
471 (dp
= parsefh(dp
, v3
)) != NULL
) {
474 printf(" %u bytes @ ",
475 (u_int32_t
) ntohl(dp
[4]));
476 print_int64(dp
, UNSIGNED
);
481 tok2str(nfsv3_writemodes
,
486 printf(" %u (%u) bytes @ %u (%u)",
487 (u_int32_t
)ntohl(dp
[3]),
488 (u_int32_t
)ntohl(dp
[2]),
489 (u_int32_t
)ntohl(dp
[1]),
490 (u_int32_t
)ntohl(dp
[0]));
498 if ((dp
= parsereq(rp
, length
)) != NULL
&&
499 parsefhn(dp
, v3
) != NULL
)
505 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
509 case NFSPROC_SYMLINK
:
511 if ((dp
= parsereq(rp
, length
)) != 0 &&
512 (dp
= parsefhn(dp
, v3
)) != 0) {
513 fputs(" ->", stdout
);
514 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
516 if (parsefn(dp
) == 0)
519 print_sattr3(&sa3
, vflag
);
526 if ((dp
= parsereq(rp
, length
)) != 0 &&
527 (dp
= parsefhn(dp
, v3
)) != 0) {
529 type
= (nfstype
)ntohl(*dp
++);
530 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
532 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
533 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
535 printf(" %u/%u", ntohl(dp
[0]), ntohl(dp
[1]));
539 print_sattr3(&sa3
, vflag
);
546 if ((dp
= parsereq(rp
, length
)) != NULL
&&
547 parsefhn(dp
, v3
) != NULL
)
553 if ((dp
= parsereq(rp
, length
)) != NULL
&&
554 parsefhn(dp
, v3
) != NULL
)
560 if ((dp
= parsereq(rp
, length
)) != NULL
&&
561 (dp
= parsefhn(dp
, v3
)) != NULL
) {
562 fputs(" ->", stdout
);
563 if (parsefhn(dp
, v3
) != NULL
)
570 if ((dp
= parsereq(rp
, length
)) != NULL
&&
571 (dp
= parsefh(dp
, v3
)) != NULL
) {
572 fputs(" ->", stdout
);
573 if (parsefhn(dp
, v3
) != NULL
)
578 case NFSPROC_READDIR
:
580 if ((dp
= parsereq(rp
, length
)) != NULL
&&
581 (dp
= parsefh(dp
, v3
)) != NULL
) {
585 * We shouldn't really try to interpret the
586 * offset cookie here.
588 printf(" %u bytes @ ",
589 (u_int32_t
) ntohl(dp
[4]));
590 print_int64(dp
, SIGNED
);
592 printf(" verf %08x%08x", dp
[2],
597 * Print the offset as signed, since -1 is
598 * common, but offsets > 2^31 aren't.
600 printf(" %u bytes @ %d",
601 (u_int32_t
)ntohl(dp
[1]),
602 (u_int32_t
)ntohl(dp
[0]));
608 case NFSPROC_READDIRPLUS
:
609 printf(" readdirplus");
610 if ((dp
= parsereq(rp
, length
)) != NULL
&&
611 (dp
= parsefh(dp
, v3
)) != NULL
) {
614 * We don't try to interpret the offset
617 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
618 print_int64(dp
, SIGNED
);
620 printf(" max %u verf %08x%08x",
621 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
628 if ((dp
= parsereq(rp
, length
)) != NULL
&&
629 parsefh(dp
, v3
) != NULL
)
637 case NFSPROC_PATHCONF
:
643 if ((dp
= parsereq(rp
, length
)) != NULL
&&
644 (dp
= parsefh(dp
, v3
)) != NULL
) {
645 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
646 print_int64(dp
, UNSIGNED
);
652 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
658 fputs(" [|nfs]", stdout
);
662 * Print out an NFS file handle.
663 * We assume packet was not truncated before the end of the
664 * file handle pointed to by dp.
666 * Note: new version (using portable file-handle parser) doesn't produce
667 * generation number. It probably could be made to do that, with some
668 * additional hacking on the parser code.
671 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
675 char *sfsname
= NULL
;
677 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
680 /* file system ID is ASCII, not numeric, for this server OS */
681 static char temp
[NFSX_V3FHMAX
+1];
683 /* Make sure string is null-terminated */
684 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
685 /* Remove trailing spaces */
686 sfsname
= strchr(temp
, ' ');
690 (void)printf(" fh %s/%ld", temp
, (long) ino
);
693 (void)printf(" fh %d,%d/%ld",
694 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
,
700 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
701 * us to match up replies with requests and thus to know how to parse
705 struct xid_map_entry
{
706 u_int32_t xid
; /* transaction ID (net order) */
707 struct in_addr client
; /* client IP address (net order) */
708 struct in_addr server
; /* server IP address (net order) */
709 u_int32_t proc
; /* call proc number (host order) */
710 u_int32_t vers
; /* program version (host order) */
714 * Map entries are kept in an array that we manage as a ring;
715 * new entries are always added at the tail of the ring. Initially,
716 * all the entries are zero and hence don't match anything.
719 #define XIDMAPSIZE 64
721 struct xid_map_entry xid_map
[XIDMAPSIZE
];
723 int xid_map_next
= 0;
724 int xid_map_hint
= 0;
727 xid_map_enter(const struct rpc_msg
*rp
, const struct ip
*ip
)
729 struct xid_map_entry
*xmep
;
731 xmep
= &xid_map
[xid_map_next
];
733 if (++xid_map_next
>= XIDMAPSIZE
)
736 xmep
->xid
= rp
->rm_xid
;
737 xmep
->client
= ip
->ip_src
;
738 xmep
->server
= ip
->ip_dst
;
739 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
740 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
744 * Returns 0 and puts NFSPROC_xxx in proc return and
745 * version in vers return, or returns -1 on failure
748 xid_map_find(const struct rpc_msg
*rp
, const struct ip
*ip
, u_int32_t
*proc
,
752 struct xid_map_entry
*xmep
;
753 u_int32_t xid
= rp
->rm_xid
;
754 u_int32_t clip
= ip
->ip_dst
.s_addr
;
755 u_int32_t sip
= ip
->ip_src
.s_addr
;
757 /* Start searching from where we last left off */
761 if (xmep
->xid
== xid
&& xmep
->client
.s_addr
== clip
&&
762 xmep
->server
.s_addr
== sip
) {
769 if (++i
>= XIDMAPSIZE
)
771 } while (i
!= xid_map_hint
);
778 * Routines for parsing reply packets
782 * Return a pointer to the beginning of the actual results.
783 * If the packet was truncated, return 0.
785 static const u_int32_t
*
786 parserep(register const struct rpc_msg
*rp
, register u_int length
)
788 register const u_int32_t
*dp
;
790 enum accept_stat astat
;
794 * Here we find the address of the ar_verf credentials.
795 * Originally, this calculation was
796 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
797 * On the wire, the rp_acpt field starts immediately after
798 * the (32 bit) rp_stat field. However, rp_acpt (which is a
799 * "struct accepted_reply") contains a "struct opaque_auth",
800 * whose internal representation contains a pointer, so on a
801 * 64-bit machine the compiler inserts 32 bits of padding
802 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
803 * the internal representation to parse the on-the-wire
804 * representation. Instead, we skip past the rp_stat field,
805 * which is an "enum" and so occupies one 32-bit word.
807 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
813 * skip past the ar_verf credentials.
815 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
819 * now we can check the ar_stat field
821 astat
= ntohl(*(enum accept_stat
*)dp
);
828 printf(" PROG_UNAVAIL");
829 nfserr
= 1; /* suppress trunc string */
833 printf(" PROG_MISMATCH");
834 nfserr
= 1; /* suppress trunc string */
838 printf(" PROC_UNAVAIL");
839 nfserr
= 1; /* suppress trunc string */
843 printf(" GARBAGE_ARGS");
844 nfserr
= 1; /* suppress trunc string */
848 printf(" SYSTEM_ERR");
849 nfserr
= 1; /* suppress trunc string */
853 printf(" ar_stat %d", astat
);
854 nfserr
= 1; /* suppress trunc string */
857 /* successful return */
858 TCHECK2(*dp
, sizeof(astat
));
859 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
864 static const u_int32_t
*
865 parsestatus(const u_int32_t
*dp
, int *er
)
871 errnum
= ntohl(dp
[0]);
876 printf(" ERROR: %s", pcap_strerror(errnum
));
885 static const u_int32_t
*
886 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
888 const struct nfs_fattr
*fap
;
890 fap
= (const struct nfs_fattr
*)dp
;
893 printf(" %s %o ids %d/%d",
894 tok2str(type2str
, "unk-ft %d ",
895 (u_int32_t
)ntohl(fap
->fa_type
)),
896 (u_int32_t
)ntohl(fap
->fa_mode
),
897 (u_int32_t
)ntohl(fap
->fa_uid
),
898 (u_int32_t
) ntohl(fap
->fa_gid
));
900 TCHECK(fap
->fa3_size
);
902 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
905 TCHECK(fap
->fa2_size
);
906 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
909 /* print lots more stuff */
912 TCHECK(fap
->fa3_ctime
);
913 printf("nlink %d rdev %d/%d ",
914 (u_int32_t
)ntohl(fap
->fa_nlink
),
915 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
916 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
918 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
920 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
921 printf(" a/m/ctime %u.%06u ",
922 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
923 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
925 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
926 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
928 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
929 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
931 TCHECK(fap
->fa2_ctime
);
932 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
933 (u_int32_t
) ntohl(fap
->fa_nlink
),
934 (u_int32_t
) ntohl(fap
->fa2_rdev
),
935 (u_int32_t
) ntohl(fap
->fa2_fsid
),
936 (u_int32_t
) ntohl(fap
->fa2_fileid
));
938 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
939 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
941 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
942 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
944 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
945 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
948 return ((const u_int32_t
*)((unsigned char *)dp
+
949 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
955 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
959 dp
= parsestatus(dp
, &er
);
960 if (dp
== NULL
|| er
)
963 return (parsefattr(dp
, verbose
, v3
) != NULL
);
967 parsediropres(const u_int32_t
*dp
)
971 if (!(dp
= parsestatus(dp
, &er
)) || er
)
978 return (parsefattr(dp
, vflag
, 0) != NULL
);
982 parselinkres(const u_int32_t
*dp
, int v3
)
986 dp
= parsestatus(dp
, &er
);
987 if (dp
== NULL
|| er
)
989 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
992 return (parsefn(dp
) != NULL
);
996 parsestatfs(const u_int32_t
*dp
, int v3
)
998 const struct nfs_statfs
*sfsp
;
1001 dp
= parsestatus(dp
, &er
);
1002 if (dp
== NULL
|| (!v3
&& er
))
1011 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1015 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1017 sfsp
= (const struct nfs_statfs
*)dp
;
1021 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1023 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1025 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1028 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1030 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1032 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1034 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1037 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1038 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1039 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1040 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1041 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1042 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1051 parserddires(const u_int32_t
*dp
)
1055 dp
= parsestatus(dp
, &er
);
1062 printf(" offset %x size %d ", ntohl(dp
[0]), ntohl(dp
[1]));
1071 static const u_int32_t
*
1072 parse_wcc_attr(const u_int32_t
*dp
)
1075 print_int64(dp
, UNSIGNED
);
1076 printf(" mtime %u.%06u ctime %u.%06u", ntohl(dp
[2]), ntohl(dp
[3]),
1077 ntohl(dp
[4]), ntohl(dp
[5]));
1082 * Pre operation attributes. Print only if vflag > 1.
1084 static const u_int32_t
*
1085 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1093 return parse_wcc_attr(dp
);
1095 /* If not verbose enough, just skip over wcc_attr */
1103 * Post operation attributes are printed if vflag >= 1
1105 static const u_int32_t
*
1106 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1113 return parsefattr(dp
, verbose
, 1);
1115 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1120 static const u_int32_t
*
1121 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1125 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1130 return parse_post_op_attr(dp
, verbose
);
1133 static const u_int32_t
*
1134 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1138 if (!(dp
= parsestatus(dp
, &er
)))
1141 dp
= parse_wcc_data(dp
, verbose
);
1147 if (!(dp
= parsefh(dp
, 1)))
1150 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1153 printf("dir attr:");
1154 dp
= parse_wcc_data(dp
, verbose
);
1164 parsewccres(const u_int32_t
*dp
, int verbose
)
1168 if (!(dp
= parsestatus(dp
, &er
)))
1170 return parse_wcc_data(dp
, verbose
) != 0;
1173 static const u_int32_t
*
1174 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1178 if (!(dp
= parsestatus(dp
, &er
)))
1182 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1188 printf(" verf %08x%08x", dp
[0], dp
[1]);
1197 parsefsinfo(const u_int32_t
*dp
)
1199 struct nfsv3_fsinfo
*sfp
;
1202 if (!(dp
= parsestatus(dp
, &er
)))
1206 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1211 sfp
= (struct nfsv3_fsinfo
*)dp
;
1213 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1214 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1215 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1216 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1217 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1218 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1220 printf(" rtmult %u wtmult %u maxfsz ",
1221 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1222 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1223 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1224 printf(" delta %u.%06u ",
1225 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1226 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1234 parsepathconf(const u_int32_t
*dp
)
1237 struct nfsv3_pathconf
*spp
;
1239 if (!(dp
= parsestatus(dp
, &er
)))
1243 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1248 spp
= (struct nfsv3_pathconf
*)dp
;
1251 printf(" linkmax %u namemax %u %s %s %s %s",
1252 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1253 (u_int32_t
) ntohl(spp
->pc_namemax
),
1254 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1255 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1256 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1257 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1264 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1266 register const u_int32_t
*dp
;
1270 v3
= (vers
== NFS_VER3
);
1272 if (!v3
&& proc
< NFS_NPROCS
)
1273 proc
= nfsv3_procid
[proc
];
1285 case NFSPROC_GETATTR
:
1287 dp
= parserep(rp
, length
);
1288 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1292 case NFSPROC_SETATTR
:
1294 if (!(dp
= parserep(rp
, length
)))
1297 if (parsewccres(dp
, vflag
))
1300 if (parseattrstat(dp
, !qflag
, 0) != 0)
1305 case NFSPROC_LOOKUP
:
1307 if (!(dp
= parserep(rp
, length
)))
1310 if (!(dp
= parsestatus(dp
, &er
)))
1314 printf(" post dattr:");
1315 dp
= parse_post_op_attr(dp
, vflag
);
1318 if (!(dp
= parsefh(dp
, v3
)))
1320 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1322 printf(" post dattr:");
1323 dp
= parse_post_op_attr(dp
, vflag
);
1329 if (parsediropres(dp
) != 0)
1334 case NFSPROC_ACCESS
:
1336 dp
= parserep(rp
, length
);
1337 if (!(dp
= parsestatus(dp
, &er
)))
1341 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1344 printf(" c %04x", ntohl(dp
[0]));
1347 case NFSPROC_READLINK
:
1348 printf(" readlink");
1349 dp
= parserep(rp
, length
);
1350 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1356 if (!(dp
= parserep(rp
, length
)))
1359 if (!(dp
= parsestatus(dp
, &er
)))
1361 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1367 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1373 if (parseattrstat(dp
, vflag
, 0) != 0)
1380 if (!(dp
= parserep(rp
, length
)))
1383 if (!(dp
= parsestatus(dp
, &er
)))
1385 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1391 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1395 tok2str(nfsv3_writemodes
,
1396 NULL
, ntohl(dp
[1])));
1401 if (parseattrstat(dp
, vflag
, v3
) != 0)
1406 case NFSPROC_CREATE
:
1408 if (!(dp
= parserep(rp
, length
)))
1411 if (parsecreateopres(dp
, vflag
) != 0)
1414 if (parsediropres(dp
) != 0)
1421 if (!(dp
= parserep(rp
, length
)))
1424 if (parsecreateopres(dp
, vflag
) != 0)
1427 if (parsediropres(dp
) != 0)
1432 case NFSPROC_SYMLINK
:
1434 if (!(dp
= parserep(rp
, length
)))
1437 if (parsecreateopres(dp
, vflag
) != 0)
1440 if (parsestatus(dp
, &er
) != 0)
1447 if (!(dp
= parserep(rp
, length
)))
1449 if (parsecreateopres(dp
, vflag
) != 0)
1453 case NFSPROC_REMOVE
:
1455 if (!(dp
= parserep(rp
, length
)))
1458 if (parsewccres(dp
, vflag
))
1461 if (parsestatus(dp
, &er
) != 0)
1468 if (!(dp
= parserep(rp
, length
)))
1471 if (parsewccres(dp
, vflag
))
1474 if (parsestatus(dp
, &er
) != 0)
1479 case NFSPROC_RENAME
:
1481 if (!(dp
= parserep(rp
, length
)))
1484 if (!(dp
= parsestatus(dp
, &er
)))
1488 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1491 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1496 if (parsestatus(dp
, &er
) != 0)
1503 if (!(dp
= parserep(rp
, length
)))
1506 if (!(dp
= parsestatus(dp
, &er
)))
1509 printf(" file POST:");
1510 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1513 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1518 if (parsestatus(dp
, &er
) != 0)
1523 case NFSPROC_READDIR
:
1525 if (!(dp
= parserep(rp
, length
)))
1528 if (parsev3rddirres(dp
, vflag
))
1531 if (parserddires(dp
) != 0)
1536 case NFSPROC_READDIRPLUS
:
1537 printf(" readdirplus");
1538 if (!(dp
= parserep(rp
, length
)))
1540 if (parsev3rddirres(dp
, vflag
))
1544 case NFSPROC_FSSTAT
:
1546 dp
= parserep(rp
, length
);
1547 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1551 case NFSPROC_FSINFO
:
1553 dp
= parserep(rp
, length
);
1554 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1558 case NFSPROC_PATHCONF
:
1559 printf(" pathconf");
1560 dp
= parserep(rp
, length
);
1561 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1565 case NFSPROC_COMMIT
:
1567 dp
= parserep(rp
, length
);
1568 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1573 printf(" proc-%u", proc
);
1578 fputs(" [|nfs]", stdout
);