]>
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.68 1999-11-21 09:36:57 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 const char *nfsv3_writemodes
[NFSV3WRITE_NMODES
] = {
106 static struct tok type2str
[] = {
118 * Print out a 64-bit integer. This appears to be different on each system,
119 * try to make the best of it. The integer stored as 2 consecutive XDR
120 * encoded 32-bit integers, to which a pointer is passed.
122 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
123 * integer datatype and can print it.
130 static int print_int64(const u_int32_t
*dp
, int how
)
135 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
138 printf(INT64_FORMAT
, res
);
141 printf(U_INT64_FORMAT
, res
);
144 printf(HEX_INT64_FORMAT
, res
);
154 printf ("0x%x%x", dp
[0], dp
[1]);
163 static const u_int32_t
*
164 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
166 register const u_int32_t
*ep
= (u_int32_t
*)snapend
;
170 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
173 sa3
->sa_mode
= ntohl(*dp
++);
178 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
181 sa3
->sa_uid
= ntohl(*dp
++);
186 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
189 sa3
->sa_gid
= ntohl(*dp
++);
194 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
197 sa3
->sa_size
= ntohl(*dp
++);
202 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
205 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
206 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
211 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
214 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
215 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
221 static int nfserr
; /* true if we error rather than trunc */
224 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
227 printf(" mode %o", sa3
->sa_mode
);
229 printf(" uid %u", sa3
->sa_uid
);
231 printf(" gid %u", sa3
->sa_gid
);
233 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
234 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
235 sa3
->sa_atime
.nfsv3_nsec
);
236 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
237 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
238 sa3
->sa_mtime
.nfsv3_nsec
);
243 nfsreply_print(register const u_char
*bp
, u_int length
,
244 register const u_char
*bp2
)
246 register const struct rpc_msg
*rp
;
247 register const struct ip
*ip
;
248 u_int32_t proc
, vers
;
250 nfserr
= 0; /* assume no error */
251 rp
= (const struct rpc_msg
*)bp
;
252 ip
= (const struct ip
*)bp2
;
255 (void)printf("%s.nfs > %s.%u: reply %s %d",
256 ipaddr_string(&ip
->ip_src
),
257 ipaddr_string(&ip
->ip_dst
),
258 (u_int32_t
)ntohl(rp
->rm_xid
),
259 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
263 (void)printf("%s.%u > %s.%u: reply %s %d",
264 ipaddr_string(&ip
->ip_src
),
266 ipaddr_string(&ip
->ip_dst
),
267 (u_int32_t
)ntohl(rp
->rm_xid
),
268 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
272 if (xid_map_find(rp
, ip
, &proc
, &vers
) >= 0)
273 interp_reply(rp
, proc
, vers
, length
);
277 * Return a pointer to the first file handle in the packet.
278 * If the packet was truncated, return 0.
280 static const u_int32_t
*
281 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
283 register const u_int32_t
*dp
;
287 * find the start of the req data (if we captured it)
289 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
293 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
297 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
307 * Print out an NFS file handle and return a pointer to following word.
308 * If packet was truncated, return 0.
310 static const u_int32_t
*
311 parsefh(register const u_int32_t
*dp
, int v3
)
316 if (dp
+ 1 > (u_int32_t
*)snapend
)
318 len
= (int)ntohl(*dp
) / 4;
323 if (dp
+ len
<= (u_int32_t
*)snapend
) {
324 nfs_printfh(dp
, len
);
331 * Print out a file name and return pointer to 32-bit word past it.
332 * If packet was truncated, return 0.
334 static const u_int32_t
*
335 parsefn(register const u_int32_t
*dp
)
337 register u_int32_t len
;
338 register const u_char
*cp
;
340 /* Bail if we don't have the string length */
341 if ((u_char
*)dp
> snapend
- sizeof(*dp
))
344 /* Fetch string length; convert to host order */
349 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
350 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
351 if ((u_char
*)dp
> snapend
)
353 /* XXX seems like we should be checking the length */
355 (void) fn_printn(cp
, len
, NULL
);
362 * Print out file handle and file name.
363 * Return pointer to 32-bit word past file name.
364 * If packet was truncated (or there was some other error), return 0.
366 static const u_int32_t
*
367 parsefhn(register const u_int32_t
*dp
, int v3
)
369 dp
= parsefh(dp
, v3
);
373 return (parsefn(dp
));
377 nfsreq_print(register const u_char
*bp
, u_int length
,
378 register const u_char
*bp2
)
380 register const struct rpc_msg
*rp
;
381 register const struct ip
*ip
;
382 register const u_int32_t
*dp
;
386 struct nfsv3_sattr sa3
;
388 nfserr
= 0; /* assume no error */
389 rp
= (const struct rpc_msg
*)bp
;
390 ip
= (const struct ip
*)bp2
;
392 (void)printf("%s.%u > %s.nfs: %d",
393 ipaddr_string(&ip
->ip_src
),
394 (u_int32_t
)ntohl(rp
->rm_xid
),
395 ipaddr_string(&ip
->ip_dst
),
398 (void)printf("%s.%u > %s.%u: %d",
399 ipaddr_string(&ip
->ip_src
),
400 (u_int32_t
)ntohl(rp
->rm_xid
),
401 ipaddr_string(&ip
->ip_dst
),
405 xid_map_enter(rp
, ip
); /* record proc number for later on */
407 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
408 proc
= ntohl(rp
->rm_call
.cb_proc
);
410 if (!v3
&& proc
< NFS_NPROCS
)
411 proc
= nfsv3_procid
[proc
];
421 case NFSPROC_GETATTR
:
423 if ((dp
= parsereq(rp
, length
)) != NULL
&&
424 parsefh(dp
, v3
) != NULL
)
428 case NFSPROC_SETATTR
:
430 if ((dp
= parsereq(rp
, length
)) != NULL
&&
431 parsefh(dp
, v3
) != NULL
)
437 if ((dp
= parsereq(rp
, length
)) != NULL
&&
438 parsefhn(dp
, v3
) != NULL
)
444 if ((dp
= parsereq(rp
, length
)) != NULL
&&
445 (dp
= parsefh(dp
, v3
)) != NULL
) {
447 printf(" %04x", ntohl(dp
[0]));
452 case NFSPROC_READLINK
:
454 if ((dp
= parsereq(rp
, length
)) != NULL
&&
455 parsefh(dp
, v3
) != NULL
)
461 if ((dp
= parsereq(rp
, length
)) != NULL
&&
462 (dp
= parsefh(dp
, v3
)) != NULL
) {
464 TCHECK2(dp
[0], 3 * sizeof(*dp
));
465 printf(" %u bytes @ ",
466 (u_int32_t
) ntohl(dp
[2]));
467 print_int64(dp
, UNSIGNED
);
469 TCHECK2(dp
[0], 2 * sizeof(*dp
));
470 printf(" %u bytes @ %u",
471 (u_int32_t
)ntohl(dp
[1]),
472 (u_int32_t
)ntohl(dp
[0]));
480 if ((dp
= parsereq(rp
, length
)) != NULL
&&
481 (dp
= parsefh(dp
, v3
)) != NULL
) {
483 TCHECK2(dp
[0], 3 * sizeof(*dp
));
484 printf(" %u bytes @ ",
485 (u_int32_t
) ntohl(dp
[4]));
486 print_int64(dp
, UNSIGNED
);
489 TCHECK2(dp
[0], sizeof(*dp
));
491 nfsv3_writemodes
[ntohl(*dp
)]);
494 TCHECK2(dp
[0], 4 * sizeof(*dp
));
495 printf(" %u (%u) bytes @ %u (%u)",
496 (u_int32_t
)ntohl(dp
[3]),
497 (u_int32_t
)ntohl(dp
[2]),
498 (u_int32_t
)ntohl(dp
[1]),
499 (u_int32_t
)ntohl(dp
[0]));
507 if ((dp
= parsereq(rp
, length
)) != NULL
&&
508 parsefhn(dp
, v3
) != NULL
)
514 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
518 case NFSPROC_SYMLINK
:
520 if ((dp
= parsereq(rp
, length
)) != 0 &&
521 (dp
= parsefhn(dp
, v3
)) != 0) {
522 fputs(" ->", stdout
);
523 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
525 if (parsefn(dp
) == 0)
528 print_sattr3(&sa3
, vflag
);
535 if ((dp
= parsereq(rp
, length
)) != 0 &&
536 (dp
= parsefhn(dp
, v3
)) != 0) {
537 if (dp
+ 1 > (u_int32_t
*)snapend
)
539 type
= (nfstype
)ntohl(*dp
++);
540 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
542 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
543 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
544 if (dp
+ 2 > (u_int32_t
*)snapend
)
546 printf(" %u/%u", ntohl(dp
[0]), ntohl(dp
[1]));
550 print_sattr3(&sa3
, vflag
);
557 if ((dp
= parsereq(rp
, length
)) != NULL
&&
558 parsefhn(dp
, v3
) != NULL
)
564 if ((dp
= parsereq(rp
, length
)) != NULL
&&
565 parsefhn(dp
, v3
) != NULL
)
571 if ((dp
= parsereq(rp
, length
)) != NULL
&&
572 (dp
= parsefhn(dp
, v3
)) != NULL
) {
573 fputs(" ->", stdout
);
574 if (parsefhn(dp
, v3
) != NULL
)
581 if ((dp
= parsereq(rp
, length
)) != NULL
&&
582 (dp
= parsefh(dp
, v3
)) != NULL
) {
583 fputs(" ->", stdout
);
584 if (parsefhn(dp
, v3
) != NULL
)
589 case NFSPROC_READDIR
:
591 if ((dp
= parsereq(rp
, length
)) != NULL
&&
592 (dp
= parsefh(dp
, v3
)) != NULL
) {
596 * We shouldn't really try to interpret the
597 * offset cookie here.
599 printf(" %u bytes @ ",
600 (u_int32_t
) ntohl(dp
[4]));
601 print_int64(dp
, SIGNED
);
603 printf(" verf %08x%08x", dp
[2],
606 TCHECK2(dp
[0], 2 * sizeof(*dp
));
608 * Print the offset as signed, since -1 is
609 * common, but offsets > 2^31 aren't.
611 printf(" %u bytes @ %d",
612 (u_int32_t
)ntohl(dp
[1]),
613 (u_int32_t
)ntohl(dp
[0]));
619 case NFSPROC_READDIRPLUS
:
620 printf(" readdirplus");
621 if ((dp
= parsereq(rp
, length
)) != NULL
&&
622 (dp
= parsefh(dp
, v3
)) != NULL
) {
625 * We don't try to interpret the offset
628 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
629 print_int64(dp
, SIGNED
);
631 printf(" max %u verf %08x%08x",
632 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
639 if ((dp
= parsereq(rp
, length
)) != NULL
&&
640 parsefh(dp
, v3
) != NULL
)
648 case NFSPROC_PATHCONF
:
654 if ((dp
= parsereq(rp
, length
)) != NULL
&&
655 (dp
= parsefh(dp
, v3
)) != NULL
) {
656 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
657 print_int64(dp
, UNSIGNED
);
663 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
668 fputs(" [|nfs]", stdout
);
672 * Print out an NFS file handle.
673 * We assume packet was not truncated before the end of the
674 * file handle pointed to by dp.
676 * Note: new version (using portable file-handle parser) doesn't produce
677 * generation number. It probably could be made to do that, with some
678 * additional hacking on the parser code.
681 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
685 char *sfsname
= NULL
;
687 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
690 /* file system ID is ASCII, not numeric, for this server OS */
691 static char temp
[NFSX_V3FHMAX
+1];
693 /* Make sure string is null-terminated */
694 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
695 /* Remove trailing spaces */
696 sfsname
= strchr(temp
, ' ');
700 (void)printf(" fh %s/%ld", temp
, (long) ino
);
703 (void)printf(" fh %d,%d/%ld",
704 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
,
710 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
711 * us to match up replies with requests and thus to know how to parse
715 struct xid_map_entry
{
716 u_int32_t xid
; /* transaction ID (net order) */
717 struct in_addr client
; /* client IP address (net order) */
718 struct in_addr server
; /* server IP address (net order) */
719 u_int32_t proc
; /* call proc number (host order) */
720 u_int32_t vers
; /* program version (host order) */
724 * Map entries are kept in an array that we manage as a ring;
725 * new entries are always added at the tail of the ring. Initially,
726 * all the entries are zero and hence don't match anything.
729 #define XIDMAPSIZE 64
731 struct xid_map_entry xid_map
[XIDMAPSIZE
];
733 int xid_map_next
= 0;
734 int xid_map_hint
= 0;
737 xid_map_enter(const struct rpc_msg
*rp
, const struct ip
*ip
)
739 struct xid_map_entry
*xmep
;
741 xmep
= &xid_map
[xid_map_next
];
743 if (++xid_map_next
>= XIDMAPSIZE
)
746 xmep
->xid
= rp
->rm_xid
;
747 xmep
->client
= ip
->ip_src
;
748 xmep
->server
= ip
->ip_dst
;
749 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
750 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
753 /* Returns NFSPROC_xxx or -1 on failure */
755 xid_map_find(const struct rpc_msg
*rp
, const struct ip
*ip
, u_int32_t
*proc
,
759 struct xid_map_entry
*xmep
;
760 u_int32_t xid
= rp
->rm_xid
;
761 u_int32_t clip
= ip
->ip_dst
.s_addr
;
762 u_int32_t sip
= ip
->ip_src
.s_addr
;
764 /* Start searching from where we last left off */
768 if (xmep
->xid
== xid
&& xmep
->client
.s_addr
== clip
&&
769 xmep
->server
.s_addr
== sip
) {
776 if (++i
>= XIDMAPSIZE
)
778 } while (i
!= xid_map_hint
);
785 * Routines for parsing reply packets
789 * Return a pointer to the beginning of the actual results.
790 * If the packet was truncated, return 0.
792 static const u_int32_t
*
793 parserep(register const struct rpc_msg
*rp
, register u_int length
)
795 register const u_int32_t
*dp
;
797 enum accept_stat astat
;
801 * Here we find the address of the ar_verf credentials.
802 * Originally, this calculation was
803 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
804 * On the wire, the rp_acpt field starts immediately after
805 * the (32 bit) rp_stat field. However, rp_acpt (which is a
806 * "struct accepted_reply") contains a "struct opaque_auth",
807 * whose internal representation contains a pointer, so on a
808 * 64-bit machine the compiler inserts 32 bits of padding
809 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
810 * the internal representation to parse the on-the-wire
811 * representation. Instead, we skip past the rp_stat field,
812 * which is an "enum" and so occupies one 32-bit word.
814 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
820 * skip past the ar_verf credentials.
822 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
826 * now we can check the ar_stat field
828 astat
= ntohl(*(enum accept_stat
*)dp
);
835 printf(" PROG_UNAVAIL");
836 nfserr
= 1; /* suppress trunc string */
840 printf(" PROG_MISMATCH");
841 nfserr
= 1; /* suppress trunc string */
845 printf(" PROC_UNAVAIL");
846 nfserr
= 1; /* suppress trunc string */
850 printf(" GARBAGE_ARGS");
851 nfserr
= 1; /* suppress trunc string */
855 printf(" SYSTEM_ERR");
856 nfserr
= 1; /* suppress trunc string */
860 printf(" ar_stat %d", astat
);
861 nfserr
= 1; /* suppress trunc string */
864 /* successful return */
865 if ((sizeof(astat
) + ((u_char
*)dp
)) < snapend
)
866 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
871 #define T2CHECK(p, l) if ((u_char *)(p) > ((u_char *)snapend) - l) return(0)
874 * Not all systems have strerror().
879 return (strerror(errno
));
882 static const u_int32_t
*
883 parsestatus(const u_int32_t
*dp
, int *er
)
888 errno
= ntohl(dp
[0]);
891 if (errno
!= 0 && !qflag
) {
894 errmsg
= strerr(errno
);
896 printf(" ERROR: '%s'", errmsg
);
898 printf(" ERROR: %d", errno
);
903 static const u_int32_t
*
904 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
906 const struct nfs_fattr
*fap
;
908 T2CHECK(dp
, 5 * sizeof(*dp
));
910 fap
= (const struct nfs_fattr
*)dp
;
912 printf(" %s %o ids %d/%d",
913 tok2str(type2str
, "unk-ft %d ",
914 (u_int32_t
)ntohl(fap
->fa_type
)),
915 (u_int32_t
)ntohl(fap
->fa_mode
),
916 (u_int32_t
)ntohl(fap
->fa_uid
),
917 (u_int32_t
) ntohl(fap
->fa_gid
));
919 T2CHECK(dp
, 7 * sizeof(*dp
));
921 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
925 T2CHECK(dp
, 6 * sizeof(*dp
));
926 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
929 /* print lots more stuff */
933 printf("nlink %d rdev %d/%d ",
934 (u_int32_t
)ntohl(fap
->fa_nlink
),
935 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
936 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
938 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
940 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
941 printf(" a/m/ctime %u.%06u ",
942 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
943 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
945 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
946 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
948 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
949 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
952 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
953 (u_int32_t
) ntohl(fap
->fa_nlink
),
954 (u_int32_t
) ntohl(fap
->fa2_rdev
),
955 (u_int32_t
) ntohl(fap
->fa2_fsid
),
956 (u_int32_t
) ntohl(fap
->fa2_fileid
));
958 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
959 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
961 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
962 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
964 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
965 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
968 return ((const u_int32_t
*)((unsigned char *)dp
+
969 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
973 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
977 dp
= parsestatus(dp
, &er
);
978 if (dp
== NULL
|| er
)
981 return (parsefattr(dp
, verbose
, v3
) != NULL
);
985 parsediropres(const u_int32_t
*dp
)
989 if (!(dp
= parsestatus(dp
, &er
)) || er
)
996 return (parsefattr(dp
, vflag
, 0) != NULL
);
1000 parselinkres(const u_int32_t
*dp
, int v3
)
1004 dp
= parsestatus(dp
, &er
);
1005 if (dp
== NULL
|| er
)
1007 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1010 return (parsefn(dp
) != NULL
);
1014 parsestatfs(const u_int32_t
*dp
, int v3
)
1016 const struct nfs_statfs
*sfsp
;
1019 dp
= parsestatus(dp
, &er
);
1020 if (dp
== NULL
|| (!v3
&& er
))
1029 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1033 T2CHECK(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1035 sfsp
= (const struct nfs_statfs
*)dp
;
1039 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1041 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1043 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1046 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1048 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1050 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1052 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1055 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1056 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1057 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1058 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1059 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1060 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1067 parserddires(const u_int32_t
*dp
)
1071 dp
= parsestatus(dp
, &er
);
1078 printf(" offset %x size %d ", ntohl(dp
[0]), ntohl(dp
[1]));
1085 static const u_int32_t
*
1086 parse_wcc_attr(const u_int32_t
*dp
)
1089 print_int64(dp
, UNSIGNED
);
1090 printf(" mtime %u.%06u ctime %u.%06u", ntohl(dp
[2]), ntohl(dp
[3]),
1091 ntohl(dp
[4]), ntohl(dp
[5]));
1096 * Pre operation attributes. Print only if vflag > 1.
1098 static const u_int32_t
*
1099 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1107 return parse_wcc_attr(dp
);
1109 /* If not verbose enough, just skip over wcc_attr */
1115 * Post operation attributes are printed if vflag >= 1
1117 static const u_int32_t
*
1118 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1125 return parsefattr(dp
, verbose
, 1);
1127 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1130 static const u_int32_t
*
1131 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1135 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1140 return parse_post_op_attr(dp
, verbose
);
1143 static const u_int32_t
*
1144 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1148 if (!(dp
= parsestatus(dp
, &er
)))
1151 dp
= parse_wcc_data(dp
, verbose
);
1157 if (!(dp
= parsefh(dp
, 1)))
1160 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1163 printf("dir attr:");
1164 dp
= parse_wcc_data(dp
, verbose
);
1172 parsewccres(const u_int32_t
*dp
, int verbose
)
1176 if (!(dp
= parsestatus(dp
, &er
)))
1178 return parse_wcc_data(dp
, verbose
) != 0;
1181 static const u_int32_t
*
1182 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1186 if (!(dp
= parsestatus(dp
, &er
)))
1190 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1196 printf(" verf %08x%08x", dp
[0], dp
[1]);
1203 parsefsinfo(const u_int32_t
*dp
)
1205 struct nfsv3_fsinfo
*sfp
;
1208 if (!(dp
= parsestatus(dp
, &er
)))
1212 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1217 T2CHECK(dp
, sizeof (struct nfsv3_fsinfo
));
1219 sfp
= (struct nfsv3_fsinfo
*)dp
;
1220 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1221 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1222 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1223 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1224 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1225 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1227 printf(" rtmult %u wtmult %u maxfsz ",
1228 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1229 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1230 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1231 printf(" delta %u.%06u ",
1232 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1233 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1239 parsepathconf(const u_int32_t
*dp
)
1242 struct nfsv3_pathconf
*spp
;
1244 if (!(dp
= parsestatus(dp
, &er
)))
1248 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1253 T2CHECK(dp
, sizeof (struct nfsv3_pathconf
));
1255 spp
= (struct nfsv3_pathconf
*)dp
;
1257 printf(" linkmax %u namemax %u %s %s %s %s",
1258 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1259 (u_int32_t
) ntohl(spp
->pc_namemax
),
1260 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1261 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1262 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1263 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1268 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1270 register const u_int32_t
*dp
;
1274 v3
= (vers
== NFS_VER3
);
1276 if (!v3
&& proc
< NFS_NPROCS
)
1277 proc
= nfsv3_procid
[proc
];
1289 case NFSPROC_GETATTR
:
1291 dp
= parserep(rp
, length
);
1292 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1296 case NFSPROC_SETATTR
:
1298 if (!(dp
= parserep(rp
, length
)))
1301 if (parsewccres(dp
, vflag
))
1304 if (parseattrstat(dp
, !qflag
, 0) != 0)
1309 case NFSPROC_LOOKUP
:
1311 if (!(dp
= parserep(rp
, length
)))
1314 if (!(dp
= parsestatus(dp
, &er
)))
1318 printf(" post dattr:");
1319 dp
= parse_post_op_attr(dp
, vflag
);
1322 if (!(dp
= parsefh(dp
, v3
)))
1324 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1326 printf(" post dattr:");
1327 dp
= parse_post_op_attr(dp
, vflag
);
1333 if (parsediropres(dp
) != 0)
1338 case NFSPROC_ACCESS
:
1340 dp
= parserep(rp
, length
);
1341 if (!(dp
= parsestatus(dp
, &er
)))
1345 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1348 printf(" c %04x", ntohl(dp
[0]));
1351 case NFSPROC_READLINK
:
1352 printf(" readlink");
1353 dp
= parserep(rp
, length
);
1354 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1360 if (!(dp
= parserep(rp
, length
)))
1363 if (!(dp
= parsestatus(dp
, &er
)))
1365 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1371 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1377 if (parseattrstat(dp
, vflag
, 0) != 0)
1384 if (!(dp
= parserep(rp
, length
)))
1387 if (!(dp
= parsestatus(dp
, &er
)))
1389 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1395 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1399 nfsv3_writemodes
[ntohl(dp
[1])]);
1404 if (parseattrstat(dp
, vflag
, v3
) != 0)
1409 case NFSPROC_CREATE
:
1411 if (!(dp
= parserep(rp
, length
)))
1414 if (parsecreateopres(dp
, vflag
) != 0)
1417 if (parsediropres(dp
) != 0)
1424 if (!(dp
= parserep(rp
, length
)))
1427 if (parsecreateopres(dp
, vflag
) != 0)
1430 if (parsediropres(dp
) != 0)
1435 case NFSPROC_SYMLINK
:
1437 if (!(dp
= parserep(rp
, length
)))
1440 if (parsecreateopres(dp
, vflag
) != 0)
1443 if (parsestatus(dp
, &er
) != 0)
1450 if (!(dp
= parserep(rp
, length
)))
1452 if (parsecreateopres(dp
, vflag
) != 0)
1456 case NFSPROC_REMOVE
:
1458 if (!(dp
= parserep(rp
, length
)))
1461 if (parsewccres(dp
, vflag
))
1464 if (parsestatus(dp
, &er
) != 0)
1471 if (!(dp
= parserep(rp
, length
)))
1474 if (parsewccres(dp
, vflag
))
1477 if (parsestatus(dp
, &er
) != 0)
1482 case NFSPROC_RENAME
:
1484 if (!(dp
= parserep(rp
, length
)))
1487 if (!(dp
= parsestatus(dp
, &er
)))
1491 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1494 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1499 if (parsestatus(dp
, &er
) != 0)
1506 if (!(dp
= parserep(rp
, length
)))
1509 if (!(dp
= parsestatus(dp
, &er
)))
1512 printf(" file POST:");
1513 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1516 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1521 if (parsestatus(dp
, &er
) != 0)
1526 case NFSPROC_READDIR
:
1528 if (!(dp
= parserep(rp
, length
)))
1531 if (parsev3rddirres(dp
, vflag
))
1534 if (parserddires(dp
) != 0)
1539 case NFSPROC_READDIRPLUS
:
1540 printf(" readdirplus");
1541 if (!(dp
= parserep(rp
, length
)))
1543 if (parsev3rddirres(dp
, vflag
))
1547 case NFSPROC_FSSTAT
:
1549 dp
= parserep(rp
, length
);
1550 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1554 case NFSPROC_FSINFO
:
1556 dp
= parserep(rp
, length
);
1557 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1561 case NFSPROC_PATHCONF
:
1562 printf(" pathconf");
1563 dp
= parserep(rp
, length
);
1564 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1568 case NFSPROC_COMMIT
:
1570 dp
= parserep(rp
, length
);
1571 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1576 printf(" proc-%u", proc
);
1580 fputs(" [|nfs]", stdout
);