Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
#!/bin/sh -
#	$NetBSD: MAKEDEV.tmpl,v 1.233 2022/12/28 19:23:02 jakllsch Exp $
#
# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
# 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.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
#
#
###########################################################################
#
#   PLEASE RUN "cd ../share/man/man8 ; make makedevs"
#   AFTER CHANGING THIS FILE, AND COMMIT THE UPDATED MANPAGE!
#
###########################################################################
#
# Device "make" file.  Valid special arguments:
#	all	makes all known devices, including local devices.
#		Tries to make the 'standard' number of each type.
#	init	A set of devices that is used for MFS /dev by init.
#		May be equal to "all".
#	floppy	devices to be put on install floppies
#	ramdisk	devices to be put into INSTALL kernel ramdisks.
#	std	standard devices
#	local	configuration specific devices
#	lua	Lua device
#	wscons	make wscons devices
#	usbs	make USB devices
#
# Tapes:
#	st*	SCSI tapes
#	wt*	QIC-interfaced (e.g. not SCSI) 3M cartridge tape
#	ht*	MASSBUS TM03 and TU??
#	mt*	MSCP tapes (e.g. TU81, TK50)
#	tm*	UNIBUS TM11 and TE10 emulations (e.g. Emulex TC-11)
#	ts*	UNIBUS TS11
#	ut*	UNIBUS TU45 emulations (e.g. si 9700)
#	uu*	TU58 cassettes on DL11 controller
#
# Disks:
#	dk*	wedge disk slices
#	ccd*	concatenated disk devices
#	cd*	SCSI or ATAPI CD-ROM
#	cgd*	cryptographic disk devices
#	raid*	RAIDframe disk devices
#	sd*	SCSI disks
#	wd*	"winchester" disk drives (ST506,IDE,ESDI,RLL,...)
#	bmd*	Nereid bank memory disks
#	ed*	IBM PS/2 ESDI disk devices
#	fd*	"floppy" disk drives (3 1/2", 5 1/4")
#	fss*	Files system snapshot devices
#	gdrom*	Dreamcast "gigadisc" CD-ROM drive
#	hk*	UNIBUS RK06 and RK07
#	hp*	MASSBUS RM??
#	ld*	Logical disk devices (e.g., hardware RAID)
#	mcd*	Mitsumi CD-ROM
#	md*	memory pseudo-disk devices
#	ofdisk*	OpenFirmware disk devices
#	ra*	MSCP disks (RA??, RD??)
#	rb*	730 IDC w/ RB80 and/or RB02
#	rd*	HDC9224 RD disks on VS2000
#	rl*	UNIBUS RL02
#	rx*	MSCP floppy disk (RX33/50/...)
#	up*	other UNIBUS devices (e.g. on Emulex SC-21V controller)
#	vnd*	"file" pseudo-disks
#	xbd*	Xen virtual disks
#	xd*	Xylogic 753/7053 disks
#	xy*	Xylogic 450/451 disks
#
# Pointing devices:
#	wsmouse* wscons mouse events
#	lms*	Logitech bus mouse
#	mms*	Microsoft bus mouse
#	qms*	"quadrature mouse"
#	pms*	PS/2 mouse
#	mouse	mouse (provides events, for X11)
#
# Keyboard devices:
#	wskbd*	wscons keyboard events
#	kbd	raw keyboard (provides events, for X11)
#	kbdctl	keyboard control
#
# Terminals/Console ports:
#	tty[01]*	standard serial ports
#	tty0*	SB1250 ("sbscn") serial ports (sbmips)
#	ttyE*	wscons - Workstation console ("wscons") glass-tty emulators
#	ttyCZ?	Cyclades-Z multiport serial boards.  Each "unit"
#		makes 64 ports.
#	ttyCY?	Cyclom-Y multiport serial boards. Each "unit" makes
#		32 ports.
#	ttye*	ITE bitmapped consoles
#	ttyv0	pccons
#	ttyC?	NS16550 ("com") serial ports
#	ttyS*	SA1110 serial port (hpcarm)
#	ttyTX?	TX39 internal serial ports (hpcmips)
#	ttyB?	DEC 3000 ZS8530 ("scc") serial ports (alpha)
#	ttyA*	mfc serial ports (amiga)
#	ttyB*	msc serial ports (amiga)
#	ttyC*	com style serial ports (DraCo, HyperCom) (amiga)
#		On the DraCo, units 0 and 1 are the built-in "modem" and
#		"mouse" ports, if configured.
#	ttyA0   8530 Channel A (formerly ser02) (atari)
#	ttyA1	8530 Channel B (formerly mdm02) (atari)
#	ttyB0	UART on first 68901 (formerly mdm01) (atari)
#	ixpcom	IXP12x0 COM ports
#	epcom	EP93xx COM ports
#	plcom	ARM PL01[01] serial ports
#	wmcom	EPOC Windermere COM ports
#	ttyM?	HP200/300 4 port serial mux interface (hp300)
#	ttya	"ttya" system console (luna68k)
#	ttyb	second system serial port (luna68k)
#	tty*	Onboard serial ports (mvme68k)
#		On the mvme147 these are: ttyZ1, ttyZ2 and ttyZ3.
#		On the mvme167, and '177: ttyC1, ttyC2 and ttyC3.
#		Note that tty[CZ]0 is grabbed by the console device
#		so is not created by default
#	dc*	PMAX 4 channel serial interface (kbd, mouse, modem, printer)
#	scc*	82530 serial interface (pmax)
#	ttyZ*	Zilog 8530 ("zstty") serial ports
#	tty[abcd]	Built-in serial ports (sparc)
#	tty*	Z88530 serial controllers (sparc64)
#	ttyh*	SAB82532 serial controllers (sparc64)
#	tty[a-j]	Built-in serial ports (sun2, sun3)
#	ttyC?	pccons (arc)
#	dz*	UNIBUS DZ11 and DZ32 (vax)
#	dh*	UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11) (vax)
#	dmf*	UNIBUS DMF32 (vax)
#	dhu*    UNIBUS DHU11 (vax)
#	dmz*    UNIBUS DMZ32 (vax)
#	dl*	UNIBUS DL11 (vax)
#	xencons	Xen virtual console
#	ttyVI??	viocon(4)
#
# Terminal multiplexors:
#	dc*	4 channel serial interface (keyboard, mouse, modem, printer)
#	dh*	UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11)
#	dhu*	UNIBUS DHU11
#	dl*	UNIBUS DL11
#	dmf*	UNIBUS DMF32
#	dmz*	UNIBUS DMZ32
#	dz*	UNIBUS DZ11 and DZ32
#	scc*	82530 serial interface
#
# Call units:
#	dn*	UNIBUS DN11 and emulations (e.g. Able Quadracall)
#
# Pseudo terminals:
#	ptm	pty multiplexor device, and pts directory
#	pty*	set of 16 master and slave pseudo terminals
#	opty	first 16 ptys, to save inodes on install media
#	ipty	first 2 ptys, for install media use only
#
# Printers:
#	arcpp*	Archimedes parallel port
#	lpt*	stock lp
#	lpa*	interruptless lp
#	par*	Amiga motherboard parallel port
#	cpi*	Macintosh Nubus CSI parallel printer card
#
# USB devices:
#	usb*	USB control devices
#	uhid*	USB generic HID devices
#	ulpt*	USB printer devices
#	ugen*	USB generic devices
#	ttyHS*	USB Option N.V. modems
#	ttyU*	USB modems
#	ttyY*	USB serial adapters
#
# Video devices:
#	bwtwo*	monochromatic frame buffer
#	cgtwo*	8-bit color frame buffer
#	cgthree*	8-bit color frame buffer
#	cgfour*	8-bit color frame buffer
#	cgsix*	accelerated 8-bit color frame buffer
#	cgeight*	24-bit color frame buffer
#	etvme	Tseng et-compatible cards on VME (atari)
#	ik*	UNIBUS interface to Ikonas frame buffer
#	leo	Circad Leonardo VME-bus true color (atari)
#	ps*	UNIBUS interface to Picture System 2
#	qv*	QVSS (MicroVAX) display
#	tcx*	accelerated 8/24-bit color frame buffer
#
# Maple bus devices:
#	maple	Maple bus control devices
#	mlcd*	Maple bus LCD devices
#	mmem*	Maple bus storage devices
#
# IEEE1394 bus devices:
#	fw*	IEEE1394 bus generic node access devices
#	fwmem*	IEEE1394 bus physical memory of the remote node access devices
#
# Special purpose devices:
#	ad*	UNIBUS interface to Data Translation A/D converter
#	agp*	AGP GART devices
#	altq	ALTQ control interface
#	amr*	AMI MegaRaid control device
#	apm	power management device
#	audio*	audio devices
#	bell*	OPM bell device (x68k)
#	bktr	Brooktree 848/849/878/879 based TV cards
#	bpf	packet filter
#	bthub	Bluetooth Device Hub control interface
#	cfs*	Coda file system device
#	ch*	SCSI media changer
#	cir*	Consumer IR
#	clockctl clock control for non root users
#	cpuctl	CPU control
#	crypto	hardware crypto access driver
#	dmoverio hardware-assisted data movers
#	dpt*	DPT/Adaptec EATA RAID management interface
#	dpti*	DPT/Adaptec I2O RAID management interface
#	drm*	Direct Rendering Manager interface
#	dtv*	Digital TV interface
#	fb*	PMAX generic framebuffer pseudo-device
#	fd	file descriptors
#	gpiopps* 1PPS signals on GPIO pins
#	grf*	graphics frame buffer device
#	hdaudio* High Definition audio control device
#	hdmicec* HDMI CEC devices
#	hil	HP300 HIL input devices
#	icp	ICP-Vortex/Intel RAID control interface
#	iic*	IIC bus device
#	io	x86 IOPL access for COMPAT_10, COMPAT_FREEBSD
#	iop*	I2O IOP control interface
#	ipmi*	OpenIPMI compatible interface
#	ipl	IP Filter
#	irframe* IrDA physical frame
#	ite*	terminal emulator interface to HP300 graphics devices
#	joy*	joystick device
#	kttcp	kernel ttcp helper device
#	lockstat kernel locking statistics
#	magma*	Magma multiport serial/parallel cards
#	midi*	MIDI
#	mfi*	LSI MegaRAID/MegaSAS control interface
#	mlx*	Mylex DAC960 control interface
#	mly*	Mylex AcceleRAID/eXtremeRAID control interface
#	np*	UNIBUS Ethernet co-processor interface, for downloading.
#	npf	NPF packet filter
#	nvme*	Non-Volatile Memory Host Controller Interface device driver
#	nvme*ns* Non-Volatile Memory namespace
#	nvmm	NetBSD Virtual Machine Monitor
#	openfirm OpenFirmware accessor
#	pad*	Pseudo-audio device driver
#	pci*	PCI bus access devices
#	pf	PF packet filter
#	putter	Pass-to-Userspace Transporter
#	px*	PixelStamp Xserver access
#	qemufwcfg* QEMU Firmware Configuration
#	radio*	radio devices
#	random	Random number generator
#	rtc*	RealTimeClock
#	scmd*	Sparkfun Serial Controlled Motor Driver
#	scsibus* SCSI busses
#	se*	SCSI Ethernet
#	ses*	SES/SAF-TE SCSI Devices
#	sht3xtemp*	Sensirion SHT3X temperature and humidity device driver
#	speaker	PC speaker		(XXX - installed)
#	spi*	SPI bus device
#	sram	battery backuped memory (x68k)
#	srt*	source-address based routing
#	ss*	SCSI scanner
#	stic*	PixelStamp interface chip
#	sysmon	System Monitoring hardware
#	tap*	virtual Ethernet device
#	tprof	task profiler
#	tun*	network tunnel driver
#	twa	3ware Apache control interface
#	twe	3ware Escalade control interface
#	uk*	unknown SCSI device
#	veriexec Veriexec fingerprint loader
#	vhci	virtual host controller interface
#	video*	video capture devices
#	view*	generic interface to graphic displays (Amiga)
#	wsfont*	console font control
#	wsmux*	wscons event multiplexor
#	xenevt	Xen event interface
#
# iSCSI communication devices
#	iscsi*	iSCSI driver and /sbin/iscsid communication
#
# Trusted Computing devices
#	tpm	Trusted Platform Module
#
# Debugging and tracing
#	dtrace	Dynamic tracing framework


#
# NOTE:
#
# * MAKEDEV is used both as a standalone script (via "sh ./MAKEDEV
#   all" or similar), and as a function library for MAKEDEV.local (via
#   "MAKEDEV_AS_LIBRARY=1 . MAKEDEV").  Because of this, the script
#   should consist almost entirely of function definitions, apart from a
#   few lines right at the end.
#
# * MAKEDEV may be executed in an environment that is missing some
#   common commands.  For example, it may be executed from a minimal
#   system used during installation, or it may be executed early in the
#   boot sequence before most file systems have been mounted.  It may
#   also be executed in a cross-build environment on a non-NetBSD host.
#

usage()
{
	cat 1>&2 << _USAGE_
Usage: ${0##*/} [-fMsu] [-m mknod] [-p pax] [-t mtree] special [...]
	Create listed special devices.  Options:
	-f		Force permissions to be updated on existing devices.
	-M		Create memory file system.
	-m mknod	Name of mknod(8) program.  [\$TOOL_MKNOD or mknod]
	-p pax  	Name of pax(1) program.  [\$TOOL_PAX or pax]
	-s		Generate mtree(8) specfile instead of creating devices.
	-t mtree	Name of mtree(8) program.  [\$TOOL_MTREE or mtree]
	-u		Don't re-create devices that already exist.

_USAGE_
	exit 1
}

# zeropad width number
#	display number with a zero (`0') padding of width digits.
#
zeropad()
{
	case $(($1 - ${#2})) in
	5)	echo 00000$2;;
	4)	echo 0000$2;;
	3)	echo 000$2;;
	2)	echo 00$2;;
	1)	echo 0$2;;
	0)	echo $2;;
	*)	die "bad padding" ;;
	esac
}

# hexprint number
#	display (base10) number as hexadecimal
#
hexprint()
{
	val="$(($1 + 0))"
	hex=
	set -- 0 1 2 3 4 5 6 7 8 9 a b c d e f
	while [ "$val" -gt 0 ]; do
		eval hex=\${$(($val % 16 + 1))}\$hex
		val="$(($val / 16))"
	done
	echo "${hex:-0}"
}

# linecount multiline_string
#	count the number of lines in the string
#
linecount()
{
	local IFS='
' # just a newline, no other white space between the quotes
	set -- $1
	echo $#
}

# nooutput -12 cmd [args...]
#	run a command with stdout and/or stderr ignored.
#	"nooutput -1 cmd" is like "cmd >/dev/null";
#	"nooutput -2 cmd" is like "{ cmd ; } 2>/dev/null";
#	"nooutput -12 cmd" is like "{ cmd ; } >/dev/null 2>&1";
#	except they should work even if /dev/null doesn't [yet] exist.
#
#	The "{...}" wrapper used in cases where stderr is redirected
#	serves to capture shell error messages such as "cmd: not found".
#
nooutput()
{
	local flags="$1" ; shift
	local junk
	case "$flags" in
	"-1")	junk="$( "$@" )" ;;
	"-2")	( exec 4>&1 ; junk="$( { "$@" ; } 2>&1 1>&4 )" ) ;;
	"-12")	junk="$( { "$@" ; } 2>&1 )" ;;
	*)	warn "Incorrect use of nooutput" ;;
	esac
}

# check_pax path_to_pax
#	Check whether pax exists and supports the command line options
#	and input format that we will want to use.
#
check_pax()
{
	local pax="$1"
	echo ". type=dir optional" | nooutput -12 "${pax}" -r -w -M -pe .
}

# check_mtree path_to_mtree
#	Check whether mtree exists and supports the command line options
#	and input format that we will want to use.
#
check_mtree()
{
	local mtree="$1"
	echo ". type=dir optional" | nooutput -12 "${mtree}" -e -U
}

# setup args...
#	Parse command line arguments, exit on error.
#	Callers should shift $((OPTIND - 1)) afterwards.
#
setup()
{
	PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue

	: ${HOST_SH:=sh}
	: ${TOOL_MKNOD:=mknod}
	: ${TOOL_MTREE:=mtree}
	: ${TOOL_PAX:=pax}
	status=0
	do_create_mfs=false
	do_force=false
	do_mknod=false
	do_pax=false
	do_mtree=false
	do_redirect=false
	do_specfile=false
	do_update=false
	opts=
	while getopts Mfm:p:st:u ch; do
		# Note that $opts is only for options passed through to
		# MAKEDEV.local, not for all options.
		case ${ch} in
		M)
			# "-M" sets do_create_mfs;
			# "-M -M" is for use from init(8), and sets do_redirect
			do_redirect=$do_create_mfs
			do_create_mfs=true
			;;
		f)	do_force=true
			opts="${opts} -f"
			;;
		m)	TOOL_MKNOD=${OPTARG}
			do_mknod=true
			opts="${opts} -m ${OPTARG}"
			;;
		p)	TOOL_PAX="${OPTARG}"
			if check_pax "${TOOL_PAX}"; then
				do_pax=true
				# do not add this to $opts; we will later
				# add "-s" instead.
			else
				warn "Ignored -p option:" \
					"${TOOL_PAX} is missing or broken"
				do_mknod=true
			fi
			;;
		s)	do_specfile=true
			opts="${opts} -s"
			;;
		t)	TOOL_MTREE="${OPTARG}"
			if check_mtree "${TOOL_MTREE}"; then
				do_mtree=true
				# do not add this to $opts; we will later
				# add "-s" instead.
			else
				warn "Ignored -t option:" \
					"${TOOL_MTREE} is missing or broken"
				do_mknod=true
			fi
			;;
		u)
			do_update=true
			opts="${opts} -u"
			;;
		*)	usage ;;
		esac
	done

	shift $((${OPTIND} - 1))
	[ $# -gt 0 ] || usage

	u_root="%uid_root%"
	u_uucp="%uid_uucp%"
	g_gpio="%gid__gpio%"
	g_kmem="%gid_kmem%"
	g_ntpd="%gid_ntpd%"
	g_nvmm="%gid_nvmm%"
	g_operator="%gid_operator%"
	g_wheel="%gid_wheel%"
	dialin=0
	dialout=524288
	callunit=262144

	# only allow read&write for owner by default
	umask 077

	# Set fdesc_mounted=true if the fdesc file system is mounted
	# on the current directory (typically "/dev").
	# Later, this will be used to suppress creation of device nodes
	# that are supplied by the fdesc file system.
	#
	fdesc_mounted=false
	if [ -d fd ]; then
		# Parse the output from "mount -u -o nosuchoption .".
		# We don't parse the output from df(1) because that's
		# less likely to be available on install media.
		#
		# If the current directory is a mount point for the
		# fdesc file system, then the expected output (whether
		# or not the current user is root) is:
		#	mount_fdesc: -o suchoption: option not supported.
		#
		# If the current directory is not a mount point, then
		# the expected output is:
		#	mount: .: unknown special file or file system.
		#
		# If we are not running on NetBSD, or mount(8) is not
		# found, then we should get some other error message.
		#
		case "$({ LC_ALL=C mount -u -o nosuchoption . ; } 2>&1)" in
		*mount_fdesc*)	fdesc_mounted=true ;;
		esac
	fi

	# do_force requires mknod
	if $do_force; then
		if $do_mtree || $do_pax || $do_specfile; then
			die "-f option works only with mknod"
		fi
		do_mknod=true
	fi

	# do_force and do_update do not work together
	if $do_force && $do_update; then
		die "-f and -u options do not work together"
	fi

	# If no explicit method was specified on the command line or
	# forced above, then use one of mtree, pax, or mknod, in that
	# order of preference.
	#
	# mtree is preferred because it's fast and designed for the
	# purpose.  However, it's unlikely to be available early in the
	# boot sequence, when init(8) may invoke MAKEDEV(8).
	#
	# pax is usually acceptable, and it's likely to be available
	# early in the boot sequence.  However, it's much slower than mtree.
	#
	# mknod is just very slow, because the shell has to fork for
	# each device node.
	#

	case ",${do_mtree},,${do_pax},,${do_mknod},,${do_specfile}," in
	( ,false,,false,,false,,false, )
		if check_mtree "${TOOL_MTREE}"; then
			do_mtree=true
		elif check_pax "${TOOL_PAX}"; then
			do_pax=true
		else
			do_mknod=true
		fi
		;;
	( *,true,*,true,* )
		die "-m, -p, -s, and -t options are mutually exclusive"
		;;
	esac

	# If we are using mknod, then decide what options to pass it.
	MKNOD="${TOOL_MKNOD:-mknod} -F netbsd"
	if $do_mknod; then
		if $do_force; then
			MKNOD="${MKNOD} -R"
		else
			MKNOD="${MKNOD} -r"
		fi
	fi

	# do_mtree or do_pax internally implies do_specfile.
	# This happens after checking for mutually-exclusive options.
	if $do_mtree || $do_pax && ! $do_specfile; then
		do_specfile=true
		opts="${opts} -s"
	fi
}

# specfile_before
#	This is called before the bulk of the makedev processing,
#	if do_specfile is set.
#
#	It simply prints ". type=dir optional", which must be the
#	first line of the specfile.
#
specfile_before()
{
	echo ". type=dir optional"
}

# mtree_after
#	Output in specfile format is piped into this function.
#
#	It uses mtree to create the devices defined in the specfile.
#
mtree_after()
{
	nooutput -1 "${TOOL_MTREE}" -e -U
}

# pax_after
#	Output in specfile format is piped into this function.
#
#	It uses pax to create the devices defined in the specfile.
#
pax_after()
{
	# Run pax in an empty directory, so it pays
	# attention only to the specfile, without being
	# confused by the existing contents of the target
	# directory.  Without this, pax would complain "file
	# would overwrite itself" for already-existing
	# device nodes.
	tmpdir=./tmp.$$
	mkdir "${tmpdir}" || die "can't create temporary directory"
	cd "${tmpdir}" || die "can't cd to temporary directory"
	"${TOOL_PAX}" -r -w -M -pe ..
	pax_status=$?
	cd .. # back to where we started
	rmdir "${tmpdir}"
	return $pax_status
}

# makedev_main makedev_name args...
#	Perform most of the work of the main program.  makedev_name
#	is typically "makedev", but may be the name of some other
#	makedev-like function (if we are invoked from MAKEDEV.local or
#	some other script).  The other args to this function are the
#	command line args with which the MAKEDEV (or MAKEDEV.local)
#	script was invoked.
#
makedev_main()
{
	local makedev="$1" ; shift

	# Parse command line args
	setup ${1+"$@"}
	shift $((${OPTIND}-1))

	if $do_create_mfs; then
		# Count inodes and create mfs file system.
		# The makedev call merely updates $count_nodes.
		count_nodes=0
		$makedev ${1+"$@"}
		create_mfs_dev $count_nodes
		unset count_nodes
	fi

	# Set before, middle, and after variables, so we can do
	# something like "( $before && $middle ) | $after",
	# except it will have to be more complex so we can capture
	# the exit status from both sides of the pipe.
	#
	if $do_specfile; then
		before=specfile_before
	else
		before=:
	fi
	middle='$makedev ${1+"$@"} && (exit $status)'
	if $do_mtree; then
		after=mtree_after
	elif $do_pax ; then
		after=pax_after
	else
		after=cat
	fi

	# Actually perform the "{ $before && $middle } | $after" commands.
	#
	# We go to some trouble to ensure that, if any of
	# $before, $middle, or $after fails, then we also
	# exit with a non-zero status.
	#
	# In the block below, fd 3 is a copy of the original stdout,
	# and fd 4 goes to a subshell that analyses the exit status
	# status from the other commands.
	#
	{
		exec 3>&1;
		{
			{ eval "$before" && eval "$middle"; echo $? >&4; } \
			| { eval "$after"; echo $? >&4; } \
		} 4>&1 1>&3 \
		| (
			read status1;
			read status2; 
			case "$status1,$status2" in
			0,0) exit 0;;
			0,*) exit $status2;;
			*,*) exit $status1;;
			esac
		)
	}
}

#
# functions available to create nodes:
#
# mkdev name [b|c] major minor [mode{=600} [gid{=0} [uid{=0}]]]
#	create device node `name' with the appropriate permissions
#
# lndev src target
#	create a symlink from src to target
#
# makedir dir mode
#	create directory with appropriate mode
#

mkdev()
{
	if [ -n "$count_nodes" ]; then
		count_nodes=$((count_nodes + 1))
		return
	fi
	if $do_update && test -e $1; then
		return
	fi
	if $do_specfile; then
		case $2 in
		b)	type=block ;;
		c)	type=char ;;
		esac
		echo "./$1 type=${type} device=netbsd,$3,$4 mode=${5:-600} gid=${6:-$g_wheel} uid=${7:-$u_root}"
	else
		${MKNOD} -m ${5:-600} -g \#${6:-$g_wheel} -u \#${7:-$u_root} $1 $2 $3 $4
	fi
}

lndev()
{
	if [ -n "$count_nodes" ]; then
		count_nodes=$((count_nodes + 1))
		return
	fi
	if $do_update && test -e $2; then
		return
	fi
	if $do_specfile; then
		echo "./$2 type=link link=$1 mode=0700 gid=$g_wheel uid=$u_root"
	else
		ln -f -s $1 $2
	fi
}

makedir()
{
	if [ -n "$count_nodes" ]; then
		count_nodes=$((count_nodes + 1))
		return
	fi
	if $do_update && test -e $1; then
		return
	fi
	if $do_specfile; then
		echo "./$1 type=dir mode=$2 gid=$g_wheel uid=$u_root"
	else
		nooutput -2 mkdir $1
		chmod $2 $1
	fi
}

warn()
{
	echo 1>&2 "$0: $*"
	status=1
}

die()
{
	echo 1>&2 "$0: $*"
	exit 1
}

# makedev special [...]
#	the main loop
#
makedev()
{

for i
do

case $i in

%MD_DEVICES%

all)
	makedev all_md
	makedev std fd ptm
	makedev dk0 dk1 dk2 dk3 dk4 dk5 dk6 dk7
	makedev dk8 dk9 dk10 dk11 dk12 dk13 dk14 dk15
	makedev dk16 dk17 dk18 dk19 dk20 dk21 dk22 dk23
	makedev dk24 dk25 dk26 dk27 dk28 dk29 dk30 dk31
	makedev ccd0 ccd1 ccd2 ccd3
	makedev cgd0 cgd1 cgd2 cgd3 cgd4 cgd5 cgd6 cgd7
	makedev fss0 fss1 fss2 fss3
	makedev md0 md1
	makedev raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7
	makedev vnd0 vnd1 vnd2 vnd3
	makedev iscsi0
	makedev bpf npf
	makedev tun0 tun1 tun2 tun3
	makedev ipl pf crypto random
	makedev lockstat clockctl cpuctl
	makedev atabus0 atabus1 atabus2 atabus3 atabus4 atabus5 atabus6 atabus7
	makedev srt0 srt1 srt2 srt3
	makedev tap tap0 tap1 tap2 tap3
	makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
	makedev gpiopps0
	makedev pad pad0 pad1 pad2 pad3
	makedev bthub
	makedev putter
	makedev drvctl
	makedev video
	makedev dtv
	makedev drm0 drm1 drm2 drm3
	makedev altmem
	makedev zfs
	makedev lua
	makedev hdmicec0
	makedev dtrace
	makedev veriexec
	makedev autofs
	makedev fw0 fw1 fw2 fw3
	makedev ipmi0
	makedev qemufwcfg
	makedev sht3xtemp0
	makedev scmd0
	makedev local # do this last
	;;

init)
	# unless overridden by MD entry, this is equal to 'all'
	makedev all opty
	;;

%MI_DEVICES_BEGIN%
audio)
	makedev audio0 audio1 audio2 audio3
	makedev hdaudio0 hdaudio1 hdaudio2 hdaudio3
	lndev sound0 sound
	lndev audio0 audio
	lndev mixer0 mixer
	lndev audioctl0 audioctl
	;;

gpio)
	makedev gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
	lndev gpio0 gpio
	;;

gpiopps)
	makedev gpiopps0
	lndev gpiopps0 gpiopps
	;;

lua)
	makedev lua0
	lndev lua0 lua
	;;

pad)
	makedev pad0 pad1 pad2 pad3
	lndev pad0 pad
	;;

qemufwcfg)
	makedev qemufwcfg0
	lndev qemufwcfg0 qemufwcfg
	;;

radio)
	makedev radio0 radio1
	lndev radio0 radio
	;;

video)
	makedev video0 video1 video2 video3
	;;

dtv)
	makedev dtv0 dtv1 dtv2 dtv3
	;;

iic)
	makedev iic0 iic1 iic2 iic3
	;;

altmem)
	makedev altmem0 altmem1
	;;

ramdisk)
	makedev floppy md0
	;;

sht3xtemp)
    	makedev sht3xtemp0
    	;;

scmd)
    	makedev scmd0
    	;;

usbs)
	makedev usb usb0 usb1 usb2 usb3 usb4 usb5 usb6 usb7
	makedev usb8 usb9 usb10 usb11 usb12 usb13 usb14 usb15
	makedev uhid0 uhid1 uhid2 uhid3 uhid4 uhid5
	makedev uhid6 uhid7 uhid8 uhid9 uhid10 uhid11
	makedev uhid12 uhid13 uhid14 uhid15
	makedev ulpt0 ulpt1
	makedev ttyU0 ttyU1 ttyU2 ttyU3 ttyU4 ttyU5 ttyU6 ttyU7
	makedev ttyY0 ttyY1
	makedev ttyHS0
	makedev utoppy0 utoppy1
	makedev ugen0 ugen1 ugen2 ugen3
	;;

std)
	mkdev		console c %cons_chr% 0	600
	mkdev		constty c %cons_chr% 1	600
	mkdev		drum	c %swap_chr% 0	640 $g_kmem
	mkdev		kmem	c %mem_chr% 1	640 $g_kmem
	mkdev		mem	c %mem_chr% 0	640 $g_kmem
	mkdev		null	c %mem_chr% 2	666
	mkdev		full	c %mem_chr% 11	666
	mkdev		zero	c %mem_chr% 12	666
	mkdev		klog	c %log_chr% 0	600
	mkdev		ksyms	c %ksyms_chr% 0 440 $g_kmem
	mkdev		random	c %rnd_chr% 0	444
	mkdev		urandom	c %rnd_chr% 1	644
	if ! $fdesc_mounted; then
		mkdev	tty	c %ctty_chr% 0		666
		mkdev	stdin	c %filedesc_chr% 0	666
		mkdev	stdout	c %filedesc_chr% 1	666
		mkdev	stderr	c %filedesc_chr% 2	666
	fi
	;;

usb)
	mkdev usb c %usb_chr% 255 444
	;;

usb[0-9]*)
	unit=${i#usb}
	usb=usb$unit
	mkdev usb$unit c %usb_chr% $unit
	;;

uhid[0-9]*)
	unit=${i#uhid}
	mkdev uhid$unit c %uhid_chr% $unit 666
	;;

ulpt[0-9]*)
	unit=${i#ulpt}
	mkdev ulpt$unit c %ulpt_chr% $unit
	mkdev ulpn$unit c %ulpt_chr% $(($unit + 64))
	;;

utoppy[0-9]*)
	unit=${i#utoppy}
	mkdev utoppy$unit c %utoppy_chr% $unit
	;;

ttyHS[0-9]*)
	unit=${i#ttyHS}
	for j in 00 01 02 03 04 05 06 07 08 09 10
	do
		base=$(($unit * 16 + ${j#0}))
		mkdev ttyHS$unit.$j c %uhso_chr% $(($base + $dialin  )) "" "" $u_uucp
		mkdev dtyHS$unit.$j c %uhso_chr% $(($base + $dialout )) "" "" $u_uucp
		mkdev ctyHS$unit.$j c %uhso_chr% $(($base + $callunit)) "" "" $u_uucp
	done
	;;

ttyY[0-9]*)
	unit=${i#ttyY}
	mkdev ttyY$unit c %ucycom_chr% $(($unit + $dialin  )) "" "" $u_uucp
	mkdev dtyY$unit c %ucycom_chr% $(($unit + $dialout )) "" "" $u_uucp
	mkdev ctyY$unit c %ucycom_chr% $(($unit + $callunit)) "" "" $u_uucp
	;;

ucom[0-9]*)
	makedev ttyU${i#ucom}
	;;

ttyU[0-9]*)
	unit=${i#ttyU}
	mkdev ttyU$unit c %ucom_chr% $(($unit + $dialin	 )) "" "" $u_uucp
	mkdev dtyU$unit c %ucom_chr% $(($unit + $dialout )) "" "" $u_uucp
	mkdev ctyU$unit c %ucom_chr% $(($unit + $callunit)) "" "" $u_uucp
	;;

ugen[0-9]*)
	unit=${i#ugen}
	for j in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
	do
		mkdev ugen$unit.$j c %ugen_chr% $(($unit * 16 + ${j#0}))
	done
	;;

wscons)
	makedev ttyE0 ttyE1 ttyE2 ttyE3 ttyE4 ttyE5 ttyE6 ttyE7
	makedev ttyF0 ttyF1 ttyF2 ttyF3 ttyF4 ttyF5 ttyF6 ttyF7
	makedev ttyG0 ttyG1 ttyG2 ttyG3 ttyG4 ttyG5 ttyG6 ttyG7
	makedev ttyH0 ttyH1 ttyH2 ttyH3 ttyH4 ttyH5 ttyH6 ttyH7
	makedev wsmouse0 wsmouse1 wsmouse2 wsmouse3
	makedev wskbd0 wskbd1 wskbd2 wskbd3
	makedev wsmux0 wsmux1 wsmux2 wsmux3
	makedev wsmouse wskbd
	makedev ttyEcfg ttyEstat
	makedev ttyFcfg ttyFstat
	makedev ttyGcfg ttyGstat
	makedev ttyHcfg ttyHstat
	makedev wsfont
	;;

wsmouse)
	mkdev wsmouse c %wsmux_chr% 0
	;;

wskbd)
	mkdev wskbd c %wsmux_chr% 1
	;;

wsmux[0-9]*)
	unit=${i#wsmux}
	mkdev wsmux$unit    c %wsmux_chr% $unit
	mkdev wsmuxctl$unit c %wsmux_chr% $(($unit + 128)) 200
	;;

xenevt)
	mkdev xenevt c %xenevt_chr% 0
	;;

xsd_kva)
	mkdev xsd_kva c %xenevt_chr% 1
	;;

xencons)
	mkdev xencons c %xencons_chr% 0
	;;

ttyEstat)
	mkdev ttyEstat c %wsdisplay_chr% 254
	;;

ttyEcfg)
	mkdev ttyEcfg c %wsdisplay_chr% 255
	;;

ttyE[0-9]*)
	unit=${i#ttyE}
	mkdev ttyE$unit c %wsdisplay_chr% $unit
	;;

ttyFstat)
	mkdev ttyFstat c %wsdisplay_chr% 510
	;;

ttyFcfg)
	mkdev ttyFcfg c %wsdisplay_chr% 511
	;;

ttyF[0-9]*)
	unit=${i#ttyF}
	mkdev ttyF$unit c %wsdisplay_chr% $(($unit + 256))
	;;

ttyGstat)
	mkdev ttyGstat c %wsdisplay_chr% 766
	;;

ttyGcfg)
	mkdev ttyGcfg c %wsdisplay_chr% 767
	;;

ttyG[0-9]*)
	unit=${i#ttyG}
	mkdev ttyG$unit c %wsdisplay_chr% $(($unit + 512))
	;;

ttyHstat)
	mkdev ttyHstat c %wsdisplay_chr% 1022
	;;

ttyHcfg)
	mkdev ttyHcfg c %wsdisplay_chr% 1023
	;;

ttyH[0-9]*)
	unit=${i#ttyH}
	mkdev ttyH$unit c %wsdisplay_chr% $(($unit + 768))
	;;

wsmouse[0-9]*)
	unit=${i#wsmouse}
	mkdev wsmouse$unit c %wsmouse_chr% $unit
	;;

wskbd[0-9]*)
	unit=${i#wskbd}
	mkdev wskbd$unit c %wskbd_chr% $unit
	;;

fd)
	if ! $fdesc_mounted; then
		# Create the "fd" subdirectory, and devices "fd/0" to "fd/63"
		makedir fd 755
		n=0
		while [ $n -lt 64 ]
		do
			mkdev fd/$n c %filedesc_chr% $n 666
			n=$(($n + 1))
		done
	fi
	;;

wt[0-9]*)
	name=wt;  unit=${i#wt};	chr=%wt_chr%;	blk=%wt_blk%
	for sub in $unit $(($unit+8)) $(($unit+16))
	do
		mkdev $name$sub		b $blk $(($sub + 0)) 660 $g_operator
		mkdev n$name$sub	b $blk $(($sub + 4)) 660 $g_operator
		mkdev r$name$sub	c $chr $(($sub + 0)) 660 $g_operator
		mkdev nr$name$sub	c $chr $(($sub + 4)) 660 $g_operator
	done
	;;

md[0-9]*)
	makedisk_minimal md ${i#md} %md_blk% %md_chr%
	;;

fss[0-9]*)
	name=fss; unit=${i#fss};	blk=%fss_blk%;	chr=%fss_chr%
	mkdev $name$unit	b $blk $unit 660 $g_operator
	mkdev r$name$unit	c $chr $unit 660 $g_operator
	;;

ss[0-9]*)
	name=ss;	unit=${i#ss};	chr=%ss_chr%
	mkdev $name$unit	c $chr $(($unit * 16 + 0)) 640 $g_operator
	mkdev n$name$unit	c $chr $(($unit * 16 + 1)) 640 $g_operator
	mkdev en$name$unit	c $chr $(($unit * 16 + 3)) 640 $g_operator
	;;

ccd[0-9]*|cgd[0-9]*|raid[0-9]*|vnd[0-9]*)
	case $i in
	ccd*)	name=ccd;	unit=${i#ccd};	blk=%ccd_blk%;	chr=%ccd_chr%;;
	cgd*)	name=cgd;	unit=${i#cgd};	blk=%cgd_blk%;	chr=%cgd_chr%;;
	raid*)	name=raid;	unit=${i#raid}; blk=%raid_blk%; chr=%raid_chr%;;
	vnd*)	name=vnd;	unit=${i#vnd};	blk=%vnd_blk%;	chr=%vnd_chr%;;
	esac
	%MKDISK% $name $unit $blk $chr
	;;

sd[0-9]*)
	name=sd; unit=${i#sd};	blk=%sd_blk%;	chr=%sd_chr%
	%MKDISK% $name $unit $blk $chr
	;;

ace[0-9]*)
	name=ace; unit=${i#ace};	blk=%ace_blk%;		chr=%ace_chr%
	%MKDISK% $name $unit $blk $chr
	;;

eflash[0-9]*)
	name=eflash; unit=${i#eflash};	blk=%eflash_blk%;	chr=%eflash_chr%
	%MKDISK% $name $unit $blk $chr
	;;

wd[0-9]*)
	name=wd; unit=${i#wd}; blk=%wd_blk%; chr=%wd_chr%
	%MKDISK% $name $unit $blk $chr
	;;

fd[0-9]*)
	name=fd; unit=${i#fd}; blk=%fd_blk%; chr=%fd_chr%
	%MKDISK% $name $unit $blk $chr
	;;

ld[0-9]*)
	name=ld; unit=${i#ld}; blk=%ld_blk%; chr=%ld_chr%
	%MKDISK% $name $unit $blk $chr
	;;

flash[0-9]*)
	unit=${i#flash}
	flash=flash$unit
	mkdev flash$unit b %flash_blk% $unit
	mkdev rflash$unit c %flash_chr% $unit
	;;

spiflash[0-9]*)
	unit=${i#spiflash}
	spiflash=spiflash$unit
	mkdev spiflash$unit b %spiflash_blk% $unit
	mkdev rspiflash$unit c %spiflash_chr% $unit
	;;

altmem[0-9]*)
	name=altmem; unit=${i#altmem}; blk=%altmem_blk%; chr=%altmem_chr%
	%MKDISK% $name $unit $blk $chr
	;;

bio)
	mkdev bio c %bio_chr% 0
	;;

ed[0-9]*)
	name=ed; unit=${i#ed}; blk=%ed_blk%; chr=%ed_chr%
	%MKDISK% $name $unit $blk $chr
	;;

ofdisk[0-9]*)
	name=ofdisk; unit=${i#ofdisk}; blk=%ofdisk_blk%; chr=%ofdisk_chr%
	%MKDISK% $name $unit $blk $chr
	;;

xbd[0-9]*)
	name=xbd; unit=${i#xbd}; blk=%xbd_blk%; chr=%xbd_chr%
	%MKDISK% $name $unit $blk $chr
	;;

dk[0-9]*)
	name=dk; unit=${i#dk}; blk=%dk_blk%; chr=%dk_chr%
	mkdev r$name$unit c $chr $unit 0640 $g_operator
	mkdev $name$unit b $blk  $unit 0640 $g_operator
	;;

tprof)
	mkdev tprof c %tprof_chr% 0
	;;

ttyCY[0-9]*)
	# Each unit number creates 32 pairs of {tty,dty} device nodes:
	# ttyCY0 => device nodes [td]tyCY000 to [td]tyCY031;
	# ttyCY1 => device nodes [td]tyCY032 to [td]tyCY063;
	name=tyCY; chr=%cy_chr%; off=32
	unit=${i#t${name}}
	minor=$(($unit * $off))
	eminor=$(($minor + $off))
	while [ $minor -lt $eminor ]
	do
		nminor=000$minor
		nminor=${nminor#${nminor%???}}
		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
		minor=$(($minor + 1))
	done
	;;

ttyCZ[0-9]*)
	# Each unit number creates 64 pairs of {tty,dty} device nodes:
	# ttyCZ0 => device nodes [td]tyCZ0000 to [td]tyCZ0063;
	# ttyCZ1 => device nodes [td]tyCZ0064 to [td]tyCZ0127;
	name=tyCZ; chr=%cz_chr%; off=64
	unit=${i#t${name}}
	minor=$(($unit * $off))
	eminor=$(($minor + $off))
	while [ $minor -lt $eminor ]
	do
		nminor=0000$minor
		nminor=${nminor#${nminor%????}}
		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
		minor=$(($minor + 1))
	done
	;;


tty[0-9]|tty0[0-9])
	# some archs have built-in zstty (major %zstty_chr%) instead
	# of NS16550; create ttyZ* and hardlink as [dt]ty0*; this
	# needs to be before com entry, for archs which have both
	unit=${i#tty}
	unit=$(($unit + 0))
	makedev ttyZ${unit}
	lndev ttyZ$unit tty0${unit}
	lndev dtyZ$unit dty0${unit}
	;;

tty[0-9]*)
	unit=${i#tty}
	ounit=00$unit
	ounit=${ounit#${ounit%??}}
	mkdev tty$ounit c %com_chr% $(($unit + $dialin )) "" "" $u_uucp
	mkdev dty$ounit c %com_chr% $(($unit + $dialout)) "" "" $u_uucp
	;;

ttyC[0-9]*)
		# some archs call com_chr ttyC traditionally
	unit=${i#ttyC}; name=ttyC; dname=dtyC; chr=%com_chr%
	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
	;;

ttyh[0-9]*)
	unit=${i#ttyh}; name=ttyh; dname=dtyh; chr=%sabtty_chr%
	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
	;;

ttyTX[0-9]*)
	unit=${i#ttyTX}; name=ttyTX0; dname=dtyTX0; chr=%txcom_chr%
	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
	;;

ttyZ[0-9]*)
	unit=${i#ttyZ}; name=ttyZ; dname=dtyZ; chr=%zstty_chr%
	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
	;;

opty)
	# Create 16 device nodes, [pt]typ0 to [pt]typf,
	# same as "MAKEDEV pty0".
	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
	do
		case $j in
		[0-9])	jn=$j ;;
		a)	jn=10 ;;
		b)	jn=11 ;;
		c)	jn=12 ;;
		d)	jn=13 ;;
		e)	jn=14 ;;
		f)	jn=15 ;;
		esac
		mkdev ttyp$j c %pts_chr% $jn 666
		mkdev ptyp$j c %ptc_chr% $jn 666
	done
	;;

pty[0-9]*)
	# Each unit number creates up to 16 pairs of {tty,pty} device nodes:
	# pty0 => 16 pairs, [tp]typ0 to [tp]typf
	# pty1 => 16 pairs, [tp]tyq0 to [tp]tyqf
	# pty16 => 16 pairs, [tp]typg to [tp]typv
	# pty17 => 16 pairs, [tp]typw to [tp]typL
	# pty18 => 14 pairs, [tp]typM to [tp]typZ
	warn "$i: creating BSD style tty nodes with ptyfs is a security issue"
	class=${i#pty}
	d1="p q r s t u v w x y z P Q R S T"
	if [ "$class" -ge 64 ]
	then
		warn "$i: pty unit must be between 0 and 63"
		continue
	elif [ "$class" -lt 16 ]
	then
		# pty[p-zP-T][0-9a-f]
		offset=0
		mult=0
		d2="0 1 2 3 4 5 6 7 8 9 a b c d e f"
	else
		# pty[p-zP-T][g-zA-Z]
		class=$(($class - 16))
		offset=256
		mult=2
		d2="g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
	fi
	start=$(($class * 16))
	set -- $d2
	nt=$#
	s1=$(($start / $nt))
	set -- $d1
	shift $s1
	t1=$1
	if [ "$t1" = v ]; then
		warn "$i: pty unit conflicts with console ttyv0 device"
		continue
	fi
	s2=$(($start % ($nt - $s1 * $mult)))
	set -- $d2
	shift $s2
	t2=$1
	unit=$(($start + $offset - $s1 * $mult))
	end=$(($unit + 16))
	while [ "$unit" -lt "$end" ]
	do
		mkdev tty$t1$t2 c %pts_chr% $unit 666
		mkdev pty$t1$t2 c %ptc_chr% $unit 666
		shift
		t2=$1
		if [ -z "$t2" ]
		then
			break
		fi
		unit=$(($unit + 1))
	done
	;;

stic[0-9]*)
	unit=${i#stic}
	mkdev stic$unit c %stic_chr% $unit
	;;

st[0-9]*)
	name=st;	unit=${i#st};	chr=%st_chr%;	blk=%st_blk%
	mkdev $name$unit	b $blk $(($unit * 16 + 0)) 660 $g_operator
	mkdev n$name$unit	b $blk $(($unit * 16 + 1)) 660 $g_operator
	mkdev e$name$unit	b $blk $(($unit * 16 + 2)) 660 $g_operator
	mkdev en$name$unit	b $blk $(($unit * 16 + 3)) 660 $g_operator
	mkdev r$name$unit	c $chr $(($unit * 16 + 0)) 660 $g_operator
	mkdev nr$name$unit	c $chr $(($unit * 16 + 1)) 660 $g_operator
	mkdev er$name$unit	c $chr $(($unit * 16 + 2)) 660 $g_operator
	mkdev enr$name$unit	c $chr $(($unit * 16 + 3)) 660 $g_operator
	;;

ses[0-9]*|ch[0-9]*|uk[0-9]*)
	case $i in
	ch*)	name=ch;	unit=${i#ch};	chr=%ch_chr%;;
	uk*)	name=uk;	unit=${i#uk};	chr=%uk_chr%;;
	ses*)	name=ses;	unit=${i#ses};	chr=%ses_chr%;;
	esac
	mkdev $name$unit c $chr $unit 640 $g_operator
	;;

cd[0-9]*)
	makedisk_minimal cd ${i#cd} %cd_blk% %cd_chr%
	;;

mcd[0-9]*)
	makedisk_minimal mcd ${i#mcd} %mcd_blk% %mcd_chr%
	;;

gdrom[0-9]*)
	makedisk_minimal gdrom ${i#gdrom} %gdrom_blk% %gdrom_chr%
	;;

lpt[0-9]*|lpa[0-9]*)
	case $i in
	lpt*) name=lpt; unit=${i#lpt};	chr=%lpt_chr%;	flags=0;;
	lpa*) name=lpa; unit=${i#lpa};	chr=%lpt_chr%;	flags=128;;
	esac
	mkdev $name$unit c $chr $(($unit + $flags))
	mkdev lpt${unit}ctl c $chr $(($unit + 256))
	;;

bpf)
	mkdev bpf	c %bpf_chr% 0
	lndev bpf bpf0
	;;

npf)
	mkdev npf	c %npf_chr% 0
	;;

bthub)
	mkdev bthub c %bthub_chr% 0
	;;

tun[0-9]*)
	unit=${i#tun}
	mkdev tun$unit c %tun_chr% $unit
	;;

joy[0-9]*)
	unit=${i#joy}
	mkdev joy$unit c %joy_chr% $unit
	;;

ipl)
	mkdev ipl	c %ipl_chr% 0
	mkdev ipnat	c %ipl_chr% 1
	mkdev ipstate	c %ipl_chr% 2
	mkdev ipauth	c %ipl_chr% 3
	mkdev ipsync	c %ipl_chr% 4
	mkdev ipscan	c %ipl_chr% 5
	mkdev iplookup	c %ipl_chr% 6
	;;

pf)
	mkdev pf c %pf_chr% 0
	;;

crypto)
	mkdev crypto c %crypto_chr% 0 666
	;;

cmos)
	mkdev cmos c %cmos_chr% 0 644
	;;

speaker)
	mkdev speaker c %spkr_chr% 0
	;;

lockstat)
	mkdev lockstat c %lockstat_chr% 0
	;;

cpuctl)
	mkdev cpuctl c %cpuctl_chr% 0 666
	;;

audio|audio[0-9]*)
	unit=${i#audio}
	audio=audio$unit
	sound=sound$unit
	mixer=mixer$unit
	audioctl=audioctl$unit
	: ${unit:-0}
	mkdev $sound	c %audio_chr% $(($unit + 0))	666
	mkdev $audio	c %audio_chr% $(($unit + 128))	666
	mkdev $mixer	c %audio_chr% $(($unit + 16))	666
	mkdev $audioctl c %audio_chr% $(($unit + 192))	666
	;;

hdaudio[0-9]*)
	unit=${i#hdaudio}
	mkdev hdaudio$unit c %hdaudio_chr% $unit 644
	;;

hdmicec[0-9]*)
	uint=${i#hdmicec}
	mkdev hdmicec$unit c %hdmicec_chr% $unit 644
	;;

gpio[0-9]*)
	unit=${i#gpio}
	mkdev gpio$unit c %gpio_chr% $unit 664 $g_gpio
	;;

gpiopps[0-9]*)
	unit=${i#gpiopps}
	mkdev gpiopps$unit c %gpiopps_chr% $unit 664 $g_gpio
	;;

lua[0-9]*)
	unit=${i#lua}
	mkdev lua$unit c %lua_chr% $unit 664
	;;

rmidi[0-9]*)
	unit=${i#rmidi}
	mkdev rmidi$unit c %midi_chr% $unit 666
	;;

music|music[0-9]*)
	unit=${i#music}
	: ${unit:-0}
	mkdev music$unit     c %sequencer_chr% $(($unit + 0))	666
	mkdev sequencer$unit c %sequencer_chr% $(($unit + 128)) 666
	;;

radio|radio[0-9]*)
	unit=${i#radio}
	: ${unit:-0}
	mkdev radio$unit c %radio_chr% $unit 666
	;;

video|video[0-9]*)
	unit=${i#video}
	: ${unit:-0}
	mkdev video$unit c %video_chr% $unit 666
	;;

dtv[0-9]*)
	unit=${i#dtv}
	makedir dvb 755
	makedir dvb/adapter$unit 755
	mkdev dvb/adapter$unit/frontend0 c %dtv_chr% $(($unit + 0)) 666
	mkdev dvb/adapter$unit/demux0 c %dtv_chr% $(($unit + 16)) 666
	mkdev dvb/adapter$unit/dvr0 c %dtv_chr% $(($unit + 32)) 666
	;;

iic[0-9]*)
	unit=${i#iic}
	: ${unit:-0}
	mkdev iic$unit c %iic_chr% $unit 600
	;;

spi[0-9]*)
	unit=${i#spi}
	: ${unit:-0}
	mkdev spi$unit c %spi_chr% $unit 600
	;;

amr[0-9]*)
	unit=${i#amr}
	mkdev amr$unit c %amr_chr% $unit
	;;

apm)
	mkdev apm	c %apm_chr% 0 644
	mkdev apmctl	c %apm_chr% 8 644
	;;

apm)
		# hpcmips uses `apmdev_chr' instead of `apm_chr'
	mkdev apm	c %apmdev_chr% 0 644
	mkdev apmctl	c %apmdev_chr% 8 644
	;;

random)
	mkdev random	c %rnd_chr% 0 444
	mkdev urandom	c %rnd_chr% 1 644
	;;

cfs)
	makedev cfs0
	;;

cfs[0-9]*)
	unit=${i#cfs}
	mkdev cfs$unit c %vcoda_chr% $unit
	;;

sysmon)
	mkdev sysmon	c %sysmon_chr% 0 644
	mkdev watchdog	c %sysmon_chr% 1 644
	mkdev power	c %sysmon_chr% 2 640
	;;

scsibus[0-9]*)
	unit=${i#scsibus}
	mkdev scsibus$unit c %scsibus_chr% $unit 644
	;;

bktr)
	makedev bktr0 bktr1
	lndev	bktr0	bktr
	lndev	tuner0	tuner
	lndev	vbi0	vbi
	;;

bktr[0-9]*)
	unit=${i#bktr}
	mkdev bktr$unit		c %bktr_chr% $(($unit + 0))	444
	mkdev tuner$unit	c %bktr_chr% $(($unit + 16))	444
	mkdev vbi$unit		c %bktr_chr% $(($unit + 32))	444
	;;

io)
	mkdev		io	c %mem_chr% 14	600
	;;

iop[0-9]*)
	unit=${i#iop}
	mkdev iop$unit c %iop_chr% $unit
	;;

mfi[0-9]*)
	unit=${i#mfi}
	mkdev mfi$unit c %mfi_chr% $unit
	;;

mlx[0-9]*)
	unit=${i#mlx}
	mkdev mlx$unit c %mlx_chr% $unit
	;;

mly[0-9]*)
	unit=${i#mly}
	mkdev mly$unit c %mly_chr% $unit
	;;

twa[0-9]*)
	unit=${i#twa}
	mkdev twa$unit c %twa_chr% $unit
	;;

twe[0-9]*)
	unit=${i#twe}
	mkdev twe$unit c %twe_chr% $unit
	;;

icp[0-9]*)
	unit=${i#icp}
	mkdev icp$unit c %icp_chr% $unit
	;;

agp[0-9]*)
	unit=${i#agp}
	mkdev agp$unit c %agp_chr% $unit 644
	if [ "$unit" = "0" ]; then
		lndev agp$unit agpgart
	fi
	;;

pci[0-9]*)
	unit=${i#pci}
	mkdev pci$unit c %pci_chr% $unit 640
	;;

dpti[0-9]*)
	unit=${i#dpti}
	mkdev dpti$unit c %dpti_chr% $unit
	;;

dpt[0-9]*)
	unit=${i#dpt}
	mkdev dpt$unit c %dpt_chr% $unit
	;;

altq)
	makedir altq 755
	unit=0
	for dev in altq cbq wfq afm fifoq red rio localq hfsc cdnr blue priq jobs
	do
		mkdev altq/$dev c %altq_chr% $unit 644
		unit=$(($unit + 1))
	done
	;;

wsfont)
	mkdev wsfont c %wsfont_chr% 0 644
	;;

cir[0-9]*)
	unit=${i#cir}
	mkdev cir$unit c %cir_chr% $unit 666
	;;

irframe[0-9]*)
	unit=${i#irframe}
	mkdev irframe$unit c %irframe_chr% $unit
	;;

fcom[0-9]*)
	unit=${i#fcom}
	mkdev fcom$unit c %fcom_chr% $unit "" "" $u_uucp
	;;

openfirm)
	mkdev openfirm c %openfirm_chr% 0 444
	;;

pad[0-9]*)
	unit=${i#pad}
	mkdev pad$unit c %pad_chr% $unit 444
	;;

qemufwcfg[0-9]*)
	unit=${i#qemufwcfg}
	mkdev qemufwcfg$unit c %qemufwcfg_chr% $unit 660
	;;

vio9p[0-9]*)
	unit=${i#vio9p}
	mkdev vio9p$unit c %vio9p_chr% $unit 660
	;;

fault)
	mkdev fault c %fault_chr% 0
	;;

nvram)
	mkdev nvram c %nvram_chr% 0 644
	;;

rtc)
	mkdev rtc c %rtc_chr% 0 644
	;;

clockctl)
	mkdev clockctl c %clockctl_chr% 0 660 $g_ntpd
	;;

kttcp)
	mkdev kttcp c %kttcp_chr% 0
	;;

dmoverio)
	mkdev dmoverio c %dmoverio_chr% 0 644
	;;

veriexec)
	mkdev veriexec c %veriexec_chr% 0 600
	;;

vhci[0-7]*)
	unit=${i#vhci}
	mkdev vhci$unit c %vhci_chr% $unit
	;;

ttyv[0-9]*)
	unit=${i#ttyv}
	mkdev ttyv$unit c %pc_chr% $unit
	;;

# arm, acorn32
ttyv[0-9]*)
	unit=${i#ttyv}
	mkdev ttyv$unit c %physcon_chr% $unit
	;;

arcpp[0-9]*)
	unit=${i#arcpp}
	mkdev arcpp$unit c %arcpp_chr% $unit
	;;

par[0-9]*)
	unit=${i#par}
	case $unit in
	0)
		mkdev par$unit c %par_chr% $unit
		;;
	*)
		warn "bad unit for par in: $i"
		;;
	esac
	;;

cpi[0-9]*)
	unit=${i#cpi}
	mkdev cpi$unit c %cpi_chr% $unit
	;;

ite[0-9]*|ttye[0-9]*)
	case $i in
	ite*)	unit=${i#ite};;
	ttye*)	unit=${i#ttye};;
	esac
	mkdev ttye$unit c %ite_chr% $unit
	;;

pms[0-9]*)
	unit=${i#pms}
	mkdev pms$unit c %opms_chr% $unit
	;;

qms[0-9]*)
	unit=${i#qms}
	mkdev qms$unit c %qms_chr% $unit
	;;

lms[0-9]*)
	unit=${i#lms}
	mkdev lms$unit c %lms_chr% $unit
	;;

mms[0-9]*)
	unit=${i#mms}
	mkdev mms$unit c %mms_chr% $unit
	;;

mouse-pms[0-9]*|mouse-qms[0-9]*)
	case $i in
	mouse-pms*) name=pms ;;
	mouse-qms*) name=qms ;;
	esac
	unit=${i#mouse-${name}}
	lndev $name$unit mouse
	;;

kbd)
	mkdev kbd c %kbd_chr% 0
	;;

kbdctl)
	mkdev kbdctl c %kbd_chr% 1
	;;

vidcconsole0)
	mkdev vidcconsole0 c %vidcconsole_chr% 0 640
	;;

view[0-9]*)
	unit=${i#view}
	mkdev view$unit c %view_chr% $unit 666
	;;

mouse[0-9]*)
	unit=${i#mouse}
	case $unit in
	0|1)
		mkdev mouse$unit c %ms_chr% $unit 666
		if [ $unit = 0 ]; then
			lndev mouse$unit mouse
		fi
		;;
	*)
		warn "bad unit for mouse in: $i"
		;;
	esac
	;;

panel)
	mkdev panel0 c %panel_chr% 0 660
	;;

tslcd)
	mkdev tslcd0 c %tslcd_chr% 0 660
	;;

ipty)
	mkdev ttyp0 c %pts_chr% 0 666
	mkdev ttyp1 c %pts_chr% 1 666
	mkdev ptyp0 c %ptc_chr% 0 666
	mkdev ptyp1 c %ptc_chr% 1 666
	;;

ptm)
	makedir pts 755
	mkdev ptmx c %ptm_chr% 0 666
	mkdev ptm c %ptm_chr% 1 666
	;;

grf[0-9]*)
	unit=${i#grf}
	mkdev grf$unit c %grf_chr% $unit 666
	;;

etvme)
	mkdev etvme c %et_chr% 0
	;;

leo[0-9]*)
	unit=${i#leo}
	mkdev leo$unit c %leo_chr% $unit
	;;

scif[0-9]*)
	unit=${i#scif}
	mkdev scif$unit c %scif_chr% $(($unit + $dialin )) "" "" $u_uucp
	mkdev dscif$unit c %scif_chr% $(($unit + $dialout)) "" "" $u_uucp
	;;

sci[0-9]*)
	unit=${i#sci}
	mkdev sci$unit c %sci_chr% $(($unit + $dialin )) "" "" $u_uucp
	mkdev dsci$unit c %sci_chr% $(($unit + $dialout)) "" "" $u_uucp
	;;

maple[ABCD]|maple[ABCD][0-9]*)
	case $i in
	mapleA*) name="mapleA"; unit=0;;
	mapleB*) name="mapleB"; unit=1;;
	mapleC*) name="mapleC"; unit=2;;
	mapleD*) name="mapleD"; unit=3;;
	esac
	subunit=${i#$name}
	mkdev $name$subunit c %maple_chr% $(($unit * 8 + 0$subunit))
	;;

mmem[0-9]*)
	unit=${i#mmem}
	for pt in 0	# 1 2 3 4 ... 255
	do
#		mkdev mmem${unit}.${pt}a  b %mmem_blk% $(($unit * 4096 + $pt * 16 + 0)) 640 $g_operator
		mkdev mmem${unit}.${pt}c  b %mmem_blk% $(($unit * 4096 + $pt * 16 + 2)) 640 $g_operator
#		mkdev rmmem${unit}.${pt}a c %mmem_chr% $(($unit * 4096 + $pt * 16 + 0)) 640 $g_operator
		mkdev rmmem${unit}.${pt}c c %mmem_chr% $(($unit * 4096 + $pt * 16 + 2)) 640 $g_operator
	done
	;;

mlcd[0-9]*)
	unit=${i#mlcd}
	for pt in 0	# 1 2 3 4 ... 255
	do
		mkdev mlcd${unit}.${pt} c %mlcd_chr% $(($unit * 256 + $pt)) 640 $g_operator
	done
	;;

ixpcom[0-9]*)
	unit=${i#ixpcom}
	mkdev ixpcom$unit c %ixpcom_chr% $unit "" "" $u_uucp
	;;

epcom[0-9]*)
	unit=${i#epcom}
	mkdev epcom$unit c %epcom_chr% $unit "" "" $u_uucp
	;;

plcom[0-9]*)
	unit=${i#plcom}
	mkdev plcom$unit c %plcom_chr% $unit "" "" $u_uucp
	mkdev dplcom$unit c %plcom_chr% $(($unit + $dialout)) "" "" $u_uucp
	;;

wmcom[0-9]*)
	unit=${i#wmcom}
	mkdev wmcom$unit c %wmcom_chr% $unit "" "" $u_uucp
	;;

ucbsnd)
	mkdev ucbsnd c %ucbsnd_chr% 0 666
	;;

adb)
	mkdev adb c %aed_chr% 0 666
	;;

asc[0-9]*)
	unit=${i#asc}
	mkdev asc$unit c %asc_chr% $unit 666
	;;

bwtwo[0-9]*)
	unit=${i#bwtwo}
	mkdev bwtwo$unit c %bwtwo_chr% $unit 666
	;;

cgtwo[0-9]*)
	unit=${i#cgtwo}
	mkdev cgtwo$unit c %cgtwo_chr% $unit 666
	;;

cgthree[0-9]*)
	unit=${i#cgthree}
	mkdev cgthree$unit c %cgthree_chr% $unit 666
	;;

cgfour[0-9]*)
	unit=${i#cgfour}
	mkdev cgfour$unit c %cgfour_chr% $unit 666
	;;

cgsix[0-9]*)
	unit=${i#cgsix}
	mkdev cgsix$unit c %cgsix_chr% $unit 666
	;;

cgeight[0-9]*)
	unit=${i#cgeight}
	mkdev cgeight$unit c %cgeight_chr% $unit 666
	;;

tcx[0-9]*)
	unit=${i#tcx}
	mkdev tcx$unit c %tcx_chr% $unit 666
	;;

xd[0-9]*|xy[0-9]*)
	case $i in
	xd*)	name=xd; unit=${i#xd}; blk=%xd_blk%;	chr=%xd_chr%;;
	xy*)	name=xy; unit=${i#xy}; blk=%xy_blk%;	chr=%xy_chr%;;
	esac
	%MKDISK% $name $unit $blk $chr
	;;

magma[0-9]*)
	unit=${i#magma}
	if [ 0$unit -gt 3 ]; then
		warn "bad unit for $i: $unit"
		break
	fi
	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
	do
		case $j in
		[0-9])	jn=$j ;;
		a)	jn=10 ;;
		b)	jn=11 ;;
		c)	jn=12 ;;
		d)	jn=13 ;;
		e)	jn=14 ;;
		f)	jn=15 ;;
		esac
		mkdev tty$unit$j c %mtty_chr% $(($unit * 64 + $jn))
	done
	mkdev bpp${unit}0 c %mbpp_chr% $(($unit * 64 + 0))
	mkdev bpp${unit}1 c %mbpp_chr% $(($unit * 64 + 1))
	;;

clcd[0-9]*)
	unit=${i#clcd}
	if [ 0$unit -gt 7 ]; then
		warn "bad unit for $i: $unit"
		break
	fi
	for j in 0 1 2 3 4 5 6 7
	do
		mkdev ttyA$unit$j c %clcd_chr% $(($unit * 8 + $j + $dialin)) "" "" $u_uucp
		mkdev dtyA$unit$j c %clcd_chr% $(($unit * 8 + $j + $dialout)) "" "" $u_uucp
	done
	;;

spif[0-9]*)
	unit=${i#spif}
	if [ 0$unit -gt 3 ]; then
		warn "bad unit for $i: $unit"
		break
	fi
	for j in 0 1 2 3 4 5 6 7; do
		mkdev ttyS$unit$j c %stty_chr% $(($unit * 64 + $j)) "" "" $u_uucp
	done
	mkdev bppS${unit}0 c %sbpp_chr% $(($unit * 64 + 0))
	mkdev bppS${unit}1 c %sbpp_chr% $(($unit * 64 + 1))
	;;

bpp|bpp[0-9]*)
	unit=${i#bpp}
	mkdev bpp$unit c %bpp_chr% $(($unit + 0))
	;;

tctrl[0-9]*)
	unit=${i#tctrl}
	mkdev tctrl$unit c %tctrl_chr% $unit 666
	;;

bmd[0-9]*)
	unit=${i#bmd}
	mkdev bmd${unit}a  b %bmd_blk% $(($unit * 8 + 0)) 640 $g_operator
	mkdev bmd${unit}c  b %bmd_blk% $(($unit * 8 + 2)) 640 $g_operator
	mkdev rbmd${unit}a c %bmd_chr% $(($unit * 8 + 0)) 640 $g_operator
	mkdev rbmd${unit}c c %bmd_chr% $(($unit * 8 + 2)) 640 $g_operator
	;;

sram)
	mkdev sram c %sram_chr% 0 644
	;;

ttyS[0-9]*)
	unit=${i#ttyS}
	mkdev ttyS$unit c %sacom_chr% $(($unit + $dialin )) "" "" $u_uucp
	mkdev dtyS$unit c %sacom_chr% $(($unit + $dialout)) "" "" $u_uucp
	;;

atabus[0-9]*)
	unit=${i#atabus}
	mkdev atabus$unit c %atabus_chr% $unit 644
	;;

drm[0-9]*)
	unit=${i#drm}
	unit2=$((unit + 128))
	makedir dri 755
	mkdev dri/card$unit c %drm_chr% $unit 660
	mkdev dri/renderD${unit2} c %drm_chr% ${unit2} 660
	;;

drvctl)
	mkdev drvctl c %drvctl_chr% 0 644
	;;

isv)
	mkdev isv c %isv_chr% 0 644
	;;

tap|tap[0-9]*)
	unit=${i#tap}
	case "$unit" in
	[0-9]*)
		mkdev tap${unit} c %tap_chr% ${unit} 600
		;;
	"")
		mkdev tap c %tap_chr% 0xfffff 600
		;;
	esac
	;;

srt[0-9]*)
	unit=${i#srt}
	mkdev srt$unit c %srt_chr% $unit 600
	;;

tpm)
	mkdev tpm c %tpm_chr% 0 600
	;;

dtrace)
	makedir dtrace 755
	mkdev dtrace/dtrace c %dtrace_chr% 0 600
	;;

fw[0-9]*)
	unit=${i#fw}
	for j in 0 1 2 3
	do
		mkdev fw${unit}.${j} c %fw_chr% $((${unit} * 256 + ${j})) 660 ${g_operator}
		mkdev fwmem${unit}.${j} c %fw_chr% $((65536 + ${unit} * 256 + ${j})) 660 ${g_operator}
	done
	;;

# create putter device and symlinks for all subsystems using it
putter)
	mkdev putter c %putter_chr% 0 600
	mkdev pud c %putter_chr% 1 600
	lndev putter puffs
	;;

zfs)
	mkdev zfs c %zfs_chr% 0 600
	makedir zpool 755
	;;

iscsi[0-9]*)
	unit=${i#iscsi}
	mkdev iscsi${unit} c %iscsi_chr% $unit 600
	;;

vchiq)
	mkdev vchiq c %vchiq_chr% 0 600
	;;

nvme[0-9]*ns[0-9]*)
	unit=${i#nvme}
	unit=${unit%ns*}
	subunit=${i#nvme${unit}ns}
	if [ 0$subunit -le 0 ] || [ 0$subunit -ge 65536 ]; then
		warn "bad nsid for $i: $subunit"
		break
	fi
	mkdev nvme${unit}ns$subunit c %nvme_chr% $(($unit * 65536 + $subunit))
	;;

nvme[0-9]*)
	unit=${i#nvme}
	mkdev nvme$unit c %nvme_chr% $(($unit * 65536))
	;;

nvmm)
	mkdev nvmm c %nvmm_chr% 0 660 $g_nvmm
	;;

autofs)
	mkdev autofs c %autofs_chr% 0 600
	;;

kcov)
        mkdev kcov c %kcov_chr% 0
        ;;

ipmi[0-9]*)
	unit=${i#ipmi}
	mkdev ipmi${unit} c %ipmi_chr% $unit 600
	;;

xmm[0-9])
	unit=${i#xmm}
	makedir xmm${unit} 755
	mkdev xmm${unit}/rpc c %wwanc_chr% $(($unit * 65536 + 1))
	mkdev ttyXMM${unit}0 c %wwanc_chr% $(($unit * 65536 + 2))
	mkdev ttyXMM${unit}1 c %wwanc_chr% $(($unit * 65536 + 4))
	;;

acpi)
	mkdev acpi c %acpi_chr% 0
	;;

smbios)
	mkdev smbios c %smbios_chr% 0
	;;

efi)
	mkdev efi c %efi_chr% 0 660
	;;

sht3xtemp[0-9]*)
	unit=${i#sht3xtemp}
	mkdev sht3xtemp$unit c %sht3xtemp_chr% $unit 664
	;;

scmd[0-9]*)
	unit=${i#scmd}
	mkdev scmd$unit c %scmd_chr% $unit 666
	;;

ttyVI[0-9][0-9])
	port=${i#ttyVI?}
	devunit=${i%$port}
	unit=${devunit#ttyVI}
	mkdev ttyVI$unit$port c %viocon_chr% $((16*$unit + $port))
	;;

ttyVI)
	makedev ttyVI00 ttyVI10 ttyVI20 ttyVI30
	;;

midevend)
%MI_DEVICES_END%
local)
	if [ -f "$0.local" ]; then
		umask 0
		if [ -n "$count_nodes" ]; then
			count_nodes=$((count_nodes + \
			    $(linecount "$("$HOST_SH" "$0.local" $opts -s all)") ))
		else
			"$HOST_SH" "$0.local" $opts all
		fi
		umask 077
	fi
	;;

*)
	warn "$i: unknown device"
	;;

esac
done

}


# three variants of disk partitions - max 8, max 16, max 16 with highpartoffset
# hack; only the one used by port is retained in final MAKEDEV script
# routine is called as:
# makedisk name unit blk chr
makedisk_p8()
{
	name="$1"; unit="$2"; blk="$3"; chr="$4"

	ro=%RAWDISK_OFF%
	mkdev ${name}${unit}	b $blk $(($unit * 8 + $ro))	640 $g_operator
	mkdev r${name}${unit}	c $chr $(($unit * 8 + $ro))	640 $g_operator

	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
}

makedisk_p12high()
{
	ho=524280	# offset for partition 9 to 11 (same as ...p16high)
	name="$1"; unit="$2"; blk="$3"; chr="$4"

	ro=%RAWDISK_OFF%
	mkdev ${name}${unit}	b $blk $(($unit * 8 + $ro))	640 $g_operator
	mkdev r${name}${unit}	c $chr $(($unit * 8 + $ro))	640 $g_operator

	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
	mkdev ${name}${unit}i	b $blk $(($unit * 8 + $ho + 8)) 640 $g_operator
	mkdev ${name}${unit}j	b $blk $(($unit * 8 + $ho + 9)) 640 $g_operator
	mkdev ${name}${unit}k	b $blk $(($unit * 8 + $ho + 10)) 640 $g_operator
	mkdev ${name}${unit}l	b $blk $(($unit * 8 + $ho + 11)) 640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
	mkdev r${name}${unit}i	c $chr $(($unit * 8 + $ho + 8)) 640 $g_operator
	mkdev r${name}${unit}j	c $chr $(($unit * 8 + $ho + 9)) 640 $g_operator
	mkdev r${name}${unit}k	c $chr $(($unit * 8 + $ho + 10)) 640 $g_operator
	mkdev r${name}${unit}l	c $chr $(($unit * 8 + $ho + 11)) 640 $g_operator
}

makedisk_p16()
{
	name="$1"; unit="$2"; blk="$3"; chr="$4"

	ro=%RAWDISK_OFF%
	mkdev ${name}${unit}	b $blk $(($unit * 16 + $ro))	640 $g_operator
	mkdev r${name}${unit}	c $chr $(($unit * 16 + $ro))	640 $g_operator

	mkdev ${name}${unit}a	b $blk $(($unit * 16 + 0))	640 $g_operator
	mkdev ${name}${unit}b	b $blk $(($unit * 16 + 1))	640 $g_operator
	mkdev ${name}${unit}c	b $blk $(($unit * 16 + 2))	640 $g_operator
	mkdev ${name}${unit}d	b $blk $(($unit * 16 + 3))	640 $g_operator
	mkdev ${name}${unit}e	b $blk $(($unit * 16 + 4))	640 $g_operator
	mkdev ${name}${unit}f	b $blk $(($unit * 16 + 5))	640 $g_operator
	mkdev ${name}${unit}g	b $blk $(($unit * 16 + 6))	640 $g_operator
	mkdev ${name}${unit}h	b $blk $(($unit * 16 + 7))	640 $g_operator
	mkdev ${name}${unit}i	b $blk $(($unit * 16 + 8))	640 $g_operator
	mkdev ${name}${unit}j	b $blk $(($unit * 16 + 9))	640 $g_operator
	mkdev ${name}${unit}k	b $blk $(($unit * 16 + 10))	640 $g_operator
	mkdev ${name}${unit}l	b $blk $(($unit * 16 + 11))	640 $g_operator
	mkdev ${name}${unit}m	b $blk $(($unit * 16 + 12))	640 $g_operator
	mkdev ${name}${unit}n	b $blk $(($unit * 16 + 13))	640 $g_operator
	mkdev ${name}${unit}o	b $blk $(($unit * 16 + 14))	640 $g_operator
	mkdev ${name}${unit}p	b $blk $(($unit * 16 + 15))	640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * 16 + 0))	640 $g_operator
	mkdev r${name}${unit}b	c $chr $(($unit * 16 + 1))	640 $g_operator
	mkdev r${name}${unit}c	c $chr $(($unit * 16 + 2))	640 $g_operator
	mkdev r${name}${unit}d	c $chr $(($unit * 16 + 3))	640 $g_operator
	mkdev r${name}${unit}e	c $chr $(($unit * 16 + 4))	640 $g_operator
	mkdev r${name}${unit}f	c $chr $(($unit * 16 + 5))	640 $g_operator
	mkdev r${name}${unit}g	c $chr $(($unit * 16 + 6))	640 $g_operator
	mkdev r${name}${unit}h	c $chr $(($unit * 16 + 7))	640 $g_operator
	mkdev r${name}${unit}i	c $chr $(($unit * 16 + 8))	640 $g_operator
	mkdev r${name}${unit}j	c $chr $(($unit * 16 + 9))	640 $g_operator
	mkdev r${name}${unit}k	c $chr $(($unit * 16 + 10))	640 $g_operator
	mkdev r${name}${unit}l	c $chr $(($unit * 16 + 11))	640 $g_operator
	mkdev r${name}${unit}m	c $chr $(($unit * 16 + 12))	640 $g_operator
	mkdev r${name}${unit}n	c $chr $(($unit * 16 + 13))	640 $g_operator
	mkdev r${name}${unit}o	c $chr $(($unit * 16 + 14))	640 $g_operator
	mkdev r${name}${unit}p	c $chr $(($unit * 16 + 15))	640 $g_operator
}

makedisk_p16high()
{
	ho=524280	# offset for partition 9 to 16
	name="$1"; unit="$2"; blk="$3"; chr="$4"

	ro=%RAWDISK_OFF%
	mkdev ${name}${unit}	b $blk $(($unit * 8 + $ro))	640 $g_operator
	mkdev r${name}${unit}	c $chr $(($unit * 8 + $ro))	640 $g_operator

	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
	mkdev ${name}${unit}i	b $blk $(($unit * 8 + $ho + 8)) 640 $g_operator
	mkdev ${name}${unit}j	b $blk $(($unit * 8 + $ho + 9)) 640 $g_operator
	mkdev ${name}${unit}k	b $blk $(($unit * 8 + $ho + 10)) 640 $g_operator
	mkdev ${name}${unit}l	b $blk $(($unit * 8 + $ho + 11)) 640 $g_operator
	mkdev ${name}${unit}m	b $blk $(($unit * 8 + $ho + 12)) 640 $g_operator
	mkdev ${name}${unit}n	b $blk $(($unit * 8 + $ho + 13)) 640 $g_operator
	mkdev ${name}${unit}o	b $blk $(($unit * 8 + $ho + 14)) 640 $g_operator
	mkdev ${name}${unit}p	b $blk $(($unit * 8 + $ho + 15)) 640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
	mkdev r${name}${unit}i	c $chr $(($unit * 8 + $ho + 8)) 640 $g_operator
	mkdev r${name}${unit}j	c $chr $(($unit * 8 + $ho + 9)) 640 $g_operator
	mkdev r${name}${unit}k	c $chr $(($unit * 8 + $ho + 10)) 640 $g_operator
	mkdev r${name}${unit}l	c $chr $(($unit * 8 + $ho + 11)) 640 $g_operator
	mkdev r${name}${unit}m	c $chr $(($unit * 8 + $ho + 12)) 640 $g_operator
	mkdev r${name}${unit}n	c $chr $(($unit * 8 + $ho + 13)) 640 $g_operator
	mkdev r${name}${unit}o	c $chr $(($unit * 8 + $ho + 14)) 640 $g_operator
	mkdev r${name}${unit}p	c $chr $(($unit * 8 + $ho + 15)) 640 $g_operator
}

# make only the very few basic disk device nodes - 'a' partition
# and raw partition
makedisk_minimal()
{
	name=$1; unit=$2; blk=$3; chr=$4
	doff=%DISKMINOROFFSET%
	ro=%RAWDISK_OFF%
	rn=%RAWDISK_NAME%

	mkdev ${name}${unit}	b $blk $(($unit * $doff + $ro))	640 $g_operator
	mkdev r${name}${unit}	c $chr $(($unit * $doff + $ro))	640 $g_operator

	mkdev ${name}${unit}a	b $blk $(($unit * $doff + 0))	640 $g_operator
	mkdev ${name}${unit}$rn b $blk $(($unit * $doff + $ro)) 640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * $doff + 0))	640 $g_operator
	mkdev r${name}${unit}$rn c $chr $(($unit * $doff + $ro)) 640 $g_operator
}

# create_mfs_dev nodes
#	Create a memory file system for a given number of device nodes,
#	and mount it.  Attempts to use mount_tmpfs, or falls back to
#	mount_mfs.
#
#	If do_redirect, then also redirect output to the console.
#
create_mfs_dev()
{
	ndevnodes=${1-1200}
	dev_mountpoint=${PWD:-/dev}

	# Number of inodes is the specified number of device nodes, plus
	# a margin to allow for extra device nodes created later.
	ninode=$((ndevnodes * 11 / 10))
	# Add 2 reserved inodes (needed for both mfs and tmpfs), and round
	# up to a multiple of 32 (needed for mfs, not needed for tmpfs).
	ninode=$(( (ninode + 2 + 31) / 32 * 32 ))
	# Try tmpfs; if that fails try mfs.
	#
	# For tmpfs, allocate 16KB and 512 byte per node.
	# Actual requirements are much lower, but the size limit
	# is only intended to avoid accidental writing to /dev.
	fs_bytes=$((16384 + ninode * 512))
	if mount_tmpfs -s $fs_bytes -n $ninode -m 0755 \
		-o union tmpfs "$dev_mountpoint"
	then
		fstype=tmpfs
	else
		# This file system size calculation is exact for mount_mfs(8)
		# with 512-byte sectors.  40960 bytes (80 blocks) is the
		# minimum size allowed by mount_mfs.
		fs_bytes=$((8192 + 2 * 8192 + 4096 + ninode*512 + 8192))
		[ "$fs_bytes" -lt 40960 ] && fs_bytes=40960
		fs_blocks=$((fs_bytes/512))
		if mount_mfs -b 4096 -f 512 -s $fs_blocks -n $ninode -p 0755 \
		    -o union swap "$dev_mountpoint"
		then
			fstype=mfs
		else
			die "Failed to create memory file system"
		fi
	fi

	# Our current directory was in the lower file system; change it to
	# the newly mounted upper file system.
	cd "$dev_mountpoint"

	if $do_redirect; then
		# Redirect stdout and stderr to console
		${MKNOD} -m 600 -g 0 -u 0 temp_console c %CONSOLE_CMAJOR% 0
		exec >temp_console 2>&1
		rm temp_console
	fi

	echo "Created $fstype $dev_mountpoint" \
		"($fs_bytes byte, $ninode inodes)"
}

#
# MAIN: If MAKEDEV_AS_LIBRARY is set, then we are being used as a
# function library, so just return.  Otherwise, do all the real work.
#
[ -n "${MAKEDEV_AS_LIBRARY}" ] && return
makedev_main makedev ${1+"$@"}