summaryrefslogtreecommitdiff
path: root/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_nfs4.c
blob: 40a169e9319a8b702cad68cb8d6626fea185f567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/tiuser.h>
#include <setjmp.h>

#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/clnt.h>
#include <rpc/rpc_msg.h>
#include "snoop.h"

#include <sys/stat.h>
#include <sys/param.h>
#include <rpcsvc/nfs_prot.h>
/* use the same nfs4_prot.h as the xdr code */
#include "rpcsvc/nfs4_prot.h"

/*
 * XXX With NFS v2 and v3, we only need to xdr the pieces that we care
 * about.  Anything else we can ignore and just skip to the next packet.
 * So all the stuff that deals directly with XDR lives in snoop_display.c
 * With v4, we need to XDR entire structures so that we can skip over
 * uninteresting bits in a compound array, so we call XDR directly from
 * here.  We need to rethink how we're going to structure XDR access.  Do
 * we continue to hide it all in snoop_display.c, or do we expose it to all
 * the protocol modules?
 */
extern XDR xdrm;

#ifndef MIN
#define	MIN(a, b)	((a) < (b) ? (a) : (b))
#endif

/*
 * Maximum number of characters to display in compound4 summary line.
 */
#define	SUM_COMPND_MAX	100

/*
 * Maximum number of recognized attributes.
 */
#define	MAX_ATTRIBUTES	56

/*
 * This data structure provides a more convenient way to access an
 * attribute bitmask.  map[N] = value of bit N in a bitmap4.
 * It's defined as a struct so as to step around all the weird rules in C
 * about arrays, pointers, passing them as arguments, etc.
 */

typedef struct {
	char map[MAX_ATTRIBUTES];
} unpkd_attrmap_t;


static void sumarg_cb_getattr(char *buf, size_t buflen, void *obj);
static void dtlarg_cb_getattr(void *obj);
static void sumarg_cb_recall(char *buf, size_t buflen, void *obj);
static void dtlarg_cb_recall(void *obj);


static void sumarg_access(char *buf, size_t buflen, void *obj);
static void dtlarg_access(void *obj);
static void sumarg_close(char *buf, size_t buflen, void *obj);
static void dtlarg_close(void *obj);
static void sumarg_commit(char *buf, size_t buflen, void *obj);
static void dtlarg_commit(void *obj);
static void sumarg_compnt(char *buf, size_t buflen, void *obj);
static void dtlarg_compnt(void *obj);
static void sumarg_create(char *buf, size_t buflen, void *obj);
static void dtlarg_create(void *obj);
static void sumarg_delprge(char *buf, size_t buflen, void *obj);
static void dtlarg_delprge(void *obj);
static void sumarg_delret(char *buf, size_t buflen, void *obj);
static void dtlarg_delret(void *obj);
static void sumarg_getattr(char *buf, size_t buflen, void *obj);
static void dtlarg_getattr(void *obj);
static void sumarg_link(char *buf, size_t buflen, void *obj);
static void dtlarg_link(void *obj);
static void sum_open_to_lock_owner(char *buf, int buflen,
					open_to_lock_owner4 *own);
static void sum_exist_lock_owner(char *buf, int buflen,
					exist_lock_owner4 *own);
static void sum_locker(char *buf, size_t buflen, locker4 *lk);
static void sumarg_lock(char *buf, size_t buflen, void *obj);
static void detail_open_to_lock_owner(open_to_lock_owner4 *own);
static void detail_exist_lock_owner(exist_lock_owner4 *own);
static void detail_locker(locker4 *lk);
static void dtlarg_lock(void *obj);
static void sumarg_lockt(char *buf, size_t buflen, void *obj);
static void dtlarg_lockt(void *obj);
static void sumarg_locku(char *buf, size_t buflen, void *obj);
static void dtlarg_locku(void *obj);
static void sumarg_lookup(char *buf, size_t buflen, void *obj);
static void dtlarg_lookup(void *obj);
static void sumarg_open(char *buf, size_t buflen, void *obj);
static void dtlarg_open(void *obj);
static void sumarg_openattr(char *buf, size_t buflen, void *obj);
static void dtlarg_openattr(void *obj);
static void sumarg_open_confirm(char *buf, size_t buflen, void *obj);
static void dtlarg_open_confirm(void *obj);
static void sumarg_open_downgrd(char *buf, size_t buflen, void *obj);
static void dtlarg_open_downgrd(void *obj);
static void sumarg_putfh(char *buf, size_t buflen, void *obj);
static void dtlarg_putfh(void *obj);
static void sumarg_read(char *buf, size_t buflen, void *obj);
static void dtlarg_read(void *obj);
static void sumarg_readdir(char *buf, size_t buflen, void *obj);
static void dtlarg_readdir(void *obj);
static void sumarg_release_lkown(char *buf, size_t buflen, void *obj);
static void dtlarg_release_lkown(void *obj);
static void sumarg_rename(char *buf, size_t buflen, void *obj);
static void dtlarg_rename(void *obj);
static void sumarg_renew(char *buf, size_t buflen, void *obj);
static void dtlarg_renew(void *buf);
static void sumarg_secinfo(char *buf, size_t buflen, void *obj);
static void dtlarg_secinfo(void *obj);
static void sumarg_setattr(char *buf, size_t buflen, void *obj);
static void dtlarg_setattr(void *obj);
static void sumarg_setclid(char *buf, size_t buflen, void *obj);
static void dtlarg_setclid(void *obj);
static void sumarg_setclid_cfm(char *buf, size_t buflen, void *obj);
static void dtlarg_setclid_cfm(void *obj);
static void dtlarg_verify(void *obj);
static void sumarg_write(char *buf, size_t buflen, void *obj);
static void dtlarg_write(void *obj);

static void sumres_cb_getattr(char *buf, size_t buflen, void *obj);
static void dtlres_cb_getattr(void *obj);

static void sumres_access(char *buf, size_t buflen, void *obj);
static void dtlres_access(void *obj);
static void sumres_close(char *buf, size_t buflen, void *obj);
static void dtlres_close(void *obj);
static void sumres_commit(char *buf, size_t buflen, void *obj);
static void dtlres_commit(void *obj);
static void dtlres_create(void *obj);
static void sumres_getattr(char *buf, size_t buflen, void *obj);
static void dtlres_getattr(void *obj);
static void sumres_getfh(char *buf, size_t buflen, void *obj);
static void dtlres_getfh(void *obj);
static void dtlres_link(void *obj);
static void sumres_lock(char *buf, size_t buflen, void *obj);
static void dtlres_lock(void *obj);
static void sumres_lockt(char *buf, size_t buflen, void *obj);
static void dtlres_lockt(void *obj);
static void sumres_locku(char *buf, size_t buflen, void *obj);
static void dtlres_locku(void *obj);
static void sumres_open(char *buf, size_t buflen, void *obj);
static void dtlres_open(void *obj);
static void sumres_open_confirm(char *buf, size_t buflen, void *obj);
static void dtlres_open_confirm(void *obj);
static void sumres_open_downgrd(char *buf, size_t buflen, void *obj);
static void dtlres_open_downgrd(void *obj);
static void sumres_read(char *buf, size_t buflen, void *obj);
static void dtlres_read(void *obj);
static void sumres_readdir(char *buf, size_t buflen, void *obj);
static void dtlres_readdir(void *obj);
static void sumres_readlnk(char *buf, size_t buflen, void *obj);
static void dtlres_readlnk(void *obj);
static void dtlres_remove(void *obj);
static void dtlres_rename(void *obj);
static void sumres_secinfo(char *buf, size_t buflen, void *obj);
static void dtlres_secinfo(void *obj);
static void sumres_setattr(char *buf, size_t buflen, void *obj);
static void dtlres_setattr(void *obj);
static void sumres_setclid(char *buf, size_t buflen, void *obj);
static void dtlres_setclid(void *obj);
static void sumres_write(char *buf, size_t buflen, void *obj);
static void dtlres_write(void *obj);
static void sum_nfsstat4(char *buf, size_t buflen, void *obj);
static void dtl_nfsstat4(void *obj);
static uint32_t adler16(void *, int);
static void nfs4_xdr_skip(int nbytes);
static char *sum_lock_type_name(enum nfs_lock_type4 type);

int nfs4_pkt_start;
int nfs4_pkt_len;
int nfs4_skip_bytes;
int nfs4_fragged_rpc;
char *nfs4err_fragrpc = "<Fragmented RPC>";
char *nfs4err_xdrfrag = "<XDR Error or Fragmented RPC>";

/*
 * need a way to enable this if current testcases are parsing snoop
 * error text. -- maybe an env var would do as temp workaround until
 * testcases changed to grep for new error text.
 */
int nfs4_use_old_error_text = 0;

/*
 * Information about each operation that can appear in a compound call.
 * The function pointers are to formatting functions for summary arguments
 * and results, and detail arguments & results.
 */

typedef struct {
	char	*name;
	void	(*sumarg)(char *, size_t, void *);
	void	(*sumres)(char *, size_t, void *);
	void	(*dtlarg)(void *);
	void	(*dtlres)(void *);
} op_info_t;

static op_info_t cb_opcode_info[] = {
	{"OP_ZERO",	NULL,	NULL,	NULL,	NULL},	/* 0 */
	{"OP_ONE",	NULL,	NULL,	NULL,	NULL},
	{"OP_TWO",	NULL,	NULL,	NULL,	NULL},  /* minor vers */
	{"CB_GETATTR",
		sumarg_cb_getattr,	sumres_cb_getattr,
		dtlarg_cb_getattr,	dtlres_cb_getattr},
	{"CB_RECALL",
		sumarg_cb_recall,	sum_nfsstat4,
		dtlarg_cb_recall,	dtl_nfsstat4},
};
static uint_t cb_num_opcodes = sizeof (cb_opcode_info) / sizeof (op_info_t *);

static op_info_t opcode_info[] = {
	{"OP_ZERO",	NULL,	NULL,	NULL,	NULL},	/* 0 */
	{"OP_ONE",	NULL,	NULL,	NULL,	NULL},
	{"OP_TWO",	NULL,	NULL,	NULL,	NULL},  /* minor vers */
	{"ACCESS",
	sumarg_access,	sumres_access,	dtlarg_access,	dtlres_access},
	{"CLOSE",
	sumarg_close,	sumres_close,	dtlarg_close,	dtlres_close},
	{"COMMIT",
	sumarg_commit,	sumres_commit,	dtlarg_commit,	dtlres_commit},
	{"CREATE",					/* 5 */
	sumarg_create,	sum_nfsstat4,	dtlarg_create,	dtlres_create},
	{"DELEGPURGE",
	sumarg_delprge,	sum_nfsstat4,	dtlarg_delprge,	dtl_nfsstat4},
	{"DELEGRETURN",
	sumarg_delret,	sum_nfsstat4,	dtlarg_delret,	dtl_nfsstat4},
	{"GETATTR",
	sumarg_getattr,	sumres_getattr,	dtlarg_getattr,	dtlres_getattr},
	{"GETFH",
	NULL,		sumres_getfh,	NULL,	dtlres_getfh},
	{"LINK",					/* 10 */
	sumarg_link,	sum_nfsstat4,	dtlarg_link,	dtlres_link},
	{"LOCK",
	sumarg_lock,	sumres_lock,	dtlarg_lock,	dtlres_lock},
	{"LOCKT",
	sumarg_lockt,	sumres_lockt,	dtlarg_lockt,	dtlres_lockt},
	{"LOCKU",
	sumarg_locku,	sumres_locku,	dtlarg_locku,	dtlres_locku},
	{"LOOKUP",
	sumarg_lookup,	sum_nfsstat4,	dtlarg_lookup,	dtl_nfsstat4},
	{"LOOKUPP",					/* 15 */
	NULL,		sum_nfsstat4,	NULL,		dtl_nfsstat4},
	{"NVERIFY",
	NULL,		sum_nfsstat4,	dtlarg_verify,	dtl_nfsstat4},
	{"OPEN",
	sumarg_open,	sumres_open,	dtlarg_open,	dtlres_open},
	{"OPENATTR",
	sumarg_openattr, sum_nfsstat4, dtlarg_openattr, dtl_nfsstat4},
	{"OPEN_CONFIRM",
	sumarg_open_confirm,
	sumres_open_confirm,
	dtlarg_open_confirm,
	dtlres_open_confirm},
	{"OPEN_DOWNGRADE",
	sumarg_open_downgrd,
	sumres_open_downgrd,
	dtlarg_open_downgrd,
	dtlres_open_downgrd},
	{"PUTFH",
	sumarg_putfh,	sum_nfsstat4,	dtlarg_putfh,	dtl_nfsstat4},
	{"PUTPUBFH",					/* 20 */
	NULL,		sum_nfsstat4,	NULL,		dtl_nfsstat4},
	{"PUTROOTFH",
	NULL,		sum_nfsstat4,	NULL,		dtl_nfsstat4},
	{"READ",
	sumarg_read,	sumres_read,	dtlarg_read,	dtlres_read},
	{"READDIR",
	sumarg_readdir,	sumres_readdir,	dtlarg_readdir,	dtlres_readdir},
	{"READLINK",
	NULL,		sumres_readlnk,	NULL,		dtlres_readlnk},
	{"REMOVE",					/* 25 */
	sumarg_compnt,	sum_nfsstat4,	dtlarg_compnt,	dtlres_remove},
	{"RENAME",
	sumarg_rename,	sum_nfsstat4,	dtlarg_rename,	dtlres_rename},
	{"RENEW",
	sumarg_renew,	sum_nfsstat4,	dtlarg_renew,	dtl_nfsstat4},
	{"RESTOREFH",
	NULL,		sum_nfsstat4,	NULL,		dtl_nfsstat4},
	{"SAVEFH",
	NULL,		sum_nfsstat4,	NULL,		dtl_nfsstat4},
	{"SECINFO",					/* 30 */
	sumarg_secinfo,	sumres_secinfo,	dtlarg_secinfo,	dtlres_secinfo},
	{"SETATTR",
	sumarg_setattr,	sumres_setattr,	dtlarg_setattr,	dtlres_setattr},
	{"SETCLIENTID",
	sumarg_setclid,	sumres_setclid,	dtlarg_setclid,	dtlres_setclid},
	{"SETCLIENTID_CONFIRM",
	sumarg_setclid_cfm,
	sum_nfsstat4,
	dtlarg_setclid_cfm,
	dtl_nfsstat4},
	{"VERIFY",
	NULL,		sum_nfsstat4,	dtlarg_verify,	dtl_nfsstat4},
	{"WRITE",
	sumarg_write,	sumres_write,	dtlarg_write,	dtlres_write},
	{"RELEASE_LOCKOWNER",
	sumarg_release_lkown, sum_nfsstat4,
	dtlarg_release_lkown, dtl_nfsstat4},
};
static uint_t num_opcodes = sizeof (opcode_info) / sizeof (op_info_t *);

/*
 * File types.
 */

typedef struct {
	char *short_name;		/* for summary output */
	char *long_name;		/* for detail output */
} ftype_names_t;

static ftype_names_t ftype_names[] = {
	{"Type 0",	"Type 0"},
	{"REG",		"Regular File"},
	{"DIR",		"Directory"},
	{"BLK",		"Block Device"},
	{"CHR",		"Character Device"},
	{"LNK",		"Symbolic Link"},	/* 5 */
	{"SOCK",	"Socket"},
	{"FIFO",	"FIFO"},
	{"ATTRDIR",	"Attribute Directory"},
	{"NAMEDATTR",	"Named Attribute"},
};
static uint_t num_ftypes = sizeof (ftype_names) / sizeof (ftype_names_t);

static ftype_names_t	open_rflags[] = {
	{"?",	"UNKNOWN"},	/* 0 */
	{"CF",	"CONFIRM"},	/* 1 */
	{"PL",	"POSIX LOCK"},	/* 2 */
	{"?",	"UNKNOWN"},
};
static uint_t num_open_rflags =
	sizeof (open_rflags) / sizeof (ftype_names_t) - 1;

static char *get_flags(uint_t, ftype_names_t *, uint_t, int, char *);

#define	sum_open_rflags(flag) \
	get_flags((flag), open_rflags, num_open_rflags, 1, " RF=")

#define	detail_open_rflags(flag) \
	get_flags((flag), open_rflags, num_open_rflags, 0, NULL)

static void prt_supported_attrs(XDR *);
static void prt_type(XDR *);
static void prt_fh_expire_type(XDR *);
static void prt_change(XDR *);
static void prt_size(XDR *);
static void prt_link_support(XDR *);
static void prt_symlink_support(XDR *);
static void prt_named_attr(XDR *);
static void prt_fsid(XDR *);
static void prt_unique_handles(XDR *);
static void prt_lease_time(XDR *);
static void prt_rdattr_error(XDR *);
static void prt_acl(XDR *);
static void prt_aclsupport(XDR *);
static void prt_archive(XDR *);
static void prt_cansettime(XDR *);
static void prt_case_insensitive(XDR *);
static void prt_case_preserving(XDR *);
static void prt_chown_restricted(XDR *);
static void prt_filehandle(XDR *);
static void prt_fileid(XDR *);
static void prt_mounted_on_fileid(XDR *);
static void prt_files_avail(XDR *);
static void prt_files_free(XDR *);
static void prt_files_total(XDR *);
static void prt_fs_locations(XDR *);
static void prt_hidden(XDR *);
static void prt_homogeneous(XDR *);
static void prt_maxfilesize(XDR *);
static void prt_maxlink(XDR *);
static void prt_maxname(XDR *);
static void prt_maxread(XDR *);
static void prt_maxwrite(XDR *);
static void prt_mimetype(XDR *);
static void prt_mode(XDR *);
static void prt_no_trunc(XDR *);
static void prt_numlinks(XDR *);
static void prt_owner(XDR *);
static void prt_owner_group(XDR *);
static void prt_quota_avail_hard(XDR *);
static void prt_quota_avail_soft(XDR *);
static void prt_quota_used(XDR *);
static void prt_rawdev(XDR *);
static void prt_space_avail(XDR *);
static void prt_space_free(XDR *);
static void prt_space_total(XDR *);
static void prt_space_used(XDR *);
static void prt_system(XDR *);
static void prt_time_access(XDR *);
static void prt_time_access_set(XDR *);
static void prt_time_backup(XDR *);
static void prt_time_create(XDR *);
static void prt_time_delta(XDR *);
static void prt_time_metadata(XDR *);
static void prt_time_modify(XDR *);
static void prt_time_modify_set(XDR *);



/*
 * Information for attributes.
 * name		name of the attribute.
 * prt_details	function to XDR decode the attribute and print it.
 *
 * XXX If this table ever gets extensively changed (including
 * reorganization to track changes to the spec), it would probably be a
 * good idea to change to a scheme where the table is mechanically
 * generated.  Look at $SRC/uts/common/rpcsvc for how this is done in the
 * kernel.
 */

typedef struct {
	char	*name;
	void	(*prt_details)(XDR *);
} attr_info_t;

static attr_info_t attr_info[MAX_ATTRIBUTES] = {
	{"SUPPORTED_ATTRS",	prt_supported_attrs},
	{"TYPE",		prt_type},
	{"FH_EXPIRE_TYPE",	prt_fh_expire_type},
	{"CHANGE",		prt_change},
	{"SIZE",		prt_size},
	{"LINK_SUPPORT",	prt_link_support},	/* 5 */
	{"SYMLINK_SUPPORT",	prt_symlink_support},
	{"NAMED_ATTR",		prt_named_attr},
	{"FSID",		prt_fsid},
	{"UNIQUE_HANDLES",	prt_unique_handles},
	{"LEASE_TIME",		prt_lease_time},	/* 10 */
	{"RDATTR_ERROR",	prt_rdattr_error},
	{"ACL",			prt_acl},
	{"ACLSUPPORT",		prt_aclsupport},
	{"ARCHIVE",		prt_archive},
	{"CANSETTIME",		prt_cansettime},	/* 15 */
	{"CASE_INSENSITIVE",	prt_case_insensitive},
	{"CASE_PRESERVING",	prt_case_preserving},
	{"CHOWN_RESTRICTED",	prt_chown_restricted},
	{"FILEHANDLE",		prt_filehandle},
	{"FILEID",		prt_fileid},		/* 20 */
	{"FILES_AVAIL",		prt_files_avail},
	{"FILES_FREE",		prt_files_free},
	{"FILES_TOTAL",		prt_files_total},
	{"FS_LOCATIONS",	prt_fs_locations},
	{"HIDDEN",		prt_hidden},		/* 25 */
	{"HOMOGENEOUS",		prt_homogeneous},
	{"MAXFILESIZE",		prt_maxfilesize},
	{"MAXLINK",		prt_maxlink},
	{"MAXNAME",		prt_maxname},
	{"MAXREAD",		prt_maxread},		/* 30 */
	{"MAXWRITE",		prt_maxwrite},
	{"MIMETYPE",		prt_mimetype},
	{"MODE",		prt_mode},
	{"NO_TRUNC",		prt_no_trunc},
	{"NUMLINKS",		prt_numlinks},		/* 35 */
	{"OWNER",		prt_owner},
	{"OWNER_GROUP",		prt_owner_group},
	{"QUOTA_AVAIL_HARD",	prt_quota_avail_hard},
	{"QUOTA_AVAIL_SOFT",	prt_quota_avail_soft},
	{"QUOTA_USED",		prt_quota_used},	/* 40 */
	{"RAWDEV",		prt_rawdev},
	{"SPACE_AVAIL",		prt_space_avail},
	{"SPACE_FREE",		prt_space_free},
	{"SPACE_TOTAL",		prt_space_total},
	{"SPACE_USED",		prt_space_used},	/* 45 */
	{"SYSTEM",		prt_system},
	{"TIME_ACCESS",		prt_time_access},
	{"TIME_ACCESS_SET",	prt_time_access_set},
	{"TIME_BACKUP",		prt_time_backup},
	{"TIME_CREATE",		prt_time_create},	/* 50 */
	{"TIME_DELTA",		prt_time_delta},
	{"TIME_METADATA",	prt_time_metadata},
	{"TIME_MODIFY",		prt_time_modify},
	{"TIME_MODIFY_SET",	prt_time_modify_set},
	{"MOUNTED_ON_FILEID",	prt_mounted_on_fileid},
};

extern char *get_sum_line();

extern jmp_buf xdr_err;

static void sum_comp4res(char *, char *(*)(void));
static char *sum_compound4args(void);
static char *sum_compound4res(void);
static char *sum_operand(nfs_argop4 *opp);
static char *sum_result(nfs_resop4 *resp);

static char *sum_cb_compound4args(void);
static char *sum_cb_compound4res(void);
static char *sum_cb_operand(nfs_cb_argop4 *opp);
static char *sum_cb_result(nfs_cb_resop4 *resp);

static void detail_acetype4(acetype4);
static void detail_uint32_bitmap(uint32_t, char *[], int);
static void detail_aceflag4(aceflag4);
static void detail_acemask4(acemask4);
static void detail_nfs_argop4(void);
static void detail_nfs_resop4(void);
static void detail_cb_argop4(void);
static void detail_cb_resop4(void);

static char *attr_name(uint_t);
static char *claim_name(enum open_claim_type4 claim_type);
static char *delegation_type_name(enum open_delegation_type4 type);
static char *flavor_name(uint_t flavor);
static char *gss_svc_name(rpc_gss_svc_t svc);
static char *limitby_name(enum limit_by4 limitby);
static char *lock_type_name(enum nfs_lock_type4);
static char *opcode_name(uint_t);
static char *cb_opcode_name(uint_t opnum);
static char *status_name(int);
static char *status_name_compat(int);
static char *status_name_pcol(int);
static char *sum_type_name(nfs_ftype4);
static void sum_access4(char *buf, size_t buflen, uint32_t bits);
static void detail_access4(char *, uint32_t);
static void sum_claim(char *buf, size_t buflen, open_claim4 *claim);
static void detail_claim(open_claim4 *claim);
static char *sum_clientid(clientid4 client);
static void detail_clientid(clientid4 client);
static char *_sum_stateid(stateid4 *, char *prefix);
static void sum_delegation(char *buf, size_t buflen, open_delegation4 *delp);
static void detail_delegation(open_delegation4 *delp);
static void detail_lock_owner(lock_owner4 *owner);
static void detail_open_owner(open_owner4 *owner);
static void sum_openflag(char *bufp, int buflen, openflag4 *flagp);
static char *get_deleg_typestr(open_delegation_type4 dt);
static void detail_openflag(openflag4 *flagp);
static void sum_name(char *buf, size_t buflen, open_claim4 *claim);
static void detail_rpcsec_gss(rpcsec_gss_info *);
static void detail_secinfo4(secinfo4 *infop);
static char *sum_space_limit(nfs_space_limit4 *limitp);
static void detail_space_limit(nfs_space_limit4 *limitp);
static char *detail_type_name(nfs_ftype4);
static char *createhow4_name(createhow4 *crtp);


static void showxdr_utf8string(char *);
static char *utf8localize(utf8string *);
static void utf8free(void);
static void sum_pathname4(char *, size_t, pathname4 *);
static void detail_pathname4(pathname4 *pathp, char *);
static void sum_compname4(char *buf, size_t buflen, component4 *comp);
static void detail_compname4(component4 *comp);

static void detail_fattr4(fattr4 *attrp);
static void detail_attr_bitmap(char *, bitmap4 *, unpkd_attrmap_t *);
static void sum_attr_bitmap(char *buf, size_t buflen, bitmap4 *mapp);
static void detail_fattr4_change(char *msg, fattr4_change chg);
static char *sum_fh4(nfs_fh4 *fhp);
static void detail_fh4(nfs_fh4 *fh);

#define	fh4_hash(fh) adler16((fh)->nfs_fh4_val, (fh)->nfs_fh4_len)
#define	stateid_hash(st) adler16((st)->other, sizeof ((st)->other))
#define	owner_hash(own) adler16((own)->owner_val, (own)->owner_len)

#define	sum_deleg_stateid(st)	_sum_stateid((st), "DST=")
#define	sum_open_stateid(st)	_sum_stateid((st), "OST=")
#define	sum_lock_stateid(st)	_sum_stateid((st), "LST=")
#define	sum_stateid(st)		_sum_stateid((st), "ST=")

#define	detail_deleg_stateid(st)	_detail_stateid((st), "Delegation ")
#define	detail_open_stateid(st)		_detail_stateid((st), "Open ")
#define	detail_lock_stateid(st)		_detail_stateid((st), "Lock ")
#define	detail_stateid(st)		_detail_stateid((st), "")

#define	SPECIAL_STATEID0	"SPC0"
#define	SPECIAL_STATEID1	"SPC1"

#define	DONT_CHANGE		0
#define	SET_TO_SERVER_TIME	1
#define	SET_TO_CLIENT_TIME	2

static stateid4 spec_stateid_0 =
	{0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
static stateid4 spec_stateid_1 =
	{0xFFFFFFFF, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}};

static char *procnames_short[] = {
	"NULL4",	/*  0 */
	"COMPOUND4"	/*  1 */
};

static char *procnames_long[] = {
	"Null procedure",		/*  0 */
	"Compound",			/*  1 */
};

static char *cb_procnames_short[] = {
	"CB_NULL",	/*  0 */
	"CB_COMPOUND"	/*  1 */
};

static char *cb_procnames_long[] = {
	"Null CallBack procedure",	/*  0 */
	"CallBack compound",		/*  1 */
};

static char *acetype4_names[] = {
	"ACE4_ACCESS_ALLOWED_ACE_TYPE",
	"ACE4_ACCESS_DENIED_ACE_TYPE",
	"ACE4_SYSTEM_AUDIT_ACE_TYPE",
	"ACE4_SYSTEM_ALARM_ACE_TYPE"
};
#define	ACETYPE4_NAMES_MAX (sizeof (acetype4_names) / sizeof (char *))

static char *aceflag4_names[] = {
	"ACE4_FILE_INHERIT_ACE",
	"ACE4_DIRECTORY_INHERIT_ACE",
	"ACE4_NO_PROPAGATE_INHERIT_ACE",
	"ACE4_INHERIT_ONLY_ACE",
	"ACE4_SUCCESSFUL_ACCESS_ACE_FLAG",
	"ACE4_FAILED_ACCESS_ACE_FLAG",
	"ACE4_IDENTIFIER_GROUP"
};
#define	ACEFLAG4_NAMES_MAX (sizeof (aceflag4_names) / sizeof (char *))

static char *acemask4_names[] = {
	"ACE4_READ_DATA/ACE4_LIST_DIRECTORY",
	"ACE4_WRITE_DATA/ACE4_ADD_FILE",
	"ACE4_APPEND_DATA/ACE4_ADD_SUBDIRECTORY",
	"ACE4_READ_NAMED_ATTRS",
	"ACE4_WRITE_NAMED_ATTRS",
	"ACE4_EXECUTE",
	"ACE4_DELETE_CHILD",
	"ACE4_READ_ATTRIBUTES",
	"ACE4_WRITE_ATTRIBUTES",
	"UNDEFINED",	/* 0x00000200 */
	"UNDEFINED",	/* 0x00000400 */
	"UNDEFINED",	/* 0x00000800 */
	"UNDEFINED",	/* 0x00001000 */
	"UNDEFINED",	/* 0x00002000 */
	"UNDEFINED",	/* 0x00004000 */
	"UNDEFINED",	/* 0x00008000 */
	"ACE4_DELETE",
	"ACE4_READ_ACL",
	"ACE4_WRITE_ACL",
	"ACE4_WRITE_OWNER",
	"ACE4_SYNCHRONIZE"
};
#define	ACEMASK4_NAMES_MAX (sizeof (acemask4_names) / sizeof (char *))

#define	MAXPROC	1

/*ARGSUSED*/
void
interpret_nfs4_cb(int flags, int type, int xid, int vers, int proc,
    char *data, int len)
{
	char *line = NULL;

	if (proc < 0 || proc > MAXPROC)
		return;

	if (flags & F_SUM) {
		line = get_sum_line();

		if (type == CALL) {
			(void) sprintf(line, "NFS C %s",
			    proc == CB_COMPOUND ? "CB4" :
			    cb_procnames_short[proc]);
			line += strlen(line);

			if (proc == CB_COMPOUND) {
				static utf8string tag;

				if (!xdr_utf8string(&xdrm, &tag))
					longjmp(xdr_err, 1);
				sprintf(line, " (%.20s) %s",
				    utf8localize(&tag),
				    sum_cb_compound4args());
				xdr_free(xdr_utf8string, (char *)&tag);
			}
			check_retransmit(line, xid);
		} else {
			(void) sprintf(line, "NFS R %s ",
			    proc == CB_COMPOUND ? "CB4" :
			    cb_procnames_short[proc]);
			line += strlen(line);
			if (proc == CB_COMPOUND)
				sum_comp4res(line, sum_cb_compound4res);
		}
	}

	if (flags & F_DTAIL) {
		show_header("NFS:  ", "Sun NFS4 CallBack", len);
		show_space();
		(void) sprintf(get_line(0, 0), "Proc = %d (%s)",
		    proc, cb_procnames_long[proc]);
		if (proc == CB_COMPOUND) {
			if (type == CALL) {
				showxdr_utf8string("Tag = %s");
				detail_cb_argop4();
			} else {
				nfsstat4 status;

				status = getxdr_long();
				showxdr_utf8string("Tag = %s");
				sprintf(get_line(0, 0), "Status = %d (%s)",
				    status, status_name(status));
				detail_cb_resop4();
			}
		}
		show_trailer();
	}

	utf8free();			/* cf. utf8localize() */
}


/*ARGSUSED*/
void
interpret_nfs4(int flags, int type, int xid, int vers, int proc,
    char *data, int len)
{
	char *line = NULL;

	if (proc < 0 || proc > MAXPROC)
		return;

	nfs4_fragged_rpc = 0;
	nfs4_pkt_len = len;
	nfs4_pkt_start = xdr_getpos(&xdrm);

	if (flags & F_SUM) {
		line = get_sum_line();

		if (type == CALL) {
			(void) sprintf(line, "NFS C %s",
			    proc == NFSPROC4_COMPOUND ? "4" :
			    procnames_short[proc]);
			line += strlen(line);

			if (proc == NFSPROC4_COMPOUND) {
				static utf8string tag;

				if (!xdr_utf8string(&xdrm, &tag))
					longjmp(xdr_err, 1);
				sprintf(line, " (%.20s) %s",
				    utf8localize(&tag),
				    sum_compound4args());
				xdr_free(xdr_utf8string, (char *)&tag);
			}
			check_retransmit(line, xid);
		} else {
			(void) sprintf(line, "NFS R %s ",
			    proc == NFSPROC4_COMPOUND ? "4" :
			    procnames_short[proc]);
			line += strlen(line);

			if (proc == NFSPROC4_COMPOUND)
				sum_comp4res(line, sum_compound4res);
		}
	}

	if (flags & F_DTAIL) {
		show_header("NFS:  ", "Sun NFS", len);
		show_space();
		(void) sprintf(get_line(0, 0), "Proc = %d (%s)",
		    proc, procnames_long[proc]);
		if (proc == NFSPROC4_COMPOUND) {
			if (type == CALL) {
				showxdr_utf8string("Tag = %s");
				detail_nfs_argop4();
			} else {
				nfsstat4 status;

				status = getxdr_long();
				showxdr_utf8string("Tag = %s");
				sprintf(get_line(0, 0), "Status = %d (%s)",
				    status, status_name(status));
				detail_nfs_resop4();
			}
		}
		show_trailer();
	}

	utf8free();			/* cf. utf8localize() */
}



/*
 * Return the names and arguments of the oplist elements, up to
 * SUM_COMPND_MAX characters.  If the elements don't fit, include a "..."
 * at the end of the string.
 */

static char *
sum_compound4args(void)
{
	static char buf[SUM_COMPND_MAX + 2]; /* 1 for null, 1 for overflow */
	int numops;
	const size_t buflen = sizeof (buf);
	char *bp;
	nfs_argop4 one_op;
	uint32_t minor_version;

	buf[0] = '\0';

	if (setjmp(xdr_err)) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf),
		    nfs4_fragged_rpc ? nfs4err_fragrpc : nfs4err_xdrfrag);
		return (buf);
	}

	/*
	 * might be nice to print minor version, but doesn't
	 * seem like very useful info for summary mode
	 */
	if (!xdr_uint32_t(&xdrm, &minor_version))
		longjmp(xdr_err, 1);

	numops = getxdr_long();
	bp = buf;
	while (numops-- > 0) {
		char *operand;

		bzero(&one_op, sizeof (one_op));

		if (!xdr_nfs_argop4(&xdrm, &one_op)) {
			xdr_free(xdr_nfs_argop4, (char *)&one_op);
			longjmp(xdr_err, 1);
		}
		snprintf(bp, buflen - (bp - buf), "%s ",
		    opcode_name(one_op.argop));
		bp += strlen(bp);

		operand = sum_operand(&one_op);
		if (strlen(operand) > 0) {
			snprintf(bp, buflen - (bp - buf), "%s ", operand);
			bp += strlen(bp);
		}

		/* nfs4_skip_bytes set by xdr_nfs4_argop4 */
		if (nfs4_skip_bytes != 0)
			nfs4_xdr_skip(nfs4_skip_bytes);

		xdr_free(xdr_nfs_argop4, (char *)&one_op);

		/* add "..." if past the "end" of the buffer */
		if (bp - buf > SUM_COMPND_MAX) {
			strcpy(buf + SUM_COMPND_MAX - strlen("..."),
			    "...");
			break;
		}
	}

	return (buf);
}

static void
nfs4_xdr_skip(int nbytes)
{
	int resid, off, len, cur_pos, new_pos;

	len = RNDUP(nbytes);
	cur_pos = xdr_getpos(&xdrm);

	/*
	 * Time to skip over the rd/wr data.  If the
	 * rd/wr data is completely contained in the first
	 * frag, we must skip over it to process the rest of
	 * the packet.
	 *
	 * nfs4_pkt_start: XDR position of start of NFS4 compound
	 * nfs4_pkt_len: number of bytes in pkt relative to
	 *		 nfs4_pkt_start
	 *
	 * cur_pos: current XDR position
	 * off: current XDR position relative to nfs4_pkt_start
	 * resid: number of unprocessed bytes in current pkt
	 *	  (relative to cur_pos/off)
	 *
	 * If nbytes <= resid, then we must skip over the rd/wr
	 * bytes so we can read the next op/compound in this
	 * packet.  Otherwise, set the fragged flag so we can
	 * display the fragged_rpc message.
	 */
	off = cur_pos - nfs4_pkt_start;
	resid = nfs4_pkt_len - off;

	/*
	 * set nfs4_fragged_rpc if the requested number of "skip"
	 * bytes is larger than the bytes remaining in the XDR
	 * stream/current packet.  The global is reset to 0 at
	 * start of interpret_nfs4.
	 */
	new_pos = cur_pos + ((nfs4_fragged_rpc = len > resid) ? resid : len);

	/* there's nothing to do for error case (if it fails pkt is doomed) */
	xdr_setpos(&xdrm, new_pos);
}


/*
 * Return the names and arguments of the oplist elements, up to
 * SUM_COMPND_MAX characters.  If the elements don't fit, include a "..."
 * at the end of the string.
 */
static char *
sum_cb_compound4args(void)
{
	static char buf[SUM_COMPND_MAX + 2]; /* 1 for null, 1 for overflow */
	int numops;
	const size_t buflen = sizeof (buf);
	char *bp;
	nfs_cb_argop4 one_op;
	uint32_t minor_version, callback_ident;

	buf[0] = '\0';
	if (setjmp(xdr_err)) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), "<XDR Error or Fragmented"
		    " RPC>");
		return (buf);
	}

	/*
	 * might be nice to print minor version, but doesn't
	 * seem like very useful info for summary mode
	 */
	if (!xdr_uint32_t(&xdrm, &minor_version))
		longjmp(xdr_err, 1);

	/* print callback_ident */
	if (!xdr_uint32_t(&xdrm, &callback_ident))
		longjmp(xdr_err, 1);
	snprintf(buf, buflen, "CBID=%u ", callback_ident);

	bp = buf + strlen(buf);
	numops = getxdr_long();

	while (numops-- > 0) {
		char *operand;

		bzero(&one_op, sizeof (one_op));
		if (!xdr_nfs_cb_argop4(&xdrm, &one_op)) {
			xdr_free(xdr_nfs_cb_argop4, (char *)&one_op);
			longjmp(xdr_err, 1);
		}

		snprintf(bp, buflen - (bp - buf), "%s ",
		    cb_opcode_name(one_op.argop));
		bp += strlen(bp);
		operand = sum_cb_operand(&one_op);
		if (strlen(operand) > 0) {
			snprintf(bp, buflen - (bp - buf), "%s ", operand);
			bp += strlen(bp);
		}

		xdr_free(xdr_nfs_cb_argop4, (char *)&one_op);

		/* add "..." if past the "end" of the buffer */
		if (bp - buf > SUM_COMPND_MAX) {
			strcpy(buf + SUM_COMPND_MAX - strlen("..."),
			    "...");
			break;
		}
	}

	return (buf);
}

/*
 * Return the summarized argument list for the given nfs_argop4.
 */

static char *
sum_operand(nfs_argop4 *opp)
{
	static char buf[1024];
	void (*fmtproc)(char *, size_t, void *);

	buf[0] = '\0';
	if (opp->argop < num_opcodes) {
		fmtproc = opcode_info[opp->argop].sumarg;
		if (fmtproc != NULL)
			fmtproc(buf, sizeof (buf), &opp->nfs_argop4_u);
	}

	return (buf);
}

/*
 * Return the summarized argument list for the given nfs_argop4.
 */

static char *
sum_cb_operand(nfs_cb_argop4 *opp)
{
	static char buf[1024];
	void (*fmtproc)(char *, size_t, void *);

	buf[0] = '\0';
	if (opp->argop < cb_num_opcodes) {
		fmtproc = cb_opcode_info[opp->argop].sumarg;
		if (fmtproc != NULL)
			fmtproc(buf, sizeof (buf), &opp->nfs_cb_argop4_u);
	}

	return (buf);
}

/*
 * Print details about the nfs_argop4 that is next in the XDR stream.
 */

static void
detail_nfs_argop4(void)
{
	int numops;
	nfs_argop4 one_op;
	void (*fmtproc)(void *);
	uint32_t minor_version;

	if (!xdr_uint32_t(&xdrm, &minor_version))
		longjmp(xdr_err, 1);

	(void) sprintf(get_line(0, 0), "Minor version = %u",
	    minor_version);

	numops = getxdr_long();
	(void) sprintf(get_line(0, 0), "Number of operations = %d",
	    numops);

	while (numops-- > 0) {
		bzero(&one_op, sizeof (one_op));

		if (!xdr_nfs_argop4(&xdrm, &one_op)) {
			xdr_free(xdr_nfs_argop4, (char *)&one_op);
			longjmp(xdr_err, 1);
		}

		get_line(0, 0);		/* blank line to separate ops */
		sprintf(get_line(0, 0), "Op = %d (%s)",
		    one_op.argop, opcode_name(one_op.argop));
		if (one_op.argop < num_opcodes) {
			fmtproc = opcode_info[one_op.argop].dtlarg;
			if (fmtproc != NULL)
				fmtproc(&one_op.nfs_argop4_u);
		}

		/* nfs4_skip_bytes set by xdr_nfs_argop4() */
		if (nfs4_skip_bytes)
			nfs4_xdr_skip(nfs4_skip_bytes);

		xdr_free(xdr_nfs_argop4, (char *)&one_op);
	}
}


/*
 * Print details about the nfs_argop4 that is next in the XDR stream.
 */
static void
detail_cb_argop4(void)
{
	int numops;
	nfs_cb_argop4 one_op;
	void (*fmtproc)(void *);
	uint32_t minor_version, callback_ident;

	if (!xdr_uint32_t(&xdrm, &minor_version))
		longjmp(xdr_err, 1);
	(void) sprintf(get_line(0, 0), "Minor version = %u",
	    minor_version);

	if (!xdr_uint32_t(&xdrm, &callback_ident))
		longjmp(xdr_err, 1);
	(void) sprintf(get_line(0, 0), "Callback Ident = %u",
	    callback_ident);

	numops = getxdr_long();
	(void) sprintf(get_line(0, 0), "Number of operations = %d",
	    numops);

	while (numops-- > 0) {
		bzero(&one_op, sizeof (one_op));
		if (!xdr_nfs_cb_argop4(&xdrm, &one_op)) {
			xdr_free(xdr_nfs_cb_argop4, (char *)&one_op);
			longjmp(xdr_err, 1);
		}

		get_line(0, 0);		/* blank line to separate ops */
		sprintf(get_line(0, 0), "Op = %d (%s)",
		    one_op.argop, cb_opcode_name(one_op.argop));
		if (one_op.argop < cb_num_opcodes) {
			fmtproc = cb_opcode_info[one_op.argop].dtlarg;
			if (fmtproc != NULL)
				fmtproc(&one_op.nfs_cb_argop4_u);
		}

		xdr_free(xdr_nfs_cb_argop4, (char *)&one_op);
	}
}

/*
 * component_name: return a printable string for the given component4.  I'm
 * leaving this as a separate function (as opposed to having the callers
 * call utf8localize() directly) in case the definition of component4
 * changes.
 */

static char *
component_name(component4 *cp)
{
	return (utf8localize(cp));
}

/*
 * linktext_name.  cf. component_name().
 */

static char *
linktext_name(linktext4 *lp)
{
	return (utf8localize((utf8string *)lp));
}

/*
 * stable_how4_name: return a string for "how".
 */

static char *
stable_how4_name(stable_how4 how)
{
	char *result;

	switch (how) {
	case UNSTABLE4:
		result = "ASYNC";
		break;
	case DATA_SYNC4:
		result = "DSYNC";
		break;
	case FILE_SYNC4:
		result = "FSYNC";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

/*
 * sum_open_share_access: return a string corresponding to the
 * given OPEN share access bitmask.
 */

static char *
sum_open_share_access(int32_t mask)
{
	char *result;

	switch (mask) {
	case 0:
		result = "N";
		break;
	case OPEN4_SHARE_ACCESS_READ:
		result = "R";
		break;
	case OPEN4_SHARE_ACCESS_WRITE:
		result = "W";
		break;
	case OPEN4_SHARE_ACCESS_BOTH:
		result = "RW";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

/*
 * sum_open_share_deny: return a string corresponding to the
 * given OPEN share deny bitmask.
 */

static char *
sum_open_share_deny(int32_t mask)
{
	char *result;

	switch (mask) {
	case OPEN4_SHARE_DENY_NONE:
		result = "N";
		break;
	case OPEN4_SHARE_DENY_READ:
		result = "R";
		break;
	case OPEN4_SHARE_DENY_WRITE:
		result = "W";
		break;
	case OPEN4_SHARE_DENY_BOTH:
		result = "RW";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

static int
special_stateid(stateid4 *stateid)
{

	if (! memcmp(stateid, &spec_stateid_0, sizeof (*stateid)))
		return (0);

	if (! memcmp(stateid, &spec_stateid_1, sizeof (*stateid)))
		return (1);

	return (-1);
}

static char *
_sum_stateid(stateid4 *stateid, char *prefix)
{
	static char buf[32];
	int spec;

	if ((spec = special_stateid(stateid)) < 0)
		snprintf(buf, sizeof (buf), "%s%04X:%u", prefix,
		    stateid_hash(stateid), stateid->seqid);
	else
		snprintf(buf, sizeof (buf), "%s%s", prefix,
		    spec == 0 ? "SPC0" : (spec == 1 ? "SPC1" : "SPC?"));
	return (buf);
}

static void
_detail_stateid(stateid4 *stateid, char *prefix)
{
	int spec;
	char seqstr[32] = {0};

	spec = special_stateid(stateid);

	if (spec < 0)
		sprintf(get_line(0, 0), "%sState ID hash = %04X",
		    prefix, stateid_hash(stateid));
	else
		sprintf(get_line(0, 0), "%sState ID hash = %s",	prefix,
		    spec == 0 ? "SPECIAL_0" :
		    (spec == 1 ? "SPECIAL_1" : "SPECIAL_?"));

	sprintf(get_line(0, 0), "    len = %u    val = %s",
	    sizeof (stateid->other),
	    tohex(stateid->other, sizeof (stateid->other)));

	/*
	 * If spec 0/1 stateid, print seqid in hex; otherwise,
	 * use decimal.  This makes it more clear how spec stateids
	 * are constructed [obvious that either all bits are 0, or all
	 * bits are 1].
	 */
	if (spec == -1)
		sprintf(seqstr, "%d", stateid->seqid);
	else
		sprintf(seqstr, "%08X", stateid->seqid);

	sprintf(get_line(0, 0), "    %sState ID Sequence ID = %s",
	    prefix, seqstr);
}


static char *
sum_lock_denied(LOCK4denied *denied)
{
	static char buf[64];

	sprintf(buf, "%s %llu:%llu LO=%04X",
	    sum_lock_type_name(denied->locktype),
	    denied->offset, denied->length,
	    owner_hash(&denied->owner.owner));

	return (buf);
}

static void
detail_lock_denied(LOCK4denied *denied)
{
	sprintf(get_line(0, 0), "Type = %s", lock_type_name(denied->locktype));
	detail_lock_owner(&denied->owner);
	sprintf(get_line(0, 0), "Offset = %llu", denied->offset);
	sprintf(get_line(0, 0), "Length = %llu", denied->length);
}

/*
 * sum_createhow4: return the string name of "how".
 */

static char *
createhow4_name(createhow4 *crtp)
{
	char *result;

	switch (crtp->mode) {
	case UNCHECKED4:
		result = "UNCHECKED";
		break;
	case GUARDED4:
		result = "GUARDED";
		break;
	case EXCLUSIVE4:
		result = "EXCLUSIVE";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

/*
 * detail_createhow4: print detail information about "how".
 */

static void
detail_createhow4(createhow4 *crtp)
{
	sprintf(get_line(0, 0), "Method = %s",
	    createhow4_name(crtp));

	switch (crtp->mode) {
	case UNCHECKED4:
	case GUARDED4:
		detail_fattr4(&crtp->createhow4_u.createattrs);
		break;
	case EXCLUSIVE4:
		sprintf(get_line(0, 0), "  Verifier = %s",
		    tohex(crtp->createhow4_u.createverf,
		    NFS4_VERIFIER_SIZE));
		break;
	}
}

static void
detail_createtype4(createtype4 *crtp)
{
	sprintf(get_line(0, 0), "Type = %s",
	    detail_type_name(crtp->type));
	switch (crtp->type) {
	case NF4LNK:
		sprintf(get_line(0, 0), "Linkdata = %s",
		    utf8localize((utf8string *)&crtp->createtype4_u.linkdata));
		break;
	case NF4BLK:
	case NF4CHR:
		sprintf(get_line(0, 0), "Specdata1 = %04x Specdata2 = %04x",
		    crtp->createtype4_u.devdata.specdata1,
		    crtp->createtype4_u.devdata.specdata2);
		break;
	default:
		break;
	}
}

static void
sumarg_access(char *buf, size_t buflen, void *obj)
{
	ACCESS4args *args = (ACCESS4args *)obj;

	sum_access4(buf, buflen, args->access);
}

static void
dtlarg_access(void *obj)
{
	ACCESS4args *args = (ACCESS4args *)obj;

	detail_access4("Access bits", args->access);
}

static void
sumarg_close(char *buf, size_t buflen, void *obj)
{
	CLOSE4args *args = (CLOSE4args *)obj;

	snprintf(buf, buflen, "SQ=%u %s",
	    args->seqid, sum_open_stateid(&args->open_stateid));
}

static void
dtlarg_close(void *obj)
{
	CLOSE4args *args = (CLOSE4args *)obj;

	detail_open_stateid(&args->open_stateid);
	sprintf(get_line(0, 0), "Sequence ID = %u", args->seqid);
}

static void
sumarg_commit(char *buf, size_t buflen, void *obj)
{
	COMMIT4args *args = (COMMIT4args *)obj;

	snprintf(buf, buflen, "at %llu for %u ", args->offset,
	    args->count);
}

static void
dtlarg_commit(void *obj)
{
	COMMIT4args *args = (COMMIT4args *)obj;

	sprintf(get_line(0, 0), "Offset = %llu", args->offset);
	sprintf(get_line(0, 0), "Count = %u", args->count);
}

static void
sumarg_compnt(char *buf, size_t buflen, void *obj)
{
	component4 *comp = (component4 *)obj;

	snprintf(buf, buflen, "%s", component_name(comp));
}

static void
dtlarg_compnt(void *obj)
{
	component4 *comp = (component4 *)obj;

	sprintf(get_line(0, 0), "Name = %s", component_name(comp));
}

static void
sumarg_create(char *buf, size_t buflen, void *obj)
{
	CREATE4args *args = (CREATE4args *)obj;

	snprintf(buf, buflen, "%s %s ", component_name(&args->objname),
	    sum_type_name(args->objtype.type));
}

static void
dtlarg_create(void *obj)
{
	CREATE4args *args = (CREATE4args *)obj;

	sprintf(get_line(0, 0), "Name = %s", component_name(&args->objname));
	detail_createtype4(&args->objtype);
	detail_fattr4(&args->createattrs);
}

static void
sumarg_delprge(char *buf, size_t buflen, void *obj)
{
	DELEGPURGE4args *args = (DELEGPURGE4args *)obj;

	snprintf(buf, buflen, "%s", sum_clientid(args->clientid));
}

static void
dtlarg_delprge(void *obj)
{
	DELEGPURGE4args *args = (DELEGPURGE4args *)obj;

	detail_clientid(args->clientid);
}

static void
sumarg_delret(char *buf, size_t buflen, void *obj)
{
	DELEGRETURN4args *args = (DELEGRETURN4args *)obj;

	snprintf(buf, buflen, "%s", sum_deleg_stateid(&args->deleg_stateid));
}

static void
dtlarg_delret(void *obj)
{
	DELEGRETURN4args *args = (DELEGRETURN4args *)obj;

	detail_deleg_stateid(&args->deleg_stateid);
}

static void
sumarg_getattr(char *buf, size_t buflen, void *obj)
{
	GETATTR4args *args = (GETATTR4args *)obj;

	sum_attr_bitmap(buf, buflen, &args->attr_request);
}

static void
dtlarg_getattr(void *obj)
{
	GETATTR4args *args = (GETATTR4args *)obj;

	detail_attr_bitmap("", &args->attr_request, NULL);
}

static void
sumarg_cb_getattr(char *buf, size_t buflen, void *obj)
{
	CB_GETATTR4args *args = (CB_GETATTR4args *)obj;
	char *bp = buf;

	snprintf(bp, buflen, "%s ", sum_fh4(&args->fh));
	bp += strlen(bp);
	sum_attr_bitmap(bp, buflen - (bp - buf), &args->attr_request);
}

static void
dtlarg_cb_getattr(void *obj)
{
	CB_GETATTR4args *args = (CB_GETATTR4args *)obj;

	detail_fh4(&args->fh);
	detail_attr_bitmap("", &args->attr_request, NULL);
}

static void
sumarg_cb_recall(char *buf, size_t buflen, void *obj)
{
	CB_RECALL4args *args = (CB_RECALL4args *)obj;
	char *bp = buf;

	snprintf(bp, buflen, "%s %s TR=%s", sum_fh4(&args->fh),
	    sum_stateid(&args->stateid), args->truncate ? "T" : "F");
}

static void
dtlarg_cb_recall(void *obj)
{
	CB_RECALL4args *args = (CB_RECALL4args *)obj;

	detail_fh4(&args->fh);
	detail_stateid(&args->stateid);
	sprintf(get_line(0, 0), "Truncate = %s",
	    args->truncate ? "True" : "False");
}


/*
 * name openhow seqid claim access deny owner
 */
static void
sumarg_open(char *buf, size_t buflen, void *obj)
{
	OPEN4args *args = (OPEN4args *)obj;
	char *bp = buf;
	int blen = buflen, len;

	sum_name(bp, buflen, &args->claim);
	bp += (len = strlen(bp));
	blen -= len;

	sum_openflag(bp, blen, &args->openhow);
	bp += (len = strlen(bp));
	blen -= len;

	snprintf(bp, blen, " SQ=%u", args->seqid);
	bp += (len = strlen(bp));
	blen -= len;

	sum_claim(bp, blen, &args->claim);
	bp += (len = strlen(bp));
	blen -= len;

	snprintf(bp, blen, " AC=%s DN=%s OO=%04X",
	    sum_open_share_access(args->share_access),
	    sum_open_share_deny(args->share_deny),
	    owner_hash(&args->owner.owner));
}

static void
dtlarg_open(void *obj)
{
	OPEN4args *args = (OPEN4args *)obj;

	detail_claim(&args->claim);
	detail_openflag(&args->openhow);
	detail_open_owner(&args->owner);
	sprintf(get_line(0, 0), "Sequence ID = %u", args->seqid);
	sprintf(get_line(0, 0), "Access = 0x%x (%s)",
	    args->share_access, sum_open_share_access(args->share_access));
	sprintf(get_line(0, 0), "Deny   = 0x%x (%s)",
	    args->share_deny, sum_open_share_access(args->share_deny));
}

static void
sumarg_openattr(char *buf, size_t buflen, void *obj)
{
	OPENATTR4args *args = (OPENATTR4args *)obj;

	snprintf(buf, buflen, "CD=%s",
	    args->createdir ? "T" : "F");
}

static void
dtlarg_openattr(void *obj)
{
	OPENATTR4args *args = (OPENATTR4args *)obj;

	sprintf(get_line(0, 0), "CreateDir = %s",
	    args->createdir ? "True" : "False");
}

static void
sumarg_open_confirm(char *buf, size_t buflen, void *obj)
{
	char *bp = buf;
	OPEN_CONFIRM4args *args = (OPEN_CONFIRM4args *)obj;

	snprintf(bp, buflen, "SQ=%u %s", args->seqid,
	    sum_open_stateid(&args->open_stateid));
}

static void
dtlarg_open_confirm(void *obj)
{
	OPEN_CONFIRM4args *args = (OPEN_CONFIRM4args *)obj;

	sprintf(get_line(0, 0), "Sequence ID = %u", args->seqid);
	detail_open_stateid(&args->open_stateid);
}

static void
sumarg_open_downgrd(char *buf, size_t buflen, void *obj)
{
	OPEN_DOWNGRADE4args *args = (OPEN_DOWNGRADE4args *)obj;

	snprintf(buf, buflen, "SQ=%u %s AC=%s DN=%s",
	    args->seqid, sum_open_stateid(&args->open_stateid),
	    sum_open_share_access(args->share_access),
	    sum_open_share_deny(args->share_deny));
}

static void
dtlarg_open_downgrd(void *obj)
{
	OPEN_DOWNGRADE4args *args = (OPEN_DOWNGRADE4args *)obj;

	sprintf(get_line(0, 0), "Open Sequence ID = %u", args->seqid);
	detail_open_stateid(&args->open_stateid);
	sprintf(get_line(0, 0), "Access = 0x%x (%s)",
	    args->share_access, sum_open_share_access(args->share_access));
	sprintf(get_line(0, 0), "Deny   = 0x%x (%s)",
	    args->share_deny, sum_open_share_access(args->share_deny));
}

static void
sumarg_putfh(char *buf, size_t buflen, void *obj)
{
	PUTFH4args *args = (PUTFH4args *)obj;

	snprintf(buf, buflen, "%s", sum_fh4(&args->object));
}

static void
dtlarg_putfh(void *obj)
{
	PUTFH4args *args = (PUTFH4args *)obj;

	detail_fh4(&args->object);
}

static void
sumarg_link(char *buf, size_t buflen, void *obj)
{
	LINK4args *args = (LINK4args *)obj;

	snprintf(buf, buflen, "%s", component_name(&args->newname));
}

static void
dtlarg_link(void *obj)
{
	LINK4args *args = (LINK4args *)obj;

	sprintf(get_line(0, 0), "New name = %s",
	    component_name(&args->newname));
}

static void
sum_open_to_lock_owner(char *buf, int buflen, open_to_lock_owner4 *own)
{
	snprintf(buf, buflen, " OSQ=%u %s LSQ=%u LO=%04X", own->open_seqid,
	    sum_open_stateid(&own->open_stateid), own->lock_seqid,
	    owner_hash(&own->lock_owner.owner));
}

static void
sum_exist_lock_owner(char *buf, int buflen, exist_lock_owner4 *own)
{
	snprintf(buf, buflen, " LSQ=%u %s", own->lock_seqid,
	    sum_lock_stateid(&own->lock_stateid));
}

static void
sum_locker(char *buf, size_t len, locker4 *lk)
{
	if (lk->new_lock_owner == TRUE)
		sum_open_to_lock_owner(buf, len, &lk->locker4_u.open_owner);
	else
		sum_exist_lock_owner(buf, len, &lk->locker4_u.lock_owner);
}

static char *
sum_lock_type_name(enum nfs_lock_type4 type)
{
	char *result;

	switch (type) {
	case READ_LT:
		result = "RD";
		break;
	case WRITE_LT:
		result = "WR";
		break;
	case READW_LT:
		result = "RDW";
		break;
	case WRITEW_LT:
		result = "WRW";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

static void
sumarg_lock(char *buf, size_t buflen, void *obj)
{
	LOCK4args *args = (LOCK4args *)obj;
	char *bp = buf;

	snprintf(buf, buflen, "%s%s%llu:%llu",
	    sum_lock_type_name(args->locktype),
	    args->reclaim ? " reclaim " : " ",
	    args->offset, args->length);

	bp += strlen(buf);
	sum_locker(bp, buflen - (bp - buf), &args->locker);
}

static void
detail_open_to_lock_owner(open_to_lock_owner4 *own)
{
	sprintf(get_line(0, 0), "Open Sequence ID = %u", own->open_seqid);
	detail_open_stateid(&own->open_stateid);
	sprintf(get_line(0, 0), "Lock Sequence ID = %u", own->lock_seqid);
	detail_lock_owner(&own->lock_owner);
}

static void
detail_exist_lock_owner(exist_lock_owner4 *own)
{
	detail_lock_stateid(&own->lock_stateid);
	sprintf(get_line(0, 0), "Lock Sequence ID = %u", own->lock_seqid);
}

static void
detail_locker(locker4 *lk)
{
	if (lk->new_lock_owner == TRUE)
		detail_open_to_lock_owner(&lk->locker4_u.open_owner);
	else
		detail_exist_lock_owner(&lk->locker4_u.lock_owner);
}

static void
dtlarg_lock(void *obj)
{
	LOCK4args *args = (LOCK4args *)obj;

	sprintf(get_line(0, 0), "Type = %s", lock_type_name(args->locktype));
	sprintf(get_line(0, 0), "Reclaim = %s",
	    args->reclaim ? "TRUE" : "FALSE");
	sprintf(get_line(0, 0), "Offset = %llu", args->offset);
	sprintf(get_line(0, 0), "Length = %llu", args->length);
	detail_locker(&args->locker);
}

static void
sumarg_lockt(char *buf, size_t buflen, void *obj)
{
	LOCKT4args *args = (LOCKT4args *)obj;

	snprintf(buf, buflen, "%s %llu:%llu",
	    sum_lock_type_name(args->locktype),
	    args->offset, args->length);
}

static void
dtlarg_lockt(void *obj)
{
	LOCKT4args *args = (LOCKT4args *)obj;

	sprintf(get_line(0, 0), "Type = %s", lock_type_name(args->locktype));
	detail_lock_owner(&args->owner);
	sprintf(get_line(0, 0), "Offset = %llu", args->offset);
	sprintf(get_line(0, 0), "Length = %llu", args->length);
}

static void
sumarg_locku(char *buf, size_t buflen, void *obj)
{
	LOCKU4args *args = (LOCKU4args *)obj;

	snprintf(buf, buflen, "%llu:%llu LSQ=%u %s",
	    args->offset, args->length, args->seqid,
	    sum_lock_stateid(&args->lock_stateid));
}


static void
dtlarg_locku(void *obj)
{
	LOCKU4args *args = (LOCKU4args *)obj;

	sprintf(get_line(0, 0), "Type = %s", lock_type_name(args->locktype));
	sprintf(get_line(0, 0), "Sequence ID = %u", args->seqid);
	detail_lock_stateid(&args->lock_stateid);
	sprintf(get_line(0, 0), "Offset = %llu", args->offset);
	sprintf(get_line(0, 0), "Length = %llu", args->length);
}

static void
sumarg_lookup(char *buf, size_t buflen, void *obj)
{
	LOOKUP4args *args = (LOOKUP4args *)obj;

	sum_compname4(buf, buflen, &args->objname);
}

static void
dtlarg_lookup(void *obj)
{
	LOOKUP4args *args = (LOOKUP4args *)obj;

	detail_compname4(&args->objname);
}

static void
sumarg_read(char *buf, size_t buflen, void *obj)
{
	READ4args *args = (READ4args *)obj;

	snprintf(buf, buflen, "%s at %llu for %u",
	    sum_stateid(&args->stateid), args->offset, args->count);
}

static void
dtlarg_read(void *obj)
{
	READ4args *args = (READ4args *)obj;

	sprintf(get_line(0, 0), "Offset = %llu", args->offset);
	sprintf(get_line(0, 0), "Count = %u", args->count);
	detail_stateid(&args->stateid);
}

static void
sumarg_readdir(char *buf, size_t buflen, void *obj)
{
	READDIR4args *args = (READDIR4args *)obj;

	snprintf(buf, buflen, "Cookie=%llu (%s) for %u/%u",
	    args->cookie, tohex(args->cookieverf, NFS4_VERIFIER_SIZE),
	    args->dircount, args->maxcount);
}

static void
dtlarg_readdir(void *obj)
{
	READDIR4args *args = (READDIR4args *)obj;

	sprintf(get_line(0, 0), "Cookie = %llu", args->cookie);
	sprintf(get_line(0, 0), "Verifier = %s",
	    tohex(args->cookieverf, NFS4_VERIFIER_SIZE));
	sprintf(get_line(0, 0), "Dircount = %u", args->dircount);
	sprintf(get_line(0, 0), "Maxcount = %u", args->maxcount);
	detail_attr_bitmap("", &args->attr_request, NULL);
}

static void
dtlarg_release_lkown(void *obj)
{
	RELEASE_LOCKOWNER4args *args = (RELEASE_LOCKOWNER4args *)obj;

	detail_lock_owner(&args->lock_owner);
}

static void
sumarg_release_lkown(char *buf, size_t buflen, void *obj)
{
	RELEASE_LOCKOWNER4args *args = (RELEASE_LOCKOWNER4args *)obj;

	snprintf(buf, buflen, "LO=%04X", owner_hash(&args->lock_owner.owner));
}

static void
sumarg_rename(char *buf, size_t buflen, void *obj)
{
	RENAME4args *args = (RENAME4args *)obj;

	snprintf(buf, buflen, "%s to %s",
	    component_name(&args->oldname),
	    component_name(&args->newname));
}

static void
dtlarg_rename(void *obj)
{
	RENAME4args *args = (RENAME4args *)obj;

	sprintf(get_line(0, 0), "Old name = %s",
	    component_name(&args->oldname));
	sprintf(get_line(0, 0), "New name = %s",
	    component_name(&args->newname));
}

static void
sumarg_renew(char *buf, size_t buflen, void *obj)
{
	RENEW4args *args = (RENEW4args *)obj;

	snprintf(buf, buflen, "%s", sum_clientid(args->clientid));
}
static void
dtlarg_renew(void *obj)
{
	RENEW4args *args = (RENEW4args *)obj;

	detail_clientid(args->clientid);
}

static void
sumarg_secinfo(char *buf, size_t buflen, void *obj)
{
	SECINFO4args *args = (SECINFO4args *)obj;

	snprintf(buf, buflen, "%s",
	    component_name(&args->name));
}

static void
dtlarg_secinfo(void *obj)
{
	SECINFO4args *args = (SECINFO4args *)obj;

	sprintf(get_line(0, 0), "Name = %s",
	    component_name(&args->name));
}

static void
sumarg_setattr(char *buf, size_t buflen, void *obj)
{
	SETATTR4args *args = (SETATTR4args *)obj;

	snprintf(buf, buflen, "%s", sum_stateid(&args->stateid));
}

static void
dtlarg_setattr(void *obj)
{
	SETATTR4args *args = (SETATTR4args *)obj;

	detail_stateid(&args->stateid);
	detail_fattr4(&args->obj_attributes);
}

static void
sumarg_setclid(char *buf, size_t buflen, void *obj)
{
	SETCLIENTID4args *args = (SETCLIENTID4args *)obj;

	snprintf(buf, buflen, "Prog=%u ID=%s Addr=%s CBID=%u",
	    args->callback.cb_program,
	    args->callback.cb_location.r_netid,
	    args->callback.cb_location.r_addr, args->callback_ident);
}

static void
dtlarg_setclid(void *obj)
{
	SETCLIENTID4args *args = (SETCLIENTID4args *)obj;

	sprintf(get_line(0, 0), "Verifier=%s",
	    tohex(args->client.verifier, NFS4_VERIFIER_SIZE));
	sprintf(get_line(0, 0), "ID = (%d) %s",
	    args->client.id.id_len,
	    tohex(args->client.id.id_val, args->client.id.id_len));

	sprintf(get_line(0, 0), "Callback Program = %u",
	    args->callback.cb_program);
	sprintf(get_line(0, 0), "Callback Net ID = %s",
	    args->callback.cb_location.r_netid);
	sprintf(get_line(0, 0), "Callback Addr = %s",
	    args->callback.cb_location.r_addr);
	sprintf(get_line(0, 0), "Callback Ident = %u", args->callback_ident);
}

static void
sumarg_setclid_cfm(char *buf, size_t buflen, void *obj)
{
	SETCLIENTID_CONFIRM4args *args = (SETCLIENTID_CONFIRM4args *)obj;

	snprintf(buf, buflen, "%s CFV=%s", sum_clientid(args->clientid),
	    tohex(args->setclientid_confirm, NFS4_VERIFIER_SIZE));
}

static void
dtlarg_setclid_cfm(void *obj)
{
	SETCLIENTID_CONFIRM4args *args = (SETCLIENTID_CONFIRM4args *)obj;

	detail_clientid(args->clientid);
	sprintf(get_line(0, 0), "Set Client ID Confirm Verifier = %s",
	    tohex(args->setclientid_confirm, NFS4_VERIFIER_SIZE));
}


static void
dtlarg_verify(void *obj)
{
	NVERIFY4args *args = (NVERIFY4args *)obj;

	detail_fattr4(&args->obj_attributes);
}

static void
sumarg_write(char *buf, size_t buflen, void *obj)
{
	WRITE4args *args = (WRITE4args *)obj;

	snprintf(buf, buflen, "%s at %llu for %u",
	    sum_stateid(&args->stateid), args->offset, args->data.data_len);
}

static void
dtlarg_write(void *obj)
{
	WRITE4args *args = (WRITE4args *)obj;

	sprintf(get_line(0, 0), "Offset = %llu", args->offset);
	sprintf(get_line(0, 0), "Count = %u", args->data.data_len);
	sprintf(get_line(0, 0), "Stable = %s", stable_how4_name(args->stable));
	detail_stateid(&args->stateid);
}

static char *
sum_fh4(nfs_fh4 *fh)
{
	static char buf[20];

	sprintf(buf, "FH=%04X", fh4_hash(fh));

	return (buf);
}

static void
detail_fh4(nfs_fh4 *fh)
{
	int i;
	uchar_t *cp;
	char *bufp;

	sprintf(get_line(0, 0), "File handle = [%04X]", fh4_hash(fh));
	bufp = get_line(0, 0);
	sprintf(bufp, "(%d) ", fh->nfs_fh4_len);
	bufp += strlen(bufp);
	/* XXX use tohex()? */
	for (i = 0, cp = (uchar_t *)fh->nfs_fh4_val;
	    i < fh->nfs_fh4_len;
	    i++, cp++) {
		if (i != 0 && i % 32 == 0)
			bufp = get_line(0, 0);
		sprintf(bufp, "%02x", *cp);
		bufp += strlen(bufp);
	}
}

static void
detail_fattr4(fattr4 *attrp)
{
	unpkd_attrmap_t provided;
	uint_t attrnum;
	XDR attrxdr;
	jmp_buf old_errbuf;

	xdrmem_create(&attrxdr, attrp->attr_vals.attrlist4_val,
	    attrp->attr_vals.attrlist4_len, XDR_DECODE);

	bcopy(xdr_err, old_errbuf, sizeof (old_errbuf));
	if (setjmp(xdr_err)) {
		sprintf(get_line(0, 0), "<attr_vals too short>");
		goto done;
	}

	detail_attr_bitmap("", &attrp->attrmask, &provided);
	for (attrnum = 0; attrnum < MAX_ATTRIBUTES; attrnum++) {
		if (provided.map[attrnum]) {
			attr_info[attrnum].prt_details(&attrxdr);
		}
	}

done:
	bcopy(old_errbuf, xdr_err, sizeof (old_errbuf));
}

static void
sum_attr_bitmap(char *buf, size_t buflen, bitmap4 *mapp)
{
	uint_t num_words;
	char *bp;
	size_t curlen, remaining;

	buf[0] = '\0';
	for (num_words = 0; num_words < mapp->bitmap4_len; num_words++) {
		curlen = strlen(buf);
		if (curlen + sizeof ("<Too Long>") >= buflen) {
			strcpy(buf + buflen - sizeof ("<Too Long>"),
			    "<Too Long>");
			return;
		}
		bp = buf + curlen;
		remaining = buflen - curlen;
		snprintf(bp, remaining,
		    num_words == 0 ? "%x" : " %x",
		    mapp->bitmap4_val[num_words]);
	}
}

/*
 * Print detail information for the given attribute bitmap, and fill in the
 * unpacked version of the map if "unpacked" is non-null.  Returns the
 * number of bytes in the bitmap.  "prefix" is an initial string that is
 * printed at the front of each line.
 */

static void
detail_attr_bitmap(char *prefix, bitmap4 *bitp, unpkd_attrmap_t *unpacked)
{
	uint_t num_words;
	uint32_t *wp;
	uint_t byte_num;

	if (unpacked != NULL)
		memset(unpacked, 0, sizeof (unpkd_attrmap_t));

	/*
	 * Break the bitmap into octets, then print in hex and
	 * symbolically.
	 */

	for (num_words = 0, wp = bitp->bitmap4_val;
	    num_words < bitp->bitmap4_len;
	    num_words++, wp++) {
		for (byte_num = 0; byte_num < 4; byte_num++) {
			uchar_t val = (*wp) >> (byte_num * 8);
			char *buf = get_line(0, 0);
			uint_t attrnum;
			int bit;

			sprintf(buf, "%s  0x%02x  ", prefix, val);
			attrnum = num_words * 32 + byte_num * 8;
			for (bit = 7; bit >= 0; bit--) {
				if (val & (1 << bit)) {
					strcat(buf, " ");
					strcat(buf,
					    attr_name(attrnum + bit));
					if (unpacked != NULL)
						unpacked->map[attrnum + bit] =
						    1;
				}
			}
		}
	}
}

/*
 * Format the summary line results from a COMPOUND4 call.
 */

static void
sum_comp4res(char *line, char *(*sumres_fn)(void))
{
	nfsstat4 status;
	static utf8string tag;

	status = getxdr_long();
	if (!xdr_utf8string(&xdrm, &tag))
		longjmp(xdr_err, 1);

	sprintf(line, "(%.20s) %s %s", utf8localize(&tag),
	    status_name(status), sumres_fn());

	xdr_free(xdr_utf8string, (char *)&tag);
}


/*
 * Return a set of summary strings for the result data that's next in the
 * XDR stream, up to SUM_COMPND_MAX characters.  If the strings don't fit,
 * include a "..." at the end of the string.
 */

static char *
sum_compound4res(void)
{
	static char buf[SUM_COMPND_MAX + 2]; /* 1 for null, 1 for overflow */
	int numres;
	const size_t buflen = sizeof (buf);
	char *bp;
	nfs_resop4 one_res;

	buf[0] = '\0';
	if (setjmp(xdr_err)) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf),
		    nfs4_fragged_rpc ? nfs4err_fragrpc : nfs4err_xdrfrag);
		return (buf);
	}

	numres = getxdr_long();
	bp = buf;
	while (numres-- > 0) {
		char *result;

		bzero(&one_res, sizeof (one_res));

		if (!xdr_nfs_resop4(&xdrm, &one_res)) {
			xdr_free(xdr_nfs_resop4, (char *)&one_res);
			longjmp(xdr_err, 1);
		}

		snprintf(bp, buflen - (bp - buf), "%s ",
		    opcode_name(one_res.resop));
		bp += strlen(bp);

		result = sum_result(&one_res);
		if (strlen(result) > 0) {
			snprintf(bp, buflen - (bp - buf), "%s ", result);
			bp += strlen(bp);
		}

		/* nfs4_skip_bytes set by xdr_nfs4_argop4() */
		if (nfs4_skip_bytes != 0)
			nfs4_xdr_skip(nfs4_skip_bytes);

		xdr_free(xdr_nfs_resop4, (char *)&one_res);
		/* add "..." if past the "end" of the buffer */
		if (bp - buf > SUM_COMPND_MAX) {
			strcpy(buf + SUM_COMPND_MAX - strlen("..."),
			    "...");
			break;
		}
	}

	return (buf);
}


/*
 * Return a set of summary strings for the result data that's next in the
 * XDR stream, up to SUM_COMPND_MAX characters.  If the strings don't fit,
 * include a "..." at the end of the string.
 */

static char *
sum_cb_compound4res(void)
{
	static char buf[SUM_COMPND_MAX + 2]; /* 1 for null, 1 for overflow */
	int numres;
	const size_t buflen = sizeof (buf);
	char *bp;
	nfs_cb_resop4 one_res;

	buf[0] = '\0';
	if (setjmp(xdr_err)) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), "<XDR Error or Fragmented"
		    " RPC>");
		return (buf);
	}

	numres = getxdr_long();
	bp = buf;
	while (numres-- > 0) {
		bzero(&one_res, sizeof (one_res));
		if (!xdr_nfs_cb_resop4(&xdrm, &one_res)) {
			xdr_free(xdr_nfs_cb_resop4, (char *)&one_res);
			longjmp(xdr_err, 1);
		}
		snprintf(bp, buflen - (bp - buf), "%s %s ",
		    cb_opcode_name(one_res.resop),
		    sum_cb_result(&one_res));
		bp += strlen(bp);

		xdr_free(xdr_nfs_cb_resop4, (char *)&one_res);

		/* add "..." if past the "end" of the buffer */
		if (bp - buf > SUM_COMPND_MAX) {
			strcpy(buf + SUM_COMPND_MAX - strlen("..."),
			    "...");
			break;
		}
	}

	return (buf);
}


/*
 * Return the summarized results for the given resultdata.
 */

static char *
sum_result(nfs_resop4 *resp)
{
	static char buf[1024];
	void (*fmtproc)(char *, size_t, void *);

	buf[0] = '\0';
	if (resp->resop < num_opcodes)
		fmtproc = opcode_info[resp->resop].sumres;
	else if (resp->resop == OP_ILLEGAL)
		fmtproc = sum_nfsstat4;
	else
		fmtproc = NULL;

	if (fmtproc != NULL)
		fmtproc(buf, sizeof (buf), &resp->nfs_resop4_u);

	return (buf);
}

/*
 * Return the summarized results for the given resultdata.
 */

static char *
sum_cb_result(nfs_cb_resop4 *resp)
{
	static char buf[1024];
	void (*fmtproc)(char *, size_t, void *);

	buf[0] = '\0';
	if (resp->resop < cb_num_opcodes)
		fmtproc = cb_opcode_info[resp->resop].sumres;
	else if (resp->resop == OP_CB_ILLEGAL)
		fmtproc = sum_nfsstat4;
	else
		fmtproc = NULL;

	if (fmtproc != NULL)
		fmtproc(buf, sizeof (buf), &resp->nfs_cb_resop4_u);

	return (buf);
}


static void
dtl_change_info(char *msg, change_info4 *infop)
{
	sprintf(get_line(0, 0), "%s:", msg);
	sprintf(get_line(0, 0), "  Atomic = %s",
	    infop->atomic ? "TRUE" : "FALSE");
	detail_fattr4_change("  Before", infop->before);
	detail_fattr4_change("  After", infop->after);
}

static void
detail_fattr4_change(char *msg, fattr4_change chg)
{
	sprintf(get_line(0, 0), "%s: 0x%llx", msg, chg);
					/* XXX print as time_t, too? */
}

static void
sum_nfsstat4(char *buf, size_t buflen, void *obj)
{
	nfsstat4 status = *(nfsstat4 *)obj;

	strncpy(buf, status_name(status), buflen);
}

static void
dtl_nfsstat4(void *obj)
{
	nfsstat4 status = *(nfsstat4 *)obj;

	sprintf(get_line(0, 0), "Status = %d (%s)", status,
	    status_name(status));
}

static void
sumres_access(char *buf, size_t buflen, void *obj)
{
	ACCESS4res *res = (ACCESS4res *)obj;
	char *bp = buf;
	int len, blen = buflen;

	strcpy(bp, status_name(res->status));
	if (res->status == NFS4_OK) {
		bp += (len = strlen(bp));
		blen -= len;

		snprintf(bp, blen, " Supp=");
		bp += (len = strlen(bp));
		blen -= len;

		sum_access4(bp, blen, res->ACCESS4res_u.resok4.supported);
		bp += (len = strlen(bp));
		blen -= len;

		snprintf(bp, blen, " Allow=");
		bp += (len = strlen(bp));
		blen -= len;

		sum_access4(bp, blen, res->ACCESS4res_u.resok4.access);
	}
}

static void
dtlres_access(void *obj)
{
	ACCESS4res *res = (ACCESS4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_access4("Supported Attributes",
		    res->ACCESS4res_u.resok4.supported);
		detail_access4("Allowed Attributes",
		    res->ACCESS4res_u.resok4.access);
	}
}

static void
sumres_close(char *buf, size_t buflen, void *obj)
{
	CLOSE4res *res = (CLOSE4res *)obj;

	if (res->status == NFS4_OK)
		snprintf(buf, buflen, "%s",
		    sum_open_stateid(&res->CLOSE4res_u.open_stateid));
}

static void
dtlres_close(void *obj)
{
	CLOSE4res *res = (CLOSE4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_open_stateid(&res->CLOSE4res_u.open_stateid);
	}
}

static void
sumres_commit(char *buf, size_t buflen, void *obj)
{
	COMMIT4res *res = (COMMIT4res *)obj;

	if (res->status == NFS4_OK)
		snprintf(buf, buflen, "Verf=%s",
		    tohex(res->COMMIT4res_u.resok4.writeverf,
		    NFS4_VERIFIER_SIZE));
}

static void
dtlres_commit(void *obj)
{
	COMMIT4res *res = (COMMIT4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		sprintf(get_line(0, 0), "Verifier = %s",
		    tohex(res->COMMIT4res_u.resok4.writeverf,
		    NFS4_VERIFIER_SIZE));
	}
}

static void
dtlres_create(void *obj)
{
	CREATE4res *res = (CREATE4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		dtl_change_info("Change Information",
		    &res->CREATE4res_u.resok4.cinfo);
		detail_attr_bitmap("", &res->CREATE4res_u.resok4.attrset,
		    NULL);
	}
}

static void
sumres_getattr(char *buf, size_t buflen, void *obj)
{
	GETATTR4res *res = (GETATTR4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
}

static void
dtlres_getattr(void *obj)
{
	GETATTR4res *res = (GETATTR4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_fattr4(&res->GETATTR4res_u.resok4.obj_attributes);
	}
}

static void
sumres_cb_getattr(char *buf, size_t buflen, void *obj)
{
	CB_GETATTR4res *res = (CB_GETATTR4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
}

static void
dtlres_cb_getattr(void *obj)
{
	CB_GETATTR4res *res = (CB_GETATTR4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_fattr4(&res->CB_GETATTR4res_u.resok4.obj_attributes);
	}
}


static void
sumres_getfh(char *buf, size_t buflen, void *obj)
{
	char *bp;
	GETFH4res *res = (GETFH4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s",
		    sum_fh4(&res->GETFH4res_u.resok4.object));
	}
}

static void
dtlres_getfh(void *obj)
{
	GETFH4res *res = (GETFH4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_fh4(&res->GETFH4res_u.resok4.object);
	}
}

static void
dtlres_link(void *obj)
{
	LINK4res *res = (LINK4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		dtl_change_info("Change Information",
		    &res->LINK4res_u.resok4.cinfo);
	}
}

static void
sumres_lock(char *buf, size_t buflen, void *obj)
{
	char *bp;
	LOCK4res *res = (LOCK4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s",
		    sum_lock_stateid(&res->LOCK4res_u.resok4.lock_stateid));
	}
	if (res->status == NFS4ERR_DENIED) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s",
		    sum_lock_denied(&res->LOCK4res_u.denied));
	}
}

static void
dtlres_lock(void *obj)
{
	LOCK4res *res = (LOCK4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_lock_stateid(&res->LOCK4res_u.resok4.lock_stateid);
	}
	if (res->status == NFS4ERR_DENIED) {
		detail_lock_denied(&res->LOCK4res_u.denied);
	}
}

static void
sumres_lockt(char *buf, size_t buflen, void *obj)
{
	char *bp;
	LOCKT4res *res = (LOCKT4res *)obj;

	strcpy(buf, status_name(res->status));
	if (res->status == NFS4ERR_DENIED) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s",
		    sum_lock_denied(&res->LOCKT4res_u.denied));
	}
}

static void
dtlres_lockt(void *obj)
{
	LOCKT4res *res = (LOCKT4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4ERR_DENIED) {
		detail_lock_denied(&res->LOCKT4res_u.denied);
	}
}

static void
sumres_locku(char *buf, size_t buflen, void *obj)
{
	char *bp;
	LOCKU4res *res = (LOCKU4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	bp = buf + strlen(buf);
	if (res->status == NFS4_OK)
		snprintf(bp, buflen - (bp - buf), " %s",
		    sum_lock_stateid(&res->LOCKU4res_u.lock_stateid));
}

static void
dtlres_locku(void *obj)
{
	LOCKU4res *res = (LOCKU4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK)
		detail_lock_stateid(&res->LOCKU4res_u.lock_stateid);
}

static void
sumres_open(char *buf, size_t buflen, void *obj)
{
	char *bp = buf;
	OPEN4res *res = (OPEN4res *)obj;
	uint_t rflags;
	int len, blen = buflen;

	strncpy(bp, status_name(res->status), blen);

	if (res->status == NFS4_OK) {
		bp += (len = strlen(bp));
		blen -= len;

		snprintf(bp, blen, " %s",
		    sum_stateid(&res->OPEN4res_u.resok4.stateid));
		bp += (len = strlen(bp));
		blen -= len;

		if ((rflags = res->OPEN4res_u.resok4.rflags) != 0) {
			snprintf(bp, blen, "%s", sum_open_rflags(rflags));
			bp += (len = strlen(bp));
			blen -= len;
		}

		sum_delegation(bp, blen, &res->OPEN4res_u.resok4.delegation);
	}
}

static void
dtlres_open(void *obj)
{
	OPEN4res *res = (OPEN4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_stateid(&res->OPEN4res_u.resok4.stateid);
		dtl_change_info("Change Information",
		    &res->OPEN4res_u.resok4.cinfo);
		sprintf(get_line(0, 0), "Flags = 0x%x (%s)",
		    res->OPEN4res_u.resok4.rflags,
		    detail_open_rflags(res->OPEN4res_u.resok4.rflags));
		detail_attr_bitmap("", &res->OPEN4res_u.resok4.attrset,
		    NULL);
		detail_delegation(&res->OPEN4res_u.resok4.delegation);
	}
}

static void
sumres_open_confirm(char *buf, size_t buflen, void *obj)
{
	char *bp;
	OPEN_CONFIRM4res *res = (OPEN_CONFIRM4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s",
		    sum_open_stateid(&res->OPEN_CONFIRM4res_u.resok4.
		    open_stateid));
	}
}

static void
dtlres_open_confirm(void *obj)
{
	OPEN_CONFIRM4res *res = (OPEN_CONFIRM4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_open_stateid(&res->OPEN_CONFIRM4res_u.resok4.
		    open_stateid);
	}
}

static void
sumres_open_downgrd(char *buf, size_t buflen, void *obj)
{
	char *bp;
	OPEN_DOWNGRADE4res *res = (OPEN_DOWNGRADE4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s",
		    sum_open_stateid(&res->OPEN_DOWNGRADE4res_u.resok4.
		    open_stateid));
	}
}

static void
dtlres_open_downgrd(void *obj)
{
	OPEN_DOWNGRADE4res *res = (OPEN_DOWNGRADE4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		detail_open_stateid(&res->OPEN_DOWNGRADE4res_u.resok4.
		    open_stateid);
	}
}

static void
sumres_read(char *buf, size_t buflen, void *obj)
{
	char *bp;
	READ4res *res = (READ4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " (%u bytes) %s",
		    res->READ4res_u.resok4.data.data_len,
		    res->READ4res_u.resok4.eof ? "EOF" : "");
	}
}

static void
dtlres_read(void *obj)
{
	READ4res *res = (READ4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		sprintf(get_line(0, 0), "Count = %u bytes read",
		    res->READ4res_u.resok4.data.data_len);
		sprintf(get_line(0, 0), "End of file = %s",
		    res->READ4res_u.resok4.eof ? "TRUE" : "FALSE");
	}
}

static void
sumres_readdir(char *buf, size_t buflen, void *obj)
{
	char *bp;
	READDIR4res *res = (READDIR4res *)obj;
	int num_entries = 0;
	entry4 *ep;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		for (ep = res->READDIR4res_u.resok4.reply.entries;
		    ep != NULL;
		    ep = ep->nextentry)
			num_entries++;
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %d entries (%s)",
		    num_entries,
		    res->READDIR4res_u.resok4.reply.eof
		    ? "No more" : "More");
	}
}

static void
dtlres_readdir(void *obj)
{
	READDIR4res *res = (READDIR4res *)obj;
	int num_entries = 0;
	entry4 *ep;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		for (ep = res->READDIR4res_u.resok4.reply.entries;
		    ep != NULL;
		    ep = ep->nextentry) {
			num_entries++;
			sprintf(get_line(0, 0),
			    "------------------ entry #%d",
			    num_entries);
			sprintf(get_line(0, 0), "Cookie = %llu",
			    ep->cookie);
			sprintf(get_line(0, 0), "Name = %s",
			    component_name(&ep->name));
			detail_fattr4(&ep->attrs);
		}
		if (num_entries == 0)
			sprintf(get_line(0, 0), "(No entries)");
		sprintf(get_line(0, 0), "EOF = %s",
		    res->READDIR4res_u.resok4.reply.eof ? "TRUE" : "FALSE");
		sprintf(get_line(0, 0), "Verifer = %s",
		    tohex(res->READDIR4res_u.resok4.cookieverf,
		    NFS4_VERIFIER_SIZE));
	}
}

static void
sumres_readlnk(char *buf, size_t buflen, void *obj)
{
	char *bp;
	READLINK4res *res = (READLINK4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s",
		    linktext_name(&res->READLINK4res_u.resok4.link));
	}
}

static void
dtlres_readlnk(void *obj)
{
	READLINK4res *res = (READLINK4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		sprintf(get_line(0, 0), "Link = %s",
		    linktext_name(&res->READLINK4res_u.resok4.link));
	}
}

static void
dtlres_remove(void *obj)
{
	REMOVE4res *res = (REMOVE4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		dtl_change_info("Change Information",
		    &res->REMOVE4res_u.resok4.cinfo);
	}
}

static void
dtlres_rename(void *obj)
{
	RENAME4res *res = (RENAME4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		dtl_change_info("Source Change Information",
		    &res->RENAME4res_u.resok4.source_cinfo);
		dtl_change_info("Target Change Information",
		    &res->RENAME4res_u.resok4.target_cinfo);
	}
}

static void
sumres_secinfo(char *buf, size_t buflen, void *obj)
{
	char *bp;
	SECINFO4res *res = (SECINFO4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	bp = buf + strlen(buf);
	if (res->status == NFS4_OK) {
		uint_t numinfo = res->SECINFO4res_u.resok4.SECINFO4resok_len;
		secinfo4 *infop;

		for (infop = res->SECINFO4res_u.resok4.SECINFO4resok_val;
		    numinfo != 0;
		    infop++, numinfo--) {
			snprintf(bp, buflen - (bp - buf), " %s",
			    flavor_name(infop->flavor));
			bp += strlen(bp);
		}
	}
}

static void
dtlres_secinfo(void *obj)
{
	SECINFO4res *res = (SECINFO4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		uint_t numinfo =
		    res->SECINFO4res_u.resok4.SECINFO4resok_len;
		secinfo4 *infop;

		for (infop = res->SECINFO4res_u.resok4.SECINFO4resok_val;
		    numinfo != 0;
		    infop++, numinfo--) {
			detail_secinfo4(infop);
		}
	}
}

static void
sumres_setattr(char *buf, size_t buflen, void *obj)
{
	SETATTR4res *res = (SETATTR4res *)obj;
	size_t len;

	(void) snprintf(buf, buflen, "%s ", status_name(res->status));
	len = strlen(buf);
	sum_attr_bitmap(buf + len, buflen - len, &res->attrsset);
}

static void
dtlres_setattr(void *obj)
{
	SETATTR4res *res = (SETATTR4res *)obj;

	dtl_nfsstat4(obj);
	detail_attr_bitmap("", &res->attrsset, NULL);
}

static void
sumres_setclid(char *buf, size_t buflen, void *obj)
{
	char *bp;
	SETCLIENTID4res *res = (SETCLIENTID4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	switch (res->status) {
	case NFS_OK:
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %s CFV=%s",
		    sum_clientid(res->SETCLIENTID4res_u.resok4.clientid),
		    tohex(res->SETCLIENTID4res_u.resok4.setclientid_confirm,
		    NFS4_VERIFIER_SIZE));
		break;
	case NFS4ERR_CLID_INUSE:
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " ID=%s Addr=%s",
		    res->SETCLIENTID4res_u.client_using.r_netid,
		    res->SETCLIENTID4res_u.client_using.r_addr);
		break;
	}
}

static void
dtlres_setclid(void *obj)
{
	SETCLIENTID4res *res = (SETCLIENTID4res *)obj;

	dtl_nfsstat4(obj);
	switch (res->status) {
	case NFS_OK:
		detail_clientid(res->SETCLIENTID4res_u.resok4.clientid);
		sprintf(get_line(0, 0), "Set Client ID Confirm Verifier = %s",
		    tohex(res->SETCLIENTID4res_u.resok4.setclientid_confirm,
		    NFS4_VERIFIER_SIZE));
		break;
	case NFS4ERR_CLID_INUSE:
		sprintf(get_line(0, 0), "Used by Net ID = %s",
		    res->SETCLIENTID4res_u.client_using.r_netid);
		sprintf(get_line(0, 0), "Used by Addr = %s",
		    res->SETCLIENTID4res_u.client_using.r_addr);
		break;
	}
}

static void
sumres_write(char *buf, size_t buflen, void *obj)
{
	char *bp;
	WRITE4res *res = (WRITE4res *)obj;

	strncpy(buf, status_name(res->status), buflen);
	if (res->status == NFS4_OK) {
		bp = buf + strlen(buf);
		snprintf(bp, buflen - (bp - buf), " %u (%s)",
		    res->WRITE4res_u.resok4.count,
		    stable_how4_name(res->WRITE4res_u.resok4.committed));
	}
}

static void
dtlres_write(void *obj)
{
	WRITE4res *res = (WRITE4res *)obj;

	dtl_nfsstat4(obj);
	if (res->status == NFS4_OK) {
		sprintf(get_line(0, 0), "Count = %u bytes written",
		    res->WRITE4res_u.resok4.count);
		sprintf(get_line(0, 0), "Stable = %s",
		    stable_how4_name(res->WRITE4res_u.resok4.committed));
		sprintf(get_line(0, 0), "Verifier = %s",
		    tohex(res->WRITE4res_u.resok4.writeverf,
		    NFS4_VERIFIER_SIZE));
	}
}

/*
 * Print details about the nfs_resop4 that is next in the XDR stream.
 */

static void
detail_nfs_resop4(void)
{
	int numres;
	nfs_resop4 one_res;
	void (*fmtproc)(void *);

	numres = getxdr_long();
	(void) sprintf(get_line(0, 0), "Number of results = %d",
	    numres);

	while (numres-- > 0) {
		bzero(&one_res, sizeof (one_res));

		if (!xdr_nfs_resop4(&xdrm, &one_res)) {
			xdr_free(xdr_nfs_resop4, (char *)&one_res);
			longjmp(xdr_err, 1);
		}

		get_line(0, 0);		/* blank line to separate ops */
		sprintf(get_line(0, 0), "Op = %d (%s)",
		    one_res.resop, opcode_name(one_res.resop));
		if (one_res.resop < num_opcodes)
			fmtproc = opcode_info[one_res.resop].dtlres;
		else if (one_res.resop == OP_ILLEGAL)
			fmtproc = dtl_nfsstat4;
		else
			fmtproc = NULL;

		if (fmtproc != NULL)
			fmtproc(&one_res.nfs_resop4_u);

		/* nfs4_skip_bytes set by xdr_nfs_resop4()() */
		if (nfs4_skip_bytes)
			nfs4_xdr_skip(nfs4_skip_bytes);

		xdr_free(xdr_nfs_resop4, (char *)&one_res);
	}
}


/*
 * Print details about the nfs_cb_resop4 that is next in the XDR stream.
 */

static void
detail_cb_resop4(void)
{
	int numres;
	nfs_cb_resop4 one_res;
	void (*fmtproc)(void *);

	numres = getxdr_long();
	(void) sprintf(get_line(0, 0), "Number of results = %d",
	    numres);

	while (numres-- > 0) {
		bzero(&one_res, sizeof (one_res));
		if (!xdr_nfs_cb_resop4(&xdrm, &one_res))
			longjmp(xdr_err, 1);

		get_line(0, 0);		/* blank line to separate ops */
		sprintf(get_line(0, 0), "Op = %d (%s)",
		    one_res.resop, cb_opcode_name(one_res.resop));
		if (one_res.resop < cb_num_opcodes)
			fmtproc = cb_opcode_info[one_res.resop].dtlres;
		else if (one_res.resop == OP_CB_ILLEGAL)
			fmtproc = dtl_nfsstat4;
		else
			fmtproc = NULL;

		if (fmtproc != NULL)
			fmtproc(&one_res.nfs_cb_resop4_u);

		xdr_free(xdr_nfs_cb_resop4, (char *)&one_res);
	}
}


/*
 * Return the name of a lock type.
 */
static char *
lock_type_name(enum nfs_lock_type4 type)
{
	char *result;

	switch (type) {
	case READ_LT:
		result = "READ";
		break;
	case WRITE_LT:
		result = "WRITE";
		break;
	case READW_LT:
		result = "READW";
		break;
	case WRITEW_LT:
		result = "WRITEW";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

/*
 * Return the name of an opcode.
 */

static char *
opcode_name(uint_t opnum)
{
	static char buf[20];

	if (opnum < num_opcodes)
		return (opcode_info[opnum].name);

	if (opnum == OP_ILLEGAL)
		return ("ILLEGAL");

	sprintf(buf, "op %d", opnum);
	return (buf);
}

/*
 * Return the name of an opcode.
 */
static char *
cb_opcode_name(uint_t opnum)
{
	static char buf[20];

	if (opnum < cb_num_opcodes)
		return (cb_opcode_info[opnum].name);

	if (opnum == OP_CB_ILLEGAL)
		return ("CB_ILLEGAL");

	sprintf(buf, "op %d", opnum);
	return (buf);
}


/*
 * Fill in a summary string for the given access bitmask.
 */

static void
sum_access4(char *buf, size_t buflen, uint32_t bits)
{
	buf[0] = '\0';

	if (bits & ACCESS4_READ)
		(void) strncat(buf, "rd,", buflen);
	if (bits & ACCESS4_LOOKUP)
		(void) strncat(buf, "lk,", buflen);
	if (bits & ACCESS4_MODIFY)
		(void) strncat(buf, "mo,", buflen);
	if (bits & ACCESS4_EXTEND)
		(void) strncat(buf, "ext,", buflen);
	if (bits & ACCESS4_DELETE)
		(void) strncat(buf, "dl,", buflen);
	if (bits & ACCESS4_EXECUTE)
		(void) strncat(buf, "exc,", buflen);
	if (buf[0] != '\0')
		buf[strlen(buf) - 1] = '\0';
}

/*
 * Print detail information about the given access bitmask.
 */

static void
detail_access4(char *descrip, uint32_t bits)
{
	sprintf(get_line(0, 0), "%s = 0x%08x", descrip, bits);

	(void) sprintf(get_line(0, 0), "	%s",
	    getflag(bits, ACCESS4_READ, "Read", "(no read)"));
	(void) sprintf(get_line(0, 0), "	%s",
	    getflag(bits, ACCESS4_LOOKUP, "Lookup", "(no lookup)"));
	(void) sprintf(get_line(0, 0), "	%s",
	    getflag(bits, ACCESS4_MODIFY, "Modify", "(no modify)"));
	(void) sprintf(get_line(0, 0), "	%s",
	    getflag(bits, ACCESS4_EXTEND, "Extend", "(no extend)"));
	(void) sprintf(get_line(0, 0), "	%s",
	    getflag(bits, ACCESS4_DELETE, "Delete", "(no delete)"));
	(void) sprintf(get_line(0, 0), "	%s",
	    getflag(bits, ACCESS4_EXECUTE, "Execute", "(no execute)"));
}


/*
 * Fill in a summary string for the given open_claim4.
 */
static void
sum_name(char *buf, size_t buflen, open_claim4 *claim)
{
	char *bp = buf;

	switch (claim->claim) {
	case CLAIM_NULL:
		snprintf(bp, buflen, "%s ",
		    component_name(&claim->open_claim4_u.file));
		break;
	case CLAIM_PREVIOUS:
		break;
	case CLAIM_DELEGATE_CUR:
		snprintf(bp, buflen, "%s ",
		    component_name(&claim->open_claim4_u.
		    delegate_cur_info.file));
		break;
	case CLAIM_DELEGATE_PREV:
		snprintf(bp, buflen, "%s ",
		    component_name(&claim->open_claim4_u.
		    file_delegate_prev));
		break;
	}
}

/*
 * Fill in a summary string for the given open_claim4.
 */
static void
sum_claim(char *buf, size_t buflen, open_claim4 *claim)
{
	char *bp = buf;

	switch (claim->claim) {
	case CLAIM_NULL:
		snprintf(bp, buflen, " CT=N");
		break;
	case CLAIM_PREVIOUS:
		snprintf(bp, buflen, " CT=P DT=%s",
		    get_deleg_typestr(claim->open_claim4_u.delegate_type));
		break;
	case CLAIM_DELEGATE_CUR:
		snprintf(bp, buflen, " CT=DC %s",
		    sum_deleg_stateid(&claim->open_claim4_u.
		    delegate_cur_info.delegate_stateid));
		break;
	case CLAIM_DELEGATE_PREV:
		snprintf(bp, buflen, " CT=DP");
		break;
	default:
		snprintf(bp, buflen, " CT=?");
		break;
	}
}

static char *
get_deleg_typestr(open_delegation_type4 dt)
{
	char *str = "";

	switch (dt) {
	case OPEN_DELEGATE_NONE:
		str = "N";
		break;
	case OPEN_DELEGATE_READ:
		str = "R";
		break;
	case OPEN_DELEGATE_WRITE:
		str = "W";
		break;
	default:
		str = "?";
	}

	return (str);
}

/*
 * Print detail information for the given open_claim4.
 */

static void
detail_claim(open_claim4 *claim)
{
	sprintf(get_line(0, 0), "Claim Type = %d (%s)",
	    claim->claim, claim_name(claim->claim));

	switch (claim->claim) {
	case CLAIM_NULL:
		detail_compname4(&claim->open_claim4_u.file);
		break;
	case CLAIM_PREVIOUS:
		sprintf(get_line(0, 0), "Delegate Type = %s (val = %d)",
		    get_deleg_typestr(claim->open_claim4_u.delegate_type),
		    claim->open_claim4_u.delegate_type);
		break;
	case CLAIM_DELEGATE_CUR:
		detail_compname4(&claim->open_claim4_u.delegate_cur_info.file);
		detail_deleg_stateid(&claim->open_claim4_u.delegate_cur_info.
		    delegate_stateid);
		break;
	case CLAIM_DELEGATE_PREV:
		detail_compname4(&claim->open_claim4_u.file_delegate_prev);
		break;
	}
}

/*
 * Return a summary string for the given clientid4.
 */
static char *
sum_clientid(clientid4 client)
{
	static char buf[50];

	snprintf(buf, sizeof (buf), "CL=%llx", client);

	return (buf);
}

/*
 * Print a detail string for the given clientid4.
 */
static void
detail_clientid(clientid4 client)
{
	sprintf(get_line(0, 0), "Client ID = %llx", client);
}

/*
 * Write a summary string for the given delegation into buf.
 */

static void
sum_delegation(char *buf, size_t buflen, open_delegation4 *delp)
{
	switch (delp->delegation_type) {
	case OPEN_DELEGATE_NONE:
		snprintf(buf, buflen, " DT=N");
		break;
	case OPEN_DELEGATE_READ:
		snprintf(buf, buflen, " DT=R %s",
		    sum_deleg_stateid(&delp->open_delegation4_u.write.
		    stateid));
		break;
	case OPEN_DELEGATE_WRITE:
		snprintf(buf, buflen, " DT=W %s %s",
		    sum_deleg_stateid(&delp->open_delegation4_u.write.
		    stateid),
		    sum_space_limit(&delp->open_delegation4_u.write.
		    space_limit));
		break;
	default:
		snprintf(buf, buflen, " DT=?");
		break;
	}
}

static void
detail_delegation(open_delegation4 *delp)
{
	sprintf(get_line(0, 0), "Delegation Type = %d (%s)",
	    delp->delegation_type,
	    delegation_type_name(delp->delegation_type));

	switch (delp->delegation_type) {
	case OPEN_DELEGATE_NONE:
		/* no-op */
		break;
	case OPEN_DELEGATE_READ:
		detail_deleg_stateid(&delp->open_delegation4_u.read.stateid);
		sprintf(get_line(0, 0), "Recall = %s",
		    delp->open_delegation4_u.read.recall ?
		    "TRUE" : "FALSE");
		sprintf(get_line(0, 0), "[nfsacl4]");
		break;
	case OPEN_DELEGATE_WRITE:
		detail_deleg_stateid(&delp->open_delegation4_u.write.stateid);
		sprintf(get_line(0, 0), "Recall = %s",
		    delp->open_delegation4_u.write.recall ?
		    "TRUE" : "FALSE");
		detail_space_limit(&delp->open_delegation4_u.write.
		    space_limit);
		sprintf(get_line(0, 0), "[nfsacl4]");
		break;
	}
}


static void
detail_open_owner(open_owner4 *owner)
{
	sprintf(get_line(0, 0), "Open Owner hash = [%04X] ",
	    owner_hash(&owner->owner));
	sprintf(get_line(0, 0), "    len = %u   val = %s ",
	    owner->owner.owner_len,
	    tohex(owner->owner.owner_val, owner->owner.owner_len));
	detail_clientid(owner->clientid);
}

static void
detail_lock_owner(lock_owner4 *owner)
{
	sprintf(get_line(0, 0), "Lock Owner hash = [%04X] ",
	    owner_hash(&owner->owner));
	sprintf(get_line(0, 0), "    len = %u   val = %s ",
	    owner->owner.owner_len,
	    tohex(owner->owner.owner_val, owner->owner.owner_len));
	detail_clientid(owner->clientid);
}

static void
sum_openflag(char *bufp, int buflen, openflag4 *flagp)
{
	if (flagp->opentype == OPEN4_CREATE) {
		switch (flagp->openflag4_u.how.mode) {
		case UNCHECKED4:
			snprintf(bufp, buflen, "OT=CR(U)");
			break;
		case GUARDED4:
			snprintf(bufp, buflen, "OT=CR(G)");
			break;
		case EXCLUSIVE4:
			snprintf(bufp, buflen, "OT=CR(E)");
			break;
		default:
			snprintf(bufp, buflen, "OT=CR(?:%d)",
			    flagp->openflag4_u.how.mode);
			break;
		}
	} else
		snprintf(bufp, buflen, "OT=NC");
}

static void
detail_openflag(openflag4 *flagp)
{
	sprintf(get_line(0, 0), "Open Type = %s",
	    flagp->opentype == OPEN4_CREATE ? "CREATE" : "NOCREATE");
	if (flagp->opentype == OPEN4_CREATE)
		detail_createhow4(&flagp->openflag4_u.how);
}

/*
 * Fill in buf with the given path.
 */
static void
sum_pathname4(char *buf, size_t buflen, pathname4 *pathp)
{
	char *bp = buf;
	uint_t component;

	for (component = 0; component < pathp->pathname4_len;
	    component++) {
		snprintf(bp, buflen - (bp - buf),
		    component == 0 ? "%s" : "/%s",
		    component_name(&pathp->pathname4_val[component]));
		bp += strlen(bp);
	}
}

static void
sum_compname4(char *buf, size_t buflen, component4 *comp)
{
	snprintf(buf, buflen, "%s", component_name(comp));
}

static void
detail_compname4(component4 *comp)
{
	sprintf(get_line(0, 0), "%s", component_name(comp));
}

static void
detail_pathname4(pathname4 *pathp, char *what)
{
	char *bp = get_line(0, 0);
	uint_t component;

	sprintf(bp, what);
	bp += strlen(bp);

	for (component = 0; component < pathp->pathname4_len; component++) {
		sprintf(bp, component == 0 ? "%s" : "/%s",
		    component_name(&pathp->pathname4_val[component]));
		bp += strlen(bp);
	}
}

/*
 * Print detail information about the rpcsec_gss_info that is XDR-encoded
 * at mem.
 */

static void
detail_rpcsec_gss(rpcsec_gss_info *info)
{
	sprintf(get_line(0, 0), "OID = %s",
	    tohex(info->oid.sec_oid4_val, info->oid.sec_oid4_len));
	sprintf(get_line(0, 0), "QOP = %u", info->qop);
	sprintf(get_line(0, 0), "Service = %d (%s)",
	    info->service, gss_svc_name(info->service));
}

/*
 * Print detail information about the given secinfo4.
 */

static void
detail_secinfo4(secinfo4 *infop)
{
	sprintf(get_line(0, 0), "Flavor = %d (%s)",
	    infop->flavor, flavor_name(infop->flavor));
	switch (infop->flavor) {
	case RPCSEC_GSS:
		detail_rpcsec_gss(&infop->secinfo4_u.flavor_info);
		break;
	}
}


/*
 * Return a summary string corresponding to the given nfs_space_limit4.
 */

static char *
sum_space_limit(nfs_space_limit4 *limitp)
{
	static char buf[64];
	int buflen = sizeof (buf);

	buf[0] = '\0';
	switch (limitp->limitby) {
	case NFS_LIMIT_SIZE:
		snprintf(buf, buflen, "LB=SZ(%llu)",
		    limitp->nfs_space_limit4_u.filesize);
		break;
	case NFS_LIMIT_BLOCKS:
		snprintf(buf, buflen, "LB=BL(%u*%u)",
		    limitp->nfs_space_limit4_u.mod_blocks.num_blocks,
		    limitp->nfs_space_limit4_u.mod_blocks.bytes_per_block);
		break;
	default:
		snprintf(buf, buflen, "LB=?(%d)", limitp->limitby);
		break;
	}

	return (buf);
}

/*
 * Print detail information about the given nfs_space_limit4.
 */

static void
detail_space_limit(nfs_space_limit4 *limitp)
{
	sprintf(get_line(0, 0), "LimitBy = %d (%s)",
	    limitp->limitby,
	    limitby_name(limitp->limitby));

	switch (limitp->limitby) {
	case NFS_LIMIT_SIZE:
		sprintf(get_line(0, 0), "Bytes = %llu",
		    limitp->nfs_space_limit4_u.filesize);
		break;
	case NFS_LIMIT_BLOCKS:
		sprintf(get_line(0, 0), "Blocks = %u",
		    limitp->nfs_space_limit4_u.mod_blocks.num_blocks);
		sprintf(get_line(0, 0), "Bytes Per Block = %u",
		    limitp->nfs_space_limit4_u.mod_blocks.bytes_per_block);
		break;
	}
}


/*
 * Return the short name of a file type.
 */

static char *
sum_type_name(nfs_ftype4 type)
{
	static char buf[20];

	if (type < num_ftypes)
		return (ftype_names[type].short_name);
	else {
		sprintf(buf, "type %d", type);
		return (buf);
	}
}


/*
 * Return string with long/short flag names
 */

static char *
get_flags(uint_t flag, ftype_names_t *names, uint_t num_flags, int shortname,
    char *prefix)
{
	static char buf[200];
	char *bp = buf, *str;
	int i, len, blen = sizeof (buf);
	ftype_names_t *fn = NULL;

	*bp = '\0';

	if (prefix) {
		snprintf(bp, blen, "%s", prefix);
		bp += (len = sizeof (bp));
		blen -= len;
	}

	for (i = 0; i < 32; i++)
		if (flag & (1 << i)) {
			fn = names + (i < num_flags ? i : num_flags);
			str = (shortname ? fn->short_name : fn->long_name);

			snprintf(bp, blen, "%s,", str);
			bp += (len = strlen(bp));
			blen -= len;
		}

	if (fn)
		*(bp - 1) = '\0';
	else
		*buf = '\0';

	return (buf);
}


/*
 * Return the long name of a file type.
 */

static char *
detail_type_name(nfs_ftype4 type)
{
	static char buf[20];

	if (type < num_ftypes)
		return (ftype_names[type].long_name);
	else {
		sprintf(buf, "type %d", type);
		return (buf);
	}
}

/*
 * Return the name of an attribute.
 */

static char *
attr_name(uint_t attrnum)
{
	static char buf[20];

	if (attrnum < MAX_ATTRIBUTES)
		return (attr_info[attrnum].name);
	else {
		sprintf(buf, "attr #%d", attrnum);
		return (buf);
	}
}

/*
 * Return the name of the given open_claim_type4.
 */

static char *
claim_name(enum open_claim_type4 claim_type)
{
	char *result;

	switch (claim_type) {
	case CLAIM_NULL:
		result = "NULL";
		break;
	case CLAIM_PREVIOUS:
		result = "PREVIOUS";
		break;
	case CLAIM_DELEGATE_CUR:
		result = "DELEGATE CURRENT";
		break;
	case CLAIM_DELEGATE_PREV:
		result = "DELEGATE PREVIOUS";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

/*
 * Return a string naming the given delegation.
 */

static char *
delegation_type_name(enum open_delegation_type4 type)
{
	char *result;

	switch (type) {
	case OPEN_DELEGATE_NONE:
		result = "NONE";
		break;
	case OPEN_DELEGATE_READ:
		result = "READ";
		break;
	case OPEN_DELEGATE_WRITE:
		result = "WRITE";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

/*
 * Return the name of the given authentication flavor.
 */

static char *
flavor_name(uint_t flavor)
{
	char *result;
	static char buf[50];

	switch (flavor) {
	case AUTH_SYS:
		result = "AUTH_SYS";
		break;
	case AUTH_NONE:
		result = "AUTH_NONE";
		break;
	case AUTH_DH:
		result = "AUTH_DH";
		break;
	case RPCSEC_GSS:
		result = "RPCSEC_GSS";
		break;
	default:
		sprintf(buf, "[flavor %d]", flavor);
		result = buf;
		break;
	}

	return (result);
}

/*
 * Return the name of the given rpc_gss_svc_t.
 */

static char *
gss_svc_name(rpc_gss_svc_t svc)
{
	char *result;
	static char buf[50];

	switch (svc) {
	case RPC_GSS_SVC_NONE:
		result = "NONE";
		break;
	case RPC_GSS_SVC_INTEGRITY:
		result = "INTEGRITY";
		break;
	case RPC_GSS_SVC_PRIVACY:
		result = "PRIVACY";
		break;
	default:
		sprintf(buf, "Service %d", svc);
		result = buf;
		break;
	}

	return (result);
}

/*
 * Return a string name for the given limit_by4.
 */

static char *
limitby_name(enum limit_by4 limitby)
{
	char *result;

	switch (limitby) {
	case NFS_LIMIT_SIZE:
		result = "SIZE";
		break;
	case NFS_LIMIT_BLOCKS:
		result = "BLOCKS";
		break;
	default:
		result = "?";
		break;
	}

	return (result);
}

static char *
status_name(int status)
{
	char *p;

	switch (status) {
	case NFS4_OK:		p = "NFS4_OK"; break;
	case NFS4ERR_PERM:	p = "NFS4ERR_PERM"; break;
	case NFS4ERR_NOENT:	p = "NFS4ERR_NOENT"; break;
	case NFS4ERR_IO:	p = "NFS4ERR_IO"; break;
	case NFS4ERR_NXIO:	p = "NFS4ERR_NXIO"; break;
	case NFS4ERR_ACCESS:	p = "NFS4ERR_ACCESS"; break;
	case NFS4ERR_EXIST:	p = "NFS4ERR_EXIST"; break;
	case NFS4ERR_XDEV:	p = "NFS4ERR_XDEV"; break;
	case NFS4ERR_NOTDIR:	p = "NFS4ERR_NOTDIR"; break;
	case NFS4ERR_ISDIR:	p = "NFS4ERR_ISDIR"; break;
	case NFS4ERR_INVAL:	p = "NFS4ERR_INVAL"; break;
	case NFS4ERR_FBIG:	p = "NFS4ERR_FBIG"; break;
	case NFS4ERR_NOSPC:	p = "NFS4ERR_NOSPC"; break;
	case NFS4ERR_ROFS:	p = "NFS4ERR_ROFS"; break;
	case NFS4ERR_MLINK:	p = "NFS4ERR_MLINK"; break;
	case NFS4ERR_NAMETOOLONG:p = "NFS4ERR_NAMETOOLONG"; break;
	case NFS4ERR_NOTEMPTY:	p = "NFS4ERR_NOTEMPTY"; break;
	case NFS4ERR_DQUOT:	p = "NFS4ERR_DQUOT"; break;
	case NFS4ERR_STALE:	p = "NFS4ERR_STALE"; break;
	case NFS4ERR_BADHANDLE:	p = "NFS4ERR_BADHANDLE"; break;
	case NFS4ERR_BAD_COOKIE:p = "NFS4ERR_BAD_COOKIE"; break;
	case NFS4ERR_NOTSUPP:	p = "NFS4ERR_NOTSUPP"; break;
	case NFS4ERR_TOOSMALL:	p = "NFS4ERR_TOOSMALL"; break;
	case NFS4ERR_SERVERFAULT:p = "NFS4ERR_SERVERFAULT"; break;
	case NFS4ERR_BADTYPE:	p = "NFS4ERR_BADTYPE"; break;
	case NFS4ERR_DELAY:	p = "NFS4ERR_DELAY"; break;
	case NFS4ERR_SAME:	p = "NFS4ERR_SAME"; break;
	case NFS4ERR_DENIED:	p = "NFS4ERR_DENIED"; break;
	case NFS4ERR_EXPIRED:	p = "NFS4ERR_EXPIRED"; break;
	case NFS4ERR_LOCKED:	p = "NFS4ERR_LOCKED"; break;
	case NFS4ERR_GRACE:	p = "NFS4ERR_GRACE"; break;
	case NFS4ERR_FHEXPIRED:	p = "NFS4ERR_FHEXPIRED"; break;
	case NFS4ERR_SHARE_DENIED: p = "NFS4ERR_SHARE_DENIED"; break;
	case NFS4ERR_WRONGSEC:	p = "NFS4ERR_WRONGSEC"; break;
	case NFS4ERR_CLID_INUSE: p = "NFS4ERR_CLID_INUSE"; break;
	case NFS4ERR_RESOURCE:	p = "NFS4ERR_RESOURCE"; break;
	case NFS4ERR_MOVED:	p = "NFS4ERR_MOVED"; break;
	case NFS4ERR_NOFILEHANDLE: p = "NFS4ERR_NOFILEHANDLE"; break;
	case NFS4ERR_MINOR_VERS_MISMATCH: p = "NFS4ERR_MINOR_VERS_MISMATCH";
	break;
	case NFS4ERR_STALE_CLIENTID: p = "NFS4ERR_STALE_CLIENTID"; break;
	case NFS4ERR_STALE_STATEID: p = "NFS4ERR_STALE_STATEID"; break;
	case NFS4ERR_OLD_STATEID: p = "NFS4ERR_OLD_STATEID"; break;
	case NFS4ERR_BAD_STATEID: p = "NFS4ERR_BAD_STATEID"; break;
	case NFS4ERR_BAD_SEQID: p = "NFS4ERR_BAD_SEQID"; break;
	case NFS4ERR_NOT_SAME: p = "NFS4ERR_NOT_SAME"; break;
	case NFS4ERR_LOCK_RANGE: p = "NFS4ERR_LOCK_RANGE"; break;
	case NFS4ERR_SYMLINK: p = "NFS4ERR_SYMLINK"; break;
	case NFS4ERR_RESTOREFH: p = "NFS4ERR_RESTOREFH"; break;
	case NFS4ERR_LEASE_MOVED: p = "NFS4ERR_LEASE_MOVED"; break;
	case NFS4ERR_ATTRNOTSUPP: p = "NFS4ERR_ATTRNOTSUPP"; break;
	case NFS4ERR_NO_GRACE: p = "NFS4ERR_NO_GRACE"; break;
	case NFS4ERR_RECLAIM_BAD: p = "NFS4ERR_RECLAIM_BAD"; break;
	case NFS4ERR_RECLAIM_CONFLICT: p = "NFS4ERR_RECLAIM_CONFLICT"; break;
	case NFS4ERR_BADXDR: p = "NFS4ERR_BADXDR"; break;
	case NFS4ERR_LOCKS_HELD: p = "NFS4ERR_LOCKS_HELD"; break;
	case NFS4ERR_OPENMODE: p = "NFS4ERR_OPENMODE"; break;
	case NFS4ERR_BADOWNER: p = "NFS4ERR_BADOWNER"; break;
	case NFS4ERR_BADCHAR: p = "NFS4ERR_BADCHAR"; break;
	case NFS4ERR_BADNAME: p = "NFS4ERR_BADNAME"; break;
	case NFS4ERR_BAD_RANGE: p = "NFS4ERR_BAD_RANGE"; break;
	case NFS4ERR_LOCK_NOTSUPP: p = "NFS4ERR_LOCK_NOTSUPP"; break;
	case NFS4ERR_OP_ILLEGAL: p = "NFS4ERR_OP_ILLEGAL"; break;
	case NFS4ERR_DEADLOCK: p = "NFS4ERR_DEADLOCK"; break;
	case NFS4ERR_FILE_OPEN: p = "NFS4ERR_FILE_OPEN"; break;
	case NFS4ERR_ADMIN_REVOKED: p = "NFS4ERR_ADMIN_REVOKED"; break;
	case NFS4ERR_CB_PATH_DOWN: p = "NFS4ERR_CB_PATH_DOWN"; break;
	default:		p = "(unknown error)"; break;
	}

	return (p);
}

char *
nfsstat4_to_name(int status)
{
	return (status_name(status));
}

/*
 * Attribute print functions.  See attr_info_t.
 */

static void
prt_supported_attrs(XDR *xdr)
{
	static bitmap4 val;

	if (!xdr_bitmap4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Supported Attributes:");
	detail_attr_bitmap("\t", &val, NULL);
	xdr_free(xdr_bitmap4, (char *)&val);
}

static void
prt_type(XDR *xdr)
{
	nfs_ftype4 val;

	if (!xdr_nfs_ftype4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Type = %s", sum_type_name(val));
}

static void
prt_fh_expire_type(XDR *xdr)
{
	fattr4_fh_expire_type val;
	char *buf;
	bool_t first = TRUE;

	if (!xdr_fattr4_fh_expire_type(xdr, &val))
		longjmp(xdr_err, 1);
	buf = get_line(0, 0);

	sprintf(buf, "Filehandle expire type = ");
	if ((val & (FH4_NOEXPIRE_WITH_OPEN | FH4_VOLATILE_ANY |
	    FH4_VOL_MIGRATION | FH4_VOL_RENAME)) == 0) {
		strcat(buf, "Persistent");
		return;
	}
	if (val & FH4_NOEXPIRE_WITH_OPEN) {
		strcat(buf, "No Expire With OPEN");
		first = FALSE;
	}
	if (val & FH4_VOLATILE_ANY) {
		if (first)
			first = FALSE;
		else
			strcat(buf, ", ");
		strcat(buf, "Volatile at any time");
	}
	if (val & FH4_VOL_MIGRATION) {
		if (first)
			first = FALSE;
		else
			strcat(buf, ", ");
		strcat(buf, "Volatile at Migration");
	}
	if (val & FH4_VOL_RENAME) {
		if (first)
			first = FALSE;
		else
			strcat(buf, ", ");
		strcat(buf, "Volatile at Rename");
	}
}

static void
prt_change(XDR *xdr)
{
	changeid4 val;

	if (!xdr_changeid4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Change ID = 0x%llx", val);
					/* XXX print as time_t, too? */
}

static void
prt_size(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Size = %llu", val);
}

static void
prt_link_support(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Link Support = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_symlink_support(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Symlink Support = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_named_attr(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Has Named Attributes = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_fsid(XDR *xdr)
{
	fsid4 val;

	if (!xdr_fsid4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "FS ID: Major = %llx, Minor = %llx",
	    val.major, val.minor);
}

static void
prt_unique_handles(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Unique Handles = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_lease_time(XDR *xdr)
{
	uint32_t val;

	if (!xdr_uint32_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Lease Time = %u", val);
}

static void
prt_rdattr_error(XDR *xdr)
{
	nfsstat4 val;

	if (!xdr_nfsstat4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Rdattr Error = %u (%s)",
	    val, status_name(val));
}

static void
prt_acl(XDR *xdr)
{
	static fattr4_acl val;
	char buffy[NFS4_OPAQUE_LIMIT];
	int i, len;

	if (!xdr_fattr4_acl(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "ACL of %d entries", val.fattr4_acl_len);
	for (i = 0; i < val.fattr4_acl_len; i++) {
		sprintf(get_line(0, 0), "nfsace4[%d]", i);

		sprintf(get_line(0, 0), "  type = %x",
		    val.fattr4_acl_val[i].type);
		detail_acetype4(val.fattr4_acl_val[i].type);

		sprintf(get_line(0, 0), "  flags = %x",
		    val.fattr4_acl_val[i].flag);
		detail_aceflag4(val.fattr4_acl_val[i].flag);

		sprintf(get_line(0, 0), "  mask = %x",
		    val.fattr4_acl_val[i].access_mask);
		detail_acemask4(val.fattr4_acl_val[i].access_mask);

		len = val.fattr4_acl_val[i].who.utf8string_len;
		if (len >= NFS4_OPAQUE_LIMIT)
			len = NFS4_OPAQUE_LIMIT - 1;
		(void) strncpy(buffy, val.fattr4_acl_val[i].who.utf8string_val,
		    len);
		buffy[len] = '\0';
		sprintf(get_line(0, 0), "  who = %s", buffy);
	}
	xdr_free(xdr_fattr4_acl, (char *)&val);
}

static void
detail_acetype4(acetype4 type)
{
	if (type >= ACETYPE4_NAMES_MAX) {
		sprintf(get_line(0, 0), "     unknown type");
	} else {
		sprintf(get_line(0, 0), "     %s", acetype4_names[type]);
	}
}

static void
detail_uint32_bitmap(uint32_t mask, char *mask_names[], int names_max)
{
	char buffy[BUFSIZ], *name;
	char *indent = "     ";
	char *spacer = "  ";
	int pending = 0;
	int bit;
	int len, namelen, spacelen;

	strcpy(buffy, indent);
	len = strlen(buffy);
	spacelen = strlen(spacer);

	for (bit = 0; bit < names_max; bit++) {
		if (mask & (1 << bit)) {
			name = mask_names[bit];
			namelen = strlen(name);
			/* 80 - 6 for "NFS:  " = 74 */
			if ((len + spacelen + namelen) >= 74) {
				sprintf(get_line(0, 0), "%s", buffy);
				strcpy(buffy, indent);
				len = strlen(buffy);
				pending = 0;
			}
			(void) strlcat(buffy, spacer, sizeof (buffy));
			(void) strlcat(buffy, name, sizeof (buffy));
			pending = 1;
			len += spacelen + namelen;
		}
	}
	if (pending)
		sprintf(get_line(0, 0), "%s", buffy);
}

static void
detail_aceflag4(aceflag4 flag)
{
	detail_uint32_bitmap(flag, aceflag4_names, ACEFLAG4_NAMES_MAX);
}

static void
detail_acemask4(acemask4 mask)
{
	detail_uint32_bitmap(mask, acemask4_names, ACEMASK4_NAMES_MAX);
}

static void
prt_aclsupport(XDR *xdr)
{
	fattr4_aclsupport val;

	if (!xdr_fattr4_aclsupport(xdr, &val))
		longjmp(xdr_err, 1);
	if (val & ACL4_SUPPORT_ALLOW_ACL)
		sprintf(get_line(0, 0), "ALLOW ACL Supported");
	if (val & ACL4_SUPPORT_DENY_ACL)
		sprintf(get_line(0, 0), "DENY ACL Supported");
	if (val & ACL4_SUPPORT_AUDIT_ACL)
		sprintf(get_line(0, 0), "AUDIT ACL Supported");
	if (val & ACL4_SUPPORT_ALARM_ACL)
		sprintf(get_line(0, 0), "ALARM ACL Supported");
}

static void
prt_archive(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Archived = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_cansettime(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Server Can Set Time = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_case_insensitive(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Case Insensitive Lookups = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_case_preserving(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Case Preserving = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_chown_restricted(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Chown Is Restricted = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_filehandle(XDR *xdr)
{
	static nfs_fh4 val;

	if (!xdr_nfs_fh4(xdr, &val))
		longjmp(xdr_err, 1);
	detail_fh4(&val);
	xdr_free(xdr_nfs_fh4, (char *)&val);
}

static void
prt_fileid(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "File ID = %llu", val);
}

static void
prt_mounted_on_fileid(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Mounted On File ID = %llu", val);
}

static void
prt_files_avail(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Files Available = %llu", val);
}

static void
prt_files_free(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Files Free = %llu", val);
}

static void
prt_files_total(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Files Total = %llu", val);
}

static void
prt_fs_location(fs_location4 *fsl)
{
	int i;

	for (i = 0; i < fsl->server.server_len; i++)
		sprintf(get_line(0, 0), "server: %s",
		    utf8localize(&fsl->server.server_val[i]));

	detail_pathname4(&fsl->rootpath, "rootpath: ");
}

static void
prt_fs_locations(XDR *xdr)
{
	static fs_locations4 val;
	int i;

	if (!xdr_fs_locations4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "[fs_locations]");
	detail_pathname4(&val.fs_root, "fs_root: ");
	for (i = 0; i < val.locations.locations_len; i++)
		prt_fs_location(&val.locations.locations_val[i]);
	xdr_free(xdr_fs_locations4, (char *)&val);
}

static void
prt_hidden(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Hidden = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_homogeneous(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "FS Is Homogeneous = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_maxfilesize(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Maximum File Size = %llu", val);
}

static void
prt_maxlink(XDR *xdr)
{
	uint32_t val;

	if (!xdr_uint32_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Maximum Number of Links = %u", val);
}

static void
prt_maxname(XDR *xdr)
{
	uint32_t val;

	if (!xdr_uint32_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Maximum File Name Length = %u", val);
}

static void
prt_maxread(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Maximum Read Size = %llu", val);
}

static void
prt_maxwrite(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);

	sprintf(get_line(0, 0), "Maximum Write Size = %llu", val);
}

static void
prt_mimetype(XDR *xdr)
{
	static utf8string val;

	if (!xdr_utf8string(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "MIME Type = %s", utf8localize(&val));
	xdr_free(xdr_utf8string, (char *)&val);
}

static void
prt_mode(XDR *xdr)
{
	mode4 val;

	if (!xdr_mode4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Mode = 0%03o", val);
}

static void
prt_no_trunc(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Long Names Are Error (no_trunc) = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_numlinks(XDR *xdr)
{
	uint32_t val;

	if (!xdr_uint32_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Number of Links = %u", val);
}

static void
prt_owner(XDR *xdr)
{
	static utf8string val;

	if (!xdr_utf8string(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Owner = %s", utf8localize(&val));
	xdr_free(xdr_utf8string, (char *)&val);
}

static void
prt_owner_group(XDR *xdr)
{
	static utf8string val;

	if (!xdr_utf8string(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Group = %s", utf8localize(&val));
	xdr_free(xdr_utf8string, (char *)&val);
}

static void
prt_quota_avail_hard(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Quota Hard Limit = %llu", val);
}

static void
prt_quota_avail_soft(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Quota Soft Limit = %llu", val);
}

static void
prt_quota_used(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Quota Used = %llu", val);
}

static void
prt_rawdev(XDR *xdr)
{
	specdata4 val;

	if (!xdr_specdata4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Raw Device ID = %u, %u",
	    val.specdata1, val.specdata2);
}

static void
prt_space_avail(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Space Available = %llu", val);
}

static void
prt_space_free(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Space Free = %llu", val);
}

static void
prt_space_total(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Total Disk Space = %llu", val);
}

static void
prt_space_used(XDR *xdr)
{
	uint64_t val;

	if (!xdr_uint64_t(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Space Used (this object) = %llu", val);
}

static void
prt_system(XDR *xdr)
{
	bool_t val;

	if (!xdr_bool(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "System File = %s",
	    val ? "TRUE" : "FALSE");
}

static void
prt_time_access(XDR *xdr)
{
	nfstime4 val;

	if (!xdr_nfstime4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Last Access Time = %s",
	    format_time(val.seconds, val.nseconds));
}

static void
prt_time_access_set(XDR *xdr)
{
	settime4 val;

	if (!xdr_settime4(xdr, &val))
		longjmp(xdr_err, 1);
	if (val.set_it == SET_TO_CLIENT_TIME4) {
		sprintf(get_line(0, 0), "Access Time = %s (set to client time)",
		    format_time(val.settime4_u.time.seconds,
		    val.settime4_u.time.nseconds));
	} else if (val.set_it == SET_TO_SERVER_TIME4) {
		sprintf(get_line(0, 0), "Access Time (set to server time)");
	} else
		longjmp(xdr_err, 1);
}

static void
prt_time_backup(XDR *xdr)
{
	nfstime4 val;

	if (!xdr_nfstime4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Last Backup Time = %s",
	    format_time(val.seconds, val.nseconds));
}

static void
prt_time_create(XDR *xdr)
{
	nfstime4 val;

	if (!xdr_nfstime4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Creation Time = %s",
	    format_time(val.seconds, val.nseconds));
}

static void
prt_time_delta(XDR *xdr)
{
	nfstime4 val;

	if (!xdr_nfstime4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Server Time Granularity = %lld.%09d sec",
	    val.seconds, val.nseconds);
}

static void
prt_time_metadata(XDR *xdr)
{
	nfstime4 val;

	if (!xdr_nfstime4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Last Metadata Change Time = %s",
	    format_time(val.seconds, val.nseconds));
}

static void
prt_time_modify(XDR *xdr)
{
	nfstime4 val;

	if (!xdr_nfstime4(xdr, &val))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), "Last Modification Time = %s",
	    format_time(val.seconds, val.nseconds));
}

static void
prt_time_modify_set(XDR *xdr)
{
	settime4 val;

	if (!xdr_settime4(xdr, &val))
		longjmp(xdr_err, 1);
	if (val.set_it == SET_TO_CLIENT_TIME4) {
		sprintf(get_line(0, 0),
		    "Modification Time = %s (set to client time)",
		    format_time(val.settime4_u.time.seconds,
		    val.settime4_u.time.nseconds));
	} else if (val.set_it == SET_TO_SERVER_TIME4) {
		sprintf(get_line(0, 0),
		    "Modification Time (set to server time)");
	} else
		longjmp(xdr_err, 1);
}

/*
 * Display the UTF8 string that is next in the XDR stream.
 */

static void
showxdr_utf8string(char *fmt)
{
	static utf8string string;

	if (!xdr_utf8string(&xdrm, &string))
		longjmp(xdr_err, 1);
	sprintf(get_line(0, 0), fmt, utf8localize(&string));
	xdr_free(xdr_utf8string, (char *)&string);
}

/*
 * utf8string is defined in nfs4_prot.x as an opaque array, which means
 * when it is decoded into a string, the string might not have a trailing
 * null.  Also, the string will still be encoded in UTF-8, rather than
 * whatever character encoding is associated with the current locale.  This
 * routine converts a utf8string into a (null-terminated) C string.  One day
 * it will convert into the current character encoding, too.  To avoid
 * dealing with storage management issues, it allocates storage for each
 * new string, then this storage is "freed" when the packet has been
 * processed.
 */

#define	MAX_UTF8_STRINGS	512

static char *utf_buf[MAX_UTF8_STRINGS];
static size_t utf_buflen[MAX_UTF8_STRINGS];
static uint_t cur_utf_buf = 0;

static char *
utf8localize(utf8string *utf8str)
{
	size_t newsize, oldsize, len;
	char *result, *cp;

	len = utf8str->utf8string_len;
	if (len == 0)
		return ("");
	if (cur_utf_buf >= MAX_UTF8_STRINGS)
		return ("[Too Many UTF-8 Strings]");

	newsize = oldsize = utf_buflen[cur_utf_buf];


	if (oldsize < len + 1) {
		/* truncate opaques at NFS4_OPAQUE_LIMIT */
		if (len > NFS4_OPAQUE_LIMIT)
			len = NFS4_OPAQUE_LIMIT;
		newsize = len + 1;
	}
	if (newsize != oldsize) {
		utf_buf[cur_utf_buf] = realloc(utf_buf[cur_utf_buf],
		    newsize);
		if (utf_buf[cur_utf_buf] == NULL) {
			pr_err("out of memory\n");
			utf_buflen[cur_utf_buf] = 0;
			return ("");
		}
		utf_buflen[cur_utf_buf] = newsize;
	}

	result = utf_buf[cur_utf_buf];
	strncpy(result, utf8str->utf8string_val, len);
	result[len] = '\0';
	for (cp = result; cp < result + len; cp++) {
		if (!isprint(*cp)) {
			*cp = '.';
		}
	}

	cur_utf_buf++;

	return (result);
}

static void
utf8free()
{
	cur_utf_buf = 0;
}


/*
 * adler16(): adler32 hash code shamelessly copied and mutiliated from
 * usr/src/uts/common/io/ppp/spppcomp/zlib.[ch]
 *
 * The alg was originally created to provide a running
 * checksum, but we don't need that -- we just want to
 * chksum data described by buf,len; therefore, the first
 * parameter was removed (held the running checksum),
 * and s1/s2 are always set to their required initial
 * values (1 and 0).  I also ripped out code which only
 * applied to large data sets (bufs larger than 5k).  All
 * I wanted was their core checksum alg (which is supposed
 * to do really well).  The v2/v3 hash alg didn't work well
 * at all for v4 stuff -- it produced too many collisions.
 *
 * The copyright info from uts/common/io/ppp/spppcomp/zlib.[ch]
 * is included below.
 */

/* -----zlib.c copyright info below */
/*
 * Copyright 2000 Sun Microsystems, Inc.
 * All rights reserved.
 *
 * Updated from zlib-1.0.4 to zlib-1.1.3 by James Carlson.
 *
 * This file is derived from various .h and .c files from the zlib-1.0.4
 * distribution by Jean-loup Gailly and Mark Adler, with some additions
 * by Paul Mackerras to aid in implementing Deflate compression and
 * decompression for PPP packets.  See zlib.h for conditions of
 * distribution and use.
 *
 * Changes that have been made include:
 * - added Z_PACKET_FLUSH (see zlib.h for details)
 * - added inflateIncomp and deflateOutputPending
 * - allow strm->next_out to be NULL, meaning discard the output
 *
 * $Id: zlib.c,v 1.11 1998/09/13 23:37:12 paulus Exp $
 */
/* +++ adler32.c */
/*
 * adler32.c -- compute the Adler-32 checksum of a data stream
 * Copyright (C) 1995-1998 Mark Adler
 * For conditions of distribution and use, see copyright notice in zlib.h
 */
/* From: adler32.c,v 1.10 1996/05/22 11:52:18 me Exp $ */
/* -----zlib.c copyright info above */

/* -----zlib.h copyright info below */
/*
 * Copyright 2000 Sun Microsystems, Inc.
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation is hereby granted, provided that the above
 * copyright notice appears in all copies.
 *
 * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE
 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
 *
 * This file has been altered from its original by Sun Microsystems to
 * fit local coding style.
 */
/* -----zlib.h copyright info above */

#define	DO1(buf, i)  {s1 += buf[i]; s2 += s1; }
#define	DO2(buf, i)  DO1(buf, i); DO1(buf, i+1);
#define	DO4(buf, i)  DO2(buf, i); DO2(buf, i+2);
#define	DO8(buf, i)  DO4(buf, i); DO4(buf, i+4);
#define	DO16(buf)   DO8(buf, 0); DO8(buf, 8);

static uint32_t
adler16(void *p, int len)
{
	uint32_t s1 = 1;
	uint32_t s2 = 0;
	uchar_t *buf = p;

	while (len >= 16) {
		DO16(buf);
		buf += 16;
		len -= 16;
	}

	while (len > 0) {
		s1 += *buf++;
		s2 += s1;
		len--;
	}

	return ((uint32_t)(s2 ^ s1) & 0xFFFFU);
}