1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
|
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# cmd/backup/dump/Makefile
#
# Copyright (c) 1980 Regents of the University of California.
# All rights reserved. The Berkeley software License Agreement
# specifies the terms and conditions for redistribution.
#
# dump.h header file
# dumpfstab.c reads fstab/vfstab, mtab/mnttab
# dumpitime.c reads /etc/dumpdates
# dumpmain.c driver
# dumponline.c online dump support
# dumpoptr.c operator interface
# dumptape.c handles the mag tape and opening/closing
# dumptraverse.c traverses the file system
# lftw.c fixed version of ftw(3)
# partial.c partial filesystem dump support
# unctime.c undo ctime
#
# CPPFLAGS:
# DEBUG use local directory to find ddate and dumpdates
# PARTIAL enable partial filesystem dump support
# TDEBUG trace out the process forking
#
# CAUTION: FSTYPE must be defined before including ../Makefile.backup,
# otherwise UFSROOTPKGUSRLIBFSTYPE doesn't get expanded
# properly and the magic doesn't happen.
FSTYPE= ufs
include ../Makefile.backup
#CFLAGS += -DTDEBUG
UFSDUMP= ufsdump
PROG= $(UFSDUMP)
PRODUCT= $(PROG)
ROLLDIR= ../../fs.d/ufs/roll_log
ROLLOBJS= $(ROLLDIR)/$(MACH)/roll_log.o
ROLLSRCS= $(ROLLDIR)/roll_log.c
LOBJECTS= dumponline.o dumpfstab.o dumpitime.o dumpmain.o \
dumpoptr.o dumptape.o dumptraverse.o unctime.o \
partial.o lftw.o
OBJECTS= $(LOBJECTS) roll_log.o
SRCS= $(LOBJECTS:.o=.c)
POFILES= $(OBJECTS:.o=.po) ../lib/libdump.po
POFILE= ufsdump.po
ROLLPOFILES= roll_log.po
# XXX This is only needed for the check: target. It would be nice to
# XXX automatically generate the list when needed.
HEADERS= ../../../head/protocols/dumprestore.h \
../../fs.d/ufs/roll_log/roll_log.h ../include/byteorder.h \
../include/memutils.h \
../include/rmt.h dump.h dumpusg.h
CLOBBERFILES += $(PRODUCT) $(DEBUGPRODUCTS) dumpdates
LOCAL= .
GENERAL= ../include
GLOBAL= ../../../head
CPPFLAGS= -I$(LOCAL) -I$(GENERAL) -I$(GLOBAL) -DPARTIAL \
-I$(ROLLDIR) $(CPPFLAGS.master) \
-D_LARGEFILE64_SOURCE=1
CERRWARN += -Wno-implicit-function-declaration
CERRWARN += -Wno-parentheses
CERRWARN += $(CNOWARN_UNINIT)
CERRWARN += -Wno-clobbered
CERRWARN += -Wno-extra
LIBDUMP= ../lib/libdump.a
LINTLIBDUMP= ../lib/llib-ldump.ln -lkstat
LDLIBS += $(BSTATIC) -L../lib -ldump $(BDYNAMIC) \
-lsocket -lnsl -ladm -lm -lkstat
UFSROOTDUMPDATES= $(UFSROOTETC)/dumpdates
UFSROOTLINK= $(UFSROOTUSRSBIN)/$(PROG)
LINKVALUE= ../lib/fs/$(FSTYPE)/$(PROG)
LIBDIR= $(UFSROOTUSRLIBFS)/$(FSTYPE)
$(UFSROOTDUMPDATES): FILEMODE= 0664
$(LIBDIR): DIRMODE= 0755
FILEMODE= 04555
.KEEP_STATE:
all: $(PRODUCT)
$(PROG): $(OBJECTS) $$(LIBDUMP)
$(LINK.c) -o $@ $(OBJECTS) $(LDLIBS)
$(POST_PROCESS)
$(LIBDUMP): FRC
$(DO_LIBDIR)
$(POFILE): $(POFILES)
$(RM) $@; cat $(POFILES) > $@
FRC:
install: all $(LIBDIR) $(UFSROOTPKGUSRLIBFSTYPE) dumpdates \
$(UFSROOTDUMPDATES) $(UFSROOTLINK)
dumpdates:
cp /dev/null dumpdates
#XXX Should actually note return value from close(2), particularly regarding
#XXX tape descriptors. Some drives don't actually force anything to media
#XXX except when they are writing a file mark....
# grep is looking for non-space/tab
lint: $(SRCS) $(ROLLSRCS) $$(LINTLIBDUMP)
$(LINT.c) $(SRCS) $(ROLLSRCS) $(LINTLIBDUMP) 2>&1 \
| sed -f lint.sed | grep '^[^ ]'
$(LINTLIBDUMP): FRC
cd ../lib; pwd; $(MAKE) lint
pwd
check: FRC
$(CSTYLE) $(CSTYLEFLAGS) $(SRCS) $(ROLLSRCS) $(HEADERS)
$(HDRCHK) $(HDRCHKFLAGS) $(HEADERS)
clean:
$(RM) $(OBJECTS) $(ROLLOBJS) $(DEBUGOBJS) *.ln
$(LIBDIR):
$(INS.dir)
$(UFSROOTLINK):
-$(RM) $@; $(SYMLINK) $(LINKVALUE) $(UFSROOTLINK)
roll_log.o:
cd $(ROLLDIR) ; pwd ; $(MAKE)
cp $(ROLLOBJS) .
pwd
$(ROLLPOFILES): $(ROLLSRCS)
cd $(ROLLDIR) ; pwd ; $(MAKE) `echo $(ROLLPOFILES) | sed -e 's@$(ROLLDIR)/@@g'`
cp $(ROLLDIR)/*.po .
pwd
../lib/libdump.po:
cd ../lib ; pwd ; $(MAKE) libdump.po
include ../Makefile.targ
Copyright (c) 1980 Regents of the University of California.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgement:
This product includes software developed by the University
of California, Berkeley and its contributors.
4. Neither the name of the University nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PORTIONS OF BACKUP COMMAND FUNCTIONALITY
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#ifndef _DUMP_H
#define _DUMP_H
#include <stdio.h>
#include <locale.h>
#include <sys/types.h>
#include <ctype.h>
#include <string.h>
#include <syslog.h>
#include <errno.h>
#include <fcntl.h>
#include <utmpx.h>
#include <signal.h>
#include <stdlib.h>
#include <time.h>
#include <sys/param.h> /* for MAXBSIZE */
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/vnode.h> /* needed by inode.h */
#include <setjmp.h>
#include <sys/mman.h>
#include <assert.h>
#include <dumpusg.h>
#include <kstat.h>
#include <sys/fssnap_if.h>
#include <libgen.h>
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SUPPORTS_MTB_TAPE_FORMAT
#include <protocols/dumprestore.h>
#include <memutils.h>
#include <note.h>
#define NI 16
#define MAXINOPB (MAXBSIZE / sizeof (struct dinode))
#define MAXNINDIR (MAXBSIZE / sizeof (daddr32_t))
#ifndef roundup
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
#endif
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
/*
* Define an overflow-free version of howmany so that we don't
* run into trouble with large files.
*/
#define d_howmany(x, y) ((x) / (y) + ((x) % (y) != 0))
#define MWORD(m, i) (m[(ino_t)(i-1)/NBBY])
#define MBIT(i) ((1<<((ino_t)(i-1)%NBBY))&0xff)
#define BIS(i, w) (MWORD(w, i) |= MBIT(i))
#define BIC(i, w) (MWORD(w, i) &= ~MBIT(i))
#define BIT(i, w) (MWORD(w, i) & MBIT(i))
extern uint_t msiz;
extern uchar_t *clrmap;
extern uchar_t *dirmap;
extern uchar_t *filmap;
extern uchar_t *nodmap;
extern uchar_t *shamap;
extern uchar_t *activemap;
/*
* All calculations done in 0.1" units!
*/
extern char *disk; /* name of the disk file */
extern char *dname; /* name to put in /etc/dumpdates */
extern int disk_dynamic; /* true if disk refers to dynamic storage */
extern char *tape; /* name of the tape file */
extern char *host; /* name of the remote tape host (may be "user@host") */
extern char *dumpdev; /* hostname:device for current volume */
extern char *sdumpdev; /* short form of dumpdev (no user name if remote) */
extern char *increm; /* name of file containing incremental information */
extern char *filesystem; /* name of the file system */
extern char *myname; /* argv[0] without leading path components */
extern char lastincno; /* increment number of previous dump */
extern char incno; /* increment number */
extern char *tlabel; /* what goes in tape header c_label field */
extern int uflag; /* update flag */
extern int fi; /* disk file descriptor */
extern int to; /* tape file descriptor */
extern int mapfd; /* block disk device descriptor for mmap */
extern int pipeout; /* true => output to standard output */
extern int tapeout; /* true => output to a tape drive */
extern ino_t ino; /* current inumber; used globally */
extern off_t pos; /* starting offset within ino; used globally */
extern int leftover; /* number of tape recs left over from prev vol */
extern int nsubdir; /* counts subdirs, for deciding to dump a dir */
extern int newtape; /* new tape flag */
extern int nadded; /* number of added sub directories */
extern int dadded; /* directory added flag */
extern int density; /* density in 0.1" units */
extern ulong_t tsize; /* tape size in 0.1" units */
extern u_offset_t esize; /* estimated tape size, blocks */
extern u_offset_t o_esize; /* number of header blocks (overhead) */
extern u_offset_t f_esize; /* number of TP_BSIZE blocks for files/maps */
extern uint_t etapes; /* estimated number of tapes */
extern uint_t ntrec; /* 1K records per tape block */
extern int tenthsperirg; /* 1/10" per tape inter-record gap */
extern dev_t partial_dev; /* id of BLOCK device used in partial mode */
extern pid_t dumppid; /* process-ID of top-level process */
extern int verify; /* verify each volume */
extern int doingverify; /* true => doing a verify pass */
extern int active; /* recopy active files */
extern int doingactive; /* true => redumping active files */
extern int archive; /* true => saving a archive in archivefile */
extern char *archivefile; /* name of archivefile */
extern int archive_opened; /* have opened/created the archivefile */
extern int notify; /* notify operator flag */
extern int diskette; /* true if dumping to a diskette */
extern int cartridge; /* true if dumping to a cartridge tape */
extern uint_t tracks; /* number of tracks on a cartridge tape */
extern int printsize; /* just print estimated size and exit */
extern int offline; /* take tape offline after rewinding */
extern int autoload; /* wait for next tape to autoload; implies offline */
extern int autoload_tries; /* number of times to check on autoload */
extern int autoload_period; /* seconds, tries*period = total wait time */
extern int doposition; /* move to specified... */
extern daddr32_t filenum; /* position of dump on 1st volume */
extern int dumpstate; /* dump output state (see below) */
extern int dumptoarchive; /* mark records to be archived */
extern int blockswritten; /* number of blocks written on current tape */
extern uint_t tapeno; /* current tape number */
extern struct fs *sblock; /* the file system super block */
extern int shortmeta; /* current file has small amount of metadata */
extern union u_shadow c_shadow_save[1];
extern time_t *telapsed; /* time spent writing previous tapes */
extern time_t *tstart_writing; /* when we started writing the latest tape */
extern time_t *tschedule; /* when next to give a remaining-time estimate */
extern char *debug_chdir; /* non-NULL means to mkdir this/pid, */
/* and chdir there, once for each separate child */
/*
* Defines for the msec part of
* inode-based times, since we're
* not part of the kernel.
*/
#define di_atspare di_ic.ic_atspare
#define di_mtspare di_ic.ic_mtspare
#define di_ctspare di_ic.ic_ctspare
#define HOUR (60L*60L)
#define DAY (24L*HOUR)
#define YEAR (365L*DAY)
/*
* Dump output states
*/
#define DS_INIT 0
#define DS_START 1
#define DS_CLRI 2
#define DS_BITS 3
#define DS_DIRS 4
#define DS_FILES 5
#define DS_END 6
#define DS_DONE 7
/*
* Exit status codes
*/
#define X_FINOK 0 /* normal exit */
#define X_REWRITE 2 /* restart writing from the check point */
#define X_ABORT 3 /* abort all of dump; no checkpoint restart */
#define X_VERIFY 4 /* verify the reel just written */
#define X_RESTART 5 /* abort all progress so far; attempt restart */
#define NINCREM "/etc/dumpdates" /* new format incremental info */
#define TAPE "/dev/rmt/0b" /* default tape device */
#define OPGRENT "sys" /* group entry to notify */
#define DIALUP "ttyd" /* prefix for dialups */
#define DISKETTE "/dev/rfd0c"
#define NBUF 64 /* number of output buffers */
#define MAXNTREC 256 /* max tape blocking factor (in Kb) */
/*
* The contents of the file NINCREM are maintained both on
* a linked list and then (eventually) arrayified.
*/
struct idates {
char id_name[MAXNAMLEN+3];
char id_incno;
time32_t id_ddate;
};
extern size_t nidates; /* number of records (might be zero) */
extern struct idates **idatev; /* the arrayfied version */
#define ITITERATE(i, ip) \
for (i = 0; i < nidates && (ip = idatev[i]) != NULL; i++)
/*
* Function declarations
*/
#ifdef __STDC__
/*
* dumpfstab.c
*/
extern void mnttabread(void);
extern struct mntent *mnttabsearch(char *, int);
extern void setmnttab(void);
extern struct mntent *getmnttab(void);
/*
* dumpitime.c
*/
extern char *prdate(time_t);
extern void inititimes(void);
extern void getitime(void);
extern void putitime(void);
extern void est(struct dinode *);
extern time32_t is_fssnap_dump(char *);
extern void bmapest(uchar_t *);
/*
* dumplabel.c
*/
extern void getlabel(void);
/*
* dumpmain.c
*/
extern void child_chdir(void);
extern char *unrawname(char *);
extern void sigAbort(int);
extern char *rawname(char *);
extern char *lf_rawname(char *);
extern time32_t timeclock(time32_t);
#ifdef signal
extern void (*nsignal(int, void (*)(int)))(int);
#endif
extern int safe_file_open(const char *file, int mode, int perms);
extern int safe_device_open(const char *file, int mode, int perms);
extern FILE *safe_fopen(const char *filename, const char *smode, int perms);
/*
* dumponline.c
*/
extern void allocino(void);
extern void freeino(void);
extern void saveino(ino_t, struct dinode *);
extern void resetino(ino_t);
extern long getigen(ino_t);
extern int lf_ismounted(char *, char *);
extern int isoperator(uid_t, gid_t);
extern int lockfs(char *, char *);
extern int openi(ino_t, long, char *);
extern caddr_t mapfile(int, off_t, off_t, int);
extern void unmapfile(void);
extern void stattoi(struct stat *, struct dinode *);
extern void dumpfile(int, caddr_t, off_t, off_t, off_t, int, int);
extern void activepass(void);
/*
* dumpoptr.c
*/
extern int query(char *);
extern int query_once(char *, int);
extern void interrupt(int);
extern void broadcast(char *);
extern void timeest(int, int);
/*PRINTFLIKE1*/
extern void msg(const char *, ...);
/*PRINTFLIKE1*/
extern void msgtail(const char *, ...);
extern void lastdump(int);
extern char *getresponse(char *, char *);
/*
* dumptape.c
*/
extern void alloctape(void);
extern void reset(void);
extern void spclrec(void);
extern void taprec(uchar_t *, int, int);
extern void dmpblk(daddr32_t, size_t, off_t);
extern void toslave(void (*)(ino_t), ino_t);
extern void doinode(ino_t);
extern void dospcl(ino_t);
extern void flushcmds(void);
extern void flusht(void);
extern void nextdevice(void);
extern int isrewind(int);
extern void trewind(void);
extern void close_rewind(void);
extern void changevol(void);
extern void otape(int);
extern void dumpabort(void);
extern void dumpailing(void);
extern void Exit(int);
extern void positiontape(char *);
/*
* dumptraverse.c
*/
extern void pass(void (*)(struct dinode *), uchar_t *);
extern void mark(struct dinode *);
extern void active_mark(struct dinode *);
extern void markshad(struct dinode *);
extern void estshad(struct dinode *);
extern void freeshad();
extern void add(struct dinode *);
extern void dirdump(struct dinode *);
extern void dump(struct dinode *);
extern void lf_dump(struct dinode *);
extern void dumpblocks(ino_t);
extern void bitmap(uchar_t *, int);
extern struct dinode *getino(ino_t);
extern void bread(diskaddr_t, uchar_t *, size_t);
extern int hasshortmeta(struct dinode **ip);
/*
* lftw.c
*/
extern int lftw(const char *,
int (*)(const char *, const struct stat *, int), int);
extern int lf_lftw(const char *,
int (*)(const char *, const struct stat64 *, int), int);
/*
* partial.c
*/
extern void partial_check(void);
extern void lf_partial_check(void);
extern int partial_mark(int, char **);
/*
* unctime.c
*/
extern time_t unctime(char *);
#else /* !STDC */
/*
* dumpfstab.c
*/
extern void mnttabread();
extern struct mntent *mnttabsearch();
extern void setmnttab();
extern struct mntent *getmnttab();
/*
* dumpitime.c
*/
extern char *prdate();
extern void inititimes();
extern void getitime();
extern void putitime();
extern void est();
extern time32_t is_fssnap_dump();
extern void bmapest();
/*
* dumplabel.c
*/
extern void getlabel();
/*
* dumpmain.c
*/
extern void child_chdir();
extern char *unrawname();
extern void sigAbort();
extern char *rawname();
extern char *lf_rawname();
extern time_t timeclock();
#ifdef signal
extern void nsignal();
#endif
extern int safe_file_open();
extern int safe_device_open();
extern FILE *safe_fopen();
/*
* dumponline.c
*/
extern void allocino();
extern void freeino();
extern void saveino();
extern void resetino();
extern long getigen();
extern int lf_ismounted();
extern int isoperator();
extern ulong_t lockfs();
extern int openi();
extern caddr_t mapfile();
extern void unmapfile();
extern void stattoi();
extern void dumpfile();
extern void activepass();
/*
* dumpoptr.c
*/
extern int query();
extern int query_once();
extern void interrupt();
extern void broadcast();
extern void timeest();
extern void msg();
extern void msgtail();
extern void lastdump();
extern char *getresponse();
/*
* dumptape.c
*/
extern void alloctape();
extern void reset();
extern void spclrec();
extern void taprec();
extern void dmpblk();
extern void toslave();
extern void doinode();
extern void dospcl();
extern void flushcmds();
extern void flusht();
extern void nextdevice();
extern int isrewind();
extern void trewind();
extern void close_rewind();
extern void changevol();
extern void otape();
extern void dumpabort();
extern void dumpailing();
extern void Exit();
extern void positiontape();
/*
* dumptraverse.c
*/
extern void pass();
extern void mark();
extern void active_mark();
extern void markshad();
extern void estshad();
extern void freeshad();
extern void add();
extern void dirdump();
extern void dump();
extern void lf_dump();
extern void dumpblocks();
extern void bitmap();
extern struct dinode *getino();
extern void bread();
extern int hasshortmeta();
/*
* lftw.c
*/
extern int lftw();
extern int lf_lftw();
/*
* partial.c
*/
extern void partial_check();
extern void lf_partial_check();
extern int partial_mark();
/*
* unctime.c
*/
extern time_t unctime();
#endif /* __STDC__ */
/* Insufficiently-featureful system header files... */
NOTE(ALIGNMENT(mmap, 8))
#ifdef __cplusplus
}
#endif
#endif /* _DUMP_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1996,1998 by Sun Microsystems, Inc.
* All rights reserved.
*/
#include "dump.h"
/*
* File system mount table input routines. We handle a
* a combination of BSD and SVR4 formats by coding functions
* to explicitly read the SVR4 vfstab file and using
* #define's to build a routine to read both BSD files
* (fstab and mtab) and SVR4's mnttab file. Internally
* we keep everything in the common (mtab/mnttab) format.
*/
static struct pmntent {
struct mntent *pm_mnt;
struct pmntent *pm_next;
} *mnttable;
/* Note that nothing is ever free()'d, so this is safe */
#define mntstrdup(s) ((s) ? strdup((s)) : "")
#ifdef __STDC__
static struct mntent *mygetmntent(FILE *, char *);
static struct pmntent *addmtab(char *, struct pmntent *);
static struct mntent *allocmntent(struct mntent *);
#else /* !__STDC__ */
static struct pmntent *addmtab();
static struct mntent *mygetmntent();
static struct mntent *allocmntent();
static int idatesort();
#endif
static struct mntent *
mygetmntent(f, name)
FILE *f;
char *name;
{
static struct mntent mt;
int status;
if ((status = getmntent(f, &mt)) == 0)
return (&mt);
switch (status) {
case EOF: break; /* normal exit condition */
case MNT_TOOLONG:
msg(gettext("%s has a line that is too long\n"), name);
break;
case MNT_TOOMANY:
msg(gettext("%s has a line with too many entries\n"), name);
break;
case MNT_TOOFEW:
msg(gettext("%s has a line with too few entries\n"), name);
break;
default:
msg(gettext(
"Unknown return code, %d, from getmntent() on %s\n"),
status, name);
break;
}
return (NULL);
}
/*
* Read in SVR4 vfstab-format table.
*/
static struct pmntent *
addvfstab(tablename, pm)
char *tablename;
struct pmntent *pm;
{
struct mnttab *mnt;
struct vfstab vfs;
FILE *tp;
int status;
assert(((mnttable == NULL) && (pm == NULL)) || (pm != NULL));
/*
* No need to secure this, as tablename is hard-coded to VFSTAB,
* and that file is in /etc. If random people have write-permission
* there, then there are more problems than any degree of paranoia
* on our part can fix.
*/
tp = fopen(tablename, "r");
if (tp == (FILE *)0) {
msg(gettext("Cannot open %s for dump table information.\n"),
tablename);
return ((struct pmntent *)0);
}
while ((status = getvfsent(tp, &vfs)) == 0) {
if (vfs.vfs_fstype == (char *)0 ||
strcmp(vfs.vfs_fstype, MNTTYPE_42) != 0)
continue;
mnt = (struct mnttab *)xmalloc(sizeof (*mnt));
mnt->mnt_fsname = mntstrdup(vfs.vfs_special);
mnt->mnt_dir = mntstrdup(vfs.vfs_mountp);
mnt->mnt_type = mntstrdup(vfs.vfs_fstype);
mnt->mnt_opts = mntstrdup(vfs.vfs_mntopts);
if (mnttable == (struct pmntent *)0)
/*
* Guaranteed by caller that pm will also be NULL,
* so no memory leak to worry about.
*/
mnttable = pm = (struct pmntent *)xmalloc(sizeof (*pm));
else {
/* Guaranteed pm not NULL by caller and local logic */
pm->pm_next = (struct pmntent *)xmalloc(sizeof (*pm));
pm = pm->pm_next;
}
pm->pm_mnt = mnt;
pm->pm_next = (struct pmntent *)0;
}
switch (status) {
case EOF: break; /* normal exit condition */
case VFS_TOOLONG:
msg(gettext("%s has a line that is too long\n"), tablename);
break;
case VFS_TOOMANY:
msg(gettext("%s has a line with too many entries\n"),
tablename);
break;
case VFS_TOOFEW:
msg(gettext("%s has a line with too few entries\n"), tablename);
break;
default:
msg(gettext(
"Unknown return code, %d, from getvfsent() on %s\n"),
status, tablename);
break;
}
(void) fclose(tp);
return (pm);
}
static struct mntent *
allocmntent(mnt)
struct mntent *mnt;
{
struct mntent *new;
new = (struct mntent *)xmalloc(sizeof (*mnt));
new->mnt_fsname = mntstrdup(mnt->mnt_fsname); /* mnt_special */
new->mnt_dir = mntstrdup(mnt->mnt_dir); /* mnt_mountp */
new->mnt_type = mntstrdup(mnt->mnt_type); /* mnt_fstype */
new->mnt_opts = mntstrdup(mnt->mnt_opts); /* mnt_mntopts */
return (new);
}
void
mnttabread()
{
struct pmntent *pm = (struct pmntent *)0;
if (mnttable != (struct pmntent *)0)
return;
/*
* Read in the file system mount tables. Order
* is important as the first matched entry is used
* if the target device/filesystem is not mounted.
* We try fstab or vfstab first, then mtab or mnttab.
*/
pm = addvfstab(VFSTAB, pm);
(void) addmtab(MOUNTED, pm);
}
static struct pmntent *
addmtab(tablename, pm)
char *tablename;
struct pmntent *pm;
{
struct mntent *mnt;
FILE *tp;
tp = setmntent(tablename, "r");
if (tp == (FILE *)0) {
msg(gettext("Cannot open %s for dump table information.\n"),
tablename);
return ((struct pmntent *)0);
}
while (mnt = mygetmntent(tp, tablename)) {
if (mnt->mnt_type == (char *)0 ||
strcmp(mnt->mnt_type, MNTTYPE_42) != 0)
continue;
mnt = allocmntent(mnt);
if (mnttable == (struct pmntent *)0)
/*
* Guaranteed by caller that pm will also be NULL,
* so no memory leak to worry about.
*/
mnttable = pm = (struct pmntent *)xmalloc(sizeof (*pm));
else {
/* Guaranteed pm not NULL by caller and local logic */
pm->pm_next = (struct pmntent *)xmalloc(sizeof (*pm));
pm = pm->pm_next;
}
pm->pm_mnt = mnt;
pm->pm_next = (struct pmntent *)0;
}
(void) endmntent(tp);
return (pm);
}
/*
* Search in fstab and potentially mtab for a file name.
* If "mounted" is non-zero, the target file system must
* be mounted in order for the search to succeed.
* This file name can be either the special or the path file name.
*
* The entries in either fstab or mtab are the BLOCK special names,
* not the character special names.
* The caller of mnttabsearch assures that the character device
* is dumped (that is much faster)
*
* The file name can omit the leading '/'.
*/
struct mntent *
mnttabsearch(key, mounted)
char *key;
int mounted;
{
struct pmntent *pm;
struct mntent *mnt;
struct mntent *first = (struct mntent *)0;
char *s;
char *gotreal;
char path[MAXPATHLEN];
for (pm = mnttable; pm; pm = pm->pm_next) {
s = NULL;
mnt = pm->pm_mnt;
if (strcmp(mnt->mnt_dir, key) == 0)
goto found;
if (strcmp(mnt->mnt_fsname, key) == 0)
goto found;
if ((s = rawname(mnt->mnt_fsname)) != NULL &&
strcmp(s, key) == 0)
goto found;
gotreal = realpath(mnt->mnt_dir, path);
if (gotreal && strcmp(path, key) == 0)
goto found;
if (key[0] != '/') {
if (*mnt->mnt_fsname == '/' &&
strcmp(mnt->mnt_fsname + 1, key) == 0)
goto found;
if (*mnt->mnt_dir == '/' &&
strcmp(mnt->mnt_dir + 1, key) == 0)
goto found;
if (gotreal && *path == '/' &&
strcmp(path + 1, key) == 0)
goto found;
}
if (s != NULL && s != mnt->mnt_fsname)
free(s);
continue;
found:
/* Pointer comparison, not string comparison */
if (s != NULL && s != mnt->mnt_fsname)
free(s);
/*
* Found a match; return immediately if
* it is mounted (valid), otherwise just
* record if it's the first matched entry.
*/
if (lf_ismounted(mnt->mnt_fsname, mnt->mnt_dir) > 0)
return (mnt);
else if (first == (struct mntent *)0)
first = mnt;
}
/*
* If we get here, there were either
* no matches, or no matched entries
* were mounted. Return failure if
* we were supposed to find a mounted
* entry, otherwise return the first
* matched entry (or null).
*/
if (mounted)
return ((struct mntent *)0);
return (first);
}
static struct pmntent *current;
static int set;
void
#ifdef __STDC__
setmnttab(void)
#else
setmnttab()
#endif
{
current = mnttable;
set = 1;
}
struct mntent *
#ifdef __STDC__
getmnttab(void)
#else
getmnttab()
#endif
{
struct pmntent *pm;
if (!set)
setmnttab();
pm = current;
if (current) {
current = current->pm_next;
return (pm->pm_mnt);
}
return ((struct mntent *)0);
}
/*
* Copyright 1996-1998, 2002-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#include "dump.h"
#ifndef LOCK_EX
static struct flock fl;
#define flock(fd, flag) (fl.l_type = (flag), fcntl(fd, F_SETLKW, &fl))
#define LOCK_EX F_WRLCK
#define LOCK_SH F_RDLCK
#define LOCK_UN F_UNLCK
#endif
char *disk;
char *dname;
char *increm;
char incno;
char lastincno;
int uflag;
uint_t msiz;
u_offset_t o_esize;
u_offset_t f_esize;
/*
* Print a date. A date of 0 is the beginning of time (the "epoch").
* If the 2nd argument is non-zero, it is ok to format the date in
* locale-specific form, otherwise we use ctime. We must use ctime
* for dates such as those in the dumpdates file, which must be
* locale-independent.
*/
char *
prdate(time_t d)
{
static char buf[256];
struct tm *tm;
char *p;
if (d == 0)
return (gettext("the epoch"));
tm = localtime(&d);
if (strftime(buf, sizeof (buf), "%c", tm) != 0) {
p = buf;
} else {
/* Wouldn't fit in buf, fall back */
p = ctime(&d);
p[24] = '\0'; /* lose trailing newline */
}
return (p);
}
struct idates **idatev = 0;
size_t nidates = 0;
static int idates_in = 0; /* we have read the increment file */
static int recno;
#ifdef __STDC__
static void readitimes(FILE *);
static void recout(FILE *, struct idates *);
static int getrecord(FILE *, struct idates *);
static int makeidate(struct idates *, char *);
#else
static void readitimes();
static void recout();
static int getrecord();
static int makeidate();
#endif
void
inititimes(void)
{
FILE *df;
int saverr;
if (idates_in)
return;
if (increm == NULL || *increm == '\0') {
msg(gettext("inititimes: No dump record file name defined\n"));
dumpabort();
/*NOTREACHED*/
}
/*
* No need to secure this, as increm is hard-coded to NINCREM,
* and that file is in /etc. If random people have write-permission
* there, then there are more problems than any degree of paranoia
* on our part can fix.
*/
if ((df = fopen(increm, "r")) == NULL) {
saverr = errno;
if (errno == ENOENT)
msg(gettext(
"Warning - dump record file `%s' does not exist\n"),
increm);
else {
msg(gettext("Cannot open dump record file `%s': %s\n"),
increm, strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
return;
}
if (uflag && access(increm, W_OK) < 0) {
msg(gettext("Cannot access dump record file `%s' for update\n"),
increm);
dumpabort();
/*NOTREACHED*/
}
(void) flock(fileno(df), LOCK_SH);
readitimes(df);
(void) fclose(df);
}
static void
readitimes(FILE *df)
{
struct idates *idp;
recno = 0;
for (;;) {
idp = (struct idates *)xcalloc(1, sizeof (*idp));
if (getrecord(df, idp) < 0) {
free((char *)idp);
break;
}
nidates++;
idatev = (struct idates **)xrealloc((void *)idatev,
nidates * (size_t)sizeof (*idatev));
idatev[nidates - 1] = idp;
}
/* LINTED: assigned value is used in inititimes */
idates_in = 1;
}
void
getitime(void)
{
struct idates *ip;
int i;
char *fname;
/*
* if an alternate name was specified via the N flag, use it instead
* of the disk name.
*/
if (dname != NULL)
fname = dname;
else
fname = disk;
#ifdef FDEBUG
/* XGETTEXT: #ifdef FDEBUG only */
msg(gettext("Looking for name %s in increm = %s for delta = %c\n"),
fname, increm, (uchar_t)incno);
#endif
spcl.c_ddate = 0;
lastincno = '0';
inititimes();
if (idatev == 0)
return;
/*
* Go find the entry with the same name for a lower increment
* and older date
*/
ITITERATE(i, ip) {
if (strncmp(fname, ip->id_name, sizeof (ip->id_name)) != 0)
continue;
if (ip->id_incno >= incno)
continue;
if (ip->id_ddate <= spcl.c_ddate)
continue;
spcl.c_ddate = ip->id_ddate;
lastincno = ip->id_incno;
}
}
void
putitime(void)
{
FILE *df;
struct idates *itwalk;
int i;
int fd, saverr;
char *fname;
if (uflag == 0)
return;
if ((df = safe_fopen(increm, "r+", 0664)) == (FILE *)NULL) {
msg("%s: %s\n", increm, strerror(errno));
(void) unlink(increm);
dumpabort();
/*NOTREACHED*/
}
fd = fileno(df);
(void) flock(fd, LOCK_EX);
/*
* if an alternate name was specified via the N flag, use it instead
* of the disk name.
*/
if (dname != NULL)
fname = dname;
else
fname = disk;
if (idatev != 0) {
for (i = 0; i < nidates && idatev[i] != 0; i++)
free((char *)idatev[i]);
free((char *)idatev);
}
idatev = 0;
nidates = 0;
readitimes(df);
if (fseek(df, 0L, 0) < 0) { /* rewind() was redefined in dumptape.c */
saverr = errno;
msg(gettext("%s: %s error:\n"),
increm, "fseek", strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
spcl.c_ddate = 0;
/* LINTED: won't dereference idatev if it is NULL (see readitimes) */
ITITERATE(i, itwalk) {
if (strncmp(fname, itwalk->id_name,
sizeof (itwalk->id_name)) != 0)
continue;
if (itwalk->id_incno != incno)
continue;
goto found;
}
/*
* Add one more entry to idatev
*/
nidates++;
idatev = (struct idates **)xrealloc((void *)idatev,
nidates * (size_t)sizeof (struct idates *));
itwalk = idatev[nidates - 1] =
(struct idates *)xcalloc(1, sizeof (*itwalk));
found:
(void) strncpy(itwalk->id_name, fname, sizeof (itwalk->id_name));
itwalk->id_name[sizeof (itwalk->id_name) - 1] = '\0';
itwalk->id_incno = incno;
itwalk->id_ddate = spcl.c_date;
ITITERATE(i, itwalk) {
recout(df, itwalk);
}
if (ftruncate64(fd, ftello64(df))) {
saverr = errno;
msg(gettext("%s: %s error:\n"),
increm, "ftruncate64", strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
(void) fclose(df);
msg(gettext("Level %c dump on %s\n"),
(uchar_t)incno, prdate(spcl.c_date));
}
static void
recout(FILE *file, struct idates *what)
{
time_t ddate = what->id_ddate;
/* must use ctime, so we can later use unctime() */
(void) fprintf(file, DUMPOUTFMT, what->id_name,
(uchar_t)what->id_incno, ctime(&ddate));
}
static int
getrecord(FILE *df, struct idates *idatep)
{
char buf[BUFSIZ];
if ((fgets(buf, BUFSIZ, df)) != buf)
return (-1);
recno++;
if (makeidate(idatep, buf) < 0) {
msg(gettext(
"Malformed entry in dump record file `%s', line %d\n"),
increm, recno);
if (strcmp(increm, NINCREM)) {
msg(gettext("`%s' not a dump record file\n"), increm);
dumpabort();
/*NOTREACHED*/
}
return (-1);
}
#ifdef FDEBUG
msg("getrecord: %s %c %s\n",
idatep->id_name,
(uchar_t)idatep->id_incno,
prdate(idatep->id_ddate));
#endif
return (0);
}
static int
makeidate(struct idates *ip, char *buf)
{
char un_buf[128]; /* size must be >= second one in DUMPINFMT */
/*
* MAXNAMLEN has different values in dirent.h and ufs_fsdir.h,
* and we need to ensure that the length in DUMPINFMT matches
* what we allow for. Can't just use MAXNAMLEN in the test,
* because there's no convenient way to substitute it into
* DUMPINFMT.
* XXX There's got to be a better way.
*/
/*LINTED [assertion always true]*/
assert(sizeof (ip->id_name) == (255 + 3));
if (sscanf(buf, DUMPINFMT, ip->id_name, &ip->id_incno, un_buf) != 3)
return (-1);
/* LINTED casting from 64-bit to 32-bit time */
ip->id_ddate = (time32_t)unctime(un_buf);
if (ip->id_ddate < 0)
return (-1);
return (0);
}
/*
* This is an estimation of the number of tp_bsize blocks in the file.
* It estimates the number of blocks in files with holes by assuming
* that all of the blocks accounted for by di_blocks are data blocks
* (when some of the blocks are usually used for indirect pointers);
* hence the estimate may be high.
*/
void
est(struct dinode *ip)
{
u_offset_t s, t;
/*
* ip->di_size is the size of the file in bytes.
* ip->di_blocks stores the number of sectors actually in the file.
* If there are more sectors than the size would indicate, this just
* means that there are indirect blocks in the file or unused
* sectors in the last file block; we can safely ignore these
* (s = t below).
* If the file is bigger than the number of sectors would indicate,
* then the file has holes in it. In this case we must use the
* block count to estimate the number of data blocks used, but
* we use the actual size for estimating the number of indirect
* dump blocks (t vs. s in the indirect block calculation).
*/
o_esize++;
s = (unsigned)(ip->di_blocks) / (unsigned)(tp_bsize / DEV_BSIZE);
/* LINTED: spurious complaint about sign-extending 32 to 64 bits */
t = d_howmany(ip->di_size, (unsigned)tp_bsize);
if (s > t)
s = t;
if (ip->di_size > (u_offset_t)((unsigned)(sblock->fs_bsize) * NDADDR)) {
/* calculate the number of indirect blocks on the dump tape */
/* LINTED: spurious complaint sign-extending 32 to 64 bits */
s += d_howmany(t -
(unsigned)(NDADDR * sblock->fs_bsize / tp_bsize),
(unsigned)TP_NINDIR);
}
f_esize += s;
}
/*ARGSUSED*/
void
bmapest(uchar_t *map)
{
o_esize++;
/* LINTED: spurious complaint sign-extending 32 to 64 bits */
f_esize += d_howmany(msiz * sizeof (map[0]), (unsigned)tp_bsize);
}
/*
* Check to see if what we are trying to dump is a fs snapshot
* If so, we can use the snapshot's create time to populate
* the dumpdates file, instead of the time of the dump.
*/
time32_t
is_fssnap_dump(char *disk)
{
struct stat st;
char *last;
int snapnum;
kstat_ctl_t *kslib;
kstat_t *ksnum;
kstat_named_t *numval;
last = basename(disk);
if ((strstr(disk, SNAP_NAME) == NULL) || (stat(disk, &st) == -1) ||
(isdigit(last[0]) == 0))
return (0);
snapnum = atoi(last);
if ((kslib = kstat_open()) == NULL)
return (0);
ksnum = kstat_lookup(kslib, SNAP_NAME, snapnum, FSSNAP_KSTAT_NUM);
if (ksnum == NULL) {
(void) kstat_close(kslib);
return (0);
}
if (kstat_read(kslib, ksnum, NULL) == -1) {
(void) kstat_close(kslib);
return (0);
}
numval = kstat_data_lookup(ksnum, FSSNAP_KSTAT_NUM_CREATETIME);
if (numval == NULL) {
(void) kstat_close(kslib);
return (0);
}
(void) kstat_close(kslib);
/* LINTED casting from long to 32-bit time */
return (time32_t)(numval->value.l & INT_MAX);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#include "dump.h"
#include <rmt.h>
#include <sys/mtio.h>
#include <limits.h>
#include <priv_utils.h>
#include "roll_log.h"
#include <unistd.h>
char *filesystem;
char *host;
char *debug_chdir;
char *dumpdev;
char *sdumpdev;
char *tlabel;
time_t *telapsed;
time_t *tstart_writing;
uchar_t *clrmap;
uchar_t *dirmap;
uchar_t *filmap;
uchar_t *nodmap;
uchar_t *shamap;
uchar_t *activemap;
int archive;
int autoload;
int autoload_period;
int autoload_tries;
int archive_opened;
int doingverify;
int disk_dynamic;
int dumpstate;
int dumptoarchive;
int fi;
int leftover;
int nadded;
int offline;
int verify;
uint_t etapes;
ulong_t tsize;
ino_t ino;
off_t pos;
pid_t dumppid;
u_offset_t esize;
union u_shadow c_shadow_save[1];
int notify = 0; /* notify operator flag */
int blockswritten = 0; /* number of blocks written on current tape */
uint_t tapeno = 0; /* current tape number */
daddr32_t filenum = 0; /* current file number on tape */
int density = 0; /* density in bytes/0.1" */
int tenthsperirg; /* inter-record-gap in 0.1"'s */
uint_t ntrec = 0; /* # tape blocks in each tape record */
uint_t saved_ntrec = 0; /* saved value of ntrec */
uint_t forceflag = 0; /* forced to change tp_bsize */
int cartridge = 0; /* assume non-cartridge tape */
uint_t tracks; /* # tracks on a cartridge tape */
int diskette = 0; /* assume not dumping to a diskette */
int printsize = 0; /* just print estimated size and exit */
int mapfd = -1; /* if >= 0, file descriptor for mmap */
int32_t tp_bsize = TP_BSIZE_MIN; /* tape block record size (frag size) */
#ifdef DEBUG
int xflag; /* debugging switch */
#endif
char *myname;
/*
* This should be struct fs, but there are trailing bits on disk
* that we also need to read in as part of it. It's an array of
* longs instead of char to force proper alignment.
*/
static long sblock_buf[SBSIZE/sizeof (long)];
#ifdef __STDC__
static char *mb(u_offset_t);
static void nextstate(int);
#else
static char *mb();
static void nextstate();
#endif
extern jmp_buf checkpoint_buf; /* context for return from checkpoint */
#define FUDGE_FACTOR 0x2000000
int
main(int argc, char *argv[])
{
char *arg;
int bflag = 0, i, error = 0, saverr;
double fetapes = 0.0;
struct mnttab *dt;
char msgbuf[3000], *msgp;
char kbsbuf[BUFSIZ];
u_offset_t esize_shift = 0;
int32_t new_mult = 0;
time32_t snapdate;
host = NULL;
if (myname = strrchr(argv[0], '/'))
myname++;
else
myname = argv[0];
if (strcmp("hsmdump", myname) == 0) {
msg(gettext("hsmdump emulation is no longer supported.\n"));
Exit(X_ABORT);
}
tape = DEFTAPE;
autoload_period = 12;
autoload_tries = 12; /* traditional default of ~2.5 minutes */
(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif /* TEXT_DOMAIN */
(void) textdomain(TEXT_DOMAIN);
/*
* If someone strips the set-uid bit, dump will still work for local
* tapes. Fail when we try to access a remote tape.
*/
(void) __init_suid_priv(0, PRIV_NET_PRIVADDR, (char *)NULL);
if (sysinfo(SI_HOSTNAME, spcl.c_host, sizeof (spcl.c_host)) < 0) {
saverr = errno;
msg(gettext("Could not get host name: %s\n"),
strerror(saverr));
bzero(spcl.c_host, sizeof (spcl.c_host));
}
dumppid = getpid();
tsize = 0; /* no default size, detect EOT dynamically */
archive_opened = 0;
disk = NULL;
dname = NULL;
disk_dynamic = 0;
increm = NINCREM;
incno = '9';
uflag = 0;
arg = "u";
tlabel = "none";
if (argc > 1) {
argv++;
argc--;
arg = *argv;
if (*arg == '-')
arg++;
}
while (*arg)
switch (*arg++) { /* BE CAUTIOUS OF FALLTHROUGHS */
case 'M':
/*
* This undocumented option causes each process to
* mkdir debug_chdir/getpid(), and chdir to it. This is
* to ease the collection of profiling information and
* core dumps.
*/
if (argc > 1) {
argv++;
argc--;
debug_chdir = *argv;
msg(gettext(
"Each process shall try to chdir to %s/<pid>\n"),
debug_chdir);
child_chdir();
} else {
msg(gettext("Missing move-to-dir (M) name\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'w':
lastdump('w'); /* tell us only what has to be done */
exit(0);
break;
case 'W': /* what to do */
lastdump('W'); /* tell state of what has been done */
exit(0); /* do nothing else */
break;
case 'T':
if (argc > 1) {
int count;
int multiplier;
char units;
argv++;
argc--;
count = atoi(*argv);
if (count < 1) {
msg(gettext(
"Unreasonable autoload timeout period\n"));
dumpabort();
/*NOTREACHED*/
}
units = *(*argv + strlen(*argv) - 1);
switch (units) {
case 's':
multiplier = 1;
break;
case 'h':
multiplier = 3600;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'm':
multiplier = 60;
break;
default:
msg(gettext(
"Unknown timeout units indicator `%c'\n"),
units);
dumpabort();
/*NOTREACHED*/
}
autoload_tries = 1 +
((count * multiplier) / autoload_period);
} else {
msg(gettext("Missing autoload timeout period\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'f': /* output file */
if (argc > 1) {
argv++;
argc--;
tape = *argv;
if (*tape == '\0') {
msg(gettext("Bad output device name\n"));
dumpabort();
/*NOTREACHED*/
}
} else {
msg(gettext("Missing output device name\n"));
dumpabort();
/*NOTREACHED*/
}
if (strcmp(tape, "-") == 0 && verify) {
msg(gettext(
"Cannot verify when dumping to standard out.\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'd': /* density, in bits per inch */
if (argc > 1) {
argv++;
argc--;
density = atoi(*argv) / 10;
if (density <= 0) {
msg(gettext(
"Density must be a positive integer\n"));
dumpabort();
/*NOTREACHED*/
}
} else {
msg(gettext("Missing density\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 's': /* tape size, feet */
if (argc > 1) {
argv++;
argc--;
tsize = atol(*argv);
if ((*argv[0] == '-') || (tsize == 0)) {
msg(gettext(
"Tape size must be a positive integer\n"));
dumpabort();
/*NOTREACHED*/
}
} else {
msg(gettext("Missing tape size\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 't': /* tracks */
if (argc > 1) {
argv++;
argc--;
tracks = atoi(*argv);
} else {
msg(gettext("Missing track count\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'b': /* blocks per tape write */
if (argc > 1) {
argv++;
argc--;
bflag++;
/*
* We save the ntrec in case we need to change
* tp_bsize later, we will have to recalculate
* it.
*/
saved_ntrec = ntrec = atoi(*argv);
if (ntrec == 0 || (ntrec&1) || ntrec > (MAXNTREC*2)) {
msg(gettext(
"Block size must be a positive, even integer <= %d\n"),
MAXNTREC*2);
dumpabort();
/*NOTREACHED*/
}
ntrec /= (tp_bsize/DEV_BSIZE);
} else {
msg(gettext("Missing blocking factor\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'c': /* Tape is cart. not 9-track */
case 'C': /* 'C' to be consistent with 'D' */
cartridge++;
break;
case '0': /* dump level */
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
incno = arg[-1];
break;
case 'u': /* update /etc/dumpdates */
uflag++;
break;
case 'n': /* notify operators */
notify++;
break;
case 'a': /* create archive file */
archive = 1;
if (argc > 1) {
argv++;
argc--;
if (**argv == '\0') {
msg(gettext("Bad archive file name\n"));
dumpabort();
/*NOTREACHED*/
}
archivefile = strdup(*argv);
if (archivefile == NULL) {
saverr = errno;
msg(gettext("Cannot allocate memory: %s\n"),
strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
} else {
msg(gettext("Missing archive file name\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'v':
verify++;
doingverify++;
if (strcmp(tape, "-") == 0) {
msg(gettext(
"Cannot verify when dumping to standard out.\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'D':
diskette++;
break;
case 'N':
if (argc > 1) {
argv++;
argc--;
if (**argv == '\0') {
msg(gettext("Missing name for dumpdates "
"entry.\n"));
dumpabort();
/*NOTREACHED*/
}
dname = *argv;
if (strlen(dname) > MAXNAMLEN + 2) {
msg(gettext("Dumpdates entry name too "
"long.\n"));
dumpabort();
/*NOTREACHED*/
}
for (i = 0; i < strlen(dname); i++) {
if (isspace(*(dname+i))) {
msg(gettext("Dumpdates entry name may "
"not contain white space.\n"));
dumpabort();
/*NOTREACHED*/
}
}
} else {
msg(gettext("Missing name for dumpdates entry.\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'L':
if (argc > 1) {
argv++;
argc--;
if (**argv == '\0') {
msg(gettext("Missing tape label name\n"));
dumpabort();
/*NOTREACHED*/
}
tlabel = *argv;
if (strlen(tlabel) > (sizeof (spcl.c_label) - 1)) {
tlabel[sizeof (spcl.c_label) - 1] = '\0';
msg(gettext(
"Truncating label to maximum supported length: `%s'\n"),
tlabel);
}
} else {
msg(gettext("Missing tape label name\n"));
dumpabort();
/*NOTREACHED*/
}
break;
case 'l':
autoload++;
break;
case 'o':
offline++;
break;
case 'S':
printsize++;
break;
#ifdef DEBUG
case 'z':
xflag++;
break;
#endif
default:
msg(gettext("Bad option `%c'\n"), arg[-1]);
dumpabort();
/*NOTREACHED*/
}
if (argc > 1) {
argv++;
argc--;
if (**argv == '\0') {
msg(gettext("Bad disk name\n"));
dumpabort();
/*NOTREACHED*/
}
disk = *argv;
disk_dynamic = 0;
}
if (disk == NULL) {
(void) fprintf(stderr, gettext(
"Usage: %s [0123456789fustdWwnNDCcbavloS [argument]] filesystem\n"),
myname);
Exit(X_ABORT);
}
if (!filenum)
filenum = 1;
if (signal(SIGINT, interrupt) == SIG_IGN)
(void) signal(SIGINT, SIG_IGN);
if (strcmp(tape, "-") == 0) {
pipeout++;
tape = gettext("standard output");
dumpdev = sdumpdev = strdup(tape);
if (dumpdev == NULL) {
saverr = errno;
msg(gettext("Cannot allocate memory: %s\n"),
strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
/*CONSTANTCONDITION*/
assert(sizeof (spcl.c_label) > 5);
(void) strcpy(spcl.c_label, "none");
} else if (*tape == '+') {
nextdevice();
(void) strcpy(spcl.c_label, tlabel);
} else {
/* if not already set, set diskette to default */
if (diskette && strcmp(tape, DEFTAPE) == 0)
tape = DISKETTE;
nextdevice();
(void) strcpy(spcl.c_label, tlabel);
}
if (cartridge && diskette) {
error = 1;
msg(gettext("Cannot select both cartridge and diskette\n"));
}
if (density && diskette) {
error = 1;
msg(gettext("Cannot select density of diskette\n"));
}
if (tracks && diskette) {
error = 1;
msg(gettext("Cannot select number of tracks of diskette\n"));
}
if (error) {
dumpabort();
/*NOTREACHED*/
}
/*
* Determine how to default tape size and density
*
* density tape size
* 9-track 1600 bpi (160 bytes/.1") 2300 ft.
* 9-track 6250 bpi (625 bytes/.1") 2300 ft.
*
* Most Sun-2's came with 4 track (20MB) cartridge tape drives,
* while most other machines (Sun-3's and non-Sun's) come with
* 9 track (45MB) cartridge tape drives. Some Sun-2's came with
* 9 track drives, but there is no way for the software to detect
* which drive type is installed. Sigh... We make the gross
* assumption that #ifdef mc68010 will test for a Sun-2.
*
* cartridge 8000 bpi (100 bytes/.1") 425 * tracks ft.
*/
if (density == 0)
density = cartridge ? 100 : 625;
if (tracks == 0)
tracks = 9;
if (!bflag) {
if (cartridge)
ntrec = CARTRIDGETREC;
else if (diskette)
ntrec = NTREC;
else if (density >= 625)
ntrec = HIGHDENSITYTREC;
else
ntrec = NTREC;
/*
* save ntrec in case we have to change tp_bsize later.
*/
saved_ntrec = (ntrec * (tp_bsize/DEV_BSIZE));
}
if (!diskette) {
tsize *= 12L*10L;
if (cartridge)
tsize *= tracks;
}
rmtinit(msg, Exit);
if (host) {
char *cp = strchr(host, '@');
if (cp == (char *)0)
cp = host;
else
cp++;
if (rmthost(host, ntrec) == 0) {
msg(gettext("Cannot connect to tape host `%s'\n"), cp);
dumpabort();
/*NOTREACHED*/
}
}
if (signal(SIGHUP, sigAbort) == SIG_IGN)
(void) signal(SIGHUP, SIG_IGN);
if (signal(SIGTRAP, sigAbort) == SIG_IGN)
(void) signal(SIGTRAP, SIG_IGN);
if (signal(SIGFPE, sigAbort) == SIG_IGN)
(void) signal(SIGFPE, SIG_IGN);
if (signal(SIGBUS, sigAbort) == SIG_IGN)
(void) signal(SIGBUS, SIG_IGN);
if (signal(SIGSEGV, sigAbort) == SIG_IGN)
(void) signal(SIGSEGV, SIG_IGN);
if (signal(SIGTERM, sigAbort) == SIG_IGN)
(void) signal(SIGTERM, SIG_IGN);
if (signal(SIGUSR1, sigAbort) == SIG_IGN)
(void) signal(SIGUSR1, SIG_IGN);
if (signal(SIGPIPE, sigAbort) == SIG_IGN)
(void) signal(SIGPIPE, SIG_IGN);
mnttabread(); /* /etc/fstab, /etc/mtab snarfed */
/*
* disk can be either the full special file name,
* the suffix of the special file name,
* the special name missing the leading '/',
* the file system name with or without the leading '/'.
* NB: we attempt to avoid dumping the block device
* (using rawname) because specfs and the vm system
* are not necessarily in sync.
*/
/*
* Attempt to roll the log if its root user before doing the dump.
* There's nothing the user can do if we are unable to roll the log,
* so we'll silently ignore failures.
*/
if (getuid() == 0 && rl_roll_log(disk) != RL_SUCCESS &&
disk[0] != '/') {
/* Try it again with leading '/'. */
char *slashed;
slashed = (char *)malloc(strlen(disk) + 2);
if (slashed != (char *)NULL) {
(void) sprintf(slashed, "%c%s", '/', disk);
(void) rl_roll_log(slashed);
free(slashed);
}
}
dt = mnttabsearch(disk, 0);
if (dt != 0) {
filesystem = dt->mnt_mountp;
if (disk_dynamic) {
/* LINTED: disk is not NULL */
free(disk);
}
disk = rawname(dt->mnt_special);
disk_dynamic = (disk != dt->mnt_special);
(void) strncpy(spcl.c_dev, dt->mnt_special,
sizeof (spcl.c_dev));
spcl.c_dev[sizeof (spcl.c_dev) - 1] = '\0';
(void) strncpy(spcl.c_filesys, dt->mnt_mountp,
sizeof (spcl.c_filesys));
spcl.c_filesys[sizeof (spcl.c_filesys) - 1] = '\0';
} else {
(void) strncpy(spcl.c_dev, disk, sizeof (spcl.c_dev));
spcl.c_dev[sizeof (spcl.c_dev) - 1] = '\0';
#ifdef PARTIAL
/* check for partial filesystem dump */
partial_check();
dt = mnttabsearch(disk, 1);
if (dt != 0) {
filesystem = dt->mnt_mountp;
if (disk_dynamic)
free(disk);
disk = rawname(dt->mnt_special);
disk_dynamic = (disk != dt->mnt_special);
(void) strncpy(spcl.c_filesys,
"a partial file system", sizeof (spcl.c_filesys));
spcl.c_filesys[sizeof (spcl.c_filesys) - 1] = '\0';
}
else
#endif /* PARTIAL */
{
char *old_disk = disk;
(void) strncpy(spcl.c_filesys,
"an unlisted file system",
sizeof (spcl.c_filesys));
spcl.c_filesys[sizeof (spcl.c_filesys) - 1] = '\0';
disk = rawname(old_disk);
if (disk != old_disk) {
if (disk_dynamic)
free(old_disk);
disk_dynamic = 1;
}
/*
* If disk == old_disk, then disk_dynamic's state
* does not change.
*/
}
}
fi = open64(disk, O_RDONLY);
if (fi < 0) {
saverr = errno;
msg(gettext("Cannot open dump device `%s': %s\n"),
disk, strerror(saverr));
Exit(X_ABORT);
}
if (sscanf(&incno, "%1d", &spcl.c_level) != 1) {
msg(gettext("Bad dump level `%c' specified\n"), incno);
dumpabort();
/*NOTREACHED*/
}
getitime(); /* /etc/dumpdates snarfed */
sblock = (struct fs *)&sblock_buf;
sync();
bread((diskaddr_t)SBLOCK, (uchar_t *)sblock, (long)SBSIZE);
if ((sblock->fs_magic != FS_MAGIC) &&
(sblock->fs_magic != MTB_UFS_MAGIC)) {
msg(gettext(
"Warning - super-block on device `%s' is corrupt - run fsck\n"),
disk);
dumpabort();
/*NOTREACHED*/
}
if (sblock->fs_magic == FS_MAGIC &&
(sblock->fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
sblock->fs_version != UFS_VERSION_MIN)) {
msg(gettext("Unrecognized UFS version: %d\n"),
sblock->fs_version);
dumpabort();
/*NOTREACHED*/
}
if (sblock->fs_magic == MTB_UFS_MAGIC &&
(sblock->fs_version < MTB_UFS_VERSION_MIN ||
sblock->fs_version > MTB_UFS_VERSION_1)) {
msg(gettext("Unrecognized UFS version: %d\n"),
sblock->fs_version);
dumpabort();
/*NOTREACHED*/
}
/*
* Try to set up for using mmap(2). It only works on the block
* device, but if we can use it, things go somewhat faster. If
* we can't open it, we'll silently fall back to the old method
* (read/memcpy). We also only try this if it's been cleanly
* unmounted. Dumping a live filesystem this way runs into
* buffer consistency problems. Of course, we don't support
* running dump on a mounted filesystem, but some people do it
* anyway.
*/
if (sblock->fs_clean == FSCLEAN) {
char *block = unrawname(disk);
if (block != NULL) {
mapfd = open(block, O_RDONLY, 0);
free(block);
}
}
restart:
bread((diskaddr_t)SBLOCK, (uchar_t *)sblock, (long)SBSIZE);
if ((sblock->fs_magic != FS_MAGIC) &&
(sblock->fs_magic != MTB_UFS_MAGIC)) { /* paranoia */
msg(gettext("bad super-block magic number, run fsck\n"));
dumpabort();
/*NOTREACHED*/
}
if (sblock->fs_magic == FS_MAGIC &&
(sblock->fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
sblock->fs_version != UFS_VERSION_MIN)) {
msg(gettext("Unrecognized UFS version: %d\n"),
sblock->fs_version);
dumpabort();
/*NOTREACHED*/
}
if (sblock->fs_magic == MTB_UFS_MAGIC &&
(sblock->fs_version < MTB_UFS_VERSION_MIN ||
sblock->fs_version > MTB_UFS_VERSION_1)) {
msg(gettext("Unrecognized UFS version: %d\n"),
sblock->fs_version);
dumpabort();
/*NOTREACHED*/
}
if (!doingactive)
allocino();
/* XXX should sanity-check the super block before trusting/using it */
/* LINTED XXX time truncated - tolerate until tape format changes */
spcl.c_date = (time32_t)time((time_t *)NULL);
bcopy(&(spcl.c_shadow), c_shadow_save, sizeof (c_shadow_save));
snapdate = is_fssnap_dump(disk);
if (snapdate)
spcl.c_date = snapdate;
if (!printsize) {
msg(gettext("Date of this level %c dump: %s\n"),
incno, prdate(spcl.c_date));
msg(gettext("Date of last level %c dump: %s\n"),
(uchar_t)lastincno, prdate(spcl.c_ddate));
msg(gettext("Dumping %s "), disk);
if (filesystem != 0)
msgtail("(%.*s:%s) ",
/* LINTED unsigned -> signed cast ok */
(int)sizeof (spcl.c_host), spcl.c_host, filesystem);
msgtail(gettext("to %s.\n"), sdumpdev);
}
esize = f_esize = o_esize = 0;
msiz = roundup(d_howmany(sblock->fs_ipg * sblock->fs_ncg, NBBY),
TP_BSIZE_MAX);
if (!doingactive) {
clrmap = (uchar_t *)xcalloc(msiz, sizeof (*clrmap));
filmap = (uchar_t *)xcalloc(msiz, sizeof (*filmap));
dirmap = (uchar_t *)xcalloc(msiz, sizeof (*dirmap));
nodmap = (uchar_t *)xcalloc(msiz, sizeof (*nodmap));
shamap = (uchar_t *)xcalloc(msiz, sizeof (*shamap));
activemap = (uchar_t *)xcalloc(msiz, sizeof (*activemap));
} else {
if (clrmap == NULL || filmap == NULL || dirmap == NULL ||
nodmap == NULL || shamap == NULL || activemap == NULL) {
msg(gettext(
"Internal error: NULL map pointer while re-dumping active files"));
dumpabort();
/*NOTREACHED*/
}
bzero(clrmap, msiz);
bzero(filmap, msiz);
bzero(dirmap, msiz);
bzero(nodmap, msiz);
bzero(shamap, msiz);
/* retain active map */
}
dumpstate = DS_INIT;
dumptoarchive = 1;
/*
* Read cylinder group inode-used bitmaps to avoid reading clear inodes.
*/
{
uchar_t *clrp = clrmap;
struct cg *cgp =
(struct cg *)xcalloc((uint_t)sblock->fs_cgsize, 1);
for (i = 0; i < sblock->fs_ncg; i++) {
bread(fsbtodb(sblock, cgtod(sblock, i)),
(uchar_t *)cgp, sblock->fs_cgsize);
bcopy(cg_inosused(cgp), clrp,
(int)sblock->fs_ipg / NBBY);
clrp += sblock->fs_ipg / NBBY;
}
free((char *)cgp);
/* XXX right-shift clrmap one bit. why? */
for (i = 0; clrp > clrmap; i <<= NBBY) {
i |= *--clrp & ((1<<NBBY) - 1);
*clrp = i >> 1;
}
}
if (!printsize) {
msgp = gettext("Mapping (Pass I) [regular files]\n");
msg(msgp);
}
ino = 0;
#ifdef PARTIAL
if (partial_mark(argc, argv)) {
#endif /* PARTIAL */
if (!doingactive)
pass(mark, clrmap); /* mark updates 'x'_esize */
else
pass(active_mark, clrmap); /* updates 'x'_esize */
#ifdef PARTIAL
}
#endif /* PARTIAL */
do {
if (!printsize) {
msgp = gettext("Mapping (Pass II) [directories]\n");
msg(msgp);
}
nadded = 0;
ino = 0;
pass(add, dirmap);
} while (nadded);
ino = 0; /* adjust estimated size for shadow inodes */
pass(markshad, nodmap);
ino = 0;
pass(estshad, shamap);
freeshad();
bmapest(clrmap);
bmapest(nodmap);
esize = o_esize + f_esize;
if (diskette) {
/* estimate number of floppies */
if (tsize != 0)
fetapes = (double)(esize + ntrec) / (double)tsize;
} else if (cartridge) {
/*
* Estimate number of tapes, assuming streaming stops at
* the end of each block written, and not in mid-block.
* Assume no erroneous blocks; this can be compensated for
* with an artificially low tape size.
*/
tenthsperirg = 16; /* actually 15.48, says Archive */
if (tsize != 0)
fetapes = ((double)esize /* blocks */
* (tp_bsize /* bytes/block */
* (1.0/density)) /* 0.1" / byte */
+
(double)esize /* blocks */
* (1.0/ntrec) /* streaming-stops per block */
* tenthsperirg) /* 0.1" / streaming-stop */
* (1.0 / tsize); /* tape / 0.1" */
} else {
/* Estimate number of tapes, for old fashioned 9-track tape */
#ifdef sun
/* sun has long irg's */
tenthsperirg = (density == 625) ? 6 : 12;
#else
tenthsperirg = (density == 625) ? 5 : 8;
#endif
if (tsize != 0)
fetapes = ((double)esize /* blocks */
* (tp_bsize /* bytes / block */
* (1.0/density)) /* 0.1" / byte */
+
(double)esize /* blocks */
* (1.0/ntrec) /* IRG's / block */
* tenthsperirg) /* 0.1" / IRG */
* (1.0 / tsize); /* tape / 0.1" */
}
etapes = fetapes; /* truncating assignment */
etapes++;
/* count the nodemap on each additional tape */
for (i = 1; i < etapes; i++)
bmapest(nodmap);
/*
* If the above bmapest is called, it changes o_esize and f_esize.
* So we will recalculate esize here anyway to make sure.
* Also, add tape headers and trailer records.
*/
esize = o_esize + f_esize + etapes + ntrec;
/*
* If the estimated number of tp_bsize tape blocks is greater than
* INT_MAX we have to adjust tp_bsize and ntrec to handle
* the larger dump. esize is an estimate, so we 'fudge'
* INT_MAX a little. If tp_bsize is adjusted, it will be adjusted
* to the size needed for this dump (2048, 4096, 8192, ...)
*/
if (esize > (INT_MAX - FUDGE_FACTOR)) { /* esize is too big */
forceflag++;
esize_shift =
((esize + (INT_MAX - FUDGE_FACTOR) - 1)/
((u_offset_t)(INT_MAX - FUDGE_FACTOR))) - 1;
if ((esize_shift > ESIZE_SHIFT_MAX) || (ntrec == 0)) {
msgp = gettext(
"Block factor %d ('b' flag) is too small for this size dump.");
msg(msgp, saved_ntrec);
dumpabort();
/*NOTREACHED*/
}
/*
* recalculate esize from:
* o_esize - header tape records
* (f_esize + (num_mult -1)) >> esize_shift - new non-header
* tape records for files/maps
* etapes - TS_TAPE records
* ntrec - TS_END records
*
* ntrec is adjusted so a tape record is still 'b' flag
* number of DEV_BSIZE (512) in size
*/
new_mult = (tp_bsize << esize_shift)/tp_bsize;
tp_bsize = (tp_bsize << esize_shift);
esize = o_esize + ((f_esize +
(new_mult - 1)) >> esize_shift) + etapes + ntrec;
ntrec = (saved_ntrec/(tp_bsize/DEV_BSIZE));
}
if (forceflag != 0) {
msgp = gettext(
"Forcing larger tape block size (%d).\n");
msg(msgp, tp_bsize);
}
alloctape(); /* allocate tape buffers */
assert((tp_bsize / DEV_BSIZE != 0) && (tp_bsize % DEV_BSIZE == 0));
/*
* If all we wanted was the size estimate,
* just print it out and exit.
*/
if (printsize) {
(void) printf("%llu\n", esize * tp_bsize);
Exit(0);
}
if (tsize != 0) {
if (diskette)
msgp = gettext(
"Estimated %lld blocks (%s) on %3.2f diskettes.\n");
else
msgp = gettext(
"Estimated %lld blocks (%s) on %3.2f tapes.\n");
msg(msgp,
(esize*(tp_bsize/DEV_BSIZE)), mb(esize), fetapes);
} else {
msgp = gettext("Estimated %lld blocks (%s).\n");
msg(msgp, (esize*(tp_bsize/DEV_BSIZE)), mb(esize));
}
dumpstate = DS_CLRI;
otape(1); /* bitmap is the first to tape write */
*telapsed = 0;
(void) time(tstart_writing);
/* filmap indicates all non-directory inodes */
{
uchar_t *np, *fp, *dp;
np = nodmap;
dp = dirmap;
fp = filmap;
for (i = 0; i < msiz; i++)
*fp++ = *np++ ^ *dp++;
}
while (dumpstate != DS_DONE) {
/*
* When we receive EOT notification from
* the writer, the signal handler calls
* rollforward and then jumps here.
*/
(void) setjmp(checkpoint_buf);
switch (dumpstate) {
case DS_INIT:
/*
* We get here if a tape error occurred
* after releasing the name lock but before
* the volume containing the last of the
* dir info was completed. We have to start
* all over in this case.
*/
{
char *rmsg = gettext(
"Warning - output error occurred after releasing name lock\n\
\tThe dump will restart\n");
msg(rmsg);
goto restart;
}
/* NOTREACHED */
case DS_START:
case DS_CLRI:
ino = UFSROOTINO;
dumptoarchive = 1;
bitmap(clrmap, TS_CLRI);
nextstate(DS_BITS);
/* FALLTHROUGH */
case DS_BITS:
ino = UFSROOTINO;
dumptoarchive = 1;
if (BIT(UFSROOTINO, nodmap)) /* empty dump check */
bitmap(nodmap, TS_BITS);
nextstate(DS_DIRS);
if (!doingverify) {
msgp = gettext(
"Dumping (Pass III) [directories]\n");
msg(msgp);
}
/* FALLTHROUGH */
case DS_DIRS:
dumptoarchive = 1;
pass(dirdump, dirmap);
nextstate(DS_FILES);
if (!doingverify) {
msgp = gettext(
"Dumping (Pass IV) [regular files]\n");
msg(msgp);
}
/* FALLTHROUGH */
case DS_FILES:
dumptoarchive = 0;
pass(lf_dump, filmap);
flushcmds();
dumpstate = DS_END; /* don't reset ino */
/* FALLTHROUGH */
case DS_END:
dumptoarchive = 1;
spcl.c_type = TS_END;
for (i = 0; i < ntrec; i++) {
spclrec();
}
flusht();
break;
case DS_DONE:
break;
default:
msg(gettext("Internal state error\n"));
dumpabort();
/*NOTREACHED*/
}
}
if ((! doingactive) && (! active))
trewind();
if (verify && !doingverify) {
msgp = gettext("Finished writing last dump volume\n");
msg(msgp);
Exit(X_VERIFY);
}
if (spcl.c_volume > 1)
(void) snprintf(msgbuf, sizeof (msgbuf),
gettext("%lld blocks (%s) on %ld volumes"),
((uint64_t)spcl.c_tapea*(tp_bsize/DEV_BSIZE)),
mb((u_offset_t)(unsigned)(spcl.c_tapea)),
spcl.c_volume);
else
(void) snprintf(msgbuf, sizeof (msgbuf),
gettext("%lld blocks (%s) on 1 volume"),
((uint64_t)spcl.c_tapea*(tp_bsize/DEV_BSIZE)),
mb((u_offset_t)(unsigned)(spcl.c_tapea)));
if (timeclock((time_t)0) != (time_t)0) {
(void) snprintf(kbsbuf, sizeof (kbsbuf),
gettext(" at %ld KB/sec"),
(long)(((float)spcl.c_tapea / (float)timeclock((time_t)0))
* 1000.0));
(void) strcat(msgbuf, kbsbuf);
}
(void) strcat(msgbuf, "\n");
msg(msgbuf);
(void) timeclock((time_t)-1);
if (archive)
msg(gettext("Archiving dump to `%s'\n"), archivefile);
if (active && !verify) {
nextstate(DS_INIT);
activepass();
goto restart;
}
msgp = gettext("DUMP IS DONE\n");
msg(msgp);
broadcast(msgp);
if (! doingactive)
putitime();
Exit(X_FINOK);
/*NOTREACHED*/
return (0);
}
void
sigAbort(int sig)
{
char *sigtype;
switch (sig) {
case SIGHUP:
sigtype = "SIGHUP";
break;
case SIGTRAP:
sigtype = "SIGTRAP";
break;
case SIGFPE:
sigtype = "SIGFPE";
break;
case SIGBUS:
msg(gettext("%s ABORTING!\n"), "SIGBUS()");
(void) signal(SIGUSR2, SIG_DFL);
abort();
/*NOTREACHED*/
case SIGSEGV:
msg(gettext("%s ABORTING!\n"), "SIGSEGV()");
(void) signal(SIGUSR2, SIG_DFL);
abort();
/*NOTREACHED*/
case SIGALRM:
sigtype = "SIGALRM";
break;
case SIGTERM:
sigtype = "SIGTERM";
break;
case SIGPIPE:
msg(gettext("Broken pipe\n"));
dumpabort();
/*NOTREACHED*/
default:
sigtype = "SIGNAL";
break;
}
msg(gettext("%s() try rewriting\n"), sigtype);
if (pipeout) {
msg(gettext("Unknown signal, Cannot recover\n"));
dumpabort();
/*NOTREACHED*/
}
msg(gettext("Rewriting attempted as response to unknown signal.\n"));
(void) fflush(stderr);
(void) fflush(stdout);
close_rewind();
Exit(X_REWRITE);
}
/* Note that returned value is malloc'd if != cp && != NULL */
char *
rawname(char *cp)
{
struct stat64 st;
char *dp;
extern char *getfullrawname();
if (stat64(cp, &st) < 0 || (st.st_mode & S_IFMT) != S_IFBLK)
return (cp);
dp = getfullrawname(cp);
if (dp == 0)
return (0);
if (*dp == '\0') {
free(dp);
return (0);
}
if (stat64(dp, &st) < 0 || (st.st_mode & S_IFMT) != S_IFCHR) {
free(dp);
return (cp);
}
return (dp);
}
static char *
mb(u_offset_t blks)
{
static char buf[16];
if (blks < 1024)
(void) snprintf(buf, sizeof (buf), "%lldKB", blks);
else
(void) snprintf(buf, sizeof (buf), "%.2fMB",
((double)(blks*tp_bsize)) / (double)(1024*1024));
return (buf);
}
#ifdef signal
void (*nsignal(int sig, void (*act)(int)))(int)
{
struct sigaction sa, osa;
sa.sa_handler = act;
(void) sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if (sigaction(sig, &sa, &osa) < 0)
return ((void (*)(int))-1);
return (osa.sa_handler);
}
#endif
static void
nextstate(int state)
{
/* LINTED assigned value never used - kept for documentary purposes */
dumpstate = state;
/* LINTED assigned value never used - kept for documentary purposes */
ino = 0;
/* LINTED assigned value never used - kept for documentary purposes */
pos = 0;
leftover = 0;
}
/*
* timeclock() function, for keeping track of how much time we've spent
* writing to the tape device. it always returns the amount of time
* already spent, in milliseconds. if you pass it a positive, then that's
* telling it that we're writing, so the time counts. if you pass it a
* zero, then that's telling it we're not writing; perhaps we're waiting
* for user input.
*
* a state of -1 resets everything.
*/
time32_t
timeclock(time32_t state)
{
static int *currentState = NULL;
static struct timeval *clockstart;
static time32_t *emilli;
struct timeval current[1];
int fd, saverr;
#ifdef DEBUG
fprintf(stderr, "pid=%d timeclock ", getpid());
if (state == (time32_t)-1)
fprintf(stderr, "cleared\n");
else if (state > 0)
fprintf(stderr, "ticking\n");
else
fprintf(stderr, "paused\n");
#endif /* DEBUG */
/* if we haven't setup the shared memory, init */
if (currentState == (int *)NULL) {
if ((fd = open("/dev/zero", O_RDWR)) < 0) {
saverr = errno;
msg(gettext("Cannot open `%s': %s\n"),
"/dev/zero", strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
/*LINTED [mmap always returns an aligned value]*/
currentState = (int *)mmap((char *)0, getpagesize(),
PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)0);
if (currentState == (int *)-1) {
saverr = errno;
msg(gettext(
"Cannot memory map monitor variables: %s\n"),
strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
(void) close(fd);
/* LINTED currentState is sufficiently aligned */
clockstart = (struct timeval *)(currentState + 1);
emilli = (time32_t *)(clockstart + 1);
/* Note everything is initialized to zero via /dev/zero */
}
if (state == (time32_t)-1) {
bzero(clockstart, sizeof (*clockstart));
*currentState = 0;
*emilli = (time32_t)0;
return (0);
}
(void) gettimeofday(current, NULL);
if (*currentState != 0) {
current->tv_usec += 1000000;
current->tv_sec--;
/* LINTED: result will fit in a time32_t */
*emilli += (current->tv_sec - clockstart->tv_sec) * 1000;
/* LINTED: result will fit in a time32_t */
*emilli += (current->tv_usec - clockstart->tv_usec) / 1000;
}
if (state != 0)
bcopy(current, clockstart, sizeof (current));
*currentState = state;
return (*emilli);
}
static int
statcmp(const struct stat64 *left, const struct stat64 *right)
{
int result = 1;
if ((left->st_dev == right->st_dev) &&
(left->st_ino == right->st_ino) &&
(left->st_mode == right->st_mode) &&
(left->st_nlink == right->st_nlink) &&
(left->st_uid == right->st_uid) &&
(left->st_gid == right->st_gid) &&
(left->st_rdev == right->st_rdev) &&
(left->st_ctim.tv_sec == right->st_ctim.tv_sec) &&
(left->st_ctim.tv_nsec == right->st_ctim.tv_nsec) &&
(left->st_mtim.tv_sec == right->st_mtim.tv_sec) &&
(left->st_mtim.tv_nsec == right->st_mtim.tv_nsec)) {
/*
* Unlike in the ufsrestore version
* st_blocks and st_blksiz are not
* compared. The reason for this is
* problems with zfs dump files. Zfs
* changes it's statistics in those
* fields.
*/
result = 0;
}
return (result);
}
/*
* Safely open a file or device.
*/
static int
safe_open_common(const char *filename, int mode, int perms, int device)
{
int fd;
int working_mode;
int saverr;
char *errtext;
struct stat64 pre_stat, pre_lstat;
struct stat64 post_stat, post_lstat;
/*
* Don't want to be spoofed into trashing something we
* shouldn't, thus the following rigamarole. If it doesn't
* exist, we create it and proceed. Otherwise, require that
* what's there be a real file with no extraneous links and
* owned by whoever ran us.
*
* The silliness with using both lstat() and fstat() is to avoid
* race-condition games with someone replacing the file with a
* symlink after we've opened it. If there was an flstat(),
* we wouldn't need the fstat().
*
* The initial open with the hard-coded flags is ok even if we
* are intending to open only for reading. If it succeeds,
* then the file did not exist, and we'll synthesize an appropriate
* complaint below. Otherwise, it does exist, so we won't be
* truncating it with the open.
*/
if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_LARGEFILE,
perms)) < 0) {
if (errno == EEXIST) {
if (lstat64(filename, &pre_lstat) < 0) {
return (-1);
}
if (stat64(filename, &pre_stat) < 0) {
return (-1);
}
working_mode = mode & (O_WRONLY|O_RDWR|O_RDONLY);
working_mode |= O_LARGEFILE;
if ((fd = open(filename, working_mode)) < 0) {
if (errno == ENOENT) {
errtext = gettext(
"Unexpected condition detected: %s used to exist, but doesn't any longer\n");
msg(errtext, filename);
syslog(LOG_WARNING, errtext, filename);
errno = ENOENT;
}
return (-1);
}
if (lstat64(filename, &post_lstat) < 0) {
saverr = errno;
(void) close(fd);
errno = saverr;
return (-1);
}
if (fstat64(fd, &post_stat) < 0) {
saverr = errno;
(void) close(fd);
errno = saverr;
return (-1);
}
/*
* Can't just use memcmp(3C), because the access
* time is updated by open(2).
*/
if (statcmp(&pre_lstat, &post_lstat) != 0) {
errtext = gettext("Unexpected change detected: "
"%s's lstat(2) information changed\n");
msg(errtext, filename);
syslog(LOG_WARNING, errtext, filename);
errno = EPERM;
return (-1);
}
if (statcmp(&pre_stat, &post_stat) != 0) {
errtext = gettext("Unexpected change detected: "
"%s's stat(2) information changed\n"),
msg(errtext, filename);
syslog(LOG_WARNING, errtext, filename);
errno = EPERM;
return (-1);
}
/*
* If inode, device, or type are wrong, bail out.
* Note using post_stat instead of post_lstat for the
* S_ISCHR() test. This is to allow the /dev ->
* /devices bit to work, as long as the final target
* is a character device (i.e., raw disk or tape).
*/
if (device && !(S_ISCHR(post_stat.st_mode)) &&
!(S_ISFIFO(post_stat.st_mode)) &&
!(S_ISREG(post_lstat.st_mode))) {
errtext = gettext("Unexpected condition "
"detected: %s is not a supported device\n"),
msg(errtext, filename);
syslog(LOG_WARNING, errtext, filename);
(void) close(fd);
errno = EPERM;
return (-1);
} else if (!device &&
(!S_ISREG(post_lstat.st_mode) ||
(post_stat.st_ino != post_lstat.st_ino) ||
(post_stat.st_dev != post_lstat.st_dev))) {
errtext = gettext("Unexpected condition "
"detected: %s is not a regular file\n"),
msg(errtext, filename);
syslog(LOG_WARNING, errtext, filename);
(void) close(fd);
errno = EPERM;
return (-1);
}
/*
* Bad link count implies someone's linked our
* target to something else, which we probably
* shouldn't step on.
*/
if (post_lstat.st_nlink != 1) {
errtext = gettext("Unexpected condition "
"detected: %s must have exactly one "
"link\n"), msg(errtext, filename);
syslog(LOG_WARNING, errtext, filename);
(void) close(fd);
errno = EPERM;
return (-1);
}
/*
* Root might make a file, but non-root might
* need to open it. If the permissions let us
* get this far, then let it through.
*/
if (post_lstat.st_uid != getuid() &&
post_lstat.st_uid != 0) {
errtext = gettext("Unsupported "
"condition detected: %s "
"must be owned by uid %ld or 0\n"),
msg(errtext, filename, (long)getuid());
syslog(LOG_WARNING, errtext, filename,
(long)getuid());
(void) close(fd);
errno = EPERM;
return (-1);
}
if (mode & O_TRUNC) {
if (ftruncate(fd, (off_t)0) < 0) {
msg("ftruncate(%s): %s\n",
filename, strerror(errno));
(void) close(fd);
return (-1);
}
}
} else {
/*
* Didn't exist, but couldn't open it.
*/
return (-1);
}
} else {
/*
* If truncating open succeeded for a read-only open,
* bail out, as we really shouldn't have succeeded.
*/
if (mode & O_RDONLY) {
/* Undo the O_CREAT */
(void) unlink(filename);
msg("open(%s): %s\n",
filename, strerror(ENOENT));
(void) close(fd);
errno = ENOENT;
return (-1);
}
}
return (fd);
}
/*
* Safely open a file.
*/
int
safe_file_open(const char *filename, int mode, int perms)
{
return (safe_open_common(filename, mode, perms, 0));
}
/*
* Safely open a device.
*/
int
safe_device_open(const char *filename, int mode, int perms)
{
return (safe_open_common(filename, mode, perms, 1));
}
/*
* STDIO version of safe_open
*/
FILE *
safe_fopen(const char *filename, const char *smode, int perms)
{
int fd;
int bmode;
/*
* accepts only modes "r", "r+", and "w"
*/
if (smode[0] == 'r') {
if (smode[1] == '\0') {
bmode = O_RDONLY;
} else if ((smode[1] == '+') && (smode[2] == '\0')) {
bmode = O_RDWR;
}
} else if ((smode[0] == 'w') && (smode[1] == '\0')) {
bmode = O_WRONLY;
} else {
msg(gettext("internal error: safe_fopen: invalid mode `%s'\n"),
smode);
return (NULL);
}
fd = safe_file_open(filename, bmode, perms);
/*
* caller is expected to report error.
*/
if (fd >= 0)
return (fdopen(fd, smode));
return ((FILE *)NULL);
}
void
child_chdir(void)
{
char name[MAXPATHLEN];
if (debug_chdir != NULL) {
snprintf(name, sizeof (name), "%s/%ld",
debug_chdir, (long)getpid());
if (mkdir(name, 0755) < 0)
msg("mkdir(%s): %s", name, strerror(errno));
if (chdir(name) < 0)
msg("chdir(%s): %s", name, strerror(errno));
}
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1991,1996,1998 by Sun Microsystems, Inc.
* All rights reserved.
*/
#include "dump.h"
#include <math.h>
#include <limits.h>
/*
* Uncomment if using mmap'ing of files for pre-fetch.
* #define ENABLE_MMAP 1
*/
struct inodesc {
ino_t id_inumber; /* inode number */
long id_gen; /* generation number */
struct inodesc *id_next; /* next on linked list */
};
char *archivefile;
char *tape;
int active;
int doingactive;
int doposition;
int pipeout;
int tapeout;
int to;
struct fs *sblock;
union u_spcl u_spcl;
static struct inodesc ilist; /* list of used inodesc structs */
static struct inodesc *last; /* last inodesc init'd or matched */
static struct inodesc *freeinodesc; /* free list of inodesc structs */
static struct inodesc **ialloc; /* allocated chunks, for freeing */
static int nchunks; /* number of allocations */
#ifdef ENABLE_MMAP /* XXX part of mmap support */
/*
* If an mmap'ed file is truncated as it is being dumped or
* faulted in, we are delivered a SIGBUS.
*/
static jmp_buf truncate_buf;
static void (*savebus)();
static int incopy;
static void onsigbus(int);
#endif /* ENABLE_MMAP */
#ifdef DEBUG
extern int xflag;
#endif
#ifdef ENABLE_MMAP /* XXX part of mmap support */
static void
onsigbus(int sig)
{
if (!incopy) {
dumpabort();
/*NOTREACHED*/
}
incopy = 0;
longjmp(truncate_buf, 1);
/*NOTREACHED*/
}
#endif /* ENABLE_MMAP */
void
allocino(void)
{
ino_t maxino;
size_t nused;
maxino = (unsigned)(sblock->fs_ipg * sblock->fs_ncg);
if (maxino > ULONG_MAX) {
msg(gettext("allocino: filesystem too large\n"));
dumpabort();
/*NOTREACHED*/
}
/* LINTED maxino guaranteed to fit into a size_t by above test */
nused = maxino - sblock->fs_cstotal.cs_nifree;
freeinodesc = (struct inodesc *)xcalloc(nused, sizeof (*freeinodesc));
if (freeinodesc == (struct inodesc *)0) {
msg(gettext("%s: out of memory\n"), "allocino");
dumpabort();
/*NOTREACHED*/
}
last = &ilist;
ialloc =
(struct inodesc **)xmalloc(2*sizeof (*ialloc));
ialloc[0] = freeinodesc;
ialloc[1] = (struct inodesc *)0;
nchunks = 1;
}
void
freeino(void)
{
int i;
if (ialloc == (struct inodesc **)0)
return;
for (i = 0; i < nchunks; i++)
if (ialloc[i] != 0)
free(ialloc[i]);
free(ialloc);
ialloc = (struct inodesc **)0;
}
void
resetino(ino_t ino)
{
last = ilist.id_next;
while (last && last->id_inumber < ino)
last = last->id_next;
}
char *
unrawname(char *cp)
{
char *dp;
extern char *getfullblkname();
dp = getfullblkname(cp);
if (dp == 0)
return (0);
if (*dp == '\0') {
free(dp);
return (0);
}
if (dp == cp) /* caller wants to always free() dp */
dp = strdup(cp);
return (dp);
}
/*
* Determine if specified device is mounted at
* specified mount point. Returns 1 if mounted,
* 0 if not mounted, -1 on error.
*/
int
lf_ismounted(char *devname, char *dirname)
{
struct stat64 st;
char *blockname; /* name of block device */
dev_t dev;
int saverr;
if ((blockname = unrawname(devname)) == NULL) {
msg(gettext("Cannot obtain block name from `%s'\n"), devname);
return (-1);
}
if (stat64(blockname, &st) < 0) {
saverr = errno;
msg(gettext("Cannot obtain status of device `%s': %s\n"),
blockname, strerror(saverr));
free(blockname);
return (-1);
}
free(blockname);
dev = st.st_rdev;
if (stat64(dirname, &st) < 0) {
saverr = errno;
msg(gettext("Cannot obtain status of device `%s': %s\n"),
dirname, strerror(saverr));
return (-1);
}
if (dev == st.st_dev)
return (1);
return (0);
}
#ifdef ENABLE_MMAP /* XXX mapped-file support */
#define MINMAPSIZE 1024*1024
#define MAXMAPSIZE 1024*1024*32
static caddr_t mapbase; /* base of mapped data */
static caddr_t mapend; /* last byte of mapped data */
static size_t mapsize; /* amount of mapped data */
/*
* Map a file prior to dumping and start faulting in its
* pages. Stop if we catch a signal indicating our turn
* to dump has arrived. If the file is truncated out from
* under us, immediately return.
* NB: the base of the mapped data may not coincide
* exactly to the requested offset, due to alignment
* constraints.
*/
caddr_t
mapfile(int fd, off_t offset, off_t bytes, int fetch)
{
/*LINTED [c used during pre-fetch faulting]*/
volatile char c, *p;
int stride = (int)sysconf(_SC_PAGESIZE);
extern int caught; /* pre-fetch until set */
caddr_t mapstart; /* beginning of file's mapped data */
off_t mapoffset; /* page-aligned offset */
int saverr;
mapbase = mapend = (caddr_t)0;
if (bytes == 0)
return ((caddr_t)0);
/*
* mmap the file for reading
*/
mapoffset = offset & ~(stride - 1);
/* LINTED: "bytes" will always fit into a size_t */
mapsize = bytes + (offset - mapoffset);
if (mapsize > MAXMAPSIZE)
mapsize = MAXMAPSIZE;
while ((mapbase = mmap((caddr_t)0, mapsize, PROT_READ,
MAP_SHARED, fd, mapoffset)) == (caddr_t)-1 &&
errno == ENOMEM && mapsize >= MINMAPSIZE) {
/*
* Due to address space limitations, we
* may not be able to map as much as we want.
*/
mapsize /= 2; /* exponential back-off */
}
if (mapbase == (caddr_t)-1) {
saverr = errno;
msg(gettext("Cannot map file at inode `%lu' into memory: %s\n"),
ino, strerror(saverr));
/* XXX why not call dumpailing() here? */
if (!query(gettext(
"Do you want to attempt to continue? (\"yes\" or \"no\") "))) {
dumpabort();
/*NOTREACHED*/
}
mapbase = (caddr_t)0;
return ((caddr_t)0);
}
(void) madvise(mapbase, mapsize, MADV_SEQUENTIAL);
mapstart = mapbase + (offset - mapoffset);
mapend = mapbase + (mapsize - 1);
if (!fetch)
return (mapstart);
if (setjmp(truncate_buf) == 0) {
savebus = signal(SIGBUS, onsigbus);
/*
* Touch each page to pre-fetch by faulting. At least
* one of c or *p must be declared volatile, lest the
* optimizer eliminate the assignment in the loop.
*/
incopy = 1;
for (p = mapbase; !caught && p <= mapend; p += stride) {
/* LINTED: c is used for its side-effects */
c = *p;
}
incopy = 0;
}
#ifdef DEBUG
else
/* XGETTEXT: #ifdef DEBUG only */
msg(gettext(
"FILE TRUNCATED (fault): Interrupting pre-fetch\n"));
#endif
(void) signal(SIGBUS, savebus);
return (mapstart);
}
void
unmapfile(void)
{
if (mapbase) {
/* XXX we're unmapping it, so what does this gain us? */
(void) msync(mapbase, mapsize, MS_ASYNC|MS_INVALIDATE);
(void) munmap(mapbase, mapsize);
mapbase = (caddr_t)0;
}
}
#endif /* ENABLE_MMAP */
void
activepass(void)
{
static int passno = 1; /* active file pass number */
char *ext, *old;
char buf[3000];
static char defext[] = ".retry";
if (pipeout) {
msg(gettext("Cannot re-dump active files to `%s'\n"), tape);
dumpabort();
/*NOTREACHED*/
}
if (active > 1)
(void) snprintf(buf, sizeof (buf), gettext(
"%d files were active and will be re-dumped\n"), active);
else
(void) snprintf(buf, sizeof (buf), gettext(
"1 file was active and will be re-dumped\n"));
msg(buf);
doingactive++;
active = 0;
reset(); /* reset tape params */
spcl.c_ddate = spcl.c_date; /* chain with last dump/pass */
/*
* If archiving, create a new
* archive file.
*/
if (archivefile) {
old = archivefile;
ext = strstr(old, defext);
if (ext != (char *)NULL)
*ext = '\0'; /* just want the base name */
/* The two is for the trailing \0 and rounding up log10() */
archivefile = xmalloc(strlen(old) + strlen(defext) +
(int)log10((double)passno) + 2);
/* Always fits */
(void) sprintf(archivefile, "%s%s%d", old, defext, passno);
free(old);
}
if (tapeout) {
if (isrewind(to)) {
/*
* A "rewind" tape device. When we do
* the close, we will lose our position.
* Be nice and switch volumes.
*/
(void) snprintf(buf, sizeof (buf), gettext(
"Warning - cannot dump active files to rewind "
"device `%s'\n"), tape);
msg(buf);
close_rewind();
changevol();
} else {
trewind();
doposition = 0;
filenum++;
}
} else {
/*
* Not a tape. Do a volume switch.
* This will advance to the next file
* if using a sequence of files, next
* diskette if using diskettes, or
* let the user move the old file out
* of the way.
*/
close_rewind();
changevol(); /* switch files */
}
(void) snprintf(buf, sizeof (buf), gettext(
"Dumping active files (retry pass %d) to `%s'\n"), passno, tape);
msg(buf);
passno++;
}
/*
* Copyright (c) 1998 by Sun Microsystems, Inc.
* All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#include <errno.h>
#include "dump.h"
time_t *tschedule;
static unsigned int timeout; /* current timeout */
static char *attnmessage, *saveattn; /* attention message */
static void alarmcatch(int);
static int idatesort(const void *, const void *);
#ifdef DEBUG
extern int xflag;
#endif
/*
* Query the operator; This fascist piece of code requires
* an exact response.
* It is intended to protect dump aborting by inquisitive
* people banging on the console terminal to see what is
* happening which might cause dump to croak, destroying
* a large number of hours of work.
*
* Every time += 2 minutes we reprint the message, alerting others
* that dump needs attention.
*/
int
query(char *question)
{
int def = -1;
while (def == -1)
def = query_once(question, -1);
return (def);
}
static int in_query_once;
static jmp_buf sjalarmbuf;
/* real simple check-sum */
static int
addem(char *s)
{
int total = 0;
if (s == (char *)NULL)
return (total);
while (*s)
total += *s++;
return (total);
}
int
query_once(char *question, int def)
{
static char *lastmsg;
static int lastmsgsum;
int msgsum;
char replybuffer[BUFSIZ];
int back;
time32_t timeclockstate;
pollfd_t pollset;
struct sigvec sv;
/* special hook to flush timeout cache */
if (question == NULL) {
lastmsg = (char *)NULL;
lastmsgsum = 0;
return (0);
}
attnmessage = question;
/*
* Only reset the state if the message changed somehow
*/
msgsum = addem(question);
if (lastmsg != question || lastmsgsum != msgsum) {
timeout = 0;
if (telapsed && tstart_writing)
*telapsed += time((time_t *)0) - *tstart_writing;
lastmsg = question;
lastmsgsum = msgsum;
}
timeclockstate = timeclock((time_t)0);
if (setjmp(sjalarmbuf) != 0) {
if (def != -1) {
if (def)
msgtail(gettext("YES\n"));
else
msgtail(gettext("NO\n"));
}
back = def;
goto done;
}
alarmcatch(SIGALRM);
in_query_once = 1;
pollset.fd = -1;
pollset.events = 0;
pollset.revents = 0;
if (isatty(fileno(stdin))) {
pollset.fd = fileno(stdin);
pollset.events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND;
} else {
dumpabort();
/*NOTREACHED*/
}
for (;;) {
if (poll(&pollset, 1, -1) < 0) {
if (errno == EINTR)
continue;
perror("poll(stdin)");
dumpabort();
/*NOTREACHED*/
}
if (pollset.revents == 0)
continue; /* sanity check */
if (fgets(replybuffer, sizeof (replybuffer), stdin) == NULL) {
if (ferror(stdin)) {
clearerr(stdin);
continue;
} else {
dumpabort();
/*NOTREACHED*/
}
}
timeout = 0;
if (strcasecmp(replybuffer, gettext("yes\n")) == 0) {
back = 1;
lastmsg = (char *)NULL;
lastmsgsum = 0;
goto done;
} else if (strcasecmp(replybuffer, gettext("no\n")) == 0) {
back = 0;
lastmsg = (char *)NULL;
lastmsgsum = 0;
goto done;
} else {
msg(gettext("\"yes\" or \"no\"?\n"));
in_query_once = 0;
alarmcatch(SIGALRM);
in_query_once = 1;
}
}
done:
/*
* Turn off the alarm, and reset the signal to trap out..
*/
(void) alarm(0);
attnmessage = NULL;
sv.sv_handler = sigAbort;
sv.sv_flags = SA_RESTART;
(void) sigemptyset(&sv.sa_mask);
(void) sigvec(SIGALRM, &sv, (struct sigvec *)0);
if (tstart_writing)
(void) time(tstart_writing);
(void) timeclock(timeclockstate);
in_query_once = 0;
return (back);
}
/*
* Alert the console operator, and enable the alarm clock to
* sleep for time += 2 minutes in case nobody comes to satisfy dump
* If the alarm goes off while in the query_once for loop, we just
* longjmp back there and return the default answer.
*/
static void
alarmcatch(int signal __unused)
{
struct sigvec sv;
if (in_query_once) {
longjmp(sjalarmbuf, 1);
}
if (timeout) {
msgtail("\n");
}
timeout += 120;
msg(gettext("NEEDS ATTENTION: %s"), attnmessage);
sv.sv_handler = alarmcatch;
sv.sv_flags = SA_RESTART;
(void) sigemptyset(&sv.sa_mask);
(void) sigvec(SIGALRM, &sv, (struct sigvec *)0);
(void) alarm(timeout);
}
/*
* Here if an inquisitive operator interrupts the dump program
*/
/*ARGSUSED*/
void
interrupt(int sig)
{
if (!saveattn) {
saveattn = attnmessage;
}
msg(gettext("Interrupt received.\n"));
if (query(gettext(
"Do you want to abort dump?: (\"yes\" or \"no\") "))) {
dumpabort();
/*NOTREACHED*/
}
if (saveattn) {
attnmessage = saveattn;
saveattn = NULL;
alarmcatch(SIGALRM);
}
}
/*
* We use wall(8) to do the actual broadcasting, so
* that we don't have to worry about duplicated code
* only getting fixed in one place. This also saves
* us from having to worry about process groups,
* controlling terminals, and the like.
*/
void
broadcast(char *message)
{
time_t clock;
pid_t pid;
int saverr;
int fildes[2];
FILE *wall;
struct tm *localclock;
if (!notify)
return;
if (pipe(fildes) < 0) {
saverr = errno;
msg(gettext("pipe: %s\n"), strerror(saverr));
return;
}
switch (pid = fork()) {
case -1:
return;
case 0:
close(fildes[0]);
if (dup2(fildes[1], 0) < 0) {
saverr = errno;
msg(gettext("dup2: %s\n"), strerror(saverr));
exit(1);
}
execl("/usr/sbin/wall", "wall", "-g", OPGRENT, (char *)NULL);
saverr = errno;
msg(gettext("execl: %s\n"), strerror(saverr));
exit(1);
default:
break; /* parent */
}
close(fildes[1]);
wall = fdopen(fildes[0], "r+");
if (wall == (FILE *)NULL) {
saverr = errno;
msg(gettext("fdopen: %s\n"), strerror(saverr));
return;
}
clock = time((time_t *)0);
localclock = localtime(&clock);
(void) fprintf(wall, gettext(
"\n\007\007\007Message from the dump program to all operators at \
%d:%02d ...\n\n%s"),
localclock->tm_hour, localclock->tm_min, message);
fclose(wall);
while (wait((int *)0) != pid) {
continue;
/*LINTED [empty loop body]*/
}
}
/*
* print out an estimate of the amount of time left to do the dump
*/
#define EST_SEC 600 /* every 10 minutes */
void
timeest(int force, int blkswritten)
{
time_t tnow, deltat;
char *msgp;
if (tschedule == NULL)
return;
if (*tschedule == 0)
*tschedule = time((time_t *)0) + EST_SEC;
(void) time(&tnow);
if ((force || tnow >= *tschedule) && blkswritten) {
*tschedule = tnow + EST_SEC;
if (!force && blkswritten < 50 * ntrec)
return;
deltat = (*telapsed + (tnow - *tstart_writing))
* ((double)esize / blkswritten - 1.0);
msgp = gettext("%3.2f%% done, finished in %d:%02d\n");
msg(msgp, (blkswritten*100.0)/esize,
deltat/3600, (deltat%3600)/60);
}
}
#include <stdarg.h>
/* VARARGS1 */
void
msg(const char *fmt, ...)
{
char buf[1024], *cp;
size_t size;
va_list args;
va_start(args, fmt);
(void) strcpy(buf, " DUMP: ");
cp = &buf[strlen(buf)];
#ifdef TDEBUG
(void) sprintf(cp, "pid=%d ", getpid());
cp = &buf[strlen(buf)];
#endif
/* don't need -1, vsnprintf does it right */
/* LINTED pointer arithmetic result fits in size_t */
size = ((size_t)sizeof (buf)) - (size_t)(cp - buf);
(void) vsnprintf(cp, size, fmt, args);
(void) fputs(buf, stderr);
(void) fflush(stdout);
(void) fflush(stderr);
va_end(args);
}
/* VARARGS1 */
void
msgtail(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
(void) vfprintf(stderr, fmt, args);
va_end(args);
}
#define MINUTES(x) ((x) * 60)
/*
* Tell the operator what has to be done;
* we don't actually do it
*/
void
lastdump(int arg) /* w ==> just what to do; W ==> most recent dumps */
{
char *lastname;
char *date;
int i;
time_t tnow, ddate;
struct mntent *dt;
int dumpme = 0;
struct idates *itwalk;
(void) time(&tnow);
mnttabread(); /* /etc/fstab input */
inititimes(); /* /etc/dumpdates input */
/* Don't use msg(), this isn't a tell-the-world kind of thing */
if (arg == 'w')
(void) fprintf(stdout, gettext("Dump these file systems:\n"));
else
(void) fprintf(stdout, gettext(
"Last dump(s) done (Dump '>' file systems):\n"));
if (idatev != NULL) {
qsort((char *)idatev, nidates, sizeof (*idatev), idatesort);
lastname = "??";
ITITERATE(i, itwalk) {
if (strncmp(lastname, itwalk->id_name,
sizeof (itwalk->id_name)) == 0)
continue;
/* must be ctime(), per ufsdump(5) */
ddate = itwalk->id_ddate;
date = (char *)ctime(&ddate);
date[16] = '\0'; /* blow away seconds and year */
lastname = itwalk->id_name;
dt = mnttabsearch(itwalk->id_name, 0);
if ((time_t)(itwalk->id_ddate) < (tnow - DAY)) {
dumpme = 1;
}
if ((arg == 'w') && dumpme) {
/*
* Handle the w option: print out file systems
* which haven't been backed up within a day.
*/
(void) printf(gettext("%8s\t(%6s)\n"),
itwalk->id_name, dt ? dt->mnt_dir : "");
}
if (arg == 'W') {
/*
* Handle the W option: print out ALL
* filesystems including recent dump dates and
* dump levels. Mark the backup-needing
* filesystems with a >.
*/
(void) printf(gettext(
"%c %8s\t(%6s) Last dump: Level %c, Date %s\n"),
dumpme ? '>' : ' ',
itwalk->id_name,
dt ? dt->mnt_dir : "",
(uchar_t)itwalk->id_incno,
date);
}
dumpme = 0;
}
}
}
static int
idatesort(const void *v1, const void *v2)
{
struct idates **p1 = (struct idates **)v1;
struct idates **p2 = (struct idates **)v2;
int diff;
diff = strcoll((*p1)->id_name, (*p2)->id_name);
if (diff == 0) {
/*
* Time may eventually become unsigned, so can't
* rely on subtraction to give a useful result.
* Note that we are sorting dates into reverse
* order, so that we will report based on the
* most-recent record for a particular filesystem.
*/
if ((*p1)->id_ddate > (*p2)->id_ddate)
diff = -1;
else if ((*p1)->id_ddate < (*p2)->id_ddate)
diff = 1;
}
return (diff);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#include "dump.h"
#include <rmt.h>
#include <setjmp.h>
#include <sys/fdio.h>
#include <sys/mkdev.h>
#include <assert.h>
#include <limits.h>
#define SLEEPMS 50
int newtape;
static uint_t writesize; /* size of malloc()ed buffer for tape */
static ino_t inos[TP_NINOS]; /* starting inodes on each tape */
/*
* The req structure is used to pass commands from the parent
* process through the pipes to the slave processes. It comes
* in two flavors, depending on which mode dump is operating under:
* an inode request (on-line mode) and a disk block request ("old" mode).
*/
/*
* The inode request structure is used during on-line mode.
* The master passes inode numbers and starting offsets to
* the slaves. The tape writer passes out the current inode,
* offset, and number of tape records written after completing a volume.
*/
struct ireq {
ino_t inumber; /* inode number to open/dump */
long igen; /* inode generation number */
off_t offset; /* starting offset in inode */
int count; /* count for 1st spclrec */
};
/*
* The block request structure is used in off-line mode to pass
* commands to dump disk blocks from the parent process through
* the pipes to the slave processes.
*/
struct breq {
diskaddr_t dblk; /* disk address to read */
size_t size; /* number of bytes to read from disk */
ulong_t spclrec[1]; /* actually longer */
};
struct req {
short aflag; /* write data to archive process as well */
short tflag; /* begin new tape */
union reqdata {
struct ireq ino; /* used for on-line mode */
struct breq blks; /* used for off-line mode */
} data;
};
#define ir_inumber data.ino.inumber
#define ir_igen data.ino.igen
#define ir_offset data.ino.offset
#define ir_count data.ino.count
#define br_dblk data.blks.dblk
#define br_size data.blks.size
#define br_spcl data.blks.spclrec
static int reqsiz = 0; /* alloctape will initialize */
#define SLAVES 3
struct slaves {
int sl_slavefd; /* pipe from master to slave */
pid_t sl_slavepid; /* slave pid; used by killall() */
ino_t sl_inos; /* inos, if this record starts tape */
int sl_offset; /* logical blocks written for object */
int sl_count; /* logical blocks left in spclrec */
int sl_tapea; /* header number, if starting tape */
int sl_firstrec; /* number of first block on tape */
int sl_state; /* dump output state */
struct req *sl_req; /* instruction packet to slave */
};
static struct slaves slaves[SLAVES]; /* one per slave */
static struct slaves *slp; /* pointer to current slave */
static struct slaves chkpt; /* checkpointed data */
struct bdesc {
char *b_data; /* pointer to buffer data */
int b_flags; /* flags (see below) */
};
/*
* The following variables are in shared memory, and must be
* explicitly checkpointed and/or reset.
*/
static caddr_t shared; /* pointer to block of shared memory */
static struct bdesc *bufp; /* buffer descriptors */
static struct bdesc **current; /* output buffer to fill */
static int *tapea; /* logical record count */
#ifdef INSTRUMENT
static int *readmissp; /* number of times writer was idle */
static int *idle; /* number of times slaves were idle */
#endif /* INSTRUMENT */
/*
* Buffer flags
*/
#define BUF_EMPTY 0x0 /* nothing in buffer */
#define BUF_FULL 0x1 /* data in buffer */
#define BUF_SPCLREC 0x2 /* contains special record */
#define BUF_ARCHIVE 0x4 /* dump to archive */
static int recsout; /* number of req's sent to slaves */
static int totalrecsout; /* total number of req's sent to slaves */
static int rotor; /* next slave to be instructed */
static pid_t master; /* pid of master, for sending error signals */
static int writer = -1; /* fd of tape writer */
static pid_t writepid; /* pid of tape writer */
static int arch; /* fd of output archiver */
static pid_t archivepid; /* pid of output archiver */
static int archivefd; /* fd of archive file (proper) */
static offset_t lf_archoffset; /* checkpointed offset into archive file */
int caught; /* caught signal -- imported by mapfile() */
#ifdef DEBUG
extern int xflag;
#endif
static void cmdwrterr(void);
static void cmdrderr(void);
static void freetape(void);
static void bufclear(void);
static pid_t setuparchive(void);
static pid_t setupwriter(void);
static void nextslave(void);
static void tperror(int);
static void rollforward(int);
static void nap(int);
static void alrm(int);
static void just_rewind(void);
static void killall(void);
static void proceed(int);
static void die(int);
static void enslave(void);
static void wait_our_turn(void);
static void dumpoffline(int, pid_t, int);
static void onxfsz(int);
static void dowrite(int);
static void checkpoint(struct bdesc *, int);
static ssize_t atomic(int (*)(), int, char *, int);
static size_t tapesize;
/*
* Allocate buffers and shared memory variables. Tape buffers are
* allocated on page boundaries for tape write() efficiency.
*/
void
alloctape(void)
{
struct slaves *slavep;
ulong_t pgoff = (unsigned)(getpagesize() - 1); /* 2**n - 1 */
int mapfd;
char *obuf;
int saverr;
int i, j;
writesize = ntrec * tp_bsize;
if (!printsize)
msg(gettext("Writing %d Kilobyte records\n"),
writesize / TP_BSIZE_MIN);
/*
* set up shared memory seg for here and child
*/
mapfd = open("/dev/zero", O_RDWR);
if (mapfd == -1) {
saverr = errno;
msg(gettext("Cannot open `%s': %s\n"),
"/dev/zero", strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
/*
* Allocate space such that buffers are page-aligned and
* pointers are aligned on 4-byte boundaries (for SPARC).
* This code assumes that (NBUF * writesize) is a multiple
* of the page size and that pages are aligned on 4-byte
* boundaries. Space is allocated as follows:
*
* (NBUF * writesize) for the actual buffers
* (pagesize - 1) for padding so the buffers are page-aligned
* (NBUF * ntrec * sizeof (struct bdesc)) for each buffer
* (n * sizeof (int)) for [n] debugging variables/pointers
* (n * sizeof (int)) for [n] miscellaneous variables/pointers
*/
tapesize =
(NBUF * writesize) /* output buffers */
/* LINTED: pgoff fits into a size_t */
+ (size_t)pgoff /* page alignment */
/* buffer descriptors */
+ (((size_t)sizeof (struct bdesc)) * NBUF * ntrec)
#ifdef INSTRUMENT
+ (2 * (size_t)sizeof (int *)) /* instrumentation */
#endif
/* shared variables */
+ (size_t)sizeof (struct bdesc **)
+ (size_t)sizeof (int *)
+ (3 * (size_t)sizeof (time_t));
shared = mmap((char *)0, tapesize, PROT_READ|PROT_WRITE,
MAP_SHARED, mapfd, (off_t)0);
if (shared == (caddr_t)-1) {
saverr = errno;
msg(gettext("Cannot memory map output buffers: %s\n"),
strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
(void) close(mapfd);
/*
* Buffers and buffer headers
*/
obuf = (char *)(((ulong_t)shared + pgoff) & ~pgoff);
/* LINTED obuf and writesize are aligned */
bufp = (struct bdesc *)(obuf + NBUF*writesize);
/*
* Shared memory variables
*/
current = (struct bdesc **)&bufp[NBUF*ntrec];
tapea = (int *)(current + 1);
/* LINTED pointer alignment ok */
telapsed = (time_t *)(tapea + 1);
tstart_writing = telapsed + 1;
tschedule = tstart_writing + 1;
#ifdef INSTRUMENT
/*
* Debugging and instrumentation variables
*/
readmissp = (int *)(tschedule + 1);
idle = readmissp + 1;
#endif
for (i = 0, j = 0; i < NBUF * ntrec; i++, j += tp_bsize) {
bufp[i].b_data = &obuf[j];
}
reqsiz = sizeof (struct req) + tp_bsize - sizeof (long);
for (slavep = slaves; slavep < &slaves[SLAVES]; slavep++)
slavep->sl_req = (struct req *)xmalloc(reqsiz);
chkpt.sl_offset = 0; /* start at offset 0 */
chkpt.sl_count = 0;
chkpt.sl_inos = UFSROOTINO; /* in root inode */
chkpt.sl_firstrec = 1;
chkpt.sl_tapea = 0;
}
static void
freetape(void)
{
if (shared == NULL)
return;
(void) timeclock((time_t)0);
(void) munmap(shared, tapesize);
shared = NULL;
}
/*
* Reset tape state variables -- called
* before a pass to dump active files.
*/
void
reset(void)
{
bufclear();
#ifdef INSTRUMENT
(*readmissp) = 0;
(*idle) = 0;
#endif
spcl.c_flags = 0;
spcl.c_volume = 0;
tapeno = 0;
chkpt.sl_offset = 0; /* start at offset 0 */
chkpt.sl_count = 0;
chkpt.sl_inos = UFSROOTINO; /* in root inode */
chkpt.sl_firstrec = 1;
chkpt.sl_tapea = 0;
}
static void
bufclear(void)
{
struct bdesc *bp;
int i;
for (i = 0, bp = bufp; i < NBUF * ntrec; i++, bp++)
bp->b_flags = BUF_EMPTY;
if ((caddr_t)current < shared ||
(caddr_t)current > (shared + tapesize)) {
msg(gettext(
"bufclear: current pointer out of range of shared memory\n"));
dumpabort();
/*NOTREACHED*/
}
if ((*current != NULL) &&
(*current < &bufp[0] || *current > &bufp[NBUF*ntrec])) {
/* ANSI string catenation, to shut cstyle up */
msg(gettext("bufclear: current buffer pointer (0x%x) "
"out of range of buffer\naddresses (0x%x - 0x%x)\n"),
*current, &bufp[0], &bufp[NBUF*ntrec]);
dumpabort();
/*NOTREACHED*/
}
*current = bufp;
}
/*
* Start a process to collect information describing the dump.
* This data takes two forms:
* the bitmap and directory information being written to
* the front of the tape (the "archive" file)
* information describing each directory and inode (to
* be included in the database tmp file)
* Write the data to the files as it is received so huge file
* systems don't cause dump to consume large amounts of memory.
*/
static pid_t
setuparchive(void)
{
struct slaves *slavep;
int cmd[2];
pid_t pid;
ssize_t size;
char *data;
char *errmsg;
int flags, saverr;
int punt = 0;
/*
* Both the archive and database tmp files are
* checkpointed by taking their current offsets
* (sizes) after completing each volume. Restoring
* from a checkpoint involves truncating to the
* checkpointed size.
*/
if (archive && !doingactive) {
/* It's allowed/expected to exist, so can't use O_EXCL */
archivefd = safe_file_open(archivefile, O_WRONLY, 0600);
if (archivefd < 0) {
saverr = errno;
msg(gettext("Cannot open archive file `%s': %s\n"),
archivefile, strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
archive_opened = 1;
if (lseek64(archivefd, lf_archoffset, 0) < 0) {
saverr = errno;
msg(gettext(
"Cannot position archive file `%s' : %s\n"),
archivefile, strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
if (ftruncate64(archivefd, lf_archoffset) < 0) {
saverr = errno;
msg(gettext(
"Cannot truncate archive file `%s' : %s\n"),
archivefile, strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
}
if (pipe(cmd) < 0) {
saverr = errno;
msg(gettext("%s: %s error: %s\n"),
"setuparchive", "pipe", strerror(saverr));
return (0);
}
sighold(SIGINT);
if ((pid = fork()) < 0) {
saverr = errno;
msg(gettext("%s: %s error: %s\n"),
"setuparchive", "fork", strerror(saverr));
return (0);
}
if (pid > 0) {
sigrelse(SIGINT);
/* parent process */
(void) close(cmd[0]);
arch = cmd[1];
return (pid);
}
/*
* child process
*/
(void) signal(SIGINT, SIG_IGN); /* master handles this */
#ifdef TDEBUG
(void) sleep(4); /* allow time for parent's message to get out */
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Archiver has pid = %ld\n"), (long)getpid());
#endif
freeino(); /* release unneeded resources */
freetape();
for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) {
if (slavep->sl_slavefd != -1) {
(void) close(slavep->sl_slavefd);
slavep->sl_slavefd = -1;
}
}
(void) close(to);
(void) close(fi);
to = fi = -1;
(void) close(cmd[1]);
data = xmalloc(tp_bsize);
for (;;) {
size = atomic((int(*)())read, cmd[0], (char *)&flags,
sizeof (flags));
if ((unsigned)size != sizeof (flags))
break;
size = atomic((int(*)())read, cmd[0], data, tp_bsize);
if (size == tp_bsize) {
if (archive && flags & BUF_ARCHIVE && !punt &&
(size = write(archivefd, data, tp_bsize))
!= tp_bsize) {
struct stat64 stats;
if (size != -1) {
errmsg = strdup(gettext(
"Output truncated"));
if (errmsg == NULL)
errmsg = "";
} else {
errmsg = strerror(errno);
}
if (fstat64(archivefd, &stats) < 0)
stats.st_size = -1;
/* cast to keep lint&printf happy */
msg(gettext(
"Cannot write archive file `%s' at offset %lld: %s\n"),
archivefile, (longlong_t)stats.st_size,
errmsg);
msg(gettext(
"Archive file will be deleted, dump will continue\n"));
punt++;
if ((size != -1) && (*errmsg != '\0')) {
free(errmsg);
}
}
} else {
break;
}
}
(void) close(cmd[0]);
if (archive) {
(void) close(archivefd);
archivefd = -1;
}
if (punt) {
(void) unlink(archivefile);
Exit(X_ABORT);
}
Exit(X_FINOK);
/* NOTREACHED */
return (0);
}
/*
* Start a process to read the output buffers and write the data
* to the output device.
*/
static pid_t
setupwriter(void)
{
struct slaves *slavep;
int cmd[2];
pid_t pid;
int saverr;
caught = 0;
if (pipe(cmd) < 0) {
saverr = errno;
msg(gettext("%s: %s error: %s\n"),
"setupwriter", "pipe", strerror(saverr));
return (0);
}
sighold(SIGINT);
if ((pid = fork()) < 0) {
saverr = errno;
msg(gettext("%s: %s error: %s\n"),
"setupwriter", "fork", strerror(saverr));
return (0);
}
if (pid > 0) {
/*
* Parent process
*/
sigrelse(SIGINT);
(void) close(cmd[0]);
writer = cmd[1];
return (pid);
}
/*
* Child (writer) process
*/
(void) signal(SIGINT, SIG_IGN); /* master handles this */
#ifdef TDEBUG
(void) sleep(4); /* allow time for parent's message to get out */
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Writer has pid = %ld\n"), (long)getpid());
#endif
child_chdir();
freeino(); /* release unneeded resources */
for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) {
if (slavep->sl_slavefd != -1) {
(void) close(slavep->sl_slavefd);
slavep->sl_slavefd = -1;
}
}
(void) close(fi);
fi = -1;
(void) close(cmd[1]);
dowrite(cmd[0]);
if (arch >= 0) {
(void) close(arch);
arch = -1;
}
(void) close(cmd[0]);
Exit(X_FINOK);
/* NOTREACHED */
return (0);
}
void
spclrec(void)
{
int s, i;
int32_t *ip;
int flags = BUF_SPCLREC;
if ((BIT(ino, shamap)) && (spcl.c_type == TS_INODE)) {
spcl.c_type = TS_ADDR;
/* LINTED: result fits in a short */
spcl.c_dinode.di_mode &= ~S_IFMT;
/* LINTED: result fits in a short */
spcl.c_dinode.di_mode |= IFSHAD;
}
/*
* Only TS_INODEs should have short metadata, if this
* isn't such a spclrec, clear the metadata flag and
* the c_shadow contents.
*/
if (!(spcl.c_type == TS_INODE && (spcl.c_flags & DR_HASMETA))) {
spcl.c_flags &= ~DR_HASMETA;
bcopy(c_shadow_save, &(spcl.c_shadow),
sizeof (spcl.c_shadow));
}
if (spcl.c_type == TS_END) {
spcl.c_count = 1;
spcl.c_flags |= DR_INODEINFO;
bcopy((char *)inos, (char *)spcl.c_inos, sizeof (inos));
} else if (spcl.c_type == TS_TAPE) {
spcl.c_flags |= DR_NEWHEADER;
if (doingactive)
spcl.c_flags |= DR_REDUMP;
} else if (spcl.c_type != TS_INODE)
flags = BUF_SPCLREC;
spcl.c_tapea = *tapea;
/* LINTED for now, max inode # is 2**31 (ufs max size is 4TB) */
spcl.c_inumber = (ino32_t)ino;
spcl.c_magic = (tp_bsize == TP_BSIZE_MIN) ? NFS_MAGIC : MTB_MAGIC;
spcl.c_checksum = 0;
ip = (int32_t *)&spcl;
s = CHECKSUM;
assert((tp_bsize % sizeof (*ip)) == 0);
i = tp_bsize / sizeof (*ip);
assert((i%8) == 0);
i /= 8;
do {
s -= *ip++; s -= *ip++; s -= *ip++; s -= *ip++;
s -= *ip++; s -= *ip++; s -= *ip++; s -= *ip++;
} while (--i > 0);
spcl.c_checksum = s;
taprec((uchar_t *)&spcl, flags, sizeof (spcl));
if (spcl.c_type == TS_END)
spcl.c_flags &= ~DR_INODEINFO;
else if (spcl.c_type == TS_TAPE)
spcl.c_flags &= ~(DR_NEWHEADER|DR_REDUMP|DR_TRUEINC);
}
/*
* Fill appropriate buffer
*/
void
taprec(uchar_t *dp, int flags, int size)
{
if (size > tp_bsize) {
msg(gettext(
"taprec: Unexpected buffer size, expected %d, got %d.\n"),
tp_bsize, size);
dumpabort();
/*NOTREACHED*/
}
while ((*current)->b_flags & BUF_FULL)
nap(10);
bcopy(dp, (*current)->b_data, (size_t)size);
if (size < tp_bsize) {
bzero((*current)->b_data + size, tp_bsize - size);
}
if (dumptoarchive)
flags |= BUF_ARCHIVE;
/* no locking as we assume only one reader and one writer active */
(*current)->b_flags = (flags | BUF_FULL);
if (++*current >= &bufp[NBUF*ntrec])
(*current) = &bufp[0];
(*tapea)++;
}
void
dmpblk(daddr32_t blkno, size_t size, off_t offset)
{
diskaddr_t dblkno;
assert((offset >> DEV_BSHIFT) <= INT32_MAX);
dblkno = fsbtodb(sblock, blkno) + (offset >> DEV_BSHIFT);
size = (size + DEV_BSIZE-1) & ~(DEV_BSIZE-1);
slp->sl_req->br_dblk = dblkno;
slp->sl_req->br_size = size;
if (dumptoarchive) {
/* LINTED: result fits in a short */
slp->sl_req->aflag |= BUF_ARCHIVE;
}
toslave((void(*)())0, ino);
}
/*ARGSUSED*/
static void
tperror(int sig)
{
char buf[3000];
if (pipeout) {
msg(gettext("Write error on %s\n"), tape);
msg(gettext("Cannot recover\n"));
dumpabort();
/* NOTREACHED */
}
if (!doingverify) {
broadcast(gettext("WRITE ERROR!\n"));
(void) snprintf(buf, sizeof (buf),
gettext("Do you want to restart?: (\"yes\" or \"no\") "));
if (!query(buf)) {
dumpabort();
/*NOTREACHED*/
}
if (tapeout && (isrewind(to) || offline)) {
/* ANSI string catenation, to shut cstyle up */
msg(gettext("This tape will rewind. After "
"it is rewound,\nreplace the faulty tape "
"with a new one;\nthis dump volume will "
"be rewritten.\n"));
}
} else {
broadcast(gettext("TAPE VERIFICATION ERROR!\n"));
(void) snprintf(buf, sizeof (buf), gettext(
"Do you want to rewrite?: (\"yes\" or \"no\") "));
if (!query(buf)) {
dumpabort();
/*NOTREACHED*/
}
msg(gettext(
"This tape will be rewritten and then verified\n"));
}
killall();
trewind();
Exit(X_REWRITE);
}
/*
* Called by master from pass() to send a request to dump files/blocks
* to one of the slaves. Slaves return whether the file was active
* when it was being dumped. The tape writer process sends checkpoint
* info when it completes a volume.
*/
void
toslave(void (*fn)(), ino_t inumber)
{
int wasactive;
if (recsout >= SLAVES) {
if ((unsigned)atomic((int(*)())read, slp->sl_slavefd,
(char *)&wasactive, sizeof (wasactive)) !=
sizeof (wasactive)) {
cmdrderr();
dumpabort();
/*NOTREACHED*/
}
if (wasactive) {
active++;
msg(gettext(
"The file at inode `%lu' was active and will "
"be recopied\n"),
slp->sl_req->ir_inumber);
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(slp->sl_req->ir_inumber, activemap);
}
}
slp->sl_req->aflag = 0;
if (dumptoarchive) {
/* LINTED: result fits in a short */
slp->sl_req->aflag |= BUF_ARCHIVE;
}
if (fn)
(*fn)(inumber);
if (atomic((int(*)())write, slp->sl_slavefd, (char *)slp->sl_req,
reqsiz) != reqsiz) {
cmdwrterr();
dumpabort();
/*NOTREACHED*/
}
++recsout;
nextslave();
}
void
dospcl(ino_t inumber)
{
/* LINTED for now, max inode # is 2**31 (ufs max size is 1TB) */
spcl.c_inumber = (ino32_t)inumber;
slp->sl_req->br_dblk = 0;
bcopy((char *)&spcl, (char *)slp->sl_req->br_spcl, tp_bsize);
}
static void
nextslave(void)
{
if (++rotor >= SLAVES) {
rotor = 0;
}
slp = &slaves[rotor];
}
void
flushcmds(void)
{
int i;
int wasactive;
/*
* Retrieve all slave status
*/
if (recsout < SLAVES) {
slp = slaves;
rotor = 0;
}
for (i = 0; i < (recsout < SLAVES ? recsout : SLAVES); i++) {
if ((unsigned)atomic((int(*)())read, slp->sl_slavefd,
(char *)&wasactive, sizeof (wasactive)) !=
sizeof (wasactive)) {
cmdrderr();
dumpabort();
/*NOTREACHED*/
}
if (wasactive) {
active++;
msg(gettext(
"inode %d was active and will be recopied\n"),
slp->sl_req->ir_inumber);
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(slp->sl_req->ir_inumber, activemap);
}
nextslave();
}
}
void
flusht(void)
{
sigset_t block_set, oset; /* hold SIGUSR1 and atomically sleep */
(void) sigemptyset(&block_set);
(void) sigaddset(&block_set, SIGUSR1);
(void) sigprocmask(SIG_BLOCK, &block_set, &oset);
(void) kill(writepid, SIGUSR1); /* tell writer to flush */
(void) sigpause(SIGUSR1); /* wait for SIGUSR1 from writer */
/*NOTREACHED*/
}
jmp_buf checkpoint_buf;
/*
* Roll forward to the next volume after receiving
* an EOT signal from writer. Get checkpoint data
* from writer and return if done, otherwise fork
* a new process and jump back to main state loop
* to begin the next volume. Installed as the master's
* signal handler for SIGUSR1.
*/
/*ARGSUSED*/
static void
rollforward(int sig)
{
int status;
(void) sighold(SIGUSR1);
/*
* Writer sends us checkpoint information after
* each volume. A returned state of DS_DONE with no
* unwritten (left-over) records differentiates a
* clean flush from one in which EOT was encountered.
*/
if ((unsigned)atomic((int(*)())read, writer, (char *)&chkpt,
sizeof (struct slaves)) != sizeof (struct slaves)) {
cmdrderr();
dumpabort();
/*NOTREACHED*/
}
if (atomic((int(*)())read, writer, (char *)&spcl,
TP_BSIZE_MIN) != TP_BSIZE_MIN) {
cmdrderr();
dumpabort();
/*NOTREACHED*/
}
ino = chkpt.sl_inos - 1;
pos = chkpt.sl_offset;
leftover = chkpt.sl_count;
dumpstate = chkpt.sl_state;
blockswritten = ++chkpt.sl_tapea;
if (dumpstate == DS_DONE) {
if (archivepid) {
/*
* If archiving (either archive or
* database), signal the archiver
* to finish up. This must happen
* before the writer exits in order
* to avoid a race.
*/
(void) kill(archivepid, SIGUSR1);
}
(void) signal(SIGUSR1, SIG_IGN);
(void) sigrelse(SIGUSR1);
(void) kill(writepid, SIGUSR1); /* tell writer to exit */
lf_archoffset = 0LL;
longjmp(checkpoint_buf, 1);
/*NOTREACHED*/
}
if (leftover) {
(void) memmove(spcl.c_addr,
&spcl.c_addr[spcl.c_count-leftover], leftover);
bzero(&spcl.c_addr[leftover], TP_NINDIR-leftover);
}
if (writepid) {
(void) kill(writepid, SIGUSR1); /* tell writer to exit */
(void) close(writer);
writer = -1;
}
if (archivepid) {
(void) waitpid(archivepid, &status, 0); /* wait for archiver */
#ifdef TDEBUG
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Archiver %ld returns with status %d\n"),
(long)archivepid, status);
#endif
archivepid = 0;
}
/*
* Checkpoint archive file
*/
if (!doingverify && archive) {
lf_archoffset = lseek64(archivefd, (off64_t)0, 2);
if (lf_archoffset < 0) {
int saverr = errno;
msg(gettext("Cannot position archive file `%s': %s\n"),
archivefile, strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
(void) close(archivefd);
archivefd = -1;
}
resetino(ino);
if (dumpstate == DS_START) {
msg(gettext(
"Tape too short: changing volumes and restarting\n"));
reset();
}
if (!pipeout) {
if (verify && !doingverify)
trewind();
else {
close_rewind();
changevol();
}
}
(void) sigrelse(SIGUSR1);
otape(0);
longjmp(checkpoint_buf, 1);
/*NOTREACHED*/
}
static void
nap(int ms)
{
struct timeval tv;
tv.tv_sec = ms / 1000;
tv.tv_usec = (ms - tv.tv_sec * 1000) * 1000;
(void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);
}
static jmp_buf alrm_buf;
/*ARGSUSED*/
static void
alrm(int sig)
{
longjmp(alrm_buf, 1);
/*NOTREACHED*/
}
void
nextdevice(void)
{
char *cp;
if (host != NULL) /* we set the host only once in ufsdump */
return;
host = NULL;
if (strchr(tape, ':')) {
if (diskette) {
msg(gettext("Cannot do remote dump to diskette\n"));
Exit(X_ABORT);
}
host = tape;
tape = strchr(host, ':');
*tape++ = 0;
cp = strchr(host, '@'); /* user@host? */
if (cp != (char *)0)
cp++;
else
cp = host;
} else
cp = spcl.c_host;
/*
* dumpdev is provided for use in prompts and is of
* the form:
* hostname:device
* sdumpdev is of the form:
* hostname:device
* for remote devices, and simply:
* device
* for local devices.
*/
if (dumpdev != (char *)NULL) {
/* LINTED: dumpdev is not NULL */
free(dumpdev);
}
/*LINTED [cast to smaller integer]*/
dumpdev = xmalloc((size_t)((sizeof (spcl.c_host) + strlen(tape) + 2)));
/* LINTED unsigned -> signed cast ok */
(void) sprintf(dumpdev, "%.*s:%s", (int)sizeof (spcl.c_host), cp, tape);
if (cp == spcl.c_host)
sdumpdev = strchr(dumpdev, ':') + 1;
else
sdumpdev = dumpdev;
}
/*
* Gross hack due to misfeature of mt tape driver that causes
* the device to rewind if we generate any signals. Guess
* whether tape is rewind device or not -- for local devices
* we can just look at the minor number. For rmt devices,
* make an educated guess.
*/
int
isrewind(int f)
{
struct stat64 sbuf;
char *c;
int unit;
int rewind;
if (host) {
c = strrchr(tape, '/');
if (c == NULL)
c = tape;
else
c++;
/*
* If the last component begins or ends with an 'n', it is
* assumed to be a non-rewind device.
*/
if (c[0] == 'n' || c[strlen(c)-1] == 'n')
rewind = 0;
else if ((strstr(tape, "mt") || strstr(tape, "st")) &&
sscanf(tape, "%*[a-zA-Z/]%d", &unit) == 1 &&
(unit & MT_NOREWIND))
rewind = 0;
else
rewind = 1;
} else {
if (fstat64(f, &sbuf) < 0) {
msg(gettext(
"Cannot obtain status of output device `%s'\n"),
tape);
dumpabort();
/*NOTREACHED*/
}
rewind = minor(sbuf.st_rdev) & MT_NOREWIND ? 0 : 1;
}
return (rewind);
}
static void
just_rewind(void)
{
struct slaves *slavep;
char *rewinding = gettext("Tape rewinding\n");
for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++) {
if (slavep->sl_slavepid > 0) /* signal normal exit */
(void) kill(slavep->sl_slavepid, SIGTERM);
if (slavep->sl_slavefd >= 0) {
(void) close(slavep->sl_slavefd);
slavep->sl_slavefd = -1;
}
}
/* wait for any signals from slaves */
while (waitpid(0, (int *)0, 0) >= 0)
/*LINTED [empty body]*/
continue;
if (pipeout)
return;
if (doingverify) {
/*
* Space to the end of the tape.
* Backup first in case we already read the EOF.
*/
if (host) {
(void) rmtioctl(MTBSR, 1);
if (rmtioctl(MTEOM, 1) < 0)
(void) rmtioctl(MTFSF, 1);
} else {
static struct mtop bsr = { MTBSR, 1 };
static struct mtop eom = { MTEOM, 1 };
static struct mtop fsf = { MTFSF, 1 };
(void) ioctl(to, MTIOCTOP, &bsr);
if (ioctl(to, MTIOCTOP, &eom) < 0)
(void) ioctl(to, MTIOCTOP, &fsf);
}
}
/*
* Guess whether the tape is rewinding so we can tell
* the operator if it's going to take a long time.
*/
if (tapeout && isrewind(to)) {
/* tape is probably rewinding */
msg(rewinding);
}
}
void
trewind(void)
{
(void) timeclock((time_t)0);
if (offline && (!verify || doingverify)) {
close_rewind();
} else {
just_rewind();
if (host)
rmtclose();
else {
(void) close(to);
to = -1;
}
}
}
void
close_rewind(void)
{
char *rewinding = gettext("Tape rewinding\n");
(void) timeclock((time_t)0);
just_rewind();
/*
* The check in just_rewind won't catch the case in
* which the current volume is being taken off-line
* and is not mounted on a no-rewind device (and is
* not the last volume, which is not taken off-line).
*/
if (tapeout && !isrewind(to) && offline) {
/* tape is probably rewinding */
msg(rewinding);
}
if (host) {
if (offline || autoload)
(void) rmtioctl(MTOFFL, 0);
rmtclose();
} else {
if (offline || autoload) {
static struct mtop offl = { MTOFFL, 0 };
(void) ioctl(to, MTIOCTOP, &offl);
if (diskette)
(void) ioctl(to, FDEJECT, 0);
}
(void) close(to);
to = -1;
}
}
void
changevol(void)
{
char buf1[3000], buf2[3000];
char volname[LBLSIZE+1];
/*CONSTANTCONDITION*/
assert(sizeof (spcl.c_label) < sizeof (volname));
filenum = 1;
nextdevice();
(void) strcpy(spcl.c_label, tlabel);
if (host) {
char *rhost = host;
char *cp = strchr(host, '@');
if (cp == (char *)0)
cp = host;
else
cp++;
if (rmthost(rhost, ntrec) == 0) {
msg(gettext("Cannot connect to tape host `%s'\n"), cp);
dumpabort();
/*NOTREACHED*/
}
if (rhost != host)
free(rhost);
}
/*
* Make volume switching as automatic as possible
* while avoiding overwriting volumes. We will
* switch automatically under the following condition:
* 1) The user specified autoloading from the
* command line.
* At one time, we (in the guise of hsmdump) had the
* concept of a sequence of devices to rotate through,
* but that's never been a ufsdump feature.
*/
if (autoload) {
int tries;
/*
* Stop the clock for throughput calculations.
*/
if ((telapsed != NULL) && (tstart_writing != NULL)) {
*telapsed += time((time_t *)NULL) - *tstart_writing;
}
(void) snprintf(volname, sizeof (volname), "#%d", tapeno+1);
(void) snprintf(buf1, sizeof (buf1), gettext(
"Mounting volume %s on %s\n"), volname, dumpdev);
msg(buf1);
broadcast(buf1);
/*
* Wait for the tape to autoload. Note that the delay
* period doesn't take into account however long it takes
* for the open to fail (measured at 21 seconds for an
* Exabyte 8200 under 2.7 on an Ultra 2).
*/
for (tries = 0; tries < autoload_tries; tries++) {
if (host) {
if (rmtopen(tape, O_RDONLY) >= 0) {
rmtclose();
return;
}
} else {
int f, m;
m = (access(tape, F_OK) == 0) ? 0 : O_CREAT;
if ((f = doingverify ?
safe_device_open(tape, O_RDONLY, 0600) :
safe_device_open(tape, O_RDONLY|m, 0600))
>= 0) {
(void) close(f);
return;
}
}
(void) sleep(autoload_period);
}
/*
* Autoload timed out, ask the operator to do it.
* Note that query() will update *telapsed, and we
* shouldn't charge for the autoload time. So, since
* we updated *telapsed ourselves above, we just set
* tstart_writing to the current time, and query()
* will end up making a null-effect change. This,
* of course, assumes that our caller will be resetting
* *tstart_writing. This is currently the case.
* If tstart_writing is NULL (should never happen),
* we're ok, since time(2) will accept a NULL pointer.
*/
(void) time(tstart_writing);
}
if (strncmp(spcl.c_label, "none", 5)) {
(void) strncpy(volname, spcl.c_label, sizeof (spcl.c_label));
volname[sizeof (spcl.c_label)] = '\0';
} else
(void) snprintf(volname, sizeof (volname), "#%d", tapeno+1);
timeest(1, spcl.c_tapea);
(void) snprintf(buf1, sizeof (buf1), gettext(
"Change Volumes: Mount volume `%s' on `%s'\n"), volname, dumpdev);
msg(buf1);
broadcast(gettext("CHANGE VOLUMES!\7\7\n"));
(void) snprintf(buf1, sizeof (buf1), gettext(
"Is the new volume (%s) mounted on `%s' and ready to go?: %s"),
volname, dumpdev, gettext("(\"yes\" or \"no\") "));
while (!query(buf1)) {
(void) snprintf(buf2, sizeof (buf2), gettext(
"Do you want to abort dump?: (\"yes\" or \"no\") "));
if (query(buf2)) {
dumpabort();
/*NOTREACHED*/
}
}
}
/*
* We implement taking and restoring checkpoints on the tape level.
* When each tape is opened, a new process is created by forking; this
* saves all of the necessary context in the parent. The child
* continues the dump; the parent waits around, saving the context.
* If the child returns X_REWRITE, then it had problems writing that tape;
* this causes the parent to fork again, duplicating the context, and
* everything continues as if nothing had happened.
*/
void
otape(int top)
{
static struct mtget mt;
char buf[3000];
pid_t parentpid;
pid_t childpid;
pid_t waitproc;
int status;
struct sigvec sv, osv;
sv.sv_flags = SA_RESTART;
(void) sigemptyset(&sv.sa_mask);
sv.sv_handler = SIG_IGN;
(void) sigvec(SIGINT, &sv, (struct sigvec *)0);
parentpid = getpid();
if (verify) {
if (doingverify)
doingverify = 0;
else
Exit(X_VERIFY);
}
restore_check_point:
sv.sv_handler = interrupt;
(void) sigvec(SIGINT, &sv, (struct sigvec *)0);
(void) fflush(stderr);
/*
* All signals are inherited...
*/
sighold(SIGINT);
childpid = fork();
if (childpid < 0) {
msg(gettext(
"Context-saving fork failed in parent %ld\n"),
(long)parentpid);
Exit(X_ABORT);
}
if (childpid != 0) {
/*
* PARENT:
* save the context by waiting
* until the child doing all of the work returns.
* let the child catch user interrupts
*/
sv.sv_handler = SIG_IGN;
(void) sigvec(SIGINT, &sv, (struct sigvec *)0);
sigrelse(SIGINT);
#ifdef TDEBUG
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext(
"Volume: %d; parent process: %ld child process %ld\n"),
tapeno+1, (long)parentpid, (long)childpid);
#endif /* TDEBUG */
for (;;) {
waitproc = waitpid(0, &status, 0);
if (waitproc == childpid)
break;
msg(gettext(
"Parent %ld waiting for child %ld had another child %ld return\n"),
(long)parentpid, (long)childpid, (long)waitproc);
}
if (WIFSIGNALED(status)) {
msg(gettext("Process %ld killed by signal %d: %s\n"),
(long)childpid, WTERMSIG(status),
strsignal(WTERMSIG(status)));
status = X_ABORT;
} else
status = WEXITSTATUS(status);
#ifdef TDEBUG
switch (status) {
case X_FINOK:
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext(
"Child %ld finishes X_FINOK\n"), (long)childpid);
break;
case X_ABORT:
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext(
"Child %ld finishes X_ABORT\n"), (long)childpid);
break;
case X_REWRITE:
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext(
"Child %ld finishes X_REWRITE\n"), (long)childpid);
break;
case X_RESTART:
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext(
"Child %ld finishes X_RESTART\n"), (long)childpid);
break;
case X_VERIFY:
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext(
"Child %ld finishes X_VERIFY\n"), (long)childpid);
break;
default:
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Child %ld finishes unknown %d\n"),
(long)childpid, status);
break;
}
#endif /* TDEBUG */
switch (status) {
case X_FINOK:
/* wait for children */
while (waitpid(0, (int *)0, 0) >= 0)
/*LINTED [empty body]*/
continue;
Exit(X_FINOK);
/*NOTREACHED*/
case X_ABORT:
Exit(X_ABORT);
/*NOTREACHED*/
case X_VERIFY:
doingverify++;
goto restore_check_point;
/*NOTREACHED*/
case X_REWRITE:
doingverify = 0;
changevol();
goto restore_check_point;
/* NOTREACHED */
case X_RESTART:
doingverify = 0;
if (!top) {
Exit(X_RESTART);
}
if (!offline)
autoload = 0;
changevol();
sv.sv_handler = interrupt;
(void) sigvec(SIGINT, &sv, (struct sigvec *)0);
return;
/* NOTREACHED */
default:
msg(gettext("Bad return code from dump: %d\n"), status);
Exit(X_ABORT);
/*NOTREACHED*/
}
/*NOTREACHED*/
} else { /* we are the child; just continue */
child_chdir();
sigrelse(SIGINT);
#ifdef TDEBUG
(void) sleep(4); /* time for parent's message to get out */
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext(
"Child on Volume %d has parent %ld, my pid = %ld\n"),
tapeno+1, (long)parentpid, (long)getpid());
#endif
(void) snprintf(buf, sizeof (buf), gettext(
"Cannot open `%s'. Do you want to retry the open?: (\"yes\" or \"no\") "),
dumpdev);
if (doingverify) {
/* 1 for stdout */
while ((to = host ? rmtopen(tape, O_RDONLY) :
pipeout ? 1 :
safe_device_open(tape, O_RDONLY, 0600)) < 0) {
perror(tape);
if (autoload) {
if (!query_once(buf, 1)) {
dumpabort();
/*NOTREACHED*/
}
} else {
if (!query(buf)) {
dumpabort();
/*NOTREACHED*/
}
}
}
/*
* If we're using the non-rewinding tape device,
* the tape will be left positioned after the
* EOF mark. We need to back up to the beginning
* of this tape file (cross two tape marks in the
* reverse direction and one in the forward
* direction) before the verify pass.
*/
if (host) {
if (rmtioctl(MTBSF, 2) >= 0)
(void) rmtioctl(MTFSF, 1);
else
(void) rmtioctl(MTNBSF, 1);
} else {
static struct mtop bsf = { MTBSF, 2 };
static struct mtop fsf = { MTFSF, 1 };
static struct mtop nbsf = { MTNBSF, 1 };
if (ioctl(to, MTIOCTOP, &bsf) >= 0)
(void) ioctl(to, MTIOCTOP, &fsf);
else
(void) ioctl(to, MTIOCTOP, &nbsf);
}
} else {
/*
* XXX Add logic to test for "tape" being a
* XXX device or a non-existent file.
* Current behaviour is that it must exist,
* and we over-write whatever's there.
* This can be bad if tape == "/etc/passwd".
*/
if (!pipeout && doposition && (tapeno == 0)) {
positiontape(buf);
if (setjmp(alrm_buf)) {
/*
* The tape is rewinding;
* we're screwed.
*/
msg(gettext(
"Cannot position tape using "
"rewind device!\n"));
dumpabort();
/*NOTREACHED*/
} else {
sv.sv_handler = alrm;
(void) sigvec(SIGALRM, &sv, &osv);
(void) alarm(15);
}
while ((to = host ? rmtopen(tape, O_WRONLY) :
safe_device_open(tape, O_WRONLY, 0600)) < 0)
(void) sleep(10);
(void) alarm(0);
(void) sigvec(SIGALRM, &osv,
(struct sigvec *)0);
} else {
int m;
m = (access(tape, F_OK) == 0) ? 0 : O_CREAT;
/*
* Only verify the tape label if label
* verification is on and we are at BOT
*/
if (pipeout)
to = 1;
else while ((to = host ?
rmtopen(tape, O_WRONLY) :
safe_device_open(tape, O_WRONLY|m, 0600))
< 0)
if (!query_once(buf, 1)) {
dumpabort();
/*NOTREACHED*/
}
}
}
if (!pipeout) {
tapeout = host ? rmtstatus(&mt) >= 0 :
ioctl(to, MTIOCGET, &mt) >= 0; /* set state */
/*
* Make sure the tape is positioned
* where it is supposed to be
*/
if (tapeout && (tapeno > 0) &&
(mt.mt_fileno != (filenum-1))) {
(void) snprintf(buf, sizeof (buf), gettext(
"Warning - tape positioning error!\n\
\t%s current file %ld, should be %ld\n"),
tape, mt.mt_fileno+1, filenum);
msg(buf);
dumpailing();
}
}
tapeno++; /* current tape sequence */
if (tapeno < TP_NINOS)
inos[tapeno] = chkpt.sl_inos;
spcl.c_firstrec = chkpt.sl_firstrec;
spcl.c_tapea = (*tapea) = chkpt.sl_tapea;
spcl.c_volume++;
enslave(); /* Share tape buffers with slaves */
#ifdef DEBUG
if (xflag) {
/* XGETTEXT: #ifdef DEBUG only */
msg(gettext("Checkpoint state:\n"));
msg(" blockswritten %u\n", blockswritten);
msg(" ino %u\n", ino);
msg(" pos %u\n", pos);
msg(" left %u\n", leftover);
msg(" tapea %u\n", (*tapea));
msg(" state %d\n", dumpstate);
}
#endif
spcl.c_type = TS_TAPE;
spcl.c_tpbsize = tp_bsize;
if (leftover == 0) {
spcl.c_count = 0;
spclrec();
newtape = 0;
} else
newtape++; /* new volume indication */
if (doingverify) {
msg(gettext("Starting verify pass\n"));
} else if (tapeno > 1) {
msg(gettext(
"Volume %d begins with blocks from inode %lu\n"),
tapeno, chkpt.sl_inos);
}
(void) timeclock((time_t)1);
(void) time(tstart_writing);
timeest(0, spcl.c_tapea);
}
}
void
dumpabort(void)
{
if (master && master != getpid())
/*
* signal master to call dumpabort
*/
(void) kill(master, SIGTERM);
else {
killall();
if (archivefile && archive_opened)
(void) unlink(archivefile);
msg(gettext("The ENTIRE dump is aborted.\n"));
}
Exit(X_ABORT);
}
void
dumpailing(void)
{
broadcast(gettext("DUMP IS AILING!\n"));
if (!query(gettext(
"Do you want to attempt to continue? (\"yes\" or \"no\") "))) {
dumpabort();
/*NOTREACHED*/
}
}
void
Exit(int status)
{
/*
* Clean up message system
*/
#ifdef TDEBUG
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("pid = %ld exits with status %d\n"),
(long)getpid(), status);
#endif /* TDEBUG */
exit(status);
}
static void
killall(void)
{
struct slaves *slavep;
for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++)
if (slavep->sl_slavepid > 0) {
(void) kill(slavep->sl_slavepid, SIGKILL);
#ifdef TDEBUG
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Slave child %ld killed\n"),
(long)slavep->sl_slavepid);
#endif
}
if (writepid) {
(void) kill(writepid, SIGKILL);
#ifdef TDEBUG
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Writer child %ld killed\n"), (long)writepid);
#endif
}
if (archivepid) {
(void) kill(archivepid, SIGKILL);
#ifdef TDEBUG
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Archiver child %ld killed\n"), (long)archivepid);
#endif
}
}
/*ARGSUSED*/
static void
proceed(int sig)
{
caught++;
}
/*ARGSUSED*/
static void
die(int sig)
{
Exit(X_FINOK);
}
static void
enslave(void)
{
int cmd[2]; /* file descriptors */
int i;
struct sigvec sv;
struct slaves *slavep;
int saverr;
sv.sv_flags = SA_RESTART;
(void) sigemptyset(&sv.sa_mask);
master = getpid();
/*
* slave sends SIGTERM on dumpabort
*/
sv.sv_handler = (void(*)(int))dumpabort;
(void) sigvec(SIGTERM, &sv, (struct sigvec *)0);
sv.sv_handler = tperror;
(void) sigvec(SIGUSR2, &sv, (struct sigvec *)0);
sv.sv_handler = proceed;
(void) sigvec(SIGUSR1, &sv, (struct sigvec *)0);
totalrecsout += recsout;
caught = 0;
recsout = 0;
rotor = 0;
bufclear();
for (slavep = &slaves[0]; slavep < &slaves[SLAVES]; slavep++)
slavep->sl_slavefd = -1;
archivefd = arch = writer = -1;
for (i = 0; i < SLAVES; i++) {
if (pipe(cmd) < 0) {
saverr = errno;
msg(gettext(
"Cannot create pipe for slave process: %s\n"),
strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
sighold(SIGUSR2);
sighold(SIGINT);
sighold(SIGTERM);
if ((slaves[i].sl_slavepid = fork()) < 0) {
saverr = errno;
msg(gettext("Cannot create slave process: %s\n"),
strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
slaves[i].sl_slavefd = cmd[1];
if (slaves[i].sl_slavepid == 0) { /* Slave starts up here */
pid_t next; /* pid of neighbor */
sv.sv_handler = SIG_DFL;
(void) sigvec(SIGUSR2, &sv, (struct sigvec *)0);
sv.sv_handler = SIG_IGN; /* master handler INT */
(void) sigvec(SIGINT, &sv, (struct sigvec *)0);
sv.sv_handler = die; /* normal slave exit */
(void) sigvec(SIGTERM, &sv, (struct sigvec *)0);
child_chdir();
sigrelse(SIGUSR2);
sigrelse(SIGINT);
sigrelse(SIGTERM);
freeino(); /* release unneeded resources */
#ifdef TDEBUG
(void) sleep(4); /* time for parent's message to get out */
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("Neighbor has pid = %ld\n"), (long)getpid());
#endif
/* Closes cmd[1] as a side-effect */
for (slavep = &slaves[0];
slavep < &slaves[SLAVES];
slavep++)
if (slavep->sl_slavefd >= 0) {
(void) close(slavep->sl_slavefd);
slavep->sl_slavefd = -1;
}
(void) close(to);
(void) close(fi); /* Need our own seek ptr */
to = -1;
fi = open(disk, O_RDONLY);
if (fi < 0) {
saverr = errno;
msg(gettext(
"Cannot open dump device `%s': %s\n"),
disk, strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
if ((unsigned)atomic((int(*)())read, cmd[0],
(char *)&next, sizeof (next)) != sizeof (next)) {
cmdrderr();
dumpabort();
/*NOTREACHED*/
}
dumpoffline(cmd[0], next, i);
Exit(X_FINOK);
}
/* Parent continues here */
sigrelse(SIGUSR2);
sigrelse(SIGINT);
sigrelse(SIGTERM);
(void) close(cmd[0]);
}
if (archive) {
archivepid = setuparchive();
if (!archivepid) {
dumpabort();
/*NOTREACHED*/
}
}
writepid = setupwriter();
if (!writepid) {
dumpabort();
/*NOTREACHED*/
}
if (arch >= 0) {
(void) close(arch); /* only writer has this open */
arch = -1;
}
/* Tell each slave who follows it */
for (i = 0; i < SLAVES; i++) {
if ((unsigned)atomic((int(*)())write, slaves[i].sl_slavefd,
(char *)&(slaves[(i + 1) % SLAVES].sl_slavepid),
sizeof (int)) != sizeof (int)) {
cmdwrterr();
dumpabort();
/*NOTREACHED*/
}
}
sv.sv_handler = rollforward; /* rcvd from writer on EOT */
(void) sigvec(SIGUSR1, &sv, (struct sigvec *)0);
slp = slaves;
(void) kill(slp->sl_slavepid, SIGUSR1);
master = 0;
}
static void
wait_our_turn(void)
{
(void) sighold(SIGUSR1);
if (!caught) {
#ifdef INSTRUMENT
(*idle)++;
#endif
(void) sigpause(SIGUSR1);
}
caught = 0;
(void) sigrelse(SIGUSR1);
}
static void
dumpoffline(int cmd, pid_t next, int mynum)
{
struct req *p = slaves[mynum].sl_req;
ulong_t i;
uchar_t *cp;
uchar_t *blkbuf;
int notactive = 0;
blkbuf = xmalloc(sblock->fs_bsize);
/*CONSTANTCONDITION*/
assert(sizeof (spcl) == TP_BSIZE_MIN);
while (atomic((int(*)())read, cmd, (char *)p, reqsiz) == reqsiz) {
if (p->br_dblk) {
bread(p->br_dblk, (uchar_t *)blkbuf, p->br_size);
} else {
bcopy((char *)p->br_spcl, (char *)&spcl,
sizeof (spcl));
ino = spcl.c_inumber;
}
dumptoarchive = p->aflag & BUF_ARCHIVE;
wait_our_turn();
if (p->br_dblk) {
for (i = p->br_size, cp = blkbuf;
i > 0;
/* LINTED character pointers aren't signed */
cp += i > tp_bsize ? tp_bsize : i,
i -= i > tp_bsize ? tp_bsize : i) {
/* LINTED unsigned to signed conversion ok */
taprec(cp, 0, i > tp_bsize ? tp_bsize : (int)i);
}
} else
spclrec();
(void) kill(next, SIGUSR1); /* Next slave's turn */
/*
* Note that we lie about file activity since we don't
* check for it.
*/
if ((unsigned)atomic((int(*)())write, cmd, (char *)¬active,
sizeof (notactive)) != sizeof (notactive)) {
cmdwrterr();
dumpabort();
/*NOTREACHED*/
}
}
free(blkbuf);
}
static int count; /* tape blocks written since last spclrec */
/*ARGSUSED*/
static void
onxfsz(int sig)
{
msg(gettext("File size limit exceeded writing output volume %d\n"),
tapeno);
(void) kill(master, SIGUSR2);
Exit(X_REWRITE);
}
static long lastnonaddr; /* last DS_{INODE,CLRI,BITS} written */
static long lastnonaddrm; /* and the mode thereof */
/*
* dowrite -- the main body of the output writer process
*/
static void
dowrite(int cmd)
{
struct bdesc *last =
&bufp[(NBUF*ntrec)-1]; /* last buffer in pool */
struct bdesc *bp = bufp; /* current buf in tape block */
struct bdesc *begin = bufp; /* first buf of tape block */
struct bdesc *end = bufp + (ntrec-1); /* last buf of tape block */
int siz; /* bytes written (block) */
int trecs; /* records written (block) */
long asize = 0; /* number of 0.1" units... */
/* ...written on current tape */
char *tp, *rbuf = NULL;
char *recmap = spcl.c_addr; /* current tape record map */
char *endmp; /* end of valid map data */
char *mp; /* current map entry */
union u_spcl *sp;
(void) signal(SIGXFSZ, onxfsz);
bzero((char *)&spcl, sizeof (spcl));
count = 0;
if (doingverify) {
rbuf = (char *)malloc((uint_t)writesize);
if (rbuf == 0) {
/* Restart from checkpoint */
(void) kill(master, SIGUSR2);
Exit(X_REWRITE);
}
}
for (;;) {
/* START: wait until all buffers in tape block are full */
if ((bp->b_flags & BUF_FULL) == 0) {
if (caught) { /* master signalled flush */
(void) sighold(SIGUSR1);
caught = 0;
/* signal ready */
(void) kill(master, SIGUSR1);
chkpt.sl_count = 0; /* signal not at EOT */
checkpoint(bp-1, cmd); /* send data */
(void) sigpause(SIGUSR1);
break;
}
#ifdef INSTRUMENT
(*readmissp)++;
#endif
nap(50);
continue;
}
if (bp < end) {
bp++;
continue;
}
/* END: wait until all buffers in tape block are full */
tp = begin->b_data;
(void) sighold(SIGUSR1);
if (host) {
if (!doingverify)
siz = rmtwrite(tp, writesize);
else if ((siz = rmtread(rbuf, writesize)) ==
writesize && bcmp(rbuf, tp, writesize))
siz = -1;
} else {
if (!doingverify)
siz = write(to, tp, writesize);
else if ((siz = read(to, rbuf, writesize)) ==
writesize && bcmp(rbuf, tp, writesize))
siz = -1;
if (siz < 0 && diskette && errno == ENOSPC)
siz = 0; /* really EOF */
}
(void) sigrelse(SIGUSR1);
if (siz < 0 ||
(pipeout && siz != writesize)) {
char buf[3000];
/*
* Isn't i18n wonderful?
*/
if (doingverify) {
if (diskette)
(void) snprintf(buf, sizeof (buf),
gettext(
"Verification error %ld blocks into diskette %d\n"),
asize * 2, tapeno);
else if (tapeout)
(void) snprintf(buf, sizeof (buf),
gettext(
"Verification error %ld feet into tape %d\n"),
(cartridge ? asize/tracks :
asize)/120L,
tapeno);
else
(void) snprintf(buf, sizeof (buf),
gettext(
"Verification error %ld blocks into volume %d\n"),
asize * 2, tapeno);
} else {
if (diskette)
(void) snprintf(buf, sizeof (buf),
gettext(
"Write error %ld blocks into diskette %d\n"),
asize * 2, tapeno);
else if (tapeout)
(void) snprintf(buf, sizeof (buf),
gettext(
"Write error %ld feet into tape %d\n"),
(cartridge ? asize/tracks :
asize)/120L, tapeno);
else
(void) snprintf(buf, sizeof (buf),
gettext(
"Write error %ld blocks into volume %d\n"),
asize * 2, tapeno);
}
msg(buf);
/* Restart from checkpoint */
#ifdef TDEBUG
/* XGETTEXT: #ifdef TDEBUG only */
msg(gettext("sending SIGUSR2 to pid %ld\n"), master);
#endif
(void) kill(master, SIGUSR2);
Exit(X_REWRITE);
}
trecs = siz / tp_bsize;
if (diskette)
asize += trecs; /* asize == blocks written */
else
asize += (siz/density + tenthsperirg);
if (trecs)
chkpt.sl_firstrec++;
for (bp = begin; bp < begin + trecs; bp++) {
if ((arch >= 0) && (bp->b_flags & BUF_ARCHIVE)) {
if ((unsigned)atomic((int(*)())write, arch,
(char *)&bp->b_flags, sizeof (bp->b_flags))
!= sizeof (bp->b_flags)) {
cmdwrterr();
dumpabort();
/*NOTREACHED*/
}
if (atomic((int(*)())write, arch, bp->b_data,
tp_bsize) != tp_bsize) {
cmdwrterr();
dumpabort();
/*NOTREACHED*/
}
}
if (bp->b_flags & BUF_SPCLREC) {
/*LINTED [bp->b_data is aligned]*/
sp = (union u_spcl *)bp->b_data;
if (sp->s_spcl.c_type != TS_ADDR) {
lastnonaddr = sp->s_spcl.c_type;
lastnonaddrm =
sp->s_spcl.c_dinode.di_mode;
if (sp->s_spcl.c_type != TS_TAPE)
chkpt.sl_offset = 0;
}
chkpt.sl_count = sp->s_spcl.c_count;
bcopy((char *)sp, (char *)&spcl, sizeof (spcl));
mp = recmap;
endmp = &recmap[spcl.c_count];
count = 0;
} else {
chkpt.sl_offset++;
chkpt.sl_count--;
count++;
mp++;
}
/*
* Adjust for contiguous hole
*/
for (; mp < endmp; mp++) {
if (*mp)
break;
chkpt.sl_offset++;
chkpt.sl_count--;
}
}
/*
* Check for end of tape
*/
if (trecs < ntrec ||
(!pipeout && tsize > 0 && asize > tsize)) {
if (tapeout)
msg(gettext("End-of-tape detected\n"));
else
msg(gettext("End-of-file detected\n"));
(void) sighold(SIGUSR1);
caught = 0;
(void) kill(master, SIGUSR1); /* signal EOT */
checkpoint(--bp, cmd); /* send checkpoint data */
(void) sigpause(SIGUSR1);
break;
}
for (bp = begin; bp <= end; bp++)
bp->b_flags = BUF_EMPTY;
if (end + ntrec > last) {
bp = begin = bufp;
timeest(0, spcl.c_tapea);
} else
bp = begin = end+1;
end = begin + (ntrec-1);
}
if (rbuf != NULL)
free(rbuf);
}
/*
* Send checkpoint info back to master. This information
* consists of the current inode number, number of logical
* blocks written for that inode (or bitmap), the last logical
* block number written, the number of logical blocks written
* to this volume, the current dump state, and the current
* special record map.
*/
static void
checkpoint(struct bdesc *bp, int cmd)
{
int state, type;
ino_t ino;
if (++bp >= &bufp[NBUF*ntrec])
bp = bufp;
/*
* If we are dumping files and the record following
* the last written to tape is a special record, use
* it to get an accurate indication of current state.
*/
if ((bp->b_flags & BUF_SPCLREC) && (bp->b_flags & BUF_FULL) &&
lastnonaddr == TS_INODE) {
/*LINTED [bp->b_data is aligned]*/
union u_spcl *nextspcl = (union u_spcl *)bp->b_data;
if (nextspcl->s_spcl.c_type == TS_INODE) {
chkpt.sl_offset = 0;
chkpt.sl_count = 0;
} else if (nextspcl->s_spcl.c_type == TS_END) {
chkpt.sl_offset = 0;
chkpt.sl_count = 1; /* EOT indicator */
}
ino = nextspcl->s_spcl.c_inumber;
type = nextspcl->s_spcl.c_type;
} else {
/*
* If not, use what we have.
*/
ino = spcl.c_inumber;
type = spcl.c_type;
}
switch (type) { /* set output state */
case TS_ADDR:
switch (lastnonaddr) {
case TS_INODE:
case TS_TAPE:
if ((lastnonaddrm & IFMT) == IFDIR ||
(lastnonaddrm & IFMT) == IFATTRDIR)
state = DS_DIRS;
else
state = DS_FILES;
break;
case TS_CLRI:
state = DS_CLRI;
break;
case TS_BITS:
state = DS_BITS;
break;
}
break;
case TS_INODE:
if ((spcl.c_dinode.di_mode & IFMT) == IFDIR ||
(spcl.c_dinode.di_mode & IFMT) == IFATTRDIR)
state = DS_DIRS;
else
state = DS_FILES;
break;
case 0: /* EOT on 1st record */
case TS_TAPE:
state = DS_START;
ino = UFSROOTINO;
break;
case TS_CLRI:
state = DS_CLRI;
break;
case TS_BITS:
state = DS_BITS;
break;
case TS_END:
if (spcl.c_type == TS_END)
state = DS_DONE;
else
state = DS_END;
break;
}
/*
* Checkpoint info to be processed by rollforward():
* The inode with which the next volume should begin
* The last inode number on this volume
* The last logical block number on this volume
* The current output state
* The offset within the current inode (already in sl_offset)
* The number of records left from last spclrec (in sl_count)
* The physical block the next vol begins with (in sl_firstrec)
*/
chkpt.sl_inos = ino;
chkpt.sl_tapea = spcl.c_tapea + count;
chkpt.sl_state = state;
if ((unsigned)atomic((int(*)())write, cmd, (char *)&chkpt,
sizeof (chkpt)) != sizeof (chkpt)) {
cmdwrterr();
dumpabort();
/*NOTREACHED*/
}
if ((unsigned)atomic((int(*)())write, cmd, (char *)&spcl,
sizeof (spcl)) != sizeof (spcl)) {
cmdwrterr();
dumpabort();
/*NOTREACHED*/
}
#ifdef DEBUG
if (xflag) {
/* XGETTEXT: #ifdef DEBUG only */
msg(gettext("sent chkpt to master:\n"));
msg(" ino %u\n", chkpt.sl_inos);
msg(" 1strec %u\n", chkpt.sl_firstrec);
msg(" lastrec %u\n", chkpt.sl_tapea);
msg(" written %u\n", chkpt.sl_offset);
msg(" left %u\n", chkpt.sl_count);
msg(" state %d\n", chkpt.sl_state);
}
#endif
}
/*
* Since a read from a pipe may not return all we asked for,
* or a write may not write all we ask if we get a signal,
* loop until the count is satisfied (or error).
*/
static ssize_t
atomic(int (*func)(), int fd, char *buf, int count)
{
ssize_t got = 0, need = count;
/* don't inherit random value if immediately get zero back from func */
errno = 0;
while (need > 0) {
got = (*func)(fd, buf, MIN(need, 4096));
if (got < 0 && errno == EINTR)
continue;
if (got <= 0)
break;
buf += got;
need -= got;
}
/* if we got what was asked for, return count, else failure (got) */
return ((need != 0) ? got : count);
}
void
positiontape(char *msgbuf)
{
/* Static as never change, no need to waste stack space */
static struct mtget mt;
static struct mtop rew = { MTREW, 1 };
static struct mtop fsf = { MTFSF, 1 };
char *info = strdup(gettext("Positioning `%s' to file %ld\n"));
char *fail = strdup(gettext("Cannot position tape to file %d\n"));
int m;
/* gettext()'s return value is volatile, hence the strdup()s */
m = (access(tape, F_OK) == 0) ? 0 : O_CREAT;
/*
* To avoid writing tape marks at inappropriate places, we open the
* device read-only, position it, close it, and reopen it for writing.
*/
while ((to = host ? rmtopen(tape, O_RDONLY) :
safe_device_open(tape, O_RDONLY|m, 0600)) < 0) {
if (autoload) {
if (!query_once(msgbuf, 1)) {
dumpabort();
/*NOTREACHED*/
}
} else {
if (!query(msgbuf)) {
dumpabort();
/*NOTREACHED*/
}
}
}
if (host) {
if (rmtstatus(&mt) >= 0 &&
rmtioctl(MTREW, 1) >= 0 &&
filenum > 1) {
msg(info, dumpdev, filenum);
if (rmtioctl(MTFSF, filenum-1) < 0) {
msg(fail, filenum);
dumpabort();
/*NOTREACHED*/
}
}
rmtclose();
} else {
if (ioctl(to, MTIOCGET, &mt) >= 0 &&
ioctl(to, MTIOCTOP, &rew) >= 0 &&
filenum > 1) {
msg(info, dumpdev, filenum);
fsf.mt_count = filenum - 1;
if (ioctl(to, MTIOCTOP, &fsf) < 0) {
msg(fail, filenum);
dumpabort();
/*NOTREACHED*/
}
}
(void) close(to);
to = -1;
}
free(info);
free(fail);
}
static void
cmdwrterr(void)
{
int saverr = errno;
msg(gettext("Error writing command pipe: %s\n"), strerror(saverr));
}
static void
cmdrderr(void)
{
int saverr = errno;
msg(gettext("Error reading command pipe: %s\n"), strerror(saverr));
}
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#include "dump.h"
#include <sys/file.h>
#include <sys/mman.h>
static void lf_dmpindir(daddr32_t, int, u_offset_t *);
static void indir(daddr32_t, int, u_offset_t *);
static void lf_blksout(daddr32_t *, u_offset_t);
static void lf_dumpinode(struct dinode *);
static void dsrch(daddr32_t, ulong_t, u_offset_t);
void lf_dump(struct dinode *);
int dadded;
int nsubdir;
int shortmeta;
static char msgbuf[256];
void
pass(void (*fn)(struct dinode *), uchar_t *map)
{
int bits;
ino_t maxino;
maxino = (unsigned)(sblock->fs_ipg * sblock->fs_ncg - 1);
/*
* Handle pass restarts. We don't check for UFSROOTINO just in
* case we need to restart on the root inode.
*/
if (ino != 0) {
bits = ~0;
if (map != NULL) {
/* LINTED: lint seems to think map is signed */
map += (ino / NBBY);
bits = *map++;
}
bits >>= (ino % NBBY);
resetino(ino);
goto restart;
}
while (ino < maxino) {
if ((ino % NBBY) == 0) {
bits = ~0;
if (map != NULL)
bits = *map++;
}
restart:
ino++;
/*
* Ignore any inode less than UFSROOTINO and inodes that
* we have already done on a previous pass.
*/
if ((ino >= UFSROOTINO) && (bits & 1)) {
/*
* The following test is merely an optimization
* for common case where "add" will just return.
*/
if (!(fn == add && BIT(ino, nodmap)))
(*fn)(getino(ino));
}
bits >>= 1;
}
}
void
mark(struct dinode *ip)
{
int f;
f = ip->di_mode & IFMT;
if (f == 0 || ip->di_nlink <= 0) {
/* LINTED: 32-bit to 8-bit assignment ok */
BIC(ino, clrmap);
return;
}
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(ino, clrmap);
if (f == IFDIR || f == IFATTRDIR) {
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(ino, dirmap);
}
if (ip->di_ctime >= spcl.c_ddate) {
if (f == IFSHAD)
return;
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(ino, nodmap);
/* attribute changes impact the root */
if (f == IFATTRDIR)
BIS(UFSROOTINO, nodmap);
if (f != IFREG && f != IFDIR && f != IFATTRDIR && f != IFLNK) {
o_esize += 1;
return;
}
est(ip);
}
}
void
active_mark(struct dinode *ip)
{
int f;
f = ip->di_mode & IFMT;
if (f == 0 || ip->di_nlink <= 0) {
/* LINTED: 32-bit to 8-bit assignment ok */
BIC(ino, clrmap);
return;
}
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(ino, clrmap);
if (f == IFDIR || f == IFATTRDIR) {
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(ino, dirmap);
}
if (BIT(ino, activemap)) {
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(ino, nodmap);
/* attribute changes impact the root */
if (f == IFATTRDIR)
BIS(UFSROOTINO, nodmap);
if (f != IFREG && f != IFDIR && f != IFATTRDIR && f != IFLNK) {
o_esize += 1;
return;
}
est(ip);
}
}
static struct shcount {
struct shcount *higher, *lower;
ino_t ino;
unsigned long count;
} shcounts = {
NULL, NULL,
0,
0
};
static struct shcount *shc = NULL;
void
markshad(struct dinode *ip)
{
ino_t shadow;
if (ip->di_shadow == 0)
return;
if (shc == NULL)
shc = &shcounts;
shadow = (ino_t)(unsigned)(ip->di_shadow);
while ((shadow > shc->ino) && (shc->higher))
shc = shc->higher;
while ((shadow < shc->ino) && (shc->lower))
shc = shc->lower;
if (shadow != shc->ino) {
struct shcount *new;
new = (struct shcount *)xcalloc(1, sizeof (*new));
new->higher = shc->higher;
if (shc->higher != NULL)
shc->higher->lower = new;
shc->higher = new;
new->lower = shc;
shc = new;
shc->ino = shadow;
}
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(shadow, shamap);
shc->count++;
}
void
estshad(struct dinode *ip)
{
u_offset_t esizeprime;
u_offset_t tmpesize;
if (ip->di_size <= sizeof (union u_shadow))
return;
while ((ino > shc->ino) && (shc->higher))
shc = shc->higher;
while ((ino < shc->ino) && (shc->lower))
shc = shc->lower;
if (ino != shc->ino)
return; /* xxx panic? complain? */
tmpesize = (o_esize + f_esize);
esizeprime = tmpesize;
est(ip);
esizeprime = tmpesize - esizeprime;
esizeprime *= shc->count - 1;
f_esize += esizeprime;
}
void
freeshad()
{
if (shc == NULL)
return;
while (shc->higher)
shc = shc->higher;
while (shc->lower) {
shc = shc->lower;
if (shc->higher) /* else panic? */
(void) free(shc->higher);
}
/*
* This should be unnecessary, but do it just to be safe.
* Note that shc might be malloc'd or static, so can't free().
*/
bzero(shc, sizeof (*shc));
}
void
add(struct dinode *ip)
{
int i;
u_offset_t filesize;
if (BIT(ino, nodmap))
return;
if ((ip->di_mode & IFMT) != IFDIR &&
(ip->di_mode & IFMT) != IFATTRDIR) {
(void) snprintf(msgbuf, sizeof (msgbuf), gettext(
"Warning - directory at inode `%lu' vanished!\n"), ino);
msg(msgbuf);
/* LINTED: 32-bit to 8-bit assignment ok */
BIC(ino, dirmap);
return;
}
nsubdir = 0;
dadded = 0;
filesize = ip->di_size;
for (i = 0; i < NDADDR; i++) {
if (ip->di_db[i] != 0)
/* LINTED dblksize/blkoff does a safe cast here */
dsrch(ip->di_db[i], (ulong_t)dblksize(sblock, ip, i),
filesize);
filesize -= (unsigned)(sblock->fs_bsize);
}
for (i = 0; i < NIADDR; i++) {
if (ip->di_ib[i] != 0)
indir(ip->di_ib[i], i, &filesize);
}
if (dadded) {
nadded++;
if (!BIT(ino, nodmap)) {
/* LINTED: 32-bit to 8-bit assignment ok */
BIS(ino, nodmap);
if ((ip->di_mode & IFMT) == IFATTRDIR) {
/* attribute changes "auto-percolate" to root */
BIS(UFSROOTINO, nodmap);
}
est(ip);
}
}
if (nsubdir == 0) {
if (!BIT(ino, nodmap)) {
/* LINTED: 32-bit to 8-bit assignment ok */
BIC(ino, dirmap);
}
}
}
static void
indir(daddr32_t d, int n, u_offset_t *filesize)
{
int i;
daddr32_t idblk[MAXNINDIR];
if ((unsigned)(sblock->fs_bsize) > sizeof (idblk)) {
msg(gettext(
"Inconsistency detected: filesystem block size larger than valid maximum.\n"));
dumpabort();
/*NOTREACHED*/
}
if ((unsigned)NINDIR(sblock) > MAXNINDIR) {
/*CSTYLED*/
msg(gettext(
"Inconsistency detected: inode has more indirect \
blocks than valid maximum.\n"));
dumpabort();
/*NOTREACHED*/
}
if (dadded || *filesize == 0)
return;
#ifdef lint
idblk[0] = '\0';
#endif /* lint */
/* xxx sanity check sblock contents before trusting them */
bread(fsbtodb(sblock, d), (uchar_t *)idblk, (size_t)sblock->fs_bsize);
if (n <= 0) {
for (i = 0; i < NINDIR(sblock); i++) {
d = idblk[i];
if (d != 0)
dsrch(d, (ulong_t)(uint32_t)sblock->fs_bsize,
*filesize);
*filesize -= (unsigned)(sblock->fs_bsize);
}
} else {
n--;
for (i = 0; i < NINDIR(sblock); i++) {
d = idblk[i];
if (d != 0)
indir(d, n, filesize);
}
}
}
void
dirdump(struct dinode *ip)
{
/* watchout for dir inodes deleted and maybe reallocated */
if (((ip->di_mode & IFMT) != IFDIR &&
(ip->di_mode & IFMT) != IFATTRDIR) || ip->di_nlink < 2) {
(void) snprintf(msgbuf, sizeof (msgbuf), gettext(
"Warning - directory at inode `%lu' vanished!\n"), ino);
msg(msgbuf);
return;
}
lf_dump(ip);
}
static u_offset_t loffset; /* current offset in file (ufsdump) */
static void
lf_dumpmeta(struct dinode *ip)
{
if ((ip->di_shadow == 0) || shortmeta)
return;
lf_dumpinode(getino((ino_t)(unsigned)(ip->di_shadow)));
}
int
hasshortmeta(struct dinode **ip)
{
ino_t savino;
int rc;
if ((*ip)->di_shadow == 0)
return (0);
savino = ino;
*ip = getino((ino_t)(unsigned)((*ip)->di_shadow));
rc = ((*ip)->di_size <= sizeof (union u_shadow));
*ip = getino(ino = savino);
return (rc);
}
void
lf_dumpinode(struct dinode *ip)
{
int i;
u_offset_t size;
i = ip->di_mode & IFMT;
if (i == 0 || ip->di_nlink <= 0)
return;
spcl.c_dinode = *ip;
spcl.c_count = 0;
if ((i != IFDIR && i != IFATTRDIR && i != IFREG && i != IFLNK &&
i != IFSHAD) || ip->di_size == 0) {
toslave(dospcl, ino);
return;
}
size = NDADDR * (unsigned)(sblock->fs_bsize);
if (size > ip->di_size)
size = ip->di_size;
lf_blksout(&ip->di_db[0], size);
size = ip->di_size - size;
if (size > 0) {
for (i = 0; i < NIADDR; i++) {
lf_dmpindir(ip->di_ib[i], i, &size);
if (size == 0)
break;
}
}
}
void
lf_dump(struct dinode *ip)
{
if ((!BIT(ino, nodmap)) && (!BIT(ino, shamap)))
return;
shortmeta = hasshortmeta(&ip);
if (shortmeta) {
ip = getino((ino_t)(unsigned)(ip->di_shadow));
/* assume spcl.c_shadow is smaller than 1 block */
bread(fsbtodb(sblock, ip->di_db[0]),
(uchar_t *)spcl.c_shadow.c_shadow, sizeof (spcl.c_shadow));
spcl.c_flags |= DR_HASMETA;
} else {
spcl.c_flags &= ~DR_HASMETA;
}
ip = getino(ino);
loffset = 0;
if (newtape) {
spcl.c_type = TS_TAPE;
} else if (pos)
spcl.c_type = TS_ADDR;
else
spcl.c_type = TS_INODE;
newtape = 0;
lf_dumpinode(ip);
lf_dumpmeta(ip);
pos = 0;
}
static void
lf_dmpindir(daddr32_t blk, int lvl, u_offset_t *size)
{
int i;
u_offset_t cnt;
daddr32_t idblk[MAXNINDIR];
if ((unsigned)(sblock->fs_bsize) > sizeof (idblk)) {
msg(gettext(
"Inconsistency detected: filesystem block size larger than valid maximum.\n"));
dumpabort();
/*NOTREACHED*/
}
if ((unsigned)NINDIR(sblock) > MAXNINDIR) {
msg(gettext(
"Inconsistency detected: inode has more indirect \
blocks than valid maximum.\n"));
dumpabort();
/*NOTREACHED*/
}
if (blk != 0)
bread(fsbtodb(sblock, blk), (uchar_t *)idblk,
(size_t)sblock->fs_bsize);
else
bzero((char *)idblk, (size_t)sblock->fs_bsize);
if (lvl <= 0) {
cnt = (u_offset_t)(unsigned)NINDIR(sblock) *
(u_offset_t)(unsigned)(sblock->fs_bsize);
if (cnt > *size)
cnt = *size;
*size -= cnt;
lf_blksout(&idblk[0], cnt);
return;
}
lvl--;
for (i = 0; i < NINDIR(sblock); i++) {
lf_dmpindir(idblk[i], lvl, size);
if (*size == 0)
return;
}
}
static void
lf_blksout(daddr32_t *blkp, u_offset_t bytes)
{
u_offset_t i;
u_offset_t tbperfsb = (unsigned)(sblock->fs_bsize / tp_bsize);
u_offset_t j, k, count;
u_offset_t bytepos, diff;
u_offset_t bytecnt = 0;
off_t byteoff = 0; /* bytes to skip within first f/s block */
off_t fragoff = 0; /* frags to skip within first f/s block */
u_offset_t tpblkoff = 0; /* tape blocks to skip in first f/s block */
u_offset_t tpblkskip = 0; /* total tape blocks to skip */
u_offset_t skip; /* tape blocks to skip this pass */
if (pos) {
/*
* We get here if a slave throws a signal to the
* master indicating a partially dumped file.
* Begin by figuring out what was undone.
*/
bytepos = (offset_t)pos * tp_bsize;
if ((loffset + bytes) <= bytepos) {
/* This stuff was dumped already, forget it. */
loffset += (u_offset_t)tp_bsize *
/* LINTED: spurious complaint on sign-extending */
d_howmany(bytes, (u_offset_t)tp_bsize);
return;
}
if (loffset < bytepos) {
/*
* Some of this was dumped, some wasn't.
* Figure out what was done and skip it.
*/
diff = bytepos - loffset;
/* LINTED: spurious complaint on sign-extending */
tpblkskip = d_howmany(diff, (u_offset_t)tp_bsize);
/* LINTED room after EOT is only a few MB */
blkp += (int)(diff / sblock->fs_bsize);
bytecnt = diff % (unsigned)(sblock->fs_bsize);
/* LINTED: result fits, due to modulus */
byteoff = bytecnt % (off_t)(sblock->fs_fsize);
/* LINTED: spurious complaint on sign-extending */
tpblkoff = d_howmany(bytecnt,
(u_offset_t)(unsigned)tp_bsize);
/* LINTED: result fits, due to modulus */
fragoff = bytecnt / (off_t)(sblock->fs_fsize);
bytecnt = (unsigned)(sblock->fs_bsize) - bytecnt;
}
}
loffset += bytes;
while (bytes > 0) {
if (bytes < TP_NINDIR*tp_bsize)
/* LINTED: spurious complaint on sign-extending */
count = d_howmany(bytes, (u_offset_t)tp_bsize);
else
count = TP_NINDIR;
if (tpblkskip) {
if (tpblkskip < TP_NINDIR) {
bytes -= (tpblkskip * (u_offset_t)tp_bsize);
skip = tpblkskip;
tpblkskip = 0;
} else {
bytes -= (offset_t)TP_NINDIR*tp_bsize;
tpblkskip -= TP_NINDIR;
continue;
}
} else
skip = 0;
assert(tbperfsb >= tpblkoff);
assert((count - skip) <= TP_NINDIR);
for (j = 0, k = 0; j < count - skip; j++, k++) {
spcl.c_addr[j] = (blkp[k] != 0);
for (i = tbperfsb - tpblkoff; --i > 0; j++)
spcl.c_addr[j+1] = spcl.c_addr[j];
tpblkoff = 0;
}
/* LINTED (count - skip) will always fit into an int32_t */
spcl.c_count = count - skip;
toslave(dospcl, ino);
bytecnt = MIN(bytes, bytecnt ?
bytecnt : (unsigned)(sblock->fs_bsize));
j = 0;
while (j < count - skip) {
if (*blkp != 0) {
/* LINTED: fragoff fits into 32 bits */
dmpblk(*blkp+(int32_t)fragoff,
/* LINTED: bytecnt fits into 32 bits */
(size_t)bytecnt, byteoff);
}
blkp++;
bytes -= bytecnt;
/* LINTED: spurious complaint on sign-extending */
j += d_howmany(bytecnt, (u_offset_t)tp_bsize);
bytecnt = MIN(bytes, (unsigned)(sblock->fs_bsize));
byteoff = 0;
fragoff = 0;
}
spcl.c_type = TS_ADDR;
bytecnt = 0;
}
pos = 0;
}
void
bitmap(uchar_t *map, int typ)
{
int i;
u_offset_t count;
uchar_t *cp;
if (!newtape)
spcl.c_type = typ;
else
newtape = 0;
for (i = 0; i < TP_NINDIR; i++)
spcl.c_addr[i] = 1;
/* LINTED: spurious complaint on sign-extending */
count = d_howmany(msiz * sizeof (map[0]), tp_bsize) - pos;
for (cp = &map[pos * tp_bsize]; count > 0;
count -= (u_offset_t)(unsigned)spcl.c_count) {
if (leftover) {
spcl.c_count = leftover;
leftover = 0;
} else {
/* LINTED value always less than INT32_MAX */
spcl.c_count = count > TP_NINDIR ? TP_NINDIR : count;
}
spclrec();
for (i = 0; i < spcl.c_count; i++, cp += tp_bsize)
taprec(cp, 0, tp_bsize);
spcl.c_type = TS_ADDR;
}
}
static void
dsrch(daddr32_t d, ulong_t size, u_offset_t filesize)
{
struct direct *dp;
struct dinode *ip;
ulong_t loc;
char dblk[MAXBSIZE];
if (dadded || filesize == 0)
return;
if (filesize > (u_offset_t)size)
filesize = (u_offset_t)size;
if (sizeof (dblk) < roundup(filesize, DEV_BSIZE)) {
msg(gettext(
"Inconsistency detected: filesystem block size larger than valid maximum.\n"));
dumpabort();
/*NOTREACHED*/
}
#ifdef lint
dblk[0] = '\0';
#endif /* lint */
/* LINTED ufs disk addresses always fit into 32 bits */
bread(fsbtodb(sblock, d), (uchar_t *)dblk,
/* LINTED from sizeof check above, roundup() <= max(size_t) */
(size_t)(roundup(filesize, DEV_BSIZE)));
loc = 0;
while ((u_offset_t)loc < filesize) {
/*LINTED [dblk is char[], loc (dp->d_reclen) % 4 == 0]*/
dp = (struct direct *)(dblk + loc);
if (dp->d_reclen == 0) {
(void) snprintf(msgbuf, sizeof (msgbuf), gettext(
"Warning - directory at inode `%lu' is "
"corrupted\n"), ino);
msg(msgbuf);
break;
}
loc += dp->d_reclen;
if (dp->d_ino == 0)
continue;
if (dp->d_name[0] == '.') {
if (dp->d_name[1] == '\0') {
if ((ino_t)(dp->d_ino) != ino) {
(void) snprintf(msgbuf, sizeof (msgbuf),
gettext(
"Warning - directory at inode `%lu' is corrupted:\n\
\t\".\" points to inode `%lu' - run fsck\n"),
ino, dp->d_ino);
msg(msgbuf);
}
continue;
}
if (dp->d_name[1] == '.' && dp->d_name[2] == '\0') {
if (!BIT(dp->d_ino, dirmap) &&
((ip = getino(ino)) == NULL ||
(ip->di_mode & IFMT) != IFATTRDIR)) {
(void) snprintf(msgbuf, sizeof (msgbuf),
gettext(
"Warning - directory at inode `%lu' is corrupted:\n\
\t\"..\" points to non-directory inode `%lu' - run fsck\n"),
ino, dp->d_ino);
msg(msgbuf);
}
continue;
}
}
if (BIT(dp->d_ino, nodmap)) {
dadded++;
return;
}
if (BIT(dp->d_ino, dirmap))
nsubdir++;
}
}
#define CACHESIZE 32
struct dinode *
getino(ino_t ino)
{
static ino_t minino, maxino;
static struct dinode itab[MAXINOPB];
static struct dinode icache[CACHESIZE];
static ino_t icacheval[CACHESIZE], lasti = 0;
static int cacheoff = 0;
int i;
if (ino >= minino && ino < maxino) {
lasti = ino;
return (&itab[ino - minino]);
}
/* before we do major i/o, check for a secondary cache hit */
for (i = 0; i < CACHESIZE; i++)
if (icacheval[i] == ino)
return (icache + i);
/* we need to do major i/o. throw the last inode retrieved into */
/* the cache. note: this copies garbage the first time it is */
/* used, but no harm done. */
icacheval[cacheoff] = lasti;
bcopy(itab + (lasti - minino), icache + cacheoff, sizeof (itab[0]));
lasti = ino;
if (++cacheoff >= CACHESIZE)
cacheoff = 0;
#define INOPERDB (DEV_BSIZE / sizeof (struct dinode))
minino = ino &~ (INOPERDB - 1);
maxino = ((itog(sblock, ino) + 1) * (unsigned)(sblock->fs_ipg));
if (maxino > minino + MAXINOPB)
maxino = minino + MAXINOPB;
bread(
/* LINTED: can't make up for broken system macros here */
(fsbtodb(sblock, itod(sblock, ino)) + itoo(sblock, ino) / INOPERDB),
/* LINTED: (max - min) * size fits into a size_t */
(uchar_t *)itab, (size_t)((maxino - minino) * sizeof (*itab)));
return (&itab[ino - minino]);
}
#define BREADEMAX 32
#ifdef NO__LONGLONG__
#define DEV_LSEEK(fd, offset, whence) \
lseek((fd), (((off_t)(offset))*DEV_BSIZE), (whence))
#else
#define DEV_LSEEK(fd, offset, whence) \
llseek((fd), (((offset_t)((offset)))*DEV_BSIZE), (whence))
#endif
#define BREAD_FAIL(buf, size) { \
breaderrors += 1; \
bzero(buf, (size_t)size); \
}
void
bread(diskaddr_t da, uchar_t *ba, size_t cnt)
{
caddr_t maddr;
uchar_t *dest;
int saverr;
int n;
size_t len;
off64_t filoff;
off64_t mapoff;
off64_t displacement;
static size_t pagesize = 0;
static int breaderrors = 0;
/* mechanics for caching small bread requests. these are */
/* often small ACLs that are used over and over. */
static uchar_t bcache[DEV_BSIZE * CACHESIZE];
static diskaddr_t bcacheval[CACHESIZE];
static int cacheoff = 0;
int i;
if ((cnt >= DEV_BSIZE) && (mapfd != -1)) {
if (pagesize == 0)
pagesize = getpagesize();
/*
* We depend on mmap(2)'s guarantee that mapping a
* partial page will cause the remainder of the page
* to be zero-filled.
*/
filoff = ((off64_t)da) * DEV_BSIZE;
displacement = filoff & (pagesize - 1);
mapoff = filoff - displacement;
/* LINTED offset will fit into 32 bits */
len = (size_t)roundup(cnt + (filoff - mapoff), pagesize);
maddr = mmap64(NULL, len, PROT_READ, MAP_SHARED, mapfd, mapoff);
if (maddr != MAP_FAILED) {
(void) memcpy(ba, maddr + displacement, cnt);
(void) munmap(maddr, len);
return;
}
}
if (DEV_LSEEK(fi, da, L_SET) < 0) {
saverr = errno;
msg(gettext("bread: dev_seek error: %s\n"), strerror(saverr));
/* Don't know where we are, return the least-harmful data */
BREAD_FAIL(ba, cnt);
return;
}
if (read(fi, ba, (size_t)cnt) == (size_t)cnt)
return;
while (cnt != 0) {
if (da >= fsbtodb(sblock, sblock->fs_size)) {
msg(gettext(
"Warning - block %llu is beyond the end of `%s'\n"),
da, disk);
BREAD_FAIL(ba, cnt);
break;
}
if (DEV_LSEEK(fi, da, L_SET) < 0) {
msg(gettext("%s: %s error\n"), "bread", "DEV_LSEEK2");
BREAD_FAIL(ba, cnt);
break;
}
if (cnt < DEV_BSIZE) {
/* small read. check for cache hit. */
for (i = 0; i < CACHESIZE; i++)
if (bcacheval[i] == da) {
bcopy(bcache + (i * DEV_BSIZE),
ba, cnt);
return;
}
/* no cache hit; throw this one into the cache... */
len = cnt;
dest = bcache + (cacheoff * DEV_BSIZE);
bcacheval[cacheoff] = da;
if (++cacheoff >= CACHESIZE)
cacheoff = 0;
} else {
len = DEV_BSIZE;
dest = ba;
}
n = read(fi, dest, DEV_BSIZE);
if (n != DEV_BSIZE) {
n = MAX(n, 0);
bzero(dest+n, DEV_BSIZE-n);
breaderrors += 1;
msg(gettext(
"Warning - cannot read sector %llu of `%s'\n"),
da, disk);
}
if (dest != ba)
bcopy(dest, ba, len);
da++;
/* LINTED character pointers aren't signed */
ba += len;
cnt -= len;
}
if (breaderrors > BREADEMAX) {
msg(gettext(
"More than %d block read errors from dump device `%s'\n"),
BREADEMAX, disk);
dumpailing();
breaderrors = 0;
}
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _DUMPUSG_H
#define _DUMPUSG_H
/*
* Translate from BSD to System V, where possible.
*/
/*
* System-V specific header files
*/
#include <netdb.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/statvfs.h>
#include <sys/systeminfo.h>
#include <sys/vfstab.h>
#include <sys/fs/ufs_inode.h>
#include <sys/fs/ufs_fs.h>
#include <sys/fs/ufs_fsdir.h>
#include <sys/fs/ufs_acl.h>
#include <sys/mnttab.h>
#include <sys/vfstab.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* make mnttab look like mtab
*/
#define MOUNTED MNTTAB
#define mntent mnttab
#define mnt_fsname mnt_special
#define mnt_dir mnt_mountp
#define mnt_type mnt_fstype
#define mnt_opts mnt_mntopts
#define MNTTYPE_42 "ufs"
#define MNTINFO_DEV "dev"
#define setmntent fopen
#define endmntent fclose
/*
* Function translations
*/
#define gethostname(name, len) \
((sysinfo(SI_HOSTNAME, (name), (len)) < 0) ? -1 : 0)
#define signal nsignal /* defined in dumpmain.c */
#define sigvec sigaction /* both struct and func */
#define sv_flags sa_flags
#define sv_handler sa_handler
#define sv_mask sa_mask
#define sigmask(x) x
#define setreuid(r, e) seteuid(e)
#define statfs statvfs /* both struct and func */
#undef setjmp
#define setjmp(b) sigsetjmp((b), 1)
#define longjmp siglongjmp
#define jmp_buf sigjmp_buf
#if !__STDC__
extern int seteuid();
#endif
/*
* Inode related translations
*/
#define ROOTINO UFSROOTINO
#define di_rdev di_ordev
/*
* For stat-inode translation.
* Don't forget the translation from
* nanosecs to usecs (or vica versa)
*/
#define st_spare1 st_atim.tv_nsec
#define st_spare2 st_mtim.tv_nsec
#define st_spare3 st_ctim.tv_nsec
#define TMCONV 1000
#ifdef __cplusplus
}
#endif
#endif /* _DUMPUSG_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/* LINTLIBRARY */
/*
* ftw - file tree walk
*
* int ftw (path, fn, depth) char *path; int (*fn)(); int depth;
*
* Given a path name, ftw starts from the file given by that path
* name and visits each file and directory in the tree beneath
* that file. If a single file has multiple links within the
* structure, it will be visited once for each such link.
* For each object visited, fn is called with three arguments.
* The first contains the path name of the object, the second
* contains a pointer to a stat buffer which will usually hold
* appropriate information for the object and the third will
* contain an integer value giving additional information:
*
* FTW_F The object is a file for which stat was
* successful. It does not guarantee that the
* file can actually be read.
*
* FTW_D The object is a directory for which stat and
* open for read were both successful.
*
* FTW_DNR The object is a directory for which stat
* succeeded, but which cannot be read. Because
* the directory cannot be read, fn will not be
* called for any descendants of this directory.
*
* FTW_NS Stat failed on the object because of lack of
* appropriate permission. This indication will
* be given, for example, for each file in a
* directory with read but no execute permission.
* Because stat failed, it is not possible to
* determine whether this object is a file or a
* directory. The stat buffer passed to fn will
* contain garbage. Stat failure for any reason
* other than lack of permission will be
* considered an error and will cause ftw to stop
* and return -1 to its caller.
*
* If fn returns nonzero, ftw stops and returns the same value
* to its caller. If ftw gets into other trouble along the way,
* it returns -1 and leaves an indication of the cause in errno.
*
* The third argument to ftw does not limit the depth to which
* ftw will go. Rather, it limits the depth to which ftw will
* go before it starts recycling file descriptors. In general,
* it is necessary to use a file descriptor for each level of the
* tree, but they can be recycled for deep trees by saving the
* position, closing, re-opening, and seeking. It is possible
* to start recycling file descriptors by sensing when we have
* run out, but in general this will not be terribly useful if
* fn expects to be able to open files. We could also figure out
* how many file descriptors are available and guarantee a certain
* number to fn, but we would not know how many to guarantee,
* and we do not want to impose the extra overhead on a caller who
* knows how many are available without having to figure it out.
*
* It is possible for ftw to die with a memory fault in the event
* of a file system so deeply nested that the stack overflows.
*/
#include <sys/fs/ufs_inode.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <malloc.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <ftw.h>
static int pwdfd;
static int lf_xftw(
const char *,
int (*)(const char *, const struct stat64 *, int),
int,
int (*)(const char *, struct stat64 *));
int
lf_lftw(
const char *path,
int (*fn)(const char *, const struct stat64 *, int),
int depth)
{
int rc;
if ((pwdfd = open(".", O_RDONLY)) < 0) {
return (-1);
} else {
rc = (lf_xftw(path, fn, depth, lstat64));
(void) close(pwdfd);
return (rc);
}
}
static int
#ifdef __STDC__
lf_xftw(
const char *path,
int (*fn)(const char *, const struct stat64 *, int),
int depth,
int (*statfn)(const char *, struct stat64 *))
#else
lf_xftw(char *path, int (*fn)(), int depth, int (*statfn)())
#endif
{
int n;
int rc, sublen, saverr, attrfd;
DIR *dirp;
char *subpath, *component;
struct stat64 sb;
struct dirent *dp;
extern dev_t partial_dev;
/*
* Try to get file status.
* If unsuccessful, errno will say why.
*/
if ((*statfn)(path, &sb) < 0)
return (errno == EACCES? (*fn)(path, &sb, FTW_NS): -1);
/*
* The stat succeeded, so we know the object exists.
* Make sure it is not a mount point for another filesystem.
* The following check must be made here because:
*
* + namefs can be mounted on anything, but a directory
* + all other filesystems must be mounted on a directory
*/
if (sb.st_dev != partial_dev) {
return (0);
}
/*
* Check for presence of attributes on file
*/
if (pathconf(path, _PC_XATTR_EXISTS) == 1) {
attrfd = attropen64(path, ".", O_RDONLY|O_NONBLOCK);
} else {
attrfd = -1;
}
/*
* If not a directory, call the user function and return.
*/
if ((sb.st_mode & S_IFMT) != S_IFDIR &&
(sb.st_mode & IFMT) != IFATTRDIR) {
rc = (*fn)(path, &sb, FTW_F);
if (rc == 0 && attrfd != -1) {
(void) fchdir(attrfd);
rc = lf_xftw(".", fn, depth-1, statfn);
(void) fchdir(pwdfd);
(void) close(attrfd);
}
return (rc);
}
/*
* The object was a directory and not a mount point.
*
* Open a file to read the directory
*/
dirp = opendir(path);
/*
* Call the user function, telling it whether
* the directory can be read. If it can't be read
* call the user function or indicate an error,
* depending on the reason it couldn't be read.
*/
if (dirp == NULL)
rc = (errno == EACCES? (*fn)(path, &sb, FTW_DNR): -1);
else
rc = (*fn)(path, &sb, FTW_D);
/*
* If the directory has attributes, process the
* attributes before processing the directory contents.
*/
if (rc == 0 && attrfd != -1) {
(void) fchdir(attrfd);
rc = lf_xftw(".", fn, depth-1, statfn);
(void) fchdir(pwdfd);
(void) close(attrfd);
}
if (rc != 0 || dirp == NULL)
return (rc);
/* Allocate a buffer to hold generated pathnames. */
/* LINTED: the length will fit into a signed integer */
n = (int)strlen(path);
sublen = n + MAXNAMLEN + 1; /* +1 for appended / */
subpath = malloc((unsigned)(sublen+1)); /* +1 for NUL */
if (subpath == NULL) {
saverr = errno;
(void) closedir(dirp);
errno = saverr;
return (-1);
}
/* Create a prefix to which we will append component names */
(void) strcpy(subpath, path);
if (subpath[0] != '\0' && subpath[n-1] != '/')
subpath[n++] = '/';
component = &subpath[n];
/* LINTED: result will fit into a 32-bit int */
sublen -= component - subpath;
/*
* Read the directory one component at a time.
* We must ignore "." and "..", but other than that,
* just create a path name and call self to check it out.
*/
while ((dp = readdir(dirp)) != NULL) {
if (strcmp(dp->d_name, ".") != 0 &&
strcmp(dp->d_name, "..") != 0) {
long here;
/* Append component name to the working path */
(void) strncpy(component, dp->d_name, sublen);
component[sublen - 1] = '\0';
/*
* If we are about to exceed our depth,
* remember where we are and close a file.
*/
if (depth <= 1) {
here = telldir(dirp);
(void) closedir(dirp);
}
/*
* Do a recursive call to process the file.
* (watch this, sports fans)
*/
rc = lf_xftw(subpath, fn, depth-1, statfn);
if (rc != 0) {
free(subpath);
if (depth > 1)
(void) closedir(dirp);
return (rc);
}
/*
* If we closed the file, try to reopen it.
*/
if (depth <= 1) {
dirp = opendir(path);
if (dirp == NULL) {
free(subpath);
return (-1);
}
seekdir(dirp, here);
}
}
}
/*
* We got out of the subdirectory loop. The return from
* the final readdir is in dp. Clean up.
*/
free(subpath);
(void) closedir(dirp);
return (0);
}
/stdio.h",.*always ignored: fclose/d
/stdio.h",.*always ignored: fprintf/d
/stdio.h",.*always ignored: printf/d
/stdio.h",.*always ignored: snprintf/d
/time.h",.*sometimes ignored: time/d
/string.h",.*sometimes ignored: memcpy/d
/signal.h",.*always ignored: sighold/d
/signal.h",.*always ignored: sigrelse/d
/unistd.h",.*always ignored: close/d
/unistd.h",.*always ignored: execl/d
/unistd.h",.*always ignored: sleep/d
/myrcmd.c",.*assigned value never used: retval .*(22[0-9])/d
/dumptape.c",.*use of a pointer.*questionable/d
/dumponline.c",.*name used but not defined: log10 /d
/dumponline.c",.*name used but not defined: getfullblkname /d
/dumpmain.c",.*name used but not defined: getfullrawname /d
/^ obuf defined/d
/roll_log.c",.*include file.*unnecessary:/d
/partial.c",.*name used but not defined: ulimit/d
/dirent.h",.*different definitions of macro: MAXNAMLEN/d
/limits.h",.*different definitions of macro: SYS_NMLN/d
/lint suppression directive not used/d
/memutils.c",.*deallocating NULL pointer/d
/memutils.c",.*assigned value never used: allocated at/d
/dumpmain.c",.*assigned value never used:/d
/dumptape.c",.*deallocating NULL pointer/d
/dumpmain.c",.*deallocating NULL pointer/d
/partial.c",.*deallocating NULL pointer/d
/dumpitime.c",.*reference to deallocated memory/d
/dumpitime.c",.*reference using a NULL pointer/d
/assigned value never used: idates_in/d
/roll_log.c",.*assigned value never used/d
/dumptape.c",.*statement not reached/d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1998,2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#include "dump.h"
#include <ftw.h>
#include <ulimit.h>
dev_t partial_dev;
static int partial;
static dev_t devfromopts(struct mntent *);
static int lf_mark_root(dev_t, char *);
static int lf_ftw_mark(const char *, const struct stat64 *, int);
static void markino(ino_t);
void
partial_check(void)
{
struct mntent *mnt;
struct stat64 st;
if (stat64(disk, &st) < 0 ||
(st.st_mode & S_IFMT) == S_IFCHR ||
(st.st_mode & S_IFMT) == S_IFBLK)
return;
partial_dev = st.st_dev;
setmnttab();
while (mnt = getmnttab()) {
st.st_dev = devfromopts(mnt);
if (st.st_dev == NODEV &&
stat64(mnt->mnt_dir, &st) < 0)
continue;
if (partial_dev == st.st_dev) {
if (disk_dynamic) {
/* LINTED: disk is not NULL */
free(disk);
}
disk = rawname(mnt->mnt_fsname);
disk_dynamic = (disk != mnt->mnt_fsname);
partial = 1;
incno = '0';
uflag = 0;
return;
}
}
msg(gettext("`%s' is not on a locally mounted filesystem\n"), disk);
dumpabort();
/*NOTREACHED*/
}
/*
* The device id for the mount should be available in
* the mount option string as "dev=%04x". If it's there
* extract the device id and avoid having to stat.
*/
static dev_t
devfromopts(struct mntent *mnt)
{
char *str;
str = hasmntopt(mnt, MNTINFO_DEV);
if (str != NULL && (str = strchr(str, '=')))
return ((dev_t)strtol(str + 1, (char **)NULL, 16));
return (NODEV);
}
int
partial_mark(int argc, char **argv)
{
char *path;
struct stat64 st;
if (partial == 0)
return (1);
while (--argc >= 0) {
path = *argv++;
if (stat64(path, &st) < 0 ||
st.st_dev != partial_dev) {
msg(gettext("`%s' is not on dump device `%s'\n"),
path, disk);
dumpabort();
/*NOTREACHED*/
}
if (lf_mark_root(partial_dev, path)) {
msg(gettext(
"Cannot find filesystem mount point for `%s'\n"),
path);
dumpabort();
/*NOTREACHED*/
}
/* LINTED this ulimit will always be < INT_MAX */
if (lf_lftw(path, lf_ftw_mark, (int)ulimit(UL_GDESLIM, 0) / 2)
< 0) {
int saverr = errno;
msg(gettext("Error in %s (%s)\n"),
"ftw", strerror(saverr));
dumpabort();
/*NOTREACHED*/
}
}
return (0);
}
/* mark directories between target and root */
static int
lf_mark_root(dev_t dev, char *path)
{
struct stat64 st;
char dotdot[MAXPATHLEN + 16];
char *slash;
if (strlen(path) > sizeof (dotdot))
return (1);
(void) strcpy(dotdot, path);
if (stat64(dotdot, &st) < 0)
return (1);
/* if target is a regular file, find directory */
if ((st.st_mode & S_IFMT) != S_IFDIR)
if (slash = strrchr(dotdot, '/'))
/* "/file" -> "/" */
if (slash == dotdot)
slash[1] = 0;
/* "dir/file" -> "dir" */
else
slash[0] = 0;
else
/* "file" -> "." */
(void) strcpy(dotdot, ".");
/* keep marking parent until we hit mount point */
do {
if (stat64(dotdot, &st) < 0 ||
(st.st_mode & S_IFMT) != S_IFDIR ||
st.st_dev != dev)
return (1);
markino(st.st_ino);
if (strlen(dotdot) > (sizeof (dotdot) - 4))
return (1);
(void) strcat(dotdot, "/..");
} while (st.st_ino != 2);
return (0);
}
/*ARGSUSED*/
static int
lf_ftw_mark(const char *name, const struct stat64 *st, int flag)
{
if (flag != FTW_NS) {
/* LINTED ufs only uses the lower 32 bits */
markino((ino_t)st->st_ino);
}
return (0);
}
static void
markino(ino_t i)
{
struct dinode *dp;
dp = getino(ino = i);
mark(dp);
}
/*
* Copyright (c) 1998,2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#include <sys/types.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
/*
* Convert a ctime(3) format string into a system format date.
* Return the date thus calculated.
*
* Return -1 if the string is not in ctime format.
*/
/*
* Offsets into the ctime string to various parts.
*/
#define E_MONTH 4
#define E_DAY 8
#define E_HOUR 11
#define E_MINUTE 14
#define E_SECOND 17
#define E_YEAR 20
#ifdef __STDC__
static int lookup(char *);
static time_t emitl(struct tm *);
#else
static int lookup();
static time_t emitl();
#endif
time_t
unctime(str)
char *str;
{
struct tm then;
char dbuf[30];
/* Definition of ctime(3) is 24 characters + newline + NUL */
(void) strncpy(dbuf, str, 24);
dbuf[24] = '\0';
dbuf[E_MONTH+3] = '\0';
then.tm_mon = lookup(&dbuf[E_MONTH]);
if (then.tm_mon < 0) {
return (-1);
}
then.tm_mday = atoi(&dbuf[E_DAY]);
then.tm_hour = atoi(&dbuf[E_HOUR]);
then.tm_min = atoi(&dbuf[E_MINUTE]);
then.tm_sec = atoi(&dbuf[E_SECOND]);
then.tm_year = atoi(&dbuf[E_YEAR]) - 1900;
return (emitl(&then));
}
static char months[] =
"JanFebMarAprMayJunJulAugSepOctNovDec";
static int
lookup(str)
char *str;
{
char *cp, *cp2;
for (cp = months, cp2 = str; *cp != 0; cp += 3)
if (strncmp(cp, cp2, 3) == 0)
/* LINTED ptr arith will give < INT_MAX result */
return (((int)(cp-months)) / 3);
return (-1);
}
/*
* Routine to convert a localtime(3) format date back into
* a system format date.
*/
static time_t
emitl(dp)
struct tm *dp;
{
dp->tm_isdst = -1;
return (mktime(dp));
}
|