|
root / base / usr / src / cmd / initpkg
initpkg Plain Text 1575 lines 37.9 KB
   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
#
# 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.
#

# Hammerhead: SysV-init / SMF run-level scripts removed.
# init(8) is now /sbin/zyginit; /sbin/rc[0-3S], /etc/inittab, /etc/init.d/,
# /etc/rc[0-3S].d/, and the sysetup/uucp init scripts are gone — zyginit
# services own boot orchestration. What remains here is the boot-time
# filesystem and swap plumbing that zyginit's services invoke:
# mountall, umountall, swapadd, shutdown, plus the static configs
# (vfstab, nscd.conf, crypt.conf) and /etc/dfs/dfstab.

SHFILES=	dfstab vfstab
CPFILES=	mountall shutdown swapadd umountall
ALL=		$(SHFILES) $(CPFILES)
CLOBBERFILES=	$(ALL)

include ../Makefile.cmd

ETCDFSD=	$(ROOTETC)/dfs

SBINF=		mountall shutdown swapadd umountall
USRSBINF=	mountall umountall

ETCTABS=	vfstab nscd.conf security/crypt.conf

DFSTAB=		dfstab
SBINETC=	mountall shutdown swapadd umountall
USRSBINETC=

FILEMODE=	0744

ROOTSBINF=	$(SBINF:%=$(ROOTSBIN)/%)
ROOTUSRSBINF=	$(USRSBINF:%=$(ROOTUSRSBIN)/%)
ROOTETCTABS=	$(ETCTABS:%=$(ROOTETC)/%)
ROOTDFSTAB=	$(DFSTAB:%=$(ETCDFSD)/%)
SYMSBINF=	$(SBINETC:%=$(ROOTETC)/%)
SYMUSRSBINF=	$(USRSBINETC:%=$(ROOTETC)/%)

$(ROOTETC)/vfstab		: FILEMODE =	0644
$(ROOTETC)/nscd.conf		: FILEMODE =	0644
$(ROOTETC)/security/crypt.conf	: FILEMODE =	0644
$(ROOTDFSTAB)			: FILEMODE =	0644
$(ROOTSBIN)/mountall		: FILEMODE =	0555
$(ROOTUSRSBIN)/mountall		: FILEMODE =	0555
$(ROOTSBIN)/umountall		: FILEMODE =	0555
$(ROOTUSRSBIN)/umountall	: FILEMODE =	0555
$(ROOTSBIN)/shutdown		: FILEMODE =	0755

$(ETCDFSD)/% : %
	$(INS.file)

.KEEP_STATE:

all: $(ALL)

$(SYMSBINF):
	$(RM) $@; $(SYMLINK) ../sbin/$(@F) $@

$(SYMUSRSBINF):
	$(RM) $@; $(SYMLINK) ../usr/sbin/$(@F) $@

$(SHFILES):
	sh $@.sh $(ROOT)

install: $(ALL) ins_all

# Hammerhead: /sbin/shutdown → ../../sbin/shutdown compat symlink
ROOTUSRSBIN_SHUTDOWN = $(ROOTUSRSBIN)/shutdown
$(ROOTUSRSBIN_SHUTDOWN):
	$(RM) $@; $(SYMLINK) ../../sbin/shutdown $@

ins_all : $(ROOTSBINF) $(ROOTUSRSBINF) $(ROOTETCTABS) \
	$(ROOTDFSTAB)  $(SYMSBINF) $(SYMUSRSBINF) $(ROOTUSRSBIN_SHUTDOWN)

FRC:

clean lint:

include	../Makefile.targ
#!/sbin/sh
#
# 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 (c) 1984, 1986, 1987, 1988, 1989 AT&T
#	  All Rights Reserved
#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

case "$MACH" in
  "u3b2"|"sparc"|"i386"|"ppc" )
	echo "
# Do not modify this file directly.
# Use the sharemgr(8) command for all share management
# This file is reconstructed and only maintained for backward
# compatibility. Configuration lines could be lost.
#
#	share [-F fstype] [ -o options] [-d \"<text>\"] <pathname> [resource]
#	.e.g,
#	share  -F nfs  -o rw=engineering  -d \"home dirs\"  /export/home2
" >dfstab
	;;
  * )
	echo "Unknown architecture."
	exit 1
	;;
esac
#!/sbin/sh
#
# 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 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
#
#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
#	  All Rights Reserved
#

usage () {
	if [ -n "$1" ]; then
		echo "mountall: $1" 1>&2
	fi
	echo "Usage:\nmountall [-F FSType] [-l|-r|-g] [file_system_table]" 1>&2
	exit 2
}

PATH=/bin:/sbin:/usr/bin:/usr/sbin
TYPES=all
FSTAB=/etc/vfstab
err=0

# Clear these in case they were already set in our environment.
FSType=
GFLAG=
RFLAG=
LFLAG=
SFLAG=
RemoteFSTypes=

#	checkmessage "fsck_device | mount_point"
#
# Simple auxilary routine to the shell function checkfs. Prints out
# instructions for a manual file system check before entering the shell.
#
checkmessage() {
	echo "" > /dev/console
	if [ "$1" != "" ] ; then
		echo "WARNING - Unable to repair one or more \c" > /dev/console
		echo "of the following filesystem(s):" > /dev/console
		echo "\t$1" > /dev/console
	else
		echo "WARNING - Unable to repair one or more filesystems." \
			> /dev/console
	fi
	echo "Run fsck manually (fsck filesystem...)." > /dev/console
	echo "" > /dev/console
}

#
#	checkfs raw_device fstype mountpoint
#
# Check the file system specified. The return codes from fsck have the
# following meanings.
#	 0 - file system is unmounted and okay
#	32 - file system is unmounted and needs checking (fsck -m only)
#	33 - file system is already mounted
#	34 - cannot stat device
#	36 - uncorrectable errors detected - terminate normally (4.1 code 8)
#	37 - a signal was caught during processing (4.1 exit 12)
#	39 - uncorrectable errors detected - terminate rightaway (4.1 code 8)
#	40 - for root, same as 0 (used by rcS to remount root)
#
checkfs() {
	/sbin/fsck -F $2 -m $1  >/dev/null 2>&1

	if [ $? -ne 0 ]
	then
		# Determine fsck options by file system type
		case "$2" in
		ufs)	foptions="-o p"
			;;
		*)	foptions="-y"
			;;
		esac

		echo "The "$3" file system ("$1") is being checked."
		/sbin/fsck -F $2 ${foptions} $1
	
		case $? in
		0|40)	# file system OK
			;;

		*)	# couldn't fix the file system
			echo "/sbin/fsck failed with exit code "$?"."
			checkmessage "$1"
			;;
		esac
	fi
}

#
# Used to save an entry that we will want to mount either in
# a command file or as a mount point list.
#
# saveentry fstype options special mountp
#
saveentry() {
	if [ "$ALTM" ]; then
		echo "/sbin/mount -F $1 $2 $3 $4" >> $ALTM
	else
		mntlist="$mntlist $4"
	fi
}

# Do the passed mount options include "global"?
isglobal() {
	case ",${1}," in
	*,global,*)
		return 0
		;;
	esac
	return 1
}

# Is the passed fstype a "remote" one?
# Essentially: /bin/grep "^$1" /etc/dfs/fstypes
isremote() {
	for t in $RemoteFSTypes
	do
		[ "$t" = "$1" ] && return 0
	done
	return 1
}

# Get list of remote FS types (just once)
RemoteFSTypes=`while read t junk; do echo $t; done < /etc/dfs/fstypes`


#
# Process command line args
#
while getopts ?grlsF: c
do
	case $c in
	g)	GFLAG="g";;
	r)	RFLAG="r";;
	l)	LFLAG="l";;
	s)	SFLAG="s";;
	F)	FSType="$OPTARG";
		if [ "$TYPES" = "one" ]
		then
			echo "mountall: more than one FSType specified"
			exit 2
		fi
		TYPES="one";

		case $FSType in
		?????????*) 
			echo "mountall: FSType $FSType exceeds 8 characters"
			exit 2
		esac
		;;
	\?)	usage "";;
	esac
done

shift `/bin/expr $OPTIND - 1`	# get past the processed args

if [ $# -gt 1 ]; then
	usage "multiple arguments not supported"
fi

# get file system table name and make sure file exists
if [ $# = 1 ]; then
	case $1 in
	"-")	FSTAB=""
		;;
	*)	FSTAB=$1
		;;
	esac
fi
#
# if an alternate vfstab file is used or serial mode is specified, then
# use a mount command file
#
if [ $# = 1 -o "$SFLAG" ]; then
	ALTM=/var/tmp/mount$$
	rm -f $ALTM
fi

if [ "$FSTAB" != ""  -a  ! -s "$FSTAB" ]
then
	echo "mountall: file system table ($FSTAB) not found"
	exit 1
fi

#
# Check for incompatible args
#
if [ "$GFLAG" = "g" -a "$RFLAG$LFLAG" != "" -o \
     "$RFLAG" = "r" -a "$GFLAG$LFLAG" != "" -o \
     "$LFLAG" = "l" -a "$RFLAG$GFLAG" != "" ]
then
	usage "options -g, -r and -l are mutually exclusive"
fi

if [ "$LFLAG" = "l" -a -n "$FSType" ]; then
	# remote FSType not allowed
	isremote "$FSType" &&
	usage "option -l and FSType are incompatible"
fi

if [ "$RFLAG" = "r" -a -n "$FSType" ]; then
	# remote FSType required
	isremote "$FSType" ||
	usage "option -r and FSType are incompatible"
fi

#	file-system-table format:
#
#	column 1:	special- block special device or resource name
#	column 2: 	fsckdev- char special device for fsck 
#	column 3:	mountp- mount point
#	column 4:	fstype- File system type
#	column 5:	fsckpass- number if to be checked automatically
#	column 6:	automnt-	yes/no for automatic mount
#	column 7:	mntopts- -o specific mount options

#	White-space separates columns.
#	Lines beginning with \"#\" are comments.  Empty lines are ignored.
#	a '-' in any field is a no-op.

#
# Read FSTAB, fsck'ing appropriate filesystems:
#
exec < $FSTAB
while  read special fsckdev mountp fstype fsckpass automnt mntopts
do
	case $special in
	'#'* | '')	#  Ignore comments, empty lines
			continue ;;
	'-')		#  Ignore no-action lines
			continue
	esac

	if [ "$automnt" != "yes" ]; then
		continue
	fi
	if [ "$FSType" -a "$FSType" != "$fstype" ]; then
		# ignore different fstypes
		continue
	fi

	# The -g option is not in the man page, but according to
	# PSARC/1998/255 it's used by Sun Cluster (via contract) to
	# mount disk-based filesystems with the "global" option.
	# Also, the -l option now skips those "global" mounts.
	#
	# Note: options -g -l -r are mutually exclusive
	#
	if [ -n "$GFLAG" ]; then
		# Mount "local" filesystems that have
		# the "global" option in mntopts.
		isremote "$fstype" && continue
		isglobal "$mntopts" || continue
	fi
	if [ -n "$LFLAG" ]; then
		# Mount "local" filesystems, excluding
		# those marked "global".
		isremote "$fstype" && continue
		isglobal "$mntopts" && continue
	fi
	if [ -n "$RFLAG" ]; then
		# Mount "remote" filesystems.
		isremote "$fstype" || continue
	fi

	if [ "$fstype" = "-" ]; then
		echo "mountall: FSType of $special cannot be identified" 1>&2
		continue
	fi

	if [ "$ALTM" -a "$mntopts" != "-" ]; then
		OPTIONS="-o $mntopts"		# Use mount options if any
	else
		OPTIONS=""
	fi

	#
	# Ignore entries already mounted
	#
	/bin/grep "	$mountp	" /etc/mnttab >/dev/null 2>&1 && continue

	#
	# Can't fsck if no fsckdev is specified
	#
	if [ "$fsckdev" = "-" ]; then
		saveentry $fstype "$OPTIONS" $special $mountp
		continue
	fi
	#
	# For fsck purposes, we make a distinction between file systems
	# that have a /usr/lib/fs/<fstyp>/fsckall script and those
	# that don't.  For those that do, just keep a list of them
	# and pass the list to the fsckall script for that file
	# file system type.
	# 
	if [ -x /usr/lib/fs/$fstype/fsckall ]; then

		#
		# add fstype to the list of fstypes for which
		# fsckall should be called, if it's not already
		# in the list.
		#
		found=no
		if [ "$fsckall_fstypes" != "" ] ; then
			for fst in $fsckall_fstypes; do
				if [ "$fst" = "$fstype" ] ; then
					found=yes
					break
				fi
			done
		fi
		if [ $found = no ] ; then
			fsckall_fstypes="$fsckall_fstypes ${fstype}"
		fi

		#
		# add the device to the name of devices to be passed
		# to the fsckall program for this file system type
		#
		cmd="${fstype}_fscklist=\"\$${fstype}_fscklist $fsckdev\""
		eval $cmd
		saveentry $fstype "$OPTIONS" $special $mountp
		continue
	fi
	#
	# fsck everything else:
 	#
 	# fsck -m simply returns true if the filesystem is suitable for
 	# mounting.
 	#
	/sbin/fsck -m -F $fstype $fsckdev >/dev/null 2>&1
	case $? in
	0|40)	saveentry $fstype "$OPTIONS" $special $mountp
		continue
		;;
	32)	checkfs $fsckdev $fstype $mountp
		saveentry $fstype "$OPTIONS" $special $mountp
		continue
		;;
	33)	# already mounted
		echo "$special already mounted"
		;;
	34)	# bogus special device
		echo "Cannot stat $fsckdev - ignoring"
		err=1
		;;
	*)	# uncorrectable errors
		echo "$fsckdev uncorrectable error"
		err=1
		;;
	esac
done

#
# Call the fsckall programs
#
for fst in $fsckall_fstypes
do
	cmd="/usr/lib/fs/$fst/fsckall \$${fst}_fscklist"
	eval $cmd

	case $? in
	0)	# file systems OK
			;;

	*)	# couldn't fix some of the filesystems
		echo "fsckall failed with exit code "$?"."
		checkmessage
		;;
	esac
done

if [ "$ALTM" ]; then
	if [ ! -f "$ALTM" ]; then
		exit
	fi
	/sbin/sh $ALTM		# run the saved mount commands
	/bin/rm -f $ALTM
	exit
fi

if [ -n "$FSType" ]; then
	/sbin/mount -a -F $FSType
	exit
fi

# Some remote filesystems (e.g. autofs) shouldn't be mounted
# with mountall, so the list here is explicit (not from /etc/dfs/fstypes)
if [ "$RFLAG" ]; then
	/sbin/mount -a -F nfs
	/sbin/mount -a -F smbfs
	exit
fi

if [ "$LFLAG" -o "$GFLAG" -o $err != 0 ]; then
	[ -z "$mntlist" ] || /sbin/mount -a $mntlist
	exit
fi

# else mount them all

/sbin/mount -a
#
# 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 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"%Z%%M%	%I%	%E% SMI"
#

#
#	Currently supported cache names:
#		audit_user, auth_attr, bootparams, ethers
#		exec_attr, group, hosts, ipnodes, netmasks
#		networks, passwd, printers, prof_attr, project
#		protocols, rpc, services, tnrhdb, tnrhtp, user_attr
#
#	logfile			/var/adm/nscd.log
	enable-cache		hosts		yes

	debug-level		0

	positive-time-to-live	audit_user	3600
	negative-time-to-live	audit_user	5
	keep-hot-count		audit_user	20
	check-files		audit_user	yes

	positive-time-to-live	auth_attr	3600
	negative-time-to-live	auth_attr	5
	keep-hot-count		auth_attr	20
	check-files		auth_attr	yes

	positive-time-to-live	bootparams	3600
	negative-time-to-live	bootparams	5
	keep-hot-count		bootparams	20
	check-files		bootparams	yes

	positive-time-to-live	ethers		3600
	negative-time-to-live	ethers		5
	keep-hot-count		ethers		20
	check-files		ethers		yes

	positive-time-to-live	exec_attr	3600
	negative-time-to-live	exec_attr	300
	keep-hot-count		exec_attr	20
	check-files		exec_attr	yes

	positive-time-to-live	group		3600
	negative-time-to-live	group		5
	keep-hot-count		group		20
	check-files		group		yes

	positive-time-to-live	hosts		3600
	negative-time-to-live	hosts		5
	keep-hot-count		hosts		20
	check-files		hosts		yes

	positive-time-to-live	ipnodes		3600
	negative-time-to-live	ipnodes		5
	keep-hot-count		ipnodes		20
	check-files		ipnodes		yes

	positive-time-to-live	netmasks	3600
	negative-time-to-live	netmasks	5
	keep-hot-count		netmasks	20
	check-files		netmasks	yes

	positive-time-to-live	networks	3600
	negative-time-to-live	networks	5
	keep-hot-count		networks	20
	check-files		networks	yes

	positive-time-to-live	passwd		600
	negative-time-to-live	passwd		5
	keep-hot-count		passwd		20
	check-files		passwd		yes

	positive-time-to-live	printers	3600
	negative-time-to-live	printers	5
	keep-hot-count		printers	20
	check-files		printers	yes

	positive-time-to-live	prof_attr	3600
	negative-time-to-live	prof_attr	5
	keep-hot-count		prof_attr	20
	check-files		prof_attr	yes

	positive-time-to-live	project		3600
	negative-time-to-live	project		5
	keep-hot-count		project		20
	check-files		project		yes

	positive-time-to-live	protocols	3600
	negative-time-to-live	protocols	5
	keep-hot-count		protocols	20
	check-files		protocols	yes

	positive-time-to-live	rpc		3600
	negative-time-to-live	rpc		5
	keep-hot-count		rpc		20
	check-files		rpc		yes

	positive-time-to-live	services	3600
	negative-time-to-live	services	5
	keep-hot-count		services	20
	check-files		services	yes

	positive-time-to-live	tnrhdb		3600
	negative-time-to-live	tnrhdb		5
	keep-hot-count		tnrhdb		20
	check-files		tnrhdb		yes

	positive-time-to-live	tnrhtp		3600
	negative-time-to-live	tnrhtp		5
	keep-hot-count		tnrhtp		20
	check-files		tnrhtp		yes

	positive-time-to-live	user_attr	3600
	negative-time-to-live	user_attr	5
	keep-hot-count		user_attr	20
	check-files		user_attr	yes
#
# 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 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# The algorithm name __unix__ is reserved.

1	crypt_bsdmd5.so.1
2a	crypt_bsdbf.so.1
2b	crypt_bsdbf.so.1
md5	crypt_sunmd5.so.1
5	crypt_sha256.so.1
6	crypt_sha512.so.1
#!/sbin/sh
#
# 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 2017, OmniTI Computer Consulting, Inc. All rights reserved.
#

#	Sequence performed to change the init state of a machine.  Only allows
#	transitions to states 0,1,5,6,s,S (i.e.: down or administrative states).

#	This procedure checks to see if you are permitted and allows an
#	interactive shutdown.  The actual change of state, killing of
#	processes and such are performed by the new init state, say 0,
#	and its /sbin/rc0.

usage() {
	echo "Usage: $0 [ -y ] [ -g<grace> ] [ -i<initstate> ] [ message ]"
	exit 1
}

notify() {
	/usr/sbin/wall -a <<-!
	$*
	!
	# We used to do rwall here if showmounts had any output, but
	# rwall is a potential security hole, and it could block this, so
	# we don't bother with it anymore.
}

nologin=/etc/nologin

# Set the PATH so that to guarentee behavior of shell built in commands
# (such as echo).

PATH=/bin:/sbin:/usr/bin:/usr/sbin

# Initial sanity checks:
#	Make sure /usr is mounted
#	Check the user id (only root can run shutdown)

if [ ! -d /usr/bin ]
then
	echo "$0:  /usr is not mounted.  Mount /usr or use init to shutdown."
	exit 1
fi

if [ -x /bin/id ]
then
	eval `/bin/id  |  /bin/sed 's/[^a-z0-9=].*//'`
	if [ "${uid:=0}" -ne 0 ]
	then
	        echo "$0:  Only root can run $0"
		exit 2
	fi
else
	echo "$0:  can't check user id."
	exit 2
fi

# Get options (defaults immediately below):

grace=60
askconfirmation=yes
initstate=s

while getopts g:i:y? c
do
	case $c in
	g)
		case $OPTARG in
		*[!0-9]* )
			echo "$0: -g requires a numeric option"
			usage
			;;
		[0-9]* )
			grace=$OPTARG
			;;
		esac
		;;
	i)
		case $OPTARG in
		[Ss0156])
			initstate=$OPTARG
			;;
		[234abcqQ])
			echo "$0: Initstate $OPTARG is not for system shutdown"
			exit 1
			;;
		*)
			echo "$0: $OPTARG is not a valid initstate"
			usage
			;;
		esac
		;;
	y)
		askconfirmation=
		;;
	\?)	usage
		;;
	esac
done
shift $(($OPTIND - 1))

echo '\nShutdown started.    \c'
/bin/date
echo

NODENAME=`uname -n`

cd /

trap "rm $nologin >/dev/null 2>&1 ;exit 1"  1 2 15

# If other users are on the system (and any grace period is given), warn them.

for i in 7200 3600 1800 1200 600 300 120 60 30 10; do
	if [ ${grace} -gt $i ]
	then
		hours=$((${grace} / 3600))
		minutes=$((${grace} % 3600 / 60))
		seconds=$((${grace} % 60))
		time=""
		if [ ${hours} -gt 1 ]
		then
			time="${hours} hours "
		elif [ ${hours} -eq 1 ]
		then
			time="1 hour "
		fi
		if [ ${minutes} -gt 1 ]
		then
			time="${time}${minutes} minutes "
		elif [ ${minutes} -eq 1 ]
		then
			time="${time}1 minute "
		fi
		if [ ${hours} -eq 0 -a ${seconds} -gt 0 ]
		then
			if [ ${seconds} -eq 1 ]
			then
				time="${time}${seconds} second"
			else
				time="${time}${seconds} seconds"
			fi
		fi

		(notify \
"The system ${NODENAME} will be shut down in ${time}
$*")

		rm $nologin >/dev/null 2>&1
		cat > $nologin <<-!

			NO LOGINS: System going down in ${time}
			$*

		!

		/bin/sleep $((${grace} - $i))
		grace=$i
	fi
done

# Confirm that we really want to shutdown.

if [ ${askconfirmation} ]
then
	echo "Do you want to continue? (y or n):   \c"
	read b
	if [ "$b" != "y" ]
	then
		notify "False Alarm:  The system ${NODENAME} will not be brought down."
		echo 'Shutdown aborted.'
		rm $nologin >/dev/null 2>&1
		exit 1
	fi
fi

# Final shutdown message, and sleep away the final 10 seconds (or less).

(notify \
"THE SYSTEM ${NODENAME} IS BEING SHUT DOWN NOW ! ! !
Log off now or risk your files being damaged
$*")

if [ ${grace} -gt 0 ]
then
	/bin/sleep ${grace}
fi

# Go to the requested initstate.


echo "Changing to init state $initstate - please wait"

# We might be racing with a system that's still booting.
# Before starting init, check to see if smf(7) is running.  The easiest way
# to do this is to check for the existence of the repository service door.

i=0
# Try three times, sleeping one second each time...
while [ ! -e /etc/svc/volatile/repository_door -a $i -lt 3 ]; do
	sleep 1
	i=$(($i + 1))
done

if [ ! -e /etc/svc/volatile/repository_door ]; then
	notify "Could not find repository door, init-state change may fail!"
fi

/sbin/init ${initstate}
#!/sbin/sh
#
# 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 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
# All rights reserved.
#
#
#ident	"%Z%%M%	%I%	%E% SMI"

# Set noinuse checking during boot. We want to disable device in use checking
# so that normal swap use, such as specified in /etc/vfstab, will not cause
# swap devices to fail to be configured during boot.
NOINUSE_CHECK=1; export NOINUSE_CHECK

PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH
USAGE="Usage: swapadd [-12] [file_system_table]"

VFSTAB=/etc/vfstab	# Default file system table
PASS=2			# Default to checking for existing swap

#
# Check to see if there is an entry in the fstab for a specified file and
# mount it.  This allows swap files (e.g. nfs files) to be mounted before
# being added for swap.
#
checkmount()
{
	while read rspecial rfsckdev rmountp rfstype rfsckpass rautomnt rmntopts
	do
		#
		# Ignore comments, empty lines, and no-action lines
		#
		case "$rspecial" in
		'#'* | '' | '-') continue ;;
		esac

		if [ "x$rmountp" = "x$1" ]; then
			#
			# If mount options are '-', default to 'rw'
			#
			[ "x$rmntopts" = x- ] && rmntopts=rw

			if /sbin/mount -m -o $rmntopts $rspecial \
			    >/dev/null 2>&1; then
				echo "Mounting $rmountp for swap"
			else
				echo "Mount of $rmountp for swap failed"
			fi
			return
		fi
	done <$VFSTAB
}

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

while getopts 12 opt; do
	case "$opt" in
	1|2) PASS=$opt ;;
	 \?) die "$USAGE" ;;
	esac
done
shift `expr $OPTIND - 1`

[ $# -gt 1 ] && die "$USAGE"
[ $# -gt 0 ] && VFSTAB="$1"

#
# If $VFSTAB is not "-" (stdin), re-open stdin as the specified file
#
if [ "x$VFSTAB" != x- ]; then
	[ -s "$VFSTAB" ] || die "swapadd: file system table ($VFSTAB) not found"
	exec <$VFSTAB
fi

#
# Read the file system table to find entries of file system type "swap".
# Add the swap device or file specified in the first column.
#
while read special t1 t2 fstype t3 t4 t5; do
	#
	# Ignore comments, empty lines, and no-action lines
	#
	case "$special" in
	'#'* | '' | '-') continue ;;
	esac

	#
	# Ignore non-swap fstypes
	#
	[ "$fstype" != swap ] && continue

	if [ $PASS = 1 ]; then
		#
		# Pass 1 should handle adding the swap files that
		# are accessable immediately; block devices, files
		# in / and /usr, and direct nfs mounted files.
		#
		if [ ! -b $special ]; then
			#
			# Read the file system table searching for mountpoints
			# matching the swap file about to be added.
			#
			# NB: This won't work correctly if the file to added
			# for swapping is a sub-directory of the mountpoint.
			# e.g.	swapfile-> servername:/export/swap/clientname
			# 	mountpoint-> servername:/export/swap
			#
			checkmount $special
		fi
		if [ -f $special -a -w $special -o -b $special ]; then
			swap -$PASS -a $special >/dev/null
		fi
	else
		#
		# Pass 2 should skip all the swap already added.  If something
		# added earlier uses the same name as something to be added
		# later, the following test won't work. This should only happen
		# if parts of a particular swap file are added or deleted by
		# hand between invocations.
		#
		swap -l 2>/dev/null | grep '\<'${special}'\>' >/dev/null 2>&1 \
		    || swap -$PASS -a $special >/dev/null
	fi
done
#!/sbin/sh
#
# 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 (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
#
#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
#	  All Rights Reserved
#
#

usage () {
	if [ -n "$1" ]; then
		echo "umountall: $1" 1>&2
	fi
	echo "Usage:\n\tumountall [-k] [-s] [-F FSType] [-l|-r] [-Z] [-n]" 1>&2
	echo "\tumountall [-k] [-s] [-h host] [-Z] [-n]" 1>&2
	exit 2
}

MNTTAB=/etc/mnttab

# This script is installed as both /sbin/umountall (as used in some
# /sbin/rc? and /etc/init.d scripts) _and_ as /sbin/umountall (typically
# PATHed from the command line).  As such it should not depend on /usr
# being mounted (if /usr is a separate filesystem).
#
# /sbin/sh Bourne shell builtins we use:
#	echo
#	exit
#	getopts
#	test, [ ]
#	exec
#	read
#
# /sbin commands we use:
#	/sbin/uname
#	/sbin/umount
#
# The following /usr based commands may be used by this script (depending on
# command line options).  We will set our PATH to find them, but where they
# are not present (eg, if /usr is not mounted) we will catch references to
# them via shell functions conditionally defined after option processing
# (don't use any of these commands before then).
#
#	Command		Command line option and use
# /bin/sleep	-k, to sleep after an fuser -c -k on the mountpoint
# /usr/sbin/fuser	-k, to kill processes keeping a mount point busy
#
# In addition, we use /bin/tail if it is available; if not we use
# slower shell constructs to reverse a file.

PATH=/bin:/sbin:/usr/bin:/usr/sbin

# Clear these in case they were already set in our inherited environment.
FSType=
FFLAG=
HOST=
HFLAG=
RFLAG=
LFLAG=
SFLAG=
KFLAG=
ZFLAG=
NFLAG=
LOCALNAME=
UMOUNTFLAG=
RemoteFSTypes=

# Is the passed fstype a "remote" one?
# Essentially: /bin/grep "^$1" /etc/dfs/fstypes
isremote() {
	for t in $RemoteFSTypes
	do
		[ "$t" = "$1" ] && return 0
	done
	return 1
}

# Get list of remote FS types (just once)
RemoteFSTypes=`while read t junk; do echo $t; done < /etc/dfs/fstypes`


#
# Process command line args
#
while getopts ?rslkF:h:Zn c
do
	case $c in
	r)	RFLAG="r";;
	l)	LFLAG="l";;
	s)	SFLAG="s";;
	k)	KFLAG="k";;
	h)	if [ -n "$HFLAG" ]; then
			usage "more than one host specified"
		fi
		HOST=$OPTARG
		HFLAG="h"
		LOCALNAME=`/bin/uname -n`
		;; 
	F)	if [ -n "$FFLAG" ]; then
			usage "more than one FStype specified"
		fi
		FSType=$OPTARG 
		FFLAG="f"
		case $FSType in
		?????????*) 
			usage "FSType ${FSType} exceeds 8 characters"
		esac;
		;;
	Z)	ZFLAG="z";;
	n)	NFLAG="n"
		# Alias any commands that would perform real actions to
		# something that tells what action would have been performed
		UMOUNTFLAG="-V"
		fuser () {
			echo "fuser $*" 1>&2
		}
		sleep () {
			: # No need to show where we'd sleep
		}
		;;
	\?)	usage ""
		;;
	esac
done

# Sanity checking:
#	1) arguments beyond those supported
#	2) can't specify both remote and local
#	3) can't specify a host with -r or -l
#	4) can't specify a fstype with -h
#	5) can't specify this host with -h (checks only uname -n)
#	6) can't be fstype nfs and local
#	7) only fstype nfs is remote

if [ $# -ge $OPTIND ]; then						# 1
	usage "additional arguments not supported"
fi

if [ -n "$RFLAG" -a -n "$LFLAG" ]; then					# 2
	usage "options -r and -l are incompatible"
fi

if [ \( -n "$RFLAG" -o -n "$LFLAG" \) -a "$HFLAG" = "h" ]; then		# 3
	usage "option -${RFLAG}${LFLAG} incompatible with -h option"
fi

if [ -n "$FFLAG" -a "$HFLAG" = "h" ]; then				# 4
	usage "Specifying FStype incompatible with -h option"
fi

if [ -n "$HFLAG" -a "$HOST" = "$LOCALNAME" ]; then			# 5
	usage "Specifying local host illegal for -h option"
fi

if [ "$LFLAG" = "l" -a -n "$FSType" ]; then				# 6
	# remote FSType not allowed
	isremote "$FSType" &&
	usage "option -l and FSType ${FSType} are incompatible"
fi

if [ "$RFLAG" = "r" -a -n "$FSType" ]; then				# 7
	# remote FSType required
	isremote "$FSType" ||
	usage "option -r and FSType ${FSType} are incompatible"
fi

ZONENAME=`zonename`

#
# Take advantage of parallel unmounting at this point if we have no
# criteria to match and we are in the global zone
#
if [ -z "${SFLAG}${LFLAG}${RFLAG}${HFLAG}${KFLAG}${FFLAG}${ZFLAG}" -a \
    "$ZONENAME" = "global" ]; then
	umount -a ${UMOUNTFLAG}
	exit			# with return code of the umount -a
fi

#
# Catch uses of /usr commands when /usr is not mounted
if [ -n "$KFLAG" -a -z "$NFLAG" ]; then
	if [ ! -x /usr/sbin/fuser ]; then
		fuser () {
			echo "umountall: fuser -k skipped (no /usr)" 1>&2
			# continue - not fatal
		}
		sleep () {
			: # no point in sleeping if fuser is doing nothing
		}
	else
		if [ ! -x /bin/sleep ]; then
			sleep () {
		echo "umountall: sleep after fuser -k skipped (no /usr)" 1>&2
				# continue - not fatal
			}
		fi
	fi
fi

#
# Shell function to avoid using /usr/bin/cut.  Given a dev from a
# fstype=nfs line in mnttab (eg, "host:/export) extract the host
# component.  The dev string looks like: "host:/path"
print_nfs_host () {
	OIFS=$IFS
	IFS=":"
	set -- $*
	echo $1
	IFS=$OIFS
}
#
# Similar for smbfs, but tricky due to the optional parts
# of the "device" syntax.  The dev strings look like:
# "//server/share" or "//user@server/share"
print_smbfs_host () {
	OIFS=$IFS
	IFS="/@"
	set -- $*
	case $# in
	3) echo "$2";;
	2) echo "$1";;
	esac
	IFS=$OIFS
}

#
# doumounts echos its return code to stdout, so commands used within
# this function should take care to produce no other output to stdout.
doumounts () {
	(
	rc=0
	fslist=""
	while read dev mountp fstype mode dummy
	do
		case "${mountp}" in
		/			| \
		/dev			| \
		/dev/fd			| \
		/devices		| \
		/etc/mnttab		| \
		/etc/svc/volatile	| \
		/lib			| \
		/proc			| \
		/sbin			| \
		/system/contract	| \
		/system/object		| \
		/tmp			| \
		/tmp/.libgrubmgmt*	| \
		/usr			| \
		/var			| \
		/var/adm		| \
		/var/run		| \
		'' )
			#
			# file systems possibly mounted in the kernel or
			# in the methods of some of the file system
			# services
			#
			continue
			;;
		* )
			if [ -n "$HFLAG" ]; then
				thishost='-'
				if [ "$fstype" = "nfs" ]; then
					thishost=`print_nfs_host $dev`
				fi
				if [ "$fstype" = "smbfs" ]; then
					thishost=`print_smbfs_host $dev`
				fi
				if [ "$HOST" != "$thishost" ]; then
					continue
				fi
			fi
			if [ -n "$FFLAG" -a "$FSType" != "$fstype" ]; then
				continue
			fi

			if [ -n "$LFLAG" ]; then
				# umount local filesystems
				isremote "$fstype" && continue
			fi

			# Note: isremote is true for both nfs & autofs, so
			# this will filter out autofs mounts with nfs file
			# system mounted on the top of it.
			#
			# WARNING: use of any syscall on a NFS file system has
			# the danger to go over-the-wire and could cause nfs
			# clients to hang on shutdown, if the nfs server is
			# down beforehand.
			# For the reason described above, a simple test like 
			# "df -F nfs $mountp" can't be used to filter out
			# nfs-over-autofs mounts.  (isremote works OK)
			#
			if [ -n "$RFLAG" ]; then
				# umount remote filesystems
				isremote "$fstype" || continue
			fi
			if [ "$ZONENAME" != "global" ]; then
				for option in `echo $mode | tr , '\012'`; do
					#
					# should not see any zone options
					# but our own
					#
					if [ "$option" = "zone=$ZONENAME" ]; then
						break
					fi
				done
				if [ "$option" != "zone=$ZONENAME" ]; then
					continue
				fi
			# we are called from the global zone
			else 
				for option in `echo $mode | tr , '\012'`; do
					case "$option" in
					zone=*)
						option="zone="
						break
					;;
					esac
				done
				# skip mounts from non-global zones if ZFLAG is not set
				if [ "$option" = "zone=" -a -z "$ZFLAG" ]; then
					continue
				fi
				# skip mounts from the global zone if ZFLAG is set
				if [ "$option" != "zone=" -a -n "$ZFLAG" ]; then
					continue
				fi
			fi
			if [ -n "${KFLAG}" ]; then
				fuser -c -k $mountp 1>&2
				sleep 2
			fi
			if [ -n "$SFLAG" ]; then
				umount ${UMOUNTFLAG} ${mountp} 1>&2
				trc=$?
				if [ $trc -ne 0 ]; then
					rc=$trc
				fi
			else
				# We want to umount in parallel
				fslist="$fslist $mountp"
			fi
		esac
	done

	if [ -n "$fslist" ]; then
		umount -a ${UMOUNTFLAG} $fslist 1>&2
		trc=$?
		if [ $trc -ne 0 ]; then
			rc=$trc
		fi
	fi

	echo $rc
	)
}

#
# /etc/mnttab has the most recent mounts last.  Reverse it so that we
# may umount in opposite order to the original mounts.
#

if [ ! -x /bin/tail ]; then
	exec < $MNTTAB
	REVERSED=
	while read line; do
		if [ -n "$REVERSED" ]; then
        		REVERSED="$line\n$REVERSED"
		else
			REVERSED="$line"
		fi
	done

	error=`echo $REVERSED | doumounts`
else
	error=`/bin/tail -r $MNTTAB | doumounts`
fi

exit $error
#!/sbin/sh
#
# 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 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"%Z%%M%	%I%	%E% SMI"
#
#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
#	  All Rights Reserved

#

echo "#device		device		mount		FS	fsck	mount	mount
#to mount	to fsck		point		type	pass	at boot	options
#
/devices	-		/devices	devfs	-	no	-
/proc		-		/proc		proc	-	no	-
ctfs		-		/system/contract ctfs	-	no	-
objfs		-		/system/object	objfs	-	no	-
sharefs		-		/etc/dfs/sharetab	sharefs	-	no	-
fd		-		/dev/fd		fd	-	no	-
swap		-		/tmp		tmpfs	-	yes	-
">vfstab