]>
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.77 2000-06-12 15:45:05 itojun 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>
46 #include <netinet/ip6.h>
56 #include "interface.h"
57 #include "addrtoname.h"
62 static void nfs_printfh(const u_int32_t
*, const u_int
);
63 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
64 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
65 u_int32_t
*, u_int32_t
*);
66 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
67 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
68 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
69 static int print_int64(const u_int32_t
*dp
, int how
);
70 static void print_nfsaddr(const u_char
*, const char *, const char *);
73 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
75 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
104 static struct tok nfsv3_writemodes
[] = {
111 static struct tok type2str
[] = {
123 * Print out a 64-bit integer. This appears to be different on each system,
124 * try to make the best of it. The integer stored as 2 consecutive XDR
125 * encoded 32-bit integers, to which a pointer is passed.
127 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
128 * integer datatype and can print it.
135 static int print_int64(const u_int32_t
*dp
, int how
)
140 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
143 printf(INT64_FORMAT
, res
);
146 printf(U_INT64_FORMAT
, res
);
149 printf(HEX_INT64_FORMAT
, res
);
159 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
160 (u_int32_t
)ntohl(dp
[1]));
170 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
175 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
177 #ifndef INET_ADDRSTRLEN
178 #define INET_ADDRSTRLEN 16
180 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
183 srcaddr
[0] = dstaddr
[0] = '\0';
184 switch (((struct ip
*)bp
)->ip_v
) {
186 ip
= (struct ip
*)bp
;
187 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
188 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
192 ip6
= (struct ip6_hdr
*)bp
;
193 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
195 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
200 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
201 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
205 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
208 static const u_int32_t
*
209 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
212 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
214 sa3
->sa_mode
= ntohl(*dp
++);
218 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
220 sa3
->sa_uid
= ntohl(*dp
++);
224 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
226 sa3
->sa_gid
= ntohl(*dp
++);
230 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
232 sa3
->sa_size
= ntohl(*dp
++);
236 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
238 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
239 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
243 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
245 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
246 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
254 static int nfserr
; /* true if we error rather than trunc */
257 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
260 printf(" mode %o", sa3
->sa_mode
);
262 printf(" uid %u", sa3
->sa_uid
);
264 printf(" gid %u", sa3
->sa_gid
);
266 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
267 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
268 sa3
->sa_atime
.nfsv3_nsec
);
269 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
270 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
271 sa3
->sa_mtime
.nfsv3_nsec
);
276 nfsreply_print(register const u_char
*bp
, u_int length
,
277 register const u_char
*bp2
)
279 register const struct rpc_msg
*rp
;
280 u_int32_t proc
, vers
;
281 char srcid
[20], dstid
[20]; /*fits 32bit*/
283 nfserr
= 0; /* assume no error */
284 rp
= (const struct rpc_msg
*)bp
;
287 strlcpy(srcid
, "nfs", sizeof(srcid
));
288 snprintf(dstid
, sizeof(dstid
), "%u",
289 (u_int32_t
)ntohl(rp
->rm_xid
));
291 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
292 snprintf(dstid
, sizeof(dstid
), "%u",
293 (u_int32_t
)ntohl(rp
->rm_xid
));
295 print_nfsaddr(bp2
, srcid
, dstid
);
296 (void)printf("reply %s %d",
297 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
301 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
302 interp_reply(rp
, proc
, vers
, length
);
306 * Return a pointer to the first file handle in the packet.
307 * If the packet was truncated, return 0.
309 static const u_int32_t
*
310 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
312 register const u_int32_t
*dp
;
316 * find the start of the req data (if we captured it)
318 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
322 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
326 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
336 * Print out an NFS file handle and return a pointer to following word.
337 * If packet was truncated, return 0.
339 static const u_int32_t
*
340 parsefh(register const u_int32_t
*dp
, int v3
)
346 len
= (int)ntohl(*dp
) / 4;
351 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
352 nfs_printfh(dp
, len
);
360 * Print out a file name and return pointer to 32-bit word past it.
361 * If packet was truncated, return 0.
363 static const u_int32_t
*
364 parsefn(register const u_int32_t
*dp
)
366 register u_int32_t len
;
367 register const u_char
*cp
;
369 /* Bail if we don't have the string length */
372 /* Fetch string length; convert to host order */
376 TCHECK2(*dp
, ((len
+ 3) & ~3));
379 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
380 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
381 /* XXX seems like we should be checking the length */
383 (void) fn_printn(cp
, len
, NULL
);
392 * Print out file handle and file name.
393 * Return pointer to 32-bit word past file name.
394 * If packet was truncated (or there was some other error), return 0.
396 static const u_int32_t
*
397 parsefhn(register const u_int32_t
*dp
, int v3
)
399 dp
= parsefh(dp
, v3
);
403 return (parsefn(dp
));
407 nfsreq_print(register const u_char
*bp
, u_int length
,
408 register const u_char
*bp2
)
410 register const struct rpc_msg
*rp
;
411 register const u_int32_t
*dp
;
415 struct nfsv3_sattr sa3
;
416 char srcid
[20], dstid
[20]; /*fits 32bit*/
418 nfserr
= 0; /* assume no error */
419 rp
= (const struct rpc_msg
*)bp
;
421 snprintf(srcid
, sizeof(srcid
), "%u",
422 (u_int32_t
)ntohl(rp
->rm_xid
));
423 strlcpy(dstid
, "nfs", sizeof(dstid
));
425 snprintf(srcid
, sizeof(srcid
), "%u",
426 (u_int32_t
)ntohl(rp
->rm_xid
));
427 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
429 print_nfsaddr(bp2
, srcid
, dstid
);
430 (void)printf("%d", length
);
432 xid_map_enter(rp
, bp2
); /* record proc number for later on */
434 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
435 proc
= ntohl(rp
->rm_call
.cb_proc
);
437 if (!v3
&& proc
< NFS_NPROCS
)
438 proc
= nfsv3_procid
[proc
];
448 case NFSPROC_GETATTR
:
450 if ((dp
= parsereq(rp
, length
)) != NULL
&&
451 parsefh(dp
, v3
) != NULL
)
455 case NFSPROC_SETATTR
:
457 if ((dp
= parsereq(rp
, length
)) != NULL
&&
458 parsefh(dp
, v3
) != NULL
)
464 if ((dp
= parsereq(rp
, length
)) != NULL
&&
465 parsefhn(dp
, v3
) != NULL
)
471 if ((dp
= parsereq(rp
, length
)) != NULL
&&
472 (dp
= parsefh(dp
, v3
)) != NULL
) {
474 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
479 case NFSPROC_READLINK
:
481 if ((dp
= parsereq(rp
, length
)) != NULL
&&
482 parsefh(dp
, v3
) != NULL
)
488 if ((dp
= parsereq(rp
, length
)) != NULL
&&
489 (dp
= parsefh(dp
, v3
)) != NULL
) {
492 printf(" %u bytes @ ",
493 (u_int32_t
) ntohl(dp
[2]));
494 print_int64(dp
, UNSIGNED
);
497 printf(" %u bytes @ %u",
498 (u_int32_t
)ntohl(dp
[1]),
499 (u_int32_t
)ntohl(dp
[0]));
507 if ((dp
= parsereq(rp
, length
)) != NULL
&&
508 (dp
= parsefh(dp
, v3
)) != NULL
) {
511 printf(" %u bytes @ ",
512 (u_int32_t
) ntohl(dp
[4]));
513 print_int64(dp
, UNSIGNED
);
518 tok2str(nfsv3_writemodes
,
523 printf(" %u (%u) bytes @ %u (%u)",
524 (u_int32_t
)ntohl(dp
[3]),
525 (u_int32_t
)ntohl(dp
[2]),
526 (u_int32_t
)ntohl(dp
[1]),
527 (u_int32_t
)ntohl(dp
[0]));
535 if ((dp
= parsereq(rp
, length
)) != NULL
&&
536 parsefhn(dp
, v3
) != NULL
)
542 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
546 case NFSPROC_SYMLINK
:
548 if ((dp
= parsereq(rp
, length
)) != 0 &&
549 (dp
= parsefhn(dp
, v3
)) != 0) {
550 fputs(" ->", stdout
);
551 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
553 if (parsefn(dp
) == 0)
556 print_sattr3(&sa3
, vflag
);
563 if ((dp
= parsereq(rp
, length
)) != 0 &&
564 (dp
= parsefhn(dp
, v3
)) != 0) {
566 type
= (nfstype
)ntohl(*dp
++);
567 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
569 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
570 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
573 (u_int32_t
)ntohl(dp
[0]),
574 (u_int32_t
)ntohl(dp
[1]));
578 print_sattr3(&sa3
, vflag
);
585 if ((dp
= parsereq(rp
, length
)) != NULL
&&
586 parsefhn(dp
, v3
) != NULL
)
592 if ((dp
= parsereq(rp
, length
)) != NULL
&&
593 parsefhn(dp
, v3
) != NULL
)
599 if ((dp
= parsereq(rp
, length
)) != NULL
&&
600 (dp
= parsefhn(dp
, v3
)) != NULL
) {
601 fputs(" ->", stdout
);
602 if (parsefhn(dp
, v3
) != NULL
)
609 if ((dp
= parsereq(rp
, length
)) != NULL
&&
610 (dp
= parsefh(dp
, v3
)) != NULL
) {
611 fputs(" ->", stdout
);
612 if (parsefhn(dp
, v3
) != NULL
)
617 case NFSPROC_READDIR
:
619 if ((dp
= parsereq(rp
, length
)) != NULL
&&
620 (dp
= parsefh(dp
, v3
)) != NULL
) {
624 * We shouldn't really try to interpret the
625 * offset cookie here.
627 printf(" %u bytes @ ",
628 (u_int32_t
) ntohl(dp
[4]));
629 print_int64(dp
, SIGNED
);
631 printf(" verf %08x%08x", dp
[2],
636 * Print the offset as signed, since -1 is
637 * common, but offsets > 2^31 aren't.
639 printf(" %u bytes @ %d",
640 (u_int32_t
)ntohl(dp
[1]),
641 (u_int32_t
)ntohl(dp
[0]));
647 case NFSPROC_READDIRPLUS
:
648 printf(" readdirplus");
649 if ((dp
= parsereq(rp
, length
)) != NULL
&&
650 (dp
= parsefh(dp
, v3
)) != NULL
) {
653 * We don't try to interpret the offset
656 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
657 print_int64(dp
, SIGNED
);
659 printf(" max %u verf %08x%08x",
660 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
667 if ((dp
= parsereq(rp
, length
)) != NULL
&&
668 parsefh(dp
, v3
) != NULL
)
676 case NFSPROC_PATHCONF
:
682 if ((dp
= parsereq(rp
, length
)) != NULL
&&
683 (dp
= parsefh(dp
, v3
)) != NULL
) {
684 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
685 print_int64(dp
, UNSIGNED
);
691 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
697 fputs(" [|nfs]", stdout
);
701 * Print out an NFS file handle.
702 * We assume packet was not truncated before the end of the
703 * file handle pointed to by dp.
705 * Note: new version (using portable file-handle parser) doesn't produce
706 * generation number. It probably could be made to do that, with some
707 * additional hacking on the parser code.
710 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
714 char *sfsname
= NULL
;
716 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
719 /* file system ID is ASCII, not numeric, for this server OS */
720 static char temp
[NFSX_V3FHMAX
+1];
722 /* Make sure string is null-terminated */
723 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
724 temp
[sizeof(temp
) - 1] = '\0';
725 /* Remove trailing spaces */
726 sfsname
= strchr(temp
, ' ');
730 (void)printf(" fh %s/", temp
);
732 (void)printf(" fh %d,%d/",
733 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
736 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
737 /* Print the undecoded handle */
738 (void)printf("%s", fsid
.Opaque_Handle
);
740 (void)printf("%ld", (long) ino
);
744 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
745 * us to match up replies with requests and thus to know how to parse
749 struct xid_map_entry
{
750 u_int32_t xid
; /* transaction ID (net order) */
751 int ipver
; /* IP version (4 or 6) */
753 struct in6_addr client
; /* client IP address (net order) */
754 struct in6_addr server
; /* server IP address (net order) */
756 struct in_addr client
; /* client IP address (net order) */
757 struct in_addr server
; /* server IP address (net order) */
759 u_int32_t proc
; /* call proc number (host order) */
760 u_int32_t vers
; /* program version (host order) */
764 * Map entries are kept in an array that we manage as a ring;
765 * new entries are always added at the tail of the ring. Initially,
766 * all the entries are zero and hence don't match anything.
769 #define XIDMAPSIZE 64
771 struct xid_map_entry xid_map
[XIDMAPSIZE
];
773 int xid_map_next
= 0;
774 int xid_map_hint
= 0;
777 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
779 struct ip
*ip
= NULL
;
781 struct ip6_hdr
*ip6
= NULL
;
783 struct xid_map_entry
*xmep
;
785 switch (((struct ip
*)bp
)->ip_v
) {
787 ip
= (struct ip
*)bp
;
791 ip6
= (struct ip6_hdr
*)bp
;
798 xmep
= &xid_map
[xid_map_next
];
800 if (++xid_map_next
>= XIDMAPSIZE
)
803 xmep
->xid
= rp
->rm_xid
;
806 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
807 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
812 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
813 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
816 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
817 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
821 * Returns 0 and puts NFSPROC_xxx in proc return and
822 * version in vers return, or returns -1 on failure
825 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
829 struct xid_map_entry
*xmep
;
830 u_int32_t xid
= rp
->rm_xid
;
831 struct ip
*ip
= (struct ip
*)ip
;
833 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
837 /* Start searching from where we last left off */
842 if (xmep
->ipver
!= ip
->ip_v
|| xmep
->xid
!= xid
)
844 switch (xmep
->ipver
) {
846 if (memcmp(&ip
->ip_src
, &xmep
->server
,
847 sizeof(ip
->ip_src
)) != 0 ||
848 memcmp(&ip
->ip_dst
, &xmep
->client
,
849 sizeof(ip
->ip_dst
)) != 0) {
855 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
856 sizeof(ip6
->ip6_src
)) != 0 ||
857 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
858 sizeof(ip6
->ip6_dst
)) != 0) {
875 if (++i
>= XIDMAPSIZE
)
877 } while (i
!= xid_map_hint
);
884 * Routines for parsing reply packets
888 * Return a pointer to the beginning of the actual results.
889 * If the packet was truncated, return 0.
891 static const u_int32_t
*
892 parserep(register const struct rpc_msg
*rp
, register u_int length
)
894 register const u_int32_t
*dp
;
896 enum accept_stat astat
;
900 * Here we find the address of the ar_verf credentials.
901 * Originally, this calculation was
902 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
903 * On the wire, the rp_acpt field starts immediately after
904 * the (32 bit) rp_stat field. However, rp_acpt (which is a
905 * "struct accepted_reply") contains a "struct opaque_auth",
906 * whose internal representation contains a pointer, so on a
907 * 64-bit machine the compiler inserts 32 bits of padding
908 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
909 * the internal representation to parse the on-the-wire
910 * representation. Instead, we skip past the rp_stat field,
911 * which is an "enum" and so occupies one 32-bit word.
913 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
919 * skip past the ar_verf credentials.
921 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
925 * now we can check the ar_stat field
927 astat
= ntohl(*(enum accept_stat
*)dp
);
934 printf(" PROG_UNAVAIL");
935 nfserr
= 1; /* suppress trunc string */
939 printf(" PROG_MISMATCH");
940 nfserr
= 1; /* suppress trunc string */
944 printf(" PROC_UNAVAIL");
945 nfserr
= 1; /* suppress trunc string */
949 printf(" GARBAGE_ARGS");
950 nfserr
= 1; /* suppress trunc string */
954 printf(" SYSTEM_ERR");
955 nfserr
= 1; /* suppress trunc string */
959 printf(" ar_stat %d", astat
);
960 nfserr
= 1; /* suppress trunc string */
963 /* successful return */
964 TCHECK2(*dp
, sizeof(astat
));
965 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
970 static const u_int32_t
*
971 parsestatus(const u_int32_t
*dp
, int *er
)
977 errnum
= ntohl(dp
[0]);
982 printf(" ERROR: %s", pcap_strerror(errnum
));
991 static const u_int32_t
*
992 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
994 const struct nfs_fattr
*fap
;
996 fap
= (const struct nfs_fattr
*)dp
;
999 printf(" %s %o ids %d/%d",
1000 tok2str(type2str
, "unk-ft %d ",
1001 (u_int32_t
)ntohl(fap
->fa_type
)),
1002 (u_int32_t
)ntohl(fap
->fa_mode
),
1003 (u_int32_t
)ntohl(fap
->fa_uid
),
1004 (u_int32_t
) ntohl(fap
->fa_gid
));
1006 TCHECK(fap
->fa3_size
);
1008 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1011 TCHECK(fap
->fa2_size
);
1012 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1015 /* print lots more stuff */
1018 TCHECK(fap
->fa3_ctime
);
1019 printf("nlink %d rdev %d/%d ",
1020 (u_int32_t
)ntohl(fap
->fa_nlink
),
1021 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1022 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1024 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1026 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1027 printf(" a/m/ctime %u.%06u ",
1028 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1029 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1031 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1032 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1034 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1035 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1037 TCHECK(fap
->fa2_ctime
);
1038 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1039 (u_int32_t
) ntohl(fap
->fa_nlink
),
1040 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1041 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1042 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1044 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1045 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1047 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1048 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1050 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1051 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1054 return ((const u_int32_t
*)((unsigned char *)dp
+
1055 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1061 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1065 dp
= parsestatus(dp
, &er
);
1066 if (dp
== NULL
|| er
)
1069 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1073 parsediropres(const u_int32_t
*dp
)
1077 if (!(dp
= parsestatus(dp
, &er
)) || er
)
1080 dp
= parsefh(dp
, 0);
1084 return (parsefattr(dp
, vflag
, 0) != NULL
);
1088 parselinkres(const u_int32_t
*dp
, int v3
)
1092 dp
= parsestatus(dp
, &er
);
1093 if (dp
== NULL
|| er
)
1095 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1098 return (parsefn(dp
) != NULL
);
1102 parsestatfs(const u_int32_t
*dp
, int v3
)
1104 const struct nfs_statfs
*sfsp
;
1107 dp
= parsestatus(dp
, &er
);
1108 if (dp
== NULL
|| (!v3
&& er
))
1117 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1121 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1123 sfsp
= (const struct nfs_statfs
*)dp
;
1127 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1129 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1131 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1134 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1136 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1138 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1140 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1143 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1144 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1145 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1146 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1147 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1148 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1157 parserddires(const u_int32_t
*dp
)
1161 dp
= parsestatus(dp
, &er
);
1168 printf(" offset %x size %d ",
1169 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1178 static const u_int32_t
*
1179 parse_wcc_attr(const u_int32_t
*dp
)
1182 print_int64(dp
, UNSIGNED
);
1183 printf(" mtime %u.%06u ctime %u.%06u",
1184 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1185 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1190 * Pre operation attributes. Print only if vflag > 1.
1192 static const u_int32_t
*
1193 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1201 return parse_wcc_attr(dp
);
1203 /* If not verbose enough, just skip over wcc_attr */
1211 * Post operation attributes are printed if vflag >= 1
1213 static const u_int32_t
*
1214 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1221 return parsefattr(dp
, verbose
, 1);
1223 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1228 static const u_int32_t
*
1229 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1233 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1238 return parse_post_op_attr(dp
, verbose
);
1241 static const u_int32_t
*
1242 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1246 if (!(dp
= parsestatus(dp
, &er
)))
1249 dp
= parse_wcc_data(dp
, verbose
);
1255 if (!(dp
= parsefh(dp
, 1)))
1258 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1261 printf("dir attr:");
1262 dp
= parse_wcc_data(dp
, verbose
);
1272 parsewccres(const u_int32_t
*dp
, int verbose
)
1276 if (!(dp
= parsestatus(dp
, &er
)))
1278 return parse_wcc_data(dp
, verbose
) != 0;
1281 static const u_int32_t
*
1282 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1286 if (!(dp
= parsestatus(dp
, &er
)))
1290 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1296 printf(" verf %08x%08x", dp
[0], dp
[1]);
1305 parsefsinfo(const u_int32_t
*dp
)
1307 struct nfsv3_fsinfo
*sfp
;
1310 if (!(dp
= parsestatus(dp
, &er
)))
1314 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1319 sfp
= (struct nfsv3_fsinfo
*)dp
;
1321 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1322 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1323 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1324 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1325 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1326 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1328 printf(" rtmult %u wtmult %u maxfsz ",
1329 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1330 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1331 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1332 printf(" delta %u.%06u ",
1333 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1334 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1342 parsepathconf(const u_int32_t
*dp
)
1345 struct nfsv3_pathconf
*spp
;
1347 if (!(dp
= parsestatus(dp
, &er
)))
1351 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1356 spp
= (struct nfsv3_pathconf
*)dp
;
1359 printf(" linkmax %u namemax %u %s %s %s %s",
1360 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1361 (u_int32_t
) ntohl(spp
->pc_namemax
),
1362 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1363 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1364 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1365 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1372 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1374 register const u_int32_t
*dp
;
1378 v3
= (vers
== NFS_VER3
);
1380 if (!v3
&& proc
< NFS_NPROCS
)
1381 proc
= nfsv3_procid
[proc
];
1393 case NFSPROC_GETATTR
:
1395 dp
= parserep(rp
, length
);
1396 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1400 case NFSPROC_SETATTR
:
1402 if (!(dp
= parserep(rp
, length
)))
1405 if (parsewccres(dp
, vflag
))
1408 if (parseattrstat(dp
, !qflag
, 0) != 0)
1413 case NFSPROC_LOOKUP
:
1415 if (!(dp
= parserep(rp
, length
)))
1418 if (!(dp
= parsestatus(dp
, &er
)))
1422 printf(" post dattr:");
1423 dp
= parse_post_op_attr(dp
, vflag
);
1426 if (!(dp
= parsefh(dp
, v3
)))
1428 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1430 printf(" post dattr:");
1431 dp
= parse_post_op_attr(dp
, vflag
);
1437 if (parsediropres(dp
) != 0)
1442 case NFSPROC_ACCESS
:
1444 dp
= parserep(rp
, length
);
1445 if (!(dp
= parsestatus(dp
, &er
)))
1449 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1452 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1455 case NFSPROC_READLINK
:
1456 printf(" readlink");
1457 dp
= parserep(rp
, length
);
1458 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1464 if (!(dp
= parserep(rp
, length
)))
1467 if (!(dp
= parsestatus(dp
, &er
)))
1469 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1475 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1481 if (parseattrstat(dp
, vflag
, 0) != 0)
1488 if (!(dp
= parserep(rp
, length
)))
1491 if (!(dp
= parsestatus(dp
, &er
)))
1493 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1499 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1503 tok2str(nfsv3_writemodes
,
1504 NULL
, ntohl(dp
[1])));
1509 if (parseattrstat(dp
, vflag
, v3
) != 0)
1514 case NFSPROC_CREATE
:
1516 if (!(dp
= parserep(rp
, length
)))
1519 if (parsecreateopres(dp
, vflag
) != 0)
1522 if (parsediropres(dp
) != 0)
1529 if (!(dp
= parserep(rp
, length
)))
1532 if (parsecreateopres(dp
, vflag
) != 0)
1535 if (parsediropres(dp
) != 0)
1540 case NFSPROC_SYMLINK
:
1542 if (!(dp
= parserep(rp
, length
)))
1545 if (parsecreateopres(dp
, vflag
) != 0)
1548 if (parsestatus(dp
, &er
) != 0)
1555 if (!(dp
= parserep(rp
, length
)))
1557 if (parsecreateopres(dp
, vflag
) != 0)
1561 case NFSPROC_REMOVE
:
1563 if (!(dp
= parserep(rp
, length
)))
1566 if (parsewccres(dp
, vflag
))
1569 if (parsestatus(dp
, &er
) != 0)
1576 if (!(dp
= parserep(rp
, length
)))
1579 if (parsewccres(dp
, vflag
))
1582 if (parsestatus(dp
, &er
) != 0)
1587 case NFSPROC_RENAME
:
1589 if (!(dp
= parserep(rp
, length
)))
1592 if (!(dp
= parsestatus(dp
, &er
)))
1596 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1599 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1604 if (parsestatus(dp
, &er
) != 0)
1611 if (!(dp
= parserep(rp
, length
)))
1614 if (!(dp
= parsestatus(dp
, &er
)))
1617 printf(" file POST:");
1618 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1621 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1626 if (parsestatus(dp
, &er
) != 0)
1631 case NFSPROC_READDIR
:
1633 if (!(dp
= parserep(rp
, length
)))
1636 if (parsev3rddirres(dp
, vflag
))
1639 if (parserddires(dp
) != 0)
1644 case NFSPROC_READDIRPLUS
:
1645 printf(" readdirplus");
1646 if (!(dp
= parserep(rp
, length
)))
1648 if (parsev3rddirres(dp
, vflag
))
1652 case NFSPROC_FSSTAT
:
1654 dp
= parserep(rp
, length
);
1655 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1659 case NFSPROC_FSINFO
:
1661 dp
= parserep(rp
, length
);
1662 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1666 case NFSPROC_PATHCONF
:
1667 printf(" pathconf");
1668 dp
= parserep(rp
, length
);
1669 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1673 case NFSPROC_COMMIT
:
1675 dp
= parserep(rp
, length
);
1676 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1681 printf(" proc-%u", proc
);
1686 fputs(" [|nfs]", stdout
);