aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-pvfs2.c
blob: ce327e094991a1241b4a2589d057408c3f29940c (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
/* packet-pvfs2.c
 * Routines for pvfs2 packet dissection
 * By Mike Frisch <mfrisch@platform.com>
 * Joint and Several Copyright 2005, Mike Frisch and Platform Computing Inc.
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-smb.c and others
 *
 * TODO
 *
 *    - Add filename snooping (match file handles with file names),
 *      similar to how packet-rpc.c/packet-nfs.c implements it
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"


#include <epan/packet.h>
#include <epan/exceptions.h>
#include <epan/prefs.h>
#include <epan/strutil.h>
#include <epan/expert.h>
#include "packet-tcp.h"

#define TCP_PORT_PVFS2 3334 /* Not IANA registered */

#define PVFS2_FH_LENGTH 8

/* Header incl. magic number, mode, tag, size */
#define BMI_HEADER_SIZE 24

/* desegmentation of PVFS over TCP */
static gboolean pvfs_desegment = TRUE;

/* Forward declaration we need below */
void proto_register_pvfs(void);
void proto_reg_handoff_pvfs(void);

/* Initialize the protocol and registered fields */
static int proto_pvfs = -1;
static int hf_pvfs_magic_nr = -1;
static int hf_pvfs_uid = -1;
static int hf_pvfs_gid = -1;
static int hf_pvfs_mode = -1;
static int hf_pvfs_tag = -1;
static int hf_pvfs_size = -1;
static int hf_pvfs_release_number = -1;
static int hf_pvfs_encoding = -1;
static int hf_pvfs_server_op = -1;
/* static int hf_pvfs_handle = -1; */
static int hf_pvfs_fs_id = -1;
static int hf_pvfs_attrmask = -1;
static int hf_pvfs_attr = -1;
static int hf_pvfs_ds_type = -1;
static int hf_pvfs_error = -1;
static int hf_pvfs_atime = -1;
static int hf_pvfs_atime_sec = -1;
static int hf_pvfs_atime_nsec = -1;
static int hf_pvfs_mtime = -1;
static int hf_pvfs_mtime_sec = -1;
static int hf_pvfs_mtime_nsec = -1;
static int hf_pvfs_ctime = -1;
static int hf_pvfs_ctime_sec = -1;
static int hf_pvfs_ctime_nsec = -1;
static int hf_pvfs_parent_atime = -1;
static int hf_pvfs_parent_atime_sec = -1;
static int hf_pvfs_parent_atime_nsec = -1;
static int hf_pvfs_parent_mtime = -1;
static int hf_pvfs_parent_mtime_sec = -1;
static int hf_pvfs_parent_mtime_nsec = -1;
static int hf_pvfs_parent_ctime = -1;
static int hf_pvfs_parent_ctime_sec = -1;
static int hf_pvfs_parent_ctime_nsec = -1;
static int hf_pvfs_distribution = -1;
static int hf_pvfs_dfile_count = -1;
static int hf_pvfs_dirent_count = -1;
static int hf_pvfs_directory_version = -1;
static int hf_pvfs_path = -1;
static int hf_pvfs_total_completed = -1;
static int hf_pvfs_io_dist = -1;
static int hf_pvfs_aggregate_size = -1;
static int hf_pvfs_io_type = -1;
static int hf_pvfs_flowproto_type = -1;
static int hf_pvfs_server_param = -1;
static int hf_pvfs_prev_value = -1;
/* static int hf_pvfs_ram_free_bytes = -1; */
static int hf_pvfs_bytes_available = -1;
static int hf_pvfs_bytes_total = -1;
static int hf_pvfs_ram_bytes_total = -1;
static int hf_pvfs_ram_bytes_free = -1;
static int hf_pvfs_load_average_1s = -1;
static int hf_pvfs_load_average_5s = -1;
static int hf_pvfs_load_average_15s = -1;
static int hf_pvfs_uptime_seconds = -1;
static int hf_pvfs_handles_available = -1;
static int hf_pvfs_handles_total = -1;
static int hf_pvfs_unused = -1;
static int hf_pvfs_context_id = -1;
static int hf_pvfs_offset = -1;
static int hf_pvfs_stride = -1;
static int hf_pvfs_lb = -1;
static int hf_pvfs_ub = -1;
static int hf_pvfs_end_time_ms = -1;
static int hf_pvfs_cur_time_ms = -1;
static int hf_pvfs_start_time_ms = -1;
static int hf_pvfs_bytes_written = -1;
static int hf_pvfs_bytes_read = -1;
static int hf_pvfs_metadata_write = -1;
static int hf_pvfs_metadata_read = -1;
static int hf_pvfs_b_size = -1;
static int hf_pvfs_k_size = -1;
static int hf_pvfs_id_gen_t = -1;
static int hf_pvfs_attribute_key = -1;
static int hf_pvfs_attribute_value = -1;
static int hf_pvfs_strip_size = -1;
static int hf_pvfs_ereg = -1;
static int hf_pvfs_sreg = -1;
static int hf_pvfs_num_eregs = -1;
static int hf_pvfs_num_blocks = -1;
static int hf_pvfs_num_contig_chunks = -1;
static int hf_pvfs_server_nr = -1;
static int hf_pvfs_server_count = -1;
static int hf_pvfs_fh_length = -1;
static int hf_pvfs_fh_hash = -1;
static int hf_pvfs_permissions = -1;
static int hf_pvfs_server_mode = -1;
static int hf_pvfs_depth = -1;
static int hf_pvfs_num_nested_req = -1;
static int hf_pvfs_committed = -1;
static int hf_pvfs_refcount = -1;
static int hf_pvfs_numreq = -1;
static int hf_pvfs_truncate_request_flags = -1;
static int hf_pvfs_ds_position = -1;
static int hf_pvfs_dirent_limit = -1;
static int hf_pvfs_flush_request_flags = -1;
static int hf_pvfs_next_id = -1;
static int hf_pvfs_mgmt_perf_mon_request_count = -1;
static int hf_pvfs_mgmt_perf_mon_request_event_count = -1;
static int hf_pvfs_lookup_path_response_handle_count = -1;
static int hf_pvfs_getconfig_response_total_bytes = -1;
static int hf_pvfs_getconfig_response_lines = -1;
static int hf_pvfs_getconfig_response_config_bytes = -1;
static int hf_pvfs_mgmt_perf_mon_response_suggested_next_id = -1;
static int hf_pvfs_mgmt_perf_stat_valid_flag = -1;
static int hf_pvfs_mgmt_perf_stat_id = -1;
static int hf_pvfs_mgmt_perf_mon_response_perf_array_count = -1;
static int hf_pvfs_mgmt_iterate_handles_response_ds_position = -1;
static int hf_pvfs_mgmt_iterate_handles_response_handle_count = -1;
static int hf_pvfs_mgmt_dspace_info_list_response_dspace_info_count = -1;
static int hf_pvfs_mgmt_event_mon_response_api = -1;
static int hf_pvfs_mgmt_event_mon_response_operation = -1;
static int hf_pvfs_mgmt_event_mon_response_value = -1;
static int hf_pvfs_mgmt_event_mon_response_flags = -1;
static int hf_pvfs_mgmt_event_mon_response_tv_sec = -1;
static int hf_pvfs_mgmt_event_mon_response_tv_usec = -1;
static int hf_pvfs_fill_bytes = -1;
static int hf_pvfs_target_path_len = -1;
static int hf_pvfs_version2 = -1;
static int hf_pvfs_flow_data = -1;
static int hf_pvfs_getconfig_response_entry = -1;
static int hf_fhandle_data = -1;
static int hf_pvfs_opaque_length = -1;

/* Initialize the subtree pointers */
static gint ett_pvfs = -1;
static gint ett_pvfs_hdr = -1;
static gint ett_pvfs_credentials = -1;
static gint ett_pvfs_server_config = -1;
static gint ett_pvfs_server_config_branch = -1;
static gint ett_pvfs_attrmask = -1;
static gint ett_pvfs_time = -1;
static gint ett_pvfs_extent_array_tree = -1;
static gint ett_pvfs_extent_item = -1;
static gint ett_pvfs_string = -1;
static gint ett_pvfs_attr_tree = -1;
static gint ett_pvfs_distribution = -1;
static gint ett_pvfs_mgmt_perf_stat = -1;
static gint ett_pvfs_mgmt_dspace_info = -1;
static gint ett_pvfs_attr = -1;
static gint ett_pvfs_fh = -1;

static expert_field ei_pvfs_malformed = EI_INIT;

#define BMI_MAGIC_NR 51903

static const value_string names_pvfs_mode[] =
{
#define TCP_MODE_IMMED 1
	{ TCP_MODE_IMMED, "TCP_MODE_IMMED" },
#define TCP_MODE_UNEXP 2
	{ TCP_MODE_UNEXP, "TCP_MODE_UNEXP" },
#define TCP_MODE_EAGER 4
	{ TCP_MODE_EAGER, "TCP_MODE_EAGER" },
#define TCP_MODE_REND 8
	{ TCP_MODE_REND,  "TCP_MODE_REND" },
	{ 0, NULL }
};

static const value_string names_pvfs_encoding[] =
{
#define PVFS_ENCODING_DIRECT 1
	{ PVFS_ENCODING_DIRECT, "ENCODING_DIRECT" },
#define PVFS_ENCODING_LE_BFIELD 2
	{ PVFS_ENCODING_LE_BFIELD, "ENCODING_LE_BFIELD" },
#define PVFS_ENCODING_XDR 3
	{ PVFS_ENCODING_XDR, "ENCODING_XDR" },
	{ 0, NULL }
};

static const value_string names_pvfs_io_type[] =
{
#define PVFS_IO_READ 1
	{ PVFS_IO_READ, "PVFS_IO_READ" },
#define PVFS_IO_WRITE 2
	{ PVFS_IO_WRITE, "PVFS_IO_WRITE" },
	{ 0, NULL }
};

static const value_string names_pvfs_flowproto_type[] =
{
#define FLOWPROTO_DUMP_OFFSETS 1
	{ FLOWPROTO_DUMP_OFFSETS, "FLOWPROTO_DUMP_OFFSETS" },
#define FLOWPROTO_BMI_CACHE 2
	{ FLOWPROTO_BMI_CACHE, "FLOWPROTO_BMI_CACHE" },
#define FLOWPROTO_MULTIQUEUE 3
	{ FLOWPROTO_MULTIQUEUE, "FLOWPROTO_MULTIQUEUE" },
	{ 0, NULL }
};

static const value_string names_pvfs_server_param[] =
{
#define PVFS_SERV_PARAM_INVALID 0
	{ PVFS_SERV_PARAM_INVALID, "PVFS_SERV_PARAM_INVALID" },
#define PVFS_SERV_PARAM_GOSSIP_MASK 1
	{ PVFS_SERV_PARAM_GOSSIP_MASK, "PVFS_SERV_PARAM_GOSSIP_MASK" },
#define PVFS_SERV_PARAM_FSID_CHECK 2
	{ PVFS_SERV_PARAM_FSID_CHECK, "PVFS_SERV_PARAM_FSID_CHECK" },
#define PVFS_SERV_PARAM_ROOT_CHECK 3
	{ PVFS_SERV_PARAM_ROOT_CHECK, "PVFS_SERV_PARAM_ROOT_CHECK" },
#define PVFS_SERV_PARAM_MODE 4
	{ PVFS_SERV_PARAM_MODE, "PVFS_SERV_PARAM_MODE" },
#define PVFS_SERV_PARAM_EVENT_ON 5
	{ PVFS_SERV_PARAM_EVENT_ON, "PVFS_SERV_PARAM_EVENT_ON" },
#define PVFS_SERV_PARAM_EVENT_MASKS 6
	{ PVFS_SERV_PARAM_EVENT_MASKS, "PVFS_SERV_PARAM_EVENT_MASKS" },
	{ 0, NULL }
};

static const value_string names_pvfs_server_mode[] =
{
#define PVFS_SERVER_NORMAL_MODE 1
	{ PVFS_SERVER_NORMAL_MODE, "PVFS_SERVER_NORMAL_MODE" },
#define PVFS_SERVER_ADMIN_MODE 2
	{ PVFS_SERVER_ADMIN_MODE, "PVFS_SERVER_ADMIN_MODE" },
	{ 0, NULL }
};

/* Forward declaration */
static gboolean
dissect_pvfs_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		gboolean dissect_other_as_continuation);


static int dissect_pvfs_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
	dissect_pvfs_common(tvb, pinfo, tree, FALSE);
	return tvb_reported_length(tvb);
}

static guint get_pvfs_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb,
                              int offset, void *data _U_)
{
	guint32 plen;

	/*
	 * Get the length of the PVFS-over-TCP packet. Ignore top 32 bits
	 */
	plen = tvb_get_letohl(tvb, offset + 16);

	return plen+24;
}

static int
dissect_pvfs_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
	guint32 magic_nr, mode;
	guint64 size;

	/* verify that this is indeed PVFS and that it looks sane */
	if(tvb_reported_length(tvb)<24){
		/* too few bytes remaining to verify the header */
		return 0;
	}

	/* validate the magic number */
	magic_nr = tvb_get_letohl(tvb, 0);
	if(magic_nr!=BMI_MAGIC_NR){
		return 0;
	}

	/* Validate the TCP message mode (32-bit) */
	mode = tvb_get_letohl(tvb, 4);
	switch(mode){
	case TCP_MODE_IMMED:
	case TCP_MODE_UNEXP:
	case TCP_MODE_EAGER:
	case TCP_MODE_REND:
		break;
	default:
		/* invalid mode, not a PVFS packet */
		return 0;
	}

	/* validate the size : assume size must be >0 and less than 1000000 */
	size=tvb_get_letohl(tvb, 20);
	size<<=32;
	size|=tvb_get_letohl(tvb, 16);
	if((size>1000000)||(size==0)){
		return 0;
	}

	tcp_dissect_pdus(tvb, pinfo, tree, pvfs_desegment, 24, get_pvfs_pdu_len,
		dissect_pvfs_pdu, data);

	return tvb_reported_length(tvb);
}

static const value_string names_pvfs_server_op[] =
{
#define PVFS_SERV_INVALID 0
	{ PVFS_SERV_INVALID, "PVFS_SERV_INVALID" },
#define PVFS_SERV_CREATE 1
	{ PVFS_SERV_CREATE, "PVFS_SERV_CREATE" },
#define PVFS_SERV_REMOVE 2
	{ PVFS_SERV_REMOVE, "PVFS_SERV_REMOVE" },
#define PVFS_SERV_IO 3
	{ PVFS_SERV_IO, "PVFS_SERV_IO" },
#define PVFS_SERV_GETATTR 4
	{ PVFS_SERV_GETATTR, "PVFS_SERV_GETATTR" },
#define PVFS_SERV_SETATTR 5
	{ PVFS_SERV_SETATTR, "PVFS_SERV_SETATTR" },
#define PVFS_SERV_LOOKUP_PATH 6
	{ PVFS_SERV_LOOKUP_PATH, "PVFS_SERV_LOOKUP_PATH" },
#define PVFS_SERV_CRDIRENT 7
	{ PVFS_SERV_CRDIRENT, "PVFS_SERV_CRDIRENT" },
#define PVFS_SERV_RMDIRENT 8
	{ PVFS_SERV_RMDIRENT, "PVFS_SERV_RMDIRENT" },
#define PVFS_SERV_CHDIRENT 9
	{ PVFS_SERV_CHDIRENT, "PVFS_SERV_CHDIRENT" },
#define PVFS_SERV_TRUNCATE 10
	{ PVFS_SERV_TRUNCATE, "PVFS_SERV_TRUNCATE" },
#define PVFS_SERV_MKDIR 11
	{ PVFS_SERV_MKDIR, "PVFS_SERV_MKDIR" },
#define PVFS_SERV_READDIR 12
	{ PVFS_SERV_READDIR, "PVFS_SERV_READDIR" },
#define PVFS_SERV_GETCONFIG 13
	{ PVFS_SERV_GETCONFIG, "PVFS_SERV_GETCONFIG" },
#define PVFS_SERV_WRITE_COMPLETION 14
	{ PVFS_SERV_WRITE_COMPLETION, "PVFS_SERV_WRITE_COMPLETION" },
#define PVFS_SERV_FLUSH 15
	{ PVFS_SERV_FLUSH, "PVFS_SERV_FLUSH" },
#define PVFS_SERV_MGMT_SETPARAM 16
	{ PVFS_SERV_MGMT_SETPARAM, "PVFS_SERV_MGMT_SETPARAM" },
#define PVFS_SERV_MGMT_NOOP 17
	{ PVFS_SERV_MGMT_NOOP, "PVFS_SERV_MGMT_NOOP" },
#define PVFS_SERV_STATFS 18
	{ PVFS_SERV_STATFS, "PVFS_SERV_STATFS" },
#define PVFS_SERV_PERF_UPDATE 19  /* not a real protocol request */
	{ PVFS_SERV_PERF_UPDATE, "PVFS_SERV_PERF_UPDATE" },
#define PVFS_SERV_MGMT_PERF_MON 20
	{ PVFS_SERV_MGMT_PERF_MON, "PVFS_SERV_MGMT_PERF_MON" },
#define PVFS_SERV_MGMT_ITERATE_HANDLES 21
	{ PVFS_SERV_MGMT_ITERATE_HANDLES, "PVFS_SERV_MGMT_ITERATE_HANDLES" },
#define PVFS_SERV_MGMT_DSPACE_INFO_LIST 22
	{ PVFS_SERV_MGMT_DSPACE_INFO_LIST, "PVFS_SERV_MGMT_DSPACE_INFO_LIST" },
#define PVFS_SERV_MGMT_EVENT_MON 23
	{ PVFS_SERV_MGMT_EVENT_MON, "PVFS_SERV_MGMT_EVENT_MON" },
#define PVFS_SERV_MGMT_REMOVE_OBJECT 24
	{ PVFS_SERV_MGMT_REMOVE_OBJECT, "PVFS_SERV_MGMT_REMOVE_OBJECT" },
#define PVFS_SERV_MGMT_REMOVE_DIRENT 25
	{ PVFS_SERV_MGMT_REMOVE_DIRENT, "PVFS_SERV_MGMT_REMOVE_DIRENT" },
#define PVFS_SERV_MGMT_GET_DIRDATA_HANDLE 26
	{ PVFS_SERV_MGMT_GET_DIRDATA_HANDLE, "PVFS_SERV_MGMT_GET_DIRDATA_HANDLE" },
#define PVFS_SERV_JOB_TIMER 27    /* not a real protocol request */
	{ PVFS_SERV_JOB_TIMER, "PVFS_SERV_JOB_TIMER" },
#define PVFS_SERV_PROTO_ERROR 28
	{ PVFS_SERV_PROTO_ERROR, "PVFS_SERV_PROTO_ERROR" },
#define PVFS_SERV_GETEATTR 29
	{ PVFS_SERV_GETEATTR, "PVFS_SERV_GETEATTR" },
#define PVFS_SERV_SETEATTR 30
	{ PVFS_SERV_SETEATTR, "PVFS_SERV_SETEATTR" },
#define PVFS_SERV_DELEATTR 31
	{ PVFS_SERV_DELEATTR, "PVFS_SERV_DELEATTR" },
	{ 0, NULL }
};

/* special bits used to differentiate PVFS error codes from system
 *  * errno values
 *   */
#define PVFS_ERROR_BIT           (1 << 30)

/* a shorthand to make the error code definitions more readable */
#define E(num) (num|PVFS_ERROR_BIT)

static const value_string names_pvfs_error[] = {
	{ 0, "Success" },
#define PVFS_EPERM            E(1) /* Operation not permitted */
	{ PVFS_EPERM, "PVFS_EPERM" },
#define PVFS_ENOENT           E(2) /* No such file or directory */
	{ PVFS_ENOENT, "PVFS_ENOENT" },
#define PVFS_EINTR            E(3) /* Interrupted system call */
	{ PVFS_EINTR, "PVFS_EINTR" },
#define PVFS_EIO              E(4) /* I/O error */
	{ PVFS_EIO, "PVFS_EIO" },
#define PVFS_ENXIO            E(5) /* No such device or address */
	{ PVFS_ENXIO, "PVFS_ENXIO" },
#define PVFS_EBADF            E(6) /* Bad file number */
	{ PVFS_EBADF, "PVFS_EBADF" },
#define PVFS_EAGAIN           E(7) /* Try again */
	{ PVFS_EAGAIN, "PVFS_EAGAIN" },
#define PVFS_ENOMEM           E(8) /* Out of memory */
	{ PVFS_ENOMEM, "PVFS_ENOMEM" },
#define PVFS_EFAULT           E(9) /* Bad address */
	{ PVFS_EFAULT, "PVFS_EFAULT" },
#define PVFS_EBUSY           E(10) /* Device or resource busy */
	{ PVFS_EBUSY, "PVFS_EBUSY" },
#define PVFS_EEXIST          E(11) /* File exists */
	{ PVFS_EEXIST, "PVFS_EEXIST" },
#define PVFS_ENODEV          E(12) /* No such device */
	{ PVFS_ENODEV, "PVFS_ENODEV" },
#define PVFS_ENOTDIR         E(13) /* Not a directory */
	{ PVFS_ENOTDIR, "PVFS_ENOTDIR" },
#define PVFS_EISDIR          E(14) /* Is a directory */
	{ PVFS_EISDIR, "PVFS_EISDIR" },
#define PVFS_EINVAL          E(15) /* Invalid argument */
	{ PVFS_EINVAL, "PVFS_EINVAL" },
#define PVFS_EMFILE          E(16) /* Too many open files */
	{ PVFS_EMFILE, "PVFS_EMFILE" },
#define PVFS_EFBIG           E(17) /* File too large */
	{ PVFS_EFBIG, "PVFS_EFBIG" },
#define PVFS_ENOSPC          E(18) /* No space left on device */
	{ PVFS_ENOSPC, "PVFS_ENOSPC" },
#define PVFS_EROFS           E(19) /* Read-only file system */
	{ PVFS_EROFS, "PVFS_EROFS" },
#define PVFS_EMLINK          E(20) /* Too many links */
	{ PVFS_EMLINK, "PVFS_EMLINK" },
#define PVFS_EPIPE           E(21) /* Broken pipe */
	{ PVFS_EPIPE, "PVFS_EPIPE" },
#define PVFS_EDEADLK         E(22) /* Resource deadlock would occur */
	{ PVFS_EDEADLK, "PVFS_EDEADLK" },
#define PVFS_ENAMETOOLONG    E(23) /* File name too long */
	{ PVFS_ENAMETOOLONG, "PVFS_ENAMETOOLONG" },
#define PVFS_ENOLCK          E(24) /* No record locks available */
	{ PVFS_ENOLCK, "PVFS_ENOLCK" },
#define PVFS_ENOSYS          E(25) /* Function not implemented */
	{ PVFS_ENOSYS, "PVFS_ENOSYS" },
#define PVFS_ENOTEMPTY       E(26) /* Directory not empty */
	{ PVFS_ENOTEMPTY, "PVFS_ENOTEMPTY" },
#define PVFS_ELOOP           E(27) /* Too many symbolic links encountered */
	{ PVFS_ELOOP, "PVFS_ELOOP" },
#define PVFS_EWOULDBLOCK     E(28) /* Operation would block */
	{ PVFS_EWOULDBLOCK, "PVFS_EWOULDBLOCK" },
#define PVFS_ENOMSG          E(29) /* No message of desired type */
	{ PVFS_ENOMSG, "PVFS_ENOMSG" },
#define PVFS_EUNATCH         E(30) /* Protocol driver not attached */
	{ PVFS_EUNATCH, "PVFS_EUNATCH" },
#define PVFS_EBADR           E(31) /* Invalid request descriptor */
	{ PVFS_EBADR, "PVFS_EBADR" },
#define PVFS_EDEADLOCK       E(32)
	{ PVFS_EDEADLOCK, "PVFS_EDEADLOCK" },
#define PVFS_ENODATA         E(33) /* No data available */
	{ PVFS_ENODATA, "PVFS_ENODATA" },
#define PVFS_ETIME           E(34) /* Timer expired */
	{ PVFS_ETIME, "PVFS_ETIME" },
#define PVFS_ENONET          E(35) /* Machine is not on the network */
	{ PVFS_ENONET, "PVFS_ENONET" },
#define PVFS_EREMOTE         E(36) /* Object is remote */
	{ PVFS_EREMOTE, "PVFS_EREMOTE" },
#define PVFS_ECOMM           E(37) /* Communication error on send */
	{ PVFS_ECOMM, "PVFS_ECOMM" },
#define PVFS_EPROTO          E(38) /* Protocol error */
	{ PVFS_EPROTO, "PVFS_EPROTO" },
#define PVFS_EBADMSG         E(39) /* Not a data message */
	{ PVFS_EBADMSG, "PVFS_EBADMSG" },
#define PVFS_EOVERFLOW       E(40) /* Value too large for defined data type */
	{ PVFS_EOVERFLOW, "PVFS_EOVERFLOW" },
#define PVFS_ERESTART        E(41) /* Interrupted system call should be restarted */
	{ PVFS_ERESTART, "PVFS_ERESTART" },
#define PVFS_EMSGSIZE        E(42) /* Message too long */
	{ PVFS_EMSGSIZE, "PVFS_EMSGSIZE" },
#define PVFS_EPROTOTYPE      E(43) /* Protocol wrong type for socket */
	{ PVFS_EPROTOTYPE, "PVFS_EPROTOTYPE" },
#define PVFS_ENOPROTOOPT     E(44) /* Protocol not available */
	{ PVFS_ENOPROTOOPT, "PVFS_ENOPROTOOPT" },
#define PVFS_EPROTONOSUPPORT E(45) /* Protocol not supported */
	{ PVFS_EPROTONOSUPPORT, "PVFS_EPROTONOSUPPORT" },
#define PVFS_EOPNOTSUPP      E(46) /* Operation not supported on transport endpoint */
	{ PVFS_EOPNOTSUPP, "PVFS_EOPNOTSUPP" },
#define PVFS_EADDRINUSE      E(47) /* Address already in use */
	{ PVFS_EADDRINUSE, "PVFS_EADDRINUSE" },
#define PVFS_EADDRNOTAVAIL   E(48) /* Cannot assign requested address */
	{ PVFS_EADDRNOTAVAIL, "PVFS_EADDRNOTAVAIL" },
#define PVFS_ENETDOWN        E(49) /* Network is down */
	{ PVFS_ENETDOWN, "PVFS_ENETDOWN" },
#define PVFS_ENETUNREACH     E(50) /* Network is unreachable */
	{ PVFS_ENETUNREACH, "PVFS_ENETUNREACH" },
#define PVFS_ENETRESET       E(51) /* Network dropped connection because of reset */
	{ PVFS_ENETRESET, "PVFS_ENETRESET" },
#define PVFS_ENOBUFS         E(52) /* No buffer space available */
	{ PVFS_ENOBUFS, "PVFS_ENOBUFS" },
#define PVFS_ETIMEDOUT       E(53) /* Connection timed out */
	{ PVFS_ETIMEDOUT, "PVFS_ETIMEDOUT" },
#define PVFS_ECONNREFUSED    E(54) /* Connection refused */
	{ PVFS_ECONNREFUSED, "PVFS_ECONNREFUSED" },
#define PVFS_EHOSTDOWN       E(55) /* Host is down */
	{ PVFS_EHOSTDOWN, "PVFS_EHOSTDOWN" },
#define PVFS_EHOSTUNREACH    E(56) /* No route to host */
	{ PVFS_EHOSTUNREACH, "PVFS_EHOSTUNREACH" },
#define PVFS_EALREADY        E(57) /* Operation already in progress */
	{ PVFS_EALREADY, "PVFS_EALREADY" },
#define PVFS_EACCES          E(58) /* Operation already in progress */
	{ PVFS_EACCES, "PVFS_EACCES" },
	{ 0, NULL }
};

static int
dissect_pvfs2_error(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	gint32 err;
	const char *errmsg = NULL;

	err = tvb_get_letohl(tvb, offset);
	proto_tree_add_uint(tree, hf_pvfs_error, tvb, offset, 4, -err);
	offset += 4;

	if (err != 0)
	{
		errmsg = val_to_str(-err, names_pvfs_error, "Unknown error: %u");
		col_append_fstr(pinfo->cinfo, COL_INFO, " Error: %s", errmsg);
	}

	return offset;
}

static int
dissect_pvfs_credentials(tvbuff_t *tvb, proto_tree *parent_tree,
		int offset)
{
	proto_tree *hcred_tree;
	guint32 uid, gid;

	uid = tvb_get_letohl(tvb, offset);
	gid = tvb_get_letohl(tvb, offset + 4);

	hcred_tree = proto_tree_add_subtree_format(parent_tree, tvb, offset, 8,
			ett_pvfs_credentials, NULL, "Credentials (UID: %d, GID: %d)", uid, gid);

	/* UID */
	proto_tree_add_item(hcred_tree, hf_pvfs_uid, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* GID */
	proto_tree_add_item(hcred_tree, hf_pvfs_gid, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static const value_string names_pvfs_attr[] =
{
#define PVFS_ATTR_COMMON_UID   (1 << 0)
#define PVFS_ATTR_BIT_COMMON_UID 0
	{ PVFS_ATTR_BIT_COMMON_UID, "PVFS_ATTR_COMMON_UID" },

#define PVFS_ATTR_COMMON_GID   (1 << 1)
#define PVFS_ATTR_BIT_COMMON_GID 1
	{ PVFS_ATTR_BIT_COMMON_GID, "PVFS_ATTR_COMMON_GID" },

#define PVFS_ATTR_COMMON_PERM  (1 << 2)
#define PVFS_ATTR_BIT_COMMON_PERM 2
	{ PVFS_ATTR_BIT_COMMON_PERM, "PVFS_ATTR_COMMON_PERM" },

#define PVFS_ATTR_COMMON_ATIME (1 << 3)
#define PVFS_ATTR_BIT_COMMON_ATIME 3
	{ PVFS_ATTR_BIT_COMMON_ATIME, "PVFS_ATTR_COMMON_ATIME" },

#define PVFS_ATTR_COMMON_CTIME (1 << 4)
#define PVFS_ATTR_BIT_COMMON_CTIME 4
	{ PVFS_ATTR_BIT_COMMON_CTIME, "PVFS_ATTR_COMMON_CTIME" },

#define PVFS_ATTR_COMMON_MTIME (1 << 5)
#define PVFS_ATTR_BIT_COMMON_MTIME 5
	{ PVFS_ATTR_BIT_COMMON_MTIME, "PVFS_ATTR_COMMON_MTIME" },

#define PVFS_ATTR_COMMON_TYPE  (1 << 6)
#define PVFS_ATTR_BIT_COMMON_TYPE 6
	{ PVFS_ATTR_BIT_COMMON_TYPE, "PVFS_ATTR_COMMON_TYPE" },

#if 0
#define PVFS_ATTR_COMMON_ALL                       \
	(PVFS_ATTR_COMMON_UID   | PVFS_ATTR_COMMON_GID   | \
	  PVFS_ATTR_COMMON_PERM  | PVFS_ATTR_COMMON_ATIME | \
	  PVFS_ATTR_COMMON_CTIME | PVFS_ATTR_COMMON_MTIME | \
	  PVFS_ATTR_COMMON_TYPE)
#endif

/* internal attribute masks for metadata objects */
#define PVFS_ATTR_META_DIST    (1 << 10)
#define PVFS_ATTR_BIT_META_DIST 10
	{ PVFS_ATTR_BIT_META_DIST, "PVFS_ATTR_META_DIST" },

#define PVFS_ATTR_META_DFILES  (1 << 11)
#define PVFS_ATTR_BIT_META_DFILES 11
	{ PVFS_ATTR_BIT_META_DFILES, "PVFS_ATTR_META_DFILES" },

#if 0
#define PVFS_ATTR_META_ALL \
	(PVFS_ATTR_META_DIST | PVFS_ATTR_META_DFILES)
#endif

/* internal attribute masks for datafile objects */
#define PVFS_ATTR_DATA_SIZE            (1 << 15)
#define PVFS_ATTR_BIT_DATA_SIZE 15
	{ PVFS_ATTR_BIT_DATA_SIZE, "PVFS_ATTR_DATA_SIZE" },

#if 0
#define PVFS_ATTR_DATA_ALL   PVFS_ATTR_DATA_SIZE
#endif

/* internal attribute masks for symlink objects */
#define PVFS_ATTR_SYMLNK_TARGET            (1 << 18)
#define PVFS_ATTR_BIT_SYMLINK_TARGET 18
	{ PVFS_ATTR_BIT_SYMLINK_TARGET, "PVFS_ATTR_SYMLNK_TARGET" },

#if 0
#define PVFS_ATTR_SYMLNK_ALL PVFS_ATTR_SYMLNK_TARGET
#endif

/* internal attribute masks for directory objects */
#define PVFS_ATTR_DIR_DIRENT_COUNT         (1 << 19)
#define PVFS_ATTR_BIT_DIR_DIRENT_COUNT 19
	{ PVFS_ATTR_BIT_DIR_DIRENT_COUNT, "PVFS_ATTR_DIR_DIRENT_COUNT" },

#if 0
#define PVFS_ATTR_DIR_ALL PVFS_ATTR_DIR_DIRENT_COUNT
#endif

/* attribute masks used by system interface callers */
#define PVFS_ATTR_SYS_SIZE                  (1 << 20)
#define PVFS_ATTR_BIT_SYS_SIZE 20
	{ PVFS_ATTR_BIT_SYS_SIZE, "PVFS_ATTR_SYS_SIZE" },

#define PVFS_ATTR_SYS_LNK_TARGET            (1 << 24)
#define PVFS_ATTR_BIT_SYS_LNK_TARGET 24
	{ PVFS_ATTR_BIT_SYS_LNK_TARGET, "PVFS_ATTR_SYS_LNK_TARGET" },

#define PVFS_ATTR_SYS_DFILE_COUNT           (1 << 25)
#define PVFS_ATTR_BIT_SYS_DFILE_COUNT 25
	{ PVFS_ATTR_BIT_SYS_DFILE_COUNT, "PVFS_ATTR_SYS_DFILE_COUNT" },

#define PVFS_ATTR_SYS_DIRENT_COUNT          (1 << 26)
#define PVFS_ATTR_BIT_SYS_DIRENT_COUNT 26
	{ PVFS_ATTR_BIT_SYS_DIRENT_COUNT, "PVFS_ATTR_SYS_DIRENT_COUNT" },

#if 0
#define PVFS_ATTR_SYS_UID        PVFS_ATTR_COMMON_UID
#define PVFS_ATTR_SYS_GID        PVFS_ATTR_COMMON_GID
#define PVFS_ATTR_SYS_PERM       PVFS_ATTR_COMMON_PERM
#define PVFS_ATTR_SYS_ATIME      PVFS_ATTR_COMMON_ATIME
#define PVFS_ATTR_SYS_CTIME      PVFS_ATTR_COMMON_CTIME
#define PVFS_ATTR_SYS_MTIME      PVFS_ATTR_COMMON_MTIME
#define PVFS_ATTR_SYS_TYPE       PVFS_ATTR_COMMON_TYPE
#endif
	{ 0, NULL }
};

#if 0
#define PVFS_ATTR_SYS_ALL                    \
	(PVFS_ATTR_COMMON_ALL | PVFS_ATTR_SYS_SIZE | \
	  PVFS_ATTR_SYS_LNK_TARGET | PVFS_ATTR_SYS_DFILE_COUNT | \
	  PVFS_ATTR_SYS_DIRENT_COUNT)

#define PVFS_ATTR_SYS_ALL_NOSIZE                   \
	(PVFS_ATTR_COMMON_ALL | PVFS_ATTR_SYS_LNK_TARGET | \
	  PVFS_ATTR_SYS_DFILE_COUNT | PVFS_ATTR_SYS_DIRENT_COUNT)

#define PVFS_ATTR_SYS_ALL_SETABLE \
	(PVFS_ATTR_COMMON_ALL-PVFS_ATTR_COMMON_TYPE)
#endif


static int
dissect_pvfs2_attrmask(tvbuff_t *tvb, proto_tree *tree, int offset,
		guint32 *pattrmask)
{
	guint32 attrmask, i;
	proto_item *attritem;
	proto_tree *attrtree;

	attrmask = tvb_get_letohl(tvb, offset);

	attritem = proto_tree_add_uint(tree, hf_pvfs_attrmask, tvb, offset, 4, attrmask);
	attrtree = proto_item_add_subtree(attritem, ett_pvfs_attrmask);

	for (i = 0; i < 32; i++)
	{
		if (attrmask & (1 << i))
			proto_tree_add_uint(attrtree, hf_pvfs_attr, tvb, offset, 4, i);
	}

	offset += 4;

	if (pattrmask)
		*pattrmask = attrmask;

	return offset;
}

static const value_string names_pvfs_ds_type[] = {
#define PVFS_TYPE_NONE 0
	{ PVFS_TYPE_NONE, "PVFS_TYPE_NONE" },
#define PVFS_TYPE_METAFILE (1 << 0)
	{ PVFS_TYPE_METAFILE, "PVFS_TYPE_METAFILE" },
#define PVFS_TYPE_DATAFILE (1 << 1)
	{ PVFS_TYPE_DATAFILE, "PVFS_TYPE_DATAFILE" },
#define PVFS_TYPE_DIRECTORY (1 << 2)
	{ PVFS_TYPE_DIRECTORY, "PVFS_TYPE_DIRECTORY" },
#define PVFS_TYPE_SYMLINK (1 << 3)
	{ PVFS_TYPE_SYMLINK, "PVFS_TYPE_SYMLINK" },
#define PVFS_TYPE_DIRDATA (1 << 4)
	{ PVFS_TYPE_DIRDATA, "PVFS_TYPE_DIRDATA" },
	{ 0, NULL }
};

static int
dissect_pvfs2_ds_type(tvbuff_t *tvb, proto_tree *tree, int offset,
		int *pds_type)
{
	guint32 ds_type;

	ds_type = tvb_get_letohl(tvb, offset);

	proto_tree_add_uint(tree, hf_pvfs_ds_type, tvb, offset, 4, ds_type);

	offset += 4;

	if (pds_type)
		*pds_type = ds_type;

	return offset;
}

#define roundup4(x) (((x) + 3) & ~3)
#define roundup8(x) (((x) + 7) & ~7)

static int
dissect_pvfs_opaque_data(tvbuff_t *tvb, int offset,
	proto_tree *tree,
	packet_info *pinfo _U_,
	int hfindex,
	gboolean fixed_length, guint32 length,
	gboolean string_data, const char **string_buffer_ret)
{
	int data_offset;
	proto_item *string_item = NULL;
	proto_tree *string_tree = NULL;

	guint32 string_length;
	guint32 string_length_full;
	guint32 string_length_packet;
	guint32 string_length_captured;
	guint32 string_length_copy;

	int fill_truncated;
	guint32 fill_length;
	guint32 fill_length_packet;
	guint32 fill_length_captured;
	guint32 fill_length_copy;

	int exception = 0;

	char *string_buffer = NULL;
	const char *string_buffer_print = NULL;

	if (fixed_length) {
		string_length = length;
		data_offset = offset;
	} else {
		string_length = tvb_get_letohl(tvb,offset+0);
		data_offset = offset + 4;

		/*
		 * Variable-length strings include NULL terminator on-the-wire but
		 * NULL terminator is not included in string length.
		 */

		if (string_data)
			string_length += 1;
	}

	string_length_captured = tvb_captured_length_remaining(tvb, data_offset);
	string_length_packet = tvb_reported_length_remaining(tvb, data_offset);

	/*
	 * Strangeness...  the protocol basically says that the length plus
	 * the string must be padded out to an 8-byte boundary.
	 */

	if (!string_data)
		string_length_full = roundup4(string_length);
	else
		string_length_full = roundup8(4 + string_length);

	if (string_length_captured < string_length) {
		/* truncated string */
		string_length_copy = string_length_captured;
		fill_truncated = 2;
		fill_length = 0;
		fill_length_copy = 0;

		if (string_length_packet < string_length)
			exception = ReportedBoundsError;
		else
			exception = BoundsError;
	}
	else {
		/* full string data */
		string_length_copy = string_length;

		if (!string_data)
			fill_length = string_length_full - string_length;
		else
			fill_length = string_length_full - string_length - 4;

		fill_length_captured = tvb_captured_length_remaining(tvb,
		    data_offset + string_length);
		fill_length_packet = tvb_reported_length_remaining(tvb,
		    data_offset + string_length);

		if (fill_length_captured < fill_length) {
			/* truncated fill bytes */
			fill_length_copy = fill_length_packet;
			fill_truncated = 1;
			if (fill_length_packet < fill_length)
				exception = ReportedBoundsError;
			else
				exception = BoundsError;
		}
		else {
			/* full fill bytes */
			fill_length_copy = fill_length;
			fill_truncated = 0;
		}
	}

	if (string_data) {
		char *tmpstr;

		tmpstr = (char *) tvb_get_string_enc(wmem_packet_scope(), tvb, data_offset,
				string_length_copy, ENC_ASCII);

		string_buffer = (char *)memcpy(wmem_alloc(wmem_packet_scope(), string_length_copy+1), tmpstr, string_length_copy);
	} else {
		string_buffer = (char *) tvb_memcpy(tvb,
				wmem_alloc(wmem_packet_scope(), string_length_copy+1), data_offset, string_length_copy);
	}

	string_buffer[string_length_copy] = '\0';

	/* calculate a nice printable string */
	if (string_length) {
		if (string_length != string_length_copy) {
			if (string_data) {
				char *formatted;
				size_t string_buffer_size = 0;
				char *string_buffer_temp;

				formatted = format_text(wmem_packet_scope(), (guint8 *)string_buffer,
						(int)strlen(string_buffer));

				string_buffer_size = strlen(formatted) + 12 + 1;

				/* alloc maximum data area */
				string_buffer_temp = (char*) wmem_alloc(wmem_packet_scope(), string_buffer_size);
				/* copy over the data */
				g_snprintf(string_buffer_temp, (gulong)string_buffer_size,
						"%s<TRUNCATED>", formatted);
				/* append <TRUNCATED> */
				/* This way, we get the TRUNCATED even
				   in the case of totally wrong packets,
				   where \0 are inside the string.
				   TRUNCATED will appear at the
				   first \0 or at the end (where we
				   put the securing \0).
				*/
				string_buffer_print = string_buffer_temp;
			} else {
				string_buffer_print="<DATA><TRUNCATED>";
			}
		} else {
			if (string_data) {
				string_buffer_print = format_text(wmem_packet_scope(), (guint8 *) string_buffer,
								 (int)strlen(string_buffer));
			} else {
				string_buffer_print="<DATA>";
			}
		}
	} else {
		string_buffer_print="<EMPTY>";
	}

	string_item = proto_tree_add_string(tree, hfindex, tvb, offset+0, -1,
		    string_buffer_print);

	string_tree = proto_item_add_subtree(string_item,
		    	ett_pvfs_string);

	if (!fixed_length) {
		proto_tree_add_uint_format_value(string_tree, hf_pvfs_opaque_length, tvb, offset, 4,
				string_length - 1, "%u (excl. NULL terminator)", string_length - 1);
		offset += 4;
	}

	if (string_data) {
		proto_tree_add_string_format(string_tree,
			hfindex, tvb, offset, string_length_copy,
			string_buffer,
			"contents: %s", string_buffer_print);
	} else {
		proto_tree_add_bytes_format(string_tree,
			hfindex, tvb, offset, string_length_copy,
			(guint8 *) string_buffer,
			"contents: %s", string_buffer_print);
	}

	offset += string_length_copy;

	if (fill_length) {
		if (string_tree) {
			if (fill_truncated) {
				proto_tree_add_bytes_format_value(string_tree, hf_pvfs_fill_bytes, tvb,
				offset, fill_length_copy, NULL,
				"opaque data <TRUNCATED>");
			}
			else {
				proto_tree_add_bytes_format_value(string_tree, hf_pvfs_fill_bytes, tvb,
				offset, fill_length_copy, NULL,
				"opaque data");
			}
		}
		offset += fill_length_copy;
	}

	if (string_item)
		proto_item_set_end(string_item, tvb, offset);

	if (string_buffer_ret != NULL)
		*string_buffer_ret = string_buffer_print;

	/*
	 * If the data was truncated, throw the appropriate exception,
	 * so that dissection stops and the frame is properly marked.
	 */
	if (exception != 0)
		THROW(exception);

	return offset;
}

static int
dissect_pvfs_string(tvbuff_t *tvb, proto_tree *tree, int hfindex,
		int offset, const char **string_buffer_ret)
{
	return dissect_pvfs_opaque_data(tvb, offset, tree, NULL, hfindex,
			FALSE, 0, TRUE, string_buffer_ret);
}

static void
dissect_fhandle_data_unknown(tvbuff_t *tvb, int offset, proto_tree *tree)
{
	guint bytes_left  = PVFS2_FH_LENGTH;

	proto_tree_add_item(tree, hf_fhandle_data, tvb, offset, bytes_left, ENC_NA);
}

static void
dissect_fhandle_data(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
		     proto_tree *tree, guint32 *hash)
{
	guint32 fhhash;
	guint32 i;

	/* Not all bytes there. Any attempt to deduce the type would be
		senseless. */
	if (!tvb_bytes_exist(tvb, offset, PVFS2_FH_LENGTH))
		goto type_ready;

	/* create a semiunique hash value for the filehandle */
	for(fhhash=0,i=0;i<(PVFS2_FH_LENGTH-3);i+=4){
		guint32 val;
		val = tvb_get_ntohl(tvb, offset+i);
		fhhash ^= val;
		fhhash += val;
	}

	proto_tree_add_uint(tree, hf_pvfs_fh_hash, tvb, offset, PVFS2_FH_LENGTH,
			fhhash);

	if (hash)
		*hash = fhhash;

	/* TODO: add file name snooping code here */

type_ready:
	dissect_fhandle_data_unknown(tvb, offset, tree);
}

static int
dissect_pvfs_fh(tvbuff_t *tvb, int offset, packet_info *pinfo,
		proto_tree *tree, const char *name, guint32 *hash)
{
	proto_tree* ftree;

	ftree = proto_tree_add_subtree(tree, tvb, offset, PVFS2_FH_LENGTH,
			ett_pvfs_fh, NULL, name);

	/* TODO: add fh to file name snooping code here */

	proto_tree_add_uint(ftree, hf_pvfs_fh_length, tvb, offset, 0,
			PVFS2_FH_LENGTH);

	dissect_fhandle_data(tvb, offset, pinfo, ftree, hash);

	offset += PVFS2_FH_LENGTH;

	return offset;
}

static int
dissect_pvfs_handle_extent(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo, guint32 nCount)
{
	proto_tree *extent_tree;

	extent_tree = proto_tree_add_subtree_format(tree, tvb, offset, 8,
			ett_pvfs_extent_item, NULL, "Item %d", nCount);

	/* first handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, extent_tree, "first handle",
			NULL);

	/* last handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, extent_tree, "last handle",
			NULL);

	return offset;
}

static int
dissect_pvfs_handle_extent_array(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	guint32 extent_count;
	guint32 nCount;
	proto_tree *extent_array_tree;

	/* extent count */
	extent_count = tvb_get_letohl(tvb, offset);

	extent_array_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4,
					ett_pvfs_extent_array_tree, NULL, "Handle Extent Array (count = %d)", extent_count);

	offset += 4;

	if (extent_count > 0)
	{
		/* Add extent array items */
		for (nCount = 0; nCount < extent_count; nCount++)
			offset = dissect_pvfs_handle_extent(tvb, extent_array_tree, offset,
					pinfo, nCount);
	}

	return offset;
}

static int
dissect_pvfs_time(tvbuff_t *tvb, proto_tree *tree, int offset,
		int hf_time, int hf_time_sec, int hf_time_nsec)
{
	guint32 seconds;
	guint32 nseconds;
	nstime_t ts;
	proto_item *time_item;
	proto_tree *time_tree;

	ts.secs = seconds = tvb_get_letohl(tvb, offset);
	ts.nsecs = nseconds = tvb_get_letohl(tvb, offset + 4);

	time_item = proto_tree_add_time(tree, hf_time, tvb, offset, 8, &ts);
	time_tree = proto_item_add_subtree(time_item, ett_pvfs_time);

	proto_tree_add_uint(time_tree, hf_time_sec, tvb, offset, 4, seconds);
	proto_tree_add_uint(time_tree, hf_time_nsec, tvb, offset + 4, 4, nseconds);

	offset += 8;
	return offset;
}

static
int dissect_pvfs_uint64(tvbuff_t *tvb, proto_tree *tree, int offset,
		int hfindex, guint64 *pvalue)
{
	guint64 val;

	val = tvb_get_letoh64(tvb, offset);
	proto_tree_add_uint64(tree, hfindex, tvb, offset, 8, val);

	if (pvalue)
		*pvalue = val;

	return offset + 8;
}

/* Taken from pvfs2-dist-simple-stripe.h */
#define PVFS_DIST_SIMPLE_STRIPE_NAME "simple_stripe"
#define PVFS_DIST_SIMPLE_STRIPE_NAME_SIZE 14

static int
dissect_pvfs_distribution(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	proto_item *dist_item;
	proto_tree *dist_tree;
	guint32 distlen;
	char *tmpstr;
	guint8 issimplestripe = 0;
	guint32 total_len;

	/* Get distribution name length */
	distlen = tvb_get_letohl(tvb, offset);

	/* Get distribution name */
	tmpstr = (char *) tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 4, distlen, ENC_ASCII);

	/* 'distlen' does not include the NULL terminator */
	total_len = roundup8(4 + distlen + 1);

	if (((distlen + 1) == PVFS_DIST_SIMPLE_STRIPE_NAME_SIZE) &&
			(g_ascii_strncasecmp(tmpstr, PVFS_DIST_SIMPLE_STRIPE_NAME,
					     distlen) == 0))
	{
		/* Parameter for 'simple_stripe' is 8 bytes */
		total_len += 8;

		issimplestripe = 1;
	}

	dist_item = proto_tree_add_string(tree, hf_pvfs_distribution,
			tvb, offset, total_len + 8, tmpstr);
	dist_tree = proto_item_add_subtree(dist_item, ett_pvfs_distribution);

	/* io_dist */
	offset = dissect_pvfs_string(tvb, dist_tree, hf_pvfs_io_dist, offset,
			NULL);

	/* TODO: only one distribution type is currently supported */
	if (issimplestripe)
		offset = dissect_pvfs_uint64(tvb, dist_tree, offset,
				hf_pvfs_strip_size, NULL);

	offset += 8;

	return offset;
}

static int
dissect_pvfs_meta_attr_dfiles(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	guint32 dfile_count, i;

	/* dfile_count */
	dfile_count = tvb_get_letohl(tvb, offset);
	proto_tree_add_uint(tree, hf_pvfs_dfile_count, tvb, offset, 4, dfile_count);

	offset += 4;

	for (i = 0; i < dfile_count; i++)
		offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs_object_attr(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	gint32 ds_type = 0;
	guint32 attrmask = 0;
	proto_tree *attr_tree;

	attr_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_pvfs_attr_tree, NULL, "Attributes");

	/* UID */
	proto_tree_add_item(attr_tree, hf_pvfs_uid, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* GID */
	proto_tree_add_item(attr_tree, hf_pvfs_gid, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* Permissions */
	proto_tree_add_item(attr_tree, hf_pvfs_permissions, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	offset += 4;

	/* atime */
	offset = dissect_pvfs_time(tvb, attr_tree, offset, hf_pvfs_atime,
			hf_pvfs_atime_sec, hf_pvfs_atime_nsec);

	/* mtime */
	offset = dissect_pvfs_time(tvb, attr_tree, offset, hf_pvfs_mtime,
			hf_pvfs_mtime_sec, hf_pvfs_mtime_nsec);

	/* ctime */
	offset = dissect_pvfs_time(tvb, attr_tree, offset, hf_pvfs_ctime,
			hf_pvfs_ctime_sec, hf_pvfs_ctime_nsec);

	/* attrmask */
	offset = dissect_pvfs2_attrmask(tvb, attr_tree, offset, &attrmask);

	/* objtype */
	offset = dissect_pvfs2_ds_type(tvb, attr_tree, offset, &ds_type);

	if (attrmask & PVFS_ATTR_META_DIST)
	{
		offset = dissect_pvfs_distribution(tvb, attr_tree, offset);

		offset = dissect_pvfs_meta_attr_dfiles(tvb, attr_tree, offset, pinfo);
	}
	else
	{
		if (attrmask & PVFS_ATTR_META_DFILES)
		{
			offset = dissect_pvfs_meta_attr_dfiles(tvb, attr_tree, offset, pinfo);
		}
		else
		{
			if (attrmask & PVFS_ATTR_DATA_SIZE)
			{
				offset = dissect_pvfs_uint64(tvb, attr_tree, offset, hf_pvfs_size,
						NULL);
			}
			else
			{
				if (attrmask & PVFS_ATTR_SYMLNK_TARGET)
				{
					/* target_path_len */
					proto_tree_add_item(attr_tree, hf_pvfs_target_path_len, tvb, offset, 4, ENC_LITTLE_ENDIAN);
					offset += 4;

					offset += 4;

					/* target_path */
					offset = dissect_pvfs_string(tvb, attr_tree, hf_pvfs_path,
							offset, NULL);
				}
				else
				{
					if (attrmask & PVFS_ATTR_DIR_DIRENT_COUNT)
					{
						offset = dissect_pvfs_uint64(tvb, attr_tree, offset,
								hf_pvfs_size, NULL);
					}
				}
			}
		}
	}

	return offset;
}

static int
dissect_pvfs_io_type(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	proto_tree_add_item(tree, hf_pvfs_io_type, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs_flowproto_type(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	proto_tree_add_item(tree, hf_pvfs_flowproto_type, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs_server_param(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	guint32 server_param;
	proto_item* ti;

	/* server_param */
	server_param = tvb_get_letohl(tvb, offset);
	proto_tree_add_uint(tree, hf_pvfs_server_param, tvb, offset, 4,
			server_param);
	offset += 4;

	switch (server_param)
	{
		case PVFS_SERV_PARAM_MODE:
			ti = proto_tree_add_item(tree, hf_pvfs_server_mode, tvb, offset, 4, ENC_LITTLE_ENDIAN);
			proto_item_set_len(ti, 8);
			break;

		case PVFS_SERV_PARAM_FSID_CHECK:
			proto_tree_add_item(tree, hf_pvfs_fs_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
			proto_tree_add_item(tree, hf_pvfs_unused, tvb, offset + 4, 4, ENC_LITTLE_ENDIAN);
			break;

		case PVFS_SERV_PARAM_ROOT_CHECK:
			offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);
			break;
	}

	offset += 8;

	return offset;
}

static int
dissect_pvfs_fs_id(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	proto_tree_add_item(tree, hf_pvfs_fs_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

/*
 * =======================================================================
 * Request handlers
 * =======================================================================
 */

static int
dissect_pvfs2_create_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* type */
	offset = dissect_pvfs2_ds_type(tvb, tree, offset, NULL);

	offset += 4;

	offset = dissect_pvfs_handle_extent_array(tvb, tree, offset, pinfo);

	return offset;
}

static int
dissect_pvfs2_remove_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	return offset;
}

static int
dissect_pvfs_pint_request(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	/* offset */
	proto_tree_add_item(tree, hf_pvfs_offset, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	/* TODO: num_eregs */
	proto_tree_add_item(tree, hf_pvfs_num_eregs, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* TODO: num_blocks */
	proto_tree_add_item(tree, hf_pvfs_num_blocks, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* TODO: stride */
	proto_tree_add_item(tree, hf_pvfs_stride, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	/* TODO: ub */
	proto_tree_add_item(tree, hf_pvfs_ub, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	/* TODO: lb */
	proto_tree_add_item(tree, hf_pvfs_lb, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	/* TODO: aggregate size */
	proto_tree_add_item(tree, hf_pvfs_aggregate_size, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	/* num_contig_chunks */
	proto_tree_add_item(tree, hf_pvfs_num_contig_chunks, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* depth */
	proto_tree_add_item(tree, hf_pvfs_depth, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* num_nested_req */
	proto_tree_add_item(tree, hf_pvfs_num_nested_req, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* committed */
	proto_tree_add_item(tree, hf_pvfs_committed, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* refcount */
	proto_tree_add_item(tree, hf_pvfs_refcount, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* documented */
	offset += 4;

	/* ereg */
	proto_tree_add_item(tree, hf_pvfs_ereg, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* sreg */
	proto_tree_add_item(tree, hf_pvfs_sreg, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs2_io_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* skip4 as per source code */
	offset += 4;

	/* io_type */
	offset = dissect_pvfs_io_type(tvb, tree, offset);

	/* flow_type */
	offset = dissect_pvfs_flowproto_type(tvb, tree, offset);

	/* server_nr */
	proto_tree_add_item(tree, hf_pvfs_server_nr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* server_ct */
	proto_tree_add_item(tree, hf_pvfs_server_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* Distribution */
	offset = dissect_pvfs_distribution(tvb, tree, offset);

	proto_tree_add_item(tree, hf_pvfs_numreq, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* */
	offset += 4;

	/*offset = */dissect_pvfs_pint_request(tvb, tree, offset);

	/* TODO: remove this!!! */
	offset = tvb_reported_length(tvb) - 16;

	/* offset */
	proto_tree_add_item(tree, hf_pvfs_offset, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	/* size */
	proto_tree_add_item(tree, hf_pvfs_size, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	return offset;
}

static int
dissect_pvfs2_getattr_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* attrmask */
	offset = dissect_pvfs2_attrmask(tvb, tree, offset, NULL);

	return offset;
}

static int
dissect_pvfs2_setattr_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* parent_ref: fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	offset = dissect_pvfs_object_attr(tvb, tree, offset, pinfo);

	return offset;
}

/* As per pvfs2-1.2.0/src/proto/pvfs2-req-proto.h */
static int
dissect_pvfs2_lookup_path_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* Path */
	offset = dissect_pvfs_string(tvb, tree, hf_pvfs_path, offset, NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	/* starting_handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* attribute mask */
	offset = dissect_pvfs2_attrmask(tvb, tree, offset, NULL);

	return offset;
}

static int
dissect_pvfs2_crdirent_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* Filename */
	offset = dissect_pvfs_string(tvb, tree, hf_pvfs_path, offset, NULL);

	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "file handle", NULL);

	/* parent_handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "parent handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	/* atime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_atime,
			hf_pvfs_atime_sec, hf_pvfs_atime_nsec);

	/* mtime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_mtime,
			hf_pvfs_mtime_sec, hf_pvfs_mtime_nsec);

	/* ctime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_ctime,
			hf_pvfs_ctime_sec, hf_pvfs_ctime_nsec);

	return offset;
}

/* TODO: incomplete */
static int
dissect_pvfs2_rmdirent_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* path */
	offset = dissect_pvfs_string(tvb, tree, hf_pvfs_path, offset, NULL);

	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	/* atime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_atime,
			hf_pvfs_atime_sec, hf_pvfs_atime_nsec);

	/* mtime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_mtime,
			hf_pvfs_mtime_sec, hf_pvfs_mtime_nsec);

	/* ctime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_ctime,
			hf_pvfs_ctime_sec, hf_pvfs_ctime_nsec);

	return offset;
}

static int
dissect_pvfs2_chdirent_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* path */
	offset = dissect_pvfs_string(tvb, tree, hf_pvfs_path, offset, NULL);

	/* New directory entry handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "new directory handle",
			NULL);

	/* Parent handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "parent handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* Parent atime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_parent_atime,
			hf_pvfs_parent_atime_sec, hf_pvfs_parent_atime_nsec);

	/* Parent mtime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_parent_mtime,
			hf_pvfs_parent_mtime_sec, hf_pvfs_parent_mtime_nsec);

	/* Parent ctime */
	offset = dissect_pvfs_time(tvb, tree, offset, hf_pvfs_parent_ctime,
			hf_pvfs_parent_ctime_sec, hf_pvfs_parent_ctime_nsec);

	return offset;
}

static int
dissect_pvfs2_truncate_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	/* size */
	proto_tree_add_item(tree, hf_pvfs_size, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	/* TODO: flags */
	proto_tree_add_item(tree, hf_pvfs_truncate_request_flags, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs2_mkdir_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	guint count, i;

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	/* attr */
	offset = dissect_pvfs_object_attr(tvb, tree, offset, pinfo);

	/* handle_extent_array */
	count = tvb_get_letohl(tvb, offset);
	offset += 4;

	for (i = 0; i < count; i++)
		offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs2_readdir_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* object_ref: handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* object_ref: fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* ds_position */
	proto_tree_add_item(tree, hf_pvfs_ds_position, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* dirent_limit */
	proto_tree_add_item(tree, hf_pvfs_dirent_limit, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs2_flush_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* flags */
	proto_tree_add_item(tree, hf_pvfs_flush_request_flags, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs2_mgmt_setparam_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* server_param */
	offset = dissect_pvfs_server_param(tvb, tree, offset, pinfo);

	return offset;
}

static int
dissect_pvfs2_statfs_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo _U_)
{
	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	return offset;
}

static int
dissect_pvfs2_mgmt_perf_mon_request(tvbuff_t *tvb _U_, proto_tree *tree _U_,
		int offset, packet_info *pinfo _U_)
{
	/* TODO: next_id */
	proto_tree_add_item(tree, hf_pvfs_next_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* TODO: count */
	proto_tree_add_item(tree, hf_pvfs_mgmt_perf_mon_request_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs2_mgmt_iterate_handles_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs2_mgmt_dspace_info_list_request(tvbuff_t *tvb,
		proto_tree *tree, int offset, packet_info *pinfo)
{
	guint32 handle_count, i;

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* handle count */
	handle_count = tvb_get_letohl(tvb, offset);
	offset += 4;

	for (i = 0; i < handle_count; i++)
	{
		/* handle */
		offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);
	}

	return offset;
}

static int
dissect_pvfs2_mgmt_event_mon_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo _U_)
{
	/* event_count */
	proto_tree_add_item(tree, hf_pvfs_mgmt_perf_mon_request_event_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs2_mgmt_remove_object_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* Handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	return offset;
}

static int
dissect_pvfs2_mgmt_remove_dirent_request(tvbuff_t *tvb,
		proto_tree *tree, int offset, packet_info *pinfo)
{
	/* Handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* */
	offset += 4;

	/* entry */
	offset = dissect_pvfs_string(tvb, tree, hf_pvfs_path, offset, NULL);

	return offset;
}

static int
dissect_pvfs2_mgmt_get_dirdata_handle_request(tvbuff_t *tvb,
		proto_tree *tree, int offset, packet_info *pinfo)
{
	/* Handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	return offset;
}

/* TODO: untested/incomplete */
static int
dissect_pvfs_ds_keyval(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	/* attribute key */
	offset = dissect_pvfs_string(tvb, tree, hf_pvfs_attribute_key, offset,
			NULL);

	/* attribute value */
	offset = dissect_pvfs_string(tvb, tree, hf_pvfs_attribute_value, offset,
			NULL);

	return offset;
}

/* TODO: incomplete/untested */
static int
dissect_ds_keyval_array(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	guint32 nKey, i;

	/* number of keys and vals */
	nKey = tvb_get_letohl(tvb, offset);
	offset += 4;

	for (i = 0; i < nKey; i++)
		offset = dissect_pvfs_ds_keyval(tvb, tree, offset);

	return offset;
}

/* TODO: incomplete/untested */
static int
dissect_pvfs2_geteattr_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	offset = dissect_ds_keyval_array(tvb, tree, offset);

	return offset;
}

/* TODO: incomplete/untested */
static int
dissect_pvfs2_seteattr_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	offset += 4;

	offset = dissect_ds_keyval_array(tvb, tree, offset);

	return offset;
}

/* TODO: untested */
static int
dissect_pvfs2_deleattr_request(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* key */
	offset = dissect_pvfs_ds_keyval(tvb, tree, offset);

	return offset;
}

static void
pvfc_fmt_release_num(gchar *result, guint32 release_nr)
{
	g_snprintf( result, ITEM_LABEL_LENGTH, "%d (%d.%d.%d)",
			release_nr,
			release_nr / 10000,
			(release_nr % 10000) / 100,
			(release_nr % 10000) % 100);
}

static int
dissect_pvfs2_common_header(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	/* PVFS release number */
	proto_tree_add_item(tree, hf_pvfs_release_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* wire encoding type */
	proto_tree_add_item(tree, hf_pvfs_encoding, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* server op */
	proto_tree_add_item(tree, hf_pvfs_server_op, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	return offset;
}

static int
dissect_pvfs2_request(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo, guint32 server_op)
{
	/* context_id */
	proto_tree_add_item(tree, hf_pvfs_context_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* credentials */
	offset = dissect_pvfs_credentials(tvb, tree, offset);

	switch (server_op)
	{
		case  PVFS_SERV_CREATE:
			offset = dissect_pvfs2_create_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_REMOVE:
			offset = dissect_pvfs2_remove_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_IO:
			offset = dissect_pvfs2_io_request(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_GETATTR:
			offset = dissect_pvfs2_getattr_request(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_SETATTR:
			offset = dissect_pvfs2_setattr_request(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_LOOKUP_PATH:
			offset = dissect_pvfs2_lookup_path_request(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_CRDIRENT:
			offset = dissect_pvfs2_crdirent_request(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_RMDIRENT:
			offset = dissect_pvfs2_rmdirent_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_CHDIRENT:
			offset = dissect_pvfs2_chdirent_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_TRUNCATE:
			offset = dissect_pvfs2_truncate_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_MKDIR:
			offset = dissect_pvfs2_mkdir_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_READDIR:
			offset = dissect_pvfs2_readdir_request(tvb, tree, offset, pinfo);
			break;

#if 0
		case PVFS_SERV_GETCONFIG:
			/* No parameters in request */
			break;
#endif

#if 0
		case  PVFS_SERV_WRITE_COMPLETION:
			/* No parameters in request */
			break;
#endif

		case  PVFS_SERV_FLUSH:
			offset = dissect_pvfs2_flush_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_MGMT_SETPARAM:
			offset = dissect_pvfs2_mgmt_setparam_request(tvb, tree, offset,
					pinfo);
			break;

#if 0
		case  PVFS_SERV_MGMT_NOOP:
			/* No parameters in request */
			break;
#endif

		case  PVFS_SERV_STATFS:
			offset = dissect_pvfs2_statfs_request(tvb, tree, offset, pinfo);
			break;

#if 0
		case  PVFS_SERV_PERF_UPDATE:
			/* No parameters in request */
			break;
#endif

		case  PVFS_SERV_MGMT_PERF_MON:
			offset = dissect_pvfs2_mgmt_perf_mon_request(tvb, tree, offset,
					pinfo);
			break;

		case  PVFS_SERV_MGMT_ITERATE_HANDLES:
			offset = dissect_pvfs2_mgmt_iterate_handles_request(tvb, tree,
					offset, pinfo);
			break;

		case  PVFS_SERV_MGMT_DSPACE_INFO_LIST:
			offset = dissect_pvfs2_mgmt_dspace_info_list_request(tvb, tree,
					offset, pinfo);
			break;

		case  PVFS_SERV_MGMT_EVENT_MON:
			offset = dissect_pvfs2_mgmt_event_mon_request(tvb, tree, offset,
					pinfo);
			break;

		case  PVFS_SERV_MGMT_REMOVE_OBJECT:
			offset = dissect_pvfs2_mgmt_remove_object_request(tvb, tree, offset,
					pinfo);
			break;

		case  PVFS_SERV_MGMT_REMOVE_DIRENT:
			offset = dissect_pvfs2_mgmt_remove_dirent_request(tvb, tree, offset,
					pinfo);
			break;

		case  PVFS_SERV_MGMT_GET_DIRDATA_HANDLE:
			offset = dissect_pvfs2_mgmt_get_dirdata_handle_request(tvb, tree,
					offset, pinfo);
			break;

#if 0
		case  PVFS_SERV_JOB_TIMER:
			/* No parameters in request */
			break;
#endif

		case  PVFS_SERV_PROTO_ERROR:
			/* TODO: is this necessary? */
			break;

		case  PVFS_SERV_GETEATTR:
			offset = dissect_pvfs2_geteattr_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_SETEATTR:
			offset = dissect_pvfs2_seteattr_request(tvb, tree, offset, pinfo);
			break;

		case  PVFS_SERV_DELEATTR:
			offset = dissect_pvfs2_deleattr_request(tvb, tree, offset, pinfo);
			break;

		default:
			/* TODO: what should we do here? */
			break;
	}

	return offset;
}

/*
 * =======================================================================
 * Response handlers
 * =======================================================================
 */

static int
dissect_pvfs2_create_response(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* Handle */
	return dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);
}

static int
dissect_pvfs2_io_response(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	return dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_size, NULL);
}

static int
dissect_pvfs2_getattr_response(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	offset = dissect_pvfs_object_attr(tvb, tree, offset, pinfo);

	return offset;
}

static int
dissect_pvfs2_lookup_path_response(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	guint32 nCount = 0;
	guint32 handle_count = 0;
	guint32 attr_count = 0;
	proto_tree *attr_tree;

	offset += 4;

	/* handle_count */
	handle_count = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_lookup_path_response_handle_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* TODO: add bounds checking */
	for (nCount = 0; nCount < handle_count; nCount++)
		offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	offset += 4;

	/* array of attributes */
	attr_count = tvb_get_letohl(tvb, offset);

	attr_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4,
				ett_pvfs_attr, NULL, "Attribute array (total items: %d)", attr_count);

	offset += 4;

	/* Array of attributes */
	for (nCount = 0; nCount < attr_count; nCount++)
		offset = dissect_pvfs_object_attr(tvb, attr_tree, offset, pinfo);

	return offset;
}

static int
dissect_pvfs2_rmdirent_response(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* Handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs2_chdirent_response(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* Handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs2_mkdir_response(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	/* Handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs2_readdir_response(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	guint32 dirent_count = 0;
	guint32 nCount = 0;

	/* ds_position */
	proto_tree_add_item(tree, hf_pvfs_ds_position, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	offset += 4;

	/* directory_version */
	proto_tree_add_item(tree, hf_pvfs_directory_version, tvb, offset, 8, ENC_LITTLE_ENDIAN);
	offset += 8;

	offset += 4;

	/* dirent_count */
	dirent_count = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_dirent_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	for (nCount = 0; nCount < dirent_count; nCount++)
	{
		offset = dissect_pvfs_string(tvb, tree, hf_pvfs_path, offset, NULL);
		offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);
	}

	return offset;
}

/*
 * TODO: this code needs work!  Not finished yet!
 */
static int
dissect_pvfs2_getconfig_response(tvbuff_t *tvb, proto_tree *parent_tree,
		int offset, packet_info *pinfo)
{
	guint32 i;
	guint32 total_bytes = 0, total_config_bytes = 0, total_lines = 0;
	guint32 bytes_processed = 0;
	guint32 length_remaining = 0;
	const char *ptr = NULL;
	proto_tree *tree, *config_tree = NULL;
	/*guint8 truncated = 0;*/

	tree = proto_tree_add_subtree(parent_tree, tvb, offset, 12,
				ett_pvfs_server_config, NULL, "Server Config");

	/* Total number of bytes in server config (incl. entry count) */
	total_bytes = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_getconfig_response_total_bytes, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* There must be at least 4 bytes of data returned to determine the
	 * size of the server config data
	 */
	if (total_bytes < 4)
	{
		/* Server config not returned, bail out */
		return offset;
	}

	/* Number of entries in server config */
	total_lines = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_getconfig_response_lines, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* Number of bytes in server config */
	total_config_bytes = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_getconfig_response_config_bytes, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* Get pointer to server config data */
	ptr = tvb_get_ptr(tvb, offset, total_config_bytes);

	/* Check if all data is available */
	length_remaining = tvb_captured_length_remaining(tvb, offset);

	if (length_remaining < total_config_bytes)
	{
		total_config_bytes = length_remaining;

		/*truncated = 1;*/
	}

	bytes_processed = 0;

	for (i = 0; i < total_lines; i++)
	{
		guint8 entry[256], *pentry = entry, *tmp_entry = NULL;
		guint32 entry_length = 0, tmp_entry_length = 0;
		guint32 bufsiz = sizeof(entry);

		while ((*ptr != '\n') && (*ptr != '\0') &&
				(bytes_processed < total_config_bytes) &&
				(entry_length < bufsiz))
		{
			*pentry++ = *ptr++;

			bytes_processed++;
			entry_length++;
		}

		if ((entry_length == bufsiz) &&
				((entry[entry_length - 1] != '\n') &&
				 (entry[entry_length - 1] != '\0')))
		{
			/*
			 * Single line of config data doesn't fit into provided buffer,
			 * config data is malformed.
			 */

			break;
		}

		if (bytes_processed == total_config_bytes)
		{
			/* Oops...  ran out of data before we could complete the entry */
			break;
		}

		*pentry= '\0';

		tmp_entry = entry;
		tmp_entry_length = entry_length;

		/* Remove all whitespace from front of entry */
		while ((tmp_entry_length > 0) && (!g_ascii_isalnum(*tmp_entry)) &&
				(*tmp_entry != '<'))
		{
			tmp_entry++;
			tmp_entry_length--;
		}

		if (tmp_entry[0] == '<')
		{
 			if (tmp_entry[tmp_entry_length - 1] == '>')
			{
				/* Token */
				if (tmp_entry[1] != '/')
				{
					/* Opening token, create new tree root */
					config_tree = proto_tree_add_subtree(tree, tvb, offset,
							tmp_entry_length, ett_pvfs_server_config_branch, NULL, tmp_entry);
				}
				else
				{
					/* Closing token */
					config_tree = NULL;
				}
			}
			else
			{
				/* Malformed token */
				break;
			}
		}
		else
		{
			/* Insert items into the root config tree if there's no subtree
			 * defined.
			 */
			if (config_tree == NULL)
				config_tree = tree;

			if (tmp_entry_length > 0)
			{
				proto_tree_add_string_format(config_tree, hf_pvfs_getconfig_response_entry, tvb, offset, tmp_entry_length,
						tmp_entry, "%s", tmp_entry);
			}
		}

		offset += entry_length + 1;

		ptr++;
		bytes_processed++;
	}

	if (bytes_processed < total_config_bytes)
	{
		/* We ran out of server config data */
		proto_tree_add_expert(config_tree, pinfo, &ei_pvfs_malformed, tvb, offset, -1);
	}

	return offset;
}

static int
dissect_pvfs2_write_completion_response(tvbuff_t *tvb, proto_tree *tree,
		int offset)
{
	/* size */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_total_completed,
			NULL);

	return offset;
}

static int
dissect_pvfs2_mgmt_setparam_response(tvbuff_t *tvb, proto_tree *tree,
		int offset)
{
	/* old_value */
	proto_tree_add_item(tree, hf_pvfs_prev_value, tvb, offset, 8, ENC_LITTLE_ENDIAN);

	offset += 8;

	return offset;
}

static int
dissect_pvfs2_statfs_response(tvbuff_t *tvb, proto_tree *tree, int offset)
{
	offset += 4;

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	/* bytes_available */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_bytes_available,
			NULL);

	/* bytes_total */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_bytes_total,
			NULL);

	/* RAM bytes total */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_ram_bytes_total,
			NULL);

	/* RAM bytes free */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_ram_bytes_free,
			NULL);

	/* load average (1s) */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_load_average_1s,
			NULL);

	/* load average (5s) */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_load_average_5s,
			NULL);

	/* load average (15s) */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_load_average_15s,
			NULL);

	/* uptime (seconds) */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_uptime_seconds,
			NULL);

	/* handles_available_count */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_handles_available,
			NULL);

	/* handles_total_count */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_handles_total,
			NULL);

	return offset;
}

static int
dissect_pvfs_mgmt_perf_stat(tvbuff_t *tvb, proto_tree *tree, int offset,
		int nItem)
{
	proto_tree *stat_tree;

	stat_tree = proto_tree_add_subtree_format(tree, tvb, offset, 48,
				ett_pvfs_mgmt_perf_stat, NULL, "Stat Array - Element %d", nItem);

	/* TODO: valid_flag */
	proto_tree_add_item(stat_tree, hf_pvfs_mgmt_perf_stat_valid_flag, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* TODO: id */
	proto_tree_add_item(stat_tree, hf_pvfs_mgmt_perf_stat_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	offset = dissect_pvfs_uint64(tvb, stat_tree, offset, hf_pvfs_start_time_ms,
			NULL);
	offset = dissect_pvfs_uint64(tvb, stat_tree, offset, hf_pvfs_bytes_written,
			NULL);
	offset = dissect_pvfs_uint64(tvb, stat_tree, offset, hf_pvfs_bytes_read,
			NULL);
	offset = dissect_pvfs_uint64(tvb, stat_tree, offset, hf_pvfs_metadata_write,
			NULL);
	offset = dissect_pvfs_uint64(tvb, stat_tree, offset, hf_pvfs_metadata_read,
			NULL);

	return offset;
}

static int
dissect_pvfs2_mgmt_perf_mon_response(tvbuff_t *tvb, proto_tree *tree,
		int offset)
{
	guint32 perf_array_count, i;

	/* TODO: suggested_next_id */
	proto_tree_add_item(tree, hf_pvfs_mgmt_perf_mon_response_suggested_next_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	offset += 4;

	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_end_time_ms, NULL);
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_cur_time_ms, NULL);

	offset += 4;

	/* TODO: perf_array_count */
	perf_array_count = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_mgmt_perf_mon_response_perf_array_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	for (i = 0; i < perf_array_count; i++)
		offset = dissect_pvfs_mgmt_perf_stat(tvb, tree, offset, i);

	return offset;
}

static int
dissect_pvfs2_mgmt_iterate_handles_response(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	guint32 handle_count, i;

	/* ds_position */
	proto_tree_add_item(tree, hf_pvfs_mgmt_iterate_handles_response_ds_position, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* handle_count */
	handle_count = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_mgmt_iterate_handles_response_handle_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* TODO: this could be improved */
	for (i = 0; i < handle_count; i++)
		offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs2_mgmt_dspace_info(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo)
{
	offset = dissect_pvfs2_error(tvb, tree, offset, pinfo);
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);
	offset = dissect_pvfs2_ds_type(tvb, tree, offset, NULL);
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_b_size,
			NULL);
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_k_size,
			NULL);
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

static int
dissect_pvfs2_mgmt_dspace_info_list_response(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	guint32 dspace_info_count, i;
	proto_tree *arr_tree = NULL;

	offset += 4;

	/* dspace_info_count */
	dspace_info_count = tvb_get_letohl(tvb, offset);
	proto_tree_add_item(tree, hf_pvfs_mgmt_dspace_info_list_response_dspace_info_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);

	if ((dspace_info_count > 0) && (tree))
	{
		arr_tree = proto_tree_add_subtree_format(tree, tvb, offset,
				dspace_info_count * 40, ett_pvfs_mgmt_dspace_info, NULL, "dspace_info Array (%d items)",
				dspace_info_count);
	}

	for (i = 0; i < dspace_info_count; i++)
		offset = dissect_pvfs2_mgmt_dspace_info(tvb, arr_tree, offset, pinfo);

	return offset;
}

static int
dissect_pvfs2_mgmt_event_mon_response(tvbuff_t *tvb, proto_tree *tree,
		int offset)
{
	/* api */
	proto_tree_add_item(tree, hf_pvfs_mgmt_event_mon_response_api, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* operation */
	proto_tree_add_item(tree, hf_pvfs_mgmt_event_mon_response_operation, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* value */
	proto_tree_add_item(tree, hf_pvfs_mgmt_event_mon_response_value, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* id */
	offset = dissect_pvfs_uint64(tvb, tree, offset, hf_pvfs_id_gen_t,
			NULL);

	/* flags */
	proto_tree_add_item(tree, hf_pvfs_mgmt_event_mon_response_flags, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* tv_sec */
	proto_tree_add_item(tree, hf_pvfs_mgmt_event_mon_response_tv_sec, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* tv_usec */
	proto_tree_add_item(tree, hf_pvfs_mgmt_event_mon_response_tv_usec, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	offset += 4;

	return offset;
}

static int
dissect_pvfs2_mgmt_remove_object_response(tvbuff_t *tvb, proto_tree *tree,
		int offset, packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	/* fs_id */
	offset = dissect_pvfs_fs_id(tvb, tree, offset);

	return offset;
}

static int
dissect_pvfs2_mgmt_get_dirdata_handle_response(tvbuff_t *tvb,
		proto_tree *tree, int offset, packet_info *pinfo)
{
	/* handle */
	offset = dissect_pvfs_fh(tvb, offset, pinfo, tree, "handle", NULL);

	return offset;
}

/* TODO: untested */
static int
dissect_pvfs2_geteattr_response(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo _U_)
{
	offset += 4;

	/* Dissect nKey & ds_keyval array */
	offset = dissect_ds_keyval_array(tvb, tree, offset);

	return offset;
}

static int
dissect_pvfs2_response(tvbuff_t *tvb, proto_tree *tree, int offset,
		packet_info *pinfo, guint32 server_op)
{
	/* error code */
	offset = dissect_pvfs2_error(tvb, tree, offset, pinfo);

	switch (server_op)
	{
		case PVFS_SERV_CREATE:
			offset = dissect_pvfs2_create_response(tvb, tree, offset, pinfo);
			break;

#if 0
		case PVFS_SERV_REMOVE:
			/* No result data */
			break;
#endif

		case PVFS_SERV_IO:
			offset = dissect_pvfs2_io_response(tvb, tree, offset);
			break;

		case PVFS_SERV_GETATTR:
			offset = dissect_pvfs2_getattr_response(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_SETATTR:
			/* No result data */
			break;

		case PVFS_SERV_LOOKUP_PATH:
			offset = dissect_pvfs2_lookup_path_response(tvb, tree, offset, pinfo);
			break;

#if 0
		case PVFS_SERV_CRDIRENT:
			/* No result data */
			break;
#endif

		case PVFS_SERV_RMDIRENT:
			offset = dissect_pvfs2_rmdirent_response(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_CHDIRENT:
			offset = dissect_pvfs2_chdirent_response(tvb, tree, offset, pinfo);
			break;

#if 0
		case PVFS_SERV_TRUNCATE:
			/* No result data */
			break;
#endif

		case PVFS_SERV_MKDIR:
			offset = dissect_pvfs2_mkdir_response(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_READDIR:
			offset = dissect_pvfs2_readdir_response(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_GETCONFIG:
			offset = dissect_pvfs2_getconfig_response(tvb, tree, offset, pinfo);
			break;

		case PVFS_SERV_WRITE_COMPLETION:
			offset = dissect_pvfs2_write_completion_response(tvb, tree, offset);
			break;

#if 0
		case PVFS_SERV_FLUSH:
			/* No result data */
			break;
#endif

		case PVFS_SERV_MGMT_SETPARAM:
			offset = dissect_pvfs2_mgmt_setparam_response(tvb, tree, offset);
			break;

#if 0
		case PVFS_SERV_MGMT_NOOP:
			/* No result data */
			break;
#endif

		case PVFS_SERV_STATFS:
			offset = dissect_pvfs2_statfs_response(tvb, tree, offset);
			break;

#if 0
		case PVFS_SERV_PERF_UPDATE:
			/* No result data */
			break;
#endif

		case PVFS_SERV_MGMT_PERF_MON:
			offset = dissect_pvfs2_mgmt_perf_mon_response(tvb, tree, offset);
			break;

		case PVFS_SERV_MGMT_ITERATE_HANDLES:
			offset = dissect_pvfs2_mgmt_iterate_handles_response(tvb, tree,
					offset, pinfo);
			break;

		case PVFS_SERV_MGMT_DSPACE_INFO_LIST:
			offset = dissect_pvfs2_mgmt_dspace_info_list_response(tvb, tree,
					offset, pinfo);
			break;

		case PVFS_SERV_MGMT_EVENT_MON:
			offset = dissect_pvfs2_mgmt_event_mon_response(tvb, tree, offset);
			break;

		case PVFS_SERV_MGMT_REMOVE_OBJECT:
			offset = dissect_pvfs2_mgmt_remove_object_response(tvb, tree, offset,
					pinfo);
			break;

#if 0
		case PVFS_SERV_MGMT_REMOVE_DIRENT:
			/* No result data */
			break;
#endif

		case PVFS_SERV_MGMT_GET_DIRDATA_HANDLE:
			offset = dissect_pvfs2_mgmt_get_dirdata_handle_response(tvb, tree,
					offset, pinfo);
			break;

#if 0
		case PVFS_SERV_JOB_TIMER:
			/* No result data */
			break;
#endif

		case PVFS_SERV_PROTO_ERROR:
			/* No result data */
			break;

			/* TODO: untested */
		case PVFS_SERV_GETEATTR:
			offset = dissect_pvfs2_geteattr_response(tvb, tree, offset, pinfo);
			break;

#if 0
		case PVFS_SERV_SETEATTR:
			/* No result data */
			break;
#endif

#if 0
		case PVFS_SERV_DELEATTR:
			/* No result data */
			break;
#endif

		default:
			/* TODO: what do we do here? */
			break;
	}

	return offset;
}

static wmem_map_t *pvfs2_io_tracking_value_table = NULL;

typedef struct pvfs2_io_tracking_key
{
	guint64 tag;
} pvfs2_io_tracking_key_t;

typedef struct pvfs2_io_tracking_value
{
	guint32 request_frame_num;
	guint32 response_frame_num;
	guint32 flow_frame_num;

} pvfs2_io_tracking_value_t;

static gint
pvfs2_io_tracking_equal(gconstpointer k1, gconstpointer k2)
{
	const pvfs2_io_tracking_key_t *key1 = (const pvfs2_io_tracking_key_t *) k1;
	const pvfs2_io_tracking_key_t *key2 = (const pvfs2_io_tracking_key_t *) k2;

	return (key1->tag == key2->tag);
}

static guint
pvfs2_io_tracking_hash(gconstpointer k)
{
	const pvfs2_io_tracking_key_t *key = (const pvfs2_io_tracking_key_t *) k;

	return (guint) ((key->tag >> 32) ^ ((guint32) key->tag));
}

static pvfs2_io_tracking_value_t *
pvfs2_io_tracking_new_with_tag(guint64 tag, guint32 num)
{
	pvfs2_io_tracking_value_t *value;
	pvfs2_io_tracking_key_t *newkey;

	newkey = wmem_new0(wmem_file_scope(), pvfs2_io_tracking_key_t);
	newkey->tag = tag;

	value = wmem_new0(wmem_file_scope(), pvfs2_io_tracking_value_t);

	wmem_map_insert(pvfs2_io_tracking_value_table, newkey, value);

	value->request_frame_num = num;

	return value;
}

static gboolean
dissect_pvfs_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
		gboolean dissect_other_as_continuation _U_)
{
	guint32 mode = 0;
	proto_item *item;
	proto_tree *pvfs_tree = NULL, *pvfs_htree = NULL;
	int offset = 0;
	guint64 tag;
	guint32 server_op;
	pvfs2_io_tracking_value_t *val = NULL;

	col_set_str(pinfo->cinfo, COL_PROTOCOL, "PVFS");

	col_clear(pinfo->cinfo, COL_INFO);

	item = proto_tree_add_item(parent_tree, proto_pvfs, tvb, 0, -1, ENC_NA);
	pvfs_tree = proto_item_add_subtree(item, ett_pvfs);

	proto_tree_add_item(pvfs_tree, hf_pvfs_version2, tvb, 0, -1, ENC_NA);

	/* PVFS packet header is 24 bytes */
	pvfs_htree = proto_tree_add_subtree(pvfs_tree, tvb, 0, BMI_HEADER_SIZE,
			ett_pvfs_hdr, NULL, "BMI Header");

	/* Magic number */
	proto_tree_add_item(pvfs_htree, hf_pvfs_magic_nr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
	offset += 4;

	/* TCP message mode (32-bit) */
	mode = tvb_get_letohl(tvb, offset);
	proto_tree_add_uint(pvfs_htree, hf_pvfs_mode, tvb, offset, 4, mode);
	offset += 4;

	/* tag (64-bit) */
	offset = dissect_pvfs_uint64(tvb, pvfs_htree, offset, hf_pvfs_tag, &tag);

	/* size (64-bit) */
	offset = dissect_pvfs_uint64(tvb, pvfs_htree, offset, hf_pvfs_size, NULL);

	/* Lookahead to get server_op (invalid if frame contains flow data) */
	server_op = tvb_get_letohl(tvb, offset + 8);

	if (mode == TCP_MODE_UNEXP)
	{
		/* Add entry to tracking table for PVFS_SERV_IO request */
		if ((server_op == PVFS_SERV_IO) && !pinfo->fd->flags.visited)
			val = pvfs2_io_tracking_new_with_tag(tag, pinfo->num);
	}
	else
	{
		pvfs2_io_tracking_key_t key;

		memset(&key, 0, sizeof(key));
		key.tag = tag;

		val = (pvfs2_io_tracking_value_t *)wmem_map_lookup(pvfs2_io_tracking_value_table, &key);

		/* If this frame contains a known PVFS_SERV_IO tag, track it */
		if (val && !pinfo->fd->flags.visited)
		{
			/* If response HAS NOT been seen, mark this frame as response */
			if (val->response_frame_num == 0)
				val->response_frame_num = pinfo->num;
			else
			{
				/* If response HAS been seen, this frame is flow data */
				if (val->flow_frame_num == 0)
					val->flow_frame_num = pinfo->num;
			}
		}
	}

	if (val && (val->flow_frame_num == pinfo->num))
	{
		/* This frame is marked as being flow data */
		col_set_str(pinfo->cinfo, COL_INFO, "PVFS flow data");

		proto_tree_add_item(pvfs_tree, hf_pvfs_flow_data, tvb, offset, -1, ENC_NA);

		return TRUE;
	}

	/* Extract common part of packet found in requests and responses */
	offset = dissect_pvfs2_common_header(tvb, pvfs_htree, offset);

	/* Update column info display */
	col_add_str(pinfo->cinfo, COL_INFO,
			val_to_str(server_op, names_pvfs_server_op, "%u (unknown)"));

	col_append_str(pinfo->cinfo, COL_INFO,
			(mode == TCP_MODE_UNEXP)? " (request)": " (response)");

	/* TODO: handle all modes */
	if (mode == TCP_MODE_UNEXP)
	{
		/* Request */
		/*offset = */dissect_pvfs2_request(tvb, pvfs_tree, offset, pinfo, server_op);
	}
	else
	{
		/* TODO: re-examine this! */
#if 0
		if (mode == TCP_MODE_REND)
		{
			/*
			 * TODO: move this code outside so it's common for requests and
			 * responses
			 */

			col_set_str(pinfo->cinfo, COL_INFO, "PVFS2 DATA (request)");
		}
		else
#endif
		{
			/* Response */
			/*offset = */dissect_pvfs2_response(tvb, pvfs_tree, offset, pinfo,
					server_op);
		}
	}

	return TRUE;
}

/* Register the protocol with Wireshark */
void
proto_register_pvfs(void)
{
	static hf_register_info hf[] = {
		{ &hf_pvfs_magic_nr,
			{ "Magic Number", "pvfs.magic_nr", FT_UINT32, BASE_HEX,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_uid,
			{ "UID", "pvfs.uid", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_gid,
			{ "GID", "pvfs.gid", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mode,
			{ "Mode", "pvfs.mode", FT_UINT32, BASE_DEC,
				VALS(names_pvfs_mode), 0, NULL, HFILL }},

		{ &hf_pvfs_tag,
			{ "Tag", "pvfs.tag", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_size,
			{ "Size", "pvfs.size", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_release_number,
			{ "Release Number", "pvfs.release_number", FT_UINT32, BASE_CUSTOM,
				CF_FUNC(pvfc_fmt_release_num), 0, NULL, HFILL }},

		{ &hf_pvfs_encoding,
			{ "Encoding", "pvfs.encoding", FT_UINT32, BASE_DEC,
				VALS(names_pvfs_encoding), 0, NULL, HFILL }},

		{ &hf_pvfs_server_op,
			{ "Server Operation", "pvfs.server_op", FT_UINT32, BASE_DEC,
				VALS(names_pvfs_server_op), 0, NULL, HFILL }},

#if 0
		{ &hf_pvfs_handle,
			{ "Handle", "pvfs.handle", FT_BYTES, BASE_NONE,
				NULL, 0, NULL, HFILL }},
#endif

		{ &hf_pvfs_fs_id,
			{ "fs_id", "pvfs.fs_id", FT_UINT32, BASE_HEX,
				NULL, 0, "File System ID", HFILL }},

		{ &hf_pvfs_attrmask,
			{ "Attribute Mask", "pvfs.attrmask", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_attr,
			{ "attr", "pvfs.attribute", FT_UINT32, BASE_HEX,
				VALS(names_pvfs_attr), 0, "Attribute", HFILL }},

		{ &hf_pvfs_ds_type,
			{ "ds_type", "pvfs.ds_type", FT_UINT32, BASE_HEX,
				VALS(names_pvfs_ds_type), 0, "Type", HFILL }},

		{ &hf_pvfs_error,
			{ "Result", "pvfs.error", FT_UINT32, BASE_HEX,
				VALS(names_pvfs_error), 0, NULL, HFILL }},

		{ &hf_pvfs_atime,
			{ "atime", "pvfs.atime", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
				NULL, 0, "Access Time", HFILL }},

		{ &hf_pvfs_atime_sec,
			{ "seconds", "pvfs.atime.sec", FT_UINT32, BASE_DEC,
				NULL, 0, "Access Time (seconds)", HFILL }},

		{ &hf_pvfs_atime_nsec,
			{ "microseconds", "pvfs.atime.usec", FT_UINT32, BASE_DEC,
				NULL, 0, "Access Time (microseconds)", HFILL }},

		{ &hf_pvfs_mtime,
			{ "mtime", "pvfs.mtime", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
				NULL, 0, "Modify Time", HFILL }},

		{ &hf_pvfs_mtime_sec,
			{ "seconds", "pvfs.mtime.sec", FT_UINT32, BASE_DEC,
				NULL, 0, "Modify Time (seconds)", HFILL }},

		{ &hf_pvfs_mtime_nsec,
			{ "microseconds", "pvfs.mtime.usec", FT_UINT32, BASE_DEC,
				NULL, 0, "Modify Time (microseconds)", HFILL }},

		{ &hf_pvfs_ctime,
			{ "ctime", "pvfs.ctime", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
				NULL, 0, "Creation Time", HFILL }},

		{ &hf_pvfs_ctime_sec,
			{ "seconds", "pvfs.ctime.sec", FT_UINT32, BASE_DEC,
				NULL, 0, "Creation Time (seconds)", HFILL }},

		{ &hf_pvfs_ctime_nsec,
			{ "microseconds", "pvfs.ctime.usec", FT_UINT32, BASE_DEC,
				NULL, 0, "Creation Time (microseconds)", HFILL }},

		{ &hf_pvfs_parent_atime,
			{ "Parent atime", "pvfs.parent_atime", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
				NULL, 0, "Access Time", HFILL }},

		{ &hf_pvfs_parent_atime_sec,
			{ "seconds", "pvfs.parent_atime.sec", FT_UINT32, BASE_DEC,
				NULL, 0, "Access Time (seconds)", HFILL }},

		{ &hf_pvfs_parent_atime_nsec,
			{ "microseconds", "pvfs.parent_atime.usec", FT_UINT32, BASE_DEC,
				NULL, 0, "Access Time (microseconds)", HFILL }},

		{ &hf_pvfs_parent_mtime,
			{ "Parent mtime", "pvfs.parent_mtime", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
				NULL, 0, "Modify Time", HFILL }},

		{ &hf_pvfs_parent_mtime_sec,
			{ "seconds", "pvfs.parent_mtime.sec", FT_UINT32, BASE_DEC,
				NULL, 0, "Modify Time (seconds)", HFILL }},

		{ &hf_pvfs_parent_mtime_nsec,
			{ "microseconds", "pvfs.parent_mtime.usec", FT_UINT32, BASE_DEC,
				NULL, 0, "Modify Time (microseconds)", HFILL }},

		{ &hf_pvfs_parent_ctime,
			{ "Parent ctime", "pvfs.parent_ctime", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
				NULL, 0, "Creation Time", HFILL }},

		{ &hf_pvfs_parent_ctime_sec,
			{ "seconds", "pvfs.parent_ctime.sec", FT_UINT32, BASE_DEC,
				NULL, 0, "Creation Time (seconds)", HFILL }},

		{ &hf_pvfs_parent_ctime_nsec,
			{ "microseconds", "pvfs.parent_ctime.usec", FT_UINT32, BASE_DEC,
				NULL, 0, "Creation Time (microseconds)", HFILL }},

		{ &hf_pvfs_dfile_count,
			{ "dfile_count", "pvfs.dfile_count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_distribution,
			{ "Distribution", "pvfs.distribution", FT_STRING, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_dirent_count,
			{ "Dir Entry Count", "pvfs.dirent_count", FT_UINT32, BASE_DEC,
				NULL, 0, "Directory Entry Count", HFILL }},

		{ &hf_pvfs_directory_version,
			{ "Directory Version", "pvfs.directory_version", FT_UINT64, BASE_HEX,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_path,
			{ "Path", "pvfs.path", FT_STRING, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_total_completed,
			{ "Bytes Completed", "pvfs.bytes_completed", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_io_dist,
			 { "Name", "pvfs.distribution.name", FT_STRING, BASE_NONE,
				 NULL, 0, "Distribution Name", HFILL }},

		{ &hf_pvfs_aggregate_size,
			{ "Aggregate Size", "pvfs.aggregate_size", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_io_type,
			{ "I/O Type", "pvfs.io_type", FT_UINT32, BASE_DEC,
				VALS(names_pvfs_io_type), 0, NULL, HFILL }},

		{ &hf_pvfs_flowproto_type,
			{ "Flow Protocol Type", "pvfs.flowproto_type", FT_UINT32, BASE_DEC,
				VALS(names_pvfs_flowproto_type), 0, NULL, HFILL }},

		{ &hf_pvfs_server_param,
			{ "Server Parameter", "pvfs.server_param", FT_UINT32, BASE_DEC,
				VALS(names_pvfs_server_param), 0, NULL, HFILL }},

		{ &hf_pvfs_prev_value,
			{ "Previous Value", "pvfs.prev_value", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

#if 0
		{ &hf_pvfs_ram_free_bytes,
			{ "RAM Free Bytes", "pvfs.ram.free_bytes", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},
#endif

		{ &hf_pvfs_bytes_available,
			{ "Bytes Available", "pvfs.bytes_available", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_bytes_total,
			{ "Bytes Total", "pvfs.bytes_total", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_ram_bytes_total,
			{ "RAM Bytes Total", "pvfs.ram_bytes_total", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_ram_bytes_free,
			{ "RAM Bytes Free", "pvfs.ram_bytes_free", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_load_average_1s,
			{ "Load Average (1s)", "pvfs.load_average.1s", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_load_average_5s,
			{ "Load Average (5s)", "pvfs.load_average.5s", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_load_average_15s,
			{ "Load Average (15s)", "pvfs.load_average.15s", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_uptime_seconds,
			{ "Uptime (seconds)", "pvfs.uptime", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_handles_available,
			{ "Handles Available", "pvfs.handles_available", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_handles_total,
			{ "Total Handles", "pvfs.total_handles", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		/*
		 * This is used when the field returns 64-bits but we're only interested
		 * in the lower 32-bit bits.
		 */
		{ &hf_pvfs_unused,
			{ "Unused", "pvfs.unused", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_context_id,
			{ "Context ID", "pvfs.context_id", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_offset,
			{ "Offset", "pvfs.offset", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_stride,
			{ "Stride", "pvfs.stride", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_ub,
			{ "ub", "pvfs.ub", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_lb,
			{ "lb", "pvfs.lb", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_end_time_ms,
			{ "end_time_ms", "pvfs.end_time_ms", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_cur_time_ms,
			{ "cur_time_ms", "pvfs.cur_time_ms", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_start_time_ms,
			{ "start_time_ms", "pvfs.start_time_ms", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_bytes_written,
			{ "bytes_written", "pvfs.bytes_written", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_bytes_read,
			{ "bytes_read", "pvfs.bytes_read", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_metadata_write,
			{ "metadata_write", "pvfs.metadata_write", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_metadata_read,
			{ "metadata_read", "pvfs.metadata_read", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_b_size,
			{ "Size of bstream (if applicable)", "pvfs.b_size", FT_UINT64,
				BASE_DEC, NULL, 0, "Size of bstream", HFILL }},

		{ &hf_pvfs_k_size,
			{ "Number of keyvals (if applicable)", "pvfs.k_size", FT_UINT64,
				BASE_DEC, NULL, 0, "Number of keyvals", HFILL }},

		{ &hf_pvfs_id_gen_t,
			{ "id_gen_t", "pvfs.id_gen_t", FT_UINT64, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_attribute_key,
			{ "Attribute key", "pvfs.attribute.key", FT_STRING, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_attribute_value,
			{ "Attribute value", "pvfs.attribute.value", FT_STRING, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_strip_size,
			{ "Strip size", "pvfs.strip_size", FT_UINT64, BASE_DEC,
				NULL, 0, "Strip size (bytes)", HFILL }},

		/* TODO: need description */
		{ &hf_pvfs_ereg,
			{ "ereg", "pvfs.ereg", FT_INT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		/* TODO: need description */
		{ &hf_pvfs_sreg,
			{ "sreg", "pvfs.sreg", FT_INT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_num_eregs,
			{ "Number of eregs", "pvfs.num_eregs", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_num_blocks,
			{ "Number of blocks", "pvfs.num_blocks", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_num_contig_chunks,
			{ "Number of contig_chunks", "pvfs.num_contig_chunks", FT_UINT32,
				BASE_DEC, NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_server_nr,
			{ "Server #", "pvfs.server_nr", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_server_count,
			{ "Number of servers", "pvfs.server_count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_fh_length,
			{ "length", "pvfs.fh.length", FT_UINT32, BASE_DEC,
				NULL, 0, "file handle length", HFILL }},

		{ &hf_pvfs_fh_hash,
			{ "hash", "pvfs.fh.hash", FT_UINT32, BASE_HEX,
				NULL, 0, "file handle hash", HFILL }},

		{ &hf_pvfs_permissions,
			{ "Permissions", "pvfs.permissions", FT_UINT32, BASE_OCT,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_server_mode,
			{ "Server Mode", "pvfs.server_mode", FT_UINT32, BASE_DEC,
				VALS(names_pvfs_server_mode), 0, NULL, HFILL }},

		{ &hf_pvfs_depth,
			{ "depth", "pvfs.depth", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_num_nested_req,
			{ "num_nested_req", "pvfs.num_nested_req", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_committed,
			{ "committed", "pvfs.committed", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_refcount,
			{ "refcount", "pvfs.refcount", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_numreq,
			{ "numreq", "pvfs.numreq", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_truncate_request_flags,
			{ "flags", "pvfs.truncate_request_flags", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_ds_position,
			{ "ds_position", "pvfs.ds_position", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_dirent_limit,
			{ "dirent_limit", "pvfs.dirent_limit", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_flush_request_flags,
			{ "flags", "pvfs.flush_request_flags", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_next_id,
			{ "next_id", "pvfs.next_id", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_perf_mon_request_count,
			{ "count", "pvfs.mgmt_perf_mon_request.count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_perf_mon_request_event_count,
			{ "Event count", "pvfs.mgmt_perf_mon_request.event_count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_lookup_path_response_handle_count,
			{ "Handle Count", "pvfs.lookup_path_response.handle_count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_getconfig_response_total_bytes,
			{ "Total Bytes", "pvfs.getconfig_response.total_bytes", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_getconfig_response_lines,
			{ "Lines", "pvfs.getconfig_response.lines", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_getconfig_response_config_bytes,
			{ "Config Bytes", "pvfs.getconfig_response.config_bytes", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_perf_stat_valid_flag,
			{ "valid_flag", "pvfs.mgmt_perf_stat.valid_flag", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_perf_stat_id,
			{ "id", "pvfs.mgmt_perf_stat.id", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_perf_mon_response_suggested_next_id,
			{ "suggested_next_id", "pvfs.mgmt_perf_mon_response.suggested_next_id", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_perf_mon_response_perf_array_count,
			{ "perf_array_count", "pvfs.mgmt_perf_mon_response.perf_array_count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_iterate_handles_response_ds_position,
			{ "ds_position", "pvfs.mgmt_iterate_handles_response.ds_position", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_iterate_handles_response_handle_count,
			{ "handle_count", "pvfs.mgmt_iterate_handles_response.handle_count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_dspace_info_list_response_dspace_info_count,
			{ "dspace_info_count", "pvfs.mgmt_dspace_info_list_response.dspace_info_count", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_event_mon_response_api,
			{ "api", "pvfs.mgmt_event_mon_response.api", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_event_mon_response_operation,
			{ "operation", "pvfs.mgmt_event_mon_response.operation", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_event_mon_response_value,
			{ "value", "pvfs.mgmt_event_mon_response.value", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_event_mon_response_flags,
			{ "flags", "pvfs.mgmt_event_mon_response.flags", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_event_mon_response_tv_sec,
			{ "tv_sec", "pvfs.mgmt_event_mon_response.tv_sec", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_mgmt_event_mon_response_tv_usec,
			{ "tv_usec", "pvfs.mgmt_event_mon_response.tv_usec", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_fill_bytes,
			{ "fill_bytes", "pvfs.fill_bytes", FT_BYTES, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_target_path_len,
			{ "target_path_len", "pvfs.target_path_len", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_version2,
			{ "Version 2", "pvfs.version2", FT_NONE, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_flow_data,
			{ "PVFC Flow Data", "pvfs.flow_data", FT_BYTES, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_getconfig_response_entry,
			{ "GETCONFIG Response entry", "pvfs.getconfig_response_entry", FT_STRING, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_fhandle_data,
			{ "data", "pvfs.fhandle_data", FT_BYTES, BASE_NONE,
				NULL, 0, NULL, HFILL }},

		{ &hf_pvfs_opaque_length,
			{ "length", "pvfs.opaque_length", FT_UINT32, BASE_DEC,
				NULL, 0, NULL, HFILL }},
	};

	/* Setup protocol subtree array */
	static gint *ett[] = {
		&ett_pvfs,
		&ett_pvfs_hdr,
		&ett_pvfs_credentials,
		&ett_pvfs_server_config,
		&ett_pvfs_server_config_branch,
		&ett_pvfs_attrmask,
		&ett_pvfs_time,
		&ett_pvfs_extent_array_tree,
		&ett_pvfs_extent_item,
		&ett_pvfs_string,
		&ett_pvfs_attr_tree,
		&ett_pvfs_distribution,
		&ett_pvfs_mgmt_perf_stat,
		&ett_pvfs_mgmt_dspace_info,
		&ett_pvfs_attr,
		&ett_pvfs_fh
	};

	static ei_register_info ei[] = {
		{ &ei_pvfs_malformed, { "pvfs.malformed", PI_MALFORMED, PI_ERROR, "MALFORMED OR TRUNCATED DATA", EXPFILL }},
	};

	module_t *pvfs_module;
	expert_module_t* expert_pvfs;

	/* Register the protocol name and description */
	proto_pvfs = proto_register_protocol("Parallel Virtual File System",
			"PVFS", "pvfs");

	/*
	 * Required function calls to register the header fields and
	 * subtrees used
	 */

	proto_register_field_array(proto_pvfs, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
	expert_pvfs = expert_register_protocol(proto_pvfs);
	expert_register_field_array(expert_pvfs, ei, array_length(ei));

	pvfs2_io_tracking_value_table = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), pvfs2_io_tracking_hash, pvfs2_io_tracking_equal);

	pvfs_module = prefs_register_protocol(proto_pvfs, NULL);
	prefs_register_bool_preference(pvfs_module, "desegment",
	    "Reassemble PVFS messages spanning multiple TCP segments",
	    "Whether the PVFS dissector should reassemble messages spanning multiple TCP segments. "
	    "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
	    &pvfs_desegment);
}

void
proto_reg_handoff_pvfs(void)
{
	dissector_handle_t pvfs_handle;

	pvfs_handle = create_dissector_handle(dissect_pvfs_heur, proto_pvfs);
	dissector_add_uint_with_preference("tcp.port", TCP_PORT_PVFS2, pvfs_handle);

	heur_dissector_add("tcp", dissect_pvfs_heur, "PVFS over TCP", "pvfs_tcp", proto_pvfs, HEURISTIC_ENABLE);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */